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

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

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