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

1.10      albertel    1: # The LearningOnline Network with CAPA
1.1       albertel    2: # a pile of common routines
1.10      albertel    3: #
1.792   ! raeburn     4: # $Id: loncommon.pm,v 1.791 2009/04/22 11:21:13 tempelho 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');
1.776     bisitz    409: <script type="text/javascript" language="Javascript">
1.74      www       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";
1.776     bisitz    455: <script type="text/javascript" language="JavaScript">
1.653     raeburn   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.776     bisitz    476: <script type="text/javascript" language="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.787     bisitz    605:    return '<span class="LC_nobreak">'
                    606:          ."<a href='"
                    607:          .'javascript:opencrsbrowser("'.$form.'","'.$unameele
                    608:          .'","'.$udomele.'","'.$desc.'","'.$extra_element
                    609:          .'","'.$multflag.'","'.$selecttype.'");'
                    610:          ."'>".&mt('Select Course').'</a>'
                    611:          .'</span>';
1.74      www       612: }
1.42      matthew   613: 
1.653     raeburn   614: sub selectauthor_link {
                    615:    my ($form,$udom)=@_;
                    616:    return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
                    617:           &mt('Select Author').'</a>';
                    618: }
                    619: 
1.273     raeburn   620: sub check_uncheck_jscript {
                    621:     my $jscript = <<"ENDSCRT";
                    622: function checkAll(field) {
                    623:     if (field.length > 0) {
                    624:         for (i = 0; i < field.length; i++) {
                    625:             field[i].checked = true ;
                    626:         }
                    627:     } else {
                    628:         field.checked = true
                    629:     }
                    630: }
                    631:  
                    632: function uncheckAll(field) {
                    633:     if (field.length > 0) {
                    634:         for (i = 0; i < field.length; i++) {
                    635:             field[i].checked = false ;
1.543     albertel  636:         }
                    637:     } else {
1.273     raeburn   638:         field.checked = false ;
                    639:     }
                    640: }
                    641: ENDSCRT
                    642:     return $jscript;
                    643: }
                    644: 
1.656     www       645: sub select_timezone {
1.659     raeburn   646:    my ($name,$selected,$onchange,$includeempty)=@_;
                    647:    my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
                    648:    if ($includeempty) {
                    649:        $output .= '<option value=""';
                    650:        if (($selected eq '') || ($selected eq 'local')) {
                    651:            $output .= ' selected="selected" ';
                    652:        }
                    653:        $output .= '> </option>';
                    654:    }
1.657     raeburn   655:    my @timezones = DateTime::TimeZone->all_names;
                    656:    foreach my $tzone (@timezones) {
                    657:        $output.= '<option value="'.$tzone.'"';
                    658:        if ($tzone eq $selected) {
                    659:            $output.=' selected="selected"';
                    660:        }
                    661:        $output.=">$tzone</option>\n";
1.656     www       662:    }
                    663:    $output.="</select>";
                    664:    return $output;
                    665: }
1.273     raeburn   666: 
1.687     raeburn   667: sub select_datelocale {
                    668:     my ($name,$selected,$onchange,$includeempty)=@_;
                    669:     my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
                    670:     if ($includeempty) {
                    671:         $output .= '<option value=""';
                    672:         if ($selected eq '') {
                    673:             $output .= ' selected="selected" ';
                    674:         }
                    675:         $output .= '> </option>';
                    676:     }
                    677:     my (@possibles,%locale_names);
                    678:     my @locales = DateTime::Locale::Catalog::Locales;
                    679:     foreach my $locale (@locales) {
                    680:         if (ref($locale) eq 'HASH') {
                    681:             my $id = $locale->{'id'};
                    682:             if ($id ne '') {
                    683:                 my $en_terr = $locale->{'en_territory'};
                    684:                 my $native_terr = $locale->{'native_territory'};
1.695     raeburn   685:                 my @languages = &Apache::lonlocal::preferred_languages();
1.687     raeburn   686:                 if (grep(/^en$/,@languages) || !@languages) {
                    687:                     if ($en_terr ne '') {
                    688:                         $locale_names{$id} = '('.$en_terr.')';
                    689:                     } elsif ($native_terr ne '') {
                    690:                         $locale_names{$id} = $native_terr;
                    691:                     }
                    692:                 } else {
                    693:                     if ($native_terr ne '') {
                    694:                         $locale_names{$id} = $native_terr.' ';
                    695:                     } elsif ($en_terr ne '') {
                    696:                         $locale_names{$id} = '('.$en_terr.')';
                    697:                     }
                    698:                 }
                    699:                 push (@possibles,$id);
                    700:             }
                    701:         }
                    702:     }
                    703:     foreach my $item (sort(@possibles)) {
                    704:         $output.= '<option value="'.$item.'"';
                    705:         if ($item eq $selected) {
                    706:             $output.=' selected="selected"';
                    707:         }
                    708:         $output.=">$item";
                    709:         if ($locale_names{$item} ne '') {
                    710:             $output.="  $locale_names{$item}</option>\n";
                    711:         }
                    712:         $output.="</option>\n";
                    713:     }
                    714:     $output.="</select>";
                    715:     return $output;
                    716: }
                    717: 
1.792   ! raeburn   718: sub select_language {
        !           719:     my ($name,$selected,$includeempty) = @_;
        !           720:     my %langchoices;
        !           721:     if ($includeempty) {
        !           722:         %langchoices = ('' => 'No language preference');
        !           723:     }
        !           724:     foreach my $id (&languageids()) {
        !           725:         my $code = &supportedlanguagecode($id);
        !           726:         if ($code) {
        !           727:             $langchoices{$code} = &plainlanguagedescription($id);
        !           728:         }
        !           729:     }
        !           730:     return &select_form($selected,$name,%langchoices);
        !           731: }
        !           732: 
1.42      matthew   733: =pod
1.36      matthew   734: 
1.648     raeburn   735: =item * &linked_select_forms(...)
1.36      matthew   736: 
                    737: linked_select_forms returns a string containing a <script></script> block
                    738: and html for two <select> menus.  The select menus will be linked in that
                    739: changing the value of the first menu will result in new values being placed
                    740: in the second menu.  The values in the select menu will appear in alphabetical
1.609     raeburn   741: order unless a defined order is provided.
1.36      matthew   742: 
                    743: linked_select_forms takes the following ordered inputs:
                    744: 
                    745: =over 4
                    746: 
1.112     bowersj2  747: =item * $formname, the name of the <form> tag
1.36      matthew   748: 
1.112     bowersj2  749: =item * $middletext, the text which appears between the <select> tags
1.36      matthew   750: 
1.112     bowersj2  751: =item * $firstdefault, the default value for the first menu
1.36      matthew   752: 
1.112     bowersj2  753: =item * $firstselectname, the name of the first <select> tag
1.36      matthew   754: 
1.112     bowersj2  755: =item * $secondselectname, the name of the second <select> tag
1.36      matthew   756: 
1.112     bowersj2  757: =item * $hashref, a reference to a hash containing the data for the menus.
1.36      matthew   758: 
1.609     raeburn   759: =item * $menuorder, the order of values in the first menu
                    760: 
1.41      ng        761: =back 
                    762: 
1.36      matthew   763: Below is an example of such a hash.  Only the 'text', 'default', and 
                    764: 'select2' keys must appear as stated.  keys(%menu) are the possible 
                    765: values for the first select menu.  The text that coincides with the 
1.41      ng        766: first menu value is given in $menu{$choice1}->{'text'}.  The values 
1.36      matthew   767: and text for the second menu are given in the hash pointed to by 
                    768: $menu{$choice1}->{'select2'}.  
                    769: 
1.112     bowersj2  770:  my %menu = ( A1 => { text =>"Choice A1" ,
                    771:                        default => "B3",
                    772:                        select2 => { 
                    773:                            B1 => "Choice B1",
                    774:                            B2 => "Choice B2",
                    775:                            B3 => "Choice B3",
                    776:                            B4 => "Choice B4"
1.609     raeburn   777:                            },
                    778:                        order => ['B4','B3','B1','B2'],
1.112     bowersj2  779:                    },
                    780:                A2 => { text =>"Choice A2" ,
                    781:                        default => "C2",
                    782:                        select2 => { 
                    783:                            C1 => "Choice C1",
                    784:                            C2 => "Choice C2",
                    785:                            C3 => "Choice C3"
1.609     raeburn   786:                            },
                    787:                        order => ['C2','C1','C3'],
1.112     bowersj2  788:                    },
                    789:                A3 => { text =>"Choice A3" ,
                    790:                        default => "D6",
                    791:                        select2 => { 
                    792:                            D1 => "Choice D1",
                    793:                            D2 => "Choice D2",
                    794:                            D3 => "Choice D3",
                    795:                            D4 => "Choice D4",
                    796:                            D5 => "Choice D5",
                    797:                            D6 => "Choice D6",
                    798:                            D7 => "Choice D7"
1.609     raeburn   799:                            },
                    800:                        order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112     bowersj2  801:                    }
                    802:                );
1.36      matthew   803: 
                    804: =cut
                    805: 
                    806: sub linked_select_forms {
                    807:     my ($formname,
                    808:         $middletext,
                    809:         $firstdefault,
                    810:         $firstselectname,
                    811:         $secondselectname, 
1.609     raeburn   812:         $hashref,
                    813:         $menuorder,
1.36      matthew   814:         ) = @_;
                    815:     my $second = "document.$formname.$secondselectname";
                    816:     my $first = "document.$formname.$firstselectname";
                    817:     # output the javascript to do the changing
                    818:     my $result = '';
1.776     bisitz    819:     $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.36      matthew   820:     $result.="var select2data = new Object();\n";
                    821:     $" = '","';
                    822:     my $debug = '';
                    823:     foreach my $s1 (sort(keys(%$hashref))) {
                    824:         $result.="select2data.d_$s1 = new Object();\n";        
                    825:         $result.="select2data.d_$s1.def = new String('".
                    826:             $hashref->{$s1}->{'default'}."');\n";
1.609     raeburn   827:         $result.="select2data.d_$s1.values = new Array(";
1.36      matthew   828:         my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609     raeburn   829:         if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
                    830:             @s2values = @{$hashref->{$s1}->{'order'}};
                    831:         }
1.36      matthew   832:         $result.="\"@s2values\");\n";
                    833:         $result.="select2data.d_$s1.texts = new Array(";        
                    834:         my @s2texts;
                    835:         foreach my $value (@s2values) {
                    836:             push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
                    837:         }
                    838:         $result.="\"@s2texts\");\n";
                    839:     }
                    840:     $"=' ';
                    841:     $result.= <<"END";
                    842: 
                    843: function select1_changed() {
                    844:     // Determine new choice
                    845:     var newvalue = "d_" + $first.value;
                    846:     // update select2
                    847:     var values     = select2data[newvalue].values;
                    848:     var texts      = select2data[newvalue].texts;
                    849:     var select2def = select2data[newvalue].def;
                    850:     var i;
                    851:     // out with the old
                    852:     for (i = 0; i < $second.options.length; i++) {
                    853:         $second.options[i] = null;
                    854:     }
                    855:     // in with the nuclear
                    856:     for (i=0;i<values.length; i++) {
                    857:         $second.options[i] = new Option(values[i]);
1.143     matthew   858:         $second.options[i].value = values[i];
1.36      matthew   859:         $second.options[i].text = texts[i];
                    860:         if (values[i] == select2def) {
                    861:             $second.options[i].selected = true;
                    862:         }
                    863:     }
                    864: }
                    865: </script>
                    866: END
                    867:     # output the initial values for the selection lists
                    868:     $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609     raeburn   869:     my @order = sort(keys(%{$hashref}));
                    870:     if (ref($menuorder) eq 'ARRAY') {
                    871:         @order = @{$menuorder};
                    872:     }
                    873:     foreach my $value (@order) {
1.36      matthew   874:         $result.="    <option value=\"$value\" ";
1.253     albertel  875:         $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119     www       876:         $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36      matthew   877:     }
                    878:     $result .= "</select>\n";
                    879:     my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
                    880:     $result .= $middletext;
                    881:     $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
                    882:     my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609     raeburn   883:     
                    884:     my @secondorder = sort(keys(%select2));
                    885:     if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
                    886:         @secondorder = @{$hashref->{$firstdefault}->{'order'}};
                    887:     }
                    888:     foreach my $value (@secondorder) {
1.36      matthew   889:         $result.="    <option value=\"$value\" ";        
1.253     albertel  890:         $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119     www       891:         $result.=">".&mt($select2{$value})."</option>\n";
1.36      matthew   892:     }
                    893:     $result .= "</select>\n";
                    894:     #    return $debug;
                    895:     return $result;
                    896: }   #  end of sub linked_select_forms {
                    897: 
1.45      matthew   898: =pod
1.44      bowersj2  899: 
1.648     raeburn   900: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height)
1.44      bowersj2  901: 
1.112     bowersj2  902: Returns a string corresponding to an HTML link to the given help
                    903: $topic, where $topic corresponds to the name of a .tex file in
                    904: /home/httpd/html/adm/help/tex, with underscores replaced by
                    905: spaces. 
                    906: 
                    907: $text will optionally be linked to the same topic, allowing you to
                    908: link text in addition to the graphic. If you do not want to link
                    909: text, but wish to specify one of the later parameters, pass an
                    910: empty string. 
                    911: 
                    912: $stayOnPage is a value that will be interpreted as a boolean. If true,
                    913: the link will not open a new window. If false, the link will open
                    914: a new window using Javascript. (Default is false.) 
                    915: 
                    916: $width and $height are optional numerical parameters that will
                    917: override the width and height of the popped up window, which may
                    918: be useful for certain help topics with big pictures included. 
1.44      bowersj2  919: 
                    920: =cut
                    921: 
                    922: sub help_open_topic {
1.48      bowersj2  923:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
                    924:     $text = "" if (not defined $text);
1.44      bowersj2  925:     $stayOnPage = 0 if (not defined $stayOnPage);
1.552     banghart  926:     if ($env{'browser.interface'} eq 'textual') {
1.79      www       927: 	$stayOnPage=1;
                    928:     }
1.44      bowersj2  929:     $width = 350 if (not defined $width);
                    930:     $height = 400 if (not defined $height);
                    931:     my $filename = $topic;
                    932:     $filename =~ s/ /_/g;
                    933: 
1.48      bowersj2  934:     my $template = "";
                    935:     my $link;
1.572     banghart  936:     
1.159     www       937:     $topic=~s/\W/\_/g;
1.44      bowersj2  938: 
1.572     banghart  939:     if (!$stayOnPage) {
1.72      bowersj2  940: 	$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  941:     } else {
1.48      bowersj2  942: 	$link = "/adm/help/${filename}.hlp";
                    943:     }
                    944: 
                    945:     # Add the text
1.755     neumanie  946:     if ($text ne "") {	
1.763     bisitz    947: 	$template.='<span class="LC_help_open_topic">'
                    948:                   .'<a target="_top" href="'.$link.'">'
                    949:                   .$text.'</a>';
1.48      bowersj2  950:     }
                    951: 
1.763     bisitz    952:     # (Always) Add the graphic
1.179     matthew   953:     my $title = &mt('Online Help');
1.667     raeburn   954:     my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.763     bisitz    955:     $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
                    956:               .'<img src="'.$helpicon.'" border="0"'
                    957:               .' alt="'.&mt('Help: [_1]',$topic).'"'
1.783     amueller  958:               .' title="'.$title.'"' 
1.763     bisitz    959:               .' /></a>';
                    960:     if ($text ne "") {	
                    961:         $template.='</span>';
                    962:     }
1.44      bowersj2  963:     return $template;
                    964: 
1.106     bowersj2  965: }
                    966: 
                    967: # This is a quicky function for Latex cheatsheet editing, since it 
                    968: # appears in at least four places
                    969: sub helpLatexCheatsheet {
1.732     raeburn   970:     my ($topic,$text,$not_author) = @_;
                    971:     my $out;
1.106     bowersj2  972:     my $addOther = '';
1.732     raeburn   973:     if ($topic) {
1.763     bisitz    974: 	$addOther = '<span>'.&Apache::loncommon::help_open_topic($topic,&mt($text),
                    975: 							       undef, undef, 600).
                    976: 								   '</span> ';
                    977:     }
                    978:     $out = '<span>' # Start cheatsheet
                    979: 	  .$addOther
                    980:           .'<span>'
                    981: 	  .&Apache::loncommon::help_open_topic('Greek_Symbols',&mt('Greek Symbols'),
                    982: 					       undef,undef,600)
                    983: 	  .'</span> <span>'
                    984: 	  .&Apache::loncommon::help_open_topic('Other_Symbols',&mt('Other Symbols'),
                    985: 					       undef,undef,600)
                    986: 	  .'</span>';
1.732     raeburn   987:     unless ($not_author) {
1.763     bisitz    988:         $out .= ' <span>'
                    989: 	       .&Apache::loncommon::help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),
                    990: 	                                            undef,undef,600)
                    991: 	       .'</span>';
1.732     raeburn   992:     }
1.763     bisitz    993:     $out .= '</span>'; # End cheatsheet
1.732     raeburn   994:     return $out;
1.172     www       995: }
                    996: 
1.430     albertel  997: sub general_help {
                    998:     my $helptopic='Student_Intro';
                    999:     if ($env{'request.role'}=~/^(ca|au)/) {
                   1000: 	$helptopic='Authoring_Intro';
                   1001:     } elsif ($env{'request.role'}=~/^cc/) {
                   1002: 	$helptopic='Course_Coordination_Intro';
1.672     raeburn  1003:     } elsif ($env{'request.role'}=~/^dc/) {
                   1004:         $helptopic='Domain_Coordination_Intro';
1.430     albertel 1005:     }
                   1006:     return $helptopic;
                   1007: }
                   1008: 
                   1009: sub update_help_link {
                   1010:     my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
                   1011:     my $origurl = $ENV{'REQUEST_URI'};
                   1012:     $origurl=~s|^/~|/priv/|;
                   1013:     my $timestamp = time;
                   1014:     foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
                   1015:         $$datum = &escape($$datum);
                   1016:     }
                   1017: 
                   1018:     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";
                   1019:     my $output .= <<"ENDOUTPUT";
                   1020: <script type="text/javascript">
                   1021: banner_link = '$banner_link';
                   1022: </script>
                   1023: ENDOUTPUT
                   1024:     return $output;
                   1025: }
                   1026: 
                   1027: # now just updates the help link and generates a blue icon
1.193     raeburn  1028: sub help_open_menu {
1.430     albertel 1029:     my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text) 
1.552     banghart 1030: 	= @_;    
1.430     albertel 1031:     $stayOnPage = 0 if (not defined $stayOnPage);
1.572     banghart 1032:     # only use pop-up help (stayOnPage == 0)
1.552     banghart 1033:     # if environment.remote is on (using remote control UI)
1.572     banghart 1034:     if ($env{'browser.interface'} eq 'textual' ||
                   1035:     	$env{'environment.remote'} eq 'off' ) {
1.552     banghart 1036:         $stayOnPage=1;
1.430     albertel 1037:     }
                   1038:     my $output;
                   1039:     if ($component_help) {
                   1040: 	if (!$text) {
                   1041: 	    $output=&help_open_topic($component_help,undef,$stayOnPage,
                   1042: 				       $width,$height);
                   1043: 	} else {
                   1044: 	    my $help_text;
                   1045: 	    $help_text=&unescape($topic);
                   1046: 	    $output='<table><tr><td>'.
                   1047: 		&help_open_topic($component_help,$help_text,$stayOnPage,
                   1048: 				 $width,$height).'</td></tr></table>';
                   1049: 	}
                   1050:     }
                   1051:     my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
                   1052:     return $output.$banner_link;
                   1053: }
                   1054: 
                   1055: sub top_nav_help {
                   1056:     my ($text) = @_;
1.436     albertel 1057:     $text = &mt($text);
1.572     banghart 1058:     my $stay_on_page = 
1.436     albertel 1059: 	($env{'browser.interface'}  eq 'textual' ||
                   1060: 	 $env{'environment.remote'} eq 'off' );
1.572     banghart 1061:     my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436     albertel 1062: 	                     : "javascript:helpMenu('open')";
1.572     banghart 1063:     my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436     albertel 1064: 
1.201     raeburn  1065:     my $title = &mt('Get help');
1.436     albertel 1066: 
                   1067:     return <<"END";
                   1068: $banner_link
                   1069:  <a href="$link" title="$title">$text</a>
                   1070: END
                   1071: }
                   1072: 
                   1073: sub help_menu_js {
                   1074:     my ($text) = @_;
                   1075: 
                   1076:     my $stayOnPage = 
                   1077: 	($env{'browser.interface'}  eq 'textual' ||
                   1078: 	 $env{'environment.remote'} eq 'off' );
                   1079: 
                   1080:     my $width = 620;
                   1081:     my $height = 600;
1.430     albertel 1082:     my $helptopic=&general_help();
                   1083:     my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261     albertel 1084:     my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331     albertel 1085:     my $start_page =
                   1086:         &Apache::loncommon::start_page('Help Menu', undef,
                   1087: 				       {'frameset'    => 1,
                   1088: 					'js_ready'    => 1,
                   1089: 					'add_entries' => {
                   1090: 					    'border' => '0',
1.579     raeburn  1091: 					    'rows'   => "110,*",},});
1.331     albertel 1092:     my $end_page =
                   1093:         &Apache::loncommon::end_page({'frameset' => 1,
                   1094: 				      'js_ready' => 1,});
                   1095: 
1.436     albertel 1096:     my $template .= <<"ENDTEMPLATE";
                   1097: <script type="text/javascript">
1.253     albertel 1098: // <!-- BEGIN LON-CAPA Internal
                   1099: // <![CDATA[
1.430     albertel 1100: var banner_link = '';
1.243     raeburn  1101: function helpMenu(target) {
                   1102:     var caller = this;
                   1103:     if (target == 'open') {
                   1104:         var newWindow = null;
                   1105:         try {
1.262     albertel 1106:             newWindow =  window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243     raeburn  1107:         }
                   1108:         catch(error) {
                   1109:             writeHelp(caller);
                   1110:             return;
                   1111:         }
                   1112:         if (newWindow) {
                   1113:             caller = newWindow;
                   1114:         }
1.193     raeburn  1115:     }
1.243     raeburn  1116:     writeHelp(caller);
                   1117:     return;
                   1118: }
                   1119: function writeHelp(caller) {
1.430     albertel 1120:     caller.document.writeln('$start_page<frame name="bannerframe"  src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243     raeburn  1121:     caller.document.close()
                   1122:     caller.focus()
1.193     raeburn  1123: }
1.253     albertel 1124: // ]]>
1.219     albertel 1125: // END LON-CAPA Internal -->
1.436     albertel 1126: </script>
1.193     raeburn  1127: ENDTEMPLATE
                   1128:     return $template;
                   1129: }
                   1130: 
1.172     www      1131: sub help_open_bug {
                   1132:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258     albertel 1133:     unless ($env{'user.adv'}) { return ''; }
1.172     www      1134:     unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
                   1135:     $text = "" if (not defined $text);
                   1136:     $stayOnPage = 0 if (not defined $stayOnPage);
1.258     albertel 1137:     if ($env{'browser.interface'} eq 'textual' ||
                   1138: 	$env{'environment.remote'} eq 'off' ) {
1.172     www      1139: 	$stayOnPage=1;
                   1140:     }
1.184     albertel 1141:     $width = 600 if (not defined $width);
                   1142:     $height = 600 if (not defined $height);
1.172     www      1143: 
                   1144:     $topic=~s/\W+/\+/g;
                   1145:     my $link='';
                   1146:     my $template='';
1.379     albertel 1147:     my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&amp;bug_file_loc='.
                   1148: 	&escape($ENV{'REQUEST_URI'}).'&amp;component='.$topic;
1.172     www      1149:     if (!$stayOnPage)
                   1150:     {
                   1151: 	$link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
                   1152:     }
                   1153:     else
                   1154:     {
                   1155: 	$link = $url;
                   1156:     }
                   1157:     # Add the text
                   1158:     if ($text ne "")
                   1159:     {
                   1160: 	$template .= 
                   1161:   "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705     tempelho 1162:   "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172     www      1163:     }
                   1164: 
                   1165:     # Add the graphic
1.179     matthew  1166:     my $title = &mt('Report a Bug');
1.215     albertel 1167:     my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172     www      1168:     $template .= <<"ENDTEMPLATE";
1.436     albertel 1169:  <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172     www      1170: ENDTEMPLATE
                   1171:     if ($text ne '') { $template.='</td></tr></table>' };
                   1172:     return $template;
                   1173: 
                   1174: }
                   1175: 
                   1176: sub help_open_faq {
                   1177:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258     albertel 1178:     unless ($env{'user.adv'}) { return ''; }
1.172     www      1179:     unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
                   1180:     $text = "" if (not defined $text);
                   1181:     $stayOnPage = 0 if (not defined $stayOnPage);
1.258     albertel 1182:     if ($env{'browser.interface'} eq 'textual' ||
                   1183: 	$env{'environment.remote'} eq 'off' ) {
1.172     www      1184: 	$stayOnPage=1;
                   1185:     }
                   1186:     $width = 350 if (not defined $width);
                   1187:     $height = 400 if (not defined $height);
                   1188: 
                   1189:     $topic=~s/\W+/\+/g;
                   1190:     my $link='';
                   1191:     my $template='';
                   1192:     my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
                   1193:     if (!$stayOnPage)
                   1194:     {
                   1195: 	$link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
                   1196:     }
                   1197:     else
                   1198:     {
                   1199: 	$link = $url;
                   1200:     }
                   1201: 
                   1202:     # Add the text
                   1203:     if ($text ne "")
                   1204:     {
                   1205: 	$template .= 
1.173     www      1206:   "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705     tempelho 1207:   "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172     www      1208:     }
                   1209: 
                   1210:     # Add the graphic
1.179     matthew  1211:     my $title = &mt('View the FAQ');
1.215     albertel 1212:     my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172     www      1213:     $template .= <<"ENDTEMPLATE";
1.436     albertel 1214:  <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172     www      1215: ENDTEMPLATE
                   1216:     if ($text ne '') { $template.='</td></tr></table>' };
                   1217:     return $template;
                   1218: 
1.44      bowersj2 1219: }
1.37      matthew  1220: 
1.180     matthew  1221: ###############################################################
                   1222: ###############################################################
                   1223: 
1.45      matthew  1224: =pod
                   1225: 
1.648     raeburn  1226: =item * &change_content_javascript():
1.256     matthew  1227: 
                   1228: This and the next function allow you to create small sections of an
                   1229: otherwise static HTML page that you can update on the fly with
                   1230: Javascript, even in Netscape 4.
                   1231: 
                   1232: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
                   1233: must be written to the HTML page once. It will prove the Javascript
                   1234: function "change(name, content)". Calling the change function with the
                   1235: name of the section 
                   1236: you want to update, matching the name passed to C<changable_area>, and
                   1237: the new content you want to put in there, will put the content into
                   1238: that area.
                   1239: 
                   1240: B<Note>: Netscape 4 only reserves enough space for the changable area
                   1241: to contain room for the original contents. You need to "make space"
                   1242: for whatever changes you wish to make, and be B<sure> to check your
                   1243: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
                   1244: it's adequate for updating a one-line status display, but little more.
                   1245: This script will set the space to 100% width, so you only need to
                   1246: worry about height in Netscape 4.
                   1247: 
                   1248: Modern browsers are much less limiting, and if you can commit to the
                   1249: user not using Netscape 4, this feature may be used freely with
                   1250: pretty much any HTML.
                   1251: 
                   1252: =cut
                   1253: 
                   1254: sub change_content_javascript {
                   1255:     # If we're on Netscape 4, we need to use Layer-based code
1.258     albertel 1256:     if ($env{'browser.type'} eq 'netscape' &&
                   1257: 	$env{'browser.version'} =~ /^4\./) {
1.256     matthew  1258: 	return (<<NETSCAPE4);
                   1259: 	function change(name, content) {
                   1260: 	    doc = document.layers[name+"___escape"].layers[0].document;
                   1261: 	    doc.open();
                   1262: 	    doc.write(content);
                   1263: 	    doc.close();
                   1264: 	}
                   1265: NETSCAPE4
                   1266:     } else {
                   1267: 	# Otherwise, we need to use semi-standards-compliant code
                   1268: 	# (technically, "innerHTML" isn't standard but the equivalent
                   1269: 	# is really scary, and every useful browser supports it
                   1270: 	return (<<DOMBASED);
                   1271: 	function change(name, content) {
                   1272: 	    element = document.getElementById(name);
                   1273: 	    element.innerHTML = content;
                   1274: 	}
                   1275: DOMBASED
                   1276:     }
                   1277: }
                   1278: 
                   1279: =pod
                   1280: 
1.648     raeburn  1281: =item * &changable_area($name,$origContent):
1.256     matthew  1282: 
                   1283: This provides a "changable area" that can be modified on the fly via
                   1284: the Javascript code provided in C<change_content_javascript>. $name is
                   1285: the name you will use to reference the area later; do not repeat the
                   1286: same name on a given HTML page more then once. $origContent is what
                   1287: the area will originally contain, which can be left blank.
                   1288: 
                   1289: =cut
                   1290: 
                   1291: sub changable_area {
                   1292:     my ($name, $origContent) = @_;
                   1293: 
1.258     albertel 1294:     if ($env{'browser.type'} eq 'netscape' &&
                   1295: 	$env{'browser.version'} =~ /^4\./) {
1.256     matthew  1296: 	# If this is netscape 4, we need to use the Layer tag
                   1297: 	return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
                   1298:     } else {
                   1299: 	return "<span id='$name'>$origContent</span>";
                   1300:     }
                   1301: }
                   1302: 
                   1303: =pod
                   1304: 
1.648     raeburn  1305: =item * &viewport_geometry_js 
1.590     raeburn  1306: 
                   1307: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
                   1308: 
                   1309: =cut
                   1310: 
                   1311: 
                   1312: sub viewport_geometry_js { 
                   1313:     return <<"GEOMETRY";
                   1314: var Geometry = {};
                   1315: function init_geometry() {
                   1316:     if (Geometry.init) { return };
                   1317:     Geometry.init=1;
                   1318:     if (window.innerHeight) {
                   1319:         Geometry.getViewportHeight   = function() { return window.innerHeight; };
                   1320:         Geometry.getViewportWidth   = function() { return window.innerWidth; };
                   1321:         Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
                   1322:         Geometry.getVerticalScroll   = function() { return window.pageYOffset; };
                   1323:     }
                   1324:     else if (document.documentElement && document.documentElement.clientHeight) {
                   1325:         Geometry.getViewportHeight =
                   1326:             function() { return document.documentElement.clientHeight; };
                   1327:         Geometry.getViewportWidth =
                   1328:             function() { return document.documentElement.clientWidth; };
                   1329: 
                   1330:         Geometry.getHorizontalScroll =
                   1331:             function() { return document.documentElement.scrollLeft; };
                   1332:         Geometry.getVerticalScroll =
                   1333:             function() { return document.documentElement.scrollTop; };
                   1334:     }
                   1335:     else if (document.body.clientHeight) {
                   1336:         Geometry.getViewportHeight =
                   1337:             function() { return document.body.clientHeight; };
                   1338:         Geometry.getViewportWidth =
                   1339:             function() { return document.body.clientWidth; };
                   1340:         Geometry.getHorizontalScroll =
                   1341:             function() { return document.body.scrollLeft; };
                   1342:         Geometry.getVerticalScroll =
                   1343:             function() { return document.body.scrollTop; };
                   1344:     }
                   1345: }
                   1346: 
                   1347: GEOMETRY
                   1348: }
                   1349: 
                   1350: =pod
                   1351: 
1.648     raeburn  1352: =item * &viewport_size_js()
1.590     raeburn  1353: 
                   1354: 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. 
                   1355: 
                   1356: =cut
                   1357: 
                   1358: sub viewport_size_js {
                   1359:     my $geometry = &viewport_geometry_js();
                   1360:     return <<"DIMS";
                   1361: 
                   1362: $geometry
                   1363: 
                   1364: function getViewportDims(width,height) {
                   1365:     init_geometry();
                   1366:     width.value = Geometry.getViewportWidth();
                   1367:     height.value = Geometry.getViewportHeight();
                   1368:     return;
                   1369: }
                   1370: 
                   1371: DIMS
                   1372: }
                   1373: 
                   1374: =pod
                   1375: 
1.648     raeburn  1376: =item * &resize_textarea_js()
1.565     albertel 1377: 
                   1378: emits the needed javascript to resize a textarea to be as big as possible
                   1379: 
                   1380: creates a function resize_textrea that takes two IDs first should be
                   1381: the id of the element to resize, second should be the id of a div that
                   1382: surrounds everything that comes after the textarea, this routine needs
                   1383: to be attached to the <body> for the onload and onresize events.
                   1384: 
1.648     raeburn  1385: =back
1.565     albertel 1386: 
                   1387: =cut
                   1388: 
                   1389: sub resize_textarea_js {
1.590     raeburn  1390:     my $geometry = &viewport_geometry_js();
1.565     albertel 1391:     return <<"RESIZE";
                   1392:     <script type="text/javascript">
1.590     raeburn  1393: $geometry
1.565     albertel 1394: 
1.588     albertel 1395: function getX(element) {
                   1396:     var x = 0;
                   1397:     while (element) {
                   1398: 	x += element.offsetLeft;
                   1399: 	element = element.offsetParent;
                   1400:     }
                   1401:     return x;
                   1402: }
                   1403: function getY(element) {
                   1404:     var y = 0;
                   1405:     while (element) {
                   1406: 	y += element.offsetTop;
                   1407: 	element = element.offsetParent;
                   1408:     }
                   1409:     return y;
                   1410: }
                   1411: 
                   1412: 
1.565     albertel 1413: function resize_textarea(textarea_id,bottom_id) {
                   1414:     init_geometry();
                   1415:     var textarea        = document.getElementById(textarea_id);
                   1416:     //alert(textarea);
                   1417: 
1.588     albertel 1418:     var textarea_top    = getY(textarea);
1.565     albertel 1419:     var textarea_height = textarea.offsetHeight;
                   1420:     var bottom          = document.getElementById(bottom_id);
1.588     albertel 1421:     var bottom_top      = getY(bottom);
1.565     albertel 1422:     var bottom_height   = bottom.offsetHeight;
                   1423:     var window_height   = Geometry.getViewportHeight();
1.588     albertel 1424:     var fudge           = 23;
1.565     albertel 1425:     var new_height      = window_height-fudge-textarea_top-bottom_height;
                   1426:     if (new_height < 300) {
                   1427: 	new_height = 300;
                   1428:     }
                   1429:     textarea.style.height=new_height+'px';
                   1430: }
                   1431: </script>
                   1432: RESIZE
                   1433: 
                   1434: }
                   1435: 
                   1436: =pod
                   1437: 
1.256     matthew  1438: =head1 Excel and CSV file utility routines
                   1439: 
                   1440: =over 4
                   1441: 
                   1442: =cut
                   1443: 
                   1444: ###############################################################
                   1445: ###############################################################
                   1446: 
                   1447: =pod
                   1448: 
1.648     raeburn  1449: =item * &csv_translate($text) 
1.37      matthew  1450: 
1.185     www      1451: Translate $text to allow it to be output as a 'comma separated values' 
1.37      matthew  1452: format.
                   1453: 
                   1454: =cut
                   1455: 
1.180     matthew  1456: ###############################################################
                   1457: ###############################################################
1.37      matthew  1458: sub csv_translate {
                   1459:     my $text = shift;
                   1460:     $text =~ s/\"/\"\"/g;
1.209     albertel 1461:     $text =~ s/\n/ /g;
1.37      matthew  1462:     return $text;
                   1463: }
1.180     matthew  1464: 
                   1465: ###############################################################
                   1466: ###############################################################
                   1467: 
                   1468: =pod
                   1469: 
1.648     raeburn  1470: =item * &define_excel_formats()
1.180     matthew  1471: 
                   1472: Define some commonly used Excel cell formats.
                   1473: 
                   1474: Currently supported formats:
                   1475: 
                   1476: =over 4
                   1477: 
                   1478: =item header
                   1479: 
                   1480: =item bold
                   1481: 
                   1482: =item h1
                   1483: 
                   1484: =item h2
                   1485: 
                   1486: =item h3
                   1487: 
1.256     matthew  1488: =item h4
                   1489: 
                   1490: =item i
                   1491: 
1.180     matthew  1492: =item date
                   1493: 
                   1494: =back
                   1495: 
                   1496: Inputs: $workbook
                   1497: 
                   1498: Returns: $format, a hash reference.
                   1499: 
                   1500: =cut
                   1501: 
                   1502: ###############################################################
                   1503: ###############################################################
                   1504: sub define_excel_formats {
                   1505:     my ($workbook) = @_;
                   1506:     my $format;
                   1507:     $format->{'header'} = $workbook->add_format(bold      => 1, 
                   1508:                                                 bottom    => 1,
                   1509:                                                 align     => 'center');
                   1510:     $format->{'bold'} = $workbook->add_format(bold=>1);
                   1511:     $format->{'h1'}   = $workbook->add_format(bold=>1, size=>18);
                   1512:     $format->{'h2'}   = $workbook->add_format(bold=>1, size=>16);
                   1513:     $format->{'h3'}   = $workbook->add_format(bold=>1, size=>14);
1.255     matthew  1514:     $format->{'h4'}   = $workbook->add_format(bold=>1, size=>12);
1.246     matthew  1515:     $format->{'i'}    = $workbook->add_format(italic=>1);
1.180     matthew  1516:     $format->{'date'} = $workbook->add_format(num_format=>
1.207     matthew  1517:                                             'mm/dd/yyyy hh:mm:ss');
1.180     matthew  1518:     return $format;
                   1519: }
                   1520: 
                   1521: ###############################################################
                   1522: ###############################################################
1.113     bowersj2 1523: 
                   1524: =pod
                   1525: 
1.648     raeburn  1526: =item * &create_workbook()
1.255     matthew  1527: 
                   1528: Create an Excel worksheet.  If it fails, output message on the
                   1529: request object and return undefs.
                   1530: 
                   1531: Inputs: Apache request object
                   1532: 
                   1533: Returns (undef) on failure, 
                   1534:     Excel worksheet object, scalar with filename, and formats 
                   1535:     from &Apache::loncommon::define_excel_formats on success
                   1536: 
                   1537: =cut
                   1538: 
                   1539: ###############################################################
                   1540: ###############################################################
                   1541: sub create_workbook {
                   1542:     my ($r) = @_;
                   1543:         #
                   1544:     # Create the excel spreadsheet
                   1545:     my $filename = '/prtspool/'.
1.258     albertel 1546:         $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255     matthew  1547:         time.'_'.rand(1000000000).'.xls';
                   1548:     my $workbook  = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
                   1549:     if (! defined($workbook)) {
                   1550:         $r->log_error("Error creating excel spreadsheet $filename: $!");
                   1551:         $r->print('<p>'.&mt("Unable to create new Excel file.  ".
                   1552:                             "This error has been logged.  ".
                   1553:                             "Please alert your LON-CAPA administrator").
                   1554:                   '</p>');
                   1555:         return (undef);
                   1556:     }
                   1557:     #
                   1558:     $workbook->set_tempdir('/home/httpd/perl/tmp');
                   1559:     #
                   1560:     my $format = &Apache::loncommon::define_excel_formats($workbook);
                   1561:     return ($workbook,$filename,$format);
                   1562: }
                   1563: 
                   1564: ###############################################################
                   1565: ###############################################################
                   1566: 
                   1567: =pod
                   1568: 
1.648     raeburn  1569: =item * &create_text_file()
1.113     bowersj2 1570: 
1.542     raeburn  1571: Create a file to write to and eventually make available to the user.
1.256     matthew  1572: If file creation fails, outputs an error message on the request object and 
                   1573: return undefs.
1.113     bowersj2 1574: 
1.256     matthew  1575: Inputs: Apache request object, and file suffix
1.113     bowersj2 1576: 
1.256     matthew  1577: Returns (undef) on failure, 
                   1578:     Filehandle and filename on success.
1.113     bowersj2 1579: 
                   1580: =cut
                   1581: 
1.256     matthew  1582: ###############################################################
                   1583: ###############################################################
                   1584: sub create_text_file {
                   1585:     my ($r,$suffix) = @_;
                   1586:     if (! defined($suffix)) { $suffix = 'txt'; };
                   1587:     my $fh;
                   1588:     my $filename = '/prtspool/'.
1.258     albertel 1589:         $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256     matthew  1590:         time.'_'.rand(1000000000).'.'.$suffix;
                   1591:     $fh = Apache::File->new('>/home/httpd'.$filename);
                   1592:     if (! defined($fh)) {
                   1593:         $r->log_error("Couldn't open $filename for output $!");
1.683     bisitz   1594:         $r->print(&mt('Problems occurred in creating the output file. '
                   1595:                      .'This error has been logged. '
                   1596:                      .'Please alert your LON-CAPA administrator.'));
1.113     bowersj2 1597:     }
1.256     matthew  1598:     return ($fh,$filename)
1.113     bowersj2 1599: }
                   1600: 
                   1601: 
1.256     matthew  1602: =pod 
1.113     bowersj2 1603: 
                   1604: =back
                   1605: 
                   1606: =cut
1.37      matthew  1607: 
                   1608: ###############################################################
1.33      matthew  1609: ##        Home server <option> list generating code          ##
                   1610: ###############################################################
1.35      matthew  1611: 
1.169     www      1612: # ------------------------------------------
                   1613: 
                   1614: sub domain_select {
                   1615:     my ($name,$value,$multiple)=@_;
                   1616:     my %domains=map { 
1.514     albertel 1617: 	$_ => $_.' '. &Apache::lonnet::domain($_,'description') 
1.512     albertel 1618:     } &Apache::lonnet::all_domains();
1.169     www      1619:     if ($multiple) {
                   1620: 	$domains{''}=&mt('Any domain');
1.550     albertel 1621: 	$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287     albertel 1622: 	return &multiple_select_form($name,$value,4,\%domains);
1.169     www      1623:     } else {
1.550     albertel 1624: 	$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.169     www      1625: 	return &select_form($name,$value,%domains);
                   1626:     }
                   1627: }
                   1628: 
1.282     albertel 1629: #-------------------------------------------
                   1630: 
                   1631: =pod
                   1632: 
1.519     raeburn  1633: =head1 Routines for form select boxes
                   1634: 
                   1635: =over 4
                   1636: 
1.648     raeburn  1637: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282     albertel 1638: 
                   1639: Returns a string containing a <select> element int multiple mode
                   1640: 
                   1641: 
                   1642: Args:
                   1643:   $name - name of the <select> element
1.506     raeburn  1644:   $value - scalar or array ref of values that should already be selected
1.282     albertel 1645:   $size - number of rows long the select element is
1.283     albertel 1646:   $hash - the elements should be 'option' => 'shown text'
1.282     albertel 1647:           (shown text should already have been &mt())
1.506     raeburn  1648:   $order - (optional) array ref of the order to show the elements in
1.283     albertel 1649: 
1.282     albertel 1650: =cut
                   1651: 
                   1652: #-------------------------------------------
1.169     www      1653: sub multiple_select_form {
1.284     albertel 1654:     my ($name,$value,$size,$hash,$order)=@_;
1.169     www      1655:     my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
                   1656:     my $output='';
1.191     matthew  1657:     if (! defined($size)) {
                   1658:         $size = 4;
1.283     albertel 1659:         if (scalar(keys(%$hash))<4) {
                   1660:             $size = scalar(keys(%$hash));
1.191     matthew  1661:         }
                   1662:     }
1.734     bisitz   1663:     $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501     banghart 1664:     my @order;
1.506     raeburn  1665:     if (ref($order) eq 'ARRAY')  {
                   1666:         @order = @{$order};
                   1667:     } else {
                   1668:         @order = sort(keys(%$hash));
1.501     banghart 1669:     }
                   1670:     if (exists($$hash{'select_form_order'})) {
                   1671:         @order = @{$$hash{'select_form_order'}};
                   1672:     }
                   1673:         
1.284     albertel 1674:     foreach my $key (@order) {
1.356     albertel 1675:         $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284     albertel 1676:         $output.='selected="selected" ' if ($selected{$key});
                   1677:         $output.='>'.$hash->{$key}."</option>\n";
1.169     www      1678:     }
                   1679:     $output.="</select>\n";
                   1680:     return $output;
                   1681: }
                   1682: 
1.88      www      1683: #-------------------------------------------
                   1684: 
                   1685: =pod
                   1686: 
1.648     raeburn  1687: =item * &select_form($defdom,$name,%hash)
1.88      www      1688: 
                   1689: Returns a string containing a <select name='$name' size='1'> form to 
                   1690: allow a user to select options from a hash option_name => displayed text.  
                   1691: See lonrights.pm for an example invocation and use.
                   1692: 
                   1693: =cut
                   1694: 
                   1695: #-------------------------------------------
                   1696: sub select_form {
                   1697:     my ($def,$name,%hash) = @_;
                   1698:     my $selectform = "<select name=\"$name\" size=\"1\">\n";
1.128     albertel 1699:     my @keys;
                   1700:     if (exists($hash{'select_form_order'})) {
                   1701: 	@keys=@{$hash{'select_form_order'}};
                   1702:     } else {
                   1703: 	@keys=sort(keys(%hash));
                   1704:     }
1.356     albertel 1705:     foreach my $key (@keys) {
                   1706:         $selectform.=
                   1707: 	    '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
                   1708:             ($key eq $def ? 'selected="selected" ' : '').
                   1709:                 ">".&mt($hash{$key})."</option>\n";
1.88      www      1710:     }
                   1711:     $selectform.="</select>";
                   1712:     return $selectform;
                   1713: }
                   1714: 
1.475     www      1715: # For display filters
                   1716: 
                   1717: sub display_filter {
                   1718:     if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477     www      1719:     if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.714     bisitz   1720:     return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1.475     www      1721: 			       &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
                   1722: 							   (&mt('all'),10,20,50,100,1000,10000))).
1.714     bisitz   1723: 	   '</label></span> <span class="LC_nobreak">'.
1.475     www      1724:            &mt('Filter [_1]',
1.477     www      1725: 	   &select_form($env{'form.displayfilter'},
                   1726: 			'displayfilter',
                   1727: 			('currentfolder' => 'Current folder/page',
                   1728: 			 'containing' => 'Containing phrase',
                   1729: 			 'none' => 'None'))).
1.714     bisitz   1730: 			 '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1.475     www      1731: }
                   1732: 
1.167     www      1733: sub gradeleveldescription {
                   1734:     my $gradelevel=shift;
                   1735:     my %gradelevels=(0 => 'Not specified',
                   1736: 		     1 => 'Grade 1',
                   1737: 		     2 => 'Grade 2',
                   1738: 		     3 => 'Grade 3',
                   1739: 		     4 => 'Grade 4',
                   1740: 		     5 => 'Grade 5',
                   1741: 		     6 => 'Grade 6',
                   1742: 		     7 => 'Grade 7',
                   1743: 		     8 => 'Grade 8',
                   1744: 		     9 => 'Grade 9',
                   1745: 		     10 => 'Grade 10',
                   1746: 		     11 => 'Grade 11',
                   1747: 		     12 => 'Grade 12',
                   1748: 		     13 => 'Grade 13',
                   1749: 		     14 => '100 Level',
                   1750: 		     15 => '200 Level',
                   1751: 		     16 => '300 Level',
                   1752: 		     17 => '400 Level',
                   1753: 		     18 => 'Graduate Level');
                   1754:     return &mt($gradelevels{$gradelevel});
                   1755: }
                   1756: 
1.163     www      1757: sub select_level_form {
                   1758:     my ($deflevel,$name)=@_;
                   1759:     unless ($deflevel) { $deflevel=0; }
1.167     www      1760:     my $selectform = "<select name=\"$name\" size=\"1\">\n";
                   1761:     for (my $i=0; $i<=18; $i++) {
                   1762:         $selectform.="<option value=\"$i\" ".
1.253     albertel 1763:             ($i==$deflevel ? 'selected="selected" ' : '').
1.167     www      1764:                 ">".&gradeleveldescription($i)."</option>\n";
                   1765:     }
                   1766:     $selectform.="</select>";
                   1767:     return $selectform;
1.163     www      1768: }
1.167     www      1769: 
1.35      matthew  1770: #-------------------------------------------
                   1771: 
1.45      matthew  1772: =pod
                   1773: 
1.743     raeburn  1774: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$autosubmit)
1.35      matthew  1775: 
                   1776: Returns a string containing a <select name='$name' size='1'> form to 
                   1777: allow a user to select the domain to preform an operation in.  
                   1778: See loncreateuser.pm for an example invocation and use.
                   1779: 
1.90      www      1780: If the $includeempty flag is set, it also includes an empty choice ("no domain
                   1781: selected");
                   1782: 
1.743     raeburn  1783: If the $showdomdesc flag is set, the domain name is followed by the domain description.
                   1784: 
                   1785: If the $autosubmit flag is set, the form containing the domain selector will be auto-submitted by an onchange action.  
1.563     raeburn  1786: 
1.35      matthew  1787: =cut
                   1788: 
                   1789: #-------------------------------------------
1.34      matthew  1790: sub select_dom_form {
1.743     raeburn  1791:     my ($defdom,$name,$includeempty,$showdomdesc,$autosubmit) = @_;
                   1792:     my $onchange;
                   1793:     if ($autosubmit) {
                   1794:         $onchange = ' onchange="this.form.submit()"';
                   1795:     }
1.550     albertel 1796:     my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1.90      www      1797:     if ($includeempty) { @domains=('',@domains); }
1.743     raeburn  1798:     my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356     albertel 1799:     foreach my $dom (@domains) {
                   1800:         $selectdomain.="<option value=\"$dom\" ".
1.563     raeburn  1801:             ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
                   1802:         if ($showdomdesc) {
                   1803:             if ($dom ne '') {
                   1804:                 my $domdesc = &Apache::lonnet::domain($dom,'description');
                   1805:                 if ($domdesc ne '') {
                   1806:                     $selectdomain .= ' ('.$domdesc.')';
                   1807:                 }
                   1808:             } 
                   1809:         }
                   1810:         $selectdomain .= "</option>\n";
1.34      matthew  1811:     }
                   1812:     $selectdomain.="</select>";
                   1813:     return $selectdomain;
                   1814: }
                   1815: 
1.35      matthew  1816: #-------------------------------------------
                   1817: 
1.45      matthew  1818: =pod
                   1819: 
1.648     raeburn  1820: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35      matthew  1821: 
1.586     raeburn  1822: input: 4 arguments (two required, two optional) - 
                   1823:     $domain - domain of new user
                   1824:     $name - name of form element
                   1825:     $default - Value of 'default' causes a default item to be first 
                   1826:                             option, and selected by default. 
                   1827:     $hide - Value of 'hide' causes hiding of the name of the server, 
                   1828:                             if 1 server found, or default, if 0 found.
1.594     raeburn  1829: output: returns 2 items: 
1.586     raeburn  1830: (a) form element which contains either:
                   1831:    (i) <select name="$name">
                   1832:         <option value="$hostid1">$hostid $servers{$hostid}</option>
                   1833:         <option value="$hostid2">$hostid $servers{$hostid}</option>       
                   1834:        </select>
                   1835:        form item if there are multiple library servers in $domain, or
                   1836:    (ii) an <input type="hidden" name="$name" value="$hostid" /> form item 
                   1837:        if there is only one library server in $domain.
                   1838: 
                   1839: (b) number of library servers found.
                   1840: 
                   1841: See loncreateuser.pm for example of use.
1.35      matthew  1842: 
                   1843: =cut
                   1844: 
                   1845: #-------------------------------------------
1.586     raeburn  1846: sub home_server_form_item {
                   1847:     my ($domain,$name,$default,$hide) = @_;
1.513     albertel 1848:     my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586     raeburn  1849:     my $result;
                   1850:     my $numlib = keys(%servers);
                   1851:     if ($numlib > 1) {
                   1852:         $result .= '<select name="'.$name.'" />'."\n";
                   1853:         if ($default) {
                   1854:             $result .= '<option value="default" selected>'.&mt('default').
                   1855:                        '</option>'."\n";
                   1856:         }
                   1857:         foreach my $hostid (sort(keys(%servers))) {
                   1858:             $result.= '<option value="'.$hostid.'">'.
                   1859: 	              $hostid.' '.$servers{$hostid}."</option>\n";
                   1860:         }
                   1861:         $result .= '</select>'."\n";
                   1862:     } elsif ($numlib == 1) {
                   1863:         my $hostid;
                   1864:         foreach my $item (keys(%servers)) {
                   1865:             $hostid = $item;
                   1866:         }
                   1867:         $result .= '<input type="hidden" name="'.$name.'" value="'.
                   1868:                    $hostid.'" />';
                   1869:                    if (!$hide) {
                   1870:                        $result .= $hostid.' '.$servers{$hostid};
                   1871:                    }
                   1872:                    $result .= "\n";
                   1873:     } elsif ($default) {
                   1874:         $result .= '<input type="hidden" name="'.$name.
                   1875:                    '" value="default" />';
                   1876:                    if (!$hide) {
                   1877:                        $result .= &mt('default');
                   1878:                    }
                   1879:                    $result .= "\n";
1.33      matthew  1880:     }
1.586     raeburn  1881:     return ($result,$numlib);
1.33      matthew  1882: }
1.112     bowersj2 1883: 
                   1884: =pod
                   1885: 
1.534     albertel 1886: =back 
                   1887: 
1.112     bowersj2 1888: =cut
1.87      matthew  1889: 
                   1890: ###############################################################
1.112     bowersj2 1891: ##                  Decoding User Agent                      ##
1.87      matthew  1892: ###############################################################
                   1893: 
                   1894: =pod
                   1895: 
1.112     bowersj2 1896: =head1 Decoding the User Agent
                   1897: 
                   1898: =over 4
                   1899: 
                   1900: =item * &decode_user_agent()
1.87      matthew  1901: 
                   1902: Inputs: $r
                   1903: 
                   1904: Outputs:
                   1905: 
                   1906: =over 4
                   1907: 
1.112     bowersj2 1908: =item * $httpbrowser
1.87      matthew  1909: 
1.112     bowersj2 1910: =item * $clientbrowser
1.87      matthew  1911: 
1.112     bowersj2 1912: =item * $clientversion
1.87      matthew  1913: 
1.112     bowersj2 1914: =item * $clientmathml
1.87      matthew  1915: 
1.112     bowersj2 1916: =item * $clientunicode
1.87      matthew  1917: 
1.112     bowersj2 1918: =item * $clientos
1.87      matthew  1919: 
                   1920: =back
                   1921: 
1.157     matthew  1922: =back 
                   1923: 
1.87      matthew  1924: =cut
                   1925: 
                   1926: ###############################################################
                   1927: ###############################################################
                   1928: sub decode_user_agent {
1.247     albertel 1929:     my ($r)=@_;
1.87      matthew  1930:     my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
                   1931:     my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
                   1932:     my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247     albertel 1933:     if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87      matthew  1934:     my $clientbrowser='unknown';
                   1935:     my $clientversion='0';
                   1936:     my $clientmathml='';
                   1937:     my $clientunicode='0';
                   1938:     for (my $i=0;$i<=$#browsertype;$i++) {
                   1939:         my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
                   1940: 	if (($httpbrowser=~/$match/i)  && ($httpbrowser!~/$notmatch/i)) {
                   1941: 	    $clientbrowser=$bname;
                   1942:             $httpbrowser=~/$vreg/i;
                   1943: 	    $clientversion=$1;
                   1944:             $clientmathml=($clientversion>=$minv);
                   1945:             $clientunicode=($clientversion>=$univ);
                   1946: 	}
                   1947:     }
                   1948:     my $clientos='unknown';
                   1949:     if (($httpbrowser=~/linux/i) ||
                   1950:         ($httpbrowser=~/unix/i) ||
                   1951:         ($httpbrowser=~/ux/i) ||
                   1952:         ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
                   1953:     if (($httpbrowser=~/vax/i) ||
                   1954:         ($httpbrowser=~/vms/i)) { $clientos='vms'; }
                   1955:     if ($httpbrowser=~/next/i) { $clientos='next'; }
                   1956:     if (($httpbrowser=~/mac/i) ||
                   1957:         ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
                   1958:     if ($httpbrowser=~/win/i) { $clientos='win'; }
                   1959:     if ($httpbrowser=~/embed/i) { $clientos='pda'; }
                   1960:     return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
                   1961:             $clientunicode,$clientos,);
                   1962: }
                   1963: 
1.32      matthew  1964: ###############################################################
                   1965: ##    Authentication changing form generation subroutines    ##
                   1966: ###############################################################
                   1967: ##
                   1968: ## All of the authform_xxxxxxx subroutines take their inputs in a
                   1969: ## hash, and have reasonable default values.
                   1970: ##
                   1971: ##    formname = the name given in the <form> tag.
1.35      matthew  1972: #-------------------------------------------
                   1973: 
1.45      matthew  1974: =pod
                   1975: 
1.112     bowersj2 1976: =head1 Authentication Routines
                   1977: 
                   1978: =over 4
                   1979: 
1.648     raeburn  1980: =item * &authform_xxxxxx()
1.35      matthew  1981: 
                   1982: The authform_xxxxxx subroutines provide javascript and html forms which 
                   1983: handle some of the conveniences required for authentication forms.  
                   1984: This is not an optimal method, but it works.  
                   1985: 
                   1986: =over 4
                   1987: 
1.112     bowersj2 1988: =item * authform_header
1.35      matthew  1989: 
1.112     bowersj2 1990: =item * authform_authorwarning
1.35      matthew  1991: 
1.112     bowersj2 1992: =item * authform_nochange
1.35      matthew  1993: 
1.112     bowersj2 1994: =item * authform_kerberos
1.35      matthew  1995: 
1.112     bowersj2 1996: =item * authform_internal
1.35      matthew  1997: 
1.112     bowersj2 1998: =item * authform_filesystem
1.35      matthew  1999: 
                   2000: =back
                   2001: 
1.648     raeburn  2002: See loncreateuser.pm for invocation and use examples.
1.157     matthew  2003: 
1.35      matthew  2004: =cut
                   2005: 
                   2006: #-------------------------------------------
1.32      matthew  2007: sub authform_header{  
                   2008:     my %in = (
                   2009:         formname => 'cu',
1.80      albertel 2010:         kerb_def_dom => '',
1.32      matthew  2011:         @_,
                   2012:     );
                   2013:     $in{'formname'} = 'document.' . $in{'formname'};
                   2014:     my $result='';
1.80      albertel 2015: 
                   2016: #---------------------------------------------- Code for upper case translation
                   2017:     my $Javascript_toUpperCase;
                   2018:     unless ($in{kerb_def_dom}) {
                   2019:         $Javascript_toUpperCase =<<"END";
                   2020:         switch (choice) {
                   2021:            case 'krb': currentform.elements[choicearg].value =
                   2022:                currentform.elements[choicearg].value.toUpperCase();
                   2023:                break;
                   2024:            default:
                   2025:         }
                   2026: END
                   2027:     } else {
                   2028:         $Javascript_toUpperCase = "";
                   2029:     }
                   2030: 
1.165     raeburn  2031:     my $radioval = "'nochange'";
1.591     raeburn  2032:     if (defined($in{'curr_authtype'})) {
                   2033:         if ($in{'curr_authtype'} ne '') {
                   2034:             $radioval = "'".$in{'curr_authtype'}."arg'";
                   2035:         }
1.174     matthew  2036:     }
1.165     raeburn  2037:     my $argfield = 'null';
1.591     raeburn  2038:     if (defined($in{'mode'})) {
1.165     raeburn  2039:         if ($in{'mode'} eq 'modifycourse')  {
1.591     raeburn  2040:             if (defined($in{'curr_autharg'})) {
                   2041:                 if ($in{'curr_autharg'} ne '') {
1.165     raeburn  2042:                     $argfield = "'$in{'curr_autharg'}'";
                   2043:                 }
                   2044:             }
                   2045:         }
                   2046:     }
                   2047: 
1.32      matthew  2048:     $result.=<<"END";
                   2049: var current = new Object();
1.165     raeburn  2050: current.radiovalue = $radioval;
                   2051: current.argfield = $argfield;
1.32      matthew  2052: 
                   2053: function changed_radio(choice,currentform) {
                   2054:     var choicearg = choice + 'arg';
                   2055:     // If a radio button in changed, we need to change the argfield
                   2056:     if (current.radiovalue != choice) {
                   2057:         current.radiovalue = choice;
                   2058:         if (current.argfield != null) {
                   2059:             currentform.elements[current.argfield].value = '';
                   2060:         }
                   2061:         if (choice == 'nochange') {
                   2062:             current.argfield = null;
                   2063:         } else {
                   2064:             current.argfield = choicearg;
                   2065:             switch(choice) {
                   2066:                 case 'krb': 
                   2067:                     currentform.elements[current.argfield].value = 
                   2068:                         "$in{'kerb_def_dom'}";
                   2069:                 break;
                   2070:               default:
                   2071:                 break;
                   2072:             }
                   2073:         }
                   2074:     }
                   2075:     return;
                   2076: }
1.22      www      2077: 
1.32      matthew  2078: function changed_text(choice,currentform) {
                   2079:     var choicearg = choice + 'arg';
                   2080:     if (currentform.elements[choicearg].value !='') {
1.80      albertel 2081:         $Javascript_toUpperCase
1.32      matthew  2082:         // clear old field
                   2083:         if ((current.argfield != choicearg) && (current.argfield != null)) {
                   2084:             currentform.elements[current.argfield].value = '';
                   2085:         }
                   2086:         current.argfield = choicearg;
                   2087:     }
                   2088:     set_auth_radio_buttons(choice,currentform);
                   2089:     return;
1.20      www      2090: }
1.32      matthew  2091: 
                   2092: function set_auth_radio_buttons(newvalue,currentform) {
                   2093:     var i=0;
                   2094:     while (i < currentform.login.length) {
                   2095:         if (currentform.login[i].value == newvalue) { break; }
                   2096:         i++;
                   2097:     }
                   2098:     if (i == currentform.login.length) {
                   2099:         return;
                   2100:     }
                   2101:     current.radiovalue = newvalue;
                   2102:     currentform.login[i].checked = true;
                   2103:     return;
                   2104: }
                   2105: END
                   2106:     return $result;
                   2107: }
                   2108: 
                   2109: sub authform_authorwarning{
                   2110:     my $result='';
1.144     matthew  2111:     $result='<i>'.
                   2112:         &mt('As a general rule, only authors or co-authors should be '.
                   2113:             'filesystem authenticated '.
                   2114:             '(which allows access to the server filesystem).')."</i>\n";
1.32      matthew  2115:     return $result;
                   2116: }
                   2117: 
                   2118: sub authform_nochange{  
                   2119:     my %in = (
                   2120:               formname => 'document.cu',
                   2121:               kerb_def_dom => 'MSU.EDU',
                   2122:               @_,
                   2123:           );
1.586     raeburn  2124:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'}); 
                   2125:     my $result;
                   2126:     if (keys(%can_assign) == 0) {
                   2127:         $result = &mt('Under you current role you are not permitted to change login settings for this user');  
                   2128:     } else {
                   2129:         $result = '<label>'.&mt('[_1] Do not change login data',
                   2130:                   '<input type="radio" name="login" value="nochange" '.
                   2131:                   'checked="checked" onclick="'.
1.281     albertel 2132:             "javascript:changed_radio('nochange',$in{'formname'});".'" />').
                   2133: 	    '</label>';
1.586     raeburn  2134:     }
1.32      matthew  2135:     return $result;
                   2136: }
                   2137: 
1.591     raeburn  2138: sub authform_kerberos {
1.32      matthew  2139:     my %in = (
                   2140:               formname => 'document.cu',
                   2141:               kerb_def_dom => 'MSU.EDU',
1.80      albertel 2142:               kerb_def_auth => 'krb4',
1.32      matthew  2143:               @_,
                   2144:               );
1.586     raeburn  2145:     my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
                   2146:         $autharg,$jscall);
                   2147:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.80      albertel 2148:     if ($in{'kerb_def_auth'} eq 'krb5') {
1.772     bisitz   2149:        $check5 = ' checked="checked"';
1.80      albertel 2150:     } else {
1.772     bisitz   2151:        $check4 = ' checked="checked"';
1.80      albertel 2152:     }
1.165     raeburn  2153:     $krbarg = $in{'kerb_def_dom'};
1.591     raeburn  2154:     if (defined($in{'curr_authtype'})) {
                   2155:         if ($in{'curr_authtype'} eq 'krb') {
1.772     bisitz   2156:             $krbcheck = ' checked="checked"';
1.623     raeburn  2157:             if (defined($in{'mode'})) {
                   2158:                 if ($in{'mode'} eq 'modifyuser') {
                   2159:                     $krbcheck = '';
                   2160:                 }
                   2161:             }
1.591     raeburn  2162:             if (defined($in{'curr_kerb_ver'})) {
                   2163:                 if ($in{'curr_krb_ver'} eq '5') {
1.772     bisitz   2164:                     $check5 = ' checked="checked"';
1.591     raeburn  2165:                     $check4 = '';
                   2166:                 } else {
1.772     bisitz   2167:                     $check4 = ' checked="checked"';
1.591     raeburn  2168:                     $check5 = '';
                   2169:                 }
1.586     raeburn  2170:             }
1.591     raeburn  2171:             if (defined($in{'curr_autharg'})) {
1.165     raeburn  2172:                 $krbarg = $in{'curr_autharg'};
                   2173:             }
1.586     raeburn  2174:             if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591     raeburn  2175:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2176:                     $result = 
                   2177:     &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
                   2178:         $in{'curr_autharg'},$krbver);
                   2179:                 } else {
                   2180:                     $result =
                   2181:     &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
                   2182:                 }
                   2183:                 return $result; 
                   2184:             }
                   2185:         }
                   2186:     } else {
                   2187:         if ($authnum == 1) {
1.784     bisitz   2188:             $authtype = '<input type="hidden" name="login" value="krb" />';
1.165     raeburn  2189:         }
                   2190:     }
1.586     raeburn  2191:     if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
                   2192:         return;
1.587     raeburn  2193:     } elsif ($authtype eq '') {
1.591     raeburn  2194:         if (defined($in{'mode'})) {
1.587     raeburn  2195:             if ($in{'mode'} eq 'modifycourse') {
                   2196:                 if ($authnum == 1) {
1.784     bisitz   2197:                     $authtype = '<input type="hidden" name="login" value="krb" />';
1.587     raeburn  2198:                 }
                   2199:             }
                   2200:         }
1.586     raeburn  2201:     }
                   2202:     $jscall = "javascript:changed_radio('krb',$in{'formname'});";
                   2203:     if ($authtype eq '') {
                   2204:         $authtype = '<input type="radio" name="login" value="krb" '.
                   2205:                     'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
                   2206:                     $krbcheck.' />';
                   2207:     }
                   2208:     if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
                   2209:         ($can_assign{'krb4'} && !$can_assign{'krb5'} && 
                   2210:          $in{'curr_authtype'} eq 'krb5') ||
                   2211:         (!$can_assign{'krb4'} && $can_assign{'krb5'} && 
                   2212:          $in{'curr_authtype'} eq 'krb4')) {
                   2213:         $result .= &mt
1.144     matthew  2214:         ('[_1] Kerberos authenticated with domain [_2] '.
1.281     albertel 2215:          '[_3] Version 4 [_4] Version 5 [_5]',
1.586     raeburn  2216:          '<label>'.$authtype,
1.281     albertel 2217:          '</label><input type="text" size="10" name="krbarg" '.
1.165     raeburn  2218:              'value="'.$krbarg.'" '.
1.144     matthew  2219:              'onchange="'.$jscall.'" />',
1.281     albertel 2220:          '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
                   2221:          '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
                   2222: 	 '</label>');
1.586     raeburn  2223:     } elsif ($can_assign{'krb4'}) {
                   2224:         $result .= &mt
                   2225:         ('[_1] Kerberos authenticated with domain [_2] '.
                   2226:          '[_3] Version 4 [_4]',
                   2227:          '<label>'.$authtype,
                   2228:          '</label><input type="text" size="10" name="krbarg" '.
                   2229:              'value="'.$krbarg.'" '.
                   2230:              'onchange="'.$jscall.'" />',
                   2231:          '<label><input type="hidden" name="krbver" value="4" />',
                   2232:          '</label>');
                   2233:     } elsif ($can_assign{'krb5'}) {
                   2234:         $result .= &mt
                   2235:         ('[_1] Kerberos authenticated with domain [_2] '.
                   2236:          '[_3] Version 5 [_4]',
                   2237:          '<label>'.$authtype,
                   2238:          '</label><input type="text" size="10" name="krbarg" '.
                   2239:              'value="'.$krbarg.'" '.
                   2240:              'onchange="'.$jscall.'" />',
                   2241:          '<label><input type="hidden" name="krbver" value="5" />',
                   2242:          '</label>');
                   2243:     }
1.32      matthew  2244:     return $result;
                   2245: }
                   2246: 
                   2247: sub authform_internal{  
1.586     raeburn  2248:     my %in = (
1.32      matthew  2249:                 formname => 'document.cu',
                   2250:                 kerb_def_dom => 'MSU.EDU',
                   2251:                 @_,
                   2252:                 );
1.586     raeburn  2253:     my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
                   2254:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2255:     if (defined($in{'curr_authtype'})) {
                   2256:         if ($in{'curr_authtype'} eq 'int') {
1.586     raeburn  2257:             if ($can_assign{'int'}) {
1.772     bisitz   2258:                 $intcheck = 'checked="checked" ';
1.623     raeburn  2259:                 if (defined($in{'mode'})) {
                   2260:                     if ($in{'mode'} eq 'modifyuser') {
                   2261:                         $intcheck = '';
                   2262:                     }
                   2263:                 }
1.591     raeburn  2264:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2265:                     $intarg = $in{'curr_autharg'};
                   2266:                 }
                   2267:             } else {
                   2268:                 $result = &mt('Currently internally authenticated.');
                   2269:                 return $result;
1.165     raeburn  2270:             }
                   2271:         }
1.586     raeburn  2272:     } else {
                   2273:         if ($authnum == 1) {
1.784     bisitz   2274:             $authtype = '<input type="hidden" name="login" value="int" />';
1.586     raeburn  2275:         }
                   2276:     }
                   2277:     if (!$can_assign{'int'}) {
                   2278:         return;
1.587     raeburn  2279:     } elsif ($authtype eq '') {
1.591     raeburn  2280:         if (defined($in{'mode'})) {
1.587     raeburn  2281:             if ($in{'mode'} eq 'modifycourse') {
                   2282:                 if ($authnum == 1) {
1.784     bisitz   2283:                     $authtype = '<input type="hidden" name="login" value="int" />';
1.587     raeburn  2284:                 }
                   2285:             }
                   2286:         }
1.165     raeburn  2287:     }
1.586     raeburn  2288:     $jscall = "javascript:changed_radio('int',$in{'formname'});";
                   2289:     if ($authtype eq '') {
                   2290:         $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
                   2291:                     ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
                   2292:     }
1.605     bisitz   2293:     $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586     raeburn  2294:                $intarg.'" onchange="'.$jscall.'" />';
                   2295:     $result = &mt
1.144     matthew  2296:         ('[_1] Internally authenticated (with initial password [_2])',
1.586     raeburn  2297:          '<label>'.$authtype,'</label>'.$autharg);
1.620     www      2298:     $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  2299:     return $result;
                   2300: }
                   2301: 
                   2302: sub authform_local{  
                   2303:     my %in = (
                   2304:               formname => 'document.cu',
                   2305:               kerb_def_dom => 'MSU.EDU',
                   2306:               @_,
                   2307:               );
1.586     raeburn  2308:     my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
                   2309:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2310:     if (defined($in{'curr_authtype'})) {
                   2311:         if ($in{'curr_authtype'} eq 'loc') {
1.586     raeburn  2312:             if ($can_assign{'loc'}) {
1.772     bisitz   2313:                 $loccheck = 'checked="checked" ';
1.623     raeburn  2314:                 if (defined($in{'mode'})) {
                   2315:                     if ($in{'mode'} eq 'modifyuser') {
                   2316:                         $loccheck = '';
                   2317:                     }
                   2318:                 }
1.591     raeburn  2319:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2320:                     $locarg = $in{'curr_autharg'};
                   2321:                 }
                   2322:             } else {
                   2323:                 $result = &mt('Currently using local (institutional) authentication.');
                   2324:                 return $result;
1.165     raeburn  2325:             }
                   2326:         }
1.586     raeburn  2327:     } else {
                   2328:         if ($authnum == 1) {
1.784     bisitz   2329:             $authtype = '<input type="hidden" name="login" value="loc" />';
1.586     raeburn  2330:         }
                   2331:     }
                   2332:     if (!$can_assign{'loc'}) {
                   2333:         return;
1.587     raeburn  2334:     } elsif ($authtype eq '') {
1.591     raeburn  2335:         if (defined($in{'mode'})) {
1.587     raeburn  2336:             if ($in{'mode'} eq 'modifycourse') {
                   2337:                 if ($authnum == 1) {
1.784     bisitz   2338:                     $authtype = '<input type="hidden" name="login" value="loc" />';
1.587     raeburn  2339:                 }
                   2340:             }
                   2341:         }
1.165     raeburn  2342:     }
1.586     raeburn  2343:     $jscall = "javascript:changed_radio('loc',$in{'formname'});";
                   2344:     if ($authtype eq '') {
                   2345:         $authtype = '<input type="radio" name="login" value="loc" '.
                   2346:                     $loccheck.' onchange="'.$jscall.'" onclick="'.
                   2347:                     $jscall.'" />';
                   2348:     }
                   2349:     $autharg = '<input type="text" size="10" name="locarg" value="'.
                   2350:                $locarg.'" onchange="'.$jscall.'" />';
                   2351:     $result = &mt('[_1] Local Authentication with argument [_2]',
                   2352:                   '<label>'.$authtype,'</label>'.$autharg);
1.32      matthew  2353:     return $result;
                   2354: }
                   2355: 
                   2356: sub authform_filesystem{  
                   2357:     my %in = (
                   2358:               formname => 'document.cu',
                   2359:               kerb_def_dom => 'MSU.EDU',
                   2360:               @_,
                   2361:               );
1.586     raeburn  2362:     my ($fsyscheck,$result,$authtype,$autharg,$jscall);
                   2363:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2364:     if (defined($in{'curr_authtype'})) {
                   2365:         if ($in{'curr_authtype'} eq 'fsys') {
1.586     raeburn  2366:             if ($can_assign{'fsys'}) {
1.772     bisitz   2367:                 $fsyscheck = 'checked="checked" ';
1.623     raeburn  2368:                 if (defined($in{'mode'})) {
                   2369:                     if ($in{'mode'} eq 'modifyuser') {
                   2370:                         $fsyscheck = '';
                   2371:                     }
                   2372:                 }
1.586     raeburn  2373:             } else {
                   2374:                 $result = &mt('Currently Filesystem Authenticated.');
                   2375:                 return $result;
                   2376:             }           
                   2377:         }
                   2378:     } else {
                   2379:         if ($authnum == 1) {
1.784     bisitz   2380:             $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586     raeburn  2381:         }
                   2382:     }
                   2383:     if (!$can_assign{'fsys'}) {
                   2384:         return;
1.587     raeburn  2385:     } elsif ($authtype eq '') {
1.591     raeburn  2386:         if (defined($in{'mode'})) {
1.587     raeburn  2387:             if ($in{'mode'} eq 'modifycourse') {
                   2388:                 if ($authnum == 1) {
1.784     bisitz   2389:                     $authtype = '<input type="hidden" name="login" value="fsys" />';
1.587     raeburn  2390:                 }
                   2391:             }
                   2392:         }
1.586     raeburn  2393:     }
                   2394:     $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
                   2395:     if ($authtype eq '') {
                   2396:         $authtype = '<input type="radio" name="login" value="fsys" '.
                   2397:                     $fsyscheck.' onchange="'.$jscall.'" onclick="'.
                   2398:                     $jscall.'" />';
                   2399:     }
                   2400:     $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
                   2401:                ' onchange="'.$jscall.'" />';
                   2402:     $result = &mt
1.144     matthew  2403:         ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281     albertel 2404:          '<label><input type="radio" name="login" value="fsys" '.
1.586     raeburn  2405:          $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605     bisitz   2406:          '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144     matthew  2407:                   'onchange="'.$jscall.'" />');
1.32      matthew  2408:     return $result;
                   2409: }
                   2410: 
1.586     raeburn  2411: sub get_assignable_auth {
                   2412:     my ($dom) = @_;
                   2413:     if ($dom eq '') {
                   2414:         $dom = $env{'request.role.domain'};
                   2415:     }
                   2416:     my %can_assign = (
                   2417:                           krb4 => 1,
                   2418:                           krb5 => 1,
                   2419:                           int  => 1,
                   2420:                           loc  => 1,
                   2421:                      );
                   2422:     my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
                   2423:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   2424:         if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
                   2425:             my $authhash = $domconfig{'usercreation'}{'authtypes'};
                   2426:             my $context;
                   2427:             if ($env{'request.role'} =~ /^au/) {
                   2428:                 $context = 'author';
                   2429:             } elsif ($env{'request.role'} =~ /^dc/) {
                   2430:                 $context = 'domain';
                   2431:             } elsif ($env{'request.course.id'}) {
                   2432:                 $context = 'course';
                   2433:             }
                   2434:             if ($context) {
                   2435:                 if (ref($authhash->{$context}) eq 'HASH') {
                   2436:                    %can_assign = %{$authhash->{$context}}; 
                   2437:                 }
                   2438:             }
                   2439:         }
                   2440:     }
                   2441:     my $authnum = 0;
                   2442:     foreach my $key (keys(%can_assign)) {
                   2443:         if ($can_assign{$key}) {
                   2444:             $authnum ++;
                   2445:         }
                   2446:     }
                   2447:     if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
                   2448:         $authnum --;
                   2449:     }
                   2450:     return ($authnum,%can_assign);
                   2451: }
                   2452: 
1.80      albertel 2453: ###############################################################
                   2454: ##    Get Kerberos Defaults for Domain                 ##
                   2455: ###############################################################
                   2456: ##
                   2457: ## Returns default kerberos version and an associated argument
                   2458: ## as listed in file domain.tab. If not listed, provides
                   2459: ## appropriate default domain and kerberos version.
                   2460: ##
                   2461: #-------------------------------------------
                   2462: 
                   2463: =pod
                   2464: 
1.648     raeburn  2465: =item * &get_kerberos_defaults()
1.80      albertel 2466: 
                   2467: get_kerberos_defaults($target_domain) returns the default kerberos
1.641     raeburn  2468: version and domain. If not found, it defaults to version 4 and the 
                   2469: domain of the server.
1.80      albertel 2470: 
1.648     raeburn  2471: =over 4
                   2472: 
1.80      albertel 2473: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
                   2474: 
1.648     raeburn  2475: =back
                   2476: 
                   2477: =back
                   2478: 
1.80      albertel 2479: =cut
                   2480: 
                   2481: #-------------------------------------------
                   2482: sub get_kerberos_defaults {
                   2483:     my $domain=shift;
1.641     raeburn  2484:     my ($krbdef,$krbdefdom);
                   2485:     my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
                   2486:     if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
                   2487:         $krbdef = $domdefaults{'auth_def'};
                   2488:         $krbdefdom = $domdefaults{'auth_arg_def'};
                   2489:     } else {
1.80      albertel 2490:         $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
                   2491:         my $krbdefdom=$1;
                   2492:         $krbdefdom=~tr/a-z/A-Z/;
                   2493:         $krbdef = "krb4";
                   2494:     }
                   2495:     return ($krbdef,$krbdefdom);
                   2496: }
1.112     bowersj2 2497: 
1.32      matthew  2498: 
1.46      matthew  2499: ###############################################################
                   2500: ##                Thesaurus Functions                        ##
                   2501: ###############################################################
1.20      www      2502: 
1.46      matthew  2503: =pod
1.20      www      2504: 
1.112     bowersj2 2505: =head1 Thesaurus Functions
                   2506: 
                   2507: =over 4
                   2508: 
1.648     raeburn  2509: =item * &initialize_keywords()
1.46      matthew  2510: 
                   2511: Initializes the package variable %Keywords if it is empty.  Uses the
                   2512: package variable $thesaurus_db_file.
                   2513: 
                   2514: =cut
                   2515: 
                   2516: ###################################################
                   2517: 
                   2518: sub initialize_keywords {
                   2519:     return 1 if (scalar keys(%Keywords));
                   2520:     # If we are here, %Keywords is empty, so fill it up
                   2521:     #   Make sure the file we need exists...
                   2522:     if (! -e $thesaurus_db_file) {
                   2523:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
                   2524:                                  " failed because it does not exist");
                   2525:         return 0;
                   2526:     }
                   2527:     #   Set up the hash as a database
                   2528:     my %thesaurus_db;
                   2529:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 2530:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  2531:         &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
                   2532:                                  $thesaurus_db_file);
                   2533:         return 0;
                   2534:     } 
                   2535:     #  Get the average number of appearances of a word.
                   2536:     my $avecount = $thesaurus_db{'average.count'};
                   2537:     #  Put keywords (those that appear > average) into %Keywords
                   2538:     while (my ($word,$data)=each (%thesaurus_db)) {
                   2539:         my ($count,undef) = split /:/,$data;
                   2540:         $Keywords{$word}++ if ($count > $avecount);
                   2541:     }
                   2542:     untie %thesaurus_db;
                   2543:     # Remove special values from %Keywords.
1.356     albertel 2544:     foreach my $value ('total.count','average.count') {
                   2545:         delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586     raeburn  2546:   }
1.46      matthew  2547:     return 1;
                   2548: }
                   2549: 
                   2550: ###################################################
                   2551: 
                   2552: =pod
                   2553: 
1.648     raeburn  2554: =item * &keyword($word)
1.46      matthew  2555: 
                   2556: Returns true if $word is a keyword.  A keyword is a word that appears more 
                   2557: than the average number of times in the thesaurus database.  Calls 
                   2558: &initialize_keywords
                   2559: 
                   2560: =cut
                   2561: 
                   2562: ###################################################
1.20      www      2563: 
                   2564: sub keyword {
1.46      matthew  2565:     return if (!&initialize_keywords());
                   2566:     my $word=lc(shift());
                   2567:     $word=~s/\W//g;
                   2568:     return exists($Keywords{$word});
1.20      www      2569: }
1.46      matthew  2570: 
                   2571: ###############################################################
                   2572: 
                   2573: =pod 
1.20      www      2574: 
1.648     raeburn  2575: =item * &get_related_words()
1.46      matthew  2576: 
1.160     matthew  2577: Look up a word in the thesaurus.  Takes a scalar argument and returns
1.46      matthew  2578: an array of words.  If the keyword is not in the thesaurus, an empty array
                   2579: will be returned.  The order of the words returned is determined by the
                   2580: database which holds them.
                   2581: 
                   2582: Uses global $thesaurus_db_file.
                   2583: 
                   2584: =cut
                   2585: 
                   2586: ###############################################################
                   2587: sub get_related_words {
                   2588:     my $keyword = shift;
                   2589:     my %thesaurus_db;
                   2590:     if (! -e $thesaurus_db_file) {
                   2591:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
                   2592:                                  "failed because the file does not exist");
                   2593:         return ();
                   2594:     }
                   2595:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 2596:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  2597:         return ();
                   2598:     } 
                   2599:     my @Words=();
1.429     www      2600:     my $count=0;
1.46      matthew  2601:     if (exists($thesaurus_db{$keyword})) {
1.356     albertel 2602: 	# The first element is the number of times
                   2603: 	# the word appears.  We do not need it now.
1.429     www      2604: 	my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
                   2605: 	my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
                   2606: 	my $threshold=$mostfrequentcount/10;
                   2607:         foreach my $possibleword (@RelatedWords) {
                   2608:             my ($word,$wordcount)=split(/\,/,$possibleword);
                   2609:             if ($wordcount>$threshold) {
                   2610: 		push(@Words,$word);
                   2611:                 $count++;
                   2612:                 if ($count>10) { last; }
                   2613: 	    }
1.20      www      2614:         }
                   2615:     }
1.46      matthew  2616:     untie %thesaurus_db;
                   2617:     return @Words;
1.14      harris41 2618: }
1.46      matthew  2619: 
1.112     bowersj2 2620: =pod
                   2621: 
                   2622: =back
                   2623: 
                   2624: =cut
1.61      www      2625: 
                   2626: # -------------------------------------------------------------- Plaintext name
1.81      albertel 2627: =pod
                   2628: 
1.112     bowersj2 2629: =head1 User Name Functions
                   2630: 
                   2631: =over 4
                   2632: 
1.648     raeburn  2633: =item * &plainname($uname,$udom,$first)
1.81      albertel 2634: 
1.112     bowersj2 2635: Takes a users logon name and returns it as a string in
1.226     albertel 2636: "first middle last generation" form 
                   2637: if $first is set to 'lastname' then it returns it as
                   2638: 'lastname generation, firstname middlename' if their is a lastname
1.81      albertel 2639: 
                   2640: =cut
1.61      www      2641: 
1.295     www      2642: 
1.81      albertel 2643: ###############################################################
1.61      www      2644: sub plainname {
1.226     albertel 2645:     my ($uname,$udom,$first)=@_;
1.537     albertel 2646:     return if (!defined($uname) || !defined($udom));
1.295     www      2647:     my %names=&getnames($uname,$udom);
1.226     albertel 2648:     my $name=&Apache::lonnet::format_name($names{'firstname'},
                   2649: 					  $names{'middlename'},
                   2650: 					  $names{'lastname'},
                   2651: 					  $names{'generation'},$first);
                   2652:     $name=~s/^\s+//;
1.62      www      2653:     $name=~s/\s+$//;
                   2654:     $name=~s/\s+/ /g;
1.353     albertel 2655:     if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62      www      2656:     return $name;
1.61      www      2657: }
1.66      www      2658: 
                   2659: # -------------------------------------------------------------------- Nickname
1.81      albertel 2660: =pod
                   2661: 
1.648     raeburn  2662: =item * &nickname($uname,$udom)
1.81      albertel 2663: 
                   2664: Gets a users name and returns it as a string as
                   2665: 
                   2666: "&quot;nickname&quot;"
1.66      www      2667: 
1.81      albertel 2668: if the user has a nickname or
                   2669: 
                   2670: "first middle last generation"
                   2671: 
                   2672: if the user does not
                   2673: 
                   2674: =cut
1.66      www      2675: 
                   2676: sub nickname {
                   2677:     my ($uname,$udom)=@_;
1.537     albertel 2678:     return if (!defined($uname) || !defined($udom));
1.295     www      2679:     my %names=&getnames($uname,$udom);
1.68      albertel 2680:     my $name=$names{'nickname'};
1.66      www      2681:     if ($name) {
                   2682:        $name='&quot;'.$name.'&quot;'; 
                   2683:     } else {
                   2684:        $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
                   2685: 	     $names{'lastname'}.' '.$names{'generation'};
                   2686:        $name=~s/\s+$//;
                   2687:        $name=~s/\s+/ /g;
                   2688:     }
                   2689:     return $name;
                   2690: }
                   2691: 
1.295     www      2692: sub getnames {
                   2693:     my ($uname,$udom)=@_;
1.537     albertel 2694:     return if (!defined($uname) || !defined($udom));
1.433     albertel 2695:     if ($udom eq 'public' && $uname eq 'public') {
                   2696: 	return ('lastname' => &mt('Public'));
                   2697:     }
1.295     www      2698:     my $id=$uname.':'.$udom;
                   2699:     my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
                   2700:     if ($cached) {
                   2701: 	return %{$names};
                   2702:     } else {
                   2703: 	my %loadnames=&Apache::lonnet::get('environment',
                   2704:                     ['firstname','middlename','lastname','generation','nickname'],
                   2705: 					 $udom,$uname);
                   2706: 	&Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
                   2707: 	return %loadnames;
                   2708:     }
                   2709: }
1.61      www      2710: 
1.542     raeburn  2711: # -------------------------------------------------------------------- getemails
1.648     raeburn  2712: 
1.542     raeburn  2713: =pod
                   2714: 
1.648     raeburn  2715: =item * &getemails($uname,$udom)
1.542     raeburn  2716: 
                   2717: Gets a user's email information and returns it as a hash with keys:
                   2718: notification, critnotification, permanentemail
                   2719: 
                   2720: For notification and critnotification, values are comma-separated lists 
1.648     raeburn  2721: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542     raeburn  2722:  
1.648     raeburn  2723: 
1.542     raeburn  2724: =cut
                   2725: 
1.648     raeburn  2726: 
1.466     albertel 2727: sub getemails {
                   2728:     my ($uname,$udom)=@_;
                   2729:     if ($udom eq 'public' && $uname eq 'public') {
                   2730: 	return;
                   2731:     }
1.467     www      2732:     if (!$udom) { $udom=$env{'user.domain'}; }
                   2733:     if (!$uname) { $uname=$env{'user.name'}; }
1.466     albertel 2734:     my $id=$uname.':'.$udom;
                   2735:     my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
                   2736:     if ($cached) {
                   2737: 	return %{$names};
                   2738:     } else {
                   2739: 	my %loadnames=&Apache::lonnet::get('environment',
                   2740:                     			   ['notification','critnotification',
                   2741: 					    'permanentemail'],
                   2742: 					   $udom,$uname);
                   2743: 	&Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
                   2744: 	return %loadnames;
                   2745:     }
                   2746: }
                   2747: 
1.551     albertel 2748: sub flush_email_cache {
                   2749:     my ($uname,$udom)=@_;
                   2750:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2751:     if (!$uname) { $uname=$env{'user.name'};   }
                   2752:     return if ($udom eq 'public' && $uname eq 'public');
                   2753:     my $id=$uname.':'.$udom;
                   2754:     &Apache::lonnet::devalidate_cache_new('emailscache',$id);
                   2755: }
                   2756: 
1.728     raeburn  2757: # -------------------------------------------------------------------- getlangs
                   2758: 
                   2759: =pod
                   2760: 
                   2761: =item * &getlangs($uname,$udom)
                   2762: 
                   2763: Gets a user's language preference and returns it as a hash with key:
                   2764: language.
                   2765: 
                   2766: =cut
                   2767: 
                   2768: 
                   2769: sub getlangs {
                   2770:     my ($uname,$udom) = @_;
                   2771:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2772:     if (!$uname) { $uname=$env{'user.name'};   }
                   2773:     my $id=$uname.':'.$udom;
                   2774:     my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
                   2775:     if ($cached) {
                   2776:         return %{$langs};
                   2777:     } else {
                   2778:         my %loadlangs=&Apache::lonnet::get('environment',['languages'],
                   2779:                                            $udom,$uname);
                   2780:         &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
                   2781:         return %loadlangs;
                   2782:     }
                   2783: }
                   2784: 
                   2785: sub flush_langs_cache {
                   2786:     my ($uname,$udom)=@_;
                   2787:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2788:     if (!$uname) { $uname=$env{'user.name'};   }
                   2789:     return if ($udom eq 'public' && $uname eq 'public');
                   2790:     my $id=$uname.':'.$udom;
                   2791:     &Apache::lonnet::devalidate_cache_new('userlangs',$id);
                   2792: }
                   2793: 
1.61      www      2794: # ------------------------------------------------------------------ Screenname
1.81      albertel 2795: 
                   2796: =pod
                   2797: 
1.648     raeburn  2798: =item * &screenname($uname,$udom)
1.81      albertel 2799: 
                   2800: Gets a users screenname and returns it as a string
                   2801: 
                   2802: =cut
1.61      www      2803: 
                   2804: sub screenname {
                   2805:     my ($uname,$udom)=@_;
1.258     albertel 2806:     if ($uname eq $env{'user.name'} &&
                   2807: 	$udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212     albertel 2808:     my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68      albertel 2809:     return $names{'screenname'};
1.62      www      2810: }
                   2811: 
1.212     albertel 2812: 
1.62      www      2813: # ------------------------------------------------------------- Message Wrapper
                   2814: 
                   2815: sub messagewrapper {
1.369     www      2816:     my ($link,$username,$domain,$subject,$text)=@_;
1.62      www      2817:     return 
1.441     albertel 2818:         '<a href="/adm/email?compose=individual&amp;'.
                   2819:         'recname='.$username.'&amp;recdom='.$domain.
                   2820: 	'&amp;subject='.&escape($subject).'&amp;text='.&escape($text).'" '.
1.200     matthew  2821:         'title="'.&mt('Send message').'">'.$link.'</a>';
1.74      www      2822: }
                   2823: # --------------------------------------------------------------- Notes Wrapper
                   2824: 
                   2825: sub noteswrapper {
                   2826:     my ($link,$un,$do)=@_;
                   2827:     return 
                   2828: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62      www      2829: }
                   2830: # ------------------------------------------------------------- Aboutme Wrapper
                   2831: 
                   2832: sub aboutmewrapper {
1.166     www      2833:     my ($link,$username,$domain,$target)=@_;
1.447     raeburn  2834:     if (!defined($username)  && !defined($domain)) {
                   2835:         return;
                   2836:     }
1.205     www      2837:     return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.756     weissno  2838: 	($target?' target="$target"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62      www      2839: }
                   2840: 
                   2841: # ------------------------------------------------------------ Syllabus Wrapper
                   2842: 
                   2843: 
                   2844: sub syllabuswrapper {
1.707     bisitz   2845:     my ($linktext,$coursedir,$domain)=@_;
1.208     matthew  2846:     return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61      www      2847: }
1.14      harris41 2848: 
1.208     matthew  2849: sub track_student_link {
1.268     albertel 2850:     my ($linktext,$sname,$sdom,$target,$start) = @_;
                   2851:     my $link ="/adm/trackstudent?";
1.208     matthew  2852:     my $title = 'View recent activity';
                   2853:     if (defined($sname) && $sname !~ /^\s*$/ &&
                   2854:         defined($sdom)  && $sdom  !~ /^\s*$/) {
1.268     albertel 2855:         $link .= "selected_student=$sname:$sdom";
1.208     matthew  2856:         $title .= ' of this student';
1.268     albertel 2857:     } 
1.208     matthew  2858:     if (defined($target) && $target !~ /^\s*$/) {
                   2859:         $target = qq{target="$target"};
                   2860:     } else {
                   2861:         $target = '';
                   2862:     }
1.268     albertel 2863:     if ($start) { $link.='&amp;start='.$start; }
1.554     albertel 2864:     $title = &mt($title);
                   2865:     $linktext = &mt($linktext);
1.448     albertel 2866:     return qq{<a href="$link" title="$title" $target>$linktext</a>}.
                   2867: 	&help_open_topic('View_recent_activity');
1.208     matthew  2868: }
                   2869: 
1.781     raeburn  2870: sub slot_reservations_link {
                   2871:     my ($linktext,$sname,$sdom,$target) = @_;
                   2872:     my $link ="/adm/slotrequest?command=showresv&amp;origin=aboutme";
                   2873:     my $title = 'View slot reservation history';
                   2874:     if (defined($sname) && $sname !~ /^\s*$/ &&
                   2875:         defined($sdom)  && $sdom  !~ /^\s*$/) {
                   2876:         $link .= "&amp;uname=$sname&amp;udom=$sdom";
                   2877:         $title .= ' of this student';
                   2878:     }
                   2879:     if (defined($target) && $target !~ /^\s*$/) {
                   2880:         $target = qq{target="$target"};
                   2881:     } else {
                   2882:         $target = '';
                   2883:     }
                   2884:     $title = &mt($title);
                   2885:     $linktext = &mt($linktext);
                   2886:     return qq{<a href="$link" title="$title" $target>$linktext</a>};
                   2887: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
                   2888: 
                   2889: }
                   2890: 
1.508     www      2891: # ===================================================== Display a student photo
                   2892: 
                   2893: 
1.509     albertel 2894: sub student_image_tag {
1.508     www      2895:     my ($domain,$user)=@_;
                   2896:     my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
                   2897:     if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
                   2898: 	return '<img src="'.$imgsrc.'" align="right" />';
                   2899:     } else {
                   2900: 	return '';
                   2901:     }
                   2902: }
                   2903: 
1.112     bowersj2 2904: =pod
                   2905: 
                   2906: =back
                   2907: 
                   2908: =head1 Access .tab File Data
                   2909: 
                   2910: =over 4
                   2911: 
1.648     raeburn  2912: =item * &languageids() 
1.112     bowersj2 2913: 
                   2914: returns list of all language ids
                   2915: 
                   2916: =cut
                   2917: 
1.14      harris41 2918: sub languageids {
1.16      harris41 2919:     return sort(keys(%language));
1.14      harris41 2920: }
                   2921: 
1.112     bowersj2 2922: =pod
                   2923: 
1.648     raeburn  2924: =item * &languagedescription() 
1.112     bowersj2 2925: 
                   2926: returns description of a specified language id
                   2927: 
                   2928: =cut
                   2929: 
1.14      harris41 2930: sub languagedescription {
1.125     www      2931:     my $code=shift;
                   2932:     return  ($supported_language{$code}?'* ':'').
                   2933:             $language{$code}.
1.126     www      2934: 	    ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145     www      2935: }
                   2936: 
                   2937: sub plainlanguagedescription {
                   2938:     my $code=shift;
                   2939:     return $language{$code};
                   2940: }
                   2941: 
                   2942: sub supportedlanguagecode {
                   2943:     my $code=shift;
                   2944:     return $supported_language{$code};
1.97      www      2945: }
                   2946: 
1.112     bowersj2 2947: =pod
                   2948: 
1.648     raeburn  2949: =item * &copyrightids() 
1.112     bowersj2 2950: 
                   2951: returns list of all copyrights
                   2952: 
                   2953: =cut
                   2954: 
                   2955: sub copyrightids {
                   2956:     return sort(keys(%cprtag));
                   2957: }
                   2958: 
                   2959: =pod
                   2960: 
1.648     raeburn  2961: =item * &copyrightdescription() 
1.112     bowersj2 2962: 
                   2963: returns description of a specified copyright id
                   2964: 
                   2965: =cut
                   2966: 
                   2967: sub copyrightdescription {
1.166     www      2968:     return &mt($cprtag{shift(@_)});
1.112     bowersj2 2969: }
1.197     matthew  2970: 
                   2971: =pod
                   2972: 
1.648     raeburn  2973: =item * &source_copyrightids() 
1.192     taceyjo1 2974: 
                   2975: returns list of all source copyrights
                   2976: 
                   2977: =cut
                   2978: 
                   2979: sub source_copyrightids {
                   2980:     return sort(keys(%scprtag));
                   2981: }
                   2982: 
                   2983: =pod
                   2984: 
1.648     raeburn  2985: =item * &source_copyrightdescription() 
1.192     taceyjo1 2986: 
                   2987: returns description of a specified source copyright id
                   2988: 
                   2989: =cut
                   2990: 
                   2991: sub source_copyrightdescription {
                   2992:     return &mt($scprtag{shift(@_)});
                   2993: }
1.112     bowersj2 2994: 
                   2995: =pod
                   2996: 
1.648     raeburn  2997: =item * &filecategories() 
1.112     bowersj2 2998: 
                   2999: returns list of all file categories
                   3000: 
                   3001: =cut
                   3002: 
                   3003: sub filecategories {
                   3004:     return sort(keys(%category_extensions));
                   3005: }
                   3006: 
                   3007: =pod
                   3008: 
1.648     raeburn  3009: =item * &filecategorytypes() 
1.112     bowersj2 3010: 
                   3011: returns list of file types belonging to a given file
                   3012: category
                   3013: 
                   3014: =cut
                   3015: 
                   3016: sub filecategorytypes {
1.356     albertel 3017:     my ($cat) = @_;
                   3018:     return @{$category_extensions{lc($cat)}};
1.112     bowersj2 3019: }
                   3020: 
                   3021: =pod
                   3022: 
1.648     raeburn  3023: =item * &fileembstyle() 
1.112     bowersj2 3024: 
                   3025: returns embedding style for a specified file type
                   3026: 
                   3027: =cut
                   3028: 
                   3029: sub fileembstyle {
                   3030:     return $fe{lc(shift(@_))};
1.169     www      3031: }
                   3032: 
1.351     www      3033: sub filemimetype {
                   3034:     return $fm{lc(shift(@_))};
                   3035: }
                   3036: 
1.169     www      3037: 
                   3038: sub filecategoryselect {
                   3039:     my ($name,$value)=@_;
1.189     matthew  3040:     return &select_form($value,$name,
1.169     www      3041: 			'' => &mt('Any category'),
                   3042: 			map { $_,$_ } sort(keys(%category_extensions)));
1.112     bowersj2 3043: }
                   3044: 
                   3045: =pod
                   3046: 
1.648     raeburn  3047: =item * &filedescription() 
1.112     bowersj2 3048: 
                   3049: returns description for a specified file type
                   3050: 
                   3051: =cut
                   3052: 
                   3053: sub filedescription {
1.188     matthew  3054:     my $file_description = $fd{lc(shift())};
                   3055:     $file_description =~ s:([\[\]]):~$1:g;
                   3056:     return &mt($file_description);
1.112     bowersj2 3057: }
                   3058: 
                   3059: =pod
                   3060: 
1.648     raeburn  3061: =item * &filedescriptionex() 
1.112     bowersj2 3062: 
                   3063: returns description for a specified file type with
                   3064: extra formatting
                   3065: 
                   3066: =cut
                   3067: 
                   3068: sub filedescriptionex {
                   3069:     my $ex=shift;
1.188     matthew  3070:     my $file_description = $fd{lc($ex)};
                   3071:     $file_description =~ s:([\[\]]):~$1:g;
                   3072:     return '.'.$ex.' '.&mt($file_description);
1.112     bowersj2 3073: }
                   3074: 
                   3075: # End of .tab access
                   3076: =pod
                   3077: 
                   3078: =back
                   3079: 
                   3080: =cut
                   3081: 
                   3082: # ------------------------------------------------------------------ File Types
                   3083: sub fileextensions {
                   3084:     return sort(keys(%fe));
                   3085: }
                   3086: 
1.97      www      3087: # ----------------------------------------------------------- Display Languages
                   3088: # returns a hash with all desired display languages
                   3089: #
                   3090: 
                   3091: sub display_languages {
                   3092:     my %languages=();
1.695     raeburn  3093:     foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356     albertel 3094: 	$languages{$lang}=1;
1.97      www      3095:     }
                   3096:     &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258     albertel 3097:     if ($env{'form.displaylanguage'}) {
1.356     albertel 3098: 	foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
                   3099: 	    $languages{$lang}=1;
1.97      www      3100:         }
                   3101:     }
                   3102:     return %languages;
1.14      harris41 3103: }
                   3104: 
1.582     albertel 3105: sub languages {
                   3106:     my ($possible_langs) = @_;
1.695     raeburn  3107:     my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582     albertel 3108:     if (!ref($possible_langs)) {
                   3109: 	if( wantarray ) {
                   3110: 	    return @preferred_langs;
                   3111: 	} else {
                   3112: 	    return $preferred_langs[0];
                   3113: 	}
                   3114:     }
                   3115:     my %possibilities = map { $_ => 1 } (@$possible_langs);
                   3116:     my @preferred_possibilities;
                   3117:     foreach my $preferred_lang (@preferred_langs) {
                   3118: 	if (exists($possibilities{$preferred_lang})) {
                   3119: 	    push(@preferred_possibilities, $preferred_lang);
                   3120: 	}
                   3121:     }
                   3122:     if( wantarray ) {
                   3123: 	return @preferred_possibilities;
                   3124:     }
                   3125:     return $preferred_possibilities[0];
                   3126: }
                   3127: 
1.742     raeburn  3128: sub user_lang {
                   3129:     my ($touname,$toudom,$fromcid) = @_;
                   3130:     my @userlangs;
                   3131:     if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
                   3132:         @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
                   3133:                     $env{'course.'.$fromcid.'.languages'}));
                   3134:     } else {
                   3135:         my %langhash = &getlangs($touname,$toudom);
                   3136:         if ($langhash{'languages'} ne '') {
                   3137:             @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
                   3138:         } else {
                   3139:             my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
                   3140:             if ($domdefs{'lang_def'} ne '') {
                   3141:                 @userlangs = ($domdefs{'lang_def'});
                   3142:             }
                   3143:         }
                   3144:     }
                   3145:     my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
                   3146:     my $user_lh = Apache::localize->get_handle(@languages);
                   3147:     return $user_lh;
                   3148: }
                   3149: 
                   3150: 
1.112     bowersj2 3151: ###############################################################
                   3152: ##               Student Answer Attempts                     ##
                   3153: ###############################################################
                   3154: 
                   3155: =pod
                   3156: 
                   3157: =head1 Alternate Problem Views
                   3158: 
                   3159: =over 4
                   3160: 
1.648     raeburn  3161: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112     bowersj2 3162:     $getattempt, $regexp, $gradesub)
                   3163: 
                   3164: Return string with previous attempt on problem. Arguments:
                   3165: 
                   3166: =over 4
                   3167: 
                   3168: =item * $symb: Problem, including path
                   3169: 
                   3170: =item * $username: username of the desired student
                   3171: 
                   3172: =item * $domain: domain of the desired student
1.14      harris41 3173: 
1.112     bowersj2 3174: =item * $course: Course ID
1.14      harris41 3175: 
1.112     bowersj2 3176: =item * $getattempt: Leave blank for all attempts, otherwise put
                   3177:     something
1.14      harris41 3178: 
1.112     bowersj2 3179: =item * $regexp: if string matches this regexp, the string will be
                   3180:     sent to $gradesub
1.14      harris41 3181: 
1.112     bowersj2 3182: =item * $gradesub: routine that processes the string if it matches $regexp
1.14      harris41 3183: 
1.112     bowersj2 3184: =back
1.14      harris41 3185: 
1.112     bowersj2 3186: The output string is a table containing all desired attempts, if any.
1.16      harris41 3187: 
1.112     bowersj2 3188: =cut
1.1       albertel 3189: 
                   3190: sub get_previous_attempt {
1.43      ng       3191:   my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1       albertel 3192:   my $prevattempts='';
1.43      ng       3193:   no strict 'refs';
1.1       albertel 3194:   if ($symb) {
1.3       albertel 3195:     my (%returnhash)=
                   3196:       &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1       albertel 3197:     if ($returnhash{'version'}) {
                   3198:       my %lasthash=();
                   3199:       my $version;
                   3200:       for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356     albertel 3201:         foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
                   3202: 	  $lasthash{$key}=$returnhash{$version.':'.$key};
1.19      harris41 3203:         }
1.1       albertel 3204:       }
1.596     albertel 3205:       $prevattempts=&start_data_table().&start_data_table_header_row();
                   3206:       $prevattempts.='<th>'.&mt('History').'</th>';
1.356     albertel 3207:       foreach my $key (sort(keys(%lasthash))) {
                   3208: 	my ($ign,@parts) = split(/\./,$key);
1.41      ng       3209: 	if ($#parts > 0) {
1.31      albertel 3210: 	  my $data=$parts[-1];
                   3211: 	  pop(@parts);
1.596     albertel 3212: 	  $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.'&nbsp;</th>';
1.31      albertel 3213: 	} else {
1.41      ng       3214: 	  if ($#parts == 0) {
                   3215: 	    $prevattempts.='<th>'.$parts[0].'</th>';
                   3216: 	  } else {
                   3217: 	    $prevattempts.='<th>'.$ign.'</th>';
                   3218: 	  }
1.31      albertel 3219: 	}
1.16      harris41 3220:       }
1.596     albertel 3221:       $prevattempts.=&end_data_table_header_row();
1.40      ng       3222:       if ($getattempt eq '') {
                   3223: 	for ($version=1;$version<=$returnhash{'version'};$version++) {
1.596     albertel 3224: 	  $prevattempts.=&start_data_table_row().
                   3225: 	      '<td>'.&mt('Transaction [_1]',$version).'</td>';
1.356     albertel 3226: 	    foreach my $key (sort(keys(%lasthash))) {
1.581     albertel 3227: 		my $value = &format_previous_attempt_value($key,
                   3228: 							   $returnhash{$version.':'.$key});
                   3229: 		$prevattempts.='<td>'.$value.'&nbsp;</td>';   
1.40      ng       3230: 	    }
1.596     albertel 3231: 	  $prevattempts.=&end_data_table_row();
1.40      ng       3232: 	 }
1.1       albertel 3233:       }
1.596     albertel 3234:       $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356     albertel 3235:       foreach my $key (sort(keys(%lasthash))) {
1.581     albertel 3236: 	my $value = &format_previous_attempt_value($key,$lasthash{$key});
1.356     albertel 3237: 	if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
1.40      ng       3238: 	$prevattempts.='<td>'.$value.'&nbsp;</td>';
1.16      harris41 3239:       }
1.596     albertel 3240:       $prevattempts.= &end_data_table_row().&end_data_table();
1.1       albertel 3241:     } else {
1.596     albertel 3242:       $prevattempts=
                   3243: 	  &start_data_table().&start_data_table_row().
                   3244: 	  '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
                   3245: 	  &end_data_table_row().&end_data_table();
1.1       albertel 3246:     }
                   3247:   } else {
1.596     albertel 3248:     $prevattempts=
                   3249: 	  &start_data_table().&start_data_table_row().
                   3250: 	  '<td>'.&mt('No data.').'</td>'.
                   3251: 	  &end_data_table_row().&end_data_table();
1.1       albertel 3252:   }
1.10      albertel 3253: }
                   3254: 
1.581     albertel 3255: sub format_previous_attempt_value {
                   3256:     my ($key,$value) = @_;
                   3257:     if ($key =~ /timestamp/) {
                   3258: 	$value = &Apache::lonlocal::locallocaltime($value);
                   3259:     } elsif (ref($value) eq 'ARRAY') {
                   3260: 	$value = '('.join(', ', @{ $value }).')';
                   3261:     } else {
                   3262: 	$value = &unescape($value);
                   3263:     }
                   3264:     return $value;
                   3265: }
                   3266: 
                   3267: 
1.107     albertel 3268: sub relative_to_absolute {
                   3269:     my ($url,$output)=@_;
                   3270:     my $parser=HTML::TokeParser->new(\$output);
                   3271:     my $token;
                   3272:     my $thisdir=$url;
                   3273:     my @rlinks=();
                   3274:     while ($token=$parser->get_token) {
                   3275: 	if ($token->[0] eq 'S') {
                   3276: 	    if ($token->[1] eq 'a') {
                   3277: 		if ($token->[2]->{'href'}) {
                   3278: 		    $rlinks[$#rlinks+1]=$token->[2]->{'href'};
                   3279: 		}
                   3280: 	    } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
                   3281: 		$rlinks[$#rlinks+1]=$token->[2]->{'src'};
                   3282: 	    } elsif ($token->[1] eq 'base') {
                   3283: 		$thisdir=$token->[2]->{'href'};
                   3284: 	    }
                   3285: 	}
                   3286:     }
                   3287:     $thisdir=~s-/[^/]*$--;
1.356     albertel 3288:     foreach my $link (@rlinks) {
1.726     raeburn  3289: 	unless (($link=~/^https?\:\/\//i) ||
1.356     albertel 3290: 		($link=~/^\//) ||
                   3291: 		($link=~/^javascript:/i) ||
                   3292: 		($link=~/^mailto:/i) ||
                   3293: 		($link=~/^\#/)) {
                   3294: 	    my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
                   3295: 	    $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107     albertel 3296: 	}
                   3297:     }
                   3298: # -------------------------------------------------- Deal with Applet codebases
                   3299:     $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
                   3300:     return $output;
                   3301: }
                   3302: 
1.112     bowersj2 3303: =pod
                   3304: 
1.648     raeburn  3305: =item * &get_student_view()
1.112     bowersj2 3306: 
                   3307: show a snapshot of what student was looking at
                   3308: 
                   3309: =cut
                   3310: 
1.10      albertel 3311: sub get_student_view {
1.186     albertel 3312:   my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114     www      3313:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 3314:   my (%form);
1.10      albertel 3315:   my @elements=('symb','courseid','domain','username');
                   3316:   foreach my $element (@elements) {
1.186     albertel 3317:       $form{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 3318:   }
1.186     albertel 3319:   if (defined($moreenv)) {
                   3320:       %form=(%form,%{$moreenv});
                   3321:   }
1.236     albertel 3322:   if (defined($target)) { $form{'grade_target'} = $target; }
1.107     albertel 3323:   $feedurl=&Apache::lonnet::clutter($feedurl);
1.650     www      3324:   my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11      albertel 3325:   $userview=~s/\<body[^\>]*\>//gi;
                   3326:   $userview=~s/\<\/body\>//gi;
                   3327:   $userview=~s/\<html\>//gi;
                   3328:   $userview=~s/\<\/html\>//gi;
                   3329:   $userview=~s/\<head\>//gi;
                   3330:   $userview=~s/\<\/head\>//gi;
                   3331:   $userview=~s/action\s*\=/would_be_action\=/gi;
1.107     albertel 3332:   $userview=&relative_to_absolute($feedurl,$userview);
1.650     www      3333:   if (wantarray) {
                   3334:      return ($userview,$response);
                   3335:   } else {
                   3336:      return $userview;
                   3337:   }
                   3338: }
                   3339: 
                   3340: sub get_student_view_with_retries {
                   3341:   my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
                   3342: 
                   3343:     my $ok = 0;                 # True if we got a good response.
                   3344:     my $content;
                   3345:     my $response;
                   3346: 
                   3347:     # Try to get the student_view done. within the retries count:
                   3348:     
                   3349:     do {
                   3350:          ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
                   3351:          $ok      = $response->is_success;
                   3352:          if (!$ok) {
                   3353:             &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
                   3354:          }
                   3355:          $retries--;
                   3356:     } while (!$ok && ($retries > 0));
                   3357:     
                   3358:     if (!$ok) {
                   3359:        $content = '';          # On error return an empty content.
                   3360:     }
1.651     www      3361:     if (wantarray) {
                   3362:        return ($content, $response);
                   3363:     } else {
                   3364:        return $content;
                   3365:     }
1.11      albertel 3366: }
                   3367: 
1.112     bowersj2 3368: =pod
                   3369: 
1.648     raeburn  3370: =item * &get_student_answers() 
1.112     bowersj2 3371: 
                   3372: show a snapshot of how student was answering problem
                   3373: 
                   3374: =cut
                   3375: 
1.11      albertel 3376: sub get_student_answers {
1.100     sakharuk 3377:   my ($symb,$username,$domain,$courseid,%form) = @_;
1.114     www      3378:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 3379:   my (%moreenv);
1.11      albertel 3380:   my @elements=('symb','courseid','domain','username');
                   3381:   foreach my $element (@elements) {
1.186     albertel 3382:     $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 3383:   }
1.186     albertel 3384:   $moreenv{'grade_target'}='answer';
                   3385:   %moreenv=(%form,%moreenv);
1.497     raeburn  3386:   $feedurl = &Apache::lonnet::clutter($feedurl);
                   3387:   my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10      albertel 3388:   return $userview;
1.1       albertel 3389: }
1.116     albertel 3390: 
                   3391: =pod
                   3392: 
                   3393: =item * &submlink()
                   3394: 
1.242     albertel 3395: Inputs: $text $uname $udom $symb $target
1.116     albertel 3396: 
                   3397: Returns: A link to grades.pm such as to see the SUBM view of a student
                   3398: 
                   3399: =cut
                   3400: 
                   3401: ###############################################
                   3402: sub submlink {
1.242     albertel 3403:     my ($text,$uname,$udom,$symb,$target)=@_;
1.116     albertel 3404:     if (!($uname && $udom)) {
                   3405: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 3406: 	    &Apache::lonnet::whichuser($symb);
1.116     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\""; }
                   3412:     return '<a href="/adm/grades?&command=submission&'.
                   3413: 	'symb='.$symb.'&student='.$uname.
                   3414: 	'&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
                   3415: }
                   3416: ##############################################
                   3417: 
                   3418: =pod
                   3419: 
                   3420: =item * &pgrdlink()
                   3421: 
                   3422: Inputs: $text $uname $udom $symb $target
                   3423: 
                   3424: Returns: A link to grades.pm such as to see the PGRD view of a student
                   3425: 
                   3426: =cut
                   3427: 
                   3428: ###############################################
                   3429: sub pgrdlink {
                   3430:     my $link=&submlink(@_);
                   3431:     $link=~s/(&command=submission)/$1&showgrading=yes/;
                   3432:     return $link;
                   3433: }
                   3434: ##############################################
                   3435: 
                   3436: =pod
                   3437: 
                   3438: =item * &pprmlink()
                   3439: 
                   3440: Inputs: $text $uname $udom $symb $target
                   3441: 
                   3442: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283     albertel 3443: student and a specific resource
1.242     albertel 3444: 
                   3445: =cut
                   3446: 
                   3447: ###############################################
                   3448: sub pprmlink {
                   3449:     my ($text,$uname,$udom,$symb,$target)=@_;
                   3450:     if (!($uname && $udom)) {
                   3451: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 3452: 	    &Apache::lonnet::whichuser($symb);
1.242     albertel 3453: 	if (!$symb) { $symb=$cursymb; }
                   3454:     }
1.254     matthew  3455:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      3456:     $symb=&escape($symb);
1.242     albertel 3457:     if ($target) { $target="target=\"$target\""; }
1.595     albertel 3458:     return '<a href="/adm/parmset?command=set&amp;'.
                   3459: 	'symb='.$symb.'&amp;uname='.$uname.
                   3460: 	'&amp;udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116     albertel 3461: }
                   3462: ##############################################
1.37      matthew  3463: 
1.112     bowersj2 3464: =pod
                   3465: 
                   3466: =back
                   3467: 
                   3468: =cut
                   3469: 
1.37      matthew  3470: ###############################################
1.51      www      3471: 
                   3472: 
                   3473: sub timehash {
1.687     raeburn  3474:     my ($thistime) = @_;
                   3475:     my $timezone = &Apache::lonlocal::gettimezone();
                   3476:     my $dt = DateTime->from_epoch(epoch => $thistime)
                   3477:                      ->set_time_zone($timezone);
                   3478:     my $wday = $dt->day_of_week();
                   3479:     if ($wday == 7) { $wday = 0; }
                   3480:     return ( 'second' => $dt->second(),
                   3481:              'minute' => $dt->minute(),
                   3482:              'hour'   => $dt->hour(),
                   3483:              'day'     => $dt->day_of_month(),
                   3484:              'month'   => $dt->month(),
                   3485:              'year'    => $dt->year(),
                   3486:              'weekday' => $wday,
                   3487:              'dayyear' => $dt->day_of_year(),
                   3488:              'dlsav'   => $dt->is_dst() );
1.51      www      3489: }
                   3490: 
1.370     www      3491: sub utc_string {
                   3492:     my ($date)=@_;
1.371     www      3493:     return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370     www      3494: }
                   3495: 
1.51      www      3496: sub maketime {
                   3497:     my %th=@_;
1.687     raeburn  3498:     my ($epoch_time,$timezone,$dt);
                   3499:     $timezone = &Apache::lonlocal::gettimezone();
                   3500:     eval {
                   3501:         $dt = DateTime->new( year   => $th{'year'},
                   3502:                              month  => $th{'month'},
                   3503:                              day    => $th{'day'},
                   3504:                              hour   => $th{'hour'},
                   3505:                              minute => $th{'minute'},
                   3506:                              second => $th{'second'},
                   3507:                              time_zone => $timezone,
                   3508:                          );
                   3509:     };
                   3510:     if (!$@) {
                   3511:         $epoch_time = $dt->epoch;
                   3512:         if ($epoch_time) {
                   3513:             return $epoch_time;
                   3514:         }
                   3515:     }
1.51      www      3516:     return POSIX::mktime(
                   3517:         ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210     www      3518:          $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70      www      3519: }
                   3520: 
                   3521: #########################################
1.51      www      3522: 
                   3523: sub findallcourses {
1.482     raeburn  3524:     my ($roles,$uname,$udom) = @_;
1.355     albertel 3525:     my %roles;
                   3526:     if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348     albertel 3527:     my %courses;
1.51      www      3528:     my $now=time;
1.482     raeburn  3529:     if (!defined($uname)) {
                   3530:         $uname = $env{'user.name'};
                   3531:     }
                   3532:     if (!defined($udom)) {
                   3533:         $udom = $env{'user.domain'};
                   3534:     }
                   3535:     if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
                   3536:         my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
                   3537:         if (!%roles) {
                   3538:             %roles = (
                   3539:                        cc => 1,
                   3540:                        in => 1,
                   3541:                        ep => 1,
                   3542:                        ta => 1,
                   3543:                        cr => 1,
                   3544:                        st => 1,
                   3545:              );
                   3546:         }
                   3547:         foreach my $entry (keys(%roleshash)) {
                   3548:             my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
                   3549:             if ($trole =~ /^cr/) { 
                   3550:                 next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
                   3551:             } else {
                   3552:                 next if (!exists($roles{$trole}));
                   3553:             }
                   3554:             if ($tend) {
                   3555:                 next if ($tend < $now);
                   3556:             }
                   3557:             if ($tstart) {
                   3558:                 next if ($tstart > $now);
                   3559:             }
                   3560:             my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
                   3561:             (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
                   3562:             if ($secpart eq '') {
                   3563:                 ($cnum,$role) = split(/_/,$cnumpart); 
                   3564:                 $sec = 'none';
                   3565:                 $realsec = '';
                   3566:             } else {
                   3567:                 $cnum = $cnumpart;
                   3568:                 ($sec,$role) = split(/_/,$secpart);
                   3569:                 $realsec = $sec;
1.490     raeburn  3570:             }
1.482     raeburn  3571:             $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
                   3572:         }
                   3573:     } else {
                   3574:         foreach my $key (keys(%env)) {
1.483     albertel 3575: 	    if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
                   3576:                  $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482     raeburn  3577: 	        my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
                   3578: 	        next if ($role eq 'ca' || $role eq 'aa');
                   3579: 	        next if (%roles && !exists($roles{$role}));
                   3580: 	        my ($starttime,$endtime)=split(/\./,$env{$key});
                   3581:                 my $active=1;
                   3582:                 if ($starttime) {
                   3583: 		    if ($now<$starttime) { $active=0; }
                   3584:                 }
                   3585:                 if ($endtime) {
                   3586:                     if ($now>$endtime) { $active=0; }
                   3587:                 }
                   3588:                 if ($active) {
                   3589:                     if ($sec eq '') {
                   3590:                         $sec = 'none';
                   3591:                     }
                   3592:                     $courses{$cdom.'_'.$cnum}{$sec} = 
                   3593:                                      $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474     raeburn  3594:                 }
                   3595:             }
1.51      www      3596:         }
                   3597:     }
1.474     raeburn  3598:     return %courses;
1.51      www      3599: }
1.37      matthew  3600: 
1.54      www      3601: ###############################################
1.474     raeburn  3602: 
                   3603: sub blockcheck {
1.482     raeburn  3604:     my ($setters,$activity,$uname,$udom) = @_;
1.490     raeburn  3605: 
                   3606:     if (!defined($udom)) {
                   3607:         $udom = $env{'user.domain'};
                   3608:     }
                   3609:     if (!defined($uname)) {
                   3610:         $uname = $env{'user.name'};
                   3611:     }
                   3612: 
                   3613:     # If uname and udom are for a course, check for blocks in the course.
                   3614: 
                   3615:     if (&Apache::lonnet::is_course($udom,$uname)) {
                   3616:         my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502     raeburn  3617:         my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490     raeburn  3618:         return ($startblock,$endblock);
                   3619:     }
1.474     raeburn  3620: 
1.502     raeburn  3621:     my $startblock = 0;
                   3622:     my $endblock = 0;
1.482     raeburn  3623:     my %live_courses = &findallcourses(undef,$uname,$udom);
1.474     raeburn  3624: 
1.490     raeburn  3625:     # If uname is for a user, and activity is course-specific, i.e.,
                   3626:     # boards, chat or groups, check for blocking in current course only.
1.474     raeburn  3627: 
1.490     raeburn  3628:     if (($activity eq 'boards' || $activity eq 'chat' ||
                   3629:          $activity eq 'groups') && ($env{'request.course.id'})) {
                   3630:         foreach my $key (keys(%live_courses)) {
                   3631:             if ($key ne $env{'request.course.id'}) {
                   3632:                 delete($live_courses{$key});
                   3633:             }
                   3634:         }
                   3635:     }
                   3636: 
                   3637:     my $otheruser = 0;
                   3638:     my %own_courses;
                   3639:     if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
                   3640:         # Resource belongs to user other than current user.
                   3641:         $otheruser = 1;
                   3642:         # Gather courses for current user
                   3643:         %own_courses = 
                   3644:             &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
                   3645:     }
                   3646: 
                   3647:     # Gather active course roles - course coordinator, instructor, 
                   3648:     # exam proctor, ta, student, or custom role.
1.474     raeburn  3649: 
                   3650:     foreach my $course (keys(%live_courses)) {
1.482     raeburn  3651:         my ($cdom,$cnum);
                   3652:         if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
                   3653:             $cdom = $env{'course.'.$course.'.domain'};
                   3654:             $cnum = $env{'course.'.$course.'.num'};
                   3655:         } else {
1.490     raeburn  3656:             ($cdom,$cnum) = split(/_/,$course); 
1.482     raeburn  3657:         }
                   3658:         my $no_ownblock = 0;
                   3659:         my $no_userblock = 0;
1.533     raeburn  3660:         if ($otheruser && $activity ne 'com') {
1.490     raeburn  3661:             # Check if current user has 'evb' priv for this
                   3662:             if (defined($own_courses{$course})) {
                   3663:                 foreach my $sec (keys(%{$own_courses{$course}})) {
                   3664:                     my $checkrole = 'cm./'.$cdom.'/'.$cnum;
                   3665:                     if ($sec ne 'none') {
                   3666:                         $checkrole .= '/'.$sec;
                   3667:                     }
                   3668:                     if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   3669:                         $no_ownblock = 1;
                   3670:                         last;
                   3671:                     }
                   3672:                 }
                   3673:             }
                   3674:             # if they have 'evb' priv and are currently not playing student
                   3675:             next if (($no_ownblock) &&
                   3676:                  ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
                   3677:         }
1.474     raeburn  3678:         foreach my $sec (keys(%{$live_courses{$course}})) {
1.482     raeburn  3679:             my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474     raeburn  3680:             if ($sec ne 'none') {
1.482     raeburn  3681:                 $checkrole .= '/'.$sec;
1.474     raeburn  3682:             }
1.490     raeburn  3683:             if ($otheruser) {
                   3684:                 # Resource belongs to user other than current user.
                   3685:                 # Assemble privs for that user, and check for 'evb' priv.
1.482     raeburn  3686:                 my ($trole,$tdom,$tnum,$tsec);
                   3687:                 my $entry = $live_courses{$course}{$sec};
                   3688:                 if ($entry =~ /^cr/) {
                   3689:                     ($trole,$tdom,$tnum,$tsec) = 
                   3690:                       ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
                   3691:                 } else {
                   3692:                     ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
                   3693:                 }
                   3694:                 my ($spec,$area,$trest,%allroles,%userroles);
                   3695:                 $area = '/'.$tdom.'/'.$tnum;
                   3696:                 $trest = $tnum;
                   3697:                 if ($tsec ne '') {
                   3698:                     $area .= '/'.$tsec;
                   3699:                     $trest .= '/'.$tsec;
                   3700:                 }
                   3701:                 $spec = $trole.'.'.$area;
                   3702:                 if ($trole =~ /^cr/) {
                   3703:                     &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
                   3704:                                                       $tdom,$spec,$trest,$area);
                   3705:                 } else {
                   3706:                     &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
                   3707:                                                        $tdom,$spec,$trest,$area);
                   3708:                 }
                   3709:                 my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486     raeburn  3710:                 if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
                   3711:                     if ($1) {
                   3712:                         $no_userblock = 1;
                   3713:                         last;
                   3714:                     }
                   3715:                 }
1.490     raeburn  3716:             } else {
                   3717:                 # Resource belongs to current user
                   3718:                 # Check for 'evb' priv via lonnet::allowed().
1.482     raeburn  3719:                 if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   3720:                     $no_ownblock = 1;
                   3721:                     last;
                   3722:                 }
1.474     raeburn  3723:             }
                   3724:         }
                   3725:         # if they have the evb priv and are currently not playing student
1.482     raeburn  3726:         next if (($no_ownblock) &&
1.491     albertel 3727:                  ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482     raeburn  3728:         next if ($no_userblock);
1.474     raeburn  3729: 
1.490     raeburn  3730:         # Retrieve blocking times and identity of blocker for course
                   3731:         # of specified user, unless user has 'evb' privilege.
1.502     raeburn  3732:         
                   3733:         my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
                   3734:         if (($start != 0) && 
                   3735:             (($startblock == 0) || ($startblock > $start))) {
                   3736:             $startblock = $start;
                   3737:         }
                   3738:         if (($end != 0)  &&
                   3739:             (($endblock == 0) || ($endblock < $end))) {
                   3740:             $endblock = $end;
                   3741:         }
1.490     raeburn  3742:     }
                   3743:     return ($startblock,$endblock);
                   3744: }
                   3745: 
                   3746: sub get_blocks {
                   3747:     my ($setters,$activity,$cdom,$cnum) = @_;
                   3748:     my $startblock = 0;
                   3749:     my $endblock = 0;
                   3750:     my $course = $cdom.'_'.$cnum;
                   3751:     $setters->{$course} = {};
                   3752:     $setters->{$course}{'staff'} = [];
                   3753:     $setters->{$course}{'times'} = [];
                   3754:     my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
                   3755:     foreach my $record (keys(%records)) {
                   3756:         my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
                   3757:         if ($start <= time && $end >= time) {
                   3758:             my ($staff_name,$staff_dom,$title,$blocks) =
                   3759:                 &parse_block_record($records{$record});
                   3760:             if ($blocks->{$activity} eq 'on') {
                   3761:                 push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
                   3762:                 push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491     albertel 3763:                 if ( ($startblock == 0) || ($startblock > $start) ) {
                   3764:                     $startblock = $start;
1.490     raeburn  3765:                 }
1.491     albertel 3766:                 if ( ($endblock == 0) || ($endblock < $end) ) {
                   3767:                     $endblock = $end;
1.474     raeburn  3768:                 }
                   3769:             }
                   3770:         }
                   3771:     }
                   3772:     return ($startblock,$endblock);
                   3773: }
                   3774: 
                   3775: sub parse_block_record {
                   3776:     my ($record) = @_;
                   3777:     my ($setuname,$setudom,$title,$blocks);
                   3778:     if (ref($record) eq 'HASH') {
                   3779:         ($setuname,$setudom) = split(/:/,$record->{'setter'});
                   3780:         $title = &unescape($record->{'event'});
                   3781:         $blocks = $record->{'blocks'};
                   3782:     } else {
                   3783:         my @data = split(/:/,$record,3);
                   3784:         if (scalar(@data) eq 2) {
                   3785:             $title = $data[1];
                   3786:             ($setuname,$setudom) = split(/@/,$data[0]);
                   3787:         } else {
                   3788:             ($setuname,$setudom,$title) = @data;
                   3789:         }
                   3790:         $blocks = { 'com' => 'on' };
                   3791:     }
                   3792:     return ($setuname,$setudom,$title,$blocks);
                   3793: }
                   3794: 
                   3795: sub build_block_table {
                   3796:     my ($startblock,$endblock,$setters) = @_;
                   3797:     my %lt = &Apache::lonlocal::texthash(
                   3798:         'cacb' => 'Currently active communication blocks',
                   3799:         'cour' => 'Course',
                   3800:         'dura' => 'Duration',
                   3801:         'blse' => 'Block set by'
                   3802:     );
                   3803:     my $output;
1.476     raeburn  3804:     $output = '<br />'.$lt{'cacb'}.':<br />';
1.474     raeburn  3805:     $output .= &start_data_table();
                   3806:     $output .= '
                   3807: <tr>
                   3808:  <th>'.$lt{'cour'}.'</th>
                   3809:  <th>'.$lt{'dura'}.'</th>
                   3810:  <th>'.$lt{'blse'}.'</th>
                   3811: </tr>
                   3812: ';
                   3813:     foreach my $course (keys(%{$setters})) {
                   3814:         my %courseinfo=&Apache::lonnet::coursedescription($course);
                   3815:         for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) {
                   3816:             my ($uname,$udom) = @{$$setters{$course}{staff}[$i]};
1.490     raeburn  3817:             my $fullname = &plainname($uname,$udom);
                   3818:             if (defined($env{'user.name'}) && defined($env{'user.domain'})
                   3819:                 && $env{'user.name'} ne 'public' 
                   3820:                 && $env{'user.domain'} ne 'public') {
                   3821:                 $fullname = &aboutmewrapper($fullname,$uname,$udom);
                   3822:             }
1.474     raeburn  3823:             my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]};
                   3824:             $openblock = &Apache::lonlocal::locallocaltime($openblock);
                   3825:             $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
                   3826:             $output .= &Apache::loncommon::start_data_table_row().
                   3827:                        '<td>'.$courseinfo{'description'}.'</td>'.
                   3828:                        '<td>'.$openblock.' to '.$closeblock.'</td>'.
1.490     raeburn  3829:                        '<td>'.$fullname.'</td>'.
1.474     raeburn  3830:                         &Apache::loncommon::end_data_table_row();
                   3831:         }
                   3832:     }
                   3833:     $output .= &end_data_table();
                   3834: }
                   3835: 
1.490     raeburn  3836: sub blocking_status {
                   3837:     my ($activity,$uname,$udom) = @_;
                   3838:     my %setters;
                   3839:     my ($blocked,$output,$ownitem,$is_course);
                   3840:     my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
                   3841:     if ($startblock && $endblock) {
                   3842:         $blocked = 1;
                   3843:         if (wantarray) {
                   3844:             my $category;
                   3845:             if ($activity eq 'boards') {
                   3846:                 $category = 'Discussion posts in this course';
                   3847:             } elsif ($activity eq 'blogs') {
                   3848:                 $category = 'Blogs';
                   3849:             } elsif ($activity eq 'port') {
                   3850:                 if (defined($uname) && defined($udom)) {
                   3851:                     if ($uname eq $env{'user.name'} &&
                   3852:                         $udom eq $env{'user.domain'}) {
                   3853:                         $ownitem = 1;
                   3854:                     }
                   3855:                 }
                   3856:                 $is_course = &Apache::lonnet::is_course($udom,$uname);
                   3857:                 if ($ownitem) { 
                   3858:                     $category = 'Your portfolio files';  
                   3859:                 } elsif ($is_course) {
                   3860:                     my $coursedesc;
                   3861:                     foreach my $course (keys(%setters)) {
                   3862:                         my %courseinfo =
                   3863:                              &Apache::lonnet::coursedescription($course);
                   3864:                         $coursedesc = $courseinfo{'description'};
                   3865:                     }
1.764     weissno  3866:                     $category = "Group portfolio in the course '$coursedesc'";
1.490     raeburn  3867:                 } else {
                   3868:                     $category = 'Portfolio files belonging to ';
                   3869:                     if ($env{'user.name'} eq 'public' && 
                   3870:                         $env{'user.domain'} eq 'public') {
                   3871:                         $category .= &plainname($uname,$udom);
                   3872:                     } else {
                   3873:                         $category .= &aboutmewrapper(&plainname($uname,$udom),$uname,$udom);  
                   3874:                     }
                   3875:                 }
                   3876:             } elsif ($activity eq 'groups') {
                   3877:                 $category = 'Groups in this course';
                   3878:             }
                   3879:             my $showstart = &Apache::lonlocal::locallocaltime($startblock);
                   3880:             my $showend = &Apache::lonlocal::locallocaltime($endblock);
                   3881:             $output = '<br />'.&mt('[_1] will be inaccessible between [_2] and [_3] because communication is being blocked.',$category,$showstart,$showend).'<br />';
                   3882:             if (!($activity eq 'port' && !($ownitem) && !($is_course))) { 
                   3883:                 $output .= &build_block_table($startblock,$endblock,\%setters);
                   3884:             }
                   3885:         }
                   3886:     }
                   3887:     if (wantarray) {
                   3888:         return ($blocked,$output);
                   3889:     } else {
                   3890:         return $blocked;
                   3891:     }
                   3892: }
                   3893: 
1.60      matthew  3894: ###############################################
                   3895: 
1.682     raeburn  3896: sub check_ip_acc {
                   3897:     my ($acc)=@_;
                   3898:     &Apache::lonxml::debug("acc is $acc");
                   3899:     if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
                   3900:         return 1;
                   3901:     }
                   3902:     my $allowed=0;
                   3903:     my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
                   3904: 
                   3905:     my $name;
                   3906:     foreach my $pattern (split(',',$acc)) {
                   3907:         $pattern =~ s/^\s*//;
                   3908:         $pattern =~ s/\s*$//;
                   3909:         if ($pattern =~ /\*$/) {
                   3910:             #35.8.*
                   3911:             $pattern=~s/\*//;
                   3912:             if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
                   3913:         } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
                   3914:             #35.8.3.[34-56]
                   3915:             my $low=$2;
                   3916:             my $high=$3;
                   3917:             $pattern=$1;
                   3918:             if ($ip =~ /^\Q$pattern\E/) {
                   3919:                 my $last=(split(/\./,$ip))[3];
                   3920:                 if ($last <=$high && $last >=$low) { $allowed=1; }
                   3921:             }
                   3922:         } elsif ($pattern =~ /^\*/) {
                   3923:             #*.msu.edu
                   3924:             $pattern=~s/\*//;
                   3925:             if (!defined($name)) {
                   3926:                 use Socket;
                   3927:                 my $netaddr=inet_aton($ip);
                   3928:                 ($name)=gethostbyaddr($netaddr,AF_INET);
                   3929:             }
                   3930:             if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
                   3931:         } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
                   3932:             #127.0.0.1
                   3933:             if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
                   3934:         } else {
                   3935:             #some.name.com
                   3936:             if (!defined($name)) {
                   3937:                 use Socket;
                   3938:                 my $netaddr=inet_aton($ip);
                   3939:                 ($name)=gethostbyaddr($netaddr,AF_INET);
                   3940:             }
                   3941:             if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
                   3942:         }
                   3943:         if ($allowed) { last; }
                   3944:     }
                   3945:     return $allowed;
                   3946: }
                   3947: 
                   3948: ###############################################
                   3949: 
1.60      matthew  3950: =pod
                   3951: 
1.112     bowersj2 3952: =head1 Domain Template Functions
                   3953: 
                   3954: =over 4
                   3955: 
                   3956: =item * &determinedomain()
1.60      matthew  3957: 
                   3958: Inputs: $domain (usually will be undef)
                   3959: 
1.63      www      3960: Returns: Determines which domain should be used for designs
1.60      matthew  3961: 
                   3962: =cut
1.54      www      3963: 
1.60      matthew  3964: ###############################################
1.63      www      3965: sub determinedomain {
                   3966:     my $domain=shift;
1.531     albertel 3967:     if (! $domain) {
1.60      matthew  3968:         # Determine domain if we have not been given one
                   3969:         $domain = $Apache::lonnet::perlvar{'lonDefDomain'};
1.258     albertel 3970:         if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
                   3971:         if ($env{'request.role.domain'}) { 
                   3972:             $domain=$env{'request.role.domain'}; 
1.60      matthew  3973:         }
                   3974:     }
1.63      www      3975:     return $domain;
                   3976: }
                   3977: ###############################################
1.517     raeburn  3978: 
1.518     albertel 3979: sub devalidate_domconfig_cache {
                   3980:     my ($udom)=@_;
                   3981:     &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
                   3982: }
                   3983: 
                   3984: # ---------------------- Get domain configuration for a domain
                   3985: sub get_domainconf {
                   3986:     my ($udom) = @_;
                   3987:     my $cachetime=1800;
                   3988:     my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
                   3989:     if (defined($cached)) { return %{$result}; }
                   3990: 
                   3991:     my %domconfig = &Apache::lonnet::get_dom('configuration',
                   3992: 					     ['login','rolecolors'],$udom);
1.632     raeburn  3993:     my (%designhash,%legacy);
1.518     albertel 3994:     if (keys(%domconfig) > 0) {
                   3995:         if (ref($domconfig{'login'}) eq 'HASH') {
1.632     raeburn  3996:             if (keys(%{$domconfig{'login'}})) {
                   3997:                 foreach my $key (keys(%{$domconfig{'login'}})) {
1.699     raeburn  3998:                     if (ref($domconfig{'login'}{$key}) eq 'HASH') {
                   3999:                         foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
                   4000:                             $designhash{$udom.'.login.'.$key.'_'.$img} = 
                   4001:                                 $domconfig{'login'}{$key}{$img};
                   4002:                         }
                   4003:                     } else {
                   4004:                         $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
                   4005:                     }
1.632     raeburn  4006:                 }
                   4007:             } else {
                   4008:                 $legacy{'login'} = 1;
1.518     albertel 4009:             }
1.632     raeburn  4010:         } else {
                   4011:             $legacy{'login'} = 1;
1.518     albertel 4012:         }
                   4013:         if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632     raeburn  4014:             if (keys(%{$domconfig{'rolecolors'}})) {
                   4015:                 foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
                   4016:                     if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
                   4017:                         foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
                   4018:                             $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
                   4019:                         }
1.518     albertel 4020:                     }
                   4021:                 }
1.632     raeburn  4022:             } else {
                   4023:                 $legacy{'rolecolors'} = 1;
1.518     albertel 4024:             }
1.632     raeburn  4025:         } else {
                   4026:             $legacy{'rolecolors'} = 1;
1.518     albertel 4027:         }
1.632     raeburn  4028:         if (keys(%legacy) > 0) {
                   4029:             my %legacyhash = &get_legacy_domconf($udom);
                   4030:             foreach my $item (keys(%legacyhash)) {
                   4031:                 if ($item =~ /^\Q$udom\E\.login/) {
                   4032:                     if ($legacy{'login'}) { 
                   4033:                         $designhash{$item} = $legacyhash{$item};
                   4034:                     }
                   4035:                 } else {
                   4036:                     if ($legacy{'rolecolors'}) {
                   4037:                         $designhash{$item} = $legacyhash{$item};
                   4038:                     }
1.518     albertel 4039:                 }
                   4040:             }
                   4041:         }
1.632     raeburn  4042:     } else {
                   4043:         %designhash = &get_legacy_domconf($udom); 
1.518     albertel 4044:     }
                   4045:     &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
                   4046: 				  $cachetime);
                   4047:     return %designhash;
                   4048: }
                   4049: 
1.632     raeburn  4050: sub get_legacy_domconf {
                   4051:     my ($udom) = @_;
                   4052:     my %legacyhash;
                   4053:     my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
                   4054:     my $designfile =  $designdir.'/'.$udom.'.tab';
                   4055:     if (-e $designfile) {
                   4056:         if ( open (my $fh,"<$designfile") ) {
                   4057:             while (my $line = <$fh>) {
                   4058:                 next if ($line =~ /^\#/);
                   4059:                 chomp($line);
                   4060:                 my ($key,$val)=(split(/\=/,$line));
                   4061:                 if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
                   4062:             }
                   4063:             close($fh);
                   4064:         }
                   4065:     }
                   4066:     if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
                   4067:         $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
                   4068:     }
                   4069:     return %legacyhash;
                   4070: }
                   4071: 
1.63      www      4072: =pod
                   4073: 
1.112     bowersj2 4074: =item * &domainlogo()
1.63      www      4075: 
                   4076: Inputs: $domain (usually will be undef)
                   4077: 
                   4078: Returns: A link to a domain logo, if the domain logo exists.
                   4079: If the domain logo does not exist, a description of the domain.
                   4080: 
                   4081: =cut
1.112     bowersj2 4082: 
1.63      www      4083: ###############################################
                   4084: sub domainlogo {
1.517     raeburn  4085:     my $domain = &determinedomain(shift);
1.518     albertel 4086:     my %designhash = &get_domainconf($domain);    
1.517     raeburn  4087:     # See if there is a logo
                   4088:     if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519     raeburn  4089:         my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538     albertel 4090:         if ($imgsrc =~ m{^/(adm|res)/}) {
                   4091: 	    if ($imgsrc =~ m{^/res/}) {
                   4092: 		my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
                   4093: 		&Apache::lonnet::repcopy($local_name);
                   4094: 	    }
                   4095: 	   $imgsrc = &lonhttpdurl($imgsrc);
1.519     raeburn  4096:         } 
                   4097:         return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514     albertel 4098:     } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
                   4099:         return &Apache::lonnet::domain($domain,'description');
1.59      www      4100:     } else {
1.60      matthew  4101:         return '';
1.59      www      4102:     }
                   4103: }
1.63      www      4104: ##############################################
                   4105: 
                   4106: =pod
                   4107: 
1.112     bowersj2 4108: =item * &designparm()
1.63      www      4109: 
                   4110: Inputs: $which parameter; $domain (usually will be undef)
                   4111: 
                   4112: Returns: value of designparamter $which
                   4113: 
                   4114: =cut
1.112     bowersj2 4115: 
1.397     albertel 4116: 
1.400     albertel 4117: ##############################################
1.397     albertel 4118: sub designparm {
                   4119:     my ($which,$domain)=@_;
1.258     albertel 4120:     if ($env{'browser.blackwhite'} eq 'on') {
1.635     raeburn  4121: 	if ($which=~/\.(font|alink|vlink|link|textcol)$/) {
1.110     www      4122: 	    return '#000000';
                   4123: 	}
1.635     raeburn  4124: 	if ($which=~/\.(pgbg|sidebg|bgcol)$/) {
1.110     www      4125: 	    return '#FFFFFF';
                   4126: 	}
                   4127: 	if ($which=~/\.tabbg$/) {
                   4128: 	    return '#CCCCCC';
                   4129: 	}
                   4130:     }
1.397     albertel 4131:     if (exists($env{'environment.color.'.$which})) {
1.258     albertel 4132: 	return $env{'environment.color.'.$which};
1.96      www      4133:     }
1.63      www      4134:     $domain=&determinedomain($domain);
1.518     albertel 4135:     my %domdesign = &get_domainconf($domain);
1.520     raeburn  4136:     my $output;
1.517     raeburn  4137:     if ($domdesign{$domain.'.'.$which} ne '') {
1.520     raeburn  4138: 	$output = $domdesign{$domain.'.'.$which};
1.63      www      4139:     } else {
1.520     raeburn  4140:         $output = $defaultdesign{$which};
                   4141:     }
                   4142:     if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635     raeburn  4143:         ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538     albertel 4144:         if ($output =~ m{^/(adm|res)/}) {
                   4145: 	    if ($output =~ m{^/res/}) {
                   4146: 		my $local_name = &Apache::lonnet::filelocation('',$output);
                   4147: 		&Apache::lonnet::repcopy($local_name);
                   4148: 	    }
1.520     raeburn  4149:             $output = &lonhttpdurl($output);
                   4150:         }
1.63      www      4151:     }
1.520     raeburn  4152:     return $output;
1.63      www      4153: }
1.59      www      4154: 
1.60      matthew  4155: ###############################################
                   4156: ###############################################
                   4157: 
                   4158: =pod
                   4159: 
1.112     bowersj2 4160: =back
                   4161: 
1.549     albertel 4162: =head1 HTML Helpers
1.112     bowersj2 4163: 
                   4164: =over 4
                   4165: 
                   4166: =item * &bodytag()
1.60      matthew  4167: 
                   4168: Returns a uniform header for LON-CAPA web pages.
                   4169: 
                   4170: Inputs: 
                   4171: 
1.112     bowersj2 4172: =over 4
                   4173: 
                   4174: =item * $title, A title to be displayed on the page.
                   4175: 
                   4176: =item * $function, the current role (can be undef).
                   4177: 
                   4178: =item * $addentries, extra parameters for the <body> tag.
                   4179: 
                   4180: =item * $bodyonly, if defined, only return the <body> tag.
                   4181: 
                   4182: =item * $domain, if defined, force a given domain.
                   4183: 
                   4184: =item * $forcereg, if page should register as content page (relevant for 
1.86      www      4185:             text interface only)
1.60      matthew  4186: 
1.326     albertel 4187: =item * $customtitle, alternate text to use instead of $title
                   4188:                       in the title box that appears, this text
                   4189:                       is not auto translated like the $title is
1.309     albertel 4190: 
                   4191: =item * $notopbar, if true, keep the 'what is this' info but remove the
                   4192:                    navigational links
1.317     albertel 4193: 
1.338     albertel 4194: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
                   4195: 
                   4196: =item * $notitle, if true keep the nav controls, but remove the title bar
                   4197: 
1.361     albertel 4198: =item * $no_inline_link, if true and in remote mode, don't show the 
                   4199:          'Switch To Inline Menu' link
                   4200: 
1.460     albertel 4201: =item * $args, optional argument valid values are
                   4202:             no_auto_mt_title -> prevents &mt()ing the title arg
1.562     albertel 4203:             inherit_jsmath -> when creating popup window in a page,
                   4204:                               should it have jsmath forced on by the
                   4205:                               current page
1.460     albertel 4206: 
1.112     bowersj2 4207: =back
                   4208: 
1.60      matthew  4209: Returns: A uniform header for LON-CAPA web pages.  
                   4210: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
                   4211: If $bodyonly is undef or zero, an html string containing a <body> tag and 
                   4212: other decorations will be returned.
                   4213: 
                   4214: =cut
                   4215: 
1.54      www      4216: sub bodytag {
1.309     albertel 4217:     my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,$customtitle,
1.460     albertel 4218: 	$notopbar,$bgcolor,$notitle,$no_inline_link,$args)=@_;
1.339     albertel 4219: 
1.460     albertel 4220:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339     albertel 4221: 
1.183     matthew  4222:     $function = &get_users_function() if (!$function);
1.339     albertel 4223:     my $img =    &designparm($function.'.img',$domain);
                   4224:     my $font =   &designparm($function.'.font',$domain);
                   4225:     my $pgbg   = $bgcolor || &designparm($function.'.pgbg',$domain);
                   4226: 
                   4227:     my %design = ( 'style'   => 'margin-top: 0px',
1.535     albertel 4228: 		   'bgcolor' => $pgbg,
1.339     albertel 4229: 		   'text'    => $font,
                   4230:                    'alink'   => &designparm($function.'.alink',$domain),
                   4231: 		   'vlink'   => &designparm($function.'.vlink',$domain),
                   4232: 		   'link'    => &designparm($function.'.link',$domain),);
1.438     albertel 4233:     @design{keys(%$addentries)} = @$addentries{keys(%$addentries)}; 
1.339     albertel 4234: 
1.63      www      4235:  # role and realm
1.378     raeburn  4236:     my ($role,$realm) = split(/\./,$env{'request.role'},2);
                   4237:     if ($role  eq 'ca') {
1.479     albertel 4238:         my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500     albertel 4239:         $realm = &plainname($rname,$rdom);
1.378     raeburn  4240:     } 
1.55      www      4241: # realm
1.258     albertel 4242:     if ($env{'request.course.id'}) {
1.378     raeburn  4243:         if ($env{'request.role'} !~ /^cr/) {
                   4244:             $role = &Apache::lonnet::plaintext($role,&course_type());
                   4245:         }
1.359     albertel 4246: 	$realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378     raeburn  4247:     } else {
                   4248:         $role = &Apache::lonnet::plaintext($role);
1.54      www      4249:     }
1.433     albertel 4250: 
1.359     albertel 4251:     if (!$realm) { $realm='&nbsp;'; }
1.55      www      4252: # Set messages
1.60      matthew  4253:     my $messages=&domainlogo($domain);
1.330     albertel 4254: 
1.438     albertel 4255:     my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329     albertel 4256: 
1.101     www      4257: # construct main body tag
1.359     albertel 4258:     my $bodytag = "<body $extra_body_attr>".
1.562     albertel 4259: 	&Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252     albertel 4260: 
1.530     albertel 4261:     if ($bodyonly) {
1.60      matthew  4262:         return $bodytag;
1.258     albertel 4263:     } elsif ($env{'browser.interface'} eq 'textual') {
1.95      www      4264: # Accessibility
1.224     raeburn  4265:           
1.337     albertel 4266: 	$bodytag.=&Apache::lonmenu::menubuttons($forcereg,$forcereg);
1.338     albertel 4267: 	if (!$notitle) {
1.337     albertel 4268: 	    $bodytag.='<h1>LON-CAPA: '.$title.'</h1>';
                   4269: 	}
                   4270: 	return $bodytag;
1.359     albertel 4271:     }
                   4272: 
1.410     albertel 4273:     my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.433     albertel 4274:     if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
                   4275: 	undef($role);
1.434     albertel 4276:     } else {
                   4277: 	$name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433     albertel 4278:     }
1.359     albertel 4279:     
                   4280:     my $roleinfo=(<<ENDROLE);
                   4281: <td class="LC_title_bar_who">
                   4282: <div class="LC_title_bar_name">
1.410     albertel 4283:     $name
1.361     albertel 4284:     &nbsp;
1.359     albertel 4285: </div>
                   4286: <div class="LC_title_bar_role">
1.361     albertel 4287: $role&nbsp;
1.359     albertel 4288: </div>
                   4289: <div class="LC_title_bar_realm">
1.361     albertel 4290: $realm&nbsp;
1.359     albertel 4291: </div>
1.206     albertel 4292: </td>
                   4293: ENDROLE
1.235     raeburn  4294: 
1.762     bisitz   4295:     my $titleinfo = '<h1>'.$title.'</h1>';
1.359     albertel 4296:     if ($customtitle) {
                   4297:         $titleinfo = $customtitle;
                   4298:     }
                   4299:     #
                   4300:     # Extra info if you are the DC
                   4301:     my $dc_info = '';
                   4302:     if ($env{'user.adv'} && exists($env{'user.role.dc./'.
                   4303:                         $env{'course.'.$env{'request.course.id'}.
                   4304:                                  '.domain'}.'/'})) {
                   4305:         my $cid = $env{'request.course.id'};
                   4306:         $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380     www      4307:         $dc_info =~ s/\s+$//;
1.359     albertel 4308:         $dc_info = '('.$dc_info.')';
                   4309:     }
                   4310: 
1.644     www      4311:     if (($env{'environment.remote'} eq 'off') || ($args->{'suppress_header_logos'})) {
1.359     albertel 4312:         # No Remote
1.258     albertel 4313: 	if ($env{'request.state'} eq 'construct') {
1.359     albertel 4314: 	    $forcereg=1;
                   4315: 	}
                   4316: 
                   4317: 	if (!$customtitle && $env{'request.state'} eq 'construct') {
                   4318: 	    # this is for resources; directories have customtitle, and crumbs
                   4319:             # and select recent are created in lonpubdir.pm  
1.229     albertel 4320: 	    my ($uname,$thisdisfn)=
1.258     albertel 4321: 		($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
1.229     albertel 4322: 	    my $formaction='/priv/'.$uname.'/'.$thisdisfn;
                   4323: 	    $formaction=~s/\/+/\//g;
                   4324: 
1.359     albertel 4325: 	    my $parentpath = '';
                   4326: 	    my $lastitem = '';
                   4327: 	    if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
                   4328: 		$parentpath = $1;
                   4329: 		$lastitem = $2;
                   4330: 	    } else {
                   4331: 		$lastitem = $thisdisfn;
                   4332: 	    }
                   4333: 	    $titleinfo = 
1.640     bisitz   4334: 		&Apache::loncommon::help_open_menu('','',3,'Authoring')
                   4335: 		.'<b>'.&mt('Construction Space').'</b>:&nbsp;'
                   4336: 		.'<form name="dirs" method="post" action="'.$formaction
1.359     albertel 4337: 		.'" target="_top"><tt><b>'
1.705     tempelho 4338: 		.&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."<span class=\"LC_fontsize_big\">$lastitem</span></b></tt><br />"
1.359     albertel 4339: 		.&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
                   4340: 		.'</form>'
                   4341: 		.&Apache::lonmenu::constspaceform();
1.235     raeburn  4342:         }
1.359     albertel 4343: 
1.337     albertel 4344:         my $titletable;
1.338     albertel 4345: 	if (!$notitle) {
1.337     albertel 4346: 	    $titletable =
1.359     albertel 4347: 		'<table id="LC_title_bar">'.
                   4348:                          "<tr><td> $titleinfo $dc_info</td>".$roleinfo.
                   4349: 			 '</tr></table>';
1.337     albertel 4350: 	}
1.359     albertel 4351: 	if ($notopbar) {
                   4352: 	    $bodytag .= $titletable;
                   4353: 	} else {
                   4354: 	    if ($env{'request.state'} eq 'construct') {
1.337     albertel 4355:                 $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg,
                   4356: 							  $titletable);
1.272     raeburn  4357:             } else {
1.336     albertel 4358:                 $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg).
1.359     albertel 4359: 		    $titletable;
1.272     raeburn  4360:             }
1.235     raeburn  4361:         }
                   4362:         return $bodytag;
1.94      www      4363:     }
1.95      www      4364: 
1.93      www      4365: #
1.95      www      4366: # Top frame rendering, Remote is up
1.93      www      4367: #
1.359     albertel 4368: 
1.517     raeburn  4369:     my $imgsrc = $img;
                   4370:     if ($img =~ /^\/adm/) {
1.575     albertel 4371:         $imgsrc = &lonhttpdurl($img);
1.517     raeburn  4372:     }
                   4373:     my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359     albertel 4374: 
1.305     www      4375:     # Explicit link to get inline menu
1.361     albertel 4376:     my $menu= ($no_inline_link?''
                   4377: 	       :'<br /><a href="/adm/remote?action=collapse">'.&mt('Switch to Inline Menu Mode').'</a>');
1.245     matthew  4378:     #
1.338     albertel 4379:     if ($notitle) {
1.337     albertel 4380: 	return $bodytag;
                   4381:     }
1.94      www      4382:     return(<<ENDBODY);
1.60      matthew  4383: $bodytag
1.359     albertel 4384: <table id="LC_title_bar" class="LC_with_remote">
1.791     tempelho 4385: <tr><td>$upperleft</td>
                   4386:     <td>$messages&nbsp;</td>
1.54      www      4387: </tr>
1.359     albertel 4388: <tr><td>$titleinfo $dc_info $menu</td>
                   4389: $roleinfo
1.368     albertel 4390: </tr>
1.356     albertel 4391: </table>
1.54      www      4392: ENDBODY
1.182     matthew  4393: }
                   4394: 
1.330     albertel 4395: sub make_attr_string {
                   4396:     my ($register,$attr_ref) = @_;
                   4397: 
                   4398:     if ($attr_ref && !ref($attr_ref)) {
                   4399: 	die("addentries Must be a hash ref ".
                   4400: 	    join(':',caller(1))." ".
                   4401: 	    join(':',caller(0))." ");
                   4402:     }
                   4403: 
                   4404:     if ($register) {
1.339     albertel 4405: 	my ($on_load,$on_unload);
                   4406: 	foreach my $key (keys(%{$attr_ref})) {
                   4407: 	    if      (lc($key) eq 'onload') {
                   4408: 		$on_load.=$attr_ref->{$key}.';';
                   4409: 		delete($attr_ref->{$key});
                   4410: 
                   4411: 	    } elsif (lc($key) eq 'onunload') {
                   4412: 		$on_unload.=$attr_ref->{$key}.';';
                   4413: 		delete($attr_ref->{$key});
                   4414: 	    }
                   4415: 	}
                   4416: 	$attr_ref->{'onload'}  =
                   4417: 	    &Apache::lonmenu::loadevents().  $on_load;
                   4418: 	$attr_ref->{'onunload'}=
                   4419: 	    &Apache::lonmenu::unloadevents().$on_unload;
                   4420:     }
                   4421: 
                   4422: # Accessibility font enhance
                   4423:     if ($env{'browser.fontenhance'} eq 'on') {
                   4424: 	my $style;
                   4425: 	foreach my $key (keys(%{$attr_ref})) {
                   4426: 	    if (lc($key) eq 'style') {
                   4427: 		$style.=$attr_ref->{$key}.';';
                   4428: 		delete($attr_ref->{$key});
                   4429: 	    }
                   4430: 	}
                   4431: 	$attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330     albertel 4432:     }
1.339     albertel 4433: 
                   4434:     if ($env{'browser.blackwhite'} eq 'on') {
                   4435: 	delete($attr_ref->{'font'});
                   4436: 	delete($attr_ref->{'link'});
                   4437: 	delete($attr_ref->{'alink'});
                   4438: 	delete($attr_ref->{'vlink'});
                   4439: 	delete($attr_ref->{'bgcolor'});
                   4440: 	delete($attr_ref->{'background'});
                   4441:     }
                   4442: 
1.330     albertel 4443:     my $attr_string;
                   4444:     foreach my $attr (keys(%$attr_ref)) {
                   4445: 	$attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
                   4446:     }
                   4447:     return $attr_string;
                   4448: }
                   4449: 
                   4450: 
1.182     matthew  4451: ###############################################
1.251     albertel 4452: ###############################################
                   4453: 
                   4454: =pod
                   4455: 
                   4456: =item * &endbodytag()
                   4457: 
                   4458: Returns a uniform footer for LON-CAPA web pages.
                   4459: 
1.635     raeburn  4460: Inputs: 1 - optional reference to an args hash
                   4461: If in the hash, key for noredirectlink has a value which evaluates to true,
                   4462: a 'Continue' link is not displayed if the page contains an
                   4463: internal redirect in the <head></head> section,
                   4464: i.e., $env{'internal.head.redirect'} exists   
1.251     albertel 4465: 
                   4466: =cut
                   4467: 
                   4468: sub endbodytag {
1.635     raeburn  4469:     my ($args) = @_;
1.251     albertel 4470:     my $endbodytag='</body>';
1.269     albertel 4471:     $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315     albertel 4472:     if ( exists( $env{'internal.head.redirect'} ) ) {
1.635     raeburn  4473:         if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
                   4474: 	    $endbodytag=
                   4475: 	        "<br /><a href=\"$env{'internal.head.redirect'}\">".
                   4476: 	        &mt('Continue').'</a>'.
                   4477: 	        $endbodytag;
                   4478:         }
1.315     albertel 4479:     }
1.251     albertel 4480:     return $endbodytag;
                   4481: }
                   4482: 
1.352     albertel 4483: =pod
                   4484: 
                   4485: =item * &standard_css()
                   4486: 
                   4487: Returns a style sheet
                   4488: 
                   4489: Inputs: (all optional)
                   4490:             domain         -> force to color decorate a page for a specific
                   4491:                                domain
                   4492:             function       -> force usage of a specific rolish color scheme
                   4493:             bgcolor        -> override the default page bgcolor
                   4494: 
                   4495: =cut
                   4496: 
1.343     albertel 4497: sub standard_css {
1.345     albertel 4498:     my ($function,$domain,$bgcolor) = @_;
1.352     albertel 4499:     $function  = &get_users_function() if (!$function);
                   4500:     my $img    = &designparm($function.'.img',   $domain);
                   4501:     my $tabbg  = &designparm($function.'.tabbg', $domain);
                   4502:     my $font   = &designparm($function.'.font',  $domain);
1.791     tempelho 4503: #second colour for later usage
1.345     albertel 4504:     my $sidebg = &designparm($function.'.sidebg',$domain);
1.382     albertel 4505:     my $pgbg_or_bgcolor =
                   4506: 	         $bgcolor ||
1.352     albertel 4507: 	         &designparm($function.'.pgbg',  $domain);
1.382     albertel 4508:     my $pgbg   = &designparm($function.'.pgbg',  $domain);
1.352     albertel 4509:     my $alink  = &designparm($function.'.alink', $domain);
                   4510:     my $vlink  = &designparm($function.'.vlink', $domain);
                   4511:     my $link   = &designparm($function.'.link',  $domain);
                   4512: 
1.704     muellerd 4513:     my $loginbg = &designparm('login.sidebg',$domain);
1.712     muellerd 4514:     my $bgcol = &designparm('login.bgcol',$domain);
                   4515:     my $textcol = &designparm('login.textcol',$domain);
1.704     muellerd 4516: 
1.602     albertel 4517:     my $sans                 = 'Verdana,Arial,Helvetica,sans-serif';
1.395     albertel 4518:     my $mono                 = 'monospace';
1.352     albertel 4519:     my $data_table_head      = $tabbg;
                   4520:     my $data_table_light     = '#EEEEEE';
1.470     banghart 4521:     my $data_table_dark      = '#DDDDDD';
                   4522:     my $data_table_darker    = '#CCCCCC';
1.349     albertel 4523:     my $data_table_highlight = '#FFFF00';
1.352     albertel 4524:     my $mail_new             = '#FFBB77';
                   4525:     my $mail_new_hover       = '#DD9955';
                   4526:     my $mail_read            = '#BBBB77';
                   4527:     my $mail_read_hover      = '#999944';
                   4528:     my $mail_replied         = '#AAAA88';
                   4529:     my $mail_replied_hover   = '#888855';
                   4530:     my $mail_other           = '#99BBBB';
                   4531:     my $mail_other_hover     = '#669999';
1.391     albertel 4532:     my $table_header         = '#DDDDDD';
1.489     raeburn  4533:     my $feedback_link_bg     = '#BBBBBB';
1.701     harmsja  4534:     my $lg_border_color	     = '#C8C8C8';
1.392     albertel 4535: 
1.608     albertel 4536:     my $border = ($env{'browser.type'} eq 'explorer' ||
                   4537: 		  $env{'browser.type'} eq 'safari'     ) ? '0px 2px 0px 2px'
                   4538: 	                                                 : '0px 3px 0px 4px';
1.448     albertel 4539: 
1.523     albertel 4540: 
1.343     albertel 4541:     return <<END;
1.698     harmsja  4542: body{
                   4543:      font-family: $sans;
                   4544:      line-height:130%;
1.701     harmsja  4545:      font-size:0.83em;
1.698     harmsja  4546:      color:$font;
                   4547:   }
1.701     harmsja  4548: a:link, a:visited { font-size:100%; }
1.698     harmsja  4549: 
1.779     bisitz   4550: a:focus { color: red; background: yellow }
1.510     albertel 4551: table.thinborder,
                   4552: table.thinborder tr th {
                   4553:   border-style: solid;
                   4554:   border-width: 1px;
1.698     harmsja  4555:   border-color: $lg_border_color;
1.510     albertel 4556:   background: $tabbg;
                   4557: }
1.523     albertel 4558: table.thinborder tr td {
1.510     albertel 4559:   border-style: solid;
1.698     harmsja  4560:   border-width: 1px;
                   4561:   border-color: $lg_border_color;
1.510     albertel 4562: }
1.426     albertel 4563: 
1.343     albertel 4564: form, .inline { display: inline; }
1.721     harmsja  4565: 
                   4566: .LC_right {text-align:right;}
                   4567: .LC_middle {vertical-align:middle;}
                   4568: 
                   4569: /* just for tests */
1.754     droeschl 4570: .LC_400Box {width:400px; }
1.721     harmsja  4571: /* end */
                   4572: 
1.778     bisitz   4573: .LC_filename {
                   4574:   font-family: $mono;
                   4575:   white-space:pre;
                   4576: }
                   4577: 
                   4578: .LC_fileicon {
                   4579:   border: none;
                   4580:   height: 1.3em;
                   4581:   vertical-align: text-bottom;
                   4582:   margin-right: 0.3em;
                   4583:   text-decoration:none;
                   4584: }
                   4585: 
1.350     albertel 4586: .LC_error {
                   4587:   color: red;
                   4588:   font-size: larger;
                   4589: }
1.457     albertel 4590: .LC_warning,
                   4591: .LC_diff_removed {
1.733     bisitz   4592:   color: red;
1.394     albertel 4593: }
1.532     albertel 4594: 
                   4595: .LC_info,
1.457     albertel 4596: .LC_success,
                   4597: .LC_diff_added {
1.350     albertel 4598:   color: green;
                   4599: }
1.543     albertel 4600: .LC_unknown {
                   4601:   color: yellow;
                   4602: }
                   4603: 
1.440     albertel 4604: .LC_icon {
1.771     droeschl 4605:   border: none;
1.790     droeschl 4606:   vertical-align: middle;
1.771     droeschl 4607: }
                   4608: 
1.539     albertel 4609: .LC_indexer_icon {
                   4610:   border: 0px;
                   4611:   height: 22px;
                   4612: }
1.543     albertel 4613: .LC_docs_spacer {
                   4614:   width: 25px;
                   4615:   height: 1px;
1.771     droeschl 4616:   border: none;
1.543     albertel 4617: }
1.346     albertel 4618: 
1.532     albertel 4619: .LC_internal_info {
1.735     bisitz   4620:   color: #999999;
1.532     albertel 4621: }
                   4622: 
1.458     albertel 4623: table.LC_pastsubmission {
                   4624:   border: 1px solid black;
                   4625:   margin: 2px;
                   4626: }
                   4627: 
1.606     albertel 4628: table#LC_top_nav, table#LC_menubuttons,table#LC_nav_location {
1.345     albertel 4629:   width: 100%;
                   4630:   background: $pgbg;
1.392     albertel 4631:   border: 2px;
1.402     albertel 4632:   border-collapse: separate;
1.403     albertel 4633:   padding: 0px;
1.345     albertel 4634: }
1.392     albertel 4635: 
1.779     bisitz   4636: table#LC_title_bar, table.LC_breadcrumbs,
1.393     albertel 4637: table#LC_title_bar.LC_with_remote {
1.359     albertel 4638:   width: 100%;
1.392     albertel 4639:   border-color: $pgbg;
                   4640:   border-style: solid;
                   4641:   border-width: $border;
                   4642: 
1.379     albertel 4643:   background: $pgbg;
                   4644:   font-family: $sans;
1.392     albertel 4645:   border-collapse: collapse;
1.403     albertel 4646:   padding: 0px;
1.359     albertel 4647: }
1.409     albertel 4648: table.LC_docs_path {
                   4649:   width: 100%;
                   4650:   border: 0;
                   4651:   background: $pgbg;
                   4652:   font-family: $sans;
                   4653:   border-collapse: collapse;
                   4654:   padding: 0px;
                   4655: }
                   4656: 
1.359     albertel 4657: table#LC_title_bar td {
                   4658:   background: $tabbg;
                   4659: }
1.773     ehlerst  4660: table#LC_title_bar .LC_title_bar_who {
1.359     albertel 4661:   background: $tabbg;
                   4662:   color: $font;
1.427     albertel 4663:   font: small $sans;
1.359     albertel 4664:   text-align: right;
1.773     ehlerst  4665:   margin: 0px;
                   4666: }
                   4667: table#LC_title_bar .LC_title_bar_name {
                   4668:   margin: 0px;
                   4669: }
                   4670: table#LC_title_bar .LC_title_bar_role {
                   4671:   margin: 0px;
                   4672: }
1.775     bisitz   4673: table#LC_title_bar .LC_title_bar_realm {
1.773     ehlerst  4674:   margin: 0px;
1.359     albertel 4675: }
1.469     banghart 4676: span.LC_metadata {
                   4677:     font-family: $sans;
                   4678: }
1.359     albertel 4679: 
1.706     harmsja  4680: table#LC_menubuttons img{
1.346     albertel 4681:   border: 0px;
                   4682: }
1.345     albertel 4683: table#LC_top_nav td {
                   4684:   background: $tabbg;
1.392     albertel 4685:   border: 0px;
1.407     albertel 4686:   font-size: small;
1.706     harmsja  4687:   vertical-align:top;
                   4688:   padding:2px 5px 2px 5px;
1.345     albertel 4689: }
                   4690: table#LC_top_nav td a, div#LC_top_nav a {
                   4691:   color: $font;
                   4692:   font-family: $sans;
                   4693: }
1.364     albertel 4694: table#LC_top_nav td.LC_top_nav_logo {
                   4695:   background: $tabbg;
1.432     albertel 4696:   text-align: left;
1.408     albertel 4697:   white-space: nowrap;
1.432     albertel 4698:   width: 31px;
1.408     albertel 4699: }
                   4700: table#LC_top_nav td.LC_top_nav_logo img {
1.432     albertel 4701:   border: 0px;
1.408     albertel 4702:   vertical-align: bottom;
1.364     albertel 4703: }
1.777     tempelho 4704: table#LC_top_nav td.LC_top_nav_exit,
1.779     bisitz   4705: table#LC_top_nav td.LC_top_nav_help {
1.777     tempelho 4706:   width: 2.0em;
                   4707: }
1.442     albertel 4708: table#LC_top_nav td.LC_top_nav_login {
                   4709:   width: 4.0em;
                   4710:   text-align: center;
                   4711: }
1.409     albertel 4712: table.LC_breadcrumbs td, table.LC_docs_path td  {
1.357     albertel 4713:   background: $tabbg;
                   4714:   color: $font;
                   4715:   font-family: $sans;
1.358     albertel 4716:   font-size: smaller;
1.357     albertel 4717: }
1.777     tempelho 4718: table.LC_breadcrumbs td.LC_breadcrumbs_component,
                   4719: table.LC_docs_path td.LC_docs_path_component {
1.779     bisitz   4720:   background: $tabbg;
1.777     tempelho 4721:   color: $font;
                   4722:   font-family: $sans;
1.779     bisitz   4723:   font-size: larger;
                   4724:   text-align: right;
1.777     tempelho 4725: }
1.383     albertel 4726: td.LC_table_cell_checkbox {
                   4727:   text-align: center;
                   4728: }
1.779     bisitz   4729: table#LC_mainmenu td.LC_mainmenu_column {
                   4730:     vertical-align: top;
1.777     tempelho 4731: }
1.522     albertel 4732: 
1.705     tempelho 4733: .LC_fontsize_small
                   4734: {
                   4735:  font-size: 70%;
                   4736: }
                   4737: 
                   4738: .LC_fontsize_medium
                   4739: {
                   4740:  font-size: 85%;
                   4741: }
                   4742: 
                   4743: .LC_fontsize_large
                   4744: {
                   4745:  font-size: 120%;
                   4746: }
                   4747: 
1.346     albertel 4748: .LC_menubuttons_inline_text {
                   4749:   color: $font;
                   4750:   font-family: $sans;
1.698     harmsja  4751:   font-size: 90%;
1.701     harmsja  4752:   padding-left:3px;
1.346     albertel 4753: }
                   4754: 
1.526     www      4755: .LC_menubuttons_link {
                   4756:   text-decoration: none;
                   4757: }
1.698     harmsja  4758: /*2008--9-5: new menu style sheet.Changed category*/
1.522     albertel 4759: .LC_menubuttons_category {
1.521     www      4760:   color: $font;
1.526     www      4761:   background: $pgbg;
1.521     www      4762:   font-family: $sans;
                   4763:   font-size: larger;
                   4764:   font-weight: bold;
                   4765: }
                   4766: 
1.346     albertel 4767: td.LC_menubuttons_text {
1.779     bisitz   4768:  	color: $font;
1.346     albertel 4769: }
1.706     harmsja  4770: 
                   4771: 
1.526     www      4772: 
1.346     albertel 4773: .LC_current_location {
                   4774:   font-family: $sans;
                   4775:   background: $tabbg;
                   4776: }
                   4777: .LC_new_mail {
                   4778:   font-family: $sans;
1.634     www      4779:   background: $tabbg;
1.346     albertel 4780:   font-weight: bold;
                   4781: }
1.347     albertel 4782: 
1.526     www      4783: 
1.527     www      4784: .LC_dropadd_labeltext {
                   4785:   font-family: $sans;
                   4786:   text-align: right;
                   4787: }
                   4788: 
                   4789: .LC_preferences_labeltext {
                   4790:   font-family: $sans;
                   4791:   text-align: right;
                   4792: }
                   4793: 
1.666     raeburn  4794: .LC_roleslog_note {
1.701     harmsja  4795:   font-size: small;
1.666     raeburn  4796: }
                   4797: 
1.715     raeburn  4798: .LC_mail_functions {
                   4799:     font-weight: bold;
                   4800: }
                   4801: 
1.440     albertel 4802: table.LC_aboutme_port {
                   4803:   border: 0px;
                   4804:   border-collapse: collapse;
                   4805:   border-spacing: 0px;
                   4806: }
1.349     albertel 4807: table.LC_data_table, table.LC_mail_list {
1.347     albertel 4808:   border: 1px solid #000000;
1.402     albertel 4809:   border-collapse: separate;
1.426     albertel 4810:   border-spacing: 1px;
1.610     albertel 4811:   background: $pgbg;
1.347     albertel 4812: }
1.422     albertel 4813: .LC_data_table_dense {
                   4814:   font-size: small;
                   4815: }
1.507     raeburn  4816: table.LC_nested_outer {
                   4817:   border: 1px solid #000000;
1.589     raeburn  4818:   border-collapse: collapse;
1.507     raeburn  4819:   border-spacing: 0px;
                   4820:   width: 100%;
                   4821: }
                   4822: table.LC_nested {
                   4823:   border: 0px;
1.589     raeburn  4824:   border-collapse: collapse;
1.507     raeburn  4825:   border-spacing: 0px;
                   4826:   width: 100%;
                   4827: }
1.523     albertel 4828: table.LC_data_table tr th, table.LC_calendar tr th, table.LC_mail_list tr th,
                   4829: table.LC_prior_tries tr th {
1.349     albertel 4830:   font-weight: bold;
                   4831:   background-color: $data_table_head;
1.701     harmsja  4832:   font-size:90%;
1.347     albertel 4833: }
1.711     raeburn  4834: table.LC_data_table tr.LC_info_row > td {
1.735     bisitz   4835:   background-color: #CCCCCC;
1.711     raeburn  4836:   font-weight: bold;
                   4837:   text-align: left;
                   4838: }
1.779     bisitz   4839: table.LC_data_table tr.LC_odd_row > td,
1.709     bisitz   4840: table.LC_pick_box tr > td.LC_odd_row,
1.440     albertel 4841: table.LC_aboutme_port tr td {
1.349     albertel 4842:   background-color: $data_table_light;
1.425     albertel 4843:   padding: 2px;
1.347     albertel 4844: }
1.610     albertel 4845: table.LC_data_table tr.LC_even_row > td,
1.709     bisitz   4846: table.LC_pick_box tr > td.LC_even_row,
1.440     albertel 4847: table.LC_aboutme_port tr.LC_even_row td {
1.349     albertel 4848:   background-color: $data_table_dark;
1.709     bisitz   4849:   padding: 2px;
1.347     albertel 4850: }
1.425     albertel 4851: table.LC_data_table tr.LC_data_table_highlight td {
                   4852:   background-color: $data_table_darker;
                   4853: }
1.639     raeburn  4854: table.LC_data_table tr td.LC_leftcol_header {
                   4855:   background-color: $data_table_head;
                   4856:   font-weight: bold;
                   4857: }
1.451     albertel 4858: table.LC_data_table tr.LC_empty_row td,
1.507     raeburn  4859: table.LC_nested tr.LC_empty_row td {
1.347     albertel 4860:   background-color: #FFFFFF;
1.421     albertel 4861:   font-weight: bold;
                   4862:   font-style: italic;
                   4863:   text-align: center;
                   4864:   padding: 8px;
1.347     albertel 4865: }
1.507     raeburn  4866: table.LC_nested tr.LC_empty_row td {
1.465     albertel 4867:   padding: 4ex
                   4868: }
1.507     raeburn  4869: table.LC_nested_outer tr th {
                   4870:   font-weight: bold;
                   4871:   background-color: $data_table_head;
1.701     harmsja  4872:   font-size: small;
1.507     raeburn  4873:   border-bottom: 1px solid #000000;
                   4874: }
                   4875: table.LC_nested_outer tr td.LC_subheader {
                   4876:   background-color: $data_table_head;
                   4877:   font-weight: bold;
                   4878:   font-size: small;
                   4879:   border-bottom: 1px solid #000000;
                   4880:   text-align: right;
1.451     albertel 4881: }
1.507     raeburn  4882: table.LC_nested tr.LC_info_row td {
1.735     bisitz   4883:   background-color: #CCCCCC;
1.451     albertel 4884:   font-weight: bold;
                   4885:   font-size: small;
1.507     raeburn  4886:   text-align: center;
                   4887: }
1.589     raeburn  4888: table.LC_nested tr.LC_info_row td.LC_left_item,
                   4889: table.LC_nested_outer tr th.LC_left_item {
1.507     raeburn  4890:   text-align: left;
1.451     albertel 4891: }
1.507     raeburn  4892: table.LC_nested td {
1.735     bisitz   4893:   background-color: #FFFFFF;
1.451     albertel 4894:   font-size: small;
1.507     raeburn  4895: }
                   4896: table.LC_nested_outer tr th.LC_right_item,
                   4897: table.LC_nested tr.LC_info_row td.LC_right_item,
                   4898: table.LC_nested tr.LC_odd_row td.LC_right_item,
                   4899: table.LC_nested tr td.LC_right_item {
1.451     albertel 4900:   text-align: right;
                   4901: }
                   4902: 
1.507     raeburn  4903: table.LC_nested tr.LC_odd_row td {
1.735     bisitz   4904:   background-color: #EEEEEE;
1.451     albertel 4905: }
                   4906: 
1.473     raeburn  4907: table.LC_createuser {
                   4908: }
                   4909: 
                   4910: table.LC_createuser tr.LC_section_row td {
1.701     harmsja  4911:   font-size: small;
1.473     raeburn  4912: }
                   4913: 
                   4914: table.LC_createuser tr.LC_info_row td  {
1.735     bisitz   4915:   background-color: #CCCCCC;
1.473     raeburn  4916:   font-weight: bold;
                   4917:   text-align: center;
                   4918: }
                   4919: 
1.349     albertel 4920: table.LC_calendar {
                   4921:   border: 1px solid #000000;
                   4922:   border-collapse: collapse;
                   4923: }
                   4924: table.LC_calendar_pickdate {
                   4925:   font-size: xx-small;
                   4926: }
                   4927: table.LC_calendar tr td {
                   4928:   border: 1px solid #000000;
                   4929:   vertical-align: top;
                   4930: }
                   4931: table.LC_calendar tr td.LC_calendar_day_empty {
                   4932:   background-color: $data_table_dark;
                   4933: }
1.779     bisitz   4934: table.LC_calendar tr td.LC_calendar_day_current {
                   4935:   background-color: $data_table_highlight;
1.777     tempelho 4936: }
1.349     albertel 4937: table.LC_mail_list tr.LC_mail_new {
                   4938:   background-color: $mail_new;
                   4939: }
                   4940: table.LC_mail_list tr.LC_mail_new:hover {
                   4941:   background-color: $mail_new_hover;
                   4942: }
1.777     tempelho 4943: table.LC_mail_list tr.LC_mail_even{
                   4944: }
                   4945: table.LC_mail_list tr.LC_mail_odd{
                   4946: }
1.349     albertel 4947: table.LC_mail_list tr.LC_mail_read {
                   4948:   background-color: $mail_read;
                   4949: }
                   4950: table.LC_mail_list tr.LC_mail_read:hover {
                   4951:   background-color: $mail_read_hover;
                   4952: }
                   4953: table.LC_mail_list tr.LC_mail_replied {
                   4954:   background-color: $mail_replied;
                   4955: }
                   4956: table.LC_mail_list tr.LC_mail_replied:hover {
                   4957:   background-color: $mail_replied_hover;
                   4958: }
                   4959: table.LC_mail_list tr.LC_mail_other {
                   4960:   background-color: $mail_other;
                   4961: }
                   4962: table.LC_mail_list tr.LC_mail_other:hover {
                   4963:   background-color: $mail_other_hover;
                   4964: }
1.494     raeburn  4965: 
1.777     tempelho 4966: table.LC_data_table tr > td.LC_browser_file,
                   4967: table.LC_data_table tr > td.LC_browser_file_published {
1.389     albertel 4968:   background: #CCFF88;
                   4969: }
1.777     tempelho 4970: table.LC_data_table tr > td.LC_browser_file_locked,
                   4971: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389     albertel 4972:   background: #FFAA99;
1.387     albertel 4973: }
1.777     tempelho 4974: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.779     bisitz   4975:   background: #AAAAAA;
                   4976: }
1.777     tempelho 4977: table.LC_data_table tr > td.LC_browser_file_modified,
1.779     bisitz   4978: table.LC_data_table tr > td.LC_browser_file_metamodified {
                   4979:   background: #FFFF77;
1.777     tempelho 4980: }
1.696     bisitz   4981: table.LC_data_table tr.LC_browser_folder > td {
1.389     albertel 4982:   background: #CCCCFF;
1.387     albertel 4983: }
1.696     bisitz   4984: 
1.707     bisitz   4985: table.LC_data_table tr > td.LC_roles_is {
                   4986: /*  background: #77FF77; */
                   4987: }
                   4988: table.LC_data_table tr > td.LC_roles_future {
                   4989:   background: #FFFF77;
                   4990: }
                   4991: table.LC_data_table tr > td.LC_roles_will {
                   4992:   background: #FFAA77;
                   4993: }
                   4994: table.LC_data_table tr > td.LC_roles_expired {
                   4995:   background: #FF7777;
                   4996: }
                   4997: table.LC_data_table tr > td.LC_roles_will_not {
                   4998:   background: #AAFF77;
                   4999: }
                   5000: table.LC_data_table tr > td.LC_roles_selected {
                   5001:   background: #11CC55;
                   5002: }
                   5003: 
1.388     albertel 5004: span.LC_current_location {
1.701     harmsja  5005:   font-size:larger;
1.388     albertel 5006:   background: $pgbg;
                   5007: }
1.387     albertel 5008: 
1.395     albertel 5009: span.LC_parm_menu_item {
                   5010:   font-size: larger;
                   5011:   font-family: $sans;
                   5012: }
                   5013: span.LC_parm_scope_all {
                   5014:   color: red;
                   5015: }
                   5016: span.LC_parm_scope_folder {
                   5017:   color: green;
                   5018: }
                   5019: span.LC_parm_scope_resource {
                   5020:   color: orange;
                   5021: }
                   5022: span.LC_parm_part {
                   5023:   color: blue;
                   5024: }
                   5025: span.LC_parm_folder, span.LC_parm_symb {
                   5026:   font-size: x-small;
                   5027:   font-family: $mono;
                   5028:   color: #AAAAAA;
                   5029: }
                   5030: 
1.396     albertel 5031: td.LC_parm_overview_level_menu, td.LC_parm_overview_map_menu,
1.777     tempelho 5032: td.LC_parm_overview_parm_selectors,td.LC_parm_overview_restrictions  {
1.396     albertel 5033:   border: 1px solid black;
                   5034:   border-collapse: collapse;
                   5035: }
                   5036: table.LC_parm_overview_restrictions td {
                   5037:   border-width: 1px 4px 1px 4px;
                   5038:   border-style: solid;
                   5039:   border-color: $pgbg;
                   5040:   text-align: center;
                   5041: }
                   5042: table.LC_parm_overview_restrictions th {
                   5043:   background: $tabbg;
                   5044:   border-width: 1px 4px 1px 4px;
                   5045:   border-style: solid;
                   5046:   border-color: $pgbg;
                   5047: }
1.398     albertel 5048: table#LC_helpmenu {
                   5049:   border: 0px;
                   5050:   height: 55px;
                   5051:   border-spacing: 0px;
                   5052: }
                   5053: 
                   5054: table#LC_helpmenu fieldset legend {
                   5055:   font-size: larger;
                   5056:   font-weight: bold;
                   5057: }
1.397     albertel 5058: table#LC_helpmenu_links {
                   5059:   width: 100%;
                   5060:   border: 1px solid black;
                   5061:   background: $pgbg;
                   5062:   padding: 0px;
                   5063:   border-spacing: 1px;
                   5064: }
                   5065: table#LC_helpmenu_links tr td {
                   5066:   padding: 1px;
                   5067:   background: $tabbg;
1.399     albertel 5068:   text-align: center;
                   5069:   font-weight: bold;
1.397     albertel 5070: }
1.396     albertel 5071: 
1.397     albertel 5072: table#LC_helpmenu_links a:link, table#LC_helpmenu_links a:visited,
                   5073: table#LC_helpmenu_links a:active {
                   5074:   text-decoration: none;
                   5075:   color: $font;
                   5076: }
                   5077: table#LC_helpmenu_links a:hover {
                   5078:   text-decoration: underline;
                   5079:   color: $vlink;
                   5080: }
1.396     albertel 5081: 
1.417     albertel 5082: .LC_chrt_popup_exists {
                   5083:   border: 1px solid #339933;
                   5084:   margin: -1px;
                   5085: }
                   5086: .LC_chrt_popup_up {
                   5087:   border: 1px solid yellow;
                   5088:   margin: -1px;
                   5089: }
                   5090: .LC_chrt_popup {
                   5091:   border: 1px solid #8888FF;
                   5092:   background: #CCCCFF;
                   5093: }
1.421     albertel 5094: table.LC_pick_box {
                   5095:   border-collapse: separate;
                   5096:   background: white;
                   5097:   border: 1px solid black;
                   5098:   border-spacing: 1px;
                   5099: }
                   5100: table.LC_pick_box td.LC_pick_box_title {
                   5101:   background: $tabbg;
                   5102:   font-weight: bold;
                   5103:   text-align: right;
1.740     bisitz   5104:   vertical-align: top;
1.421     albertel 5105:   width: 184px;
                   5106:   padding: 8px;
                   5107: }
1.645     raeburn  5108: table.LC_pick_box td.LC_selfenroll_pick_box_title {
                   5109:   background: $tabbg;
                   5110:   font-weight: bold;
                   5111:   text-align: right;
                   5112:   width: 350px;
                   5113:   padding: 8px;
                   5114: }
                   5115: 
1.579     raeburn  5116: table.LC_pick_box td.LC_pick_box_value {
                   5117:   text-align: left;
                   5118:   padding: 8px;
                   5119: }
                   5120: table.LC_pick_box td.LC_pick_box_select {
                   5121:   text-align: left;
                   5122:   padding: 8px;
                   5123: }
1.424     albertel 5124: table.LC_pick_box td.LC_pick_box_separator {
1.421     albertel 5125:   padding: 0px;
                   5126:   height: 1px;
                   5127:   background: black;
                   5128: }
                   5129: table.LC_pick_box td.LC_pick_box_submit {
                   5130:   text-align: right;
                   5131: }
1.579     raeburn  5132: table.LC_pick_box td.LC_evenrow_value {
                   5133:   text-align: left;
                   5134:   padding: 8px;
                   5135:   background-color: $data_table_light;
                   5136: }
                   5137: table.LC_pick_box td.LC_oddrow_value {
                   5138:   text-align: left;
                   5139:   padding: 8px;
                   5140:   background-color: $data_table_light;
                   5141: }
                   5142: table.LC_helpform_receipt {
                   5143:   width: 620px;
                   5144:   border-collapse: separate;
                   5145:   background: white;
                   5146:   border: 1px solid black;
                   5147:   border-spacing: 1px;
                   5148: }
                   5149: table.LC_helpform_receipt td.LC_pick_box_title {
                   5150:   background: $tabbg;
                   5151:   font-weight: bold;
                   5152:   text-align: right;
                   5153:   width: 184px;
                   5154:   padding: 8px;
                   5155: }
                   5156: table.LC_helpform_receipt td.LC_evenrow_value {
                   5157:   text-align: left;
                   5158:   padding: 8px;
                   5159:   background-color: $data_table_light;
                   5160: }
                   5161: table.LC_helpform_receipt td.LC_oddrow_value {
                   5162:   text-align: left;
                   5163:   padding: 8px;
                   5164:   background-color: $data_table_light;
                   5165: }
                   5166: table.LC_helpform_receipt td.LC_pick_box_separator {
                   5167:   padding: 0px;
                   5168:   height: 1px;
                   5169:   background: black;
                   5170: }
                   5171: span.LC_helpform_receipt_cat {
                   5172:   font-weight: bold;
                   5173: }
1.424     albertel 5174: table.LC_group_priv_box {
                   5175:   background: white;
                   5176:   border: 1px solid black;
                   5177:   border-spacing: 1px;
                   5178: }
                   5179: table.LC_group_priv_box td.LC_pick_box_title {
                   5180:   background: $tabbg;
                   5181:   font-weight: bold;
                   5182:   text-align: right;
                   5183:   width: 184px;
                   5184: }
                   5185: table.LC_group_priv_box td.LC_groups_fixed {
                   5186:   background: $data_table_light;
                   5187:   text-align: center;
                   5188: }
                   5189: table.LC_group_priv_box td.LC_groups_optional {
                   5190:   background: $data_table_dark;
                   5191:   text-align: center;
                   5192: }
                   5193: table.LC_group_priv_box td.LC_groups_functionality {
                   5194:   background: $data_table_darker;
                   5195:   text-align: center;
                   5196:   font-weight: bold;
                   5197: }
                   5198: table.LC_group_priv td {
                   5199:   text-align: left;
                   5200:   padding: 0px;
                   5201: }
                   5202: 
1.421     albertel 5203: table.LC_notify_front_page {
                   5204:   background: white;
                   5205:   border: 1px solid black;
                   5206:   padding: 8px;
                   5207: }
                   5208: table.LC_notify_front_page td {
                   5209:   padding: 8px;
                   5210: }
1.424     albertel 5211: .LC_navbuttons {
                   5212:   margin: 2ex 0ex 2ex 0ex;
                   5213: }
1.423     albertel 5214: .LC_topic_bar {
                   5215:   font-family: $sans;
                   5216:   font-weight: bold;
                   5217:   width: 100%;
                   5218:   background: $tabbg;
                   5219:   vertical-align: middle;
                   5220:   margin: 2ex 0ex 2ex 0ex;
                   5221: }
                   5222: .LC_topic_bar span {
                   5223:   vertical-align: middle;
                   5224: }
                   5225: .LC_topic_bar img {
                   5226:   vertical-align: bottom;
                   5227: }
                   5228: table.LC_course_group_status {
                   5229:   margin: 20px;
                   5230: }
                   5231: table.LC_status_selector td {
                   5232:   vertical-align: top;
                   5233:   text-align: center;
1.424     albertel 5234:   padding: 4px;
                   5235: }
                   5236: table.LC_descriptive_input td.LC_description {
                   5237:   vertical-align: top;
                   5238:   text-align: right;
                   5239:   font-weight: bold;
1.423     albertel 5240: }
1.599     albertel 5241: div.LC_feedback_link {
1.616     albertel 5242:   clear: both;
1.599     albertel 5243:   background: white;
1.779     bisitz   5244:   width: 100%;
1.489     raeburn  5245: }
                   5246: span.LC_feedback_link {
1.599     albertel 5247:   background: $feedback_link_bg;
                   5248:   font-size: larger;
                   5249: }
                   5250: span.LC_message_link {
                   5251:   background: $feedback_link_bg;
                   5252:   font-size: larger;
                   5253:   position: absolute;
                   5254:   right: 1em;
1.489     raeburn  5255: }
1.421     albertel 5256: 
1.515     albertel 5257: table.LC_prior_tries {
1.524     albertel 5258:   border: 1px solid #000000;
                   5259:   border-collapse: separate;
                   5260:   border-spacing: 1px;
1.515     albertel 5261: }
1.523     albertel 5262: 
1.515     albertel 5263: table.LC_prior_tries td {
1.524     albertel 5264:   padding: 2px;
1.515     albertel 5265: }
1.523     albertel 5266: 
                   5267: .LC_answer_correct {
                   5268:   background: #AAFFAA;
                   5269:   color: black;
                   5270: }
                   5271: .LC_answer_charged_try {
                   5272:   background: #FFAAAA ! important;
                   5273:   color: black;
                   5274: }
1.779     bisitz   5275: .LC_answer_not_charged_try,
1.523     albertel 5276: .LC_answer_no_grade,
                   5277: .LC_answer_late {
                   5278:   background: #FFFFAA;
                   5279:   color: black;
                   5280: }
                   5281: .LC_answer_previous {
                   5282:   background: #AAAAFF;
                   5283:   color: black;
                   5284: }
1.779     bisitz   5285: .LC_answer_no_message {
1.777     tempelho 5286:   background: #FFFFFF;
                   5287:   color: black;
1.779     bisitz   5288: }
                   5289: .LC_answer_unknown {
                   5290:   background: orange;
                   5291:   color: black;
1.777     tempelho 5292: }
1.529     albertel 5293: span.LC_prior_numerical,
                   5294: span.LC_prior_string,
                   5295: span.LC_prior_custom,
                   5296: span.LC_prior_reaction,
                   5297: span.LC_prior_math {
1.523     albertel 5298:   font-family: monospace;
                   5299:   white-space: pre;
                   5300: }
                   5301: 
1.525     albertel 5302: span.LC_prior_string {
                   5303:   font-family: monospace;
                   5304:   white-space: pre;
                   5305: }
                   5306: 
1.523     albertel 5307: table.LC_prior_option {
                   5308:   width: 100%;
                   5309:   border-collapse: collapse;
                   5310: }
1.528     albertel 5311: table.LC_prior_rank, table.LC_prior_match {
                   5312:   border-collapse: collapse;
                   5313: }
                   5314: table.LC_prior_option tr td,
                   5315: table.LC_prior_rank tr td,
                   5316: table.LC_prior_match tr td {
1.524     albertel 5317:   border: 1px solid #000000;
1.515     albertel 5318: }
                   5319: 
1.770     droeschl 5320: td.LC_nobreak,
1.519     raeburn  5321: span.LC_nobreak {
1.544     albertel 5322:   white-space: nowrap;
1.519     raeburn  5323: }
                   5324: 
1.576     raeburn  5325: span.LC_cusr_emph {
                   5326:   font-style: italic;
                   5327: }
                   5328: 
1.633     raeburn  5329: span.LC_cusr_subheading {
                   5330:   font-weight: normal;
                   5331:   font-size: 85%;
                   5332: }
                   5333: 
1.545     albertel 5334: table.LC_docs_documents {
                   5335:   background: #BBBBBB;
1.547     albertel 5336:   border-width: 0px;
1.545     albertel 5337:   border-collapse: collapse;
                   5338: }
1.777     tempelho 5339: table.LC_docs_documents td.LC_docs_document {
1.779     bisitz   5340:   border: 2px solid black;
                   5341:   padding: 4px;
1.777     tempelho 5342: }
1.545     albertel 5343: .LC_docs_entry_move {
                   5344:   border: 0px;
                   5345:   border-collapse: collapse;
1.544     albertel 5346: }
                   5347: 
1.545     albertel 5348: .LC_docs_entry_move td {
                   5349:   border: 2px solid #BBBBBB;
                   5350:   background: #DDDDDD;
                   5351: }
                   5352: 
                   5353: .LC_docs_editor td.LC_docs_entry_commands {
                   5354:   background: #DDDDDD;
                   5355:   font-size: x-small;
                   5356: }
1.544     albertel 5357: .LC_docs_copy {
1.545     albertel 5358:   color: #000099;
1.544     albertel 5359: }
                   5360: .LC_docs_cut {
1.545     albertel 5361:   color: #550044;
1.544     albertel 5362: }
                   5363: .LC_docs_rename {
1.545     albertel 5364:   color: #009900;
1.544     albertel 5365: }
                   5366: .LC_docs_remove {
1.545     albertel 5367:   color: #990000;
                   5368: }
                   5369: 
1.547     albertel 5370: .LC_docs_reinit_warn,
                   5371: .LC_docs_ext_edit {
                   5372:   font-size: x-small;
                   5373: }
                   5374: 
1.545     albertel 5375: .LC_docs_editor td.LC_docs_entry_title,
                   5376: .LC_docs_editor td.LC_docs_entry_icon {
                   5377:   background: #FFFFBB;
                   5378: }
                   5379: .LC_docs_editor td.LC_docs_entry_parameter {
                   5380:   background: #BBBBFF;
                   5381:   font-size: x-small;
                   5382:   white-space: nowrap;
                   5383: }
                   5384: 
                   5385: table.LC_docs_adddocs td,
                   5386: table.LC_docs_adddocs th {
                   5387:   border: 1px solid #BBBBBB;
                   5388:   padding: 4px;
                   5389:   background: #DDDDDD;
1.543     albertel 5390: }
                   5391: 
1.584     albertel 5392: table.LC_sty_begin {
                   5393:   background: #BBFFBB;
                   5394: }
                   5395: table.LC_sty_end {
                   5396:   background: #FFBBBB;
                   5397: }
                   5398: 
1.589     raeburn  5399: table.LC_double_column {
                   5400:   border-width: 0px;
                   5401:   border-collapse: collapse;
                   5402:   width: 100%;
                   5403:   padding: 2px;
                   5404: }
                   5405: 
                   5406: table.LC_double_column tr td.LC_left_col {
1.590     raeburn  5407:   top: 2px;
1.589     raeburn  5408:   left: 2px;
                   5409:   width: 47%;
                   5410:   vertical-align: top;
                   5411: }
                   5412: 
                   5413: table.LC_double_column tr td.LC_right_col {
                   5414:   top: 2px;
1.779     bisitz   5415:   right: 2px;
1.589     raeburn  5416:   width: 47%;
                   5417:   vertical-align: top;
                   5418: }
                   5419: 
1.594     raeburn  5420: span.LC_role_level {
                   5421:   font-weight: bold;
                   5422: }
                   5423: 
1.591     raeburn  5424: div.LC_left_float {
                   5425:   float: left;
                   5426:   padding-right: 5%;
1.597     albertel 5427:   padding-bottom: 4px;
1.591     raeburn  5428: }
                   5429: 
                   5430: div.LC_clear_float_header {
1.597     albertel 5431:   padding-bottom: 2px;
1.591     raeburn  5432: }
                   5433: 
                   5434: div.LC_clear_float_footer {
1.597     albertel 5435:   padding-top: 10px;
1.591     raeburn  5436:   clear: both;
                   5437: }
                   5438: 
1.597     albertel 5439: 
                   5440: div.LC_grade_show_user {
                   5441:   margin-top: 20px;
                   5442:   border: 1px solid black;
                   5443: }
                   5444: div.LC_grade_user_name {
                   5445:   background: #DDDDEE;
                   5446:   border-bottom: 1px solid black;
1.705     tempelho 5447:   font-weight: bold;
                   5448:   font-size: large;
1.597     albertel 5449: }
                   5450: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
                   5451:   background: #DDEEDD;
                   5452: }
                   5453: 
                   5454: div.LC_grade_show_problem,
                   5455: div.LC_grade_submissions,
                   5456: div.LC_grade_message_center,
                   5457: div.LC_grade_info_links,
                   5458: div.LC_grade_assign {
                   5459:   margin: 5px;
                   5460:   width: 99%;
                   5461:   background: #FFFFFF;
                   5462: }
                   5463: div.LC_grade_show_problem_header,
                   5464: div.LC_grade_submissions_header,
                   5465: div.LC_grade_message_center_header,
                   5466: div.LC_grade_assign_header {
1.705     tempelho 5467:   font-weight: bold;
                   5468:   font-size: large;
1.597     albertel 5469: }
                   5470: div.LC_grade_show_problem_problem,
                   5471: div.LC_grade_submissions_body,
                   5472: div.LC_grade_message_center_body,
                   5473: div.LC_grade_assign_body {
                   5474:   border: 1px solid black;
                   5475:   width: 99%;
                   5476:   background: #FFFFFF;
                   5477: }
1.598     albertel 5478: span.LC_grade_check_note {
1.705     tempelho 5479:   font-weight: normal;
                   5480:   font-size: medium;
1.598     albertel 5481:   display: inline;
                   5482:   position: absolute;
                   5483:   right: 1em;
                   5484: }
1.597     albertel 5485: 
1.613     albertel 5486: table.LC_scantron_action {
                   5487:   width: 100%;
                   5488: }
                   5489: table.LC_scantron_action tr th {
1.698     harmsja  5490:   font-weight:bold;
                   5491:   font-style:normal;
1.613     albertel 5492: }
1.779     bisitz   5493: .LC_edit_problem_header,
1.614     albertel 5494: div.LC_edit_problem_footer {
1.705     tempelho 5495:   font-weight: normal;
                   5496:   font-size:  medium;
1.602     albertel 5497:   margin: 2px;
1.600     albertel 5498: }
                   5499: div.LC_edit_problem_header,
1.602     albertel 5500: div.LC_edit_problem_header div,
1.614     albertel 5501: div.LC_edit_problem_footer,
                   5502: div.LC_edit_problem_footer div,
1.602     albertel 5503: div.LC_edit_problem_editxml_header,
                   5504: div.LC_edit_problem_editxml_header div {
1.600     albertel 5505:   margin-top: 5px;
                   5506: }
1.602     albertel 5507: div.LC_edit_problem_header_edit_row {
                   5508:   background: $tabbg;
                   5509:   padding: 3px;
                   5510:   margin-bottom: 5px;
                   5511: }
1.600     albertel 5512: div.LC_edit_problem_header_title {
1.705     tempelho 5513:   font-weight: bold;
                   5514:   font-size: larger;
1.602     albertel 5515:   background: $tabbg;
                   5516:   padding: 3px;
                   5517: }
                   5518: table.LC_edit_problem_header_title {
1.705     tempelho 5519:   font-size: larger;
                   5520:   font-weight:  bold;
1.602     albertel 5521:   width: 100%;
                   5522:   border-color: $pgbg;
                   5523:   border-style: solid;
                   5524:   border-width: $border;
                   5525: 
1.600     albertel 5526:   background: $tabbg;
1.602     albertel 5527:   border-collapse: collapse;
                   5528:   padding: 0px
                   5529: }
                   5530: 
                   5531: div.LC_edit_problem_discards {
                   5532:   float: left;
                   5533:   padding-bottom: 5px;
                   5534: }
                   5535: div.LC_edit_problem_saves {
                   5536:   float: right;
                   5537:   padding-bottom: 5px;
1.600     albertel 5538: }
                   5539: hr.LC_edit_problem_divide {
1.602     albertel 5540:   clear: both;
1.600     albertel 5541:   color: $tabbg;
                   5542:   background-color: $tabbg;
                   5543:   height: 3px;
                   5544:   border: 0px;
                   5545: }
1.679     riegler  5546: img.stift{
1.678     riegler  5547:   border-width:0;
1.679     riegler  5548:   vertical-align:middle;
1.677     riegler  5549: }
1.680     riegler  5550: 
1.681     riegler  5551: table#LC_mainmenu{
                   5552:  margin-top:10px;
                   5553:  width:80%;
                   5554: 
                   5555: }
                   5556: 
1.680     riegler  5557: table#LC_mainmenu td.LC_mainmenu_col_fieldset{
                   5558:   vertical-align: top;
                   5559:   width: 45%;
                   5560: }
1.779     bisitz   5561: .LC_mainmenu_fieldset_category {
                   5562:   color: $font;
                   5563:   background: $pgbg;
                   5564:   font-family: $sans;
                   5565:   font-size: small;
                   5566:   font-weight: bold;
1.777     tempelho 5567: }
1.716     raeburn  5568: div.LC_createcourse {
                   5569:     margin: 10px 10px 10px 10px;
                   5570: }
                   5571: 
1.693     droeschl 5572: /* ---- Remove when done ----
                   5573: # The following styles is part of the redesign of LON-CAPA and are
                   5574: # subject to change during this project.
                   5575: # Don't rely on their current functionality as they might be 
                   5576: # changed or removed.
                   5577: # --------------------------*/
                   5578: 
1.698     harmsja  5579: a:hover,
1.721     harmsja  5580: ol.LC_smallMenu a:hover,
                   5581: ol#LC_MenuBreadcrumbs a:hover,
                   5582: ol#LC_PathBreadcrumbs a:hover,
                   5583: ul#LC_TabMainMenuContent a:hover,
                   5584: .LC_FormSectionClearButton input:hover
                   5585: ul.LC_TabContent   li:hover a{
1.698     harmsja  5586: 	color:#BF2317;
                   5587:         text-decoration:none;
1.693     droeschl 5588: }
                   5589: 
1.779     bisitz   5590: h1 {
1.721     harmsja  5591: 	padding:5px 10px 5px 20px;
1.693     droeschl 5592: 	line-height:130%;
                   5593: }
1.698     harmsja  5594: 
1.693     droeschl 5595: h2,h3,h4,h5,h6
                   5596: {
1.721     harmsja  5597: 	margin:5px 0px 5px 0px;
                   5598: 	padding:0px;
                   5599: 	line-height:130%;
1.693     droeschl 5600: }
1.721     harmsja  5601: .LC_hcell{
1.698     harmsja  5602:         padding:3px 15px 3px 15px;
                   5603:         margin:0px;
1.703     harmsja  5604: 	background-color:$tabbg;
1.779     bisitz   5605: 	border-bottom:solid 1px $lg_border_color;
1.693     droeschl 5606: }
1.721     harmsja  5607: .LC_noBorder {
1.698     harmsja  5608:         border:0px;
                   5609: }
1.693     droeschl 5610: 
                   5611: 
1.698     harmsja  5612: /* Main Header with discription of Person, Course, etc. */
1.693     droeschl 5613: 
1.761     tempelho 5614: .LC_Right {
                   5615:         float: right;
                   5616:         margin: 0px;
                   5617:         padding: 0px;
                   5618: }
                   5619: 
1.721     harmsja  5620: p, .LC_ContentBox {
1.698     harmsja  5621: 	padding: 10px;
                   5622: 
                   5623: }
1.721     harmsja  5624: .LC_FormSectionClearButton input {
1.779     bisitz   5625:         background-color:transparent;
1.698     harmsja  5626:         border:0px;
                   5627:         cursor:pointer;
                   5628:         text-decoration:underline;
1.693     droeschl 5629: }
1.763     bisitz   5630: 
                   5631: .LC_help_open_topic {
                   5632:         color: #FFFFFF;
                   5633:         background-color: #EEEEFF;
                   5634:         margin: 1px;
                   5635:         padding: 4px;
                   5636:         border: 1px solid #000033;
                   5637:         white-space: nowrap;
1.783     amueller 5638: /*		vertical-align: middle; */
1.759     neumanie 5639: }
1.693     droeschl 5640: 
1.698     harmsja  5641: dl,ul,div,fieldset {
                   5642: 	margin: 10px 10px 10px 0px;
1.693     droeschl 5643: 	overflow:hidden;
                   5644: }
1.721     harmsja  5645: ol.LC_smallMenu, ol#LC_PathBreadcrumbs {
1.698     harmsja  5646: 	margin: 0px;
1.693     droeschl 5647: }
                   5648: 
1.721     harmsja  5649: ol.LC_smallMenu li {
1.693     droeschl 5650: 	display: inline;
                   5651: 	padding: 5px 5px 0px 10px;
                   5652: 	vertical-align: top;
                   5653: }
                   5654: 
1.721     harmsja  5655: ol.LC_smallMenu li img {
1.693     droeschl 5656: 	vertical-align: bottom;
                   5657: }
                   5658: 
1.721     harmsja  5659: ol.LC_smallMenu a {
1.693     droeschl 5660: 	font-size: 90%;
                   5661: 	color: RGB(80, 80, 80);
                   5662: 	text-decoration: none;
                   5663: }
1.760     harmsja  5664: ol#LC_TabMainMenuContent, ul.LC_TabContent ,
1.741     harmsja  5665: ul.LC_TabContentBigger {
1.721     harmsja  5666: 	display:block;
                   5667: 	list-style:none;
1.741     harmsja  5668: 	margin: 0px;
1.693     droeschl 5669: 	padding: 0px;
                   5670: }
                   5671: 
1.744     ehlerst  5672: ol#LC_TabMainMenuContent li, ul.LC_TabContent li,
1.741     harmsja  5673: ul.LC_TabContentBigger li{
1.693     droeschl 5674: 	display: inline;
1.741     harmsja  5675: 	border-right: solid 1px $lg_border_color;
                   5676: 	float:left;
                   5677: 	line-height:140%;
                   5678: 	white-space:nowrap;
                   5679: }
                   5680: ol#LC_TabMainMenuContent li{
1.693     droeschl 5681: 	vertical-align: bottom;
                   5682: 	border-bottom: solid 1px RGB(175, 175, 175);
1.721     harmsja  5683: 	padding: 5px 10px 5px 10px;
1.741     harmsja  5684: 	margin-right:5px;
                   5685: 	margin-bottom:3px;
1.693     droeschl 5686: 	font-weight: bold;
1.723     riegler  5687: 	background: url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
1.693     droeschl 5688: }
                   5689: 
1.721     harmsja  5690: ol#LC_TabMainMenuContent li a{
1.693     droeschl 5691: 	color: RGB(47, 47, 47);
                   5692: 	text-decoration: none;
                   5693: }
1.721     harmsja  5694: ul.LC_TabContent {
1.741     harmsja  5695: 	min-height:1.6em;
1.721     harmsja  5696: }
                   5697: ul.LC_TabContent li{
1.741     harmsja  5698: 	vertical-align:middle;
                   5699: 	padding:0px 10px 0px 10px;
1.745     ehlerst  5700: 	background-color:$tabbg;
                   5701: 	border-bottom:solid 1px $lg_border_color;
1.721     harmsja  5702: }
1.779     bisitz   5703: ul.LC_TabContent li a, ul.LC_TabContent li{
1.721     harmsja  5704: 	color:rgb(47,47,47);
                   5705: 	text-decoration:none;
                   5706: 	font-size:95%;
                   5707: 	font-weight:bold;
1.761     tempelho 5708: 	padding-right: 16px;
1.721     harmsja  5709: }
1.744     ehlerst  5710: ul.LC_TabContent li:hover, ul.LC_TabContent li.active{
1.761     tempelho 5711:         background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.745     ehlerst  5712: 	border-bottom:solid 1px #FFFFFF;
1.761     tempelho 5713: 	padding-right: 16px;
1.744     ehlerst  5714: }
1.741     harmsja  5715: ul.LC_TabContentBigger li{
                   5716: 	vertical-align:bottom;
                   5717: 	border-top:solid 1px $lg_border_color;
                   5718: 	border-left:solid 1px $lg_border_color;
                   5719: 	padding:5px 10px 5px 10px;
                   5720: 	margin-left:2px;
                   5721: 	background:url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
                   5722: }
1.744     ehlerst  5723: ul.LC_TabContentBigger li:hover, ul.LC_TabContentBigger li.active{
                   5724: 	background:url(/adm/lonIcons/lightGreyBG.png) repeat-x right bottom;
                   5725: }
1.741     harmsja  5726: ul.LC_TabContentBigger li, ul.LC_TabContentBigger li a{
                   5727: 	font-size:110%;
                   5728: 	font-weight:bold;
                   5729: }
1.693     droeschl 5730: 
1.783     amueller 5731: ol#LC_MenuBreadcrumbs, ol#LC_PathBreadcrumbs, ul.LC_CourseBreadcrumbs{
1.693     droeschl 5732: 	border-top: solid 1px RGB(255, 255, 255);
                   5733: 	height: 20px;
                   5734: 	line-height: 20px;
                   5735: 	vertical-align: bottom;
                   5736: 	margin: 0px 0px 30px 0px;
                   5737: 	padding-left: 10px;
                   5738: 	list-style-position: inside;
1.723     riegler  5739: 	background: url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
1.693     droeschl 5740: }
                   5741: 
1.783     amueller 5742: ol#LC_MenuBreadcrumbs li, ol#LC_PathBreadcrumbs li, ul.LC_CourseBreadcrumbs li {
1.741     harmsja  5743: /*
1.723     riegler  5744: 	background: url(/adm/lonIcons/arrow_white.png) no-repeat left center;
1.779     bisitz   5745: */
1.693     droeschl 5746: 	display: inline;
                   5747: 	padding: 0px 0px 0px 10px;
1.783     amueller 5748: /*	vertical-align: bottom; */
1.693     droeschl 5749: 	overflow:hidden;
                   5750: }
                   5751: 
1.783     amueller 5752: ol#LC_MenuBreadcrumbs li a, ul.LC_CourseBreadcrumbs li a {
1.693     droeschl 5753: 	text-decoration: none;
                   5754: 	font-size:90%;
                   5755: }
1.721     harmsja  5756: ol#LC_PathBreadcrumbs li a{
1.698     harmsja  5757: 	text-decoration:none;
                   5758: 	font-size:100%;
                   5759: 	font-weight:bold;
1.693     droeschl 5760: }
1.786     neumanie 5761: .LC_BoxPadding
                   5762: {
                   5763: 	padding: 10px;
                   5764: }
1.721     harmsja  5765: .LC_ContentBoxSpecial
1.693     droeschl 5766: {
1.701     harmsja  5767: 	border: solid 1px $lg_border_color;
1.746     neumanie 5768: }
                   5769: .LC_ContentBoxSpecialContactInfo
                   5770: {
                   5771: 	border: solid 1px $lg_border_color;
                   5772: 	max-width:25%;
                   5773: 	min-width:25%;
1.698     harmsja  5774: }
1.747     neumanie 5775: .LC_AboutMe_Image
                   5776: {
                   5777: 	float:left;
                   5778: 	margin-right:10px;
                   5779: }
                   5780: .LC_Clear_AboutMe_Image
                   5781: {
                   5782: 	clear:left;
                   5783: }
1.721     harmsja  5784: dl.LC_ListStyleClean dt {
1.693     droeschl 5785: 	padding-right: 5px;
                   5786: 	display: table-header-group;
                   5787: }
                   5788: 
1.721     harmsja  5789: dl.LC_ListStyleClean dd {
1.693     droeschl 5790: 	display: table-row;
                   5791: }
                   5792: 
1.721     harmsja  5793: .LC_ListStyleClean,
                   5794: .LC_ListStyleSimple,
                   5795: .LC_ListStyleNormal,
1.777     tempelho 5796: .LC_ListStyle_Border,
1.721     harmsja  5797: .LC_ListStyleSpecial
1.693     droeschl 5798: 	{
                   5799: 	/*display:block;	*/
                   5800: 	list-style-position: inside;
                   5801: 	list-style-type: none;
                   5802: 	overflow: hidden;
                   5803: 	padding: 0px;
                   5804: }
                   5805: 
1.721     harmsja  5806: .LC_ListStyleSimple li,
                   5807: .LC_ListStyleSimple dd,
                   5808: .LC_ListStyleNormal li,
                   5809: .LC_ListStyleNormal dd,
                   5810: .LC_ListStyleSpecial li,
                   5811: .LC_ListStyleSpecial dd
1.693     droeschl 5812: 	{
                   5813: 	margin: 0px;
                   5814: 	padding: 5px 5px 5px 10px;
                   5815: 	clear: both;
                   5816: }
                   5817: 
1.721     harmsja  5818: .LC_ListStyleClean li,
                   5819: .LC_ListStyleClean dd {
1.693     droeschl 5820: 	padding-top: 0px;
                   5821: 	padding-bottom: 0px;
                   5822: }
                   5823: 
1.721     harmsja  5824: .LC_ListStyleSimple dd,
                   5825: .LC_ListStyleSimple li{
1.698     harmsja  5826: 	border-bottom: solid 1px $lg_border_color;
1.693     droeschl 5827: }
                   5828: 
1.721     harmsja  5829: .LC_ListStyleSpecial li,
                   5830: .LC_ListStyleSpecial dd {
1.693     droeschl 5831: 	list-style-type: none;
                   5832: 	background-color: RGB(220, 220, 220);
                   5833: 	margin-bottom: 4px;
                   5834: }
                   5835: 
1.721     harmsja  5836: table.LC_SimpleTable {
1.698     harmsja  5837: 	margin:5px;
                   5838: 	border:solid 1px $lg_border_color;
1.693     droeschl 5839: 	}
                   5840: 
1.721     harmsja  5841: table.LC_SimpleTable tr {
1.698     harmsja  5842: 	padding:0px;
                   5843: 	border:solid 1px $lg_border_color;
1.693     droeschl 5844: }
1.721     harmsja  5845: table.LC_SimpleTable thead{
1.698     harmsja  5846: 	 background:rgb(220,220,220);
1.693     droeschl 5847: }
                   5848: 
1.721     harmsja  5849: div.LC_columnSection {
1.693     droeschl 5850: 	display: block;
                   5851: 	clear: both;
                   5852: 	overflow: hidden;
                   5853: 	margin:0px;
                   5854: }
                   5855: 
1.721     harmsja  5856: div.LC_columnSection>* {
1.693     droeschl 5857: 	float: left;
                   5858: 	margin: 10px 20px 10px 0px;
1.747     neumanie 5859: 	overflow:hidden;
1.693     droeschl 5860: }
1.721     harmsja  5861: 
1.719     ehlerst  5862: .ContentBoxSpecialTemplate
                   5863: {
1.747     neumanie 5864:         border: solid 1px $lg_border_color;
1.719     ehlerst  5865: }
                   5866: .ContentBoxTemplate {
                   5867:         padding:10px;
                   5868: }
                   5869: 
1.721     harmsja  5870: div.LC_columnSection > .ContentBoxTemplate,
                   5871: div.LC_columnSection > .ContentBoxSpecialTemplate
1.719     ehlerst  5872:         {
                   5873:         width: 600px;
                   5874: }
1.753     droeschl 5875: 
1.720     ehlerst  5876: .clear{
                   5877: 	clear: both;
                   5878: 	line-height: 0px;
                   5879: 	font-size: 0px;
                   5880: 	height: 0px;
                   5881: }
1.693     droeschl 5882: 
1.694     tempelho 5883: .LC_loginpage_container {
                   5884: 	text-align:left;
                   5885: 	margin : 0 auto;
1.785     tempelho 5886: 	width:90%;
1.694     tempelho 5887: 	padding: 10px;
                   5888: 	height: auto;
1.712     muellerd 5889: 	background-color:#FFFFFF;
1.694     tempelho 5890: 	border:1px solid #CCCCCC;
                   5891: }
                   5892: 
                   5893: 
                   5894: .LC_loginpage_loginContainer {
                   5895: 	float:left;
1.712     muellerd 5896: 	width: 182px;
1.785     tempelho 5897: 	padding: 2px;
1.712     muellerd 5898: 	border:1px solid #CCCCCC;
                   5899: 	background-color:$loginbg;
1.694     tempelho 5900: }
                   5901: 
1.717     tempelho 5902: .LC_loginpage_loginContainer h2{
1.712     muellerd 5903: 	margin-top:0;
                   5904: 	display:block;
                   5905: 	background:$bgcol;
                   5906: 	color:$textcol;
                   5907: 	padding-left:5px;
                   5908: }
1.785     tempelho 5909: 
1.694     tempelho 5910: .LC_loginpage_loginInfo {
                   5911: 	float:left;
1.785     tempelho 5912: 	width:182px;
1.694     tempelho 5913: 	border:1px solid #CCCCCC;
1.785     tempelho 5914: 	padding:2px;
1.712     muellerd 5915: }
                   5916: 
1.694     tempelho 5917: .LC_loginpage_space {
1.754     droeschl 5918: 	clear: both;
                   5919: 	margin-bottom: 20px;
1.694     tempelho 5920: 	border-bottom: 1px solid #CCCCCC;
                   5921: }
                   5922: 
1.785     tempelho 5923: .LC_loginpage_floatLeft {
                   5924: 	float: left;
                   5925: 	width: 200px;
                   5926: 	margin: 0;
                   5927: }
                   5928: 
1.748     schulted 5929: table em{
1.754     droeschl 5930: 	font-weight: bold;
                   5931: 	font-style: normal;
1.748     schulted 5932: }
1.779     bisitz   5933: table.LC_tableBrowseRes,
1.768     schulted 5934: table.LC_tableOfContent{
1.769     schulted 5935:         border:none;
                   5936: 	border-spacing: 1;
1.754     droeschl 5937: 	padding: 3px;
                   5938: 	background-color: #FFFFFF;
                   5939: 	font-size: 90%;
1.753     droeschl 5940: }
1.789     droeschl 5941: 
                   5942: table.LC_tableOfContent{
                   5943:     border-collapse: collapse;
                   5944: }
                   5945: 
1.771     droeschl 5946: table.LC_tableBrowseRes a,
1.768     schulted 5947: table.LC_tableOfContent a {
1.771     droeschl 5948:         background-color: transparent;
1.753     droeschl 5949: 	text-decoration: none;
                   5950: }
                   5951: 
1.771     droeschl 5952: table.LC_tableBrowseRes tr.LC_trOdd,
1.768     schulted 5953: table.LC_tableOfContent tr.LC_trOdd{
1.754     droeschl 5954: 	background-color: #EEEEEE;
1.753     droeschl 5955: }
                   5956: 
1.768     schulted 5957: table.LC_tableOfContent img{
1.753     droeschl 5958: 	border: none;
                   5959: 	height: 1.3em;
                   5960: 	vertical-align: text-bottom;
                   5961: 	margin-right: 0.3em;
                   5962: }
1.757     schulted 5963: 
1.774     ehlerst  5964: a#LC_content_toolbar_firsthomework{
                   5965: 	background-image:url(/res/adm/pages/open-first-problem.gif);
                   5966: }
                   5967: 
                   5968: a#LC_content_toolbar_launchnav{
                   5969: 	background-image:url(/res/adm/pages/start-navigation.gif);
                   5970: }
                   5971: 
                   5972: a#LC_content_toolbar_closenav{
                   5973: 	background-image:url(/res/adm/pages/close-navigation.gif);
                   5974: }
                   5975: 
                   5976: a#LC_content_toolbar_everything{
                   5977: 	background-image:url(/res/adm/pages/show-all.gif);
                   5978: }
                   5979: 
                   5980: a#LC_content_toolbar_uncompleted{
                   5981: 	background-image:url(/res/adm/pages/show-incomplete-problems.gif);
                   5982: }
                   5983: 
                   5984: #LC_content_toolbar_clearbubbles{
                   5985: 	background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
                   5986: }
                   5987: 
1.757     schulted 5988: a#LC_content_toolbar_changefolder{
                   5989: 	background : url(/res/adm/pages/close-all-folders.gif) top center ;
                   5990: }
                   5991: 
                   5992: a#LC_content_toolbar_changefolder_toggled{
                   5993: 	background-image:url(/res/adm/pages/open-all-folders.gif);
                   5994: }
                   5995: 
                   5996: ul#LC_toolbar li a:hover{
                   5997: 	background-position: bottom center;
                   5998: }
                   5999: 
                   6000: ul#LC_toolbar{
1.779     bisitz   6001: 	padding:0;
1.757     schulted 6002: 	margin: 2px;
                   6003: 	list-style:none;
                   6004: 	position:relative;
                   6005: 	background-color:white;
                   6006: }
                   6007: 
                   6008: ul#LC_toolbar li{
                   6009: 	border:1px solid white;
                   6010: 	padding:0;
                   6011: 	margin: 0;
1.767     droeschl 6012:     float: left;
                   6013: 	display:inline;
1.757     schulted 6014: 	vertical-align:middle;
                   6015: }
                   6016: 
1.783     amueller 6017: 
1.757     schulted 6018: a.LC_toolbarItem{
1.767     droeschl 6019: 	display:block;
1.757     schulted 6020: 	padding:0;
                   6021: 	margin:0;
                   6022: 	height: 32px;
                   6023: 	width: 32px;
1.779     bisitz   6024: 	color:white;
                   6025: 	border:0 none;
1.757     schulted 6026: 	background-repeat:no-repeat;
                   6027: 	background-color:transparent;
                   6028: }
                   6029: 
1.782     bisitz   6030: ul.LC_functionslist li {
                   6031:   float: left;
                   6032:   white-space: nowrap;
                   6033:   height: 35px; /* at least as high as heighest list item */
                   6034:   margin: 0px 15px 15px 10px;
                   6035: }
                   6036: 
1.757     schulted 6037: 
1.343     albertel 6038: END
                   6039: }
                   6040: 
1.306     albertel 6041: =pod
                   6042: 
                   6043: =item * &headtag()
                   6044: 
                   6045: Returns a uniform footer for LON-CAPA web pages.
                   6046: 
1.307     albertel 6047: Inputs: $title - optional title for the head
                   6048:         $head_extra - optional extra HTML to put inside the <head>
1.315     albertel 6049:         $args - optional arguments
1.319     albertel 6050:             force_register - if is true call registerurl so the remote is 
                   6051:                              informed
1.415     albertel 6052:             redirect       -> array ref of
                   6053:                                    1- seconds before redirect occurs
                   6054:                                    2- url to redirect to
                   6055:                                    3- whether the side effect should occur
1.315     albertel 6056:                            (side effect of setting 
                   6057:                                $env{'internal.head.redirect'} to the url 
                   6058:                                redirected too)
1.352     albertel 6059:             domain         -> force to color decorate a page for a specific
                   6060:                                domain
                   6061:             function       -> force usage of a specific rolish color scheme
                   6062:             bgcolor        -> override the default page bgcolor
1.460     albertel 6063:             no_auto_mt_title
                   6064:                            -> prevent &mt()ing the title arg
1.464     albertel 6065: 
1.306     albertel 6066: =cut
                   6067: 
                   6068: sub headtag {
1.313     albertel 6069:     my ($title,$head_extra,$args) = @_;
1.306     albertel 6070:     
1.363     albertel 6071:     my $function = $args->{'function'} || &get_users_function();
                   6072:     my $domain   = $args->{'domain'}   || &determinedomain();
                   6073:     my $bgcolor  = $args->{'bgcolor'}  || &designparm($function.'.pgbg',$domain);
1.418     albertel 6074:     my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458     albertel 6075: 		   $Apache::lonnet::perlvar{'lonVersion'},
1.531     albertel 6076: 		   #time(),
1.418     albertel 6077: 		   $env{'environment.color.timestamp'},
1.363     albertel 6078: 		   $function,$domain,$bgcolor);
                   6079: 
1.369     www      6080:     $url = '/adm/css/'.&escape($url).'.css';
1.363     albertel 6081: 
1.308     albertel 6082:     my $result =
                   6083: 	'<head>'.
1.461     albertel 6084: 	&font_settings();
1.319     albertel 6085: 
1.461     albertel 6086:     if (!$args->{'frameset'}) {
                   6087: 	$result .= &Apache::lonhtmlcommon::htmlareaheaders();
                   6088:     }
1.319     albertel 6089:     if ($args->{'force_register'}) {
                   6090: 	$result .= &Apache::lonmenu::registerurl(1);
                   6091:     }
1.436     albertel 6092:     if (!$args->{'no_nav_bar'} 
                   6093: 	&& !$args->{'only_body'}
                   6094: 	&& !$args->{'frameset'}) {
                   6095: 	$result .= &help_menu_js();
                   6096:     }
1.319     albertel 6097: 
1.314     albertel 6098:     if (ref($args->{'redirect'})) {
1.414     albertel 6099: 	my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315     albertel 6100: 	$url = &Apache::lonenc::check_encrypt($url);
1.414     albertel 6101: 	if (!$inhibit_continue) {
                   6102: 	    $env{'internal.head.redirect'} = $url;
                   6103: 	}
1.313     albertel 6104: 	$result.=<<ADDMETA
                   6105: <meta http-equiv="pragma" content="no-cache" />
1.344     albertel 6106: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313     albertel 6107: ADDMETA
                   6108:     }
1.306     albertel 6109:     if (!defined($title)) {
                   6110: 	$title = 'The LearningOnline Network with CAPA';
                   6111:     }
1.460     albertel 6112:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
                   6113:     $result .= '<title> LON-CAPA '.$title.'</title>'
1.414     albertel 6114: 	.'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
                   6115: 	.$head_extra;
1.306     albertel 6116:     return $result;
                   6117: }
                   6118: 
                   6119: =pod
                   6120: 
1.340     albertel 6121: =item * &font_settings()
                   6122: 
                   6123: Returns neccessary <meta> to set the proper encoding
                   6124: 
                   6125: Inputs: none
                   6126: 
                   6127: =cut
                   6128: 
                   6129: sub font_settings {
                   6130:     my $headerstring='';
1.647     www      6131:     if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340     albertel 6132: 	$headerstring.=
                   6133: 	    '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
                   6134:     }
                   6135:     return $headerstring;
                   6136: }
                   6137: 
1.341     albertel 6138: =pod
                   6139: 
                   6140: =item * &xml_begin()
                   6141: 
                   6142: Returns the needed doctype and <html>
                   6143: 
                   6144: Inputs: none
                   6145: 
                   6146: =cut
                   6147: 
                   6148: sub xml_begin {
                   6149:     my $output='';
                   6150: 
1.592     albertel 6151:     if ($env{'internal.start_page'}==1) {
                   6152: 	&Apache::lonhtmlcommon::init_htmlareafields();
                   6153:     }
1.342     albertel 6154: 
1.341     albertel 6155:     if ($env{'browser.mathml'}) {
                   6156: 	$output='<?xml version="1.0"?>'
                   6157:             #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
                   6158: #            .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
                   6159:             
                   6160: #	    .'<!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">] >'
                   6161: 	    .'<!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">'
                   6162:             .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" ' 
                   6163: 	    .'xmlns="http://www.w3.org/1999/xhtml">';
                   6164:     } else {
                   6165: 	$output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>';
                   6166:     }
                   6167:     return $output;
                   6168: }
1.340     albertel 6169: 
                   6170: =pod
                   6171: 
1.306     albertel 6172: =item * &endheadtag()
                   6173: 
                   6174: Returns a uniform </head> for LON-CAPA web pages.
                   6175: 
                   6176: Inputs: none
                   6177: 
                   6178: =cut
                   6179: 
                   6180: sub endheadtag {
                   6181:     return '</head>';
                   6182: }
                   6183: 
                   6184: =pod
                   6185: 
                   6186: =item * &head()
                   6187: 
                   6188: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
                   6189: 
1.648     raeburn  6190: Inputs:
                   6191: 
                   6192: =over 4
                   6193: 
                   6194: $title - optional title for the page
                   6195: 
                   6196: $head_extra - optional extra HTML to put inside the <head>
                   6197: 
                   6198: =back
1.405     albertel 6199: 
1.306     albertel 6200: =cut
                   6201: 
                   6202: sub head {
1.325     albertel 6203:     my ($title,$head_extra,$args) = @_;
                   6204:     return &headtag($title,$head_extra,$args).&endheadtag();
1.306     albertel 6205: }
                   6206: 
                   6207: =pod
                   6208: 
                   6209: =item * &start_page()
                   6210: 
                   6211: Returns a complete <html> .. <body> section for LON-CAPA web pages.
                   6212: 
1.648     raeburn  6213: Inputs:
                   6214: 
                   6215: =over 4
                   6216: 
                   6217: $title - optional title for the page
                   6218: 
                   6219: $head_extra - optional extra HTML to incude inside the <head>
                   6220: 
                   6221: $args - additional optional args supported are:
                   6222: 
                   6223: =over 8
                   6224: 
                   6225:              only_body      -> is true will set &bodytag() onlybodytag
1.317     albertel 6226:                                     arg on
1.648     raeburn  6227:              no_nav_bar     -> is true will set &bodytag() notopbar arg on
                   6228:              add_entries    -> additional attributes to add to the  <body>
                   6229:              domain         -> force to color decorate a page for a 
1.317     albertel 6230:                                     specific domain
1.648     raeburn  6231:              function       -> force usage of a specific rolish color
1.317     albertel 6232:                                     scheme
1.648     raeburn  6233:              redirect       -> see &headtag()
                   6234:              bgcolor        -> override the default page bg color
                   6235:              js_ready       -> return a string ready for being used in 
1.317     albertel 6236:                                     a javascript writeln
1.648     raeburn  6237:              html_encode    -> return a string ready for being used in 
1.320     albertel 6238:                                     a html attribute
1.648     raeburn  6239:              force_register -> if is true will turn on the &bodytag()
1.317     albertel 6240:                                     $forcereg arg
1.648     raeburn  6241:              body_title     -> alternate text to use instead of $title
1.326     albertel 6242:                                     in the title box that appears, this text
                   6243:                                     is not auto translated like the $title is
1.648     raeburn  6244:              frameset       -> if true will start with a <frameset>
1.330     albertel 6245:                                     rather than <body>
1.648     raeburn  6246:              no_title       -> if true the title bar won't be shown
                   6247:              skip_phases    -> hash ref of 
1.338     albertel 6248:                                     head -> skip the <html><head> generation
                   6249:                                     body -> skip all <body> generation
1.648     raeburn  6250:              no_inline_link -> if true and in remote mode, don't show the 
1.361     albertel 6251:                                     'Switch To Inline Menu' link
1.648     raeburn  6252:              no_auto_mt_title -> prevent &mt()ing the title arg
                   6253:              inherit_jsmath -> when creating popup window in a page,
                   6254:                                     should it have jsmath forced on by the
                   6255:                                     current page
1.361     albertel 6256: 
1.648     raeburn  6257: =back
1.460     albertel 6258: 
1.648     raeburn  6259: =back
1.562     albertel 6260: 
1.306     albertel 6261: =cut
                   6262: 
                   6263: sub start_page {
1.309     albertel 6264:     my ($title,$head_extra,$args) = @_;
1.318     albertel 6265:     #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313     albertel 6266:     my %head_args;
1.352     albertel 6267:     foreach my $arg ('redirect','force_register','domain','function',
1.460     albertel 6268: 		     'bgcolor','frameset','no_nav_bar','only_body',
                   6269: 		     'no_auto_mt_title') {
1.319     albertel 6270: 	if (defined($args->{$arg})) {
1.324     raeburn  6271: 	    $head_args{$arg} = $args->{$arg};
1.319     albertel 6272: 	}
1.313     albertel 6273:     }
1.319     albertel 6274: 
1.315     albertel 6275:     $env{'internal.start_page'}++;
1.338     albertel 6276:     my $result;
                   6277:     if (! exists($args->{'skip_phases'}{'head'}) ) {
                   6278: 	$result.=
1.341     albertel 6279: 	    &xml_begin().
1.338     albertel 6280: 	    &headtag($title,$head_extra,\%head_args).&endheadtag();
                   6281:     }
                   6282:     
                   6283:     if (! exists($args->{'skip_phases'}{'body'}) ) {
                   6284: 	if ($args->{'frameset'}) {
                   6285: 	    my $attr_string = &make_attr_string($args->{'force_register'},
                   6286: 						$args->{'add_entries'});
                   6287: 	    $result .= "\n<frameset $attr_string>\n";
                   6288: 	} else {
                   6289: 	    $result .=
                   6290: 		&bodytag($title, 
                   6291: 			 $args->{'function'},       $args->{'add_entries'},
                   6292: 			 $args->{'only_body'},      $args->{'domain'},
                   6293: 			 $args->{'force_register'}, $args->{'body_title'},
                   6294: 			 $args->{'no_nav_bar'},     $args->{'bgcolor'},
1.460     albertel 6295: 			 $args->{'no_title'},       $args->{'no_inline_link'},
                   6296: 			 $args);
1.338     albertel 6297: 	}
1.330     albertel 6298:     }
1.338     albertel 6299: 
1.315     albertel 6300:     if ($args->{'js_ready'}) {
1.713     kaisler  6301: 		$result = &js_ready($result);
1.315     albertel 6302:     }
1.320     albertel 6303:     if ($args->{'html_encode'}) {
1.713     kaisler  6304: 		$result = &html_encode($result);
                   6305:     }
                   6306: 
1.758     kaisler  6307: 	#Breadcrumbs
                   6308:     if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
                   6309: 		&Apache::lonhtmlcommon::clear_breadcrumbs();
                   6310: 		#if any br links exists, add them to the breadcrumbs
                   6311: 		if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {         
                   6312: 			foreach my $crumb (@{$args->{'bread_crumbs'}}){
                   6313: 				&Apache::lonhtmlcommon::add_breadcrumb($crumb);
                   6314: 			}
                   6315: 		}
                   6316: 
                   6317: 		#if bread_crumbs_component exists show it as headline else show only the breadcrumbs
                   6318: 		if(exists($args->{'bread_crumbs_component'})){
                   6319: 			$result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
                   6320: 		}else{
                   6321: 			$result .= &Apache::lonhtmlcommon::breadcrumbs();
                   6322: 		}
1.320     albertel 6323:     }
1.315     albertel 6324:     return $result;
1.306     albertel 6325: }
                   6326: 
1.330     albertel 6327: 
1.306     albertel 6328: =pod
                   6329: 
                   6330: =item * &head()
                   6331: 
                   6332: Returns a complete </body></html> section for LON-CAPA web pages.
                   6333: 
1.315     albertel 6334: Inputs:         $args - additional optional args supported are:
                   6335:                  js_ready     -> return a string ready for being used in 
                   6336:                                  a javascript writeln
1.320     albertel 6337:                  html_encode  -> return a string ready for being used in 
                   6338:                                  a html attribute
1.330     albertel 6339:                  frameset     -> if true will start with a <frameset>
                   6340:                                  rather than <body>
1.493     albertel 6341:                  dicsussion   -> if true will get discussion from
                   6342:                                   lonxml::xmlend
                   6343:                                  (you can pass the target and parser arguments
                   6344:                                   through optional 'target' and 'parser' args
                   6345:                                   to this routine)
1.306     albertel 6346: 
                   6347: =cut
                   6348: 
                   6349: sub end_page {
1.315     albertel 6350:     my ($args) = @_;
                   6351:     $env{'internal.end_page'}++;
1.330     albertel 6352:     my $result;
1.335     albertel 6353:     if ($args->{'discussion'}) {
                   6354: 	my ($target,$parser);
                   6355: 	if (ref($args->{'discussion'})) {
                   6356: 	    ($target,$parser) =($args->{'discussion'}{'target'},
                   6357: 				$args->{'discussion'}{'parser'});
                   6358: 	}
                   6359: 	$result .= &Apache::lonxml::xmlend($target,$parser);
                   6360:     }
                   6361: 
1.330     albertel 6362:     if ($args->{'frameset'}) {
                   6363: 	$result .= '</frameset>';
                   6364:     } else {
1.635     raeburn  6365: 	$result .= &endbodytag($args);
1.330     albertel 6366:     }
                   6367:     $result .= "\n</html>";
                   6368: 
1.315     albertel 6369:     if ($args->{'js_ready'}) {
1.317     albertel 6370: 	$result = &js_ready($result);
1.315     albertel 6371:     }
1.335     albertel 6372: 
1.320     albertel 6373:     if ($args->{'html_encode'}) {
                   6374: 	$result = &html_encode($result);
                   6375:     }
1.335     albertel 6376: 
1.315     albertel 6377:     return $result;
                   6378: }
                   6379: 
1.320     albertel 6380: sub html_encode {
                   6381:     my ($result) = @_;
                   6382: 
1.322     albertel 6383:     $result = &HTML::Entities::encode($result,'<>&"');
1.320     albertel 6384:     
                   6385:     return $result;
                   6386: }
1.317     albertel 6387: sub js_ready {
                   6388:     my ($result) = @_;
                   6389: 
1.323     albertel 6390:     $result =~ s/[\n\r]/ /xmsg;
                   6391:     $result =~ s/\\/\\\\/xmsg;
                   6392:     $result =~ s/'/\\'/xmsg;
1.372     albertel 6393:     $result =~ s{</}{<\\/}xmsg;
1.317     albertel 6394:     
                   6395:     return $result;
                   6396: }
                   6397: 
1.315     albertel 6398: sub validate_page {
                   6399:     if (  exists($env{'internal.start_page'})
1.316     albertel 6400: 	  &&     $env{'internal.start_page'} > 1) {
                   6401: 	&Apache::lonnet::logthis('start_page called multiple times '.
1.318     albertel 6402: 				 $env{'internal.start_page'}.' '.
1.316     albertel 6403: 				 $ENV{'request.filename'});
1.315     albertel 6404:     }
                   6405:     if (  exists($env{'internal.end_page'})
1.316     albertel 6406: 	  &&     $env{'internal.end_page'} > 1) {
                   6407: 	&Apache::lonnet::logthis('end_page called multiple times '.
1.318     albertel 6408: 				 $env{'internal.end_page'}.' '.
1.316     albertel 6409: 				 $env{'request.filename'});
1.315     albertel 6410:     }
                   6411:     if (     exists($env{'internal.start_page'})
                   6412: 	&& ! exists($env{'internal.end_page'})) {
1.316     albertel 6413: 	&Apache::lonnet::logthis('start_page called without end_page '.
                   6414: 				 $env{'request.filename'});
1.315     albertel 6415:     }
                   6416:     if (   ! exists($env{'internal.start_page'})
                   6417: 	&&   exists($env{'internal.end_page'})) {
1.316     albertel 6418: 	&Apache::lonnet::logthis('end_page called without start_page'.
                   6419: 				 $env{'request.filename'});
1.315     albertel 6420:     }
1.306     albertel 6421: }
1.315     albertel 6422: 
1.318     albertel 6423: sub simple_error_page {
                   6424:     my ($r,$title,$msg) = @_;
                   6425:     my $page =
                   6426: 	&Apache::loncommon::start_page($title).
                   6427: 	&mt($msg).
                   6428: 	&Apache::loncommon::end_page();
                   6429:     if (ref($r)) {
                   6430: 	$r->print($page);
1.327     albertel 6431: 	return;
1.318     albertel 6432:     }
                   6433:     return $page;
                   6434: }
1.347     albertel 6435: 
                   6436: {
1.610     albertel 6437:     my @row_count;
1.347     albertel 6438:     sub start_data_table {
1.422     albertel 6439: 	my ($add_class) = @_;
                   6440: 	my $css_class = (join(' ','LC_data_table',$add_class));
1.610     albertel 6441: 	unshift(@row_count,0);
1.422     albertel 6442: 	return '<table class="'.$css_class.'">'."\n";
1.347     albertel 6443:     }
                   6444: 
                   6445:     sub end_data_table {
1.610     albertel 6446: 	shift(@row_count);
1.389     albertel 6447: 	return '</table>'."\n";;
1.347     albertel 6448:     }
                   6449: 
                   6450:     sub start_data_table_row {
1.422     albertel 6451: 	my ($add_class) = @_;
1.610     albertel 6452: 	$row_count[0]++;
                   6453: 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.428     albertel 6454: 	$css_class = (join(' ',$css_class,$add_class));
1.422     albertel 6455: 	return  '<tr class="'.$css_class.'">'."\n";;
1.347     albertel 6456:     }
1.471     banghart 6457:     
                   6458:     sub continue_data_table_row {
                   6459: 	my ($add_class) = @_;
1.610     albertel 6460: 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.471     banghart 6461: 	$css_class = (join(' ',$css_class,$add_class));
                   6462: 	return  '<tr class="'.$css_class.'">'."\n";;
                   6463:     }
1.347     albertel 6464: 
                   6465:     sub end_data_table_row {
1.389     albertel 6466: 	return '</tr>'."\n";;
1.347     albertel 6467:     }
1.367     www      6468: 
1.421     albertel 6469:     sub start_data_table_empty_row {
1.707     bisitz   6470: #	$row_count[0]++;
1.421     albertel 6471: 	return  '<tr class="LC_empty_row" >'."\n";;
                   6472:     }
                   6473: 
                   6474:     sub end_data_table_empty_row {
                   6475: 	return '</tr>'."\n";;
                   6476:     }
                   6477: 
1.367     www      6478:     sub start_data_table_header_row {
1.389     albertel 6479: 	return  '<tr class="LC_header_row">'."\n";;
1.367     www      6480:     }
                   6481: 
                   6482:     sub end_data_table_header_row {
1.389     albertel 6483: 	return '</tr>'."\n";;
1.367     www      6484:     }
1.347     albertel 6485: }
                   6486: 
1.548     albertel 6487: =pod
                   6488: 
                   6489: =item * &inhibit_menu_check($arg)
                   6490: 
                   6491: Checks for a inhibitmenu state and generates output to preserve it
                   6492: 
                   6493: Inputs:         $arg - can be any of
                   6494:                      - undef - in which case the return value is a string 
                   6495:                                to add  into arguments list of a uri
                   6496:                      - 'input' - in which case the return value is a HTML
                   6497:                                  <form> <input> field of type hidden to
                   6498:                                  preserve the value
                   6499:                      - a url - in which case the return value is the url with
                   6500:                                the neccesary cgi args added to preserve the
                   6501:                                inhibitmenu state
                   6502:                      - a ref to a url - no return value, but the string is
                   6503:                                         updated to include the neccessary cgi
                   6504:                                         args to preserve the inhibitmenu state
                   6505: 
                   6506: =cut
                   6507: 
                   6508: sub inhibit_menu_check {
                   6509:     my ($arg) = @_;
                   6510:     &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
                   6511:     if ($arg eq 'input') {
                   6512: 	if ($env{'form.inhibitmenu'}) {
                   6513: 	    return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
                   6514: 	} else {
                   6515: 	    return
                   6516: 	}
                   6517:     }
                   6518:     if ($env{'form.inhibitmenu'}) {
                   6519: 	if (ref($arg)) {
                   6520: 	    $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
                   6521: 	} elsif ($arg eq '') {
                   6522: 	    $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
                   6523: 	} else {
                   6524: 	    $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
                   6525: 	}
                   6526:     }
                   6527:     if (!ref($arg)) {
                   6528: 	return $arg;
                   6529:     }
                   6530: }
                   6531: 
1.251     albertel 6532: ###############################################
1.182     matthew  6533: 
                   6534: =pod
                   6535: 
1.549     albertel 6536: =back
                   6537: 
                   6538: =head1 User Information Routines
                   6539: 
                   6540: =over 4
                   6541: 
1.405     albertel 6542: =item * &get_users_function()
1.182     matthew  6543: 
                   6544: Used by &bodytag to determine the current users primary role.
                   6545: Returns either 'student','coordinator','admin', or 'author'.
                   6546: 
                   6547: =cut
                   6548: 
                   6549: ###############################################
                   6550: sub get_users_function {
                   6551:     my $function = 'student';
1.258     albertel 6552:     if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
1.182     matthew  6553:         $function='coordinator';
                   6554:     }
1.258     albertel 6555:     if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182     matthew  6556:         $function='admin';
                   6557:     }
1.258     albertel 6558:     if (($env{'request.role'}=~/^(au|ca)/) ||
1.182     matthew  6559:         ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
                   6560:         $function='author';
                   6561:     }
                   6562:     return $function;
1.54      www      6563: }
1.99      www      6564: 
                   6565: ###############################################
                   6566: 
1.233     raeburn  6567: =pod
                   6568: 
1.542     raeburn  6569: =item * &check_user_status()
1.274     raeburn  6570: 
                   6571: Determines current status of supplied role for a
                   6572: specific user. Roles can be active, previous or future.
                   6573: 
                   6574: Inputs: 
                   6575: user's domain, user's username, course's domain,
1.375     raeburn  6576: course's number, optional section ID.
1.274     raeburn  6577: 
                   6578: Outputs:
                   6579: role status: active, previous or future. 
                   6580: 
                   6581: =cut
                   6582: 
                   6583: sub check_user_status {
1.412     raeburn  6584:     my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274     raeburn  6585:     my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
                   6586:     my @uroles = keys %userinfo;
                   6587:     my $srchstr;
                   6588:     my $active_chk = 'none';
1.412     raeburn  6589:     my $now = time;
1.274     raeburn  6590:     if (@uroles > 0) {
1.412     raeburn  6591:         if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
1.274     raeburn  6592:             $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
                   6593:         } else {
1.412     raeburn  6594:             $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
                   6595:         }
                   6596:         if (grep/^\Q$srchstr\E$/,@uroles) {
1.274     raeburn  6597:             my $role_end = 0;
                   6598:             my $role_start = 0;
                   6599:             $active_chk = 'active';
1.412     raeburn  6600:             if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
                   6601:                 $role_end = $1;
                   6602:                 if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
                   6603:                     $role_start = $1;
1.274     raeburn  6604:                 }
                   6605:             }
                   6606:             if ($role_start > 0) {
1.412     raeburn  6607:                 if ($now < $role_start) {
1.274     raeburn  6608:                     $active_chk = 'future';
                   6609:                 }
                   6610:             }
                   6611:             if ($role_end > 0) {
1.412     raeburn  6612:                 if ($now > $role_end) {
1.274     raeburn  6613:                     $active_chk = 'previous';
                   6614:                 }
                   6615:             }
                   6616:         }
                   6617:     }
                   6618:     return $active_chk;
                   6619: }
                   6620: 
                   6621: ###############################################
                   6622: 
                   6623: =pod
                   6624: 
1.405     albertel 6625: =item * &get_sections()
1.233     raeburn  6626: 
                   6627: Determines all the sections for a course including
                   6628: sections with students and sections containing other roles.
1.419     raeburn  6629: Incoming parameters: 
                   6630: 
                   6631: 1. domain
                   6632: 2. course number 
                   6633: 3. reference to array containing roles for which sections should 
                   6634: be gathered (optional).
                   6635: 4. reference to array containing status types for which sections 
                   6636: should be gathered (optional).
                   6637: 
                   6638: If the third argument is undefined, sections are gathered for any role. 
                   6639: If the fourth argument is undefined, sections are gathered for any status.
                   6640: Permissible values are 'active' or 'future' or 'previous'.
1.233     raeburn  6641:  
1.374     raeburn  6642: Returns section hash (keys are section IDs, values are
                   6643: number of users in each section), subject to the
1.419     raeburn  6644: optional roles filter, optional status filter 
1.233     raeburn  6645: 
                   6646: =cut
                   6647: 
                   6648: ###############################################
                   6649: sub get_sections {
1.419     raeburn  6650:     my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366     albertel 6651:     if (!defined($cdom) || !defined($cnum)) {
                   6652:         my $cid =  $env{'request.course.id'};
                   6653: 
                   6654: 	return if (!defined($cid));
                   6655: 
                   6656:         $cdom = $env{'course.'.$cid.'.domain'};
                   6657:         $cnum = $env{'course.'.$cid.'.num'};
                   6658:     }
                   6659: 
                   6660:     my %sectioncount;
1.419     raeburn  6661:     my $now = time;
1.240     albertel 6662: 
1.366     albertel 6663:     if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276     albertel 6664: 	my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240     albertel 6665: 	my $sec_index = &Apache::loncoursedata::CL_SECTION();
                   6666: 	my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419     raeburn  6667:         my $start_index = &Apache::loncoursedata::CL_START();
                   6668:         my $end_index = &Apache::loncoursedata::CL_END();
                   6669:         my $status;
1.366     albertel 6670: 	while (my ($student,$data) = each(%$classlist)) {
1.419     raeburn  6671: 	    my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
                   6672: 				                     $data->[$status_index],
                   6673:                                                      $data->[$start_index],
                   6674:                                                      $data->[$end_index]);
                   6675:             if ($stu_status eq 'Active') {
                   6676:                 $status = 'active';
                   6677:             } elsif ($end < $now) {
                   6678:                 $status = 'previous';
                   6679:             } elsif ($start > $now) {
                   6680:                 $status = 'future';
                   6681:             } 
                   6682: 	    if ($section ne '-1' && $section !~ /^\s*$/) {
                   6683:                 if ((!defined($possible_status)) || (($status ne '') && 
                   6684:                     (grep/^\Q$status\E$/,@{$possible_status}))) { 
                   6685: 		    $sectioncount{$section}++;
                   6686:                 }
1.240     albertel 6687: 	    }
                   6688: 	}
                   6689:     }
                   6690:     my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   6691:     foreach my $user (sort(keys(%courseroles))) {
                   6692: 	if ($user !~ /^(\w{2})/) { next; }
                   6693: 	my ($role) = ($user =~ /^(\w{2})/);
                   6694: 	if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419     raeburn  6695: 	my ($section,$status);
1.240     albertel 6696: 	if ($role eq 'cr' &&
                   6697: 	    $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
                   6698: 	    $section=$1;
                   6699: 	}
                   6700: 	if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
                   6701: 	if (!defined($section) || $section eq '-1') { next; }
1.419     raeburn  6702:         my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
                   6703:         if ($end == -1 && $start == -1) {
                   6704:             next; #deleted role
                   6705:         }
                   6706:         if (!defined($possible_status)) { 
                   6707:             $sectioncount{$section}++;
                   6708:         } else {
                   6709:             if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
                   6710:                 $status = 'active';
                   6711:             } elsif ($end < $now) {
                   6712:                 $status = 'future';
                   6713:             } elsif ($start > $now) {
                   6714:                 $status = 'previous';
                   6715:             }
                   6716:             if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
                   6717:                 $sectioncount{$section}++;
                   6718:             }
                   6719:         }
1.233     raeburn  6720:     }
1.366     albertel 6721:     return %sectioncount;
1.233     raeburn  6722: }
                   6723: 
1.274     raeburn  6724: ###############################################
1.294     raeburn  6725: 
                   6726: =pod
1.405     albertel 6727: 
                   6728: =item * &get_course_users()
                   6729: 
1.275     raeburn  6730: Retrieves usernames:domains for users in the specified course
                   6731: with specific role(s), and access status. 
                   6732: 
                   6733: Incoming parameters:
1.277     albertel 6734: 1. course domain
                   6735: 2. course number
                   6736: 3. access status: users must have - either active, 
1.275     raeburn  6737: previous, future, or all.
1.277     albertel 6738: 4. reference to array of permissible roles
1.288     raeburn  6739: 5. reference to array of section restrictions (optional)
                   6740: 6. reference to results object (hash of hashes).
                   6741: 7. reference to optional userdata hash
1.609     raeburn  6742: 8. reference to optional statushash
1.630     raeburn  6743: 9. flag if privileged users (except those set to unhide in
                   6744:    course settings) should be excluded    
1.609     raeburn  6745: Keys of top level results hash are roles.
1.275     raeburn  6746: Keys of inner hashes are username:domain, with 
                   6747: values set to access type.
1.288     raeburn  6748: Optional userdata hash returns an array with arguments in the 
                   6749: same order as loncoursedata::get_classlist() for student data.
                   6750: 
1.609     raeburn  6751: Optional statushash returns
                   6752: 
1.288     raeburn  6753: Entries for end, start, section and status are blank because
                   6754: of the possibility of multiple values for non-student roles.
                   6755: 
1.275     raeburn  6756: =cut
1.405     albertel 6757: 
1.275     raeburn  6758: ###############################################
1.405     albertel 6759: 
1.275     raeburn  6760: sub get_course_users {
1.630     raeburn  6761:     my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288     raeburn  6762:     my %idx = ();
1.419     raeburn  6763:     my %seclists;
1.288     raeburn  6764: 
                   6765:     $idx{udom} = &Apache::loncoursedata::CL_SDOM();
                   6766:     $idx{uname} =  &Apache::loncoursedata::CL_SNAME();
                   6767:     $idx{end} = &Apache::loncoursedata::CL_END();
                   6768:     $idx{start} = &Apache::loncoursedata::CL_START();
                   6769:     $idx{id} = &Apache::loncoursedata::CL_ID();
                   6770:     $idx{section} = &Apache::loncoursedata::CL_SECTION();
                   6771:     $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
                   6772:     $idx{status} = &Apache::loncoursedata::CL_STATUS();
                   6773: 
1.290     albertel 6774:     if (grep(/^st$/,@{$roles})) {
1.276     albertel 6775:         my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278     raeburn  6776:         my $now = time;
1.277     albertel 6777:         foreach my $student (keys(%{$classlist})) {
1.288     raeburn  6778:             my $match = 0;
1.412     raeburn  6779:             my $secmatch = 0;
1.419     raeburn  6780:             my $section = $$classlist{$student}[$idx{section}];
1.609     raeburn  6781:             my $status = $$classlist{$student}[$idx{status}];
1.419     raeburn  6782:             if ($section eq '') {
                   6783:                 $section = 'none';
                   6784:             }
1.291     albertel 6785:             if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 6786:                 if (grep(/^all$/,@{$sections})) {
1.412     raeburn  6787:                     $secmatch = 1;
                   6788:                 } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420     albertel 6789:                     if (grep(/^none$/,@{$sections})) {
1.412     raeburn  6790:                         $secmatch = 1;
                   6791:                     }
                   6792:                 } else {  
1.419     raeburn  6793: 		    if (grep(/^\Q$section\E$/,@{$sections})) {
1.412     raeburn  6794: 		        $secmatch = 1;
                   6795:                     }
1.290     albertel 6796: 		}
1.412     raeburn  6797:                 if (!$secmatch) {
                   6798:                     next;
                   6799:                 }
1.419     raeburn  6800:             }
1.275     raeburn  6801:             if (defined($$types{'active'})) {
1.288     raeburn  6802:                 if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275     raeburn  6803:                     push(@{$$users{st}{$student}},'active');
1.288     raeburn  6804:                     $match = 1;
1.275     raeburn  6805:                 }
                   6806:             }
                   6807:             if (defined($$types{'previous'})) {
1.609     raeburn  6808:                 if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275     raeburn  6809:                     push(@{$$users{st}{$student}},'previous');
1.288     raeburn  6810:                     $match = 1;
1.275     raeburn  6811:                 }
                   6812:             }
                   6813:             if (defined($$types{'future'})) {
1.609     raeburn  6814:                 if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275     raeburn  6815:                     push(@{$$users{st}{$student}},'future');
1.288     raeburn  6816:                     $match = 1;
1.275     raeburn  6817:                 }
                   6818:             }
1.609     raeburn  6819:             if ($match) {
                   6820:                 push(@{$seclists{$student}},$section);
                   6821:                 if (ref($userdata) eq 'HASH') {
                   6822:                     $$userdata{$student} = $$classlist{$student};
                   6823:                 }
                   6824:                 if (ref($statushash) eq 'HASH') {
                   6825:                     $statushash->{$student}{'st'}{$section} = $status;
                   6826:                 }
1.288     raeburn  6827:             }
1.275     raeburn  6828:         }
                   6829:     }
1.412     raeburn  6830:     if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439     raeburn  6831:         my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   6832:         my $now = time;
1.609     raeburn  6833:         my %displaystatus = ( previous => 'Expired',
                   6834:                               active   => 'Active',
                   6835:                               future   => 'Future',
                   6836:                             );
1.630     raeburn  6837:         my %nothide;
                   6838:         if ($hidepriv) {
                   6839:             my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
                   6840:             foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
                   6841:                 if ($user !~ /:/) {
                   6842:                     $nothide{join(':',split(/[\@]/,$user))}=1;
                   6843:                 } else {
                   6844:                     $nothide{$user} = 1;
                   6845:                 }
                   6846:             }
                   6847:         }
1.439     raeburn  6848:         foreach my $person (sort(keys(%coursepersonnel))) {
1.288     raeburn  6849:             my $match = 0;
1.412     raeburn  6850:             my $secmatch = 0;
1.439     raeburn  6851:             my $status;
1.412     raeburn  6852:             my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275     raeburn  6853:             $user =~ s/:$//;
1.439     raeburn  6854:             my ($end,$start) = split(/:/,$coursepersonnel{$person});
                   6855:             if ($end == -1 || $start == -1) {
                   6856:                 next;
                   6857:             }
                   6858:             if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
                   6859:                 (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412     raeburn  6860:                 my ($uname,$udom) = split(/:/,$user);
                   6861:                 if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 6862:                     if (grep(/^all$/,@{$sections})) {
1.412     raeburn  6863:                         $secmatch = 1;
                   6864:                     } elsif ($usec eq '') {
1.420     albertel 6865:                         if (grep(/^none$/,@{$sections})) {
1.412     raeburn  6866:                             $secmatch = 1;
                   6867:                         }
                   6868:                     } else {
                   6869:                         if (grep(/^\Q$usec\E$/,@{$sections})) {
                   6870:                             $secmatch = 1;
                   6871:                         }
                   6872:                     }
                   6873:                     if (!$secmatch) {
                   6874:                         next;
                   6875:                     }
1.288     raeburn  6876:                 }
1.419     raeburn  6877:                 if ($usec eq '') {
                   6878:                     $usec = 'none';
                   6879:                 }
1.275     raeburn  6880:                 if ($uname ne '' && $udom ne '') {
1.630     raeburn  6881:                     if ($hidepriv) {
                   6882:                         if ((&Apache::lonnet::privileged($uname,$udom)) &&
                   6883:                             (!$nothide{$uname.':'.$udom})) {
                   6884:                             next;
                   6885:                         }
                   6886:                     }
1.503     raeburn  6887:                     if ($end > 0 && $end < $now) {
1.439     raeburn  6888:                         $status = 'previous';
                   6889:                     } elsif ($start > $now) {
                   6890:                         $status = 'future';
                   6891:                     } else {
                   6892:                         $status = 'active';
                   6893:                     }
1.277     albertel 6894:                     foreach my $type (keys(%{$types})) { 
1.275     raeburn  6895:                         if ($status eq $type) {
1.420     albertel 6896:                             if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419     raeburn  6897:                                 push(@{$$users{$role}{$user}},$type);
                   6898:                             }
1.288     raeburn  6899:                             $match = 1;
                   6900:                         }
                   6901:                     }
1.419     raeburn  6902:                     if (($match) && (ref($userdata) eq 'HASH')) {
                   6903:                         if (!exists($$userdata{$uname.':'.$udom})) {
                   6904: 			    &get_user_info($udom,$uname,\%idx,$userdata);
                   6905:                         }
1.420     albertel 6906:                         if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419     raeburn  6907:                             push(@{$seclists{$uname.':'.$udom}},$usec);
                   6908:                         }
1.609     raeburn  6909:                         if (ref($statushash) eq 'HASH') {
                   6910:                             $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
                   6911:                         }
1.275     raeburn  6912:                     }
                   6913:                 }
                   6914:             }
                   6915:         }
1.290     albertel 6916:         if (grep(/^ow$/,@{$roles})) {
1.279     raeburn  6917:             if ((defined($cdom)) && (defined($cnum))) {
                   6918:                 my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
                   6919:                 if ( defined($csettings{'internal.courseowner'}) ) {
                   6920:                     my $owner = $csettings{'internal.courseowner'};
1.609     raeburn  6921:                     next if ($owner eq '');
                   6922:                     my ($ownername,$ownerdom);
                   6923:                     if ($owner =~ /^([^:]+):([^:]+)$/) {
                   6924:                         $ownername = $1;
                   6925:                         $ownerdom = $2;
                   6926:                     } else {
                   6927:                         $ownername = $owner;
                   6928:                         $ownerdom = $cdom;
                   6929:                         $owner = $ownername.':'.$ownerdom;
1.439     raeburn  6930:                     }
                   6931:                     @{$$users{'ow'}{$owner}} = 'any';
1.290     albertel 6932:                     if (defined($userdata) && 
1.609     raeburn  6933: 			!exists($$userdata{$owner})) {
                   6934: 			&get_user_info($ownerdom,$ownername,\%idx,$userdata);
                   6935:                         if (!grep(/^none$/,@{$seclists{$owner}})) {
                   6936:                             push(@{$seclists{$owner}},'none');
                   6937:                         }
                   6938:                         if (ref($statushash) eq 'HASH') {
                   6939:                             $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419     raeburn  6940:                         }
1.290     albertel 6941: 		    }
1.279     raeburn  6942:                 }
                   6943:             }
                   6944:         }
1.419     raeburn  6945:         foreach my $user (keys(%seclists)) {
                   6946:             @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
                   6947:             $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
                   6948:         }
1.275     raeburn  6949:     }
                   6950:     return;
                   6951: }
                   6952: 
1.288     raeburn  6953: sub get_user_info {
                   6954:     my ($udom,$uname,$idx,$userdata) = @_;
1.289     albertel 6955:     $$userdata{$uname.':'.$udom}[$$idx{fullname}] = 
                   6956: 	&plainname($uname,$udom,'lastname');
1.291     albertel 6957:     $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297     raeburn  6958:     $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609     raeburn  6959:     my %idhash =  &Apache::lonnet::idrget($udom,($uname));
                   6960:     $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname}; 
1.288     raeburn  6961:     return;
                   6962: }
1.275     raeburn  6963: 
1.472     raeburn  6964: ###############################################
                   6965: 
                   6966: =pod
                   6967: 
                   6968: =item * &get_user_quota()
                   6969: 
                   6970: Retrieves quota assigned for storage of portfolio files for a user  
                   6971: 
                   6972: Incoming parameters:
                   6973: 1. user's username
                   6974: 2. user's domain
                   6975: 
                   6976: Returns:
1.536     raeburn  6977: 1. Disk quota (in Mb) assigned to student.
                   6978: 2. (Optional) Type of setting: custom or default
                   6979:    (individually assigned or default for user's 
                   6980:    institutional status).
                   6981: 3. (Optional) - User's institutional status (e.g., faculty, staff
                   6982:    or student - types as defined in localenroll::inst_usertypes 
                   6983:    for user's domain, which determines default quota for user.
                   6984: 4. (Optional) - Default quota which would apply to the user.
1.472     raeburn  6985: 
                   6986: If a value has been stored in the user's environment, 
1.536     raeburn  6987: it will return that, otherwise it returns the maximal default
                   6988: defined for the user's instituional status(es) in the domain.
1.472     raeburn  6989: 
                   6990: =cut
                   6991: 
                   6992: ###############################################
                   6993: 
                   6994: 
                   6995: sub get_user_quota {
                   6996:     my ($uname,$udom) = @_;
1.536     raeburn  6997:     my ($quota,$quotatype,$settingstatus,$defquota);
1.472     raeburn  6998:     if (!defined($udom)) {
                   6999:         $udom = $env{'user.domain'};
                   7000:     }
                   7001:     if (!defined($uname)) {
                   7002:         $uname = $env{'user.name'};
                   7003:     }
                   7004:     if (($udom eq '' || $uname eq '') ||
                   7005:         ($udom eq 'public') && ($uname eq 'public')) {
                   7006:         $quota = 0;
1.536     raeburn  7007:         $quotatype = 'default';
                   7008:         $defquota = 0; 
1.472     raeburn  7009:     } else {
1.536     raeburn  7010:         my $inststatus;
1.472     raeburn  7011:         if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
                   7012:             $quota = $env{'environment.portfolioquota'};
1.536     raeburn  7013:             $inststatus = $env{'environment.inststatus'};
1.472     raeburn  7014:         } else {
1.536     raeburn  7015:             my %userenv = 
                   7016:                 &Apache::lonnet::get('environment',['portfolioquota',
                   7017:                                      'inststatus'],$udom,$uname);
1.472     raeburn  7018:             my ($tmp) = keys(%userenv);
                   7019:             if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   7020:                 $quota = $userenv{'portfolioquota'};
1.536     raeburn  7021:                 $inststatus = $userenv{'inststatus'};
1.472     raeburn  7022:             } else {
                   7023:                 undef(%userenv);
                   7024:             }
                   7025:         }
1.536     raeburn  7026:         ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472     raeburn  7027:         if ($quota eq '') {
1.536     raeburn  7028:             $quota = $defquota;
                   7029:             $quotatype = 'default';
                   7030:         } else {
                   7031:             $quotatype = 'custom';
1.472     raeburn  7032:         }
                   7033:     }
1.536     raeburn  7034:     if (wantarray) {
                   7035:         return ($quota,$quotatype,$settingstatus,$defquota);
                   7036:     } else {
                   7037:         return $quota;
                   7038:     }
1.472     raeburn  7039: }
                   7040: 
                   7041: ###############################################
                   7042: 
                   7043: =pod
                   7044: 
                   7045: =item * &default_quota()
                   7046: 
1.536     raeburn  7047: Retrieves default quota assigned for storage of user portfolio files,
                   7048: given an (optional) user's institutional status.
1.472     raeburn  7049: 
                   7050: Incoming parameters:
                   7051: 1. domain
1.536     raeburn  7052: 2. (Optional) institutional status(es).  This is a : separated list of 
                   7053:    status types (e.g., faculty, staff, student etc.)
                   7054:    which apply to the user for whom the default is being retrieved.
                   7055:    If the institutional status string in undefined, the domain
                   7056:    default quota will be returned. 
1.472     raeburn  7057: 
                   7058: Returns:
                   7059: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536     raeburn  7060: 2. (Optional) institutional type which determined the value of the
                   7061:    default quota.
1.472     raeburn  7062: 
                   7063: If a value has been stored in the domain's configuration db,
                   7064: it will return that, otherwise it returns 20 (for backwards 
                   7065: compatibility with domains which have not set up a configuration
                   7066: db file; the original statically defined portfolio quota was 20 Mb). 
                   7067: 
1.536     raeburn  7068: If the user's status includes multiple types (e.g., staff and student),
                   7069: the largest default quota which applies to the user determines the
                   7070: default quota returned.
                   7071: 
1.780     raeburn  7072: =back
                   7073: 
1.472     raeburn  7074: =cut
                   7075: 
                   7076: ###############################################
                   7077: 
                   7078: 
                   7079: sub default_quota {
1.536     raeburn  7080:     my ($udom,$inststatus) = @_;
                   7081:     my ($defquota,$settingstatus);
                   7082:     my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622     raeburn  7083:                                             ['quotas'],$udom);
                   7084:     if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536     raeburn  7085:         if ($inststatus ne '') {
1.765     raeburn  7086:             my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536     raeburn  7087:             foreach my $item (@statuses) {
1.711     raeburn  7088:                 if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
                   7089:                     if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
                   7090:                         if ($defquota eq '') {
                   7091:                             $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
                   7092:                             $settingstatus = $item;
                   7093:                         } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
                   7094:                             $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
                   7095:                             $settingstatus = $item;
                   7096:                         }
                   7097:                     }
                   7098:                 } else {
                   7099:                     if ($quotahash{'quotas'}{$item} ne '') {
                   7100:                         if ($defquota eq '') {
                   7101:                             $defquota = $quotahash{'quotas'}{$item};
                   7102:                             $settingstatus = $item;
                   7103:                         } elsif ($quotahash{'quotas'}{$item} > $defquota) {
                   7104:                             $defquota = $quotahash{'quotas'}{$item};
                   7105:                             $settingstatus = $item;
                   7106:                         }
1.536     raeburn  7107:                     }
                   7108:                 }
                   7109:             }
                   7110:         }
                   7111:         if ($defquota eq '') {
1.711     raeburn  7112:             if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
                   7113:                 $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
                   7114:             } else {
                   7115:                 $defquota = $quotahash{'quotas'}{'default'};
                   7116:             }
1.536     raeburn  7117:             $settingstatus = 'default';
                   7118:         }
                   7119:     } else {
                   7120:         $settingstatus = 'default';
                   7121:         $defquota = 20;
                   7122:     }
                   7123:     if (wantarray) {
                   7124:         return ($defquota,$settingstatus);
1.472     raeburn  7125:     } else {
1.536     raeburn  7126:         return $defquota;
1.472     raeburn  7127:     }
                   7128: }
                   7129: 
1.384     raeburn  7130: sub get_secgrprole_info {
                   7131:     my ($cdom,$cnum,$needroles,$type)  = @_;
                   7132:     my %sections_count = &get_sections($cdom,$cnum);
                   7133:     my @sections =  (sort {$a <=> $b} keys(%sections_count));
                   7134:     my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
                   7135:     my @groups = sort(keys(%curr_groups));
                   7136:     my $allroles = [];
                   7137:     my $rolehash;
                   7138:     my $accesshash = {
                   7139:                      active => 'Currently has access',
                   7140:                      future => 'Will have future access',
                   7141:                      previous => 'Previously had access',
                   7142:                   };
                   7143:     if ($needroles) {
                   7144:         $rolehash = {'all' => 'all'};
1.385     albertel 7145:         my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   7146: 	if (&Apache::lonnet::error(%user_roles)) {
                   7147: 	    undef(%user_roles);
                   7148: 	}
                   7149:         foreach my $item (keys(%user_roles)) {
1.384     raeburn  7150:             my ($role)=split(/\:/,$item,2);
                   7151:             if ($role eq 'cr') { next; }
                   7152:             if ($role =~ /^cr/) {
                   7153:                 $$rolehash{$role} = (split('/',$role))[3];
                   7154:             } else {
                   7155:                 $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
                   7156:             }
                   7157:         }
                   7158:         foreach my $key (sort(keys(%{$rolehash}))) {
                   7159:             push(@{$allroles},$key);
                   7160:         }
                   7161:         push (@{$allroles},'st');
                   7162:         $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
                   7163:     }
                   7164:     return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
                   7165: }
                   7166: 
1.555     raeburn  7167: sub user_picker {
1.627     raeburn  7168:     my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555     raeburn  7169:     my $currdom = $dom;
                   7170:     my %curr_selected = (
                   7171:                         srchin => 'dom',
1.580     raeburn  7172:                         srchby => 'lastname',
1.555     raeburn  7173:                       );
                   7174:     my $srchterm;
1.625     raeburn  7175:     if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555     raeburn  7176:         if ($srch->{'srchby'} ne '') {
                   7177:             $curr_selected{'srchby'} = $srch->{'srchby'};
                   7178:         }
                   7179:         if ($srch->{'srchin'} ne '') {
                   7180:             $curr_selected{'srchin'} = $srch->{'srchin'};
                   7181:         }
                   7182:         if ($srch->{'srchtype'} ne '') {
                   7183:             $curr_selected{'srchtype'} = $srch->{'srchtype'};
                   7184:         }
                   7185:         if ($srch->{'srchdomain'} ne '') {
                   7186:             $currdom = $srch->{'srchdomain'};
                   7187:         }
                   7188:         $srchterm = $srch->{'srchterm'};
                   7189:     }
                   7190:     my %lt=&Apache::lonlocal::texthash(
1.573     raeburn  7191:                     'usr'       => 'Search criteria',
1.563     raeburn  7192:                     'doma'      => 'Domain/institution to search',
1.558     albertel 7193:                     'uname'     => 'username',
                   7194:                     'lastname'  => 'last name',
1.555     raeburn  7195:                     'lastfirst' => 'last name, first name',
1.558     albertel 7196:                     'crs'       => 'in this course',
1.576     raeburn  7197:                     'dom'       => 'in selected LON-CAPA domain', 
1.558     albertel 7198:                     'alc'       => 'all LON-CAPA',
1.573     raeburn  7199:                     'instd'     => 'in institutional directory for selected domain',
1.558     albertel 7200:                     'exact'     => 'is',
                   7201:                     'contains'  => 'contains',
1.569     raeburn  7202:                     'begins'    => 'begins with',
1.571     raeburn  7203:                     'youm'      => "You must include some text to search for.",
                   7204:                     'thte'      => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
                   7205:                     'thet'      => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
                   7206:                     'yomc'      => "You must choose a domain when using an institutional directory search.",
                   7207:                     'ymcd'      => "You must choose a domain when using a domain search.",
                   7208:                     'whus'      => "When using searching by last,first you must include a comma as separator between last name and first name.",
                   7209:                     'whse'      => "When searching by last,first you must include at least one character in the first name.",
                   7210:                      'thfo'     => "The following need to be corrected before the search can be run:",
1.555     raeburn  7211:                                        );
1.563     raeburn  7212:     my $domform = &select_dom_form($currdom,'srchdomain',1,1);
                   7213:     my $srchinsel = ' <select name="srchin">';
1.555     raeburn  7214: 
                   7215:     my @srchins = ('crs','dom','alc','instd');
                   7216: 
                   7217:     foreach my $option (@srchins) {
                   7218:         # FIXME 'alc' option unavailable until 
                   7219:         #       loncreateuser::print_user_query_page()
                   7220:         #       has been completed.
                   7221:         next if ($option eq 'alc');
                   7222:         next if ($option eq 'crs' && !$env{'request.course.id'});
1.563     raeburn  7223:         if ($curr_selected{'srchin'} eq $option) {
                   7224:             $srchinsel .= ' 
                   7225:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7226:         } else {
                   7227:             $srchinsel .= '
                   7228:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7229:         }
1.555     raeburn  7230:     }
1.563     raeburn  7231:     $srchinsel .= "\n  </select>\n";
1.555     raeburn  7232: 
                   7233:     my $srchbysel =  ' <select name="srchby">';
1.580     raeburn  7234:     foreach my $option ('lastname','lastfirst','uname') {
1.555     raeburn  7235:         if ($curr_selected{'srchby'} eq $option) {
                   7236:             $srchbysel .= '
                   7237:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7238:         } else {
                   7239:             $srchbysel .= '
                   7240:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7241:          }
                   7242:     }
                   7243:     $srchbysel .= "\n  </select>\n";
                   7244: 
                   7245:     my $srchtypesel = ' <select name="srchtype">';
1.580     raeburn  7246:     foreach my $option ('begins','contains','exact') {
1.555     raeburn  7247:         if ($curr_selected{'srchtype'} eq $option) {
                   7248:             $srchtypesel .= '
                   7249:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7250:         } else {
                   7251:             $srchtypesel .= '
                   7252:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7253:         }
                   7254:     }
                   7255:     $srchtypesel .= "\n  </select>\n";
                   7256: 
1.558     albertel 7257:     my ($newuserscript,$new_user_create);
1.556     raeburn  7258: 
                   7259:     if ($forcenewuser) {
1.576     raeburn  7260:         if (ref($srch) eq 'HASH') {
                   7261:             if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627     raeburn  7262:                 if ($cancreate) {
                   7263:                     $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>';
                   7264:                 } else {
                   7265:                     my $helplink = ' href="javascript:helpMenu('."'display'".')"';
                   7266:                     my %usertypetext = (
                   7267:                         official   => 'institutional',
                   7268:                         unofficial => 'non-institutional',
                   7269:                     );
                   7270:                     $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 />';
                   7271:                 }
1.576     raeburn  7272:             }
                   7273:         }
                   7274: 
1.556     raeburn  7275:         $newuserscript = <<"ENDSCRIPT";
                   7276: 
1.570     raeburn  7277: function setSearch(createnew,callingForm) {
1.556     raeburn  7278:     if (createnew == 1) {
1.570     raeburn  7279:         for (var i=0; i<callingForm.srchby.length; i++) {
                   7280:             if (callingForm.srchby.options[i].value == 'uname') {
                   7281:                 callingForm.srchby.selectedIndex = i;
1.556     raeburn  7282:             }
                   7283:         }
1.570     raeburn  7284:         for (var i=0; i<callingForm.srchin.length; i++) {
                   7285:             if ( callingForm.srchin.options[i].value == 'dom') {
                   7286: 		callingForm.srchin.selectedIndex = i;
1.556     raeburn  7287:             }
                   7288:         }
1.570     raeburn  7289:         for (var i=0; i<callingForm.srchtype.length; i++) {
                   7290:             if (callingForm.srchtype.options[i].value == 'exact') {
                   7291:                 callingForm.srchtype.selectedIndex = i;
1.556     raeburn  7292:             }
                   7293:         }
1.570     raeburn  7294:         for (var i=0; i<callingForm.srchdomain.length; i++) {
                   7295:             if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
                   7296:                 callingForm.srchdomain.selectedIndex = i;
1.556     raeburn  7297:             }
                   7298:         }
                   7299:     }
                   7300: }
                   7301: ENDSCRIPT
1.558     albertel 7302: 
1.556     raeburn  7303:     }
                   7304: 
1.555     raeburn  7305:     my $output = <<"END_BLOCK";
1.556     raeburn  7306: <script type="text/javascript">
1.570     raeburn  7307: function validateEntry(callingForm) {
1.558     albertel 7308: 
1.556     raeburn  7309:     var checkok = 1;
1.558     albertel 7310:     var srchin;
1.570     raeburn  7311:     for (var i=0; i<callingForm.srchin.length; i++) {
                   7312: 	if ( callingForm.srchin[i].checked ) {
                   7313: 	    srchin = callingForm.srchin[i].value;
1.558     albertel 7314: 	}
                   7315:     }
                   7316: 
1.570     raeburn  7317:     var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
                   7318:     var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
                   7319:     var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
                   7320:     var srchterm =  callingForm.srchterm.value;
                   7321:     var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556     raeburn  7322:     var msg = "";
                   7323: 
                   7324:     if (srchterm == "") {
                   7325:         checkok = 0;
1.571     raeburn  7326:         msg += "$lt{'youm'}\\n";
1.556     raeburn  7327:     }
                   7328: 
1.569     raeburn  7329:     if (srchtype== 'begins') {
                   7330:         if (srchterm.length < 2) {
                   7331:             checkok = 0;
1.571     raeburn  7332:             msg += "$lt{'thte'}\\n";
1.569     raeburn  7333:         }
                   7334:     }
                   7335: 
1.556     raeburn  7336:     if (srchtype== 'contains') {
                   7337:         if (srchterm.length < 3) {
                   7338:             checkok = 0;
1.571     raeburn  7339:             msg += "$lt{'thet'}\\n";
1.556     raeburn  7340:         }
                   7341:     }
                   7342:     if (srchin == 'instd') {
                   7343:         if (srchdomain == '') {
                   7344:             checkok = 0;
1.571     raeburn  7345:             msg += "$lt{'yomc'}\\n";
1.556     raeburn  7346:         }
                   7347:     }
                   7348:     if (srchin == 'dom') {
                   7349:         if (srchdomain == '') {
                   7350:             checkok = 0;
1.571     raeburn  7351:             msg += "$lt{'ymcd'}\\n";
1.556     raeburn  7352:         }
                   7353:     }
                   7354:     if (srchby == 'lastfirst') {
                   7355:         if (srchterm.indexOf(",") == -1) {
                   7356:             checkok = 0;
1.571     raeburn  7357:             msg += "$lt{'whus'}\\n";
1.556     raeburn  7358:         }
                   7359:         if (srchterm.indexOf(",") == srchterm.length -1) {
                   7360:             checkok = 0;
1.571     raeburn  7361:             msg += "$lt{'whse'}\\n";
1.556     raeburn  7362:         }
                   7363:     }
                   7364:     if (checkok == 0) {
1.571     raeburn  7365:         alert("$lt{'thfo'}\\n"+msg);
1.556     raeburn  7366:         return;
                   7367:     }
                   7368:     if (checkok == 1) {
1.570     raeburn  7369:         callingForm.submit();
1.556     raeburn  7370:     }
                   7371: }
                   7372: 
                   7373: $newuserscript
                   7374: 
                   7375: </script>
1.558     albertel 7376: 
                   7377: $new_user_create
                   7378: 
1.555     raeburn  7379: <table>
1.558     albertel 7380:  <tr>
1.573     raeburn  7381:   <td>$lt{'doma'}:</td>
                   7382:   <td>$domform</td>
                   7383:   </td>
                   7384:  </tr>
                   7385:  <tr>
                   7386:   <td>$lt{'usr'}:</td>
1.563     raeburn  7387:   <td>$srchbysel
                   7388:       $srchtypesel 
                   7389:       <input type="text" size="15" name="srchterm" value="$srchterm" />
1.564     albertel 7390:       $srchinsel 
1.563     raeburn  7391:   </td>
                   7392:  </tr>
1.555     raeburn  7393: </table>
                   7394: <br />
                   7395: END_BLOCK
1.558     albertel 7396: 
1.555     raeburn  7397:     return $output;
                   7398: }
                   7399: 
1.612     raeburn  7400: sub user_rule_check {
1.615     raeburn  7401:     my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612     raeburn  7402:     my $response;
                   7403:     if (ref($usershash) eq 'HASH') {
                   7404:         foreach my $user (keys(%{$usershash})) {
                   7405:             my ($uname,$udom) = split(/:/,$user);
                   7406:             next if ($udom eq '' || $uname eq '');
1.615     raeburn  7407:             my ($id,$newuser);
1.612     raeburn  7408:             if (ref($usershash->{$user}) eq 'HASH') {
1.615     raeburn  7409:                 $newuser = $usershash->{$user}->{'newuser'};
1.612     raeburn  7410:                 $id = $usershash->{$user}->{'id'};
                   7411:             }
                   7412:             my $inst_response;
                   7413:             if (ref($checks) eq 'HASH') {
                   7414:                 if (defined($checks->{'username'})) {
1.615     raeburn  7415:                     ($inst_response,%{$inst_results->{$user}}) = 
1.612     raeburn  7416:                         &Apache::lonnet::get_instuser($udom,$uname);
                   7417:                 } elsif (defined($checks->{'id'})) {
1.615     raeburn  7418:                     ($inst_response,%{$inst_results->{$user}}) =
1.612     raeburn  7419:                         &Apache::lonnet::get_instuser($udom,undef,$id);
                   7420:                 }
1.615     raeburn  7421:             } else {
                   7422:                 ($inst_response,%{$inst_results->{$user}}) =
                   7423:                     &Apache::lonnet::get_instuser($udom,$uname);
                   7424:                 return;
1.612     raeburn  7425:             }
1.615     raeburn  7426:             if (!$got_rules->{$udom}) {
1.612     raeburn  7427:                 my %domconfig = &Apache::lonnet::get_dom('configuration',
                   7428:                                                   ['usercreation'],$udom);
                   7429:                 if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615     raeburn  7430:                     foreach my $item ('username','id') {
1.612     raeburn  7431:                         if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
                   7432:                             $$curr_rules{$udom}{$item} = 
                   7433:                                 $domconfig{'usercreation'}{$item.'_rule'};
1.585     raeburn  7434:                         }
                   7435:                     }
                   7436:                 }
1.615     raeburn  7437:                 $got_rules->{$udom} = 1;  
1.585     raeburn  7438:             }
1.612     raeburn  7439:             foreach my $item (keys(%{$checks})) {
                   7440:                 if (ref($$curr_rules{$udom}) eq 'HASH') {
                   7441:                     if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
                   7442:                         if (@{$$curr_rules{$udom}{$item}} > 0) {
                   7443:                             my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
                   7444:                             foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
                   7445:                                 if ($rule_check{$rule}) {
                   7446:                                     $$rulematch{$user}{$item} = $rule;
                   7447:                                     if ($inst_response eq 'ok') {
1.615     raeburn  7448:                                         if (ref($inst_results) eq 'HASH') {
                   7449:                                             if (ref($inst_results->{$user}) eq 'HASH') {
                   7450:                                                 if (keys(%{$inst_results->{$user}}) == 0) {
                   7451:                                                     $$alerts{$item}{$udom}{$uname} = 1;
                   7452:                                                 }
1.612     raeburn  7453:                                             }
                   7454:                                         }
1.615     raeburn  7455:                                     }
                   7456:                                     last;
1.585     raeburn  7457:                                 }
                   7458:                             }
                   7459:                         }
                   7460:                     }
                   7461:                 }
                   7462:             }
                   7463:         }
                   7464:     }
1.612     raeburn  7465:     return;
                   7466: }
                   7467: 
                   7468: sub user_rule_formats {
                   7469:     my ($domain,$domdesc,$curr_rules,$check) = @_;
                   7470:     my %text = ( 
                   7471:                  'username' => 'Usernames',
                   7472:                  'id'       => 'IDs',
                   7473:                );
                   7474:     my $output;
                   7475:     my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
                   7476:     if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
                   7477:         if (@{$ruleorder} > 0) {
                   7478:             $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>';
                   7479:             foreach my $rule (@{$ruleorder}) {
                   7480:                 if (ref($curr_rules) eq 'ARRAY') {
                   7481:                     if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
                   7482:                         if (ref($rules->{$rule}) eq 'HASH') {
                   7483:                             $output .= '<li>'.$rules->{$rule}{'name'}.': '.
                   7484:                                         $rules->{$rule}{'desc'}.'</li>';
                   7485:                         }
                   7486:                     }
                   7487:                 }
                   7488:             }
                   7489:             $output .= '</ul>';
                   7490:         }
                   7491:     }
                   7492:     return $output;
                   7493: }
                   7494: 
                   7495: sub instrule_disallow_msg {
1.615     raeburn  7496:     my ($checkitem,$domdesc,$count,$mode) = @_;
1.612     raeburn  7497:     my $response;
                   7498:     my %text = (
                   7499:                   item   => 'username',
                   7500:                   items  => 'usernames',
                   7501:                   match  => 'matches',
                   7502:                   do     => 'does',
                   7503:                   action => 'a username',
                   7504:                   one    => 'one',
                   7505:                );
                   7506:     if ($count > 1) {
                   7507:         $text{'item'} = 'usernames';
                   7508:         $text{'match'} ='match';
                   7509:         $text{'do'} = 'do';
                   7510:         $text{'action'} = 'usernames',
                   7511:         $text{'one'} = 'ones';
                   7512:     }
                   7513:     if ($checkitem eq 'id') {
                   7514:         $text{'items'} = 'IDs';
                   7515:         $text{'item'} = 'ID';
                   7516:         $text{'action'} = 'an ID';
1.615     raeburn  7517:         if ($count > 1) {
                   7518:             $text{'item'} = 'IDs';
                   7519:             $text{'action'} = 'IDs';
                   7520:         }
1.612     raeburn  7521:     }
1.674     bisitz   7522:     $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  7523:     if ($mode eq 'upload') {
                   7524:         if ($checkitem eq 'username') {
                   7525:             $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'}.");
                   7526:         } elsif ($checkitem eq 'id') {
1.674     bisitz   7527:             $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  7528:         }
1.669     raeburn  7529:     } elsif ($mode eq 'selfcreate') {
                   7530:         if ($checkitem eq 'id') {
                   7531:             $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.");
                   7532:         }
1.615     raeburn  7533:     } else {
                   7534:         if ($checkitem eq 'username') {
                   7535:             $response .= &mt("You must choose $text{'action'} with a different format --  $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
                   7536:         } elsif ($checkitem eq 'id') {
                   7537:             $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.");
                   7538:         }
1.612     raeburn  7539:     }
                   7540:     return $response;
1.585     raeburn  7541: }
                   7542: 
1.624     raeburn  7543: sub personal_data_fieldtitles {
                   7544:     my %fieldtitles = &Apache::lonlocal::texthash (
                   7545:                         id => 'Student/Employee ID',
                   7546:                         permanentemail => 'E-mail address',
                   7547:                         lastname => 'Last Name',
                   7548:                         firstname => 'First Name',
                   7549:                         middlename => 'Middle Name',
                   7550:                         generation => 'Generation',
                   7551:                         gen => 'Generation',
1.765     raeburn  7552:                         inststatus => 'Affiliation',
1.624     raeburn  7553:                    );
                   7554:     return %fieldtitles;
                   7555: }
                   7556: 
1.642     raeburn  7557: sub sorted_inst_types {
                   7558:     my ($dom) = @_;
                   7559:     my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
                   7560:     my $othertitle = &mt('All users');
                   7561:     if ($env{'request.course.id'}) {
1.668     raeburn  7562:         $othertitle  = &mt('Any users');
1.642     raeburn  7563:     }
                   7564:     my @types;
                   7565:     if (ref($order) eq 'ARRAY') {
                   7566:         @types = @{$order};
                   7567:     }
                   7568:     if (@types == 0) {
                   7569:         if (ref($usertypes) eq 'HASH') {
                   7570:             @types = sort(keys(%{$usertypes}));
                   7571:         }
                   7572:     }
                   7573:     if (keys(%{$usertypes}) > 0) {
                   7574:         $othertitle = &mt('Other users');
                   7575:     }
                   7576:     return ($othertitle,$usertypes,\@types);
                   7577: }
                   7578: 
1.645     raeburn  7579: sub get_institutional_codes {
                   7580:     my ($settings,$allcourses,$LC_code) = @_;
                   7581: # Get complete list of course sections to update
                   7582:     my @currsections = ();
                   7583:     my @currxlists = ();
                   7584:     my $coursecode = $$settings{'internal.coursecode'};
                   7585: 
                   7586:     if ($$settings{'internal.sectionnums'} ne '') {
                   7587:         @currsections = split(/,/,$$settings{'internal.sectionnums'});
                   7588:     }
                   7589: 
                   7590:     if ($$settings{'internal.crosslistings'} ne '') {
                   7591:         @currxlists = split(/,/,$$settings{'internal.crosslistings'});
                   7592:     }
                   7593: 
                   7594:     if (@currxlists > 0) {
                   7595:         foreach (@currxlists) {
                   7596:             if (m/^([^:]+):(\w*)$/) {
                   7597:                 unless (grep/^$1$/,@{$allcourses}) {
                   7598:                     push @{$allcourses},$1;
                   7599:                     $$LC_code{$1} = $2;
                   7600:                 }
                   7601:             }
                   7602:         }
                   7603:     }
                   7604:  
                   7605:     if (@currsections > 0) {
                   7606:         foreach (@currsections) {
                   7607:             if (m/^(\w+):(\w*)$/) {
                   7608:                 my $sec = $coursecode.$1;
                   7609:                 my $lc_sec = $2;
                   7610:                 unless (grep/^$sec$/,@{$allcourses}) {
                   7611:                     push @{$allcourses},$sec;
                   7612:                     $$LC_code{$sec} = $lc_sec;
                   7613:                 }
                   7614:             }
                   7615:         }
                   7616:     }
                   7617:     return;
                   7618: }
                   7619: 
1.112     bowersj2 7620: =pod
                   7621: 
1.780     raeburn  7622: =head1 Slot Helpers
                   7623: 
                   7624: =over 4
                   7625: 
                   7626: =item * sorted_slots()
                   7627: 
                   7628: Sorts an array of slot names in order of slot start time (earliest first). 
                   7629: 
                   7630: Inputs:
                   7631: 
                   7632: =over 4
                   7633: 
                   7634: slotsarr  - Reference to array of unsorted slot names.
                   7635: 
                   7636: slots     - Reference to hash of hash, where outer hash keys are slot names.
                   7637: 
1.549     albertel 7638: =back
                   7639: 
1.780     raeburn  7640: Returns:
                   7641: 
                   7642: =over 4
                   7643: 
                   7644: sorted   - An array of slot names sorted by the start time of the slot.
                   7645: 
                   7646: =back
                   7647: 
                   7648: =back
                   7649: 
                   7650: =cut
                   7651: 
                   7652: 
                   7653: sub sorted_slots {
                   7654:     my ($slotsarr,$slots) = @_;
                   7655:     my @sorted;
                   7656:     if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
                   7657:         @sorted =
                   7658:             sort {
                   7659:                      if (ref($slots->{$a}) && ref($slots->{$b})) {
                   7660:                          return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
                   7661:                      }
                   7662:                      if (ref($slots->{$a})) { return -1;}
                   7663:                      if (ref($slots->{$b})) { return 1;}
                   7664:                      return 0;
                   7665:                  } @{$slotsarr};
                   7666:     }
                   7667:     return @sorted;
                   7668: }
                   7669: 
                   7670: 
                   7671: =pod
                   7672: 
1.549     albertel 7673: =head1 HTTP Helpers
                   7674: 
                   7675: =over 4
                   7676: 
1.648     raeburn  7677: =item * &get_unprocessed_cgi($query,$possible_names)
1.112     bowersj2 7678: 
1.258     albertel 7679: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112     bowersj2 7680: $query.  The parameters listed in $possible_names (an array reference),
1.258     albertel 7681: will be set in $env{'form.name'} if they do not already exist.
1.112     bowersj2 7682: 
                   7683: Typically called with $ENV{'QUERY_STRING'} as the first parameter.  
                   7684: $possible_names is an ref to an array of form element names.  As an example:
                   7685: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258     albertel 7686: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112     bowersj2 7687: 
                   7688: =cut
1.1       albertel 7689: 
1.6       albertel 7690: sub get_unprocessed_cgi {
1.25      albertel 7691:   my ($query,$possible_names)= @_;
1.26      matthew  7692:   # $Apache::lonxml::debug=1;
1.356     albertel 7693:   foreach my $pair (split(/&/,$query)) {
                   7694:     my ($name, $value) = split(/=/,$pair);
1.369     www      7695:     $name = &unescape($name);
1.25      albertel 7696:     if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
                   7697:       $value =~ tr/+/ /;
                   7698:       $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258     albertel 7699:       unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25      albertel 7700:     }
1.16      harris41 7701:   }
1.6       albertel 7702: }
                   7703: 
1.112     bowersj2 7704: =pod
                   7705: 
1.648     raeburn  7706: =item * &cacheheader() 
1.112     bowersj2 7707: 
                   7708: returns cache-controlling header code
                   7709: 
                   7710: =cut
                   7711: 
1.7       albertel 7712: sub cacheheader {
1.258     albertel 7713:     unless ($env{'request.method'} eq 'GET') { return ''; }
1.216     albertel 7714:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
                   7715:     my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7       albertel 7716:                 <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
                   7717:                 <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216     albertel 7718:     return $output;
1.7       albertel 7719: }
                   7720: 
1.112     bowersj2 7721: =pod
                   7722: 
1.648     raeburn  7723: =item * &no_cache($r) 
1.112     bowersj2 7724: 
                   7725: specifies header code to not have cache
                   7726: 
                   7727: =cut
                   7728: 
1.9       albertel 7729: sub no_cache {
1.216     albertel 7730:     my ($r) = @_;
                   7731:     if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258     albertel 7732: 	$env{'request.method'} ne 'GET') { return ''; }
1.216     albertel 7733:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
                   7734:     $r->no_cache(1);
                   7735:     $r->header_out("Expires" => $date);
                   7736:     $r->header_out("Pragma" => "no-cache");
1.123     www      7737: }
                   7738: 
                   7739: sub content_type {
1.181     albertel 7740:     my ($r,$type,$charset) = @_;
1.299     foxr     7741:     if ($r) {
                   7742: 	#  Note that printout.pl calls this with undef for $r.
                   7743: 	&no_cache($r);
                   7744:     }
1.258     albertel 7745:     if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181     albertel 7746:     unless ($charset) {
                   7747: 	$charset=&Apache::lonlocal::current_encoding;
                   7748:     }
                   7749:     if ($charset) { $type.='; charset='.$charset; }
                   7750:     if ($r) {
                   7751: 	$r->content_type($type);
                   7752:     } else {
                   7753: 	print("Content-type: $type\n\n");
                   7754:     }
1.9       albertel 7755: }
1.25      albertel 7756: 
1.112     bowersj2 7757: =pod
                   7758: 
1.648     raeburn  7759: =item * &add_to_env($name,$value) 
1.112     bowersj2 7760: 
1.258     albertel 7761: adds $name to the %env hash with value
1.112     bowersj2 7762: $value, if $name already exists, the entry is converted to an array
                   7763: reference and $value is added to the array.
                   7764: 
                   7765: =cut
                   7766: 
1.25      albertel 7767: sub add_to_env {
                   7768:   my ($name,$value)=@_;
1.258     albertel 7769:   if (defined($env{$name})) {
                   7770:     if (ref($env{$name})) {
1.25      albertel 7771:       #already have multiple values
1.258     albertel 7772:       push(@{ $env{$name} },$value);
1.25      albertel 7773:     } else {
                   7774:       #first time seeing multiple values, convert hash entry to an arrayref
1.258     albertel 7775:       my $first=$env{$name};
                   7776:       undef($env{$name});
                   7777:       push(@{ $env{$name} },$first,$value);
1.25      albertel 7778:     }
                   7779:   } else {
1.258     albertel 7780:     $env{$name}=$value;
1.25      albertel 7781:   }
1.31      albertel 7782: }
1.149     albertel 7783: 
                   7784: =pod
                   7785: 
1.648     raeburn  7786: =item * &get_env_multiple($name) 
1.149     albertel 7787: 
1.258     albertel 7788: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149     albertel 7789: values may be defined and end up as an array ref.
                   7790: 
                   7791: returns an array of values
                   7792: 
                   7793: =cut
                   7794: 
                   7795: sub get_env_multiple {
                   7796:     my ($name) = @_;
                   7797:     my @values;
1.258     albertel 7798:     if (defined($env{$name})) {
1.149     albertel 7799:         # exists is it an array
1.258     albertel 7800:         if (ref($env{$name})) {
                   7801:             @values=@{ $env{$name} };
1.149     albertel 7802:         } else {
1.258     albertel 7803:             $values[0]=$env{$name};
1.149     albertel 7804:         }
                   7805:     }
                   7806:     return(@values);
                   7807: }
                   7808: 
1.660     raeburn  7809: sub ask_for_embedded_content {
                   7810:     my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
                   7811:     my $upload_output = '
                   7812:    <form name="upload_embedded" action="'.$actionurl.'"
                   7813:                   method="post" enctype="multipart/form-data">';
                   7814:     $upload_output .= $state;
1.661     raeburn  7815:     $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
1.660     raeburn  7816: 
                   7817:     my $num = 0;
                   7818:     foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
                   7819:         $upload_output .= &start_data_table_row().
                   7820:             '<td>'.$embed_file.'</td><td>';
                   7821:         if ($args->{'ignore_remote_references'}
                   7822:             && $embed_file =~ m{^\w+://}) {
                   7823:             $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
                   7824:         } elsif ($args->{'error_on_invalid_names'}
                   7825:             && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
                   7826: 
                   7827:             $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
                   7828: 
                   7829:         } else {
                   7830:             $upload_output .='
1.661     raeburn  7831:            <input name="embedded_item_'.$num.'" type="file" value="" />
1.660     raeburn  7832:            <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
                   7833:             my $attrib = join(':',@{$$allfiles{$embed_file}});
                   7834:             $upload_output .=
                   7835:                 "\n\t\t".
                   7836:                 '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
                   7837:                 $attrib.'" />';
                   7838:             if (exists($$codebase{$embed_file})) {
                   7839:                 $upload_output .=
                   7840:                     "\n\t\t".
                   7841:                     '<input name="codebase_'.$num.'" type="hidden" value="'.
                   7842:                     &escape($$codebase{$embed_file}).'" />';
                   7843:             }
                   7844:         }
                   7845:         $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
                   7846:         $num++;
                   7847:     }
                   7848:     $upload_output .= &Apache::loncommon::end_data_table().'<br />
                   7849:    <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
                   7850:    <input type ="submit" value="'.&mt('Upload Listed Files').'" />
                   7851:    '.&mt('(only files for which a location has been provided will be uploaded)').'
                   7852:    </form>';
                   7853:     return $upload_output;
                   7854: }
                   7855: 
1.661     raeburn  7856: sub upload_embedded {
                   7857:     my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
                   7858:         $current_disk_usage) = @_;
                   7859:     my $output;
                   7860:     for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
                   7861:         next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
                   7862:         my $orig_uploaded_filename =
                   7863:             $env{'form.embedded_item_'.$i.'.filename'};
                   7864: 
                   7865:         $env{'form.embedded_orig_'.$i} =
                   7866:             &unescape($env{'form.embedded_orig_'.$i});
                   7867:         my ($path,$fname) =
                   7868:             ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
                   7869:         # no path, whole string is fname
                   7870:         if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
                   7871: 
                   7872:         $path = $env{'form.currentpath'}.$path;
                   7873:         $fname = &Apache::lonnet::clean_filename($fname);
                   7874:         # See if there is anything left
                   7875:         next if ($fname eq '');
                   7876: 
                   7877:         # Check if file already exists as a file or directory.
                   7878:         my ($state,$msg);
                   7879:         if ($context eq 'portfolio') {
                   7880:             my $port_path = $dirpath;
                   7881:             if ($group ne '') {
                   7882:                 $port_path = "groups/$group/$port_path";
                   7883:             }
                   7884:             ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
                   7885:                                               $dir_root,$port_path,$disk_quota,
                   7886:                                               $current_disk_usage,$uname,$udom);
                   7887:             if ($state eq 'will_exceed_quota'
                   7888:                 || $state eq 'file_locked'
                   7889:                 || $state eq 'file_exists' ) {
                   7890:                 $output .= $msg;
                   7891:                 next;
                   7892:             }
                   7893:         } elsif (($context eq 'author') || ($context eq 'testbank')) {
                   7894:             ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
                   7895:             if ($state eq 'exists') {
                   7896:                 $output .= $msg;
                   7897:                 next;
                   7898:             }
                   7899:         }
                   7900:         # Check if extension is valid
                   7901:         if (($fname =~ /\.(\w+)$/) &&
                   7902:             (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
                   7903:             $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
                   7904:             next;
                   7905:         } elsif (($fname =~ /\.(\w+)$/) &&
                   7906:                  (!defined(&Apache::loncommon::fileembstyle($1)))) {
                   7907:             $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
                   7908:             next;
                   7909:         } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
                   7910:             $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
                   7911:             next;
                   7912:         }
                   7913: 
                   7914:         $env{'form.embedded_item_'.$i.'.filename'}=$fname;
                   7915:         if ($context eq 'portfolio') {
                   7916:             my $result=
                   7917:                 &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
                   7918:                                                 $dirpath.$path);
                   7919:             if ($result !~ m|^/uploaded/|) {
                   7920:                 $output .= '<span class="LC_error">'
                   7921:                       .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
                   7922:                            ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
                   7923:                       .'</span><br />';
                   7924:                 next;
                   7925:             } else {
                   7926:                 $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
                   7927:                            $path.$fname.'</span>').'</p>';     
                   7928:             }
                   7929:         } else {
                   7930: # Save the file
                   7931:             my $target = $env{'form.embedded_item_'.$i};
                   7932:             my $fullpath = $dir_root.$dirpath.'/'.$path;
                   7933:             my $dest = $fullpath.$fname;
                   7934:             my $url = $url_root.$dirpath.'/'.$path.$fname;
                   7935:             my @parts=split(/\//,$fullpath);
                   7936:             my $count;
                   7937:             my $filepath = $dir_root;
                   7938:             for ($count=4;$count<=$#parts;$count++) {
                   7939:                 $filepath .= "/$parts[$count]";
                   7940:                 if ((-e $filepath)!=1) {
                   7941:                     mkdir($filepath,0770);
                   7942:                 }
                   7943:             }
                   7944:             my $fh;
                   7945:             if (!open($fh,'>'.$dest)) {
                   7946:                 &Apache::lonnet::logthis('Failed to create '.$dest);
                   7947:                 $output .= '<span class="LC_error">'.
                   7948:                            &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
                   7949:                            '</span><br />';
                   7950:             } else {
                   7951:                 if (!print $fh $env{'form.embedded_item_'.$i}) {
                   7952:                     &Apache::lonnet::logthis('Failed to write to '.$dest);
                   7953:                     $output .= '<span class="LC_error">'.
                   7954:                               &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
                   7955:                               '</span><br />';
                   7956:                 } else {
                   7957:                     if ($context eq 'testbank') {
                   7958:                         $output .= &mt('Embedded file uploaded successfully:').
                   7959:                                    '&nbsp;<a href="'.$url.'">'.
                   7960:                                    $orig_uploaded_filename.'</a><br />';
                   7961:                     } else {
1.705     tempelho 7962:                         $output .= '<span class=\"LC_fontsize_large\">'.
1.661     raeburn  7963:                                    &mt('View embedded file: [_1]','<a href="'.$url.'">'.
1.705     tempelho 7964:                                    $orig_uploaded_filename.'</a>').'</span><br />';
1.661     raeburn  7965:                     }
                   7966:                 }
                   7967:                 close($fh);
                   7968:             }
                   7969:         }
                   7970:     }
                   7971:     return $output;
                   7972: }
                   7973: 
                   7974: sub check_for_existing {
                   7975:     my ($path,$fname,$element) = @_;
                   7976:     my ($state,$msg);
                   7977:     if (-d $path.'/'.$fname) {
                   7978:         $state = 'exists';
                   7979:         $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
                   7980:     } elsif (-e $path.'/'.$fname) {
                   7981:         $state = 'exists';
                   7982:         $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
                   7983:     }
                   7984:     if ($state eq 'exists') {
                   7985:         $msg = '<span class="LC_error">'.$msg.'</span><br />';
                   7986:     }
                   7987:     return ($state,$msg);
                   7988: }
                   7989: 
                   7990: sub check_for_upload {
                   7991:     my ($path,$fname,$group,$element,$portfolio_root,$port_path,
                   7992:         $disk_quota,$current_disk_usage,$uname,$udom) = @_;
                   7993:     my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
                   7994:     my $getpropath = 1;
                   7995:     my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
                   7996:                                             $getpropath);
                   7997:     my $found_file = 0;
                   7998:     my $locked_file = 0;
                   7999:     foreach my $line (@dir_list) {
                   8000:         my ($file_name)=split(/\&/,$line,2);
                   8001:         if ($file_name eq $fname){
                   8002:             $file_name = $path.$file_name;
                   8003:             if ($group ne '') {
                   8004:                 $file_name = $group.$file_name;
                   8005:             }
                   8006:             $found_file = 1;
                   8007:             if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
                   8008:                 $locked_file = 1;
                   8009:             }
                   8010:         }
                   8011:     }
                   8012:     if (($current_disk_usage + $filesize) > $disk_quota){
                   8013:         my $msg = '<span class="LC_error">'.
                   8014:                 &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
                   8015:                   '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
                   8016:         return ('will_exceed_quota',$msg);
                   8017:     } elsif ($found_file) {
                   8018:         if ($locked_file) {
                   8019:             my $msg = '<span class="LC_error">';
                   8020:             $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>');
                   8021:             $msg .= '</span><br />';
                   8022:             $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
                   8023:             return ('file_locked',$msg);
                   8024:         } else {
                   8025:             my $msg = '<span class="LC_error">';
                   8026:             $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'});
                   8027:             $msg .= '</span>';
                   8028:             $msg .= '<br />';
                   8029:             $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
                   8030:             return ('file_exists',$msg);
                   8031:         }
                   8032:     }
                   8033: }
                   8034: 
1.31      albertel 8035: 
1.41      ng       8036: =pod
1.45      matthew  8037: 
1.464     albertel 8038: =back
1.41      ng       8039: 
1.112     bowersj2 8040: =head1 CSV Upload/Handling functions
1.38      albertel 8041: 
1.41      ng       8042: =over 4
                   8043: 
1.648     raeburn  8044: =item * &upfile_store($r)
1.41      ng       8045: 
                   8046: Store uploaded file, $r should be the HTTP Request object,
1.258     albertel 8047: needs $env{'form.upfile'}
1.41      ng       8048: returns $datatoken to be put into hidden field
                   8049: 
                   8050: =cut
1.31      albertel 8051: 
                   8052: sub upfile_store {
                   8053:     my $r=shift;
1.258     albertel 8054:     $env{'form.upfile'}=~s/\r/\n/gs;
                   8055:     $env{'form.upfile'}=~s/\f/\n/gs;
                   8056:     $env{'form.upfile'}=~s/\n+/\n/gs;
                   8057:     $env{'form.upfile'}=~s/\n+$//gs;
1.31      albertel 8058: 
1.258     albertel 8059:     my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
                   8060: 	'_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31      albertel 8061:     {
1.158     raeburn  8062:         my $datafile = $r->dir_config('lonDaemons').
                   8063:                            '/tmp/'.$datatoken.'.tmp';
                   8064:         if ( open(my $fh,">$datafile") ) {
1.258     albertel 8065:             print $fh $env{'form.upfile'};
1.158     raeburn  8066:             close($fh);
                   8067:         }
1.31      albertel 8068:     }
                   8069:     return $datatoken;
                   8070: }
                   8071: 
1.56      matthew  8072: =pod
                   8073: 
1.648     raeburn  8074: =item * &load_tmp_file($r)
1.41      ng       8075: 
                   8076: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258     albertel 8077: needs $env{'form.datatoken'},
                   8078: sets $env{'form.upfile'} to the contents of the file
1.41      ng       8079: 
                   8080: =cut
1.31      albertel 8081: 
                   8082: sub load_tmp_file {
                   8083:     my $r=shift;
                   8084:     my @studentdata=();
                   8085:     {
1.158     raeburn  8086:         my $studentfile = $r->dir_config('lonDaemons').
1.258     albertel 8087:                               '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158     raeburn  8088:         if ( open(my $fh,"<$studentfile") ) {
                   8089:             @studentdata=<$fh>;
                   8090:             close($fh);
                   8091:         }
1.31      albertel 8092:     }
1.258     albertel 8093:     $env{'form.upfile'}=join('',@studentdata);
1.31      albertel 8094: }
                   8095: 
1.56      matthew  8096: =pod
                   8097: 
1.648     raeburn  8098: =item * &upfile_record_sep()
1.41      ng       8099: 
                   8100: Separate uploaded file into records
                   8101: returns array of records,
1.258     albertel 8102: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41      ng       8103: 
                   8104: =cut
1.31      albertel 8105: 
                   8106: sub upfile_record_sep {
1.258     albertel 8107:     if ($env{'form.upfiletype'} eq 'xml') {
1.31      albertel 8108:     } else {
1.248     albertel 8109: 	my @records;
1.258     albertel 8110: 	foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248     albertel 8111: 	    if ($line=~/^\s*$/) { next; }
                   8112: 	    push(@records,$line);
                   8113: 	}
                   8114: 	return @records;
1.31      albertel 8115:     }
                   8116: }
                   8117: 
1.56      matthew  8118: =pod
                   8119: 
1.648     raeburn  8120: =item * &record_sep($record)
1.41      ng       8121: 
1.258     albertel 8122: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41      ng       8123: 
                   8124: =cut
                   8125: 
1.263     www      8126: sub takeleft {
                   8127:     my $index=shift;
                   8128:     return substr('0000'.$index,-4,4);
                   8129: }
                   8130: 
1.31      albertel 8131: sub record_sep {
                   8132:     my $record=shift;
                   8133:     my %components=();
1.258     albertel 8134:     if ($env{'form.upfiletype'} eq 'xml') {
                   8135:     } elsif ($env{'form.upfiletype'} eq 'space') {
1.31      albertel 8136:         my $i=0;
1.356     albertel 8137:         foreach my $field (split(/\s+/,$record)) {
1.31      albertel 8138:             $field=~s/^(\"|\')//;
                   8139:             $field=~s/(\"|\')$//;
1.263     www      8140:             $components{&takeleft($i)}=$field;
1.31      albertel 8141:             $i++;
                   8142:         }
1.258     albertel 8143:     } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31      albertel 8144:         my $i=0;
1.356     albertel 8145:         foreach my $field (split(/\t/,$record)) {
1.31      albertel 8146:             $field=~s/^(\"|\')//;
                   8147:             $field=~s/(\"|\')$//;
1.263     www      8148:             $components{&takeleft($i)}=$field;
1.31      albertel 8149:             $i++;
                   8150:         }
                   8151:     } else {
1.561     www      8152:         my $separator=',';
1.480     banghart 8153:         if ($env{'form.upfiletype'} eq 'semisv') {
1.561     www      8154:             $separator=';';
1.480     banghart 8155:         }
1.31      albertel 8156:         my $i=0;
1.561     www      8157: # the character we are looking for to indicate the end of a quote or a record 
                   8158:         my $looking_for=$separator;
                   8159: # do not add the characters to the fields
                   8160:         my $ignore=0;
                   8161: # we just encountered a separator (or the beginning of the record)
                   8162:         my $just_found_separator=1;
                   8163: # store the field we are working on here
                   8164:         my $field='';
                   8165: # work our way through all characters in record
                   8166:         foreach my $character ($record=~/(.)/g) {
                   8167:             if ($character eq $looking_for) {
                   8168:                if ($character ne $separator) {
                   8169: # Found the end of a quote, again looking for separator
                   8170:                   $looking_for=$separator;
                   8171:                   $ignore=1;
                   8172:                } else {
                   8173: # Found a separator, store away what we got
                   8174:                   $components{&takeleft($i)}=$field;
                   8175: 	          $i++;
                   8176:                   $just_found_separator=1;
                   8177:                   $ignore=0;
                   8178:                   $field='';
                   8179:                }
                   8180:                next;
                   8181:             }
                   8182: # single or double quotation marks after a separator indicate beginning of a quote
                   8183: # we are now looking for the end of the quote and need to ignore separators
                   8184:             if ((($character eq '"') || ($character eq "'")) && ($just_found_separator))  {
                   8185:                $looking_for=$character;
                   8186:                next;
                   8187:             }
                   8188: # ignore would be true after we reached the end of a quote
                   8189:             if ($ignore) { next; }
                   8190:             if (($just_found_separator) && ($character=~/\s/)) { next; }
                   8191:             $field.=$character;
                   8192:             $just_found_separator=0; 
1.31      albertel 8193:         }
1.561     www      8194: # catch the very last entry, since we never encountered the separator
                   8195:         $components{&takeleft($i)}=$field;
1.31      albertel 8196:     }
                   8197:     return %components;
                   8198: }
                   8199: 
1.144     matthew  8200: ######################################################
                   8201: ######################################################
                   8202: 
1.56      matthew  8203: =pod
                   8204: 
1.648     raeburn  8205: =item * &upfile_select_html()
1.41      ng       8206: 
1.144     matthew  8207: Return HTML code to select a file from the users machine and specify 
                   8208: the file type.
1.41      ng       8209: 
                   8210: =cut
                   8211: 
1.144     matthew  8212: ######################################################
                   8213: ######################################################
1.31      albertel 8214: sub upfile_select_html {
1.144     matthew  8215:     my %Types = (
                   8216:                  csv   => &mt('CSV (comma separated values, spreadsheet)'),
1.480     banghart 8217:                  semisv => &mt('Semicolon separated values'),
1.144     matthew  8218:                  space => &mt('Space separated'),
                   8219:                  tab   => &mt('Tabulator separated'),
                   8220: #                 xml   => &mt('HTML/XML'),
                   8221:                  );
                   8222:     my $Str = '<input type="file" name="upfile" size="50" />'.
1.727     riegler  8223:         '<br />'.&mt('Type').': <select name="upfiletype">';
1.144     matthew  8224:     foreach my $type (sort(keys(%Types))) {
                   8225:         $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
                   8226:     }
                   8227:     $Str .= "</select>\n";
                   8228:     return $Str;
1.31      albertel 8229: }
                   8230: 
1.301     albertel 8231: sub get_samples {
                   8232:     my ($records,$toget) = @_;
                   8233:     my @samples=({});
                   8234:     my $got=0;
                   8235:     foreach my $rec (@$records) {
                   8236: 	my %temp = &record_sep($rec);
                   8237: 	if (! grep(/\S/, values(%temp))) { next; }
                   8238: 	if (%temp) {
                   8239: 	    $samples[$got]=\%temp;
                   8240: 	    $got++;
                   8241: 	    if ($got == $toget) { last; }
                   8242: 	}
                   8243:     }
                   8244:     return \@samples;
                   8245: }
                   8246: 
1.144     matthew  8247: ######################################################
                   8248: ######################################################
                   8249: 
1.56      matthew  8250: =pod
                   8251: 
1.648     raeburn  8252: =item * &csv_print_samples($r,$records)
1.41      ng       8253: 
                   8254: Prints a table of sample values from each column uploaded $r is an
                   8255: Apache Request ref, $records is an arrayref from
                   8256: &Apache::loncommon::upfile_record_sep
                   8257: 
                   8258: =cut
                   8259: 
1.144     matthew  8260: ######################################################
                   8261: ######################################################
1.31      albertel 8262: sub csv_print_samples {
                   8263:     my ($r,$records) = @_;
1.662     bisitz   8264:     my $samples = &get_samples($records,5);
1.301     albertel 8265: 
1.594     raeburn  8266:     $r->print(&mt('Samples').'<br />'.&start_data_table().
                   8267:               &start_data_table_header_row());
1.356     albertel 8268:     foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) { 
                   8269:         $r->print('<th>'.&mt('Column&nbsp;[_1]',($sample+1)).'</th>'); }
1.594     raeburn  8270:     $r->print(&end_data_table_header_row());
1.301     albertel 8271:     foreach my $hash (@$samples) {
1.594     raeburn  8272: 	$r->print(&start_data_table_row());
1.356     albertel 8273: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31      albertel 8274: 	    $r->print('<td>');
1.356     albertel 8275: 	    if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31      albertel 8276: 	    $r->print('</td>');
                   8277: 	}
1.594     raeburn  8278: 	$r->print(&end_data_table_row());
1.31      albertel 8279:     }
1.594     raeburn  8280:     $r->print(&end_data_table().'<br />'."\n");
1.31      albertel 8281: }
                   8282: 
1.144     matthew  8283: ######################################################
                   8284: ######################################################
                   8285: 
1.56      matthew  8286: =pod
                   8287: 
1.648     raeburn  8288: =item * &csv_print_select_table($r,$records,$d)
1.41      ng       8289: 
                   8290: Prints a table to create associations between values and table columns.
1.144     matthew  8291: 
1.41      ng       8292: $r is an Apache Request ref,
                   8293: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174     matthew  8294: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41      ng       8295: 
                   8296: =cut
                   8297: 
1.144     matthew  8298: ######################################################
                   8299: ######################################################
1.31      albertel 8300: sub csv_print_select_table {
                   8301:     my ($r,$records,$d) = @_;
1.301     albertel 8302:     my $i=0;
                   8303:     my $samples = &get_samples($records,1);
1.144     matthew  8304:     $r->print(&mt('Associate columns with student attributes.')."\n".
1.594     raeburn  8305: 	      &start_data_table().&start_data_table_header_row().
1.144     matthew  8306:               '<th>'.&mt('Attribute').'</th>'.
1.594     raeburn  8307:               '<th>'.&mt('Column').'</th>'.
                   8308:               &end_data_table_header_row()."\n");
1.356     albertel 8309:     foreach my $array_ref (@$d) {
                   8310: 	my ($value,$display,$defaultcol)=@{ $array_ref };
1.729     raeburn  8311: 	$r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31      albertel 8312: 
                   8313: 	$r->print('<td><select name=f'.$i.
1.32      matthew  8314: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.31      albertel 8315: 	$r->print('<option value="none"></option>');
1.356     albertel 8316: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
                   8317: 	    $r->print('<option value="'.$sample.'"'.
                   8318:                       ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662     bisitz   8319:                       '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31      albertel 8320: 	}
1.594     raeburn  8321: 	$r->print('</select></td>'.&end_data_table_row()."\n");
1.31      albertel 8322: 	$i++;
                   8323:     }
1.594     raeburn  8324:     $r->print(&end_data_table());
1.31      albertel 8325:     $i--;
                   8326:     return $i;
                   8327: }
1.56      matthew  8328: 
1.144     matthew  8329: ######################################################
                   8330: ######################################################
                   8331: 
1.56      matthew  8332: =pod
1.31      albertel 8333: 
1.648     raeburn  8334: =item * &csv_samples_select_table($r,$records,$d)
1.41      ng       8335: 
                   8336: Prints a table of sample values from the upload and can make associate samples to internal names.
                   8337: 
                   8338: $r is an Apache Request ref,
                   8339: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
                   8340: $d is an array of 2 element arrays (internal name, displayed name)
                   8341: 
                   8342: =cut
                   8343: 
1.144     matthew  8344: ######################################################
                   8345: ######################################################
1.31      albertel 8346: sub csv_samples_select_table {
                   8347:     my ($r,$records,$d) = @_;
                   8348:     my $i=0;
1.144     matthew  8349:     #
1.662     bisitz   8350:     my $max_samples = 5;
                   8351:     my $samples = &get_samples($records,$max_samples);
1.594     raeburn  8352:     $r->print(&start_data_table().
                   8353:               &start_data_table_header_row().'<th>'.
                   8354:               &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
                   8355:               &end_data_table_header_row());
1.301     albertel 8356: 
                   8357:     foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594     raeburn  8358: 	$r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32      matthew  8359: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.301     albertel 8360: 	foreach my $option (@$d) {
                   8361: 	    my ($value,$display,$defaultcol)=@{ $option };
1.174     matthew  8362: 	    $r->print('<option value="'.$value.'"'.
1.253     albertel 8363:                       ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174     matthew  8364:                       $display.'</option>');
1.31      albertel 8365: 	}
                   8366: 	$r->print('</select></td><td>');
1.662     bisitz   8367: 	foreach my $line (0..($max_samples-1)) {
1.301     albertel 8368: 	    if (defined($samples->[$line]{$key})) { 
                   8369: 		$r->print($samples->[$line]{$key}."<br />\n"); 
                   8370: 	    }
                   8371: 	}
1.594     raeburn  8372: 	$r->print('</td>'.&end_data_table_row());
1.31      albertel 8373: 	$i++;
                   8374:     }
1.594     raeburn  8375:     $r->print(&end_data_table());
1.31      albertel 8376:     $i--;
                   8377:     return($i);
1.115     matthew  8378: }
                   8379: 
1.144     matthew  8380: ######################################################
                   8381: ######################################################
                   8382: 
1.115     matthew  8383: =pod
                   8384: 
1.648     raeburn  8385: =item * &clean_excel_name($name)
1.115     matthew  8386: 
                   8387: Returns a replacement for $name which does not contain any illegal characters.
                   8388: 
                   8389: =cut
                   8390: 
1.144     matthew  8391: ######################################################
                   8392: ######################################################
1.115     matthew  8393: sub clean_excel_name {
                   8394:     my ($name) = @_;
                   8395:     $name =~ s/[:\*\?\/\\]//g;
                   8396:     if (length($name) > 31) {
                   8397:         $name = substr($name,0,31);
                   8398:     }
                   8399:     return $name;
1.25      albertel 8400: }
1.84      albertel 8401: 
1.85      albertel 8402: =pod
                   8403: 
1.648     raeburn  8404: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85      albertel 8405: 
                   8406: Returns either 1 or undef
                   8407: 
                   8408: 1 if the part is to be hidden, undef if it is to be shown
                   8409: 
                   8410: Arguments are:
                   8411: 
                   8412: $id the id of the part to be checked
                   8413: $symb, optional the symb of the resource to check
                   8414: $udom, optional the domain of the user to check for
                   8415: $uname, optional the username of the user to check for
                   8416: 
                   8417: =cut
1.84      albertel 8418: 
                   8419: sub check_if_partid_hidden {
                   8420:     my ($id,$symb,$udom,$uname) = @_;
1.133     albertel 8421:     my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84      albertel 8422: 					 $symb,$udom,$uname);
1.141     albertel 8423:     my $truth=1;
                   8424:     #if the string starts with !, then the list is the list to show not hide
                   8425:     if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84      albertel 8426:     my @hiddenlist=split(/,/,$hiddenparts);
                   8427:     foreach my $checkid (@hiddenlist) {
1.141     albertel 8428: 	if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84      albertel 8429:     }
1.141     albertel 8430:     return !$truth;
1.84      albertel 8431: }
1.127     matthew  8432: 
1.138     matthew  8433: 
                   8434: ############################################################
                   8435: ############################################################
                   8436: 
                   8437: =pod
                   8438: 
1.157     matthew  8439: =back 
                   8440: 
1.138     matthew  8441: =head1 cgi-bin script and graphing routines
                   8442: 
1.157     matthew  8443: =over 4
                   8444: 
1.648     raeburn  8445: =item * &get_cgi_id()
1.138     matthew  8446: 
                   8447: Inputs: none
                   8448: 
                   8449: Returns an id which can be used to pass environment variables
                   8450: to various cgi-bin scripts.  These environment variables will
                   8451: be removed from the users environment after a given time by
                   8452: the routine &Apache::lonnet::transfer_profile_to_env.
                   8453: 
                   8454: =cut
                   8455: 
                   8456: ############################################################
                   8457: ############################################################
1.152     albertel 8458: my $uniq=0;
1.136     matthew  8459: sub get_cgi_id {
1.154     albertel 8460:     $uniq=($uniq+1)%100000;
1.280     albertel 8461:     return (time.'_'.$$.'_'.$uniq);
1.136     matthew  8462: }
                   8463: 
1.127     matthew  8464: ############################################################
                   8465: ############################################################
                   8466: 
                   8467: =pod
                   8468: 
1.648     raeburn  8469: =item * &DrawBarGraph()
1.127     matthew  8470: 
1.138     matthew  8471: Facilitates the plotting of data in a (stacked) bar graph.
                   8472: Puts plot definition data into the users environment in order for 
                   8473: graph.png to plot it.  Returns an <img> tag for the plot.
                   8474: The bars on the plot are labeled '1','2',...,'n'.
                   8475: 
                   8476: Inputs:
                   8477: 
                   8478: =over 4
                   8479: 
                   8480: =item $Title: string, the title of the plot
                   8481: 
                   8482: =item $xlabel: string, text describing the X-axis of the plot
                   8483: 
                   8484: =item $ylabel: string, text describing the Y-axis of the plot
                   8485: 
                   8486: =item $Max: scalar, the maximum Y value to use in the plot
                   8487: If $Max is < any data point, the graph will not be rendered.
                   8488: 
1.140     matthew  8489: =item $colors: array ref holding the colors to be used for the data sets when
1.138     matthew  8490: they are plotted.  If undefined, default values will be used.
                   8491: 
1.178     matthew  8492: =item $labels: array ref holding the labels to use on the x-axis for the bars.
                   8493: 
1.138     matthew  8494: =item @Values: An array of array references.  Each array reference holds data
                   8495: to be plotted in a stacked bar chart.
                   8496: 
1.239     matthew  8497: =item If the final element of @Values is a hash reference the key/value
                   8498: pairs will be added to the graph definition.
                   8499: 
1.138     matthew  8500: =back
                   8501: 
                   8502: Returns:
                   8503: 
                   8504: An <img> tag which references graph.png and the appropriate identifying
                   8505: information for the plot.
                   8506: 
1.127     matthew  8507: =cut
                   8508: 
                   8509: ############################################################
                   8510: ############################################################
1.134     matthew  8511: sub DrawBarGraph {
1.178     matthew  8512:     my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134     matthew  8513:     #
                   8514:     if (! defined($colors)) {
                   8515:         $colors = ['#33ff00', 
                   8516:                   '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
                   8517:                   '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
                   8518:                   ]; 
                   8519:     }
1.228     matthew  8520:     my $extra_settings = {};
                   8521:     if (ref($Values[-1]) eq 'HASH') {
                   8522:         $extra_settings = pop(@Values);
                   8523:     }
1.127     matthew  8524:     #
1.136     matthew  8525:     my $identifier = &get_cgi_id();
                   8526:     my $id = 'cgi.'.$identifier;        
1.129     matthew  8527:     if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127     matthew  8528:         return '';
                   8529:     }
1.225     matthew  8530:     #
                   8531:     my @Labels;
                   8532:     if (defined($labels)) {
                   8533:         @Labels = @$labels;
                   8534:     } else {
                   8535:         for (my $i=0;$i<@{$Values[0]};$i++) {
                   8536:             push (@Labels,$i+1);
                   8537:         }
                   8538:     }
                   8539:     #
1.129     matthew  8540:     my $NumBars = scalar(@{$Values[0]});
1.225     matthew  8541:     if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129     matthew  8542:     my %ValuesHash;
                   8543:     my $NumSets=1;
                   8544:     foreach my $array (@Values) {
                   8545:         next if (! ref($array));
1.136     matthew  8546:         $ValuesHash{$id.'.data.'.$NumSets++} = 
1.132     matthew  8547:             join(',',@$array);
1.129     matthew  8548:     }
1.127     matthew  8549:     #
1.136     matthew  8550:     my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225     matthew  8551:     if ($NumBars < 3) {
                   8552:         $width = 120+$NumBars*32;
1.220     matthew  8553:         $xskip = 1;
1.225     matthew  8554:         $bar_width = 30;
                   8555:     } elsif ($NumBars < 5) {
                   8556:         $width = 120+$NumBars*20;
                   8557:         $xskip = 1;
                   8558:         $bar_width = 20;
1.220     matthew  8559:     } elsif ($NumBars < 10) {
1.136     matthew  8560:         $width = 120+$NumBars*15;
                   8561:         $xskip = 1;
                   8562:         $bar_width = 15;
                   8563:     } elsif ($NumBars <= 25) {
                   8564:         $width = 120+$NumBars*11;
                   8565:         $xskip = 5;
                   8566:         $bar_width = 8;
                   8567:     } elsif ($NumBars <= 50) {
                   8568:         $width = 120+$NumBars*8;
                   8569:         $xskip = 5;
                   8570:         $bar_width = 4;
                   8571:     } else {
                   8572:         $width = 120+$NumBars*8;
                   8573:         $xskip = 5;
                   8574:         $bar_width = 4;
                   8575:     }
                   8576:     #
1.137     matthew  8577:     $Max = 1 if ($Max < 1);
                   8578:     if ( int($Max) < $Max ) {
                   8579:         $Max++;
                   8580:         $Max = int($Max);
                   8581:     }
1.127     matthew  8582:     $Title  = '' if (! defined($Title));
                   8583:     $xlabel = '' if (! defined($xlabel));
                   8584:     $ylabel = '' if (! defined($ylabel));
1.369     www      8585:     $ValuesHash{$id.'.title'}    = &escape($Title);
                   8586:     $ValuesHash{$id.'.xlabel'}   = &escape($xlabel);
                   8587:     $ValuesHash{$id.'.ylabel'}   = &escape($ylabel);
1.137     matthew  8588:     $ValuesHash{$id.'.y_max_value'} = $Max;
1.136     matthew  8589:     $ValuesHash{$id.'.NumBars'}  = $NumBars;
                   8590:     $ValuesHash{$id.'.NumSets'}  = $NumSets;
                   8591:     $ValuesHash{$id.'.PlotType'} = 'bar';
                   8592:     $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   8593:     $ValuesHash{$id.'.height'}   = $height;
                   8594:     $ValuesHash{$id.'.width'}    = $width;
                   8595:     $ValuesHash{$id.'.xskip'}    = $xskip;
                   8596:     $ValuesHash{$id.'.bar_width'} = $bar_width;
                   8597:     $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127     matthew  8598:     #
1.228     matthew  8599:     # Deal with other parameters
                   8600:     while (my ($key,$value) = each(%$extra_settings)) {
                   8601:         $ValuesHash{$id.'.'.$key} = $value;
                   8602:     }
                   8603:     #
1.646     raeburn  8604:     &Apache::lonnet::appenv(\%ValuesHash);
1.137     matthew  8605:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   8606: }
                   8607: 
                   8608: ############################################################
                   8609: ############################################################
                   8610: 
                   8611: =pod
                   8612: 
1.648     raeburn  8613: =item * &DrawXYGraph()
1.137     matthew  8614: 
1.138     matthew  8615: Facilitates the plotting of data in an XY graph.
                   8616: Puts plot definition data into the users environment in order for 
                   8617: graph.png to plot it.  Returns an <img> tag for the plot.
                   8618: 
                   8619: Inputs:
                   8620: 
                   8621: =over 4
                   8622: 
                   8623: =item $Title: string, the title of the plot
                   8624: 
                   8625: =item $xlabel: string, text describing the X-axis of the plot
                   8626: 
                   8627: =item $ylabel: string, text describing the Y-axis of the plot
                   8628: 
                   8629: =item $Max: scalar, the maximum Y value to use in the plot
                   8630: If $Max is < any data point, the graph will not be rendered.
                   8631: 
                   8632: =item $colors: Array ref containing the hex color codes for the data to be 
                   8633: plotted in.  If undefined, default values will be used.
                   8634: 
                   8635: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   8636: 
                   8637: =item $Ydata: Array ref containing Array refs.  
1.185     www      8638: Each of the contained arrays will be plotted as a separate curve.
1.138     matthew  8639: 
                   8640: =item %Values: hash indicating or overriding any default values which are 
                   8641: passed to graph.png.  
                   8642: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   8643: 
                   8644: =back
                   8645: 
                   8646: Returns:
                   8647: 
                   8648: An <img> tag which references graph.png and the appropriate identifying
                   8649: information for the plot.
                   8650: 
1.137     matthew  8651: =cut
                   8652: 
                   8653: ############################################################
                   8654: ############################################################
                   8655: sub DrawXYGraph {
                   8656:     my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
                   8657:     #
                   8658:     # Create the identifier for the graph
                   8659:     my $identifier = &get_cgi_id();
                   8660:     my $id = 'cgi.'.$identifier;
                   8661:     #
                   8662:     $Title  = '' if (! defined($Title));
                   8663:     $xlabel = '' if (! defined($xlabel));
                   8664:     $ylabel = '' if (! defined($ylabel));
                   8665:     my %ValuesHash = 
                   8666:         (
1.369     www      8667:          $id.'.title'  => &escape($Title),
                   8668:          $id.'.xlabel' => &escape($xlabel),
                   8669:          $id.'.ylabel' => &escape($ylabel),
1.137     matthew  8670:          $id.'.y_max_value'=> $Max,
                   8671:          $id.'.labels'     => join(',',@$Xlabels),
                   8672:          $id.'.PlotType'   => 'XY',
                   8673:          );
                   8674:     #
                   8675:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   8676:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   8677:     }
                   8678:     #
                   8679:     if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
                   8680:         return '';
                   8681:     }
                   8682:     my $NumSets=1;
1.138     matthew  8683:     foreach my $array (@{$Ydata}){
1.137     matthew  8684:         next if (! ref($array));
                   8685:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
                   8686:     }
1.138     matthew  8687:     $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137     matthew  8688:     #
                   8689:     # Deal with other parameters
                   8690:     while (my ($key,$value) = each(%Values)) {
                   8691:         $ValuesHash{$id.'.'.$key} = $value;
1.127     matthew  8692:     }
                   8693:     #
1.646     raeburn  8694:     &Apache::lonnet::appenv(\%ValuesHash);
1.136     matthew  8695:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   8696: }
                   8697: 
                   8698: ############################################################
                   8699: ############################################################
                   8700: 
                   8701: =pod
                   8702: 
1.648     raeburn  8703: =item * &DrawXYYGraph()
1.138     matthew  8704: 
                   8705: Facilitates the plotting of data in an XY graph with two Y axes.
                   8706: Puts plot definition data into the users environment in order for 
                   8707: graph.png to plot it.  Returns an <img> tag for the plot.
                   8708: 
                   8709: Inputs:
                   8710: 
                   8711: =over 4
                   8712: 
                   8713: =item $Title: string, the title of the plot
                   8714: 
                   8715: =item $xlabel: string, text describing the X-axis of the plot
                   8716: 
                   8717: =item $ylabel: string, text describing the Y-axis of the plot
                   8718: 
                   8719: =item $colors: Array ref containing the hex color codes for the data to be 
                   8720: plotted in.  If undefined, default values will be used.
                   8721: 
                   8722: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   8723: 
                   8724: =item $Ydata1: The first data set
                   8725: 
                   8726: =item $Min1: The minimum value of the left Y-axis
                   8727: 
                   8728: =item $Max1: The maximum value of the left Y-axis
                   8729: 
                   8730: =item $Ydata2: The second data set
                   8731: 
                   8732: =item $Min2: The minimum value of the right Y-axis
                   8733: 
                   8734: =item $Max2: The maximum value of the left Y-axis
                   8735: 
                   8736: =item %Values: hash indicating or overriding any default values which are 
                   8737: passed to graph.png.  
                   8738: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   8739: 
                   8740: =back
                   8741: 
                   8742: Returns:
                   8743: 
                   8744: An <img> tag which references graph.png and the appropriate identifying
                   8745: information for the plot.
1.136     matthew  8746: 
                   8747: =cut
                   8748: 
                   8749: ############################################################
                   8750: ############################################################
1.137     matthew  8751: sub DrawXYYGraph {
                   8752:     my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
                   8753:                                         $Ydata2,$Min2,$Max2,%Values)=@_;
1.136     matthew  8754:     #
                   8755:     # Create the identifier for the graph
                   8756:     my $identifier = &get_cgi_id();
                   8757:     my $id = 'cgi.'.$identifier;
                   8758:     #
                   8759:     $Title  = '' if (! defined($Title));
                   8760:     $xlabel = '' if (! defined($xlabel));
                   8761:     $ylabel = '' if (! defined($ylabel));
                   8762:     my %ValuesHash = 
                   8763:         (
1.369     www      8764:          $id.'.title'  => &escape($Title),
                   8765:          $id.'.xlabel' => &escape($xlabel),
                   8766:          $id.'.ylabel' => &escape($ylabel),
1.136     matthew  8767:          $id.'.labels' => join(',',@$Xlabels),
                   8768:          $id.'.PlotType' => 'XY',
                   8769:          $id.'.NumSets' => 2,
1.137     matthew  8770:          $id.'.two_axes' => 1,
                   8771:          $id.'.y1_max_value' => $Max1,
                   8772:          $id.'.y1_min_value' => $Min1,
                   8773:          $id.'.y2_max_value' => $Max2,
                   8774:          $id.'.y2_min_value' => $Min2,
1.136     matthew  8775:          );
                   8776:     #
1.137     matthew  8777:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   8778:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   8779:     }
                   8780:     #
                   8781:     if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
                   8782:         ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136     matthew  8783:         return '';
                   8784:     }
                   8785:     my $NumSets=1;
1.137     matthew  8786:     foreach my $array ($Ydata1,$Ydata2){
1.136     matthew  8787:         next if (! ref($array));
                   8788:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137     matthew  8789:     }
                   8790:     #
                   8791:     # Deal with other parameters
                   8792:     while (my ($key,$value) = each(%Values)) {
                   8793:         $ValuesHash{$id.'.'.$key} = $value;
1.136     matthew  8794:     }
                   8795:     #
1.646     raeburn  8796:     &Apache::lonnet::appenv(\%ValuesHash);
1.130     albertel 8797:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139     matthew  8798: }
                   8799: 
                   8800: ############################################################
                   8801: ############################################################
                   8802: 
                   8803: =pod
                   8804: 
1.157     matthew  8805: =back 
                   8806: 
1.139     matthew  8807: =head1 Statistics helper routines?  
                   8808: 
                   8809: Bad place for them but what the hell.
                   8810: 
1.157     matthew  8811: =over 4
                   8812: 
1.648     raeburn  8813: =item * &chartlink()
1.139     matthew  8814: 
                   8815: Returns a link to the chart for a specific student.  
                   8816: 
                   8817: Inputs:
                   8818: 
                   8819: =over 4
                   8820: 
                   8821: =item $linktext: The text of the link
                   8822: 
                   8823: =item $sname: The students username
                   8824: 
                   8825: =item $sdomain: The students domain
                   8826: 
                   8827: =back
                   8828: 
1.157     matthew  8829: =back
                   8830: 
1.139     matthew  8831: =cut
                   8832: 
                   8833: ############################################################
                   8834: ############################################################
                   8835: sub chartlink {
                   8836:     my ($linktext, $sname, $sdomain) = @_;
                   8837:     my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369     www      8838:         '&amp;SelectedStudent='.&escape($sname.':'.$sdomain).
1.219     albertel 8839:         '&amp;chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139     matthew  8840:        '">'.$linktext.'</a>';
1.153     matthew  8841: }
                   8842: 
                   8843: #######################################################
                   8844: #######################################################
                   8845: 
                   8846: =pod
                   8847: 
                   8848: =head1 Course Environment Routines
1.157     matthew  8849: 
                   8850: =over 4
1.153     matthew  8851: 
1.648     raeburn  8852: =item * &restore_course_settings()
1.153     matthew  8853: 
1.648     raeburn  8854: =item * &store_course_settings()
1.153     matthew  8855: 
                   8856: Restores/Store indicated form parameters from the course environment.
                   8857: Will not overwrite existing values of the form parameters.
                   8858: 
                   8859: Inputs: 
                   8860: a scalar describing the data (e.g. 'chart', 'problem_analysis')
                   8861: 
                   8862: a hash ref describing the data to be stored.  For example:
                   8863:    
                   8864: %Save_Parameters = ('Status' => 'scalar',
                   8865:     'chartoutputmode' => 'scalar',
                   8866:     'chartoutputdata' => 'scalar',
                   8867:     'Section' => 'array',
1.373     raeburn  8868:     'Group' => 'array',
1.153     matthew  8869:     'StudentData' => 'array',
                   8870:     'Maps' => 'array');
                   8871: 
                   8872: Returns: both routines return nothing
                   8873: 
1.631     raeburn  8874: =back
                   8875: 
1.153     matthew  8876: =cut
                   8877: 
                   8878: #######################################################
                   8879: #######################################################
                   8880: sub store_course_settings {
1.496     albertel 8881:     return &store_settings($env{'request.course.id'},@_);
                   8882: }
                   8883: 
                   8884: sub store_settings {
1.153     matthew  8885:     # save to the environment
                   8886:     # appenv the same items, just to be safe
1.300     albertel 8887:     my $udom  = $env{'user.domain'};
                   8888:     my $uname = $env{'user.name'};
1.496     albertel 8889:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  8890:     my %SaveHash;
                   8891:     my %AppHash;
                   8892:     while (my ($setting,$type) = each(%$Settings)) {
1.496     albertel 8893:         my $basename = join('.','internal',$context,$prefix,$setting);
1.300     albertel 8894:         my $envname = 'environment.'.$basename;
1.258     albertel 8895:         if (exists($env{'form.'.$setting})) {
1.153     matthew  8896:             # Save this value away
                   8897:             if ($type eq 'scalar' &&
1.258     albertel 8898:                 (! exists($env{$envname}) || 
                   8899:                  $env{$envname} ne $env{'form.'.$setting})) {
                   8900:                 $SaveHash{$basename} = $env{'form.'.$setting};
                   8901:                 $AppHash{$envname}   = $env{'form.'.$setting};
1.153     matthew  8902:             } elsif ($type eq 'array') {
                   8903:                 my $stored_form;
1.258     albertel 8904:                 if (ref($env{'form.'.$setting})) {
1.153     matthew  8905:                     $stored_form = join(',',
                   8906:                                         map {
1.369     www      8907:                                             &escape($_);
1.258     albertel 8908:                                         } sort(@{$env{'form.'.$setting}}));
1.153     matthew  8909:                 } else {
                   8910:                     $stored_form = 
1.369     www      8911:                         &escape($env{'form.'.$setting});
1.153     matthew  8912:                 }
                   8913:                 # Determine if the array contents are the same.
1.258     albertel 8914:                 if ($stored_form ne $env{$envname}) {
1.153     matthew  8915:                     $SaveHash{$basename} = $stored_form;
                   8916:                     $AppHash{$envname}   = $stored_form;
                   8917:                 }
                   8918:             }
                   8919:         }
                   8920:     }
                   8921:     my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300     albertel 8922:                                           $udom,$uname);
1.153     matthew  8923:     if ($put_result !~ /^(ok|delayed)/) {
                   8924:         &Apache::lonnet::logthis('unable to save form parameters, '.
                   8925:                                  'got error:'.$put_result);
                   8926:     }
                   8927:     # Make sure these settings stick around in this session, too
1.646     raeburn  8928:     &Apache::lonnet::appenv(\%AppHash);
1.153     matthew  8929:     return;
                   8930: }
                   8931: 
                   8932: sub restore_course_settings {
1.499     albertel 8933:     return &restore_settings($env{'request.course.id'},@_);
1.496     albertel 8934: }
                   8935: 
                   8936: sub restore_settings {
                   8937:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  8938:     while (my ($setting,$type) = each(%$Settings)) {
1.258     albertel 8939:         next if (exists($env{'form.'.$setting}));
1.496     albertel 8940:         my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153     matthew  8941:             '.'.$setting;
1.258     albertel 8942:         if (exists($env{$envname})) {
1.153     matthew  8943:             if ($type eq 'scalar') {
1.258     albertel 8944:                 $env{'form.'.$setting} = $env{$envname};
1.153     matthew  8945:             } elsif ($type eq 'array') {
1.258     albertel 8946:                 $env{'form.'.$setting} = [ 
1.153     matthew  8947:                                            map { 
1.369     www      8948:                                                &unescape($_); 
1.258     albertel 8949:                                            } split(',',$env{$envname})
1.153     matthew  8950:                                            ];
                   8951:             }
                   8952:         }
                   8953:     }
1.127     matthew  8954: }
                   8955: 
1.618     raeburn  8956: #######################################################
                   8957: #######################################################
                   8958: 
                   8959: =pod
                   8960: 
                   8961: =head1 Domain E-mail Routines  
                   8962: 
                   8963: =over 4
                   8964: 
1.648     raeburn  8965: =item * &build_recipient_list()
1.618     raeburn  8966: 
1.766     raeburn  8967: Build recipient lists for four types of e-mail:
                   8968: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
                   8969: (d) Help requests, generated by
                   8970: lonerrorhandler.pm, CHECKRPMS, loncron, and lonsupportreq.pm respectively.
1.618     raeburn  8971: 
                   8972: Inputs:
1.619     raeburn  8973: defmail (scalar - email address of default recipient), 
1.618     raeburn  8974: mailing type (scalar - errormail, packagesmail, or helpdeskmail), 
1.619     raeburn  8975: defdom (domain for which to retrieve configuration settings),
                   8976: origmail (scalar - email address of recipient from loncapa.conf, 
                   8977: i.e., predates configuration by DC via domainprefs.pm 
1.618     raeburn  8978: 
1.655     raeburn  8979: Returns: comma separated list of addresses to which to send e-mail.
                   8980: 
                   8981: =back
1.618     raeburn  8982: 
                   8983: =cut
                   8984: 
                   8985: ############################################################
                   8986: ############################################################
                   8987: sub build_recipient_list {
1.619     raeburn  8988:     my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618     raeburn  8989:     my @recipients;
                   8990:     my $otheremails;
                   8991:     my %domconfig =
                   8992:          &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
                   8993:     if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766     raeburn  8994:         if (exists($domconfig{'contacts'}{$mailing})) {
                   8995:             if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
                   8996:                 my @contacts = ('adminemail','supportemail');
                   8997:                 foreach my $item (@contacts) {
                   8998:                     if ($domconfig{'contacts'}{$mailing}{$item}) {
                   8999:                         my $addr = $domconfig{'contacts'}{$item}; 
                   9000:                         if (!grep(/^\Q$addr\E$/,@recipients)) {
                   9001:                             push(@recipients,$addr);
                   9002:                         }
1.619     raeburn  9003:                     }
1.766     raeburn  9004:                     $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618     raeburn  9005:                 }
                   9006:             }
1.766     raeburn  9007:         } elsif ($origmail ne '') {
                   9008:             push(@recipients,$origmail);
1.618     raeburn  9009:         }
1.619     raeburn  9010:     } elsif ($origmail ne '') {
                   9011:         push(@recipients,$origmail);
1.618     raeburn  9012:     }
1.688     raeburn  9013:     if (defined($defmail)) {
                   9014:         if ($defmail ne '') {
                   9015:             push(@recipients,$defmail);
                   9016:         }
1.618     raeburn  9017:     }
                   9018:     if ($otheremails) {
1.619     raeburn  9019:         my @others;
                   9020:         if ($otheremails =~ /,/) {
                   9021:             @others = split(/,/,$otheremails);
1.618     raeburn  9022:         } else {
1.619     raeburn  9023:             push(@others,$otheremails);
                   9024:         }
                   9025:         foreach my $addr (@others) {
                   9026:             if (!grep(/^\Q$addr\E$/,@recipients)) {
                   9027:                 push(@recipients,$addr);
                   9028:             }
1.618     raeburn  9029:         }
                   9030:     }
1.619     raeburn  9031:     my $recipientlist = join(',',@recipients); 
1.618     raeburn  9032:     return $recipientlist;
                   9033: }
                   9034: 
1.127     matthew  9035: ############################################################
                   9036: ############################################################
1.154     albertel 9037: 
1.655     raeburn  9038: =pod
                   9039: 
                   9040: =head1 Course Catalog Routines
                   9041: 
                   9042: =over 4
                   9043: 
                   9044: =item * &gather_categories()
                   9045: 
                   9046: Converts category definitions - keys of categories hash stored in  
                   9047: coursecategories in configuration.db on the primary library server in a 
                   9048: domain - to an array.  Also generates javascript and idx hash used to 
                   9049: generate Domain Coordinator interface for editing Course Categories.
                   9050: 
                   9051: Inputs:
1.663     raeburn  9052: 
1.655     raeburn  9053: categories (reference to hash of category definitions).
1.663     raeburn  9054: 
1.655     raeburn  9055: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   9056:       categories and subcategories).
1.663     raeburn  9057: 
1.655     raeburn  9058: idx (reference to hash of counters used in Domain Coordinator interface for 
                   9059:       editing Course Categories).
1.663     raeburn  9060: 
1.655     raeburn  9061: jsarray (reference to array of categories used to create Javascript arrays for
                   9062:          Domain Coordinator interface for editing Course Categories).
                   9063: 
                   9064: Returns: nothing
                   9065: 
                   9066: Side effects: populates cats, idx and jsarray. 
                   9067: 
                   9068: =cut
                   9069: 
                   9070: sub gather_categories {
                   9071:     my ($categories,$cats,$idx,$jsarray) = @_;
                   9072:     my %counters;
                   9073:     my $num = 0;
                   9074:     foreach my $item (keys(%{$categories})) {
                   9075:         my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
                   9076:         if ($container eq '' && $depth == 0) {
                   9077:             $cats->[$depth][$categories->{$item}] = $cat;
                   9078:         } else {
                   9079:             $cats->[$depth]{$container}[$categories->{$item}] = $cat;
                   9080:         }
                   9081:         my ($escitem,$tail) = split(/:/,$item,2);
                   9082:         if ($counters{$tail} eq '') {
                   9083:             $counters{$tail} = $num;
                   9084:             $num ++;
                   9085:         }
                   9086:         if (ref($idx) eq 'HASH') {
                   9087:             $idx->{$item} = $counters{$tail};
                   9088:         }
                   9089:         if (ref($jsarray) eq 'ARRAY') {
                   9090:             push(@{$jsarray->[$counters{$tail}]},$item);
                   9091:         }
                   9092:     }
                   9093:     return;
                   9094: }
                   9095: 
                   9096: =pod
                   9097: 
                   9098: =item * &extract_categories()
                   9099: 
                   9100: Used to generate breadcrumb trails for course categories.
                   9101: 
                   9102: Inputs:
1.663     raeburn  9103: 
1.655     raeburn  9104: categories (reference to hash of category definitions).
1.663     raeburn  9105: 
1.655     raeburn  9106: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   9107:       categories and subcategories).
1.663     raeburn  9108: 
1.655     raeburn  9109: trails (reference to array of breacrumb trails for each category).
1.663     raeburn  9110: 
1.655     raeburn  9111: allitems (reference to hash - key is category key 
                   9112:          (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663     raeburn  9113: 
1.655     raeburn  9114: idx (reference to hash of counters used in Domain Coordinator interface for
                   9115:       editing Course Categories).
1.663     raeburn  9116: 
1.655     raeburn  9117: jsarray (reference to array of categories used to create Javascript arrays for
                   9118:          Domain Coordinator interface for editing Course Categories).
                   9119: 
1.665     raeburn  9120: subcats (reference to hash of arrays containing all subcategories within each 
                   9121:          category, -recursive)
                   9122: 
1.655     raeburn  9123: Returns: nothing
                   9124: 
                   9125: Side effects: populates trails and allitems hash references.
                   9126: 
                   9127: =cut
                   9128: 
                   9129: sub extract_categories {
1.665     raeburn  9130:     my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655     raeburn  9131:     if (ref($categories) eq 'HASH') {
                   9132:         &gather_categories($categories,$cats,$idx,$jsarray);
                   9133:         if (ref($cats->[0]) eq 'ARRAY') {
                   9134:             for (my $i=0; $i<@{$cats->[0]}; $i++) {
                   9135:                 my $name = $cats->[0][$i];
                   9136:                 my $item = &escape($name).'::0';
                   9137:                 my $trailstr;
                   9138:                 if ($name eq 'instcode') {
                   9139:                     $trailstr = &mt('Official courses (with institutional codes)');
                   9140:                 } else {
                   9141:                     $trailstr = $name;
                   9142:                 }
                   9143:                 if ($allitems->{$item} eq '') {
                   9144:                     push(@{$trails},$trailstr);
                   9145:                     $allitems->{$item} = scalar(@{$trails})-1;
                   9146:                 }
                   9147:                 my @parents = ($name);
                   9148:                 if (ref($cats->[1]{$name}) eq 'ARRAY') {
                   9149:                     for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
                   9150:                         my $category = $cats->[1]{$name}[$j];
1.665     raeburn  9151:                         if (ref($subcats) eq 'HASH') {
                   9152:                             push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
                   9153:                         }
                   9154:                         &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
                   9155:                     }
                   9156:                 } else {
                   9157:                     if (ref($subcats) eq 'HASH') {
                   9158:                         $subcats->{$item} = [];
1.655     raeburn  9159:                     }
                   9160:                 }
                   9161:             }
                   9162:         }
                   9163:     }
                   9164:     return;
                   9165: }
                   9166: 
                   9167: =pod
                   9168: 
                   9169: =item *&recurse_categories()
                   9170: 
                   9171: Recursively used to generate breadcrumb trails for course categories.
                   9172: 
                   9173: Inputs:
1.663     raeburn  9174: 
1.655     raeburn  9175: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   9176:       categories and subcategories).
1.663     raeburn  9177: 
1.655     raeburn  9178: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663     raeburn  9179: 
                   9180: category (current course category, for which breadcrumb trail is being generated).
                   9181: 
                   9182: trails (reference to array of breadcrumb trails for each category).
                   9183: 
1.655     raeburn  9184: allitems (reference to hash - key is category key
                   9185:          (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663     raeburn  9186: 
1.655     raeburn  9187: parents (array containing containers directories for current category, 
                   9188:          back to top level). 
                   9189: 
                   9190: Returns: nothing
                   9191: 
                   9192: Side effects: populates trails and allitems hash references
                   9193: 
                   9194: =cut
                   9195: 
                   9196: sub recurse_categories {
1.665     raeburn  9197:     my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655     raeburn  9198:     my $shallower = $depth - 1;
                   9199:     if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
                   9200:         for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
                   9201:             my $name = $cats->[$depth]{$category}[$k];
                   9202:             my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
                   9203:             my $trailstr = join(' -&gt; ',(@{$parents},$category));
                   9204:             if ($allitems->{$item} eq '') {
                   9205:                 push(@{$trails},$trailstr);
                   9206:                 $allitems->{$item} = scalar(@{$trails})-1;
                   9207:             }
                   9208:             my $deeper = $depth+1;
                   9209:             push(@{$parents},$category);
1.665     raeburn  9210:             if (ref($subcats) eq 'HASH') {
                   9211:                 my $subcat = &escape($name).':'.$category.':'.$depth;
                   9212:                 for (my $j=@{$parents}; $j>=0; $j--) {
                   9213:                     my $higher;
                   9214:                     if ($j > 0) {
                   9215:                         $higher = &escape($parents->[$j]).':'.
                   9216:                                   &escape($parents->[$j-1]).':'.$j;
                   9217:                     } else {
                   9218:                         $higher = &escape($parents->[$j]).'::'.$j;
                   9219:                     }
                   9220:                     push(@{$subcats->{$higher}},$subcat);
                   9221:                 }
                   9222:             }
                   9223:             &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
                   9224:                                 $subcats);
1.655     raeburn  9225:             pop(@{$parents});
                   9226:         }
                   9227:     } else {
                   9228:         my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
                   9229:         my $trailstr = join(' -&gt; ',(@{$parents},$category));
                   9230:         if ($allitems->{$item} eq '') {
                   9231:             push(@{$trails},$trailstr);
                   9232:             $allitems->{$item} = scalar(@{$trails})-1;
                   9233:         }
                   9234:     }
                   9235:     return;
                   9236: }
                   9237: 
1.663     raeburn  9238: =pod
                   9239: 
                   9240: =item *&assign_categories_table()
                   9241: 
                   9242: Create a datatable for display of hierarchical categories in a domain,
                   9243: with checkboxes to allow a course to be categorized. 
                   9244: 
                   9245: Inputs:
                   9246: 
                   9247: cathash - reference to hash of categories defined for the domain (from
                   9248:           configuration.db)
                   9249: 
                   9250: currcat - scalar with an & separated list of categories assigned to a course. 
                   9251: 
                   9252: Returns: $output (markup to be displayed) 
                   9253: 
                   9254: =cut
                   9255: 
                   9256: sub assign_categories_table {
                   9257:     my ($cathash,$currcat) = @_;
                   9258:     my $output;
                   9259:     if (ref($cathash) eq 'HASH') {
                   9260:         my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
                   9261:         &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
                   9262:         $maxdepth = scalar(@cats);
                   9263:         if (@cats > 0) {
                   9264:             my $itemcount = 0;
                   9265:             if (ref($cats[0]) eq 'ARRAY') {
                   9266:                 $output = &Apache::loncommon::start_data_table();
                   9267:                 my @currcategories;
                   9268:                 if ($currcat ne '') {
                   9269:                     @currcategories = split('&',$currcat);
                   9270:                 }
                   9271:                 for (my $i=0; $i<@{$cats[0]}; $i++) {
                   9272:                     my $parent = $cats[0][$i];
                   9273:                     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   9274:                     next if ($parent eq 'instcode');
                   9275:                     my $item = &escape($parent).'::0';
                   9276:                     my $checked = '';
                   9277:                     if (@currcategories > 0) {
                   9278:                         if (grep(/^\Q$item\E$/,@currcategories)) {
1.772     bisitz   9279:                             $checked = ' checked="checked"';
1.663     raeburn  9280:                         }
                   9281:                     }
1.675     raeburn  9282:                     $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
                   9283:                                '<input type="checkbox" name="usecategory" value="'.
                   9284:                                $item.'"'.$checked.' />'.$parent.'</span>'.
                   9285:                                '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663     raeburn  9286:                     my $depth = 1;
                   9287:                     push(@path,$parent);
                   9288:                     $output .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
                   9289:                     pop(@path);
                   9290:                     $output .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
                   9291:                     $itemcount ++;
                   9292:                 }
                   9293:                 $output .= &Apache::loncommon::end_data_table();
                   9294:             }
                   9295:         }
                   9296:     }
                   9297:     return $output;
                   9298: }
                   9299: 
                   9300: =pod
                   9301: 
                   9302: =item *&assign_category_rows()
                   9303: 
                   9304: Create a datatable row for display of nested categories in a domain,
                   9305: with checkboxes to allow a course to be categorized,called recursively.
                   9306: 
                   9307: Inputs:
                   9308: 
                   9309: itemcount - track row number for alternating colors
                   9310: 
                   9311: cats - reference to array of arrays/hashes which encapsulates hierarchy of
                   9312:       categories and subcategories.
                   9313: 
                   9314: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
                   9315: 
                   9316: parent - parent of current category item
                   9317: 
                   9318: path - Array containing all categories back up through the hierarchy from the
                   9319:        current category to the top level.
                   9320: 
                   9321: currcategories - reference to array of current categories assigned to the course
                   9322: 
                   9323: Returns: $output (markup to be displayed).
                   9324: 
                   9325: =cut
                   9326: 
                   9327: sub assign_category_rows {
                   9328:     my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
                   9329:     my ($text,$name,$item,$chgstr);
                   9330:     if (ref($cats) eq 'ARRAY') {
                   9331:         my $maxdepth = scalar(@{$cats});
                   9332:         if (ref($cats->[$depth]) eq 'HASH') {
                   9333:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   9334:                 my $numchildren = @{$cats->[$depth]{$parent}};
                   9335:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   9336:                 $text .= '<td><table class="LC_datatable">';
                   9337:                 for (my $j=0; $j<$numchildren; $j++) {
                   9338:                     $name = $cats->[$depth]{$parent}[$j];
                   9339:                     $item = &escape($name).':'.&escape($parent).':'.$depth;
                   9340:                     my $deeper = $depth+1;
                   9341:                     my $checked = '';
                   9342:                     if (ref($currcategories) eq 'ARRAY') {
                   9343:                         if (@{$currcategories} > 0) {
                   9344:                             if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772     bisitz   9345:                                 $checked = ' checked="checked"';
1.663     raeburn  9346:                             }
                   9347:                         }
                   9348:                     }
1.664     raeburn  9349:                     $text .= '<tr><td><span class="LC_nobreak"><label>'.
                   9350:                              '<input type="checkbox" name="usecategory" value="'.
1.675     raeburn  9351:                              $item.'"'.$checked.' />'.$name.'</label></span>'.
                   9352:                              '<input type="hidden" name="catname" value="'.$name.'" />'.
                   9353:                              '</td><td>';
1.663     raeburn  9354:                     if (ref($path) eq 'ARRAY') {
                   9355:                         push(@{$path},$name);
                   9356:                         $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
                   9357:                         pop(@{$path});
                   9358:                     }
                   9359:                     $text .= '</td></tr>';
                   9360:                 }
                   9361:                 $text .= '</table></td>';
                   9362:             }
                   9363:         }
                   9364:     }
                   9365:     return $text;
                   9366: }
                   9367: 
1.655     raeburn  9368: ############################################################
                   9369: ############################################################
                   9370: 
                   9371: 
1.443     albertel 9372: sub commit_customrole {
1.664     raeburn  9373:     my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630     raeburn  9374:     my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443     albertel 9375:                          ($start?', '.&mt('starting').' '.localtime($start):'').
                   9376:                          ($end?', ending '.localtime($end):'').': <b>'.
                   9377:               &Apache::lonnet::assigncustomrole(
1.664     raeburn  9378:                  $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443     albertel 9379:                  '</b><br />';
                   9380:     return $output;
                   9381: }
                   9382: 
                   9383: sub commit_standardrole {
1.541     raeburn  9384:     my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
                   9385:     my ($output,$logmsg,$linefeed);
                   9386:     if ($context eq 'auto') {
                   9387:         $linefeed = "\n";
                   9388:     } else {
                   9389:         $linefeed = "<br />\n";
                   9390:     }  
1.443     albertel 9391:     if ($three eq 'st') {
1.541     raeburn  9392:         my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
                   9393:                                          $one,$two,$sec,$context);
                   9394:         if (($result =~ /^error/) || ($result eq 'not_in_class') || 
1.626     raeburn  9395:             ($result eq 'unknown_course') || ($result eq 'refused')) {
                   9396:             $output = $logmsg.' '.&mt('Error: ').$result."\n"; 
1.443     albertel 9397:         } else {
1.541     raeburn  9398:             $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443     albertel 9399:                ($start?', '.&mt('starting').' '.localtime($start):'').
1.541     raeburn  9400:                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
                   9401:             if ($context eq 'auto') {
                   9402:                 $output .= $result.$linefeed.&mt('Add to classlist').': ok';
                   9403:             } else {
                   9404:                $output .= '<b>'.$result.'</b>'.$linefeed.
                   9405:                &mt('Add to classlist').': <b>ok</b>';
                   9406:             }
                   9407:             $output .= $linefeed;
1.443     albertel 9408:         }
                   9409:     } else {
                   9410:         $output = &mt('Assigning').' '.$three.' in '.$url.
                   9411:                ($start?', '.&mt('starting').' '.localtime($start):'').
1.541     raeburn  9412:                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652     raeburn  9413:         my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541     raeburn  9414:         if ($context eq 'auto') {
                   9415:             $output .= $result.$linefeed;
                   9416:         } else {
                   9417:             $output .= '<b>'.$result.'</b>'.$linefeed;
                   9418:         }
1.443     albertel 9419:     }
                   9420:     return $output;
                   9421: }
                   9422: 
                   9423: sub commit_studentrole {
1.541     raeburn  9424:     my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626     raeburn  9425:     my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541     raeburn  9426:     if ($context eq 'auto') {
                   9427:         $linefeed = "\n";
                   9428:     } else {
                   9429:         $linefeed = '<br />'."\n";
                   9430:     }
1.443     albertel 9431:     if (defined($one) && defined($two)) {
                   9432:         my $cid=$one.'_'.$two;
                   9433:         my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
                   9434:         my $secchange = 0;
                   9435:         my $expire_role_result;
                   9436:         my $modify_section_result;
1.628     raeburn  9437:         if ($oldsec ne '-1') { 
                   9438:             if ($oldsec ne $sec) {
1.443     albertel 9439:                 $secchange = 1;
1.628     raeburn  9440:                 my $now = time;
1.443     albertel 9441:                 my $uurl='/'.$cid;
                   9442:                 $uurl=~s/\_/\//g;
                   9443:                 if ($oldsec) {
                   9444:                     $uurl.='/'.$oldsec;
                   9445:                 }
1.626     raeburn  9446:                 $oldsecurl = $uurl;
1.628     raeburn  9447:                 $expire_role_result = 
1.652     raeburn  9448:                     &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628     raeburn  9449:                 if ($env{'request.course.sec'} ne '') { 
                   9450:                     if ($expire_role_result eq 'refused') {
                   9451:                         my @roles = ('st');
                   9452:                         my @statuses = ('previous');
                   9453:                         my @roledoms = ($one);
                   9454:                         my $withsec = 1;
                   9455:                         my %roleshash = 
                   9456:                             &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
                   9457:                                               \@statuses,\@roles,\@roledoms,$withsec);
                   9458:                         if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
                   9459:                             my ($oldstart,$oldend) = 
                   9460:                                 split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
                   9461:                             if ($oldend > 0 && $oldend <= $now) {
                   9462:                                 $expire_role_result = 'ok';
                   9463:                             }
                   9464:                         }
                   9465:                     }
                   9466:                 }
1.443     albertel 9467:                 $result = $expire_role_result;
                   9468:             }
                   9469:         }
                   9470:         if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652     raeburn  9471:             $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443     albertel 9472:             if ($modify_section_result =~ /^ok/) {
                   9473:                 if ($secchange == 1) {
1.628     raeburn  9474:                     if ($sec eq '') {
                   9475:                         $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
                   9476:                     } else {
                   9477:                         $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
                   9478:                     }
1.443     albertel 9479:                 } elsif ($oldsec eq '-1') {
1.628     raeburn  9480:                     if ($sec eq '') {
                   9481:                         $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
                   9482:                     } else {
                   9483:                         $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                   9484:                     }
1.443     albertel 9485:                 } else {
1.628     raeburn  9486:                     if ($sec eq '') {
                   9487:                         $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
                   9488:                     } else {
                   9489:                         $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                   9490:                     }
1.443     albertel 9491:                 }
                   9492:             } else {
1.628     raeburn  9493:                 if ($secchange) {       
                   9494:                     $$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;
                   9495:                 } else {
                   9496:                     $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
                   9497:                 }
1.443     albertel 9498:             }
                   9499:             $result = $modify_section_result;
                   9500:         } elsif ($secchange == 1) {
1.628     raeburn  9501:             if ($oldsec eq '') {
                   9502:                 $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
                   9503:             } else {
                   9504:                 $$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;
                   9505:             }
1.626     raeburn  9506:             if ($expire_role_result eq 'refused') {
                   9507:                 my $newsecurl = '/'.$cid;
                   9508:                 $newsecurl =~ s/\_/\//g;
                   9509:                 if ($sec ne '') {
                   9510:                     $newsecurl.='/'.$sec;
                   9511:                 }
                   9512:                 if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
                   9513:                     if ($sec eq '') {
                   9514:                         $$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;
                   9515:                     } else {
                   9516:                         $$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;
                   9517:                     }
                   9518:                 }
                   9519:             }
1.443     albertel 9520:         }
                   9521:     } else {
1.626     raeburn  9522:         $$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 9523:         $result = "error: incomplete course id\n";
                   9524:     }
                   9525:     return $result;
                   9526: }
                   9527: 
                   9528: ############################################################
                   9529: ############################################################
                   9530: 
1.566     albertel 9531: sub check_clone {
1.578     raeburn  9532:     my ($args,$linefeed) = @_;
1.566     albertel 9533:     my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
                   9534:     my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
                   9535:     my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
                   9536:     my $clonemsg;
                   9537:     my $can_clone = 0;
                   9538: 
                   9539:     if ($clonehome eq 'no_host') {
1.578     raeburn  9540:         $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 9541:     } else {
                   9542: 	my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.568     albertel 9543: 	if ($env{'request.role.domain'} eq $args->{'clonedomain'}) {
1.566     albertel 9544: 	    $can_clone = 1;
                   9545: 	} else {
                   9546: 	    my %clonehash = &Apache::lonnet::get('environment',['cloners'],
                   9547: 						 $args->{'clonedomain'},$args->{'clonecourse'});
                   9548: 	    my @cloners = split(/,/,$clonehash{'cloners'});
1.578     raeburn  9549:             if (grep(/^\*$/,@cloners)) {
                   9550:                 $can_clone = 1;
                   9551:             } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
                   9552:                 $can_clone = 1;
                   9553:             } else {
                   9554: 	        my %roleshash =
                   9555: 		    &Apache::lonnet::get_my_roles($args->{'ccuname'},
                   9556: 					 $args->{'ccdomain'},
                   9557:                                          'userroles',['active'],['cc'],
                   9558: 					 [$args->{'clonedomain'}]);
                   9559: 	        if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
                   9560: 		    $can_clone = 1;
                   9561: 	        } else {
                   9562:                     $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'});
                   9563: 	        }
1.566     albertel 9564: 	    }
1.578     raeburn  9565:         }
1.566     albertel 9566:     }
                   9567:     return ($can_clone, $clonemsg, $cloneid, $clonehome);
                   9568: }
                   9569: 
1.444     albertel 9570: sub construct_course {
1.541     raeburn  9571:     my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context) = @_;
1.444     albertel 9572:     my $outcome;
1.541     raeburn  9573:     my $linefeed =  '<br />'."\n";
                   9574:     if ($context eq 'auto') {
                   9575:         $linefeed = "\n";
                   9576:     }
1.566     albertel 9577: 
                   9578: #
                   9579: # Are we cloning?
                   9580: #
                   9581:     my ($can_clone, $clonemsg, $cloneid, $clonehome);
                   9582:     if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578     raeburn  9583: 	($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566     albertel 9584: 	if ($context ne 'auto') {
1.578     raeburn  9585:             if ($clonemsg ne '') {
                   9586: 	        $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
                   9587:             }
1.566     albertel 9588: 	}
                   9589: 	$outcome .= $clonemsg.$linefeed;
                   9590: 
                   9591:         if (!$can_clone) {
                   9592: 	    return (0,$outcome);
                   9593: 	}
                   9594:     }
                   9595: 
1.444     albertel 9596: #
                   9597: # Open course
                   9598: #
                   9599:     my $crstype = lc($args->{'crstype'});
                   9600:     my %cenv=();
                   9601:     $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
                   9602:                                              $args->{'cdescr'},
                   9603:                                              $args->{'curl'},
                   9604:                                              $args->{'course_home'},
                   9605:                                              $args->{'nonstandard'},
                   9606:                                              $args->{'crscode'},
                   9607:                                              $args->{'ccuname'}.':'.
                   9608:                                              $args->{'ccdomain'},
                   9609:                                              $args->{'crstype'});
                   9610: 
                   9611:     # Note: The testing routines depend on this being output; see 
                   9612:     # Utils::Course. This needs to at least be output as a comment
                   9613:     # if anyone ever decides to not show this, and Utils::Course::new
                   9614:     # will need to be suitably modified.
1.541     raeburn  9615:     $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.444     albertel 9616: #
                   9617: # Check if created correctly
                   9618: #
1.479     albertel 9619:     ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444     albertel 9620:     my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.541     raeburn  9621:     $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566     albertel 9622: 
1.444     albertel 9623: #
1.566     albertel 9624: # Do the cloning
                   9625: #   
                   9626:     if ($can_clone && $cloneid) {
                   9627: 	$clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
                   9628: 	if ($context ne 'auto') {
                   9629: 	    $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
                   9630: 	}
                   9631: 	$outcome .= $clonemsg.$linefeed;
                   9632: 	my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444     albertel 9633: # Copy all files
1.637     www      9634: 	&Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444     albertel 9635: # Restore URL
1.566     albertel 9636: 	$cenv{'url'}=$oldcenv{'url'};
1.444     albertel 9637: # Restore title
1.566     albertel 9638: 	$cenv{'description'}=$oldcenv{'description'};
1.444     albertel 9639: # Mark as cloned
1.566     albertel 9640: 	$cenv{'clonedfrom'}=$cloneid;
1.638     www      9641: # Need to clone grading mode
                   9642:         my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
                   9643:         $cenv{'grading'}=$newenv{'grading'};
                   9644: # Do not clone these environment entries
                   9645:         &Apache::lonnet::del('environment',
                   9646:                   ['default_enrollment_start_date',
                   9647:                    'default_enrollment_end_date',
                   9648:                    'question.email',
                   9649:                    'policy.email',
                   9650:                    'comment.email',
                   9651:                    'pch.users.denied',
1.725     raeburn  9652:                    'plc.users.denied',
                   9653:                    'hidefromcat',
                   9654:                    'categories'],
1.638     www      9655:                    $$crsudom,$$crsunum);
1.444     albertel 9656:     }
1.566     albertel 9657: 
1.444     albertel 9658: #
                   9659: # Set environment (will override cloned, if existing)
                   9660: #
                   9661:     my @sections = ();
                   9662:     my @xlists = ();
                   9663:     if ($args->{'crstype'}) {
                   9664:         $cenv{'type'}=$args->{'crstype'};
                   9665:     }
                   9666:     if ($args->{'crsid'}) {
                   9667:         $cenv{'courseid'}=$args->{'crsid'};
                   9668:     }
                   9669:     if ($args->{'crscode'}) {
                   9670:         $cenv{'internal.coursecode'}=$args->{'crscode'};
                   9671:     }
                   9672:     if ($args->{'crsquota'} ne '') {
                   9673:         $cenv{'internal.coursequota'}=$args->{'crsquota'};
                   9674:     } else {
                   9675:         $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
                   9676:     }
                   9677:     if ($args->{'ccuname'}) {
                   9678:         $cenv{'internal.courseowner'} = $args->{'ccuname'}.
                   9679:                                         ':'.$args->{'ccdomain'};
                   9680:     } else {
                   9681:         $cenv{'internal.courseowner'} = $args->{'curruser'};
                   9682:     }
                   9683:     my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
                   9684:     if ($args->{'crssections'}) {
                   9685:         $cenv{'internal.sectionnums'} = '';
                   9686:         if ($args->{'crssections'} =~ m/,/) {
                   9687:             @sections = split/,/,$args->{'crssections'};
                   9688:         } else {
                   9689:             $sections[0] = $args->{'crssections'};
                   9690:         }
                   9691:         if (@sections > 0) {
                   9692:             foreach my $item (@sections) {
                   9693:                 my ($sec,$gp) = split/:/,$item;
                   9694:                 my $class = $args->{'crscode'}.$sec;
                   9695:                 my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
                   9696:                 $cenv{'internal.sectionnums'} .= $item.',';
                   9697:                 unless ($addcheck eq 'ok') {
                   9698:                     push @badclasses, $class;
                   9699:                 }
                   9700:             }
                   9701:             $cenv{'internal.sectionnums'} =~ s/,$//;
                   9702:         }
                   9703:     }
                   9704: # do not hide course coordinator from staff listing, 
                   9705: # even if privileged
                   9706:     $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   9707: # add crosslistings
                   9708:     if ($args->{'crsxlist'}) {
                   9709:         $cenv{'internal.crosslistings'}='';
                   9710:         if ($args->{'crsxlist'} =~ m/,/) {
                   9711:             @xlists = split/,/,$args->{'crsxlist'};
                   9712:         } else {
                   9713:             $xlists[0] = $args->{'crsxlist'};
                   9714:         }
                   9715:         if (@xlists > 0) {
                   9716:             foreach my $item (@xlists) {
                   9717:                 my ($xl,$gp) = split/:/,$item;
                   9718:                 my $addcheck =  &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
                   9719:                 $cenv{'internal.crosslistings'} .= $item.',';
                   9720:                 unless ($addcheck eq 'ok') {
                   9721:                     push @badclasses, $xl;
                   9722:                 }
                   9723:             }
                   9724:             $cenv{'internal.crosslistings'} =~ s/,$//;
                   9725:         }
                   9726:     }
                   9727:     if ($args->{'autoadds'}) {
                   9728:         $cenv{'internal.autoadds'}=$args->{'autoadds'};
                   9729:     }
                   9730:     if ($args->{'autodrops'}) {
                   9731:         $cenv{'internal.autodrops'}=$args->{'autodrops'};
                   9732:     }
                   9733: # check for notification of enrollment changes
                   9734:     my @notified = ();
                   9735:     if ($args->{'notify_owner'}) {
                   9736:         if ($args->{'ccuname'} ne '') {
                   9737:             push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
                   9738:         }
                   9739:     }
                   9740:     if ($args->{'notify_dc'}) {
                   9741:         if ($uname ne '') { 
1.630     raeburn  9742:             push(@notified,$uname.':'.$udom);
1.444     albertel 9743:         }
                   9744:     }
                   9745:     if (@notified > 0) {
                   9746:         my $notifylist;
                   9747:         if (@notified > 1) {
                   9748:             $notifylist = join(',',@notified);
                   9749:         } else {
                   9750:             $notifylist = $notified[0];
                   9751:         }
                   9752:         $cenv{'internal.notifylist'} = $notifylist;
                   9753:     }
                   9754:     if (@badclasses > 0) {
                   9755:         my %lt=&Apache::lonlocal::texthash(
                   9756:                 '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',
                   9757:                 'dnhr' => 'does not have rights to access enrollment in these classes',
                   9758:                 'adby' => 'as determined by the policies of your institution on access to official classlists'
                   9759:         );
1.541     raeburn  9760:         my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
                   9761:                            ' ('.$lt{'adby'}.')';
                   9762:         if ($context eq 'auto') {
                   9763:             $outcome .= $badclass_msg.$linefeed;
1.566     albertel 9764:             $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541     raeburn  9765:             foreach my $item (@badclasses) {
                   9766:                 if ($context eq 'auto') {
                   9767:                     $outcome .= " - $item\n";
                   9768:                 } else {
                   9769:                     $outcome .= "<li>$item</li>\n";
                   9770:                 }
                   9771:             }
                   9772:             if ($context eq 'auto') {
                   9773:                 $outcome .= $linefeed;
                   9774:             } else {
1.566     albertel 9775:                 $outcome .= "</ul><br /><br /></div>\n";
1.541     raeburn  9776:             }
                   9777:         } 
1.444     albertel 9778:     }
                   9779:     if ($args->{'no_end_date'}) {
                   9780:         $args->{'endaccess'} = 0;
                   9781:     }
                   9782:     $cenv{'internal.autostart'}=$args->{'enrollstart'};
                   9783:     $cenv{'internal.autoend'}=$args->{'enrollend'};
                   9784:     $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
                   9785:     $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
                   9786:     if ($args->{'showphotos'}) {
                   9787:       $cenv{'internal.showphotos'}=$args->{'showphotos'};
                   9788:     }
                   9789:     $cenv{'internal.authtype'} = $args->{'authtype'};
                   9790:     $cenv{'internal.autharg'} = $args->{'autharg'}; 
                   9791:     if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
                   9792:         if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'}  eq '') {
1.541     raeburn  9793:             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'); 
                   9794:             if ($context eq 'auto') {
                   9795:                 $outcome .= $krb_msg;
                   9796:             } else {
1.566     albertel 9797:                 $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541     raeburn  9798:             }
                   9799:             $outcome .= $linefeed;
1.444     albertel 9800:         }
                   9801:     }
                   9802:     if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
                   9803:        if ($args->{'setpolicy'}) {
                   9804:            $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   9805:        }
                   9806:        if ($args->{'setcontent'}) {
                   9807:            $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   9808:        }
                   9809:     }
                   9810:     if ($args->{'reshome'}) {
                   9811: 	$cenv{'reshome'}=$args->{'reshome'}.'/';
                   9812: 	$cenv{'reshome'}=~s/\/+$/\//;
                   9813:     }
                   9814: #
                   9815: # course has keyed access
                   9816: #
                   9817:     if ($args->{'setkeys'}) {
                   9818:        $cenv{'keyaccess'}='yes';
                   9819:     }
                   9820: # if specified, key authority is not course, but user
                   9821: # only active if keyaccess is yes
                   9822:     if ($args->{'keyauth'}) {
1.487     albertel 9823: 	my ($user,$domain) = split(':',$args->{'keyauth'});
                   9824: 	$user = &LONCAPA::clean_username($user);
                   9825: 	$domain = &LONCAPA::clean_username($domain);
1.488     foxr     9826: 	if ($user ne '' && $domain ne '') {
1.487     albertel 9827: 	    $cenv{'keyauth'}=$user.':'.$domain;
1.444     albertel 9828: 	}
                   9829:     }
                   9830: 
                   9831:     if ($args->{'disresdis'}) {
                   9832:         $cenv{'pch.roles.denied'}='st';
                   9833:     }
                   9834:     if ($args->{'disablechat'}) {
                   9835:         $cenv{'plc.roles.denied'}='st';
                   9836:     }
                   9837: 
                   9838:     # Record we've not yet viewed the Course Initialization Helper for this 
                   9839:     # course
                   9840:     $cenv{'course.helper.not.run'} = 1;
                   9841:     #
                   9842:     # Use new Randomseed
                   9843:     #
                   9844:     $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
                   9845:     $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
                   9846:     #
                   9847:     # The encryption code and receipt prefix for this course
                   9848:     #
                   9849:     $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
                   9850:     $cenv{'internal.encpref'}=100+int(9*rand(99));
                   9851:     #
                   9852:     # By default, use standard grading
                   9853:     if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
                   9854: 
1.541     raeburn  9855:     $outcome .= $linefeed.&mt('Setting environment').': '.                 
                   9856:           &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444     albertel 9857: #
                   9858: # Open all assignments
                   9859: #
                   9860:     if ($args->{'openall'}) {
                   9861:        my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
                   9862:        my %storecontent = ($storeunder         => time,
                   9863:                            $storeunder.'.type' => 'date_start');
                   9864:        
                   9865:        $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541     raeburn  9866:                  ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444     albertel 9867:    }
                   9868: #
                   9869: # Set first page
                   9870: #
                   9871:     unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
                   9872: 	    || ($cloneid)) {
1.445     albertel 9873: 	use LONCAPA::map;
1.444     albertel 9874: 	$outcome .= &mt('Setting first resource').': ';
1.445     albertel 9875: 
                   9876: 	my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
                   9877:         my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
                   9878: 
1.444     albertel 9879:         $outcome .= ($fatal?$errtext:'read ok').' - ';
                   9880:         my $title; my $url;
                   9881:         if ($args->{'firstres'} eq 'syl') {
1.690     bisitz   9882: 	    $title=&mt('Syllabus');
1.444     albertel 9883:             $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
                   9884:         } else {
1.690     bisitz   9885:             $title=&mt('Navigate Contents');
1.444     albertel 9886:             $url='/adm/navmaps';
                   9887:         }
1.445     albertel 9888: 
                   9889:         $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
                   9890: 	(my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
                   9891: 
                   9892: 	if ($errtext) { $fatal=2; }
1.541     raeburn  9893:         $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444     albertel 9894:     }
1.566     albertel 9895: 
                   9896:     return (1,$outcome);
1.444     albertel 9897: }
                   9898: 
                   9899: ############################################################
                   9900: ############################################################
                   9901: 
1.378     raeburn  9902: sub course_type {
                   9903:     my ($cid) = @_;
                   9904:     if (!defined($cid)) {
                   9905:         $cid = $env{'request.course.id'};
                   9906:     }
1.404     albertel 9907:     if (defined($env{'course.'.$cid.'.type'})) {
                   9908:         return $env{'course.'.$cid.'.type'};
1.378     raeburn  9909:     } else {
                   9910:         return 'Course';
1.377     raeburn  9911:     }
                   9912: }
1.156     albertel 9913: 
1.406     raeburn  9914: sub group_term {
                   9915:     my $crstype = &course_type();
                   9916:     my %names = (
                   9917:                   'Course' => 'group',
                   9918:                   'Group' => 'team',
                   9919:                 );
                   9920:     return $names{$crstype};
                   9921: }
                   9922: 
1.156     albertel 9923: sub icon {
                   9924:     my ($file)=@_;
1.505     albertel 9925:     my $curfext = lc((split(/\./,$file))[-1]);
1.168     albertel 9926:     my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156     albertel 9927:     my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168     albertel 9928:     if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
                   9929: 	if (-e  $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
                   9930: 	          $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   9931: 	            $curfext.".gif") {
                   9932: 	    $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   9933: 		$curfext.".gif";
                   9934: 	}
                   9935:     }
1.249     albertel 9936:     return &lonhttpdurl($iconname);
1.154     albertel 9937: } 
1.84      albertel 9938: 
1.575     albertel 9939: sub lonhttpdurl {
1.692     www      9940: #
                   9941: # Had been used for "small fry" static images on separate port 8080.
                   9942: # Modify here if lightweight http functionality desired again.
                   9943: # Currently eliminated due to increasing firewall issues.
                   9944: #
1.575     albertel 9945:     my ($url)=@_;
1.692     www      9946:     return $url;
1.215     albertel 9947: }
                   9948: 
1.213     albertel 9949: sub connection_aborted {
                   9950:     my ($r)=@_;
                   9951:     $r->print(" ");$r->rflush();
                   9952:     my $c = $r->connection;
                   9953:     return $c->aborted();
                   9954: }
                   9955: 
1.221     foxr     9956: #    Escapes strings that may have embedded 's that will be put into
1.222     foxr     9957: #    strings as 'strings'.
                   9958: sub escape_single {
1.221     foxr     9959:     my ($input) = @_;
1.223     albertel 9960:     $input =~ s/\\/\\\\/g;	# Escape the \'s..(must be first)>
1.221     foxr     9961:     $input =~ s/\'/\\\'/g;	# Esacpe the 's....
                   9962:     return $input;
                   9963: }
1.223     albertel 9964: 
1.222     foxr     9965: #  Same as escape_single, but escape's "'s  This 
                   9966: #  can be used for  "strings"
                   9967: sub escape_double {
                   9968:     my ($input) = @_;
                   9969:     $input =~ s/\\/\\\\/g;	# Escape the /'s..(must be first)>
                   9970:     $input =~ s/\"/\\\"/g;	# Esacpe the "s....
                   9971:     return $input;
                   9972: }
1.223     albertel 9973:  
1.222     foxr     9974: #   Escapes the last element of a full URL.
                   9975: sub escape_url {
                   9976:     my ($url)   = @_;
1.238     raeburn  9977:     my @urlslices = split(/\//, $url,-1);
1.369     www      9978:     my $lastitem = &escape(pop(@urlslices));
1.223     albertel 9979:     return join('/',@urlslices).'/'.$lastitem;
1.222     foxr     9980: }
1.462     albertel 9981: 
                   9982: # -------------------------------------------------------- Initliaze user login
                   9983: sub init_user_environment {
1.463     albertel 9984:     my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462     albertel 9985:     my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
                   9986: 
                   9987:     my $public=($username eq 'public' && $domain eq 'public');
                   9988: 
                   9989: # See if old ID present, if so, remove
                   9990: 
                   9991:     my ($filename,$cookie,$userroles);
                   9992:     my $now=time;
                   9993: 
                   9994:     if ($public) {
                   9995: 	my $max_public=100;
                   9996: 	my $oldest;
                   9997: 	my $oldest_time=0;
                   9998: 	for(my $next=1;$next<=$max_public;$next++) {
                   9999: 	    if (-e $lonids."/publicuser_$next.id") {
                   10000: 		my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
                   10001: 		if ($mtime<$oldest_time || !$oldest_time) {
                   10002: 		    $oldest_time=$mtime;
                   10003: 		    $oldest=$next;
                   10004: 		}
                   10005: 	    } else {
                   10006: 		$cookie="publicuser_$next";
                   10007: 		last;
                   10008: 	    }
                   10009: 	}
                   10010: 	if (!$cookie) { $cookie="publicuser_$oldest"; }
                   10011:     } else {
1.463     albertel 10012: 	# if this isn't a robot, kill any existing non-robot sessions
                   10013: 	if (!$args->{'robot'}) {
                   10014: 	    opendir(DIR,$lonids);
                   10015: 	    while ($filename=readdir(DIR)) {
                   10016: 		if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
                   10017: 		    unlink($lonids.'/'.$filename);
                   10018: 		}
1.462     albertel 10019: 	    }
1.463     albertel 10020: 	    closedir(DIR);
1.462     albertel 10021: 	}
                   10022: # Give them a new cookie
1.463     albertel 10023: 	my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684     www      10024: 		                   : $now.$$.int(rand(10000)));
1.463     albertel 10025: 	$cookie="$username\_$id\_$domain\_$authhost";
1.462     albertel 10026:     
                   10027: # Initialize roles
                   10028: 
                   10029: 	$userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
                   10030:     }
                   10031: # ------------------------------------ Check browser type and MathML capability
                   10032: 
                   10033:     my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
                   10034:         $clientunicode,$clientos) = &decode_user_agent($r);
                   10035: 
                   10036: # -------------------------------------- Any accessibility options to remember?
                   10037:     if (($form->{'interface'}) && ($form->{'remember'} eq 'true')) {
                   10038: 	foreach my $option ('imagesuppress','appletsuppress',
                   10039: 			    'embedsuppress','fontenhance','blackwhite') {
                   10040: 	    if ($form->{$option} eq 'true') {
                   10041: 		&Apache::lonnet::put('environment',{$option => 'on'},
                   10042: 				     $domain,$username);
                   10043: 	    } else {
                   10044: 		&Apache::lonnet::del('environment',[$option],
                   10045: 				     $domain,$username);
                   10046: 	    }
                   10047: 	}
                   10048:     }
                   10049: # ------------------------------------------------------------- Get environment
                   10050: 
                   10051:     my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
                   10052:     my ($tmp) = keys(%userenv);
                   10053:     if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   10054: 	# default remote control to off
                   10055: 	if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
                   10056:     } else {
                   10057: 	undef(%userenv);
                   10058:     }
                   10059:     if (($userenv{'interface'}) && (!$form->{'interface'})) {
                   10060: 	$form->{'interface'}=$userenv{'interface'};
                   10061:     }
                   10062:     $env{'environment.remote'}=$userenv{'remote'};
                   10063:     if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
                   10064: 
                   10065: # --------------- Do not trust query string to be put directly into environment
                   10066:     foreach my $option ('imagesuppress','appletsuppress',
                   10067: 			'embedsuppress','fontenhance','blackwhite',
                   10068: 			'interface','localpath','localres') {
                   10069: 	$form->{$option}=~s/[\n\r\=]//gs;
                   10070:     }
                   10071: # --------------------------------------------------------- Write first profile
                   10072: 
                   10073:     {
                   10074: 	my %initial_env = 
                   10075: 	    ("user.name"          => $username,
                   10076: 	     "user.domain"        => $domain,
                   10077: 	     "user.home"          => $authhost,
                   10078: 	     "browser.type"       => $clientbrowser,
                   10079: 	     "browser.version"    => $clientversion,
                   10080: 	     "browser.mathml"     => $clientmathml,
                   10081: 	     "browser.unicode"    => $clientunicode,
                   10082: 	     "browser.os"         => $clientos,
                   10083: 	     "server.domain"      => $Apache::lonnet::perlvar{'lonDefDomain'},
                   10084: 	     "request.course.fn"  => '',
                   10085: 	     "request.course.uri" => '',
                   10086: 	     "request.course.sec" => '',
                   10087: 	     "request.role"       => 'cm',
                   10088: 	     "request.role.adv"   => $env{'user.adv'},
                   10089: 	     "request.host"       => $ENV{'REMOTE_ADDR'},);
                   10090: 
                   10091:         if ($form->{'localpath'}) {
                   10092: 	    $initial_env{"browser.localpath"}  = $form->{'localpath'};
                   10093: 	    $initial_env{"browser.localres"}   = $form->{'localres'};
                   10094:         }
                   10095: 	
                   10096: 	if ($public) {
                   10097: 	    $initial_env{"environment.remote"} = "off";
                   10098: 	}
                   10099: 	if ($form->{'interface'}) {
                   10100: 	    $form->{'interface'}=~s/\W//gs;
                   10101: 	    $initial_env{"browser.interface"} = $form->{'interface'};
                   10102: 	    $env{'browser.interface'}=$form->{'interface'};
                   10103: 	    foreach my $option ('imagesuppress','appletsuppress',
                   10104: 				'embedsuppress','fontenhance','blackwhite') {
                   10105: 		if (($form->{$option} eq 'true') ||
                   10106: 		    ($userenv{$option} eq 'on')) {
                   10107: 		    $initial_env{"browser.$option"} = "on";
                   10108: 		}
                   10109: 	    }
                   10110: 	}
                   10111: 
1.724     raeburn  10112:         foreach my $tool ('aboutme','blog','portfolio') {
                   10113:             $userenv{'availabletools.'.$tool} = 
                   10114:                 &Apache::lonnet::usertools_access($username,$domain,$tool,'reload');
                   10115:         }
                   10116: 
1.765     raeburn  10117:         foreach my $crstype ('official','unofficial') {
                   10118:             $userenv{'canrequest.'.$crstype} =
                   10119:                 &Apache::lonnet::usertools_access($username,$domain,$crstype,
                   10120:                                                   'reload','requestcourses');
                   10121:         }
                   10122: 
1.462     albertel 10123: 	$env{'user.environment'} = "$lonids/$cookie.id";
                   10124: 	
                   10125: 	if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
                   10126: 		 &GDBM_WRCREAT(),0640)) {
                   10127: 	    &_add_to_env(\%disk_env,\%initial_env);
                   10128: 	    &_add_to_env(\%disk_env,\%userenv,'environment.');
                   10129: 	    &_add_to_env(\%disk_env,$userroles);
1.463     albertel 10130: 	    if (ref($args->{'extra_env'})) {
                   10131: 		&_add_to_env(\%disk_env,$args->{'extra_env'});
                   10132: 	    }
1.462     albertel 10133: 	    untie(%disk_env);
                   10134: 	} else {
1.705     tempelho 10135: 	    &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
                   10136: 			   'Could not create environment storage in lonauth: '.$!.'</span>');
1.462     albertel 10137: 	    return 'error: '.$!;
                   10138: 	}
                   10139:     }
                   10140:     $env{'request.role'}='cm';
                   10141:     $env{'request.role.adv'}=$env{'user.adv'};
                   10142:     $env{'browser.type'}=$clientbrowser;
                   10143: 
                   10144:     return $cookie;
                   10145: 
                   10146: }
                   10147: 
                   10148: sub _add_to_env {
                   10149:     my ($idf,$env_data,$prefix) = @_;
1.676     raeburn  10150:     if (ref($env_data) eq 'HASH') {
                   10151:         while (my ($key,$value) = each(%$env_data)) {
                   10152: 	    $idf->{$prefix.$key} = $value;
                   10153: 	    $env{$prefix.$key}   = $value;
                   10154:         }
1.462     albertel 10155:     }
                   10156: }
                   10157: 
1.685     tempelho 10158: # --- Get the symbolic name of a problem and the url
                   10159: sub get_symb {
                   10160:     my ($request,$silent) = @_;
1.726     raeburn  10161:     (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685     tempelho 10162:     my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
                   10163:     if ($symb eq '') {
                   10164:         if (!$silent) {
                   10165:             $request->print("Unable to handle ambiguous references:$url:.");
                   10166:             return ();
                   10167:         }
                   10168:     }
                   10169:     &Apache::lonenc::check_decrypt(\$symb);
                   10170:     return ($symb);
                   10171: }
                   10172: 
                   10173: # --------------------------------------------------------------Get annotation
                   10174: 
                   10175: sub get_annotation {
                   10176:     my ($symb,$enc) = @_;
                   10177: 
                   10178:     my $key = $symb;
                   10179:     if (!$enc) {
                   10180:         $key =
                   10181:             &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
                   10182:     }
                   10183:     my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
                   10184:     return $annotation{$key};
                   10185: }
                   10186: 
                   10187: sub clean_symb {
1.731     raeburn  10188:     my ($symb,$delete_enc) = @_;
1.685     tempelho 10189: 
                   10190:     &Apache::lonenc::check_decrypt(\$symb);
                   10191:     my $enc = $env{'request.enc'};
1.731     raeburn  10192:     if ($delete_enc) {
1.730     raeburn  10193:         delete($env{'request.enc'});
                   10194:     }
1.685     tempelho 10195: 
                   10196:     return ($symb,$enc);
                   10197: }
1.462     albertel 10198: 
1.41      ng       10199: =pod
                   10200: 
                   10201: =back
                   10202: 
1.112     bowersj2 10203: =cut
1.41      ng       10204: 
1.112     bowersj2 10205: 1;
                   10206: __END__;
1.41      ng       10207: 

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