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

1.10      albertel    1: # The LearningOnline Network with CAPA
1.1       albertel    2: # a pile of common routines
1.10      albertel    3: #
1.744   ! ehlerst     4: # $Id: loncommon.pm,v 1.743 2009/02/07 20:45:27 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.685     tempelho   64: use Apache::lonnet();
1.139     matthew    65: use HTML::Entities;
1.334     albertel   66: use Apache::lonhtmlcommon();
                     67: use Apache::loncoursedata();
1.344     albertel   68: use Apache::lontexconvert();
1.444     albertel   69: use Apache::lonclonecourse();
1.479     albertel   70: use LONCAPA qw(:DEFAULT :match);
1.657     raeburn    71: use DateTime::TimeZone;
1.687     raeburn    72: use DateTime::Locale::Catalog;
1.117     www        73: 
1.517     raeburn    74: # ---------------------------------------------- Designs
                     75: use vars qw(%defaultdesign);
                     76: 
1.22      www        77: my $readit;
                     78: 
1.517     raeburn    79: 
1.157     matthew    80: ##
                     81: ## Global Variables
                     82: ##
1.46      matthew    83: 
1.643     foxr       84: 
                     85: # ----------------------------------------------- SSI with retries:
                     86: #
                     87: 
                     88: =pod
                     89: 
1.648     raeburn    90: =head1 Server Side include with retries:
1.643     foxr       91: 
                     92: =over 4
                     93: 
1.648     raeburn    94: =item * &ssi_with_retries(resource,retries form)
1.643     foxr       95: 
                     96: Performs an ssi with some number of retries.  Retries continue either
                     97: until the result is ok or until the retry count supplied by the
                     98: caller is exhausted.  
                     99: 
                    100: Inputs:
1.648     raeburn   101: 
                    102: =over 4
                    103: 
1.643     foxr      104: resource   - Identifies the resource to insert.
1.648     raeburn   105: 
1.643     foxr      106: retries    - Count of the number of retries allowed.
1.648     raeburn   107: 
1.643     foxr      108: form       - Hash that identifies the rendering options.
                    109: 
1.648     raeburn   110: =back
                    111: 
                    112: Returns:
                    113: 
                    114: =over 4
                    115: 
1.643     foxr      116: content    - The content of the response.  If retries were exhausted this is empty.
1.648     raeburn   117: 
1.643     foxr      118: response   - The response from the last attempt (which may or may not have been successful.
                    119: 
1.648     raeburn   120: =back
                    121: 
                    122: =back
                    123: 
1.643     foxr      124: =cut
                    125: 
                    126: sub ssi_with_retries {
                    127:     my ($resource, $retries, %form) = @_;
                    128: 
                    129: 
                    130:     my $ok = 0;			# True if we got a good response.
                    131:     my $content;
                    132:     my $response;
                    133: 
                    134:     # Try to get the ssi done. within the retries count:
                    135: 
                    136:     do {
                    137: 	($content, $response) = &Apache::lonnet::ssi($resource, %form);
                    138: 	$ok      = $response->is_success;
1.650     www       139:         if (!$ok) {
                    140:             &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
                    141:         }
1.643     foxr      142: 	$retries--;
                    143:     } while (!$ok && ($retries > 0));
                    144: 
                    145:     if (!$ok) {
                    146: 	$content = '';		# On error return an empty content.
                    147:     }
                    148:     return ($content, $response);
                    149: 
                    150: }
                    151: 
                    152: 
                    153: 
1.20      www       154: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12      harris41  155: my %language;
1.124     www       156: my %supported_language;
1.12      harris41  157: my %cprtag;
1.192     taceyjo1  158: my %scprtag;
1.351     www       159: my %fe; my %fd; my %fm;
1.41      ng        160: my %category_extensions;
1.12      harris41  161: 
1.46      matthew   162: # ---------------------------------------------- Thesaurus variables
1.144     matthew   163: #
                    164: # %Keywords:
                    165: #      A hash used by &keyword to determine if a word is considered a keyword.
                    166: # $thesaurus_db_file 
                    167: #      Scalar containing the full path to the thesaurus database.
1.46      matthew   168: 
                    169: my %Keywords;
                    170: my $thesaurus_db_file;
                    171: 
1.144     matthew   172: #
                    173: # Initialize values from language.tab, copyright.tab, filetypes.tab,
                    174: # thesaurus.tab, and filecategories.tab.
                    175: #
1.18      www       176: BEGIN {
1.46      matthew   177:     # Variable initialization
                    178:     $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
                    179:     #
1.22      www       180:     unless ($readit) {
1.12      harris41  181: # ------------------------------------------------------------------- languages
                    182:     {
1.158     raeburn   183:         my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
                    184:                                    '/language.tab';
                    185:         if ( open(my $fh,"<$langtabfile") ) {
1.356     albertel  186:             while (my $line = <$fh>) {
                    187:                 next if ($line=~/^\#/);
                    188:                 chomp($line);
                    189:                 my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$line));
1.158     raeburn   190:                 $language{$key}=$val.' - '.$enc;
                    191:                 if ($sup) {
                    192:                     $supported_language{$key}=$sup;
                    193:                 }
                    194:             }
                    195:             close($fh);
                    196:         }
1.12      harris41  197:     }
                    198: # ------------------------------------------------------------------ copyrights
                    199:     {
1.158     raeburn   200:         my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
                    201:                                   '/copyright.tab';
                    202:         if ( open (my $fh,"<$copyrightfile") ) {
1.356     albertel  203:             while (my $line = <$fh>) {
                    204:                 next if ($line=~/^\#/);
                    205:                 chomp($line);
                    206:                 my ($key,$val)=(split(/\s+/,$line,2));
1.158     raeburn   207:                 $cprtag{$key}=$val;
                    208:             }
                    209:             close($fh);
                    210:         }
1.12      harris41  211:     }
1.351     www       212: # ----------------------------------------------------------- source copyrights
1.192     taceyjo1  213:     {
                    214:         my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
                    215:                                   '/source_copyright.tab';
                    216:         if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356     albertel  217:             while (my $line = <$fh>) {
                    218:                 next if ($line =~ /^\#/);
                    219:                 chomp($line);
                    220:                 my ($key,$val)=(split(/\s+/,$line,2));
1.192     taceyjo1  221:                 $scprtag{$key}=$val;
                    222:             }
                    223:             close($fh);
                    224:         }
                    225:     }
1.63      www       226: 
1.517     raeburn   227: # -------------------------------------------------------------- default domain designs
1.63      www       228:     my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517     raeburn   229:     my $designfile = $designdir.'/default.tab';
                    230:     if ( open (my $fh,"<$designfile") ) {
                    231:         while (my $line = <$fh>) {
                    232:             next if ($line =~ /^\#/);
                    233:             chomp($line);
                    234:             my ($key,$val)=(split(/\=/,$line));
                    235:             if ($val) { $defaultdesign{$key}=$val; }
                    236:         }
                    237:         close($fh);
1.63      www       238:     }
                    239: 
1.15      harris41  240: # ------------------------------------------------------------- file categories
                    241:     {
1.158     raeburn   242:         my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
                    243:                                   '/filecategories.tab';
                    244:         if ( open (my $fh,"<$categoryfile") ) {
1.356     albertel  245: 	    while (my $line = <$fh>) {
                    246: 		next if ($line =~ /^\#/);
                    247: 		chomp($line);
                    248:                 my ($extension,$category)=(split(/\s+/,$line,2));
1.158     raeburn   249:                 push @{$category_extensions{lc($category)}},$extension;
                    250:             }
                    251:             close($fh);
                    252:         }
                    253: 
1.15      harris41  254:     }
1.12      harris41  255: # ------------------------------------------------------------------ file types
                    256:     {
1.158     raeburn   257:         my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
                    258:                '/filetypes.tab';
                    259:         if ( open (my $fh,"<$typesfile") ) {
1.356     albertel  260:             while (my $line = <$fh>) {
                    261: 		next if ($line =~ /^\#/);
                    262: 		chomp($line);
                    263:                 my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158     raeburn   264:                 if ($descr ne '') {
                    265:                     $fe{$ending}=lc($emb);
                    266:                     $fd{$ending}=$descr;
1.351     www       267:                     if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158     raeburn   268:                 }
                    269:             }
                    270:             close($fh);
                    271:         }
1.12      harris41  272:     }
1.22      www       273:     &Apache::lonnet::logthis(
1.705     tempelho  274:              "<span style='color:yellow;'>INFO: Read file types</span>");
1.22      www       275:     $readit=1;
1.46      matthew   276:     }  # end of unless($readit) 
1.32      matthew   277:     
                    278: }
1.112     bowersj2  279: 
1.42      matthew   280: ###############################################################
                    281: ##           HTML and Javascript Helper Functions            ##
                    282: ###############################################################
                    283: 
                    284: =pod 
                    285: 
1.112     bowersj2  286: =head1 HTML and Javascript Functions
1.42      matthew   287: 
1.112     bowersj2  288: =over 4
                    289: 
1.648     raeburn   290: =item * &browser_and_searcher_javascript()
1.112     bowersj2  291: 
                    292: X<browsing, javascript>X<searching, javascript>Returns a string
                    293: containing javascript with two functions, C<openbrowser> and
                    294: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
                    295: tags.
1.42      matthew   296: 
1.648     raeburn   297: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42      matthew   298: 
                    299: inputs: formname, elementname, only, omit
                    300: 
                    301: formname and elementname indicate the name of the html form and name of
                    302: the element that the results of the browsing selection are to be placed in. 
                    303: 
                    304: Specifying 'only' will restrict the browser to displaying only files
1.185     www       305: with the given extension.  Can be a comma separated list.
1.42      matthew   306: 
                    307: Specifying 'omit' will restrict the browser to NOT displaying files
1.185     www       308: with the given extension.  Can be a comma separated list.
1.42      matthew   309: 
1.648     raeburn   310: =item * &opensearcher(formname,elementname) [javascript]
1.42      matthew   311: 
                    312: Inputs: formname, elementname
                    313: 
                    314: formname and elementname specify the name of the html form and the name
                    315: of the element the selection from the search results will be placed in.
1.542     raeburn   316: 
1.42      matthew   317: =cut
                    318: 
                    319: sub browser_and_searcher_javascript {
1.199     albertel  320:     my ($mode)=@_;
                    321:     if (!defined($mode)) { $mode='edit'; }
1.453     albertel  322:     my $resurl=&escape_single(&lastresurl());
1.42      matthew   323:     return <<END;
1.219     albertel  324: // <!-- BEGIN LON-CAPA Internal
1.50      matthew   325:     var editbrowser = null;
1.135     albertel  326:     function openbrowser(formname,elementname,only,omit,titleelement) {
1.170     www       327:         var url = '$resurl/?';
1.42      matthew   328:         if (editbrowser == null) {
                    329:             url += 'launch=1&';
                    330:         }
                    331:         url += 'catalogmode=interactive&';
1.199     albertel  332:         url += 'mode=$mode&';
1.611     albertel  333:         url += 'inhibitmenu=yes&';
1.42      matthew   334:         url += 'form=' + formname + '&';
                    335:         if (only != null) {
                    336:             url += 'only=' + only + '&';
1.217     albertel  337:         } else {
                    338:             url += 'only=&';
                    339: 	}
1.42      matthew   340:         if (omit != null) {
                    341:             url += 'omit=' + omit + '&';
1.217     albertel  342:         } else {
                    343:             url += 'omit=&';
                    344: 	}
1.135     albertel  345:         if (titleelement != null) {
                    346:             url += 'titleelement=' + titleelement + '&';
1.217     albertel  347:         } else {
                    348: 	    url += 'titleelement=&';
                    349: 	}
1.42      matthew   350:         url += 'element=' + elementname + '';
                    351:         var title = 'Browser';
1.435     albertel  352:         var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42      matthew   353:         options += ',width=700,height=600';
                    354:         editbrowser = open(url,title,options,'1');
                    355:         editbrowser.focus();
                    356:     }
                    357:     var editsearcher;
1.135     albertel  358:     function opensearcher(formname,elementname,titleelement) {
1.42      matthew   359:         var url = '/adm/searchcat?';
                    360:         if (editsearcher == null) {
                    361:             url += 'launch=1&';
                    362:         }
                    363:         url += 'catalogmode=interactive&';
1.199     albertel  364:         url += 'mode=$mode&';
1.42      matthew   365:         url += 'form=' + formname + '&';
1.135     albertel  366:         if (titleelement != null) {
                    367:             url += 'titleelement=' + titleelement + '&';
1.217     albertel  368:         } else {
                    369: 	    url += 'titleelement=&';
                    370: 	}
1.42      matthew   371:         url += 'element=' + elementname + '';
                    372:         var title = 'Search';
1.435     albertel  373:         var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42      matthew   374:         options += ',width=700,height=600';
                    375:         editsearcher = open(url,title,options,'1');
                    376:         editsearcher.focus();
                    377:     }
1.219     albertel  378: // END LON-CAPA Internal -->
1.42      matthew   379: END
1.170     www       380: }
                    381: 
                    382: sub lastresurl {
1.258     albertel  383:     if ($env{'environment.lastresurl'}) {
                    384: 	return $env{'environment.lastresurl'}
1.170     www       385:     } else {
                    386: 	return '/res';
                    387:     }
                    388: }
                    389: 
                    390: sub storeresurl {
                    391:     my $resurl=&Apache::lonnet::clutter(shift);
                    392:     unless ($resurl=~/^\/res/) { return 0; }
                    393:     $resurl=~s/\/$//;
                    394:     &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646     raeburn   395:     &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170     www       396:     return 1;
1.42      matthew   397: }
                    398: 
1.74      www       399: sub studentbrowser_javascript {
1.111     www       400:    unless (
1.258     albertel  401:             (($env{'request.course.id'}) && 
1.302     albertel  402:              (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
                    403: 	      || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
                    404: 					  '/'.$env{'request.course.sec'})
                    405: 	      ))
1.258     albertel  406:          || ($env{'request.role'}=~/^(au|dc|su)/)
1.111     www       407:           ) { return ''; }  
1.74      www       408:    return (<<'ENDSTDBRW');
                    409: <script type="text/javascript" language="Javascript" >
                    410:     var stdeditbrowser;
1.558     albertel  411:     function openstdbrowser(formname,uname,udom,roleflag,ignorefilter) {
1.74      www       412:         var url = '/adm/pickstudent?';
                    413:         var filter;
1.558     albertel  414: 	if (!ignorefilter) {
                    415: 	    eval('filter=document.'+formname+'.'+uname+'.value;');
                    416: 	}
1.74      www       417:         if (filter != null) {
                    418:            if (filter != '') {
                    419:                url += 'filter='+filter+'&';
                    420: 	   }
                    421:         }
                    422:         url += 'form=' + formname + '&unameelement='+uname+
                    423:                                     '&udomelement='+udom;
1.111     www       424: 	if (roleflag) { url+="&roles=1"; }
1.102     www       425:         var title = 'Student_Browser';
1.74      www       426:         var options = 'scrollbars=1,resizable=1,menubar=0';
                    427:         options += ',width=700,height=600';
                    428:         stdeditbrowser = open(url,title,options,'1');
                    429:         stdeditbrowser.focus();
                    430:     }
                    431: </script>
                    432: ENDSTDBRW
                    433: }
1.42      matthew   434: 
1.74      www       435: sub selectstudent_link {
1.111     www       436:    my ($form,$unameele,$udomele)=@_;
1.258     albertel  437:    if ($env{'request.course.id'}) {  
1.302     albertel  438:        if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
                    439: 	   && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
                    440: 					'/'.$env{'request.course.sec'})) {
1.111     www       441: 	   return '';
                    442:        }
                    443:        return "<a href='".'javascript:openstdbrowser("'.$form.'","'.$unameele.
1.607     albertel  444:         '","'.$udomele.'");'."'>".&mt('Select User')."</a>";
1.74      www       445:    }
1.258     albertel  446:    if ($env{'request.role'}=~/^(au|dc|su)/) {
1.111     www       447:        return "<a href='".'javascript:openstdbrowser("'.$form.'","'.$unameele.
1.119     www       448:         '","'.$udomele.'",1);'."'>".&mt('Select User')."</a>";
1.111     www       449:    }
                    450:    return '';
1.91      www       451: }
                    452: 
1.653     raeburn   453: sub authorbrowser_javascript {
                    454:     return <<"ENDAUTHORBRW";
                    455: <script type="text/javascript">
                    456: var stdeditbrowser;
                    457: 
                    458: function openauthorbrowser(formname,udom) {
                    459:     var url = '/adm/pickauthor?';
                    460:     url += 'form='+formname+'&roledom='+udom;
                    461:     var title = 'Author_Browser';
                    462:     var options = 'scrollbars=1,resizable=1,menubar=0';
                    463:     options += ',width=700,height=600';
                    464:     stdeditbrowser = open(url,title,options,'1');
                    465:     stdeditbrowser.focus();
                    466: }
                    467: 
                    468: </script>
                    469: ENDAUTHORBRW
                    470: }
                    471: 
1.91      www       472: sub coursebrowser_javascript {
1.468     raeburn   473:     my ($domainfilter,$sec_element,$formname)=@_;
1.377     raeburn   474:     my $crs_or_grp_alert = &mt('Please select the type of LON-CAPA entity - Course or Group - for which you wish to add/modify a user role');
1.468     raeburn   475:    my $output = '
1.538     albertel  476: <script type="text/javascript">
1.468     raeburn   477:     var stdeditbrowser;'."\n";
                    478:    $output .= <<"ENDSTDBRW";
1.377     raeburn   479:     function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,crstype) {
1.91      www       480:         var url = '/adm/pickcourse?';
1.468     raeburn   481:         var domainfilter = '';
                    482:         var formid = getFormIdByName(formname);
                    483:         if (formid > -1) {
                    484:             var domid = getIndexByName(formid,udom);
                    485:             if (domid > -1) {
                    486:                 if (document.forms[formid].elements[domid].type == 'select-one') {
                    487:                     domainfilter=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
                    488:                 }
                    489:                 if (document.forms[formid].elements[domid].type == 'hidden') {
                    490:                     domainfilter=document.forms[formid].elements[domid].value;
                    491:                 }
                    492:             }
1.91      www       493:         }
1.128     albertel  494:         if (domainfilter != null) {
                    495:            if (domainfilter != '') {
                    496:                url += 'domainfilter='+domainfilter+'&';
                    497: 	   }
                    498:         }
1.91      www       499:         url += 'form=' + formname + '&cnumelement='+uname+
1.187     albertel  500: 	                            '&cdomelement='+udom+
                    501:                                     '&cnameelement='+desc;
1.468     raeburn   502:         if (extra_element !=null && extra_element != '') {
1.594     raeburn   503:             if (formname == 'rolechoice' || formname == 'studentform') {
1.468     raeburn   504:                 url += '&roleelement='+extra_element;
                    505:                 if (domainfilter == null || domainfilter == '') {
                    506:                     url += '&domainfilter='+extra_element;
                    507:                 }
1.234     raeburn   508:             }
1.468     raeburn   509:             else {
                    510:                 if (formname == 'portform') {
                    511:                     url += '&setroles='+extra_element;
                    512:                 }
                    513:             }     
1.230     raeburn   514:         }
1.293     raeburn   515:         if (multflag !=null && multflag != '') {
                    516:             url += '&multiple='+multflag;
                    517:         }
1.377     raeburn   518:         if (crstype == 'Course/Group') {
                    519:             if (formname == 'cu') {
                    520:                 crstype = document.cu.crstype.options[document.cu.crstype.selectedIndex].value; 
                    521:                 if (crstype == "") {
                    522:                     alert("$crs_or_grp_alert");
                    523:                     return;
                    524:                 }
                    525:             }
                    526:         }
                    527:         if (crstype !=null && crstype != '') {
                    528:             url += '&type='+crstype;
                    529:         }
1.102     www       530:         var title = 'Course_Browser';
1.91      www       531:         var options = 'scrollbars=1,resizable=1,menubar=0';
                    532:         options += ',width=700,height=600';
                    533:         stdeditbrowser = open(url,title,options,'1');
                    534:         stdeditbrowser.focus();
                    535:     }
1.468     raeburn   536: 
                    537:     function getFormIdByName(formname) {
                    538:         for (var i=0;i<document.forms.length;i++) {
                    539:             if (document.forms[i].name == formname) {
                    540:                 return i;
                    541:             }
                    542:         }
                    543:         return -1; 
                    544:     }
                    545: 
                    546:     function getIndexByName(formid,item) {
                    547:         for (var i=0;i<document.forms[formid].elements.length;i++) {
                    548:             if (document.forms[formid].elements[i].name == item) {
                    549:                 return i;
                    550:             }
                    551:         }
                    552:         return -1;
                    553:     }
1.91      www       554: ENDSTDBRW
1.468     raeburn   555:     if ($sec_element ne '') {
                    556:         $output .= &setsec_javascript($sec_element,$formname);
                    557:     }
                    558:     $output .= '
                    559: </script>';
                    560:     return $output;
                    561: }
                    562: 
                    563: sub setsec_javascript {
                    564:     my ($sec_element,$formname) = @_;
                    565:     my $setsections = qq|
                    566: function setSect(sectionlist) {
1.629     raeburn   567:     var sectionsArray = new Array();
                    568:     if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
                    569:         sectionsArray = sectionlist.split(",");
                    570:     }
1.468     raeburn   571:     var numSections = sectionsArray.length;
                    572:     document.$formname.$sec_element.length = 0;
                    573:     if (numSections == 0) {
                    574:         document.$formname.$sec_element.multiple=false;
                    575:         document.$formname.$sec_element.size=1;
                    576:         document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
                    577:     } else {
                    578:         if (numSections == 1) {
                    579:             document.$formname.$sec_element.multiple=false;
                    580:             document.$formname.$sec_element.size=1;
                    581:             document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
                    582:             document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
                    583:             document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
                    584:         } else {
                    585:             for (var i=0; i<numSections; i++) {
                    586:                 document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
                    587:             }
                    588:             document.$formname.$sec_element.multiple=true
                    589:             if (numSections < 3) {
                    590:                 document.$formname.$sec_element.size=numSections;
                    591:             } else {
                    592:                 document.$formname.$sec_element.size=3;
                    593:             }
                    594:             document.$formname.$sec_element.options[0].selected = false
                    595:         }
                    596:     }
1.91      www       597: }
1.468     raeburn   598: |;
                    599:     return $setsections;
                    600: }
                    601: 
1.91      www       602: 
                    603: sub selectcourse_link {
1.377     raeburn   604:    my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype)=@_;
1.492     albertel  605:    return "<a href='".'javascript:opencrsbrowser("'.$form.'","'.$unameele.
                    606:         '","'.$udomele.'","'.$desc.'","'.$extra_element.'","'.$multflag.'","'.$selecttype.'");'."'>".&mt('Select Course')."</a>";
1.74      www       607: }
1.42      matthew   608: 
1.653     raeburn   609: sub selectauthor_link {
                    610:    my ($form,$udom)=@_;
                    611:    return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
                    612:           &mt('Select Author').'</a>';
                    613: }
                    614: 
1.273     raeburn   615: sub check_uncheck_jscript {
                    616:     my $jscript = <<"ENDSCRT";
                    617: function checkAll(field) {
                    618:     if (field.length > 0) {
                    619:         for (i = 0; i < field.length; i++) {
                    620:             field[i].checked = true ;
                    621:         }
                    622:     } else {
                    623:         field.checked = true
                    624:     }
                    625: }
                    626:  
                    627: function uncheckAll(field) {
                    628:     if (field.length > 0) {
                    629:         for (i = 0; i < field.length; i++) {
                    630:             field[i].checked = false ;
1.543     albertel  631:         }
                    632:     } else {
1.273     raeburn   633:         field.checked = false ;
                    634:     }
                    635: }
                    636: ENDSCRT
                    637:     return $jscript;
                    638: }
                    639: 
1.656     www       640: sub select_timezone {
1.659     raeburn   641:    my ($name,$selected,$onchange,$includeempty)=@_;
                    642:    my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
                    643:    if ($includeempty) {
                    644:        $output .= '<option value=""';
                    645:        if (($selected eq '') || ($selected eq 'local')) {
                    646:            $output .= ' selected="selected" ';
                    647:        }
                    648:        $output .= '> </option>';
                    649:    }
1.657     raeburn   650:    my @timezones = DateTime::TimeZone->all_names;
                    651:    foreach my $tzone (@timezones) {
                    652:        $output.= '<option value="'.$tzone.'"';
                    653:        if ($tzone eq $selected) {
                    654:            $output.=' selected="selected"';
                    655:        }
                    656:        $output.=">$tzone</option>\n";
1.656     www       657:    }
                    658:    $output.="</select>";
                    659:    return $output;
                    660: }
1.273     raeburn   661: 
1.687     raeburn   662: sub select_datelocale {
                    663:     my ($name,$selected,$onchange,$includeempty)=@_;
                    664:     my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
                    665:     if ($includeempty) {
                    666:         $output .= '<option value=""';
                    667:         if ($selected eq '') {
                    668:             $output .= ' selected="selected" ';
                    669:         }
                    670:         $output .= '> </option>';
                    671:     }
                    672:     my (@possibles,%locale_names);
                    673:     my @locales = DateTime::Locale::Catalog::Locales;
                    674:     foreach my $locale (@locales) {
                    675:         if (ref($locale) eq 'HASH') {
                    676:             my $id = $locale->{'id'};
                    677:             if ($id ne '') {
                    678:                 my $en_terr = $locale->{'en_territory'};
                    679:                 my $native_terr = $locale->{'native_territory'};
1.695     raeburn   680:                 my @languages = &Apache::lonlocal::preferred_languages();
1.687     raeburn   681:                 if (grep(/^en$/,@languages) || !@languages) {
                    682:                     if ($en_terr ne '') {
                    683:                         $locale_names{$id} = '('.$en_terr.')';
                    684:                     } elsif ($native_terr ne '') {
                    685:                         $locale_names{$id} = $native_terr;
                    686:                     }
                    687:                 } else {
                    688:                     if ($native_terr ne '') {
                    689:                         $locale_names{$id} = $native_terr.' ';
                    690:                     } elsif ($en_terr ne '') {
                    691:                         $locale_names{$id} = '('.$en_terr.')';
                    692:                     }
                    693:                 }
                    694:                 push (@possibles,$id);
                    695:             }
                    696:         }
                    697:     }
                    698:     foreach my $item (sort(@possibles)) {
                    699:         $output.= '<option value="'.$item.'"';
                    700:         if ($item eq $selected) {
                    701:             $output.=' selected="selected"';
                    702:         }
                    703:         $output.=">$item";
                    704:         if ($locale_names{$item} ne '') {
                    705:             $output.="  $locale_names{$item}</option>\n";
                    706:         }
                    707:         $output.="</option>\n";
                    708:     }
                    709:     $output.="</select>";
                    710:     return $output;
                    711: }
                    712: 
1.42      matthew   713: =pod
1.36      matthew   714: 
1.648     raeburn   715: =item * &linked_select_forms(...)
1.36      matthew   716: 
                    717: linked_select_forms returns a string containing a <script></script> block
                    718: and html for two <select> menus.  The select menus will be linked in that
                    719: changing the value of the first menu will result in new values being placed
                    720: in the second menu.  The values in the select menu will appear in alphabetical
1.609     raeburn   721: order unless a defined order is provided.
1.36      matthew   722: 
                    723: linked_select_forms takes the following ordered inputs:
                    724: 
                    725: =over 4
                    726: 
1.112     bowersj2  727: =item * $formname, the name of the <form> tag
1.36      matthew   728: 
1.112     bowersj2  729: =item * $middletext, the text which appears between the <select> tags
1.36      matthew   730: 
1.112     bowersj2  731: =item * $firstdefault, the default value for the first menu
1.36      matthew   732: 
1.112     bowersj2  733: =item * $firstselectname, the name of the first <select> tag
1.36      matthew   734: 
1.112     bowersj2  735: =item * $secondselectname, the name of the second <select> tag
1.36      matthew   736: 
1.112     bowersj2  737: =item * $hashref, a reference to a hash containing the data for the menus.
1.36      matthew   738: 
1.609     raeburn   739: =item * $menuorder, the order of values in the first menu
                    740: 
1.41      ng        741: =back 
                    742: 
1.36      matthew   743: Below is an example of such a hash.  Only the 'text', 'default', and 
                    744: 'select2' keys must appear as stated.  keys(%menu) are the possible 
                    745: values for the first select menu.  The text that coincides with the 
1.41      ng        746: first menu value is given in $menu{$choice1}->{'text'}.  The values 
1.36      matthew   747: and text for the second menu are given in the hash pointed to by 
                    748: $menu{$choice1}->{'select2'}.  
                    749: 
1.112     bowersj2  750:  my %menu = ( A1 => { text =>"Choice A1" ,
                    751:                        default => "B3",
                    752:                        select2 => { 
                    753:                            B1 => "Choice B1",
                    754:                            B2 => "Choice B2",
                    755:                            B3 => "Choice B3",
                    756:                            B4 => "Choice B4"
1.609     raeburn   757:                            },
                    758:                        order => ['B4','B3','B1','B2'],
1.112     bowersj2  759:                    },
                    760:                A2 => { text =>"Choice A2" ,
                    761:                        default => "C2",
                    762:                        select2 => { 
                    763:                            C1 => "Choice C1",
                    764:                            C2 => "Choice C2",
                    765:                            C3 => "Choice C3"
1.609     raeburn   766:                            },
                    767:                        order => ['C2','C1','C3'],
1.112     bowersj2  768:                    },
                    769:                A3 => { text =>"Choice A3" ,
                    770:                        default => "D6",
                    771:                        select2 => { 
                    772:                            D1 => "Choice D1",
                    773:                            D2 => "Choice D2",
                    774:                            D3 => "Choice D3",
                    775:                            D4 => "Choice D4",
                    776:                            D5 => "Choice D5",
                    777:                            D6 => "Choice D6",
                    778:                            D7 => "Choice D7"
1.609     raeburn   779:                            },
                    780:                        order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112     bowersj2  781:                    }
                    782:                );
1.36      matthew   783: 
                    784: =cut
                    785: 
                    786: sub linked_select_forms {
                    787:     my ($formname,
                    788:         $middletext,
                    789:         $firstdefault,
                    790:         $firstselectname,
                    791:         $secondselectname, 
1.609     raeburn   792:         $hashref,
                    793:         $menuorder,
1.36      matthew   794:         ) = @_;
                    795:     my $second = "document.$formname.$secondselectname";
                    796:     my $first = "document.$formname.$firstselectname";
                    797:     # output the javascript to do the changing
                    798:     my $result = '';
1.219     albertel  799:     $result.="<script type=\"text/javascript\">\n";
1.36      matthew   800:     $result.="var select2data = new Object();\n";
                    801:     $" = '","';
                    802:     my $debug = '';
                    803:     foreach my $s1 (sort(keys(%$hashref))) {
                    804:         $result.="select2data.d_$s1 = new Object();\n";        
                    805:         $result.="select2data.d_$s1.def = new String('".
                    806:             $hashref->{$s1}->{'default'}."');\n";
1.609     raeburn   807:         $result.="select2data.d_$s1.values = new Array(";
1.36      matthew   808:         my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609     raeburn   809:         if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
                    810:             @s2values = @{$hashref->{$s1}->{'order'}};
                    811:         }
1.36      matthew   812:         $result.="\"@s2values\");\n";
                    813:         $result.="select2data.d_$s1.texts = new Array(";        
                    814:         my @s2texts;
                    815:         foreach my $value (@s2values) {
                    816:             push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
                    817:         }
                    818:         $result.="\"@s2texts\");\n";
                    819:     }
                    820:     $"=' ';
                    821:     $result.= <<"END";
                    822: 
                    823: function select1_changed() {
                    824:     // Determine new choice
                    825:     var newvalue = "d_" + $first.value;
                    826:     // update select2
                    827:     var values     = select2data[newvalue].values;
                    828:     var texts      = select2data[newvalue].texts;
                    829:     var select2def = select2data[newvalue].def;
                    830:     var i;
                    831:     // out with the old
                    832:     for (i = 0; i < $second.options.length; i++) {
                    833:         $second.options[i] = null;
                    834:     }
                    835:     // in with the nuclear
                    836:     for (i=0;i<values.length; i++) {
                    837:         $second.options[i] = new Option(values[i]);
1.143     matthew   838:         $second.options[i].value = values[i];
1.36      matthew   839:         $second.options[i].text = texts[i];
                    840:         if (values[i] == select2def) {
                    841:             $second.options[i].selected = true;
                    842:         }
                    843:     }
                    844: }
                    845: </script>
                    846: END
                    847:     # output the initial values for the selection lists
                    848:     $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609     raeburn   849:     my @order = sort(keys(%{$hashref}));
                    850:     if (ref($menuorder) eq 'ARRAY') {
                    851:         @order = @{$menuorder};
                    852:     }
                    853:     foreach my $value (@order) {
1.36      matthew   854:         $result.="    <option value=\"$value\" ";
1.253     albertel  855:         $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119     www       856:         $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36      matthew   857:     }
                    858:     $result .= "</select>\n";
                    859:     my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
                    860:     $result .= $middletext;
                    861:     $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
                    862:     my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609     raeburn   863:     
                    864:     my @secondorder = sort(keys(%select2));
                    865:     if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
                    866:         @secondorder = @{$hashref->{$firstdefault}->{'order'}};
                    867:     }
                    868:     foreach my $value (@secondorder) {
1.36      matthew   869:         $result.="    <option value=\"$value\" ";        
1.253     albertel  870:         $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119     www       871:         $result.=">".&mt($select2{$value})."</option>\n";
1.36      matthew   872:     }
                    873:     $result .= "</select>\n";
                    874:     #    return $debug;
                    875:     return $result;
                    876: }   #  end of sub linked_select_forms {
                    877: 
1.45      matthew   878: =pod
1.44      bowersj2  879: 
1.648     raeburn   880: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height)
1.44      bowersj2  881: 
1.112     bowersj2  882: Returns a string corresponding to an HTML link to the given help
                    883: $topic, where $topic corresponds to the name of a .tex file in
                    884: /home/httpd/html/adm/help/tex, with underscores replaced by
                    885: spaces. 
                    886: 
                    887: $text will optionally be linked to the same topic, allowing you to
                    888: link text in addition to the graphic. If you do not want to link
                    889: text, but wish to specify one of the later parameters, pass an
                    890: empty string. 
                    891: 
                    892: $stayOnPage is a value that will be interpreted as a boolean. If true,
                    893: the link will not open a new window. If false, the link will open
                    894: a new window using Javascript. (Default is false.) 
                    895: 
                    896: $width and $height are optional numerical parameters that will
                    897: override the width and height of the popped up window, which may
                    898: be useful for certain help topics with big pictures included. 
1.44      bowersj2  899: 
                    900: =cut
                    901: 
                    902: sub help_open_topic {
1.48      bowersj2  903:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
                    904:     $text = "" if (not defined $text);
1.44      bowersj2  905:     $stayOnPage = 0 if (not defined $stayOnPage);
1.552     banghart  906:     if ($env{'browser.interface'} eq 'textual') {
1.79      www       907: 	$stayOnPage=1;
                    908:     }
1.44      bowersj2  909:     $width = 350 if (not defined $width);
                    910:     $height = 400 if (not defined $height);
                    911:     my $filename = $topic;
                    912:     $filename =~ s/ /_/g;
                    913: 
1.48      bowersj2  914:     my $template = "";
                    915:     my $link;
1.572     banghart  916:     
1.159     www       917:     $topic=~s/\W/\_/g;
1.44      bowersj2  918: 
1.572     banghart  919:     if (!$stayOnPage) {
1.72      bowersj2  920: 	$link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1.572     banghart  921:     } else {
1.48      bowersj2  922: 	$link = "/adm/help/${filename}.hlp";
                    923:     }
                    924: 
                    925:     # Add the text
1.572     banghart  926:     if ($text ne "") {
1.77      www       927: 	$template .= 
1.572     banghart  928:             "<table bgcolor='#3333AA' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705     tempelho  929:             "<td bgcolor='#5555FF'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.48      bowersj2  930:     }
                    931: 
                    932:     # Add the graphic
1.179     matthew   933:     my $title = &mt('Online Help');
1.667     raeburn   934:     my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.48      bowersj2  935:     $template .= <<"ENDTEMPLATE";
1.436     albertel  936:  <a target="_top" href="$link" title="$title"><img src="$helpicon" border="0" alt="(Help: $topic)" /></a>
1.44      bowersj2  937: ENDTEMPLATE
1.705     tempelho  938:     if ($text ne '') { $template.='</td></tr></table>' };
1.44      bowersj2  939:     return $template;
                    940: 
1.106     bowersj2  941: }
                    942: 
                    943: # This is a quicky function for Latex cheatsheet editing, since it 
                    944: # appears in at least four places
                    945: sub helpLatexCheatsheet {
1.732     raeburn   946:     my ($topic,$text,$not_author) = @_;
                    947:     my $out;
1.106     bowersj2  948:     my $addOther = '';
1.732     raeburn   949:     if ($topic) {
                    950: 	$addOther = &Apache::loncommon::help_open_topic($topic,$text,
                    951: 						       undef, undef, 600).
1.106     bowersj2  952: 							   '</td><td>';
                    953:     }
1.732     raeburn   954:     $out = '<table><tr><td>'.
                    955: 	   $addOther .
                    956: 	   &Apache::loncommon::help_open_topic("Greek_Symbols",&mt('Greek Symbols'),
                    957: 					       undef,undef,600).
                    958: 	   '</td><td>'.
                    959: 	   &Apache::loncommon::help_open_topic("Other_Symbols",&mt('Other Symbols'),
                    960: 					       undef,undef,600).
                    961: 	   '</td>';
                    962:     unless ($not_author) {
                    963:         $out .= '<td>'.
                    964: 	        &Apache::loncommon::help_open_topic("Authoring_Output_Tags",&mt('Output Tags'),
                    965: 	                                            undef,undef,600).
                    966: 	        '</td>';
                    967:     }
                    968:     $out .= '</tr></table>';
                    969:     return $out;
1.172     www       970: }
                    971: 
1.430     albertel  972: sub general_help {
                    973:     my $helptopic='Student_Intro';
                    974:     if ($env{'request.role'}=~/^(ca|au)/) {
                    975: 	$helptopic='Authoring_Intro';
                    976:     } elsif ($env{'request.role'}=~/^cc/) {
                    977: 	$helptopic='Course_Coordination_Intro';
1.672     raeburn   978:     } elsif ($env{'request.role'}=~/^dc/) {
                    979:         $helptopic='Domain_Coordination_Intro';
1.430     albertel  980:     }
                    981:     return $helptopic;
                    982: }
                    983: 
                    984: sub update_help_link {
                    985:     my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
                    986:     my $origurl = $ENV{'REQUEST_URI'};
                    987:     $origurl=~s|^/~|/priv/|;
                    988:     my $timestamp = time;
                    989:     foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
                    990:         $$datum = &escape($$datum);
                    991:     }
                    992: 
                    993:     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";
                    994:     my $output .= <<"ENDOUTPUT";
                    995: <script type="text/javascript">
                    996: banner_link = '$banner_link';
                    997: </script>
                    998: ENDOUTPUT
                    999:     return $output;
                   1000: }
                   1001: 
                   1002: # now just updates the help link and generates a blue icon
1.193     raeburn  1003: sub help_open_menu {
1.430     albertel 1004:     my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text) 
1.552     banghart 1005: 	= @_;    
1.430     albertel 1006:     $stayOnPage = 0 if (not defined $stayOnPage);
1.572     banghart 1007:     # only use pop-up help (stayOnPage == 0)
1.552     banghart 1008:     # if environment.remote is on (using remote control UI)
1.572     banghart 1009:     if ($env{'browser.interface'} eq 'textual' ||
                   1010:     	$env{'environment.remote'} eq 'off' ) {
1.552     banghart 1011:         $stayOnPage=1;
1.430     albertel 1012:     }
                   1013:     my $output;
                   1014:     if ($component_help) {
                   1015: 	if (!$text) {
                   1016: 	    $output=&help_open_topic($component_help,undef,$stayOnPage,
                   1017: 				       $width,$height);
                   1018: 	} else {
                   1019: 	    my $help_text;
                   1020: 	    $help_text=&unescape($topic);
                   1021: 	    $output='<table><tr><td>'.
                   1022: 		&help_open_topic($component_help,$help_text,$stayOnPage,
                   1023: 				 $width,$height).'</td></tr></table>';
                   1024: 	}
                   1025:     }
                   1026:     my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
                   1027:     return $output.$banner_link;
                   1028: }
                   1029: 
                   1030: sub top_nav_help {
                   1031:     my ($text) = @_;
1.436     albertel 1032:     $text = &mt($text);
1.572     banghart 1033:     my $stay_on_page = 
1.436     albertel 1034: 	($env{'browser.interface'}  eq 'textual' ||
                   1035: 	 $env{'environment.remote'} eq 'off' );
1.572     banghart 1036:     my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436     albertel 1037: 	                     : "javascript:helpMenu('open')";
1.572     banghart 1038:     my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436     albertel 1039: 
1.201     raeburn  1040:     my $title = &mt('Get help');
1.436     albertel 1041: 
                   1042:     return <<"END";
                   1043: $banner_link
                   1044:  <a href="$link" title="$title">$text</a>
                   1045: END
                   1046: }
                   1047: 
                   1048: sub help_menu_js {
                   1049:     my ($text) = @_;
                   1050: 
                   1051:     my $stayOnPage = 
                   1052: 	($env{'browser.interface'}  eq 'textual' ||
                   1053: 	 $env{'environment.remote'} eq 'off' );
                   1054: 
                   1055:     my $width = 620;
                   1056:     my $height = 600;
1.430     albertel 1057:     my $helptopic=&general_help();
                   1058:     my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261     albertel 1059:     my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331     albertel 1060:     my $start_page =
                   1061:         &Apache::loncommon::start_page('Help Menu', undef,
                   1062: 				       {'frameset'    => 1,
                   1063: 					'js_ready'    => 1,
                   1064: 					'add_entries' => {
                   1065: 					    'border' => '0',
1.579     raeburn  1066: 					    'rows'   => "110,*",},});
1.331     albertel 1067:     my $end_page =
                   1068:         &Apache::loncommon::end_page({'frameset' => 1,
                   1069: 				      'js_ready' => 1,});
                   1070: 
1.436     albertel 1071:     my $template .= <<"ENDTEMPLATE";
                   1072: <script type="text/javascript">
1.253     albertel 1073: // <!-- BEGIN LON-CAPA Internal
                   1074: // <![CDATA[
1.430     albertel 1075: var banner_link = '';
1.243     raeburn  1076: function helpMenu(target) {
                   1077:     var caller = this;
                   1078:     if (target == 'open') {
                   1079:         var newWindow = null;
                   1080:         try {
1.262     albertel 1081:             newWindow =  window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243     raeburn  1082:         }
                   1083:         catch(error) {
                   1084:             writeHelp(caller);
                   1085:             return;
                   1086:         }
                   1087:         if (newWindow) {
                   1088:             caller = newWindow;
                   1089:         }
1.193     raeburn  1090:     }
1.243     raeburn  1091:     writeHelp(caller);
                   1092:     return;
                   1093: }
                   1094: function writeHelp(caller) {
1.430     albertel 1095:     caller.document.writeln('$start_page<frame name="bannerframe"  src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243     raeburn  1096:     caller.document.close()
                   1097:     caller.focus()
1.193     raeburn  1098: }
1.253     albertel 1099: // ]]>
1.219     albertel 1100: // END LON-CAPA Internal -->
1.436     albertel 1101: </script>
1.193     raeburn  1102: ENDTEMPLATE
                   1103:     return $template;
                   1104: }
                   1105: 
1.172     www      1106: sub help_open_bug {
                   1107:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258     albertel 1108:     unless ($env{'user.adv'}) { return ''; }
1.172     www      1109:     unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
                   1110:     $text = "" if (not defined $text);
                   1111:     $stayOnPage = 0 if (not defined $stayOnPage);
1.258     albertel 1112:     if ($env{'browser.interface'} eq 'textual' ||
                   1113: 	$env{'environment.remote'} eq 'off' ) {
1.172     www      1114: 	$stayOnPage=1;
                   1115:     }
1.184     albertel 1116:     $width = 600 if (not defined $width);
                   1117:     $height = 600 if (not defined $height);
1.172     www      1118: 
                   1119:     $topic=~s/\W+/\+/g;
                   1120:     my $link='';
                   1121:     my $template='';
1.379     albertel 1122:     my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&amp;bug_file_loc='.
                   1123: 	&escape($ENV{'REQUEST_URI'}).'&amp;component='.$topic;
1.172     www      1124:     if (!$stayOnPage)
                   1125:     {
                   1126: 	$link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
                   1127:     }
                   1128:     else
                   1129:     {
                   1130: 	$link = $url;
                   1131:     }
                   1132:     # Add the text
                   1133:     if ($text ne "")
                   1134:     {
                   1135: 	$template .= 
                   1136:   "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705     tempelho 1137:   "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172     www      1138:     }
                   1139: 
                   1140:     # Add the graphic
1.179     matthew  1141:     my $title = &mt('Report a Bug');
1.215     albertel 1142:     my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172     www      1143:     $template .= <<"ENDTEMPLATE";
1.436     albertel 1144:  <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172     www      1145: ENDTEMPLATE
                   1146:     if ($text ne '') { $template.='</td></tr></table>' };
                   1147:     return $template;
                   1148: 
                   1149: }
                   1150: 
                   1151: sub help_open_faq {
                   1152:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258     albertel 1153:     unless ($env{'user.adv'}) { return ''; }
1.172     www      1154:     unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
                   1155:     $text = "" if (not defined $text);
                   1156:     $stayOnPage = 0 if (not defined $stayOnPage);
1.258     albertel 1157:     if ($env{'browser.interface'} eq 'textual' ||
                   1158: 	$env{'environment.remote'} eq 'off' ) {
1.172     www      1159: 	$stayOnPage=1;
                   1160:     }
                   1161:     $width = 350 if (not defined $width);
                   1162:     $height = 400 if (not defined $height);
                   1163: 
                   1164:     $topic=~s/\W+/\+/g;
                   1165:     my $link='';
                   1166:     my $template='';
                   1167:     my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
                   1168:     if (!$stayOnPage)
                   1169:     {
                   1170: 	$link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
                   1171:     }
                   1172:     else
                   1173:     {
                   1174: 	$link = $url;
                   1175:     }
                   1176: 
                   1177:     # Add the text
                   1178:     if ($text ne "")
                   1179:     {
                   1180: 	$template .= 
1.173     www      1181:   "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705     tempelho 1182:   "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172     www      1183:     }
                   1184: 
                   1185:     # Add the graphic
1.179     matthew  1186:     my $title = &mt('View the FAQ');
1.215     albertel 1187:     my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172     www      1188:     $template .= <<"ENDTEMPLATE";
1.436     albertel 1189:  <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172     www      1190: ENDTEMPLATE
                   1191:     if ($text ne '') { $template.='</td></tr></table>' };
                   1192:     return $template;
                   1193: 
1.44      bowersj2 1194: }
1.37      matthew  1195: 
1.180     matthew  1196: ###############################################################
                   1197: ###############################################################
                   1198: 
1.45      matthew  1199: =pod
                   1200: 
1.648     raeburn  1201: =item * &change_content_javascript():
1.256     matthew  1202: 
                   1203: This and the next function allow you to create small sections of an
                   1204: otherwise static HTML page that you can update on the fly with
                   1205: Javascript, even in Netscape 4.
                   1206: 
                   1207: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
                   1208: must be written to the HTML page once. It will prove the Javascript
                   1209: function "change(name, content)". Calling the change function with the
                   1210: name of the section 
                   1211: you want to update, matching the name passed to C<changable_area>, and
                   1212: the new content you want to put in there, will put the content into
                   1213: that area.
                   1214: 
                   1215: B<Note>: Netscape 4 only reserves enough space for the changable area
                   1216: to contain room for the original contents. You need to "make space"
                   1217: for whatever changes you wish to make, and be B<sure> to check your
                   1218: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
                   1219: it's adequate for updating a one-line status display, but little more.
                   1220: This script will set the space to 100% width, so you only need to
                   1221: worry about height in Netscape 4.
                   1222: 
                   1223: Modern browsers are much less limiting, and if you can commit to the
                   1224: user not using Netscape 4, this feature may be used freely with
                   1225: pretty much any HTML.
                   1226: 
                   1227: =cut
                   1228: 
                   1229: sub change_content_javascript {
                   1230:     # If we're on Netscape 4, we need to use Layer-based code
1.258     albertel 1231:     if ($env{'browser.type'} eq 'netscape' &&
                   1232: 	$env{'browser.version'} =~ /^4\./) {
1.256     matthew  1233: 	return (<<NETSCAPE4);
                   1234: 	function change(name, content) {
                   1235: 	    doc = document.layers[name+"___escape"].layers[0].document;
                   1236: 	    doc.open();
                   1237: 	    doc.write(content);
                   1238: 	    doc.close();
                   1239: 	}
                   1240: NETSCAPE4
                   1241:     } else {
                   1242: 	# Otherwise, we need to use semi-standards-compliant code
                   1243: 	# (technically, "innerHTML" isn't standard but the equivalent
                   1244: 	# is really scary, and every useful browser supports it
                   1245: 	return (<<DOMBASED);
                   1246: 	function change(name, content) {
                   1247: 	    element = document.getElementById(name);
                   1248: 	    element.innerHTML = content;
                   1249: 	}
                   1250: DOMBASED
                   1251:     }
                   1252: }
                   1253: 
                   1254: =pod
                   1255: 
1.648     raeburn  1256: =item * &changable_area($name,$origContent):
1.256     matthew  1257: 
                   1258: This provides a "changable area" that can be modified on the fly via
                   1259: the Javascript code provided in C<change_content_javascript>. $name is
                   1260: the name you will use to reference the area later; do not repeat the
                   1261: same name on a given HTML page more then once. $origContent is what
                   1262: the area will originally contain, which can be left blank.
                   1263: 
                   1264: =cut
                   1265: 
                   1266: sub changable_area {
                   1267:     my ($name, $origContent) = @_;
                   1268: 
1.258     albertel 1269:     if ($env{'browser.type'} eq 'netscape' &&
                   1270: 	$env{'browser.version'} =~ /^4\./) {
1.256     matthew  1271: 	# If this is netscape 4, we need to use the Layer tag
                   1272: 	return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
                   1273:     } else {
                   1274: 	return "<span id='$name'>$origContent</span>";
                   1275:     }
                   1276: }
                   1277: 
                   1278: =pod
                   1279: 
1.648     raeburn  1280: =item * &viewport_geometry_js 
1.590     raeburn  1281: 
                   1282: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
                   1283: 
                   1284: =cut
                   1285: 
                   1286: 
                   1287: sub viewport_geometry_js { 
                   1288:     return <<"GEOMETRY";
                   1289: var Geometry = {};
                   1290: function init_geometry() {
                   1291:     if (Geometry.init) { return };
                   1292:     Geometry.init=1;
                   1293:     if (window.innerHeight) {
                   1294:         Geometry.getViewportHeight   = function() { return window.innerHeight; };
                   1295:         Geometry.getViewportWidth   = function() { return window.innerWidth; };
                   1296:         Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
                   1297:         Geometry.getVerticalScroll   = function() { return window.pageYOffset; };
                   1298:     }
                   1299:     else if (document.documentElement && document.documentElement.clientHeight) {
                   1300:         Geometry.getViewportHeight =
                   1301:             function() { return document.documentElement.clientHeight; };
                   1302:         Geometry.getViewportWidth =
                   1303:             function() { return document.documentElement.clientWidth; };
                   1304: 
                   1305:         Geometry.getHorizontalScroll =
                   1306:             function() { return document.documentElement.scrollLeft; };
                   1307:         Geometry.getVerticalScroll =
                   1308:             function() { return document.documentElement.scrollTop; };
                   1309:     }
                   1310:     else if (document.body.clientHeight) {
                   1311:         Geometry.getViewportHeight =
                   1312:             function() { return document.body.clientHeight; };
                   1313:         Geometry.getViewportWidth =
                   1314:             function() { return document.body.clientWidth; };
                   1315:         Geometry.getHorizontalScroll =
                   1316:             function() { return document.body.scrollLeft; };
                   1317:         Geometry.getVerticalScroll =
                   1318:             function() { return document.body.scrollTop; };
                   1319:     }
                   1320: }
                   1321: 
                   1322: GEOMETRY
                   1323: }
                   1324: 
                   1325: =pod
                   1326: 
1.648     raeburn  1327: =item * &viewport_size_js()
1.590     raeburn  1328: 
                   1329: 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. 
                   1330: 
                   1331: =cut
                   1332: 
                   1333: sub viewport_size_js {
                   1334:     my $geometry = &viewport_geometry_js();
                   1335:     return <<"DIMS";
                   1336: 
                   1337: $geometry
                   1338: 
                   1339: function getViewportDims(width,height) {
                   1340:     init_geometry();
                   1341:     width.value = Geometry.getViewportWidth();
                   1342:     height.value = Geometry.getViewportHeight();
                   1343:     return;
                   1344: }
                   1345: 
                   1346: DIMS
                   1347: }
                   1348: 
                   1349: =pod
                   1350: 
1.648     raeburn  1351: =item * &resize_textarea_js()
1.565     albertel 1352: 
                   1353: emits the needed javascript to resize a textarea to be as big as possible
                   1354: 
                   1355: creates a function resize_textrea that takes two IDs first should be
                   1356: the id of the element to resize, second should be the id of a div that
                   1357: surrounds everything that comes after the textarea, this routine needs
                   1358: to be attached to the <body> for the onload and onresize events.
                   1359: 
1.648     raeburn  1360: =back
1.565     albertel 1361: 
                   1362: =cut
                   1363: 
                   1364: sub resize_textarea_js {
1.590     raeburn  1365:     my $geometry = &viewport_geometry_js();
1.565     albertel 1366:     return <<"RESIZE";
                   1367:     <script type="text/javascript">
1.590     raeburn  1368: $geometry
1.565     albertel 1369: 
1.588     albertel 1370: function getX(element) {
                   1371:     var x = 0;
                   1372:     while (element) {
                   1373: 	x += element.offsetLeft;
                   1374: 	element = element.offsetParent;
                   1375:     }
                   1376:     return x;
                   1377: }
                   1378: function getY(element) {
                   1379:     var y = 0;
                   1380:     while (element) {
                   1381: 	y += element.offsetTop;
                   1382: 	element = element.offsetParent;
                   1383:     }
                   1384:     return y;
                   1385: }
                   1386: 
                   1387: 
1.565     albertel 1388: function resize_textarea(textarea_id,bottom_id) {
                   1389:     init_geometry();
                   1390:     var textarea        = document.getElementById(textarea_id);
                   1391:     //alert(textarea);
                   1392: 
1.588     albertel 1393:     var textarea_top    = getY(textarea);
1.565     albertel 1394:     var textarea_height = textarea.offsetHeight;
                   1395:     var bottom          = document.getElementById(bottom_id);
1.588     albertel 1396:     var bottom_top      = getY(bottom);
1.565     albertel 1397:     var bottom_height   = bottom.offsetHeight;
                   1398:     var window_height   = Geometry.getViewportHeight();
1.588     albertel 1399:     var fudge           = 23;
1.565     albertel 1400:     var new_height      = window_height-fudge-textarea_top-bottom_height;
                   1401:     if (new_height < 300) {
                   1402: 	new_height = 300;
                   1403:     }
                   1404:     textarea.style.height=new_height+'px';
                   1405: }
                   1406: </script>
                   1407: RESIZE
                   1408: 
                   1409: }
                   1410: 
                   1411: =pod
                   1412: 
1.256     matthew  1413: =head1 Excel and CSV file utility routines
                   1414: 
                   1415: =over 4
                   1416: 
                   1417: =cut
                   1418: 
                   1419: ###############################################################
                   1420: ###############################################################
                   1421: 
                   1422: =pod
                   1423: 
1.648     raeburn  1424: =item * &csv_translate($text) 
1.37      matthew  1425: 
1.185     www      1426: Translate $text to allow it to be output as a 'comma separated values' 
1.37      matthew  1427: format.
                   1428: 
                   1429: =cut
                   1430: 
1.180     matthew  1431: ###############################################################
                   1432: ###############################################################
1.37      matthew  1433: sub csv_translate {
                   1434:     my $text = shift;
                   1435:     $text =~ s/\"/\"\"/g;
1.209     albertel 1436:     $text =~ s/\n/ /g;
1.37      matthew  1437:     return $text;
                   1438: }
1.180     matthew  1439: 
                   1440: ###############################################################
                   1441: ###############################################################
                   1442: 
                   1443: =pod
                   1444: 
1.648     raeburn  1445: =item * &define_excel_formats()
1.180     matthew  1446: 
                   1447: Define some commonly used Excel cell formats.
                   1448: 
                   1449: Currently supported formats:
                   1450: 
                   1451: =over 4
                   1452: 
                   1453: =item header
                   1454: 
                   1455: =item bold
                   1456: 
                   1457: =item h1
                   1458: 
                   1459: =item h2
                   1460: 
                   1461: =item h3
                   1462: 
1.256     matthew  1463: =item h4
                   1464: 
                   1465: =item i
                   1466: 
1.180     matthew  1467: =item date
                   1468: 
                   1469: =back
                   1470: 
                   1471: Inputs: $workbook
                   1472: 
                   1473: Returns: $format, a hash reference.
                   1474: 
                   1475: =cut
                   1476: 
                   1477: ###############################################################
                   1478: ###############################################################
                   1479: sub define_excel_formats {
                   1480:     my ($workbook) = @_;
                   1481:     my $format;
                   1482:     $format->{'header'} = $workbook->add_format(bold      => 1, 
                   1483:                                                 bottom    => 1,
                   1484:                                                 align     => 'center');
                   1485:     $format->{'bold'} = $workbook->add_format(bold=>1);
                   1486:     $format->{'h1'}   = $workbook->add_format(bold=>1, size=>18);
                   1487:     $format->{'h2'}   = $workbook->add_format(bold=>1, size=>16);
                   1488:     $format->{'h3'}   = $workbook->add_format(bold=>1, size=>14);
1.255     matthew  1489:     $format->{'h4'}   = $workbook->add_format(bold=>1, size=>12);
1.246     matthew  1490:     $format->{'i'}    = $workbook->add_format(italic=>1);
1.180     matthew  1491:     $format->{'date'} = $workbook->add_format(num_format=>
1.207     matthew  1492:                                             'mm/dd/yyyy hh:mm:ss');
1.180     matthew  1493:     return $format;
                   1494: }
                   1495: 
                   1496: ###############################################################
                   1497: ###############################################################
1.113     bowersj2 1498: 
                   1499: =pod
                   1500: 
1.648     raeburn  1501: =item * &create_workbook()
1.255     matthew  1502: 
                   1503: Create an Excel worksheet.  If it fails, output message on the
                   1504: request object and return undefs.
                   1505: 
                   1506: Inputs: Apache request object
                   1507: 
                   1508: Returns (undef) on failure, 
                   1509:     Excel worksheet object, scalar with filename, and formats 
                   1510:     from &Apache::loncommon::define_excel_formats on success
                   1511: 
                   1512: =cut
                   1513: 
                   1514: ###############################################################
                   1515: ###############################################################
                   1516: sub create_workbook {
                   1517:     my ($r) = @_;
                   1518:         #
                   1519:     # Create the excel spreadsheet
                   1520:     my $filename = '/prtspool/'.
1.258     albertel 1521:         $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255     matthew  1522:         time.'_'.rand(1000000000).'.xls';
                   1523:     my $workbook  = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
                   1524:     if (! defined($workbook)) {
                   1525:         $r->log_error("Error creating excel spreadsheet $filename: $!");
                   1526:         $r->print('<p>'.&mt("Unable to create new Excel file.  ".
                   1527:                             "This error has been logged.  ".
                   1528:                             "Please alert your LON-CAPA administrator").
                   1529:                   '</p>');
                   1530:         return (undef);
                   1531:     }
                   1532:     #
                   1533:     $workbook->set_tempdir('/home/httpd/perl/tmp');
                   1534:     #
                   1535:     my $format = &Apache::loncommon::define_excel_formats($workbook);
                   1536:     return ($workbook,$filename,$format);
                   1537: }
                   1538: 
                   1539: ###############################################################
                   1540: ###############################################################
                   1541: 
                   1542: =pod
                   1543: 
1.648     raeburn  1544: =item * &create_text_file()
1.113     bowersj2 1545: 
1.542     raeburn  1546: Create a file to write to and eventually make available to the user.
1.256     matthew  1547: If file creation fails, outputs an error message on the request object and 
                   1548: return undefs.
1.113     bowersj2 1549: 
1.256     matthew  1550: Inputs: Apache request object, and file suffix
1.113     bowersj2 1551: 
1.256     matthew  1552: Returns (undef) on failure, 
                   1553:     Filehandle and filename on success.
1.113     bowersj2 1554: 
                   1555: =cut
                   1556: 
1.256     matthew  1557: ###############################################################
                   1558: ###############################################################
                   1559: sub create_text_file {
                   1560:     my ($r,$suffix) = @_;
                   1561:     if (! defined($suffix)) { $suffix = 'txt'; };
                   1562:     my $fh;
                   1563:     my $filename = '/prtspool/'.
1.258     albertel 1564:         $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256     matthew  1565:         time.'_'.rand(1000000000).'.'.$suffix;
                   1566:     $fh = Apache::File->new('>/home/httpd'.$filename);
                   1567:     if (! defined($fh)) {
                   1568:         $r->log_error("Couldn't open $filename for output $!");
1.683     bisitz   1569:         $r->print(&mt('Problems occurred in creating the output file. '
                   1570:                      .'This error has been logged. '
                   1571:                      .'Please alert your LON-CAPA administrator.'));
1.113     bowersj2 1572:     }
1.256     matthew  1573:     return ($fh,$filename)
1.113     bowersj2 1574: }
                   1575: 
                   1576: 
1.256     matthew  1577: =pod 
1.113     bowersj2 1578: 
                   1579: =back
                   1580: 
                   1581: =cut
1.37      matthew  1582: 
                   1583: ###############################################################
1.33      matthew  1584: ##        Home server <option> list generating code          ##
                   1585: ###############################################################
1.35      matthew  1586: 
1.169     www      1587: # ------------------------------------------
                   1588: 
                   1589: sub domain_select {
                   1590:     my ($name,$value,$multiple)=@_;
                   1591:     my %domains=map { 
1.514     albertel 1592: 	$_ => $_.' '. &Apache::lonnet::domain($_,'description') 
1.512     albertel 1593:     } &Apache::lonnet::all_domains();
1.169     www      1594:     if ($multiple) {
                   1595: 	$domains{''}=&mt('Any domain');
1.550     albertel 1596: 	$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287     albertel 1597: 	return &multiple_select_form($name,$value,4,\%domains);
1.169     www      1598:     } else {
1.550     albertel 1599: 	$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.169     www      1600: 	return &select_form($name,$value,%domains);
                   1601:     }
                   1602: }
                   1603: 
1.282     albertel 1604: #-------------------------------------------
                   1605: 
                   1606: =pod
                   1607: 
1.519     raeburn  1608: =head1 Routines for form select boxes
                   1609: 
                   1610: =over 4
                   1611: 
1.648     raeburn  1612: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282     albertel 1613: 
                   1614: Returns a string containing a <select> element int multiple mode
                   1615: 
                   1616: 
                   1617: Args:
                   1618:   $name - name of the <select> element
1.506     raeburn  1619:   $value - scalar or array ref of values that should already be selected
1.282     albertel 1620:   $size - number of rows long the select element is
1.283     albertel 1621:   $hash - the elements should be 'option' => 'shown text'
1.282     albertel 1622:           (shown text should already have been &mt())
1.506     raeburn  1623:   $order - (optional) array ref of the order to show the elements in
1.283     albertel 1624: 
1.282     albertel 1625: =cut
                   1626: 
                   1627: #-------------------------------------------
1.169     www      1628: sub multiple_select_form {
1.284     albertel 1629:     my ($name,$value,$size,$hash,$order)=@_;
1.169     www      1630:     my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
                   1631:     my $output='';
1.191     matthew  1632:     if (! defined($size)) {
                   1633:         $size = 4;
1.283     albertel 1634:         if (scalar(keys(%$hash))<4) {
                   1635:             $size = scalar(keys(%$hash));
1.191     matthew  1636:         }
                   1637:     }
1.734     bisitz   1638:     $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501     banghart 1639:     my @order;
1.506     raeburn  1640:     if (ref($order) eq 'ARRAY')  {
                   1641:         @order = @{$order};
                   1642:     } else {
                   1643:         @order = sort(keys(%$hash));
1.501     banghart 1644:     }
                   1645:     if (exists($$hash{'select_form_order'})) {
                   1646:         @order = @{$$hash{'select_form_order'}};
                   1647:     }
                   1648:         
1.284     albertel 1649:     foreach my $key (@order) {
1.356     albertel 1650:         $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284     albertel 1651:         $output.='selected="selected" ' if ($selected{$key});
                   1652:         $output.='>'.$hash->{$key}."</option>\n";
1.169     www      1653:     }
                   1654:     $output.="</select>\n";
                   1655:     return $output;
                   1656: }
                   1657: 
1.88      www      1658: #-------------------------------------------
                   1659: 
                   1660: =pod
                   1661: 
1.648     raeburn  1662: =item * &select_form($defdom,$name,%hash)
1.88      www      1663: 
                   1664: Returns a string containing a <select name='$name' size='1'> form to 
                   1665: allow a user to select options from a hash option_name => displayed text.  
                   1666: See lonrights.pm for an example invocation and use.
                   1667: 
                   1668: =cut
                   1669: 
                   1670: #-------------------------------------------
                   1671: sub select_form {
                   1672:     my ($def,$name,%hash) = @_;
                   1673:     my $selectform = "<select name=\"$name\" size=\"1\">\n";
1.128     albertel 1674:     my @keys;
                   1675:     if (exists($hash{'select_form_order'})) {
                   1676: 	@keys=@{$hash{'select_form_order'}};
                   1677:     } else {
                   1678: 	@keys=sort(keys(%hash));
                   1679:     }
1.356     albertel 1680:     foreach my $key (@keys) {
                   1681:         $selectform.=
                   1682: 	    '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
                   1683:             ($key eq $def ? 'selected="selected" ' : '').
                   1684:                 ">".&mt($hash{$key})."</option>\n";
1.88      www      1685:     }
                   1686:     $selectform.="</select>";
                   1687:     return $selectform;
                   1688: }
                   1689: 
1.475     www      1690: # For display filters
                   1691: 
                   1692: sub display_filter {
                   1693:     if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477     www      1694:     if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.714     bisitz   1695:     return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1.475     www      1696: 			       &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
                   1697: 							   (&mt('all'),10,20,50,100,1000,10000))).
1.714     bisitz   1698: 	   '</label></span> <span class="LC_nobreak">'.
1.475     www      1699:            &mt('Filter [_1]',
1.477     www      1700: 	   &select_form($env{'form.displayfilter'},
                   1701: 			'displayfilter',
                   1702: 			('currentfolder' => 'Current folder/page',
                   1703: 			 'containing' => 'Containing phrase',
                   1704: 			 'none' => 'None'))).
1.714     bisitz   1705: 			 '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1.475     www      1706: }
                   1707: 
1.167     www      1708: sub gradeleveldescription {
                   1709:     my $gradelevel=shift;
                   1710:     my %gradelevels=(0 => 'Not specified',
                   1711: 		     1 => 'Grade 1',
                   1712: 		     2 => 'Grade 2',
                   1713: 		     3 => 'Grade 3',
                   1714: 		     4 => 'Grade 4',
                   1715: 		     5 => 'Grade 5',
                   1716: 		     6 => 'Grade 6',
                   1717: 		     7 => 'Grade 7',
                   1718: 		     8 => 'Grade 8',
                   1719: 		     9 => 'Grade 9',
                   1720: 		     10 => 'Grade 10',
                   1721: 		     11 => 'Grade 11',
                   1722: 		     12 => 'Grade 12',
                   1723: 		     13 => 'Grade 13',
                   1724: 		     14 => '100 Level',
                   1725: 		     15 => '200 Level',
                   1726: 		     16 => '300 Level',
                   1727: 		     17 => '400 Level',
                   1728: 		     18 => 'Graduate Level');
                   1729:     return &mt($gradelevels{$gradelevel});
                   1730: }
                   1731: 
1.163     www      1732: sub select_level_form {
                   1733:     my ($deflevel,$name)=@_;
                   1734:     unless ($deflevel) { $deflevel=0; }
1.167     www      1735:     my $selectform = "<select name=\"$name\" size=\"1\">\n";
                   1736:     for (my $i=0; $i<=18; $i++) {
                   1737:         $selectform.="<option value=\"$i\" ".
1.253     albertel 1738:             ($i==$deflevel ? 'selected="selected" ' : '').
1.167     www      1739:                 ">".&gradeleveldescription($i)."</option>\n";
                   1740:     }
                   1741:     $selectform.="</select>";
                   1742:     return $selectform;
1.163     www      1743: }
1.167     www      1744: 
1.35      matthew  1745: #-------------------------------------------
                   1746: 
1.45      matthew  1747: =pod
                   1748: 
1.743     raeburn  1749: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$autosubmit)
1.35      matthew  1750: 
                   1751: Returns a string containing a <select name='$name' size='1'> form to 
                   1752: allow a user to select the domain to preform an operation in.  
                   1753: See loncreateuser.pm for an example invocation and use.
                   1754: 
1.90      www      1755: If the $includeempty flag is set, it also includes an empty choice ("no domain
                   1756: selected");
                   1757: 
1.743     raeburn  1758: If the $showdomdesc flag is set, the domain name is followed by the domain description.
                   1759: 
                   1760: If the $autosubmit flag is set, the form containing the domain selector will be auto-submitted by an onchange action.  
1.563     raeburn  1761: 
1.35      matthew  1762: =cut
                   1763: 
                   1764: #-------------------------------------------
1.34      matthew  1765: sub select_dom_form {
1.743     raeburn  1766:     my ($defdom,$name,$includeempty,$showdomdesc,$autosubmit) = @_;
                   1767:     my $onchange;
                   1768:     if ($autosubmit) {
                   1769:         $onchange = ' onchange="this.form.submit()"';
                   1770:     }
1.550     albertel 1771:     my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1.90      www      1772:     if ($includeempty) { @domains=('',@domains); }
1.743     raeburn  1773:     my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356     albertel 1774:     foreach my $dom (@domains) {
                   1775:         $selectdomain.="<option value=\"$dom\" ".
1.563     raeburn  1776:             ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
                   1777:         if ($showdomdesc) {
                   1778:             if ($dom ne '') {
                   1779:                 my $domdesc = &Apache::lonnet::domain($dom,'description');
                   1780:                 if ($domdesc ne '') {
                   1781:                     $selectdomain .= ' ('.$domdesc.')';
                   1782:                 }
                   1783:             } 
                   1784:         }
                   1785:         $selectdomain .= "</option>\n";
1.34      matthew  1786:     }
                   1787:     $selectdomain.="</select>";
                   1788:     return $selectdomain;
                   1789: }
                   1790: 
1.35      matthew  1791: #-------------------------------------------
                   1792: 
1.45      matthew  1793: =pod
                   1794: 
1.648     raeburn  1795: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35      matthew  1796: 
1.586     raeburn  1797: input: 4 arguments (two required, two optional) - 
                   1798:     $domain - domain of new user
                   1799:     $name - name of form element
                   1800:     $default - Value of 'default' causes a default item to be first 
                   1801:                             option, and selected by default. 
                   1802:     $hide - Value of 'hide' causes hiding of the name of the server, 
                   1803:                             if 1 server found, or default, if 0 found.
1.594     raeburn  1804: output: returns 2 items: 
1.586     raeburn  1805: (a) form element which contains either:
                   1806:    (i) <select name="$name">
                   1807:         <option value="$hostid1">$hostid $servers{$hostid}</option>
                   1808:         <option value="$hostid2">$hostid $servers{$hostid}</option>       
                   1809:        </select>
                   1810:        form item if there are multiple library servers in $domain, or
                   1811:    (ii) an <input type="hidden" name="$name" value="$hostid" /> form item 
                   1812:        if there is only one library server in $domain.
                   1813: 
                   1814: (b) number of library servers found.
                   1815: 
                   1816: See loncreateuser.pm for example of use.
1.35      matthew  1817: 
                   1818: =cut
                   1819: 
                   1820: #-------------------------------------------
1.586     raeburn  1821: sub home_server_form_item {
                   1822:     my ($domain,$name,$default,$hide) = @_;
1.513     albertel 1823:     my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586     raeburn  1824:     my $result;
                   1825:     my $numlib = keys(%servers);
                   1826:     if ($numlib > 1) {
                   1827:         $result .= '<select name="'.$name.'" />'."\n";
                   1828:         if ($default) {
                   1829:             $result .= '<option value="default" selected>'.&mt('default').
                   1830:                        '</option>'."\n";
                   1831:         }
                   1832:         foreach my $hostid (sort(keys(%servers))) {
                   1833:             $result.= '<option value="'.$hostid.'">'.
                   1834: 	              $hostid.' '.$servers{$hostid}."</option>\n";
                   1835:         }
                   1836:         $result .= '</select>'."\n";
                   1837:     } elsif ($numlib == 1) {
                   1838:         my $hostid;
                   1839:         foreach my $item (keys(%servers)) {
                   1840:             $hostid = $item;
                   1841:         }
                   1842:         $result .= '<input type="hidden" name="'.$name.'" value="'.
                   1843:                    $hostid.'" />';
                   1844:                    if (!$hide) {
                   1845:                        $result .= $hostid.' '.$servers{$hostid};
                   1846:                    }
                   1847:                    $result .= "\n";
                   1848:     } elsif ($default) {
                   1849:         $result .= '<input type="hidden" name="'.$name.
                   1850:                    '" value="default" />';
                   1851:                    if (!$hide) {
                   1852:                        $result .= &mt('default');
                   1853:                    }
                   1854:                    $result .= "\n";
1.33      matthew  1855:     }
1.586     raeburn  1856:     return ($result,$numlib);
1.33      matthew  1857: }
1.112     bowersj2 1858: 
                   1859: =pod
                   1860: 
1.534     albertel 1861: =back 
                   1862: 
1.112     bowersj2 1863: =cut
1.87      matthew  1864: 
                   1865: ###############################################################
1.112     bowersj2 1866: ##                  Decoding User Agent                      ##
1.87      matthew  1867: ###############################################################
                   1868: 
                   1869: =pod
                   1870: 
1.112     bowersj2 1871: =head1 Decoding the User Agent
                   1872: 
                   1873: =over 4
                   1874: 
                   1875: =item * &decode_user_agent()
1.87      matthew  1876: 
                   1877: Inputs: $r
                   1878: 
                   1879: Outputs:
                   1880: 
                   1881: =over 4
                   1882: 
1.112     bowersj2 1883: =item * $httpbrowser
1.87      matthew  1884: 
1.112     bowersj2 1885: =item * $clientbrowser
1.87      matthew  1886: 
1.112     bowersj2 1887: =item * $clientversion
1.87      matthew  1888: 
1.112     bowersj2 1889: =item * $clientmathml
1.87      matthew  1890: 
1.112     bowersj2 1891: =item * $clientunicode
1.87      matthew  1892: 
1.112     bowersj2 1893: =item * $clientos
1.87      matthew  1894: 
                   1895: =back
                   1896: 
1.157     matthew  1897: =back 
                   1898: 
1.87      matthew  1899: =cut
                   1900: 
                   1901: ###############################################################
                   1902: ###############################################################
                   1903: sub decode_user_agent {
1.247     albertel 1904:     my ($r)=@_;
1.87      matthew  1905:     my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
                   1906:     my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
                   1907:     my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247     albertel 1908:     if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87      matthew  1909:     my $clientbrowser='unknown';
                   1910:     my $clientversion='0';
                   1911:     my $clientmathml='';
                   1912:     my $clientunicode='0';
                   1913:     for (my $i=0;$i<=$#browsertype;$i++) {
                   1914:         my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
                   1915: 	if (($httpbrowser=~/$match/i)  && ($httpbrowser!~/$notmatch/i)) {
                   1916: 	    $clientbrowser=$bname;
                   1917:             $httpbrowser=~/$vreg/i;
                   1918: 	    $clientversion=$1;
                   1919:             $clientmathml=($clientversion>=$minv);
                   1920:             $clientunicode=($clientversion>=$univ);
                   1921: 	}
                   1922:     }
                   1923:     my $clientos='unknown';
                   1924:     if (($httpbrowser=~/linux/i) ||
                   1925:         ($httpbrowser=~/unix/i) ||
                   1926:         ($httpbrowser=~/ux/i) ||
                   1927:         ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
                   1928:     if (($httpbrowser=~/vax/i) ||
                   1929:         ($httpbrowser=~/vms/i)) { $clientos='vms'; }
                   1930:     if ($httpbrowser=~/next/i) { $clientos='next'; }
                   1931:     if (($httpbrowser=~/mac/i) ||
                   1932:         ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
                   1933:     if ($httpbrowser=~/win/i) { $clientos='win'; }
                   1934:     if ($httpbrowser=~/embed/i) { $clientos='pda'; }
                   1935:     return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
                   1936:             $clientunicode,$clientos,);
                   1937: }
                   1938: 
1.32      matthew  1939: ###############################################################
                   1940: ##    Authentication changing form generation subroutines    ##
                   1941: ###############################################################
                   1942: ##
                   1943: ## All of the authform_xxxxxxx subroutines take their inputs in a
                   1944: ## hash, and have reasonable default values.
                   1945: ##
                   1946: ##    formname = the name given in the <form> tag.
1.35      matthew  1947: #-------------------------------------------
                   1948: 
1.45      matthew  1949: =pod
                   1950: 
1.112     bowersj2 1951: =head1 Authentication Routines
                   1952: 
                   1953: =over 4
                   1954: 
1.648     raeburn  1955: =item * &authform_xxxxxx()
1.35      matthew  1956: 
                   1957: The authform_xxxxxx subroutines provide javascript and html forms which 
                   1958: handle some of the conveniences required for authentication forms.  
                   1959: This is not an optimal method, but it works.  
                   1960: 
                   1961: =over 4
                   1962: 
1.112     bowersj2 1963: =item * authform_header
1.35      matthew  1964: 
1.112     bowersj2 1965: =item * authform_authorwarning
1.35      matthew  1966: 
1.112     bowersj2 1967: =item * authform_nochange
1.35      matthew  1968: 
1.112     bowersj2 1969: =item * authform_kerberos
1.35      matthew  1970: 
1.112     bowersj2 1971: =item * authform_internal
1.35      matthew  1972: 
1.112     bowersj2 1973: =item * authform_filesystem
1.35      matthew  1974: 
                   1975: =back
                   1976: 
1.648     raeburn  1977: See loncreateuser.pm for invocation and use examples.
1.157     matthew  1978: 
1.35      matthew  1979: =cut
                   1980: 
                   1981: #-------------------------------------------
1.32      matthew  1982: sub authform_header{  
                   1983:     my %in = (
                   1984:         formname => 'cu',
1.80      albertel 1985:         kerb_def_dom => '',
1.32      matthew  1986:         @_,
                   1987:     );
                   1988:     $in{'formname'} = 'document.' . $in{'formname'};
                   1989:     my $result='';
1.80      albertel 1990: 
                   1991: #---------------------------------------------- Code for upper case translation
                   1992:     my $Javascript_toUpperCase;
                   1993:     unless ($in{kerb_def_dom}) {
                   1994:         $Javascript_toUpperCase =<<"END";
                   1995:         switch (choice) {
                   1996:            case 'krb': currentform.elements[choicearg].value =
                   1997:                currentform.elements[choicearg].value.toUpperCase();
                   1998:                break;
                   1999:            default:
                   2000:         }
                   2001: END
                   2002:     } else {
                   2003:         $Javascript_toUpperCase = "";
                   2004:     }
                   2005: 
1.165     raeburn  2006:     my $radioval = "'nochange'";
1.591     raeburn  2007:     if (defined($in{'curr_authtype'})) {
                   2008:         if ($in{'curr_authtype'} ne '') {
                   2009:             $radioval = "'".$in{'curr_authtype'}."arg'";
                   2010:         }
1.174     matthew  2011:     }
1.165     raeburn  2012:     my $argfield = 'null';
1.591     raeburn  2013:     if (defined($in{'mode'})) {
1.165     raeburn  2014:         if ($in{'mode'} eq 'modifycourse')  {
1.591     raeburn  2015:             if (defined($in{'curr_autharg'})) {
                   2016:                 if ($in{'curr_autharg'} ne '') {
1.165     raeburn  2017:                     $argfield = "'$in{'curr_autharg'}'";
                   2018:                 }
                   2019:             }
                   2020:         }
                   2021:     }
                   2022: 
1.32      matthew  2023:     $result.=<<"END";
                   2024: var current = new Object();
1.165     raeburn  2025: current.radiovalue = $radioval;
                   2026: current.argfield = $argfield;
1.32      matthew  2027: 
                   2028: function changed_radio(choice,currentform) {
                   2029:     var choicearg = choice + 'arg';
                   2030:     // If a radio button in changed, we need to change the argfield
                   2031:     if (current.radiovalue != choice) {
                   2032:         current.radiovalue = choice;
                   2033:         if (current.argfield != null) {
                   2034:             currentform.elements[current.argfield].value = '';
                   2035:         }
                   2036:         if (choice == 'nochange') {
                   2037:             current.argfield = null;
                   2038:         } else {
                   2039:             current.argfield = choicearg;
                   2040:             switch(choice) {
                   2041:                 case 'krb': 
                   2042:                     currentform.elements[current.argfield].value = 
                   2043:                         "$in{'kerb_def_dom'}";
                   2044:                 break;
                   2045:               default:
                   2046:                 break;
                   2047:             }
                   2048:         }
                   2049:     }
                   2050:     return;
                   2051: }
1.22      www      2052: 
1.32      matthew  2053: function changed_text(choice,currentform) {
                   2054:     var choicearg = choice + 'arg';
                   2055:     if (currentform.elements[choicearg].value !='') {
1.80      albertel 2056:         $Javascript_toUpperCase
1.32      matthew  2057:         // clear old field
                   2058:         if ((current.argfield != choicearg) && (current.argfield != null)) {
                   2059:             currentform.elements[current.argfield].value = '';
                   2060:         }
                   2061:         current.argfield = choicearg;
                   2062:     }
                   2063:     set_auth_radio_buttons(choice,currentform);
                   2064:     return;
1.20      www      2065: }
1.32      matthew  2066: 
                   2067: function set_auth_radio_buttons(newvalue,currentform) {
                   2068:     var i=0;
                   2069:     while (i < currentform.login.length) {
                   2070:         if (currentform.login[i].value == newvalue) { break; }
                   2071:         i++;
                   2072:     }
                   2073:     if (i == currentform.login.length) {
                   2074:         return;
                   2075:     }
                   2076:     current.radiovalue = newvalue;
                   2077:     currentform.login[i].checked = true;
                   2078:     return;
                   2079: }
                   2080: END
                   2081:     return $result;
                   2082: }
                   2083: 
                   2084: sub authform_authorwarning{
                   2085:     my $result='';
1.144     matthew  2086:     $result='<i>'.
                   2087:         &mt('As a general rule, only authors or co-authors should be '.
                   2088:             'filesystem authenticated '.
                   2089:             '(which allows access to the server filesystem).')."</i>\n";
1.32      matthew  2090:     return $result;
                   2091: }
                   2092: 
                   2093: sub authform_nochange{  
                   2094:     my %in = (
                   2095:               formname => 'document.cu',
                   2096:               kerb_def_dom => 'MSU.EDU',
                   2097:               @_,
                   2098:           );
1.586     raeburn  2099:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'}); 
                   2100:     my $result;
                   2101:     if (keys(%can_assign) == 0) {
                   2102:         $result = &mt('Under you current role you are not permitted to change login settings for this user');  
                   2103:     } else {
                   2104:         $result = '<label>'.&mt('[_1] Do not change login data',
                   2105:                   '<input type="radio" name="login" value="nochange" '.
                   2106:                   'checked="checked" onclick="'.
1.281     albertel 2107:             "javascript:changed_radio('nochange',$in{'formname'});".'" />').
                   2108: 	    '</label>';
1.586     raeburn  2109:     }
1.32      matthew  2110:     return $result;
                   2111: }
                   2112: 
1.591     raeburn  2113: sub authform_kerberos {
1.32      matthew  2114:     my %in = (
                   2115:               formname => 'document.cu',
                   2116:               kerb_def_dom => 'MSU.EDU',
1.80      albertel 2117:               kerb_def_auth => 'krb4',
1.32      matthew  2118:               @_,
                   2119:               );
1.586     raeburn  2120:     my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
                   2121:         $autharg,$jscall);
                   2122:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.80      albertel 2123:     if ($in{'kerb_def_auth'} eq 'krb5') {
1.586     raeburn  2124:        $check5 = ' checked="on"';
1.80      albertel 2125:     } else {
1.586     raeburn  2126:        $check4 = ' checked="on"';
1.80      albertel 2127:     }
1.165     raeburn  2128:     $krbarg = $in{'kerb_def_dom'};
1.591     raeburn  2129:     if (defined($in{'curr_authtype'})) {
                   2130:         if ($in{'curr_authtype'} eq 'krb') {
1.586     raeburn  2131:             $krbcheck = ' checked="on"';
1.623     raeburn  2132:             if (defined($in{'mode'})) {
                   2133:                 if ($in{'mode'} eq 'modifyuser') {
                   2134:                     $krbcheck = '';
                   2135:                 }
                   2136:             }
1.591     raeburn  2137:             if (defined($in{'curr_kerb_ver'})) {
                   2138:                 if ($in{'curr_krb_ver'} eq '5') {
                   2139:                     $check5 = ' checked="on"';
                   2140:                     $check4 = '';
                   2141:                 } else {
                   2142:                     $check4 = ' checked="on"';
                   2143:                     $check5 = '';
                   2144:                 }
1.586     raeburn  2145:             }
1.591     raeburn  2146:             if (defined($in{'curr_autharg'})) {
1.165     raeburn  2147:                 $krbarg = $in{'curr_autharg'};
                   2148:             }
1.586     raeburn  2149:             if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591     raeburn  2150:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2151:                     $result = 
                   2152:     &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
                   2153:         $in{'curr_autharg'},$krbver);
                   2154:                 } else {
                   2155:                     $result =
                   2156:     &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
                   2157:                 }
                   2158:                 return $result; 
                   2159:             }
                   2160:         }
                   2161:     } else {
                   2162:         if ($authnum == 1) {
                   2163:             $authtype = '<input type="hidden" name="login" value="krb">';
1.165     raeburn  2164:         }
                   2165:     }
1.586     raeburn  2166:     if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
                   2167:         return;
1.587     raeburn  2168:     } elsif ($authtype eq '') {
1.591     raeburn  2169:         if (defined($in{'mode'})) {
1.587     raeburn  2170:             if ($in{'mode'} eq 'modifycourse') {
                   2171:                 if ($authnum == 1) {
                   2172:                     $authtype = '<input type="hidden" name="login" value="krb">';
                   2173:                 }
                   2174:             }
                   2175:         }
1.586     raeburn  2176:     }
                   2177:     $jscall = "javascript:changed_radio('krb',$in{'formname'});";
                   2178:     if ($authtype eq '') {
                   2179:         $authtype = '<input type="radio" name="login" value="krb" '.
                   2180:                     'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
                   2181:                     $krbcheck.' />';
                   2182:     }
                   2183:     if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
                   2184:         ($can_assign{'krb4'} && !$can_assign{'krb5'} && 
                   2185:          $in{'curr_authtype'} eq 'krb5') ||
                   2186:         (!$can_assign{'krb4'} && $can_assign{'krb5'} && 
                   2187:          $in{'curr_authtype'} eq 'krb4')) {
                   2188:         $result .= &mt
1.144     matthew  2189:         ('[_1] Kerberos authenticated with domain [_2] '.
1.281     albertel 2190:          '[_3] Version 4 [_4] Version 5 [_5]',
1.586     raeburn  2191:          '<label>'.$authtype,
1.281     albertel 2192:          '</label><input type="text" size="10" name="krbarg" '.
1.165     raeburn  2193:              'value="'.$krbarg.'" '.
1.144     matthew  2194:              'onchange="'.$jscall.'" />',
1.281     albertel 2195:          '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
                   2196:          '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
                   2197: 	 '</label>');
1.586     raeburn  2198:     } elsif ($can_assign{'krb4'}) {
                   2199:         $result .= &mt
                   2200:         ('[_1] Kerberos authenticated with domain [_2] '.
                   2201:          '[_3] Version 4 [_4]',
                   2202:          '<label>'.$authtype,
                   2203:          '</label><input type="text" size="10" name="krbarg" '.
                   2204:              'value="'.$krbarg.'" '.
                   2205:              'onchange="'.$jscall.'" />',
                   2206:          '<label><input type="hidden" name="krbver" value="4" />',
                   2207:          '</label>');
                   2208:     } elsif ($can_assign{'krb5'}) {
                   2209:         $result .= &mt
                   2210:         ('[_1] Kerberos authenticated with domain [_2] '.
                   2211:          '[_3] Version 5 [_4]',
                   2212:          '<label>'.$authtype,
                   2213:          '</label><input type="text" size="10" name="krbarg" '.
                   2214:              'value="'.$krbarg.'" '.
                   2215:              'onchange="'.$jscall.'" />',
                   2216:          '<label><input type="hidden" name="krbver" value="5" />',
                   2217:          '</label>');
                   2218:     }
1.32      matthew  2219:     return $result;
                   2220: }
                   2221: 
                   2222: sub authform_internal{  
1.586     raeburn  2223:     my %in = (
1.32      matthew  2224:                 formname => 'document.cu',
                   2225:                 kerb_def_dom => 'MSU.EDU',
                   2226:                 @_,
                   2227:                 );
1.586     raeburn  2228:     my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
                   2229:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2230:     if (defined($in{'curr_authtype'})) {
                   2231:         if ($in{'curr_authtype'} eq 'int') {
1.586     raeburn  2232:             if ($can_assign{'int'}) {
                   2233:                 $intcheck = 'checked="on" ';
1.623     raeburn  2234:                 if (defined($in{'mode'})) {
                   2235:                     if ($in{'mode'} eq 'modifyuser') {
                   2236:                         $intcheck = '';
                   2237:                     }
                   2238:                 }
1.591     raeburn  2239:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2240:                     $intarg = $in{'curr_autharg'};
                   2241:                 }
                   2242:             } else {
                   2243:                 $result = &mt('Currently internally authenticated.');
                   2244:                 return $result;
1.165     raeburn  2245:             }
                   2246:         }
1.586     raeburn  2247:     } else {
                   2248:         if ($authnum == 1) {
                   2249:             $authtype = '<input type="hidden" name="login" value="int">';
                   2250:         }
                   2251:     }
                   2252:     if (!$can_assign{'int'}) {
                   2253:         return;
1.587     raeburn  2254:     } elsif ($authtype eq '') {
1.591     raeburn  2255:         if (defined($in{'mode'})) {
1.587     raeburn  2256:             if ($in{'mode'} eq 'modifycourse') {
                   2257:                 if ($authnum == 1) {
                   2258:                     $authtype = '<input type="hidden" name="login" value="int">';
                   2259:                 }
                   2260:             }
                   2261:         }
1.165     raeburn  2262:     }
1.586     raeburn  2263:     $jscall = "javascript:changed_radio('int',$in{'formname'});";
                   2264:     if ($authtype eq '') {
                   2265:         $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
                   2266:                     ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
                   2267:     }
1.605     bisitz   2268:     $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586     raeburn  2269:                $intarg.'" onchange="'.$jscall.'" />';
                   2270:     $result = &mt
1.144     matthew  2271:         ('[_1] Internally authenticated (with initial password [_2])',
1.586     raeburn  2272:          '<label>'.$authtype,'</label>'.$autharg);
1.620     www      2273:     $result.="<label><input type=\"checkbox\" name=\"visible\" onClick='if (this.checked) { this.form.intarg.type=\"text\" } else { this.form.intarg.type=\"password\" }' />".&mt('Visible input').'</label>';
1.32      matthew  2274:     return $result;
                   2275: }
                   2276: 
                   2277: sub authform_local{  
                   2278:     my %in = (
                   2279:               formname => 'document.cu',
                   2280:               kerb_def_dom => 'MSU.EDU',
                   2281:               @_,
                   2282:               );
1.586     raeburn  2283:     my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
                   2284:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2285:     if (defined($in{'curr_authtype'})) {
                   2286:         if ($in{'curr_authtype'} eq 'loc') {
1.586     raeburn  2287:             if ($can_assign{'loc'}) {
                   2288:                 $loccheck = 'checked="on" ';
1.623     raeburn  2289:                 if (defined($in{'mode'})) {
                   2290:                     if ($in{'mode'} eq 'modifyuser') {
                   2291:                         $loccheck = '';
                   2292:                     }
                   2293:                 }
1.591     raeburn  2294:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2295:                     $locarg = $in{'curr_autharg'};
                   2296:                 }
                   2297:             } else {
                   2298:                 $result = &mt('Currently using local (institutional) authentication.');
                   2299:                 return $result;
1.165     raeburn  2300:             }
                   2301:         }
1.586     raeburn  2302:     } else {
                   2303:         if ($authnum == 1) {
                   2304:             $authtype = '<input type="hidden" name="login" value="loc">';
                   2305:         }
                   2306:     }
                   2307:     if (!$can_assign{'loc'}) {
                   2308:         return;
1.587     raeburn  2309:     } elsif ($authtype eq '') {
1.591     raeburn  2310:         if (defined($in{'mode'})) {
1.587     raeburn  2311:             if ($in{'mode'} eq 'modifycourse') {
                   2312:                 if ($authnum == 1) {
                   2313:                     $authtype = '<input type="hidden" name="login" value="loc">';
                   2314:                 }
                   2315:             }
                   2316:         }
1.165     raeburn  2317:     }
1.586     raeburn  2318:     $jscall = "javascript:changed_radio('loc',$in{'formname'});";
                   2319:     if ($authtype eq '') {
                   2320:         $authtype = '<input type="radio" name="login" value="loc" '.
                   2321:                     $loccheck.' onchange="'.$jscall.'" onclick="'.
                   2322:                     $jscall.'" />';
                   2323:     }
                   2324:     $autharg = '<input type="text" size="10" name="locarg" value="'.
                   2325:                $locarg.'" onchange="'.$jscall.'" />';
                   2326:     $result = &mt('[_1] Local Authentication with argument [_2]',
                   2327:                   '<label>'.$authtype,'</label>'.$autharg);
1.32      matthew  2328:     return $result;
                   2329: }
                   2330: 
                   2331: sub authform_filesystem{  
                   2332:     my %in = (
                   2333:               formname => 'document.cu',
                   2334:               kerb_def_dom => 'MSU.EDU',
                   2335:               @_,
                   2336:               );
1.586     raeburn  2337:     my ($fsyscheck,$result,$authtype,$autharg,$jscall);
                   2338:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2339:     if (defined($in{'curr_authtype'})) {
                   2340:         if ($in{'curr_authtype'} eq 'fsys') {
1.586     raeburn  2341:             if ($can_assign{'fsys'}) {
                   2342:                 $fsyscheck = 'checked="on" ';
1.623     raeburn  2343:                 if (defined($in{'mode'})) {
                   2344:                     if ($in{'mode'} eq 'modifyuser') {
                   2345:                         $fsyscheck = '';
                   2346:                     }
                   2347:                 }
1.586     raeburn  2348:             } else {
                   2349:                 $result = &mt('Currently Filesystem Authenticated.');
                   2350:                 return $result;
                   2351:             }           
                   2352:         }
                   2353:     } else {
                   2354:         if ($authnum == 1) {
                   2355:             $authtype = '<input type="hidden" name="login" value="fsys">';
                   2356:         }
                   2357:     }
                   2358:     if (!$can_assign{'fsys'}) {
                   2359:         return;
1.587     raeburn  2360:     } elsif ($authtype eq '') {
1.591     raeburn  2361:         if (defined($in{'mode'})) {
1.587     raeburn  2362:             if ($in{'mode'} eq 'modifycourse') {
                   2363:                 if ($authnum == 1) {
                   2364:                     $authtype = '<input type="hidden" name="login" value="fsys">';
                   2365:                 }
                   2366:             }
                   2367:         }
1.586     raeburn  2368:     }
                   2369:     $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
                   2370:     if ($authtype eq '') {
                   2371:         $authtype = '<input type="radio" name="login" value="fsys" '.
                   2372:                     $fsyscheck.' onchange="'.$jscall.'" onclick="'.
                   2373:                     $jscall.'" />';
                   2374:     }
                   2375:     $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
                   2376:                ' onchange="'.$jscall.'" />';
                   2377:     $result = &mt
1.144     matthew  2378:         ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281     albertel 2379:          '<label><input type="radio" name="login" value="fsys" '.
1.586     raeburn  2380:          $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605     bisitz   2381:          '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144     matthew  2382:                   'onchange="'.$jscall.'" />');
1.32      matthew  2383:     return $result;
                   2384: }
                   2385: 
1.586     raeburn  2386: sub get_assignable_auth {
                   2387:     my ($dom) = @_;
                   2388:     if ($dom eq '') {
                   2389:         $dom = $env{'request.role.domain'};
                   2390:     }
                   2391:     my %can_assign = (
                   2392:                           krb4 => 1,
                   2393:                           krb5 => 1,
                   2394:                           int  => 1,
                   2395:                           loc  => 1,
                   2396:                      );
                   2397:     my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
                   2398:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   2399:         if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
                   2400:             my $authhash = $domconfig{'usercreation'}{'authtypes'};
                   2401:             my $context;
                   2402:             if ($env{'request.role'} =~ /^au/) {
                   2403:                 $context = 'author';
                   2404:             } elsif ($env{'request.role'} =~ /^dc/) {
                   2405:                 $context = 'domain';
                   2406:             } elsif ($env{'request.course.id'}) {
                   2407:                 $context = 'course';
                   2408:             }
                   2409:             if ($context) {
                   2410:                 if (ref($authhash->{$context}) eq 'HASH') {
                   2411:                    %can_assign = %{$authhash->{$context}}; 
                   2412:                 }
                   2413:             }
                   2414:         }
                   2415:     }
                   2416:     my $authnum = 0;
                   2417:     foreach my $key (keys(%can_assign)) {
                   2418:         if ($can_assign{$key}) {
                   2419:             $authnum ++;
                   2420:         }
                   2421:     }
                   2422:     if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
                   2423:         $authnum --;
                   2424:     }
                   2425:     return ($authnum,%can_assign);
                   2426: }
                   2427: 
1.80      albertel 2428: ###############################################################
                   2429: ##    Get Kerberos Defaults for Domain                 ##
                   2430: ###############################################################
                   2431: ##
                   2432: ## Returns default kerberos version and an associated argument
                   2433: ## as listed in file domain.tab. If not listed, provides
                   2434: ## appropriate default domain and kerberos version.
                   2435: ##
                   2436: #-------------------------------------------
                   2437: 
                   2438: =pod
                   2439: 
1.648     raeburn  2440: =item * &get_kerberos_defaults()
1.80      albertel 2441: 
                   2442: get_kerberos_defaults($target_domain) returns the default kerberos
1.641     raeburn  2443: version and domain. If not found, it defaults to version 4 and the 
                   2444: domain of the server.
1.80      albertel 2445: 
1.648     raeburn  2446: =over 4
                   2447: 
1.80      albertel 2448: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
                   2449: 
1.648     raeburn  2450: =back
                   2451: 
                   2452: =back
                   2453: 
1.80      albertel 2454: =cut
                   2455: 
                   2456: #-------------------------------------------
                   2457: sub get_kerberos_defaults {
                   2458:     my $domain=shift;
1.641     raeburn  2459:     my ($krbdef,$krbdefdom);
                   2460:     my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
                   2461:     if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
                   2462:         $krbdef = $domdefaults{'auth_def'};
                   2463:         $krbdefdom = $domdefaults{'auth_arg_def'};
                   2464:     } else {
1.80      albertel 2465:         $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
                   2466:         my $krbdefdom=$1;
                   2467:         $krbdefdom=~tr/a-z/A-Z/;
                   2468:         $krbdef = "krb4";
                   2469:     }
                   2470:     return ($krbdef,$krbdefdom);
                   2471: }
1.112     bowersj2 2472: 
1.32      matthew  2473: 
1.46      matthew  2474: ###############################################################
                   2475: ##                Thesaurus Functions                        ##
                   2476: ###############################################################
1.20      www      2477: 
1.46      matthew  2478: =pod
1.20      www      2479: 
1.112     bowersj2 2480: =head1 Thesaurus Functions
                   2481: 
                   2482: =over 4
                   2483: 
1.648     raeburn  2484: =item * &initialize_keywords()
1.46      matthew  2485: 
                   2486: Initializes the package variable %Keywords if it is empty.  Uses the
                   2487: package variable $thesaurus_db_file.
                   2488: 
                   2489: =cut
                   2490: 
                   2491: ###################################################
                   2492: 
                   2493: sub initialize_keywords {
                   2494:     return 1 if (scalar keys(%Keywords));
                   2495:     # If we are here, %Keywords is empty, so fill it up
                   2496:     #   Make sure the file we need exists...
                   2497:     if (! -e $thesaurus_db_file) {
                   2498:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
                   2499:                                  " failed because it does not exist");
                   2500:         return 0;
                   2501:     }
                   2502:     #   Set up the hash as a database
                   2503:     my %thesaurus_db;
                   2504:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 2505:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  2506:         &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
                   2507:                                  $thesaurus_db_file);
                   2508:         return 0;
                   2509:     } 
                   2510:     #  Get the average number of appearances of a word.
                   2511:     my $avecount = $thesaurus_db{'average.count'};
                   2512:     #  Put keywords (those that appear > average) into %Keywords
                   2513:     while (my ($word,$data)=each (%thesaurus_db)) {
                   2514:         my ($count,undef) = split /:/,$data;
                   2515:         $Keywords{$word}++ if ($count > $avecount);
                   2516:     }
                   2517:     untie %thesaurus_db;
                   2518:     # Remove special values from %Keywords.
1.356     albertel 2519:     foreach my $value ('total.count','average.count') {
                   2520:         delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586     raeburn  2521:   }
1.46      matthew  2522:     return 1;
                   2523: }
                   2524: 
                   2525: ###################################################
                   2526: 
                   2527: =pod
                   2528: 
1.648     raeburn  2529: =item * &keyword($word)
1.46      matthew  2530: 
                   2531: Returns true if $word is a keyword.  A keyword is a word that appears more 
                   2532: than the average number of times in the thesaurus database.  Calls 
                   2533: &initialize_keywords
                   2534: 
                   2535: =cut
                   2536: 
                   2537: ###################################################
1.20      www      2538: 
                   2539: sub keyword {
1.46      matthew  2540:     return if (!&initialize_keywords());
                   2541:     my $word=lc(shift());
                   2542:     $word=~s/\W//g;
                   2543:     return exists($Keywords{$word});
1.20      www      2544: }
1.46      matthew  2545: 
                   2546: ###############################################################
                   2547: 
                   2548: =pod 
1.20      www      2549: 
1.648     raeburn  2550: =item * &get_related_words()
1.46      matthew  2551: 
1.160     matthew  2552: Look up a word in the thesaurus.  Takes a scalar argument and returns
1.46      matthew  2553: an array of words.  If the keyword is not in the thesaurus, an empty array
                   2554: will be returned.  The order of the words returned is determined by the
                   2555: database which holds them.
                   2556: 
                   2557: Uses global $thesaurus_db_file.
                   2558: 
                   2559: =cut
                   2560: 
                   2561: ###############################################################
                   2562: sub get_related_words {
                   2563:     my $keyword = shift;
                   2564:     my %thesaurus_db;
                   2565:     if (! -e $thesaurus_db_file) {
                   2566:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
                   2567:                                  "failed because the file does not exist");
                   2568:         return ();
                   2569:     }
                   2570:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 2571:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  2572:         return ();
                   2573:     } 
                   2574:     my @Words=();
1.429     www      2575:     my $count=0;
1.46      matthew  2576:     if (exists($thesaurus_db{$keyword})) {
1.356     albertel 2577: 	# The first element is the number of times
                   2578: 	# the word appears.  We do not need it now.
1.429     www      2579: 	my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
                   2580: 	my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
                   2581: 	my $threshold=$mostfrequentcount/10;
                   2582:         foreach my $possibleword (@RelatedWords) {
                   2583:             my ($word,$wordcount)=split(/\,/,$possibleword);
                   2584:             if ($wordcount>$threshold) {
                   2585: 		push(@Words,$word);
                   2586:                 $count++;
                   2587:                 if ($count>10) { last; }
                   2588: 	    }
1.20      www      2589:         }
                   2590:     }
1.46      matthew  2591:     untie %thesaurus_db;
                   2592:     return @Words;
1.14      harris41 2593: }
1.46      matthew  2594: 
1.112     bowersj2 2595: =pod
                   2596: 
                   2597: =back
                   2598: 
                   2599: =cut
1.61      www      2600: 
                   2601: # -------------------------------------------------------------- Plaintext name
1.81      albertel 2602: =pod
                   2603: 
1.112     bowersj2 2604: =head1 User Name Functions
                   2605: 
                   2606: =over 4
                   2607: 
1.648     raeburn  2608: =item * &plainname($uname,$udom,$first)
1.81      albertel 2609: 
1.112     bowersj2 2610: Takes a users logon name and returns it as a string in
1.226     albertel 2611: "first middle last generation" form 
                   2612: if $first is set to 'lastname' then it returns it as
                   2613: 'lastname generation, firstname middlename' if their is a lastname
1.81      albertel 2614: 
                   2615: =cut
1.61      www      2616: 
1.295     www      2617: 
1.81      albertel 2618: ###############################################################
1.61      www      2619: sub plainname {
1.226     albertel 2620:     my ($uname,$udom,$first)=@_;
1.537     albertel 2621:     return if (!defined($uname) || !defined($udom));
1.295     www      2622:     my %names=&getnames($uname,$udom);
1.226     albertel 2623:     my $name=&Apache::lonnet::format_name($names{'firstname'},
                   2624: 					  $names{'middlename'},
                   2625: 					  $names{'lastname'},
                   2626: 					  $names{'generation'},$first);
                   2627:     $name=~s/^\s+//;
1.62      www      2628:     $name=~s/\s+$//;
                   2629:     $name=~s/\s+/ /g;
1.353     albertel 2630:     if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62      www      2631:     return $name;
1.61      www      2632: }
1.66      www      2633: 
                   2634: # -------------------------------------------------------------------- Nickname
1.81      albertel 2635: =pod
                   2636: 
1.648     raeburn  2637: =item * &nickname($uname,$udom)
1.81      albertel 2638: 
                   2639: Gets a users name and returns it as a string as
                   2640: 
                   2641: "&quot;nickname&quot;"
1.66      www      2642: 
1.81      albertel 2643: if the user has a nickname or
                   2644: 
                   2645: "first middle last generation"
                   2646: 
                   2647: if the user does not
                   2648: 
                   2649: =cut
1.66      www      2650: 
                   2651: sub nickname {
                   2652:     my ($uname,$udom)=@_;
1.537     albertel 2653:     return if (!defined($uname) || !defined($udom));
1.295     www      2654:     my %names=&getnames($uname,$udom);
1.68      albertel 2655:     my $name=$names{'nickname'};
1.66      www      2656:     if ($name) {
                   2657:        $name='&quot;'.$name.'&quot;'; 
                   2658:     } else {
                   2659:        $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
                   2660: 	     $names{'lastname'}.' '.$names{'generation'};
                   2661:        $name=~s/\s+$//;
                   2662:        $name=~s/\s+/ /g;
                   2663:     }
                   2664:     return $name;
                   2665: }
                   2666: 
1.295     www      2667: sub getnames {
                   2668:     my ($uname,$udom)=@_;
1.537     albertel 2669:     return if (!defined($uname) || !defined($udom));
1.433     albertel 2670:     if ($udom eq 'public' && $uname eq 'public') {
                   2671: 	return ('lastname' => &mt('Public'));
                   2672:     }
1.295     www      2673:     my $id=$uname.':'.$udom;
                   2674:     my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
                   2675:     if ($cached) {
                   2676: 	return %{$names};
                   2677:     } else {
                   2678: 	my %loadnames=&Apache::lonnet::get('environment',
                   2679:                     ['firstname','middlename','lastname','generation','nickname'],
                   2680: 					 $udom,$uname);
                   2681: 	&Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
                   2682: 	return %loadnames;
                   2683:     }
                   2684: }
1.61      www      2685: 
1.542     raeburn  2686: # -------------------------------------------------------------------- getemails
1.648     raeburn  2687: 
1.542     raeburn  2688: =pod
                   2689: 
1.648     raeburn  2690: =item * &getemails($uname,$udom)
1.542     raeburn  2691: 
                   2692: Gets a user's email information and returns it as a hash with keys:
                   2693: notification, critnotification, permanentemail
                   2694: 
                   2695: For notification and critnotification, values are comma-separated lists 
1.648     raeburn  2696: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542     raeburn  2697:  
1.648     raeburn  2698: 
1.542     raeburn  2699: =cut
                   2700: 
1.648     raeburn  2701: 
1.466     albertel 2702: sub getemails {
                   2703:     my ($uname,$udom)=@_;
                   2704:     if ($udom eq 'public' && $uname eq 'public') {
                   2705: 	return;
                   2706:     }
1.467     www      2707:     if (!$udom) { $udom=$env{'user.domain'}; }
                   2708:     if (!$uname) { $uname=$env{'user.name'}; }
1.466     albertel 2709:     my $id=$uname.':'.$udom;
                   2710:     my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
                   2711:     if ($cached) {
                   2712: 	return %{$names};
                   2713:     } else {
                   2714: 	my %loadnames=&Apache::lonnet::get('environment',
                   2715:                     			   ['notification','critnotification',
                   2716: 					    'permanentemail'],
                   2717: 					   $udom,$uname);
                   2718: 	&Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
                   2719: 	return %loadnames;
                   2720:     }
                   2721: }
                   2722: 
1.551     albertel 2723: sub flush_email_cache {
                   2724:     my ($uname,$udom)=@_;
                   2725:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2726:     if (!$uname) { $uname=$env{'user.name'};   }
                   2727:     return if ($udom eq 'public' && $uname eq 'public');
                   2728:     my $id=$uname.':'.$udom;
                   2729:     &Apache::lonnet::devalidate_cache_new('emailscache',$id);
                   2730: }
                   2731: 
1.728     raeburn  2732: # -------------------------------------------------------------------- getlangs
                   2733: 
                   2734: =pod
                   2735: 
                   2736: =item * &getlangs($uname,$udom)
                   2737: 
                   2738: Gets a user's language preference and returns it as a hash with key:
                   2739: language.
                   2740: 
                   2741: =cut
                   2742: 
                   2743: 
                   2744: sub getlangs {
                   2745:     my ($uname,$udom) = @_;
                   2746:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2747:     if (!$uname) { $uname=$env{'user.name'};   }
                   2748:     my $id=$uname.':'.$udom;
                   2749:     my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
                   2750:     if ($cached) {
                   2751:         return %{$langs};
                   2752:     } else {
                   2753:         my %loadlangs=&Apache::lonnet::get('environment',['languages'],
                   2754:                                            $udom,$uname);
                   2755:         &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
                   2756:         return %loadlangs;
                   2757:     }
                   2758: }
                   2759: 
                   2760: sub flush_langs_cache {
                   2761:     my ($uname,$udom)=@_;
                   2762:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2763:     if (!$uname) { $uname=$env{'user.name'};   }
                   2764:     return if ($udom eq 'public' && $uname eq 'public');
                   2765:     my $id=$uname.':'.$udom;
                   2766:     &Apache::lonnet::devalidate_cache_new('userlangs',$id);
                   2767: }
                   2768: 
1.61      www      2769: # ------------------------------------------------------------------ Screenname
1.81      albertel 2770: 
                   2771: =pod
                   2772: 
1.648     raeburn  2773: =item * &screenname($uname,$udom)
1.81      albertel 2774: 
                   2775: Gets a users screenname and returns it as a string
                   2776: 
                   2777: =cut
1.61      www      2778: 
                   2779: sub screenname {
                   2780:     my ($uname,$udom)=@_;
1.258     albertel 2781:     if ($uname eq $env{'user.name'} &&
                   2782: 	$udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212     albertel 2783:     my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68      albertel 2784:     return $names{'screenname'};
1.62      www      2785: }
                   2786: 
1.212     albertel 2787: 
1.62      www      2788: # ------------------------------------------------------------- Message Wrapper
                   2789: 
                   2790: sub messagewrapper {
1.369     www      2791:     my ($link,$username,$domain,$subject,$text)=@_;
1.62      www      2792:     return 
1.441     albertel 2793:         '<a href="/adm/email?compose=individual&amp;'.
                   2794:         'recname='.$username.'&amp;recdom='.$domain.
                   2795: 	'&amp;subject='.&escape($subject).'&amp;text='.&escape($text).'" '.
1.200     matthew  2796:         'title="'.&mt('Send message').'">'.$link.'</a>';
1.74      www      2797: }
                   2798: # --------------------------------------------------------------- Notes Wrapper
                   2799: 
                   2800: sub noteswrapper {
                   2801:     my ($link,$un,$do)=@_;
                   2802:     return 
                   2803: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62      www      2804: }
                   2805: # ------------------------------------------------------------- Aboutme Wrapper
                   2806: 
                   2807: sub aboutmewrapper {
1.166     www      2808:     my ($link,$username,$domain,$target)=@_;
1.447     raeburn  2809:     if (!defined($username)  && !defined($domain)) {
                   2810:         return;
                   2811:     }
1.205     www      2812:     return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.454     banghart 2813: 	($target?' target="$target"':'').' title="'.&mt("View this user's personal page").'">'.$link.'</a>';
1.62      www      2814: }
                   2815: 
                   2816: # ------------------------------------------------------------ Syllabus Wrapper
                   2817: 
                   2818: 
                   2819: sub syllabuswrapper {
1.707     bisitz   2820:     my ($linktext,$coursedir,$domain)=@_;
1.208     matthew  2821:     return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61      www      2822: }
1.14      harris41 2823: 
1.208     matthew  2824: sub track_student_link {
1.268     albertel 2825:     my ($linktext,$sname,$sdom,$target,$start) = @_;
                   2826:     my $link ="/adm/trackstudent?";
1.208     matthew  2827:     my $title = 'View recent activity';
                   2828:     if (defined($sname) && $sname !~ /^\s*$/ &&
                   2829:         defined($sdom)  && $sdom  !~ /^\s*$/) {
1.268     albertel 2830:         $link .= "selected_student=$sname:$sdom";
1.208     matthew  2831:         $title .= ' of this student';
1.268     albertel 2832:     } 
1.208     matthew  2833:     if (defined($target) && $target !~ /^\s*$/) {
                   2834:         $target = qq{target="$target"};
                   2835:     } else {
                   2836:         $target = '';
                   2837:     }
1.268     albertel 2838:     if ($start) { $link.='&amp;start='.$start; }
1.554     albertel 2839:     $title = &mt($title);
                   2840:     $linktext = &mt($linktext);
1.448     albertel 2841:     return qq{<a href="$link" title="$title" $target>$linktext</a>}.
                   2842: 	&help_open_topic('View_recent_activity');
1.208     matthew  2843: }
                   2844: 
1.508     www      2845: # ===================================================== Display a student photo
                   2846: 
                   2847: 
1.509     albertel 2848: sub student_image_tag {
1.508     www      2849:     my ($domain,$user)=@_;
                   2850:     my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
                   2851:     if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
                   2852: 	return '<img src="'.$imgsrc.'" align="right" />';
                   2853:     } else {
                   2854: 	return '';
                   2855:     }
                   2856: }
                   2857: 
1.112     bowersj2 2858: =pod
                   2859: 
                   2860: =back
                   2861: 
                   2862: =head1 Access .tab File Data
                   2863: 
                   2864: =over 4
                   2865: 
1.648     raeburn  2866: =item * &languageids() 
1.112     bowersj2 2867: 
                   2868: returns list of all language ids
                   2869: 
                   2870: =cut
                   2871: 
1.14      harris41 2872: sub languageids {
1.16      harris41 2873:     return sort(keys(%language));
1.14      harris41 2874: }
                   2875: 
1.112     bowersj2 2876: =pod
                   2877: 
1.648     raeburn  2878: =item * &languagedescription() 
1.112     bowersj2 2879: 
                   2880: returns description of a specified language id
                   2881: 
                   2882: =cut
                   2883: 
1.14      harris41 2884: sub languagedescription {
1.125     www      2885:     my $code=shift;
                   2886:     return  ($supported_language{$code}?'* ':'').
                   2887:             $language{$code}.
1.126     www      2888: 	    ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145     www      2889: }
                   2890: 
                   2891: sub plainlanguagedescription {
                   2892:     my $code=shift;
                   2893:     return $language{$code};
                   2894: }
                   2895: 
                   2896: sub supportedlanguagecode {
                   2897:     my $code=shift;
                   2898:     return $supported_language{$code};
1.97      www      2899: }
                   2900: 
1.112     bowersj2 2901: =pod
                   2902: 
1.648     raeburn  2903: =item * &copyrightids() 
1.112     bowersj2 2904: 
                   2905: returns list of all copyrights
                   2906: 
                   2907: =cut
                   2908: 
                   2909: sub copyrightids {
                   2910:     return sort(keys(%cprtag));
                   2911: }
                   2912: 
                   2913: =pod
                   2914: 
1.648     raeburn  2915: =item * &copyrightdescription() 
1.112     bowersj2 2916: 
                   2917: returns description of a specified copyright id
                   2918: 
                   2919: =cut
                   2920: 
                   2921: sub copyrightdescription {
1.166     www      2922:     return &mt($cprtag{shift(@_)});
1.112     bowersj2 2923: }
1.197     matthew  2924: 
                   2925: =pod
                   2926: 
1.648     raeburn  2927: =item * &source_copyrightids() 
1.192     taceyjo1 2928: 
                   2929: returns list of all source copyrights
                   2930: 
                   2931: =cut
                   2932: 
                   2933: sub source_copyrightids {
                   2934:     return sort(keys(%scprtag));
                   2935: }
                   2936: 
                   2937: =pod
                   2938: 
1.648     raeburn  2939: =item * &source_copyrightdescription() 
1.192     taceyjo1 2940: 
                   2941: returns description of a specified source copyright id
                   2942: 
                   2943: =cut
                   2944: 
                   2945: sub source_copyrightdescription {
                   2946:     return &mt($scprtag{shift(@_)});
                   2947: }
1.112     bowersj2 2948: 
                   2949: =pod
                   2950: 
1.648     raeburn  2951: =item * &filecategories() 
1.112     bowersj2 2952: 
                   2953: returns list of all file categories
                   2954: 
                   2955: =cut
                   2956: 
                   2957: sub filecategories {
                   2958:     return sort(keys(%category_extensions));
                   2959: }
                   2960: 
                   2961: =pod
                   2962: 
1.648     raeburn  2963: =item * &filecategorytypes() 
1.112     bowersj2 2964: 
                   2965: returns list of file types belonging to a given file
                   2966: category
                   2967: 
                   2968: =cut
                   2969: 
                   2970: sub filecategorytypes {
1.356     albertel 2971:     my ($cat) = @_;
                   2972:     return @{$category_extensions{lc($cat)}};
1.112     bowersj2 2973: }
                   2974: 
                   2975: =pod
                   2976: 
1.648     raeburn  2977: =item * &fileembstyle() 
1.112     bowersj2 2978: 
                   2979: returns embedding style for a specified file type
                   2980: 
                   2981: =cut
                   2982: 
                   2983: sub fileembstyle {
                   2984:     return $fe{lc(shift(@_))};
1.169     www      2985: }
                   2986: 
1.351     www      2987: sub filemimetype {
                   2988:     return $fm{lc(shift(@_))};
                   2989: }
                   2990: 
1.169     www      2991: 
                   2992: sub filecategoryselect {
                   2993:     my ($name,$value)=@_;
1.189     matthew  2994:     return &select_form($value,$name,
1.169     www      2995: 			'' => &mt('Any category'),
                   2996: 			map { $_,$_ } sort(keys(%category_extensions)));
1.112     bowersj2 2997: }
                   2998: 
                   2999: =pod
                   3000: 
1.648     raeburn  3001: =item * &filedescription() 
1.112     bowersj2 3002: 
                   3003: returns description for a specified file type
                   3004: 
                   3005: =cut
                   3006: 
                   3007: sub filedescription {
1.188     matthew  3008:     my $file_description = $fd{lc(shift())};
                   3009:     $file_description =~ s:([\[\]]):~$1:g;
                   3010:     return &mt($file_description);
1.112     bowersj2 3011: }
                   3012: 
                   3013: =pod
                   3014: 
1.648     raeburn  3015: =item * &filedescriptionex() 
1.112     bowersj2 3016: 
                   3017: returns description for a specified file type with
                   3018: extra formatting
                   3019: 
                   3020: =cut
                   3021: 
                   3022: sub filedescriptionex {
                   3023:     my $ex=shift;
1.188     matthew  3024:     my $file_description = $fd{lc($ex)};
                   3025:     $file_description =~ s:([\[\]]):~$1:g;
                   3026:     return '.'.$ex.' '.&mt($file_description);
1.112     bowersj2 3027: }
                   3028: 
                   3029: # End of .tab access
                   3030: =pod
                   3031: 
                   3032: =back
                   3033: 
                   3034: =cut
                   3035: 
                   3036: # ------------------------------------------------------------------ File Types
                   3037: sub fileextensions {
                   3038:     return sort(keys(%fe));
                   3039: }
                   3040: 
1.97      www      3041: # ----------------------------------------------------------- Display Languages
                   3042: # returns a hash with all desired display languages
                   3043: #
                   3044: 
                   3045: sub display_languages {
                   3046:     my %languages=();
1.695     raeburn  3047:     foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356     albertel 3048: 	$languages{$lang}=1;
1.97      www      3049:     }
                   3050:     &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258     albertel 3051:     if ($env{'form.displaylanguage'}) {
1.356     albertel 3052: 	foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
                   3053: 	    $languages{$lang}=1;
1.97      www      3054:         }
                   3055:     }
                   3056:     return %languages;
1.14      harris41 3057: }
                   3058: 
1.582     albertel 3059: sub languages {
                   3060:     my ($possible_langs) = @_;
1.695     raeburn  3061:     my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582     albertel 3062:     if (!ref($possible_langs)) {
                   3063: 	if( wantarray ) {
                   3064: 	    return @preferred_langs;
                   3065: 	} else {
                   3066: 	    return $preferred_langs[0];
                   3067: 	}
                   3068:     }
                   3069:     my %possibilities = map { $_ => 1 } (@$possible_langs);
                   3070:     my @preferred_possibilities;
                   3071:     foreach my $preferred_lang (@preferred_langs) {
                   3072: 	if (exists($possibilities{$preferred_lang})) {
                   3073: 	    push(@preferred_possibilities, $preferred_lang);
                   3074: 	}
                   3075:     }
                   3076:     if( wantarray ) {
                   3077: 	return @preferred_possibilities;
                   3078:     }
                   3079:     return $preferred_possibilities[0];
                   3080: }
                   3081: 
1.742     raeburn  3082: sub user_lang {
                   3083:     my ($touname,$toudom,$fromcid) = @_;
                   3084:     my @userlangs;
                   3085:     if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
                   3086:         @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
                   3087:                     $env{'course.'.$fromcid.'.languages'}));
                   3088:     } else {
                   3089:         my %langhash = &getlangs($touname,$toudom);
                   3090:         if ($langhash{'languages'} ne '') {
                   3091:             @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
                   3092:         } else {
                   3093:             my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
                   3094:             if ($domdefs{'lang_def'} ne '') {
                   3095:                 @userlangs = ($domdefs{'lang_def'});
                   3096:             }
                   3097:         }
                   3098:     }
                   3099:     my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
                   3100:     my $user_lh = Apache::localize->get_handle(@languages);
                   3101:     return $user_lh;
                   3102: }
                   3103: 
                   3104: 
1.112     bowersj2 3105: ###############################################################
                   3106: ##               Student Answer Attempts                     ##
                   3107: ###############################################################
                   3108: 
                   3109: =pod
                   3110: 
                   3111: =head1 Alternate Problem Views
                   3112: 
                   3113: =over 4
                   3114: 
1.648     raeburn  3115: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112     bowersj2 3116:     $getattempt, $regexp, $gradesub)
                   3117: 
                   3118: Return string with previous attempt on problem. Arguments:
                   3119: 
                   3120: =over 4
                   3121: 
                   3122: =item * $symb: Problem, including path
                   3123: 
                   3124: =item * $username: username of the desired student
                   3125: 
                   3126: =item * $domain: domain of the desired student
1.14      harris41 3127: 
1.112     bowersj2 3128: =item * $course: Course ID
1.14      harris41 3129: 
1.112     bowersj2 3130: =item * $getattempt: Leave blank for all attempts, otherwise put
                   3131:     something
1.14      harris41 3132: 
1.112     bowersj2 3133: =item * $regexp: if string matches this regexp, the string will be
                   3134:     sent to $gradesub
1.14      harris41 3135: 
1.112     bowersj2 3136: =item * $gradesub: routine that processes the string if it matches $regexp
1.14      harris41 3137: 
1.112     bowersj2 3138: =back
1.14      harris41 3139: 
1.112     bowersj2 3140: The output string is a table containing all desired attempts, if any.
1.16      harris41 3141: 
1.112     bowersj2 3142: =cut
1.1       albertel 3143: 
                   3144: sub get_previous_attempt {
1.43      ng       3145:   my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1       albertel 3146:   my $prevattempts='';
1.43      ng       3147:   no strict 'refs';
1.1       albertel 3148:   if ($symb) {
1.3       albertel 3149:     my (%returnhash)=
                   3150:       &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1       albertel 3151:     if ($returnhash{'version'}) {
                   3152:       my %lasthash=();
                   3153:       my $version;
                   3154:       for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356     albertel 3155:         foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
                   3156: 	  $lasthash{$key}=$returnhash{$version.':'.$key};
1.19      harris41 3157:         }
1.1       albertel 3158:       }
1.596     albertel 3159:       $prevattempts=&start_data_table().&start_data_table_header_row();
                   3160:       $prevattempts.='<th>'.&mt('History').'</th>';
1.356     albertel 3161:       foreach my $key (sort(keys(%lasthash))) {
                   3162: 	my ($ign,@parts) = split(/\./,$key);
1.41      ng       3163: 	if ($#parts > 0) {
1.31      albertel 3164: 	  my $data=$parts[-1];
                   3165: 	  pop(@parts);
1.596     albertel 3166: 	  $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.'&nbsp;</th>';
1.31      albertel 3167: 	} else {
1.41      ng       3168: 	  if ($#parts == 0) {
                   3169: 	    $prevattempts.='<th>'.$parts[0].'</th>';
                   3170: 	  } else {
                   3171: 	    $prevattempts.='<th>'.$ign.'</th>';
                   3172: 	  }
1.31      albertel 3173: 	}
1.16      harris41 3174:       }
1.596     albertel 3175:       $prevattempts.=&end_data_table_header_row();
1.40      ng       3176:       if ($getattempt eq '') {
                   3177: 	for ($version=1;$version<=$returnhash{'version'};$version++) {
1.596     albertel 3178: 	  $prevattempts.=&start_data_table_row().
                   3179: 	      '<td>'.&mt('Transaction [_1]',$version).'</td>';
1.356     albertel 3180: 	    foreach my $key (sort(keys(%lasthash))) {
1.581     albertel 3181: 		my $value = &format_previous_attempt_value($key,
                   3182: 							   $returnhash{$version.':'.$key});
                   3183: 		$prevattempts.='<td>'.$value.'&nbsp;</td>';   
1.40      ng       3184: 	    }
1.596     albertel 3185: 	  $prevattempts.=&end_data_table_row();
1.40      ng       3186: 	 }
1.1       albertel 3187:       }
1.596     albertel 3188:       $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356     albertel 3189:       foreach my $key (sort(keys(%lasthash))) {
1.581     albertel 3190: 	my $value = &format_previous_attempt_value($key,$lasthash{$key});
1.356     albertel 3191: 	if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
1.40      ng       3192: 	$prevattempts.='<td>'.$value.'&nbsp;</td>';
1.16      harris41 3193:       }
1.596     albertel 3194:       $prevattempts.= &end_data_table_row().&end_data_table();
1.1       albertel 3195:     } else {
1.596     albertel 3196:       $prevattempts=
                   3197: 	  &start_data_table().&start_data_table_row().
                   3198: 	  '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
                   3199: 	  &end_data_table_row().&end_data_table();
1.1       albertel 3200:     }
                   3201:   } else {
1.596     albertel 3202:     $prevattempts=
                   3203: 	  &start_data_table().&start_data_table_row().
                   3204: 	  '<td>'.&mt('No data.').'</td>'.
                   3205: 	  &end_data_table_row().&end_data_table();
1.1       albertel 3206:   }
1.10      albertel 3207: }
                   3208: 
1.581     albertel 3209: sub format_previous_attempt_value {
                   3210:     my ($key,$value) = @_;
                   3211:     if ($key =~ /timestamp/) {
                   3212: 	$value = &Apache::lonlocal::locallocaltime($value);
                   3213:     } elsif (ref($value) eq 'ARRAY') {
                   3214: 	$value = '('.join(', ', @{ $value }).')';
                   3215:     } else {
                   3216: 	$value = &unescape($value);
                   3217:     }
                   3218:     return $value;
                   3219: }
                   3220: 
                   3221: 
1.107     albertel 3222: sub relative_to_absolute {
                   3223:     my ($url,$output)=@_;
                   3224:     my $parser=HTML::TokeParser->new(\$output);
                   3225:     my $token;
                   3226:     my $thisdir=$url;
                   3227:     my @rlinks=();
                   3228:     while ($token=$parser->get_token) {
                   3229: 	if ($token->[0] eq 'S') {
                   3230: 	    if ($token->[1] eq 'a') {
                   3231: 		if ($token->[2]->{'href'}) {
                   3232: 		    $rlinks[$#rlinks+1]=$token->[2]->{'href'};
                   3233: 		}
                   3234: 	    } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
                   3235: 		$rlinks[$#rlinks+1]=$token->[2]->{'src'};
                   3236: 	    } elsif ($token->[1] eq 'base') {
                   3237: 		$thisdir=$token->[2]->{'href'};
                   3238: 	    }
                   3239: 	}
                   3240:     }
                   3241:     $thisdir=~s-/[^/]*$--;
1.356     albertel 3242:     foreach my $link (@rlinks) {
1.726     raeburn  3243: 	unless (($link=~/^https?\:\/\//i) ||
1.356     albertel 3244: 		($link=~/^\//) ||
                   3245: 		($link=~/^javascript:/i) ||
                   3246: 		($link=~/^mailto:/i) ||
                   3247: 		($link=~/^\#/)) {
                   3248: 	    my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
                   3249: 	    $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107     albertel 3250: 	}
                   3251:     }
                   3252: # -------------------------------------------------- Deal with Applet codebases
                   3253:     $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
                   3254:     return $output;
                   3255: }
                   3256: 
1.112     bowersj2 3257: =pod
                   3258: 
1.648     raeburn  3259: =item * &get_student_view()
1.112     bowersj2 3260: 
                   3261: show a snapshot of what student was looking at
                   3262: 
                   3263: =cut
                   3264: 
1.10      albertel 3265: sub get_student_view {
1.186     albertel 3266:   my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114     www      3267:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 3268:   my (%form);
1.10      albertel 3269:   my @elements=('symb','courseid','domain','username');
                   3270:   foreach my $element (@elements) {
1.186     albertel 3271:       $form{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 3272:   }
1.186     albertel 3273:   if (defined($moreenv)) {
                   3274:       %form=(%form,%{$moreenv});
                   3275:   }
1.236     albertel 3276:   if (defined($target)) { $form{'grade_target'} = $target; }
1.107     albertel 3277:   $feedurl=&Apache::lonnet::clutter($feedurl);
1.650     www      3278:   my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11      albertel 3279:   $userview=~s/\<body[^\>]*\>//gi;
                   3280:   $userview=~s/\<\/body\>//gi;
                   3281:   $userview=~s/\<html\>//gi;
                   3282:   $userview=~s/\<\/html\>//gi;
                   3283:   $userview=~s/\<head\>//gi;
                   3284:   $userview=~s/\<\/head\>//gi;
                   3285:   $userview=~s/action\s*\=/would_be_action\=/gi;
1.107     albertel 3286:   $userview=&relative_to_absolute($feedurl,$userview);
1.650     www      3287:   if (wantarray) {
                   3288:      return ($userview,$response);
                   3289:   } else {
                   3290:      return $userview;
                   3291:   }
                   3292: }
                   3293: 
                   3294: sub get_student_view_with_retries {
                   3295:   my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
                   3296: 
                   3297:     my $ok = 0;                 # True if we got a good response.
                   3298:     my $content;
                   3299:     my $response;
                   3300: 
                   3301:     # Try to get the student_view done. within the retries count:
                   3302:     
                   3303:     do {
                   3304:          ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
                   3305:          $ok      = $response->is_success;
                   3306:          if (!$ok) {
                   3307:             &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
                   3308:          }
                   3309:          $retries--;
                   3310:     } while (!$ok && ($retries > 0));
                   3311:     
                   3312:     if (!$ok) {
                   3313:        $content = '';          # On error return an empty content.
                   3314:     }
1.651     www      3315:     if (wantarray) {
                   3316:        return ($content, $response);
                   3317:     } else {
                   3318:        return $content;
                   3319:     }
1.11      albertel 3320: }
                   3321: 
1.112     bowersj2 3322: =pod
                   3323: 
1.648     raeburn  3324: =item * &get_student_answers() 
1.112     bowersj2 3325: 
                   3326: show a snapshot of how student was answering problem
                   3327: 
                   3328: =cut
                   3329: 
1.11      albertel 3330: sub get_student_answers {
1.100     sakharuk 3331:   my ($symb,$username,$domain,$courseid,%form) = @_;
1.114     www      3332:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 3333:   my (%moreenv);
1.11      albertel 3334:   my @elements=('symb','courseid','domain','username');
                   3335:   foreach my $element (@elements) {
1.186     albertel 3336:     $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 3337:   }
1.186     albertel 3338:   $moreenv{'grade_target'}='answer';
                   3339:   %moreenv=(%form,%moreenv);
1.497     raeburn  3340:   $feedurl = &Apache::lonnet::clutter($feedurl);
                   3341:   my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10      albertel 3342:   return $userview;
1.1       albertel 3343: }
1.116     albertel 3344: 
                   3345: =pod
                   3346: 
                   3347: =item * &submlink()
                   3348: 
1.242     albertel 3349: Inputs: $text $uname $udom $symb $target
1.116     albertel 3350: 
                   3351: Returns: A link to grades.pm such as to see the SUBM view of a student
                   3352: 
                   3353: =cut
                   3354: 
                   3355: ###############################################
                   3356: sub submlink {
1.242     albertel 3357:     my ($text,$uname,$udom,$symb,$target)=@_;
1.116     albertel 3358:     if (!($uname && $udom)) {
                   3359: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 3360: 	    &Apache::lonnet::whichuser($symb);
1.116     albertel 3361: 	if (!$symb) { $symb=$cursymb; }
                   3362:     }
1.254     matthew  3363:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      3364:     $symb=&escape($symb);
1.242     albertel 3365:     if ($target) { $target="target=\"$target\""; }
                   3366:     return '<a href="/adm/grades?&command=submission&'.
                   3367: 	'symb='.$symb.'&student='.$uname.
                   3368: 	'&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
                   3369: }
                   3370: ##############################################
                   3371: 
                   3372: =pod
                   3373: 
                   3374: =item * &pgrdlink()
                   3375: 
                   3376: Inputs: $text $uname $udom $symb $target
                   3377: 
                   3378: Returns: A link to grades.pm such as to see the PGRD view of a student
                   3379: 
                   3380: =cut
                   3381: 
                   3382: ###############################################
                   3383: sub pgrdlink {
                   3384:     my $link=&submlink(@_);
                   3385:     $link=~s/(&command=submission)/$1&showgrading=yes/;
                   3386:     return $link;
                   3387: }
                   3388: ##############################################
                   3389: 
                   3390: =pod
                   3391: 
                   3392: =item * &pprmlink()
                   3393: 
                   3394: Inputs: $text $uname $udom $symb $target
                   3395: 
                   3396: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283     albertel 3397: student and a specific resource
1.242     albertel 3398: 
                   3399: =cut
                   3400: 
                   3401: ###############################################
                   3402: sub pprmlink {
                   3403:     my ($text,$uname,$udom,$symb,$target)=@_;
                   3404:     if (!($uname && $udom)) {
                   3405: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 3406: 	    &Apache::lonnet::whichuser($symb);
1.242     albertel 3407: 	if (!$symb) { $symb=$cursymb; }
                   3408:     }
1.254     matthew  3409:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      3410:     $symb=&escape($symb);
1.242     albertel 3411:     if ($target) { $target="target=\"$target\""; }
1.595     albertel 3412:     return '<a href="/adm/parmset?command=set&amp;'.
                   3413: 	'symb='.$symb.'&amp;uname='.$uname.
                   3414: 	'&amp;udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116     albertel 3415: }
                   3416: ##############################################
1.37      matthew  3417: 
1.112     bowersj2 3418: =pod
                   3419: 
                   3420: =back
                   3421: 
                   3422: =cut
                   3423: 
1.37      matthew  3424: ###############################################
1.51      www      3425: 
                   3426: 
                   3427: sub timehash {
1.687     raeburn  3428:     my ($thistime) = @_;
                   3429:     my $timezone = &Apache::lonlocal::gettimezone();
                   3430:     my $dt = DateTime->from_epoch(epoch => $thistime)
                   3431:                      ->set_time_zone($timezone);
                   3432:     my $wday = $dt->day_of_week();
                   3433:     if ($wday == 7) { $wday = 0; }
                   3434:     return ( 'second' => $dt->second(),
                   3435:              'minute' => $dt->minute(),
                   3436:              'hour'   => $dt->hour(),
                   3437:              'day'     => $dt->day_of_month(),
                   3438:              'month'   => $dt->month(),
                   3439:              'year'    => $dt->year(),
                   3440:              'weekday' => $wday,
                   3441:              'dayyear' => $dt->day_of_year(),
                   3442:              'dlsav'   => $dt->is_dst() );
1.51      www      3443: }
                   3444: 
1.370     www      3445: sub utc_string {
                   3446:     my ($date)=@_;
1.371     www      3447:     return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370     www      3448: }
                   3449: 
1.51      www      3450: sub maketime {
                   3451:     my %th=@_;
1.687     raeburn  3452:     my ($epoch_time,$timezone,$dt);
                   3453:     $timezone = &Apache::lonlocal::gettimezone();
                   3454:     eval {
                   3455:         $dt = DateTime->new( year   => $th{'year'},
                   3456:                              month  => $th{'month'},
                   3457:                              day    => $th{'day'},
                   3458:                              hour   => $th{'hour'},
                   3459:                              minute => $th{'minute'},
                   3460:                              second => $th{'second'},
                   3461:                              time_zone => $timezone,
                   3462:                          );
                   3463:     };
                   3464:     if (!$@) {
                   3465:         $epoch_time = $dt->epoch;
                   3466:         if ($epoch_time) {
                   3467:             return $epoch_time;
                   3468:         }
                   3469:     }
1.51      www      3470:     return POSIX::mktime(
                   3471:         ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210     www      3472:          $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70      www      3473: }
                   3474: 
                   3475: #########################################
1.51      www      3476: 
                   3477: sub findallcourses {
1.482     raeburn  3478:     my ($roles,$uname,$udom) = @_;
1.355     albertel 3479:     my %roles;
                   3480:     if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348     albertel 3481:     my %courses;
1.51      www      3482:     my $now=time;
1.482     raeburn  3483:     if (!defined($uname)) {
                   3484:         $uname = $env{'user.name'};
                   3485:     }
                   3486:     if (!defined($udom)) {
                   3487:         $udom = $env{'user.domain'};
                   3488:     }
                   3489:     if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
                   3490:         my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
                   3491:         if (!%roles) {
                   3492:             %roles = (
                   3493:                        cc => 1,
                   3494:                        in => 1,
                   3495:                        ep => 1,
                   3496:                        ta => 1,
                   3497:                        cr => 1,
                   3498:                        st => 1,
                   3499:              );
                   3500:         }
                   3501:         foreach my $entry (keys(%roleshash)) {
                   3502:             my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
                   3503:             if ($trole =~ /^cr/) { 
                   3504:                 next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
                   3505:             } else {
                   3506:                 next if (!exists($roles{$trole}));
                   3507:             }
                   3508:             if ($tend) {
                   3509:                 next if ($tend < $now);
                   3510:             }
                   3511:             if ($tstart) {
                   3512:                 next if ($tstart > $now);
                   3513:             }
                   3514:             my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
                   3515:             (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
                   3516:             if ($secpart eq '') {
                   3517:                 ($cnum,$role) = split(/_/,$cnumpart); 
                   3518:                 $sec = 'none';
                   3519:                 $realsec = '';
                   3520:             } else {
                   3521:                 $cnum = $cnumpart;
                   3522:                 ($sec,$role) = split(/_/,$secpart);
                   3523:                 $realsec = $sec;
1.490     raeburn  3524:             }
1.482     raeburn  3525:             $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
                   3526:         }
                   3527:     } else {
                   3528:         foreach my $key (keys(%env)) {
1.483     albertel 3529: 	    if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
                   3530:                  $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482     raeburn  3531: 	        my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
                   3532: 	        next if ($role eq 'ca' || $role eq 'aa');
                   3533: 	        next if (%roles && !exists($roles{$role}));
                   3534: 	        my ($starttime,$endtime)=split(/\./,$env{$key});
                   3535:                 my $active=1;
                   3536:                 if ($starttime) {
                   3537: 		    if ($now<$starttime) { $active=0; }
                   3538:                 }
                   3539:                 if ($endtime) {
                   3540:                     if ($now>$endtime) { $active=0; }
                   3541:                 }
                   3542:                 if ($active) {
                   3543:                     if ($sec eq '') {
                   3544:                         $sec = 'none';
                   3545:                     }
                   3546:                     $courses{$cdom.'_'.$cnum}{$sec} = 
                   3547:                                      $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474     raeburn  3548:                 }
                   3549:             }
1.51      www      3550:         }
                   3551:     }
1.474     raeburn  3552:     return %courses;
1.51      www      3553: }
1.37      matthew  3554: 
1.54      www      3555: ###############################################
1.474     raeburn  3556: 
                   3557: sub blockcheck {
1.482     raeburn  3558:     my ($setters,$activity,$uname,$udom) = @_;
1.490     raeburn  3559: 
                   3560:     if (!defined($udom)) {
                   3561:         $udom = $env{'user.domain'};
                   3562:     }
                   3563:     if (!defined($uname)) {
                   3564:         $uname = $env{'user.name'};
                   3565:     }
                   3566: 
                   3567:     # If uname and udom are for a course, check for blocks in the course.
                   3568: 
                   3569:     if (&Apache::lonnet::is_course($udom,$uname)) {
                   3570:         my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502     raeburn  3571:         my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490     raeburn  3572:         return ($startblock,$endblock);
                   3573:     }
1.474     raeburn  3574: 
1.502     raeburn  3575:     my $startblock = 0;
                   3576:     my $endblock = 0;
1.482     raeburn  3577:     my %live_courses = &findallcourses(undef,$uname,$udom);
1.474     raeburn  3578: 
1.490     raeburn  3579:     # If uname is for a user, and activity is course-specific, i.e.,
                   3580:     # boards, chat or groups, check for blocking in current course only.
1.474     raeburn  3581: 
1.490     raeburn  3582:     if (($activity eq 'boards' || $activity eq 'chat' ||
                   3583:          $activity eq 'groups') && ($env{'request.course.id'})) {
                   3584:         foreach my $key (keys(%live_courses)) {
                   3585:             if ($key ne $env{'request.course.id'}) {
                   3586:                 delete($live_courses{$key});
                   3587:             }
                   3588:         }
                   3589:     }
                   3590: 
                   3591:     my $otheruser = 0;
                   3592:     my %own_courses;
                   3593:     if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
                   3594:         # Resource belongs to user other than current user.
                   3595:         $otheruser = 1;
                   3596:         # Gather courses for current user
                   3597:         %own_courses = 
                   3598:             &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
                   3599:     }
                   3600: 
                   3601:     # Gather active course roles - course coordinator, instructor, 
                   3602:     # exam proctor, ta, student, or custom role.
1.474     raeburn  3603: 
                   3604:     foreach my $course (keys(%live_courses)) {
1.482     raeburn  3605:         my ($cdom,$cnum);
                   3606:         if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
                   3607:             $cdom = $env{'course.'.$course.'.domain'};
                   3608:             $cnum = $env{'course.'.$course.'.num'};
                   3609:         } else {
1.490     raeburn  3610:             ($cdom,$cnum) = split(/_/,$course); 
1.482     raeburn  3611:         }
                   3612:         my $no_ownblock = 0;
                   3613:         my $no_userblock = 0;
1.533     raeburn  3614:         if ($otheruser && $activity ne 'com') {
1.490     raeburn  3615:             # Check if current user has 'evb' priv for this
                   3616:             if (defined($own_courses{$course})) {
                   3617:                 foreach my $sec (keys(%{$own_courses{$course}})) {
                   3618:                     my $checkrole = 'cm./'.$cdom.'/'.$cnum;
                   3619:                     if ($sec ne 'none') {
                   3620:                         $checkrole .= '/'.$sec;
                   3621:                     }
                   3622:                     if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   3623:                         $no_ownblock = 1;
                   3624:                         last;
                   3625:                     }
                   3626:                 }
                   3627:             }
                   3628:             # if they have 'evb' priv and are currently not playing student
                   3629:             next if (($no_ownblock) &&
                   3630:                  ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
                   3631:         }
1.474     raeburn  3632:         foreach my $sec (keys(%{$live_courses{$course}})) {
1.482     raeburn  3633:             my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474     raeburn  3634:             if ($sec ne 'none') {
1.482     raeburn  3635:                 $checkrole .= '/'.$sec;
1.474     raeburn  3636:             }
1.490     raeburn  3637:             if ($otheruser) {
                   3638:                 # Resource belongs to user other than current user.
                   3639:                 # Assemble privs for that user, and check for 'evb' priv.
1.482     raeburn  3640:                 my ($trole,$tdom,$tnum,$tsec);
                   3641:                 my $entry = $live_courses{$course}{$sec};
                   3642:                 if ($entry =~ /^cr/) {
                   3643:                     ($trole,$tdom,$tnum,$tsec) = 
                   3644:                       ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
                   3645:                 } else {
                   3646:                     ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
                   3647:                 }
                   3648:                 my ($spec,$area,$trest,%allroles,%userroles);
                   3649:                 $area = '/'.$tdom.'/'.$tnum;
                   3650:                 $trest = $tnum;
                   3651:                 if ($tsec ne '') {
                   3652:                     $area .= '/'.$tsec;
                   3653:                     $trest .= '/'.$tsec;
                   3654:                 }
                   3655:                 $spec = $trole.'.'.$area;
                   3656:                 if ($trole =~ /^cr/) {
                   3657:                     &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
                   3658:                                                       $tdom,$spec,$trest,$area);
                   3659:                 } else {
                   3660:                     &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
                   3661:                                                        $tdom,$spec,$trest,$area);
                   3662:                 }
                   3663:                 my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486     raeburn  3664:                 if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
                   3665:                     if ($1) {
                   3666:                         $no_userblock = 1;
                   3667:                         last;
                   3668:                     }
                   3669:                 }
1.490     raeburn  3670:             } else {
                   3671:                 # Resource belongs to current user
                   3672:                 # Check for 'evb' priv via lonnet::allowed().
1.482     raeburn  3673:                 if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   3674:                     $no_ownblock = 1;
                   3675:                     last;
                   3676:                 }
1.474     raeburn  3677:             }
                   3678:         }
                   3679:         # if they have the evb priv and are currently not playing student
1.482     raeburn  3680:         next if (($no_ownblock) &&
1.491     albertel 3681:                  ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482     raeburn  3682:         next if ($no_userblock);
1.474     raeburn  3683: 
1.490     raeburn  3684:         # Retrieve blocking times and identity of blocker for course
                   3685:         # of specified user, unless user has 'evb' privilege.
1.502     raeburn  3686:         
                   3687:         my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
                   3688:         if (($start != 0) && 
                   3689:             (($startblock == 0) || ($startblock > $start))) {
                   3690:             $startblock = $start;
                   3691:         }
                   3692:         if (($end != 0)  &&
                   3693:             (($endblock == 0) || ($endblock < $end))) {
                   3694:             $endblock = $end;
                   3695:         }
1.490     raeburn  3696:     }
                   3697:     return ($startblock,$endblock);
                   3698: }
                   3699: 
                   3700: sub get_blocks {
                   3701:     my ($setters,$activity,$cdom,$cnum) = @_;
                   3702:     my $startblock = 0;
                   3703:     my $endblock = 0;
                   3704:     my $course = $cdom.'_'.$cnum;
                   3705:     $setters->{$course} = {};
                   3706:     $setters->{$course}{'staff'} = [];
                   3707:     $setters->{$course}{'times'} = [];
                   3708:     my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
                   3709:     foreach my $record (keys(%records)) {
                   3710:         my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
                   3711:         if ($start <= time && $end >= time) {
                   3712:             my ($staff_name,$staff_dom,$title,$blocks) =
                   3713:                 &parse_block_record($records{$record});
                   3714:             if ($blocks->{$activity} eq 'on') {
                   3715:                 push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
                   3716:                 push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491     albertel 3717:                 if ( ($startblock == 0) || ($startblock > $start) ) {
                   3718:                     $startblock = $start;
1.490     raeburn  3719:                 }
1.491     albertel 3720:                 if ( ($endblock == 0) || ($endblock < $end) ) {
                   3721:                     $endblock = $end;
1.474     raeburn  3722:                 }
                   3723:             }
                   3724:         }
                   3725:     }
                   3726:     return ($startblock,$endblock);
                   3727: }
                   3728: 
                   3729: sub parse_block_record {
                   3730:     my ($record) = @_;
                   3731:     my ($setuname,$setudom,$title,$blocks);
                   3732:     if (ref($record) eq 'HASH') {
                   3733:         ($setuname,$setudom) = split(/:/,$record->{'setter'});
                   3734:         $title = &unescape($record->{'event'});
                   3735:         $blocks = $record->{'blocks'};
                   3736:     } else {
                   3737:         my @data = split(/:/,$record,3);
                   3738:         if (scalar(@data) eq 2) {
                   3739:             $title = $data[1];
                   3740:             ($setuname,$setudom) = split(/@/,$data[0]);
                   3741:         } else {
                   3742:             ($setuname,$setudom,$title) = @data;
                   3743:         }
                   3744:         $blocks = { 'com' => 'on' };
                   3745:     }
                   3746:     return ($setuname,$setudom,$title,$blocks);
                   3747: }
                   3748: 
                   3749: sub build_block_table {
                   3750:     my ($startblock,$endblock,$setters) = @_;
                   3751:     my %lt = &Apache::lonlocal::texthash(
                   3752:         'cacb' => 'Currently active communication blocks',
                   3753:         'cour' => 'Course',
                   3754:         'dura' => 'Duration',
                   3755:         'blse' => 'Block set by'
                   3756:     );
                   3757:     my $output;
1.476     raeburn  3758:     $output = '<br />'.$lt{'cacb'}.':<br />';
1.474     raeburn  3759:     $output .= &start_data_table();
                   3760:     $output .= '
                   3761: <tr>
                   3762:  <th>'.$lt{'cour'}.'</th>
                   3763:  <th>'.$lt{'dura'}.'</th>
                   3764:  <th>'.$lt{'blse'}.'</th>
                   3765: </tr>
                   3766: ';
                   3767:     foreach my $course (keys(%{$setters})) {
                   3768:         my %courseinfo=&Apache::lonnet::coursedescription($course);
                   3769:         for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) {
                   3770:             my ($uname,$udom) = @{$$setters{$course}{staff}[$i]};
1.490     raeburn  3771:             my $fullname = &plainname($uname,$udom);
                   3772:             if (defined($env{'user.name'}) && defined($env{'user.domain'})
                   3773:                 && $env{'user.name'} ne 'public' 
                   3774:                 && $env{'user.domain'} ne 'public') {
                   3775:                 $fullname = &aboutmewrapper($fullname,$uname,$udom);
                   3776:             }
1.474     raeburn  3777:             my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]};
                   3778:             $openblock = &Apache::lonlocal::locallocaltime($openblock);
                   3779:             $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
                   3780:             $output .= &Apache::loncommon::start_data_table_row().
                   3781:                        '<td>'.$courseinfo{'description'}.'</td>'.
                   3782:                        '<td>'.$openblock.' to '.$closeblock.'</td>'.
1.490     raeburn  3783:                        '<td>'.$fullname.'</td>'.
1.474     raeburn  3784:                         &Apache::loncommon::end_data_table_row();
                   3785:         }
                   3786:     }
                   3787:     $output .= &end_data_table();
                   3788: }
                   3789: 
1.490     raeburn  3790: sub blocking_status {
                   3791:     my ($activity,$uname,$udom) = @_;
                   3792:     my %setters;
                   3793:     my ($blocked,$output,$ownitem,$is_course);
                   3794:     my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
                   3795:     if ($startblock && $endblock) {
                   3796:         $blocked = 1;
                   3797:         if (wantarray) {
                   3798:             my $category;
                   3799:             if ($activity eq 'boards') {
                   3800:                 $category = 'Discussion posts in this course';
                   3801:             } elsif ($activity eq 'blogs') {
                   3802:                 $category = 'Blogs';
                   3803:             } elsif ($activity eq 'port') {
                   3804:                 if (defined($uname) && defined($udom)) {
                   3805:                     if ($uname eq $env{'user.name'} &&
                   3806:                         $udom eq $env{'user.domain'}) {
                   3807:                         $ownitem = 1;
                   3808:                     }
                   3809:                 }
                   3810:                 $is_course = &Apache::lonnet::is_course($udom,$uname);
                   3811:                 if ($ownitem) { 
                   3812:                     $category = 'Your portfolio files';  
                   3813:                 } elsif ($is_course) {
                   3814:                     my $coursedesc;
                   3815:                     foreach my $course (keys(%setters)) {
                   3816:                         my %courseinfo =
                   3817:                              &Apache::lonnet::coursedescription($course);
                   3818:                         $coursedesc = $courseinfo{'description'};
                   3819:                     }
                   3820:                     $category = "Group files in the course '$coursedesc'";
                   3821:                 } else {
                   3822:                     $category = 'Portfolio files belonging to ';
                   3823:                     if ($env{'user.name'} eq 'public' && 
                   3824:                         $env{'user.domain'} eq 'public') {
                   3825:                         $category .= &plainname($uname,$udom);
                   3826:                     } else {
                   3827:                         $category .= &aboutmewrapper(&plainname($uname,$udom),$uname,$udom);  
                   3828:                     }
                   3829:                 }
                   3830:             } elsif ($activity eq 'groups') {
                   3831:                 $category = 'Groups in this course';
                   3832:             }
                   3833:             my $showstart = &Apache::lonlocal::locallocaltime($startblock);
                   3834:             my $showend = &Apache::lonlocal::locallocaltime($endblock);
                   3835:             $output = '<br />'.&mt('[_1] will be inaccessible between [_2] and [_3] because communication is being blocked.',$category,$showstart,$showend).'<br />';
                   3836:             if (!($activity eq 'port' && !($ownitem) && !($is_course))) { 
                   3837:                 $output .= &build_block_table($startblock,$endblock,\%setters);
                   3838:             }
                   3839:         }
                   3840:     }
                   3841:     if (wantarray) {
                   3842:         return ($blocked,$output);
                   3843:     } else {
                   3844:         return $blocked;
                   3845:     }
                   3846: }
                   3847: 
1.60      matthew  3848: ###############################################
                   3849: 
1.682     raeburn  3850: sub check_ip_acc {
                   3851:     my ($acc)=@_;
                   3852:     &Apache::lonxml::debug("acc is $acc");
                   3853:     if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
                   3854:         return 1;
                   3855:     }
                   3856:     my $allowed=0;
                   3857:     my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
                   3858: 
                   3859:     my $name;
                   3860:     foreach my $pattern (split(',',$acc)) {
                   3861:         $pattern =~ s/^\s*//;
                   3862:         $pattern =~ s/\s*$//;
                   3863:         if ($pattern =~ /\*$/) {
                   3864:             #35.8.*
                   3865:             $pattern=~s/\*//;
                   3866:             if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
                   3867:         } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
                   3868:             #35.8.3.[34-56]
                   3869:             my $low=$2;
                   3870:             my $high=$3;
                   3871:             $pattern=$1;
                   3872:             if ($ip =~ /^\Q$pattern\E/) {
                   3873:                 my $last=(split(/\./,$ip))[3];
                   3874:                 if ($last <=$high && $last >=$low) { $allowed=1; }
                   3875:             }
                   3876:         } elsif ($pattern =~ /^\*/) {
                   3877:             #*.msu.edu
                   3878:             $pattern=~s/\*//;
                   3879:             if (!defined($name)) {
                   3880:                 use Socket;
                   3881:                 my $netaddr=inet_aton($ip);
                   3882:                 ($name)=gethostbyaddr($netaddr,AF_INET);
                   3883:             }
                   3884:             if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
                   3885:         } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
                   3886:             #127.0.0.1
                   3887:             if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
                   3888:         } else {
                   3889:             #some.name.com
                   3890:             if (!defined($name)) {
                   3891:                 use Socket;
                   3892:                 my $netaddr=inet_aton($ip);
                   3893:                 ($name)=gethostbyaddr($netaddr,AF_INET);
                   3894:             }
                   3895:             if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
                   3896:         }
                   3897:         if ($allowed) { last; }
                   3898:     }
                   3899:     return $allowed;
                   3900: }
                   3901: 
                   3902: ###############################################
                   3903: 
1.60      matthew  3904: =pod
                   3905: 
1.112     bowersj2 3906: =head1 Domain Template Functions
                   3907: 
                   3908: =over 4
                   3909: 
                   3910: =item * &determinedomain()
1.60      matthew  3911: 
                   3912: Inputs: $domain (usually will be undef)
                   3913: 
1.63      www      3914: Returns: Determines which domain should be used for designs
1.60      matthew  3915: 
                   3916: =cut
1.54      www      3917: 
1.60      matthew  3918: ###############################################
1.63      www      3919: sub determinedomain {
                   3920:     my $domain=shift;
1.531     albertel 3921:     if (! $domain) {
1.60      matthew  3922:         # Determine domain if we have not been given one
                   3923:         $domain = $Apache::lonnet::perlvar{'lonDefDomain'};
1.258     albertel 3924:         if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
                   3925:         if ($env{'request.role.domain'}) { 
                   3926:             $domain=$env{'request.role.domain'}; 
1.60      matthew  3927:         }
                   3928:     }
1.63      www      3929:     return $domain;
                   3930: }
                   3931: ###############################################
1.517     raeburn  3932: 
1.518     albertel 3933: sub devalidate_domconfig_cache {
                   3934:     my ($udom)=@_;
                   3935:     &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
                   3936: }
                   3937: 
                   3938: # ---------------------- Get domain configuration for a domain
                   3939: sub get_domainconf {
                   3940:     my ($udom) = @_;
                   3941:     my $cachetime=1800;
                   3942:     my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
                   3943:     if (defined($cached)) { return %{$result}; }
                   3944: 
                   3945:     my %domconfig = &Apache::lonnet::get_dom('configuration',
                   3946: 					     ['login','rolecolors'],$udom);
1.632     raeburn  3947:     my (%designhash,%legacy);
1.518     albertel 3948:     if (keys(%domconfig) > 0) {
                   3949:         if (ref($domconfig{'login'}) eq 'HASH') {
1.632     raeburn  3950:             if (keys(%{$domconfig{'login'}})) {
                   3951:                 foreach my $key (keys(%{$domconfig{'login'}})) {
1.699     raeburn  3952:                     if (ref($domconfig{'login'}{$key}) eq 'HASH') {
                   3953:                         foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
                   3954:                             $designhash{$udom.'.login.'.$key.'_'.$img} = 
                   3955:                                 $domconfig{'login'}{$key}{$img};
                   3956:                         }
                   3957:                     } else {
                   3958:                         $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
                   3959:                     }
1.632     raeburn  3960:                 }
                   3961:             } else {
                   3962:                 $legacy{'login'} = 1;
1.518     albertel 3963:             }
1.632     raeburn  3964:         } else {
                   3965:             $legacy{'login'} = 1;
1.518     albertel 3966:         }
                   3967:         if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632     raeburn  3968:             if (keys(%{$domconfig{'rolecolors'}})) {
                   3969:                 foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
                   3970:                     if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
                   3971:                         foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
                   3972:                             $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
                   3973:                         }
1.518     albertel 3974:                     }
                   3975:                 }
1.632     raeburn  3976:             } else {
                   3977:                 $legacy{'rolecolors'} = 1;
1.518     albertel 3978:             }
1.632     raeburn  3979:         } else {
                   3980:             $legacy{'rolecolors'} = 1;
1.518     albertel 3981:         }
1.632     raeburn  3982:         if (keys(%legacy) > 0) {
                   3983:             my %legacyhash = &get_legacy_domconf($udom);
                   3984:             foreach my $item (keys(%legacyhash)) {
                   3985:                 if ($item =~ /^\Q$udom\E\.login/) {
                   3986:                     if ($legacy{'login'}) { 
                   3987:                         $designhash{$item} = $legacyhash{$item};
                   3988:                     }
                   3989:                 } else {
                   3990:                     if ($legacy{'rolecolors'}) {
                   3991:                         $designhash{$item} = $legacyhash{$item};
                   3992:                     }
1.518     albertel 3993:                 }
                   3994:             }
                   3995:         }
1.632     raeburn  3996:     } else {
                   3997:         %designhash = &get_legacy_domconf($udom); 
1.518     albertel 3998:     }
                   3999:     &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
                   4000: 				  $cachetime);
                   4001:     return %designhash;
                   4002: }
                   4003: 
1.632     raeburn  4004: sub get_legacy_domconf {
                   4005:     my ($udom) = @_;
                   4006:     my %legacyhash;
                   4007:     my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
                   4008:     my $designfile =  $designdir.'/'.$udom.'.tab';
                   4009:     if (-e $designfile) {
                   4010:         if ( open (my $fh,"<$designfile") ) {
                   4011:             while (my $line = <$fh>) {
                   4012:                 next if ($line =~ /^\#/);
                   4013:                 chomp($line);
                   4014:                 my ($key,$val)=(split(/\=/,$line));
                   4015:                 if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
                   4016:             }
                   4017:             close($fh);
                   4018:         }
                   4019:     }
                   4020:     if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
                   4021:         $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
                   4022:     }
                   4023:     return %legacyhash;
                   4024: }
                   4025: 
1.63      www      4026: =pod
                   4027: 
1.112     bowersj2 4028: =item * &domainlogo()
1.63      www      4029: 
                   4030: Inputs: $domain (usually will be undef)
                   4031: 
                   4032: Returns: A link to a domain logo, if the domain logo exists.
                   4033: If the domain logo does not exist, a description of the domain.
                   4034: 
                   4035: =cut
1.112     bowersj2 4036: 
1.63      www      4037: ###############################################
                   4038: sub domainlogo {
1.517     raeburn  4039:     my $domain = &determinedomain(shift);
1.518     albertel 4040:     my %designhash = &get_domainconf($domain);    
1.517     raeburn  4041:     # See if there is a logo
                   4042:     if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519     raeburn  4043:         my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538     albertel 4044:         if ($imgsrc =~ m{^/(adm|res)/}) {
                   4045: 	    if ($imgsrc =~ m{^/res/}) {
                   4046: 		my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
                   4047: 		&Apache::lonnet::repcopy($local_name);
                   4048: 	    }
                   4049: 	   $imgsrc = &lonhttpdurl($imgsrc);
1.519     raeburn  4050:         } 
                   4051:         return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514     albertel 4052:     } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
                   4053:         return &Apache::lonnet::domain($domain,'description');
1.59      www      4054:     } else {
1.60      matthew  4055:         return '';
1.59      www      4056:     }
                   4057: }
1.63      www      4058: ##############################################
                   4059: 
                   4060: =pod
                   4061: 
1.112     bowersj2 4062: =item * &designparm()
1.63      www      4063: 
                   4064: Inputs: $which parameter; $domain (usually will be undef)
                   4065: 
                   4066: Returns: value of designparamter $which
                   4067: 
                   4068: =cut
1.112     bowersj2 4069: 
1.397     albertel 4070: 
1.400     albertel 4071: ##############################################
1.397     albertel 4072: sub designparm {
                   4073:     my ($which,$domain)=@_;
1.258     albertel 4074:     if ($env{'browser.blackwhite'} eq 'on') {
1.635     raeburn  4075: 	if ($which=~/\.(font|alink|vlink|link|textcol)$/) {
1.110     www      4076: 	    return '#000000';
                   4077: 	}
1.635     raeburn  4078: 	if ($which=~/\.(pgbg|sidebg|bgcol)$/) {
1.110     www      4079: 	    return '#FFFFFF';
                   4080: 	}
                   4081: 	if ($which=~/\.tabbg$/) {
                   4082: 	    return '#CCCCCC';
                   4083: 	}
                   4084:     }
1.397     albertel 4085:     if (exists($env{'environment.color.'.$which})) {
1.258     albertel 4086: 	return $env{'environment.color.'.$which};
1.96      www      4087:     }
1.63      www      4088:     $domain=&determinedomain($domain);
1.518     albertel 4089:     my %domdesign = &get_domainconf($domain);
1.520     raeburn  4090:     my $output;
1.517     raeburn  4091:     if ($domdesign{$domain.'.'.$which} ne '') {
1.520     raeburn  4092: 	$output = $domdesign{$domain.'.'.$which};
1.63      www      4093:     } else {
1.520     raeburn  4094:         $output = $defaultdesign{$which};
                   4095:     }
                   4096:     if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635     raeburn  4097:         ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538     albertel 4098:         if ($output =~ m{^/(adm|res)/}) {
                   4099: 	    if ($output =~ m{^/res/}) {
                   4100: 		my $local_name = &Apache::lonnet::filelocation('',$output);
                   4101: 		&Apache::lonnet::repcopy($local_name);
                   4102: 	    }
1.520     raeburn  4103:             $output = &lonhttpdurl($output);
                   4104:         }
1.63      www      4105:     }
1.520     raeburn  4106:     return $output;
1.63      www      4107: }
1.59      www      4108: 
1.60      matthew  4109: ###############################################
                   4110: ###############################################
                   4111: 
                   4112: =pod
                   4113: 
1.112     bowersj2 4114: =back
                   4115: 
1.549     albertel 4116: =head1 HTML Helpers
1.112     bowersj2 4117: 
                   4118: =over 4
                   4119: 
                   4120: =item * &bodytag()
1.60      matthew  4121: 
                   4122: Returns a uniform header for LON-CAPA web pages.
                   4123: 
                   4124: Inputs: 
                   4125: 
1.112     bowersj2 4126: =over 4
                   4127: 
                   4128: =item * $title, A title to be displayed on the page.
                   4129: 
                   4130: =item * $function, the current role (can be undef).
                   4131: 
                   4132: =item * $addentries, extra parameters for the <body> tag.
                   4133: 
                   4134: =item * $bodyonly, if defined, only return the <body> tag.
                   4135: 
                   4136: =item * $domain, if defined, force a given domain.
                   4137: 
                   4138: =item * $forcereg, if page should register as content page (relevant for 
1.86      www      4139:             text interface only)
1.60      matthew  4140: 
1.326     albertel 4141: =item * $customtitle, alternate text to use instead of $title
                   4142:                       in the title box that appears, this text
                   4143:                       is not auto translated like the $title is
1.309     albertel 4144: 
                   4145: =item * $notopbar, if true, keep the 'what is this' info but remove the
                   4146:                    navigational links
1.317     albertel 4147: 
1.338     albertel 4148: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
                   4149: 
                   4150: =item * $notitle, if true keep the nav controls, but remove the title bar
                   4151: 
1.361     albertel 4152: =item * $no_inline_link, if true and in remote mode, don't show the 
                   4153:          'Switch To Inline Menu' link
                   4154: 
1.460     albertel 4155: =item * $args, optional argument valid values are
                   4156:             no_auto_mt_title -> prevents &mt()ing the title arg
1.562     albertel 4157:             inherit_jsmath -> when creating popup window in a page,
                   4158:                               should it have jsmath forced on by the
                   4159:                               current page
1.460     albertel 4160: 
1.112     bowersj2 4161: =back
                   4162: 
1.60      matthew  4163: Returns: A uniform header for LON-CAPA web pages.  
                   4164: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
                   4165: If $bodyonly is undef or zero, an html string containing a <body> tag and 
                   4166: other decorations will be returned.
                   4167: 
                   4168: =cut
                   4169: 
1.54      www      4170: sub bodytag {
1.309     albertel 4171:     my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,$customtitle,
1.460     albertel 4172: 	$notopbar,$bgcolor,$notitle,$no_inline_link,$args)=@_;
1.339     albertel 4173: 
1.460     albertel 4174:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339     albertel 4175: 
1.183     matthew  4176:     $function = &get_users_function() if (!$function);
1.339     albertel 4177:     my $img =    &designparm($function.'.img',$domain);
                   4178:     my $font =   &designparm($function.'.font',$domain);
                   4179:     my $pgbg   = $bgcolor || &designparm($function.'.pgbg',$domain);
                   4180: 
                   4181:     my %design = ( 'style'   => 'margin-top: 0px',
1.535     albertel 4182: 		   'bgcolor' => $pgbg,
1.339     albertel 4183: 		   'text'    => $font,
                   4184:                    'alink'   => &designparm($function.'.alink',$domain),
                   4185: 		   'vlink'   => &designparm($function.'.vlink',$domain),
                   4186: 		   'link'    => &designparm($function.'.link',$domain),);
1.438     albertel 4187:     @design{keys(%$addentries)} = @$addentries{keys(%$addentries)}; 
1.339     albertel 4188: 
1.63      www      4189:  # role and realm
1.378     raeburn  4190:     my ($role,$realm) = split(/\./,$env{'request.role'},2);
                   4191:     if ($role  eq 'ca') {
1.479     albertel 4192:         my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500     albertel 4193:         $realm = &plainname($rname,$rdom);
1.378     raeburn  4194:     } 
1.55      www      4195: # realm
1.258     albertel 4196:     if ($env{'request.course.id'}) {
1.378     raeburn  4197:         if ($env{'request.role'} !~ /^cr/) {
                   4198:             $role = &Apache::lonnet::plaintext($role,&course_type());
                   4199:         }
1.359     albertel 4200: 	$realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378     raeburn  4201:     } else {
                   4202:         $role = &Apache::lonnet::plaintext($role);
1.54      www      4203:     }
1.433     albertel 4204: 
1.359     albertel 4205:     if (!$realm) { $realm='&nbsp;'; }
1.55      www      4206: # Set messages
1.60      matthew  4207:     my $messages=&domainlogo($domain);
1.330     albertel 4208: 
1.438     albertel 4209:     my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329     albertel 4210: 
1.101     www      4211: # construct main body tag
1.359     albertel 4212:     my $bodytag = "<body $extra_body_attr>".
1.562     albertel 4213: 	&Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252     albertel 4214: 
1.530     albertel 4215:     if ($bodyonly) {
1.60      matthew  4216:         return $bodytag;
1.258     albertel 4217:     } elsif ($env{'browser.interface'} eq 'textual') {
1.95      www      4218: # Accessibility
1.224     raeburn  4219:           
1.337     albertel 4220: 	$bodytag.=&Apache::lonmenu::menubuttons($forcereg,$forcereg);
1.338     albertel 4221: 	if (!$notitle) {
1.337     albertel 4222: 	    $bodytag.='<h1>LON-CAPA: '.$title.'</h1>';
                   4223: 	}
                   4224: 	return $bodytag;
1.359     albertel 4225:     }
                   4226: 
1.410     albertel 4227:     my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.433     albertel 4228:     if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
                   4229: 	undef($role);
1.434     albertel 4230:     } else {
                   4231: 	$name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433     albertel 4232:     }
1.359     albertel 4233:     
                   4234:     my $roleinfo=(<<ENDROLE);
                   4235: <td class="LC_title_bar_who">
                   4236: <div class="LC_title_bar_name">
1.410     albertel 4237:     $name
1.361     albertel 4238:     &nbsp;
1.359     albertel 4239: </div>
                   4240: <div class="LC_title_bar_role">
1.361     albertel 4241: $role&nbsp;
1.359     albertel 4242: </div>
                   4243: <div class="LC_title_bar_realm">
1.361     albertel 4244: $realm&nbsp;
1.359     albertel 4245: </div>
1.206     albertel 4246: </td>
                   4247: ENDROLE
1.235     raeburn  4248: 
1.359     albertel 4249:     my $titleinfo = '<span class="LC_title_bar_title">'.$title.'</span>';
                   4250:     if ($customtitle) {
                   4251:         $titleinfo = $customtitle;
                   4252:     }
                   4253:     #
                   4254:     # Extra info if you are the DC
                   4255:     my $dc_info = '';
                   4256:     if ($env{'user.adv'} && exists($env{'user.role.dc./'.
                   4257:                         $env{'course.'.$env{'request.course.id'}.
                   4258:                                  '.domain'}.'/'})) {
                   4259:         my $cid = $env{'request.course.id'};
                   4260:         $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380     www      4261:         $dc_info =~ s/\s+$//;
1.359     albertel 4262:         $dc_info = '('.$dc_info.')';
                   4263:     }
                   4264: 
1.644     www      4265:     if (($env{'environment.remote'} eq 'off') || ($args->{'suppress_header_logos'})) {
1.359     albertel 4266:         # No Remote
1.258     albertel 4267: 	if ($env{'request.state'} eq 'construct') {
1.359     albertel 4268: 	    $forcereg=1;
                   4269: 	}
                   4270: 
                   4271: 	if (!$customtitle && $env{'request.state'} eq 'construct') {
                   4272: 	    # this is for resources; directories have customtitle, and crumbs
                   4273:             # and select recent are created in lonpubdir.pm  
1.229     albertel 4274: 	    my ($uname,$thisdisfn)=
1.258     albertel 4275: 		($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
1.229     albertel 4276: 	    my $formaction='/priv/'.$uname.'/'.$thisdisfn;
                   4277: 	    $formaction=~s/\/+/\//g;
                   4278: 
1.359     albertel 4279: 	    my $parentpath = '';
                   4280: 	    my $lastitem = '';
                   4281: 	    if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
                   4282: 		$parentpath = $1;
                   4283: 		$lastitem = $2;
                   4284: 	    } else {
                   4285: 		$lastitem = $thisdisfn;
                   4286: 	    }
                   4287: 	    $titleinfo = 
1.640     bisitz   4288: 		&Apache::loncommon::help_open_menu('','',3,'Authoring')
                   4289: 		.'<b>'.&mt('Construction Space').'</b>:&nbsp;'
                   4290: 		.'<form name="dirs" method="post" action="'.$formaction
1.359     albertel 4291: 		.'" target="_top"><tt><b>'
1.705     tempelho 4292: 		.&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."<span class=\"LC_fontsize_big\">$lastitem</span></b></tt><br />"
1.359     albertel 4293: 		.&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
                   4294: 		.'</form>'
                   4295: 		.&Apache::lonmenu::constspaceform();
1.235     raeburn  4296:         }
1.359     albertel 4297: 
1.337     albertel 4298:         my $titletable;
1.338     albertel 4299: 	if (!$notitle) {
1.337     albertel 4300: 	    $titletable =
1.359     albertel 4301: 		'<table id="LC_title_bar">'.
                   4302:                          "<tr><td> $titleinfo $dc_info</td>".$roleinfo.
                   4303: 			 '</tr></table>';
1.337     albertel 4304: 	}
1.359     albertel 4305: 	if ($notopbar) {
                   4306: 	    $bodytag .= $titletable;
                   4307: 	} else {
                   4308: 	    if ($env{'request.state'} eq 'construct') {
1.337     albertel 4309:                 $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg,
                   4310: 							  $titletable);
1.272     raeburn  4311:             } else {
1.336     albertel 4312:                 $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg).
1.359     albertel 4313: 		    $titletable;
1.272     raeburn  4314:             }
1.235     raeburn  4315:         }
                   4316:         return $bodytag;
1.94      www      4317:     }
1.95      www      4318: 
1.93      www      4319: #
1.95      www      4320: # Top frame rendering, Remote is up
1.93      www      4321: #
1.359     albertel 4322: 
1.517     raeburn  4323:     my $imgsrc = $img;
                   4324:     if ($img =~ /^\/adm/) {
1.575     albertel 4325:         $imgsrc = &lonhttpdurl($img);
1.517     raeburn  4326:     }
                   4327:     my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359     albertel 4328: 
1.305     www      4329:     # Explicit link to get inline menu
1.361     albertel 4330:     my $menu= ($no_inline_link?''
                   4331: 	       :'<br /><a href="/adm/remote?action=collapse">'.&mt('Switch to Inline Menu Mode').'</a>');
1.245     matthew  4332:     #
1.338     albertel 4333:     if ($notitle) {
1.337     albertel 4334: 	return $bodytag;
                   4335:     }
1.94      www      4336:     return(<<ENDBODY);
1.60      matthew  4337: $bodytag
1.359     albertel 4338: <table id="LC_title_bar" class="LC_with_remote">
1.368     albertel 4339: <tr><td class="LC_title_bar_role_logo">$upperleft</td>
1.359     albertel 4340:     <td class="LC_title_bar_domain_logo">$messages&nbsp;</td>
1.54      www      4341: </tr>
1.359     albertel 4342: <tr><td>$titleinfo $dc_info $menu</td>
                   4343: $roleinfo
1.368     albertel 4344: </tr>
1.356     albertel 4345: </table>
1.54      www      4346: ENDBODY
1.182     matthew  4347: }
                   4348: 
1.330     albertel 4349: sub make_attr_string {
                   4350:     my ($register,$attr_ref) = @_;
                   4351: 
                   4352:     if ($attr_ref && !ref($attr_ref)) {
                   4353: 	die("addentries Must be a hash ref ".
                   4354: 	    join(':',caller(1))." ".
                   4355: 	    join(':',caller(0))." ");
                   4356:     }
                   4357: 
                   4358:     if ($register) {
1.339     albertel 4359: 	my ($on_load,$on_unload);
                   4360: 	foreach my $key (keys(%{$attr_ref})) {
                   4361: 	    if      (lc($key) eq 'onload') {
                   4362: 		$on_load.=$attr_ref->{$key}.';';
                   4363: 		delete($attr_ref->{$key});
                   4364: 
                   4365: 	    } elsif (lc($key) eq 'onunload') {
                   4366: 		$on_unload.=$attr_ref->{$key}.';';
                   4367: 		delete($attr_ref->{$key});
                   4368: 	    }
                   4369: 	}
                   4370: 	$attr_ref->{'onload'}  =
                   4371: 	    &Apache::lonmenu::loadevents().  $on_load;
                   4372: 	$attr_ref->{'onunload'}=
                   4373: 	    &Apache::lonmenu::unloadevents().$on_unload;
                   4374:     }
                   4375: 
                   4376: # Accessibility font enhance
                   4377:     if ($env{'browser.fontenhance'} eq 'on') {
                   4378: 	my $style;
                   4379: 	foreach my $key (keys(%{$attr_ref})) {
                   4380: 	    if (lc($key) eq 'style') {
                   4381: 		$style.=$attr_ref->{$key}.';';
                   4382: 		delete($attr_ref->{$key});
                   4383: 	    }
                   4384: 	}
                   4385: 	$attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330     albertel 4386:     }
1.339     albertel 4387: 
                   4388:     if ($env{'browser.blackwhite'} eq 'on') {
                   4389: 	delete($attr_ref->{'font'});
                   4390: 	delete($attr_ref->{'link'});
                   4391: 	delete($attr_ref->{'alink'});
                   4392: 	delete($attr_ref->{'vlink'});
                   4393: 	delete($attr_ref->{'bgcolor'});
                   4394: 	delete($attr_ref->{'background'});
                   4395:     }
                   4396: 
1.330     albertel 4397:     my $attr_string;
                   4398:     foreach my $attr (keys(%$attr_ref)) {
                   4399: 	$attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
                   4400:     }
                   4401:     return $attr_string;
                   4402: }
                   4403: 
                   4404: 
1.182     matthew  4405: ###############################################
1.251     albertel 4406: ###############################################
                   4407: 
                   4408: =pod
                   4409: 
                   4410: =item * &endbodytag()
                   4411: 
                   4412: Returns a uniform footer for LON-CAPA web pages.
                   4413: 
1.635     raeburn  4414: Inputs: 1 - optional reference to an args hash
                   4415: If in the hash, key for noredirectlink has a value which evaluates to true,
                   4416: a 'Continue' link is not displayed if the page contains an
                   4417: internal redirect in the <head></head> section,
                   4418: i.e., $env{'internal.head.redirect'} exists   
1.251     albertel 4419: 
                   4420: =cut
                   4421: 
                   4422: sub endbodytag {
1.635     raeburn  4423:     my ($args) = @_;
1.251     albertel 4424:     my $endbodytag='</body>';
1.269     albertel 4425:     $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315     albertel 4426:     if ( exists( $env{'internal.head.redirect'} ) ) {
1.635     raeburn  4427:         if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
                   4428: 	    $endbodytag=
                   4429: 	        "<br /><a href=\"$env{'internal.head.redirect'}\">".
                   4430: 	        &mt('Continue').'</a>'.
                   4431: 	        $endbodytag;
                   4432:         }
1.315     albertel 4433:     }
1.251     albertel 4434:     return $endbodytag;
                   4435: }
                   4436: 
1.352     albertel 4437: =pod
                   4438: 
                   4439: =item * &standard_css()
                   4440: 
                   4441: Returns a style sheet
                   4442: 
                   4443: Inputs: (all optional)
                   4444:             domain         -> force to color decorate a page for a specific
                   4445:                                domain
                   4446:             function       -> force usage of a specific rolish color scheme
                   4447:             bgcolor        -> override the default page bgcolor
                   4448: 
                   4449: =cut
                   4450: 
1.343     albertel 4451: sub standard_css {
1.345     albertel 4452:     my ($function,$domain,$bgcolor) = @_;
1.352     albertel 4453:     $function  = &get_users_function() if (!$function);
                   4454:     my $img    = &designparm($function.'.img',   $domain);
                   4455:     my $tabbg  = &designparm($function.'.tabbg', $domain);
                   4456:     my $font   = &designparm($function.'.font',  $domain);
1.345     albertel 4457:     my $sidebg = &designparm($function.'.sidebg',$domain);
1.382     albertel 4458:     my $pgbg_or_bgcolor =
                   4459: 	         $bgcolor ||
1.352     albertel 4460: 	         &designparm($function.'.pgbg',  $domain);
1.382     albertel 4461:     my $pgbg   = &designparm($function.'.pgbg',  $domain);
1.352     albertel 4462:     my $alink  = &designparm($function.'.alink', $domain);
                   4463:     my $vlink  = &designparm($function.'.vlink', $domain);
                   4464:     my $link   = &designparm($function.'.link',  $domain);
                   4465: 
1.704     muellerd 4466:     my $loginbg = &designparm('login.sidebg',$domain);
1.712     muellerd 4467:     my $bgcol = &designparm('login.bgcol',$domain);
                   4468:     my $textcol = &designparm('login.textcol',$domain);
1.704     muellerd 4469: 
1.602     albertel 4470:     my $sans                 = 'Verdana,Arial,Helvetica,sans-serif';
1.395     albertel 4471:     my $mono                 = 'monospace';
1.352     albertel 4472:     my $data_table_head      = $tabbg;
                   4473:     my $data_table_light     = '#EEEEEE';
1.470     banghart 4474:     my $data_table_dark      = '#DDDDDD';
                   4475:     my $data_table_darker    = '#CCCCCC';
1.349     albertel 4476:     my $data_table_highlight = '#FFFF00';
1.352     albertel 4477:     my $mail_new             = '#FFBB77';
                   4478:     my $mail_new_hover       = '#DD9955';
                   4479:     my $mail_read            = '#BBBB77';
                   4480:     my $mail_read_hover      = '#999944';
                   4481:     my $mail_replied         = '#AAAA88';
                   4482:     my $mail_replied_hover   = '#888855';
                   4483:     my $mail_other           = '#99BBBB';
                   4484:     my $mail_other_hover     = '#669999';
1.391     albertel 4485:     my $table_header         = '#DDDDDD';
1.489     raeburn  4486:     my $feedback_link_bg     = '#BBBBBB';
1.701     harmsja  4487:     my $lg_border_color	     = '#C8C8C8';
1.392     albertel 4488: 
1.608     albertel 4489:     my $border = ($env{'browser.type'} eq 'explorer' ||
                   4490: 		  $env{'browser.type'} eq 'safari'     ) ? '0px 2px 0px 2px'
                   4491: 	                                                 : '0px 3px 0px 4px';
1.448     albertel 4492: 
1.523     albertel 4493: 
1.343     albertel 4494:     return <<END;
1.698     harmsja  4495: body{
                   4496:      font-family: $sans;
                   4497:      line-height:130%;
1.701     harmsja  4498:      font-size:0.83em;
1.698     harmsja  4499:      color:$font;
                   4500:   }
1.701     harmsja  4501: a:link, a:visited { font-size:100%; }
1.698     harmsja  4502: 
1.343     albertel 4503: a:focus { color: red; background: yellow } 
1.510     albertel 4504: table.thinborder,
                   4505: table.thinborder tr th {
                   4506:   border-style: solid;
                   4507:   border-width: 1px;
1.698     harmsja  4508:   border-color: $lg_border_color;
1.510     albertel 4509:   background: $tabbg;
                   4510: }
1.523     albertel 4511: table.thinborder tr td {
1.510     albertel 4512:   border-style: solid;
1.698     harmsja  4513:   border-width: 1px;
                   4514:   border-color: $lg_border_color;
1.510     albertel 4515: }
1.426     albertel 4516: 
1.343     albertel 4517: form, .inline { display: inline; }
1.721     harmsja  4518: 
                   4519: .LC_center { text-align: center; }
                   4520: .LC_left { text-align:left; }
                   4521: .LC_right {text-align:right;}
                   4522: .LC_middle {vertical-align:middle;}
                   4523: .LC_top {vertical-align:top;}
                   4524: .LC_bottom {vertical-align:bottom;}
                   4525: 
                   4526: /* just for tests */
                   4527: .LC_300Box { width:300px; }
                   4528: .LC_200Box {width:200px; }
                   4529: .LC_500Box {width:500px; }
                   4530: .LC_600Box {width:600px; }
1.741     harmsja  4531: .LC_800Box {width:800px;}
1.721     harmsja  4532: /* end */
                   4533: 
1.593     albertel 4534: .LC_filename {font-family: $mono; white-space:pre;}
1.350     albertel 4535: .LC_error {
                   4536:   color: red;
                   4537:   font-size: larger;
                   4538: }
1.457     albertel 4539: .LC_warning,
                   4540: .LC_diff_removed {
1.733     bisitz   4541:   color: red;
1.394     albertel 4542: }
1.532     albertel 4543: 
                   4544: .LC_info,
1.457     albertel 4545: .LC_success,
                   4546: .LC_diff_added {
1.350     albertel 4547:   color: green;
                   4548: }
1.543     albertel 4549: .LC_unknown {
                   4550:   color: yellow;
                   4551: }
                   4552: 
1.440     albertel 4553: .LC_icon {
                   4554:   border: 0px;
                   4555: }
1.539     albertel 4556: .LC_indexer_icon {
                   4557:   border: 0px;
                   4558:   height: 22px;
                   4559: }
1.543     albertel 4560: .LC_docs_spacer {
                   4561:   width: 25px;
                   4562:   height: 1px;
                   4563:   border: 0px;
                   4564: }
1.346     albertel 4565: 
1.532     albertel 4566: .LC_internal_info {
1.735     bisitz   4567:   color: #999999;
1.532     albertel 4568: }
                   4569: 
1.458     albertel 4570: table.LC_pastsubmission {
                   4571:   border: 1px solid black;
                   4572:   margin: 2px;
                   4573: }
                   4574: 
1.606     albertel 4575: table#LC_top_nav, table#LC_menubuttons,table#LC_nav_location {
1.345     albertel 4576:   width: 100%;
                   4577:   background: $pgbg;
1.392     albertel 4578:   border: 2px;
1.402     albertel 4579:   border-collapse: separate;
1.403     albertel 4580:   padding: 0px;
1.345     albertel 4581: }
1.392     albertel 4582: 
1.606     albertel 4583: table#LC_title_bar, table.LC_breadcrumbs, 
1.393     albertel 4584: table#LC_title_bar.LC_with_remote {
1.359     albertel 4585:   width: 100%;
1.392     albertel 4586:   border-color: $pgbg;
                   4587:   border-style: solid;
                   4588:   border-width: $border;
                   4589: 
1.379     albertel 4590:   background: $pgbg;
                   4591:   font-family: $sans;
1.392     albertel 4592:   border-collapse: collapse;
1.403     albertel 4593:   padding: 0px;
1.359     albertel 4594: }
1.409     albertel 4595: table.LC_docs_path {
                   4596:   width: 100%;
                   4597:   border: 0;
                   4598:   background: $pgbg;
                   4599:   font-family: $sans;
                   4600:   border-collapse: collapse;
                   4601:   padding: 0px;
                   4602: }
                   4603: 
1.359     albertel 4604: table#LC_title_bar td {
                   4605:   background: $tabbg;
                   4606: }
                   4607: table#LC_title_bar td.LC_title_bar_who {
                   4608:   background: $tabbg;
                   4609:   color: $font;
1.427     albertel 4610:   font: small $sans;
1.359     albertel 4611:   text-align: right;
                   4612: }
1.469     banghart 4613: span.LC_metadata {
                   4614:     font-family: $sans;
                   4615: }
1.359     albertel 4616: span.LC_title_bar_title {
1.416     albertel 4617:   font: bold x-large $sans;
1.359     albertel 4618: }
                   4619: table#LC_title_bar td.LC_title_bar_domain_logo {
                   4620:   background: $sidebg;
                   4621:   text-align: right;
1.368     albertel 4622:   padding: 0px;
                   4623: }
                   4624: table#LC_title_bar td.LC_title_bar_role_logo {
                   4625:   background: $sidebg;
                   4626:   padding: 0px;
1.359     albertel 4627: }
                   4628: 
1.706     harmsja  4629: table#LC_menubuttons img{
1.346     albertel 4630:   border: 0px;
                   4631: }
1.345     albertel 4632: table#LC_top_nav td {
                   4633:   background: $tabbg;
1.392     albertel 4634:   border: 0px;
1.407     albertel 4635:   font-size: small;
1.706     harmsja  4636:   vertical-align:top;
                   4637:   padding:2px 5px 2px 5px;
1.345     albertel 4638: }
                   4639: table#LC_top_nav td a, div#LC_top_nav a {
                   4640:   color: $font;
                   4641:   font-family: $sans;
                   4642: }
1.364     albertel 4643: table#LC_top_nav td.LC_top_nav_logo {
                   4644:   background: $tabbg;
1.432     albertel 4645:   text-align: left;
1.408     albertel 4646:   white-space: nowrap;
1.432     albertel 4647:   width: 31px;
1.408     albertel 4648: }
                   4649: table#LC_top_nav td.LC_top_nav_logo img {
1.432     albertel 4650:   border: 0px;
1.408     albertel 4651:   vertical-align: bottom;
1.364     albertel 4652: }
1.432     albertel 4653: table#LC_top_nav td.LC_top_nav_exit,
                   4654: table#LC_top_nav td.LC_top_nav_help {
                   4655:   width: 2.0em;
                   4656: }
1.442     albertel 4657: table#LC_top_nav td.LC_top_nav_login {
                   4658:   width: 4.0em;
                   4659:   text-align: center;
                   4660: }
1.409     albertel 4661: table.LC_breadcrumbs td, table.LC_docs_path td  {
1.357     albertel 4662:   background: $tabbg;
                   4663:   color: $font;
                   4664:   font-family: $sans;
1.358     albertel 4665:   font-size: smaller;
1.357     albertel 4666: }
1.411     albertel 4667: table.LC_breadcrumbs td.LC_breadcrumbs_component,
1.409     albertel 4668: table.LC_docs_path td.LC_docs_path_component {
1.357     albertel 4669:   background: $tabbg;
                   4670:   color: $font;
                   4671:   font-family: $sans;
                   4672:   font-size: larger;
                   4673:   text-align: right;
                   4674: }
1.383     albertel 4675: td.LC_table_cell_checkbox {
                   4676:   text-align: center;
                   4677: }
1.522     albertel 4678: table#LC_mainmenu td.LC_mainmenu_column {
                   4679:     vertical-align: top;
                   4680: }
                   4681: 
1.705     tempelho 4682: .LC_fontsize_small
                   4683: {
                   4684:  font-size: 70%;
                   4685: }
                   4686: 
                   4687: .LC_fontsize_medium
                   4688: {
                   4689:  font-size: 85%;
                   4690: }
                   4691: 
                   4692: .LC_fontsize_large
                   4693: {
                   4694:  font-size: 120%;
                   4695: }
                   4696: 
                   4697: .LC_fontcolor_red
                   4698: {
                   4699:  color: #FF0000;
                   4700: }
                   4701: 
1.346     albertel 4702: .LC_menubuttons_inline_text {
                   4703:   color: $font;
                   4704:   font-family: $sans;
1.698     harmsja  4705:   font-size: 90%;
1.701     harmsja  4706:   padding-left:3px;
1.346     albertel 4707: }
                   4708: 
1.526     www      4709: .LC_menubuttons_link {
                   4710:   text-decoration: none;
                   4711: }
1.698     harmsja  4712: /*2008--9-5: new menu style sheet.Changed category*/
1.522     albertel 4713: .LC_menubuttons_category {
1.521     www      4714:   color: $font;
1.526     www      4715:   background: $pgbg;
1.521     www      4716:   font-family: $sans;
                   4717:   font-size: larger;
                   4718:   font-weight: bold;
                   4719: }
                   4720: 
1.346     albertel 4721: td.LC_menubuttons_text {
1.701     harmsja  4722:  	color: $font; 	
1.346     albertel 4723: }
1.706     harmsja  4724: 
                   4725: 
1.526     www      4726: 
1.346     albertel 4727: .LC_current_location {
                   4728:   font-family: $sans;
                   4729:   background: $tabbg;
                   4730: }
                   4731: .LC_new_mail {
                   4732:   font-family: $sans;
1.634     www      4733:   background: $tabbg;
1.346     albertel 4734:   font-weight: bold;
                   4735: }
1.347     albertel 4736: 
1.526     www      4737: 
1.527     www      4738: .LC_dropadd_labeltext {
                   4739:   font-family: $sans;
                   4740:   text-align: right;
                   4741: }
                   4742: 
                   4743: .LC_preferences_labeltext {
                   4744:   font-family: $sans;
                   4745:   text-align: right;
                   4746: }
                   4747: 
1.666     raeburn  4748: .LC_roleslog_note {
1.701     harmsja  4749:   font-size: small;
1.666     raeburn  4750: }
                   4751: 
1.715     raeburn  4752: .LC_mail_functions {
                   4753:     font-weight: bold;
                   4754: }
                   4755: 
1.440     albertel 4756: table.LC_aboutme_port {
                   4757:   border: 0px;
                   4758:   border-collapse: collapse;
                   4759:   border-spacing: 0px;
                   4760: }
1.349     albertel 4761: table.LC_data_table, table.LC_mail_list {
1.347     albertel 4762:   border: 1px solid #000000;
1.402     albertel 4763:   border-collapse: separate;
1.426     albertel 4764:   border-spacing: 1px;
1.610     albertel 4765:   background: $pgbg;
1.347     albertel 4766: }
1.422     albertel 4767: .LC_data_table_dense {
                   4768:   font-size: small;
                   4769: }
1.507     raeburn  4770: table.LC_nested_outer {
                   4771:   border: 1px solid #000000;
1.589     raeburn  4772:   border-collapse: collapse;
1.507     raeburn  4773:   border-spacing: 0px;
                   4774:   width: 100%;
                   4775: }
                   4776: table.LC_nested {
                   4777:   border: 0px;
1.589     raeburn  4778:   border-collapse: collapse;
1.507     raeburn  4779:   border-spacing: 0px;
                   4780:   width: 100%;
                   4781: }
1.523     albertel 4782: table.LC_data_table tr th, table.LC_calendar tr th, table.LC_mail_list tr th,
                   4783: table.LC_prior_tries tr th {
1.349     albertel 4784:   font-weight: bold;
                   4785:   background-color: $data_table_head;
1.701     harmsja  4786:   font-size:90%;
1.347     albertel 4787: }
1.711     raeburn  4788: table.LC_data_table tr.LC_info_row > td {
1.735     bisitz   4789:   background-color: #CCCCCC;
1.711     raeburn  4790:   font-weight: bold;
                   4791:   text-align: left;
                   4792: }
1.610     albertel 4793: table.LC_data_table tr.LC_odd_row > td, 
1.709     bisitz   4794: table.LC_pick_box tr > td.LC_odd_row,
1.440     albertel 4795: table.LC_aboutme_port tr td {
1.349     albertel 4796:   background-color: $data_table_light;
1.425     albertel 4797:   padding: 2px;
1.347     albertel 4798: }
1.610     albertel 4799: table.LC_data_table tr.LC_even_row > td,
1.709     bisitz   4800: table.LC_pick_box tr > td.LC_even_row,
1.440     albertel 4801: table.LC_aboutme_port tr.LC_even_row td {
1.349     albertel 4802:   background-color: $data_table_dark;
1.709     bisitz   4803:   padding: 2px;
1.347     albertel 4804: }
1.425     albertel 4805: table.LC_data_table tr.LC_data_table_highlight td {
                   4806:   background-color: $data_table_darker;
                   4807: }
1.639     raeburn  4808: table.LC_data_table tr td.LC_leftcol_header {
                   4809:   background-color: $data_table_head;
                   4810:   font-weight: bold;
                   4811: }
1.451     albertel 4812: table.LC_data_table tr.LC_empty_row td,
1.507     raeburn  4813: table.LC_nested tr.LC_empty_row td {
1.347     albertel 4814:   background-color: #FFFFFF;
1.421     albertel 4815:   font-weight: bold;
                   4816:   font-style: italic;
                   4817:   text-align: center;
                   4818:   padding: 8px;
1.347     albertel 4819: }
1.507     raeburn  4820: table.LC_nested tr.LC_empty_row td {
1.465     albertel 4821:   padding: 4ex
                   4822: }
1.507     raeburn  4823: table.LC_nested_outer tr th {
                   4824:   font-weight: bold;
                   4825:   background-color: $data_table_head;
1.701     harmsja  4826:   font-size: small;
1.507     raeburn  4827:   border-bottom: 1px solid #000000;
                   4828: }
                   4829: table.LC_nested_outer tr td.LC_subheader {
                   4830:   background-color: $data_table_head;
                   4831:   font-weight: bold;
                   4832:   font-size: small;
                   4833:   border-bottom: 1px solid #000000;
                   4834:   text-align: right;
1.451     albertel 4835: }
1.507     raeburn  4836: table.LC_nested tr.LC_info_row td {
1.735     bisitz   4837:   background-color: #CCCCCC;
1.451     albertel 4838:   font-weight: bold;
                   4839:   font-size: small;
1.507     raeburn  4840:   text-align: center;
                   4841: }
1.589     raeburn  4842: table.LC_nested tr.LC_info_row td.LC_left_item,
                   4843: table.LC_nested_outer tr th.LC_left_item {
1.507     raeburn  4844:   text-align: left;
1.451     albertel 4845: }
1.507     raeburn  4846: table.LC_nested td {
1.735     bisitz   4847:   background-color: #FFFFFF;
1.451     albertel 4848:   font-size: small;
1.507     raeburn  4849: }
                   4850: table.LC_nested_outer tr th.LC_right_item,
                   4851: table.LC_nested tr.LC_info_row td.LC_right_item,
                   4852: table.LC_nested tr.LC_odd_row td.LC_right_item,
                   4853: table.LC_nested tr td.LC_right_item {
1.451     albertel 4854:   text-align: right;
                   4855: }
                   4856: 
1.507     raeburn  4857: table.LC_nested tr.LC_odd_row td {
1.735     bisitz   4858:   background-color: #EEEEEE;
1.451     albertel 4859: }
                   4860: 
1.473     raeburn  4861: table.LC_createuser {
                   4862: }
                   4863: 
                   4864: table.LC_createuser tr.LC_section_row td {
1.701     harmsja  4865:   font-size: small;
1.473     raeburn  4866: }
                   4867: 
                   4868: table.LC_createuser tr.LC_info_row td  {
1.735     bisitz   4869:   background-color: #CCCCCC;
1.473     raeburn  4870:   font-weight: bold;
                   4871:   text-align: center;
                   4872: }
                   4873: 
1.349     albertel 4874: table.LC_calendar {
                   4875:   border: 1px solid #000000;
                   4876:   border-collapse: collapse;
                   4877: }
                   4878: table.LC_calendar_pickdate {
                   4879:   font-size: xx-small;
                   4880: }
                   4881: table.LC_calendar tr td {
                   4882:   border: 1px solid #000000;
                   4883:   vertical-align: top;
                   4884: }
                   4885: table.LC_calendar tr td.LC_calendar_day_empty {
                   4886:   background-color: $data_table_dark;
                   4887: }
                   4888: table.LC_calendar tr td.LC_calendar_day_current {
                   4889:   background-color: $data_table_highlight;
                   4890: }
                   4891: 
                   4892: table.LC_mail_list tr.LC_mail_new {
                   4893:   background-color: $mail_new;
                   4894: }
                   4895: table.LC_mail_list tr.LC_mail_new:hover {
                   4896:   background-color: $mail_new_hover;
                   4897: }
                   4898: table.LC_mail_list tr.LC_mail_read {
                   4899:   background-color: $mail_read;
                   4900: }
                   4901: table.LC_mail_list tr.LC_mail_read:hover {
                   4902:   background-color: $mail_read_hover;
                   4903: }
                   4904: table.LC_mail_list tr.LC_mail_replied {
                   4905:   background-color: $mail_replied;
                   4906: }
                   4907: table.LC_mail_list tr.LC_mail_replied:hover {
                   4908:   background-color: $mail_replied_hover;
                   4909: }
                   4910: table.LC_mail_list tr.LC_mail_other {
                   4911:   background-color: $mail_other;
                   4912: }
                   4913: table.LC_mail_list tr.LC_mail_other:hover {
                   4914:   background-color: $mail_other_hover;
                   4915: }
1.494     raeburn  4916: table.LC_mail_list tr.LC_mail_even {
                   4917: }
                   4918: table.LC_mail_list tr.LC_mail_odd {
                   4919: }
                   4920: 
1.696     bisitz   4921: table.LC_data_table tr > td.LC_browser_file,
                   4922: table.LC_data_table tr > td.LC_browser_file_published {
1.389     albertel 4923:   background: #CCFF88;
                   4924: }
1.696     bisitz   4925: table.LC_data_table tr > td.LC_browser_file_locked,
                   4926: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389     albertel 4927:   background: #FFAA99;
1.387     albertel 4928: }
1.696     bisitz   4929: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.389     albertel 4930:   background: #AAAAAA;
1.387     albertel 4931: }
1.696     bisitz   4932: table.LC_data_table tr > td.LC_browser_file_modified,
                   4933: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.389     albertel 4934:   background: #FFFF77;
1.387     albertel 4935: }
1.696     bisitz   4936: table.LC_data_table tr.LC_browser_folder > td {
1.389     albertel 4937:   background: #CCCCFF;
1.387     albertel 4938: }
1.696     bisitz   4939: 
1.707     bisitz   4940: table.LC_data_table tr > td.LC_roles_is {
                   4941: /*  background: #77FF77; */
                   4942: }
                   4943: table.LC_data_table tr > td.LC_roles_future {
                   4944:   background: #FFFF77;
                   4945: }
                   4946: table.LC_data_table tr > td.LC_roles_will {
                   4947:   background: #FFAA77;
                   4948: }
                   4949: table.LC_data_table tr > td.LC_roles_expired {
                   4950:   background: #FF7777;
                   4951: }
                   4952: table.LC_data_table tr > td.LC_roles_will_not {
                   4953:   background: #AAFF77;
                   4954: }
                   4955: table.LC_data_table tr > td.LC_roles_selected {
                   4956:   background: #11CC55;
                   4957: }
                   4958: 
1.388     albertel 4959: span.LC_current_location {
1.701     harmsja  4960:   font-size:larger;
1.388     albertel 4961:   background: $pgbg;
                   4962: }
1.387     albertel 4963: 
1.395     albertel 4964: span.LC_parm_menu_item {
                   4965:   font-size: larger;
                   4966:   font-family: $sans;
                   4967: }
                   4968: span.LC_parm_scope_all {
                   4969:   color: red;
                   4970: }
                   4971: span.LC_parm_scope_folder {
                   4972:   color: green;
                   4973: }
                   4974: span.LC_parm_scope_resource {
                   4975:   color: orange;
                   4976: }
                   4977: span.LC_parm_part {
                   4978:   color: blue;
                   4979: }
                   4980: span.LC_parm_folder, span.LC_parm_symb {
                   4981:   font-size: x-small;
                   4982:   font-family: $mono;
                   4983:   color: #AAAAAA;
                   4984: }
                   4985: 
1.396     albertel 4986: td.LC_parm_overview_level_menu, td.LC_parm_overview_map_menu,
                   4987: td.LC_parm_overview_parm_selectors, td.LC_parm_overview_parm_restrictions {
                   4988:   border: 1px solid black;
                   4989:   border-collapse: collapse;
                   4990: }
                   4991: table.LC_parm_overview_restrictions td {
                   4992:   border-width: 1px 4px 1px 4px;
                   4993:   border-style: solid;
                   4994:   border-color: $pgbg;
                   4995:   text-align: center;
                   4996: }
                   4997: table.LC_parm_overview_restrictions th {
                   4998:   background: $tabbg;
                   4999:   border-width: 1px 4px 1px 4px;
                   5000:   border-style: solid;
                   5001:   border-color: $pgbg;
                   5002: }
1.398     albertel 5003: table#LC_helpmenu {
                   5004:   border: 0px;
                   5005:   height: 55px;
                   5006:   border-spacing: 0px;
                   5007: }
                   5008: 
                   5009: table#LC_helpmenu fieldset legend {
                   5010:   font-size: larger;
                   5011:   font-weight: bold;
                   5012: }
1.397     albertel 5013: table#LC_helpmenu_links {
                   5014:   width: 100%;
                   5015:   border: 1px solid black;
                   5016:   background: $pgbg;
                   5017:   padding: 0px;
                   5018:   border-spacing: 1px;
                   5019: }
                   5020: table#LC_helpmenu_links tr td {
                   5021:   padding: 1px;
                   5022:   background: $tabbg;
1.399     albertel 5023:   text-align: center;
                   5024:   font-weight: bold;
1.397     albertel 5025: }
1.396     albertel 5026: 
1.397     albertel 5027: table#LC_helpmenu_links a:link, table#LC_helpmenu_links a:visited,
                   5028: table#LC_helpmenu_links a:active {
                   5029:   text-decoration: none;
                   5030:   color: $font;
                   5031: }
                   5032: table#LC_helpmenu_links a:hover {
                   5033:   text-decoration: underline;
                   5034:   color: $vlink;
                   5035: }
1.396     albertel 5036: 
1.417     albertel 5037: .LC_chrt_popup_exists {
                   5038:   border: 1px solid #339933;
                   5039:   margin: -1px;
                   5040: }
                   5041: .LC_chrt_popup_up {
                   5042:   border: 1px solid yellow;
                   5043:   margin: -1px;
                   5044: }
                   5045: .LC_chrt_popup {
                   5046:   border: 1px solid #8888FF;
                   5047:   background: #CCCCFF;
                   5048: }
1.421     albertel 5049: table.LC_pick_box {
                   5050:   border-collapse: separate;
                   5051:   background: white;
                   5052:   border: 1px solid black;
                   5053:   border-spacing: 1px;
                   5054: }
                   5055: table.LC_pick_box td.LC_pick_box_title {
                   5056:   background: $tabbg;
                   5057:   font-weight: bold;
                   5058:   text-align: right;
1.740     bisitz   5059:   vertical-align: top;
1.421     albertel 5060:   width: 184px;
                   5061:   padding: 8px;
                   5062: }
1.645     raeburn  5063: table.LC_pick_box td.LC_selfenroll_pick_box_title {
                   5064:   background: $tabbg;
                   5065:   font-weight: bold;
                   5066:   text-align: right;
                   5067:   width: 350px;
                   5068:   padding: 8px;
                   5069: }
                   5070: 
1.579     raeburn  5071: table.LC_pick_box td.LC_pick_box_value {
                   5072:   text-align: left;
                   5073:   padding: 8px;
                   5074: }
                   5075: table.LC_pick_box td.LC_pick_box_select {
                   5076:   text-align: left;
                   5077:   padding: 8px;
                   5078: }
1.424     albertel 5079: table.LC_pick_box td.LC_pick_box_separator {
1.421     albertel 5080:   padding: 0px;
                   5081:   height: 1px;
                   5082:   background: black;
                   5083: }
                   5084: table.LC_pick_box td.LC_pick_box_submit {
                   5085:   text-align: right;
                   5086: }
1.579     raeburn  5087: table.LC_pick_box td.LC_evenrow_value {
                   5088:   text-align: left;
                   5089:   padding: 8px;
                   5090:   background-color: $data_table_light;
                   5091: }
                   5092: table.LC_pick_box td.LC_oddrow_value {
                   5093:   text-align: left;
                   5094:   padding: 8px;
                   5095:   background-color: $data_table_light;
                   5096: }
                   5097: table.LC_helpform_receipt {
                   5098:   width: 620px;
                   5099:   border-collapse: separate;
                   5100:   background: white;
                   5101:   border: 1px solid black;
                   5102:   border-spacing: 1px;
                   5103: }
                   5104: table.LC_helpform_receipt td.LC_pick_box_title {
                   5105:   background: $tabbg;
                   5106:   font-weight: bold;
                   5107:   text-align: right;
                   5108:   width: 184px;
                   5109:   padding: 8px;
                   5110: }
                   5111: table.LC_helpform_receipt td.LC_evenrow_value {
                   5112:   text-align: left;
                   5113:   padding: 8px;
                   5114:   background-color: $data_table_light;
                   5115: }
                   5116: table.LC_helpform_receipt td.LC_oddrow_value {
                   5117:   text-align: left;
                   5118:   padding: 8px;
                   5119:   background-color: $data_table_light;
                   5120: }
                   5121: table.LC_helpform_receipt td.LC_pick_box_separator {
                   5122:   padding: 0px;
                   5123:   height: 1px;
                   5124:   background: black;
                   5125: }
                   5126: span.LC_helpform_receipt_cat {
                   5127:   font-weight: bold;
                   5128: }
1.424     albertel 5129: table.LC_group_priv_box {
                   5130:   background: white;
                   5131:   border: 1px solid black;
                   5132:   border-spacing: 1px;
                   5133: }
                   5134: table.LC_group_priv_box td.LC_pick_box_title {
                   5135:   background: $tabbg;
                   5136:   font-weight: bold;
                   5137:   text-align: right;
                   5138:   width: 184px;
                   5139: }
                   5140: table.LC_group_priv_box td.LC_groups_fixed {
                   5141:   background: $data_table_light;
                   5142:   text-align: center;
                   5143: }
                   5144: table.LC_group_priv_box td.LC_groups_optional {
                   5145:   background: $data_table_dark;
                   5146:   text-align: center;
                   5147: }
                   5148: table.LC_group_priv_box td.LC_groups_functionality {
                   5149:   background: $data_table_darker;
                   5150:   text-align: center;
                   5151:   font-weight: bold;
                   5152: }
                   5153: table.LC_group_priv td {
                   5154:   text-align: left;
                   5155:   padding: 0px;
                   5156: }
                   5157: 
1.421     albertel 5158: table.LC_notify_front_page {
                   5159:   background: white;
                   5160:   border: 1px solid black;
                   5161:   padding: 8px;
                   5162: }
                   5163: table.LC_notify_front_page td {
                   5164:   padding: 8px;
                   5165: }
1.424     albertel 5166: .LC_navbuttons {
                   5167:   margin: 2ex 0ex 2ex 0ex;
                   5168: }
1.423     albertel 5169: .LC_topic_bar {
                   5170:   font-family: $sans;
                   5171:   font-weight: bold;
                   5172:   width: 100%;
                   5173:   background: $tabbg;
                   5174:   vertical-align: middle;
                   5175:   margin: 2ex 0ex 2ex 0ex;
                   5176: }
                   5177: .LC_topic_bar span {
                   5178:   vertical-align: middle;
                   5179: }
                   5180: .LC_topic_bar img {
                   5181:   vertical-align: bottom;
                   5182: }
                   5183: table.LC_course_group_status {
                   5184:   margin: 20px;
                   5185: }
                   5186: table.LC_status_selector td {
                   5187:   vertical-align: top;
                   5188:   text-align: center;
1.424     albertel 5189:   padding: 4px;
                   5190: }
                   5191: table.LC_descriptive_input td.LC_description {
                   5192:   vertical-align: top;
                   5193:   text-align: right;
                   5194:   font-weight: bold;
1.423     albertel 5195: }
1.599     albertel 5196: div.LC_feedback_link {
1.616     albertel 5197:   clear: both;
1.599     albertel 5198:   background: white;
                   5199:   width: 100%;  
1.489     raeburn  5200: }
                   5201: span.LC_feedback_link {
1.599     albertel 5202:   background: $feedback_link_bg;
                   5203:   font-size: larger;
                   5204: }
                   5205: span.LC_message_link {
                   5206:   background: $feedback_link_bg;
                   5207:   font-size: larger;
                   5208:   position: absolute;
                   5209:   right: 1em;
1.489     raeburn  5210: }
1.421     albertel 5211: 
1.515     albertel 5212: table.LC_prior_tries {
1.524     albertel 5213:   border: 1px solid #000000;
                   5214:   border-collapse: separate;
                   5215:   border-spacing: 1px;
1.515     albertel 5216: }
1.523     albertel 5217: 
1.515     albertel 5218: table.LC_prior_tries td {
1.524     albertel 5219:   padding: 2px;
1.515     albertel 5220: }
1.523     albertel 5221: 
                   5222: .LC_answer_correct {
                   5223:   background: #AAFFAA;
                   5224:   color: black;
                   5225: }
                   5226: .LC_answer_charged_try {
                   5227:   background: #FFAAAA ! important;
                   5228:   color: black;
                   5229: }
                   5230: .LC_answer_not_charged_try, 
                   5231: .LC_answer_no_grade,
                   5232: .LC_answer_late {
                   5233:   background: #FFFFAA;
                   5234:   color: black;
                   5235: }
                   5236: .LC_answer_previous {
                   5237:   background: #AAAAFF;
                   5238:   color: black;
                   5239: }
                   5240: .LC_answer_no_message {
                   5241:   background: #FFFFFF;
                   5242:   color: black;
                   5243: }
                   5244: .LC_answer_unknown {
                   5245:   background: orange;
                   5246:   color: black;
                   5247: }
                   5248: 
                   5249: 
1.529     albertel 5250: span.LC_prior_numerical,
                   5251: span.LC_prior_string,
                   5252: span.LC_prior_custom,
                   5253: span.LC_prior_reaction,
                   5254: span.LC_prior_math {
1.523     albertel 5255:   font-family: monospace;
                   5256:   white-space: pre;
                   5257: }
                   5258: 
1.525     albertel 5259: span.LC_prior_string {
                   5260:   font-family: monospace;
                   5261:   white-space: pre;
                   5262: }
                   5263: 
1.523     albertel 5264: table.LC_prior_option {
                   5265:   width: 100%;
                   5266:   border-collapse: collapse;
                   5267: }
1.528     albertel 5268: table.LC_prior_rank, table.LC_prior_match {
                   5269:   border-collapse: collapse;
                   5270: }
                   5271: table.LC_prior_option tr td,
                   5272: table.LC_prior_rank tr td,
                   5273: table.LC_prior_match tr td {
1.524     albertel 5274:   border: 1px solid #000000;
1.515     albertel 5275: }
                   5276: 
1.519     raeburn  5277: span.LC_nobreak {
1.544     albertel 5278:   white-space: nowrap;
1.519     raeburn  5279: }
                   5280: 
1.576     raeburn  5281: span.LC_cusr_emph {
                   5282:   font-style: italic;
                   5283: }
                   5284: 
1.633     raeburn  5285: span.LC_cusr_subheading {
                   5286:   font-weight: normal;
                   5287:   font-size: 85%;
                   5288: }
                   5289: 
1.545     albertel 5290: table.LC_docs_documents {
                   5291:   background: #BBBBBB;
1.547     albertel 5292:   border-width: 0px;
1.545     albertel 5293:   border-collapse: collapse;
                   5294: }
                   5295: 
                   5296: table.LC_docs_documents td.LC_docs_document {
                   5297:   border: 2px solid black;
                   5298:   padding: 4px;
                   5299: }
                   5300: 
                   5301: .LC_docs_entry_move {
                   5302:   border: 0px;
                   5303:   border-collapse: collapse;
1.544     albertel 5304: }
                   5305: 
1.545     albertel 5306: .LC_docs_entry_move td {
                   5307:   border: 2px solid #BBBBBB;
                   5308:   background: #DDDDDD;
                   5309: }
                   5310: 
                   5311: .LC_docs_editor td.LC_docs_entry_commands {
                   5312:   background: #DDDDDD;
                   5313:   font-size: x-small;
                   5314: }
1.544     albertel 5315: .LC_docs_copy {
1.545     albertel 5316:   color: #000099;
1.544     albertel 5317: }
                   5318: .LC_docs_cut {
1.545     albertel 5319:   color: #550044;
1.544     albertel 5320: }
                   5321: .LC_docs_rename {
1.545     albertel 5322:   color: #009900;
1.544     albertel 5323: }
                   5324: .LC_docs_remove {
1.545     albertel 5325:   color: #990000;
                   5326: }
                   5327: 
1.547     albertel 5328: .LC_docs_reinit_warn,
                   5329: .LC_docs_ext_edit {
                   5330:   font-size: x-small;
                   5331: }
                   5332: 
1.545     albertel 5333: .LC_docs_editor td.LC_docs_entry_title,
                   5334: .LC_docs_editor td.LC_docs_entry_icon {
                   5335:   background: #FFFFBB;
                   5336: }
                   5337: .LC_docs_editor td.LC_docs_entry_parameter {
                   5338:   background: #BBBBFF;
                   5339:   font-size: x-small;
                   5340:   white-space: nowrap;
                   5341: }
                   5342: 
                   5343: table.LC_docs_adddocs td,
                   5344: table.LC_docs_adddocs th {
                   5345:   border: 1px solid #BBBBBB;
                   5346:   padding: 4px;
                   5347:   background: #DDDDDD;
1.543     albertel 5348: }
                   5349: 
1.584     albertel 5350: table.LC_sty_begin {
                   5351:   background: #BBFFBB;
                   5352: }
                   5353: table.LC_sty_end {
                   5354:   background: #FFBBBB;
                   5355: }
                   5356: 
1.589     raeburn  5357: table.LC_double_column {
                   5358:   border-width: 0px;
                   5359:   border-collapse: collapse;
                   5360:   width: 100%;
                   5361:   padding: 2px;
                   5362: }
                   5363: 
                   5364: table.LC_double_column tr td.LC_left_col {
1.590     raeburn  5365:   top: 2px;
1.589     raeburn  5366:   left: 2px;
                   5367:   width: 47%;
                   5368:   vertical-align: top;
                   5369: }
                   5370: 
                   5371: table.LC_double_column tr td.LC_right_col {
                   5372:   top: 2px;
                   5373:   right: 2px; 
                   5374:   width: 47%;
                   5375:   vertical-align: top;
                   5376: }
                   5377: 
1.594     raeburn  5378: span.LC_role_level {
                   5379:   font-weight: bold;
                   5380: }
                   5381: 
1.591     raeburn  5382: div.LC_left_float {
                   5383:   float: left;
                   5384:   padding-right: 5%;
1.597     albertel 5385:   padding-bottom: 4px;
1.591     raeburn  5386: }
                   5387: 
                   5388: div.LC_clear_float_header {
1.597     albertel 5389:   padding-bottom: 2px;
1.591     raeburn  5390: }
                   5391: 
                   5392: div.LC_clear_float_footer {
1.597     albertel 5393:   padding-top: 10px;
1.591     raeburn  5394:   clear: both;
                   5395: }
                   5396: 
1.597     albertel 5397: 
                   5398: div.LC_grade_show_user {
                   5399:   margin-top: 20px;
                   5400:   border: 1px solid black;
                   5401: }
                   5402: div.LC_grade_user_name {
                   5403:   background: #DDDDEE;
                   5404:   border-bottom: 1px solid black;
1.705     tempelho 5405:   font-weight: bold;
                   5406:   font-size: large;
1.597     albertel 5407: }
                   5408: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
                   5409:   background: #DDEEDD;
                   5410: }
                   5411: 
                   5412: div.LC_grade_show_problem,
                   5413: div.LC_grade_submissions,
                   5414: div.LC_grade_message_center,
                   5415: div.LC_grade_info_links,
                   5416: div.LC_grade_assign {
                   5417:   margin: 5px;
                   5418:   width: 99%;
                   5419:   background: #FFFFFF;
                   5420: }
                   5421: div.LC_grade_show_problem_header,
                   5422: div.LC_grade_submissions_header,
                   5423: div.LC_grade_message_center_header,
                   5424: div.LC_grade_assign_header {
1.705     tempelho 5425:   font-weight: bold;
                   5426:   font-size: large;
1.597     albertel 5427: }
                   5428: div.LC_grade_show_problem_problem,
                   5429: div.LC_grade_submissions_body,
                   5430: div.LC_grade_message_center_body,
                   5431: div.LC_grade_assign_body {
                   5432:   border: 1px solid black;
                   5433:   width: 99%;
                   5434:   background: #FFFFFF;
                   5435: }
1.598     albertel 5436: span.LC_grade_check_note {
1.705     tempelho 5437:   font-weight: normal;
                   5438:   font-size: medium;
1.598     albertel 5439:   display: inline;
                   5440:   position: absolute;
                   5441:   right: 1em;
                   5442: }
1.597     albertel 5443: 
1.613     albertel 5444: table.LC_scantron_action {
                   5445:   width: 100%;
                   5446: }
                   5447: table.LC_scantron_action tr th {
1.698     harmsja  5448:   font-weight:bold;
                   5449:   font-style:normal;
1.613     albertel 5450: }
1.698     harmsja  5451: .LC_edit_problem_header, 
1.614     albertel 5452: div.LC_edit_problem_footer {
1.705     tempelho 5453:   font-weight: normal;
                   5454:   font-size:  medium;
1.602     albertel 5455:   margin: 2px;
1.600     albertel 5456: }
                   5457: div.LC_edit_problem_header,
1.602     albertel 5458: div.LC_edit_problem_header div,
1.614     albertel 5459: div.LC_edit_problem_footer,
                   5460: div.LC_edit_problem_footer div,
1.602     albertel 5461: div.LC_edit_problem_editxml_header,
                   5462: div.LC_edit_problem_editxml_header div {
1.600     albertel 5463:   margin-top: 5px;
                   5464: }
1.602     albertel 5465: div.LC_edit_problem_header_edit_row {
                   5466:   background: $tabbg;
                   5467:   padding: 3px;
                   5468:   margin-bottom: 5px;
                   5469: }
1.600     albertel 5470: div.LC_edit_problem_header_title {
1.705     tempelho 5471:   font-weight: bold;
                   5472:   font-size: larger;
1.602     albertel 5473:   background: $tabbg;
                   5474:   padding: 3px;
                   5475: }
                   5476: table.LC_edit_problem_header_title {
1.705     tempelho 5477:   font-size: larger;
                   5478:   font-weight:  bold;
1.602     albertel 5479:   width: 100%;
                   5480:   border-color: $pgbg;
                   5481:   border-style: solid;
                   5482:   border-width: $border;
                   5483: 
1.600     albertel 5484:   background: $tabbg;
1.602     albertel 5485:   border-collapse: collapse;
                   5486:   padding: 0px
                   5487: }
                   5488: 
                   5489: div.LC_edit_problem_discards {
                   5490:   float: left;
                   5491:   padding-bottom: 5px;
                   5492: }
                   5493: div.LC_edit_problem_saves {
                   5494:   float: right;
                   5495:   padding-bottom: 5px;
1.600     albertel 5496: }
                   5497: hr.LC_edit_problem_divide {
1.602     albertel 5498:   clear: both;
1.600     albertel 5499:   color: $tabbg;
                   5500:   background-color: $tabbg;
                   5501:   height: 3px;
                   5502:   border: 0px;
                   5503: }
1.679     riegler  5504: img.stift{
1.678     riegler  5505:   border-width:0;
1.679     riegler  5506:   vertical-align:middle;
1.677     riegler  5507: }
1.680     riegler  5508: 
1.681     riegler  5509: table#LC_mainmenu{
                   5510:  margin-top:10px;
                   5511:  width:80%;
                   5512: 
                   5513: }
                   5514: 
1.680     riegler  5515: table#LC_mainmenu td.LC_mainmenu_col_fieldset{
                   5516:   vertical-align: top;
                   5517:   width: 45%;
                   5518: }
                   5519: .LC_mainmenu_fieldset_category {
                   5520:   color: $font;
                   5521:   background: $pgbg;
                   5522:   font-family: $sans;
                   5523:   font-size: small;
                   5524:   font-weight: bold;
                   5525: }
                   5526: 
1.716     raeburn  5527: div.LC_createcourse {
                   5528:     margin: 10px 10px 10px 10px;
                   5529: }
                   5530: 
1.693     droeschl 5531: /* ---- Remove when done ----
                   5532: # The following styles is part of the redesign of LON-CAPA and are
                   5533: # subject to change during this project.
                   5534: # Don't rely on their current functionality as they might be 
                   5535: # changed or removed.
                   5536: # --------------------------*/
                   5537: 
1.698     harmsja  5538: a:hover,
1.721     harmsja  5539: ol.LC_smallMenu a:hover,
                   5540: ol#LC_MenuBreadcrumbs a:hover,
                   5541: ol#LC_PathBreadcrumbs a:hover,
                   5542: ul#LC_TabMainMenuContent a:hover,
                   5543: .LC_FormSectionClearButton input:hover
                   5544: ul.LC_TabContent   li:hover a{
1.698     harmsja  5545: 	color:#BF2317;
                   5546:         text-decoration:none;
1.693     droeschl 5547: }
                   5548: 
                   5549: h1 { 
1.721     harmsja  5550: 	padding:5px 10px 5px 20px;
1.693     droeschl 5551: 	line-height:130%;
                   5552: }
1.698     harmsja  5553: 
1.693     droeschl 5554: h2,h3,h4,h5,h6
                   5555: {
1.721     harmsja  5556: 	margin:5px 0px 5px 0px;
                   5557: 	padding:0px;
                   5558: 	line-height:130%;
1.693     droeschl 5559: }
1.721     harmsja  5560: .LC_hcell{
1.698     harmsja  5561:         padding:3px 15px 3px 15px;
                   5562:         margin:0px;
1.703     harmsja  5563: 	background-color:$tabbg;
                   5564: 	border-bottom:solid 1px $lg_border_color;       
1.693     droeschl 5565: }
1.721     harmsja  5566: .LC_noBorder {
1.698     harmsja  5567:         border:0px;
                   5568: }
1.693     droeschl 5569: 
1.722     harmsja  5570: .LC_bgLightGrey{
1.741     harmsja  5571: 	background:URL(/adm/lonIcons/lightGreyBG.png) repeat-x left bottom;
1.722     harmsja  5572: }
1.741     harmsja  5573: 
1.693     droeschl 5574: 
1.698     harmsja  5575: /* Main Header with discription of Person, Course, etc. */
1.721     harmsja  5576: .LC_HeadRight {
1.693     droeschl 5577: 	text-align: right;
                   5578: 	float: right;
                   5579: 	margin: 0px;
                   5580: 	padding: 0px;
1.698     harmsja  5581:         right:0;
1.693     droeschl 5582:         position:absolute;
1.698     harmsja  5583:         overflow:hidden;
1.693     droeschl 5584: }
                   5585: 
1.721     harmsja  5586: p, .LC_ContentBox {
1.698     harmsja  5587: 	padding: 10px;
                   5588: 
                   5589: }
1.721     harmsja  5590: .LC_FormSectionClearButton input {
1.741     harmsja  5591:         background-color:transparent;    	    
1.698     harmsja  5592:         border:0px;
                   5593:         cursor:pointer;
                   5594:         text-decoration:underline;
1.693     droeschl 5595: }
                   5596: 
                   5597: 
1.698     harmsja  5598: dl,ul,div,fieldset {
                   5599: 	margin: 10px 10px 10px 0px;
1.693     droeschl 5600: 	overflow:hidden;
                   5601: }
1.721     harmsja  5602: ol.LC_smallMenu, ol#LC_PathBreadcrumbs {
1.698     harmsja  5603: 	margin: 0px;
1.693     droeschl 5604: }
                   5605: 
1.721     harmsja  5606: ol.LC_smallMenu li {
1.693     droeschl 5607: 	display: inline;
                   5608: 	padding: 5px 5px 0px 10px;
                   5609: 	vertical-align: top;
                   5610: }
                   5611: 
1.721     harmsja  5612: ol.LC_smallMenu li img {
1.693     droeschl 5613: 	vertical-align: bottom;
                   5614: }
                   5615: 
1.721     harmsja  5616: ol.LC_smallMenu a {
1.693     droeschl 5617: 	font-size: 90%;
                   5618: 	color: RGB(80, 80, 80);
                   5619: 	text-decoration: none;
                   5620: }
1.744   ! ehlerst  5621: ol#LC_TabMainMenueContent, ul.LC_TabContent ,
1.741     harmsja  5622: ul.LC_TabContentBigger {
1.721     harmsja  5623: 	display:block;
                   5624: 	list-style:none;
1.741     harmsja  5625: 	margin: 0px;
1.693     droeschl 5626: 	padding: 0px;
                   5627: }
                   5628: 
1.744   ! ehlerst  5629: ol#LC_TabMainMenuContent li, ul.LC_TabContent li,
1.741     harmsja  5630: ul.LC_TabContentBigger li{
1.693     droeschl 5631: 	display: inline;
1.741     harmsja  5632: 	border-right: solid 1px $lg_border_color;
                   5633: 	float:left;
                   5634: 	line-height:140%;
                   5635: 	white-space:nowrap;
                   5636: }
                   5637: ol#LC_TabMainMenuContent li{
1.693     droeschl 5638: 	vertical-align: bottom;
                   5639: 	border-bottom: solid 1px RGB(175, 175, 175);
1.721     harmsja  5640: 	padding: 5px 10px 5px 10px;
1.741     harmsja  5641: 	margin-right:5px;
                   5642: 	margin-bottom:3px;
1.693     droeschl 5643: 	font-weight: bold;
1.723     riegler  5644: 	background: url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
1.693     droeschl 5645: }
                   5646: 
1.721     harmsja  5647: ol#LC_TabMainMenuContent li a{
1.693     droeschl 5648: 	color: RGB(47, 47, 47);
                   5649: 	text-decoration: none;
                   5650: }
1.721     harmsja  5651: ul.LC_TabContent {
1.741     harmsja  5652: 	min-height:1.6em;
                   5653: 	border-bottom:solid 1px $lg_border_color;
1.721     harmsja  5654: }
                   5655: ul.LC_TabContent li{
1.741     harmsja  5656: 	vertical-align:middle;
                   5657: 	padding:0px 10px 0px 10px;
1.744   ! ehlerst  5658: 	background-color:$lg_border_color;
1.721     harmsja  5659: }
1.744   ! ehlerst  5660: ul.LC_TabContent li a, ul.LC_TabContent li{ 
1.721     harmsja  5661: 	color:rgb(47,47,47);
                   5662: 	text-decoration:none;
                   5663: 	font-size:95%;
                   5664: 	font-weight:bold;
                   5665: }
1.744   ! ehlerst  5666: ul.LC_TabContent li:hover, ul.LC_TabContent li.active{
        !          5667: 	background-color:#FFFFFF;
        !          5668: }
1.741     harmsja  5669: ul.LC_TabContentBigger li{
                   5670: 	vertical-align:bottom;
                   5671: 	border-top:solid 1px $lg_border_color;
                   5672: 	border-left:solid 1px $lg_border_color;
                   5673: 	padding:5px 10px 5px 10px;
                   5674: 	margin-left:2px;
                   5675: 	background:url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
                   5676: }
1.744   ! ehlerst  5677: ul.LC_TabContentBigger li:hover, ul.LC_TabContentBigger li.active{
        !          5678: 	background:url(/adm/lonIcons/lightGreyBG.png) repeat-x right bottom;
        !          5679: }
1.741     harmsja  5680: ul.LC_TabContentBigger li, ul.LC_TabContentBigger li a{
                   5681: 	font-size:110%;
                   5682: 	font-weight:bold;
                   5683: }
                   5684: #LC_CourseDocuments, #LC_SupplementalCourseDocuments
                   5685: {
                   5686: 	margin:0px;
1.737     tempelho 5687: }
                   5688: 
1.721     harmsja  5689: .LC_hideThis
                   5690: {
                   5691: 	display:none;
                   5692: 	visibility:hidden;
1.693     droeschl 5693: }
                   5694: 
1.721     harmsja  5695: ol#LC_MenuBreadcrumbs, ol#LC_PathBreadcrumbs {
1.693     droeschl 5696: 	border-top: solid 1px RGB(255, 255, 255);
                   5697: 	height: 20px;
                   5698: 	line-height: 20px;
                   5699: 	vertical-align: bottom;
                   5700: 	margin: 0px 0px 30px 0px;
                   5701: 	padding-left: 10px;
                   5702: 	list-style-position: inside;
1.723     riegler  5703: 	background: url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
1.693     droeschl 5704: }
                   5705: 
1.721     harmsja  5706: ol#LC_MenuBreadcrumbs li, ol#LC_PathBreadcrumbs li {
1.741     harmsja  5707: /*
1.723     riegler  5708: 	background: url(/adm/lonIcons/arrow_white.png) no-repeat left center;
1.741     harmsja  5709: */	
1.693     droeschl 5710: 	display: inline;
                   5711: 	padding: 0px 0px 0px 10px;
                   5712: 	vertical-align: bottom;
                   5713: 	overflow:hidden;
                   5714: }
                   5715: 
1.721     harmsja  5716: ol#LC_MenuBreadcrumbs li a {
1.693     droeschl 5717: 	text-decoration: none;
                   5718: 	font-size:90%;
                   5719: }
1.721     harmsja  5720: ol#LC_PathBreadcrumbs li a{
1.698     harmsja  5721: 	text-decoration:none;
                   5722: 	font-size:100%;
                   5723: 	font-weight:bold;
1.693     droeschl 5724: }
1.721     harmsja  5725: .LC_ContentBoxSpecial
1.693     droeschl 5726: {
1.701     harmsja  5727: 	border: solid 1px $lg_border_color;
1.698     harmsja  5728: }
1.693     droeschl 5729: 
1.721     harmsja  5730: dl.LC_ListStyleClean dt {
1.693     droeschl 5731: 	padding-right: 5px;
                   5732: 	display: table-header-group;
                   5733: }
                   5734: 
1.721     harmsja  5735: dl.LC_ListStyleClean dd {
1.693     droeschl 5736: 	display: table-row;
                   5737: }
                   5738: 
1.721     harmsja  5739: .LC_ListStyleClean,
                   5740: .LC_ListStyleSimple,
                   5741: .LC_ListStyleNormal,
                   5742: .LC_ListStyleNormal_Border,
                   5743: .LC_ListStyleSpecial
1.693     droeschl 5744: 	{
                   5745: 	/*display:block;	*/
                   5746: 	list-style-position: inside;
                   5747: 	list-style-type: none;
                   5748: 	overflow: hidden;
                   5749: 	padding: 0px;
                   5750: }
                   5751: 
1.721     harmsja  5752: .LC_ListStyleSimple li,
                   5753: .LC_ListStyleSimple dd,
                   5754: .LC_ListStyleNormal li,
                   5755: .LC_ListStyleNormal dd,
                   5756: .LC_ListStyleSpecial li,
                   5757: .LC_ListStyleSpecial dd
1.693     droeschl 5758: 	{
                   5759: 	margin: 0px;
                   5760: 	padding: 5px 5px 5px 10px;
                   5761: 	clear: both;
                   5762: }
                   5763: 
1.721     harmsja  5764: .LC_ListStyleClean li,
                   5765: .LC_ListStyleClean dd {
1.693     droeschl 5766: 	padding-top: 0px;
                   5767: 	padding-bottom: 0px;
                   5768: }
                   5769: 
1.721     harmsja  5770: .LC_ListStyleSimple dd,
                   5771: .LC_ListStyleSimple li{
1.698     harmsja  5772: 	border-bottom: solid 1px $lg_border_color;
1.693     droeschl 5773: }
                   5774: 
1.721     harmsja  5775: .LC_ListStyleSpecial li,
                   5776: .LC_ListStyleSpecial dd {
1.693     droeschl 5777: 	list-style-type: none;
                   5778: 	background-color: RGB(220, 220, 220);
                   5779: 	margin-bottom: 4px;
                   5780: }
                   5781: 
1.721     harmsja  5782: table.LC_SimpleTable {
1.698     harmsja  5783: 	margin:5px;
                   5784: 	border:solid 1px $lg_border_color;
1.693     droeschl 5785: 	}
                   5786: 
1.721     harmsja  5787: table.LC_SimpleTable tr {
1.698     harmsja  5788: 	padding:0px;
                   5789: 	border:solid 1px $lg_border_color;
1.693     droeschl 5790: }
1.721     harmsja  5791: table.LC_SimpleTable thead{
1.698     harmsja  5792: 	 background:rgb(220,220,220);
1.693     droeschl 5793: }
                   5794: 
1.721     harmsja  5795: div.LC_columnSection {
1.693     droeschl 5796: 	display: block;
                   5797: 	clear: both;
                   5798: 	overflow: hidden;
                   5799: 	margin:0px;
                   5800: }
                   5801: 
1.721     harmsja  5802: div.LC_columnSection>* {
1.693     droeschl 5803: 	float: left;
                   5804: 	margin: 10px 20px 10px 0px;
                   5805: 	overflow:hidden;	
                   5806: }
1.721     harmsja  5807: div.LC_columnSection > .LC_ContentBox,
                   5808: div.LC_columnSection > .LC_ContentBoxSpecial
1.693     droeschl 5809: 	{
1.721     harmsja  5810: 	width: 400px;	
1.693     droeschl 5811: }
1.721     harmsja  5812: 
1.719     ehlerst  5813: .ContentBoxSpecialTemplate
                   5814: {
                   5815:         border: solid 1px $lg_border_color;
                   5816: }
                   5817: .ContentBoxTemplate {
                   5818:         padding:10px;
                   5819: }
                   5820: 
1.721     harmsja  5821: div.LC_columnSection > .ContentBoxTemplate,
                   5822: div.LC_columnSection > .ContentBoxSpecialTemplate
1.719     ehlerst  5823:         {
                   5824:         width: 600px;
                   5825: 
                   5826: }
                   5827: 
1.720     ehlerst  5828: .clear{
                   5829: 	clear: both;
                   5830: 	line-height: 0px;
                   5831: 	font-size: 0px;
                   5832: 	height: 0px;
                   5833: }
1.693     droeschl 5834: 
1.694     tempelho 5835: .LC_loginpage_container {
                   5836: 	text-align:left;
                   5837: 	margin : 0 auto;
                   5838: 	width:65%;
                   5839: 	padding: 10px;
                   5840: 	height: auto;
1.712     muellerd 5841: 	background-color:#FFFFFF;
1.694     tempelho 5842: 	border:1px solid #CCCCCC;
                   5843: }
                   5844: 
                   5845: 
                   5846: .LC_loginpage_loginContainer {
                   5847: 	float:left;
1.712     muellerd 5848: 	width: 182px;
                   5849: 	border:1px solid #CCCCCC;
                   5850: 	background-color:$loginbg;
1.694     tempelho 5851: }
                   5852: 
1.717     tempelho 5853: .LC_loginpage_loginContainer h2{
1.712     muellerd 5854: 	margin-top:0;
                   5855: 	display:block;
                   5856: 	background:$bgcol;
                   5857: 	color:$textcol;
                   5858: 	padding-left:5px;
                   5859: }
1.694     tempelho 5860: .LC_loginpage_loginInfo {
                   5861: 	margin-left:20px;
                   5862: 	float:left;
                   5863: 	width:30%;
                   5864: 	border:1px solid #CCCCCC;
                   5865: 	padding:10px;
                   5866: }
                   5867: 
1.712     muellerd 5868: .LC_loginpage_loginDomain {
                   5869: 	margin-right:20px;
                   5870: 	width:20%;
                   5871: 	float:left;
                   5872: 	padding:10px;
                   5873: }
                   5874: 
1.694     tempelho 5875: .LC_loginpage_space {
                   5876: 	clear:both;
                   5877: 	margin-bottom:20px;
                   5878: 	border-bottom: 1px solid #CCCCCC;
                   5879: }
                   5880: 
1.343     albertel 5881: END
                   5882: }
                   5883: 
1.306     albertel 5884: =pod
                   5885: 
                   5886: =item * &headtag()
                   5887: 
                   5888: Returns a uniform footer for LON-CAPA web pages.
                   5889: 
1.307     albertel 5890: Inputs: $title - optional title for the head
                   5891:         $head_extra - optional extra HTML to put inside the <head>
1.315     albertel 5892:         $args - optional arguments
1.319     albertel 5893:             force_register - if is true call registerurl so the remote is 
                   5894:                              informed
1.415     albertel 5895:             redirect       -> array ref of
                   5896:                                    1- seconds before redirect occurs
                   5897:                                    2- url to redirect to
                   5898:                                    3- whether the side effect should occur
1.315     albertel 5899:                            (side effect of setting 
                   5900:                                $env{'internal.head.redirect'} to the url 
                   5901:                                redirected too)
1.352     albertel 5902:             domain         -> force to color decorate a page for a specific
                   5903:                                domain
                   5904:             function       -> force usage of a specific rolish color scheme
                   5905:             bgcolor        -> override the default page bgcolor
1.460     albertel 5906:             no_auto_mt_title
                   5907:                            -> prevent &mt()ing the title arg
1.464     albertel 5908: 
1.306     albertel 5909: =cut
                   5910: 
                   5911: sub headtag {
1.313     albertel 5912:     my ($title,$head_extra,$args) = @_;
1.306     albertel 5913:     
1.363     albertel 5914:     my $function = $args->{'function'} || &get_users_function();
                   5915:     my $domain   = $args->{'domain'}   || &determinedomain();
                   5916:     my $bgcolor  = $args->{'bgcolor'}  || &designparm($function.'.pgbg',$domain);
1.418     albertel 5917:     my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458     albertel 5918: 		   $Apache::lonnet::perlvar{'lonVersion'},
1.531     albertel 5919: 		   #time(),
1.418     albertel 5920: 		   $env{'environment.color.timestamp'},
1.363     albertel 5921: 		   $function,$domain,$bgcolor);
                   5922: 
1.369     www      5923:     $url = '/adm/css/'.&escape($url).'.css';
1.363     albertel 5924: 
1.308     albertel 5925:     my $result =
                   5926: 	'<head>'.
1.461     albertel 5927: 	&font_settings();
1.319     albertel 5928: 
1.461     albertel 5929:     if (!$args->{'frameset'}) {
                   5930: 	$result .= &Apache::lonhtmlcommon::htmlareaheaders();
                   5931:     }
1.319     albertel 5932:     if ($args->{'force_register'}) {
                   5933: 	$result .= &Apache::lonmenu::registerurl(1);
                   5934:     }
1.436     albertel 5935:     if (!$args->{'no_nav_bar'} 
                   5936: 	&& !$args->{'only_body'}
                   5937: 	&& !$args->{'frameset'}) {
                   5938: 	$result .= &help_menu_js();
                   5939:     }
1.319     albertel 5940: 
1.314     albertel 5941:     if (ref($args->{'redirect'})) {
1.414     albertel 5942: 	my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315     albertel 5943: 	$url = &Apache::lonenc::check_encrypt($url);
1.414     albertel 5944: 	if (!$inhibit_continue) {
                   5945: 	    $env{'internal.head.redirect'} = $url;
                   5946: 	}
1.313     albertel 5947: 	$result.=<<ADDMETA
                   5948: <meta http-equiv="pragma" content="no-cache" />
1.344     albertel 5949: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313     albertel 5950: ADDMETA
                   5951:     }
1.306     albertel 5952:     if (!defined($title)) {
                   5953: 	$title = 'The LearningOnline Network with CAPA';
                   5954:     }
1.460     albertel 5955:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
                   5956:     $result .= '<title> LON-CAPA '.$title.'</title>'
1.414     albertel 5957: 	.'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
                   5958: 	.$head_extra;
1.306     albertel 5959:     return $result;
                   5960: }
                   5961: 
                   5962: =pod
                   5963: 
1.340     albertel 5964: =item * &font_settings()
                   5965: 
                   5966: Returns neccessary <meta> to set the proper encoding
                   5967: 
                   5968: Inputs: none
                   5969: 
                   5970: =cut
                   5971: 
                   5972: sub font_settings {
                   5973:     my $headerstring='';
1.647     www      5974:     if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340     albertel 5975: 	$headerstring.=
                   5976: 	    '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
                   5977:     }
                   5978:     return $headerstring;
                   5979: }
                   5980: 
1.341     albertel 5981: =pod
                   5982: 
                   5983: =item * &xml_begin()
                   5984: 
                   5985: Returns the needed doctype and <html>
                   5986: 
                   5987: Inputs: none
                   5988: 
                   5989: =cut
                   5990: 
                   5991: sub xml_begin {
                   5992:     my $output='';
                   5993: 
1.592     albertel 5994:     if ($env{'internal.start_page'}==1) {
                   5995: 	&Apache::lonhtmlcommon::init_htmlareafields();
                   5996:     }
1.342     albertel 5997: 
1.341     albertel 5998:     if ($env{'browser.mathml'}) {
                   5999: 	$output='<?xml version="1.0"?>'
                   6000:             #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
                   6001: #            .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
                   6002:             
                   6003: #	    .'<!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">] >'
                   6004: 	    .'<!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">'
                   6005:             .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" ' 
                   6006: 	    .'xmlns="http://www.w3.org/1999/xhtml">';
                   6007:     } else {
                   6008: 	$output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>';
                   6009:     }
                   6010:     return $output;
                   6011: }
1.340     albertel 6012: 
                   6013: =pod
                   6014: 
1.306     albertel 6015: =item * &endheadtag()
                   6016: 
                   6017: Returns a uniform </head> for LON-CAPA web pages.
                   6018: 
                   6019: Inputs: none
                   6020: 
                   6021: =cut
                   6022: 
                   6023: sub endheadtag {
                   6024:     return '</head>';
                   6025: }
                   6026: 
                   6027: =pod
                   6028: 
                   6029: =item * &head()
                   6030: 
                   6031: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
                   6032: 
1.648     raeburn  6033: Inputs:
                   6034: 
                   6035: =over 4
                   6036: 
                   6037: $title - optional title for the page
                   6038: 
                   6039: $head_extra - optional extra HTML to put inside the <head>
                   6040: 
                   6041: =back
1.405     albertel 6042: 
1.306     albertel 6043: =cut
                   6044: 
                   6045: sub head {
1.325     albertel 6046:     my ($title,$head_extra,$args) = @_;
                   6047:     return &headtag($title,$head_extra,$args).&endheadtag();
1.306     albertel 6048: }
                   6049: 
                   6050: =pod
                   6051: 
                   6052: =item * &start_page()
                   6053: 
                   6054: Returns a complete <html> .. <body> section for LON-CAPA web pages.
                   6055: 
1.648     raeburn  6056: Inputs:
                   6057: 
                   6058: =over 4
                   6059: 
                   6060: $title - optional title for the page
                   6061: 
                   6062: $head_extra - optional extra HTML to incude inside the <head>
                   6063: 
                   6064: $args - additional optional args supported are:
                   6065: 
                   6066: =over 8
                   6067: 
                   6068:              only_body      -> is true will set &bodytag() onlybodytag
1.317     albertel 6069:                                     arg on
1.648     raeburn  6070:              no_nav_bar     -> is true will set &bodytag() notopbar arg on
                   6071:              add_entries    -> additional attributes to add to the  <body>
                   6072:              domain         -> force to color decorate a page for a 
1.317     albertel 6073:                                     specific domain
1.648     raeburn  6074:              function       -> force usage of a specific rolish color
1.317     albertel 6075:                                     scheme
1.648     raeburn  6076:              redirect       -> see &headtag()
                   6077:              bgcolor        -> override the default page bg color
                   6078:              js_ready       -> return a string ready for being used in 
1.317     albertel 6079:                                     a javascript writeln
1.648     raeburn  6080:              html_encode    -> return a string ready for being used in 
1.320     albertel 6081:                                     a html attribute
1.648     raeburn  6082:              force_register -> if is true will turn on the &bodytag()
1.317     albertel 6083:                                     $forcereg arg
1.648     raeburn  6084:              body_title     -> alternate text to use instead of $title
1.326     albertel 6085:                                     in the title box that appears, this text
                   6086:                                     is not auto translated like the $title is
1.648     raeburn  6087:              frameset       -> if true will start with a <frameset>
1.330     albertel 6088:                                     rather than <body>
1.648     raeburn  6089:              no_title       -> if true the title bar won't be shown
                   6090:              skip_phases    -> hash ref of 
1.338     albertel 6091:                                     head -> skip the <html><head> generation
                   6092:                                     body -> skip all <body> generation
1.648     raeburn  6093:              no_inline_link -> if true and in remote mode, don't show the 
1.361     albertel 6094:                                     'Switch To Inline Menu' link
1.648     raeburn  6095:              no_auto_mt_title -> prevent &mt()ing the title arg
                   6096:              inherit_jsmath -> when creating popup window in a page,
                   6097:                                     should it have jsmath forced on by the
                   6098:                                     current page
1.361     albertel 6099: 
1.648     raeburn  6100: =back
1.460     albertel 6101: 
1.648     raeburn  6102: =back
1.562     albertel 6103: 
1.306     albertel 6104: =cut
                   6105: 
                   6106: sub start_page {
1.309     albertel 6107:     my ($title,$head_extra,$args) = @_;
1.318     albertel 6108:     #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313     albertel 6109:     my %head_args;
1.352     albertel 6110:     foreach my $arg ('redirect','force_register','domain','function',
1.460     albertel 6111: 		     'bgcolor','frameset','no_nav_bar','only_body',
                   6112: 		     'no_auto_mt_title') {
1.319     albertel 6113: 	if (defined($args->{$arg})) {
1.324     raeburn  6114: 	    $head_args{$arg} = $args->{$arg};
1.319     albertel 6115: 	}
1.313     albertel 6116:     }
1.319     albertel 6117: 
1.315     albertel 6118:     $env{'internal.start_page'}++;
1.338     albertel 6119:     my $result;
                   6120:     if (! exists($args->{'skip_phases'}{'head'}) ) {
                   6121: 	$result.=
1.341     albertel 6122: 	    &xml_begin().
1.338     albertel 6123: 	    &headtag($title,$head_extra,\%head_args).&endheadtag();
                   6124:     }
                   6125:     
                   6126:     if (! exists($args->{'skip_phases'}{'body'}) ) {
                   6127: 	if ($args->{'frameset'}) {
                   6128: 	    my $attr_string = &make_attr_string($args->{'force_register'},
                   6129: 						$args->{'add_entries'});
                   6130: 	    $result .= "\n<frameset $attr_string>\n";
                   6131: 	} else {
                   6132: 	    $result .=
                   6133: 		&bodytag($title, 
                   6134: 			 $args->{'function'},       $args->{'add_entries'},
                   6135: 			 $args->{'only_body'},      $args->{'domain'},
                   6136: 			 $args->{'force_register'}, $args->{'body_title'},
                   6137: 			 $args->{'no_nav_bar'},     $args->{'bgcolor'},
1.460     albertel 6138: 			 $args->{'no_title'},       $args->{'no_inline_link'},
                   6139: 			 $args);
1.338     albertel 6140: 	}
1.330     albertel 6141:     }
1.338     albertel 6142: 
1.315     albertel 6143:     if ($args->{'js_ready'}) {
1.713     kaisler  6144: 		$result = &js_ready($result);
1.315     albertel 6145:     }
1.320     albertel 6146:     if ($args->{'html_encode'}) {
1.713     kaisler  6147: 		$result = &html_encode($result);
                   6148:     }
                   6149: 
1.718     raeburn  6150:     if (exists($args->{'bread_crumbs'})) {
                   6151:         &Apache::lonhtmlcommon::clear_breadcrumbs();
                   6152:         if (ref($args->{'bread_crumbs'}) eq 'ARRAY') {         
                   6153:             foreach my $crumb (@{$args->{'bread_crumbs'}}){
                   6154:                 &Apache::lonhtmlcommon::add_breadcrumb($crumb);
                   6155:             }
                   6156:         }
                   6157:         $result .= &Apache::lonhtmlcommon::breadcrumbs();
1.320     albertel 6158:     }
1.713     kaisler  6159: 
1.315     albertel 6160:     return $result;
1.306     albertel 6161: }
                   6162: 
1.330     albertel 6163: 
1.306     albertel 6164: =pod
                   6165: 
                   6166: =item * &head()
                   6167: 
                   6168: Returns a complete </body></html> section for LON-CAPA web pages.
                   6169: 
1.315     albertel 6170: Inputs:         $args - additional optional args supported are:
                   6171:                  js_ready     -> return a string ready for being used in 
                   6172:                                  a javascript writeln
1.320     albertel 6173:                  html_encode  -> return a string ready for being used in 
                   6174:                                  a html attribute
1.330     albertel 6175:                  frameset     -> if true will start with a <frameset>
                   6176:                                  rather than <body>
1.493     albertel 6177:                  dicsussion   -> if true will get discussion from
                   6178:                                   lonxml::xmlend
                   6179:                                  (you can pass the target and parser arguments
                   6180:                                   through optional 'target' and 'parser' args
                   6181:                                   to this routine)
1.306     albertel 6182: 
                   6183: =cut
                   6184: 
                   6185: sub end_page {
1.315     albertel 6186:     my ($args) = @_;
                   6187:     $env{'internal.end_page'}++;
1.330     albertel 6188:     my $result;
1.335     albertel 6189:     if ($args->{'discussion'}) {
                   6190: 	my ($target,$parser);
                   6191: 	if (ref($args->{'discussion'})) {
                   6192: 	    ($target,$parser) =($args->{'discussion'}{'target'},
                   6193: 				$args->{'discussion'}{'parser'});
                   6194: 	}
                   6195: 	$result .= &Apache::lonxml::xmlend($target,$parser);
                   6196:     }
                   6197: 
1.330     albertel 6198:     if ($args->{'frameset'}) {
                   6199: 	$result .= '</frameset>';
                   6200:     } else {
1.635     raeburn  6201: 	$result .= &endbodytag($args);
1.330     albertel 6202:     }
                   6203:     $result .= "\n</html>";
                   6204: 
1.315     albertel 6205:     if ($args->{'js_ready'}) {
1.317     albertel 6206: 	$result = &js_ready($result);
1.315     albertel 6207:     }
1.335     albertel 6208: 
1.320     albertel 6209:     if ($args->{'html_encode'}) {
                   6210: 	$result = &html_encode($result);
                   6211:     }
1.335     albertel 6212: 
1.315     albertel 6213:     return $result;
                   6214: }
                   6215: 
1.320     albertel 6216: sub html_encode {
                   6217:     my ($result) = @_;
                   6218: 
1.322     albertel 6219:     $result = &HTML::Entities::encode($result,'<>&"');
1.320     albertel 6220:     
                   6221:     return $result;
                   6222: }
1.317     albertel 6223: sub js_ready {
                   6224:     my ($result) = @_;
                   6225: 
1.323     albertel 6226:     $result =~ s/[\n\r]/ /xmsg;
                   6227:     $result =~ s/\\/\\\\/xmsg;
                   6228:     $result =~ s/'/\\'/xmsg;
1.372     albertel 6229:     $result =~ s{</}{<\\/}xmsg;
1.317     albertel 6230:     
                   6231:     return $result;
                   6232: }
                   6233: 
1.315     albertel 6234: sub validate_page {
                   6235:     if (  exists($env{'internal.start_page'})
1.316     albertel 6236: 	  &&     $env{'internal.start_page'} > 1) {
                   6237: 	&Apache::lonnet::logthis('start_page called multiple times '.
1.318     albertel 6238: 				 $env{'internal.start_page'}.' '.
1.316     albertel 6239: 				 $ENV{'request.filename'});
1.315     albertel 6240:     }
                   6241:     if (  exists($env{'internal.end_page'})
1.316     albertel 6242: 	  &&     $env{'internal.end_page'} > 1) {
                   6243: 	&Apache::lonnet::logthis('end_page called multiple times '.
1.318     albertel 6244: 				 $env{'internal.end_page'}.' '.
1.316     albertel 6245: 				 $env{'request.filename'});
1.315     albertel 6246:     }
                   6247:     if (     exists($env{'internal.start_page'})
                   6248: 	&& ! exists($env{'internal.end_page'})) {
1.316     albertel 6249: 	&Apache::lonnet::logthis('start_page called without end_page '.
                   6250: 				 $env{'request.filename'});
1.315     albertel 6251:     }
                   6252:     if (   ! exists($env{'internal.start_page'})
                   6253: 	&&   exists($env{'internal.end_page'})) {
1.316     albertel 6254: 	&Apache::lonnet::logthis('end_page called without start_page'.
                   6255: 				 $env{'request.filename'});
1.315     albertel 6256:     }
1.306     albertel 6257: }
1.315     albertel 6258: 
1.318     albertel 6259: sub simple_error_page {
                   6260:     my ($r,$title,$msg) = @_;
                   6261:     my $page =
                   6262: 	&Apache::loncommon::start_page($title).
                   6263: 	&mt($msg).
                   6264: 	&Apache::loncommon::end_page();
                   6265:     if (ref($r)) {
                   6266: 	$r->print($page);
1.327     albertel 6267: 	return;
1.318     albertel 6268:     }
                   6269:     return $page;
                   6270: }
1.347     albertel 6271: 
                   6272: {
1.610     albertel 6273:     my @row_count;
1.347     albertel 6274:     sub start_data_table {
1.422     albertel 6275: 	my ($add_class) = @_;
                   6276: 	my $css_class = (join(' ','LC_data_table',$add_class));
1.610     albertel 6277: 	unshift(@row_count,0);
1.422     albertel 6278: 	return '<table class="'.$css_class.'">'."\n";
1.347     albertel 6279:     }
                   6280: 
                   6281:     sub end_data_table {
1.610     albertel 6282: 	shift(@row_count);
1.389     albertel 6283: 	return '</table>'."\n";;
1.347     albertel 6284:     }
                   6285: 
                   6286:     sub start_data_table_row {
1.422     albertel 6287: 	my ($add_class) = @_;
1.610     albertel 6288: 	$row_count[0]++;
                   6289: 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.428     albertel 6290: 	$css_class = (join(' ',$css_class,$add_class));
1.422     albertel 6291: 	return  '<tr class="'.$css_class.'">'."\n";;
1.347     albertel 6292:     }
1.471     banghart 6293:     
                   6294:     sub continue_data_table_row {
                   6295: 	my ($add_class) = @_;
1.610     albertel 6296: 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.471     banghart 6297: 	$css_class = (join(' ',$css_class,$add_class));
                   6298: 	return  '<tr class="'.$css_class.'">'."\n";;
                   6299:     }
1.347     albertel 6300: 
                   6301:     sub end_data_table_row {
1.389     albertel 6302: 	return '</tr>'."\n";;
1.347     albertel 6303:     }
1.367     www      6304: 
1.421     albertel 6305:     sub start_data_table_empty_row {
1.707     bisitz   6306: #	$row_count[0]++;
1.421     albertel 6307: 	return  '<tr class="LC_empty_row" >'."\n";;
                   6308:     }
                   6309: 
                   6310:     sub end_data_table_empty_row {
                   6311: 	return '</tr>'."\n";;
                   6312:     }
                   6313: 
1.367     www      6314:     sub start_data_table_header_row {
1.389     albertel 6315: 	return  '<tr class="LC_header_row">'."\n";;
1.367     www      6316:     }
                   6317: 
                   6318:     sub end_data_table_header_row {
1.389     albertel 6319: 	return '</tr>'."\n";;
1.367     www      6320:     }
1.347     albertel 6321: }
                   6322: 
1.548     albertel 6323: =pod
                   6324: 
                   6325: =item * &inhibit_menu_check($arg)
                   6326: 
                   6327: Checks for a inhibitmenu state and generates output to preserve it
                   6328: 
                   6329: Inputs:         $arg - can be any of
                   6330:                      - undef - in which case the return value is a string 
                   6331:                                to add  into arguments list of a uri
                   6332:                      - 'input' - in which case the return value is a HTML
                   6333:                                  <form> <input> field of type hidden to
                   6334:                                  preserve the value
                   6335:                      - a url - in which case the return value is the url with
                   6336:                                the neccesary cgi args added to preserve the
                   6337:                                inhibitmenu state
                   6338:                      - a ref to a url - no return value, but the string is
                   6339:                                         updated to include the neccessary cgi
                   6340:                                         args to preserve the inhibitmenu state
                   6341: 
                   6342: =cut
                   6343: 
                   6344: sub inhibit_menu_check {
                   6345:     my ($arg) = @_;
                   6346:     &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
                   6347:     if ($arg eq 'input') {
                   6348: 	if ($env{'form.inhibitmenu'}) {
                   6349: 	    return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
                   6350: 	} else {
                   6351: 	    return
                   6352: 	}
                   6353:     }
                   6354:     if ($env{'form.inhibitmenu'}) {
                   6355: 	if (ref($arg)) {
                   6356: 	    $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
                   6357: 	} elsif ($arg eq '') {
                   6358: 	    $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
                   6359: 	} else {
                   6360: 	    $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
                   6361: 	}
                   6362:     }
                   6363:     if (!ref($arg)) {
                   6364: 	return $arg;
                   6365:     }
                   6366: }
                   6367: 
1.251     albertel 6368: ###############################################
1.182     matthew  6369: 
                   6370: =pod
                   6371: 
1.549     albertel 6372: =back
                   6373: 
                   6374: =head1 User Information Routines
                   6375: 
                   6376: =over 4
                   6377: 
1.405     albertel 6378: =item * &get_users_function()
1.182     matthew  6379: 
                   6380: Used by &bodytag to determine the current users primary role.
                   6381: Returns either 'student','coordinator','admin', or 'author'.
                   6382: 
                   6383: =cut
                   6384: 
                   6385: ###############################################
                   6386: sub get_users_function {
                   6387:     my $function = 'student';
1.258     albertel 6388:     if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
1.182     matthew  6389:         $function='coordinator';
                   6390:     }
1.258     albertel 6391:     if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182     matthew  6392:         $function='admin';
                   6393:     }
1.258     albertel 6394:     if (($env{'request.role'}=~/^(au|ca)/) ||
1.182     matthew  6395:         ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
                   6396:         $function='author';
                   6397:     }
                   6398:     return $function;
1.54      www      6399: }
1.99      www      6400: 
                   6401: ###############################################
                   6402: 
1.233     raeburn  6403: =pod
                   6404: 
1.542     raeburn  6405: =item * &check_user_status()
1.274     raeburn  6406: 
                   6407: Determines current status of supplied role for a
                   6408: specific user. Roles can be active, previous or future.
                   6409: 
                   6410: Inputs: 
                   6411: user's domain, user's username, course's domain,
1.375     raeburn  6412: course's number, optional section ID.
1.274     raeburn  6413: 
                   6414: Outputs:
                   6415: role status: active, previous or future. 
                   6416: 
                   6417: =cut
                   6418: 
                   6419: sub check_user_status {
1.412     raeburn  6420:     my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274     raeburn  6421:     my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
                   6422:     my @uroles = keys %userinfo;
                   6423:     my $srchstr;
                   6424:     my $active_chk = 'none';
1.412     raeburn  6425:     my $now = time;
1.274     raeburn  6426:     if (@uroles > 0) {
1.412     raeburn  6427:         if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
1.274     raeburn  6428:             $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
                   6429:         } else {
1.412     raeburn  6430:             $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
                   6431:         }
                   6432:         if (grep/^\Q$srchstr\E$/,@uroles) {
1.274     raeburn  6433:             my $role_end = 0;
                   6434:             my $role_start = 0;
                   6435:             $active_chk = 'active';
1.412     raeburn  6436:             if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
                   6437:                 $role_end = $1;
                   6438:                 if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
                   6439:                     $role_start = $1;
1.274     raeburn  6440:                 }
                   6441:             }
                   6442:             if ($role_start > 0) {
1.412     raeburn  6443:                 if ($now < $role_start) {
1.274     raeburn  6444:                     $active_chk = 'future';
                   6445:                 }
                   6446:             }
                   6447:             if ($role_end > 0) {
1.412     raeburn  6448:                 if ($now > $role_end) {
1.274     raeburn  6449:                     $active_chk = 'previous';
                   6450:                 }
                   6451:             }
                   6452:         }
                   6453:     }
                   6454:     return $active_chk;
                   6455: }
                   6456: 
                   6457: ###############################################
                   6458: 
                   6459: =pod
                   6460: 
1.405     albertel 6461: =item * &get_sections()
1.233     raeburn  6462: 
                   6463: Determines all the sections for a course including
                   6464: sections with students and sections containing other roles.
1.419     raeburn  6465: Incoming parameters: 
                   6466: 
                   6467: 1. domain
                   6468: 2. course number 
                   6469: 3. reference to array containing roles for which sections should 
                   6470: be gathered (optional).
                   6471: 4. reference to array containing status types for which sections 
                   6472: should be gathered (optional).
                   6473: 
                   6474: If the third argument is undefined, sections are gathered for any role. 
                   6475: If the fourth argument is undefined, sections are gathered for any status.
                   6476: Permissible values are 'active' or 'future' or 'previous'.
1.233     raeburn  6477:  
1.374     raeburn  6478: Returns section hash (keys are section IDs, values are
                   6479: number of users in each section), subject to the
1.419     raeburn  6480: optional roles filter, optional status filter 
1.233     raeburn  6481: 
                   6482: =cut
                   6483: 
                   6484: ###############################################
                   6485: sub get_sections {
1.419     raeburn  6486:     my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366     albertel 6487:     if (!defined($cdom) || !defined($cnum)) {
                   6488:         my $cid =  $env{'request.course.id'};
                   6489: 
                   6490: 	return if (!defined($cid));
                   6491: 
                   6492:         $cdom = $env{'course.'.$cid.'.domain'};
                   6493:         $cnum = $env{'course.'.$cid.'.num'};
                   6494:     }
                   6495: 
                   6496:     my %sectioncount;
1.419     raeburn  6497:     my $now = time;
1.240     albertel 6498: 
1.366     albertel 6499:     if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276     albertel 6500: 	my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240     albertel 6501: 	my $sec_index = &Apache::loncoursedata::CL_SECTION();
                   6502: 	my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419     raeburn  6503:         my $start_index = &Apache::loncoursedata::CL_START();
                   6504:         my $end_index = &Apache::loncoursedata::CL_END();
                   6505:         my $status;
1.366     albertel 6506: 	while (my ($student,$data) = each(%$classlist)) {
1.419     raeburn  6507: 	    my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
                   6508: 				                     $data->[$status_index],
                   6509:                                                      $data->[$start_index],
                   6510:                                                      $data->[$end_index]);
                   6511:             if ($stu_status eq 'Active') {
                   6512:                 $status = 'active';
                   6513:             } elsif ($end < $now) {
                   6514:                 $status = 'previous';
                   6515:             } elsif ($start > $now) {
                   6516:                 $status = 'future';
                   6517:             } 
                   6518: 	    if ($section ne '-1' && $section !~ /^\s*$/) {
                   6519:                 if ((!defined($possible_status)) || (($status ne '') && 
                   6520:                     (grep/^\Q$status\E$/,@{$possible_status}))) { 
                   6521: 		    $sectioncount{$section}++;
                   6522:                 }
1.240     albertel 6523: 	    }
                   6524: 	}
                   6525:     }
                   6526:     my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   6527:     foreach my $user (sort(keys(%courseroles))) {
                   6528: 	if ($user !~ /^(\w{2})/) { next; }
                   6529: 	my ($role) = ($user =~ /^(\w{2})/);
                   6530: 	if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419     raeburn  6531: 	my ($section,$status);
1.240     albertel 6532: 	if ($role eq 'cr' &&
                   6533: 	    $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
                   6534: 	    $section=$1;
                   6535: 	}
                   6536: 	if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
                   6537: 	if (!defined($section) || $section eq '-1') { next; }
1.419     raeburn  6538:         my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
                   6539:         if ($end == -1 && $start == -1) {
                   6540:             next; #deleted role
                   6541:         }
                   6542:         if (!defined($possible_status)) { 
                   6543:             $sectioncount{$section}++;
                   6544:         } else {
                   6545:             if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
                   6546:                 $status = 'active';
                   6547:             } elsif ($end < $now) {
                   6548:                 $status = 'future';
                   6549:             } elsif ($start > $now) {
                   6550:                 $status = 'previous';
                   6551:             }
                   6552:             if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
                   6553:                 $sectioncount{$section}++;
                   6554:             }
                   6555:         }
1.233     raeburn  6556:     }
1.366     albertel 6557:     return %sectioncount;
1.233     raeburn  6558: }
                   6559: 
1.274     raeburn  6560: ###############################################
1.294     raeburn  6561: 
                   6562: =pod
1.405     albertel 6563: 
                   6564: =item * &get_course_users()
                   6565: 
1.275     raeburn  6566: Retrieves usernames:domains for users in the specified course
                   6567: with specific role(s), and access status. 
                   6568: 
                   6569: Incoming parameters:
1.277     albertel 6570: 1. course domain
                   6571: 2. course number
                   6572: 3. access status: users must have - either active, 
1.275     raeburn  6573: previous, future, or all.
1.277     albertel 6574: 4. reference to array of permissible roles
1.288     raeburn  6575: 5. reference to array of section restrictions (optional)
                   6576: 6. reference to results object (hash of hashes).
                   6577: 7. reference to optional userdata hash
1.609     raeburn  6578: 8. reference to optional statushash
1.630     raeburn  6579: 9. flag if privileged users (except those set to unhide in
                   6580:    course settings) should be excluded    
1.609     raeburn  6581: Keys of top level results hash are roles.
1.275     raeburn  6582: Keys of inner hashes are username:domain, with 
                   6583: values set to access type.
1.288     raeburn  6584: Optional userdata hash returns an array with arguments in the 
                   6585: same order as loncoursedata::get_classlist() for student data.
                   6586: 
1.609     raeburn  6587: Optional statushash returns
                   6588: 
1.288     raeburn  6589: Entries for end, start, section and status are blank because
                   6590: of the possibility of multiple values for non-student roles.
                   6591: 
1.275     raeburn  6592: =cut
1.405     albertel 6593: 
1.275     raeburn  6594: ###############################################
1.405     albertel 6595: 
1.275     raeburn  6596: sub get_course_users {
1.630     raeburn  6597:     my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288     raeburn  6598:     my %idx = ();
1.419     raeburn  6599:     my %seclists;
1.288     raeburn  6600: 
                   6601:     $idx{udom} = &Apache::loncoursedata::CL_SDOM();
                   6602:     $idx{uname} =  &Apache::loncoursedata::CL_SNAME();
                   6603:     $idx{end} = &Apache::loncoursedata::CL_END();
                   6604:     $idx{start} = &Apache::loncoursedata::CL_START();
                   6605:     $idx{id} = &Apache::loncoursedata::CL_ID();
                   6606:     $idx{section} = &Apache::loncoursedata::CL_SECTION();
                   6607:     $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
                   6608:     $idx{status} = &Apache::loncoursedata::CL_STATUS();
                   6609: 
1.290     albertel 6610:     if (grep(/^st$/,@{$roles})) {
1.276     albertel 6611:         my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278     raeburn  6612:         my $now = time;
1.277     albertel 6613:         foreach my $student (keys(%{$classlist})) {
1.288     raeburn  6614:             my $match = 0;
1.412     raeburn  6615:             my $secmatch = 0;
1.419     raeburn  6616:             my $section = $$classlist{$student}[$idx{section}];
1.609     raeburn  6617:             my $status = $$classlist{$student}[$idx{status}];
1.419     raeburn  6618:             if ($section eq '') {
                   6619:                 $section = 'none';
                   6620:             }
1.291     albertel 6621:             if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 6622:                 if (grep(/^all$/,@{$sections})) {
1.412     raeburn  6623:                     $secmatch = 1;
                   6624:                 } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420     albertel 6625:                     if (grep(/^none$/,@{$sections})) {
1.412     raeburn  6626:                         $secmatch = 1;
                   6627:                     }
                   6628:                 } else {  
1.419     raeburn  6629: 		    if (grep(/^\Q$section\E$/,@{$sections})) {
1.412     raeburn  6630: 		        $secmatch = 1;
                   6631:                     }
1.290     albertel 6632: 		}
1.412     raeburn  6633:                 if (!$secmatch) {
                   6634:                     next;
                   6635:                 }
1.419     raeburn  6636:             }
1.275     raeburn  6637:             if (defined($$types{'active'})) {
1.288     raeburn  6638:                 if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275     raeburn  6639:                     push(@{$$users{st}{$student}},'active');
1.288     raeburn  6640:                     $match = 1;
1.275     raeburn  6641:                 }
                   6642:             }
                   6643:             if (defined($$types{'previous'})) {
1.609     raeburn  6644:                 if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275     raeburn  6645:                     push(@{$$users{st}{$student}},'previous');
1.288     raeburn  6646:                     $match = 1;
1.275     raeburn  6647:                 }
                   6648:             }
                   6649:             if (defined($$types{'future'})) {
1.609     raeburn  6650:                 if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275     raeburn  6651:                     push(@{$$users{st}{$student}},'future');
1.288     raeburn  6652:                     $match = 1;
1.275     raeburn  6653:                 }
                   6654:             }
1.609     raeburn  6655:             if ($match) {
                   6656:                 push(@{$seclists{$student}},$section);
                   6657:                 if (ref($userdata) eq 'HASH') {
                   6658:                     $$userdata{$student} = $$classlist{$student};
                   6659:                 }
                   6660:                 if (ref($statushash) eq 'HASH') {
                   6661:                     $statushash->{$student}{'st'}{$section} = $status;
                   6662:                 }
1.288     raeburn  6663:             }
1.275     raeburn  6664:         }
                   6665:     }
1.412     raeburn  6666:     if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439     raeburn  6667:         my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   6668:         my $now = time;
1.609     raeburn  6669:         my %displaystatus = ( previous => 'Expired',
                   6670:                               active   => 'Active',
                   6671:                               future   => 'Future',
                   6672:                             );
1.630     raeburn  6673:         my %nothide;
                   6674:         if ($hidepriv) {
                   6675:             my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
                   6676:             foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
                   6677:                 if ($user !~ /:/) {
                   6678:                     $nothide{join(':',split(/[\@]/,$user))}=1;
                   6679:                 } else {
                   6680:                     $nothide{$user} = 1;
                   6681:                 }
                   6682:             }
                   6683:         }
1.439     raeburn  6684:         foreach my $person (sort(keys(%coursepersonnel))) {
1.288     raeburn  6685:             my $match = 0;
1.412     raeburn  6686:             my $secmatch = 0;
1.439     raeburn  6687:             my $status;
1.412     raeburn  6688:             my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275     raeburn  6689:             $user =~ s/:$//;
1.439     raeburn  6690:             my ($end,$start) = split(/:/,$coursepersonnel{$person});
                   6691:             if ($end == -1 || $start == -1) {
                   6692:                 next;
                   6693:             }
                   6694:             if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
                   6695:                 (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412     raeburn  6696:                 my ($uname,$udom) = split(/:/,$user);
                   6697:                 if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 6698:                     if (grep(/^all$/,@{$sections})) {
1.412     raeburn  6699:                         $secmatch = 1;
                   6700:                     } elsif ($usec eq '') {
1.420     albertel 6701:                         if (grep(/^none$/,@{$sections})) {
1.412     raeburn  6702:                             $secmatch = 1;
                   6703:                         }
                   6704:                     } else {
                   6705:                         if (grep(/^\Q$usec\E$/,@{$sections})) {
                   6706:                             $secmatch = 1;
                   6707:                         }
                   6708:                     }
                   6709:                     if (!$secmatch) {
                   6710:                         next;
                   6711:                     }
1.288     raeburn  6712:                 }
1.419     raeburn  6713:                 if ($usec eq '') {
                   6714:                     $usec = 'none';
                   6715:                 }
1.275     raeburn  6716:                 if ($uname ne '' && $udom ne '') {
1.630     raeburn  6717:                     if ($hidepriv) {
                   6718:                         if ((&Apache::lonnet::privileged($uname,$udom)) &&
                   6719:                             (!$nothide{$uname.':'.$udom})) {
                   6720:                             next;
                   6721:                         }
                   6722:                     }
1.503     raeburn  6723:                     if ($end > 0 && $end < $now) {
1.439     raeburn  6724:                         $status = 'previous';
                   6725:                     } elsif ($start > $now) {
                   6726:                         $status = 'future';
                   6727:                     } else {
                   6728:                         $status = 'active';
                   6729:                     }
1.277     albertel 6730:                     foreach my $type (keys(%{$types})) { 
1.275     raeburn  6731:                         if ($status eq $type) {
1.420     albertel 6732:                             if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419     raeburn  6733:                                 push(@{$$users{$role}{$user}},$type);
                   6734:                             }
1.288     raeburn  6735:                             $match = 1;
                   6736:                         }
                   6737:                     }
1.419     raeburn  6738:                     if (($match) && (ref($userdata) eq 'HASH')) {
                   6739:                         if (!exists($$userdata{$uname.':'.$udom})) {
                   6740: 			    &get_user_info($udom,$uname,\%idx,$userdata);
                   6741:                         }
1.420     albertel 6742:                         if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419     raeburn  6743:                             push(@{$seclists{$uname.':'.$udom}},$usec);
                   6744:                         }
1.609     raeburn  6745:                         if (ref($statushash) eq 'HASH') {
                   6746:                             $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
                   6747:                         }
1.275     raeburn  6748:                     }
                   6749:                 }
                   6750:             }
                   6751:         }
1.290     albertel 6752:         if (grep(/^ow$/,@{$roles})) {
1.279     raeburn  6753:             if ((defined($cdom)) && (defined($cnum))) {
                   6754:                 my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
                   6755:                 if ( defined($csettings{'internal.courseowner'}) ) {
                   6756:                     my $owner = $csettings{'internal.courseowner'};
1.609     raeburn  6757:                     next if ($owner eq '');
                   6758:                     my ($ownername,$ownerdom);
                   6759:                     if ($owner =~ /^([^:]+):([^:]+)$/) {
                   6760:                         $ownername = $1;
                   6761:                         $ownerdom = $2;
                   6762:                     } else {
                   6763:                         $ownername = $owner;
                   6764:                         $ownerdom = $cdom;
                   6765:                         $owner = $ownername.':'.$ownerdom;
1.439     raeburn  6766:                     }
                   6767:                     @{$$users{'ow'}{$owner}} = 'any';
1.290     albertel 6768:                     if (defined($userdata) && 
1.609     raeburn  6769: 			!exists($$userdata{$owner})) {
                   6770: 			&get_user_info($ownerdom,$ownername,\%idx,$userdata);
                   6771:                         if (!grep(/^none$/,@{$seclists{$owner}})) {
                   6772:                             push(@{$seclists{$owner}},'none');
                   6773:                         }
                   6774:                         if (ref($statushash) eq 'HASH') {
                   6775:                             $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419     raeburn  6776:                         }
1.290     albertel 6777: 		    }
1.279     raeburn  6778:                 }
                   6779:             }
                   6780:         }
1.419     raeburn  6781:         foreach my $user (keys(%seclists)) {
                   6782:             @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
                   6783:             $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
                   6784:         }
1.275     raeburn  6785:     }
                   6786:     return;
                   6787: }
                   6788: 
1.288     raeburn  6789: sub get_user_info {
                   6790:     my ($udom,$uname,$idx,$userdata) = @_;
1.289     albertel 6791:     $$userdata{$uname.':'.$udom}[$$idx{fullname}] = 
                   6792: 	&plainname($uname,$udom,'lastname');
1.291     albertel 6793:     $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297     raeburn  6794:     $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609     raeburn  6795:     my %idhash =  &Apache::lonnet::idrget($udom,($uname));
                   6796:     $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname}; 
1.288     raeburn  6797:     return;
                   6798: }
1.275     raeburn  6799: 
1.472     raeburn  6800: ###############################################
                   6801: 
                   6802: =pod
                   6803: 
                   6804: =item * &get_user_quota()
                   6805: 
                   6806: Retrieves quota assigned for storage of portfolio files for a user  
                   6807: 
                   6808: Incoming parameters:
                   6809: 1. user's username
                   6810: 2. user's domain
                   6811: 
                   6812: Returns:
1.536     raeburn  6813: 1. Disk quota (in Mb) assigned to student.
                   6814: 2. (Optional) Type of setting: custom or default
                   6815:    (individually assigned or default for user's 
                   6816:    institutional status).
                   6817: 3. (Optional) - User's institutional status (e.g., faculty, staff
                   6818:    or student - types as defined in localenroll::inst_usertypes 
                   6819:    for user's domain, which determines default quota for user.
                   6820: 4. (Optional) - Default quota which would apply to the user.
1.472     raeburn  6821: 
                   6822: If a value has been stored in the user's environment, 
1.536     raeburn  6823: it will return that, otherwise it returns the maximal default
                   6824: defined for the user's instituional status(es) in the domain.
1.472     raeburn  6825: 
                   6826: =cut
                   6827: 
                   6828: ###############################################
                   6829: 
                   6830: 
                   6831: sub get_user_quota {
                   6832:     my ($uname,$udom) = @_;
1.536     raeburn  6833:     my ($quota,$quotatype,$settingstatus,$defquota);
1.472     raeburn  6834:     if (!defined($udom)) {
                   6835:         $udom = $env{'user.domain'};
                   6836:     }
                   6837:     if (!defined($uname)) {
                   6838:         $uname = $env{'user.name'};
                   6839:     }
                   6840:     if (($udom eq '' || $uname eq '') ||
                   6841:         ($udom eq 'public') && ($uname eq 'public')) {
                   6842:         $quota = 0;
1.536     raeburn  6843:         $quotatype = 'default';
                   6844:         $defquota = 0; 
1.472     raeburn  6845:     } else {
1.536     raeburn  6846:         my $inststatus;
1.472     raeburn  6847:         if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
                   6848:             $quota = $env{'environment.portfolioquota'};
1.536     raeburn  6849:             $inststatus = $env{'environment.inststatus'};
1.472     raeburn  6850:         } else {
1.536     raeburn  6851:             my %userenv = 
                   6852:                 &Apache::lonnet::get('environment',['portfolioquota',
                   6853:                                      'inststatus'],$udom,$uname);
1.472     raeburn  6854:             my ($tmp) = keys(%userenv);
                   6855:             if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   6856:                 $quota = $userenv{'portfolioquota'};
1.536     raeburn  6857:                 $inststatus = $userenv{'inststatus'};
1.472     raeburn  6858:             } else {
                   6859:                 undef(%userenv);
                   6860:             }
                   6861:         }
1.536     raeburn  6862:         ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472     raeburn  6863:         if ($quota eq '') {
1.536     raeburn  6864:             $quota = $defquota;
                   6865:             $quotatype = 'default';
                   6866:         } else {
                   6867:             $quotatype = 'custom';
1.472     raeburn  6868:         }
                   6869:     }
1.536     raeburn  6870:     if (wantarray) {
                   6871:         return ($quota,$quotatype,$settingstatus,$defquota);
                   6872:     } else {
                   6873:         return $quota;
                   6874:     }
1.472     raeburn  6875: }
                   6876: 
                   6877: ###############################################
                   6878: 
                   6879: =pod
                   6880: 
                   6881: =item * &default_quota()
                   6882: 
1.536     raeburn  6883: Retrieves default quota assigned for storage of user portfolio files,
                   6884: given an (optional) user's institutional status.
1.472     raeburn  6885: 
                   6886: Incoming parameters:
                   6887: 1. domain
1.536     raeburn  6888: 2. (Optional) institutional status(es).  This is a : separated list of 
                   6889:    status types (e.g., faculty, staff, student etc.)
                   6890:    which apply to the user for whom the default is being retrieved.
                   6891:    If the institutional status string in undefined, the domain
                   6892:    default quota will be returned. 
1.472     raeburn  6893: 
                   6894: Returns:
                   6895: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536     raeburn  6896: 2. (Optional) institutional type which determined the value of the
                   6897:    default quota.
1.472     raeburn  6898: 
                   6899: If a value has been stored in the domain's configuration db,
                   6900: it will return that, otherwise it returns 20 (for backwards 
                   6901: compatibility with domains which have not set up a configuration
                   6902: db file; the original statically defined portfolio quota was 20 Mb). 
                   6903: 
1.536     raeburn  6904: If the user's status includes multiple types (e.g., staff and student),
                   6905: the largest default quota which applies to the user determines the
                   6906: default quota returned.
                   6907: 
1.472     raeburn  6908: =cut
                   6909: 
                   6910: ###############################################
                   6911: 
                   6912: 
                   6913: sub default_quota {
1.536     raeburn  6914:     my ($udom,$inststatus) = @_;
                   6915:     my ($defquota,$settingstatus);
                   6916:     my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622     raeburn  6917:                                             ['quotas'],$udom);
                   6918:     if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536     raeburn  6919:         if ($inststatus ne '') {
                   6920:             my @statuses = split(/:/,$inststatus);
                   6921:             foreach my $item (@statuses) {
1.711     raeburn  6922:                 if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
                   6923:                     if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
                   6924:                         if ($defquota eq '') {
                   6925:                             $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
                   6926:                             $settingstatus = $item;
                   6927:                         } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
                   6928:                             $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
                   6929:                             $settingstatus = $item;
                   6930:                         }
                   6931:                     }
                   6932:                 } else {
                   6933:                     if ($quotahash{'quotas'}{$item} ne '') {
                   6934:                         if ($defquota eq '') {
                   6935:                             $defquota = $quotahash{'quotas'}{$item};
                   6936:                             $settingstatus = $item;
                   6937:                         } elsif ($quotahash{'quotas'}{$item} > $defquota) {
                   6938:                             $defquota = $quotahash{'quotas'}{$item};
                   6939:                             $settingstatus = $item;
                   6940:                         }
1.536     raeburn  6941:                     }
                   6942:                 }
                   6943:             }
                   6944:         }
                   6945:         if ($defquota eq '') {
1.711     raeburn  6946:             if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
                   6947:                 $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
                   6948:             } else {
                   6949:                 $defquota = $quotahash{'quotas'}{'default'};
                   6950:             }
1.536     raeburn  6951:             $settingstatus = 'default';
                   6952:         }
                   6953:     } else {
                   6954:         $settingstatus = 'default';
                   6955:         $defquota = 20;
                   6956:     }
                   6957:     if (wantarray) {
                   6958:         return ($defquota,$settingstatus);
1.472     raeburn  6959:     } else {
1.536     raeburn  6960:         return $defquota;
1.472     raeburn  6961:     }
                   6962: }
                   6963: 
1.384     raeburn  6964: sub get_secgrprole_info {
                   6965:     my ($cdom,$cnum,$needroles,$type)  = @_;
                   6966:     my %sections_count = &get_sections($cdom,$cnum);
                   6967:     my @sections =  (sort {$a <=> $b} keys(%sections_count));
                   6968:     my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
                   6969:     my @groups = sort(keys(%curr_groups));
                   6970:     my $allroles = [];
                   6971:     my $rolehash;
                   6972:     my $accesshash = {
                   6973:                      active => 'Currently has access',
                   6974:                      future => 'Will have future access',
                   6975:                      previous => 'Previously had access',
                   6976:                   };
                   6977:     if ($needroles) {
                   6978:         $rolehash = {'all' => 'all'};
1.385     albertel 6979:         my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   6980: 	if (&Apache::lonnet::error(%user_roles)) {
                   6981: 	    undef(%user_roles);
                   6982: 	}
                   6983:         foreach my $item (keys(%user_roles)) {
1.384     raeburn  6984:             my ($role)=split(/\:/,$item,2);
                   6985:             if ($role eq 'cr') { next; }
                   6986:             if ($role =~ /^cr/) {
                   6987:                 $$rolehash{$role} = (split('/',$role))[3];
                   6988:             } else {
                   6989:                 $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
                   6990:             }
                   6991:         }
                   6992:         foreach my $key (sort(keys(%{$rolehash}))) {
                   6993:             push(@{$allroles},$key);
                   6994:         }
                   6995:         push (@{$allroles},'st');
                   6996:         $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
                   6997:     }
                   6998:     return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
                   6999: }
                   7000: 
1.555     raeburn  7001: sub user_picker {
1.627     raeburn  7002:     my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555     raeburn  7003:     my $currdom = $dom;
                   7004:     my %curr_selected = (
                   7005:                         srchin => 'dom',
1.580     raeburn  7006:                         srchby => 'lastname',
1.555     raeburn  7007:                       );
                   7008:     my $srchterm;
1.625     raeburn  7009:     if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555     raeburn  7010:         if ($srch->{'srchby'} ne '') {
                   7011:             $curr_selected{'srchby'} = $srch->{'srchby'};
                   7012:         }
                   7013:         if ($srch->{'srchin'} ne '') {
                   7014:             $curr_selected{'srchin'} = $srch->{'srchin'};
                   7015:         }
                   7016:         if ($srch->{'srchtype'} ne '') {
                   7017:             $curr_selected{'srchtype'} = $srch->{'srchtype'};
                   7018:         }
                   7019:         if ($srch->{'srchdomain'} ne '') {
                   7020:             $currdom = $srch->{'srchdomain'};
                   7021:         }
                   7022:         $srchterm = $srch->{'srchterm'};
                   7023:     }
                   7024:     my %lt=&Apache::lonlocal::texthash(
1.573     raeburn  7025:                     'usr'       => 'Search criteria',
1.563     raeburn  7026:                     'doma'      => 'Domain/institution to search',
1.558     albertel 7027:                     'uname'     => 'username',
                   7028:                     'lastname'  => 'last name',
1.555     raeburn  7029:                     'lastfirst' => 'last name, first name',
1.558     albertel 7030:                     'crs'       => 'in this course',
1.576     raeburn  7031:                     'dom'       => 'in selected LON-CAPA domain', 
1.558     albertel 7032:                     'alc'       => 'all LON-CAPA',
1.573     raeburn  7033:                     'instd'     => 'in institutional directory for selected domain',
1.558     albertel 7034:                     'exact'     => 'is',
                   7035:                     'contains'  => 'contains',
1.569     raeburn  7036:                     'begins'    => 'begins with',
1.571     raeburn  7037:                     'youm'      => "You must include some text to search for.",
                   7038:                     'thte'      => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
                   7039:                     'thet'      => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
                   7040:                     'yomc'      => "You must choose a domain when using an institutional directory search.",
                   7041:                     'ymcd'      => "You must choose a domain when using a domain search.",
                   7042:                     'whus'      => "When using searching by last,first you must include a comma as separator between last name and first name.",
                   7043:                     'whse'      => "When searching by last,first you must include at least one character in the first name.",
                   7044:                      'thfo'     => "The following need to be corrected before the search can be run:",
1.555     raeburn  7045:                                        );
1.563     raeburn  7046:     my $domform = &select_dom_form($currdom,'srchdomain',1,1);
                   7047:     my $srchinsel = ' <select name="srchin">';
1.555     raeburn  7048: 
                   7049:     my @srchins = ('crs','dom','alc','instd');
                   7050: 
                   7051:     foreach my $option (@srchins) {
                   7052:         # FIXME 'alc' option unavailable until 
                   7053:         #       loncreateuser::print_user_query_page()
                   7054:         #       has been completed.
                   7055:         next if ($option eq 'alc');
                   7056:         next if ($option eq 'crs' && !$env{'request.course.id'});
1.563     raeburn  7057:         if ($curr_selected{'srchin'} eq $option) {
                   7058:             $srchinsel .= ' 
                   7059:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7060:         } else {
                   7061:             $srchinsel .= '
                   7062:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7063:         }
1.555     raeburn  7064:     }
1.563     raeburn  7065:     $srchinsel .= "\n  </select>\n";
1.555     raeburn  7066: 
                   7067:     my $srchbysel =  ' <select name="srchby">';
1.580     raeburn  7068:     foreach my $option ('lastname','lastfirst','uname') {
1.555     raeburn  7069:         if ($curr_selected{'srchby'} eq $option) {
                   7070:             $srchbysel .= '
                   7071:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7072:         } else {
                   7073:             $srchbysel .= '
                   7074:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7075:          }
                   7076:     }
                   7077:     $srchbysel .= "\n  </select>\n";
                   7078: 
                   7079:     my $srchtypesel = ' <select name="srchtype">';
1.580     raeburn  7080:     foreach my $option ('begins','contains','exact') {
1.555     raeburn  7081:         if ($curr_selected{'srchtype'} eq $option) {
                   7082:             $srchtypesel .= '
                   7083:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7084:         } else {
                   7085:             $srchtypesel .= '
                   7086:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7087:         }
                   7088:     }
                   7089:     $srchtypesel .= "\n  </select>\n";
                   7090: 
1.558     albertel 7091:     my ($newuserscript,$new_user_create);
1.556     raeburn  7092: 
                   7093:     if ($forcenewuser) {
1.576     raeburn  7094:         if (ref($srch) eq 'HASH') {
                   7095:             if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627     raeburn  7096:                 if ($cancreate) {
                   7097:                     $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>';
                   7098:                 } else {
                   7099:                     my $helplink = ' href="javascript:helpMenu('."'display'".')"';
                   7100:                     my %usertypetext = (
                   7101:                         official   => 'institutional',
                   7102:                         unofficial => 'non-institutional',
                   7103:                     );
                   7104:                     $new_user_create = '<br /><span class="LC_warning">'.&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.").' '.&mt('Contact the <a[_1]>helpdesk</a> for assistance.',$helplink).'</span><br /><br />';
                   7105:                 }
1.576     raeburn  7106:             }
                   7107:         }
                   7108: 
1.556     raeburn  7109:         $newuserscript = <<"ENDSCRIPT";
                   7110: 
1.570     raeburn  7111: function setSearch(createnew,callingForm) {
1.556     raeburn  7112:     if (createnew == 1) {
1.570     raeburn  7113:         for (var i=0; i<callingForm.srchby.length; i++) {
                   7114:             if (callingForm.srchby.options[i].value == 'uname') {
                   7115:                 callingForm.srchby.selectedIndex = i;
1.556     raeburn  7116:             }
                   7117:         }
1.570     raeburn  7118:         for (var i=0; i<callingForm.srchin.length; i++) {
                   7119:             if ( callingForm.srchin.options[i].value == 'dom') {
                   7120: 		callingForm.srchin.selectedIndex = i;
1.556     raeburn  7121:             }
                   7122:         }
1.570     raeburn  7123:         for (var i=0; i<callingForm.srchtype.length; i++) {
                   7124:             if (callingForm.srchtype.options[i].value == 'exact') {
                   7125:                 callingForm.srchtype.selectedIndex = i;
1.556     raeburn  7126:             }
                   7127:         }
1.570     raeburn  7128:         for (var i=0; i<callingForm.srchdomain.length; i++) {
                   7129:             if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
                   7130:                 callingForm.srchdomain.selectedIndex = i;
1.556     raeburn  7131:             }
                   7132:         }
                   7133:     }
                   7134: }
                   7135: ENDSCRIPT
1.558     albertel 7136: 
1.556     raeburn  7137:     }
                   7138: 
1.555     raeburn  7139:     my $output = <<"END_BLOCK";
1.556     raeburn  7140: <script type="text/javascript">
1.570     raeburn  7141: function validateEntry(callingForm) {
1.558     albertel 7142: 
1.556     raeburn  7143:     var checkok = 1;
1.558     albertel 7144:     var srchin;
1.570     raeburn  7145:     for (var i=0; i<callingForm.srchin.length; i++) {
                   7146: 	if ( callingForm.srchin[i].checked ) {
                   7147: 	    srchin = callingForm.srchin[i].value;
1.558     albertel 7148: 	}
                   7149:     }
                   7150: 
1.570     raeburn  7151:     var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
                   7152:     var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
                   7153:     var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
                   7154:     var srchterm =  callingForm.srchterm.value;
                   7155:     var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556     raeburn  7156:     var msg = "";
                   7157: 
                   7158:     if (srchterm == "") {
                   7159:         checkok = 0;
1.571     raeburn  7160:         msg += "$lt{'youm'}\\n";
1.556     raeburn  7161:     }
                   7162: 
1.569     raeburn  7163:     if (srchtype== 'begins') {
                   7164:         if (srchterm.length < 2) {
                   7165:             checkok = 0;
1.571     raeburn  7166:             msg += "$lt{'thte'}\\n";
1.569     raeburn  7167:         }
                   7168:     }
                   7169: 
1.556     raeburn  7170:     if (srchtype== 'contains') {
                   7171:         if (srchterm.length < 3) {
                   7172:             checkok = 0;
1.571     raeburn  7173:             msg += "$lt{'thet'}\\n";
1.556     raeburn  7174:         }
                   7175:     }
                   7176:     if (srchin == 'instd') {
                   7177:         if (srchdomain == '') {
                   7178:             checkok = 0;
1.571     raeburn  7179:             msg += "$lt{'yomc'}\\n";
1.556     raeburn  7180:         }
                   7181:     }
                   7182:     if (srchin == 'dom') {
                   7183:         if (srchdomain == '') {
                   7184:             checkok = 0;
1.571     raeburn  7185:             msg += "$lt{'ymcd'}\\n";
1.556     raeburn  7186:         }
                   7187:     }
                   7188:     if (srchby == 'lastfirst') {
                   7189:         if (srchterm.indexOf(",") == -1) {
                   7190:             checkok = 0;
1.571     raeburn  7191:             msg += "$lt{'whus'}\\n";
1.556     raeburn  7192:         }
                   7193:         if (srchterm.indexOf(",") == srchterm.length -1) {
                   7194:             checkok = 0;
1.571     raeburn  7195:             msg += "$lt{'whse'}\\n";
1.556     raeburn  7196:         }
                   7197:     }
                   7198:     if (checkok == 0) {
1.571     raeburn  7199:         alert("$lt{'thfo'}\\n"+msg);
1.556     raeburn  7200:         return;
                   7201:     }
                   7202:     if (checkok == 1) {
1.570     raeburn  7203:         callingForm.submit();
1.556     raeburn  7204:     }
                   7205: }
                   7206: 
                   7207: $newuserscript
                   7208: 
                   7209: </script>
1.558     albertel 7210: 
                   7211: $new_user_create
                   7212: 
1.555     raeburn  7213: <table>
1.558     albertel 7214:  <tr>
1.573     raeburn  7215:   <td>$lt{'doma'}:</td>
                   7216:   <td>$domform</td>
                   7217:   </td>
                   7218:  </tr>
                   7219:  <tr>
                   7220:   <td>$lt{'usr'}:</td>
1.563     raeburn  7221:   <td>$srchbysel
                   7222:       $srchtypesel 
                   7223:       <input type="text" size="15" name="srchterm" value="$srchterm" />
1.564     albertel 7224:       $srchinsel 
1.563     raeburn  7225:   </td>
                   7226:  </tr>
1.555     raeburn  7227: </table>
                   7228: <br />
                   7229: END_BLOCK
1.558     albertel 7230: 
1.555     raeburn  7231:     return $output;
                   7232: }
                   7233: 
1.612     raeburn  7234: sub user_rule_check {
1.615     raeburn  7235:     my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612     raeburn  7236:     my $response;
                   7237:     if (ref($usershash) eq 'HASH') {
                   7238:         foreach my $user (keys(%{$usershash})) {
                   7239:             my ($uname,$udom) = split(/:/,$user);
                   7240:             next if ($udom eq '' || $uname eq '');
1.615     raeburn  7241:             my ($id,$newuser);
1.612     raeburn  7242:             if (ref($usershash->{$user}) eq 'HASH') {
1.615     raeburn  7243:                 $newuser = $usershash->{$user}->{'newuser'};
1.612     raeburn  7244:                 $id = $usershash->{$user}->{'id'};
                   7245:             }
                   7246:             my $inst_response;
                   7247:             if (ref($checks) eq 'HASH') {
                   7248:                 if (defined($checks->{'username'})) {
1.615     raeburn  7249:                     ($inst_response,%{$inst_results->{$user}}) = 
1.612     raeburn  7250:                         &Apache::lonnet::get_instuser($udom,$uname);
                   7251:                 } elsif (defined($checks->{'id'})) {
1.615     raeburn  7252:                     ($inst_response,%{$inst_results->{$user}}) =
1.612     raeburn  7253:                         &Apache::lonnet::get_instuser($udom,undef,$id);
                   7254:                 }
1.615     raeburn  7255:             } else {
                   7256:                 ($inst_response,%{$inst_results->{$user}}) =
                   7257:                     &Apache::lonnet::get_instuser($udom,$uname);
                   7258:                 return;
1.612     raeburn  7259:             }
1.615     raeburn  7260:             if (!$got_rules->{$udom}) {
1.612     raeburn  7261:                 my %domconfig = &Apache::lonnet::get_dom('configuration',
                   7262:                                                   ['usercreation'],$udom);
                   7263:                 if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615     raeburn  7264:                     foreach my $item ('username','id') {
1.612     raeburn  7265:                         if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
                   7266:                             $$curr_rules{$udom}{$item} = 
                   7267:                                 $domconfig{'usercreation'}{$item.'_rule'};
1.585     raeburn  7268:                         }
                   7269:                     }
                   7270:                 }
1.615     raeburn  7271:                 $got_rules->{$udom} = 1;  
1.585     raeburn  7272:             }
1.612     raeburn  7273:             foreach my $item (keys(%{$checks})) {
                   7274:                 if (ref($$curr_rules{$udom}) eq 'HASH') {
                   7275:                     if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
                   7276:                         if (@{$$curr_rules{$udom}{$item}} > 0) {
                   7277:                             my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
                   7278:                             foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
                   7279:                                 if ($rule_check{$rule}) {
                   7280:                                     $$rulematch{$user}{$item} = $rule;
                   7281:                                     if ($inst_response eq 'ok') {
1.615     raeburn  7282:                                         if (ref($inst_results) eq 'HASH') {
                   7283:                                             if (ref($inst_results->{$user}) eq 'HASH') {
                   7284:                                                 if (keys(%{$inst_results->{$user}}) == 0) {
                   7285:                                                     $$alerts{$item}{$udom}{$uname} = 1;
                   7286:                                                 }
1.612     raeburn  7287:                                             }
                   7288:                                         }
1.615     raeburn  7289:                                     }
                   7290:                                     last;
1.585     raeburn  7291:                                 }
                   7292:                             }
                   7293:                         }
                   7294:                     }
                   7295:                 }
                   7296:             }
                   7297:         }
                   7298:     }
1.612     raeburn  7299:     return;
                   7300: }
                   7301: 
                   7302: sub user_rule_formats {
                   7303:     my ($domain,$domdesc,$curr_rules,$check) = @_;
                   7304:     my %text = ( 
                   7305:                  'username' => 'Usernames',
                   7306:                  'id'       => 'IDs',
                   7307:                );
                   7308:     my $output;
                   7309:     my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
                   7310:     if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
                   7311:         if (@{$ruleorder} > 0) {
                   7312:             $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>';
                   7313:             foreach my $rule (@{$ruleorder}) {
                   7314:                 if (ref($curr_rules) eq 'ARRAY') {
                   7315:                     if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
                   7316:                         if (ref($rules->{$rule}) eq 'HASH') {
                   7317:                             $output .= '<li>'.$rules->{$rule}{'name'}.': '.
                   7318:                                         $rules->{$rule}{'desc'}.'</li>';
                   7319:                         }
                   7320:                     }
                   7321:                 }
                   7322:             }
                   7323:             $output .= '</ul>';
                   7324:         }
                   7325:     }
                   7326:     return $output;
                   7327: }
                   7328: 
                   7329: sub instrule_disallow_msg {
1.615     raeburn  7330:     my ($checkitem,$domdesc,$count,$mode) = @_;
1.612     raeburn  7331:     my $response;
                   7332:     my %text = (
                   7333:                   item   => 'username',
                   7334:                   items  => 'usernames',
                   7335:                   match  => 'matches',
                   7336:                   do     => 'does',
                   7337:                   action => 'a username',
                   7338:                   one    => 'one',
                   7339:                );
                   7340:     if ($count > 1) {
                   7341:         $text{'item'} = 'usernames';
                   7342:         $text{'match'} ='match';
                   7343:         $text{'do'} = 'do';
                   7344:         $text{'action'} = 'usernames',
                   7345:         $text{'one'} = 'ones';
                   7346:     }
                   7347:     if ($checkitem eq 'id') {
                   7348:         $text{'items'} = 'IDs';
                   7349:         $text{'item'} = 'ID';
                   7350:         $text{'action'} = 'an ID';
1.615     raeburn  7351:         if ($count > 1) {
                   7352:             $text{'item'} = 'IDs';
                   7353:             $text{'action'} = 'IDs';
                   7354:         }
1.612     raeburn  7355:     }
1.674     bisitz   7356:     $response = &mt("The $text{'item'} you chose $text{'match'} the format of $text{'items'} defined for [_1], but the $text{'item'} $text{'do'} not exist in the institutional directory.",'<span class="LC_cusr_emph">'.$domdesc.'</span>').'<br />';
1.615     raeburn  7357:     if ($mode eq 'upload') {
                   7358:         if ($checkitem eq 'username') {
                   7359:             $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'}.");
                   7360:         } elsif ($checkitem eq 'id') {
1.674     bisitz   7361:             $response .= &mt("Either upload a file which includes $text{'action'} with a different format --  $text{'one'} that will not conflict with 'official' institutional $text{'items'}, or when associating fields with data columns, omit an association for the Student/Employee ID field.");
1.615     raeburn  7362:         }
1.669     raeburn  7363:     } elsif ($mode eq 'selfcreate') {
                   7364:         if ($checkitem eq 'id') {
                   7365:             $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.");
                   7366:         }
1.615     raeburn  7367:     } else {
                   7368:         if ($checkitem eq 'username') {
                   7369:             $response .= &mt("You must choose $text{'action'} with a different format --  $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
                   7370:         } elsif ($checkitem eq 'id') {
                   7371:             $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.");
                   7372:         }
1.612     raeburn  7373:     }
                   7374:     return $response;
1.585     raeburn  7375: }
                   7376: 
1.624     raeburn  7377: sub personal_data_fieldtitles {
                   7378:     my %fieldtitles = &Apache::lonlocal::texthash (
                   7379:                         id => 'Student/Employee ID',
                   7380:                         permanentemail => 'E-mail address',
                   7381:                         lastname => 'Last Name',
                   7382:                         firstname => 'First Name',
                   7383:                         middlename => 'Middle Name',
                   7384:                         generation => 'Generation',
                   7385:                         gen => 'Generation',
                   7386:                    );
                   7387:     return %fieldtitles;
                   7388: }
                   7389: 
1.642     raeburn  7390: sub sorted_inst_types {
                   7391:     my ($dom) = @_;
                   7392:     my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
                   7393:     my $othertitle = &mt('All users');
                   7394:     if ($env{'request.course.id'}) {
1.668     raeburn  7395:         $othertitle  = &mt('Any users');
1.642     raeburn  7396:     }
                   7397:     my @types;
                   7398:     if (ref($order) eq 'ARRAY') {
                   7399:         @types = @{$order};
                   7400:     }
                   7401:     if (@types == 0) {
                   7402:         if (ref($usertypes) eq 'HASH') {
                   7403:             @types = sort(keys(%{$usertypes}));
                   7404:         }
                   7405:     }
                   7406:     if (keys(%{$usertypes}) > 0) {
                   7407:         $othertitle = &mt('Other users');
                   7408:     }
                   7409:     return ($othertitle,$usertypes,\@types);
                   7410: }
                   7411: 
1.645     raeburn  7412: sub get_institutional_codes {
                   7413:     my ($settings,$allcourses,$LC_code) = @_;
                   7414: # Get complete list of course sections to update
                   7415:     my @currsections = ();
                   7416:     my @currxlists = ();
                   7417:     my $coursecode = $$settings{'internal.coursecode'};
                   7418: 
                   7419:     if ($$settings{'internal.sectionnums'} ne '') {
                   7420:         @currsections = split(/,/,$$settings{'internal.sectionnums'});
                   7421:     }
                   7422: 
                   7423:     if ($$settings{'internal.crosslistings'} ne '') {
                   7424:         @currxlists = split(/,/,$$settings{'internal.crosslistings'});
                   7425:     }
                   7426: 
                   7427:     if (@currxlists > 0) {
                   7428:         foreach (@currxlists) {
                   7429:             if (m/^([^:]+):(\w*)$/) {
                   7430:                 unless (grep/^$1$/,@{$allcourses}) {
                   7431:                     push @{$allcourses},$1;
                   7432:                     $$LC_code{$1} = $2;
                   7433:                 }
                   7434:             }
                   7435:         }
                   7436:     }
                   7437:  
                   7438:     if (@currsections > 0) {
                   7439:         foreach (@currsections) {
                   7440:             if (m/^(\w+):(\w*)$/) {
                   7441:                 my $sec = $coursecode.$1;
                   7442:                 my $lc_sec = $2;
                   7443:                 unless (grep/^$sec$/,@{$allcourses}) {
                   7444:                     push @{$allcourses},$sec;
                   7445:                     $$LC_code{$sec} = $lc_sec;
                   7446:                 }
                   7447:             }
                   7448:         }
                   7449:     }
                   7450:     return;
                   7451: }
                   7452: 
1.112     bowersj2 7453: =pod
                   7454: 
1.549     albertel 7455: =back
                   7456: 
                   7457: =head1 HTTP Helpers
                   7458: 
                   7459: =over 4
                   7460: 
1.648     raeburn  7461: =item * &get_unprocessed_cgi($query,$possible_names)
1.112     bowersj2 7462: 
1.258     albertel 7463: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112     bowersj2 7464: $query.  The parameters listed in $possible_names (an array reference),
1.258     albertel 7465: will be set in $env{'form.name'} if they do not already exist.
1.112     bowersj2 7466: 
                   7467: Typically called with $ENV{'QUERY_STRING'} as the first parameter.  
                   7468: $possible_names is an ref to an array of form element names.  As an example:
                   7469: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258     albertel 7470: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112     bowersj2 7471: 
                   7472: =cut
1.1       albertel 7473: 
1.6       albertel 7474: sub get_unprocessed_cgi {
1.25      albertel 7475:   my ($query,$possible_names)= @_;
1.26      matthew  7476:   # $Apache::lonxml::debug=1;
1.356     albertel 7477:   foreach my $pair (split(/&/,$query)) {
                   7478:     my ($name, $value) = split(/=/,$pair);
1.369     www      7479:     $name = &unescape($name);
1.25      albertel 7480:     if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
                   7481:       $value =~ tr/+/ /;
                   7482:       $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258     albertel 7483:       unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25      albertel 7484:     }
1.16      harris41 7485:   }
1.6       albertel 7486: }
                   7487: 
1.112     bowersj2 7488: =pod
                   7489: 
1.648     raeburn  7490: =item * &cacheheader() 
1.112     bowersj2 7491: 
                   7492: returns cache-controlling header code
                   7493: 
                   7494: =cut
                   7495: 
1.7       albertel 7496: sub cacheheader {
1.258     albertel 7497:     unless ($env{'request.method'} eq 'GET') { return ''; }
1.216     albertel 7498:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
                   7499:     my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7       albertel 7500:                 <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
                   7501:                 <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216     albertel 7502:     return $output;
1.7       albertel 7503: }
                   7504: 
1.112     bowersj2 7505: =pod
                   7506: 
1.648     raeburn  7507: =item * &no_cache($r) 
1.112     bowersj2 7508: 
                   7509: specifies header code to not have cache
                   7510: 
                   7511: =cut
                   7512: 
1.9       albertel 7513: sub no_cache {
1.216     albertel 7514:     my ($r) = @_;
                   7515:     if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258     albertel 7516: 	$env{'request.method'} ne 'GET') { return ''; }
1.216     albertel 7517:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
                   7518:     $r->no_cache(1);
                   7519:     $r->header_out("Expires" => $date);
                   7520:     $r->header_out("Pragma" => "no-cache");
1.123     www      7521: }
                   7522: 
                   7523: sub content_type {
1.181     albertel 7524:     my ($r,$type,$charset) = @_;
1.299     foxr     7525:     if ($r) {
                   7526: 	#  Note that printout.pl calls this with undef for $r.
                   7527: 	&no_cache($r);
                   7528:     }
1.258     albertel 7529:     if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181     albertel 7530:     unless ($charset) {
                   7531: 	$charset=&Apache::lonlocal::current_encoding;
                   7532:     }
                   7533:     if ($charset) { $type.='; charset='.$charset; }
                   7534:     if ($r) {
                   7535: 	$r->content_type($type);
                   7536:     } else {
                   7537: 	print("Content-type: $type\n\n");
                   7538:     }
1.9       albertel 7539: }
1.25      albertel 7540: 
1.112     bowersj2 7541: =pod
                   7542: 
1.648     raeburn  7543: =item * &add_to_env($name,$value) 
1.112     bowersj2 7544: 
1.258     albertel 7545: adds $name to the %env hash with value
1.112     bowersj2 7546: $value, if $name already exists, the entry is converted to an array
                   7547: reference and $value is added to the array.
                   7548: 
                   7549: =cut
                   7550: 
1.25      albertel 7551: sub add_to_env {
                   7552:   my ($name,$value)=@_;
1.258     albertel 7553:   if (defined($env{$name})) {
                   7554:     if (ref($env{$name})) {
1.25      albertel 7555:       #already have multiple values
1.258     albertel 7556:       push(@{ $env{$name} },$value);
1.25      albertel 7557:     } else {
                   7558:       #first time seeing multiple values, convert hash entry to an arrayref
1.258     albertel 7559:       my $first=$env{$name};
                   7560:       undef($env{$name});
                   7561:       push(@{ $env{$name} },$first,$value);
1.25      albertel 7562:     }
                   7563:   } else {
1.258     albertel 7564:     $env{$name}=$value;
1.25      albertel 7565:   }
1.31      albertel 7566: }
1.149     albertel 7567: 
                   7568: =pod
                   7569: 
1.648     raeburn  7570: =item * &get_env_multiple($name) 
1.149     albertel 7571: 
1.258     albertel 7572: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149     albertel 7573: values may be defined and end up as an array ref.
                   7574: 
                   7575: returns an array of values
                   7576: 
                   7577: =cut
                   7578: 
                   7579: sub get_env_multiple {
                   7580:     my ($name) = @_;
                   7581:     my @values;
1.258     albertel 7582:     if (defined($env{$name})) {
1.149     albertel 7583:         # exists is it an array
1.258     albertel 7584:         if (ref($env{$name})) {
                   7585:             @values=@{ $env{$name} };
1.149     albertel 7586:         } else {
1.258     albertel 7587:             $values[0]=$env{$name};
1.149     albertel 7588:         }
                   7589:     }
                   7590:     return(@values);
                   7591: }
                   7592: 
1.660     raeburn  7593: sub ask_for_embedded_content {
                   7594:     my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
                   7595:     my $upload_output = '
                   7596:    <form name="upload_embedded" action="'.$actionurl.'"
                   7597:                   method="post" enctype="multipart/form-data">';
                   7598:     $upload_output .= $state;
1.661     raeburn  7599:     $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
1.660     raeburn  7600: 
                   7601:     my $num = 0;
                   7602:     foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
                   7603:         $upload_output .= &start_data_table_row().
                   7604:             '<td>'.$embed_file.'</td><td>';
                   7605:         if ($args->{'ignore_remote_references'}
                   7606:             && $embed_file =~ m{^\w+://}) {
                   7607:             $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
                   7608:         } elsif ($args->{'error_on_invalid_names'}
                   7609:             && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
                   7610: 
                   7611:             $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
                   7612: 
                   7613:         } else {
                   7614:             $upload_output .='
1.661     raeburn  7615:            <input name="embedded_item_'.$num.'" type="file" value="" />
1.660     raeburn  7616:            <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
                   7617:             my $attrib = join(':',@{$$allfiles{$embed_file}});
                   7618:             $upload_output .=
                   7619:                 "\n\t\t".
                   7620:                 '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
                   7621:                 $attrib.'" />';
                   7622:             if (exists($$codebase{$embed_file})) {
                   7623:                 $upload_output .=
                   7624:                     "\n\t\t".
                   7625:                     '<input name="codebase_'.$num.'" type="hidden" value="'.
                   7626:                     &escape($$codebase{$embed_file}).'" />';
                   7627:             }
                   7628:         }
                   7629:         $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
                   7630:         $num++;
                   7631:     }
                   7632:     $upload_output .= &Apache::loncommon::end_data_table().'<br />
                   7633:    <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
                   7634:    <input type ="submit" value="'.&mt('Upload Listed Files').'" />
                   7635:    '.&mt('(only files for which a location has been provided will be uploaded)').'
                   7636:    </form>';
                   7637:     return $upload_output;
                   7638: }
                   7639: 
1.661     raeburn  7640: sub upload_embedded {
                   7641:     my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
                   7642:         $current_disk_usage) = @_;
                   7643:     my $output;
                   7644:     for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
                   7645:         next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
                   7646:         my $orig_uploaded_filename =
                   7647:             $env{'form.embedded_item_'.$i.'.filename'};
                   7648: 
                   7649:         $env{'form.embedded_orig_'.$i} =
                   7650:             &unescape($env{'form.embedded_orig_'.$i});
                   7651:         my ($path,$fname) =
                   7652:             ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
                   7653:         # no path, whole string is fname
                   7654:         if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
                   7655: 
                   7656:         $path = $env{'form.currentpath'}.$path;
                   7657:         $fname = &Apache::lonnet::clean_filename($fname);
                   7658:         # See if there is anything left
                   7659:         next if ($fname eq '');
                   7660: 
                   7661:         # Check if file already exists as a file or directory.
                   7662:         my ($state,$msg);
                   7663:         if ($context eq 'portfolio') {
                   7664:             my $port_path = $dirpath;
                   7665:             if ($group ne '') {
                   7666:                 $port_path = "groups/$group/$port_path";
                   7667:             }
                   7668:             ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
                   7669:                                               $dir_root,$port_path,$disk_quota,
                   7670:                                               $current_disk_usage,$uname,$udom);
                   7671:             if ($state eq 'will_exceed_quota'
                   7672:                 || $state eq 'file_locked'
                   7673:                 || $state eq 'file_exists' ) {
                   7674:                 $output .= $msg;
                   7675:                 next;
                   7676:             }
                   7677:         } elsif (($context eq 'author') || ($context eq 'testbank')) {
                   7678:             ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
                   7679:             if ($state eq 'exists') {
                   7680:                 $output .= $msg;
                   7681:                 next;
                   7682:             }
                   7683:         }
                   7684:         # Check if extension is valid
                   7685:         if (($fname =~ /\.(\w+)$/) &&
                   7686:             (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
                   7687:             $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
                   7688:             next;
                   7689:         } elsif (($fname =~ /\.(\w+)$/) &&
                   7690:                  (!defined(&Apache::loncommon::fileembstyle($1)))) {
                   7691:             $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
                   7692:             next;
                   7693:         } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
                   7694:             $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
                   7695:             next;
                   7696:         }
                   7697: 
                   7698:         $env{'form.embedded_item_'.$i.'.filename'}=$fname;
                   7699:         if ($context eq 'portfolio') {
                   7700:             my $result=
                   7701:                 &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
                   7702:                                                 $dirpath.$path);
                   7703:             if ($result !~ m|^/uploaded/|) {
                   7704:                 $output .= '<span class="LC_error">'
                   7705:                       .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
                   7706:                            ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
                   7707:                       .'</span><br />';
                   7708:                 next;
                   7709:             } else {
                   7710:                 $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
                   7711:                            $path.$fname.'</span>').'</p>';     
                   7712:             }
                   7713:         } else {
                   7714: # Save the file
                   7715:             my $target = $env{'form.embedded_item_'.$i};
                   7716:             my $fullpath = $dir_root.$dirpath.'/'.$path;
                   7717:             my $dest = $fullpath.$fname;
                   7718:             my $url = $url_root.$dirpath.'/'.$path.$fname;
                   7719:             my @parts=split(/\//,$fullpath);
                   7720:             my $count;
                   7721:             my $filepath = $dir_root;
                   7722:             for ($count=4;$count<=$#parts;$count++) {
                   7723:                 $filepath .= "/$parts[$count]";
                   7724:                 if ((-e $filepath)!=1) {
                   7725:                     mkdir($filepath,0770);
                   7726:                 }
                   7727:             }
                   7728:             my $fh;
                   7729:             if (!open($fh,'>'.$dest)) {
                   7730:                 &Apache::lonnet::logthis('Failed to create '.$dest);
                   7731:                 $output .= '<span class="LC_error">'.
                   7732:                            &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
                   7733:                            '</span><br />';
                   7734:             } else {
                   7735:                 if (!print $fh $env{'form.embedded_item_'.$i}) {
                   7736:                     &Apache::lonnet::logthis('Failed to write to '.$dest);
                   7737:                     $output .= '<span class="LC_error">'.
                   7738:                               &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
                   7739:                               '</span><br />';
                   7740:                 } else {
                   7741:                     if ($context eq 'testbank') {
                   7742:                         $output .= &mt('Embedded file uploaded successfully:').
                   7743:                                    '&nbsp;<a href="'.$url.'">'.
                   7744:                                    $orig_uploaded_filename.'</a><br />';
                   7745:                     } else {
1.705     tempelho 7746:                         $output .= '<span class=\"LC_fontsize_large\">'.
1.661     raeburn  7747:                                    &mt('View embedded file: [_1]','<a href="'.$url.'">'.
1.705     tempelho 7748:                                    $orig_uploaded_filename.'</a>').'</span><br />';
1.661     raeburn  7749:                     }
                   7750:                 }
                   7751:                 close($fh);
                   7752:             }
                   7753:         }
                   7754:     }
                   7755:     return $output;
                   7756: }
                   7757: 
                   7758: sub check_for_existing {
                   7759:     my ($path,$fname,$element) = @_;
                   7760:     my ($state,$msg);
                   7761:     if (-d $path.'/'.$fname) {
                   7762:         $state = 'exists';
                   7763:         $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
                   7764:     } elsif (-e $path.'/'.$fname) {
                   7765:         $state = 'exists';
                   7766:         $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
                   7767:     }
                   7768:     if ($state eq 'exists') {
                   7769:         $msg = '<span class="LC_error">'.$msg.'</span><br />';
                   7770:     }
                   7771:     return ($state,$msg);
                   7772: }
                   7773: 
                   7774: sub check_for_upload {
                   7775:     my ($path,$fname,$group,$element,$portfolio_root,$port_path,
                   7776:         $disk_quota,$current_disk_usage,$uname,$udom) = @_;
                   7777:     my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
                   7778:     my $getpropath = 1;
                   7779:     my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
                   7780:                                             $getpropath);
                   7781:     my $found_file = 0;
                   7782:     my $locked_file = 0;
                   7783:     foreach my $line (@dir_list) {
                   7784:         my ($file_name)=split(/\&/,$line,2);
                   7785:         if ($file_name eq $fname){
                   7786:             $file_name = $path.$file_name;
                   7787:             if ($group ne '') {
                   7788:                 $file_name = $group.$file_name;
                   7789:             }
                   7790:             $found_file = 1;
                   7791:             if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
                   7792:                 $locked_file = 1;
                   7793:             }
                   7794:         }
                   7795:     }
                   7796:     if (($current_disk_usage + $filesize) > $disk_quota){
                   7797:         my $msg = '<span class="LC_error">'.
                   7798:                 &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
                   7799:                   '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
                   7800:         return ('will_exceed_quota',$msg);
                   7801:     } elsif ($found_file) {
                   7802:         if ($locked_file) {
                   7803:             my $msg = '<span class="LC_error">';
                   7804:             $msg .= &mt('Unable to upload [_1]. A locked file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>','<span class="LC_filename">'.$port_path.$env{'form.currentpath'}.'</span>');
                   7805:             $msg .= '</span><br />';
                   7806:             $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
                   7807:             return ('file_locked',$msg);
                   7808:         } else {
                   7809:             my $msg = '<span class="LC_error">';
                   7810:             $msg .= &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$port_path.$env{'form.currentpath'});
                   7811:             $msg .= '</span>';
                   7812:             $msg .= '<br />';
                   7813:             $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
                   7814:             return ('file_exists',$msg);
                   7815:         }
                   7816:     }
                   7817: }
                   7818: 
1.31      albertel 7819: 
1.41      ng       7820: =pod
1.45      matthew  7821: 
1.464     albertel 7822: =back
1.41      ng       7823: 
1.112     bowersj2 7824: =head1 CSV Upload/Handling functions
1.38      albertel 7825: 
1.41      ng       7826: =over 4
                   7827: 
1.648     raeburn  7828: =item * &upfile_store($r)
1.41      ng       7829: 
                   7830: Store uploaded file, $r should be the HTTP Request object,
1.258     albertel 7831: needs $env{'form.upfile'}
1.41      ng       7832: returns $datatoken to be put into hidden field
                   7833: 
                   7834: =cut
1.31      albertel 7835: 
                   7836: sub upfile_store {
                   7837:     my $r=shift;
1.258     albertel 7838:     $env{'form.upfile'}=~s/\r/\n/gs;
                   7839:     $env{'form.upfile'}=~s/\f/\n/gs;
                   7840:     $env{'form.upfile'}=~s/\n+/\n/gs;
                   7841:     $env{'form.upfile'}=~s/\n+$//gs;
1.31      albertel 7842: 
1.258     albertel 7843:     my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
                   7844: 	'_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31      albertel 7845:     {
1.158     raeburn  7846:         my $datafile = $r->dir_config('lonDaemons').
                   7847:                            '/tmp/'.$datatoken.'.tmp';
                   7848:         if ( open(my $fh,">$datafile") ) {
1.258     albertel 7849:             print $fh $env{'form.upfile'};
1.158     raeburn  7850:             close($fh);
                   7851:         }
1.31      albertel 7852:     }
                   7853:     return $datatoken;
                   7854: }
                   7855: 
1.56      matthew  7856: =pod
                   7857: 
1.648     raeburn  7858: =item * &load_tmp_file($r)
1.41      ng       7859: 
                   7860: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258     albertel 7861: needs $env{'form.datatoken'},
                   7862: sets $env{'form.upfile'} to the contents of the file
1.41      ng       7863: 
                   7864: =cut
1.31      albertel 7865: 
                   7866: sub load_tmp_file {
                   7867:     my $r=shift;
                   7868:     my @studentdata=();
                   7869:     {
1.158     raeburn  7870:         my $studentfile = $r->dir_config('lonDaemons').
1.258     albertel 7871:                               '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158     raeburn  7872:         if ( open(my $fh,"<$studentfile") ) {
                   7873:             @studentdata=<$fh>;
                   7874:             close($fh);
                   7875:         }
1.31      albertel 7876:     }
1.258     albertel 7877:     $env{'form.upfile'}=join('',@studentdata);
1.31      albertel 7878: }
                   7879: 
1.56      matthew  7880: =pod
                   7881: 
1.648     raeburn  7882: =item * &upfile_record_sep()
1.41      ng       7883: 
                   7884: Separate uploaded file into records
                   7885: returns array of records,
1.258     albertel 7886: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41      ng       7887: 
                   7888: =cut
1.31      albertel 7889: 
                   7890: sub upfile_record_sep {
1.258     albertel 7891:     if ($env{'form.upfiletype'} eq 'xml') {
1.31      albertel 7892:     } else {
1.248     albertel 7893: 	my @records;
1.258     albertel 7894: 	foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248     albertel 7895: 	    if ($line=~/^\s*$/) { next; }
                   7896: 	    push(@records,$line);
                   7897: 	}
                   7898: 	return @records;
1.31      albertel 7899:     }
                   7900: }
                   7901: 
1.56      matthew  7902: =pod
                   7903: 
1.648     raeburn  7904: =item * &record_sep($record)
1.41      ng       7905: 
1.258     albertel 7906: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41      ng       7907: 
                   7908: =cut
                   7909: 
1.263     www      7910: sub takeleft {
                   7911:     my $index=shift;
                   7912:     return substr('0000'.$index,-4,4);
                   7913: }
                   7914: 
1.31      albertel 7915: sub record_sep {
                   7916:     my $record=shift;
                   7917:     my %components=();
1.258     albertel 7918:     if ($env{'form.upfiletype'} eq 'xml') {
                   7919:     } elsif ($env{'form.upfiletype'} eq 'space') {
1.31      albertel 7920:         my $i=0;
1.356     albertel 7921:         foreach my $field (split(/\s+/,$record)) {
1.31      albertel 7922:             $field=~s/^(\"|\')//;
                   7923:             $field=~s/(\"|\')$//;
1.263     www      7924:             $components{&takeleft($i)}=$field;
1.31      albertel 7925:             $i++;
                   7926:         }
1.258     albertel 7927:     } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31      albertel 7928:         my $i=0;
1.356     albertel 7929:         foreach my $field (split(/\t/,$record)) {
1.31      albertel 7930:             $field=~s/^(\"|\')//;
                   7931:             $field=~s/(\"|\')$//;
1.263     www      7932:             $components{&takeleft($i)}=$field;
1.31      albertel 7933:             $i++;
                   7934:         }
                   7935:     } else {
1.561     www      7936:         my $separator=',';
1.480     banghart 7937:         if ($env{'form.upfiletype'} eq 'semisv') {
1.561     www      7938:             $separator=';';
1.480     banghart 7939:         }
1.31      albertel 7940:         my $i=0;
1.561     www      7941: # the character we are looking for to indicate the end of a quote or a record 
                   7942:         my $looking_for=$separator;
                   7943: # do not add the characters to the fields
                   7944:         my $ignore=0;
                   7945: # we just encountered a separator (or the beginning of the record)
                   7946:         my $just_found_separator=1;
                   7947: # store the field we are working on here
                   7948:         my $field='';
                   7949: # work our way through all characters in record
                   7950:         foreach my $character ($record=~/(.)/g) {
                   7951:             if ($character eq $looking_for) {
                   7952:                if ($character ne $separator) {
                   7953: # Found the end of a quote, again looking for separator
                   7954:                   $looking_for=$separator;
                   7955:                   $ignore=1;
                   7956:                } else {
                   7957: # Found a separator, store away what we got
                   7958:                   $components{&takeleft($i)}=$field;
                   7959: 	          $i++;
                   7960:                   $just_found_separator=1;
                   7961:                   $ignore=0;
                   7962:                   $field='';
                   7963:                }
                   7964:                next;
                   7965:             }
                   7966: # single or double quotation marks after a separator indicate beginning of a quote
                   7967: # we are now looking for the end of the quote and need to ignore separators
                   7968:             if ((($character eq '"') || ($character eq "'")) && ($just_found_separator))  {
                   7969:                $looking_for=$character;
                   7970:                next;
                   7971:             }
                   7972: # ignore would be true after we reached the end of a quote
                   7973:             if ($ignore) { next; }
                   7974:             if (($just_found_separator) && ($character=~/\s/)) { next; }
                   7975:             $field.=$character;
                   7976:             $just_found_separator=0; 
1.31      albertel 7977:         }
1.561     www      7978: # catch the very last entry, since we never encountered the separator
                   7979:         $components{&takeleft($i)}=$field;
1.31      albertel 7980:     }
                   7981:     return %components;
                   7982: }
                   7983: 
1.144     matthew  7984: ######################################################
                   7985: ######################################################
                   7986: 
1.56      matthew  7987: =pod
                   7988: 
1.648     raeburn  7989: =item * &upfile_select_html()
1.41      ng       7990: 
1.144     matthew  7991: Return HTML code to select a file from the users machine and specify 
                   7992: the file type.
1.41      ng       7993: 
                   7994: =cut
                   7995: 
1.144     matthew  7996: ######################################################
                   7997: ######################################################
1.31      albertel 7998: sub upfile_select_html {
1.144     matthew  7999:     my %Types = (
                   8000:                  csv   => &mt('CSV (comma separated values, spreadsheet)'),
1.480     banghart 8001:                  semisv => &mt('Semicolon separated values'),
1.144     matthew  8002:                  space => &mt('Space separated'),
                   8003:                  tab   => &mt('Tabulator separated'),
                   8004: #                 xml   => &mt('HTML/XML'),
                   8005:                  );
                   8006:     my $Str = '<input type="file" name="upfile" size="50" />'.
1.727     riegler  8007:         '<br />'.&mt('Type').': <select name="upfiletype">';
1.144     matthew  8008:     foreach my $type (sort(keys(%Types))) {
                   8009:         $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
                   8010:     }
                   8011:     $Str .= "</select>\n";
                   8012:     return $Str;
1.31      albertel 8013: }
                   8014: 
1.301     albertel 8015: sub get_samples {
                   8016:     my ($records,$toget) = @_;
                   8017:     my @samples=({});
                   8018:     my $got=0;
                   8019:     foreach my $rec (@$records) {
                   8020: 	my %temp = &record_sep($rec);
                   8021: 	if (! grep(/\S/, values(%temp))) { next; }
                   8022: 	if (%temp) {
                   8023: 	    $samples[$got]=\%temp;
                   8024: 	    $got++;
                   8025: 	    if ($got == $toget) { last; }
                   8026: 	}
                   8027:     }
                   8028:     return \@samples;
                   8029: }
                   8030: 
1.144     matthew  8031: ######################################################
                   8032: ######################################################
                   8033: 
1.56      matthew  8034: =pod
                   8035: 
1.648     raeburn  8036: =item * &csv_print_samples($r,$records)
1.41      ng       8037: 
                   8038: Prints a table of sample values from each column uploaded $r is an
                   8039: Apache Request ref, $records is an arrayref from
                   8040: &Apache::loncommon::upfile_record_sep
                   8041: 
                   8042: =cut
                   8043: 
1.144     matthew  8044: ######################################################
                   8045: ######################################################
1.31      albertel 8046: sub csv_print_samples {
                   8047:     my ($r,$records) = @_;
1.662     bisitz   8048:     my $samples = &get_samples($records,5);
1.301     albertel 8049: 
1.594     raeburn  8050:     $r->print(&mt('Samples').'<br />'.&start_data_table().
                   8051:               &start_data_table_header_row());
1.356     albertel 8052:     foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) { 
                   8053:         $r->print('<th>'.&mt('Column&nbsp;[_1]',($sample+1)).'</th>'); }
1.594     raeburn  8054:     $r->print(&end_data_table_header_row());
1.301     albertel 8055:     foreach my $hash (@$samples) {
1.594     raeburn  8056: 	$r->print(&start_data_table_row());
1.356     albertel 8057: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31      albertel 8058: 	    $r->print('<td>');
1.356     albertel 8059: 	    if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31      albertel 8060: 	    $r->print('</td>');
                   8061: 	}
1.594     raeburn  8062: 	$r->print(&end_data_table_row());
1.31      albertel 8063:     }
1.594     raeburn  8064:     $r->print(&end_data_table().'<br />'."\n");
1.31      albertel 8065: }
                   8066: 
1.144     matthew  8067: ######################################################
                   8068: ######################################################
                   8069: 
1.56      matthew  8070: =pod
                   8071: 
1.648     raeburn  8072: =item * &csv_print_select_table($r,$records,$d)
1.41      ng       8073: 
                   8074: Prints a table to create associations between values and table columns.
1.144     matthew  8075: 
1.41      ng       8076: $r is an Apache Request ref,
                   8077: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174     matthew  8078: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41      ng       8079: 
                   8080: =cut
                   8081: 
1.144     matthew  8082: ######################################################
                   8083: ######################################################
1.31      albertel 8084: sub csv_print_select_table {
                   8085:     my ($r,$records,$d) = @_;
1.301     albertel 8086:     my $i=0;
                   8087:     my $samples = &get_samples($records,1);
1.144     matthew  8088:     $r->print(&mt('Associate columns with student attributes.')."\n".
1.594     raeburn  8089: 	      &start_data_table().&start_data_table_header_row().
1.144     matthew  8090:               '<th>'.&mt('Attribute').'</th>'.
1.594     raeburn  8091:               '<th>'.&mt('Column').'</th>'.
                   8092:               &end_data_table_header_row()."\n");
1.356     albertel 8093:     foreach my $array_ref (@$d) {
                   8094: 	my ($value,$display,$defaultcol)=@{ $array_ref };
1.729     raeburn  8095: 	$r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31      albertel 8096: 
                   8097: 	$r->print('<td><select name=f'.$i.
1.32      matthew  8098: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.31      albertel 8099: 	$r->print('<option value="none"></option>');
1.356     albertel 8100: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
                   8101: 	    $r->print('<option value="'.$sample.'"'.
                   8102:                       ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662     bisitz   8103:                       '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31      albertel 8104: 	}
1.594     raeburn  8105: 	$r->print('</select></td>'.&end_data_table_row()."\n");
1.31      albertel 8106: 	$i++;
                   8107:     }
1.594     raeburn  8108:     $r->print(&end_data_table());
1.31      albertel 8109:     $i--;
                   8110:     return $i;
                   8111: }
1.56      matthew  8112: 
1.144     matthew  8113: ######################################################
                   8114: ######################################################
                   8115: 
1.56      matthew  8116: =pod
1.31      albertel 8117: 
1.648     raeburn  8118: =item * &csv_samples_select_table($r,$records,$d)
1.41      ng       8119: 
                   8120: Prints a table of sample values from the upload and can make associate samples to internal names.
                   8121: 
                   8122: $r is an Apache Request ref,
                   8123: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
                   8124: $d is an array of 2 element arrays (internal name, displayed name)
                   8125: 
                   8126: =cut
                   8127: 
1.144     matthew  8128: ######################################################
                   8129: ######################################################
1.31      albertel 8130: sub csv_samples_select_table {
                   8131:     my ($r,$records,$d) = @_;
                   8132:     my $i=0;
1.144     matthew  8133:     #
1.662     bisitz   8134:     my $max_samples = 5;
                   8135:     my $samples = &get_samples($records,$max_samples);
1.594     raeburn  8136:     $r->print(&start_data_table().
                   8137:               &start_data_table_header_row().'<th>'.
                   8138:               &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
                   8139:               &end_data_table_header_row());
1.301     albertel 8140: 
                   8141:     foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594     raeburn  8142: 	$r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32      matthew  8143: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.301     albertel 8144: 	foreach my $option (@$d) {
                   8145: 	    my ($value,$display,$defaultcol)=@{ $option };
1.174     matthew  8146: 	    $r->print('<option value="'.$value.'"'.
1.253     albertel 8147:                       ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174     matthew  8148:                       $display.'</option>');
1.31      albertel 8149: 	}
                   8150: 	$r->print('</select></td><td>');
1.662     bisitz   8151: 	foreach my $line (0..($max_samples-1)) {
1.301     albertel 8152: 	    if (defined($samples->[$line]{$key})) { 
                   8153: 		$r->print($samples->[$line]{$key}."<br />\n"); 
                   8154: 	    }
                   8155: 	}
1.594     raeburn  8156: 	$r->print('</td>'.&end_data_table_row());
1.31      albertel 8157: 	$i++;
                   8158:     }
1.594     raeburn  8159:     $r->print(&end_data_table());
1.31      albertel 8160:     $i--;
                   8161:     return($i);
1.115     matthew  8162: }
                   8163: 
1.144     matthew  8164: ######################################################
                   8165: ######################################################
                   8166: 
1.115     matthew  8167: =pod
                   8168: 
1.648     raeburn  8169: =item * &clean_excel_name($name)
1.115     matthew  8170: 
                   8171: Returns a replacement for $name which does not contain any illegal characters.
                   8172: 
                   8173: =cut
                   8174: 
1.144     matthew  8175: ######################################################
                   8176: ######################################################
1.115     matthew  8177: sub clean_excel_name {
                   8178:     my ($name) = @_;
                   8179:     $name =~ s/[:\*\?\/\\]//g;
                   8180:     if (length($name) > 31) {
                   8181:         $name = substr($name,0,31);
                   8182:     }
                   8183:     return $name;
1.25      albertel 8184: }
1.84      albertel 8185: 
1.85      albertel 8186: =pod
                   8187: 
1.648     raeburn  8188: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85      albertel 8189: 
                   8190: Returns either 1 or undef
                   8191: 
                   8192: 1 if the part is to be hidden, undef if it is to be shown
                   8193: 
                   8194: Arguments are:
                   8195: 
                   8196: $id the id of the part to be checked
                   8197: $symb, optional the symb of the resource to check
                   8198: $udom, optional the domain of the user to check for
                   8199: $uname, optional the username of the user to check for
                   8200: 
                   8201: =cut
1.84      albertel 8202: 
                   8203: sub check_if_partid_hidden {
                   8204:     my ($id,$symb,$udom,$uname) = @_;
1.133     albertel 8205:     my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84      albertel 8206: 					 $symb,$udom,$uname);
1.141     albertel 8207:     my $truth=1;
                   8208:     #if the string starts with !, then the list is the list to show not hide
                   8209:     if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84      albertel 8210:     my @hiddenlist=split(/,/,$hiddenparts);
                   8211:     foreach my $checkid (@hiddenlist) {
1.141     albertel 8212: 	if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84      albertel 8213:     }
1.141     albertel 8214:     return !$truth;
1.84      albertel 8215: }
1.127     matthew  8216: 
1.138     matthew  8217: 
                   8218: ############################################################
                   8219: ############################################################
                   8220: 
                   8221: =pod
                   8222: 
1.157     matthew  8223: =back 
                   8224: 
1.138     matthew  8225: =head1 cgi-bin script and graphing routines
                   8226: 
1.157     matthew  8227: =over 4
                   8228: 
1.648     raeburn  8229: =item * &get_cgi_id()
1.138     matthew  8230: 
                   8231: Inputs: none
                   8232: 
                   8233: Returns an id which can be used to pass environment variables
                   8234: to various cgi-bin scripts.  These environment variables will
                   8235: be removed from the users environment after a given time by
                   8236: the routine &Apache::lonnet::transfer_profile_to_env.
                   8237: 
                   8238: =cut
                   8239: 
                   8240: ############################################################
                   8241: ############################################################
1.152     albertel 8242: my $uniq=0;
1.136     matthew  8243: sub get_cgi_id {
1.154     albertel 8244:     $uniq=($uniq+1)%100000;
1.280     albertel 8245:     return (time.'_'.$$.'_'.$uniq);
1.136     matthew  8246: }
                   8247: 
1.127     matthew  8248: ############################################################
                   8249: ############################################################
                   8250: 
                   8251: =pod
                   8252: 
1.648     raeburn  8253: =item * &DrawBarGraph()
1.127     matthew  8254: 
1.138     matthew  8255: Facilitates the plotting of data in a (stacked) bar graph.
                   8256: Puts plot definition data into the users environment in order for 
                   8257: graph.png to plot it.  Returns an <img> tag for the plot.
                   8258: The bars on the plot are labeled '1','2',...,'n'.
                   8259: 
                   8260: Inputs:
                   8261: 
                   8262: =over 4
                   8263: 
                   8264: =item $Title: string, the title of the plot
                   8265: 
                   8266: =item $xlabel: string, text describing the X-axis of the plot
                   8267: 
                   8268: =item $ylabel: string, text describing the Y-axis of the plot
                   8269: 
                   8270: =item $Max: scalar, the maximum Y value to use in the plot
                   8271: If $Max is < any data point, the graph will not be rendered.
                   8272: 
1.140     matthew  8273: =item $colors: array ref holding the colors to be used for the data sets when
1.138     matthew  8274: they are plotted.  If undefined, default values will be used.
                   8275: 
1.178     matthew  8276: =item $labels: array ref holding the labels to use on the x-axis for the bars.
                   8277: 
1.138     matthew  8278: =item @Values: An array of array references.  Each array reference holds data
                   8279: to be plotted in a stacked bar chart.
                   8280: 
1.239     matthew  8281: =item If the final element of @Values is a hash reference the key/value
                   8282: pairs will be added to the graph definition.
                   8283: 
1.138     matthew  8284: =back
                   8285: 
                   8286: Returns:
                   8287: 
                   8288: An <img> tag which references graph.png and the appropriate identifying
                   8289: information for the plot.
                   8290: 
1.127     matthew  8291: =cut
                   8292: 
                   8293: ############################################################
                   8294: ############################################################
1.134     matthew  8295: sub DrawBarGraph {
1.178     matthew  8296:     my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134     matthew  8297:     #
                   8298:     if (! defined($colors)) {
                   8299:         $colors = ['#33ff00', 
                   8300:                   '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
                   8301:                   '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
                   8302:                   ]; 
                   8303:     }
1.228     matthew  8304:     my $extra_settings = {};
                   8305:     if (ref($Values[-1]) eq 'HASH') {
                   8306:         $extra_settings = pop(@Values);
                   8307:     }
1.127     matthew  8308:     #
1.136     matthew  8309:     my $identifier = &get_cgi_id();
                   8310:     my $id = 'cgi.'.$identifier;        
1.129     matthew  8311:     if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127     matthew  8312:         return '';
                   8313:     }
1.225     matthew  8314:     #
                   8315:     my @Labels;
                   8316:     if (defined($labels)) {
                   8317:         @Labels = @$labels;
                   8318:     } else {
                   8319:         for (my $i=0;$i<@{$Values[0]};$i++) {
                   8320:             push (@Labels,$i+1);
                   8321:         }
                   8322:     }
                   8323:     #
1.129     matthew  8324:     my $NumBars = scalar(@{$Values[0]});
1.225     matthew  8325:     if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129     matthew  8326:     my %ValuesHash;
                   8327:     my $NumSets=1;
                   8328:     foreach my $array (@Values) {
                   8329:         next if (! ref($array));
1.136     matthew  8330:         $ValuesHash{$id.'.data.'.$NumSets++} = 
1.132     matthew  8331:             join(',',@$array);
1.129     matthew  8332:     }
1.127     matthew  8333:     #
1.136     matthew  8334:     my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225     matthew  8335:     if ($NumBars < 3) {
                   8336:         $width = 120+$NumBars*32;
1.220     matthew  8337:         $xskip = 1;
1.225     matthew  8338:         $bar_width = 30;
                   8339:     } elsif ($NumBars < 5) {
                   8340:         $width = 120+$NumBars*20;
                   8341:         $xskip = 1;
                   8342:         $bar_width = 20;
1.220     matthew  8343:     } elsif ($NumBars < 10) {
1.136     matthew  8344:         $width = 120+$NumBars*15;
                   8345:         $xskip = 1;
                   8346:         $bar_width = 15;
                   8347:     } elsif ($NumBars <= 25) {
                   8348:         $width = 120+$NumBars*11;
                   8349:         $xskip = 5;
                   8350:         $bar_width = 8;
                   8351:     } elsif ($NumBars <= 50) {
                   8352:         $width = 120+$NumBars*8;
                   8353:         $xskip = 5;
                   8354:         $bar_width = 4;
                   8355:     } else {
                   8356:         $width = 120+$NumBars*8;
                   8357:         $xskip = 5;
                   8358:         $bar_width = 4;
                   8359:     }
                   8360:     #
1.137     matthew  8361:     $Max = 1 if ($Max < 1);
                   8362:     if ( int($Max) < $Max ) {
                   8363:         $Max++;
                   8364:         $Max = int($Max);
                   8365:     }
1.127     matthew  8366:     $Title  = '' if (! defined($Title));
                   8367:     $xlabel = '' if (! defined($xlabel));
                   8368:     $ylabel = '' if (! defined($ylabel));
1.369     www      8369:     $ValuesHash{$id.'.title'}    = &escape($Title);
                   8370:     $ValuesHash{$id.'.xlabel'}   = &escape($xlabel);
                   8371:     $ValuesHash{$id.'.ylabel'}   = &escape($ylabel);
1.137     matthew  8372:     $ValuesHash{$id.'.y_max_value'} = $Max;
1.136     matthew  8373:     $ValuesHash{$id.'.NumBars'}  = $NumBars;
                   8374:     $ValuesHash{$id.'.NumSets'}  = $NumSets;
                   8375:     $ValuesHash{$id.'.PlotType'} = 'bar';
                   8376:     $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   8377:     $ValuesHash{$id.'.height'}   = $height;
                   8378:     $ValuesHash{$id.'.width'}    = $width;
                   8379:     $ValuesHash{$id.'.xskip'}    = $xskip;
                   8380:     $ValuesHash{$id.'.bar_width'} = $bar_width;
                   8381:     $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127     matthew  8382:     #
1.228     matthew  8383:     # Deal with other parameters
                   8384:     while (my ($key,$value) = each(%$extra_settings)) {
                   8385:         $ValuesHash{$id.'.'.$key} = $value;
                   8386:     }
                   8387:     #
1.646     raeburn  8388:     &Apache::lonnet::appenv(\%ValuesHash);
1.137     matthew  8389:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   8390: }
                   8391: 
                   8392: ############################################################
                   8393: ############################################################
                   8394: 
                   8395: =pod
                   8396: 
1.648     raeburn  8397: =item * &DrawXYGraph()
1.137     matthew  8398: 
1.138     matthew  8399: Facilitates the plotting of data in an XY graph.
                   8400: Puts plot definition data into the users environment in order for 
                   8401: graph.png to plot it.  Returns an <img> tag for the plot.
                   8402: 
                   8403: Inputs:
                   8404: 
                   8405: =over 4
                   8406: 
                   8407: =item $Title: string, the title of the plot
                   8408: 
                   8409: =item $xlabel: string, text describing the X-axis of the plot
                   8410: 
                   8411: =item $ylabel: string, text describing the Y-axis of the plot
                   8412: 
                   8413: =item $Max: scalar, the maximum Y value to use in the plot
                   8414: If $Max is < any data point, the graph will not be rendered.
                   8415: 
                   8416: =item $colors: Array ref containing the hex color codes for the data to be 
                   8417: plotted in.  If undefined, default values will be used.
                   8418: 
                   8419: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   8420: 
                   8421: =item $Ydata: Array ref containing Array refs.  
1.185     www      8422: Each of the contained arrays will be plotted as a separate curve.
1.138     matthew  8423: 
                   8424: =item %Values: hash indicating or overriding any default values which are 
                   8425: passed to graph.png.  
                   8426: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   8427: 
                   8428: =back
                   8429: 
                   8430: Returns:
                   8431: 
                   8432: An <img> tag which references graph.png and the appropriate identifying
                   8433: information for the plot.
                   8434: 
1.137     matthew  8435: =cut
                   8436: 
                   8437: ############################################################
                   8438: ############################################################
                   8439: sub DrawXYGraph {
                   8440:     my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
                   8441:     #
                   8442:     # Create the identifier for the graph
                   8443:     my $identifier = &get_cgi_id();
                   8444:     my $id = 'cgi.'.$identifier;
                   8445:     #
                   8446:     $Title  = '' if (! defined($Title));
                   8447:     $xlabel = '' if (! defined($xlabel));
                   8448:     $ylabel = '' if (! defined($ylabel));
                   8449:     my %ValuesHash = 
                   8450:         (
1.369     www      8451:          $id.'.title'  => &escape($Title),
                   8452:          $id.'.xlabel' => &escape($xlabel),
                   8453:          $id.'.ylabel' => &escape($ylabel),
1.137     matthew  8454:          $id.'.y_max_value'=> $Max,
                   8455:          $id.'.labels'     => join(',',@$Xlabels),
                   8456:          $id.'.PlotType'   => 'XY',
                   8457:          );
                   8458:     #
                   8459:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   8460:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   8461:     }
                   8462:     #
                   8463:     if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
                   8464:         return '';
                   8465:     }
                   8466:     my $NumSets=1;
1.138     matthew  8467:     foreach my $array (@{$Ydata}){
1.137     matthew  8468:         next if (! ref($array));
                   8469:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
                   8470:     }
1.138     matthew  8471:     $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137     matthew  8472:     #
                   8473:     # Deal with other parameters
                   8474:     while (my ($key,$value) = each(%Values)) {
                   8475:         $ValuesHash{$id.'.'.$key} = $value;
1.127     matthew  8476:     }
                   8477:     #
1.646     raeburn  8478:     &Apache::lonnet::appenv(\%ValuesHash);
1.136     matthew  8479:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   8480: }
                   8481: 
                   8482: ############################################################
                   8483: ############################################################
                   8484: 
                   8485: =pod
                   8486: 
1.648     raeburn  8487: =item * &DrawXYYGraph()
1.138     matthew  8488: 
                   8489: Facilitates the plotting of data in an XY graph with two Y axes.
                   8490: Puts plot definition data into the users environment in order for 
                   8491: graph.png to plot it.  Returns an <img> tag for the plot.
                   8492: 
                   8493: Inputs:
                   8494: 
                   8495: =over 4
                   8496: 
                   8497: =item $Title: string, the title of the plot
                   8498: 
                   8499: =item $xlabel: string, text describing the X-axis of the plot
                   8500: 
                   8501: =item $ylabel: string, text describing the Y-axis of the plot
                   8502: 
                   8503: =item $colors: Array ref containing the hex color codes for the data to be 
                   8504: plotted in.  If undefined, default values will be used.
                   8505: 
                   8506: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   8507: 
                   8508: =item $Ydata1: The first data set
                   8509: 
                   8510: =item $Min1: The minimum value of the left Y-axis
                   8511: 
                   8512: =item $Max1: The maximum value of the left Y-axis
                   8513: 
                   8514: =item $Ydata2: The second data set
                   8515: 
                   8516: =item $Min2: The minimum value of the right Y-axis
                   8517: 
                   8518: =item $Max2: The maximum value of the left Y-axis
                   8519: 
                   8520: =item %Values: hash indicating or overriding any default values which are 
                   8521: passed to graph.png.  
                   8522: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   8523: 
                   8524: =back
                   8525: 
                   8526: Returns:
                   8527: 
                   8528: An <img> tag which references graph.png and the appropriate identifying
                   8529: information for the plot.
1.136     matthew  8530: 
                   8531: =cut
                   8532: 
                   8533: ############################################################
                   8534: ############################################################
1.137     matthew  8535: sub DrawXYYGraph {
                   8536:     my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
                   8537:                                         $Ydata2,$Min2,$Max2,%Values)=@_;
1.136     matthew  8538:     #
                   8539:     # Create the identifier for the graph
                   8540:     my $identifier = &get_cgi_id();
                   8541:     my $id = 'cgi.'.$identifier;
                   8542:     #
                   8543:     $Title  = '' if (! defined($Title));
                   8544:     $xlabel = '' if (! defined($xlabel));
                   8545:     $ylabel = '' if (! defined($ylabel));
                   8546:     my %ValuesHash = 
                   8547:         (
1.369     www      8548:          $id.'.title'  => &escape($Title),
                   8549:          $id.'.xlabel' => &escape($xlabel),
                   8550:          $id.'.ylabel' => &escape($ylabel),
1.136     matthew  8551:          $id.'.labels' => join(',',@$Xlabels),
                   8552:          $id.'.PlotType' => 'XY',
                   8553:          $id.'.NumSets' => 2,
1.137     matthew  8554:          $id.'.two_axes' => 1,
                   8555:          $id.'.y1_max_value' => $Max1,
                   8556:          $id.'.y1_min_value' => $Min1,
                   8557:          $id.'.y2_max_value' => $Max2,
                   8558:          $id.'.y2_min_value' => $Min2,
1.136     matthew  8559:          );
                   8560:     #
1.137     matthew  8561:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   8562:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   8563:     }
                   8564:     #
                   8565:     if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
                   8566:         ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136     matthew  8567:         return '';
                   8568:     }
                   8569:     my $NumSets=1;
1.137     matthew  8570:     foreach my $array ($Ydata1,$Ydata2){
1.136     matthew  8571:         next if (! ref($array));
                   8572:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137     matthew  8573:     }
                   8574:     #
                   8575:     # Deal with other parameters
                   8576:     while (my ($key,$value) = each(%Values)) {
                   8577:         $ValuesHash{$id.'.'.$key} = $value;
1.136     matthew  8578:     }
                   8579:     #
1.646     raeburn  8580:     &Apache::lonnet::appenv(\%ValuesHash);
1.130     albertel 8581:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139     matthew  8582: }
                   8583: 
                   8584: ############################################################
                   8585: ############################################################
                   8586: 
                   8587: =pod
                   8588: 
1.157     matthew  8589: =back 
                   8590: 
1.139     matthew  8591: =head1 Statistics helper routines?  
                   8592: 
                   8593: Bad place for them but what the hell.
                   8594: 
1.157     matthew  8595: =over 4
                   8596: 
1.648     raeburn  8597: =item * &chartlink()
1.139     matthew  8598: 
                   8599: Returns a link to the chart for a specific student.  
                   8600: 
                   8601: Inputs:
                   8602: 
                   8603: =over 4
                   8604: 
                   8605: =item $linktext: The text of the link
                   8606: 
                   8607: =item $sname: The students username
                   8608: 
                   8609: =item $sdomain: The students domain
                   8610: 
                   8611: =back
                   8612: 
1.157     matthew  8613: =back
                   8614: 
1.139     matthew  8615: =cut
                   8616: 
                   8617: ############################################################
                   8618: ############################################################
                   8619: sub chartlink {
                   8620:     my ($linktext, $sname, $sdomain) = @_;
                   8621:     my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369     www      8622:         '&amp;SelectedStudent='.&escape($sname.':'.$sdomain).
1.219     albertel 8623:         '&amp;chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139     matthew  8624:        '">'.$linktext.'</a>';
1.153     matthew  8625: }
                   8626: 
                   8627: #######################################################
                   8628: #######################################################
                   8629: 
                   8630: =pod
                   8631: 
                   8632: =head1 Course Environment Routines
1.157     matthew  8633: 
                   8634: =over 4
1.153     matthew  8635: 
1.648     raeburn  8636: =item * &restore_course_settings()
1.153     matthew  8637: 
1.648     raeburn  8638: =item * &store_course_settings()
1.153     matthew  8639: 
                   8640: Restores/Store indicated form parameters from the course environment.
                   8641: Will not overwrite existing values of the form parameters.
                   8642: 
                   8643: Inputs: 
                   8644: a scalar describing the data (e.g. 'chart', 'problem_analysis')
                   8645: 
                   8646: a hash ref describing the data to be stored.  For example:
                   8647:    
                   8648: %Save_Parameters = ('Status' => 'scalar',
                   8649:     'chartoutputmode' => 'scalar',
                   8650:     'chartoutputdata' => 'scalar',
                   8651:     'Section' => 'array',
1.373     raeburn  8652:     'Group' => 'array',
1.153     matthew  8653:     'StudentData' => 'array',
                   8654:     'Maps' => 'array');
                   8655: 
                   8656: Returns: both routines return nothing
                   8657: 
1.631     raeburn  8658: =back
                   8659: 
1.153     matthew  8660: =cut
                   8661: 
                   8662: #######################################################
                   8663: #######################################################
                   8664: sub store_course_settings {
1.496     albertel 8665:     return &store_settings($env{'request.course.id'},@_);
                   8666: }
                   8667: 
                   8668: sub store_settings {
1.153     matthew  8669:     # save to the environment
                   8670:     # appenv the same items, just to be safe
1.300     albertel 8671:     my $udom  = $env{'user.domain'};
                   8672:     my $uname = $env{'user.name'};
1.496     albertel 8673:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  8674:     my %SaveHash;
                   8675:     my %AppHash;
                   8676:     while (my ($setting,$type) = each(%$Settings)) {
1.496     albertel 8677:         my $basename = join('.','internal',$context,$prefix,$setting);
1.300     albertel 8678:         my $envname = 'environment.'.$basename;
1.258     albertel 8679:         if (exists($env{'form.'.$setting})) {
1.153     matthew  8680:             # Save this value away
                   8681:             if ($type eq 'scalar' &&
1.258     albertel 8682:                 (! exists($env{$envname}) || 
                   8683:                  $env{$envname} ne $env{'form.'.$setting})) {
                   8684:                 $SaveHash{$basename} = $env{'form.'.$setting};
                   8685:                 $AppHash{$envname}   = $env{'form.'.$setting};
1.153     matthew  8686:             } elsif ($type eq 'array') {
                   8687:                 my $stored_form;
1.258     albertel 8688:                 if (ref($env{'form.'.$setting})) {
1.153     matthew  8689:                     $stored_form = join(',',
                   8690:                                         map {
1.369     www      8691:                                             &escape($_);
1.258     albertel 8692:                                         } sort(@{$env{'form.'.$setting}}));
1.153     matthew  8693:                 } else {
                   8694:                     $stored_form = 
1.369     www      8695:                         &escape($env{'form.'.$setting});
1.153     matthew  8696:                 }
                   8697:                 # Determine if the array contents are the same.
1.258     albertel 8698:                 if ($stored_form ne $env{$envname}) {
1.153     matthew  8699:                     $SaveHash{$basename} = $stored_form;
                   8700:                     $AppHash{$envname}   = $stored_form;
                   8701:                 }
                   8702:             }
                   8703:         }
                   8704:     }
                   8705:     my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300     albertel 8706:                                           $udom,$uname);
1.153     matthew  8707:     if ($put_result !~ /^(ok|delayed)/) {
                   8708:         &Apache::lonnet::logthis('unable to save form parameters, '.
                   8709:                                  'got error:'.$put_result);
                   8710:     }
                   8711:     # Make sure these settings stick around in this session, too
1.646     raeburn  8712:     &Apache::lonnet::appenv(\%AppHash);
1.153     matthew  8713:     return;
                   8714: }
                   8715: 
                   8716: sub restore_course_settings {
1.499     albertel 8717:     return &restore_settings($env{'request.course.id'},@_);
1.496     albertel 8718: }
                   8719: 
                   8720: sub restore_settings {
                   8721:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  8722:     while (my ($setting,$type) = each(%$Settings)) {
1.258     albertel 8723:         next if (exists($env{'form.'.$setting}));
1.496     albertel 8724:         my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153     matthew  8725:             '.'.$setting;
1.258     albertel 8726:         if (exists($env{$envname})) {
1.153     matthew  8727:             if ($type eq 'scalar') {
1.258     albertel 8728:                 $env{'form.'.$setting} = $env{$envname};
1.153     matthew  8729:             } elsif ($type eq 'array') {
1.258     albertel 8730:                 $env{'form.'.$setting} = [ 
1.153     matthew  8731:                                            map { 
1.369     www      8732:                                                &unescape($_); 
1.258     albertel 8733:                                            } split(',',$env{$envname})
1.153     matthew  8734:                                            ];
                   8735:             }
                   8736:         }
                   8737:     }
1.127     matthew  8738: }
                   8739: 
1.618     raeburn  8740: #######################################################
                   8741: #######################################################
                   8742: 
                   8743: =pod
                   8744: 
                   8745: =head1 Domain E-mail Routines  
                   8746: 
                   8747: =over 4
                   8748: 
1.648     raeburn  8749: =item * &build_recipient_list()
1.618     raeburn  8750: 
                   8751: Build recipient lists for three types of e-mail:
                   8752: (a) Error Reports, (b) Package Updates, (c) Help requests, generated by
1.619     raeburn  8753: lonerrorhandler.pm, CHECKRPMS and lonsupportreq.pm respectively.
1.618     raeburn  8754: 
                   8755: Inputs:
1.619     raeburn  8756: defmail (scalar - email address of default recipient), 
1.618     raeburn  8757: mailing type (scalar - errormail, packagesmail, or helpdeskmail), 
1.619     raeburn  8758: defdom (domain for which to retrieve configuration settings),
                   8759: origmail (scalar - email address of recipient from loncapa.conf, 
                   8760: i.e., predates configuration by DC via domainprefs.pm 
1.618     raeburn  8761: 
1.655     raeburn  8762: Returns: comma separated list of addresses to which to send e-mail.
                   8763: 
                   8764: =back
1.618     raeburn  8765: 
                   8766: =cut
                   8767: 
                   8768: ############################################################
                   8769: ############################################################
                   8770: sub build_recipient_list {
1.619     raeburn  8771:     my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618     raeburn  8772:     my @recipients;
                   8773:     my $otheremails;
                   8774:     my %domconfig =
                   8775:          &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
                   8776:     if (ref($domconfig{'contacts'}) eq 'HASH') {
                   8777:         if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
                   8778:             my @contacts = ('adminemail','supportemail');
                   8779:             foreach my $item (@contacts) {
                   8780:                 if ($domconfig{'contacts'}{$mailing}{$item}) {
1.619     raeburn  8781:                     my $addr = $domconfig{'contacts'}{$item}; 
                   8782:                     if (!grep(/^\Q$addr\E$/,@recipients)) {
                   8783:                         push(@recipients,$addr);
                   8784:                     }
1.618     raeburn  8785:                 }
                   8786:                 $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
                   8787:             }
                   8788:         }
1.619     raeburn  8789:     } elsif ($origmail ne '') {
                   8790:         push(@recipients,$origmail);
1.618     raeburn  8791:     }
1.688     raeburn  8792:     if (defined($defmail)) {
                   8793:         if ($defmail ne '') {
                   8794:             push(@recipients,$defmail);
                   8795:         }
1.618     raeburn  8796:     }
                   8797:     if ($otheremails) {
1.619     raeburn  8798:         my @others;
                   8799:         if ($otheremails =~ /,/) {
                   8800:             @others = split(/,/,$otheremails);
1.618     raeburn  8801:         } else {
1.619     raeburn  8802:             push(@others,$otheremails);
                   8803:         }
                   8804:         foreach my $addr (@others) {
                   8805:             if (!grep(/^\Q$addr\E$/,@recipients)) {
                   8806:                 push(@recipients,$addr);
                   8807:             }
1.618     raeburn  8808:         }
                   8809:     }
1.619     raeburn  8810:     my $recipientlist = join(',',@recipients); 
1.618     raeburn  8811:     return $recipientlist;
                   8812: }
                   8813: 
1.127     matthew  8814: ############################################################
                   8815: ############################################################
1.154     albertel 8816: 
1.655     raeburn  8817: =pod
                   8818: 
                   8819: =head1 Course Catalog Routines
                   8820: 
                   8821: =over 4
                   8822: 
                   8823: =item * &gather_categories()
                   8824: 
                   8825: Converts category definitions - keys of categories hash stored in  
                   8826: coursecategories in configuration.db on the primary library server in a 
                   8827: domain - to an array.  Also generates javascript and idx hash used to 
                   8828: generate Domain Coordinator interface for editing Course Categories.
                   8829: 
                   8830: Inputs:
1.663     raeburn  8831: 
1.655     raeburn  8832: categories (reference to hash of category definitions).
1.663     raeburn  8833: 
1.655     raeburn  8834: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   8835:       categories and subcategories).
1.663     raeburn  8836: 
1.655     raeburn  8837: idx (reference to hash of counters used in Domain Coordinator interface for 
                   8838:       editing Course Categories).
1.663     raeburn  8839: 
1.655     raeburn  8840: jsarray (reference to array of categories used to create Javascript arrays for
                   8841:          Domain Coordinator interface for editing Course Categories).
                   8842: 
                   8843: Returns: nothing
                   8844: 
                   8845: Side effects: populates cats, idx and jsarray. 
                   8846: 
                   8847: =cut
                   8848: 
                   8849: sub gather_categories {
                   8850:     my ($categories,$cats,$idx,$jsarray) = @_;
                   8851:     my %counters;
                   8852:     my $num = 0;
                   8853:     foreach my $item (keys(%{$categories})) {
                   8854:         my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
                   8855:         if ($container eq '' && $depth == 0) {
                   8856:             $cats->[$depth][$categories->{$item}] = $cat;
                   8857:         } else {
                   8858:             $cats->[$depth]{$container}[$categories->{$item}] = $cat;
                   8859:         }
                   8860:         my ($escitem,$tail) = split(/:/,$item,2);
                   8861:         if ($counters{$tail} eq '') {
                   8862:             $counters{$tail} = $num;
                   8863:             $num ++;
                   8864:         }
                   8865:         if (ref($idx) eq 'HASH') {
                   8866:             $idx->{$item} = $counters{$tail};
                   8867:         }
                   8868:         if (ref($jsarray) eq 'ARRAY') {
                   8869:             push(@{$jsarray->[$counters{$tail}]},$item);
                   8870:         }
                   8871:     }
                   8872:     return;
                   8873: }
                   8874: 
                   8875: =pod
                   8876: 
                   8877: =item * &extract_categories()
                   8878: 
                   8879: Used to generate breadcrumb trails for course categories.
                   8880: 
                   8881: Inputs:
1.663     raeburn  8882: 
1.655     raeburn  8883: categories (reference to hash of category definitions).
1.663     raeburn  8884: 
1.655     raeburn  8885: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   8886:       categories and subcategories).
1.663     raeburn  8887: 
1.655     raeburn  8888: trails (reference to array of breacrumb trails for each category).
1.663     raeburn  8889: 
1.655     raeburn  8890: allitems (reference to hash - key is category key 
                   8891:          (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663     raeburn  8892: 
1.655     raeburn  8893: idx (reference to hash of counters used in Domain Coordinator interface for
                   8894:       editing Course Categories).
1.663     raeburn  8895: 
1.655     raeburn  8896: jsarray (reference to array of categories used to create Javascript arrays for
                   8897:          Domain Coordinator interface for editing Course Categories).
                   8898: 
1.665     raeburn  8899: subcats (reference to hash of arrays containing all subcategories within each 
                   8900:          category, -recursive)
                   8901: 
1.655     raeburn  8902: Returns: nothing
                   8903: 
                   8904: Side effects: populates trails and allitems hash references.
                   8905: 
                   8906: =cut
                   8907: 
                   8908: sub extract_categories {
1.665     raeburn  8909:     my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655     raeburn  8910:     if (ref($categories) eq 'HASH') {
                   8911:         &gather_categories($categories,$cats,$idx,$jsarray);
                   8912:         if (ref($cats->[0]) eq 'ARRAY') {
                   8913:             for (my $i=0; $i<@{$cats->[0]}; $i++) {
                   8914:                 my $name = $cats->[0][$i];
                   8915:                 my $item = &escape($name).'::0';
                   8916:                 my $trailstr;
                   8917:                 if ($name eq 'instcode') {
                   8918:                     $trailstr = &mt('Official courses (with institutional codes)');
                   8919:                 } else {
                   8920:                     $trailstr = $name;
                   8921:                 }
                   8922:                 if ($allitems->{$item} eq '') {
                   8923:                     push(@{$trails},$trailstr);
                   8924:                     $allitems->{$item} = scalar(@{$trails})-1;
                   8925:                 }
                   8926:                 my @parents = ($name);
                   8927:                 if (ref($cats->[1]{$name}) eq 'ARRAY') {
                   8928:                     for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
                   8929:                         my $category = $cats->[1]{$name}[$j];
1.665     raeburn  8930:                         if (ref($subcats) eq 'HASH') {
                   8931:                             push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
                   8932:                         }
                   8933:                         &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
                   8934:                     }
                   8935:                 } else {
                   8936:                     if (ref($subcats) eq 'HASH') {
                   8937:                         $subcats->{$item} = [];
1.655     raeburn  8938:                     }
                   8939:                 }
                   8940:             }
                   8941:         }
                   8942:     }
                   8943:     return;
                   8944: }
                   8945: 
                   8946: =pod
                   8947: 
                   8948: =item *&recurse_categories()
                   8949: 
                   8950: Recursively used to generate breadcrumb trails for course categories.
                   8951: 
                   8952: Inputs:
1.663     raeburn  8953: 
1.655     raeburn  8954: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   8955:       categories and subcategories).
1.663     raeburn  8956: 
1.655     raeburn  8957: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663     raeburn  8958: 
                   8959: category (current course category, for which breadcrumb trail is being generated).
                   8960: 
                   8961: trails (reference to array of breadcrumb trails for each category).
                   8962: 
1.655     raeburn  8963: allitems (reference to hash - key is category key
                   8964:          (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663     raeburn  8965: 
1.655     raeburn  8966: parents (array containing containers directories for current category, 
                   8967:          back to top level). 
                   8968: 
                   8969: Returns: nothing
                   8970: 
                   8971: Side effects: populates trails and allitems hash references
                   8972: 
                   8973: =cut
                   8974: 
                   8975: sub recurse_categories {
1.665     raeburn  8976:     my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655     raeburn  8977:     my $shallower = $depth - 1;
                   8978:     if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
                   8979:         for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
                   8980:             my $name = $cats->[$depth]{$category}[$k];
                   8981:             my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
                   8982:             my $trailstr = join(' -&gt; ',(@{$parents},$category));
                   8983:             if ($allitems->{$item} eq '') {
                   8984:                 push(@{$trails},$trailstr);
                   8985:                 $allitems->{$item} = scalar(@{$trails})-1;
                   8986:             }
                   8987:             my $deeper = $depth+1;
                   8988:             push(@{$parents},$category);
1.665     raeburn  8989:             if (ref($subcats) eq 'HASH') {
                   8990:                 my $subcat = &escape($name).':'.$category.':'.$depth;
                   8991:                 for (my $j=@{$parents}; $j>=0; $j--) {
                   8992:                     my $higher;
                   8993:                     if ($j > 0) {
                   8994:                         $higher = &escape($parents->[$j]).':'.
                   8995:                                   &escape($parents->[$j-1]).':'.$j;
                   8996:                     } else {
                   8997:                         $higher = &escape($parents->[$j]).'::'.$j;
                   8998:                     }
                   8999:                     push(@{$subcats->{$higher}},$subcat);
                   9000:                 }
                   9001:             }
                   9002:             &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
                   9003:                                 $subcats);
1.655     raeburn  9004:             pop(@{$parents});
                   9005:         }
                   9006:     } else {
                   9007:         my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
                   9008:         my $trailstr = join(' -&gt; ',(@{$parents},$category));
                   9009:         if ($allitems->{$item} eq '') {
                   9010:             push(@{$trails},$trailstr);
                   9011:             $allitems->{$item} = scalar(@{$trails})-1;
                   9012:         }
                   9013:     }
                   9014:     return;
                   9015: }
                   9016: 
1.663     raeburn  9017: =pod
                   9018: 
                   9019: =item *&assign_categories_table()
                   9020: 
                   9021: Create a datatable for display of hierarchical categories in a domain,
                   9022: with checkboxes to allow a course to be categorized. 
                   9023: 
                   9024: Inputs:
                   9025: 
                   9026: cathash - reference to hash of categories defined for the domain (from
                   9027:           configuration.db)
                   9028: 
                   9029: currcat - scalar with an & separated list of categories assigned to a course. 
                   9030: 
                   9031: Returns: $output (markup to be displayed) 
                   9032: 
                   9033: =cut
                   9034: 
                   9035: sub assign_categories_table {
                   9036:     my ($cathash,$currcat) = @_;
                   9037:     my $output;
                   9038:     if (ref($cathash) eq 'HASH') {
                   9039:         my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
                   9040:         &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
                   9041:         $maxdepth = scalar(@cats);
                   9042:         if (@cats > 0) {
                   9043:             my $itemcount = 0;
                   9044:             if (ref($cats[0]) eq 'ARRAY') {
                   9045:                 $output = &Apache::loncommon::start_data_table();
                   9046:                 my @currcategories;
                   9047:                 if ($currcat ne '') {
                   9048:                     @currcategories = split('&',$currcat);
                   9049:                 }
                   9050:                 for (my $i=0; $i<@{$cats[0]}; $i++) {
                   9051:                     my $parent = $cats[0][$i];
                   9052:                     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   9053:                     next if ($parent eq 'instcode');
                   9054:                     my $item = &escape($parent).'::0';
                   9055:                     my $checked = '';
                   9056:                     if (@currcategories > 0) {
                   9057:                         if (grep(/^\Q$item\E$/,@currcategories)) {
                   9058:                             $checked = ' checked="checked" ';
                   9059:                         }
                   9060:                     }
1.675     raeburn  9061:                     $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
                   9062:                                '<input type="checkbox" name="usecategory" value="'.
                   9063:                                $item.'"'.$checked.' />'.$parent.'</span>'.
                   9064:                                '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663     raeburn  9065:                     my $depth = 1;
                   9066:                     push(@path,$parent);
                   9067:                     $output .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
                   9068:                     pop(@path);
                   9069:                     $output .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
                   9070:                     $itemcount ++;
                   9071:                 }
                   9072:                 $output .= &Apache::loncommon::end_data_table();
                   9073:             }
                   9074:         }
                   9075:     }
                   9076:     return $output;
                   9077: }
                   9078: 
                   9079: =pod
                   9080: 
                   9081: =item *&assign_category_rows()
                   9082: 
                   9083: Create a datatable row for display of nested categories in a domain,
                   9084: with checkboxes to allow a course to be categorized,called recursively.
                   9085: 
                   9086: Inputs:
                   9087: 
                   9088: itemcount - track row number for alternating colors
                   9089: 
                   9090: cats - reference to array of arrays/hashes which encapsulates hierarchy of
                   9091:       categories and subcategories.
                   9092: 
                   9093: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
                   9094: 
                   9095: parent - parent of current category item
                   9096: 
                   9097: path - Array containing all categories back up through the hierarchy from the
                   9098:        current category to the top level.
                   9099: 
                   9100: currcategories - reference to array of current categories assigned to the course
                   9101: 
                   9102: Returns: $output (markup to be displayed).
                   9103: 
                   9104: =cut
                   9105: 
                   9106: sub assign_category_rows {
                   9107:     my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
                   9108:     my ($text,$name,$item,$chgstr);
                   9109:     if (ref($cats) eq 'ARRAY') {
                   9110:         my $maxdepth = scalar(@{$cats});
                   9111:         if (ref($cats->[$depth]) eq 'HASH') {
                   9112:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   9113:                 my $numchildren = @{$cats->[$depth]{$parent}};
                   9114:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   9115:                 $text .= '<td><table class="LC_datatable">';
                   9116:                 for (my $j=0; $j<$numchildren; $j++) {
                   9117:                     $name = $cats->[$depth]{$parent}[$j];
                   9118:                     $item = &escape($name).':'.&escape($parent).':'.$depth;
                   9119:                     my $deeper = $depth+1;
                   9120:                     my $checked = '';
                   9121:                     if (ref($currcategories) eq 'ARRAY') {
                   9122:                         if (@{$currcategories} > 0) {
                   9123:                             if (grep(/^\Q$item\E$/,@{$currcategories})) {
                   9124:                                 $checked = ' checked="checked" ';
                   9125:                             }
                   9126:                         }
                   9127:                     }
1.664     raeburn  9128:                     $text .= '<tr><td><span class="LC_nobreak"><label>'.
                   9129:                              '<input type="checkbox" name="usecategory" value="'.
1.675     raeburn  9130:                              $item.'"'.$checked.' />'.$name.'</label></span>'.
                   9131:                              '<input type="hidden" name="catname" value="'.$name.'" />'.
                   9132:                              '</td><td>';
1.663     raeburn  9133:                     if (ref($path) eq 'ARRAY') {
                   9134:                         push(@{$path},$name);
                   9135:                         $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
                   9136:                         pop(@{$path});
                   9137:                     }
                   9138:                     $text .= '</td></tr>';
                   9139:                 }
                   9140:                 $text .= '</table></td>';
                   9141:             }
                   9142:         }
                   9143:     }
                   9144:     return $text;
                   9145: }
                   9146: 
1.655     raeburn  9147: ############################################################
                   9148: ############################################################
                   9149: 
                   9150: 
1.443     albertel 9151: sub commit_customrole {
1.664     raeburn  9152:     my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630     raeburn  9153:     my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443     albertel 9154:                          ($start?', '.&mt('starting').' '.localtime($start):'').
                   9155:                          ($end?', ending '.localtime($end):'').': <b>'.
                   9156:               &Apache::lonnet::assigncustomrole(
1.664     raeburn  9157:                  $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443     albertel 9158:                  '</b><br />';
                   9159:     return $output;
                   9160: }
                   9161: 
                   9162: sub commit_standardrole {
1.541     raeburn  9163:     my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
                   9164:     my ($output,$logmsg,$linefeed);
                   9165:     if ($context eq 'auto') {
                   9166:         $linefeed = "\n";
                   9167:     } else {
                   9168:         $linefeed = "<br />\n";
                   9169:     }  
1.443     albertel 9170:     if ($three eq 'st') {
1.541     raeburn  9171:         my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
                   9172:                                          $one,$two,$sec,$context);
                   9173:         if (($result =~ /^error/) || ($result eq 'not_in_class') || 
1.626     raeburn  9174:             ($result eq 'unknown_course') || ($result eq 'refused')) {
                   9175:             $output = $logmsg.' '.&mt('Error: ').$result."\n"; 
1.443     albertel 9176:         } else {
1.541     raeburn  9177:             $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443     albertel 9178:                ($start?', '.&mt('starting').' '.localtime($start):'').
1.541     raeburn  9179:                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
                   9180:             if ($context eq 'auto') {
                   9181:                 $output .= $result.$linefeed.&mt('Add to classlist').': ok';
                   9182:             } else {
                   9183:                $output .= '<b>'.$result.'</b>'.$linefeed.
                   9184:                &mt('Add to classlist').': <b>ok</b>';
                   9185:             }
                   9186:             $output .= $linefeed;
1.443     albertel 9187:         }
                   9188:     } else {
                   9189:         $output = &mt('Assigning').' '.$three.' in '.$url.
                   9190:                ($start?', '.&mt('starting').' '.localtime($start):'').
1.541     raeburn  9191:                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652     raeburn  9192:         my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541     raeburn  9193:         if ($context eq 'auto') {
                   9194:             $output .= $result.$linefeed;
                   9195:         } else {
                   9196:             $output .= '<b>'.$result.'</b>'.$linefeed;
                   9197:         }
1.443     albertel 9198:     }
                   9199:     return $output;
                   9200: }
                   9201: 
                   9202: sub commit_studentrole {
1.541     raeburn  9203:     my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626     raeburn  9204:     my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541     raeburn  9205:     if ($context eq 'auto') {
                   9206:         $linefeed = "\n";
                   9207:     } else {
                   9208:         $linefeed = '<br />'."\n";
                   9209:     }
1.443     albertel 9210:     if (defined($one) && defined($two)) {
                   9211:         my $cid=$one.'_'.$two;
                   9212:         my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
                   9213:         my $secchange = 0;
                   9214:         my $expire_role_result;
                   9215:         my $modify_section_result;
1.628     raeburn  9216:         if ($oldsec ne '-1') { 
                   9217:             if ($oldsec ne $sec) {
1.443     albertel 9218:                 $secchange = 1;
1.628     raeburn  9219:                 my $now = time;
1.443     albertel 9220:                 my $uurl='/'.$cid;
                   9221:                 $uurl=~s/\_/\//g;
                   9222:                 if ($oldsec) {
                   9223:                     $uurl.='/'.$oldsec;
                   9224:                 }
1.626     raeburn  9225:                 $oldsecurl = $uurl;
1.628     raeburn  9226:                 $expire_role_result = 
1.652     raeburn  9227:                     &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628     raeburn  9228:                 if ($env{'request.course.sec'} ne '') { 
                   9229:                     if ($expire_role_result eq 'refused') {
                   9230:                         my @roles = ('st');
                   9231:                         my @statuses = ('previous');
                   9232:                         my @roledoms = ($one);
                   9233:                         my $withsec = 1;
                   9234:                         my %roleshash = 
                   9235:                             &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
                   9236:                                               \@statuses,\@roles,\@roledoms,$withsec);
                   9237:                         if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
                   9238:                             my ($oldstart,$oldend) = 
                   9239:                                 split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
                   9240:                             if ($oldend > 0 && $oldend <= $now) {
                   9241:                                 $expire_role_result = 'ok';
                   9242:                             }
                   9243:                         }
                   9244:                     }
                   9245:                 }
1.443     albertel 9246:                 $result = $expire_role_result;
                   9247:             }
                   9248:         }
                   9249:         if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652     raeburn  9250:             $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443     albertel 9251:             if ($modify_section_result =~ /^ok/) {
                   9252:                 if ($secchange == 1) {
1.628     raeburn  9253:                     if ($sec eq '') {
                   9254:                         $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
                   9255:                     } else {
                   9256:                         $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
                   9257:                     }
1.443     albertel 9258:                 } elsif ($oldsec eq '-1') {
1.628     raeburn  9259:                     if ($sec eq '') {
                   9260:                         $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
                   9261:                     } else {
                   9262:                         $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                   9263:                     }
1.443     albertel 9264:                 } else {
1.628     raeburn  9265:                     if ($sec eq '') {
                   9266:                         $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
                   9267:                     } else {
                   9268:                         $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                   9269:                     }
1.443     albertel 9270:                 }
                   9271:             } else {
1.628     raeburn  9272:                 if ($secchange) {       
                   9273:                     $$logmsg .= &mt('Error when attempting section change for [_1] from old section "[_2]" to new section: "[_3]" in course [_4] -error:',$uname,$oldsec,$sec,$cid).' '.$modify_section_result.$linefeed;
                   9274:                 } else {
                   9275:                     $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
                   9276:                 }
1.443     albertel 9277:             }
                   9278:             $result = $modify_section_result;
                   9279:         } elsif ($secchange == 1) {
1.628     raeburn  9280:             if ($oldsec eq '') {
                   9281:                 $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
                   9282:             } else {
                   9283:                 $$logmsg .= &mt('Error when attempting to expire existing role for [_1] in section [_2] in course [_3] -error: ',$uname,$oldsec,$cid).' '.$expire_role_result.$linefeed;
                   9284:             }
1.626     raeburn  9285:             if ($expire_role_result eq 'refused') {
                   9286:                 my $newsecurl = '/'.$cid;
                   9287:                 $newsecurl =~ s/\_/\//g;
                   9288:                 if ($sec ne '') {
                   9289:                     $newsecurl.='/'.$sec;
                   9290:                 }
                   9291:                 if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
                   9292:                     if ($sec eq '') {
                   9293:                         $$logmsg .= &mt('Although your current role has privileges to add students to section "[_1]", you do not have privileges to modify existing enrollments unaffiliated with any section.',$sec).$linefeed;
                   9294:                     } else {
                   9295:                         $$logmsg .= &mt('Although your current role has privileges to add students to section "[_1]", you do not have privileges to modify existing enrollments in other sections.',$sec).$linefeed;
                   9296:                     }
                   9297:                 }
                   9298:             }
1.443     albertel 9299:         }
                   9300:     } else {
1.626     raeburn  9301:         $$logmsg .= &mt('Incomplete course id defined.').$linefeed.&mt('Addition of user [_1] from domain [_2] to course [_3], section [_4] not completed.',$uname,$udom,$one.'_'.$two,$sec).$linefeed;
1.443     albertel 9302:         $result = "error: incomplete course id\n";
                   9303:     }
                   9304:     return $result;
                   9305: }
                   9306: 
                   9307: ############################################################
                   9308: ############################################################
                   9309: 
1.566     albertel 9310: sub check_clone {
1.578     raeburn  9311:     my ($args,$linefeed) = @_;
1.566     albertel 9312:     my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
                   9313:     my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
                   9314:     my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
                   9315:     my $clonemsg;
                   9316:     my $can_clone = 0;
                   9317: 
                   9318:     if ($clonehome eq 'no_host') {
1.578     raeburn  9319:         $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 9320:     } else {
                   9321: 	my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.568     albertel 9322: 	if ($env{'request.role.domain'} eq $args->{'clonedomain'}) {
1.566     albertel 9323: 	    $can_clone = 1;
                   9324: 	} else {
                   9325: 	    my %clonehash = &Apache::lonnet::get('environment',['cloners'],
                   9326: 						 $args->{'clonedomain'},$args->{'clonecourse'});
                   9327: 	    my @cloners = split(/,/,$clonehash{'cloners'});
1.578     raeburn  9328:             if (grep(/^\*$/,@cloners)) {
                   9329:                 $can_clone = 1;
                   9330:             } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
                   9331:                 $can_clone = 1;
                   9332:             } else {
                   9333: 	        my %roleshash =
                   9334: 		    &Apache::lonnet::get_my_roles($args->{'ccuname'},
                   9335: 					 $args->{'ccdomain'},
                   9336:                                          'userroles',['active'],['cc'],
                   9337: 					 [$args->{'clonedomain'}]);
                   9338: 	        if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
                   9339: 		    $can_clone = 1;
                   9340: 	        } else {
                   9341:                     $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'});
                   9342: 	        }
1.566     albertel 9343: 	    }
1.578     raeburn  9344:         }
1.566     albertel 9345:     }
                   9346:     return ($can_clone, $clonemsg, $cloneid, $clonehome);
                   9347: }
                   9348: 
1.444     albertel 9349: sub construct_course {
1.541     raeburn  9350:     my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context) = @_;
1.444     albertel 9351:     my $outcome;
1.541     raeburn  9352:     my $linefeed =  '<br />'."\n";
                   9353:     if ($context eq 'auto') {
                   9354:         $linefeed = "\n";
                   9355:     }
1.566     albertel 9356: 
                   9357: #
                   9358: # Are we cloning?
                   9359: #
                   9360:     my ($can_clone, $clonemsg, $cloneid, $clonehome);
                   9361:     if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578     raeburn  9362: 	($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566     albertel 9363: 	if ($context ne 'auto') {
1.578     raeburn  9364:             if ($clonemsg ne '') {
                   9365: 	        $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
                   9366:             }
1.566     albertel 9367: 	}
                   9368: 	$outcome .= $clonemsg.$linefeed;
                   9369: 
                   9370:         if (!$can_clone) {
                   9371: 	    return (0,$outcome);
                   9372: 	}
                   9373:     }
                   9374: 
1.444     albertel 9375: #
                   9376: # Open course
                   9377: #
                   9378:     my $crstype = lc($args->{'crstype'});
                   9379:     my %cenv=();
                   9380:     $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
                   9381:                                              $args->{'cdescr'},
                   9382:                                              $args->{'curl'},
                   9383:                                              $args->{'course_home'},
                   9384:                                              $args->{'nonstandard'},
                   9385:                                              $args->{'crscode'},
                   9386:                                              $args->{'ccuname'}.':'.
                   9387:                                              $args->{'ccdomain'},
                   9388:                                              $args->{'crstype'});
                   9389: 
                   9390:     # Note: The testing routines depend on this being output; see 
                   9391:     # Utils::Course. This needs to at least be output as a comment
                   9392:     # if anyone ever decides to not show this, and Utils::Course::new
                   9393:     # will need to be suitably modified.
1.541     raeburn  9394:     $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.444     albertel 9395: #
                   9396: # Check if created correctly
                   9397: #
1.479     albertel 9398:     ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444     albertel 9399:     my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.541     raeburn  9400:     $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566     albertel 9401: 
1.444     albertel 9402: #
1.566     albertel 9403: # Do the cloning
                   9404: #   
                   9405:     if ($can_clone && $cloneid) {
                   9406: 	$clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
                   9407: 	if ($context ne 'auto') {
                   9408: 	    $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
                   9409: 	}
                   9410: 	$outcome .= $clonemsg.$linefeed;
                   9411: 	my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444     albertel 9412: # Copy all files
1.637     www      9413: 	&Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444     albertel 9414: # Restore URL
1.566     albertel 9415: 	$cenv{'url'}=$oldcenv{'url'};
1.444     albertel 9416: # Restore title
1.566     albertel 9417: 	$cenv{'description'}=$oldcenv{'description'};
1.444     albertel 9418: # Mark as cloned
1.566     albertel 9419: 	$cenv{'clonedfrom'}=$cloneid;
1.638     www      9420: # Need to clone grading mode
                   9421:         my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
                   9422:         $cenv{'grading'}=$newenv{'grading'};
                   9423: # Do not clone these environment entries
                   9424:         &Apache::lonnet::del('environment',
                   9425:                   ['default_enrollment_start_date',
                   9426:                    'default_enrollment_end_date',
                   9427:                    'question.email',
                   9428:                    'policy.email',
                   9429:                    'comment.email',
                   9430:                    'pch.users.denied',
1.725     raeburn  9431:                    'plc.users.denied',
                   9432:                    'hidefromcat',
                   9433:                    'categories'],
1.638     www      9434:                    $$crsudom,$$crsunum);
1.444     albertel 9435:     }
1.566     albertel 9436: 
1.444     albertel 9437: #
                   9438: # Set environment (will override cloned, if existing)
                   9439: #
                   9440:     my @sections = ();
                   9441:     my @xlists = ();
                   9442:     if ($args->{'crstype'}) {
                   9443:         $cenv{'type'}=$args->{'crstype'};
                   9444:     }
                   9445:     if ($args->{'crsid'}) {
                   9446:         $cenv{'courseid'}=$args->{'crsid'};
                   9447:     }
                   9448:     if ($args->{'crscode'}) {
                   9449:         $cenv{'internal.coursecode'}=$args->{'crscode'};
                   9450:     }
                   9451:     if ($args->{'crsquota'} ne '') {
                   9452:         $cenv{'internal.coursequota'}=$args->{'crsquota'};
                   9453:     } else {
                   9454:         $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
                   9455:     }
                   9456:     if ($args->{'ccuname'}) {
                   9457:         $cenv{'internal.courseowner'} = $args->{'ccuname'}.
                   9458:                                         ':'.$args->{'ccdomain'};
                   9459:     } else {
                   9460:         $cenv{'internal.courseowner'} = $args->{'curruser'};
                   9461:     }
                   9462:     my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
                   9463:     if ($args->{'crssections'}) {
                   9464:         $cenv{'internal.sectionnums'} = '';
                   9465:         if ($args->{'crssections'} =~ m/,/) {
                   9466:             @sections = split/,/,$args->{'crssections'};
                   9467:         } else {
                   9468:             $sections[0] = $args->{'crssections'};
                   9469:         }
                   9470:         if (@sections > 0) {
                   9471:             foreach my $item (@sections) {
                   9472:                 my ($sec,$gp) = split/:/,$item;
                   9473:                 my $class = $args->{'crscode'}.$sec;
                   9474:                 my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
                   9475:                 $cenv{'internal.sectionnums'} .= $item.',';
                   9476:                 unless ($addcheck eq 'ok') {
                   9477:                     push @badclasses, $class;
                   9478:                 }
                   9479:             }
                   9480:             $cenv{'internal.sectionnums'} =~ s/,$//;
                   9481:         }
                   9482:     }
                   9483: # do not hide course coordinator from staff listing, 
                   9484: # even if privileged
                   9485:     $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   9486: # add crosslistings
                   9487:     if ($args->{'crsxlist'}) {
                   9488:         $cenv{'internal.crosslistings'}='';
                   9489:         if ($args->{'crsxlist'} =~ m/,/) {
                   9490:             @xlists = split/,/,$args->{'crsxlist'};
                   9491:         } else {
                   9492:             $xlists[0] = $args->{'crsxlist'};
                   9493:         }
                   9494:         if (@xlists > 0) {
                   9495:             foreach my $item (@xlists) {
                   9496:                 my ($xl,$gp) = split/:/,$item;
                   9497:                 my $addcheck =  &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
                   9498:                 $cenv{'internal.crosslistings'} .= $item.',';
                   9499:                 unless ($addcheck eq 'ok') {
                   9500:                     push @badclasses, $xl;
                   9501:                 }
                   9502:             }
                   9503:             $cenv{'internal.crosslistings'} =~ s/,$//;
                   9504:         }
                   9505:     }
                   9506:     if ($args->{'autoadds'}) {
                   9507:         $cenv{'internal.autoadds'}=$args->{'autoadds'};
                   9508:     }
                   9509:     if ($args->{'autodrops'}) {
                   9510:         $cenv{'internal.autodrops'}=$args->{'autodrops'};
                   9511:     }
                   9512: # check for notification of enrollment changes
                   9513:     my @notified = ();
                   9514:     if ($args->{'notify_owner'}) {
                   9515:         if ($args->{'ccuname'} ne '') {
                   9516:             push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
                   9517:         }
                   9518:     }
                   9519:     if ($args->{'notify_dc'}) {
                   9520:         if ($uname ne '') { 
1.630     raeburn  9521:             push(@notified,$uname.':'.$udom);
1.444     albertel 9522:         }
                   9523:     }
                   9524:     if (@notified > 0) {
                   9525:         my $notifylist;
                   9526:         if (@notified > 1) {
                   9527:             $notifylist = join(',',@notified);
                   9528:         } else {
                   9529:             $notifylist = $notified[0];
                   9530:         }
                   9531:         $cenv{'internal.notifylist'} = $notifylist;
                   9532:     }
                   9533:     if (@badclasses > 0) {
                   9534:         my %lt=&Apache::lonlocal::texthash(
                   9535:                 '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',
                   9536:                 'dnhr' => 'does not have rights to access enrollment in these classes',
                   9537:                 'adby' => 'as determined by the policies of your institution on access to official classlists'
                   9538:         );
1.541     raeburn  9539:         my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
                   9540:                            ' ('.$lt{'adby'}.')';
                   9541:         if ($context eq 'auto') {
                   9542:             $outcome .= $badclass_msg.$linefeed;
1.566     albertel 9543:             $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541     raeburn  9544:             foreach my $item (@badclasses) {
                   9545:                 if ($context eq 'auto') {
                   9546:                     $outcome .= " - $item\n";
                   9547:                 } else {
                   9548:                     $outcome .= "<li>$item</li>\n";
                   9549:                 }
                   9550:             }
                   9551:             if ($context eq 'auto') {
                   9552:                 $outcome .= $linefeed;
                   9553:             } else {
1.566     albertel 9554:                 $outcome .= "</ul><br /><br /></div>\n";
1.541     raeburn  9555:             }
                   9556:         } 
1.444     albertel 9557:     }
                   9558:     if ($args->{'no_end_date'}) {
                   9559:         $args->{'endaccess'} = 0;
                   9560:     }
                   9561:     $cenv{'internal.autostart'}=$args->{'enrollstart'};
                   9562:     $cenv{'internal.autoend'}=$args->{'enrollend'};
                   9563:     $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
                   9564:     $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
                   9565:     if ($args->{'showphotos'}) {
                   9566:       $cenv{'internal.showphotos'}=$args->{'showphotos'};
                   9567:     }
                   9568:     $cenv{'internal.authtype'} = $args->{'authtype'};
                   9569:     $cenv{'internal.autharg'} = $args->{'autharg'}; 
                   9570:     if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
                   9571:         if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'}  eq '') {
1.541     raeburn  9572:             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'); 
                   9573:             if ($context eq 'auto') {
                   9574:                 $outcome .= $krb_msg;
                   9575:             } else {
1.566     albertel 9576:                 $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541     raeburn  9577:             }
                   9578:             $outcome .= $linefeed;
1.444     albertel 9579:         }
                   9580:     }
                   9581:     if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
                   9582:        if ($args->{'setpolicy'}) {
                   9583:            $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   9584:        }
                   9585:        if ($args->{'setcontent'}) {
                   9586:            $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   9587:        }
                   9588:     }
                   9589:     if ($args->{'reshome'}) {
                   9590: 	$cenv{'reshome'}=$args->{'reshome'}.'/';
                   9591: 	$cenv{'reshome'}=~s/\/+$/\//;
                   9592:     }
                   9593: #
                   9594: # course has keyed access
                   9595: #
                   9596:     if ($args->{'setkeys'}) {
                   9597:        $cenv{'keyaccess'}='yes';
                   9598:     }
                   9599: # if specified, key authority is not course, but user
                   9600: # only active if keyaccess is yes
                   9601:     if ($args->{'keyauth'}) {
1.487     albertel 9602: 	my ($user,$domain) = split(':',$args->{'keyauth'});
                   9603: 	$user = &LONCAPA::clean_username($user);
                   9604: 	$domain = &LONCAPA::clean_username($domain);
1.488     foxr     9605: 	if ($user ne '' && $domain ne '') {
1.487     albertel 9606: 	    $cenv{'keyauth'}=$user.':'.$domain;
1.444     albertel 9607: 	}
                   9608:     }
                   9609: 
                   9610:     if ($args->{'disresdis'}) {
                   9611:         $cenv{'pch.roles.denied'}='st';
                   9612:     }
                   9613:     if ($args->{'disablechat'}) {
                   9614:         $cenv{'plc.roles.denied'}='st';
                   9615:     }
                   9616: 
                   9617:     # Record we've not yet viewed the Course Initialization Helper for this 
                   9618:     # course
                   9619:     $cenv{'course.helper.not.run'} = 1;
                   9620:     #
                   9621:     # Use new Randomseed
                   9622:     #
                   9623:     $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
                   9624:     $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
                   9625:     #
                   9626:     # The encryption code and receipt prefix for this course
                   9627:     #
                   9628:     $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
                   9629:     $cenv{'internal.encpref'}=100+int(9*rand(99));
                   9630:     #
                   9631:     # By default, use standard grading
                   9632:     if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
                   9633: 
1.541     raeburn  9634:     $outcome .= $linefeed.&mt('Setting environment').': '.                 
                   9635:           &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444     albertel 9636: #
                   9637: # Open all assignments
                   9638: #
                   9639:     if ($args->{'openall'}) {
                   9640:        my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
                   9641:        my %storecontent = ($storeunder         => time,
                   9642:                            $storeunder.'.type' => 'date_start');
                   9643:        
                   9644:        $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541     raeburn  9645:                  ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444     albertel 9646:    }
                   9647: #
                   9648: # Set first page
                   9649: #
                   9650:     unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
                   9651: 	    || ($cloneid)) {
1.445     albertel 9652: 	use LONCAPA::map;
1.444     albertel 9653: 	$outcome .= &mt('Setting first resource').': ';
1.445     albertel 9654: 
                   9655: 	my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
                   9656:         my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
                   9657: 
1.444     albertel 9658:         $outcome .= ($fatal?$errtext:'read ok').' - ';
                   9659:         my $title; my $url;
                   9660:         if ($args->{'firstres'} eq 'syl') {
1.690     bisitz   9661: 	    $title=&mt('Syllabus');
1.444     albertel 9662:             $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
                   9663:         } else {
1.690     bisitz   9664:             $title=&mt('Navigate Contents');
1.444     albertel 9665:             $url='/adm/navmaps';
                   9666:         }
1.445     albertel 9667: 
                   9668:         $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
                   9669: 	(my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
                   9670: 
                   9671: 	if ($errtext) { $fatal=2; }
1.541     raeburn  9672:         $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444     albertel 9673:     }
1.566     albertel 9674: 
                   9675:     return (1,$outcome);
1.444     albertel 9676: }
                   9677: 
                   9678: ############################################################
                   9679: ############################################################
                   9680: 
1.378     raeburn  9681: sub course_type {
                   9682:     my ($cid) = @_;
                   9683:     if (!defined($cid)) {
                   9684:         $cid = $env{'request.course.id'};
                   9685:     }
1.404     albertel 9686:     if (defined($env{'course.'.$cid.'.type'})) {
                   9687:         return $env{'course.'.$cid.'.type'};
1.378     raeburn  9688:     } else {
                   9689:         return 'Course';
1.377     raeburn  9690:     }
                   9691: }
1.156     albertel 9692: 
1.406     raeburn  9693: sub group_term {
                   9694:     my $crstype = &course_type();
                   9695:     my %names = (
                   9696:                   'Course' => 'group',
                   9697:                   'Group' => 'team',
                   9698:                 );
                   9699:     return $names{$crstype};
                   9700: }
                   9701: 
1.156     albertel 9702: sub icon {
                   9703:     my ($file)=@_;
1.505     albertel 9704:     my $curfext = lc((split(/\./,$file))[-1]);
1.168     albertel 9705:     my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156     albertel 9706:     my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168     albertel 9707:     if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
                   9708: 	if (-e  $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
                   9709: 	          $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   9710: 	            $curfext.".gif") {
                   9711: 	    $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   9712: 		$curfext.".gif";
                   9713: 	}
                   9714:     }
1.249     albertel 9715:     return &lonhttpdurl($iconname);
1.154     albertel 9716: } 
1.84      albertel 9717: 
1.575     albertel 9718: sub lonhttpdurl {
1.692     www      9719: #
                   9720: # Had been used for "small fry" static images on separate port 8080.
                   9721: # Modify here if lightweight http functionality desired again.
                   9722: # Currently eliminated due to increasing firewall issues.
                   9723: #
1.575     albertel 9724:     my ($url)=@_;
1.692     www      9725:     return $url;
1.215     albertel 9726: }
                   9727: 
1.213     albertel 9728: sub connection_aborted {
                   9729:     my ($r)=@_;
                   9730:     $r->print(" ");$r->rflush();
                   9731:     my $c = $r->connection;
                   9732:     return $c->aborted();
                   9733: }
                   9734: 
1.221     foxr     9735: #    Escapes strings that may have embedded 's that will be put into
1.222     foxr     9736: #    strings as 'strings'.
                   9737: sub escape_single {
1.221     foxr     9738:     my ($input) = @_;
1.223     albertel 9739:     $input =~ s/\\/\\\\/g;	# Escape the \'s..(must be first)>
1.221     foxr     9740:     $input =~ s/\'/\\\'/g;	# Esacpe the 's....
                   9741:     return $input;
                   9742: }
1.223     albertel 9743: 
1.222     foxr     9744: #  Same as escape_single, but escape's "'s  This 
                   9745: #  can be used for  "strings"
                   9746: sub escape_double {
                   9747:     my ($input) = @_;
                   9748:     $input =~ s/\\/\\\\/g;	# Escape the /'s..(must be first)>
                   9749:     $input =~ s/\"/\\\"/g;	# Esacpe the "s....
                   9750:     return $input;
                   9751: }
1.223     albertel 9752:  
1.222     foxr     9753: #   Escapes the last element of a full URL.
                   9754: sub escape_url {
                   9755:     my ($url)   = @_;
1.238     raeburn  9756:     my @urlslices = split(/\//, $url,-1);
1.369     www      9757:     my $lastitem = &escape(pop(@urlslices));
1.223     albertel 9758:     return join('/',@urlslices).'/'.$lastitem;
1.222     foxr     9759: }
1.462     albertel 9760: 
                   9761: # -------------------------------------------------------- Initliaze user login
                   9762: sub init_user_environment {
1.463     albertel 9763:     my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462     albertel 9764:     my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
                   9765: 
                   9766:     my $public=($username eq 'public' && $domain eq 'public');
                   9767: 
                   9768: # See if old ID present, if so, remove
                   9769: 
                   9770:     my ($filename,$cookie,$userroles);
                   9771:     my $now=time;
                   9772: 
                   9773:     if ($public) {
                   9774: 	my $max_public=100;
                   9775: 	my $oldest;
                   9776: 	my $oldest_time=0;
                   9777: 	for(my $next=1;$next<=$max_public;$next++) {
                   9778: 	    if (-e $lonids."/publicuser_$next.id") {
                   9779: 		my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
                   9780: 		if ($mtime<$oldest_time || !$oldest_time) {
                   9781: 		    $oldest_time=$mtime;
                   9782: 		    $oldest=$next;
                   9783: 		}
                   9784: 	    } else {
                   9785: 		$cookie="publicuser_$next";
                   9786: 		last;
                   9787: 	    }
                   9788: 	}
                   9789: 	if (!$cookie) { $cookie="publicuser_$oldest"; }
                   9790:     } else {
1.463     albertel 9791: 	# if this isn't a robot, kill any existing non-robot sessions
                   9792: 	if (!$args->{'robot'}) {
                   9793: 	    opendir(DIR,$lonids);
                   9794: 	    while ($filename=readdir(DIR)) {
                   9795: 		if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
                   9796: 		    unlink($lonids.'/'.$filename);
                   9797: 		}
1.462     albertel 9798: 	    }
1.463     albertel 9799: 	    closedir(DIR);
1.462     albertel 9800: 	}
                   9801: # Give them a new cookie
1.463     albertel 9802: 	my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684     www      9803: 		                   : $now.$$.int(rand(10000)));
1.463     albertel 9804: 	$cookie="$username\_$id\_$domain\_$authhost";
1.462     albertel 9805:     
                   9806: # Initialize roles
                   9807: 
                   9808: 	$userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
                   9809:     }
                   9810: # ------------------------------------ Check browser type and MathML capability
                   9811: 
                   9812:     my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
                   9813:         $clientunicode,$clientos) = &decode_user_agent($r);
                   9814: 
                   9815: # -------------------------------------- Any accessibility options to remember?
                   9816:     if (($form->{'interface'}) && ($form->{'remember'} eq 'true')) {
                   9817: 	foreach my $option ('imagesuppress','appletsuppress',
                   9818: 			    'embedsuppress','fontenhance','blackwhite') {
                   9819: 	    if ($form->{$option} eq 'true') {
                   9820: 		&Apache::lonnet::put('environment',{$option => 'on'},
                   9821: 				     $domain,$username);
                   9822: 	    } else {
                   9823: 		&Apache::lonnet::del('environment',[$option],
                   9824: 				     $domain,$username);
                   9825: 	    }
                   9826: 	}
                   9827:     }
                   9828: # ------------------------------------------------------------- Get environment
                   9829: 
                   9830:     my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
                   9831:     my ($tmp) = keys(%userenv);
                   9832:     if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   9833: 	# default remote control to off
                   9834: 	if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
                   9835:     } else {
                   9836: 	undef(%userenv);
                   9837:     }
                   9838:     if (($userenv{'interface'}) && (!$form->{'interface'})) {
                   9839: 	$form->{'interface'}=$userenv{'interface'};
                   9840:     }
                   9841:     $env{'environment.remote'}=$userenv{'remote'};
                   9842:     if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
                   9843: 
                   9844: # --------------- Do not trust query string to be put directly into environment
                   9845:     foreach my $option ('imagesuppress','appletsuppress',
                   9846: 			'embedsuppress','fontenhance','blackwhite',
                   9847: 			'interface','localpath','localres') {
                   9848: 	$form->{$option}=~s/[\n\r\=]//gs;
                   9849:     }
                   9850: # --------------------------------------------------------- Write first profile
                   9851: 
                   9852:     {
                   9853: 	my %initial_env = 
                   9854: 	    ("user.name"          => $username,
                   9855: 	     "user.domain"        => $domain,
                   9856: 	     "user.home"          => $authhost,
                   9857: 	     "browser.type"       => $clientbrowser,
                   9858: 	     "browser.version"    => $clientversion,
                   9859: 	     "browser.mathml"     => $clientmathml,
                   9860: 	     "browser.unicode"    => $clientunicode,
                   9861: 	     "browser.os"         => $clientos,
                   9862: 	     "server.domain"      => $Apache::lonnet::perlvar{'lonDefDomain'},
                   9863: 	     "request.course.fn"  => '',
                   9864: 	     "request.course.uri" => '',
                   9865: 	     "request.course.sec" => '',
                   9866: 	     "request.role"       => 'cm',
                   9867: 	     "request.role.adv"   => $env{'user.adv'},
                   9868: 	     "request.host"       => $ENV{'REMOTE_ADDR'},);
                   9869: 
                   9870:         if ($form->{'localpath'}) {
                   9871: 	    $initial_env{"browser.localpath"}  = $form->{'localpath'};
                   9872: 	    $initial_env{"browser.localres"}   = $form->{'localres'};
                   9873:         }
                   9874: 	
                   9875: 	if ($public) {
                   9876: 	    $initial_env{"environment.remote"} = "off";
                   9877: 	}
                   9878: 	if ($form->{'interface'}) {
                   9879: 	    $form->{'interface'}=~s/\W//gs;
                   9880: 	    $initial_env{"browser.interface"} = $form->{'interface'};
                   9881: 	    $env{'browser.interface'}=$form->{'interface'};
                   9882: 	    foreach my $option ('imagesuppress','appletsuppress',
                   9883: 				'embedsuppress','fontenhance','blackwhite') {
                   9884: 		if (($form->{$option} eq 'true') ||
                   9885: 		    ($userenv{$option} eq 'on')) {
                   9886: 		    $initial_env{"browser.$option"} = "on";
                   9887: 		}
                   9888: 	    }
                   9889: 	}
                   9890: 
1.724     raeburn  9891:         foreach my $tool ('aboutme','blog','portfolio') {
                   9892:             $userenv{'availabletools.'.$tool} = 
                   9893:                 &Apache::lonnet::usertools_access($username,$domain,$tool,'reload');
                   9894:         }
                   9895: 
1.462     albertel 9896: 	$env{'user.environment'} = "$lonids/$cookie.id";
                   9897: 	
                   9898: 	if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
                   9899: 		 &GDBM_WRCREAT(),0640)) {
                   9900: 	    &_add_to_env(\%disk_env,\%initial_env);
                   9901: 	    &_add_to_env(\%disk_env,\%userenv,'environment.');
                   9902: 	    &_add_to_env(\%disk_env,$userroles);
1.463     albertel 9903: 	    if (ref($args->{'extra_env'})) {
                   9904: 		&_add_to_env(\%disk_env,$args->{'extra_env'});
                   9905: 	    }
1.462     albertel 9906: 	    untie(%disk_env);
                   9907: 	} else {
1.705     tempelho 9908: 	    &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
                   9909: 			   'Could not create environment storage in lonauth: '.$!.'</span>');
1.462     albertel 9910: 	    return 'error: '.$!;
                   9911: 	}
                   9912:     }
                   9913:     $env{'request.role'}='cm';
                   9914:     $env{'request.role.adv'}=$env{'user.adv'};
                   9915:     $env{'browser.type'}=$clientbrowser;
                   9916: 
                   9917:     return $cookie;
                   9918: 
                   9919: }
                   9920: 
                   9921: sub _add_to_env {
                   9922:     my ($idf,$env_data,$prefix) = @_;
1.676     raeburn  9923:     if (ref($env_data) eq 'HASH') {
                   9924:         while (my ($key,$value) = each(%$env_data)) {
                   9925: 	    $idf->{$prefix.$key} = $value;
                   9926: 	    $env{$prefix.$key}   = $value;
                   9927:         }
1.462     albertel 9928:     }
                   9929: }
                   9930: 
1.685     tempelho 9931: # --- Get the symbolic name of a problem and the url
                   9932: sub get_symb {
                   9933:     my ($request,$silent) = @_;
1.726     raeburn  9934:     (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685     tempelho 9935:     my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
                   9936:     if ($symb eq '') {
                   9937:         if (!$silent) {
                   9938:             $request->print("Unable to handle ambiguous references:$url:.");
                   9939:             return ();
                   9940:         }
                   9941:     }
                   9942:     &Apache::lonenc::check_decrypt(\$symb);
                   9943:     return ($symb);
                   9944: }
                   9945: 
                   9946: # --------------------------------------------------------------Get annotation
                   9947: 
                   9948: sub get_annotation {
                   9949:     my ($symb,$enc) = @_;
                   9950: 
                   9951:     my $key = $symb;
                   9952:     if (!$enc) {
                   9953:         $key =
                   9954:             &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
                   9955:     }
                   9956:     my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
                   9957:     return $annotation{$key};
                   9958: }
                   9959: 
                   9960: sub clean_symb {
1.731     raeburn  9961:     my ($symb,$delete_enc) = @_;
1.685     tempelho 9962: 
                   9963:     &Apache::lonenc::check_decrypt(\$symb);
                   9964:     my $enc = $env{'request.enc'};
1.731     raeburn  9965:     if ($delete_enc) {
1.730     raeburn  9966:         delete($env{'request.enc'});
                   9967:     }
1.685     tempelho 9968: 
                   9969:     return ($symb,$enc);
                   9970: }
1.462     albertel 9971: 
1.41      ng       9972: =pod
                   9973: 
                   9974: =back
                   9975: 
1.112     bowersj2 9976: =cut
1.41      ng       9977: 
1.112     bowersj2 9978: 1;
                   9979: __END__;
1.41      ng       9980: 

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