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

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

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