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

1.10      albertel    1: # The LearningOnline Network with CAPA
1.1       albertel    2: # a pile of common routines
1.10      albertel    3: #
1.518   ! albertel    4: # $Id: loncommon.pm,v 1.517 2007/04/03 18:47:23 raeburn Exp $
1.10      albertel    5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
1.1       albertel   28: 
                     29: # Makes a table out of the previous attempts
1.2       albertel   30: # Inputs result_from_symbread, user, domain, course_id
1.16      harris41   31: # Reads in non-network-related .tab files
1.1       albertel   32: 
1.35      matthew    33: # POD header:
                     34: 
1.45      matthew    35: =pod
                     36: 
1.35      matthew    37: =head1 NAME
                     38: 
                     39: Apache::loncommon - pile of common routines
                     40: 
                     41: =head1 SYNOPSIS
                     42: 
1.112     bowersj2   43: Common routines for manipulating connections, student answers,
                     44:     domains, common Javascript fragments, etc.
1.35      matthew    45: 
1.112     bowersj2   46: =head1 OVERVIEW
1.35      matthew    47: 
1.112     bowersj2   48: A collection of commonly used subroutines that don't have a natural
                     49: home anywhere else. This collection helps remove
1.35      matthew    50: redundancy from other modules and increase efficiency of memory usage.
                     51: 
                     52: =cut 
                     53: 
                     54: # End of POD header
1.1       albertel   55: package Apache::loncommon;
                     56: 
                     57: use strict;
1.258     albertel   58: use Apache::lonnet;
1.46      matthew    59: use GDBM_File;
1.51      www        60: use POSIX qw(strftime mktime);
1.82      www        61: use Apache::lonmenu();
1.498     albertel   62: use Apache::lonenc();
1.117     www        63: use Apache::lonlocal;
1.139     matthew    64: use HTML::Entities;
1.334     albertel   65: use Apache::lonhtmlcommon();
                     66: use Apache::loncoursedata();
1.344     albertel   67: use Apache::lontexconvert();
1.444     albertel   68: use Apache::lonclonecourse();
1.479     albertel   69: use LONCAPA qw(:DEFAULT :match);
1.117     www        70: 
1.517     raeburn    71: # ---------------------------------------------- Designs
                     72: use vars qw(%defaultdesign);
                     73: 
1.22      www        74: my $readit;
                     75: 
1.517     raeburn    76: 
1.157     matthew    77: ##
                     78: ## Global Variables
                     79: ##
1.46      matthew    80: 
1.20      www        81: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12      harris41   82: my %language;
1.124     www        83: my %supported_language;
1.12      harris41   84: my %cprtag;
1.192     taceyjo1   85: my %scprtag;
1.351     www        86: my %fe; my %fd; my %fm;
1.41      ng         87: my %category_extensions;
1.12      harris41   88: 
1.46      matthew    89: # ---------------------------------------------- Thesaurus variables
1.144     matthew    90: #
                     91: # %Keywords:
                     92: #      A hash used by &keyword to determine if a word is considered a keyword.
                     93: # $thesaurus_db_file 
                     94: #      Scalar containing the full path to the thesaurus database.
1.46      matthew    95: 
                     96: my %Keywords;
                     97: my $thesaurus_db_file;
                     98: 
1.144     matthew    99: #
                    100: # Initialize values from language.tab, copyright.tab, filetypes.tab,
                    101: # thesaurus.tab, and filecategories.tab.
                    102: #
1.18      www       103: BEGIN {
1.46      matthew   104:     # Variable initialization
                    105:     $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
                    106:     #
1.22      www       107:     unless ($readit) {
1.12      harris41  108: # ------------------------------------------------------------------- languages
                    109:     {
1.158     raeburn   110:         my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
                    111:                                    '/language.tab';
                    112:         if ( open(my $fh,"<$langtabfile") ) {
1.356     albertel  113:             while (my $line = <$fh>) {
                    114:                 next if ($line=~/^\#/);
                    115:                 chomp($line);
                    116:                 my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$line));
1.158     raeburn   117:                 $language{$key}=$val.' - '.$enc;
                    118:                 if ($sup) {
                    119:                     $supported_language{$key}=$sup;
                    120:                 }
                    121:             }
                    122:             close($fh);
                    123:         }
1.12      harris41  124:     }
                    125: # ------------------------------------------------------------------ copyrights
                    126:     {
1.158     raeburn   127:         my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
                    128:                                   '/copyright.tab';
                    129:         if ( open (my $fh,"<$copyrightfile") ) {
1.356     albertel  130:             while (my $line = <$fh>) {
                    131:                 next if ($line=~/^\#/);
                    132:                 chomp($line);
                    133:                 my ($key,$val)=(split(/\s+/,$line,2));
1.158     raeburn   134:                 $cprtag{$key}=$val;
                    135:             }
                    136:             close($fh);
                    137:         }
1.12      harris41  138:     }
1.351     www       139: # ----------------------------------------------------------- source copyrights
1.192     taceyjo1  140:     {
                    141:         my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
                    142:                                   '/source_copyright.tab';
                    143:         if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356     albertel  144:             while (my $line = <$fh>) {
                    145:                 next if ($line =~ /^\#/);
                    146:                 chomp($line);
                    147:                 my ($key,$val)=(split(/\s+/,$line,2));
1.192     taceyjo1  148:                 $scprtag{$key}=$val;
                    149:             }
                    150:             close($fh);
                    151:         }
                    152:     }
1.63      www       153: 
1.517     raeburn   154: # -------------------------------------------------------------- default domain designs
1.63      www       155:     my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517     raeburn   156:     my $designfile = $designdir.'/default.tab';
                    157:     if ( open (my $fh,"<$designfile") ) {
                    158:         while (my $line = <$fh>) {
                    159:             next if ($line =~ /^\#/);
                    160:             chomp($line);
                    161:             my ($key,$val)=(split(/\=/,$line));
                    162:             if ($val) { $defaultdesign{$key}=$val; }
                    163:         }
                    164:         close($fh);
1.63      www       165:     }
                    166: 
1.15      harris41  167: # ------------------------------------------------------------- file categories
                    168:     {
1.158     raeburn   169:         my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
                    170:                                   '/filecategories.tab';
                    171:         if ( open (my $fh,"<$categoryfile") ) {
1.356     albertel  172: 	    while (my $line = <$fh>) {
                    173: 		next if ($line =~ /^\#/);
                    174: 		chomp($line);
                    175:                 my ($extension,$category)=(split(/\s+/,$line,2));
1.158     raeburn   176:                 push @{$category_extensions{lc($category)}},$extension;
                    177:             }
                    178:             close($fh);
                    179:         }
                    180: 
1.15      harris41  181:     }
1.12      harris41  182: # ------------------------------------------------------------------ file types
                    183:     {
1.158     raeburn   184:         my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
                    185:                '/filetypes.tab';
                    186:         if ( open (my $fh,"<$typesfile") ) {
1.356     albertel  187:             while (my $line = <$fh>) {
                    188: 		next if ($line =~ /^\#/);
                    189: 		chomp($line);
                    190:                 my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158     raeburn   191:                 if ($descr ne '') {
                    192:                     $fe{$ending}=lc($emb);
                    193:                     $fd{$ending}=$descr;
1.351     www       194:                     if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158     raeburn   195:                 }
                    196:             }
                    197:             close($fh);
                    198:         }
1.12      harris41  199:     }
1.22      www       200:     &Apache::lonnet::logthis(
1.46      matthew   201:               "<font color=yellow>INFO: Read file types</font>");
1.22      www       202:     $readit=1;
1.46      matthew   203:     }  # end of unless($readit) 
1.32      matthew   204:     
                    205: }
1.112     bowersj2  206: 
1.42      matthew   207: ###############################################################
                    208: ##           HTML and Javascript Helper Functions            ##
                    209: ###############################################################
                    210: 
                    211: =pod 
                    212: 
1.112     bowersj2  213: =head1 HTML and Javascript Functions
1.42      matthew   214: 
1.112     bowersj2  215: =over 4
                    216: 
                    217: =item * browser_and_searcher_javascript ()
                    218: 
                    219: X<browsing, javascript>X<searching, javascript>Returns a string
                    220: containing javascript with two functions, C<openbrowser> and
                    221: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
                    222: tags.
1.42      matthew   223: 
1.112     bowersj2  224: =item * openbrowser(formname,elementname,only,omit) [javascript]
1.42      matthew   225: 
                    226: inputs: formname, elementname, only, omit
                    227: 
                    228: formname and elementname indicate the name of the html form and name of
                    229: the element that the results of the browsing selection are to be placed in. 
                    230: 
                    231: Specifying 'only' will restrict the browser to displaying only files
1.185     www       232: with the given extension.  Can be a comma separated list.
1.42      matthew   233: 
                    234: Specifying 'omit' will restrict the browser to NOT displaying files
1.185     www       235: with the given extension.  Can be a comma separated list.
1.42      matthew   236: 
1.112     bowersj2  237: =item * opensearcher(formname, elementname) [javascript]
1.42      matthew   238: 
                    239: Inputs: formname, elementname
                    240: 
                    241: formname and elementname specify the name of the html form and the name
                    242: of the element the selection from the search results will be placed in.
                    243: 
                    244: =cut
                    245: 
                    246: sub browser_and_searcher_javascript {
1.199     albertel  247:     my ($mode)=@_;
                    248:     if (!defined($mode)) { $mode='edit'; }
1.453     albertel  249:     my $resurl=&escape_single(&lastresurl());
1.42      matthew   250:     return <<END;
1.219     albertel  251: // <!-- BEGIN LON-CAPA Internal
1.50      matthew   252:     var editbrowser = null;
1.135     albertel  253:     function openbrowser(formname,elementname,only,omit,titleelement) {
1.170     www       254:         var url = '$resurl/?';
1.42      matthew   255:         if (editbrowser == null) {
                    256:             url += 'launch=1&';
                    257:         }
                    258:         url += 'catalogmode=interactive&';
1.199     albertel  259:         url += 'mode=$mode&';
1.42      matthew   260:         url += 'form=' + formname + '&';
                    261:         if (only != null) {
                    262:             url += 'only=' + only + '&';
1.217     albertel  263:         } else {
                    264:             url += 'only=&';
                    265: 	}
1.42      matthew   266:         if (omit != null) {
                    267:             url += 'omit=' + omit + '&';
1.217     albertel  268:         } else {
                    269:             url += 'omit=&';
                    270: 	}
1.135     albertel  271:         if (titleelement != null) {
                    272:             url += 'titleelement=' + titleelement + '&';
1.217     albertel  273:         } else {
                    274: 	    url += 'titleelement=&';
                    275: 	}
1.42      matthew   276:         url += 'element=' + elementname + '';
                    277:         var title = 'Browser';
1.435     albertel  278:         var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42      matthew   279:         options += ',width=700,height=600';
                    280:         editbrowser = open(url,title,options,'1');
                    281:         editbrowser.focus();
                    282:     }
                    283:     var editsearcher;
1.135     albertel  284:     function opensearcher(formname,elementname,titleelement) {
1.42      matthew   285:         var url = '/adm/searchcat?';
                    286:         if (editsearcher == null) {
                    287:             url += 'launch=1&';
                    288:         }
                    289:         url += 'catalogmode=interactive&';
1.199     albertel  290:         url += 'mode=$mode&';
1.42      matthew   291:         url += 'form=' + formname + '&';
1.135     albertel  292:         if (titleelement != null) {
                    293:             url += 'titleelement=' + titleelement + '&';
1.217     albertel  294:         } else {
                    295: 	    url += 'titleelement=&';
                    296: 	}
1.42      matthew   297:         url += 'element=' + elementname + '';
                    298:         var title = 'Search';
1.435     albertel  299:         var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42      matthew   300:         options += ',width=700,height=600';
                    301:         editsearcher = open(url,title,options,'1');
                    302:         editsearcher.focus();
                    303:     }
1.219     albertel  304: // END LON-CAPA Internal -->
1.42      matthew   305: END
1.170     www       306: }
                    307: 
                    308: sub lastresurl {
1.258     albertel  309:     if ($env{'environment.lastresurl'}) {
                    310: 	return $env{'environment.lastresurl'}
1.170     www       311:     } else {
                    312: 	return '/res';
                    313:     }
                    314: }
                    315: 
                    316: sub storeresurl {
                    317:     my $resurl=&Apache::lonnet::clutter(shift);
                    318:     unless ($resurl=~/^\/res/) { return 0; }
                    319:     $resurl=~s/\/$//;
                    320:     &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
                    321:     &Apache::lonnet::appenv('environment.lastresurl' => $resurl);
                    322:     return 1;
1.42      matthew   323: }
                    324: 
1.74      www       325: sub studentbrowser_javascript {
1.111     www       326:    unless (
1.258     albertel  327:             (($env{'request.course.id'}) && 
1.302     albertel  328:              (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
                    329: 	      || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
                    330: 					  '/'.$env{'request.course.sec'})
                    331: 	      ))
1.258     albertel  332:          || ($env{'request.role'}=~/^(au|dc|su)/)
1.111     www       333:           ) { return ''; }  
1.74      www       334:    return (<<'ENDSTDBRW');
                    335: <script type="text/javascript" language="Javascript" >
                    336:     var stdeditbrowser;
1.111     www       337:     function openstdbrowser(formname,uname,udom,roleflag) {
1.74      www       338:         var url = '/adm/pickstudent?';
                    339:         var filter;
                    340:         eval('filter=document.'+formname+'.'+uname+'.value;');
                    341:         if (filter != null) {
                    342:            if (filter != '') {
                    343:                url += 'filter='+filter+'&';
                    344: 	   }
                    345:         }
                    346:         url += 'form=' + formname + '&unameelement='+uname+
                    347:                                     '&udomelement='+udom;
1.111     www       348: 	if (roleflag) { url+="&roles=1"; }
1.102     www       349:         var title = 'Student_Browser';
1.74      www       350:         var options = 'scrollbars=1,resizable=1,menubar=0';
                    351:         options += ',width=700,height=600';
                    352:         stdeditbrowser = open(url,title,options,'1');
                    353:         stdeditbrowser.focus();
                    354:     }
                    355: </script>
                    356: ENDSTDBRW
                    357: }
1.42      matthew   358: 
1.74      www       359: sub selectstudent_link {
1.111     www       360:    my ($form,$unameele,$udomele)=@_;
1.258     albertel  361:    if ($env{'request.course.id'}) {  
1.302     albertel  362:        if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
                    363: 	   && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
                    364: 					'/'.$env{'request.course.sec'})) {
1.111     www       365: 	   return '';
                    366:        }
                    367:        return "<a href='".'javascript:openstdbrowser("'.$form.'","'.$unameele.
1.119     www       368:         '","'.$udomele.'");'."'>".&mt('Select User')."</a>";
1.74      www       369:    }
1.258     albertel  370:    if ($env{'request.role'}=~/^(au|dc|su)/) {
1.111     www       371:        return "<a href='".'javascript:openstdbrowser("'.$form.'","'.$unameele.
1.119     www       372:         '","'.$udomele.'",1);'."'>".&mt('Select User')."</a>";
1.111     www       373:    }
                    374:    return '';
1.91      www       375: }
                    376: 
                    377: sub coursebrowser_javascript {
1.468     raeburn   378:     my ($domainfilter,$sec_element,$formname)=@_;
1.377     raeburn   379:     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   380:    my $output = '
1.91      www       381: <script type="text/javascript" language="Javascript" >
1.468     raeburn   382:     var stdeditbrowser;'."\n";
                    383:    $output .= <<"ENDSTDBRW";
1.377     raeburn   384:     function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,crstype) {
1.91      www       385:         var url = '/adm/pickcourse?';
1.468     raeburn   386:         var domainfilter = '';
                    387:         var formid = getFormIdByName(formname);
                    388:         if (formid > -1) {
                    389:             var domid = getIndexByName(formid,udom);
                    390:             if (domid > -1) {
                    391:                 if (document.forms[formid].elements[domid].type == 'select-one') {
                    392:                     domainfilter=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
                    393:                 }
                    394:                 if (document.forms[formid].elements[domid].type == 'hidden') {
                    395:                     domainfilter=document.forms[formid].elements[domid].value;
                    396:                 }
                    397:             }
1.91      www       398:         }
1.128     albertel  399:         if (domainfilter != null) {
                    400:            if (domainfilter != '') {
                    401:                url += 'domainfilter='+domainfilter+'&';
                    402: 	   }
                    403:         }
1.91      www       404:         url += 'form=' + formname + '&cnumelement='+uname+
1.187     albertel  405: 	                            '&cdomelement='+udom+
                    406:                                     '&cnameelement='+desc;
1.468     raeburn   407:         if (extra_element !=null && extra_element != '') {
                    408:             if (formname == 'rolechoice') {
                    409:                 url += '&roleelement='+extra_element;
                    410:                 if (domainfilter == null || domainfilter == '') {
                    411:                     url += '&domainfilter='+extra_element;
                    412:                 }
1.234     raeburn   413:             }
1.468     raeburn   414:             else {
                    415:                 if (formname == 'portform') {
                    416:                     url += '&setroles='+extra_element;
                    417:                 }
                    418:             }     
1.230     raeburn   419:         }
1.293     raeburn   420:         if (multflag !=null && multflag != '') {
                    421:             url += '&multiple='+multflag;
                    422:         }
1.377     raeburn   423:         if (crstype == 'Course/Group') {
                    424:             if (formname == 'cu') {
                    425:                 crstype = document.cu.crstype.options[document.cu.crstype.selectedIndex].value; 
                    426:                 if (crstype == "") {
                    427:                     alert("$crs_or_grp_alert");
                    428:                     return;
                    429:                 }
                    430:             }
                    431:         }
                    432:         if (crstype !=null && crstype != '') {
                    433:             url += '&type='+crstype;
                    434:         }
1.102     www       435:         var title = 'Course_Browser';
1.91      www       436:         var options = 'scrollbars=1,resizable=1,menubar=0';
                    437:         options += ',width=700,height=600';
                    438:         stdeditbrowser = open(url,title,options,'1');
                    439:         stdeditbrowser.focus();
                    440:     }
1.468     raeburn   441: 
                    442:     function getFormIdByName(formname) {
                    443:         for (var i=0;i<document.forms.length;i++) {
                    444:             if (document.forms[i].name == formname) {
                    445:                 return i;
                    446:             }
                    447:         }
                    448:         return -1; 
                    449:     }
                    450: 
                    451:     function getIndexByName(formid,item) {
                    452:         for (var i=0;i<document.forms[formid].elements.length;i++) {
                    453:             if (document.forms[formid].elements[i].name == item) {
                    454:                 return i;
                    455:             }
                    456:         }
                    457:         return -1;
                    458:     }
1.91      www       459: ENDSTDBRW
1.468     raeburn   460:     if ($sec_element ne '') {
                    461:         $output .= &setsec_javascript($sec_element,$formname);
                    462:     }
                    463:     $output .= '
                    464: </script>';
                    465:     return $output;
                    466: }
                    467: 
                    468: sub setsec_javascript {
                    469:     my ($sec_element,$formname) = @_;
                    470:     my $setsections = qq|
                    471: function setSect(sectionlist) {
                    472:     var sectionsArray = sectionlist.split(",");
                    473:     var numSections = sectionsArray.length;
                    474:     document.$formname.$sec_element.length = 0;
                    475:     if (numSections == 0) {
                    476:         document.$formname.$sec_element.multiple=false;
                    477:         document.$formname.$sec_element.size=1;
                    478:         document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
                    479:     } else {
                    480:         if (numSections == 1) {
                    481:             document.$formname.$sec_element.multiple=false;
                    482:             document.$formname.$sec_element.size=1;
                    483:             document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
                    484:             document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
                    485:             document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
                    486:         } else {
                    487:             for (var i=0; i<numSections; i++) {
                    488:                 document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
                    489:             }
                    490:             document.$formname.$sec_element.multiple=true
                    491:             if (numSections < 3) {
                    492:                 document.$formname.$sec_element.size=numSections;
                    493:             } else {
                    494:                 document.$formname.$sec_element.size=3;
                    495:             }
                    496:             document.$formname.$sec_element.options[0].selected = false
                    497:         }
                    498:     }
1.91      www       499: }
1.468     raeburn   500: |;
                    501:     return $setsections;
                    502: }
                    503: 
1.91      www       504: 
                    505: sub selectcourse_link {
1.377     raeburn   506:    my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype)=@_;
1.492     albertel  507:    return "<a href='".'javascript:opencrsbrowser("'.$form.'","'.$unameele.
                    508:         '","'.$udomele.'","'.$desc.'","'.$extra_element.'","'.$multflag.'","'.$selecttype.'");'."'>".&mt('Select Course')."</a>";
1.74      www       509: }
1.42      matthew   510: 
1.273     raeburn   511: sub check_uncheck_jscript {
                    512:     my $jscript = <<"ENDSCRT";
                    513: function checkAll(field) {
                    514:     if (field.length > 0) {
                    515:         for (i = 0; i < field.length; i++) {
                    516:             field[i].checked = true ;
                    517:         }
                    518:     } else {
                    519:         field.checked = true
                    520:     }
                    521: }
                    522:  
                    523: function uncheckAll(field) {
                    524:     if (field.length > 0) {
                    525:         for (i = 0; i < field.length; i++) {
                    526:             field[i].checked = false ;
                    527:         }     } else {
                    528:         field.checked = false ;
                    529:     }
                    530: }
                    531: ENDSCRT
                    532:     return $jscript;
                    533: }
                    534: 
                    535: 
1.42      matthew   536: =pod
1.36      matthew   537: 
1.112     bowersj2  538: =item * linked_select_forms(...)
1.36      matthew   539: 
                    540: linked_select_forms returns a string containing a <script></script> block
                    541: and html for two <select> menus.  The select menus will be linked in that
                    542: changing the value of the first menu will result in new values being placed
                    543: in the second menu.  The values in the select menu will appear in alphabetical
                    544: order.
                    545: 
                    546: linked_select_forms takes the following ordered inputs:
                    547: 
                    548: =over 4
                    549: 
1.112     bowersj2  550: =item * $formname, the name of the <form> tag
1.36      matthew   551: 
1.112     bowersj2  552: =item * $middletext, the text which appears between the <select> tags
1.36      matthew   553: 
1.112     bowersj2  554: =item * $firstdefault, the default value for the first menu
1.36      matthew   555: 
1.112     bowersj2  556: =item * $firstselectname, the name of the first <select> tag
1.36      matthew   557: 
1.112     bowersj2  558: =item * $secondselectname, the name of the second <select> tag
1.36      matthew   559: 
1.112     bowersj2  560: =item * $hashref, a reference to a hash containing the data for the menus.
1.36      matthew   561: 
1.41      ng        562: =back 
                    563: 
1.36      matthew   564: Below is an example of such a hash.  Only the 'text', 'default', and 
                    565: 'select2' keys must appear as stated.  keys(%menu) are the possible 
                    566: values for the first select menu.  The text that coincides with the 
1.41      ng        567: first menu value is given in $menu{$choice1}->{'text'}.  The values 
1.36      matthew   568: and text for the second menu are given in the hash pointed to by 
                    569: $menu{$choice1}->{'select2'}.  
                    570: 
1.112     bowersj2  571:  my %menu = ( A1 => { text =>"Choice A1" ,
                    572:                        default => "B3",
                    573:                        select2 => { 
                    574:                            B1 => "Choice B1",
                    575:                            B2 => "Choice B2",
                    576:                            B3 => "Choice B3",
                    577:                            B4 => "Choice B4"
                    578:                            }
                    579:                    },
                    580:                A2 => { text =>"Choice A2" ,
                    581:                        default => "C2",
                    582:                        select2 => { 
                    583:                            C1 => "Choice C1",
                    584:                            C2 => "Choice C2",
                    585:                            C3 => "Choice C3"
                    586:                            }
                    587:                    },
                    588:                A3 => { text =>"Choice A3" ,
                    589:                        default => "D6",
                    590:                        select2 => { 
                    591:                            D1 => "Choice D1",
                    592:                            D2 => "Choice D2",
                    593:                            D3 => "Choice D3",
                    594:                            D4 => "Choice D4",
                    595:                            D5 => "Choice D5",
                    596:                            D6 => "Choice D6",
                    597:                            D7 => "Choice D7"
                    598:                            }
                    599:                    }
                    600:                );
1.36      matthew   601: 
                    602: =cut
                    603: 
                    604: sub linked_select_forms {
                    605:     my ($formname,
                    606:         $middletext,
                    607:         $firstdefault,
                    608:         $firstselectname,
                    609:         $secondselectname, 
                    610:         $hashref
                    611:         ) = @_;
                    612:     my $second = "document.$formname.$secondselectname";
                    613:     my $first = "document.$formname.$firstselectname";
                    614:     # output the javascript to do the changing
                    615:     my $result = '';
1.219     albertel  616:     $result.="<script type=\"text/javascript\">\n";
1.36      matthew   617:     $result.="var select2data = new Object();\n";
                    618:     $" = '","';
                    619:     my $debug = '';
                    620:     foreach my $s1 (sort(keys(%$hashref))) {
                    621:         $result.="select2data.d_$s1 = new Object();\n";        
                    622:         $result.="select2data.d_$s1.def = new String('".
                    623:             $hashref->{$s1}->{'default'}."');\n";
                    624:         $result.="select2data.d_$s1.values = new Array(";        
                    625:         my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
                    626:         $result.="\"@s2values\");\n";
                    627:         $result.="select2data.d_$s1.texts = new Array(";        
                    628:         my @s2texts;
                    629:         foreach my $value (@s2values) {
                    630:             push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
                    631:         }
                    632:         $result.="\"@s2texts\");\n";
                    633:     }
                    634:     $"=' ';
                    635:     $result.= <<"END";
                    636: 
                    637: function select1_changed() {
                    638:     // Determine new choice
                    639:     var newvalue = "d_" + $first.value;
                    640:     // update select2
                    641:     var values     = select2data[newvalue].values;
                    642:     var texts      = select2data[newvalue].texts;
                    643:     var select2def = select2data[newvalue].def;
                    644:     var i;
                    645:     // out with the old
                    646:     for (i = 0; i < $second.options.length; i++) {
                    647:         $second.options[i] = null;
                    648:     }
                    649:     // in with the nuclear
                    650:     for (i=0;i<values.length; i++) {
                    651:         $second.options[i] = new Option(values[i]);
1.143     matthew   652:         $second.options[i].value = values[i];
1.36      matthew   653:         $second.options[i].text = texts[i];
                    654:         if (values[i] == select2def) {
                    655:             $second.options[i].selected = true;
                    656:         }
                    657:     }
                    658: }
                    659: </script>
                    660: END
                    661:     # output the initial values for the selection lists
                    662:     $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
                    663:     foreach my $value (sort(keys(%$hashref))) {
                    664:         $result.="    <option value=\"$value\" ";
1.253     albertel  665:         $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119     www       666:         $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36      matthew   667:     }
                    668:     $result .= "</select>\n";
                    669:     my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
                    670:     $result .= $middletext;
                    671:     $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
                    672:     my $seconddefault = $hashref->{$firstdefault}->{'default'};
                    673:     foreach my $value (sort(keys(%select2))) {
                    674:         $result.="    <option value=\"$value\" ";        
1.253     albertel  675:         $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119     www       676:         $result.=">".&mt($select2{$value})."</option>\n";
1.36      matthew   677:     }
                    678:     $result .= "</select>\n";
                    679:     #    return $debug;
                    680:     return $result;
                    681: }   #  end of sub linked_select_forms {
                    682: 
1.45      matthew   683: =pod
1.44      bowersj2  684: 
1.112     bowersj2  685: =item * help_open_topic($topic, $text, $stayOnPage, $width, $height)
1.44      bowersj2  686: 
1.112     bowersj2  687: Returns a string corresponding to an HTML link to the given help
                    688: $topic, where $topic corresponds to the name of a .tex file in
                    689: /home/httpd/html/adm/help/tex, with underscores replaced by
                    690: spaces. 
                    691: 
                    692: $text will optionally be linked to the same topic, allowing you to
                    693: link text in addition to the graphic. If you do not want to link
                    694: text, but wish to specify one of the later parameters, pass an
                    695: empty string. 
                    696: 
                    697: $stayOnPage is a value that will be interpreted as a boolean. If true,
                    698: the link will not open a new window. If false, the link will open
                    699: a new window using Javascript. (Default is false.) 
                    700: 
                    701: $width and $height are optional numerical parameters that will
                    702: override the width and height of the popped up window, which may
                    703: be useful for certain help topics with big pictures included. 
1.44      bowersj2  704: 
                    705: =cut
                    706: 
                    707: sub help_open_topic {
1.48      bowersj2  708:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
                    709:     $text = "" if (not defined $text);
1.44      bowersj2  710:     $stayOnPage = 0 if (not defined $stayOnPage);
1.258     albertel  711:     if ($env{'browser.interface'} eq 'textual' ||
                    712: 	$env{'environment.remote'} eq 'off' ) {
1.79      www       713: 	$stayOnPage=1;
                    714:     }
1.44      bowersj2  715:     $width = 350 if (not defined $width);
                    716:     $height = 400 if (not defined $height);
                    717:     my $filename = $topic;
                    718:     $filename =~ s/ /_/g;
                    719: 
1.48      bowersj2  720:     my $template = "";
                    721:     my $link;
1.159     www       722: 
                    723:     $topic=~s/\W/\_/g;
1.44      bowersj2  724: 
                    725:     if (!$stayOnPage)
                    726:     {
1.72      bowersj2  727: 	$link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1.44      bowersj2  728:     }
                    729:     else
                    730:     {
1.48      bowersj2  731: 	$link = "/adm/help/${filename}.hlp";
                    732:     }
                    733: 
                    734:     # Add the text
                    735:     if ($text ne "")
                    736:     {
1.77      www       737: 	$template .= 
                    738:   "<table bgcolor='#3333AA' cellspacing='1' cellpadding='1' border='0'><tr>".
1.436     albertel  739:   "<td bgcolor='#5555FF'><a target=\"_top\" href=\"$link\"><font color='#FFFFFF' size='2'>$text</font></a>";
1.48      bowersj2  740:     }
                    741: 
                    742:     # Add the graphic
1.179     matthew   743:     my $title = &mt('Online Help');
1.215     albertel  744:     my $helpicon=&lonhttpdurl("/adm/help/gif/smallHelp.gif");
1.48      bowersj2  745:     $template .= <<"ENDTEMPLATE";
1.436     albertel  746:  <a target="_top" href="$link" title="$title"><img src="$helpicon" border="0" alt="(Help: $topic)" /></a>
1.44      bowersj2  747: ENDTEMPLATE
1.78      www       748:     if ($text ne '') { $template.='</td></tr></table>' };
1.44      bowersj2  749:     return $template;
                    750: 
1.106     bowersj2  751: }
                    752: 
                    753: # This is a quicky function for Latex cheatsheet editing, since it 
                    754: # appears in at least four places
                    755: sub helpLatexCheatsheet {
                    756:     my $other = shift;
                    757:     my $addOther = '';
                    758:     if ($other) {
                    759: 	$addOther = Apache::loncommon::help_open_topic($other, shift,
                    760: 						       undef, undef, 600) .
                    761: 							   '</td><td>';
                    762:     }
                    763:     return '<table><tr><td>'.
                    764: 	$addOther .
                    765: 	&Apache::loncommon::help_open_topic("Greek_Symbols",'Greek Symbols',
                    766: 					    undef,undef,600)
                    767: 	.'</td><td>'.
                    768: 	&Apache::loncommon::help_open_topic("Other_Symbols",'Other Symbols',
                    769: 					    undef,undef,600)
                    770: 	.'</td></tr></table>';
1.172     www       771: }
                    772: 
1.430     albertel  773: sub general_help {
                    774:     my $helptopic='Student_Intro';
                    775:     if ($env{'request.role'}=~/^(ca|au)/) {
                    776: 	$helptopic='Authoring_Intro';
                    777:     } elsif ($env{'request.role'}=~/^cc/) {
                    778: 	$helptopic='Course_Coordination_Intro';
                    779:     }
                    780:     return $helptopic;
                    781: }
                    782: 
                    783: sub update_help_link {
                    784:     my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
                    785:     my $origurl = $ENV{'REQUEST_URI'};
                    786:     $origurl=~s|^/~|/priv/|;
                    787:     my $timestamp = time;
                    788:     foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
                    789:         $$datum = &escape($$datum);
                    790:     }
                    791: 
                    792:     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";
                    793:     my $output .= <<"ENDOUTPUT";
                    794: <script type="text/javascript">
                    795: banner_link = '$banner_link';
                    796: </script>
                    797: ENDOUTPUT
                    798:     return $output;
                    799: }
                    800: 
                    801: # now just updates the help link and generates a blue icon
1.193     raeburn   802: sub help_open_menu {
1.430     albertel  803:     my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text) 
                    804: 	= @_;
                    805:     
                    806:     $stayOnPage = 0 if (not defined $stayOnPage);
                    807:     if ($env{'browser.interface'} eq 'textual' ||
                    808: 	$env{'environment.remote'} eq 'off' ) {
                    809: 	$stayOnPage=1;
                    810:     }
                    811:     my $output;
                    812:     if ($component_help) {
                    813: 	if (!$text) {
                    814: 	    $output=&help_open_topic($component_help,undef,$stayOnPage,
                    815: 				       $width,$height);
                    816: 	} else {
                    817: 	    my $help_text;
                    818: 	    $help_text=&unescape($topic);
                    819: 	    $output='<table><tr><td>'.
                    820: 		&help_open_topic($component_help,$help_text,$stayOnPage,
                    821: 				 $width,$height).'</td></tr></table>';
                    822: 	}
                    823:     }
                    824:     my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
                    825:     return $output.$banner_link;
                    826: }
                    827: 
                    828: sub top_nav_help {
                    829:     my ($text) = @_;
                    830: 
1.436     albertel  831:     $text = &mt($text);
                    832: 
                    833:     my $stayOnPage = 
                    834: 	($env{'browser.interface'}  eq 'textual' ||
                    835: 	 $env{'environment.remote'} eq 'off' );
                    836:     my $link=  ($stayOnPage) ? "javascript:helpMenu('display')"
                    837: 	                     : "javascript:helpMenu('open')";
                    838:     my $banner_link = &update_help_link(undef,undef,undef,undef,$stayOnPage);
                    839: 
1.201     raeburn   840:     my $title = &mt('Get help');
1.436     albertel  841: 
                    842:     return <<"END";
                    843: $banner_link
                    844:  <a href="$link" title="$title">$text</a>
                    845: END
                    846: }
                    847: 
                    848: sub help_menu_js {
                    849:     my ($text) = @_;
                    850: 
                    851:     my $stayOnPage = 
                    852: 	($env{'browser.interface'}  eq 'textual' ||
                    853: 	 $env{'environment.remote'} eq 'off' );
                    854: 
                    855:     my $width = 620;
                    856:     my $height = 600;
1.430     albertel  857:     my $helptopic=&general_help();
                    858:     my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261     albertel  859:     my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331     albertel  860:     my $start_page =
                    861:         &Apache::loncommon::start_page('Help Menu', undef,
                    862: 				       {'frameset'    => 1,
                    863: 					'js_ready'    => 1,
                    864: 					'add_entries' => {
                    865: 					    'border' => '0',
                    866: 					    'rows'   => "105,*",},});
                    867:     my $end_page =
                    868:         &Apache::loncommon::end_page({'frameset' => 1,
                    869: 				      'js_ready' => 1,});
                    870: 
1.436     albertel  871:     my $template .= <<"ENDTEMPLATE";
                    872: <script type="text/javascript">
1.253     albertel  873: // <!-- BEGIN LON-CAPA Internal
                    874: // <![CDATA[
1.430     albertel  875: var banner_link = '';
1.243     raeburn   876: function helpMenu(target) {
                    877:     var caller = this;
                    878:     if (target == 'open') {
                    879:         var newWindow = null;
                    880:         try {
1.262     albertel  881:             newWindow =  window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243     raeburn   882:         }
                    883:         catch(error) {
                    884:             writeHelp(caller);
                    885:             return;
                    886:         }
                    887:         if (newWindow) {
                    888:             caller = newWindow;
                    889:         }
1.193     raeburn   890:     }
1.243     raeburn   891:     writeHelp(caller);
                    892:     return;
                    893: }
                    894: function writeHelp(caller) {
1.430     albertel  895:     caller.document.writeln('$start_page<frame name="bannerframe"  src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243     raeburn   896:     caller.document.close()
                    897:     caller.focus()
1.193     raeburn   898: }
1.253     albertel  899: // ]]>
1.219     albertel  900: // END LON-CAPA Internal -->
1.436     albertel  901: </script>
1.193     raeburn   902: ENDTEMPLATE
                    903:     return $template;
                    904: }
                    905: 
1.172     www       906: sub help_open_bug {
                    907:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258     albertel  908:     unless ($env{'user.adv'}) { return ''; }
1.172     www       909:     unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
                    910:     $text = "" if (not defined $text);
                    911:     $stayOnPage = 0 if (not defined $stayOnPage);
1.258     albertel  912:     if ($env{'browser.interface'} eq 'textual' ||
                    913: 	$env{'environment.remote'} eq 'off' ) {
1.172     www       914: 	$stayOnPage=1;
                    915:     }
1.184     albertel  916:     $width = 600 if (not defined $width);
                    917:     $height = 600 if (not defined $height);
1.172     www       918: 
                    919:     $topic=~s/\W+/\+/g;
                    920:     my $link='';
                    921:     my $template='';
1.379     albertel  922:     my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&amp;bug_file_loc='.
                    923: 	&escape($ENV{'REQUEST_URI'}).'&amp;component='.$topic;
1.172     www       924:     if (!$stayOnPage)
                    925:     {
                    926: 	$link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
                    927:     }
                    928:     else
                    929:     {
                    930: 	$link = $url;
                    931:     }
                    932:     # Add the text
                    933:     if ($text ne "")
                    934:     {
                    935: 	$template .= 
                    936:   "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.436     albertel  937:   "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><font color='#FFFFFF' size='2'>$text</font></a>";
1.172     www       938:     }
                    939: 
                    940:     # Add the graphic
1.179     matthew   941:     my $title = &mt('Report a Bug');
1.215     albertel  942:     my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172     www       943:     $template .= <<"ENDTEMPLATE";
1.436     albertel  944:  <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172     www       945: ENDTEMPLATE
                    946:     if ($text ne '') { $template.='</td></tr></table>' };
                    947:     return $template;
                    948: 
                    949: }
                    950: 
                    951: sub help_open_faq {
                    952:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258     albertel  953:     unless ($env{'user.adv'}) { return ''; }
1.172     www       954:     unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
                    955:     $text = "" if (not defined $text);
                    956:     $stayOnPage = 0 if (not defined $stayOnPage);
1.258     albertel  957:     if ($env{'browser.interface'} eq 'textual' ||
                    958: 	$env{'environment.remote'} eq 'off' ) {
1.172     www       959: 	$stayOnPage=1;
                    960:     }
                    961:     $width = 350 if (not defined $width);
                    962:     $height = 400 if (not defined $height);
                    963: 
                    964:     $topic=~s/\W+/\+/g;
                    965:     my $link='';
                    966:     my $template='';
                    967:     my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
                    968:     if (!$stayOnPage)
                    969:     {
                    970: 	$link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
                    971:     }
                    972:     else
                    973:     {
                    974: 	$link = $url;
                    975:     }
                    976: 
                    977:     # Add the text
                    978:     if ($text ne "")
                    979:     {
                    980: 	$template .= 
1.173     www       981:   "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.436     albertel  982:   "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><font color='#FFFFFF' size='2'>$text</font></a>";
1.172     www       983:     }
                    984: 
                    985:     # Add the graphic
1.179     matthew   986:     my $title = &mt('View the FAQ');
1.215     albertel  987:     my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172     www       988:     $template .= <<"ENDTEMPLATE";
1.436     albertel  989:  <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172     www       990: ENDTEMPLATE
                    991:     if ($text ne '') { $template.='</td></tr></table>' };
                    992:     return $template;
                    993: 
1.44      bowersj2  994: }
1.37      matthew   995: 
1.180     matthew   996: ###############################################################
                    997: ###############################################################
                    998: 
1.45      matthew   999: =pod
                   1000: 
1.256     matthew  1001: =item * change_content_javascript():
                   1002: 
                   1003: This and the next function allow you to create small sections of an
                   1004: otherwise static HTML page that you can update on the fly with
                   1005: Javascript, even in Netscape 4.
                   1006: 
                   1007: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
                   1008: must be written to the HTML page once. It will prove the Javascript
                   1009: function "change(name, content)". Calling the change function with the
                   1010: name of the section 
                   1011: you want to update, matching the name passed to C<changable_area>, and
                   1012: the new content you want to put in there, will put the content into
                   1013: that area.
                   1014: 
                   1015: B<Note>: Netscape 4 only reserves enough space for the changable area
                   1016: to contain room for the original contents. You need to "make space"
                   1017: for whatever changes you wish to make, and be B<sure> to check your
                   1018: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
                   1019: it's adequate for updating a one-line status display, but little more.
                   1020: This script will set the space to 100% width, so you only need to
                   1021: worry about height in Netscape 4.
                   1022: 
                   1023: Modern browsers are much less limiting, and if you can commit to the
                   1024: user not using Netscape 4, this feature may be used freely with
                   1025: pretty much any HTML.
                   1026: 
                   1027: =cut
                   1028: 
                   1029: sub change_content_javascript {
                   1030:     # If we're on Netscape 4, we need to use Layer-based code
1.258     albertel 1031:     if ($env{'browser.type'} eq 'netscape' &&
                   1032: 	$env{'browser.version'} =~ /^4\./) {
1.256     matthew  1033: 	return (<<NETSCAPE4);
                   1034: 	function change(name, content) {
                   1035: 	    doc = document.layers[name+"___escape"].layers[0].document;
                   1036: 	    doc.open();
                   1037: 	    doc.write(content);
                   1038: 	    doc.close();
                   1039: 	}
                   1040: NETSCAPE4
                   1041:     } else {
                   1042: 	# Otherwise, we need to use semi-standards-compliant code
                   1043: 	# (technically, "innerHTML" isn't standard but the equivalent
                   1044: 	# is really scary, and every useful browser supports it
                   1045: 	return (<<DOMBASED);
                   1046: 	function change(name, content) {
                   1047: 	    element = document.getElementById(name);
                   1048: 	    element.innerHTML = content;
                   1049: 	}
                   1050: DOMBASED
                   1051:     }
                   1052: }
                   1053: 
                   1054: =pod
                   1055: 
                   1056: =item * changable_area($name, $origContent):
                   1057: 
                   1058: This provides a "changable area" that can be modified on the fly via
                   1059: the Javascript code provided in C<change_content_javascript>. $name is
                   1060: the name you will use to reference the area later; do not repeat the
                   1061: same name on a given HTML page more then once. $origContent is what
                   1062: the area will originally contain, which can be left blank.
                   1063: 
                   1064: =cut
                   1065: 
                   1066: sub changable_area {
                   1067:     my ($name, $origContent) = @_;
                   1068: 
1.258     albertel 1069:     if ($env{'browser.type'} eq 'netscape' &&
                   1070: 	$env{'browser.version'} =~ /^4\./) {
1.256     matthew  1071: 	# If this is netscape 4, we need to use the Layer tag
                   1072: 	return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
                   1073:     } else {
                   1074: 	return "<span id='$name'>$origContent</span>";
                   1075:     }
                   1076: }
                   1077: 
                   1078: =pod
                   1079: 
                   1080: =back
                   1081: 
                   1082: =head1 Excel and CSV file utility routines
                   1083: 
                   1084: =over 4
                   1085: 
                   1086: =cut
                   1087: 
                   1088: ###############################################################
                   1089: ###############################################################
                   1090: 
                   1091: =pod
                   1092: 
1.112     bowersj2 1093: =item * csv_translate($text) 
1.37      matthew  1094: 
1.185     www      1095: Translate $text to allow it to be output as a 'comma separated values' 
1.37      matthew  1096: format.
                   1097: 
                   1098: =cut
                   1099: 
1.180     matthew  1100: ###############################################################
                   1101: ###############################################################
1.37      matthew  1102: sub csv_translate {
                   1103:     my $text = shift;
                   1104:     $text =~ s/\"/\"\"/g;
1.209     albertel 1105:     $text =~ s/\n/ /g;
1.37      matthew  1106:     return $text;
                   1107: }
1.180     matthew  1108: 
                   1109: ###############################################################
                   1110: ###############################################################
                   1111: 
                   1112: =pod
                   1113: 
                   1114: =item * define_excel_formats
                   1115: 
                   1116: Define some commonly used Excel cell formats.
                   1117: 
                   1118: Currently supported formats:
                   1119: 
                   1120: =over 4
                   1121: 
                   1122: =item header
                   1123: 
                   1124: =item bold
                   1125: 
                   1126: =item h1
                   1127: 
                   1128: =item h2
                   1129: 
                   1130: =item h3
                   1131: 
1.256     matthew  1132: =item h4
                   1133: 
                   1134: =item i
                   1135: 
1.180     matthew  1136: =item date
                   1137: 
                   1138: =back
                   1139: 
                   1140: Inputs: $workbook
                   1141: 
                   1142: Returns: $format, a hash reference.
                   1143: 
                   1144: =cut
                   1145: 
                   1146: ###############################################################
                   1147: ###############################################################
                   1148: sub define_excel_formats {
                   1149:     my ($workbook) = @_;
                   1150:     my $format;
                   1151:     $format->{'header'} = $workbook->add_format(bold      => 1, 
                   1152:                                                 bottom    => 1,
                   1153:                                                 align     => 'center');
                   1154:     $format->{'bold'} = $workbook->add_format(bold=>1);
                   1155:     $format->{'h1'}   = $workbook->add_format(bold=>1, size=>18);
                   1156:     $format->{'h2'}   = $workbook->add_format(bold=>1, size=>16);
                   1157:     $format->{'h3'}   = $workbook->add_format(bold=>1, size=>14);
1.255     matthew  1158:     $format->{'h4'}   = $workbook->add_format(bold=>1, size=>12);
1.246     matthew  1159:     $format->{'i'}    = $workbook->add_format(italic=>1);
1.180     matthew  1160:     $format->{'date'} = $workbook->add_format(num_format=>
1.207     matthew  1161:                                             'mm/dd/yyyy hh:mm:ss');
1.180     matthew  1162:     return $format;
                   1163: }
                   1164: 
                   1165: ###############################################################
                   1166: ###############################################################
1.113     bowersj2 1167: 
                   1168: =pod
                   1169: 
1.256     matthew  1170: =item * create_workbook
1.255     matthew  1171: 
                   1172: Create an Excel worksheet.  If it fails, output message on the
                   1173: request object and return undefs.
                   1174: 
                   1175: Inputs: Apache request object
                   1176: 
                   1177: Returns (undef) on failure, 
                   1178:     Excel worksheet object, scalar with filename, and formats 
                   1179:     from &Apache::loncommon::define_excel_formats on success
                   1180: 
                   1181: =cut
                   1182: 
                   1183: ###############################################################
                   1184: ###############################################################
                   1185: sub create_workbook {
                   1186:     my ($r) = @_;
                   1187:         #
                   1188:     # Create the excel spreadsheet
                   1189:     my $filename = '/prtspool/'.
1.258     albertel 1190:         $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255     matthew  1191:         time.'_'.rand(1000000000).'.xls';
                   1192:     my $workbook  = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
                   1193:     if (! defined($workbook)) {
                   1194:         $r->log_error("Error creating excel spreadsheet $filename: $!");
                   1195:         $r->print('<p>'.&mt("Unable to create new Excel file.  ".
                   1196:                             "This error has been logged.  ".
                   1197:                             "Please alert your LON-CAPA administrator").
                   1198:                   '</p>');
                   1199:         return (undef);
                   1200:     }
                   1201:     #
                   1202:     $workbook->set_tempdir('/home/httpd/perl/tmp');
                   1203:     #
                   1204:     my $format = &Apache::loncommon::define_excel_formats($workbook);
                   1205:     return ($workbook,$filename,$format);
                   1206: }
                   1207: 
                   1208: ###############################################################
                   1209: ###############################################################
                   1210: 
                   1211: =pod
                   1212: 
1.256     matthew  1213: =item * create_text_file
1.113     bowersj2 1214: 
1.256     matthew  1215: Create a file to write to and eventually make available to the usre.
                   1216: If file creation fails, outputs an error message on the request object and 
                   1217: return undefs.
1.113     bowersj2 1218: 
1.256     matthew  1219: Inputs: Apache request object, and file suffix
1.113     bowersj2 1220: 
1.256     matthew  1221: Returns (undef) on failure, 
                   1222:     Filehandle and filename on success.
1.113     bowersj2 1223: 
                   1224: =cut
                   1225: 
1.256     matthew  1226: ###############################################################
                   1227: ###############################################################
                   1228: sub create_text_file {
                   1229:     my ($r,$suffix) = @_;
                   1230:     if (! defined($suffix)) { $suffix = 'txt'; };
                   1231:     my $fh;
                   1232:     my $filename = '/prtspool/'.
1.258     albertel 1233:         $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256     matthew  1234:         time.'_'.rand(1000000000).'.'.$suffix;
                   1235:     $fh = Apache::File->new('>/home/httpd'.$filename);
                   1236:     if (! defined($fh)) {
                   1237:         $r->log_error("Couldn't open $filename for output $!");
                   1238:         $r->print("Problems occured in creating the output file.  ".
                   1239:                   "This error has been logged.  ".
                   1240:                   "Please alert your LON-CAPA administrator.");
1.113     bowersj2 1241:     }
1.256     matthew  1242:     return ($fh,$filename)
1.113     bowersj2 1243: }
                   1244: 
                   1245: 
1.256     matthew  1246: =pod 
1.113     bowersj2 1247: 
                   1248: =back
                   1249: 
                   1250: =cut
1.37      matthew  1251: 
                   1252: ###############################################################
1.33      matthew  1253: ##        Home server <option> list generating code          ##
                   1254: ###############################################################
1.35      matthew  1255: 
1.169     www      1256: # ------------------------------------------
                   1257: 
                   1258: sub domain_select {
                   1259:     my ($name,$value,$multiple)=@_;
                   1260:     my %domains=map { 
1.514     albertel 1261: 	$_ => $_.' '. &Apache::lonnet::domain($_,'description') 
1.512     albertel 1262:     } &Apache::lonnet::all_domains();
1.169     www      1263:     if ($multiple) {
                   1264: 	$domains{''}=&mt('Any domain');
1.287     albertel 1265: 	return &multiple_select_form($name,$value,4,\%domains);
1.169     www      1266:     } else {
                   1267: 	return &select_form($name,$value,%domains);
                   1268:     }
                   1269: }
                   1270: 
1.282     albertel 1271: #-------------------------------------------
                   1272: 
                   1273: =pod
                   1274: 
1.287     albertel 1275: =item * multiple_select_form($name,$value,$size,$hash,$order)
1.282     albertel 1276: 
                   1277: Returns a string containing a <select> element int multiple mode
                   1278: 
                   1279: 
                   1280: Args:
                   1281:   $name - name of the <select> element
1.506     raeburn  1282:   $value - scalar or array ref of values that should already be selected
1.282     albertel 1283:   $size - number of rows long the select element is
1.283     albertel 1284:   $hash - the elements should be 'option' => 'shown text'
1.282     albertel 1285:           (shown text should already have been &mt())
1.506     raeburn  1286:   $order - (optional) array ref of the order to show the elements in
1.283     albertel 1287: 
1.282     albertel 1288: =cut
                   1289: 
                   1290: #-------------------------------------------
1.169     www      1291: sub multiple_select_form {
1.284     albertel 1292:     my ($name,$value,$size,$hash,$order)=@_;
1.169     www      1293:     my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
                   1294:     my $output='';
1.191     matthew  1295:     if (! defined($size)) {
                   1296:         $size = 4;
1.283     albertel 1297:         if (scalar(keys(%$hash))<4) {
                   1298:             $size = scalar(keys(%$hash));
1.191     matthew  1299:         }
                   1300:     }
1.169     www      1301:     $output.="\n<select name='$name' size='$size' multiple='1'>";
1.501     banghart 1302:     my @order;
1.506     raeburn  1303:     if (ref($order) eq 'ARRAY')  {
                   1304:         @order = @{$order};
                   1305:     } else {
                   1306:         @order = sort(keys(%$hash));
1.501     banghart 1307:     }
                   1308:     if (exists($$hash{'select_form_order'})) {
                   1309:         @order = @{$$hash{'select_form_order'}};
                   1310:     }
                   1311:         
1.284     albertel 1312:     foreach my $key (@order) {
1.356     albertel 1313:         $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284     albertel 1314:         $output.='selected="selected" ' if ($selected{$key});
                   1315:         $output.='>'.$hash->{$key}."</option>\n";
1.169     www      1316:     }
                   1317:     $output.="</select>\n";
                   1318:     return $output;
                   1319: }
                   1320: 
1.88      www      1321: #-------------------------------------------
                   1322: 
                   1323: =pod
                   1324: 
1.112     bowersj2 1325: =item * select_form($defdom,$name,%hash)
1.88      www      1326: 
                   1327: Returns a string containing a <select name='$name' size='1'> form to 
                   1328: allow a user to select options from a hash option_name => displayed text.  
                   1329: See lonrights.pm for an example invocation and use.
                   1330: 
                   1331: =cut
                   1332: 
                   1333: #-------------------------------------------
                   1334: sub select_form {
                   1335:     my ($def,$name,%hash) = @_;
                   1336:     my $selectform = "<select name=\"$name\" size=\"1\">\n";
1.128     albertel 1337:     my @keys;
                   1338:     if (exists($hash{'select_form_order'})) {
                   1339: 	@keys=@{$hash{'select_form_order'}};
                   1340:     } else {
                   1341: 	@keys=sort(keys(%hash));
                   1342:     }
1.356     albertel 1343:     foreach my $key (@keys) {
                   1344:         $selectform.=
                   1345: 	    '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
                   1346:             ($key eq $def ? 'selected="selected" ' : '').
                   1347:                 ">".&mt($hash{$key})."</option>\n";
1.88      www      1348:     }
                   1349:     $selectform.="</select>";
                   1350:     return $selectform;
                   1351: }
                   1352: 
1.475     www      1353: # For display filters
                   1354: 
                   1355: sub display_filter {
                   1356:     if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477     www      1357:     if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.475     www      1358:     return '<nobr><label>'.&mt('Records [_1]',
                   1359: 			       &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
                   1360: 							   (&mt('all'),10,20,50,100,1000,10000))).
1.478     www      1361: 	   '</label></nobr> <nobr>'.
1.475     www      1362:            &mt('Filter [_1]',
1.477     www      1363: 	   &select_form($env{'form.displayfilter'},
                   1364: 			'displayfilter',
                   1365: 			('currentfolder' => 'Current folder/page',
                   1366: 			 'containing' => 'Containing phrase',
                   1367: 			 'none' => 'None'))).
1.478     www      1368: 			 '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></nobr>';
1.475     www      1369: }
                   1370: 
1.167     www      1371: sub gradeleveldescription {
                   1372:     my $gradelevel=shift;
                   1373:     my %gradelevels=(0 => 'Not specified',
                   1374: 		     1 => 'Grade 1',
                   1375: 		     2 => 'Grade 2',
                   1376: 		     3 => 'Grade 3',
                   1377: 		     4 => 'Grade 4',
                   1378: 		     5 => 'Grade 5',
                   1379: 		     6 => 'Grade 6',
                   1380: 		     7 => 'Grade 7',
                   1381: 		     8 => 'Grade 8',
                   1382: 		     9 => 'Grade 9',
                   1383: 		     10 => 'Grade 10',
                   1384: 		     11 => 'Grade 11',
                   1385: 		     12 => 'Grade 12',
                   1386: 		     13 => 'Grade 13',
                   1387: 		     14 => '100 Level',
                   1388: 		     15 => '200 Level',
                   1389: 		     16 => '300 Level',
                   1390: 		     17 => '400 Level',
                   1391: 		     18 => 'Graduate Level');
                   1392:     return &mt($gradelevels{$gradelevel});
                   1393: }
                   1394: 
1.163     www      1395: sub select_level_form {
                   1396:     my ($deflevel,$name)=@_;
                   1397:     unless ($deflevel) { $deflevel=0; }
1.167     www      1398:     my $selectform = "<select name=\"$name\" size=\"1\">\n";
                   1399:     for (my $i=0; $i<=18; $i++) {
                   1400:         $selectform.="<option value=\"$i\" ".
1.253     albertel 1401:             ($i==$deflevel ? 'selected="selected" ' : '').
1.167     www      1402:                 ">".&gradeleveldescription($i)."</option>\n";
                   1403:     }
                   1404:     $selectform.="</select>";
                   1405:     return $selectform;
1.163     www      1406: }
1.167     www      1407: 
1.35      matthew  1408: #-------------------------------------------
                   1409: 
1.45      matthew  1410: =pod
                   1411: 
1.112     bowersj2 1412: =item * select_dom_form($defdom,$name,$includeempty)
1.35      matthew  1413: 
                   1414: Returns a string containing a <select name='$name' size='1'> form to 
                   1415: allow a user to select the domain to preform an operation in.  
                   1416: See loncreateuser.pm for an example invocation and use.
                   1417: 
1.90      www      1418: If the $includeempty flag is set, it also includes an empty choice ("no domain
                   1419: selected");
                   1420: 
1.35      matthew  1421: =cut
                   1422: 
                   1423: #-------------------------------------------
1.34      matthew  1424: sub select_dom_form {
1.90      www      1425:     my ($defdom,$name,$includeempty) = @_;
1.516     albertel 1426:     my @domains = sort(&Apache::lonnet::all_domains());
1.90      www      1427:     if ($includeempty) { @domains=('',@domains); }
1.34      matthew  1428:     my $selectdomain = "<select name=\"$name\" size=\"1\">\n";
1.356     albertel 1429:     foreach my $dom (@domains) {
                   1430:         $selectdomain.="<option value=\"$dom\" ".
                   1431:             ($dom eq $defdom ? 'selected="selected" ' : '').
                   1432:                 ">$dom</option>\n";
1.34      matthew  1433:     }
                   1434:     $selectdomain.="</select>";
                   1435:     return $selectdomain;
                   1436: }
                   1437: 
1.35      matthew  1438: #-------------------------------------------
                   1439: 
1.45      matthew  1440: =pod
                   1441: 
1.112     bowersj2 1442: =item * home_server_option_list($domain)
1.35      matthew  1443: 
                   1444: returns a string which contains an <option> list to be used in a 
                   1445: <select> form input.  See loncreateuser.pm for an example.
                   1446: 
                   1447: =cut
                   1448: 
                   1449: #-------------------------------------------
1.33      matthew  1450: sub home_server_option_list {
                   1451:     my $domain = shift;
1.513     albertel 1452:     my %servers = &Apache::lonnet::get_servers($domain,'library');
1.33      matthew  1453:     my $result = '';
1.356     albertel 1454:     foreach my $hostid (sort(keys(%servers))) {
1.33      matthew  1455:         $result.=
1.356     albertel 1456:             '<option value="'.$hostid.'">'.
                   1457: 	    $hostid.' '.$servers{$hostid}."</option>\n";
1.33      matthew  1458:     }
                   1459:     return $result;
                   1460: }
1.112     bowersj2 1461: 
                   1462: =pod
                   1463: 
                   1464: =back
                   1465: 
                   1466: =cut
1.87      matthew  1467: 
                   1468: ###############################################################
1.112     bowersj2 1469: ##                  Decoding User Agent                      ##
1.87      matthew  1470: ###############################################################
                   1471: 
                   1472: =pod
                   1473: 
1.112     bowersj2 1474: =head1 Decoding the User Agent
                   1475: 
                   1476: =over 4
                   1477: 
                   1478: =item * &decode_user_agent()
1.87      matthew  1479: 
                   1480: Inputs: $r
                   1481: 
                   1482: Outputs:
                   1483: 
                   1484: =over 4
                   1485: 
1.112     bowersj2 1486: =item * $httpbrowser
1.87      matthew  1487: 
1.112     bowersj2 1488: =item * $clientbrowser
1.87      matthew  1489: 
1.112     bowersj2 1490: =item * $clientversion
1.87      matthew  1491: 
1.112     bowersj2 1492: =item * $clientmathml
1.87      matthew  1493: 
1.112     bowersj2 1494: =item * $clientunicode
1.87      matthew  1495: 
1.112     bowersj2 1496: =item * $clientos
1.87      matthew  1497: 
                   1498: =back
                   1499: 
1.157     matthew  1500: =back 
                   1501: 
1.87      matthew  1502: =cut
                   1503: 
                   1504: ###############################################################
                   1505: ###############################################################
                   1506: sub decode_user_agent {
1.247     albertel 1507:     my ($r)=@_;
1.87      matthew  1508:     my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
                   1509:     my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
                   1510:     my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247     albertel 1511:     if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87      matthew  1512:     my $clientbrowser='unknown';
                   1513:     my $clientversion='0';
                   1514:     my $clientmathml='';
                   1515:     my $clientunicode='0';
                   1516:     for (my $i=0;$i<=$#browsertype;$i++) {
                   1517:         my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
                   1518: 	if (($httpbrowser=~/$match/i)  && ($httpbrowser!~/$notmatch/i)) {
                   1519: 	    $clientbrowser=$bname;
                   1520:             $httpbrowser=~/$vreg/i;
                   1521: 	    $clientversion=$1;
                   1522:             $clientmathml=($clientversion>=$minv);
                   1523:             $clientunicode=($clientversion>=$univ);
                   1524: 	}
                   1525:     }
                   1526:     my $clientos='unknown';
                   1527:     if (($httpbrowser=~/linux/i) ||
                   1528:         ($httpbrowser=~/unix/i) ||
                   1529:         ($httpbrowser=~/ux/i) ||
                   1530:         ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
                   1531:     if (($httpbrowser=~/vax/i) ||
                   1532:         ($httpbrowser=~/vms/i)) { $clientos='vms'; }
                   1533:     if ($httpbrowser=~/next/i) { $clientos='next'; }
                   1534:     if (($httpbrowser=~/mac/i) ||
                   1535:         ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
                   1536:     if ($httpbrowser=~/win/i) { $clientos='win'; }
                   1537:     if ($httpbrowser=~/embed/i) { $clientos='pda'; }
                   1538:     return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
                   1539:             $clientunicode,$clientos,);
                   1540: }
                   1541: 
1.32      matthew  1542: ###############################################################
                   1543: ##    Authentication changing form generation subroutines    ##
                   1544: ###############################################################
                   1545: ##
                   1546: ## All of the authform_xxxxxxx subroutines take their inputs in a
                   1547: ## hash, and have reasonable default values.
                   1548: ##
                   1549: ##    formname = the name given in the <form> tag.
1.35      matthew  1550: #-------------------------------------------
                   1551: 
1.45      matthew  1552: =pod
                   1553: 
1.112     bowersj2 1554: =head1 Authentication Routines
                   1555: 
                   1556: =over 4
                   1557: 
                   1558: =item * authform_xxxxxx
1.35      matthew  1559: 
                   1560: The authform_xxxxxx subroutines provide javascript and html forms which 
                   1561: handle some of the conveniences required for authentication forms.  
                   1562: This is not an optimal method, but it works.  
                   1563: 
                   1564: See loncreateuser.pm for invocation and use examples.
                   1565: 
                   1566: =over 4
                   1567: 
1.112     bowersj2 1568: =item * authform_header
1.35      matthew  1569: 
1.112     bowersj2 1570: =item * authform_authorwarning
1.35      matthew  1571: 
1.112     bowersj2 1572: =item * authform_nochange
1.35      matthew  1573: 
1.112     bowersj2 1574: =item * authform_kerberos
1.35      matthew  1575: 
1.112     bowersj2 1576: =item * authform_internal
1.35      matthew  1577: 
1.112     bowersj2 1578: =item * authform_filesystem
1.35      matthew  1579: 
                   1580: =back
                   1581: 
1.157     matthew  1582: =back 
                   1583: 
1.35      matthew  1584: =cut
                   1585: 
                   1586: #-------------------------------------------
1.32      matthew  1587: sub authform_header{  
                   1588:     my %in = (
                   1589:         formname => 'cu',
1.80      albertel 1590:         kerb_def_dom => '',
1.32      matthew  1591:         @_,
                   1592:     );
                   1593:     $in{'formname'} = 'document.' . $in{'formname'};
                   1594:     my $result='';
1.80      albertel 1595: 
                   1596: #---------------------------------------------- Code for upper case translation
                   1597:     my $Javascript_toUpperCase;
                   1598:     unless ($in{kerb_def_dom}) {
                   1599:         $Javascript_toUpperCase =<<"END";
                   1600:         switch (choice) {
                   1601:            case 'krb': currentform.elements[choicearg].value =
                   1602:                currentform.elements[choicearg].value.toUpperCase();
                   1603:                break;
                   1604:            default:
                   1605:         }
                   1606: END
                   1607:     } else {
                   1608:         $Javascript_toUpperCase = "";
                   1609:     }
                   1610: 
1.165     raeburn  1611:     my $radioval = "'nochange'";
1.174     matthew  1612:     if (exists($in{'curr_authtype'}) &&
                   1613:         defined($in{'curr_authtype'}) &&
                   1614:         $in{'curr_authtype'} ne '') {
                   1615:         $radioval = "'$in{'curr_authtype'}arg'";
                   1616:     }
1.165     raeburn  1617:     my $argfield = 'null';
                   1618:     if ( grep/^mode$/,(keys %in) ) {
                   1619:         if ($in{'mode'} eq 'modifycourse')  {
                   1620:             if ( grep/^curr_authtype$/,(keys %in) ) {
                   1621:                 $radioval = "'$in{'curr_authtype'}'";
                   1622:             }
                   1623:             if ( grep/^curr_autharg$/,(keys %in) ) {
                   1624:                 unless ($in{'curr_autharg'} eq '') {
                   1625:                     $argfield = "'$in{'curr_autharg'}'";
                   1626:                 }
                   1627:             }
                   1628:         }
                   1629:     }
                   1630: 
1.32      matthew  1631:     $result.=<<"END";
                   1632: var current = new Object();
1.165     raeburn  1633: current.radiovalue = $radioval;
                   1634: current.argfield = $argfield;
1.32      matthew  1635: 
                   1636: function changed_radio(choice,currentform) {
                   1637:     var choicearg = choice + 'arg';
                   1638:     // If a radio button in changed, we need to change the argfield
                   1639:     if (current.radiovalue != choice) {
                   1640:         current.radiovalue = choice;
                   1641:         if (current.argfield != null) {
                   1642:             currentform.elements[current.argfield].value = '';
                   1643:         }
                   1644:         if (choice == 'nochange') {
                   1645:             current.argfield = null;
                   1646:         } else {
                   1647:             current.argfield = choicearg;
                   1648:             switch(choice) {
                   1649:                 case 'krb': 
                   1650:                     currentform.elements[current.argfield].value = 
                   1651:                         "$in{'kerb_def_dom'}";
                   1652:                 break;
                   1653:               default:
                   1654:                 break;
                   1655:             }
                   1656:         }
                   1657:     }
                   1658:     return;
                   1659: }
1.22      www      1660: 
1.32      matthew  1661: function changed_text(choice,currentform) {
                   1662:     var choicearg = choice + 'arg';
                   1663:     if (currentform.elements[choicearg].value !='') {
1.80      albertel 1664:         $Javascript_toUpperCase
1.32      matthew  1665:         // clear old field
                   1666:         if ((current.argfield != choicearg) && (current.argfield != null)) {
                   1667:             currentform.elements[current.argfield].value = '';
                   1668:         }
                   1669:         current.argfield = choicearg;
                   1670:     }
                   1671:     set_auth_radio_buttons(choice,currentform);
                   1672:     return;
1.20      www      1673: }
1.32      matthew  1674: 
                   1675: function set_auth_radio_buttons(newvalue,currentform) {
                   1676:     var i=0;
                   1677:     while (i < currentform.login.length) {
                   1678:         if (currentform.login[i].value == newvalue) { break; }
                   1679:         i++;
                   1680:     }
                   1681:     if (i == currentform.login.length) {
                   1682:         return;
                   1683:     }
                   1684:     current.radiovalue = newvalue;
                   1685:     currentform.login[i].checked = true;
                   1686:     return;
                   1687: }
                   1688: END
                   1689:     return $result;
                   1690: }
                   1691: 
                   1692: sub authform_authorwarning{
                   1693:     my $result='';
1.144     matthew  1694:     $result='<i>'.
                   1695:         &mt('As a general rule, only authors or co-authors should be '.
                   1696:             'filesystem authenticated '.
                   1697:             '(which allows access to the server filesystem).')."</i>\n";
1.32      matthew  1698:     return $result;
                   1699: }
                   1700: 
                   1701: sub authform_nochange{  
                   1702:     my %in = (
                   1703:               formname => 'document.cu',
                   1704:               kerb_def_dom => 'MSU.EDU',
                   1705:               @_,
                   1706:           );
1.281     albertel 1707:     my $result = '<label>'.&mt('[_1] Do not change login data',
1.144     matthew  1708:                      '<input type="radio" name="login" value="nochange" '.
                   1709:                      'checked="checked" onclick="'.
1.281     albertel 1710:             "javascript:changed_radio('nochange',$in{'formname'});".'" />').
                   1711: 	    '</label>';
1.32      matthew  1712:     return $result;
                   1713: }
                   1714: 
                   1715: sub authform_kerberos{  
                   1716:     my %in = (
                   1717:               formname => 'document.cu',
                   1718:               kerb_def_dom => 'MSU.EDU',
1.80      albertel 1719:               kerb_def_auth => 'krb4',
1.32      matthew  1720:               @_,
                   1721:               );
1.165     raeburn  1722:     my ($check4,$check5,$krbarg);
1.80      albertel 1723:     if ($in{'kerb_def_auth'} eq 'krb5') {
                   1724:        $check5 = " checked=\"on\"";
                   1725:     } else {
                   1726:        $check4 = " checked=\"on\"";
                   1727:     }
1.165     raeburn  1728:     $krbarg = $in{'kerb_def_dom'};
                   1729: 
                   1730:     my $krbcheck = "";
                   1731:     if ( grep/^curr_authtype$/,(keys %in) ) {
                   1732:         if ($in{'curr_authtype'} =~ m/^krb/) {
                   1733:             $krbcheck = " checked=\"on\"";
                   1734:             if ( grep/^curr_autharg$/,(keys %in) ) {
                   1735:                 $krbarg = $in{'curr_autharg'};
                   1736:             }
                   1737:         }
                   1738:     }
                   1739: 
1.144     matthew  1740:     my $jscall = "javascript:changed_radio('krb',$in{'formname'});";
                   1741:     my $result .= &mt
                   1742:         ('[_1] Kerberos authenticated with domain [_2] '.
1.281     albertel 1743:          '[_3] Version 4 [_4] Version 5 [_5]',
                   1744:          '<label><input type="radio" name="login" value="krb" '.
1.165     raeburn  1745:              'onclick="'.$jscall.'" onchange="'.$jscall.'"'.$krbcheck.' />',
1.281     albertel 1746:          '</label><input type="text" size="10" name="krbarg" '.
1.165     raeburn  1747:              'value="'.$krbarg.'" '.
1.144     matthew  1748:              'onchange="'.$jscall.'" />',
1.281     albertel 1749:          '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
                   1750:          '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
                   1751: 	 '</label>');
1.32      matthew  1752:     return $result;
                   1753: }
                   1754: 
                   1755: sub authform_internal{  
                   1756:     my %args = (
                   1757:                 formname => 'document.cu',
                   1758:                 kerb_def_dom => 'MSU.EDU',
                   1759:                 @_,
                   1760:                 );
1.165     raeburn  1761: 
                   1762:     my $intcheck = "";
                   1763:     my $intarg = 'value=""';
                   1764:     if ( grep/^curr_authtype$/,(keys %args) ) {
                   1765:         if ($args{'curr_authtype'} eq 'int') {
                   1766:             $intcheck = " checked=\"on\"";
                   1767:             if ( grep/^curr_autharg$/,(keys %args) ) {
                   1768:                 $intarg = "value=\"$args{'curr_autharg'}\"";
                   1769:             }
                   1770:         }
                   1771:     }
                   1772: 
1.144     matthew  1773:     my $jscall = "javascript:changed_radio('int',$args{'formname'});";
                   1774:     my $result.=&mt
                   1775:         ('[_1] Internally authenticated (with initial password [_2])',
1.281     albertel 1776:          '<label><input type="radio" name="login" value="int" '.$intcheck.
1.165     raeburn  1777:              ' onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.281     albertel 1778:          '</label><input type="text" size="10" name="intarg" '.$intarg.
1.165     raeburn  1779:              ' onchange="'.$jscall.'" />');
1.32      matthew  1780:     return $result;
                   1781: }
                   1782: 
                   1783: sub authform_local{  
                   1784:     my %in = (
                   1785:               formname => 'document.cu',
                   1786:               kerb_def_dom => 'MSU.EDU',
                   1787:               @_,
                   1788:               );
1.165     raeburn  1789: 
                   1790:     my $loccheck = "";
                   1791:     my $locarg = 'value=""';
                   1792:     if ( grep/^curr_authtype$/,(keys %in) ) {
                   1793:         if ($in{'curr_authtype'} eq 'loc') {
                   1794:             $loccheck = " checked=\"on\"";
                   1795:             if ( grep/^curr_autharg$/,(keys %in) ) {
                   1796:                 $locarg = "value=\"$in{'curr_autharg'}\"";
                   1797:             }
                   1798:         }
                   1799:     }
                   1800: 
1.144     matthew  1801:     my $jscall = "javascript:changed_radio('loc',$in{'formname'});";
1.160     matthew  1802:     my $result.=&mt('[_1] Local Authentication with argument [_2]',
1.281     albertel 1803:                     '<label><input type="radio" name="login" value="loc" '.$loccheck.
1.165     raeburn  1804:                         ' onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.281     albertel 1805:                     '</label><input type="text" size="10" name="locarg" '.$locarg.
1.165     raeburn  1806:                         ' onchange="'.$jscall.'" />');
1.32      matthew  1807:     return $result;
                   1808: }
                   1809: 
                   1810: sub authform_filesystem{  
                   1811:     my %in = (
                   1812:               formname => 'document.cu',
                   1813:               kerb_def_dom => 'MSU.EDU',
                   1814:               @_,
                   1815:               );
1.144     matthew  1816:     my $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
                   1817:     my $result.= &mt
                   1818:         ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281     albertel 1819:          '<label><input type="radio" name="login" value="fsys" '.
1.144     matthew  1820:          'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.281     albertel 1821:          '</label><input type="text" size="10" name="fsysarg" value="" '.
1.144     matthew  1822:                   'onchange="'.$jscall.'" />');
1.32      matthew  1823:     return $result;
                   1824: }
                   1825: 
1.80      albertel 1826: ###############################################################
                   1827: ##    Get Authentication Defaults for Domain                 ##
                   1828: ###############################################################
                   1829: 
                   1830: =pod
                   1831: 
1.112     bowersj2 1832: =head1 Domains and Authentication
                   1833: 
                   1834: Returns default authentication type and an associated argument as
                   1835: listed in file 'domain.tab'.
                   1836: 
                   1837: =over 4
                   1838: 
                   1839: =item * get_auth_defaults
1.80      albertel 1840: 
                   1841: get_auth_defaults($target_domain) returns the default authentication
                   1842: type and an associated argument (initial password or a kerberos domain).
                   1843: These values are stored in lonTabs/domain.tab
                   1844: 
                   1845: ($def_auth, $def_arg) = &get_auth_defaults($target_domain);
                   1846: 
                   1847: If target_domain is not found in domain.tab, returns nothing ('').
                   1848: 
                   1849: =cut
                   1850: 
                   1851: #-------------------------------------------
                   1852: sub get_auth_defaults {
                   1853:     my $domain=shift;
1.514     albertel 1854:     return (&Apache::lonnet::domain($domain,'auth_def'),
                   1855: 	    &Apache::lonnet::domain($domain,'auth_arg_def'));
                   1856: 	    
1.80      albertel 1857: }
                   1858: ###############################################################
                   1859: ##   End Get Authentication Defaults for Domain              ##
                   1860: ###############################################################
                   1861: 
                   1862: ###############################################################
                   1863: ##    Get Kerberos Defaults for Domain                 ##
                   1864: ###############################################################
                   1865: ##
                   1866: ## Returns default kerberos version and an associated argument
                   1867: ## as listed in file domain.tab. If not listed, provides
                   1868: ## appropriate default domain and kerberos version.
                   1869: ##
                   1870: #-------------------------------------------
                   1871: 
                   1872: =pod
                   1873: 
1.112     bowersj2 1874: =item * get_kerberos_defaults
1.80      albertel 1875: 
                   1876: get_kerberos_defaults($target_domain) returns the default kerberos
                   1877: version and domain. If not found in domain.tabs, it defaults to
                   1878: version 4 and the domain of the server.
                   1879: 
                   1880: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
                   1881: 
                   1882: =cut
                   1883: 
                   1884: #-------------------------------------------
                   1885: sub get_kerberos_defaults {
                   1886:     my $domain=shift;
                   1887:     my ($krbdef,$krbdefdom) =
                   1888:         &Apache::loncommon::get_auth_defaults($domain);
                   1889:     unless ($krbdef =~/^krb/ && $krbdefdom) {
                   1890:         $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
                   1891:         my $krbdefdom=$1;
                   1892:         $krbdefdom=~tr/a-z/A-Z/;
                   1893:         $krbdef = "krb4";
                   1894:     }
                   1895:     return ($krbdef,$krbdefdom);
                   1896: }
1.112     bowersj2 1897: 
                   1898: =pod
                   1899: 
                   1900: =back
                   1901: 
                   1902: =cut
1.32      matthew  1903: 
1.46      matthew  1904: ###############################################################
                   1905: ##                Thesaurus Functions                        ##
                   1906: ###############################################################
1.20      www      1907: 
1.46      matthew  1908: =pod
1.20      www      1909: 
1.112     bowersj2 1910: =head1 Thesaurus Functions
                   1911: 
                   1912: =over 4
                   1913: 
                   1914: =item * initialize_keywords
1.46      matthew  1915: 
                   1916: Initializes the package variable %Keywords if it is empty.  Uses the
                   1917: package variable $thesaurus_db_file.
                   1918: 
                   1919: =cut
                   1920: 
                   1921: ###################################################
                   1922: 
                   1923: sub initialize_keywords {
                   1924:     return 1 if (scalar keys(%Keywords));
                   1925:     # If we are here, %Keywords is empty, so fill it up
                   1926:     #   Make sure the file we need exists...
                   1927:     if (! -e $thesaurus_db_file) {
                   1928:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
                   1929:                                  " failed because it does not exist");
                   1930:         return 0;
                   1931:     }
                   1932:     #   Set up the hash as a database
                   1933:     my %thesaurus_db;
                   1934:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 1935:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  1936:         &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
                   1937:                                  $thesaurus_db_file);
                   1938:         return 0;
                   1939:     } 
                   1940:     #  Get the average number of appearances of a word.
                   1941:     my $avecount = $thesaurus_db{'average.count'};
                   1942:     #  Put keywords (those that appear > average) into %Keywords
                   1943:     while (my ($word,$data)=each (%thesaurus_db)) {
                   1944:         my ($count,undef) = split /:/,$data;
                   1945:         $Keywords{$word}++ if ($count > $avecount);
                   1946:     }
                   1947:     untie %thesaurus_db;
                   1948:     # Remove special values from %Keywords.
1.356     albertel 1949:     foreach my $value ('total.count','average.count') {
                   1950:         delete($Keywords{$value}) if (exists($Keywords{$value}));
1.46      matthew  1951:     }
                   1952:     return 1;
                   1953: }
                   1954: 
                   1955: ###################################################
                   1956: 
                   1957: =pod
                   1958: 
1.112     bowersj2 1959: =item * keyword($word)
1.46      matthew  1960: 
                   1961: Returns true if $word is a keyword.  A keyword is a word that appears more 
                   1962: than the average number of times in the thesaurus database.  Calls 
                   1963: &initialize_keywords
                   1964: 
                   1965: =cut
                   1966: 
                   1967: ###################################################
1.20      www      1968: 
                   1969: sub keyword {
1.46      matthew  1970:     return if (!&initialize_keywords());
                   1971:     my $word=lc(shift());
                   1972:     $word=~s/\W//g;
                   1973:     return exists($Keywords{$word});
1.20      www      1974: }
1.46      matthew  1975: 
                   1976: ###############################################################
                   1977: 
                   1978: =pod 
1.20      www      1979: 
1.112     bowersj2 1980: =item * get_related_words
1.46      matthew  1981: 
1.160     matthew  1982: Look up a word in the thesaurus.  Takes a scalar argument and returns
1.46      matthew  1983: an array of words.  If the keyword is not in the thesaurus, an empty array
                   1984: will be returned.  The order of the words returned is determined by the
                   1985: database which holds them.
                   1986: 
                   1987: Uses global $thesaurus_db_file.
                   1988: 
                   1989: =cut
                   1990: 
                   1991: ###############################################################
                   1992: sub get_related_words {
                   1993:     my $keyword = shift;
                   1994:     my %thesaurus_db;
                   1995:     if (! -e $thesaurus_db_file) {
                   1996:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
                   1997:                                  "failed because the file does not exist");
                   1998:         return ();
                   1999:     }
                   2000:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 2001:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  2002:         return ();
                   2003:     } 
                   2004:     my @Words=();
1.429     www      2005:     my $count=0;
1.46      matthew  2006:     if (exists($thesaurus_db{$keyword})) {
1.356     albertel 2007: 	# The first element is the number of times
                   2008: 	# the word appears.  We do not need it now.
1.429     www      2009: 	my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
                   2010: 	my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
                   2011: 	my $threshold=$mostfrequentcount/10;
                   2012:         foreach my $possibleword (@RelatedWords) {
                   2013:             my ($word,$wordcount)=split(/\,/,$possibleword);
                   2014:             if ($wordcount>$threshold) {
                   2015: 		push(@Words,$word);
                   2016:                 $count++;
                   2017:                 if ($count>10) { last; }
                   2018: 	    }
1.20      www      2019:         }
                   2020:     }
1.46      matthew  2021:     untie %thesaurus_db;
                   2022:     return @Words;
1.14      harris41 2023: }
1.46      matthew  2024: 
1.112     bowersj2 2025: =pod
                   2026: 
                   2027: =back
                   2028: 
                   2029: =cut
1.61      www      2030: 
                   2031: # -------------------------------------------------------------- Plaintext name
1.81      albertel 2032: =pod
                   2033: 
1.112     bowersj2 2034: =head1 User Name Functions
                   2035: 
                   2036: =over 4
                   2037: 
1.226     albertel 2038: =item * plainname($uname,$udom,$first)
1.81      albertel 2039: 
1.112     bowersj2 2040: Takes a users logon name and returns it as a string in
1.226     albertel 2041: "first middle last generation" form 
                   2042: if $first is set to 'lastname' then it returns it as
                   2043: 'lastname generation, firstname middlename' if their is a lastname
1.81      albertel 2044: 
                   2045: =cut
1.61      www      2046: 
1.295     www      2047: 
1.81      albertel 2048: ###############################################################
1.61      www      2049: sub plainname {
1.226     albertel 2050:     my ($uname,$udom,$first)=@_;
1.295     www      2051:     my %names=&getnames($uname,$udom);
1.226     albertel 2052:     my $name=&Apache::lonnet::format_name($names{'firstname'},
                   2053: 					  $names{'middlename'},
                   2054: 					  $names{'lastname'},
                   2055: 					  $names{'generation'},$first);
                   2056:     $name=~s/^\s+//;
1.62      www      2057:     $name=~s/\s+$//;
                   2058:     $name=~s/\s+/ /g;
1.353     albertel 2059:     if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62      www      2060:     return $name;
1.61      www      2061: }
1.66      www      2062: 
                   2063: # -------------------------------------------------------------------- Nickname
1.81      albertel 2064: =pod
                   2065: 
1.112     bowersj2 2066: =item * nickname($uname,$udom)
1.81      albertel 2067: 
                   2068: Gets a users name and returns it as a string as
                   2069: 
                   2070: "&quot;nickname&quot;"
1.66      www      2071: 
1.81      albertel 2072: if the user has a nickname or
                   2073: 
                   2074: "first middle last generation"
                   2075: 
                   2076: if the user does not
                   2077: 
                   2078: =cut
1.66      www      2079: 
                   2080: sub nickname {
                   2081:     my ($uname,$udom)=@_;
1.295     www      2082:     my %names=&getnames($uname,$udom);
1.68      albertel 2083:     my $name=$names{'nickname'};
1.66      www      2084:     if ($name) {
                   2085:        $name='&quot;'.$name.'&quot;'; 
                   2086:     } else {
                   2087:        $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
                   2088: 	     $names{'lastname'}.' '.$names{'generation'};
                   2089:        $name=~s/\s+$//;
                   2090:        $name=~s/\s+/ /g;
                   2091:     }
                   2092:     return $name;
                   2093: }
                   2094: 
1.295     www      2095: sub getnames {
                   2096:     my ($uname,$udom)=@_;
1.433     albertel 2097:     if ($udom eq 'public' && $uname eq 'public') {
                   2098: 	return ('lastname' => &mt('Public'));
                   2099:     }
1.295     www      2100:     my $id=$uname.':'.$udom;
                   2101:     my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
                   2102:     if ($cached) {
                   2103: 	return %{$names};
                   2104:     } else {
                   2105: 	my %loadnames=&Apache::lonnet::get('environment',
                   2106:                     ['firstname','middlename','lastname','generation','nickname'],
                   2107: 					 $udom,$uname);
                   2108: 	&Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
                   2109: 	return %loadnames;
                   2110:     }
                   2111: }
1.61      www      2112: 
1.466     albertel 2113: sub getemails {
                   2114:     my ($uname,$udom)=@_;
                   2115:     if ($udom eq 'public' && $uname eq 'public') {
                   2116: 	return;
                   2117:     }
1.467     www      2118:     if (!$udom) { $udom=$env{'user.domain'}; }
                   2119:     if (!$uname) { $uname=$env{'user.name'}; }
1.466     albertel 2120:     my $id=$uname.':'.$udom;
                   2121:     my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
                   2122:     if ($cached) {
                   2123: 	return %{$names};
                   2124:     } else {
                   2125: 	my %loadnames=&Apache::lonnet::get('environment',
                   2126:                     			   ['notification','critnotification',
                   2127: 					    'permanentemail'],
                   2128: 					   $udom,$uname);
                   2129: 	&Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
                   2130: 	return %loadnames;
                   2131:     }
                   2132: }
                   2133: 
1.61      www      2134: # ------------------------------------------------------------------ Screenname
1.81      albertel 2135: 
                   2136: =pod
                   2137: 
1.112     bowersj2 2138: =item * screenname($uname,$udom)
1.81      albertel 2139: 
                   2140: Gets a users screenname and returns it as a string
                   2141: 
                   2142: =cut
1.61      www      2143: 
                   2144: sub screenname {
                   2145:     my ($uname,$udom)=@_;
1.258     albertel 2146:     if ($uname eq $env{'user.name'} &&
                   2147: 	$udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212     albertel 2148:     my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68      albertel 2149:     return $names{'screenname'};
1.62      www      2150: }
                   2151: 
1.212     albertel 2152: 
1.62      www      2153: # ------------------------------------------------------------- Message Wrapper
                   2154: 
                   2155: sub messagewrapper {
1.369     www      2156:     my ($link,$username,$domain,$subject,$text)=@_;
1.62      www      2157:     return 
1.441     albertel 2158:         '<a href="/adm/email?compose=individual&amp;'.
                   2159:         'recname='.$username.'&amp;recdom='.$domain.
                   2160: 	'&amp;subject='.&escape($subject).'&amp;text='.&escape($text).'" '.
1.200     matthew  2161:         'title="'.&mt('Send message').'">'.$link.'</a>';
1.74      www      2162: }
                   2163: # --------------------------------------------------------------- Notes Wrapper
                   2164: 
                   2165: sub noteswrapper {
                   2166:     my ($link,$un,$do)=@_;
                   2167:     return 
                   2168: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62      www      2169: }
                   2170: # ------------------------------------------------------------- Aboutme Wrapper
                   2171: 
                   2172: sub aboutmewrapper {
1.166     www      2173:     my ($link,$username,$domain,$target)=@_;
1.447     raeburn  2174:     if (!defined($username)  && !defined($domain)) {
                   2175:         return;
                   2176:     }
1.205     www      2177:     return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.454     banghart 2178: 	($target?' target="$target"':'').' title="'.&mt("View this user's personal page").'">'.$link.'</a>';
1.62      www      2179: }
                   2180: 
                   2181: # ------------------------------------------------------------ Syllabus Wrapper
                   2182: 
                   2183: 
                   2184: sub syllabuswrapper {
1.109     matthew  2185:     my ($linktext,$coursedir,$domain,$fontcolor)=@_;
                   2186:     if ($fontcolor) { 
                   2187:         $linktext='<font color="'.$fontcolor.'">'.$linktext.'</font>'; 
                   2188:     }
1.208     matthew  2189:     return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61      www      2190: }
1.14      harris41 2191: 
1.208     matthew  2192: sub track_student_link {
1.268     albertel 2193:     my ($linktext,$sname,$sdom,$target,$start) = @_;
                   2194:     my $link ="/adm/trackstudent?";
1.208     matthew  2195:     my $title = 'View recent activity';
                   2196:     if (defined($sname) && $sname !~ /^\s*$/ &&
                   2197:         defined($sdom)  && $sdom  !~ /^\s*$/) {
1.268     albertel 2198:         $link .= "selected_student=$sname:$sdom";
1.208     matthew  2199:         $title .= ' of this student';
1.268     albertel 2200:     } 
1.208     matthew  2201:     if (defined($target) && $target !~ /^\s*$/) {
                   2202:         $target = qq{target="$target"};
                   2203:     } else {
                   2204:         $target = '';
                   2205:     }
1.268     albertel 2206:     if ($start) { $link.='&amp;start='.$start; }
1.448     albertel 2207:     
                   2208:     return qq{<a href="$link" title="$title" $target>$linktext</a>}.
                   2209: 	&help_open_topic('View_recent_activity');
1.208     matthew  2210: }
                   2211: 
1.508     www      2212: # ===================================================== Display a student photo
                   2213: 
                   2214: 
1.509     albertel 2215: sub student_image_tag {
1.508     www      2216:     my ($domain,$user)=@_;
                   2217:     my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
                   2218:     if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
                   2219: 	return '<img src="'.$imgsrc.'" align="right" />';
                   2220:     } else {
                   2221: 	return '';
                   2222:     }
                   2223: }
                   2224: 
1.112     bowersj2 2225: =pod
                   2226: 
                   2227: =back
                   2228: 
                   2229: =head1 Access .tab File Data
                   2230: 
                   2231: =over 4
                   2232: 
                   2233: =item * languageids() 
                   2234: 
                   2235: returns list of all language ids
                   2236: 
                   2237: =cut
                   2238: 
1.14      harris41 2239: sub languageids {
1.16      harris41 2240:     return sort(keys(%language));
1.14      harris41 2241: }
                   2242: 
1.112     bowersj2 2243: =pod
                   2244: 
                   2245: =item * languagedescription() 
                   2246: 
                   2247: returns description of a specified language id
                   2248: 
                   2249: =cut
                   2250: 
1.14      harris41 2251: sub languagedescription {
1.125     www      2252:     my $code=shift;
                   2253:     return  ($supported_language{$code}?'* ':'').
                   2254:             $language{$code}.
1.126     www      2255: 	    ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145     www      2256: }
                   2257: 
                   2258: sub plainlanguagedescription {
                   2259:     my $code=shift;
                   2260:     return $language{$code};
                   2261: }
                   2262: 
                   2263: sub supportedlanguagecode {
                   2264:     my $code=shift;
                   2265:     return $supported_language{$code};
1.97      www      2266: }
                   2267: 
1.112     bowersj2 2268: =pod
                   2269: 
                   2270: =item * copyrightids() 
                   2271: 
                   2272: returns list of all copyrights
                   2273: 
                   2274: =cut
                   2275: 
                   2276: sub copyrightids {
                   2277:     return sort(keys(%cprtag));
                   2278: }
                   2279: 
                   2280: =pod
                   2281: 
                   2282: =item * copyrightdescription() 
                   2283: 
                   2284: returns description of a specified copyright id
                   2285: 
                   2286: =cut
                   2287: 
                   2288: sub copyrightdescription {
1.166     www      2289:     return &mt($cprtag{shift(@_)});
1.112     bowersj2 2290: }
1.197     matthew  2291: 
                   2292: =pod
                   2293: 
1.192     taceyjo1 2294: =item * source_copyrightids() 
                   2295: 
                   2296: returns list of all source copyrights
                   2297: 
                   2298: =cut
                   2299: 
                   2300: sub source_copyrightids {
                   2301:     return sort(keys(%scprtag));
                   2302: }
                   2303: 
                   2304: =pod
                   2305: 
                   2306: =item * source_copyrightdescription() 
                   2307: 
                   2308: returns description of a specified source copyright id
                   2309: 
                   2310: =cut
                   2311: 
                   2312: sub source_copyrightdescription {
                   2313:     return &mt($scprtag{shift(@_)});
                   2314: }
1.112     bowersj2 2315: 
                   2316: =pod
                   2317: 
                   2318: =item * filecategories() 
                   2319: 
                   2320: returns list of all file categories
                   2321: 
                   2322: =cut
                   2323: 
                   2324: sub filecategories {
                   2325:     return sort(keys(%category_extensions));
                   2326: }
                   2327: 
                   2328: =pod
                   2329: 
                   2330: =item * filecategorytypes() 
                   2331: 
                   2332: returns list of file types belonging to a given file
                   2333: category
                   2334: 
                   2335: =cut
                   2336: 
                   2337: sub filecategorytypes {
1.356     albertel 2338:     my ($cat) = @_;
                   2339:     return @{$category_extensions{lc($cat)}};
1.112     bowersj2 2340: }
                   2341: 
                   2342: =pod
                   2343: 
                   2344: =item * fileembstyle() 
                   2345: 
                   2346: returns embedding style for a specified file type
                   2347: 
                   2348: =cut
                   2349: 
                   2350: sub fileembstyle {
                   2351:     return $fe{lc(shift(@_))};
1.169     www      2352: }
                   2353: 
1.351     www      2354: sub filemimetype {
                   2355:     return $fm{lc(shift(@_))};
                   2356: }
                   2357: 
1.169     www      2358: 
                   2359: sub filecategoryselect {
                   2360:     my ($name,$value)=@_;
1.189     matthew  2361:     return &select_form($value,$name,
1.169     www      2362: 			'' => &mt('Any category'),
                   2363: 			map { $_,$_ } sort(keys(%category_extensions)));
1.112     bowersj2 2364: }
                   2365: 
                   2366: =pod
                   2367: 
                   2368: =item * filedescription() 
                   2369: 
                   2370: returns description for a specified file type
                   2371: 
                   2372: =cut
                   2373: 
                   2374: sub filedescription {
1.188     matthew  2375:     my $file_description = $fd{lc(shift())};
                   2376:     $file_description =~ s:([\[\]]):~$1:g;
                   2377:     return &mt($file_description);
1.112     bowersj2 2378: }
                   2379: 
                   2380: =pod
                   2381: 
                   2382: =item * filedescriptionex() 
                   2383: 
                   2384: returns description for a specified file type with
                   2385: extra formatting
                   2386: 
                   2387: =cut
                   2388: 
                   2389: sub filedescriptionex {
                   2390:     my $ex=shift;
1.188     matthew  2391:     my $file_description = $fd{lc($ex)};
                   2392:     $file_description =~ s:([\[\]]):~$1:g;
                   2393:     return '.'.$ex.' '.&mt($file_description);
1.112     bowersj2 2394: }
                   2395: 
                   2396: # End of .tab access
                   2397: =pod
                   2398: 
                   2399: =back
                   2400: 
                   2401: =cut
                   2402: 
                   2403: # ------------------------------------------------------------------ File Types
                   2404: sub fileextensions {
                   2405:     return sort(keys(%fe));
                   2406: }
                   2407: 
1.97      www      2408: # ----------------------------------------------------------- Display Languages
                   2409: # returns a hash with all desired display languages
                   2410: #
                   2411: 
                   2412: sub display_languages {
                   2413:     my %languages=();
1.356     albertel 2414:     foreach my $lang (&preferred_languages()) {
                   2415: 	$languages{$lang}=1;
1.97      www      2416:     }
                   2417:     &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258     albertel 2418:     if ($env{'form.displaylanguage'}) {
1.356     albertel 2419: 	foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
                   2420: 	    $languages{$lang}=1;
1.97      www      2421:         }
                   2422:     }
                   2423:     return %languages;
1.14      harris41 2424: }
                   2425: 
1.117     www      2426: sub preferred_languages {
                   2427:     my @languages=();
1.258     albertel 2428:     if ($env{'course.'.$env{'request.course.id'}.'.languages'}) {
1.117     www      2429: 	@languages=(@languages,split(/\s*(\,|\;|\:)\s*/,
1.258     albertel 2430: 	         $env{'course.'.$env{'request.course.id'}.'.languages'}));
1.177     www      2431:     }
1.258     albertel 2432:     if ($env{'environment.languages'}) {
1.459     albertel 2433: 	@languages=(@languages,
                   2434: 		    split(/\s*(\,|\;|\:)\s*/,$env{'environment.languages'}));
1.118     www      2435:     }
1.162     www      2436:     my $browser=(split(/\;/,$ENV{'HTTP_ACCEPT_LANGUAGE'}))[0];
                   2437:     if ($browser) {
                   2438: 	@languages=(@languages,split(/\s*(\,|\;|\:)\s*/,$browser));
                   2439:     }
1.514     albertel 2440:     if (&Apache::lonnet::domain($env{'user.domain'},'lang_def')) {
1.118     www      2441: 	@languages=(@languages,
1.514     albertel 2442: 		    &Apache::lonnet::domain($env{'user.domain'},
                   2443: 					    'lang_def'));
1.118     www      2444:     }
1.514     albertel 2445:     if (&Apache::lonnet::domain($env{'request.role.domain'},'lang_def')) {
1.118     www      2446: 	@languages=(@languages,
1.514     albertel 2447: 		    &Apache::lonnet::domain($env{'request.role.domain'},
                   2448: 					    'lang_def'));
1.118     www      2449:     }
1.514     albertel 2450:     if (&Apache::lonnet::domain($Apache::lonnet::perlvar{'lonDefDomain'},
                   2451: 				'lang_def')) {
1.118     www      2452: 	@languages=(@languages,
1.514     albertel 2453: 		    &Apache::lonnet::domain($Apache::lonnet::perlvar{'lonDefDomain'},
                   2454: 					    'lang_def'));
1.118     www      2455:     }
                   2456: # turn "en-ca" into "en-ca,en"
                   2457:     my @genlanguages;
1.356     albertel 2458:     foreach my $lang (@languages) {
                   2459: 	unless ($lang=~/\w/) { next; }
                   2460: 	push (@genlanguages,$lang);
                   2461: 	if ($lang=~/(\-|\_)/) {
                   2462: 	    push(@genlanguages,(split(/(\-|\_)/,$lang))[0]);
1.118     www      2463: 	}
                   2464:     }
                   2465:     return @genlanguages;
1.117     www      2466: }
                   2467: 
1.112     bowersj2 2468: ###############################################################
                   2469: ##               Student Answer Attempts                     ##
                   2470: ###############################################################
                   2471: 
                   2472: =pod
                   2473: 
                   2474: =head1 Alternate Problem Views
                   2475: 
                   2476: =over 4
                   2477: 
                   2478: =item * get_previous_attempt($symb, $username, $domain, $course,
                   2479:     $getattempt, $regexp, $gradesub)
                   2480: 
                   2481: Return string with previous attempt on problem. Arguments:
                   2482: 
                   2483: =over 4
                   2484: 
                   2485: =item * $symb: Problem, including path
                   2486: 
                   2487: =item * $username: username of the desired student
                   2488: 
                   2489: =item * $domain: domain of the desired student
1.14      harris41 2490: 
1.112     bowersj2 2491: =item * $course: Course ID
1.14      harris41 2492: 
1.112     bowersj2 2493: =item * $getattempt: Leave blank for all attempts, otherwise put
                   2494:     something
1.14      harris41 2495: 
1.112     bowersj2 2496: =item * $regexp: if string matches this regexp, the string will be
                   2497:     sent to $gradesub
1.14      harris41 2498: 
1.112     bowersj2 2499: =item * $gradesub: routine that processes the string if it matches $regexp
1.14      harris41 2500: 
1.112     bowersj2 2501: =back
1.14      harris41 2502: 
1.112     bowersj2 2503: The output string is a table containing all desired attempts, if any.
1.16      harris41 2504: 
1.112     bowersj2 2505: =cut
1.1       albertel 2506: 
                   2507: sub get_previous_attempt {
1.43      ng       2508:   my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1       albertel 2509:   my $prevattempts='';
1.43      ng       2510:   no strict 'refs';
1.1       albertel 2511:   if ($symb) {
1.3       albertel 2512:     my (%returnhash)=
                   2513:       &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1       albertel 2514:     if ($returnhash{'version'}) {
                   2515:       my %lasthash=();
                   2516:       my $version;
                   2517:       for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356     albertel 2518:         foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
                   2519: 	  $lasthash{$key}=$returnhash{$version.':'.$key};
1.19      harris41 2520:         }
1.1       albertel 2521:       }
1.43      ng       2522:       $prevattempts='<table border="0" width="100%"><tr><td bgcolor="#777777">';
1.40      ng       2523:       $prevattempts.='<table border="0" width="100%"><tr bgcolor="#e6ffff"><td>History</td>';
1.356     albertel 2524:       foreach my $key (sort(keys(%lasthash))) {
                   2525: 	my ($ign,@parts) = split(/\./,$key);
1.41      ng       2526: 	if ($#parts > 0) {
1.31      albertel 2527: 	  my $data=$parts[-1];
                   2528: 	  pop(@parts);
1.40      ng       2529: 	  $prevattempts.='<td>Part '.join('.',@parts).'<br />'.$data.'&nbsp;</td>';
1.31      albertel 2530: 	} else {
1.41      ng       2531: 	  if ($#parts == 0) {
                   2532: 	    $prevattempts.='<th>'.$parts[0].'</th>';
                   2533: 	  } else {
                   2534: 	    $prevattempts.='<th>'.$ign.'</th>';
                   2535: 	  }
1.31      albertel 2536: 	}
1.16      harris41 2537:       }
1.40      ng       2538:       if ($getattempt eq '') {
                   2539: 	for ($version=1;$version<=$returnhash{'version'};$version++) {
                   2540: 	  $prevattempts.='</tr><tr bgcolor="#ffffe6"><td>Transaction '.$version.'</td>';
1.356     albertel 2541: 	    foreach my $key (sort(keys(%lasthash))) {
1.40      ng       2542: 	       my $value;
1.356     albertel 2543: 	       if ($key =~ /timestamp/) {
                   2544: 		  $value=scalar(localtime($returnhash{$version.':'.$key}));
1.40      ng       2545: 	       } else {
1.356     albertel 2546: 		  $value=$returnhash{$version.':'.$key};
1.40      ng       2547: 	       }
1.369     www      2548: 	       $prevattempts.='<td>'.&unescape($value).'&nbsp;</td>';   
1.40      ng       2549: 	    }
                   2550: 	 }
1.1       albertel 2551:       }
1.40      ng       2552:       $prevattempts.='</tr><tr bgcolor="#ffffe6"><td>Current</td>';
1.356     albertel 2553:       foreach my $key (sort(keys(%lasthash))) {
1.5       albertel 2554: 	my $value;
1.356     albertel 2555: 	if ($key =~ /timestamp/) {
                   2556: 	  $value=scalar(localtime($lasthash{$key}));
1.5       albertel 2557: 	} else {
1.356     albertel 2558: 	  $value=$lasthash{$key};
1.5       albertel 2559: 	}
1.369     www      2560: 	$value=&unescape($value);
1.356     albertel 2561: 	if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
1.40      ng       2562: 	$prevattempts.='<td>'.$value.'&nbsp;</td>';
1.16      harris41 2563:       }
1.40      ng       2564:       $prevattempts.='</tr></table></td></tr></table>';
1.1       albertel 2565:     } else {
                   2566:       $prevattempts='Nothing submitted - no attempts.';
                   2567:     }
                   2568:   } else {
                   2569:     $prevattempts='No data.';
                   2570:   }
1.10      albertel 2571: }
                   2572: 
1.107     albertel 2573: sub relative_to_absolute {
                   2574:     my ($url,$output)=@_;
                   2575:     my $parser=HTML::TokeParser->new(\$output);
                   2576:     my $token;
                   2577:     my $thisdir=$url;
                   2578:     my @rlinks=();
                   2579:     while ($token=$parser->get_token) {
                   2580: 	if ($token->[0] eq 'S') {
                   2581: 	    if ($token->[1] eq 'a') {
                   2582: 		if ($token->[2]->{'href'}) {
                   2583: 		    $rlinks[$#rlinks+1]=$token->[2]->{'href'};
                   2584: 		}
                   2585: 	    } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
                   2586: 		$rlinks[$#rlinks+1]=$token->[2]->{'src'};
                   2587: 	    } elsif ($token->[1] eq 'base') {
                   2588: 		$thisdir=$token->[2]->{'href'};
                   2589: 	    }
                   2590: 	}
                   2591:     }
                   2592:     $thisdir=~s-/[^/]*$--;
1.356     albertel 2593:     foreach my $link (@rlinks) {
                   2594: 	unless (($link=~/^http:\/\//i) ||
                   2595: 		($link=~/^\//) ||
                   2596: 		($link=~/^javascript:/i) ||
                   2597: 		($link=~/^mailto:/i) ||
                   2598: 		($link=~/^\#/)) {
                   2599: 	    my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
                   2600: 	    $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107     albertel 2601: 	}
                   2602:     }
                   2603: # -------------------------------------------------- Deal with Applet codebases
                   2604:     $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
                   2605:     return $output;
                   2606: }
                   2607: 
1.112     bowersj2 2608: =pod
                   2609: 
                   2610: =item * get_student_view
                   2611: 
                   2612: show a snapshot of what student was looking at
                   2613: 
                   2614: =cut
                   2615: 
1.10      albertel 2616: sub get_student_view {
1.186     albertel 2617:   my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114     www      2618:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 2619:   my (%form);
1.10      albertel 2620:   my @elements=('symb','courseid','domain','username');
                   2621:   foreach my $element (@elements) {
1.186     albertel 2622:       $form{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 2623:   }
1.186     albertel 2624:   if (defined($moreenv)) {
                   2625:       %form=(%form,%{$moreenv});
                   2626:   }
1.236     albertel 2627:   if (defined($target)) { $form{'grade_target'} = $target; }
1.107     albertel 2628:   $feedurl=&Apache::lonnet::clutter($feedurl);
1.186     albertel 2629:   my $userview=&Apache::lonnet::ssi_body($feedurl,%form);
1.11      albertel 2630:   $userview=~s/\<body[^\>]*\>//gi;
                   2631:   $userview=~s/\<\/body\>//gi;
                   2632:   $userview=~s/\<html\>//gi;
                   2633:   $userview=~s/\<\/html\>//gi;
                   2634:   $userview=~s/\<head\>//gi;
                   2635:   $userview=~s/\<\/head\>//gi;
                   2636:   $userview=~s/action\s*\=/would_be_action\=/gi;
1.107     albertel 2637:   $userview=&relative_to_absolute($feedurl,$userview);
1.11      albertel 2638:   return $userview;
                   2639: }
                   2640: 
1.112     bowersj2 2641: =pod
                   2642: 
                   2643: =item * get_student_answers() 
                   2644: 
                   2645: show a snapshot of how student was answering problem
                   2646: 
                   2647: =cut
                   2648: 
1.11      albertel 2649: sub get_student_answers {
1.100     sakharuk 2650:   my ($symb,$username,$domain,$courseid,%form) = @_;
1.114     www      2651:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 2652:   my (%moreenv);
1.11      albertel 2653:   my @elements=('symb','courseid','domain','username');
                   2654:   foreach my $element (@elements) {
1.186     albertel 2655:     $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 2656:   }
1.186     albertel 2657:   $moreenv{'grade_target'}='answer';
                   2658:   %moreenv=(%form,%moreenv);
1.497     raeburn  2659:   $feedurl = &Apache::lonnet::clutter($feedurl);
                   2660:   &Apache::lonenc::check_encrypt(\$feedurl);
                   2661:   my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10      albertel 2662:   return $userview;
1.1       albertel 2663: }
1.116     albertel 2664: 
                   2665: =pod
                   2666: 
                   2667: =item * &submlink()
                   2668: 
1.242     albertel 2669: Inputs: $text $uname $udom $symb $target
1.116     albertel 2670: 
                   2671: Returns: A link to grades.pm such as to see the SUBM view of a student
                   2672: 
                   2673: =cut
                   2674: 
                   2675: ###############################################
                   2676: sub submlink {
1.242     albertel 2677:     my ($text,$uname,$udom,$symb,$target)=@_;
1.116     albertel 2678:     if (!($uname && $udom)) {
                   2679: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 2680: 	    &Apache::lonnet::whichuser($symb);
1.116     albertel 2681: 	if (!$symb) { $symb=$cursymb; }
                   2682:     }
1.254     matthew  2683:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      2684:     $symb=&escape($symb);
1.242     albertel 2685:     if ($target) { $target="target=\"$target\""; }
                   2686:     return '<a href="/adm/grades?&command=submission&'.
                   2687: 	'symb='.$symb.'&student='.$uname.
                   2688: 	'&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
                   2689: }
                   2690: ##############################################
                   2691: 
                   2692: =pod
                   2693: 
                   2694: =item * &pgrdlink()
                   2695: 
                   2696: Inputs: $text $uname $udom $symb $target
                   2697: 
                   2698: Returns: A link to grades.pm such as to see the PGRD view of a student
                   2699: 
                   2700: =cut
                   2701: 
                   2702: ###############################################
                   2703: sub pgrdlink {
                   2704:     my $link=&submlink(@_);
                   2705:     $link=~s/(&command=submission)/$1&showgrading=yes/;
                   2706:     return $link;
                   2707: }
                   2708: ##############################################
                   2709: 
                   2710: =pod
                   2711: 
                   2712: =item * &pprmlink()
                   2713: 
                   2714: Inputs: $text $uname $udom $symb $target
                   2715: 
                   2716: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283     albertel 2717: student and a specific resource
1.242     albertel 2718: 
                   2719: =cut
                   2720: 
                   2721: ###############################################
                   2722: sub pprmlink {
                   2723:     my ($text,$uname,$udom,$symb,$target)=@_;
                   2724:     if (!($uname && $udom)) {
                   2725: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 2726: 	    &Apache::lonnet::whichuser($symb);
1.242     albertel 2727: 	if (!$symb) { $symb=$cursymb; }
                   2728:     }
1.254     matthew  2729:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      2730:     $symb=&escape($symb);
1.242     albertel 2731:     if ($target) { $target="target=\"$target\""; }
                   2732:     return '<a href="/adm/parmset?&command=set&'.
                   2733: 	'symb='.$symb.'&uname='.$uname.
                   2734: 	'&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116     albertel 2735: }
                   2736: ##############################################
1.37      matthew  2737: 
1.112     bowersj2 2738: =pod
                   2739: 
                   2740: =back
                   2741: 
                   2742: =cut
                   2743: 
1.37      matthew  2744: ###############################################
1.51      www      2745: 
                   2746: 
                   2747: sub timehash {
                   2748:     my @ltime=localtime(shift);
                   2749:     return ( 'seconds' => $ltime[0],
                   2750:              'minutes' => $ltime[1],
                   2751:              'hours'   => $ltime[2],
                   2752:              'day'     => $ltime[3],
                   2753:              'month'   => $ltime[4]+1,
                   2754:              'year'    => $ltime[5]+1900,
                   2755:              'weekday' => $ltime[6],
                   2756:              'dayyear' => $ltime[7]+1,
                   2757:              'dlsav'   => $ltime[8] );
                   2758: }
                   2759: 
1.370     www      2760: sub utc_string {
                   2761:     my ($date)=@_;
1.371     www      2762:     return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370     www      2763: }
                   2764: 
1.51      www      2765: sub maketime {
                   2766:     my %th=@_;
                   2767:     return POSIX::mktime(
                   2768:         ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210     www      2769:          $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70      www      2770: }
                   2771: 
                   2772: #########################################
1.51      www      2773: 
                   2774: sub findallcourses {
1.482     raeburn  2775:     my ($roles,$uname,$udom) = @_;
1.355     albertel 2776:     my %roles;
                   2777:     if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348     albertel 2778:     my %courses;
1.51      www      2779:     my $now=time;
1.482     raeburn  2780:     if (!defined($uname)) {
                   2781:         $uname = $env{'user.name'};
                   2782:     }
                   2783:     if (!defined($udom)) {
                   2784:         $udom = $env{'user.domain'};
                   2785:     }
                   2786:     if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
                   2787:         my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
                   2788:         if (!%roles) {
                   2789:             %roles = (
                   2790:                        cc => 1,
                   2791:                        in => 1,
                   2792:                        ep => 1,
                   2793:                        ta => 1,
                   2794:                        cr => 1,
                   2795:                        st => 1,
                   2796:              );
                   2797:         }
                   2798:         foreach my $entry (keys(%roleshash)) {
                   2799:             my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
                   2800:             if ($trole =~ /^cr/) { 
                   2801:                 next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
                   2802:             } else {
                   2803:                 next if (!exists($roles{$trole}));
                   2804:             }
                   2805:             if ($tend) {
                   2806:                 next if ($tend < $now);
                   2807:             }
                   2808:             if ($tstart) {
                   2809:                 next if ($tstart > $now);
                   2810:             }
                   2811:             my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
                   2812:             (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
                   2813:             if ($secpart eq '') {
                   2814:                 ($cnum,$role) = split(/_/,$cnumpart); 
                   2815:                 $sec = 'none';
                   2816:                 $realsec = '';
                   2817:             } else {
                   2818:                 $cnum = $cnumpart;
                   2819:                 ($sec,$role) = split(/_/,$secpart);
                   2820:                 $realsec = $sec;
1.490     raeburn  2821:             }
1.482     raeburn  2822:             $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
                   2823:         }
                   2824:     } else {
                   2825:         foreach my $key (keys(%env)) {
1.483     albertel 2826: 	    if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
                   2827:                  $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482     raeburn  2828: 	        my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
                   2829: 	        next if ($role eq 'ca' || $role eq 'aa');
                   2830: 	        next if (%roles && !exists($roles{$role}));
                   2831: 	        my ($starttime,$endtime)=split(/\./,$env{$key});
                   2832:                 my $active=1;
                   2833:                 if ($starttime) {
                   2834: 		    if ($now<$starttime) { $active=0; }
                   2835:                 }
                   2836:                 if ($endtime) {
                   2837:                     if ($now>$endtime) { $active=0; }
                   2838:                 }
                   2839:                 if ($active) {
                   2840:                     if ($sec eq '') {
                   2841:                         $sec = 'none';
                   2842:                     }
                   2843:                     $courses{$cdom.'_'.$cnum}{$sec} = 
                   2844:                                      $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474     raeburn  2845:                 }
                   2846:             }
1.51      www      2847:         }
                   2848:     }
1.474     raeburn  2849:     return %courses;
1.51      www      2850: }
1.37      matthew  2851: 
1.54      www      2852: ###############################################
1.474     raeburn  2853: 
                   2854: sub blockcheck {
1.482     raeburn  2855:     my ($setters,$activity,$uname,$udom) = @_;
1.490     raeburn  2856: 
                   2857:     if (!defined($udom)) {
                   2858:         $udom = $env{'user.domain'};
                   2859:     }
                   2860:     if (!defined($uname)) {
                   2861:         $uname = $env{'user.name'};
                   2862:     }
                   2863: 
                   2864:     # If uname and udom are for a course, check for blocks in the course.
                   2865: 
                   2866:     if (&Apache::lonnet::is_course($udom,$uname)) {
                   2867:         my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502     raeburn  2868:         my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490     raeburn  2869:         return ($startblock,$endblock);
                   2870:     }
1.474     raeburn  2871: 
1.502     raeburn  2872:     my $startblock = 0;
                   2873:     my $endblock = 0;
1.482     raeburn  2874:     my %live_courses = &findallcourses(undef,$uname,$udom);
1.474     raeburn  2875: 
1.490     raeburn  2876:     # If uname is for a user, and activity is course-specific, i.e.,
                   2877:     # boards, chat or groups, check for blocking in current course only.
1.474     raeburn  2878: 
1.490     raeburn  2879:     if (($activity eq 'boards' || $activity eq 'chat' ||
                   2880:          $activity eq 'groups') && ($env{'request.course.id'})) {
                   2881:         foreach my $key (keys(%live_courses)) {
                   2882:             if ($key ne $env{'request.course.id'}) {
                   2883:                 delete($live_courses{$key});
                   2884:             }
                   2885:         }
                   2886:     }
                   2887: 
                   2888:     my $otheruser = 0;
                   2889:     my %own_courses;
                   2890:     if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
                   2891:         # Resource belongs to user other than current user.
                   2892:         $otheruser = 1;
                   2893:         # Gather courses for current user
                   2894:         %own_courses = 
                   2895:             &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
                   2896:     }
                   2897: 
                   2898:     # Gather active course roles - course coordinator, instructor, 
                   2899:     # exam proctor, ta, student, or custom role.
1.474     raeburn  2900: 
                   2901:     foreach my $course (keys(%live_courses)) {
1.482     raeburn  2902:         my ($cdom,$cnum);
                   2903:         if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
                   2904:             $cdom = $env{'course.'.$course.'.domain'};
                   2905:             $cnum = $env{'course.'.$course.'.num'};
                   2906:         } else {
1.490     raeburn  2907:             ($cdom,$cnum) = split(/_/,$course); 
1.482     raeburn  2908:         }
                   2909:         my $no_ownblock = 0;
                   2910:         my $no_userblock = 0;
1.490     raeburn  2911:         if ($otheruser) {
                   2912:             # Check if current user has 'evb' priv for this
                   2913:             if (defined($own_courses{$course})) {
                   2914:                 foreach my $sec (keys(%{$own_courses{$course}})) {
                   2915:                     my $checkrole = 'cm./'.$cdom.'/'.$cnum;
                   2916:                     if ($sec ne 'none') {
                   2917:                         $checkrole .= '/'.$sec;
                   2918:                     }
                   2919:                     if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   2920:                         $no_ownblock = 1;
                   2921:                         last;
                   2922:                     }
                   2923:                 }
                   2924:             }
                   2925:             # if they have 'evb' priv and are currently not playing student
                   2926:             next if (($no_ownblock) &&
                   2927:                  ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
                   2928:         }
1.474     raeburn  2929:         foreach my $sec (keys(%{$live_courses{$course}})) {
1.482     raeburn  2930:             my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474     raeburn  2931:             if ($sec ne 'none') {
1.482     raeburn  2932:                 $checkrole .= '/'.$sec;
1.474     raeburn  2933:             }
1.490     raeburn  2934:             if ($otheruser) {
                   2935:                 # Resource belongs to user other than current user.
                   2936:                 # Assemble privs for that user, and check for 'evb' priv.
1.482     raeburn  2937:                 my ($trole,$tdom,$tnum,$tsec);
                   2938:                 my $entry = $live_courses{$course}{$sec};
                   2939:                 if ($entry =~ /^cr/) {
                   2940:                     ($trole,$tdom,$tnum,$tsec) = 
                   2941:                       ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
                   2942:                 } else {
                   2943:                     ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
                   2944:                 }
                   2945:                 my ($spec,$area,$trest,%allroles,%userroles);
                   2946:                 $area = '/'.$tdom.'/'.$tnum;
                   2947:                 $trest = $tnum;
                   2948:                 if ($tsec ne '') {
                   2949:                     $area .= '/'.$tsec;
                   2950:                     $trest .= '/'.$tsec;
                   2951:                 }
                   2952:                 $spec = $trole.'.'.$area;
                   2953:                 if ($trole =~ /^cr/) {
                   2954:                     &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
                   2955:                                                       $tdom,$spec,$trest,$area);
                   2956:                 } else {
                   2957:                     &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
                   2958:                                                        $tdom,$spec,$trest,$area);
                   2959:                 }
                   2960:                 my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486     raeburn  2961:                 if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
                   2962:                     if ($1) {
                   2963:                         $no_userblock = 1;
                   2964:                         last;
                   2965:                     }
                   2966:                 }
1.490     raeburn  2967:             } else {
                   2968:                 # Resource belongs to current user
                   2969:                 # Check for 'evb' priv via lonnet::allowed().
1.482     raeburn  2970:                 if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   2971:                     $no_ownblock = 1;
                   2972:                     last;
                   2973:                 }
1.474     raeburn  2974:             }
                   2975:         }
                   2976:         # if they have the evb priv and are currently not playing student
1.482     raeburn  2977:         next if (($no_ownblock) &&
1.491     albertel 2978:                  ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482     raeburn  2979:         next if ($no_userblock);
1.474     raeburn  2980: 
1.490     raeburn  2981:         # Retrieve blocking times and identity of blocker for course
                   2982:         # of specified user, unless user has 'evb' privilege.
1.502     raeburn  2983:         
                   2984:         my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
                   2985:         if (($start != 0) && 
                   2986:             (($startblock == 0) || ($startblock > $start))) {
                   2987:             $startblock = $start;
                   2988:         }
                   2989:         if (($end != 0)  &&
                   2990:             (($endblock == 0) || ($endblock < $end))) {
                   2991:             $endblock = $end;
                   2992:         }
1.490     raeburn  2993:     }
                   2994:     return ($startblock,$endblock);
                   2995: }
                   2996: 
                   2997: sub get_blocks {
                   2998:     my ($setters,$activity,$cdom,$cnum) = @_;
                   2999:     my $startblock = 0;
                   3000:     my $endblock = 0;
                   3001:     my $course = $cdom.'_'.$cnum;
                   3002:     $setters->{$course} = {};
                   3003:     $setters->{$course}{'staff'} = [];
                   3004:     $setters->{$course}{'times'} = [];
                   3005:     my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
                   3006:     foreach my $record (keys(%records)) {
                   3007:         my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
                   3008:         if ($start <= time && $end >= time) {
                   3009:             my ($staff_name,$staff_dom,$title,$blocks) =
                   3010:                 &parse_block_record($records{$record});
                   3011:             if ($blocks->{$activity} eq 'on') {
                   3012:                 push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
                   3013:                 push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491     albertel 3014:                 if ( ($startblock == 0) || ($startblock > $start) ) {
                   3015:                     $startblock = $start;
1.490     raeburn  3016:                 }
1.491     albertel 3017:                 if ( ($endblock == 0) || ($endblock < $end) ) {
                   3018:                     $endblock = $end;
1.474     raeburn  3019:                 }
                   3020:             }
                   3021:         }
                   3022:     }
                   3023:     return ($startblock,$endblock);
                   3024: }
                   3025: 
                   3026: sub parse_block_record {
                   3027:     my ($record) = @_;
                   3028:     my ($setuname,$setudom,$title,$blocks);
                   3029:     if (ref($record) eq 'HASH') {
                   3030:         ($setuname,$setudom) = split(/:/,$record->{'setter'});
                   3031:         $title = &unescape($record->{'event'});
                   3032:         $blocks = $record->{'blocks'};
                   3033:     } else {
                   3034:         my @data = split(/:/,$record,3);
                   3035:         if (scalar(@data) eq 2) {
                   3036:             $title = $data[1];
                   3037:             ($setuname,$setudom) = split(/@/,$data[0]);
                   3038:         } else {
                   3039:             ($setuname,$setudom,$title) = @data;
                   3040:         }
                   3041:         $blocks = { 'com' => 'on' };
                   3042:     }
                   3043:     return ($setuname,$setudom,$title,$blocks);
                   3044: }
                   3045: 
                   3046: sub build_block_table {
                   3047:     my ($startblock,$endblock,$setters) = @_;
                   3048:     my %lt = &Apache::lonlocal::texthash(
                   3049:         'cacb' => 'Currently active communication blocks',
                   3050:         'cour' => 'Course',
                   3051:         'dura' => 'Duration',
                   3052:         'blse' => 'Block set by'
                   3053:     );
                   3054:     my $output;
1.476     raeburn  3055:     $output = '<br />'.$lt{'cacb'}.':<br />';
1.474     raeburn  3056:     $output .= &start_data_table();
                   3057:     $output .= '
                   3058: <tr>
                   3059:  <th>'.$lt{'cour'}.'</th>
                   3060:  <th>'.$lt{'dura'}.'</th>
                   3061:  <th>'.$lt{'blse'}.'</th>
                   3062: </tr>
                   3063: ';
                   3064:     foreach my $course (keys(%{$setters})) {
                   3065:         my %courseinfo=&Apache::lonnet::coursedescription($course);
                   3066:         for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) {
                   3067:             my ($uname,$udom) = @{$$setters{$course}{staff}[$i]};
1.490     raeburn  3068:             my $fullname = &plainname($uname,$udom);
                   3069:             if (defined($env{'user.name'}) && defined($env{'user.domain'})
                   3070:                 && $env{'user.name'} ne 'public' 
                   3071:                 && $env{'user.domain'} ne 'public') {
                   3072:                 $fullname = &aboutmewrapper($fullname,$uname,$udom);
                   3073:             }
1.474     raeburn  3074:             my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]};
                   3075:             $openblock = &Apache::lonlocal::locallocaltime($openblock);
                   3076:             $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
                   3077:             $output .= &Apache::loncommon::start_data_table_row().
                   3078:                        '<td>'.$courseinfo{'description'}.'</td>'.
                   3079:                        '<td>'.$openblock.' to '.$closeblock.'</td>'.
1.490     raeburn  3080:                        '<td>'.$fullname.'</td>'.
1.474     raeburn  3081:                         &Apache::loncommon::end_data_table_row();
                   3082:         }
                   3083:     }
                   3084:     $output .= &end_data_table();
                   3085: }
                   3086: 
1.490     raeburn  3087: sub blocking_status {
                   3088:     my ($activity,$uname,$udom) = @_;
                   3089:     my %setters;
                   3090:     my ($blocked,$output,$ownitem,$is_course);
                   3091:     my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
                   3092:     if ($startblock && $endblock) {
                   3093:         $blocked = 1;
                   3094:         if (wantarray) {
                   3095:             my $category;
                   3096:             if ($activity eq 'boards') {
                   3097:                 $category = 'Discussion posts in this course';
                   3098:             } elsif ($activity eq 'blogs') {
                   3099:                 $category = 'Blogs';
                   3100:             } elsif ($activity eq 'port') {
                   3101:                 if (defined($uname) && defined($udom)) {
                   3102:                     if ($uname eq $env{'user.name'} &&
                   3103:                         $udom eq $env{'user.domain'}) {
                   3104:                         $ownitem = 1;
                   3105:                     }
                   3106:                 }
                   3107:                 $is_course = &Apache::lonnet::is_course($udom,$uname);
                   3108:                 if ($ownitem) { 
                   3109:                     $category = 'Your portfolio files';  
                   3110:                 } elsif ($is_course) {
                   3111:                     my $coursedesc;
                   3112:                     foreach my $course (keys(%setters)) {
                   3113:                         my %courseinfo =
                   3114:                              &Apache::lonnet::coursedescription($course);
                   3115:                         $coursedesc = $courseinfo{'description'};
                   3116:                     }
                   3117:                     $category = "Group files in the course '$coursedesc'";
                   3118:                 } else {
                   3119:                     $category = 'Portfolio files belonging to ';
                   3120:                     if ($env{'user.name'} eq 'public' && 
                   3121:                         $env{'user.domain'} eq 'public') {
                   3122:                         $category .= &plainname($uname,$udom);
                   3123:                     } else {
                   3124:                         $category .= &aboutmewrapper(&plainname($uname,$udom),$uname,$udom);  
                   3125:                     }
                   3126:                 }
                   3127:             } elsif ($activity eq 'groups') {
                   3128:                 $category = 'Groups in this course';
                   3129:             }
                   3130:             my $showstart = &Apache::lonlocal::locallocaltime($startblock);
                   3131:             my $showend = &Apache::lonlocal::locallocaltime($endblock);
                   3132:             $output = '<br />'.&mt('[_1] will be inaccessible between [_2] and [_3] because communication is being blocked.',$category,$showstart,$showend).'<br />';
                   3133:             if (!($activity eq 'port' && !($ownitem) && !($is_course))) { 
                   3134:                 $output .= &build_block_table($startblock,$endblock,\%setters);
                   3135:             }
                   3136:         }
                   3137:     }
                   3138:     if (wantarray) {
                   3139:         return ($blocked,$output);
                   3140:     } else {
                   3141:         return $blocked;
                   3142:     }
                   3143: }
                   3144: 
1.60      matthew  3145: ###############################################
                   3146: 
                   3147: =pod
                   3148: 
1.112     bowersj2 3149: =head1 Domain Template Functions
                   3150: 
                   3151: =over 4
                   3152: 
                   3153: =item * &determinedomain()
1.60      matthew  3154: 
                   3155: Inputs: $domain (usually will be undef)
                   3156: 
1.63      www      3157: Returns: Determines which domain should be used for designs
1.60      matthew  3158: 
                   3159: =cut
1.54      www      3160: 
1.60      matthew  3161: ###############################################
1.63      www      3162: sub determinedomain {
                   3163:     my $domain=shift;
                   3164:    if (! $domain) {
1.60      matthew  3165:         # Determine domain if we have not been given one
                   3166:         $domain = $Apache::lonnet::perlvar{'lonDefDomain'};
1.258     albertel 3167:         if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
                   3168:         if ($env{'request.role.domain'}) { 
                   3169:             $domain=$env{'request.role.domain'}; 
1.60      matthew  3170:         }
                   3171:     }
1.63      www      3172:     return $domain;
                   3173: }
                   3174: ###############################################
1.517     raeburn  3175: 
1.518   ! albertel 3176: sub devalidate_domconfig_cache {
        !          3177:     my ($udom)=@_;
        !          3178:     &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
        !          3179: }
        !          3180: 
        !          3181: # ---------------------- Get domain configuration for a domain
        !          3182: sub get_domainconf {
        !          3183:     my ($udom) = @_;
        !          3184:     my $cachetime=1800;
        !          3185:     my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
        !          3186:     if (defined($cached)) { return %{$result}; }
        !          3187: 
        !          3188:     my %domconfig = &Apache::lonnet::get_dom('configuration',
        !          3189: 					     ['login','rolecolors'],$udom);
        !          3190:     my %designhash;
        !          3191:     if (keys(%domconfig) > 0) {
        !          3192:         if (ref($domconfig{'login'}) eq 'HASH') {
        !          3193:             foreach my $key (keys(%{$domconfig{'login'}})) {
        !          3194:                 $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
        !          3195:             }
        !          3196:         }
        !          3197:         if (ref($domconfig{'rolecolors'}) eq 'HASH') {
        !          3198:             foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
        !          3199:                 if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
        !          3200:                     foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
        !          3201:                         $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
        !          3202:                     }
        !          3203:                 }
        !          3204:             }
        !          3205:         }
        !          3206:     } else {
        !          3207:         my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
        !          3208:         my $designfile =  $designdir.'/'.$udom.'.tab';
        !          3209:         if (-e $designfile) {
        !          3210:             if ( open (my $fh,"<$designfile") ) {
        !          3211:                 while (my $line = <$fh>) {
        !          3212:                     next if ($line =~ /^\#/);
        !          3213:                     chomp($line);
        !          3214:                     my ($key,$val)=(split(/\=/,$line));
        !          3215:                     if ($val) { $designhash{$udom.'.'.$key}=$val; }
        !          3216:                 }
        !          3217:                 close($fh);
        !          3218:             }
        !          3219:         }
        !          3220:         if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
        !          3221:             $designhash{$udom.'.login.domlogo'} = 
        !          3222:                 &lonhttpdurl("/adm/lonDomLogos/$udom.gif"); 
        !          3223:         }
        !          3224:     }
        !          3225:     &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
        !          3226: 				  $cachetime);
        !          3227:     return %designhash;
        !          3228: }
        !          3229: 
1.63      www      3230: =pod
                   3231: 
1.112     bowersj2 3232: =item * &domainlogo()
1.63      www      3233: 
                   3234: Inputs: $domain (usually will be undef)
                   3235: 
                   3236: Returns: A link to a domain logo, if the domain logo exists.
                   3237: If the domain logo does not exist, a description of the domain.
                   3238: 
                   3239: =cut
1.112     bowersj2 3240: 
1.63      www      3241: ###############################################
                   3242: sub domainlogo {
1.517     raeburn  3243:     my $domain = &determinedomain(shift);
1.518   ! albertel 3244:     my %designhash = &get_domainconf($domain);    
1.517     raeburn  3245:     # See if there is a logo
                   3246:     if ($designhash{$domain.'.login.domlogo'} ne '') {
                   3247:         return '<img src="'.$designhash{$domain.'.login.domlogo'}.
                   3248:                '" alt="'.$domain.'" />';
1.514     albertel 3249:     } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
                   3250:         return &Apache::lonnet::domain($domain,'description');
1.59      www      3251:     } else {
1.60      matthew  3252:         return '';
1.59      www      3253:     }
                   3254: }
1.63      www      3255: ##############################################
                   3256: 
                   3257: =pod
                   3258: 
1.112     bowersj2 3259: =item * &designparm()
1.63      www      3260: 
                   3261: Inputs: $which parameter; $domain (usually will be undef)
                   3262: 
                   3263: Returns: value of designparamter $which
                   3264: 
                   3265: =cut
1.112     bowersj2 3266: 
1.397     albertel 3267: 
1.400     albertel 3268: ##############################################
1.397     albertel 3269: sub designparm {
                   3270:     my ($which,$domain)=@_;
1.258     albertel 3271:     if ($env{'browser.blackwhite'} eq 'on') {
1.110     www      3272: 	if ($which=~/\.(font|alink|vlink|link)$/) {
                   3273: 	    return '#000000';
                   3274: 	}
                   3275: 	if ($which=~/\.(pgbg|sidebg)$/) {
                   3276: 	    return '#FFFFFF';
                   3277: 	}
                   3278: 	if ($which=~/\.tabbg$/) {
                   3279: 	    return '#CCCCCC';
                   3280: 	}
                   3281:     }
1.397     albertel 3282:     if (exists($env{'environment.color.'.$which})) {
1.258     albertel 3283: 	return $env{'environment.color.'.$which};
1.96      www      3284:     }
1.63      www      3285:     $domain=&determinedomain($domain);
1.518   ! albertel 3286:     my %domdesign = &get_domainconf($domain);
1.517     raeburn  3287:     if ($domdesign{$domain.'.'.$which} ne '') {
                   3288: 	return $domdesign{$domain.'.'.$which};
1.63      www      3289:     } else {
1.517     raeburn  3290:         return $defaultdesign{$which};
1.63      www      3291:     }
                   3292: }
1.59      www      3293: 
1.60      matthew  3294: ###############################################
                   3295: ###############################################
                   3296: 
                   3297: =pod
                   3298: 
1.112     bowersj2 3299: =back
                   3300: 
                   3301: =head1 HTTP Helpers
                   3302: 
                   3303: =over 4
                   3304: 
                   3305: =item * &bodytag()
1.60      matthew  3306: 
                   3307: Returns a uniform header for LON-CAPA web pages.
                   3308: 
                   3309: Inputs: 
                   3310: 
1.112     bowersj2 3311: =over 4
                   3312: 
                   3313: =item * $title, A title to be displayed on the page.
                   3314: 
                   3315: =item * $function, the current role (can be undef).
                   3316: 
                   3317: =item * $addentries, extra parameters for the <body> tag.
                   3318: 
                   3319: =item * $bodyonly, if defined, only return the <body> tag.
                   3320: 
                   3321: =item * $domain, if defined, force a given domain.
                   3322: 
                   3323: =item * $forcereg, if page should register as content page (relevant for 
1.86      www      3324:             text interface only)
1.60      matthew  3325: 
1.326     albertel 3326: =item * $customtitle, alternate text to use instead of $title
                   3327:                       in the title box that appears, this text
                   3328:                       is not auto translated like the $title is
1.309     albertel 3329: 
                   3330: =item * $notopbar, if true, keep the 'what is this' info but remove the
                   3331:                    navigational links
1.317     albertel 3332: 
1.338     albertel 3333: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
                   3334: 
                   3335: =item * $notitle, if true keep the nav controls, but remove the title bar
                   3336: 
1.361     albertel 3337: =item * $no_inline_link, if true and in remote mode, don't show the 
                   3338:          'Switch To Inline Menu' link
                   3339: 
1.460     albertel 3340: =item * $args, optional argument valid values are
                   3341:             no_auto_mt_title -> prevents &mt()ing the title arg
                   3342: 
1.112     bowersj2 3343: =back
                   3344: 
1.60      matthew  3345: Returns: A uniform header for LON-CAPA web pages.  
                   3346: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
                   3347: If $bodyonly is undef or zero, an html string containing a <body> tag and 
                   3348: other decorations will be returned.
                   3349: 
                   3350: =cut
                   3351: 
1.54      www      3352: sub bodytag {
1.309     albertel 3353:     my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,$customtitle,
1.460     albertel 3354: 	$notopbar,$bgcolor,$notitle,$no_inline_link,$args)=@_;
1.339     albertel 3355: 
1.460     albertel 3356:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339     albertel 3357: 
1.183     matthew  3358:     $function = &get_users_function() if (!$function);
1.339     albertel 3359:     my $img =    &designparm($function.'.img',$domain);
                   3360:     my $font =   &designparm($function.'.font',$domain);
                   3361:     my $pgbg   = $bgcolor || &designparm($function.'.pgbg',$domain);
                   3362: 
                   3363:     my %design = ( 'style'   => 'margin-top: 0px',
                   3364: 		   'bgcolor' => $pgbg,
                   3365: 		   'text'    => $font,
                   3366:                    'alink'   => &designparm($function.'.alink',$domain),
                   3367: 		   'vlink'   => &designparm($function.'.vlink',$domain),
                   3368: 		   'link'    => &designparm($function.'.link',$domain),);
1.438     albertel 3369:     @design{keys(%$addentries)} = @$addentries{keys(%$addentries)}; 
1.339     albertel 3370: 
1.63      www      3371:  # role and realm
1.378     raeburn  3372:     my ($role,$realm) = split(/\./,$env{'request.role'},2);
                   3373:     if ($role  eq 'ca') {
1.479     albertel 3374:         my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500     albertel 3375:         $realm = &plainname($rname,$rdom);
1.378     raeburn  3376:     } 
1.55      www      3377: # realm
1.258     albertel 3378:     if ($env{'request.course.id'}) {
1.378     raeburn  3379:         if ($env{'request.role'} !~ /^cr/) {
                   3380:             $role = &Apache::lonnet::plaintext($role,&course_type());
                   3381:         }
1.359     albertel 3382: 	$realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378     raeburn  3383:     } else {
                   3384:         $role = &Apache::lonnet::plaintext($role);
1.54      www      3385:     }
1.433     albertel 3386: 
1.359     albertel 3387:     if (!$realm) { $realm='&nbsp;'; }
1.55      www      3388: # Set messages
1.60      matthew  3389:     my $messages=&domainlogo($domain);
1.101     www      3390: # Port for miniserver
1.83      albertel 3391:     my $lonhttpdPort=$Apache::lonnet::perlvar{'lonhttpdPort'};
                   3392:     if (!defined($lonhttpdPort)) { $lonhttpdPort='8080'; }
1.330     albertel 3393: 
1.438     albertel 3394:     my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329     albertel 3395: 
1.101     www      3396: # construct main body tag
1.359     albertel 3397:     my $bodytag = "<body $extra_body_attr>".
                   3398: 	&Apache::lontexconvert::init_math_support();
1.252     albertel 3399: 
1.332     albertel 3400:     if ($bodyonly 
                   3401: 	|| ($env{'request.state'} eq 'construct' 
                   3402: 	    && $env{'environment.remote'} ne 'off' )) {
1.60      matthew  3403:         return $bodytag;
1.258     albertel 3404:     } elsif ($env{'browser.interface'} eq 'textual') {
1.95      www      3405: # Accessibility
1.224     raeburn  3406:           
1.337     albertel 3407: 	$bodytag.=&Apache::lonmenu::menubuttons($forcereg,$forcereg);
1.338     albertel 3408: 	if (!$notitle) {
1.337     albertel 3409: 	    $bodytag.='<h1>LON-CAPA: '.$title.'</h1>';
                   3410: 	}
                   3411: 	return $bodytag;
1.359     albertel 3412:     }
                   3413: 
1.410     albertel 3414:     my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.433     albertel 3415:     if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
                   3416: 	undef($role);
1.434     albertel 3417:     } else {
                   3418: 	$name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433     albertel 3419:     }
1.359     albertel 3420:     
                   3421:     my $roleinfo=(<<ENDROLE);
                   3422: <td class="LC_title_bar_who">
                   3423: <div class="LC_title_bar_name">
1.410     albertel 3424:     $name
1.361     albertel 3425:     &nbsp;
1.359     albertel 3426: </div>
                   3427: <div class="LC_title_bar_role">
1.361     albertel 3428: $role&nbsp;
1.359     albertel 3429: </div>
                   3430: <div class="LC_title_bar_realm">
1.361     albertel 3431: $realm&nbsp;
1.359     albertel 3432: </div>
1.206     albertel 3433: </td>
                   3434: ENDROLE
1.235     raeburn  3435: 
1.359     albertel 3436:     my $titleinfo = '<span class="LC_title_bar_title">'.$title.'</span>';
                   3437:     if ($customtitle) {
                   3438:         $titleinfo = $customtitle;
                   3439:     }
                   3440:     #
                   3441:     # Extra info if you are the DC
                   3442:     my $dc_info = '';
                   3443:     if ($env{'user.adv'} && exists($env{'user.role.dc./'.
                   3444:                         $env{'course.'.$env{'request.course.id'}.
                   3445:                                  '.domain'}.'/'})) {
                   3446:         my $cid = $env{'request.course.id'};
                   3447:         $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380     www      3448:         $dc_info =~ s/\s+$//;
1.359     albertel 3449:         $dc_info = '('.$dc_info.')';
                   3450:     }
                   3451: 
                   3452:     if ($env{'environment.remote'} eq 'off') {
                   3453:         # No Remote
1.258     albertel 3454: 	if ($env{'request.state'} eq 'construct') {
1.359     albertel 3455: 	    $forcereg=1;
                   3456: 	}
                   3457: 
                   3458: 	if (!$customtitle && $env{'request.state'} eq 'construct') {
                   3459: 	    # this is for resources; directories have customtitle, and crumbs
                   3460:             # and select recent are created in lonpubdir.pm  
1.229     albertel 3461: 	    my ($uname,$thisdisfn)=
1.258     albertel 3462: 		($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
1.229     albertel 3463: 	    my $formaction='/priv/'.$uname.'/'.$thisdisfn;
                   3464: 	    $formaction=~s/\/+/\//g;
                   3465: 
1.359     albertel 3466: 	    my $parentpath = '';
                   3467: 	    my $lastitem = '';
                   3468: 	    if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
                   3469: 		$parentpath = $1;
                   3470: 		$lastitem = $2;
                   3471: 	    } else {
                   3472: 		$lastitem = $thisdisfn;
                   3473: 	    }
                   3474: 	    $titleinfo = 
1.401     albertel 3475: 		&Apache::loncommon::help_open_menu('','',3,'Authoring').
1.359     albertel 3476: 		'<b>Construction Space</b>:&nbsp;'. 
                   3477: 		'<form name="dirs" method="post" action="'.$formaction
                   3478: 		.'" target="_top"><tt><b>'
                   3479: 		.&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."<font size=\"+1\">$lastitem</font></b></tt><br />"
                   3480: 		.&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
                   3481: 		.'</form>'
                   3482: 		.&Apache::lonmenu::constspaceform();
1.235     raeburn  3483:         }
1.359     albertel 3484: 
1.337     albertel 3485:         my $titletable;
1.338     albertel 3486: 	if (!$notitle) {
1.337     albertel 3487: 	    $titletable =
1.359     albertel 3488: 		'<table id="LC_title_bar">'.
                   3489:                          "<tr><td> $titleinfo $dc_info</td>".$roleinfo.
                   3490: 			 '</tr></table>';
1.337     albertel 3491: 	}
1.359     albertel 3492: 	if ($notopbar) {
                   3493: 	    $bodytag .= $titletable;
                   3494: 	} else {
                   3495: 	    if ($env{'request.state'} eq 'construct') {
1.337     albertel 3496:                 $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg,
                   3497: 							  $titletable);
1.272     raeburn  3498:             } else {
1.336     albertel 3499:                 $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg).
1.359     albertel 3500: 		    $titletable;
1.272     raeburn  3501:             }
1.235     raeburn  3502:         }
                   3503:         return $bodytag;
1.94      www      3504:     }
1.95      www      3505: 
1.93      www      3506: #
1.95      www      3507: # Top frame rendering, Remote is up
1.93      www      3508: #
1.359     albertel 3509: 
1.517     raeburn  3510:     my $imgsrc = $img;
                   3511:     if ($img =~ /^\/adm/) {
                   3512:         $imgsrc = 'http://'.$ENV{'HTTP_HOST'}.':'.$lonhttpdPort.$img;
                   3513:     }
                   3514:     my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359     albertel 3515: 
1.305     www      3516:     # Explicit link to get inline menu
1.361     albertel 3517:     my $menu= ($no_inline_link?''
                   3518: 	       :'<br /><a href="/adm/remote?action=collapse">'.&mt('Switch to Inline Menu Mode').'</a>');
1.245     matthew  3519:     #
1.338     albertel 3520:     if ($notitle) {
1.337     albertel 3521: 	return $bodytag;
                   3522:     }
1.94      www      3523:     return(<<ENDBODY);
1.60      matthew  3524: $bodytag
1.359     albertel 3525: <table id="LC_title_bar" class="LC_with_remote">
1.368     albertel 3526: <tr><td class="LC_title_bar_role_logo">$upperleft</td>
1.359     albertel 3527:     <td class="LC_title_bar_domain_logo">$messages&nbsp;</td>
1.54      www      3528: </tr>
1.359     albertel 3529: <tr><td>$titleinfo $dc_info $menu</td>
                   3530: $roleinfo
1.368     albertel 3531: </tr>
1.356     albertel 3532: </table>
1.54      www      3533: ENDBODY
1.182     matthew  3534: }
                   3535: 
1.330     albertel 3536: sub make_attr_string {
                   3537:     my ($register,$attr_ref) = @_;
                   3538: 
                   3539:     if ($attr_ref && !ref($attr_ref)) {
                   3540: 	die("addentries Must be a hash ref ".
                   3541: 	    join(':',caller(1))." ".
                   3542: 	    join(':',caller(0))." ");
                   3543:     }
                   3544: 
                   3545:     if ($register) {
1.339     albertel 3546: 	my ($on_load,$on_unload);
                   3547: 	foreach my $key (keys(%{$attr_ref})) {
                   3548: 	    if      (lc($key) eq 'onload') {
                   3549: 		$on_load.=$attr_ref->{$key}.';';
                   3550: 		delete($attr_ref->{$key});
                   3551: 
                   3552: 	    } elsif (lc($key) eq 'onunload') {
                   3553: 		$on_unload.=$attr_ref->{$key}.';';
                   3554: 		delete($attr_ref->{$key});
                   3555: 	    }
                   3556: 	}
                   3557: 	$attr_ref->{'onload'}  =
                   3558: 	    &Apache::lonmenu::loadevents().  $on_load;
                   3559: 	$attr_ref->{'onunload'}=
                   3560: 	    &Apache::lonmenu::unloadevents().$on_unload;
                   3561:     }
                   3562: 
                   3563: # Accessibility font enhance
                   3564:     if ($env{'browser.fontenhance'} eq 'on') {
                   3565: 	my $style;
                   3566: 	foreach my $key (keys(%{$attr_ref})) {
                   3567: 	    if (lc($key) eq 'style') {
                   3568: 		$style.=$attr_ref->{$key}.';';
                   3569: 		delete($attr_ref->{$key});
                   3570: 	    }
                   3571: 	}
                   3572: 	$attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330     albertel 3573:     }
1.339     albertel 3574: 
                   3575:     if ($env{'browser.blackwhite'} eq 'on') {
                   3576: 	delete($attr_ref->{'font'});
                   3577: 	delete($attr_ref->{'link'});
                   3578: 	delete($attr_ref->{'alink'});
                   3579: 	delete($attr_ref->{'vlink'});
                   3580: 	delete($attr_ref->{'bgcolor'});
                   3581: 	delete($attr_ref->{'background'});
                   3582:     }
                   3583: 
1.330     albertel 3584:     my $attr_string;
                   3585:     foreach my $attr (keys(%$attr_ref)) {
                   3586: 	$attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
                   3587:     }
                   3588:     return $attr_string;
                   3589: }
                   3590: 
                   3591: 
1.182     matthew  3592: ###############################################
1.251     albertel 3593: ###############################################
                   3594: 
                   3595: =pod
                   3596: 
                   3597: =back
                   3598: 
1.306     albertel 3599: =head1 HTML Helpers
1.251     albertel 3600: 
                   3601: =over 4
                   3602: 
                   3603: =item * &endbodytag()
                   3604: 
                   3605: Returns a uniform footer for LON-CAPA web pages.
                   3606: 
1.306     albertel 3607: Inputs: none
1.251     albertel 3608: 
                   3609: =back
                   3610: 
                   3611: =cut
                   3612: 
                   3613: sub endbodytag {
                   3614:     my $endbodytag='</body>';
1.269     albertel 3615:     $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315     albertel 3616:     if ( exists( $env{'internal.head.redirect'} ) ) {
                   3617: 	$endbodytag=
                   3618: 	    "<br /><a href=\"$env{'internal.head.redirect'}\">".
                   3619: 	    &mt('Continue').'</a>'.
                   3620: 	    $endbodytag;
                   3621:     }
1.251     albertel 3622:     return $endbodytag;
                   3623: }
                   3624: 
1.352     albertel 3625: =pod
                   3626: 
                   3627: =over 4
                   3628: 
                   3629: =item * &standard_css()
                   3630: 
                   3631: Returns a style sheet
                   3632: 
                   3633: Inputs: (all optional)
                   3634:             domain         -> force to color decorate a page for a specific
                   3635:                                domain
                   3636:             function       -> force usage of a specific rolish color scheme
                   3637:             bgcolor        -> override the default page bgcolor
                   3638: 
                   3639: =back
                   3640: 
                   3641: =cut
                   3642: 
1.343     albertel 3643: sub standard_css {
1.345     albertel 3644:     my ($function,$domain,$bgcolor) = @_;
1.352     albertel 3645:     $function  = &get_users_function() if (!$function);
                   3646:     my $img    = &designparm($function.'.img',   $domain);
                   3647:     my $tabbg  = &designparm($function.'.tabbg', $domain);
                   3648:     my $font   = &designparm($function.'.font',  $domain);
1.345     albertel 3649:     my $sidebg = &designparm($function.'.sidebg',$domain);
1.382     albertel 3650:     my $pgbg_or_bgcolor =
                   3651: 	         $bgcolor ||
1.352     albertel 3652: 	         &designparm($function.'.pgbg',  $domain);
1.382     albertel 3653:     my $pgbg   = &designparm($function.'.pgbg',  $domain);
1.352     albertel 3654:     my $alink  = &designparm($function.'.alink', $domain);
                   3655:     my $vlink  = &designparm($function.'.vlink', $domain);
                   3656:     my $link   = &designparm($function.'.link',  $domain);
                   3657: 
                   3658:     my $sans                 = 'Arial,Helvetica,sans-serif';
1.395     albertel 3659:     my $mono                 = 'monospace';
1.352     albertel 3660:     my $data_table_head      = $tabbg;
                   3661:     my $data_table_light     = '#EEEEEE';
1.470     banghart 3662:     my $data_table_dark      = '#DDDDDD';
                   3663:     my $data_table_darker    = '#CCCCCC';
1.349     albertel 3664:     my $data_table_highlight = '#FFFF00';
1.352     albertel 3665:     my $mail_new             = '#FFBB77';
                   3666:     my $mail_new_hover       = '#DD9955';
                   3667:     my $mail_read            = '#BBBB77';
                   3668:     my $mail_read_hover      = '#999944';
                   3669:     my $mail_replied         = '#AAAA88';
                   3670:     my $mail_replied_hover   = '#888855';
                   3671:     my $mail_other           = '#99BBBB';
                   3672:     my $mail_other_hover     = '#669999';
1.391     albertel 3673:     my $table_header         = '#DDDDDD';
1.489     raeburn  3674:     my $feedback_link_bg     = '#BBBBBB';
1.392     albertel 3675: 
                   3676:     my $border = ($env{'browser.type'} eq 'explorer') ? '0px 2px 0px 2px'
                   3677: 	                                              : '0px 3px 0px 4px';
1.448     albertel 3678: 
1.343     albertel 3679:     return <<END;
1.345     albertel 3680: h1, h2, h3, th { font-family: $sans }
1.343     albertel 3681: a:focus { color: red; background: yellow } 
1.510     albertel 3682: table.thinborder,
                   3683: table.LC_optres_prior {
                   3684:   border-collapse: collapse;
                   3685: }
                   3686: table.thinborder tr th {
                   3687:   border-style: solid;
                   3688:   border-width: 1px;
                   3689:   background: $tabbg;
                   3690: }
                   3691: table.thinborder tr td, 
                   3692: table.LC_optres_prior tr td {
                   3693:   border-style: solid;
                   3694:   border-width: 1px
                   3695: }
1.426     albertel 3696: 
1.343     albertel 3697: form, .inline { display: inline; }
                   3698: .center { text-align: center; }
1.395     albertel 3699: .LC_filename {font-family: $mono;}
1.350     albertel 3700: .LC_error {
                   3701:   color: red;
                   3702:   font-size: larger;
                   3703: }
1.457     albertel 3704: .LC_warning,
                   3705: .LC_diff_removed {
1.394     albertel 3706:   color: red;
                   3707: }
1.457     albertel 3708: .LC_success,
                   3709: .LC_diff_added {
1.350     albertel 3710:   color: green;
                   3711: }
1.440     albertel 3712: .LC_icon {
                   3713:   border: 0px;
                   3714: }
1.346     albertel 3715: 
1.458     albertel 3716: table.LC_pastsubmission {
                   3717:   border: 1px solid black;
                   3718:   margin: 2px;
                   3719: }
                   3720: 
1.392     albertel 3721: table#LC_top_nav, table#LC_menubuttons {
1.345     albertel 3722:   width: 100%;
                   3723:   background: $pgbg;
1.392     albertel 3724:   border: 2px;
1.402     albertel 3725:   border-collapse: separate;
1.403     albertel 3726:   padding: 0px;
1.345     albertel 3727: }
1.392     albertel 3728: 
1.409     albertel 3729: table#LC_title_bar, table.LC_breadcrumbs, table#LC_nav_location,
1.393     albertel 3730: table#LC_title_bar.LC_with_remote {
1.359     albertel 3731:   width: 100%;
1.392     albertel 3732:   border-color: $pgbg;
                   3733:   border-style: solid;
                   3734:   border-width: $border;
                   3735: 
1.379     albertel 3736:   background: $pgbg;
                   3737:   font-family: $sans;
1.392     albertel 3738:   border-collapse: collapse;
1.403     albertel 3739:   padding: 0px;
1.359     albertel 3740: }
1.392     albertel 3741: 
1.409     albertel 3742: table.LC_docs_path {
                   3743:   width: 100%;
                   3744:   border: 0;
                   3745:   background: $pgbg;
                   3746:   font-family: $sans;
                   3747:   border-collapse: collapse;
                   3748:   padding: 0px;
                   3749: }
                   3750: 
1.359     albertel 3751: table#LC_title_bar td {
                   3752:   background: $tabbg;
                   3753: }
                   3754: table#LC_title_bar td.LC_title_bar_who {
                   3755:   background: $tabbg;
                   3756:   color: $font;
1.427     albertel 3757:   font: small $sans;
1.359     albertel 3758:   text-align: right;
                   3759: }
1.469     banghart 3760: span.LC_metadata {
                   3761:     font-family: $sans;
                   3762: }
1.359     albertel 3763: span.LC_title_bar_title {
1.416     albertel 3764:   font: bold x-large $sans;
1.359     albertel 3765: }
                   3766: table#LC_title_bar td.LC_title_bar_domain_logo {
                   3767:   background: $sidebg;
                   3768:   text-align: right;
1.368     albertel 3769:   padding: 0px;
                   3770: }
                   3771: table#LC_title_bar td.LC_title_bar_role_logo {
                   3772:   background: $sidebg;
                   3773:   padding: 0px;
1.359     albertel 3774: }
                   3775: 
1.346     albertel 3776: table#LC_menubuttons_mainmenu {
                   3777:   background: $pgbg;
                   3778:   border: 0px;
                   3779:   border-spacing: 1px;
1.372     albertel 3780:   padding: 0px 1px;
1.346     albertel 3781:   margin: 0px;
                   3782:   border-collapse: separate;
                   3783: }
                   3784: table#LC_menubuttons img, table#LC_menubuttons_mainmenu img {
                   3785:   border: 0px;
                   3786: }
1.345     albertel 3787: table#LC_top_nav td {
                   3788:   background: $tabbg;
1.392     albertel 3789:   border: 0px;
1.407     albertel 3790:   font-size: small;
1.345     albertel 3791: }
                   3792: table#LC_top_nav td a, div#LC_top_nav a {
                   3793:   color: $font;
                   3794:   font-family: $sans;
                   3795: }
1.364     albertel 3796: table#LC_top_nav td.LC_top_nav_logo {
                   3797:   background: $tabbg;
1.432     albertel 3798:   text-align: left;
1.408     albertel 3799:   white-space: nowrap;
1.432     albertel 3800:   width: 31px;
1.408     albertel 3801: }
                   3802: table#LC_top_nav td.LC_top_nav_logo img {
1.432     albertel 3803:   border: 0px;
1.408     albertel 3804:   vertical-align: bottom;
1.364     albertel 3805: }
1.432     albertel 3806: table#LC_top_nav td.LC_top_nav_exit,
                   3807: table#LC_top_nav td.LC_top_nav_help {
                   3808:   width: 2.0em;
                   3809: }
1.442     albertel 3810: table#LC_top_nav td.LC_top_nav_login {
                   3811:   width: 4.0em;
                   3812:   text-align: center;
                   3813: }
1.409     albertel 3814: table.LC_breadcrumbs td, table.LC_docs_path td  {
1.357     albertel 3815:   background: $tabbg;
                   3816:   color: $font;
                   3817:   font-family: $sans;
1.358     albertel 3818:   font-size: smaller;
1.357     albertel 3819: }
1.411     albertel 3820: table.LC_breadcrumbs td.LC_breadcrumbs_component,
1.409     albertel 3821: table.LC_docs_path td.LC_docs_path_component {
1.357     albertel 3822:   background: $tabbg;
                   3823:   color: $font;
                   3824:   font-family: $sans;
                   3825:   font-size: larger;
                   3826:   text-align: right;
                   3827: }
1.383     albertel 3828: td.LC_table_cell_checkbox {
                   3829:   text-align: center;
                   3830: }
                   3831: 
1.346     albertel 3832: .LC_menubuttons_inline_text {
                   3833:   color: $font;
                   3834:   font-family: $sans;
                   3835:   font-size: smaller;
                   3836: }
                   3837: 
                   3838: td.LC_menubuttons_text {
                   3839:   color: $font;
                   3840:   font-family: $sans;
                   3841: }
                   3842: td.LC_menubuttons_img {
                   3843:   background: $tabbg;
                   3844: }
                   3845: .LC_current_location {
                   3846:   font-family: $sans;
                   3847:   background: $tabbg;
                   3848: }
                   3849: .LC_new_mail {
                   3850:   font-family: $sans;
                   3851:   font-weight: bold;
                   3852: }
1.347     albertel 3853: 
1.440     albertel 3854: table.LC_aboutme_port {
                   3855:   border: 0px;
                   3856:   border-collapse: collapse;
                   3857:   border-spacing: 0px;
                   3858: }
1.349     albertel 3859: table.LC_data_table, table.LC_mail_list {
1.347     albertel 3860:   border: 1px solid #000000;
1.402     albertel 3861:   border-collapse: separate;
1.426     albertel 3862:   border-spacing: 1px;
1.347     albertel 3863: }
1.422     albertel 3864: .LC_data_table_dense {
                   3865:   font-size: small;
                   3866: }
1.507     raeburn  3867: table.LC_nested_outer {
                   3868:   border: 1px solid #000000;
                   3869:   border-collapse: separate;
                   3870:   border-spacing: 0px;
                   3871:   width: 100%;
                   3872: }
                   3873: table.LC_nested {
                   3874:   border: 0px;
                   3875:   border-collapse: separate;
                   3876:   border-spacing: 0px;
                   3877:   width: 100%;
                   3878: }
1.349     albertel 3879: table.LC_data_table tr th, table.LC_calendar tr th, table.LC_mail_list tr th {
                   3880:   font-weight: bold;
                   3881:   background-color: $data_table_head;
1.421     albertel 3882:   font-size: smaller;
1.347     albertel 3883: }
1.440     albertel 3884: table.LC_data_table tr td, 
                   3885: table.LC_aboutme_port tr td {
1.349     albertel 3886:   background-color: $data_table_light;
1.425     albertel 3887:   padding: 2px;
1.347     albertel 3888: }
1.440     albertel 3889: table.LC_data_table tr.LC_even_row td,
                   3890: table.LC_aboutme_port tr.LC_even_row td {
1.349     albertel 3891:   background-color: $data_table_dark;
1.347     albertel 3892: }
1.425     albertel 3893: table.LC_data_table tr.LC_data_table_highlight td {
                   3894:   background-color: $data_table_darker;
                   3895: }
1.451     albertel 3896: table.LC_data_table tr.LC_empty_row td,
1.507     raeburn  3897: table.LC_nested tr.LC_empty_row td {
1.347     albertel 3898:   background-color: #FFFFFF;
1.421     albertel 3899:   font-weight: bold;
                   3900:   font-style: italic;
                   3901:   text-align: center;
                   3902:   padding: 8px;
1.347     albertel 3903: }
1.507     raeburn  3904: table.LC_nested tr.LC_empty_row td {
1.465     albertel 3905:   padding: 4ex
                   3906: }
1.507     raeburn  3907: table.LC_nested_outer tr th {
                   3908:   font-weight: bold;
                   3909:   background-color: $data_table_head;
                   3910:   font-size: smaller;
                   3911:   border-bottom: 1px solid #000000;
                   3912: }
                   3913: table.LC_nested_outer tr td.LC_subheader {
                   3914:   background-color: $data_table_head;
                   3915:   font-weight: bold;
                   3916:   font-size: small;
                   3917:   border-bottom: 1px solid #000000;
                   3918:   text-align: right;
1.451     albertel 3919: }
1.507     raeburn  3920: table.LC_nested tr.LC_info_row td {
1.451     albertel 3921:   background-color: #CCC;
                   3922:   font-weight: bold;
                   3923:   font-size: small;
1.507     raeburn  3924:   text-align: center;
                   3925: }
                   3926: table.LC_nested tr.LC_info_row td.LC_left_item {
                   3927:   text-align: left;
1.451     albertel 3928: }
1.507     raeburn  3929: table.LC_nested td {
1.451     albertel 3930:   background-color: #FFF;
                   3931:   font-size: small;
1.507     raeburn  3932: }
                   3933: table.LC_nested_outer tr th.LC_right_item,
                   3934: table.LC_nested tr.LC_info_row td.LC_right_item,
                   3935: table.LC_nested tr.LC_odd_row td.LC_right_item,
                   3936: table.LC_nested tr td.LC_right_item {
1.451     albertel 3937:   text-align: right;
                   3938: }
                   3939: 
1.507     raeburn  3940: table.LC_nested tr.LC_odd_row td {
1.451     albertel 3941:   background-color: #EEE;
                   3942: }
                   3943: 
1.473     raeburn  3944: table.LC_createuser {
                   3945: }
                   3946: 
                   3947: table.LC_createuser tr.LC_section_row td {
                   3948:   font-size: smaller;
                   3949: }
                   3950: 
                   3951: table.LC_createuser tr.LC_info_row td  {
                   3952:   background-color: #CCC;
                   3953:   font-weight: bold;
                   3954:   text-align: center;
                   3955: }
                   3956: 
1.349     albertel 3957: table.LC_calendar {
                   3958:   border: 1px solid #000000;
                   3959:   border-collapse: collapse;
                   3960: }
                   3961: table.LC_calendar_pickdate {
                   3962:   font-size: xx-small;
                   3963: }
                   3964: table.LC_calendar tr td {
                   3965:   border: 1px solid #000000;
                   3966:   vertical-align: top;
                   3967: }
                   3968: table.LC_calendar tr td.LC_calendar_day_empty {
                   3969:   background-color: $data_table_dark;
                   3970: }
                   3971: table.LC_calendar tr td.LC_calendar_day_current {
                   3972:   background-color: $data_table_highlight;
                   3973: }
                   3974: 
                   3975: table.LC_mail_list tr.LC_mail_new {
                   3976:   background-color: $mail_new;
                   3977: }
                   3978: table.LC_mail_list tr.LC_mail_new:hover {
                   3979:   background-color: $mail_new_hover;
                   3980: }
                   3981: table.LC_mail_list tr.LC_mail_read {
                   3982:   background-color: $mail_read;
                   3983: }
                   3984: table.LC_mail_list tr.LC_mail_read:hover {
                   3985:   background-color: $mail_read_hover;
                   3986: }
                   3987: table.LC_mail_list tr.LC_mail_replied {
                   3988:   background-color: $mail_replied;
                   3989: }
                   3990: table.LC_mail_list tr.LC_mail_replied:hover {
                   3991:   background-color: $mail_replied_hover;
                   3992: }
                   3993: table.LC_mail_list tr.LC_mail_other {
                   3994:   background-color: $mail_other;
                   3995: }
                   3996: table.LC_mail_list tr.LC_mail_other:hover {
                   3997:   background-color: $mail_other_hover;
                   3998: }
1.494     raeburn  3999: table.LC_mail_list tr.LC_mail_even {
                   4000: }
                   4001: table.LC_mail_list tr.LC_mail_odd {
                   4002: }
                   4003: 
1.385     albertel 4004: 
1.386     albertel 4005: table#LC_portfolio_actions {
                   4006:   width: auto;
                   4007:   background: $pgbg;
                   4008:   border: 0px;
                   4009:   border-spacing: 2px 2px;
                   4010:   padding: 0px;
                   4011:   margin: 0px;
                   4012:   border-collapse: separate;
                   4013: }
                   4014: table#LC_portfolio_actions td.LC_label {
                   4015:   background: $tabbg;
                   4016:   text-align: right;
                   4017: }
                   4018: table#LC_portfolio_actions td.LC_value {
                   4019:   background: $tabbg;
                   4020: }
1.385     albertel 4021: 
1.391     albertel 4022: table#LC_cstr_controls {
                   4023:   width: 100%;
                   4024:   border-collapse: collapse;
                   4025: }
                   4026: table#LC_cstr_controls tr td {
                   4027:   border: 4px solid $pgbg;
                   4028:   padding: 4px;
                   4029:   text-align: center;
                   4030:   background: $tabbg;
                   4031: }
                   4032: table#LC_cstr_controls tr th {
                   4033:   border: 4px solid $pgbg;
                   4034:   background: $table_header;
                   4035:   text-align: center;
                   4036:   font-family: $sans;
                   4037:   font-size: smaller;
                   4038: }
                   4039: 
1.389     albertel 4040: table#LC_browser {
                   4041:  
                   4042: }
                   4043: table#LC_browser tr th {
1.391     albertel 4044:   background: $table_header;
1.389     albertel 4045: }
1.390     albertel 4046: table#LC_browser tr td {
                   4047:   padding: 2px;
                   4048: }
1.389     albertel 4049: table#LC_browser tr.LC_browser_file,
                   4050: table#LC_browser tr.LC_browser_file_published {
                   4051:   background: #CCFF88;
                   4052: }
                   4053: table#LC_browser tr.LC_browser_file_locked,
                   4054: table#LC_browser tr.LC_browser_file_unpublished {
                   4055:   background: #FFAA99;
1.387     albertel 4056: }
1.389     albertel 4057: table#LC_browser tr.LC_browser_file_obsolete {
                   4058:   background: #AAAAAA;
1.387     albertel 4059: }
1.455     albertel 4060: table#LC_browser tr.LC_browser_file_modified,
                   4061: table#LC_browser tr.LC_browser_file_metamodified {
1.389     albertel 4062:   background: #FFFF77;
1.387     albertel 4063: }
1.389     albertel 4064: table#LC_browser tr.LC_browser_folder {
                   4065:   background: #CCCCFF;
1.387     albertel 4066: }
1.388     albertel 4067: span.LC_current_location {
                   4068:   font-size: x-large;
                   4069:   background: $pgbg;
                   4070: }
1.387     albertel 4071: 
1.395     albertel 4072: span.LC_parm_menu_item {
                   4073:   font-size: larger;
                   4074:   font-family: $sans;
                   4075: }
                   4076: span.LC_parm_scope_all {
                   4077:   color: red;
                   4078: }
                   4079: span.LC_parm_scope_folder {
                   4080:   color: green;
                   4081: }
                   4082: span.LC_parm_scope_resource {
                   4083:   color: orange;
                   4084: }
                   4085: span.LC_parm_part {
                   4086:   color: blue;
                   4087: }
                   4088: span.LC_parm_folder, span.LC_parm_symb {
                   4089:   font-size: x-small;
                   4090:   font-family: $mono;
                   4091:   color: #AAAAAA;
                   4092: }
                   4093: 
1.396     albertel 4094: td.LC_parm_overview_level_menu, td.LC_parm_overview_map_menu,
                   4095: td.LC_parm_overview_parm_selectors, td.LC_parm_overview_parm_restrictions {
                   4096:   border: 1px solid black;
                   4097:   border-collapse: collapse;
                   4098: }
                   4099: table.LC_parm_overview_restrictions td {
                   4100:   border-width: 1px 4px 1px 4px;
                   4101:   border-style: solid;
                   4102:   border-color: $pgbg;
                   4103:   text-align: center;
                   4104: }
                   4105: table.LC_parm_overview_restrictions th {
                   4106:   background: $tabbg;
                   4107:   border-width: 1px 4px 1px 4px;
                   4108:   border-style: solid;
                   4109:   border-color: $pgbg;
                   4110: }
1.398     albertel 4111: table#LC_helpmenu {
                   4112:   border: 0px;
                   4113:   height: 55px;
                   4114:   border-spacing: 0px;
                   4115: }
                   4116: 
                   4117: table#LC_helpmenu fieldset legend {
                   4118:   font-size: larger;
                   4119:   font-weight: bold;
                   4120: }
1.397     albertel 4121: table#LC_helpmenu_links {
                   4122:   width: 100%;
                   4123:   border: 1px solid black;
                   4124:   background: $pgbg;
                   4125:   padding: 0px;
                   4126:   border-spacing: 1px;
                   4127: }
                   4128: table#LC_helpmenu_links tr td {
                   4129:   padding: 1px;
                   4130:   background: $tabbg;
1.399     albertel 4131:   text-align: center;
                   4132:   font-weight: bold;
1.397     albertel 4133: }
1.396     albertel 4134: 
1.397     albertel 4135: table#LC_helpmenu_links a:link, table#LC_helpmenu_links a:visited,
                   4136: table#LC_helpmenu_links a:active {
                   4137:   text-decoration: none;
                   4138:   color: $font;
                   4139: }
                   4140: table#LC_helpmenu_links a:hover {
                   4141:   text-decoration: underline;
                   4142:   color: $vlink;
                   4143: }
1.396     albertel 4144: 
1.417     albertel 4145: .LC_chrt_popup_exists {
                   4146:   border: 1px solid #339933;
                   4147:   margin: -1px;
                   4148: }
                   4149: .LC_chrt_popup_up {
                   4150:   border: 1px solid yellow;
                   4151:   margin: -1px;
                   4152: }
                   4153: .LC_chrt_popup {
                   4154:   border: 1px solid #8888FF;
                   4155:   background: #CCCCFF;
                   4156: }
                   4157: 
1.421     albertel 4158: table.LC_pick_box {
                   4159:   width: 100%;
                   4160:   border-collapse: separate;
                   4161:   background: white;
                   4162:   border: 1px solid black;
                   4163:   border-spacing: 1px;
                   4164: }
                   4165: table.LC_pick_box td.LC_pick_box_title {
                   4166:   background: $tabbg;
                   4167:   font-weight: bold;
                   4168:   text-align: right;
                   4169:   width: 184px;
                   4170:   padding: 8px;
                   4171: }
1.424     albertel 4172: table.LC_pick_box td.LC_pick_box_separator {
1.421     albertel 4173:   padding: 0px;
                   4174:   height: 1px;
                   4175:   background: black;
                   4176: }
                   4177: table.LC_pick_box td.LC_pick_box_submit {
                   4178:   text-align: right;
                   4179: }
                   4180: 
1.424     albertel 4181: table.LC_group_priv_box {
                   4182:   background: white;
                   4183:   border: 1px solid black;
                   4184:   border-spacing: 1px;
                   4185: }
                   4186: table.LC_group_priv_box td.LC_pick_box_title {
                   4187:   background: $tabbg;
                   4188:   font-weight: bold;
                   4189:   text-align: right;
                   4190:   width: 184px;
                   4191: }
                   4192: table.LC_group_priv_box td.LC_groups_fixed {
                   4193:   background: $data_table_light;
                   4194:   text-align: center;
                   4195: }
                   4196: table.LC_group_priv_box td.LC_groups_optional {
                   4197:   background: $data_table_dark;
                   4198:   text-align: center;
                   4199: }
                   4200: table.LC_group_priv_box td.LC_groups_functionality {
                   4201:   background: $data_table_darker;
                   4202:   text-align: center;
                   4203:   font-weight: bold;
                   4204: }
                   4205: table.LC_group_priv td {
                   4206:   text-align: left;
                   4207:   padding: 0px;
                   4208: }
                   4209: 
1.421     albertel 4210: table.LC_notify_front_page {
                   4211:   background: white;
                   4212:   border: 1px solid black;
                   4213:   padding: 8px;
                   4214: }
                   4215: table.LC_notify_front_page td {
                   4216:   padding: 8px;
                   4217: }
1.424     albertel 4218: .LC_navbuttons {
                   4219:   margin: 2ex 0ex 2ex 0ex;
                   4220: }
1.423     albertel 4221: .LC_topic_bar {
                   4222:   font-family: $sans;
                   4223:   font-weight: bold;
                   4224:   width: 100%;
                   4225:   background: $tabbg;
                   4226:   vertical-align: middle;
                   4227:   margin: 2ex 0ex 2ex 0ex;
                   4228: }
                   4229: .LC_topic_bar span {
                   4230:   vertical-align: middle;
                   4231: }
                   4232: .LC_topic_bar img {
                   4233:   vertical-align: bottom;
                   4234: }
                   4235: table.LC_course_group_status {
                   4236:   margin: 20px;
                   4237: }
                   4238: table.LC_status_selector td {
                   4239:   vertical-align: top;
                   4240:   text-align: center;
1.424     albertel 4241:   padding: 4px;
                   4242: }
                   4243: table.LC_descriptive_input td.LC_description {
                   4244:   vertical-align: top;
                   4245:   text-align: right;
                   4246:   font-weight: bold;
1.423     albertel 4247: }
1.489     raeburn  4248: table.LC_feedback_link {
                   4249:     background: $feedback_link_bg;
                   4250: }
                   4251: span.LC_feedback_link {
                   4252:     background: $feedback_link_bg;
                   4253:     font-size: larger;
                   4254: }
1.421     albertel 4255: 
1.515     albertel 4256: table.LC_prior_tries {
                   4257:     border-width: 1px;
                   4258:     border-style: solid;
                   4259:     border-color: gray;
                   4260:     border-collapse: collapse;
                   4261: }
                   4262: table.LC_prior_tries th,
                   4263: table.LC_prior_tries td {
                   4264:     border-width: 1px;
                   4265:     border-style: solid;
                   4266:     border-color: gray;
                   4267:     padding: 3px;
                   4268: }
                   4269: table.LC_prior_tries tr.LC_correct {
                   4270:     font-weight: bold;
                   4271:     background: #aaffaa;
                   4272: }
                   4273: span.LC_prior_numerical {
                   4274:     font-family: monospace;
                   4275:     white-space: pre;
                   4276: }
                   4277: 
1.343     albertel 4278: END
                   4279: }
                   4280: 
1.306     albertel 4281: =pod
                   4282: 
                   4283: =over 4
                   4284: 
                   4285: =item * &headtag()
                   4286: 
                   4287: Returns a uniform footer for LON-CAPA web pages.
                   4288: 
1.307     albertel 4289: Inputs: $title - optional title for the head
                   4290:         $head_extra - optional extra HTML to put inside the <head>
1.315     albertel 4291:         $args - optional arguments
1.319     albertel 4292:             force_register - if is true call registerurl so the remote is 
                   4293:                              informed
1.415     albertel 4294:             redirect       -> array ref of
                   4295:                                    1- seconds before redirect occurs
                   4296:                                    2- url to redirect to
                   4297:                                    3- whether the side effect should occur
1.315     albertel 4298:                            (side effect of setting 
                   4299:                                $env{'internal.head.redirect'} to the url 
                   4300:                                redirected too)
1.352     albertel 4301:             domain         -> force to color decorate a page for a specific
                   4302:                                domain
                   4303:             function       -> force usage of a specific rolish color scheme
                   4304:             bgcolor        -> override the default page bgcolor
1.460     albertel 4305:             no_auto_mt_title
                   4306:                            -> prevent &mt()ing the title arg
1.464     albertel 4307: 
1.306     albertel 4308: =back
                   4309: 
                   4310: =cut
                   4311: 
                   4312: sub headtag {
1.313     albertel 4313:     my ($title,$head_extra,$args) = @_;
1.306     albertel 4314:     
1.363     albertel 4315:     my $function = $args->{'function'} || &get_users_function();
                   4316:     my $domain   = $args->{'domain'}   || &determinedomain();
                   4317:     my $bgcolor  = $args->{'bgcolor'}  || &designparm($function.'.pgbg',$domain);
1.418     albertel 4318:     my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458     albertel 4319: 		   $Apache::lonnet::perlvar{'lonVersion'},
1.418     albertel 4320: 		   #time(),
                   4321: 		   $env{'environment.color.timestamp'},
1.363     albertel 4322: 		   $function,$domain,$bgcolor);
                   4323: 
1.369     www      4324:     $url = '/adm/css/'.&escape($url).'.css';
1.363     albertel 4325: 
1.308     albertel 4326:     my $result =
                   4327: 	'<head>'.
1.461     albertel 4328: 	&font_settings();
1.319     albertel 4329: 
1.461     albertel 4330:     if (!$args->{'frameset'}) {
                   4331: 	$result .= &Apache::lonhtmlcommon::htmlareaheaders();
                   4332:     }
1.319     albertel 4333:     if ($args->{'force_register'}) {
                   4334: 	$result .= &Apache::lonmenu::registerurl(1);
                   4335:     }
1.436     albertel 4336:     if (!$args->{'no_nav_bar'} 
                   4337: 	&& !$args->{'only_body'}
                   4338: 	&& !$args->{'frameset'}) {
                   4339: 	$result .= &help_menu_js();
                   4340:     }
1.319     albertel 4341: 
1.314     albertel 4342:     if (ref($args->{'redirect'})) {
1.414     albertel 4343: 	my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315     albertel 4344: 	$url = &Apache::lonenc::check_encrypt($url);
1.414     albertel 4345: 	if (!$inhibit_continue) {
                   4346: 	    $env{'internal.head.redirect'} = $url;
                   4347: 	}
1.313     albertel 4348: 	$result.=<<ADDMETA
                   4349: <meta http-equiv="pragma" content="no-cache" />
1.344     albertel 4350: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313     albertel 4351: ADDMETA
                   4352:     }
1.306     albertel 4353:     if (!defined($title)) {
                   4354: 	$title = 'The LearningOnline Network with CAPA';
                   4355:     }
1.460     albertel 4356:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
                   4357:     $result .= '<title> LON-CAPA '.$title.'</title>'
1.414     albertel 4358: 	.'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
                   4359: 	.$head_extra;
1.306     albertel 4360:     return $result;
                   4361: }
                   4362: 
                   4363: =pod
                   4364: 
                   4365: =over 4
                   4366: 
1.340     albertel 4367: =item * &font_settings()
                   4368: 
                   4369: Returns neccessary <meta> to set the proper encoding
                   4370: 
                   4371: Inputs: none
                   4372: 
                   4373: =back
                   4374: 
                   4375: =cut
                   4376: 
                   4377: sub font_settings {
                   4378:     my $headerstring='';
                   4379:     if (($env{'browser.os'} eq 'mac') && (!$env{'browser.mathml'})) { 
                   4380: 	$headerstring.=
                   4381: 	    '<meta Content-Type="text/html; charset=x-mac-roman" />';
                   4382:     } elsif (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
                   4383: 	$headerstring.=
                   4384: 	    '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
                   4385:     }
                   4386:     return $headerstring;
                   4387: }
                   4388: 
1.341     albertel 4389: =pod
                   4390: 
                   4391: =over 4
                   4392: 
                   4393: =item * &xml_begin()
                   4394: 
                   4395: Returns the needed doctype and <html>
                   4396: 
                   4397: Inputs: none
                   4398: 
                   4399: =back
                   4400: 
                   4401: =cut
                   4402: 
                   4403: sub xml_begin {
                   4404:     my $output='';
                   4405: 
1.342     albertel 4406:     &Apache::lonhtmlcommon::init_htmlareafields();
                   4407: 
1.341     albertel 4408:     if ($env{'browser.mathml'}) {
                   4409: 	$output='<?xml version="1.0"?>'
                   4410:             #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
                   4411: #            .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
                   4412:             
                   4413: #	    .'<!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">] >'
                   4414: 	    .'<!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">'
                   4415:             .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" ' 
                   4416: 	    .'xmlns="http://www.w3.org/1999/xhtml">';
                   4417:     } else {
                   4418: 	$output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>';
                   4419:     }
                   4420:     return $output;
                   4421: }
1.340     albertel 4422: 
                   4423: =pod
                   4424: 
                   4425: =over 4
                   4426: 
1.306     albertel 4427: =item * &endheadtag()
                   4428: 
                   4429: Returns a uniform </head> for LON-CAPA web pages.
                   4430: 
                   4431: Inputs: none
                   4432: 
                   4433: =back
                   4434: 
                   4435: =cut
                   4436: 
                   4437: sub endheadtag {
                   4438:     return '</head>';
                   4439: }
                   4440: 
                   4441: =pod
                   4442: 
                   4443: =over 4
                   4444: 
                   4445: =item * &head()
                   4446: 
                   4447: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
                   4448: 
                   4449: Inputs: $title - optional title for the page
1.307     albertel 4450:         $head_extra - optional extra HTML to put inside the <head>
1.405     albertel 4451: 
1.306     albertel 4452: =back
                   4453: 
                   4454: =cut
                   4455: 
                   4456: sub head {
1.325     albertel 4457:     my ($title,$head_extra,$args) = @_;
                   4458:     return &headtag($title,$head_extra,$args).&endheadtag();
1.306     albertel 4459: }
                   4460: 
                   4461: =pod
                   4462: 
                   4463: =over 4
                   4464: 
                   4465: =item * &start_page()
                   4466: 
                   4467: Returns a complete <html> .. <body> section for LON-CAPA web pages.
                   4468: 
                   4469: Inputs: $title - optional title for the page
                   4470:         $head_extra - optional extra HTML to incude inside the <head>
1.315     albertel 4471:         $args - additional optional args supported are:
1.317     albertel 4472:                   only_body      -> is true will set &bodytag() onlybodytag
                   4473:                                     arg on
                   4474:                   no_nav_bar     -> is true will set &bodytag() notopbar arg on
                   4475:                   add_entries    -> additional attributes to add to the  <body>
                   4476:                   domain         -> force to color decorate a page for a 
                   4477:                                     specific domain
                   4478:                   function       -> force usage of a specific rolish color
                   4479:                                     scheme
                   4480:                   redirect       -> see &headtag()
                   4481:                   bgcolor        -> override the default page bg color
                   4482:                   js_ready       -> return a string ready for being used in 
                   4483:                                     a javascript writeln
1.320     albertel 4484:                   html_encode    -> return a string ready for being used in 
                   4485:                                     a html attribute
1.317     albertel 4486:                   force_register -> if is true will turn on the &bodytag()
                   4487:                                     $forcereg arg
1.326     albertel 4488:                   body_title     -> alternate text to use instead of $title
                   4489:                                     in the title box that appears, this text
                   4490:                                     is not auto translated like the $title is
1.330     albertel 4491:                   frameset       -> if true will start with a <frameset>
                   4492:                                     rather than <body>
1.338     albertel 4493:                   no_title       -> if true the title bar won't be shown
                   4494:                   skip_phases    -> hash ref of 
                   4495:                                     head -> skip the <html><head> generation
                   4496:                                     body -> skip all <body> generation
1.337     albertel 4497: 
1.361     albertel 4498:                   no_inline_link -> if true and in remote mode, don't show the 
                   4499:                                     'Switch To Inline Menu' link
                   4500: 
1.460     albertel 4501:                   no_auto_mt_title -> prevent &mt()ing the title arg
                   4502: 
1.306     albertel 4503: =back
                   4504: 
                   4505: =cut
                   4506: 
                   4507: sub start_page {
1.309     albertel 4508:     my ($title,$head_extra,$args) = @_;
1.318     albertel 4509:     #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313     albertel 4510:     my %head_args;
1.352     albertel 4511:     foreach my $arg ('redirect','force_register','domain','function',
1.460     albertel 4512: 		     'bgcolor','frameset','no_nav_bar','only_body',
                   4513: 		     'no_auto_mt_title') {
1.319     albertel 4514: 	if (defined($args->{$arg})) {
1.324     raeburn  4515: 	    $head_args{$arg} = $args->{$arg};
1.319     albertel 4516: 	}
1.313     albertel 4517:     }
1.319     albertel 4518: 
1.315     albertel 4519:     $env{'internal.start_page'}++;
1.338     albertel 4520:     my $result;
                   4521:     if (! exists($args->{'skip_phases'}{'head'}) ) {
                   4522: 	$result.=
1.341     albertel 4523: 	    &xml_begin().
1.338     albertel 4524: 	    &headtag($title,$head_extra,\%head_args).&endheadtag();
                   4525:     }
                   4526:     
                   4527:     if (! exists($args->{'skip_phases'}{'body'}) ) {
                   4528: 	if ($args->{'frameset'}) {
                   4529: 	    my $attr_string = &make_attr_string($args->{'force_register'},
                   4530: 						$args->{'add_entries'});
                   4531: 	    $result .= "\n<frameset $attr_string>\n";
                   4532: 	} else {
                   4533: 	    $result .=
                   4534: 		&bodytag($title, 
                   4535: 			 $args->{'function'},       $args->{'add_entries'},
                   4536: 			 $args->{'only_body'},      $args->{'domain'},
                   4537: 			 $args->{'force_register'}, $args->{'body_title'},
                   4538: 			 $args->{'no_nav_bar'},     $args->{'bgcolor'},
1.460     albertel 4539: 			 $args->{'no_title'},       $args->{'no_inline_link'},
                   4540: 			 $args);
1.338     albertel 4541: 	}
1.330     albertel 4542:     }
1.338     albertel 4543: 
1.315     albertel 4544:     if ($args->{'js_ready'}) {
1.317     albertel 4545: 	$result = &js_ready($result);
1.315     albertel 4546:     }
1.320     albertel 4547:     if ($args->{'html_encode'}) {
                   4548: 	$result = &html_encode($result);
                   4549:     }
1.315     albertel 4550:     return $result;
1.306     albertel 4551: }
                   4552: 
1.330     albertel 4553: 
1.306     albertel 4554: =pod
                   4555: 
                   4556: =over 4
                   4557: 
                   4558: =item * &head()
                   4559: 
                   4560: Returns a complete </body></html> section for LON-CAPA web pages.
                   4561: 
1.315     albertel 4562: Inputs:         $args - additional optional args supported are:
                   4563:                  js_ready     -> return a string ready for being used in 
                   4564:                                  a javascript writeln
1.320     albertel 4565:                  html_encode  -> return a string ready for being used in 
                   4566:                                  a html attribute
1.330     albertel 4567:                  frameset     -> if true will start with a <frameset>
                   4568:                                  rather than <body>
1.493     albertel 4569:                  dicsussion   -> if true will get discussion from
                   4570:                                   lonxml::xmlend
                   4571:                                  (you can pass the target and parser arguments
                   4572:                                   through optional 'target' and 'parser' args
                   4573:                                   to this routine)
1.306     albertel 4574: 
                   4575: =cut
                   4576: 
                   4577: sub end_page {
1.315     albertel 4578:     my ($args) = @_;
                   4579:     $env{'internal.end_page'}++;
1.330     albertel 4580:     my $result;
1.335     albertel 4581:     if ($args->{'discussion'}) {
                   4582: 	my ($target,$parser);
                   4583: 	if (ref($args->{'discussion'})) {
                   4584: 	    ($target,$parser) =($args->{'discussion'}{'target'},
                   4585: 				$args->{'discussion'}{'parser'});
                   4586: 	}
                   4587: 	$result .= &Apache::lonxml::xmlend($target,$parser);
                   4588:     }
                   4589: 
1.330     albertel 4590:     if ($args->{'frameset'}) {
                   4591: 	$result .= '</frameset>';
                   4592:     } else {
                   4593: 	$result .= &endbodytag();
                   4594:     }
                   4595:     $result .= "\n</html>";
                   4596: 
1.315     albertel 4597:     if ($args->{'js_ready'}) {
1.317     albertel 4598: 	$result = &js_ready($result);
1.315     albertel 4599:     }
1.335     albertel 4600: 
1.320     albertel 4601:     if ($args->{'html_encode'}) {
                   4602: 	$result = &html_encode($result);
                   4603:     }
1.335     albertel 4604: 
1.315     albertel 4605:     return $result;
                   4606: }
                   4607: 
1.320     albertel 4608: sub html_encode {
                   4609:     my ($result) = @_;
                   4610: 
1.322     albertel 4611:     $result = &HTML::Entities::encode($result,'<>&"');
1.320     albertel 4612:     
                   4613:     return $result;
                   4614: }
1.317     albertel 4615: sub js_ready {
                   4616:     my ($result) = @_;
                   4617: 
1.323     albertel 4618:     $result =~ s/[\n\r]/ /xmsg;
                   4619:     $result =~ s/\\/\\\\/xmsg;
                   4620:     $result =~ s/'/\\'/xmsg;
1.372     albertel 4621:     $result =~ s{</}{<\\/}xmsg;
1.317     albertel 4622:     
                   4623:     return $result;
                   4624: }
                   4625: 
1.315     albertel 4626: sub validate_page {
                   4627:     if (  exists($env{'internal.start_page'})
1.316     albertel 4628: 	  &&     $env{'internal.start_page'} > 1) {
                   4629: 	&Apache::lonnet::logthis('start_page called multiple times '.
1.318     albertel 4630: 				 $env{'internal.start_page'}.' '.
1.316     albertel 4631: 				 $ENV{'request.filename'});
1.315     albertel 4632:     }
                   4633:     if (  exists($env{'internal.end_page'})
1.316     albertel 4634: 	  &&     $env{'internal.end_page'} > 1) {
                   4635: 	&Apache::lonnet::logthis('end_page called multiple times '.
1.318     albertel 4636: 				 $env{'internal.end_page'}.' '.
1.316     albertel 4637: 				 $env{'request.filename'});
1.315     albertel 4638:     }
                   4639:     if (     exists($env{'internal.start_page'})
                   4640: 	&& ! exists($env{'internal.end_page'})) {
1.316     albertel 4641: 	&Apache::lonnet::logthis('start_page called without end_page '.
                   4642: 				 $env{'request.filename'});
1.315     albertel 4643:     }
                   4644:     if (   ! exists($env{'internal.start_page'})
                   4645: 	&&   exists($env{'internal.end_page'})) {
1.316     albertel 4646: 	&Apache::lonnet::logthis('end_page called without start_page'.
                   4647: 				 $env{'request.filename'});
1.315     albertel 4648:     }
1.306     albertel 4649: }
1.315     albertel 4650: 
1.318     albertel 4651: sub simple_error_page {
                   4652:     my ($r,$title,$msg) = @_;
                   4653:     my $page =
                   4654: 	&Apache::loncommon::start_page($title).
                   4655: 	&mt($msg).
                   4656: 	&Apache::loncommon::end_page();
                   4657:     if (ref($r)) {
                   4658: 	$r->print($page);
1.327     albertel 4659: 	return;
1.318     albertel 4660:     }
                   4661:     return $page;
                   4662: }
1.347     albertel 4663: 
                   4664: {
                   4665:     my $row_count;
                   4666:     sub start_data_table {
1.422     albertel 4667: 	my ($add_class) = @_;
                   4668: 	my $css_class = (join(' ','LC_data_table',$add_class));
1.347     albertel 4669: 	undef($row_count);
1.422     albertel 4670: 	return '<table class="'.$css_class.'">'."\n";
1.347     albertel 4671:     }
                   4672: 
                   4673:     sub end_data_table {
                   4674: 	undef($row_count);
1.389     albertel 4675: 	return '</table>'."\n";;
1.347     albertel 4676:     }
                   4677: 
                   4678:     sub start_data_table_row {
1.422     albertel 4679: 	my ($add_class) = @_;
1.347     albertel 4680: 	$row_count++;
1.422     albertel 4681: 	my $css_class = ($row_count % 2)?'':'LC_even_row';
1.428     albertel 4682: 	$css_class = (join(' ',$css_class,$add_class));
1.422     albertel 4683: 	return  '<tr class="'.$css_class.'">'."\n";;
1.347     albertel 4684:     }
1.471     banghart 4685:     
                   4686:     sub continue_data_table_row {
                   4687: 	my ($add_class) = @_;
                   4688: 	my $css_class = ($row_count % 2)?'':'LC_even_row';
                   4689: 	$css_class = (join(' ',$css_class,$add_class));
                   4690: 	return  '<tr class="'.$css_class.'">'."\n";;
                   4691:     }
1.347     albertel 4692: 
                   4693:     sub end_data_table_row {
1.389     albertel 4694: 	return '</tr>'."\n";;
1.347     albertel 4695:     }
1.367     www      4696: 
1.421     albertel 4697:     sub start_data_table_empty_row {
                   4698: 	$row_count++;
                   4699: 	return  '<tr class="LC_empty_row" >'."\n";;
                   4700:     }
                   4701: 
                   4702:     sub end_data_table_empty_row {
                   4703: 	return '</tr>'."\n";;
                   4704:     }
                   4705: 
1.367     www      4706:     sub start_data_table_header_row {
1.389     albertel 4707: 	return  '<tr class="LC_header_row">'."\n";;
1.367     www      4708:     }
                   4709: 
                   4710:     sub end_data_table_header_row {
1.389     albertel 4711: 	return '</tr>'."\n";;
1.367     www      4712:     }
1.347     albertel 4713: }
                   4714: 
1.251     albertel 4715: ###############################################
1.182     matthew  4716: 
                   4717: =pod
                   4718: 
1.405     albertel 4719: =item * &get_users_function()
1.182     matthew  4720: 
                   4721: Used by &bodytag to determine the current users primary role.
                   4722: Returns either 'student','coordinator','admin', or 'author'.
                   4723: 
                   4724: =cut
                   4725: 
                   4726: ###############################################
                   4727: sub get_users_function {
                   4728:     my $function = 'student';
1.258     albertel 4729:     if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
1.182     matthew  4730:         $function='coordinator';
                   4731:     }
1.258     albertel 4732:     if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182     matthew  4733:         $function='admin';
                   4734:     }
1.258     albertel 4735:     if (($env{'request.role'}=~/^(au|ca)/) ||
1.182     matthew  4736:         ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
                   4737:         $function='author';
                   4738:     }
                   4739:     return $function;
1.54      www      4740: }
1.99      www      4741: 
                   4742: ###############################################
                   4743: 
1.233     raeburn  4744: =pod
                   4745: 
1.405     albertel 4746: =item * &check_user_status
1.274     raeburn  4747: 
                   4748: Determines current status of supplied role for a
                   4749: specific user. Roles can be active, previous or future.
                   4750: 
                   4751: Inputs: 
                   4752: user's domain, user's username, course's domain,
1.375     raeburn  4753: course's number, optional section ID.
1.274     raeburn  4754: 
                   4755: Outputs:
                   4756: role status: active, previous or future. 
                   4757: 
                   4758: =cut
                   4759: 
                   4760: sub check_user_status {
1.412     raeburn  4761:     my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274     raeburn  4762:     my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
                   4763:     my @uroles = keys %userinfo;
                   4764:     my $srchstr;
                   4765:     my $active_chk = 'none';
1.412     raeburn  4766:     my $now = time;
1.274     raeburn  4767:     if (@uroles > 0) {
1.412     raeburn  4768:         if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
1.274     raeburn  4769:             $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
                   4770:         } else {
1.412     raeburn  4771:             $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
                   4772:         }
                   4773:         if (grep/^\Q$srchstr\E$/,@uroles) {
1.274     raeburn  4774:             my $role_end = 0;
                   4775:             my $role_start = 0;
                   4776:             $active_chk = 'active';
1.412     raeburn  4777:             if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
                   4778:                 $role_end = $1;
                   4779:                 if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
                   4780:                     $role_start = $1;
1.274     raeburn  4781:                 }
                   4782:             }
                   4783:             if ($role_start > 0) {
1.412     raeburn  4784:                 if ($now < $role_start) {
1.274     raeburn  4785:                     $active_chk = 'future';
                   4786:                 }
                   4787:             }
                   4788:             if ($role_end > 0) {
1.412     raeburn  4789:                 if ($now > $role_end) {
1.274     raeburn  4790:                     $active_chk = 'previous';
                   4791:                 }
                   4792:             }
                   4793:         }
                   4794:     }
                   4795:     return $active_chk;
                   4796: }
                   4797: 
                   4798: ###############################################
                   4799: 
                   4800: =pod
                   4801: 
1.405     albertel 4802: =item * &get_sections()
1.233     raeburn  4803: 
                   4804: Determines all the sections for a course including
                   4805: sections with students and sections containing other roles.
1.419     raeburn  4806: Incoming parameters: 
                   4807: 
                   4808: 1. domain
                   4809: 2. course number 
                   4810: 3. reference to array containing roles for which sections should 
                   4811: be gathered (optional).
                   4812: 4. reference to array containing status types for which sections 
                   4813: should be gathered (optional).
                   4814: 
                   4815: If the third argument is undefined, sections are gathered for any role. 
                   4816: If the fourth argument is undefined, sections are gathered for any status.
                   4817: Permissible values are 'active' or 'future' or 'previous'.
1.233     raeburn  4818:  
1.374     raeburn  4819: Returns section hash (keys are section IDs, values are
                   4820: number of users in each section), subject to the
1.419     raeburn  4821: optional roles filter, optional status filter 
1.233     raeburn  4822: 
                   4823: =cut
                   4824: 
                   4825: ###############################################
                   4826: sub get_sections {
1.419     raeburn  4827:     my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366     albertel 4828:     if (!defined($cdom) || !defined($cnum)) {
                   4829:         my $cid =  $env{'request.course.id'};
                   4830: 
                   4831: 	return if (!defined($cid));
                   4832: 
                   4833:         $cdom = $env{'course.'.$cid.'.domain'};
                   4834:         $cnum = $env{'course.'.$cid.'.num'};
                   4835:     }
                   4836: 
                   4837:     my %sectioncount;
1.419     raeburn  4838:     my $now = time;
1.240     albertel 4839: 
1.366     albertel 4840:     if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276     albertel 4841: 	my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240     albertel 4842: 	my $sec_index = &Apache::loncoursedata::CL_SECTION();
                   4843: 	my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419     raeburn  4844:         my $start_index = &Apache::loncoursedata::CL_START();
                   4845:         my $end_index = &Apache::loncoursedata::CL_END();
                   4846:         my $status;
1.366     albertel 4847: 	while (my ($student,$data) = each(%$classlist)) {
1.419     raeburn  4848: 	    my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
                   4849: 				                     $data->[$status_index],
                   4850:                                                      $data->[$start_index],
                   4851:                                                      $data->[$end_index]);
                   4852:             if ($stu_status eq 'Active') {
                   4853:                 $status = 'active';
                   4854:             } elsif ($end < $now) {
                   4855:                 $status = 'previous';
                   4856:             } elsif ($start > $now) {
                   4857:                 $status = 'future';
                   4858:             } 
                   4859: 	    if ($section ne '-1' && $section !~ /^\s*$/) {
                   4860:                 if ((!defined($possible_status)) || (($status ne '') && 
                   4861:                     (grep/^\Q$status\E$/,@{$possible_status}))) { 
                   4862: 		    $sectioncount{$section}++;
                   4863:                 }
1.240     albertel 4864: 	    }
                   4865: 	}
                   4866:     }
                   4867:     my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   4868:     foreach my $user (sort(keys(%courseroles))) {
                   4869: 	if ($user !~ /^(\w{2})/) { next; }
                   4870: 	my ($role) = ($user =~ /^(\w{2})/);
                   4871: 	if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419     raeburn  4872: 	my ($section,$status);
1.240     albertel 4873: 	if ($role eq 'cr' &&
                   4874: 	    $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
                   4875: 	    $section=$1;
                   4876: 	}
                   4877: 	if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
                   4878: 	if (!defined($section) || $section eq '-1') { next; }
1.419     raeburn  4879:         my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
                   4880:         if ($end == -1 && $start == -1) {
                   4881:             next; #deleted role
                   4882:         }
                   4883:         if (!defined($possible_status)) { 
                   4884:             $sectioncount{$section}++;
                   4885:         } else {
                   4886:             if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
                   4887:                 $status = 'active';
                   4888:             } elsif ($end < $now) {
                   4889:                 $status = 'future';
                   4890:             } elsif ($start > $now) {
                   4891:                 $status = 'previous';
                   4892:             }
                   4893:             if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
                   4894:                 $sectioncount{$section}++;
                   4895:             }
                   4896:         }
1.233     raeburn  4897:     }
1.366     albertel 4898:     return %sectioncount;
1.233     raeburn  4899: }
                   4900: 
1.274     raeburn  4901: ###############################################
1.294     raeburn  4902: 
                   4903: =pod
1.405     albertel 4904: 
                   4905: =item * &get_course_users()
                   4906: 
1.275     raeburn  4907: Retrieves usernames:domains for users in the specified course
                   4908: with specific role(s), and access status. 
                   4909: 
                   4910: Incoming parameters:
1.277     albertel 4911: 1. course domain
                   4912: 2. course number
                   4913: 3. access status: users must have - either active, 
1.275     raeburn  4914: previous, future, or all.
1.277     albertel 4915: 4. reference to array of permissible roles
1.288     raeburn  4916: 5. reference to array of section restrictions (optional)
                   4917: 6. reference to results object (hash of hashes).
                   4918: 7. reference to optional userdata hash
1.275     raeburn  4919: Keys of top level hash are roles.
                   4920: Keys of inner hashes are username:domain, with 
                   4921: values set to access type.
1.288     raeburn  4922: Optional userdata hash returns an array with arguments in the 
                   4923: same order as loncoursedata::get_classlist() for student data.
                   4924: 
                   4925: Entries for end, start, section and status are blank because
                   4926: of the possibility of multiple values for non-student roles.
                   4927: 
1.275     raeburn  4928: =cut
1.405     albertel 4929: 
1.275     raeburn  4930: ###############################################
1.405     albertel 4931: 
1.275     raeburn  4932: sub get_course_users {
1.288     raeburn  4933:     my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata) = @_;
                   4934:     my %idx = ();
1.419     raeburn  4935:     my %seclists;
1.288     raeburn  4936: 
                   4937:     $idx{udom} = &Apache::loncoursedata::CL_SDOM();
                   4938:     $idx{uname} =  &Apache::loncoursedata::CL_SNAME();
                   4939:     $idx{end} = &Apache::loncoursedata::CL_END();
                   4940:     $idx{start} = &Apache::loncoursedata::CL_START();
                   4941:     $idx{id} = &Apache::loncoursedata::CL_ID();
                   4942:     $idx{section} = &Apache::loncoursedata::CL_SECTION();
                   4943:     $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
                   4944:     $idx{status} = &Apache::loncoursedata::CL_STATUS();
                   4945: 
1.290     albertel 4946:     if (grep(/^st$/,@{$roles})) {
1.276     albertel 4947:         my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278     raeburn  4948:         my $now = time;
1.277     albertel 4949:         foreach my $student (keys(%{$classlist})) {
1.288     raeburn  4950:             my $match = 0;
1.412     raeburn  4951:             my $secmatch = 0;
1.419     raeburn  4952:             my $section = $$classlist{$student}[$idx{section}];
                   4953:             if ($section eq '') {
                   4954:                 $section = 'none';
                   4955:             }
1.291     albertel 4956:             if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 4957:                 if (grep(/^all$/,@{$sections})) {
1.412     raeburn  4958:                     $secmatch = 1;
                   4959:                 } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420     albertel 4960:                     if (grep(/^none$/,@{$sections})) {
1.412     raeburn  4961:                         $secmatch = 1;
                   4962:                     }
                   4963:                 } else {  
1.419     raeburn  4964: 		    if (grep(/^\Q$section\E$/,@{$sections})) {
1.412     raeburn  4965: 		        $secmatch = 1;
                   4966:                     }
1.290     albertel 4967: 		}
1.412     raeburn  4968:                 if (!$secmatch) {
                   4969:                     next;
                   4970:                 }
1.419     raeburn  4971:             }
1.420     albertel 4972:             push(@{$seclists{$student}},$section); 
1.275     raeburn  4973:             if (defined($$types{'active'})) {
1.288     raeburn  4974:                 if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275     raeburn  4975:                     push(@{$$users{st}{$student}},'active');
1.288     raeburn  4976:                     $match = 1;
1.275     raeburn  4977:                 }
                   4978:             }
                   4979:             if (defined($$types{'previous'})) {
1.288     raeburn  4980:                 if ($$classlist{$student}[$idx{end}] <= $now) {
1.275     raeburn  4981:                     push(@{$$users{st}{$student}},'previous');
1.288     raeburn  4982:                     $match = 1;
1.275     raeburn  4983:                 }
                   4984:             }
                   4985:             if (defined($$types{'future'})) {
1.288     raeburn  4986:                 if (($$classlist{$student}[$idx{start}] > $now) && ($$classlist{$student}[$idx{end}] > $now) || ($$classlist{$student}[$idx{end}] == 0) || ($$classlist{$student}[$idx{end}] eq '')) {
1.275     raeburn  4987:                     push(@{$$users{st}{$student}},'future');
1.288     raeburn  4988:                     $match = 1;
1.275     raeburn  4989:                 }
                   4990:             }
1.412     raeburn  4991:             if ($match && ref($userdata) eq 'HASH') {
1.288     raeburn  4992:                 $$userdata{$student} = $$classlist{$student};
                   4993:             }
1.275     raeburn  4994:         }
                   4995:     }
1.412     raeburn  4996:     if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439     raeburn  4997:         my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   4998:         my $now = time;
                   4999:         foreach my $person (sort(keys(%coursepersonnel))) {
1.288     raeburn  5000:             my $match = 0;
1.412     raeburn  5001:             my $secmatch = 0;
1.439     raeburn  5002:             my $status;
1.412     raeburn  5003:             my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275     raeburn  5004:             $user =~ s/:$//;
1.439     raeburn  5005:             my ($end,$start) = split(/:/,$coursepersonnel{$person});
                   5006:             if ($end == -1 || $start == -1) {
                   5007:                 next;
                   5008:             }
                   5009:             if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
                   5010:                 (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412     raeburn  5011:                 my ($uname,$udom) = split(/:/,$user);
                   5012:                 if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 5013:                     if (grep(/^all$/,@{$sections})) {
1.412     raeburn  5014:                         $secmatch = 1;
                   5015:                     } elsif ($usec eq '') {
1.420     albertel 5016:                         if (grep(/^none$/,@{$sections})) {
1.412     raeburn  5017:                             $secmatch = 1;
                   5018:                         }
                   5019:                     } else {
                   5020:                         if (grep(/^\Q$usec\E$/,@{$sections})) {
                   5021:                             $secmatch = 1;
                   5022:                         }
                   5023:                     }
                   5024:                     if (!$secmatch) {
                   5025:                         next;
                   5026:                     }
1.288     raeburn  5027:                 }
1.419     raeburn  5028:                 if ($usec eq '') {
                   5029:                     $usec = 'none';
                   5030:                 }
1.275     raeburn  5031:                 if ($uname ne '' && $udom ne '') {
1.503     raeburn  5032:                     if ($end > 0 && $end < $now) {
1.439     raeburn  5033:                         $status = 'previous';
                   5034:                     } elsif ($start > $now) {
                   5035:                         $status = 'future';
                   5036:                     } else {
                   5037:                         $status = 'active';
                   5038:                     }
1.277     albertel 5039:                     foreach my $type (keys(%{$types})) { 
1.275     raeburn  5040:                         if ($status eq $type) {
1.420     albertel 5041:                             if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419     raeburn  5042:                                 push(@{$$users{$role}{$user}},$type);
                   5043:                             }
1.288     raeburn  5044:                             $match = 1;
                   5045:                         }
                   5046:                     }
1.419     raeburn  5047:                     if (($match) && (ref($userdata) eq 'HASH')) {
                   5048:                         if (!exists($$userdata{$uname.':'.$udom})) {
                   5049: 			    &get_user_info($udom,$uname,\%idx,$userdata);
                   5050:                         }
1.420     albertel 5051:                         if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419     raeburn  5052:                             push(@{$seclists{$uname.':'.$udom}},$usec);
                   5053:                         }
1.275     raeburn  5054:                     }
                   5055:                 }
                   5056:             }
                   5057:         }
1.290     albertel 5058:         if (grep(/^ow$/,@{$roles})) {
1.279     raeburn  5059:             if ((defined($cdom)) && (defined($cnum))) {
                   5060:                 my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
                   5061:                 if ( defined($csettings{'internal.courseowner'}) ) {
                   5062:                     my $owner = $csettings{'internal.courseowner'};
1.439     raeburn  5063:                     if ($owner !~ /^[^:]+:[^:]+$/) {
                   5064:                         $owner = $owner.':'.$cdom;
                   5065:                     }
                   5066:                     @{$$users{'ow'}{$owner}} = 'any';
1.290     albertel 5067:                     if (defined($userdata) && 
                   5068: 			!exists($$userdata{$owner.':'.$cdom})) {
                   5069: 			&get_user_info($cdom,$owner,\%idx,$userdata);
1.420     albertel 5070:                         if (!grep(/^none$/,@{$seclists{$owner.':'.$cdom}})) {
1.419     raeburn  5071:                             push(@{$seclists{$owner.':'.$cdom}},'none');
                   5072:                         }
1.290     albertel 5073: 		    }
1.279     raeburn  5074:                 }
                   5075:             }
                   5076:         }
1.419     raeburn  5077:         foreach my $user (keys(%seclists)) {
                   5078:             @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
                   5079:             $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
                   5080:         }
1.275     raeburn  5081:     }
                   5082:     return;
                   5083: }
                   5084: 
1.288     raeburn  5085: sub get_user_info {
                   5086:     my ($udom,$uname,$idx,$userdata) = @_;
1.289     albertel 5087:     $$userdata{$uname.':'.$udom}[$$idx{fullname}] = 
                   5088: 	&plainname($uname,$udom,'lastname');
1.291     albertel 5089:     $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297     raeburn  5090:     $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.288     raeburn  5091:     return;
                   5092: }
1.275     raeburn  5093: 
1.472     raeburn  5094: ###############################################
                   5095: 
                   5096: =pod
                   5097: 
                   5098: =item * &get_user_quota()
                   5099: 
                   5100: Retrieves quota assigned for storage of portfolio files for a user  
                   5101: 
                   5102: Incoming parameters:
                   5103: 1. user's username
                   5104: 2. user's domain
                   5105: 
                   5106: Returns:
                   5107: 1. Disk quota (in Mb) assigned to student. 
                   5108: 
                   5109: If a value has been stored in the user's environment, 
                   5110: it will return that, otherwise it returns the default
                   5111: for users in the domain.
                   5112: 
                   5113: =cut
                   5114: 
                   5115: ###############################################
                   5116: 
                   5117: 
                   5118: sub get_user_quota {
                   5119:     my ($uname,$udom) = @_;
                   5120:     my $quota;
                   5121:     if (!defined($udom)) {
                   5122:         $udom = $env{'user.domain'};
                   5123:     }
                   5124:     if (!defined($uname)) {
                   5125:         $uname = $env{'user.name'};
                   5126:     }
                   5127:     if (($udom eq '' || $uname eq '') ||
                   5128:         ($udom eq 'public') && ($uname eq 'public')) {
                   5129:         $quota = 0;
                   5130:     } else {
                   5131:         if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
                   5132:             $quota = $env{'environment.portfolioquota'};
                   5133:         } else {
                   5134:             my %userenv = &Apache::lonnet::dump('environment',$udom,$uname);
                   5135:             my ($tmp) = keys(%userenv);
                   5136:             if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   5137:                 $quota = $userenv{'portfolioquota'};
                   5138:             } else {
                   5139:                 undef(%userenv);
                   5140:             }
                   5141:         }
                   5142:         if ($quota eq '') {
                   5143:             $quota = &default_quota($udom);
                   5144:         }
                   5145:     }
                   5146:     return $quota;
                   5147: }
                   5148: 
                   5149: ###############################################
                   5150: 
                   5151: =pod
                   5152: 
                   5153: =item * &default_quota()
                   5154: 
                   5155: Retrieves default quota assigned for storage of user portfolio files
                   5156: 
                   5157: Incoming parameters:
                   5158: 1. domain
                   5159: 
                   5160: Returns:
                   5161: 1. Default disk quota (in Mb) for user portfolios in the domain.
                   5162: 
                   5163: If a value has been stored in the domain's configuration db,
                   5164: it will return that, otherwise it returns 20 (for backwards 
                   5165: compatibility with domains which have not set up a configuration
                   5166: db file; the original statically defined portfolio quota was 20 Mb). 
                   5167: 
                   5168: =cut
                   5169: 
                   5170: ###############################################
                   5171: 
                   5172: 
                   5173: sub default_quota {
                   5174:     my ($udom) = @_;
                   5175:     my %defaults = &Apache::lonnet::get_dom('configuration',
                   5176:                                             ['portfolioquota'],$udom);
                   5177:     if ($defaults{'portfolioquota'} ne '') {
                   5178:         return $defaults{'portfolioquota'};
                   5179:     } else {
                   5180:         return '20';
                   5181:     }
                   5182: }
                   5183: 
1.384     raeburn  5184: sub get_secgrprole_info {
                   5185:     my ($cdom,$cnum,$needroles,$type)  = @_;
                   5186:     my %sections_count = &get_sections($cdom,$cnum);
                   5187:     my @sections =  (sort {$a <=> $b} keys(%sections_count));
                   5188:     my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
                   5189:     my @groups = sort(keys(%curr_groups));
                   5190:     my $allroles = [];
                   5191:     my $rolehash;
                   5192:     my $accesshash = {
                   5193:                      active => 'Currently has access',
                   5194:                      future => 'Will have future access',
                   5195:                      previous => 'Previously had access',
                   5196:                   };
                   5197:     if ($needroles) {
                   5198:         $rolehash = {'all' => 'all'};
1.385     albertel 5199:         my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   5200: 	if (&Apache::lonnet::error(%user_roles)) {
                   5201: 	    undef(%user_roles);
                   5202: 	}
                   5203:         foreach my $item (keys(%user_roles)) {
1.384     raeburn  5204:             my ($role)=split(/\:/,$item,2);
                   5205:             if ($role eq 'cr') { next; }
                   5206:             if ($role =~ /^cr/) {
                   5207:                 $$rolehash{$role} = (split('/',$role))[3];
                   5208:             } else {
                   5209:                 $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
                   5210:             }
                   5211:         }
                   5212:         foreach my $key (sort(keys(%{$rolehash}))) {
                   5213:             push(@{$allroles},$key);
                   5214:         }
                   5215:         push (@{$allroles},'st');
                   5216:         $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
                   5217:     }
                   5218:     return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
                   5219: }
                   5220: 
1.112     bowersj2 5221: =pod
                   5222: 
                   5223: =item * get_unprocessed_cgi($query,$possible_names)
                   5224: 
1.258     albertel 5225: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112     bowersj2 5226: $query.  The parameters listed in $possible_names (an array reference),
1.258     albertel 5227: will be set in $env{'form.name'} if they do not already exist.
1.112     bowersj2 5228: 
                   5229: Typically called with $ENV{'QUERY_STRING'} as the first parameter.  
                   5230: $possible_names is an ref to an array of form element names.  As an example:
                   5231: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258     albertel 5232: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112     bowersj2 5233: 
                   5234: =cut
1.1       albertel 5235: 
1.6       albertel 5236: sub get_unprocessed_cgi {
1.25      albertel 5237:   my ($query,$possible_names)= @_;
1.26      matthew  5238:   # $Apache::lonxml::debug=1;
1.356     albertel 5239:   foreach my $pair (split(/&/,$query)) {
                   5240:     my ($name, $value) = split(/=/,$pair);
1.369     www      5241:     $name = &unescape($name);
1.25      albertel 5242:     if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
                   5243:       $value =~ tr/+/ /;
                   5244:       $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258     albertel 5245:       unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25      albertel 5246:     }
1.16      harris41 5247:   }
1.6       albertel 5248: }
                   5249: 
1.112     bowersj2 5250: =pod
                   5251: 
                   5252: =item * cacheheader() 
                   5253: 
                   5254: returns cache-controlling header code
                   5255: 
                   5256: =cut
                   5257: 
1.7       albertel 5258: sub cacheheader {
1.258     albertel 5259:     unless ($env{'request.method'} eq 'GET') { return ''; }
1.216     albertel 5260:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
                   5261:     my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7       albertel 5262:                 <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
                   5263:                 <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216     albertel 5264:     return $output;
1.7       albertel 5265: }
                   5266: 
1.112     bowersj2 5267: =pod
                   5268: 
                   5269: =item * no_cache($r) 
                   5270: 
                   5271: specifies header code to not have cache
                   5272: 
                   5273: =cut
                   5274: 
1.9       albertel 5275: sub no_cache {
1.216     albertel 5276:     my ($r) = @_;
                   5277:     if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258     albertel 5278: 	$env{'request.method'} ne 'GET') { return ''; }
1.216     albertel 5279:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
                   5280:     $r->no_cache(1);
                   5281:     $r->header_out("Expires" => $date);
                   5282:     $r->header_out("Pragma" => "no-cache");
1.123     www      5283: }
                   5284: 
                   5285: sub content_type {
1.181     albertel 5286:     my ($r,$type,$charset) = @_;
1.299     foxr     5287:     if ($r) {
                   5288: 	#  Note that printout.pl calls this with undef for $r.
                   5289: 	&no_cache($r);
                   5290:     }
1.258     albertel 5291:     if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181     albertel 5292:     unless ($charset) {
                   5293: 	$charset=&Apache::lonlocal::current_encoding;
                   5294:     }
                   5295:     if ($charset) { $type.='; charset='.$charset; }
                   5296:     if ($r) {
                   5297: 	$r->content_type($type);
                   5298:     } else {
                   5299: 	print("Content-type: $type\n\n");
                   5300:     }
1.9       albertel 5301: }
1.25      albertel 5302: 
1.112     bowersj2 5303: =pod
                   5304: 
                   5305: =item * add_to_env($name,$value) 
                   5306: 
1.258     albertel 5307: adds $name to the %env hash with value
1.112     bowersj2 5308: $value, if $name already exists, the entry is converted to an array
                   5309: reference and $value is added to the array.
                   5310: 
                   5311: =cut
                   5312: 
1.25      albertel 5313: sub add_to_env {
                   5314:   my ($name,$value)=@_;
1.258     albertel 5315:   if (defined($env{$name})) {
                   5316:     if (ref($env{$name})) {
1.25      albertel 5317:       #already have multiple values
1.258     albertel 5318:       push(@{ $env{$name} },$value);
1.25      albertel 5319:     } else {
                   5320:       #first time seeing multiple values, convert hash entry to an arrayref
1.258     albertel 5321:       my $first=$env{$name};
                   5322:       undef($env{$name});
                   5323:       push(@{ $env{$name} },$first,$value);
1.25      albertel 5324:     }
                   5325:   } else {
1.258     albertel 5326:     $env{$name}=$value;
1.25      albertel 5327:   }
1.31      albertel 5328: }
1.149     albertel 5329: 
                   5330: =pod
                   5331: 
                   5332: =item * get_env_multiple($name) 
                   5333: 
1.258     albertel 5334: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149     albertel 5335: values may be defined and end up as an array ref.
                   5336: 
                   5337: returns an array of values
                   5338: 
                   5339: =cut
                   5340: 
                   5341: sub get_env_multiple {
                   5342:     my ($name) = @_;
                   5343:     my @values;
1.258     albertel 5344:     if (defined($env{$name})) {
1.149     albertel 5345:         # exists is it an array
1.258     albertel 5346:         if (ref($env{$name})) {
                   5347:             @values=@{ $env{$name} };
1.149     albertel 5348:         } else {
1.258     albertel 5349:             $values[0]=$env{$name};
1.149     albertel 5350:         }
                   5351:     }
                   5352:     return(@values);
                   5353: }
                   5354: 
1.31      albertel 5355: 
1.41      ng       5356: =pod
1.45      matthew  5357: 
1.464     albertel 5358: =back
1.41      ng       5359: 
1.112     bowersj2 5360: =head1 CSV Upload/Handling functions
1.38      albertel 5361: 
1.41      ng       5362: =over 4
                   5363: 
1.112     bowersj2 5364: =item * upfile_store($r)
1.41      ng       5365: 
                   5366: Store uploaded file, $r should be the HTTP Request object,
1.258     albertel 5367: needs $env{'form.upfile'}
1.41      ng       5368: returns $datatoken to be put into hidden field
                   5369: 
                   5370: =cut
1.31      albertel 5371: 
                   5372: sub upfile_store {
                   5373:     my $r=shift;
1.258     albertel 5374:     $env{'form.upfile'}=~s/\r/\n/gs;
                   5375:     $env{'form.upfile'}=~s/\f/\n/gs;
                   5376:     $env{'form.upfile'}=~s/\n+/\n/gs;
                   5377:     $env{'form.upfile'}=~s/\n+$//gs;
1.31      albertel 5378: 
1.258     albertel 5379:     my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
                   5380: 	'_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31      albertel 5381:     {
1.158     raeburn  5382:         my $datafile = $r->dir_config('lonDaemons').
                   5383:                            '/tmp/'.$datatoken.'.tmp';
                   5384:         if ( open(my $fh,">$datafile") ) {
1.258     albertel 5385:             print $fh $env{'form.upfile'};
1.158     raeburn  5386:             close($fh);
                   5387:         }
1.31      albertel 5388:     }
                   5389:     return $datatoken;
                   5390: }
                   5391: 
1.56      matthew  5392: =pod
                   5393: 
1.112     bowersj2 5394: =item * load_tmp_file($r)
1.41      ng       5395: 
                   5396: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258     albertel 5397: needs $env{'form.datatoken'},
                   5398: sets $env{'form.upfile'} to the contents of the file
1.41      ng       5399: 
                   5400: =cut
1.31      albertel 5401: 
                   5402: sub load_tmp_file {
                   5403:     my $r=shift;
                   5404:     my @studentdata=();
                   5405:     {
1.158     raeburn  5406:         my $studentfile = $r->dir_config('lonDaemons').
1.258     albertel 5407:                               '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158     raeburn  5408:         if ( open(my $fh,"<$studentfile") ) {
                   5409:             @studentdata=<$fh>;
                   5410:             close($fh);
                   5411:         }
1.31      albertel 5412:     }
1.258     albertel 5413:     $env{'form.upfile'}=join('',@studentdata);
1.31      albertel 5414: }
                   5415: 
1.56      matthew  5416: =pod
                   5417: 
1.112     bowersj2 5418: =item * upfile_record_sep()
1.41      ng       5419: 
                   5420: Separate uploaded file into records
                   5421: returns array of records,
1.258     albertel 5422: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41      ng       5423: 
                   5424: =cut
1.31      albertel 5425: 
                   5426: sub upfile_record_sep {
1.258     albertel 5427:     if ($env{'form.upfiletype'} eq 'xml') {
1.31      albertel 5428:     } else {
1.248     albertel 5429: 	my @records;
1.258     albertel 5430: 	foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248     albertel 5431: 	    if ($line=~/^\s*$/) { next; }
                   5432: 	    push(@records,$line);
                   5433: 	}
                   5434: 	return @records;
1.31      albertel 5435:     }
                   5436: }
                   5437: 
1.56      matthew  5438: =pod
                   5439: 
1.112     bowersj2 5440: =item * record_sep($record)
1.41      ng       5441: 
1.258     albertel 5442: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41      ng       5443: 
                   5444: =cut
                   5445: 
1.263     www      5446: sub takeleft {
                   5447:     my $index=shift;
                   5448:     return substr('0000'.$index,-4,4);
                   5449: }
                   5450: 
1.31      albertel 5451: sub record_sep {
                   5452:     my $record=shift;
                   5453:     my %components=();
1.258     albertel 5454:     if ($env{'form.upfiletype'} eq 'xml') {
                   5455:     } elsif ($env{'form.upfiletype'} eq 'space') {
1.31      albertel 5456:         my $i=0;
1.356     albertel 5457:         foreach my $field (split(/\s+/,$record)) {
1.31      albertel 5458:             $field=~s/^(\"|\')//;
                   5459:             $field=~s/(\"|\')$//;
1.263     www      5460:             $components{&takeleft($i)}=$field;
1.31      albertel 5461:             $i++;
                   5462:         }
1.258     albertel 5463:     } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31      albertel 5464:         my $i=0;
1.356     albertel 5465:         foreach my $field (split(/\t/,$record)) {
1.31      albertel 5466:             $field=~s/^(\"|\')//;
                   5467:             $field=~s/(\"|\')$//;
1.263     www      5468:             $components{&takeleft($i)}=$field;
1.31      albertel 5469:             $i++;
                   5470:         }
                   5471:     } else {
1.480     banghart 5472:         my @allfields;
                   5473:         if ($env{'form.upfiletype'} eq 'semisv') {
1.504     albertel 5474:             @allfields=split(/;/,$record,-1);
1.480     banghart 5475:         } else {
1.504     albertel 5476:             @allfields=split(/\,/,$record,-1);
1.480     banghart 5477:         }
1.31      albertel 5478:         my $i=0;
                   5479:         my $j;
                   5480:         for ($j=0;$j<=$#allfields;$j++) {
                   5481:             my $field=$allfields[$j];
                   5482:             if ($field=~/^\s*(\"|\')/) {
                   5483: 		my $delimiter=$1;
                   5484:                 while (($field!~/$delimiter$/) && ($j<$#allfields)) {
                   5485: 		    $j++;
                   5486: 		    $field.=','.$allfields[$j];
                   5487: 		}
                   5488:                 $field=~s/^\s*$delimiter//;
                   5489:                 $field=~s/$delimiter\s*$//;
                   5490:             }
1.263     www      5491:             $components{&takeleft($i)}=$field;
1.31      albertel 5492: 	    $i++;
                   5493:         }
                   5494:     }
                   5495:     return %components;
                   5496: }
                   5497: 
1.144     matthew  5498: ######################################################
                   5499: ######################################################
                   5500: 
1.56      matthew  5501: =pod
                   5502: 
1.112     bowersj2 5503: =item * upfile_select_html()
1.41      ng       5504: 
1.144     matthew  5505: Return HTML code to select a file from the users machine and specify 
                   5506: the file type.
1.41      ng       5507: 
                   5508: =cut
                   5509: 
1.144     matthew  5510: ######################################################
                   5511: ######################################################
1.31      albertel 5512: sub upfile_select_html {
1.144     matthew  5513:     my %Types = (
                   5514:                  csv   => &mt('CSV (comma separated values, spreadsheet)'),
1.480     banghart 5515:                  semisv => &mt('Semicolon separated values'),
1.144     matthew  5516:                  space => &mt('Space separated'),
                   5517:                  tab   => &mt('Tabulator separated'),
                   5518: #                 xml   => &mt('HTML/XML'),
                   5519:                  );
                   5520:     my $Str = '<input type="file" name="upfile" size="50" />'.
                   5521:         '<br />Type: <select name="upfiletype">';
                   5522:     foreach my $type (sort(keys(%Types))) {
                   5523:         $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
                   5524:     }
                   5525:     $Str .= "</select>\n";
                   5526:     return $Str;
1.31      albertel 5527: }
                   5528: 
1.301     albertel 5529: sub get_samples {
                   5530:     my ($records,$toget) = @_;
                   5531:     my @samples=({});
                   5532:     my $got=0;
                   5533:     foreach my $rec (@$records) {
                   5534: 	my %temp = &record_sep($rec);
                   5535: 	if (! grep(/\S/, values(%temp))) { next; }
                   5536: 	if (%temp) {
                   5537: 	    $samples[$got]=\%temp;
                   5538: 	    $got++;
                   5539: 	    if ($got == $toget) { last; }
                   5540: 	}
                   5541:     }
                   5542:     return \@samples;
                   5543: }
                   5544: 
1.144     matthew  5545: ######################################################
                   5546: ######################################################
                   5547: 
1.56      matthew  5548: =pod
                   5549: 
1.112     bowersj2 5550: =item * csv_print_samples($r,$records)
1.41      ng       5551: 
                   5552: Prints a table of sample values from each column uploaded $r is an
                   5553: Apache Request ref, $records is an arrayref from
                   5554: &Apache::loncommon::upfile_record_sep
                   5555: 
                   5556: =cut
                   5557: 
1.144     matthew  5558: ######################################################
                   5559: ######################################################
1.31      albertel 5560: sub csv_print_samples {
                   5561:     my ($r,$records) = @_;
1.301     albertel 5562:     my $samples = &get_samples($records,3);
                   5563: 
1.144     matthew  5564:     $r->print(&mt('Samples').'<br /><table border="2"><tr>');
1.356     albertel 5565:     foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) { 
                   5566:         $r->print('<th>'.&mt('Column&nbsp;[_1]',($sample+1)).'</th>'); }
1.31      albertel 5567:     $r->print('</tr>');
1.301     albertel 5568:     foreach my $hash (@$samples) {
1.31      albertel 5569: 	$r->print('<tr>');
1.356     albertel 5570: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31      albertel 5571: 	    $r->print('<td>');
1.356     albertel 5572: 	    if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31      albertel 5573: 	    $r->print('</td>');
                   5574: 	}
                   5575: 	$r->print('</tr>');
                   5576:     }
                   5577:     $r->print('</tr></table><br />'."\n");
                   5578: }
                   5579: 
1.144     matthew  5580: ######################################################
                   5581: ######################################################
                   5582: 
1.56      matthew  5583: =pod
                   5584: 
1.112     bowersj2 5585: =item * csv_print_select_table($r,$records,$d)
1.41      ng       5586: 
                   5587: Prints a table to create associations between values and table columns.
1.144     matthew  5588: 
1.41      ng       5589: $r is an Apache Request ref,
                   5590: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174     matthew  5591: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41      ng       5592: 
                   5593: =cut
                   5594: 
1.144     matthew  5595: ######################################################
                   5596: ######################################################
1.31      albertel 5597: sub csv_print_select_table {
                   5598:     my ($r,$records,$d) = @_;
1.301     albertel 5599:     my $i=0;
                   5600:     my $samples = &get_samples($records,1);
1.144     matthew  5601:     $r->print(&mt('Associate columns with student attributes.')."\n".
                   5602: 	     '<table border="2"><tr>'.
                   5603:               '<th>'.&mt('Attribute').'</th>'.
                   5604:               '<th>'.&mt('Column').'</th></tr>'."\n");
1.356     albertel 5605:     foreach my $array_ref (@$d) {
                   5606: 	my ($value,$display,$defaultcol)=@{ $array_ref };
1.31      albertel 5607: 	$r->print('<tr><td>'.$display.'</td>');
                   5608: 
                   5609: 	$r->print('<td><select name=f'.$i.
1.32      matthew  5610: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.31      albertel 5611: 	$r->print('<option value="none"></option>');
1.356     albertel 5612: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
                   5613: 	    $r->print('<option value="'.$sample.'"'.
                   5614:                       ($sample eq $defaultcol ? ' selected="selected" ' : '').
                   5615:                       '>Column '.($sample+1).'</option>');
1.31      albertel 5616: 	}
                   5617: 	$r->print('</select></td></tr>'."\n");
                   5618: 	$i++;
                   5619:     }
                   5620:     $i--;
                   5621:     return $i;
                   5622: }
1.56      matthew  5623: 
1.144     matthew  5624: ######################################################
                   5625: ######################################################
                   5626: 
1.56      matthew  5627: =pod
1.31      albertel 5628: 
1.112     bowersj2 5629: =item * csv_samples_select_table($r,$records,$d)
1.41      ng       5630: 
                   5631: Prints a table of sample values from the upload and can make associate samples to internal names.
                   5632: 
                   5633: $r is an Apache Request ref,
                   5634: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
                   5635: $d is an array of 2 element arrays (internal name, displayed name)
                   5636: 
                   5637: =cut
                   5638: 
1.144     matthew  5639: ######################################################
                   5640: ######################################################
1.31      albertel 5641: sub csv_samples_select_table {
                   5642:     my ($r,$records,$d) = @_;
                   5643:     my $i=0;
1.144     matthew  5644:     #
1.301     albertel 5645:     my $samples = &get_samples($records,3);
1.144     matthew  5646:     $r->print('<table border=2><tr><th>'.
                   5647:               &mt('Field').'</th><th>'.&mt('Samples').'</th></tr>');
1.301     albertel 5648: 
                   5649:     foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.144     matthew  5650: 	$r->print('<tr><td><select name="f'.$i.'"'.
1.32      matthew  5651: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.301     albertel 5652: 	foreach my $option (@$d) {
                   5653: 	    my ($value,$display,$defaultcol)=@{ $option };
1.174     matthew  5654: 	    $r->print('<option value="'.$value.'"'.
1.253     albertel 5655:                       ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174     matthew  5656:                       $display.'</option>');
1.31      albertel 5657: 	}
                   5658: 	$r->print('</select></td><td>');
1.301     albertel 5659: 	foreach my $line (0..2) {
                   5660: 	    if (defined($samples->[$line]{$key})) { 
                   5661: 		$r->print($samples->[$line]{$key}."<br />\n"); 
                   5662: 	    }
                   5663: 	}
1.31      albertel 5664: 	$r->print('</td></tr>');
                   5665: 	$i++;
                   5666:     }
                   5667:     $i--;
                   5668:     return($i);
1.115     matthew  5669: }
                   5670: 
1.144     matthew  5671: ######################################################
                   5672: ######################################################
                   5673: 
1.115     matthew  5674: =pod
                   5675: 
                   5676: =item clean_excel_name($name)
                   5677: 
                   5678: Returns a replacement for $name which does not contain any illegal characters.
                   5679: 
                   5680: =cut
                   5681: 
1.144     matthew  5682: ######################################################
                   5683: ######################################################
1.115     matthew  5684: sub clean_excel_name {
                   5685:     my ($name) = @_;
                   5686:     $name =~ s/[:\*\?\/\\]//g;
                   5687:     if (length($name) > 31) {
                   5688:         $name = substr($name,0,31);
                   5689:     }
                   5690:     return $name;
1.25      albertel 5691: }
1.84      albertel 5692: 
1.85      albertel 5693: =pod
                   5694: 
1.112     bowersj2 5695: =item * check_if_partid_hidden($id,$symb,$udom,$uname)
1.85      albertel 5696: 
                   5697: Returns either 1 or undef
                   5698: 
                   5699: 1 if the part is to be hidden, undef if it is to be shown
                   5700: 
                   5701: Arguments are:
                   5702: 
                   5703: $id the id of the part to be checked
                   5704: $symb, optional the symb of the resource to check
                   5705: $udom, optional the domain of the user to check for
                   5706: $uname, optional the username of the user to check for
                   5707: 
                   5708: =cut
1.84      albertel 5709: 
                   5710: sub check_if_partid_hidden {
                   5711:     my ($id,$symb,$udom,$uname) = @_;
1.133     albertel 5712:     my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84      albertel 5713: 					 $symb,$udom,$uname);
1.141     albertel 5714:     my $truth=1;
                   5715:     #if the string starts with !, then the list is the list to show not hide
                   5716:     if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84      albertel 5717:     my @hiddenlist=split(/,/,$hiddenparts);
                   5718:     foreach my $checkid (@hiddenlist) {
1.141     albertel 5719: 	if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84      albertel 5720:     }
1.141     albertel 5721:     return !$truth;
1.84      albertel 5722: }
1.127     matthew  5723: 
1.138     matthew  5724: 
                   5725: ############################################################
                   5726: ############################################################
                   5727: 
                   5728: =pod
                   5729: 
1.157     matthew  5730: =back 
                   5731: 
1.138     matthew  5732: =head1 cgi-bin script and graphing routines
                   5733: 
1.157     matthew  5734: =over 4
                   5735: 
1.138     matthew  5736: =item get_cgi_id
                   5737: 
                   5738: Inputs: none
                   5739: 
                   5740: Returns an id which can be used to pass environment variables
                   5741: to various cgi-bin scripts.  These environment variables will
                   5742: be removed from the users environment after a given time by
                   5743: the routine &Apache::lonnet::transfer_profile_to_env.
                   5744: 
                   5745: =cut
                   5746: 
                   5747: ############################################################
                   5748: ############################################################
1.152     albertel 5749: my $uniq=0;
1.136     matthew  5750: sub get_cgi_id {
1.154     albertel 5751:     $uniq=($uniq+1)%100000;
1.280     albertel 5752:     return (time.'_'.$$.'_'.$uniq);
1.136     matthew  5753: }
                   5754: 
1.127     matthew  5755: ############################################################
                   5756: ############################################################
                   5757: 
                   5758: =pod
                   5759: 
1.134     matthew  5760: =item DrawBarGraph
1.127     matthew  5761: 
1.138     matthew  5762: Facilitates the plotting of data in a (stacked) bar graph.
                   5763: Puts plot definition data into the users environment in order for 
                   5764: graph.png to plot it.  Returns an <img> tag for the plot.
                   5765: The bars on the plot are labeled '1','2',...,'n'.
                   5766: 
                   5767: Inputs:
                   5768: 
                   5769: =over 4
                   5770: 
                   5771: =item $Title: string, the title of the plot
                   5772: 
                   5773: =item $xlabel: string, text describing the X-axis of the plot
                   5774: 
                   5775: =item $ylabel: string, text describing the Y-axis of the plot
                   5776: 
                   5777: =item $Max: scalar, the maximum Y value to use in the plot
                   5778: If $Max is < any data point, the graph will not be rendered.
                   5779: 
1.140     matthew  5780: =item $colors: array ref holding the colors to be used for the data sets when
1.138     matthew  5781: they are plotted.  If undefined, default values will be used.
                   5782: 
1.178     matthew  5783: =item $labels: array ref holding the labels to use on the x-axis for the bars.
                   5784: 
1.138     matthew  5785: =item @Values: An array of array references.  Each array reference holds data
                   5786: to be plotted in a stacked bar chart.
                   5787: 
1.239     matthew  5788: =item If the final element of @Values is a hash reference the key/value
                   5789: pairs will be added to the graph definition.
                   5790: 
1.138     matthew  5791: =back
                   5792: 
                   5793: Returns:
                   5794: 
                   5795: An <img> tag which references graph.png and the appropriate identifying
                   5796: information for the plot.
                   5797: 
1.127     matthew  5798: =cut
                   5799: 
                   5800: ############################################################
                   5801: ############################################################
1.134     matthew  5802: sub DrawBarGraph {
1.178     matthew  5803:     my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134     matthew  5804:     #
                   5805:     if (! defined($colors)) {
                   5806:         $colors = ['#33ff00', 
                   5807:                   '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
                   5808:                   '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
                   5809:                   ]; 
                   5810:     }
1.228     matthew  5811:     my $extra_settings = {};
                   5812:     if (ref($Values[-1]) eq 'HASH') {
                   5813:         $extra_settings = pop(@Values);
                   5814:     }
1.127     matthew  5815:     #
1.136     matthew  5816:     my $identifier = &get_cgi_id();
                   5817:     my $id = 'cgi.'.$identifier;        
1.129     matthew  5818:     if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127     matthew  5819:         return '';
                   5820:     }
1.225     matthew  5821:     #
                   5822:     my @Labels;
                   5823:     if (defined($labels)) {
                   5824:         @Labels = @$labels;
                   5825:     } else {
                   5826:         for (my $i=0;$i<@{$Values[0]};$i++) {
                   5827:             push (@Labels,$i+1);
                   5828:         }
                   5829:     }
                   5830:     #
1.129     matthew  5831:     my $NumBars = scalar(@{$Values[0]});
1.225     matthew  5832:     if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129     matthew  5833:     my %ValuesHash;
                   5834:     my $NumSets=1;
                   5835:     foreach my $array (@Values) {
                   5836:         next if (! ref($array));
1.136     matthew  5837:         $ValuesHash{$id.'.data.'.$NumSets++} = 
1.132     matthew  5838:             join(',',@$array);
1.129     matthew  5839:     }
1.127     matthew  5840:     #
1.136     matthew  5841:     my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225     matthew  5842:     if ($NumBars < 3) {
                   5843:         $width = 120+$NumBars*32;
1.220     matthew  5844:         $xskip = 1;
1.225     matthew  5845:         $bar_width = 30;
                   5846:     } elsif ($NumBars < 5) {
                   5847:         $width = 120+$NumBars*20;
                   5848:         $xskip = 1;
                   5849:         $bar_width = 20;
1.220     matthew  5850:     } elsif ($NumBars < 10) {
1.136     matthew  5851:         $width = 120+$NumBars*15;
                   5852:         $xskip = 1;
                   5853:         $bar_width = 15;
                   5854:     } elsif ($NumBars <= 25) {
                   5855:         $width = 120+$NumBars*11;
                   5856:         $xskip = 5;
                   5857:         $bar_width = 8;
                   5858:     } elsif ($NumBars <= 50) {
                   5859:         $width = 120+$NumBars*8;
                   5860:         $xskip = 5;
                   5861:         $bar_width = 4;
                   5862:     } else {
                   5863:         $width = 120+$NumBars*8;
                   5864:         $xskip = 5;
                   5865:         $bar_width = 4;
                   5866:     }
                   5867:     #
1.137     matthew  5868:     $Max = 1 if ($Max < 1);
                   5869:     if ( int($Max) < $Max ) {
                   5870:         $Max++;
                   5871:         $Max = int($Max);
                   5872:     }
1.127     matthew  5873:     $Title  = '' if (! defined($Title));
                   5874:     $xlabel = '' if (! defined($xlabel));
                   5875:     $ylabel = '' if (! defined($ylabel));
1.369     www      5876:     $ValuesHash{$id.'.title'}    = &escape($Title);
                   5877:     $ValuesHash{$id.'.xlabel'}   = &escape($xlabel);
                   5878:     $ValuesHash{$id.'.ylabel'}   = &escape($ylabel);
1.137     matthew  5879:     $ValuesHash{$id.'.y_max_value'} = $Max;
1.136     matthew  5880:     $ValuesHash{$id.'.NumBars'}  = $NumBars;
                   5881:     $ValuesHash{$id.'.NumSets'}  = $NumSets;
                   5882:     $ValuesHash{$id.'.PlotType'} = 'bar';
                   5883:     $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   5884:     $ValuesHash{$id.'.height'}   = $height;
                   5885:     $ValuesHash{$id.'.width'}    = $width;
                   5886:     $ValuesHash{$id.'.xskip'}    = $xskip;
                   5887:     $ValuesHash{$id.'.bar_width'} = $bar_width;
                   5888:     $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127     matthew  5889:     #
1.228     matthew  5890:     # Deal with other parameters
                   5891:     while (my ($key,$value) = each(%$extra_settings)) {
                   5892:         $ValuesHash{$id.'.'.$key} = $value;
                   5893:     }
                   5894:     #
1.137     matthew  5895:     &Apache::lonnet::appenv(%ValuesHash);
                   5896:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   5897: }
                   5898: 
                   5899: ############################################################
                   5900: ############################################################
                   5901: 
                   5902: =pod
                   5903: 
                   5904: =item DrawXYGraph
                   5905: 
1.138     matthew  5906: Facilitates the plotting of data in an XY graph.
                   5907: Puts plot definition data into the users environment in order for 
                   5908: graph.png to plot it.  Returns an <img> tag for the plot.
                   5909: 
                   5910: Inputs:
                   5911: 
                   5912: =over 4
                   5913: 
                   5914: =item $Title: string, the title of the plot
                   5915: 
                   5916: =item $xlabel: string, text describing the X-axis of the plot
                   5917: 
                   5918: =item $ylabel: string, text describing the Y-axis of the plot
                   5919: 
                   5920: =item $Max: scalar, the maximum Y value to use in the plot
                   5921: If $Max is < any data point, the graph will not be rendered.
                   5922: 
                   5923: =item $colors: Array ref containing the hex color codes for the data to be 
                   5924: plotted in.  If undefined, default values will be used.
                   5925: 
                   5926: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   5927: 
                   5928: =item $Ydata: Array ref containing Array refs.  
1.185     www      5929: Each of the contained arrays will be plotted as a separate curve.
1.138     matthew  5930: 
                   5931: =item %Values: hash indicating or overriding any default values which are 
                   5932: passed to graph.png.  
                   5933: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   5934: 
                   5935: =back
                   5936: 
                   5937: Returns:
                   5938: 
                   5939: An <img> tag which references graph.png and the appropriate identifying
                   5940: information for the plot.
                   5941: 
1.137     matthew  5942: =cut
                   5943: 
                   5944: ############################################################
                   5945: ############################################################
                   5946: sub DrawXYGraph {
                   5947:     my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
                   5948:     #
                   5949:     # Create the identifier for the graph
                   5950:     my $identifier = &get_cgi_id();
                   5951:     my $id = 'cgi.'.$identifier;
                   5952:     #
                   5953:     $Title  = '' if (! defined($Title));
                   5954:     $xlabel = '' if (! defined($xlabel));
                   5955:     $ylabel = '' if (! defined($ylabel));
                   5956:     my %ValuesHash = 
                   5957:         (
1.369     www      5958:          $id.'.title'  => &escape($Title),
                   5959:          $id.'.xlabel' => &escape($xlabel),
                   5960:          $id.'.ylabel' => &escape($ylabel),
1.137     matthew  5961:          $id.'.y_max_value'=> $Max,
                   5962:          $id.'.labels'     => join(',',@$Xlabels),
                   5963:          $id.'.PlotType'   => 'XY',
                   5964:          );
                   5965:     #
                   5966:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   5967:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   5968:     }
                   5969:     #
                   5970:     if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
                   5971:         return '';
                   5972:     }
                   5973:     my $NumSets=1;
1.138     matthew  5974:     foreach my $array (@{$Ydata}){
1.137     matthew  5975:         next if (! ref($array));
                   5976:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
                   5977:     }
1.138     matthew  5978:     $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137     matthew  5979:     #
                   5980:     # Deal with other parameters
                   5981:     while (my ($key,$value) = each(%Values)) {
                   5982:         $ValuesHash{$id.'.'.$key} = $value;
1.127     matthew  5983:     }
                   5984:     #
1.136     matthew  5985:     &Apache::lonnet::appenv(%ValuesHash);
                   5986:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   5987: }
                   5988: 
                   5989: ############################################################
                   5990: ############################################################
                   5991: 
                   5992: =pod
                   5993: 
1.138     matthew  5994: =item DrawXYYGraph
                   5995: 
                   5996: Facilitates the plotting of data in an XY graph with two Y axes.
                   5997: Puts plot definition data into the users environment in order for 
                   5998: graph.png to plot it.  Returns an <img> tag for the plot.
                   5999: 
                   6000: Inputs:
                   6001: 
                   6002: =over 4
                   6003: 
                   6004: =item $Title: string, the title of the plot
                   6005: 
                   6006: =item $xlabel: string, text describing the X-axis of the plot
                   6007: 
                   6008: =item $ylabel: string, text describing the Y-axis of the plot
                   6009: 
                   6010: =item $colors: Array ref containing the hex color codes for the data to be 
                   6011: plotted in.  If undefined, default values will be used.
                   6012: 
                   6013: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   6014: 
                   6015: =item $Ydata1: The first data set
                   6016: 
                   6017: =item $Min1: The minimum value of the left Y-axis
                   6018: 
                   6019: =item $Max1: The maximum value of the left Y-axis
                   6020: 
                   6021: =item $Ydata2: The second data set
                   6022: 
                   6023: =item $Min2: The minimum value of the right Y-axis
                   6024: 
                   6025: =item $Max2: The maximum value of the left Y-axis
                   6026: 
                   6027: =item %Values: hash indicating or overriding any default values which are 
                   6028: passed to graph.png.  
                   6029: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   6030: 
                   6031: =back
                   6032: 
                   6033: Returns:
                   6034: 
                   6035: An <img> tag which references graph.png and the appropriate identifying
                   6036: information for the plot.
1.136     matthew  6037: 
                   6038: =cut
                   6039: 
                   6040: ############################################################
                   6041: ############################################################
1.137     matthew  6042: sub DrawXYYGraph {
                   6043:     my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
                   6044:                                         $Ydata2,$Min2,$Max2,%Values)=@_;
1.136     matthew  6045:     #
                   6046:     # Create the identifier for the graph
                   6047:     my $identifier = &get_cgi_id();
                   6048:     my $id = 'cgi.'.$identifier;
                   6049:     #
                   6050:     $Title  = '' if (! defined($Title));
                   6051:     $xlabel = '' if (! defined($xlabel));
                   6052:     $ylabel = '' if (! defined($ylabel));
                   6053:     my %ValuesHash = 
                   6054:         (
1.369     www      6055:          $id.'.title'  => &escape($Title),
                   6056:          $id.'.xlabel' => &escape($xlabel),
                   6057:          $id.'.ylabel' => &escape($ylabel),
1.136     matthew  6058:          $id.'.labels' => join(',',@$Xlabels),
                   6059:          $id.'.PlotType' => 'XY',
                   6060:          $id.'.NumSets' => 2,
1.137     matthew  6061:          $id.'.two_axes' => 1,
                   6062:          $id.'.y1_max_value' => $Max1,
                   6063:          $id.'.y1_min_value' => $Min1,
                   6064:          $id.'.y2_max_value' => $Max2,
                   6065:          $id.'.y2_min_value' => $Min2,
1.136     matthew  6066:          );
                   6067:     #
1.137     matthew  6068:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   6069:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   6070:     }
                   6071:     #
                   6072:     if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
                   6073:         ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136     matthew  6074:         return '';
                   6075:     }
                   6076:     my $NumSets=1;
1.137     matthew  6077:     foreach my $array ($Ydata1,$Ydata2){
1.136     matthew  6078:         next if (! ref($array));
                   6079:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137     matthew  6080:     }
                   6081:     #
                   6082:     # Deal with other parameters
                   6083:     while (my ($key,$value) = each(%Values)) {
                   6084:         $ValuesHash{$id.'.'.$key} = $value;
1.136     matthew  6085:     }
                   6086:     #
                   6087:     &Apache::lonnet::appenv(%ValuesHash);
1.130     albertel 6088:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139     matthew  6089: }
                   6090: 
                   6091: ############################################################
                   6092: ############################################################
                   6093: 
                   6094: =pod
                   6095: 
1.157     matthew  6096: =back 
                   6097: 
1.139     matthew  6098: =head1 Statistics helper routines?  
                   6099: 
                   6100: Bad place for them but what the hell.
                   6101: 
1.157     matthew  6102: =over 4
                   6103: 
1.139     matthew  6104: =item &chartlink
                   6105: 
                   6106: Returns a link to the chart for a specific student.  
                   6107: 
                   6108: Inputs:
                   6109: 
                   6110: =over 4
                   6111: 
                   6112: =item $linktext: The text of the link
                   6113: 
                   6114: =item $sname: The students username
                   6115: 
                   6116: =item $sdomain: The students domain
                   6117: 
                   6118: =back
                   6119: 
1.157     matthew  6120: =back
                   6121: 
1.139     matthew  6122: =cut
                   6123: 
                   6124: ############################################################
                   6125: ############################################################
                   6126: sub chartlink {
                   6127:     my ($linktext, $sname, $sdomain) = @_;
                   6128:     my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369     www      6129:         '&amp;SelectedStudent='.&escape($sname.':'.$sdomain).
1.219     albertel 6130:         '&amp;chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139     matthew  6131:        '">'.$linktext.'</a>';
1.153     matthew  6132: }
                   6133: 
                   6134: #######################################################
                   6135: #######################################################
                   6136: 
                   6137: =pod
                   6138: 
                   6139: =head1 Course Environment Routines
1.157     matthew  6140: 
                   6141: =over 4
1.153     matthew  6142: 
                   6143: =item &restore_course_settings 
                   6144: 
                   6145: =item &store_course_settings
                   6146: 
                   6147: Restores/Store indicated form parameters from the course environment.
                   6148: Will not overwrite existing values of the form parameters.
                   6149: 
                   6150: Inputs: 
                   6151: a scalar describing the data (e.g. 'chart', 'problem_analysis')
                   6152: 
                   6153: a hash ref describing the data to be stored.  For example:
                   6154:    
                   6155: %Save_Parameters = ('Status' => 'scalar',
                   6156:     'chartoutputmode' => 'scalar',
                   6157:     'chartoutputdata' => 'scalar',
                   6158:     'Section' => 'array',
1.373     raeburn  6159:     'Group' => 'array',
1.153     matthew  6160:     'StudentData' => 'array',
                   6161:     'Maps' => 'array');
                   6162: 
                   6163: Returns: both routines return nothing
                   6164: 
                   6165: =cut
                   6166: 
                   6167: #######################################################
                   6168: #######################################################
                   6169: sub store_course_settings {
1.496     albertel 6170:     return &store_settings($env{'request.course.id'},@_);
                   6171: }
                   6172: 
                   6173: sub store_settings {
1.153     matthew  6174:     # save to the environment
                   6175:     # appenv the same items, just to be safe
1.300     albertel 6176:     my $udom  = $env{'user.domain'};
                   6177:     my $uname = $env{'user.name'};
1.496     albertel 6178:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  6179:     my %SaveHash;
                   6180:     my %AppHash;
                   6181:     while (my ($setting,$type) = each(%$Settings)) {
1.496     albertel 6182:         my $basename = join('.','internal',$context,$prefix,$setting);
1.300     albertel 6183:         my $envname = 'environment.'.$basename;
1.258     albertel 6184:         if (exists($env{'form.'.$setting})) {
1.153     matthew  6185:             # Save this value away
                   6186:             if ($type eq 'scalar' &&
1.258     albertel 6187:                 (! exists($env{$envname}) || 
                   6188:                  $env{$envname} ne $env{'form.'.$setting})) {
                   6189:                 $SaveHash{$basename} = $env{'form.'.$setting};
                   6190:                 $AppHash{$envname}   = $env{'form.'.$setting};
1.153     matthew  6191:             } elsif ($type eq 'array') {
                   6192:                 my $stored_form;
1.258     albertel 6193:                 if (ref($env{'form.'.$setting})) {
1.153     matthew  6194:                     $stored_form = join(',',
                   6195:                                         map {
1.369     www      6196:                                             &escape($_);
1.258     albertel 6197:                                         } sort(@{$env{'form.'.$setting}}));
1.153     matthew  6198:                 } else {
                   6199:                     $stored_form = 
1.369     www      6200:                         &escape($env{'form.'.$setting});
1.153     matthew  6201:                 }
                   6202:                 # Determine if the array contents are the same.
1.258     albertel 6203:                 if ($stored_form ne $env{$envname}) {
1.153     matthew  6204:                     $SaveHash{$basename} = $stored_form;
                   6205:                     $AppHash{$envname}   = $stored_form;
                   6206:                 }
                   6207:             }
                   6208:         }
                   6209:     }
                   6210:     my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300     albertel 6211:                                           $udom,$uname);
1.153     matthew  6212:     if ($put_result !~ /^(ok|delayed)/) {
                   6213:         &Apache::lonnet::logthis('unable to save form parameters, '.
                   6214:                                  'got error:'.$put_result);
                   6215:     }
                   6216:     # Make sure these settings stick around in this session, too
                   6217:     &Apache::lonnet::appenv(%AppHash);
                   6218:     return;
                   6219: }
                   6220: 
                   6221: sub restore_course_settings {
1.499     albertel 6222:     return &restore_settings($env{'request.course.id'},@_);
1.496     albertel 6223: }
                   6224: 
                   6225: sub restore_settings {
                   6226:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  6227:     while (my ($setting,$type) = each(%$Settings)) {
1.258     albertel 6228:         next if (exists($env{'form.'.$setting}));
1.496     albertel 6229:         my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153     matthew  6230:             '.'.$setting;
1.258     albertel 6231:         if (exists($env{$envname})) {
1.153     matthew  6232:             if ($type eq 'scalar') {
1.258     albertel 6233:                 $env{'form.'.$setting} = $env{$envname};
1.153     matthew  6234:             } elsif ($type eq 'array') {
1.258     albertel 6235:                 $env{'form.'.$setting} = [ 
1.153     matthew  6236:                                            map { 
1.369     www      6237:                                                &unescape($_); 
1.258     albertel 6238:                                            } split(',',$env{$envname})
1.153     matthew  6239:                                            ];
                   6240:             }
                   6241:         }
                   6242:     }
1.127     matthew  6243: }
                   6244: 
                   6245: ############################################################
                   6246: ############################################################
1.154     albertel 6247: 
1.443     albertel 6248: sub commit_customrole {
                   6249:     my ($udom,$uname,$url,$three,$four,$five,$start,$end) = @_;
                   6250:     my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.'@'.$three.' in '.$url.
                   6251:                          ($start?', '.&mt('starting').' '.localtime($start):'').
                   6252:                          ($end?', ending '.localtime($end):'').': <b>'.
                   6253:               &Apache::lonnet::assigncustomrole(
                   6254:                  $udom,$uname,$url,$three,$four,$five,$end,$start).
                   6255:                  '</b><br />';
                   6256:     return $output;
                   6257: }
                   6258: 
                   6259: sub commit_standardrole {
                   6260:     my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec) = @_;
                   6261:     my $output;
                   6262:     my $logmsg;
                   6263:     if ($three eq 'st') {
                   6264:         my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec);
                   6265:         if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course')) {
                   6266:             $output = "Error: $result\n"; 
                   6267:         } else {
                   6268:             $output = &mt('Assigning').' '.$three.' in '.$url.
                   6269:                ($start?', '.&mt('starting').' '.localtime($start):'').
                   6270:                ($end?', '.&mt('ending').' '.localtime($end):'').
                   6271:                ': <b>'.$result.'</b><br />'.
                   6272:                &mt('Add to classlist').': <b>ok</b><br />';
                   6273:         }
                   6274:     } else {
                   6275:         $output = &mt('Assigning').' '.$three.' in '.$url.
                   6276:                ($start?', '.&mt('starting').' '.localtime($start):'').
                   6277:                ($end?', '.&mt('ending').' '.localtime($end):'').': <b>'.
                   6278:                &Apache::lonnet::assignrole(
                   6279:                    $udom,$uname,$url,$three,$end,$start).
                   6280:                    '</b><br />';
                   6281:     }
                   6282:     return $output;
                   6283: }
                   6284: 
                   6285: sub commit_studentrole {
                   6286:     my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec) = @_;
                   6287:     my $linefeed =  '<br />'."\n";
                   6288:     my $result;
                   6289:     if (defined($one) && defined($two)) {
                   6290:         my $cid=$one.'_'.$two;
                   6291:         my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
                   6292:         my $secchange = 0;
                   6293:         my $expire_role_result;
                   6294:         my $modify_section_result;
                   6295:         unless ($oldsec eq '-1') {
                   6296:             unless ($sec eq $oldsec) {
                   6297:                 $secchange = 1;
                   6298:                 my $uurl='/'.$cid;
                   6299:                 $uurl=~s/\_/\//g;
                   6300:                 if ($oldsec) {
                   6301:                     $uurl.='/'.$oldsec;
                   6302:                 }
                   6303:                 $expire_role_result = &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',time);
                   6304:                 $result = $expire_role_result;
                   6305:             }
                   6306:         }
                   6307:         if (($expire_role_result eq 'ok') || ($secchange == 0)) {
                   6308:             $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid);
                   6309:             if ($modify_section_result =~ /^ok/) {
                   6310:                 if ($secchange == 1) {
                   6311:                     $$logmsg .= "Section for $uname switched from old section: $oldsec to new section: $sec".$linefeed;
                   6312:                 } elsif ($oldsec eq '-1') {
                   6313:                     $$logmsg .= "New student role for $uname in section $sec in course $cid".$linefeed;
                   6314:                 } else {
                   6315:                     $$logmsg .= "Student $uname assigned to unchanged section $sec in course $cid".$linefeed;
                   6316:                 }
                   6317:             } else {
                   6318:                 $$logmsg .= "Error when attempting section change for $uname from old section $oldsec to new section: $sec in course $cid -error: $modify_section_result".$linefeed;
                   6319:             }
                   6320:             $result = $modify_section_result;
                   6321:         } elsif ($secchange == 1) {
                   6322:             $$logmsg .= "Error when attempting to expire role for $uname in old section $oldsec in course $cid -error: $expire_role_result".$linefeed;
                   6323:         }
                   6324:     } else {
                   6325:         $$logmsg .= "Incomplete course id defined.  Addition of user $uname from domain $udom to course $one\_$two, section $sec not completed.$linefeed";
                   6326:         $result = "error: incomplete course id\n";
                   6327:     }
                   6328:     return $result;
                   6329: }
                   6330: 
                   6331: ############################################################
                   6332: ############################################################
                   6333: 
1.444     albertel 6334: sub construct_course {
                   6335:     my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname) = @_;
                   6336:     my $outcome;
                   6337: 
                   6338: #
                   6339: # Open course
                   6340: #
                   6341:     my $crstype = lc($args->{'crstype'});
                   6342:     my %cenv=();
                   6343:     $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
                   6344:                                              $args->{'cdescr'},
                   6345:                                              $args->{'curl'},
                   6346:                                              $args->{'course_home'},
                   6347:                                              $args->{'nonstandard'},
                   6348:                                              $args->{'crscode'},
                   6349:                                              $args->{'ccuname'}.':'.
                   6350:                                              $args->{'ccdomain'},
                   6351:                                              $args->{'crstype'});
                   6352: 
                   6353:     # Note: The testing routines depend on this being output; see 
                   6354:     # Utils::Course. This needs to at least be output as a comment
                   6355:     # if anyone ever decides to not show this, and Utils::Course::new
                   6356:     # will need to be suitably modified.
                   6357:     $outcome .= &mt('New LON-CAPA [_1] ID: [_2]<br />',$crstype,$$courseid);
                   6358: #
                   6359: # Check if created correctly
                   6360: #
1.479     albertel 6361:     ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444     albertel 6362:     my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
                   6363:     $outcome .= &mt('Created on').': '.$crsuhome.'<br>';
                   6364: #
                   6365: # Are we cloning?
                   6366: #
                   6367:     my $cloneid='';
                   6368:     if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
                   6369: 	$cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
1.479     albertel 6370:         my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
1.444     albertel 6371: 	my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
                   6372: 	if ($clonehome eq 'no_host') {
                   6373: 	    $outcome .=
                   6374:     '<br /><font color="red">'.&mt('Attempting to clone non-existing [_1]',$crstype).' '.$cloneid.'</font>';
                   6375: 	} else {
                   6376: 	    $outcome .= 
                   6377:     '<br /><font color="green">'.&mt('Cloning [_1] from [_2]',$crstype,$clonehome).'</font>';
                   6378: 	    my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
                   6379: # Copy all files
                   6380: 	    &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid);
                   6381: # Restore URL
                   6382: 	    $cenv{'url'}=$oldcenv{'url'};
                   6383: # Restore title
                   6384: 	    $cenv{'description'}=$oldcenv{'description'};
                   6385: # restore grading mode
                   6386: 	    if (defined($oldcenv{'grading'})) {
                   6387: 		$cenv{'grading'}=$oldcenv{'grading'};
                   6388: 	    }
                   6389: # Mark as cloned
                   6390: 	    $cenv{'clonedfrom'}=$cloneid;
                   6391: 	    delete($cenv{'default_enrollment_start_date'});
                   6392: 	    delete($cenv{'default_enrollment_end_date'});
                   6393: 	}
                   6394:     }
                   6395: #
                   6396: # Set environment (will override cloned, if existing)
                   6397: #
                   6398:     my @sections = ();
                   6399:     my @xlists = ();
                   6400:     if ($args->{'crstype'}) {
                   6401:         $cenv{'type'}=$args->{'crstype'};
                   6402:     }
                   6403:     if ($args->{'crsid'}) {
                   6404:         $cenv{'courseid'}=$args->{'crsid'};
                   6405:     }
                   6406:     if ($args->{'crscode'}) {
                   6407:         $cenv{'internal.coursecode'}=$args->{'crscode'};
                   6408:     }
                   6409:     if ($args->{'crsquota'} ne '') {
                   6410:         $cenv{'internal.coursequota'}=$args->{'crsquota'};
                   6411:     } else {
                   6412:         $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
                   6413:     }
                   6414:     if ($args->{'ccuname'}) {
                   6415:         $cenv{'internal.courseowner'} = $args->{'ccuname'}.
                   6416:                                         ':'.$args->{'ccdomain'};
                   6417:     } else {
                   6418:         $cenv{'internal.courseowner'} = $args->{'curruser'};
                   6419:     }
                   6420: 
                   6421:     my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
                   6422:     if ($args->{'crssections'}) {
                   6423:         $cenv{'internal.sectionnums'} = '';
                   6424:         if ($args->{'crssections'} =~ m/,/) {
                   6425:             @sections = split/,/,$args->{'crssections'};
                   6426:         } else {
                   6427:             $sections[0] = $args->{'crssections'};
                   6428:         }
                   6429:         if (@sections > 0) {
                   6430:             foreach my $item (@sections) {
                   6431:                 my ($sec,$gp) = split/:/,$item;
                   6432:                 my $class = $args->{'crscode'}.$sec;
                   6433:                 my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
                   6434:                 $cenv{'internal.sectionnums'} .= $item.',';
                   6435:                 unless ($addcheck eq 'ok') {
                   6436:                     push @badclasses, $class;
                   6437:                 }
                   6438:             }
                   6439:             $cenv{'internal.sectionnums'} =~ s/,$//;
                   6440:         }
                   6441:     }
                   6442: # do not hide course coordinator from staff listing, 
                   6443: # even if privileged
                   6444:     $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   6445: # add crosslistings
                   6446:     if ($args->{'crsxlist'}) {
                   6447:         $cenv{'internal.crosslistings'}='';
                   6448:         if ($args->{'crsxlist'} =~ m/,/) {
                   6449:             @xlists = split/,/,$args->{'crsxlist'};
                   6450:         } else {
                   6451:             $xlists[0] = $args->{'crsxlist'};
                   6452:         }
                   6453:         if (@xlists > 0) {
                   6454:             foreach my $item (@xlists) {
                   6455:                 my ($xl,$gp) = split/:/,$item;
                   6456:                 my $addcheck =  &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
                   6457:                 $cenv{'internal.crosslistings'} .= $item.',';
                   6458:                 unless ($addcheck eq 'ok') {
                   6459:                     push @badclasses, $xl;
                   6460:                 }
                   6461:             }
                   6462:             $cenv{'internal.crosslistings'} =~ s/,$//;
                   6463:         }
                   6464:     }
                   6465:     if ($args->{'autoadds'}) {
                   6466:         $cenv{'internal.autoadds'}=$args->{'autoadds'};
                   6467:     }
                   6468:     if ($args->{'autodrops'}) {
                   6469:         $cenv{'internal.autodrops'}=$args->{'autodrops'};
                   6470:     }
                   6471: # check for notification of enrollment changes
                   6472:     my @notified = ();
                   6473:     if ($args->{'notify_owner'}) {
                   6474:         if ($args->{'ccuname'} ne '') {
                   6475:             push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
                   6476:         }
                   6477:     }
                   6478:     if ($args->{'notify_dc'}) {
                   6479:         if ($uname ne '') { 
                   6480:             push(@notified,$uname.'@'.$udom);
                   6481:         }
                   6482:     }
                   6483:     if (@notified > 0) {
                   6484:         my $notifylist;
                   6485:         if (@notified > 1) {
                   6486:             $notifylist = join(',',@notified);
                   6487:         } else {
                   6488:             $notifylist = $notified[0];
                   6489:         }
                   6490:         $cenv{'internal.notifylist'} = $notifylist;
                   6491:     }
                   6492:     if (@badclasses > 0) {
                   6493:         my %lt=&Apache::lonlocal::texthash(
                   6494:                 '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',
                   6495:                 'dnhr' => 'does not have rights to access enrollment in these classes',
                   6496:                 'adby' => 'as determined by the policies of your institution on access to official classlists'
                   6497:         );
                   6498:         $outcome .= '<font color="red">'.$lt{'tclb'}.' ('.$cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.' ('.$lt{'adby'}.').<br /><ul>'."\n";
                   6499:         foreach (@badclasses) {
                   6500:             $outcome .= "<li>$_</li>\n";
                   6501:         }
                   6502:         $outcome .= "</ul><br /><br /></font>\n";
                   6503:     }
                   6504:     if ($args->{'no_end_date'}) {
                   6505:         $args->{'endaccess'} = 0;
                   6506:     }
                   6507:     $cenv{'internal.autostart'}=$args->{'enrollstart'};
                   6508:     $cenv{'internal.autoend'}=$args->{'enrollend'};
                   6509:     $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
                   6510:     $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
                   6511:     if ($args->{'showphotos'}) {
                   6512:       $cenv{'internal.showphotos'}=$args->{'showphotos'};
                   6513:     }
                   6514:     $cenv{'internal.authtype'} = $args->{'authtype'};
                   6515:     $cenv{'internal.autharg'} = $args->{'autharg'}; 
                   6516:     if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
                   6517:         if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'}  eq '') {
                   6518:             $outcome .= '<font color="red" size="+1">'.
                   6519:                       &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').'</font></p>';
                   6520:         }
                   6521:     }
                   6522:     if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
                   6523:        if ($args->{'setpolicy'}) {
                   6524:            $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   6525:        }
                   6526:        if ($args->{'setcontent'}) {
                   6527:            $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   6528:        }
                   6529:     }
                   6530:     if ($args->{'reshome'}) {
                   6531: 	$cenv{'reshome'}=$args->{'reshome'}.'/';
                   6532: 	$cenv{'reshome'}=~s/\/+$/\//;
                   6533:     }
                   6534: #
                   6535: # course has keyed access
                   6536: #
                   6537:     if ($args->{'setkeys'}) {
                   6538:        $cenv{'keyaccess'}='yes';
                   6539:     }
                   6540: # if specified, key authority is not course, but user
                   6541: # only active if keyaccess is yes
                   6542:     if ($args->{'keyauth'}) {
1.487     albertel 6543: 	my ($user,$domain) = split(':',$args->{'keyauth'});
                   6544: 	$user = &LONCAPA::clean_username($user);
                   6545: 	$domain = &LONCAPA::clean_username($domain);
1.488     foxr     6546: 	if ($user ne '' && $domain ne '') {
1.487     albertel 6547: 	    $cenv{'keyauth'}=$user.':'.$domain;
1.444     albertel 6548: 	}
                   6549:     }
                   6550: 
                   6551:     if ($args->{'disresdis'}) {
                   6552:         $cenv{'pch.roles.denied'}='st';
                   6553:     }
                   6554:     if ($args->{'disablechat'}) {
                   6555:         $cenv{'plc.roles.denied'}='st';
                   6556:     }
                   6557: 
                   6558:     # Record we've not yet viewed the Course Initialization Helper for this 
                   6559:     # course
                   6560:     $cenv{'course.helper.not.run'} = 1;
                   6561:     #
                   6562:     # Use new Randomseed
                   6563:     #
                   6564:     $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
                   6565:     $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
                   6566:     #
                   6567:     # The encryption code and receipt prefix for this course
                   6568:     #
                   6569:     $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
                   6570:     $cenv{'internal.encpref'}=100+int(9*rand(99));
                   6571:     #
                   6572:     # By default, use standard grading
                   6573:     if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
                   6574: 
                   6575:     $outcome .= ('<br />'.&mt('Setting environment').': '.                 
                   6576:           &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).'<br>');
                   6577: #
                   6578: # Open all assignments
                   6579: #
                   6580:     if ($args->{'openall'}) {
                   6581:        my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
                   6582:        my %storecontent = ($storeunder         => time,
                   6583:                            $storeunder.'.type' => 'date_start');
                   6584:        
                   6585:        $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
                   6586:                  ('resourcedata',\%storecontent,$$crsudom,$$crsunum).'<br>';
                   6587:    }
                   6588: #
                   6589: # Set first page
                   6590: #
                   6591:     unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
                   6592: 	    || ($cloneid)) {
1.445     albertel 6593: 	use LONCAPA::map;
1.444     albertel 6594: 	$outcome .= &mt('Setting first resource').': ';
1.445     albertel 6595: 
                   6596: 	my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
                   6597:         my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
                   6598: 
1.444     albertel 6599:         $outcome .= ($fatal?$errtext:'read ok').' - ';
                   6600:         my $title; my $url;
                   6601:         if ($args->{'firstres'} eq 'syl') {
                   6602: 	    $title='Syllabus';
                   6603:             $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
                   6604:         } else {
                   6605:             $title='Navigate Contents';
                   6606:             $url='/adm/navmaps';
                   6607:         }
1.445     albertel 6608: 
                   6609:         $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
                   6610: 	(my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
                   6611: 
                   6612: 	if ($errtext) { $fatal=2; }
                   6613:         $outcome .= ($fatal?$errtext:'write ok').'<br />';
1.444     albertel 6614:     }
                   6615:     return $outcome;
                   6616: }
                   6617: 
                   6618: ############################################################
                   6619: ############################################################
                   6620: 
1.378     raeburn  6621: sub course_type {
                   6622:     my ($cid) = @_;
                   6623:     if (!defined($cid)) {
                   6624:         $cid = $env{'request.course.id'};
                   6625:     }
1.404     albertel 6626:     if (defined($env{'course.'.$cid.'.type'})) {
                   6627:         return $env{'course.'.$cid.'.type'};
1.378     raeburn  6628:     } else {
                   6629:         return 'Course';
1.377     raeburn  6630:     }
                   6631: }
1.156     albertel 6632: 
1.406     raeburn  6633: sub group_term {
                   6634:     my $crstype = &course_type();
                   6635:     my %names = (
                   6636:                   'Course' => 'group',
                   6637:                   'Group' => 'team',
                   6638:                 );
                   6639:     return $names{$crstype};
                   6640: }
                   6641: 
1.156     albertel 6642: sub icon {
                   6643:     my ($file)=@_;
1.505     albertel 6644:     my $curfext = lc((split(/\./,$file))[-1]);
1.168     albertel 6645:     my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156     albertel 6646:     my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168     albertel 6647:     if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
                   6648: 	if (-e  $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
                   6649: 	          $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   6650: 	            $curfext.".gif") {
                   6651: 	    $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   6652: 		$curfext.".gif";
                   6653: 	}
                   6654:     }
1.249     albertel 6655:     return &lonhttpdurl($iconname);
1.154     albertel 6656: } 
1.84      albertel 6657: 
1.215     albertel 6658: sub lonhttpdurl {
                   6659:     my ($url)=@_;
                   6660:     my $lonhttpd_port=$Apache::lonnet::perlvar{'lonhttpdPort'};
                   6661:     if (!defined($lonhttpd_port)) { $lonhttpd_port='8080'; }
                   6662:     return 'http://'.$ENV{'SERVER_NAME'}.':'.$lonhttpd_port.$url;
                   6663: }
                   6664: 
1.213     albertel 6665: sub connection_aborted {
                   6666:     my ($r)=@_;
                   6667:     $r->print(" ");$r->rflush();
                   6668:     my $c = $r->connection;
                   6669:     return $c->aborted();
                   6670: }
                   6671: 
1.221     foxr     6672: #    Escapes strings that may have embedded 's that will be put into
1.222     foxr     6673: #    strings as 'strings'.
                   6674: sub escape_single {
1.221     foxr     6675:     my ($input) = @_;
1.223     albertel 6676:     $input =~ s/\\/\\\\/g;	# Escape the \'s..(must be first)>
1.221     foxr     6677:     $input =~ s/\'/\\\'/g;	# Esacpe the 's....
                   6678:     return $input;
                   6679: }
1.223     albertel 6680: 
1.222     foxr     6681: #  Same as escape_single, but escape's "'s  This 
                   6682: #  can be used for  "strings"
                   6683: sub escape_double {
                   6684:     my ($input) = @_;
                   6685:     $input =~ s/\\/\\\\/g;	# Escape the /'s..(must be first)>
                   6686:     $input =~ s/\"/\\\"/g;	# Esacpe the "s....
                   6687:     return $input;
                   6688: }
1.223     albertel 6689:  
1.222     foxr     6690: #   Escapes the last element of a full URL.
                   6691: sub escape_url {
                   6692:     my ($url)   = @_;
1.238     raeburn  6693:     my @urlslices = split(/\//, $url,-1);
1.369     www      6694:     my $lastitem = &escape(pop(@urlslices));
1.223     albertel 6695:     return join('/',@urlslices).'/'.$lastitem;
1.222     foxr     6696: }
1.462     albertel 6697: 
                   6698: # -------------------------------------------------------- Initliaze user login
                   6699: sub init_user_environment {
1.463     albertel 6700:     my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462     albertel 6701:     my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
                   6702: 
                   6703:     my $public=($username eq 'public' && $domain eq 'public');
                   6704: 
                   6705: # See if old ID present, if so, remove
                   6706: 
                   6707:     my ($filename,$cookie,$userroles);
                   6708:     my $now=time;
                   6709: 
                   6710:     if ($public) {
                   6711: 	my $max_public=100;
                   6712: 	my $oldest;
                   6713: 	my $oldest_time=0;
                   6714: 	for(my $next=1;$next<=$max_public;$next++) {
                   6715: 	    if (-e $lonids."/publicuser_$next.id") {
                   6716: 		my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
                   6717: 		if ($mtime<$oldest_time || !$oldest_time) {
                   6718: 		    $oldest_time=$mtime;
                   6719: 		    $oldest=$next;
                   6720: 		}
                   6721: 	    } else {
                   6722: 		$cookie="publicuser_$next";
                   6723: 		last;
                   6724: 	    }
                   6725: 	}
                   6726: 	if (!$cookie) { $cookie="publicuser_$oldest"; }
                   6727:     } else {
1.463     albertel 6728: 	# if this isn't a robot, kill any existing non-robot sessions
                   6729: 	if (!$args->{'robot'}) {
                   6730: 	    opendir(DIR,$lonids);
                   6731: 	    while ($filename=readdir(DIR)) {
                   6732: 		if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
                   6733: 		    unlink($lonids.'/'.$filename);
                   6734: 		}
1.462     albertel 6735: 	    }
1.463     albertel 6736: 	    closedir(DIR);
1.462     albertel 6737: 	}
                   6738: # Give them a new cookie
1.463     albertel 6739: 	my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
                   6740: 		                   : $now);
                   6741: 	$cookie="$username\_$id\_$domain\_$authhost";
1.462     albertel 6742:     
                   6743: # Initialize roles
                   6744: 
                   6745: 	$userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
                   6746:     }
                   6747: # ------------------------------------ Check browser type and MathML capability
                   6748: 
                   6749:     my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
                   6750:         $clientunicode,$clientos) = &decode_user_agent($r);
                   6751: 
                   6752: # -------------------------------------- Any accessibility options to remember?
                   6753:     if (($form->{'interface'}) && ($form->{'remember'} eq 'true')) {
                   6754: 	foreach my $option ('imagesuppress','appletsuppress',
                   6755: 			    'embedsuppress','fontenhance','blackwhite') {
                   6756: 	    if ($form->{$option} eq 'true') {
                   6757: 		&Apache::lonnet::put('environment',{$option => 'on'},
                   6758: 				     $domain,$username);
                   6759: 	    } else {
                   6760: 		&Apache::lonnet::del('environment',[$option],
                   6761: 				     $domain,$username);
                   6762: 	    }
                   6763: 	}
                   6764:     }
                   6765: # ------------------------------------------------------------- Get environment
                   6766: 
                   6767:     my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
                   6768:     my ($tmp) = keys(%userenv);
                   6769:     if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   6770: 	# default remote control to off
                   6771: 	if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
                   6772:     } else {
                   6773: 	undef(%userenv);
                   6774:     }
                   6775:     if (($userenv{'interface'}) && (!$form->{'interface'})) {
                   6776: 	$form->{'interface'}=$userenv{'interface'};
                   6777:     }
                   6778:     $env{'environment.remote'}=$userenv{'remote'};
                   6779:     if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
                   6780: 
                   6781: # --------------- Do not trust query string to be put directly into environment
                   6782:     foreach my $option ('imagesuppress','appletsuppress',
                   6783: 			'embedsuppress','fontenhance','blackwhite',
                   6784: 			'interface','localpath','localres') {
                   6785: 	$form->{$option}=~s/[\n\r\=]//gs;
                   6786:     }
                   6787: # --------------------------------------------------------- Write first profile
                   6788: 
                   6789:     {
                   6790: 	my %initial_env = 
                   6791: 	    ("user.name"          => $username,
                   6792: 	     "user.domain"        => $domain,
                   6793: 	     "user.home"          => $authhost,
                   6794: 	     "browser.type"       => $clientbrowser,
                   6795: 	     "browser.version"    => $clientversion,
                   6796: 	     "browser.mathml"     => $clientmathml,
                   6797: 	     "browser.unicode"    => $clientunicode,
                   6798: 	     "browser.os"         => $clientos,
                   6799: 	     "server.domain"      => $Apache::lonnet::perlvar{'lonDefDomain'},
                   6800: 	     "request.course.fn"  => '',
                   6801: 	     "request.course.uri" => '',
                   6802: 	     "request.course.sec" => '',
                   6803: 	     "request.role"       => 'cm',
                   6804: 	     "request.role.adv"   => $env{'user.adv'},
                   6805: 	     "request.host"       => $ENV{'REMOTE_ADDR'},);
                   6806: 
                   6807:         if ($form->{'localpath'}) {
                   6808: 	    $initial_env{"browser.localpath"}  = $form->{'localpath'};
                   6809: 	    $initial_env{"browser.localres"}   = $form->{'localres'};
                   6810:         }
                   6811: 	
                   6812: 	if ($public) {
                   6813: 	    $initial_env{"environment.remote"} = "off";
                   6814: 	}
                   6815: 	if ($form->{'interface'}) {
                   6816: 	    $form->{'interface'}=~s/\W//gs;
                   6817: 	    $initial_env{"browser.interface"} = $form->{'interface'};
                   6818: 	    $env{'browser.interface'}=$form->{'interface'};
                   6819: 	    foreach my $option ('imagesuppress','appletsuppress',
                   6820: 				'embedsuppress','fontenhance','blackwhite') {
                   6821: 		if (($form->{$option} eq 'true') ||
                   6822: 		    ($userenv{$option} eq 'on')) {
                   6823: 		    $initial_env{"browser.$option"} = "on";
                   6824: 		}
                   6825: 	    }
                   6826: 	}
                   6827: 
                   6828: 	$env{'user.environment'} = "$lonids/$cookie.id";
                   6829: 	
                   6830: 	if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
                   6831: 		 &GDBM_WRCREAT(),0640)) {
                   6832: 	    &_add_to_env(\%disk_env,\%initial_env);
                   6833: 	    &_add_to_env(\%disk_env,\%userenv,'environment.');
                   6834: 	    &_add_to_env(\%disk_env,$userroles);
1.463     albertel 6835: 	    if (ref($args->{'extra_env'})) {
                   6836: 		&_add_to_env(\%disk_env,$args->{'extra_env'});
                   6837: 	    }
1.462     albertel 6838: 	    untie(%disk_env);
                   6839: 	} else {
                   6840: 	    &Apache::lonnet::logthis("<font color=\"blue\">WARNING: ".
                   6841: 			   'Could not create environment storage in lonauth: '.$!.'</font>');
                   6842: 	    return 'error: '.$!;
                   6843: 	}
                   6844:     }
                   6845:     $env{'request.role'}='cm';
                   6846:     $env{'request.role.adv'}=$env{'user.adv'};
                   6847:     $env{'browser.type'}=$clientbrowser;
                   6848: 
                   6849:     return $cookie;
                   6850: 
                   6851: }
                   6852: 
                   6853: sub _add_to_env {
                   6854:     my ($idf,$env_data,$prefix) = @_;
                   6855:     while (my ($key,$value) = each(%$env_data)) {
                   6856: 	$idf->{$prefix.$key} = $value;
                   6857: 	$env{$prefix.$key}   = $value;
                   6858:     }
                   6859: }
                   6860: 
                   6861: 
1.41      ng       6862: =pod
                   6863: 
                   6864: =back
                   6865: 
1.112     bowersj2 6866: =cut
1.41      ng       6867: 
1.112     bowersj2 6868: 1;
                   6869: __END__;
1.41      ng       6870: 

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