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

1.10      albertel    1: # The LearningOnline Network with CAPA
1.1       albertel    2: # a pile of common routines
1.10      albertel    3: #
1.794   ! www         4: # $Id: loncommon.pm,v 1.793 2009/04/24 05:28:55 raeburn Exp $
1.10      albertel    5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
1.1       albertel   28: 
                     29: # Makes a table out of the previous attempts
1.2       albertel   30: # Inputs result_from_symbread, user, domain, course_id
1.16      harris41   31: # Reads in non-network-related .tab files
1.1       albertel   32: 
1.35      matthew    33: # POD header:
                     34: 
1.45      matthew    35: =pod
                     36: 
1.35      matthew    37: =head1 NAME
                     38: 
                     39: Apache::loncommon - pile of common routines
                     40: 
                     41: =head1 SYNOPSIS
                     42: 
1.112     bowersj2   43: Common routines for manipulating connections, student answers,
                     44:     domains, common Javascript fragments, etc.
1.35      matthew    45: 
1.112     bowersj2   46: =head1 OVERVIEW
1.35      matthew    47: 
1.112     bowersj2   48: A collection of commonly used subroutines that don't have a natural
                     49: home anywhere else. This collection helps remove
1.35      matthew    50: redundancy from other modules and increase efficiency of memory usage.
                     51: 
                     52: =cut 
                     53: 
                     54: # End of POD header
1.1       albertel   55: package Apache::loncommon;
                     56: 
                     57: use strict;
1.258     albertel   58: use Apache::lonnet;
1.46      matthew    59: use GDBM_File;
1.51      www        60: use POSIX qw(strftime mktime);
1.82      www        61: use Apache::lonmenu();
1.498     albertel   62: use Apache::lonenc();
1.117     www        63: use Apache::lonlocal;
1.685     tempelho   64: use Apache::lonnet();
1.139     matthew    65: use HTML::Entities;
1.334     albertel   66: use Apache::lonhtmlcommon();
                     67: use Apache::loncoursedata();
1.344     albertel   68: use Apache::lontexconvert();
1.444     albertel   69: use Apache::lonclonecourse();
1.479     albertel   70: use LONCAPA qw(:DEFAULT :match);
1.657     raeburn    71: use DateTime::TimeZone;
1.687     raeburn    72: use DateTime::Locale::Catalog;
1.117     www        73: 
1.517     raeburn    74: # ---------------------------------------------- Designs
                     75: use vars qw(%defaultdesign);
                     76: 
1.22      www        77: my $readit;
                     78: 
1.517     raeburn    79: 
1.157     matthew    80: ##
                     81: ## Global Variables
                     82: ##
1.46      matthew    83: 
1.643     foxr       84: 
                     85: # ----------------------------------------------- SSI with retries:
                     86: #
                     87: 
                     88: =pod
                     89: 
1.648     raeburn    90: =head1 Server Side include with retries:
1.643     foxr       91: 
                     92: =over 4
                     93: 
1.648     raeburn    94: =item * &ssi_with_retries(resource,retries form)
1.643     foxr       95: 
                     96: Performs an ssi with some number of retries.  Retries continue either
                     97: until the result is ok or until the retry count supplied by the
                     98: caller is exhausted.  
                     99: 
                    100: Inputs:
1.648     raeburn   101: 
                    102: =over 4
                    103: 
1.643     foxr      104: resource   - Identifies the resource to insert.
1.648     raeburn   105: 
1.643     foxr      106: retries    - Count of the number of retries allowed.
1.648     raeburn   107: 
1.643     foxr      108: form       - Hash that identifies the rendering options.
                    109: 
1.648     raeburn   110: =back
                    111: 
                    112: Returns:
                    113: 
                    114: =over 4
                    115: 
1.643     foxr      116: content    - The content of the response.  If retries were exhausted this is empty.
1.648     raeburn   117: 
1.643     foxr      118: response   - The response from the last attempt (which may or may not have been successful.
                    119: 
1.648     raeburn   120: =back
                    121: 
                    122: =back
                    123: 
1.643     foxr      124: =cut
                    125: 
                    126: sub ssi_with_retries {
                    127:     my ($resource, $retries, %form) = @_;
                    128: 
                    129: 
                    130:     my $ok = 0;			# True if we got a good response.
                    131:     my $content;
                    132:     my $response;
                    133: 
                    134:     # Try to get the ssi done. within the retries count:
                    135: 
                    136:     do {
                    137: 	($content, $response) = &Apache::lonnet::ssi($resource, %form);
                    138: 	$ok      = $response->is_success;
1.650     www       139:         if (!$ok) {
                    140:             &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
                    141:         }
1.643     foxr      142: 	$retries--;
                    143:     } while (!$ok && ($retries > 0));
                    144: 
                    145:     if (!$ok) {
                    146: 	$content = '';		# On error return an empty content.
                    147:     }
                    148:     return ($content, $response);
                    149: 
                    150: }
                    151: 
                    152: 
                    153: 
1.20      www       154: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12      harris41  155: my %language;
1.124     www       156: my %supported_language;
1.12      harris41  157: my %cprtag;
1.192     taceyjo1  158: my %scprtag;
1.351     www       159: my %fe; my %fd; my %fm;
1.41      ng        160: my %category_extensions;
1.12      harris41  161: 
1.46      matthew   162: # ---------------------------------------------- Thesaurus variables
1.144     matthew   163: #
                    164: # %Keywords:
                    165: #      A hash used by &keyword to determine if a word is considered a keyword.
                    166: # $thesaurus_db_file 
                    167: #      Scalar containing the full path to the thesaurus database.
1.46      matthew   168: 
                    169: my %Keywords;
                    170: my $thesaurus_db_file;
                    171: 
1.144     matthew   172: #
                    173: # Initialize values from language.tab, copyright.tab, filetypes.tab,
                    174: # thesaurus.tab, and filecategories.tab.
                    175: #
1.18      www       176: BEGIN {
1.46      matthew   177:     # Variable initialization
                    178:     $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
                    179:     #
1.22      www       180:     unless ($readit) {
1.12      harris41  181: # ------------------------------------------------------------------- languages
                    182:     {
1.158     raeburn   183:         my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
                    184:                                    '/language.tab';
                    185:         if ( open(my $fh,"<$langtabfile") ) {
1.356     albertel  186:             while (my $line = <$fh>) {
                    187:                 next if ($line=~/^\#/);
                    188:                 chomp($line);
                    189:                 my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$line));
1.158     raeburn   190:                 $language{$key}=$val.' - '.$enc;
                    191:                 if ($sup) {
                    192:                     $supported_language{$key}=$sup;
                    193:                 }
                    194:             }
                    195:             close($fh);
                    196:         }
1.12      harris41  197:     }
                    198: # ------------------------------------------------------------------ copyrights
                    199:     {
1.158     raeburn   200:         my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
                    201:                                   '/copyright.tab';
                    202:         if ( open (my $fh,"<$copyrightfile") ) {
1.356     albertel  203:             while (my $line = <$fh>) {
                    204:                 next if ($line=~/^\#/);
                    205:                 chomp($line);
                    206:                 my ($key,$val)=(split(/\s+/,$line,2));
1.158     raeburn   207:                 $cprtag{$key}=$val;
                    208:             }
                    209:             close($fh);
                    210:         }
1.12      harris41  211:     }
1.351     www       212: # ----------------------------------------------------------- source copyrights
1.192     taceyjo1  213:     {
                    214:         my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
                    215:                                   '/source_copyright.tab';
                    216:         if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356     albertel  217:             while (my $line = <$fh>) {
                    218:                 next if ($line =~ /^\#/);
                    219:                 chomp($line);
                    220:                 my ($key,$val)=(split(/\s+/,$line,2));
1.192     taceyjo1  221:                 $scprtag{$key}=$val;
                    222:             }
                    223:             close($fh);
                    224:         }
                    225:     }
1.63      www       226: 
1.517     raeburn   227: # -------------------------------------------------------------- default domain designs
1.63      www       228:     my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517     raeburn   229:     my $designfile = $designdir.'/default.tab';
                    230:     if ( open (my $fh,"<$designfile") ) {
                    231:         while (my $line = <$fh>) {
                    232:             next if ($line =~ /^\#/);
                    233:             chomp($line);
                    234:             my ($key,$val)=(split(/\=/,$line));
                    235:             if ($val) { $defaultdesign{$key}=$val; }
                    236:         }
                    237:         close($fh);
1.63      www       238:     }
                    239: 
1.15      harris41  240: # ------------------------------------------------------------- file categories
                    241:     {
1.158     raeburn   242:         my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
                    243:                                   '/filecategories.tab';
                    244:         if ( open (my $fh,"<$categoryfile") ) {
1.356     albertel  245: 	    while (my $line = <$fh>) {
                    246: 		next if ($line =~ /^\#/);
                    247: 		chomp($line);
                    248:                 my ($extension,$category)=(split(/\s+/,$line,2));
1.158     raeburn   249:                 push @{$category_extensions{lc($category)}},$extension;
                    250:             }
                    251:             close($fh);
                    252:         }
                    253: 
1.15      harris41  254:     }
1.12      harris41  255: # ------------------------------------------------------------------ file types
                    256:     {
1.158     raeburn   257:         my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
                    258:                '/filetypes.tab';
                    259:         if ( open (my $fh,"<$typesfile") ) {
1.356     albertel  260:             while (my $line = <$fh>) {
                    261: 		next if ($line =~ /^\#/);
                    262: 		chomp($line);
                    263:                 my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158     raeburn   264:                 if ($descr ne '') {
                    265:                     $fe{$ending}=lc($emb);
                    266:                     $fd{$ending}=$descr;
1.351     www       267:                     if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158     raeburn   268:                 }
                    269:             }
                    270:             close($fh);
                    271:         }
1.12      harris41  272:     }
1.22      www       273:     &Apache::lonnet::logthis(
1.705     tempelho  274:              "<span style='color:yellow;'>INFO: Read file types</span>");
1.22      www       275:     $readit=1;
1.46      matthew   276:     }  # end of unless($readit) 
1.32      matthew   277:     
                    278: }
1.112     bowersj2  279: 
1.42      matthew   280: ###############################################################
                    281: ##           HTML and Javascript Helper Functions            ##
                    282: ###############################################################
                    283: 
                    284: =pod 
                    285: 
1.112     bowersj2  286: =head1 HTML and Javascript Functions
1.42      matthew   287: 
1.112     bowersj2  288: =over 4
                    289: 
1.648     raeburn   290: =item * &browser_and_searcher_javascript()
1.112     bowersj2  291: 
                    292: X<browsing, javascript>X<searching, javascript>Returns a string
                    293: containing javascript with two functions, C<openbrowser> and
                    294: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
                    295: tags.
1.42      matthew   296: 
1.648     raeburn   297: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42      matthew   298: 
                    299: inputs: formname, elementname, only, omit
                    300: 
                    301: formname and elementname indicate the name of the html form and name of
                    302: the element that the results of the browsing selection are to be placed in. 
                    303: 
                    304: Specifying 'only' will restrict the browser to displaying only files
1.185     www       305: with the given extension.  Can be a comma separated list.
1.42      matthew   306: 
                    307: Specifying 'omit' will restrict the browser to NOT displaying files
1.185     www       308: with the given extension.  Can be a comma separated list.
1.42      matthew   309: 
1.648     raeburn   310: =item * &opensearcher(formname,elementname) [javascript]
1.42      matthew   311: 
                    312: Inputs: formname, elementname
                    313: 
                    314: formname and elementname specify the name of the html form and the name
                    315: of the element the selection from the search results will be placed in.
1.542     raeburn   316: 
1.42      matthew   317: =cut
                    318: 
                    319: sub browser_and_searcher_javascript {
1.199     albertel  320:     my ($mode)=@_;
                    321:     if (!defined($mode)) { $mode='edit'; }
1.453     albertel  322:     my $resurl=&escape_single(&lastresurl());
1.42      matthew   323:     return <<END;
1.219     albertel  324: // <!-- BEGIN LON-CAPA Internal
1.50      matthew   325:     var editbrowser = null;
1.135     albertel  326:     function openbrowser(formname,elementname,only,omit,titleelement) {
1.170     www       327:         var url = '$resurl/?';
1.42      matthew   328:         if (editbrowser == null) {
                    329:             url += 'launch=1&';
                    330:         }
                    331:         url += 'catalogmode=interactive&';
1.199     albertel  332:         url += 'mode=$mode&';
1.611     albertel  333:         url += 'inhibitmenu=yes&';
1.42      matthew   334:         url += 'form=' + formname + '&';
                    335:         if (only != null) {
                    336:             url += 'only=' + only + '&';
1.217     albertel  337:         } else {
                    338:             url += 'only=&';
                    339: 	}
1.42      matthew   340:         if (omit != null) {
                    341:             url += 'omit=' + omit + '&';
1.217     albertel  342:         } else {
                    343:             url += 'omit=&';
                    344: 	}
1.135     albertel  345:         if (titleelement != null) {
                    346:             url += 'titleelement=' + titleelement + '&';
1.217     albertel  347:         } else {
                    348: 	    url += 'titleelement=&';
                    349: 	}
1.42      matthew   350:         url += 'element=' + elementname + '';
                    351:         var title = 'Browser';
1.435     albertel  352:         var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42      matthew   353:         options += ',width=700,height=600';
                    354:         editbrowser = open(url,title,options,'1');
                    355:         editbrowser.focus();
                    356:     }
                    357:     var editsearcher;
1.135     albertel  358:     function opensearcher(formname,elementname,titleelement) {
1.42      matthew   359:         var url = '/adm/searchcat?';
                    360:         if (editsearcher == null) {
                    361:             url += 'launch=1&';
                    362:         }
                    363:         url += 'catalogmode=interactive&';
1.199     albertel  364:         url += 'mode=$mode&';
1.42      matthew   365:         url += 'form=' + formname + '&';
1.135     albertel  366:         if (titleelement != null) {
                    367:             url += 'titleelement=' + titleelement + '&';
1.217     albertel  368:         } else {
                    369: 	    url += 'titleelement=&';
                    370: 	}
1.42      matthew   371:         url += 'element=' + elementname + '';
                    372:         var title = 'Search';
1.435     albertel  373:         var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42      matthew   374:         options += ',width=700,height=600';
                    375:         editsearcher = open(url,title,options,'1');
                    376:         editsearcher.focus();
                    377:     }
1.219     albertel  378: // END LON-CAPA Internal -->
1.42      matthew   379: END
1.170     www       380: }
                    381: 
                    382: sub lastresurl {
1.258     albertel  383:     if ($env{'environment.lastresurl'}) {
                    384: 	return $env{'environment.lastresurl'}
1.170     www       385:     } else {
                    386: 	return '/res';
                    387:     }
                    388: }
                    389: 
                    390: sub storeresurl {
                    391:     my $resurl=&Apache::lonnet::clutter(shift);
                    392:     unless ($resurl=~/^\/res/) { return 0; }
                    393:     $resurl=~s/\/$//;
                    394:     &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646     raeburn   395:     &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170     www       396:     return 1;
1.42      matthew   397: }
                    398: 
1.74      www       399: sub studentbrowser_javascript {
1.111     www       400:    unless (
1.258     albertel  401:             (($env{'request.course.id'}) && 
1.302     albertel  402:              (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
                    403: 	      || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
                    404: 					  '/'.$env{'request.course.sec'})
                    405: 	      ))
1.258     albertel  406:          || ($env{'request.role'}=~/^(au|dc|su)/)
1.111     www       407:           ) { return ''; }  
1.74      www       408:    return (<<'ENDSTDBRW');
1.776     bisitz    409: <script type="text/javascript" language="Javascript">
1.74      www       410:     var stdeditbrowser;
1.793     raeburn   411:     function openstdbrowser(formname,uname,udom,roleflag,ignorefilter,courseadvonly) {
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.793     raeburn   425:         if (courseadvonly) { url+="&courseadvonly=1"; }
1.102     www       426:         var title = 'Student_Browser';
1.74      www       427:         var options = 'scrollbars=1,resizable=1,menubar=0';
                    428:         options += ',width=700,height=600';
                    429:         stdeditbrowser = open(url,title,options,'1');
                    430:         stdeditbrowser.focus();
                    431:     }
                    432: </script>
                    433: ENDSTDBRW
                    434: }
1.42      matthew   435: 
1.74      www       436: sub selectstudent_link {
1.793     raeburn   437:    my ($form,$unameele,$udomele,$courseadvonly)=@_;
                    438:    my $callargs = "'".$form."','".$unameele."','".$udomele."'";
1.258     albertel  439:    if ($env{'request.course.id'}) {  
1.302     albertel  440:        if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
                    441: 	   && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
                    442: 					'/'.$env{'request.course.sec'})) {
1.111     www       443: 	   return '';
                    444:        }
1.793     raeburn   445:        if ($courseadvonly)  {
                    446:            $callargs .= ",'',1,1";
                    447:        }
                    448:        return '<span class="LC_nobreak">'.
                    449:               '<a href="javascript:openstdbrowser('.$callargs.');">'.
                    450:               &mt('Select User').'</a></span>';
1.74      www       451:    }
1.258     albertel  452:    if ($env{'request.role'}=~/^(au|dc|su)/) {
1.793     raeburn   453:        $callargs .= ",1"; 
                    454:        return '<span class="LC_nobreak">'.
                    455:               '<a href="javascript:openstdbrowser('.$callargs.');">'.
                    456:               &mt('Select User').'</a></span>';
1.111     www       457:    }
                    458:    return '';
1.91      www       459: }
                    460: 
1.653     raeburn   461: sub authorbrowser_javascript {
                    462:     return <<"ENDAUTHORBRW";
1.776     bisitz    463: <script type="text/javascript" language="JavaScript">
1.653     raeburn   464: var stdeditbrowser;
                    465: 
                    466: function openauthorbrowser(formname,udom) {
                    467:     var url = '/adm/pickauthor?';
                    468:     url += 'form='+formname+'&roledom='+udom;
                    469:     var title = 'Author_Browser';
                    470:     var options = 'scrollbars=1,resizable=1,menubar=0';
                    471:     options += ',width=700,height=600';
                    472:     stdeditbrowser = open(url,title,options,'1');
                    473:     stdeditbrowser.focus();
                    474: }
                    475: 
                    476: </script>
                    477: ENDAUTHORBRW
                    478: }
                    479: 
1.91      www       480: sub coursebrowser_javascript {
1.468     raeburn   481:     my ($domainfilter,$sec_element,$formname)=@_;
1.377     raeburn   482:     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   483:    my $output = '
1.776     bisitz    484: <script type="text/javascript" language="JavaScript">
1.468     raeburn   485:     var stdeditbrowser;'."\n";
                    486:    $output .= <<"ENDSTDBRW";
1.377     raeburn   487:     function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,crstype) {
1.91      www       488:         var url = '/adm/pickcourse?';
1.468     raeburn   489:         var domainfilter = '';
                    490:         var formid = getFormIdByName(formname);
                    491:         if (formid > -1) {
                    492:             var domid = getIndexByName(formid,udom);
                    493:             if (domid > -1) {
                    494:                 if (document.forms[formid].elements[domid].type == 'select-one') {
                    495:                     domainfilter=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
                    496:                 }
                    497:                 if (document.forms[formid].elements[domid].type == 'hidden') {
                    498:                     domainfilter=document.forms[formid].elements[domid].value;
                    499:                 }
                    500:             }
1.91      www       501:         }
1.128     albertel  502:         if (domainfilter != null) {
                    503:            if (domainfilter != '') {
                    504:                url += 'domainfilter='+domainfilter+'&';
                    505: 	   }
                    506:         }
1.91      www       507:         url += 'form=' + formname + '&cnumelement='+uname+
1.187     albertel  508: 	                            '&cdomelement='+udom+
                    509:                                     '&cnameelement='+desc;
1.468     raeburn   510:         if (extra_element !=null && extra_element != '') {
1.594     raeburn   511:             if (formname == 'rolechoice' || formname == 'studentform') {
1.468     raeburn   512:                 url += '&roleelement='+extra_element;
                    513:                 if (domainfilter == null || domainfilter == '') {
                    514:                     url += '&domainfilter='+extra_element;
                    515:                 }
1.234     raeburn   516:             }
1.468     raeburn   517:             else {
                    518:                 if (formname == 'portform') {
                    519:                     url += '&setroles='+extra_element;
                    520:                 }
                    521:             }     
1.230     raeburn   522:         }
1.293     raeburn   523:         if (multflag !=null && multflag != '') {
                    524:             url += '&multiple='+multflag;
                    525:         }
1.377     raeburn   526:         if (crstype == 'Course/Group') {
                    527:             if (formname == 'cu') {
                    528:                 crstype = document.cu.crstype.options[document.cu.crstype.selectedIndex].value; 
                    529:                 if (crstype == "") {
                    530:                     alert("$crs_or_grp_alert");
                    531:                     return;
                    532:                 }
                    533:             }
                    534:         }
                    535:         if (crstype !=null && crstype != '') {
                    536:             url += '&type='+crstype;
                    537:         }
1.102     www       538:         var title = 'Course_Browser';
1.91      www       539:         var options = 'scrollbars=1,resizable=1,menubar=0';
                    540:         options += ',width=700,height=600';
                    541:         stdeditbrowser = open(url,title,options,'1');
                    542:         stdeditbrowser.focus();
                    543:     }
1.468     raeburn   544: 
                    545:     function getFormIdByName(formname) {
                    546:         for (var i=0;i<document.forms.length;i++) {
                    547:             if (document.forms[i].name == formname) {
                    548:                 return i;
                    549:             }
                    550:         }
                    551:         return -1; 
                    552:     }
                    553: 
                    554:     function getIndexByName(formid,item) {
                    555:         for (var i=0;i<document.forms[formid].elements.length;i++) {
                    556:             if (document.forms[formid].elements[i].name == item) {
                    557:                 return i;
                    558:             }
                    559:         }
                    560:         return -1;
                    561:     }
1.91      www       562: ENDSTDBRW
1.468     raeburn   563:     if ($sec_element ne '') {
                    564:         $output .= &setsec_javascript($sec_element,$formname);
                    565:     }
                    566:     $output .= '
                    567: </script>';
                    568:     return $output;
                    569: }
                    570: 
                    571: sub setsec_javascript {
                    572:     my ($sec_element,$formname) = @_;
                    573:     my $setsections = qq|
                    574: function setSect(sectionlist) {
1.629     raeburn   575:     var sectionsArray = new Array();
                    576:     if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
                    577:         sectionsArray = sectionlist.split(",");
                    578:     }
1.468     raeburn   579:     var numSections = sectionsArray.length;
                    580:     document.$formname.$sec_element.length = 0;
                    581:     if (numSections == 0) {
                    582:         document.$formname.$sec_element.multiple=false;
                    583:         document.$formname.$sec_element.size=1;
                    584:         document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
                    585:     } else {
                    586:         if (numSections == 1) {
                    587:             document.$formname.$sec_element.multiple=false;
                    588:             document.$formname.$sec_element.size=1;
                    589:             document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
                    590:             document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
                    591:             document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
                    592:         } else {
                    593:             for (var i=0; i<numSections; i++) {
                    594:                 document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
                    595:             }
                    596:             document.$formname.$sec_element.multiple=true
                    597:             if (numSections < 3) {
                    598:                 document.$formname.$sec_element.size=numSections;
                    599:             } else {
                    600:                 document.$formname.$sec_element.size=3;
                    601:             }
                    602:             document.$formname.$sec_element.options[0].selected = false
                    603:         }
                    604:     }
1.91      www       605: }
1.468     raeburn   606: |;
                    607:     return $setsections;
                    608: }
                    609: 
1.91      www       610: 
                    611: sub selectcourse_link {
1.377     raeburn   612:    my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype)=@_;
1.787     bisitz    613:    return '<span class="LC_nobreak">'
                    614:          ."<a href='"
                    615:          .'javascript:opencrsbrowser("'.$form.'","'.$unameele
                    616:          .'","'.$udomele.'","'.$desc.'","'.$extra_element
                    617:          .'","'.$multflag.'","'.$selecttype.'");'
                    618:          ."'>".&mt('Select Course').'</a>'
                    619:          .'</span>';
1.74      www       620: }
1.42      matthew   621: 
1.653     raeburn   622: sub selectauthor_link {
                    623:    my ($form,$udom)=@_;
                    624:    return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
                    625:           &mt('Select Author').'</a>';
                    626: }
                    627: 
1.273     raeburn   628: sub check_uncheck_jscript {
                    629:     my $jscript = <<"ENDSCRT";
                    630: function checkAll(field) {
                    631:     if (field.length > 0) {
                    632:         for (i = 0; i < field.length; i++) {
                    633:             field[i].checked = true ;
                    634:         }
                    635:     } else {
                    636:         field.checked = true
                    637:     }
                    638: }
                    639:  
                    640: function uncheckAll(field) {
                    641:     if (field.length > 0) {
                    642:         for (i = 0; i < field.length; i++) {
                    643:             field[i].checked = false ;
1.543     albertel  644:         }
                    645:     } else {
1.273     raeburn   646:         field.checked = false ;
                    647:     }
                    648: }
                    649: ENDSCRT
                    650:     return $jscript;
                    651: }
                    652: 
1.656     www       653: sub select_timezone {
1.659     raeburn   654:    my ($name,$selected,$onchange,$includeempty)=@_;
                    655:    my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
                    656:    if ($includeempty) {
                    657:        $output .= '<option value=""';
                    658:        if (($selected eq '') || ($selected eq 'local')) {
                    659:            $output .= ' selected="selected" ';
                    660:        }
                    661:        $output .= '> </option>';
                    662:    }
1.657     raeburn   663:    my @timezones = DateTime::TimeZone->all_names;
                    664:    foreach my $tzone (@timezones) {
                    665:        $output.= '<option value="'.$tzone.'"';
                    666:        if ($tzone eq $selected) {
                    667:            $output.=' selected="selected"';
                    668:        }
                    669:        $output.=">$tzone</option>\n";
1.656     www       670:    }
                    671:    $output.="</select>";
                    672:    return $output;
                    673: }
1.273     raeburn   674: 
1.687     raeburn   675: sub select_datelocale {
                    676:     my ($name,$selected,$onchange,$includeempty)=@_;
                    677:     my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
                    678:     if ($includeempty) {
                    679:         $output .= '<option value=""';
                    680:         if ($selected eq '') {
                    681:             $output .= ' selected="selected" ';
                    682:         }
                    683:         $output .= '> </option>';
                    684:     }
                    685:     my (@possibles,%locale_names);
                    686:     my @locales = DateTime::Locale::Catalog::Locales;
                    687:     foreach my $locale (@locales) {
                    688:         if (ref($locale) eq 'HASH') {
                    689:             my $id = $locale->{'id'};
                    690:             if ($id ne '') {
                    691:                 my $en_terr = $locale->{'en_territory'};
                    692:                 my $native_terr = $locale->{'native_territory'};
1.695     raeburn   693:                 my @languages = &Apache::lonlocal::preferred_languages();
1.687     raeburn   694:                 if (grep(/^en$/,@languages) || !@languages) {
                    695:                     if ($en_terr ne '') {
                    696:                         $locale_names{$id} = '('.$en_terr.')';
                    697:                     } elsif ($native_terr ne '') {
                    698:                         $locale_names{$id} = $native_terr;
                    699:                     }
                    700:                 } else {
                    701:                     if ($native_terr ne '') {
                    702:                         $locale_names{$id} = $native_terr.' ';
                    703:                     } elsif ($en_terr ne '') {
                    704:                         $locale_names{$id} = '('.$en_terr.')';
                    705:                     }
                    706:                 }
                    707:                 push (@possibles,$id);
                    708:             }
                    709:         }
                    710:     }
                    711:     foreach my $item (sort(@possibles)) {
                    712:         $output.= '<option value="'.$item.'"';
                    713:         if ($item eq $selected) {
                    714:             $output.=' selected="selected"';
                    715:         }
                    716:         $output.=">$item";
                    717:         if ($locale_names{$item} ne '') {
                    718:             $output.="  $locale_names{$item}</option>\n";
                    719:         }
                    720:         $output.="</option>\n";
                    721:     }
                    722:     $output.="</select>";
                    723:     return $output;
                    724: }
                    725: 
1.792     raeburn   726: sub select_language {
                    727:     my ($name,$selected,$includeempty) = @_;
                    728:     my %langchoices;
                    729:     if ($includeempty) {
                    730:         %langchoices = ('' => 'No language preference');
                    731:     }
                    732:     foreach my $id (&languageids()) {
                    733:         my $code = &supportedlanguagecode($id);
                    734:         if ($code) {
                    735:             $langchoices{$code} = &plainlanguagedescription($id);
                    736:         }
                    737:     }
                    738:     return &select_form($selected,$name,%langchoices);
                    739: }
                    740: 
1.42      matthew   741: =pod
1.36      matthew   742: 
1.648     raeburn   743: =item * &linked_select_forms(...)
1.36      matthew   744: 
                    745: linked_select_forms returns a string containing a <script></script> block
                    746: and html for two <select> menus.  The select menus will be linked in that
                    747: changing the value of the first menu will result in new values being placed
                    748: in the second menu.  The values in the select menu will appear in alphabetical
1.609     raeburn   749: order unless a defined order is provided.
1.36      matthew   750: 
                    751: linked_select_forms takes the following ordered inputs:
                    752: 
                    753: =over 4
                    754: 
1.112     bowersj2  755: =item * $formname, the name of the <form> tag
1.36      matthew   756: 
1.112     bowersj2  757: =item * $middletext, the text which appears between the <select> tags
1.36      matthew   758: 
1.112     bowersj2  759: =item * $firstdefault, the default value for the first menu
1.36      matthew   760: 
1.112     bowersj2  761: =item * $firstselectname, the name of the first <select> tag
1.36      matthew   762: 
1.112     bowersj2  763: =item * $secondselectname, the name of the second <select> tag
1.36      matthew   764: 
1.112     bowersj2  765: =item * $hashref, a reference to a hash containing the data for the menus.
1.36      matthew   766: 
1.609     raeburn   767: =item * $menuorder, the order of values in the first menu
                    768: 
1.41      ng        769: =back 
                    770: 
1.36      matthew   771: Below is an example of such a hash.  Only the 'text', 'default', and 
                    772: 'select2' keys must appear as stated.  keys(%menu) are the possible 
                    773: values for the first select menu.  The text that coincides with the 
1.41      ng        774: first menu value is given in $menu{$choice1}->{'text'}.  The values 
1.36      matthew   775: and text for the second menu are given in the hash pointed to by 
                    776: $menu{$choice1}->{'select2'}.  
                    777: 
1.112     bowersj2  778:  my %menu = ( A1 => { text =>"Choice A1" ,
                    779:                        default => "B3",
                    780:                        select2 => { 
                    781:                            B1 => "Choice B1",
                    782:                            B2 => "Choice B2",
                    783:                            B3 => "Choice B3",
                    784:                            B4 => "Choice B4"
1.609     raeburn   785:                            },
                    786:                        order => ['B4','B3','B1','B2'],
1.112     bowersj2  787:                    },
                    788:                A2 => { text =>"Choice A2" ,
                    789:                        default => "C2",
                    790:                        select2 => { 
                    791:                            C1 => "Choice C1",
                    792:                            C2 => "Choice C2",
                    793:                            C3 => "Choice C3"
1.609     raeburn   794:                            },
                    795:                        order => ['C2','C1','C3'],
1.112     bowersj2  796:                    },
                    797:                A3 => { text =>"Choice A3" ,
                    798:                        default => "D6",
                    799:                        select2 => { 
                    800:                            D1 => "Choice D1",
                    801:                            D2 => "Choice D2",
                    802:                            D3 => "Choice D3",
                    803:                            D4 => "Choice D4",
                    804:                            D5 => "Choice D5",
                    805:                            D6 => "Choice D6",
                    806:                            D7 => "Choice D7"
1.609     raeburn   807:                            },
                    808:                        order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112     bowersj2  809:                    }
                    810:                );
1.36      matthew   811: 
                    812: =cut
                    813: 
                    814: sub linked_select_forms {
                    815:     my ($formname,
                    816:         $middletext,
                    817:         $firstdefault,
                    818:         $firstselectname,
                    819:         $secondselectname, 
1.609     raeburn   820:         $hashref,
                    821:         $menuorder,
1.36      matthew   822:         ) = @_;
                    823:     my $second = "document.$formname.$secondselectname";
                    824:     my $first = "document.$formname.$firstselectname";
                    825:     # output the javascript to do the changing
                    826:     my $result = '';
1.776     bisitz    827:     $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.36      matthew   828:     $result.="var select2data = new Object();\n";
                    829:     $" = '","';
                    830:     my $debug = '';
                    831:     foreach my $s1 (sort(keys(%$hashref))) {
                    832:         $result.="select2data.d_$s1 = new Object();\n";        
                    833:         $result.="select2data.d_$s1.def = new String('".
                    834:             $hashref->{$s1}->{'default'}."');\n";
1.609     raeburn   835:         $result.="select2data.d_$s1.values = new Array(";
1.36      matthew   836:         my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609     raeburn   837:         if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
                    838:             @s2values = @{$hashref->{$s1}->{'order'}};
                    839:         }
1.36      matthew   840:         $result.="\"@s2values\");\n";
                    841:         $result.="select2data.d_$s1.texts = new Array(";        
                    842:         my @s2texts;
                    843:         foreach my $value (@s2values) {
                    844:             push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
                    845:         }
                    846:         $result.="\"@s2texts\");\n";
                    847:     }
                    848:     $"=' ';
                    849:     $result.= <<"END";
                    850: 
                    851: function select1_changed() {
                    852:     // Determine new choice
                    853:     var newvalue = "d_" + $first.value;
                    854:     // update select2
                    855:     var values     = select2data[newvalue].values;
                    856:     var texts      = select2data[newvalue].texts;
                    857:     var select2def = select2data[newvalue].def;
                    858:     var i;
                    859:     // out with the old
                    860:     for (i = 0; i < $second.options.length; i++) {
                    861:         $second.options[i] = null;
                    862:     }
                    863:     // in with the nuclear
                    864:     for (i=0;i<values.length; i++) {
                    865:         $second.options[i] = new Option(values[i]);
1.143     matthew   866:         $second.options[i].value = values[i];
1.36      matthew   867:         $second.options[i].text = texts[i];
                    868:         if (values[i] == select2def) {
                    869:             $second.options[i].selected = true;
                    870:         }
                    871:     }
                    872: }
                    873: </script>
                    874: END
                    875:     # output the initial values for the selection lists
                    876:     $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609     raeburn   877:     my @order = sort(keys(%{$hashref}));
                    878:     if (ref($menuorder) eq 'ARRAY') {
                    879:         @order = @{$menuorder};
                    880:     }
                    881:     foreach my $value (@order) {
1.36      matthew   882:         $result.="    <option value=\"$value\" ";
1.253     albertel  883:         $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119     www       884:         $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36      matthew   885:     }
                    886:     $result .= "</select>\n";
                    887:     my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
                    888:     $result .= $middletext;
                    889:     $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
                    890:     my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609     raeburn   891:     
                    892:     my @secondorder = sort(keys(%select2));
                    893:     if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
                    894:         @secondorder = @{$hashref->{$firstdefault}->{'order'}};
                    895:     }
                    896:     foreach my $value (@secondorder) {
1.36      matthew   897:         $result.="    <option value=\"$value\" ";        
1.253     albertel  898:         $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119     www       899:         $result.=">".&mt($select2{$value})."</option>\n";
1.36      matthew   900:     }
                    901:     $result .= "</select>\n";
                    902:     #    return $debug;
                    903:     return $result;
                    904: }   #  end of sub linked_select_forms {
                    905: 
1.45      matthew   906: =pod
1.44      bowersj2  907: 
1.648     raeburn   908: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height)
1.44      bowersj2  909: 
1.112     bowersj2  910: Returns a string corresponding to an HTML link to the given help
                    911: $topic, where $topic corresponds to the name of a .tex file in
                    912: /home/httpd/html/adm/help/tex, with underscores replaced by
                    913: spaces. 
                    914: 
                    915: $text will optionally be linked to the same topic, allowing you to
                    916: link text in addition to the graphic. If you do not want to link
                    917: text, but wish to specify one of the later parameters, pass an
                    918: empty string. 
                    919: 
                    920: $stayOnPage is a value that will be interpreted as a boolean. If true,
                    921: the link will not open a new window. If false, the link will open
                    922: a new window using Javascript. (Default is false.) 
                    923: 
                    924: $width and $height are optional numerical parameters that will
                    925: override the width and height of the popped up window, which may
                    926: be useful for certain help topics with big pictures included. 
1.44      bowersj2  927: 
                    928: =cut
                    929: 
                    930: sub help_open_topic {
1.48      bowersj2  931:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
                    932:     $text = "" if (not defined $text);
1.44      bowersj2  933:     $stayOnPage = 0 if (not defined $stayOnPage);
1.552     banghart  934:     if ($env{'browser.interface'} eq 'textual') {
1.79      www       935: 	$stayOnPage=1;
                    936:     }
1.44      bowersj2  937:     $width = 350 if (not defined $width);
                    938:     $height = 400 if (not defined $height);
                    939:     my $filename = $topic;
                    940:     $filename =~ s/ /_/g;
                    941: 
1.48      bowersj2  942:     my $template = "";
                    943:     my $link;
1.572     banghart  944:     
1.159     www       945:     $topic=~s/\W/\_/g;
1.44      bowersj2  946: 
1.572     banghart  947:     if (!$stayOnPage) {
1.72      bowersj2  948: 	$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  949:     } else {
1.48      bowersj2  950: 	$link = "/adm/help/${filename}.hlp";
                    951:     }
                    952: 
                    953:     # Add the text
1.755     neumanie  954:     if ($text ne "") {	
1.763     bisitz    955: 	$template.='<span class="LC_help_open_topic">'
                    956:                   .'<a target="_top" href="'.$link.'">'
                    957:                   .$text.'</a>';
1.48      bowersj2  958:     }
                    959: 
1.763     bisitz    960:     # (Always) Add the graphic
1.179     matthew   961:     my $title = &mt('Online Help');
1.667     raeburn   962:     my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.763     bisitz    963:     $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
                    964:               .'<img src="'.$helpicon.'" border="0"'
                    965:               .' alt="'.&mt('Help: [_1]',$topic).'"'
1.783     amueller  966:               .' title="'.$title.'"' 
1.763     bisitz    967:               .' /></a>';
                    968:     if ($text ne "") {	
                    969:         $template.='</span>';
                    970:     }
1.44      bowersj2  971:     return $template;
                    972: 
1.106     bowersj2  973: }
                    974: 
                    975: # This is a quicky function for Latex cheatsheet editing, since it 
                    976: # appears in at least four places
                    977: sub helpLatexCheatsheet {
1.732     raeburn   978:     my ($topic,$text,$not_author) = @_;
                    979:     my $out;
1.106     bowersj2  980:     my $addOther = '';
1.732     raeburn   981:     if ($topic) {
1.763     bisitz    982: 	$addOther = '<span>'.&Apache::loncommon::help_open_topic($topic,&mt($text),
                    983: 							       undef, undef, 600).
                    984: 								   '</span> ';
                    985:     }
                    986:     $out = '<span>' # Start cheatsheet
                    987: 	  .$addOther
                    988:           .'<span>'
                    989: 	  .&Apache::loncommon::help_open_topic('Greek_Symbols',&mt('Greek Symbols'),
                    990: 					       undef,undef,600)
                    991: 	  .'</span> <span>'
                    992: 	  .&Apache::loncommon::help_open_topic('Other_Symbols',&mt('Other Symbols'),
                    993: 					       undef,undef,600)
                    994: 	  .'</span>';
1.732     raeburn   995:     unless ($not_author) {
1.763     bisitz    996:         $out .= ' <span>'
                    997: 	       .&Apache::loncommon::help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),
                    998: 	                                            undef,undef,600)
                    999: 	       .'</span>';
1.732     raeburn  1000:     }
1.763     bisitz   1001:     $out .= '</span>'; # End cheatsheet
1.732     raeburn  1002:     return $out;
1.172     www      1003: }
                   1004: 
1.430     albertel 1005: sub general_help {
                   1006:     my $helptopic='Student_Intro';
                   1007:     if ($env{'request.role'}=~/^(ca|au)/) {
                   1008: 	$helptopic='Authoring_Intro';
                   1009:     } elsif ($env{'request.role'}=~/^cc/) {
                   1010: 	$helptopic='Course_Coordination_Intro';
1.672     raeburn  1011:     } elsif ($env{'request.role'}=~/^dc/) {
                   1012:         $helptopic='Domain_Coordination_Intro';
1.430     albertel 1013:     }
                   1014:     return $helptopic;
                   1015: }
                   1016: 
                   1017: sub update_help_link {
                   1018:     my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
                   1019:     my $origurl = $ENV{'REQUEST_URI'};
                   1020:     $origurl=~s|^/~|/priv/|;
                   1021:     my $timestamp = time;
                   1022:     foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
                   1023:         $$datum = &escape($$datum);
                   1024:     }
                   1025: 
                   1026:     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";
                   1027:     my $output .= <<"ENDOUTPUT";
                   1028: <script type="text/javascript">
                   1029: banner_link = '$banner_link';
                   1030: </script>
                   1031: ENDOUTPUT
                   1032:     return $output;
                   1033: }
                   1034: 
                   1035: # now just updates the help link and generates a blue icon
1.193     raeburn  1036: sub help_open_menu {
1.430     albertel 1037:     my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text) 
1.552     banghart 1038: 	= @_;    
1.430     albertel 1039:     $stayOnPage = 0 if (not defined $stayOnPage);
1.572     banghart 1040:     # only use pop-up help (stayOnPage == 0)
1.552     banghart 1041:     # if environment.remote is on (using remote control UI)
1.572     banghart 1042:     if ($env{'browser.interface'} eq 'textual' ||
                   1043:     	$env{'environment.remote'} eq 'off' ) {
1.552     banghart 1044:         $stayOnPage=1;
1.430     albertel 1045:     }
                   1046:     my $output;
                   1047:     if ($component_help) {
                   1048: 	if (!$text) {
                   1049: 	    $output=&help_open_topic($component_help,undef,$stayOnPage,
                   1050: 				       $width,$height);
                   1051: 	} else {
                   1052: 	    my $help_text;
                   1053: 	    $help_text=&unescape($topic);
                   1054: 	    $output='<table><tr><td>'.
                   1055: 		&help_open_topic($component_help,$help_text,$stayOnPage,
                   1056: 				 $width,$height).'</td></tr></table>';
                   1057: 	}
                   1058:     }
                   1059:     my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
                   1060:     return $output.$banner_link;
                   1061: }
                   1062: 
                   1063: sub top_nav_help {
                   1064:     my ($text) = @_;
1.436     albertel 1065:     $text = &mt($text);
1.572     banghart 1066:     my $stay_on_page = 
1.436     albertel 1067: 	($env{'browser.interface'}  eq 'textual' ||
                   1068: 	 $env{'environment.remote'} eq 'off' );
1.572     banghart 1069:     my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436     albertel 1070: 	                     : "javascript:helpMenu('open')";
1.572     banghart 1071:     my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436     albertel 1072: 
1.201     raeburn  1073:     my $title = &mt('Get help');
1.436     albertel 1074: 
                   1075:     return <<"END";
                   1076: $banner_link
                   1077:  <a href="$link" title="$title">$text</a>
                   1078: END
                   1079: }
                   1080: 
                   1081: sub help_menu_js {
                   1082:     my ($text) = @_;
                   1083: 
                   1084:     my $stayOnPage = 
                   1085: 	($env{'browser.interface'}  eq 'textual' ||
                   1086: 	 $env{'environment.remote'} eq 'off' );
                   1087: 
                   1088:     my $width = 620;
                   1089:     my $height = 600;
1.430     albertel 1090:     my $helptopic=&general_help();
                   1091:     my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261     albertel 1092:     my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331     albertel 1093:     my $start_page =
                   1094:         &Apache::loncommon::start_page('Help Menu', undef,
                   1095: 				       {'frameset'    => 1,
                   1096: 					'js_ready'    => 1,
                   1097: 					'add_entries' => {
                   1098: 					    'border' => '0',
1.579     raeburn  1099: 					    'rows'   => "110,*",},});
1.331     albertel 1100:     my $end_page =
                   1101:         &Apache::loncommon::end_page({'frameset' => 1,
                   1102: 				      'js_ready' => 1,});
                   1103: 
1.436     albertel 1104:     my $template .= <<"ENDTEMPLATE";
                   1105: <script type="text/javascript">
1.253     albertel 1106: // <!-- BEGIN LON-CAPA Internal
                   1107: // <![CDATA[
1.430     albertel 1108: var banner_link = '';
1.243     raeburn  1109: function helpMenu(target) {
                   1110:     var caller = this;
                   1111:     if (target == 'open') {
                   1112:         var newWindow = null;
                   1113:         try {
1.262     albertel 1114:             newWindow =  window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243     raeburn  1115:         }
                   1116:         catch(error) {
                   1117:             writeHelp(caller);
                   1118:             return;
                   1119:         }
                   1120:         if (newWindow) {
                   1121:             caller = newWindow;
                   1122:         }
1.193     raeburn  1123:     }
1.243     raeburn  1124:     writeHelp(caller);
                   1125:     return;
                   1126: }
                   1127: function writeHelp(caller) {
1.430     albertel 1128:     caller.document.writeln('$start_page<frame name="bannerframe"  src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243     raeburn  1129:     caller.document.close()
                   1130:     caller.focus()
1.193     raeburn  1131: }
1.253     albertel 1132: // ]]>
1.219     albertel 1133: // END LON-CAPA Internal -->
1.436     albertel 1134: </script>
1.193     raeburn  1135: ENDTEMPLATE
                   1136:     return $template;
                   1137: }
                   1138: 
1.172     www      1139: sub help_open_bug {
                   1140:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258     albertel 1141:     unless ($env{'user.adv'}) { return ''; }
1.172     www      1142:     unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
                   1143:     $text = "" if (not defined $text);
                   1144:     $stayOnPage = 0 if (not defined $stayOnPage);
1.258     albertel 1145:     if ($env{'browser.interface'} eq 'textual' ||
                   1146: 	$env{'environment.remote'} eq 'off' ) {
1.172     www      1147: 	$stayOnPage=1;
                   1148:     }
1.184     albertel 1149:     $width = 600 if (not defined $width);
                   1150:     $height = 600 if (not defined $height);
1.172     www      1151: 
                   1152:     $topic=~s/\W+/\+/g;
                   1153:     my $link='';
                   1154:     my $template='';
1.379     albertel 1155:     my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&amp;bug_file_loc='.
                   1156: 	&escape($ENV{'REQUEST_URI'}).'&amp;component='.$topic;
1.172     www      1157:     if (!$stayOnPage)
                   1158:     {
                   1159: 	$link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
                   1160:     }
                   1161:     else
                   1162:     {
                   1163: 	$link = $url;
                   1164:     }
                   1165:     # Add the text
                   1166:     if ($text ne "")
                   1167:     {
                   1168: 	$template .= 
                   1169:   "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705     tempelho 1170:   "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172     www      1171:     }
                   1172: 
                   1173:     # Add the graphic
1.179     matthew  1174:     my $title = &mt('Report a Bug');
1.215     albertel 1175:     my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172     www      1176:     $template .= <<"ENDTEMPLATE";
1.436     albertel 1177:  <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172     www      1178: ENDTEMPLATE
                   1179:     if ($text ne '') { $template.='</td></tr></table>' };
                   1180:     return $template;
                   1181: 
                   1182: }
                   1183: 
                   1184: sub help_open_faq {
                   1185:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258     albertel 1186:     unless ($env{'user.adv'}) { return ''; }
1.172     www      1187:     unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
                   1188:     $text = "" if (not defined $text);
                   1189:     $stayOnPage = 0 if (not defined $stayOnPage);
1.258     albertel 1190:     if ($env{'browser.interface'} eq 'textual' ||
                   1191: 	$env{'environment.remote'} eq 'off' ) {
1.172     www      1192: 	$stayOnPage=1;
                   1193:     }
                   1194:     $width = 350 if (not defined $width);
                   1195:     $height = 400 if (not defined $height);
                   1196: 
                   1197:     $topic=~s/\W+/\+/g;
                   1198:     my $link='';
                   1199:     my $template='';
                   1200:     my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
                   1201:     if (!$stayOnPage)
                   1202:     {
                   1203: 	$link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
                   1204:     }
                   1205:     else
                   1206:     {
                   1207: 	$link = $url;
                   1208:     }
                   1209: 
                   1210:     # Add the text
                   1211:     if ($text ne "")
                   1212:     {
                   1213: 	$template .= 
1.173     www      1214:   "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705     tempelho 1215:   "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172     www      1216:     }
                   1217: 
                   1218:     # Add the graphic
1.179     matthew  1219:     my $title = &mt('View the FAQ');
1.215     albertel 1220:     my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172     www      1221:     $template .= <<"ENDTEMPLATE";
1.436     albertel 1222:  <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172     www      1223: ENDTEMPLATE
                   1224:     if ($text ne '') { $template.='</td></tr></table>' };
                   1225:     return $template;
                   1226: 
1.44      bowersj2 1227: }
1.37      matthew  1228: 
1.180     matthew  1229: ###############################################################
                   1230: ###############################################################
                   1231: 
1.45      matthew  1232: =pod
                   1233: 
1.648     raeburn  1234: =item * &change_content_javascript():
1.256     matthew  1235: 
                   1236: This and the next function allow you to create small sections of an
                   1237: otherwise static HTML page that you can update on the fly with
                   1238: Javascript, even in Netscape 4.
                   1239: 
                   1240: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
                   1241: must be written to the HTML page once. It will prove the Javascript
                   1242: function "change(name, content)". Calling the change function with the
                   1243: name of the section 
                   1244: you want to update, matching the name passed to C<changable_area>, and
                   1245: the new content you want to put in there, will put the content into
                   1246: that area.
                   1247: 
                   1248: B<Note>: Netscape 4 only reserves enough space for the changable area
                   1249: to contain room for the original contents. You need to "make space"
                   1250: for whatever changes you wish to make, and be B<sure> to check your
                   1251: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
                   1252: it's adequate for updating a one-line status display, but little more.
                   1253: This script will set the space to 100% width, so you only need to
                   1254: worry about height in Netscape 4.
                   1255: 
                   1256: Modern browsers are much less limiting, and if you can commit to the
                   1257: user not using Netscape 4, this feature may be used freely with
                   1258: pretty much any HTML.
                   1259: 
                   1260: =cut
                   1261: 
                   1262: sub change_content_javascript {
                   1263:     # If we're on Netscape 4, we need to use Layer-based code
1.258     albertel 1264:     if ($env{'browser.type'} eq 'netscape' &&
                   1265: 	$env{'browser.version'} =~ /^4\./) {
1.256     matthew  1266: 	return (<<NETSCAPE4);
                   1267: 	function change(name, content) {
                   1268: 	    doc = document.layers[name+"___escape"].layers[0].document;
                   1269: 	    doc.open();
                   1270: 	    doc.write(content);
                   1271: 	    doc.close();
                   1272: 	}
                   1273: NETSCAPE4
                   1274:     } else {
                   1275: 	# Otherwise, we need to use semi-standards-compliant code
                   1276: 	# (technically, "innerHTML" isn't standard but the equivalent
                   1277: 	# is really scary, and every useful browser supports it
                   1278: 	return (<<DOMBASED);
                   1279: 	function change(name, content) {
                   1280: 	    element = document.getElementById(name);
                   1281: 	    element.innerHTML = content;
                   1282: 	}
                   1283: DOMBASED
                   1284:     }
                   1285: }
                   1286: 
                   1287: =pod
                   1288: 
1.648     raeburn  1289: =item * &changable_area($name,$origContent):
1.256     matthew  1290: 
                   1291: This provides a "changable area" that can be modified on the fly via
                   1292: the Javascript code provided in C<change_content_javascript>. $name is
                   1293: the name you will use to reference the area later; do not repeat the
                   1294: same name on a given HTML page more then once. $origContent is what
                   1295: the area will originally contain, which can be left blank.
                   1296: 
                   1297: =cut
                   1298: 
                   1299: sub changable_area {
                   1300:     my ($name, $origContent) = @_;
                   1301: 
1.258     albertel 1302:     if ($env{'browser.type'} eq 'netscape' &&
                   1303: 	$env{'browser.version'} =~ /^4\./) {
1.256     matthew  1304: 	# If this is netscape 4, we need to use the Layer tag
                   1305: 	return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
                   1306:     } else {
                   1307: 	return "<span id='$name'>$origContent</span>";
                   1308:     }
                   1309: }
                   1310: 
                   1311: =pod
                   1312: 
1.648     raeburn  1313: =item * &viewport_geometry_js 
1.590     raeburn  1314: 
                   1315: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
                   1316: 
                   1317: =cut
                   1318: 
                   1319: 
                   1320: sub viewport_geometry_js { 
                   1321:     return <<"GEOMETRY";
                   1322: var Geometry = {};
                   1323: function init_geometry() {
                   1324:     if (Geometry.init) { return };
                   1325:     Geometry.init=1;
                   1326:     if (window.innerHeight) {
                   1327:         Geometry.getViewportHeight   = function() { return window.innerHeight; };
                   1328:         Geometry.getViewportWidth   = function() { return window.innerWidth; };
                   1329:         Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
                   1330:         Geometry.getVerticalScroll   = function() { return window.pageYOffset; };
                   1331:     }
                   1332:     else if (document.documentElement && document.documentElement.clientHeight) {
                   1333:         Geometry.getViewportHeight =
                   1334:             function() { return document.documentElement.clientHeight; };
                   1335:         Geometry.getViewportWidth =
                   1336:             function() { return document.documentElement.clientWidth; };
                   1337: 
                   1338:         Geometry.getHorizontalScroll =
                   1339:             function() { return document.documentElement.scrollLeft; };
                   1340:         Geometry.getVerticalScroll =
                   1341:             function() { return document.documentElement.scrollTop; };
                   1342:     }
                   1343:     else if (document.body.clientHeight) {
                   1344:         Geometry.getViewportHeight =
                   1345:             function() { return document.body.clientHeight; };
                   1346:         Geometry.getViewportWidth =
                   1347:             function() { return document.body.clientWidth; };
                   1348:         Geometry.getHorizontalScroll =
                   1349:             function() { return document.body.scrollLeft; };
                   1350:         Geometry.getVerticalScroll =
                   1351:             function() { return document.body.scrollTop; };
                   1352:     }
                   1353: }
                   1354: 
                   1355: GEOMETRY
                   1356: }
                   1357: 
                   1358: =pod
                   1359: 
1.648     raeburn  1360: =item * &viewport_size_js()
1.590     raeburn  1361: 
                   1362: 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. 
                   1363: 
                   1364: =cut
                   1365: 
                   1366: sub viewport_size_js {
                   1367:     my $geometry = &viewport_geometry_js();
                   1368:     return <<"DIMS";
                   1369: 
                   1370: $geometry
                   1371: 
                   1372: function getViewportDims(width,height) {
                   1373:     init_geometry();
                   1374:     width.value = Geometry.getViewportWidth();
                   1375:     height.value = Geometry.getViewportHeight();
                   1376:     return;
                   1377: }
                   1378: 
                   1379: DIMS
                   1380: }
                   1381: 
                   1382: =pod
                   1383: 
1.648     raeburn  1384: =item * &resize_textarea_js()
1.565     albertel 1385: 
                   1386: emits the needed javascript to resize a textarea to be as big as possible
                   1387: 
                   1388: creates a function resize_textrea that takes two IDs first should be
                   1389: the id of the element to resize, second should be the id of a div that
                   1390: surrounds everything that comes after the textarea, this routine needs
                   1391: to be attached to the <body> for the onload and onresize events.
                   1392: 
1.648     raeburn  1393: =back
1.565     albertel 1394: 
                   1395: =cut
                   1396: 
                   1397: sub resize_textarea_js {
1.590     raeburn  1398:     my $geometry = &viewport_geometry_js();
1.565     albertel 1399:     return <<"RESIZE";
                   1400:     <script type="text/javascript">
1.590     raeburn  1401: $geometry
1.565     albertel 1402: 
1.588     albertel 1403: function getX(element) {
                   1404:     var x = 0;
                   1405:     while (element) {
                   1406: 	x += element.offsetLeft;
                   1407: 	element = element.offsetParent;
                   1408:     }
                   1409:     return x;
                   1410: }
                   1411: function getY(element) {
                   1412:     var y = 0;
                   1413:     while (element) {
                   1414: 	y += element.offsetTop;
                   1415: 	element = element.offsetParent;
                   1416:     }
                   1417:     return y;
                   1418: }
                   1419: 
                   1420: 
1.565     albertel 1421: function resize_textarea(textarea_id,bottom_id) {
                   1422:     init_geometry();
                   1423:     var textarea        = document.getElementById(textarea_id);
                   1424:     //alert(textarea);
                   1425: 
1.588     albertel 1426:     var textarea_top    = getY(textarea);
1.565     albertel 1427:     var textarea_height = textarea.offsetHeight;
                   1428:     var bottom          = document.getElementById(bottom_id);
1.588     albertel 1429:     var bottom_top      = getY(bottom);
1.565     albertel 1430:     var bottom_height   = bottom.offsetHeight;
                   1431:     var window_height   = Geometry.getViewportHeight();
1.588     albertel 1432:     var fudge           = 23;
1.565     albertel 1433:     var new_height      = window_height-fudge-textarea_top-bottom_height;
                   1434:     if (new_height < 300) {
                   1435: 	new_height = 300;
                   1436:     }
                   1437:     textarea.style.height=new_height+'px';
                   1438: }
                   1439: </script>
                   1440: RESIZE
                   1441: 
                   1442: }
                   1443: 
                   1444: =pod
                   1445: 
1.256     matthew  1446: =head1 Excel and CSV file utility routines
                   1447: 
                   1448: =over 4
                   1449: 
                   1450: =cut
                   1451: 
                   1452: ###############################################################
                   1453: ###############################################################
                   1454: 
                   1455: =pod
                   1456: 
1.648     raeburn  1457: =item * &csv_translate($text) 
1.37      matthew  1458: 
1.185     www      1459: Translate $text to allow it to be output as a 'comma separated values' 
1.37      matthew  1460: format.
                   1461: 
                   1462: =cut
                   1463: 
1.180     matthew  1464: ###############################################################
                   1465: ###############################################################
1.37      matthew  1466: sub csv_translate {
                   1467:     my $text = shift;
                   1468:     $text =~ s/\"/\"\"/g;
1.209     albertel 1469:     $text =~ s/\n/ /g;
1.37      matthew  1470:     return $text;
                   1471: }
1.180     matthew  1472: 
                   1473: ###############################################################
                   1474: ###############################################################
                   1475: 
                   1476: =pod
                   1477: 
1.648     raeburn  1478: =item * &define_excel_formats()
1.180     matthew  1479: 
                   1480: Define some commonly used Excel cell formats.
                   1481: 
                   1482: Currently supported formats:
                   1483: 
                   1484: =over 4
                   1485: 
                   1486: =item header
                   1487: 
                   1488: =item bold
                   1489: 
                   1490: =item h1
                   1491: 
                   1492: =item h2
                   1493: 
                   1494: =item h3
                   1495: 
1.256     matthew  1496: =item h4
                   1497: 
                   1498: =item i
                   1499: 
1.180     matthew  1500: =item date
                   1501: 
                   1502: =back
                   1503: 
                   1504: Inputs: $workbook
                   1505: 
                   1506: Returns: $format, a hash reference.
                   1507: 
                   1508: =cut
                   1509: 
                   1510: ###############################################################
                   1511: ###############################################################
                   1512: sub define_excel_formats {
                   1513:     my ($workbook) = @_;
                   1514:     my $format;
                   1515:     $format->{'header'} = $workbook->add_format(bold      => 1, 
                   1516:                                                 bottom    => 1,
                   1517:                                                 align     => 'center');
                   1518:     $format->{'bold'} = $workbook->add_format(bold=>1);
                   1519:     $format->{'h1'}   = $workbook->add_format(bold=>1, size=>18);
                   1520:     $format->{'h2'}   = $workbook->add_format(bold=>1, size=>16);
                   1521:     $format->{'h3'}   = $workbook->add_format(bold=>1, size=>14);
1.255     matthew  1522:     $format->{'h4'}   = $workbook->add_format(bold=>1, size=>12);
1.246     matthew  1523:     $format->{'i'}    = $workbook->add_format(italic=>1);
1.180     matthew  1524:     $format->{'date'} = $workbook->add_format(num_format=>
1.207     matthew  1525:                                             'mm/dd/yyyy hh:mm:ss');
1.180     matthew  1526:     return $format;
                   1527: }
                   1528: 
                   1529: ###############################################################
                   1530: ###############################################################
1.113     bowersj2 1531: 
                   1532: =pod
                   1533: 
1.648     raeburn  1534: =item * &create_workbook()
1.255     matthew  1535: 
                   1536: Create an Excel worksheet.  If it fails, output message on the
                   1537: request object and return undefs.
                   1538: 
                   1539: Inputs: Apache request object
                   1540: 
                   1541: Returns (undef) on failure, 
                   1542:     Excel worksheet object, scalar with filename, and formats 
                   1543:     from &Apache::loncommon::define_excel_formats on success
                   1544: 
                   1545: =cut
                   1546: 
                   1547: ###############################################################
                   1548: ###############################################################
                   1549: sub create_workbook {
                   1550:     my ($r) = @_;
                   1551:         #
                   1552:     # Create the excel spreadsheet
                   1553:     my $filename = '/prtspool/'.
1.258     albertel 1554:         $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255     matthew  1555:         time.'_'.rand(1000000000).'.xls';
                   1556:     my $workbook  = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
                   1557:     if (! defined($workbook)) {
                   1558:         $r->log_error("Error creating excel spreadsheet $filename: $!");
                   1559:         $r->print('<p>'.&mt("Unable to create new Excel file.  ".
                   1560:                             "This error has been logged.  ".
                   1561:                             "Please alert your LON-CAPA administrator").
                   1562:                   '</p>');
                   1563:         return (undef);
                   1564:     }
                   1565:     #
                   1566:     $workbook->set_tempdir('/home/httpd/perl/tmp');
                   1567:     #
                   1568:     my $format = &Apache::loncommon::define_excel_formats($workbook);
                   1569:     return ($workbook,$filename,$format);
                   1570: }
                   1571: 
                   1572: ###############################################################
                   1573: ###############################################################
                   1574: 
                   1575: =pod
                   1576: 
1.648     raeburn  1577: =item * &create_text_file()
1.113     bowersj2 1578: 
1.542     raeburn  1579: Create a file to write to and eventually make available to the user.
1.256     matthew  1580: If file creation fails, outputs an error message on the request object and 
                   1581: return undefs.
1.113     bowersj2 1582: 
1.256     matthew  1583: Inputs: Apache request object, and file suffix
1.113     bowersj2 1584: 
1.256     matthew  1585: Returns (undef) on failure, 
                   1586:     Filehandle and filename on success.
1.113     bowersj2 1587: 
                   1588: =cut
                   1589: 
1.256     matthew  1590: ###############################################################
                   1591: ###############################################################
                   1592: sub create_text_file {
                   1593:     my ($r,$suffix) = @_;
                   1594:     if (! defined($suffix)) { $suffix = 'txt'; };
                   1595:     my $fh;
                   1596:     my $filename = '/prtspool/'.
1.258     albertel 1597:         $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256     matthew  1598:         time.'_'.rand(1000000000).'.'.$suffix;
                   1599:     $fh = Apache::File->new('>/home/httpd'.$filename);
                   1600:     if (! defined($fh)) {
                   1601:         $r->log_error("Couldn't open $filename for output $!");
1.683     bisitz   1602:         $r->print(&mt('Problems occurred in creating the output file. '
                   1603:                      .'This error has been logged. '
                   1604:                      .'Please alert your LON-CAPA administrator.'));
1.113     bowersj2 1605:     }
1.256     matthew  1606:     return ($fh,$filename)
1.113     bowersj2 1607: }
                   1608: 
                   1609: 
1.256     matthew  1610: =pod 
1.113     bowersj2 1611: 
                   1612: =back
                   1613: 
                   1614: =cut
1.37      matthew  1615: 
                   1616: ###############################################################
1.33      matthew  1617: ##        Home server <option> list generating code          ##
                   1618: ###############################################################
1.35      matthew  1619: 
1.169     www      1620: # ------------------------------------------
                   1621: 
                   1622: sub domain_select {
                   1623:     my ($name,$value,$multiple)=@_;
                   1624:     my %domains=map { 
1.514     albertel 1625: 	$_ => $_.' '. &Apache::lonnet::domain($_,'description') 
1.512     albertel 1626:     } &Apache::lonnet::all_domains();
1.169     www      1627:     if ($multiple) {
                   1628: 	$domains{''}=&mt('Any domain');
1.550     albertel 1629: 	$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287     albertel 1630: 	return &multiple_select_form($name,$value,4,\%domains);
1.169     www      1631:     } else {
1.550     albertel 1632: 	$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.169     www      1633: 	return &select_form($name,$value,%domains);
                   1634:     }
                   1635: }
                   1636: 
1.282     albertel 1637: #-------------------------------------------
                   1638: 
                   1639: =pod
                   1640: 
1.519     raeburn  1641: =head1 Routines for form select boxes
                   1642: 
                   1643: =over 4
                   1644: 
1.648     raeburn  1645: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282     albertel 1646: 
                   1647: Returns a string containing a <select> element int multiple mode
                   1648: 
                   1649: 
                   1650: Args:
                   1651:   $name - name of the <select> element
1.506     raeburn  1652:   $value - scalar or array ref of values that should already be selected
1.282     albertel 1653:   $size - number of rows long the select element is
1.283     albertel 1654:   $hash - the elements should be 'option' => 'shown text'
1.282     albertel 1655:           (shown text should already have been &mt())
1.506     raeburn  1656:   $order - (optional) array ref of the order to show the elements in
1.283     albertel 1657: 
1.282     albertel 1658: =cut
                   1659: 
                   1660: #-------------------------------------------
1.169     www      1661: sub multiple_select_form {
1.284     albertel 1662:     my ($name,$value,$size,$hash,$order)=@_;
1.169     www      1663:     my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
                   1664:     my $output='';
1.191     matthew  1665:     if (! defined($size)) {
                   1666:         $size = 4;
1.283     albertel 1667:         if (scalar(keys(%$hash))<4) {
                   1668:             $size = scalar(keys(%$hash));
1.191     matthew  1669:         }
                   1670:     }
1.734     bisitz   1671:     $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501     banghart 1672:     my @order;
1.506     raeburn  1673:     if (ref($order) eq 'ARRAY')  {
                   1674:         @order = @{$order};
                   1675:     } else {
                   1676:         @order = sort(keys(%$hash));
1.501     banghart 1677:     }
                   1678:     if (exists($$hash{'select_form_order'})) {
                   1679:         @order = @{$$hash{'select_form_order'}};
                   1680:     }
                   1681:         
1.284     albertel 1682:     foreach my $key (@order) {
1.356     albertel 1683:         $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284     albertel 1684:         $output.='selected="selected" ' if ($selected{$key});
                   1685:         $output.='>'.$hash->{$key}."</option>\n";
1.169     www      1686:     }
                   1687:     $output.="</select>\n";
                   1688:     return $output;
                   1689: }
                   1690: 
1.88      www      1691: #-------------------------------------------
                   1692: 
                   1693: =pod
                   1694: 
1.648     raeburn  1695: =item * &select_form($defdom,$name,%hash)
1.88      www      1696: 
                   1697: Returns a string containing a <select name='$name' size='1'> form to 
                   1698: allow a user to select options from a hash option_name => displayed text.  
                   1699: See lonrights.pm for an example invocation and use.
                   1700: 
                   1701: =cut
                   1702: 
                   1703: #-------------------------------------------
                   1704: sub select_form {
                   1705:     my ($def,$name,%hash) = @_;
                   1706:     my $selectform = "<select name=\"$name\" size=\"1\">\n";
1.128     albertel 1707:     my @keys;
                   1708:     if (exists($hash{'select_form_order'})) {
                   1709: 	@keys=@{$hash{'select_form_order'}};
                   1710:     } else {
                   1711: 	@keys=sort(keys(%hash));
                   1712:     }
1.356     albertel 1713:     foreach my $key (@keys) {
                   1714:         $selectform.=
                   1715: 	    '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
                   1716:             ($key eq $def ? 'selected="selected" ' : '').
                   1717:                 ">".&mt($hash{$key})."</option>\n";
1.88      www      1718:     }
                   1719:     $selectform.="</select>";
                   1720:     return $selectform;
                   1721: }
                   1722: 
1.475     www      1723: # For display filters
                   1724: 
                   1725: sub display_filter {
                   1726:     if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477     www      1727:     if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.714     bisitz   1728:     return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1.475     www      1729: 			       &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
                   1730: 							   (&mt('all'),10,20,50,100,1000,10000))).
1.714     bisitz   1731: 	   '</label></span> <span class="LC_nobreak">'.
1.475     www      1732:            &mt('Filter [_1]',
1.477     www      1733: 	   &select_form($env{'form.displayfilter'},
                   1734: 			'displayfilter',
                   1735: 			('currentfolder' => 'Current folder/page',
                   1736: 			 'containing' => 'Containing phrase',
                   1737: 			 'none' => 'None'))).
1.714     bisitz   1738: 			 '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1.475     www      1739: }
                   1740: 
1.167     www      1741: sub gradeleveldescription {
                   1742:     my $gradelevel=shift;
                   1743:     my %gradelevels=(0 => 'Not specified',
                   1744: 		     1 => 'Grade 1',
                   1745: 		     2 => 'Grade 2',
                   1746: 		     3 => 'Grade 3',
                   1747: 		     4 => 'Grade 4',
                   1748: 		     5 => 'Grade 5',
                   1749: 		     6 => 'Grade 6',
                   1750: 		     7 => 'Grade 7',
                   1751: 		     8 => 'Grade 8',
                   1752: 		     9 => 'Grade 9',
                   1753: 		     10 => 'Grade 10',
                   1754: 		     11 => 'Grade 11',
                   1755: 		     12 => 'Grade 12',
                   1756: 		     13 => 'Grade 13',
                   1757: 		     14 => '100 Level',
                   1758: 		     15 => '200 Level',
                   1759: 		     16 => '300 Level',
                   1760: 		     17 => '400 Level',
                   1761: 		     18 => 'Graduate Level');
                   1762:     return &mt($gradelevels{$gradelevel});
                   1763: }
                   1764: 
1.163     www      1765: sub select_level_form {
                   1766:     my ($deflevel,$name)=@_;
                   1767:     unless ($deflevel) { $deflevel=0; }
1.167     www      1768:     my $selectform = "<select name=\"$name\" size=\"1\">\n";
                   1769:     for (my $i=0; $i<=18; $i++) {
                   1770:         $selectform.="<option value=\"$i\" ".
1.253     albertel 1771:             ($i==$deflevel ? 'selected="selected" ' : '').
1.167     www      1772:                 ">".&gradeleveldescription($i)."</option>\n";
                   1773:     }
                   1774:     $selectform.="</select>";
                   1775:     return $selectform;
1.163     www      1776: }
1.167     www      1777: 
1.35      matthew  1778: #-------------------------------------------
                   1779: 
1.45      matthew  1780: =pod
                   1781: 
1.743     raeburn  1782: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$autosubmit)
1.35      matthew  1783: 
                   1784: Returns a string containing a <select name='$name' size='1'> form to 
                   1785: allow a user to select the domain to preform an operation in.  
                   1786: See loncreateuser.pm for an example invocation and use.
                   1787: 
1.90      www      1788: If the $includeempty flag is set, it also includes an empty choice ("no domain
                   1789: selected");
                   1790: 
1.743     raeburn  1791: If the $showdomdesc flag is set, the domain name is followed by the domain description.
                   1792: 
                   1793: If the $autosubmit flag is set, the form containing the domain selector will be auto-submitted by an onchange action.  
1.563     raeburn  1794: 
1.35      matthew  1795: =cut
                   1796: 
                   1797: #-------------------------------------------
1.34      matthew  1798: sub select_dom_form {
1.743     raeburn  1799:     my ($defdom,$name,$includeempty,$showdomdesc,$autosubmit) = @_;
                   1800:     my $onchange;
                   1801:     if ($autosubmit) {
                   1802:         $onchange = ' onchange="this.form.submit()"';
                   1803:     }
1.550     albertel 1804:     my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1.90      www      1805:     if ($includeempty) { @domains=('',@domains); }
1.743     raeburn  1806:     my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356     albertel 1807:     foreach my $dom (@domains) {
                   1808:         $selectdomain.="<option value=\"$dom\" ".
1.563     raeburn  1809:             ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
                   1810:         if ($showdomdesc) {
                   1811:             if ($dom ne '') {
                   1812:                 my $domdesc = &Apache::lonnet::domain($dom,'description');
                   1813:                 if ($domdesc ne '') {
                   1814:                     $selectdomain .= ' ('.$domdesc.')';
                   1815:                 }
                   1816:             } 
                   1817:         }
                   1818:         $selectdomain .= "</option>\n";
1.34      matthew  1819:     }
                   1820:     $selectdomain.="</select>";
                   1821:     return $selectdomain;
                   1822: }
                   1823: 
1.35      matthew  1824: #-------------------------------------------
                   1825: 
1.45      matthew  1826: =pod
                   1827: 
1.648     raeburn  1828: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35      matthew  1829: 
1.586     raeburn  1830: input: 4 arguments (two required, two optional) - 
                   1831:     $domain - domain of new user
                   1832:     $name - name of form element
                   1833:     $default - Value of 'default' causes a default item to be first 
                   1834:                             option, and selected by default. 
                   1835:     $hide - Value of 'hide' causes hiding of the name of the server, 
                   1836:                             if 1 server found, or default, if 0 found.
1.594     raeburn  1837: output: returns 2 items: 
1.586     raeburn  1838: (a) form element which contains either:
                   1839:    (i) <select name="$name">
                   1840:         <option value="$hostid1">$hostid $servers{$hostid}</option>
                   1841:         <option value="$hostid2">$hostid $servers{$hostid}</option>       
                   1842:        </select>
                   1843:        form item if there are multiple library servers in $domain, or
                   1844:    (ii) an <input type="hidden" name="$name" value="$hostid" /> form item 
                   1845:        if there is only one library server in $domain.
                   1846: 
                   1847: (b) number of library servers found.
                   1848: 
                   1849: See loncreateuser.pm for example of use.
1.35      matthew  1850: 
                   1851: =cut
                   1852: 
                   1853: #-------------------------------------------
1.586     raeburn  1854: sub home_server_form_item {
                   1855:     my ($domain,$name,$default,$hide) = @_;
1.513     albertel 1856:     my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586     raeburn  1857:     my $result;
                   1858:     my $numlib = keys(%servers);
                   1859:     if ($numlib > 1) {
                   1860:         $result .= '<select name="'.$name.'" />'."\n";
                   1861:         if ($default) {
                   1862:             $result .= '<option value="default" selected>'.&mt('default').
                   1863:                        '</option>'."\n";
                   1864:         }
                   1865:         foreach my $hostid (sort(keys(%servers))) {
                   1866:             $result.= '<option value="'.$hostid.'">'.
                   1867: 	              $hostid.' '.$servers{$hostid}."</option>\n";
                   1868:         }
                   1869:         $result .= '</select>'."\n";
                   1870:     } elsif ($numlib == 1) {
                   1871:         my $hostid;
                   1872:         foreach my $item (keys(%servers)) {
                   1873:             $hostid = $item;
                   1874:         }
                   1875:         $result .= '<input type="hidden" name="'.$name.'" value="'.
                   1876:                    $hostid.'" />';
                   1877:                    if (!$hide) {
                   1878:                        $result .= $hostid.' '.$servers{$hostid};
                   1879:                    }
                   1880:                    $result .= "\n";
                   1881:     } elsif ($default) {
                   1882:         $result .= '<input type="hidden" name="'.$name.
                   1883:                    '" value="default" />';
                   1884:                    if (!$hide) {
                   1885:                        $result .= &mt('default');
                   1886:                    }
                   1887:                    $result .= "\n";
1.33      matthew  1888:     }
1.586     raeburn  1889:     return ($result,$numlib);
1.33      matthew  1890: }
1.112     bowersj2 1891: 
                   1892: =pod
                   1893: 
1.534     albertel 1894: =back 
                   1895: 
1.112     bowersj2 1896: =cut
1.87      matthew  1897: 
                   1898: ###############################################################
1.112     bowersj2 1899: ##                  Decoding User Agent                      ##
1.87      matthew  1900: ###############################################################
                   1901: 
                   1902: =pod
                   1903: 
1.112     bowersj2 1904: =head1 Decoding the User Agent
                   1905: 
                   1906: =over 4
                   1907: 
                   1908: =item * &decode_user_agent()
1.87      matthew  1909: 
                   1910: Inputs: $r
                   1911: 
                   1912: Outputs:
                   1913: 
                   1914: =over 4
                   1915: 
1.112     bowersj2 1916: =item * $httpbrowser
1.87      matthew  1917: 
1.112     bowersj2 1918: =item * $clientbrowser
1.87      matthew  1919: 
1.112     bowersj2 1920: =item * $clientversion
1.87      matthew  1921: 
1.112     bowersj2 1922: =item * $clientmathml
1.87      matthew  1923: 
1.112     bowersj2 1924: =item * $clientunicode
1.87      matthew  1925: 
1.112     bowersj2 1926: =item * $clientos
1.87      matthew  1927: 
                   1928: =back
                   1929: 
1.157     matthew  1930: =back 
                   1931: 
1.87      matthew  1932: =cut
                   1933: 
                   1934: ###############################################################
                   1935: ###############################################################
                   1936: sub decode_user_agent {
1.247     albertel 1937:     my ($r)=@_;
1.87      matthew  1938:     my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
                   1939:     my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
                   1940:     my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247     albertel 1941:     if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87      matthew  1942:     my $clientbrowser='unknown';
                   1943:     my $clientversion='0';
                   1944:     my $clientmathml='';
                   1945:     my $clientunicode='0';
                   1946:     for (my $i=0;$i<=$#browsertype;$i++) {
                   1947:         my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
                   1948: 	if (($httpbrowser=~/$match/i)  && ($httpbrowser!~/$notmatch/i)) {
                   1949: 	    $clientbrowser=$bname;
                   1950:             $httpbrowser=~/$vreg/i;
                   1951: 	    $clientversion=$1;
                   1952:             $clientmathml=($clientversion>=$minv);
                   1953:             $clientunicode=($clientversion>=$univ);
                   1954: 	}
                   1955:     }
                   1956:     my $clientos='unknown';
                   1957:     if (($httpbrowser=~/linux/i) ||
                   1958:         ($httpbrowser=~/unix/i) ||
                   1959:         ($httpbrowser=~/ux/i) ||
                   1960:         ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
                   1961:     if (($httpbrowser=~/vax/i) ||
                   1962:         ($httpbrowser=~/vms/i)) { $clientos='vms'; }
                   1963:     if ($httpbrowser=~/next/i) { $clientos='next'; }
                   1964:     if (($httpbrowser=~/mac/i) ||
                   1965:         ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
                   1966:     if ($httpbrowser=~/win/i) { $clientos='win'; }
                   1967:     if ($httpbrowser=~/embed/i) { $clientos='pda'; }
                   1968:     return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
                   1969:             $clientunicode,$clientos,);
                   1970: }
                   1971: 
1.32      matthew  1972: ###############################################################
                   1973: ##    Authentication changing form generation subroutines    ##
                   1974: ###############################################################
                   1975: ##
                   1976: ## All of the authform_xxxxxxx subroutines take their inputs in a
                   1977: ## hash, and have reasonable default values.
                   1978: ##
                   1979: ##    formname = the name given in the <form> tag.
1.35      matthew  1980: #-------------------------------------------
                   1981: 
1.45      matthew  1982: =pod
                   1983: 
1.112     bowersj2 1984: =head1 Authentication Routines
                   1985: 
                   1986: =over 4
                   1987: 
1.648     raeburn  1988: =item * &authform_xxxxxx()
1.35      matthew  1989: 
                   1990: The authform_xxxxxx subroutines provide javascript and html forms which 
                   1991: handle some of the conveniences required for authentication forms.  
                   1992: This is not an optimal method, but it works.  
                   1993: 
                   1994: =over 4
                   1995: 
1.112     bowersj2 1996: =item * authform_header
1.35      matthew  1997: 
1.112     bowersj2 1998: =item * authform_authorwarning
1.35      matthew  1999: 
1.112     bowersj2 2000: =item * authform_nochange
1.35      matthew  2001: 
1.112     bowersj2 2002: =item * authform_kerberos
1.35      matthew  2003: 
1.112     bowersj2 2004: =item * authform_internal
1.35      matthew  2005: 
1.112     bowersj2 2006: =item * authform_filesystem
1.35      matthew  2007: 
                   2008: =back
                   2009: 
1.648     raeburn  2010: See loncreateuser.pm for invocation and use examples.
1.157     matthew  2011: 
1.35      matthew  2012: =cut
                   2013: 
                   2014: #-------------------------------------------
1.32      matthew  2015: sub authform_header{  
                   2016:     my %in = (
                   2017:         formname => 'cu',
1.80      albertel 2018:         kerb_def_dom => '',
1.32      matthew  2019:         @_,
                   2020:     );
                   2021:     $in{'formname'} = 'document.' . $in{'formname'};
                   2022:     my $result='';
1.80      albertel 2023: 
                   2024: #---------------------------------------------- Code for upper case translation
                   2025:     my $Javascript_toUpperCase;
                   2026:     unless ($in{kerb_def_dom}) {
                   2027:         $Javascript_toUpperCase =<<"END";
                   2028:         switch (choice) {
                   2029:            case 'krb': currentform.elements[choicearg].value =
                   2030:                currentform.elements[choicearg].value.toUpperCase();
                   2031:                break;
                   2032:            default:
                   2033:         }
                   2034: END
                   2035:     } else {
                   2036:         $Javascript_toUpperCase = "";
                   2037:     }
                   2038: 
1.165     raeburn  2039:     my $radioval = "'nochange'";
1.591     raeburn  2040:     if (defined($in{'curr_authtype'})) {
                   2041:         if ($in{'curr_authtype'} ne '') {
                   2042:             $radioval = "'".$in{'curr_authtype'}."arg'";
                   2043:         }
1.174     matthew  2044:     }
1.165     raeburn  2045:     my $argfield = 'null';
1.591     raeburn  2046:     if (defined($in{'mode'})) {
1.165     raeburn  2047:         if ($in{'mode'} eq 'modifycourse')  {
1.591     raeburn  2048:             if (defined($in{'curr_autharg'})) {
                   2049:                 if ($in{'curr_autharg'} ne '') {
1.165     raeburn  2050:                     $argfield = "'$in{'curr_autharg'}'";
                   2051:                 }
                   2052:             }
                   2053:         }
                   2054:     }
                   2055: 
1.32      matthew  2056:     $result.=<<"END";
                   2057: var current = new Object();
1.165     raeburn  2058: current.radiovalue = $radioval;
                   2059: current.argfield = $argfield;
1.32      matthew  2060: 
                   2061: function changed_radio(choice,currentform) {
                   2062:     var choicearg = choice + 'arg';
                   2063:     // If a radio button in changed, we need to change the argfield
                   2064:     if (current.radiovalue != choice) {
                   2065:         current.radiovalue = choice;
                   2066:         if (current.argfield != null) {
                   2067:             currentform.elements[current.argfield].value = '';
                   2068:         }
                   2069:         if (choice == 'nochange') {
                   2070:             current.argfield = null;
                   2071:         } else {
                   2072:             current.argfield = choicearg;
                   2073:             switch(choice) {
                   2074:                 case 'krb': 
                   2075:                     currentform.elements[current.argfield].value = 
                   2076:                         "$in{'kerb_def_dom'}";
                   2077:                 break;
                   2078:               default:
                   2079:                 break;
                   2080:             }
                   2081:         }
                   2082:     }
                   2083:     return;
                   2084: }
1.22      www      2085: 
1.32      matthew  2086: function changed_text(choice,currentform) {
                   2087:     var choicearg = choice + 'arg';
                   2088:     if (currentform.elements[choicearg].value !='') {
1.80      albertel 2089:         $Javascript_toUpperCase
1.32      matthew  2090:         // clear old field
                   2091:         if ((current.argfield != choicearg) && (current.argfield != null)) {
                   2092:             currentform.elements[current.argfield].value = '';
                   2093:         }
                   2094:         current.argfield = choicearg;
                   2095:     }
                   2096:     set_auth_radio_buttons(choice,currentform);
                   2097:     return;
1.20      www      2098: }
1.32      matthew  2099: 
                   2100: function set_auth_radio_buttons(newvalue,currentform) {
                   2101:     var i=0;
                   2102:     while (i < currentform.login.length) {
                   2103:         if (currentform.login[i].value == newvalue) { break; }
                   2104:         i++;
                   2105:     }
                   2106:     if (i == currentform.login.length) {
                   2107:         return;
                   2108:     }
                   2109:     current.radiovalue = newvalue;
                   2110:     currentform.login[i].checked = true;
                   2111:     return;
                   2112: }
                   2113: END
                   2114:     return $result;
                   2115: }
                   2116: 
                   2117: sub authform_authorwarning{
                   2118:     my $result='';
1.144     matthew  2119:     $result='<i>'.
                   2120:         &mt('As a general rule, only authors or co-authors should be '.
                   2121:             'filesystem authenticated '.
                   2122:             '(which allows access to the server filesystem).')."</i>\n";
1.32      matthew  2123:     return $result;
                   2124: }
                   2125: 
                   2126: sub authform_nochange{  
                   2127:     my %in = (
                   2128:               formname => 'document.cu',
                   2129:               kerb_def_dom => 'MSU.EDU',
                   2130:               @_,
                   2131:           );
1.586     raeburn  2132:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'}); 
                   2133:     my $result;
                   2134:     if (keys(%can_assign) == 0) {
                   2135:         $result = &mt('Under you current role you are not permitted to change login settings for this user');  
                   2136:     } else {
                   2137:         $result = '<label>'.&mt('[_1] Do not change login data',
                   2138:                   '<input type="radio" name="login" value="nochange" '.
                   2139:                   'checked="checked" onclick="'.
1.281     albertel 2140:             "javascript:changed_radio('nochange',$in{'formname'});".'" />').
                   2141: 	    '</label>';
1.586     raeburn  2142:     }
1.32      matthew  2143:     return $result;
                   2144: }
                   2145: 
1.591     raeburn  2146: sub authform_kerberos {
1.32      matthew  2147:     my %in = (
                   2148:               formname => 'document.cu',
                   2149:               kerb_def_dom => 'MSU.EDU',
1.80      albertel 2150:               kerb_def_auth => 'krb4',
1.32      matthew  2151:               @_,
                   2152:               );
1.586     raeburn  2153:     my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
                   2154:         $autharg,$jscall);
                   2155:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.80      albertel 2156:     if ($in{'kerb_def_auth'} eq 'krb5') {
1.772     bisitz   2157:        $check5 = ' checked="checked"';
1.80      albertel 2158:     } else {
1.772     bisitz   2159:        $check4 = ' checked="checked"';
1.80      albertel 2160:     }
1.165     raeburn  2161:     $krbarg = $in{'kerb_def_dom'};
1.591     raeburn  2162:     if (defined($in{'curr_authtype'})) {
                   2163:         if ($in{'curr_authtype'} eq 'krb') {
1.772     bisitz   2164:             $krbcheck = ' checked="checked"';
1.623     raeburn  2165:             if (defined($in{'mode'})) {
                   2166:                 if ($in{'mode'} eq 'modifyuser') {
                   2167:                     $krbcheck = '';
                   2168:                 }
                   2169:             }
1.591     raeburn  2170:             if (defined($in{'curr_kerb_ver'})) {
                   2171:                 if ($in{'curr_krb_ver'} eq '5') {
1.772     bisitz   2172:                     $check5 = ' checked="checked"';
1.591     raeburn  2173:                     $check4 = '';
                   2174:                 } else {
1.772     bisitz   2175:                     $check4 = ' checked="checked"';
1.591     raeburn  2176:                     $check5 = '';
                   2177:                 }
1.586     raeburn  2178:             }
1.591     raeburn  2179:             if (defined($in{'curr_autharg'})) {
1.165     raeburn  2180:                 $krbarg = $in{'curr_autharg'};
                   2181:             }
1.586     raeburn  2182:             if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591     raeburn  2183:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2184:                     $result = 
                   2185:     &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
                   2186:         $in{'curr_autharg'},$krbver);
                   2187:                 } else {
                   2188:                     $result =
                   2189:     &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
                   2190:                 }
                   2191:                 return $result; 
                   2192:             }
                   2193:         }
                   2194:     } else {
                   2195:         if ($authnum == 1) {
1.784     bisitz   2196:             $authtype = '<input type="hidden" name="login" value="krb" />';
1.165     raeburn  2197:         }
                   2198:     }
1.586     raeburn  2199:     if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
                   2200:         return;
1.587     raeburn  2201:     } elsif ($authtype eq '') {
1.591     raeburn  2202:         if (defined($in{'mode'})) {
1.587     raeburn  2203:             if ($in{'mode'} eq 'modifycourse') {
                   2204:                 if ($authnum == 1) {
1.784     bisitz   2205:                     $authtype = '<input type="hidden" name="login" value="krb" />';
1.587     raeburn  2206:                 }
                   2207:             }
                   2208:         }
1.586     raeburn  2209:     }
                   2210:     $jscall = "javascript:changed_radio('krb',$in{'formname'});";
                   2211:     if ($authtype eq '') {
                   2212:         $authtype = '<input type="radio" name="login" value="krb" '.
                   2213:                     'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
                   2214:                     $krbcheck.' />';
                   2215:     }
                   2216:     if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
                   2217:         ($can_assign{'krb4'} && !$can_assign{'krb5'} && 
                   2218:          $in{'curr_authtype'} eq 'krb5') ||
                   2219:         (!$can_assign{'krb4'} && $can_assign{'krb5'} && 
                   2220:          $in{'curr_authtype'} eq 'krb4')) {
                   2221:         $result .= &mt
1.144     matthew  2222:         ('[_1] Kerberos authenticated with domain [_2] '.
1.281     albertel 2223:          '[_3] Version 4 [_4] Version 5 [_5]',
1.586     raeburn  2224:          '<label>'.$authtype,
1.281     albertel 2225:          '</label><input type="text" size="10" name="krbarg" '.
1.165     raeburn  2226:              'value="'.$krbarg.'" '.
1.144     matthew  2227:              'onchange="'.$jscall.'" />',
1.281     albertel 2228:          '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
                   2229:          '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
                   2230: 	 '</label>');
1.586     raeburn  2231:     } elsif ($can_assign{'krb4'}) {
                   2232:         $result .= &mt
                   2233:         ('[_1] Kerberos authenticated with domain [_2] '.
                   2234:          '[_3] Version 4 [_4]',
                   2235:          '<label>'.$authtype,
                   2236:          '</label><input type="text" size="10" name="krbarg" '.
                   2237:              'value="'.$krbarg.'" '.
                   2238:              'onchange="'.$jscall.'" />',
                   2239:          '<label><input type="hidden" name="krbver" value="4" />',
                   2240:          '</label>');
                   2241:     } elsif ($can_assign{'krb5'}) {
                   2242:         $result .= &mt
                   2243:         ('[_1] Kerberos authenticated with domain [_2] '.
                   2244:          '[_3] Version 5 [_4]',
                   2245:          '<label>'.$authtype,
                   2246:          '</label><input type="text" size="10" name="krbarg" '.
                   2247:              'value="'.$krbarg.'" '.
                   2248:              'onchange="'.$jscall.'" />',
                   2249:          '<label><input type="hidden" name="krbver" value="5" />',
                   2250:          '</label>');
                   2251:     }
1.32      matthew  2252:     return $result;
                   2253: }
                   2254: 
                   2255: sub authform_internal{  
1.586     raeburn  2256:     my %in = (
1.32      matthew  2257:                 formname => 'document.cu',
                   2258:                 kerb_def_dom => 'MSU.EDU',
                   2259:                 @_,
                   2260:                 );
1.586     raeburn  2261:     my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
                   2262:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2263:     if (defined($in{'curr_authtype'})) {
                   2264:         if ($in{'curr_authtype'} eq 'int') {
1.586     raeburn  2265:             if ($can_assign{'int'}) {
1.772     bisitz   2266:                 $intcheck = 'checked="checked" ';
1.623     raeburn  2267:                 if (defined($in{'mode'})) {
                   2268:                     if ($in{'mode'} eq 'modifyuser') {
                   2269:                         $intcheck = '';
                   2270:                     }
                   2271:                 }
1.591     raeburn  2272:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2273:                     $intarg = $in{'curr_autharg'};
                   2274:                 }
                   2275:             } else {
                   2276:                 $result = &mt('Currently internally authenticated.');
                   2277:                 return $result;
1.165     raeburn  2278:             }
                   2279:         }
1.586     raeburn  2280:     } else {
                   2281:         if ($authnum == 1) {
1.784     bisitz   2282:             $authtype = '<input type="hidden" name="login" value="int" />';
1.586     raeburn  2283:         }
                   2284:     }
                   2285:     if (!$can_assign{'int'}) {
                   2286:         return;
1.587     raeburn  2287:     } elsif ($authtype eq '') {
1.591     raeburn  2288:         if (defined($in{'mode'})) {
1.587     raeburn  2289:             if ($in{'mode'} eq 'modifycourse') {
                   2290:                 if ($authnum == 1) {
1.784     bisitz   2291:                     $authtype = '<input type="hidden" name="login" value="int" />';
1.587     raeburn  2292:                 }
                   2293:             }
                   2294:         }
1.165     raeburn  2295:     }
1.586     raeburn  2296:     $jscall = "javascript:changed_radio('int',$in{'formname'});";
                   2297:     if ($authtype eq '') {
                   2298:         $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
                   2299:                     ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
                   2300:     }
1.605     bisitz   2301:     $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586     raeburn  2302:                $intarg.'" onchange="'.$jscall.'" />';
                   2303:     $result = &mt
1.144     matthew  2304:         ('[_1] Internally authenticated (with initial password [_2])',
1.586     raeburn  2305:          '<label>'.$authtype,'</label>'.$autharg);
1.620     www      2306:     $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  2307:     return $result;
                   2308: }
                   2309: 
                   2310: sub authform_local{  
                   2311:     my %in = (
                   2312:               formname => 'document.cu',
                   2313:               kerb_def_dom => 'MSU.EDU',
                   2314:               @_,
                   2315:               );
1.586     raeburn  2316:     my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
                   2317:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2318:     if (defined($in{'curr_authtype'})) {
                   2319:         if ($in{'curr_authtype'} eq 'loc') {
1.586     raeburn  2320:             if ($can_assign{'loc'}) {
1.772     bisitz   2321:                 $loccheck = 'checked="checked" ';
1.623     raeburn  2322:                 if (defined($in{'mode'})) {
                   2323:                     if ($in{'mode'} eq 'modifyuser') {
                   2324:                         $loccheck = '';
                   2325:                     }
                   2326:                 }
1.591     raeburn  2327:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2328:                     $locarg = $in{'curr_autharg'};
                   2329:                 }
                   2330:             } else {
                   2331:                 $result = &mt('Currently using local (institutional) authentication.');
                   2332:                 return $result;
1.165     raeburn  2333:             }
                   2334:         }
1.586     raeburn  2335:     } else {
                   2336:         if ($authnum == 1) {
1.784     bisitz   2337:             $authtype = '<input type="hidden" name="login" value="loc" />';
1.586     raeburn  2338:         }
                   2339:     }
                   2340:     if (!$can_assign{'loc'}) {
                   2341:         return;
1.587     raeburn  2342:     } elsif ($authtype eq '') {
1.591     raeburn  2343:         if (defined($in{'mode'})) {
1.587     raeburn  2344:             if ($in{'mode'} eq 'modifycourse') {
                   2345:                 if ($authnum == 1) {
1.784     bisitz   2346:                     $authtype = '<input type="hidden" name="login" value="loc" />';
1.587     raeburn  2347:                 }
                   2348:             }
                   2349:         }
1.165     raeburn  2350:     }
1.586     raeburn  2351:     $jscall = "javascript:changed_radio('loc',$in{'formname'});";
                   2352:     if ($authtype eq '') {
                   2353:         $authtype = '<input type="radio" name="login" value="loc" '.
                   2354:                     $loccheck.' onchange="'.$jscall.'" onclick="'.
                   2355:                     $jscall.'" />';
                   2356:     }
                   2357:     $autharg = '<input type="text" size="10" name="locarg" value="'.
                   2358:                $locarg.'" onchange="'.$jscall.'" />';
                   2359:     $result = &mt('[_1] Local Authentication with argument [_2]',
                   2360:                   '<label>'.$authtype,'</label>'.$autharg);
1.32      matthew  2361:     return $result;
                   2362: }
                   2363: 
                   2364: sub authform_filesystem{  
                   2365:     my %in = (
                   2366:               formname => 'document.cu',
                   2367:               kerb_def_dom => 'MSU.EDU',
                   2368:               @_,
                   2369:               );
1.586     raeburn  2370:     my ($fsyscheck,$result,$authtype,$autharg,$jscall);
                   2371:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2372:     if (defined($in{'curr_authtype'})) {
                   2373:         if ($in{'curr_authtype'} eq 'fsys') {
1.586     raeburn  2374:             if ($can_assign{'fsys'}) {
1.772     bisitz   2375:                 $fsyscheck = 'checked="checked" ';
1.623     raeburn  2376:                 if (defined($in{'mode'})) {
                   2377:                     if ($in{'mode'} eq 'modifyuser') {
                   2378:                         $fsyscheck = '';
                   2379:                     }
                   2380:                 }
1.586     raeburn  2381:             } else {
                   2382:                 $result = &mt('Currently Filesystem Authenticated.');
                   2383:                 return $result;
                   2384:             }           
                   2385:         }
                   2386:     } else {
                   2387:         if ($authnum == 1) {
1.784     bisitz   2388:             $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586     raeburn  2389:         }
                   2390:     }
                   2391:     if (!$can_assign{'fsys'}) {
                   2392:         return;
1.587     raeburn  2393:     } elsif ($authtype eq '') {
1.591     raeburn  2394:         if (defined($in{'mode'})) {
1.587     raeburn  2395:             if ($in{'mode'} eq 'modifycourse') {
                   2396:                 if ($authnum == 1) {
1.784     bisitz   2397:                     $authtype = '<input type="hidden" name="login" value="fsys" />';
1.587     raeburn  2398:                 }
                   2399:             }
                   2400:         }
1.586     raeburn  2401:     }
                   2402:     $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
                   2403:     if ($authtype eq '') {
                   2404:         $authtype = '<input type="radio" name="login" value="fsys" '.
                   2405:                     $fsyscheck.' onchange="'.$jscall.'" onclick="'.
                   2406:                     $jscall.'" />';
                   2407:     }
                   2408:     $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
                   2409:                ' onchange="'.$jscall.'" />';
                   2410:     $result = &mt
1.144     matthew  2411:         ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281     albertel 2412:          '<label><input type="radio" name="login" value="fsys" '.
1.586     raeburn  2413:          $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605     bisitz   2414:          '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144     matthew  2415:                   'onchange="'.$jscall.'" />');
1.32      matthew  2416:     return $result;
                   2417: }
                   2418: 
1.586     raeburn  2419: sub get_assignable_auth {
                   2420:     my ($dom) = @_;
                   2421:     if ($dom eq '') {
                   2422:         $dom = $env{'request.role.domain'};
                   2423:     }
                   2424:     my %can_assign = (
                   2425:                           krb4 => 1,
                   2426:                           krb5 => 1,
                   2427:                           int  => 1,
                   2428:                           loc  => 1,
                   2429:                      );
                   2430:     my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
                   2431:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   2432:         if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
                   2433:             my $authhash = $domconfig{'usercreation'}{'authtypes'};
                   2434:             my $context;
                   2435:             if ($env{'request.role'} =~ /^au/) {
                   2436:                 $context = 'author';
                   2437:             } elsif ($env{'request.role'} =~ /^dc/) {
                   2438:                 $context = 'domain';
                   2439:             } elsif ($env{'request.course.id'}) {
                   2440:                 $context = 'course';
                   2441:             }
                   2442:             if ($context) {
                   2443:                 if (ref($authhash->{$context}) eq 'HASH') {
                   2444:                    %can_assign = %{$authhash->{$context}}; 
                   2445:                 }
                   2446:             }
                   2447:         }
                   2448:     }
                   2449:     my $authnum = 0;
                   2450:     foreach my $key (keys(%can_assign)) {
                   2451:         if ($can_assign{$key}) {
                   2452:             $authnum ++;
                   2453:         }
                   2454:     }
                   2455:     if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
                   2456:         $authnum --;
                   2457:     }
                   2458:     return ($authnum,%can_assign);
                   2459: }
                   2460: 
1.80      albertel 2461: ###############################################################
                   2462: ##    Get Kerberos Defaults for Domain                 ##
                   2463: ###############################################################
                   2464: ##
                   2465: ## Returns default kerberos version and an associated argument
                   2466: ## as listed in file domain.tab. If not listed, provides
                   2467: ## appropriate default domain and kerberos version.
                   2468: ##
                   2469: #-------------------------------------------
                   2470: 
                   2471: =pod
                   2472: 
1.648     raeburn  2473: =item * &get_kerberos_defaults()
1.80      albertel 2474: 
                   2475: get_kerberos_defaults($target_domain) returns the default kerberos
1.641     raeburn  2476: version and domain. If not found, it defaults to version 4 and the 
                   2477: domain of the server.
1.80      albertel 2478: 
1.648     raeburn  2479: =over 4
                   2480: 
1.80      albertel 2481: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
                   2482: 
1.648     raeburn  2483: =back
                   2484: 
                   2485: =back
                   2486: 
1.80      albertel 2487: =cut
                   2488: 
                   2489: #-------------------------------------------
                   2490: sub get_kerberos_defaults {
                   2491:     my $domain=shift;
1.641     raeburn  2492:     my ($krbdef,$krbdefdom);
                   2493:     my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
                   2494:     if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
                   2495:         $krbdef = $domdefaults{'auth_def'};
                   2496:         $krbdefdom = $domdefaults{'auth_arg_def'};
                   2497:     } else {
1.80      albertel 2498:         $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
                   2499:         my $krbdefdom=$1;
                   2500:         $krbdefdom=~tr/a-z/A-Z/;
                   2501:         $krbdef = "krb4";
                   2502:     }
                   2503:     return ($krbdef,$krbdefdom);
                   2504: }
1.112     bowersj2 2505: 
1.32      matthew  2506: 
1.46      matthew  2507: ###############################################################
                   2508: ##                Thesaurus Functions                        ##
                   2509: ###############################################################
1.20      www      2510: 
1.46      matthew  2511: =pod
1.20      www      2512: 
1.112     bowersj2 2513: =head1 Thesaurus Functions
                   2514: 
                   2515: =over 4
                   2516: 
1.648     raeburn  2517: =item * &initialize_keywords()
1.46      matthew  2518: 
                   2519: Initializes the package variable %Keywords if it is empty.  Uses the
                   2520: package variable $thesaurus_db_file.
                   2521: 
                   2522: =cut
                   2523: 
                   2524: ###################################################
                   2525: 
                   2526: sub initialize_keywords {
                   2527:     return 1 if (scalar keys(%Keywords));
                   2528:     # If we are here, %Keywords is empty, so fill it up
                   2529:     #   Make sure the file we need exists...
                   2530:     if (! -e $thesaurus_db_file) {
                   2531:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
                   2532:                                  " failed because it does not exist");
                   2533:         return 0;
                   2534:     }
                   2535:     #   Set up the hash as a database
                   2536:     my %thesaurus_db;
                   2537:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 2538:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  2539:         &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
                   2540:                                  $thesaurus_db_file);
                   2541:         return 0;
                   2542:     } 
                   2543:     #  Get the average number of appearances of a word.
                   2544:     my $avecount = $thesaurus_db{'average.count'};
                   2545:     #  Put keywords (those that appear > average) into %Keywords
                   2546:     while (my ($word,$data)=each (%thesaurus_db)) {
                   2547:         my ($count,undef) = split /:/,$data;
                   2548:         $Keywords{$word}++ if ($count > $avecount);
                   2549:     }
                   2550:     untie %thesaurus_db;
                   2551:     # Remove special values from %Keywords.
1.356     albertel 2552:     foreach my $value ('total.count','average.count') {
                   2553:         delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586     raeburn  2554:   }
1.46      matthew  2555:     return 1;
                   2556: }
                   2557: 
                   2558: ###################################################
                   2559: 
                   2560: =pod
                   2561: 
1.648     raeburn  2562: =item * &keyword($word)
1.46      matthew  2563: 
                   2564: Returns true if $word is a keyword.  A keyword is a word that appears more 
                   2565: than the average number of times in the thesaurus database.  Calls 
                   2566: &initialize_keywords
                   2567: 
                   2568: =cut
                   2569: 
                   2570: ###################################################
1.20      www      2571: 
                   2572: sub keyword {
1.46      matthew  2573:     return if (!&initialize_keywords());
                   2574:     my $word=lc(shift());
                   2575:     $word=~s/\W//g;
                   2576:     return exists($Keywords{$word});
1.20      www      2577: }
1.46      matthew  2578: 
                   2579: ###############################################################
                   2580: 
                   2581: =pod 
1.20      www      2582: 
1.648     raeburn  2583: =item * &get_related_words()
1.46      matthew  2584: 
1.160     matthew  2585: Look up a word in the thesaurus.  Takes a scalar argument and returns
1.46      matthew  2586: an array of words.  If the keyword is not in the thesaurus, an empty array
                   2587: will be returned.  The order of the words returned is determined by the
                   2588: database which holds them.
                   2589: 
                   2590: Uses global $thesaurus_db_file.
                   2591: 
                   2592: =cut
                   2593: 
                   2594: ###############################################################
                   2595: sub get_related_words {
                   2596:     my $keyword = shift;
                   2597:     my %thesaurus_db;
                   2598:     if (! -e $thesaurus_db_file) {
                   2599:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
                   2600:                                  "failed because the file does not exist");
                   2601:         return ();
                   2602:     }
                   2603:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 2604:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  2605:         return ();
                   2606:     } 
                   2607:     my @Words=();
1.429     www      2608:     my $count=0;
1.46      matthew  2609:     if (exists($thesaurus_db{$keyword})) {
1.356     albertel 2610: 	# The first element is the number of times
                   2611: 	# the word appears.  We do not need it now.
1.429     www      2612: 	my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
                   2613: 	my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
                   2614: 	my $threshold=$mostfrequentcount/10;
                   2615:         foreach my $possibleword (@RelatedWords) {
                   2616:             my ($word,$wordcount)=split(/\,/,$possibleword);
                   2617:             if ($wordcount>$threshold) {
                   2618: 		push(@Words,$word);
                   2619:                 $count++;
                   2620:                 if ($count>10) { last; }
                   2621: 	    }
1.20      www      2622:         }
                   2623:     }
1.46      matthew  2624:     untie %thesaurus_db;
                   2625:     return @Words;
1.14      harris41 2626: }
1.46      matthew  2627: 
1.112     bowersj2 2628: =pod
                   2629: 
                   2630: =back
                   2631: 
                   2632: =cut
1.61      www      2633: 
                   2634: # -------------------------------------------------------------- Plaintext name
1.81      albertel 2635: =pod
                   2636: 
1.112     bowersj2 2637: =head1 User Name Functions
                   2638: 
                   2639: =over 4
                   2640: 
1.648     raeburn  2641: =item * &plainname($uname,$udom,$first)
1.81      albertel 2642: 
1.112     bowersj2 2643: Takes a users logon name and returns it as a string in
1.226     albertel 2644: "first middle last generation" form 
                   2645: if $first is set to 'lastname' then it returns it as
                   2646: 'lastname generation, firstname middlename' if their is a lastname
1.81      albertel 2647: 
                   2648: =cut
1.61      www      2649: 
1.295     www      2650: 
1.81      albertel 2651: ###############################################################
1.61      www      2652: sub plainname {
1.226     albertel 2653:     my ($uname,$udom,$first)=@_;
1.537     albertel 2654:     return if (!defined($uname) || !defined($udom));
1.295     www      2655:     my %names=&getnames($uname,$udom);
1.226     albertel 2656:     my $name=&Apache::lonnet::format_name($names{'firstname'},
                   2657: 					  $names{'middlename'},
                   2658: 					  $names{'lastname'},
                   2659: 					  $names{'generation'},$first);
                   2660:     $name=~s/^\s+//;
1.62      www      2661:     $name=~s/\s+$//;
                   2662:     $name=~s/\s+/ /g;
1.353     albertel 2663:     if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62      www      2664:     return $name;
1.61      www      2665: }
1.66      www      2666: 
                   2667: # -------------------------------------------------------------------- Nickname
1.81      albertel 2668: =pod
                   2669: 
1.648     raeburn  2670: =item * &nickname($uname,$udom)
1.81      albertel 2671: 
                   2672: Gets a users name and returns it as a string as
                   2673: 
                   2674: "&quot;nickname&quot;"
1.66      www      2675: 
1.81      albertel 2676: if the user has a nickname or
                   2677: 
                   2678: "first middle last generation"
                   2679: 
                   2680: if the user does not
                   2681: 
                   2682: =cut
1.66      www      2683: 
                   2684: sub nickname {
                   2685:     my ($uname,$udom)=@_;
1.537     albertel 2686:     return if (!defined($uname) || !defined($udom));
1.295     www      2687:     my %names=&getnames($uname,$udom);
1.68      albertel 2688:     my $name=$names{'nickname'};
1.66      www      2689:     if ($name) {
                   2690:        $name='&quot;'.$name.'&quot;'; 
                   2691:     } else {
                   2692:        $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
                   2693: 	     $names{'lastname'}.' '.$names{'generation'};
                   2694:        $name=~s/\s+$//;
                   2695:        $name=~s/\s+/ /g;
                   2696:     }
                   2697:     return $name;
                   2698: }
                   2699: 
1.295     www      2700: sub getnames {
                   2701:     my ($uname,$udom)=@_;
1.537     albertel 2702:     return if (!defined($uname) || !defined($udom));
1.433     albertel 2703:     if ($udom eq 'public' && $uname eq 'public') {
                   2704: 	return ('lastname' => &mt('Public'));
                   2705:     }
1.295     www      2706:     my $id=$uname.':'.$udom;
                   2707:     my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
                   2708:     if ($cached) {
                   2709: 	return %{$names};
                   2710:     } else {
                   2711: 	my %loadnames=&Apache::lonnet::get('environment',
                   2712:                     ['firstname','middlename','lastname','generation','nickname'],
                   2713: 					 $udom,$uname);
                   2714: 	&Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
                   2715: 	return %loadnames;
                   2716:     }
                   2717: }
1.61      www      2718: 
1.542     raeburn  2719: # -------------------------------------------------------------------- getemails
1.648     raeburn  2720: 
1.542     raeburn  2721: =pod
                   2722: 
1.648     raeburn  2723: =item * &getemails($uname,$udom)
1.542     raeburn  2724: 
                   2725: Gets a user's email information and returns it as a hash with keys:
                   2726: notification, critnotification, permanentemail
                   2727: 
                   2728: For notification and critnotification, values are comma-separated lists 
1.648     raeburn  2729: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542     raeburn  2730:  
1.648     raeburn  2731: 
1.542     raeburn  2732: =cut
                   2733: 
1.648     raeburn  2734: 
1.466     albertel 2735: sub getemails {
                   2736:     my ($uname,$udom)=@_;
                   2737:     if ($udom eq 'public' && $uname eq 'public') {
                   2738: 	return;
                   2739:     }
1.467     www      2740:     if (!$udom) { $udom=$env{'user.domain'}; }
                   2741:     if (!$uname) { $uname=$env{'user.name'}; }
1.466     albertel 2742:     my $id=$uname.':'.$udom;
                   2743:     my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
                   2744:     if ($cached) {
                   2745: 	return %{$names};
                   2746:     } else {
                   2747: 	my %loadnames=&Apache::lonnet::get('environment',
                   2748:                     			   ['notification','critnotification',
                   2749: 					    'permanentemail'],
                   2750: 					   $udom,$uname);
                   2751: 	&Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
                   2752: 	return %loadnames;
                   2753:     }
                   2754: }
                   2755: 
1.551     albertel 2756: sub flush_email_cache {
                   2757:     my ($uname,$udom)=@_;
                   2758:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2759:     if (!$uname) { $uname=$env{'user.name'};   }
                   2760:     return if ($udom eq 'public' && $uname eq 'public');
                   2761:     my $id=$uname.':'.$udom;
                   2762:     &Apache::lonnet::devalidate_cache_new('emailscache',$id);
                   2763: }
                   2764: 
1.728     raeburn  2765: # -------------------------------------------------------------------- getlangs
                   2766: 
                   2767: =pod
                   2768: 
                   2769: =item * &getlangs($uname,$udom)
                   2770: 
                   2771: Gets a user's language preference and returns it as a hash with key:
                   2772: language.
                   2773: 
                   2774: =cut
                   2775: 
                   2776: 
                   2777: sub getlangs {
                   2778:     my ($uname,$udom) = @_;
                   2779:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2780:     if (!$uname) { $uname=$env{'user.name'};   }
                   2781:     my $id=$uname.':'.$udom;
                   2782:     my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
                   2783:     if ($cached) {
                   2784:         return %{$langs};
                   2785:     } else {
                   2786:         my %loadlangs=&Apache::lonnet::get('environment',['languages'],
                   2787:                                            $udom,$uname);
                   2788:         &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
                   2789:         return %loadlangs;
                   2790:     }
                   2791: }
                   2792: 
                   2793: sub flush_langs_cache {
                   2794:     my ($uname,$udom)=@_;
                   2795:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2796:     if (!$uname) { $uname=$env{'user.name'};   }
                   2797:     return if ($udom eq 'public' && $uname eq 'public');
                   2798:     my $id=$uname.':'.$udom;
                   2799:     &Apache::lonnet::devalidate_cache_new('userlangs',$id);
                   2800: }
                   2801: 
1.61      www      2802: # ------------------------------------------------------------------ Screenname
1.81      albertel 2803: 
                   2804: =pod
                   2805: 
1.648     raeburn  2806: =item * &screenname($uname,$udom)
1.81      albertel 2807: 
                   2808: Gets a users screenname and returns it as a string
                   2809: 
                   2810: =cut
1.61      www      2811: 
                   2812: sub screenname {
                   2813:     my ($uname,$udom)=@_;
1.258     albertel 2814:     if ($uname eq $env{'user.name'} &&
                   2815: 	$udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212     albertel 2816:     my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68      albertel 2817:     return $names{'screenname'};
1.62      www      2818: }
                   2819: 
1.212     albertel 2820: 
1.62      www      2821: # ------------------------------------------------------------- Message Wrapper
                   2822: 
                   2823: sub messagewrapper {
1.369     www      2824:     my ($link,$username,$domain,$subject,$text)=@_;
1.62      www      2825:     return 
1.441     albertel 2826:         '<a href="/adm/email?compose=individual&amp;'.
                   2827:         'recname='.$username.'&amp;recdom='.$domain.
                   2828: 	'&amp;subject='.&escape($subject).'&amp;text='.&escape($text).'" '.
1.200     matthew  2829:         'title="'.&mt('Send message').'">'.$link.'</a>';
1.74      www      2830: }
                   2831: # --------------------------------------------------------------- Notes Wrapper
                   2832: 
                   2833: sub noteswrapper {
                   2834:     my ($link,$un,$do)=@_;
                   2835:     return 
                   2836: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62      www      2837: }
                   2838: # ------------------------------------------------------------- Aboutme Wrapper
                   2839: 
                   2840: sub aboutmewrapper {
1.166     www      2841:     my ($link,$username,$domain,$target)=@_;
1.447     raeburn  2842:     if (!defined($username)  && !defined($domain)) {
                   2843:         return;
                   2844:     }
1.205     www      2845:     return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.756     weissno  2846: 	($target?' target="$target"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62      www      2847: }
                   2848: 
                   2849: # ------------------------------------------------------------ Syllabus Wrapper
                   2850: 
                   2851: 
                   2852: sub syllabuswrapper {
1.707     bisitz   2853:     my ($linktext,$coursedir,$domain)=@_;
1.208     matthew  2854:     return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61      www      2855: }
1.14      harris41 2856: 
1.208     matthew  2857: sub track_student_link {
1.268     albertel 2858:     my ($linktext,$sname,$sdom,$target,$start) = @_;
                   2859:     my $link ="/adm/trackstudent?";
1.208     matthew  2860:     my $title = 'View recent activity';
                   2861:     if (defined($sname) && $sname !~ /^\s*$/ &&
                   2862:         defined($sdom)  && $sdom  !~ /^\s*$/) {
1.268     albertel 2863:         $link .= "selected_student=$sname:$sdom";
1.208     matthew  2864:         $title .= ' of this student';
1.268     albertel 2865:     } 
1.208     matthew  2866:     if (defined($target) && $target !~ /^\s*$/) {
                   2867:         $target = qq{target="$target"};
                   2868:     } else {
                   2869:         $target = '';
                   2870:     }
1.268     albertel 2871:     if ($start) { $link.='&amp;start='.$start; }
1.554     albertel 2872:     $title = &mt($title);
                   2873:     $linktext = &mt($linktext);
1.448     albertel 2874:     return qq{<a href="$link" title="$title" $target>$linktext</a>}.
                   2875: 	&help_open_topic('View_recent_activity');
1.208     matthew  2876: }
                   2877: 
1.781     raeburn  2878: sub slot_reservations_link {
                   2879:     my ($linktext,$sname,$sdom,$target) = @_;
                   2880:     my $link ="/adm/slotrequest?command=showresv&amp;origin=aboutme";
                   2881:     my $title = 'View slot reservation history';
                   2882:     if (defined($sname) && $sname !~ /^\s*$/ &&
                   2883:         defined($sdom)  && $sdom  !~ /^\s*$/) {
                   2884:         $link .= "&amp;uname=$sname&amp;udom=$sdom";
                   2885:         $title .= ' of this student';
                   2886:     }
                   2887:     if (defined($target) && $target !~ /^\s*$/) {
                   2888:         $target = qq{target="$target"};
                   2889:     } else {
                   2890:         $target = '';
                   2891:     }
                   2892:     $title = &mt($title);
                   2893:     $linktext = &mt($linktext);
                   2894:     return qq{<a href="$link" title="$title" $target>$linktext</a>};
                   2895: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
                   2896: 
                   2897: }
                   2898: 
1.508     www      2899: # ===================================================== Display a student photo
                   2900: 
                   2901: 
1.509     albertel 2902: sub student_image_tag {
1.508     www      2903:     my ($domain,$user)=@_;
                   2904:     my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
                   2905:     if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
                   2906: 	return '<img src="'.$imgsrc.'" align="right" />';
                   2907:     } else {
                   2908: 	return '';
                   2909:     }
                   2910: }
                   2911: 
1.112     bowersj2 2912: =pod
                   2913: 
                   2914: =back
                   2915: 
                   2916: =head1 Access .tab File Data
                   2917: 
                   2918: =over 4
                   2919: 
1.648     raeburn  2920: =item * &languageids() 
1.112     bowersj2 2921: 
                   2922: returns list of all language ids
                   2923: 
                   2924: =cut
                   2925: 
1.14      harris41 2926: sub languageids {
1.16      harris41 2927:     return sort(keys(%language));
1.14      harris41 2928: }
                   2929: 
1.112     bowersj2 2930: =pod
                   2931: 
1.648     raeburn  2932: =item * &languagedescription() 
1.112     bowersj2 2933: 
                   2934: returns description of a specified language id
                   2935: 
                   2936: =cut
                   2937: 
1.14      harris41 2938: sub languagedescription {
1.125     www      2939:     my $code=shift;
                   2940:     return  ($supported_language{$code}?'* ':'').
                   2941:             $language{$code}.
1.126     www      2942: 	    ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145     www      2943: }
                   2944: 
                   2945: sub plainlanguagedescription {
                   2946:     my $code=shift;
                   2947:     return $language{$code};
                   2948: }
                   2949: 
                   2950: sub supportedlanguagecode {
                   2951:     my $code=shift;
                   2952:     return $supported_language{$code};
1.97      www      2953: }
                   2954: 
1.112     bowersj2 2955: =pod
                   2956: 
1.648     raeburn  2957: =item * &copyrightids() 
1.112     bowersj2 2958: 
                   2959: returns list of all copyrights
                   2960: 
                   2961: =cut
                   2962: 
                   2963: sub copyrightids {
                   2964:     return sort(keys(%cprtag));
                   2965: }
                   2966: 
                   2967: =pod
                   2968: 
1.648     raeburn  2969: =item * &copyrightdescription() 
1.112     bowersj2 2970: 
                   2971: returns description of a specified copyright id
                   2972: 
                   2973: =cut
                   2974: 
                   2975: sub copyrightdescription {
1.166     www      2976:     return &mt($cprtag{shift(@_)});
1.112     bowersj2 2977: }
1.197     matthew  2978: 
                   2979: =pod
                   2980: 
1.648     raeburn  2981: =item * &source_copyrightids() 
1.192     taceyjo1 2982: 
                   2983: returns list of all source copyrights
                   2984: 
                   2985: =cut
                   2986: 
                   2987: sub source_copyrightids {
                   2988:     return sort(keys(%scprtag));
                   2989: }
                   2990: 
                   2991: =pod
                   2992: 
1.648     raeburn  2993: =item * &source_copyrightdescription() 
1.192     taceyjo1 2994: 
                   2995: returns description of a specified source copyright id
                   2996: 
                   2997: =cut
                   2998: 
                   2999: sub source_copyrightdescription {
                   3000:     return &mt($scprtag{shift(@_)});
                   3001: }
1.112     bowersj2 3002: 
                   3003: =pod
                   3004: 
1.648     raeburn  3005: =item * &filecategories() 
1.112     bowersj2 3006: 
                   3007: returns list of all file categories
                   3008: 
                   3009: =cut
                   3010: 
                   3011: sub filecategories {
                   3012:     return sort(keys(%category_extensions));
                   3013: }
                   3014: 
                   3015: =pod
                   3016: 
1.648     raeburn  3017: =item * &filecategorytypes() 
1.112     bowersj2 3018: 
                   3019: returns list of file types belonging to a given file
                   3020: category
                   3021: 
                   3022: =cut
                   3023: 
                   3024: sub filecategorytypes {
1.356     albertel 3025:     my ($cat) = @_;
                   3026:     return @{$category_extensions{lc($cat)}};
1.112     bowersj2 3027: }
                   3028: 
                   3029: =pod
                   3030: 
1.648     raeburn  3031: =item * &fileembstyle() 
1.112     bowersj2 3032: 
                   3033: returns embedding style for a specified file type
                   3034: 
                   3035: =cut
                   3036: 
                   3037: sub fileembstyle {
                   3038:     return $fe{lc(shift(@_))};
1.169     www      3039: }
                   3040: 
1.351     www      3041: sub filemimetype {
                   3042:     return $fm{lc(shift(@_))};
                   3043: }
                   3044: 
1.169     www      3045: 
                   3046: sub filecategoryselect {
                   3047:     my ($name,$value)=@_;
1.189     matthew  3048:     return &select_form($value,$name,
1.169     www      3049: 			'' => &mt('Any category'),
                   3050: 			map { $_,$_ } sort(keys(%category_extensions)));
1.112     bowersj2 3051: }
                   3052: 
                   3053: =pod
                   3054: 
1.648     raeburn  3055: =item * &filedescription() 
1.112     bowersj2 3056: 
                   3057: returns description for a specified file type
                   3058: 
                   3059: =cut
                   3060: 
                   3061: sub filedescription {
1.188     matthew  3062:     my $file_description = $fd{lc(shift())};
                   3063:     $file_description =~ s:([\[\]]):~$1:g;
                   3064:     return &mt($file_description);
1.112     bowersj2 3065: }
                   3066: 
                   3067: =pod
                   3068: 
1.648     raeburn  3069: =item * &filedescriptionex() 
1.112     bowersj2 3070: 
                   3071: returns description for a specified file type with
                   3072: extra formatting
                   3073: 
                   3074: =cut
                   3075: 
                   3076: sub filedescriptionex {
                   3077:     my $ex=shift;
1.188     matthew  3078:     my $file_description = $fd{lc($ex)};
                   3079:     $file_description =~ s:([\[\]]):~$1:g;
                   3080:     return '.'.$ex.' '.&mt($file_description);
1.112     bowersj2 3081: }
                   3082: 
                   3083: # End of .tab access
                   3084: =pod
                   3085: 
                   3086: =back
                   3087: 
                   3088: =cut
                   3089: 
                   3090: # ------------------------------------------------------------------ File Types
                   3091: sub fileextensions {
                   3092:     return sort(keys(%fe));
                   3093: }
                   3094: 
1.97      www      3095: # ----------------------------------------------------------- Display Languages
                   3096: # returns a hash with all desired display languages
                   3097: #
                   3098: 
                   3099: sub display_languages {
                   3100:     my %languages=();
1.695     raeburn  3101:     foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356     albertel 3102: 	$languages{$lang}=1;
1.97      www      3103:     }
                   3104:     &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258     albertel 3105:     if ($env{'form.displaylanguage'}) {
1.356     albertel 3106: 	foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
                   3107: 	    $languages{$lang}=1;
1.97      www      3108:         }
                   3109:     }
                   3110:     return %languages;
1.14      harris41 3111: }
                   3112: 
1.582     albertel 3113: sub languages {
                   3114:     my ($possible_langs) = @_;
1.695     raeburn  3115:     my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582     albertel 3116:     if (!ref($possible_langs)) {
                   3117: 	if( wantarray ) {
                   3118: 	    return @preferred_langs;
                   3119: 	} else {
                   3120: 	    return $preferred_langs[0];
                   3121: 	}
                   3122:     }
                   3123:     my %possibilities = map { $_ => 1 } (@$possible_langs);
                   3124:     my @preferred_possibilities;
                   3125:     foreach my $preferred_lang (@preferred_langs) {
                   3126: 	if (exists($possibilities{$preferred_lang})) {
                   3127: 	    push(@preferred_possibilities, $preferred_lang);
                   3128: 	}
                   3129:     }
                   3130:     if( wantarray ) {
                   3131: 	return @preferred_possibilities;
                   3132:     }
                   3133:     return $preferred_possibilities[0];
                   3134: }
                   3135: 
1.742     raeburn  3136: sub user_lang {
                   3137:     my ($touname,$toudom,$fromcid) = @_;
                   3138:     my @userlangs;
                   3139:     if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
                   3140:         @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
                   3141:                     $env{'course.'.$fromcid.'.languages'}));
                   3142:     } else {
                   3143:         my %langhash = &getlangs($touname,$toudom);
                   3144:         if ($langhash{'languages'} ne '') {
                   3145:             @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
                   3146:         } else {
                   3147:             my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
                   3148:             if ($domdefs{'lang_def'} ne '') {
                   3149:                 @userlangs = ($domdefs{'lang_def'});
                   3150:             }
                   3151:         }
                   3152:     }
                   3153:     my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
                   3154:     my $user_lh = Apache::localize->get_handle(@languages);
                   3155:     return $user_lh;
                   3156: }
                   3157: 
                   3158: 
1.112     bowersj2 3159: ###############################################################
                   3160: ##               Student Answer Attempts                     ##
                   3161: ###############################################################
                   3162: 
                   3163: =pod
                   3164: 
                   3165: =head1 Alternate Problem Views
                   3166: 
                   3167: =over 4
                   3168: 
1.648     raeburn  3169: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112     bowersj2 3170:     $getattempt, $regexp, $gradesub)
                   3171: 
                   3172: Return string with previous attempt on problem. Arguments:
                   3173: 
                   3174: =over 4
                   3175: 
                   3176: =item * $symb: Problem, including path
                   3177: 
                   3178: =item * $username: username of the desired student
                   3179: 
                   3180: =item * $domain: domain of the desired student
1.14      harris41 3181: 
1.112     bowersj2 3182: =item * $course: Course ID
1.14      harris41 3183: 
1.112     bowersj2 3184: =item * $getattempt: Leave blank for all attempts, otherwise put
                   3185:     something
1.14      harris41 3186: 
1.112     bowersj2 3187: =item * $regexp: if string matches this regexp, the string will be
                   3188:     sent to $gradesub
1.14      harris41 3189: 
1.112     bowersj2 3190: =item * $gradesub: routine that processes the string if it matches $regexp
1.14      harris41 3191: 
1.112     bowersj2 3192: =back
1.14      harris41 3193: 
1.112     bowersj2 3194: The output string is a table containing all desired attempts, if any.
1.16      harris41 3195: 
1.112     bowersj2 3196: =cut
1.1       albertel 3197: 
                   3198: sub get_previous_attempt {
1.43      ng       3199:   my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1       albertel 3200:   my $prevattempts='';
1.43      ng       3201:   no strict 'refs';
1.1       albertel 3202:   if ($symb) {
1.3       albertel 3203:     my (%returnhash)=
                   3204:       &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1       albertel 3205:     if ($returnhash{'version'}) {
                   3206:       my %lasthash=();
                   3207:       my $version;
                   3208:       for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356     albertel 3209:         foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
                   3210: 	  $lasthash{$key}=$returnhash{$version.':'.$key};
1.19      harris41 3211:         }
1.1       albertel 3212:       }
1.596     albertel 3213:       $prevattempts=&start_data_table().&start_data_table_header_row();
                   3214:       $prevattempts.='<th>'.&mt('History').'</th>';
1.356     albertel 3215:       foreach my $key (sort(keys(%lasthash))) {
                   3216: 	my ($ign,@parts) = split(/\./,$key);
1.41      ng       3217: 	if ($#parts > 0) {
1.31      albertel 3218: 	  my $data=$parts[-1];
                   3219: 	  pop(@parts);
1.596     albertel 3220: 	  $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.'&nbsp;</th>';
1.31      albertel 3221: 	} else {
1.41      ng       3222: 	  if ($#parts == 0) {
                   3223: 	    $prevattempts.='<th>'.$parts[0].'</th>';
                   3224: 	  } else {
                   3225: 	    $prevattempts.='<th>'.$ign.'</th>';
                   3226: 	  }
1.31      albertel 3227: 	}
1.16      harris41 3228:       }
1.596     albertel 3229:       $prevattempts.=&end_data_table_header_row();
1.40      ng       3230:       if ($getattempt eq '') {
                   3231: 	for ($version=1;$version<=$returnhash{'version'};$version++) {
1.596     albertel 3232: 	  $prevattempts.=&start_data_table_row().
                   3233: 	      '<td>'.&mt('Transaction [_1]',$version).'</td>';
1.356     albertel 3234: 	    foreach my $key (sort(keys(%lasthash))) {
1.581     albertel 3235: 		my $value = &format_previous_attempt_value($key,
                   3236: 							   $returnhash{$version.':'.$key});
                   3237: 		$prevattempts.='<td>'.$value.'&nbsp;</td>';   
1.40      ng       3238: 	    }
1.596     albertel 3239: 	  $prevattempts.=&end_data_table_row();
1.40      ng       3240: 	 }
1.1       albertel 3241:       }
1.596     albertel 3242:       $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356     albertel 3243:       foreach my $key (sort(keys(%lasthash))) {
1.581     albertel 3244: 	my $value = &format_previous_attempt_value($key,$lasthash{$key});
1.356     albertel 3245: 	if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
1.40      ng       3246: 	$prevattempts.='<td>'.$value.'&nbsp;</td>';
1.16      harris41 3247:       }
1.596     albertel 3248:       $prevattempts.= &end_data_table_row().&end_data_table();
1.1       albertel 3249:     } else {
1.596     albertel 3250:       $prevattempts=
                   3251: 	  &start_data_table().&start_data_table_row().
                   3252: 	  '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
                   3253: 	  &end_data_table_row().&end_data_table();
1.1       albertel 3254:     }
                   3255:   } else {
1.596     albertel 3256:     $prevattempts=
                   3257: 	  &start_data_table().&start_data_table_row().
                   3258: 	  '<td>'.&mt('No data.').'</td>'.
                   3259: 	  &end_data_table_row().&end_data_table();
1.1       albertel 3260:   }
1.10      albertel 3261: }
                   3262: 
1.581     albertel 3263: sub format_previous_attempt_value {
                   3264:     my ($key,$value) = @_;
                   3265:     if ($key =~ /timestamp/) {
                   3266: 	$value = &Apache::lonlocal::locallocaltime($value);
                   3267:     } elsif (ref($value) eq 'ARRAY') {
                   3268: 	$value = '('.join(', ', @{ $value }).')';
                   3269:     } else {
                   3270: 	$value = &unescape($value);
                   3271:     }
                   3272:     return $value;
                   3273: }
                   3274: 
                   3275: 
1.107     albertel 3276: sub relative_to_absolute {
                   3277:     my ($url,$output)=@_;
                   3278:     my $parser=HTML::TokeParser->new(\$output);
                   3279:     my $token;
                   3280:     my $thisdir=$url;
                   3281:     my @rlinks=();
                   3282:     while ($token=$parser->get_token) {
                   3283: 	if ($token->[0] eq 'S') {
                   3284: 	    if ($token->[1] eq 'a') {
                   3285: 		if ($token->[2]->{'href'}) {
                   3286: 		    $rlinks[$#rlinks+1]=$token->[2]->{'href'};
                   3287: 		}
                   3288: 	    } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
                   3289: 		$rlinks[$#rlinks+1]=$token->[2]->{'src'};
                   3290: 	    } elsif ($token->[1] eq 'base') {
                   3291: 		$thisdir=$token->[2]->{'href'};
                   3292: 	    }
                   3293: 	}
                   3294:     }
                   3295:     $thisdir=~s-/[^/]*$--;
1.356     albertel 3296:     foreach my $link (@rlinks) {
1.726     raeburn  3297: 	unless (($link=~/^https?\:\/\//i) ||
1.356     albertel 3298: 		($link=~/^\//) ||
                   3299: 		($link=~/^javascript:/i) ||
                   3300: 		($link=~/^mailto:/i) ||
                   3301: 		($link=~/^\#/)) {
                   3302: 	    my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
                   3303: 	    $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107     albertel 3304: 	}
                   3305:     }
                   3306: # -------------------------------------------------- Deal with Applet codebases
                   3307:     $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
                   3308:     return $output;
                   3309: }
                   3310: 
1.112     bowersj2 3311: =pod
                   3312: 
1.648     raeburn  3313: =item * &get_student_view()
1.112     bowersj2 3314: 
                   3315: show a snapshot of what student was looking at
                   3316: 
                   3317: =cut
                   3318: 
1.10      albertel 3319: sub get_student_view {
1.186     albertel 3320:   my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114     www      3321:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 3322:   my (%form);
1.10      albertel 3323:   my @elements=('symb','courseid','domain','username');
                   3324:   foreach my $element (@elements) {
1.186     albertel 3325:       $form{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 3326:   }
1.186     albertel 3327:   if (defined($moreenv)) {
                   3328:       %form=(%form,%{$moreenv});
                   3329:   }
1.236     albertel 3330:   if (defined($target)) { $form{'grade_target'} = $target; }
1.107     albertel 3331:   $feedurl=&Apache::lonnet::clutter($feedurl);
1.650     www      3332:   my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11      albertel 3333:   $userview=~s/\<body[^\>]*\>//gi;
                   3334:   $userview=~s/\<\/body\>//gi;
                   3335:   $userview=~s/\<html\>//gi;
                   3336:   $userview=~s/\<\/html\>//gi;
                   3337:   $userview=~s/\<head\>//gi;
                   3338:   $userview=~s/\<\/head\>//gi;
                   3339:   $userview=~s/action\s*\=/would_be_action\=/gi;
1.107     albertel 3340:   $userview=&relative_to_absolute($feedurl,$userview);
1.650     www      3341:   if (wantarray) {
                   3342:      return ($userview,$response);
                   3343:   } else {
                   3344:      return $userview;
                   3345:   }
                   3346: }
                   3347: 
                   3348: sub get_student_view_with_retries {
                   3349:   my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
                   3350: 
                   3351:     my $ok = 0;                 # True if we got a good response.
                   3352:     my $content;
                   3353:     my $response;
                   3354: 
                   3355:     # Try to get the student_view done. within the retries count:
                   3356:     
                   3357:     do {
                   3358:          ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
                   3359:          $ok      = $response->is_success;
                   3360:          if (!$ok) {
                   3361:             &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
                   3362:          }
                   3363:          $retries--;
                   3364:     } while (!$ok && ($retries > 0));
                   3365:     
                   3366:     if (!$ok) {
                   3367:        $content = '';          # On error return an empty content.
                   3368:     }
1.651     www      3369:     if (wantarray) {
                   3370:        return ($content, $response);
                   3371:     } else {
                   3372:        return $content;
                   3373:     }
1.11      albertel 3374: }
                   3375: 
1.112     bowersj2 3376: =pod
                   3377: 
1.648     raeburn  3378: =item * &get_student_answers() 
1.112     bowersj2 3379: 
                   3380: show a snapshot of how student was answering problem
                   3381: 
                   3382: =cut
                   3383: 
1.11      albertel 3384: sub get_student_answers {
1.100     sakharuk 3385:   my ($symb,$username,$domain,$courseid,%form) = @_;
1.114     www      3386:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 3387:   my (%moreenv);
1.11      albertel 3388:   my @elements=('symb','courseid','domain','username');
                   3389:   foreach my $element (@elements) {
1.186     albertel 3390:     $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 3391:   }
1.186     albertel 3392:   $moreenv{'grade_target'}='answer';
                   3393:   %moreenv=(%form,%moreenv);
1.497     raeburn  3394:   $feedurl = &Apache::lonnet::clutter($feedurl);
                   3395:   my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10      albertel 3396:   return $userview;
1.1       albertel 3397: }
1.116     albertel 3398: 
                   3399: =pod
                   3400: 
                   3401: =item * &submlink()
                   3402: 
1.242     albertel 3403: Inputs: $text $uname $udom $symb $target
1.116     albertel 3404: 
                   3405: Returns: A link to grades.pm such as to see the SUBM view of a student
                   3406: 
                   3407: =cut
                   3408: 
                   3409: ###############################################
                   3410: sub submlink {
1.242     albertel 3411:     my ($text,$uname,$udom,$symb,$target)=@_;
1.116     albertel 3412:     if (!($uname && $udom)) {
                   3413: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 3414: 	    &Apache::lonnet::whichuser($symb);
1.116     albertel 3415: 	if (!$symb) { $symb=$cursymb; }
                   3416:     }
1.254     matthew  3417:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      3418:     $symb=&escape($symb);
1.242     albertel 3419:     if ($target) { $target="target=\"$target\""; }
                   3420:     return '<a href="/adm/grades?&command=submission&'.
                   3421: 	'symb='.$symb.'&student='.$uname.
                   3422: 	'&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
                   3423: }
                   3424: ##############################################
                   3425: 
                   3426: =pod
                   3427: 
                   3428: =item * &pgrdlink()
                   3429: 
                   3430: Inputs: $text $uname $udom $symb $target
                   3431: 
                   3432: Returns: A link to grades.pm such as to see the PGRD view of a student
                   3433: 
                   3434: =cut
                   3435: 
                   3436: ###############################################
                   3437: sub pgrdlink {
                   3438:     my $link=&submlink(@_);
                   3439:     $link=~s/(&command=submission)/$1&showgrading=yes/;
                   3440:     return $link;
                   3441: }
                   3442: ##############################################
                   3443: 
                   3444: =pod
                   3445: 
                   3446: =item * &pprmlink()
                   3447: 
                   3448: Inputs: $text $uname $udom $symb $target
                   3449: 
                   3450: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283     albertel 3451: student and a specific resource
1.242     albertel 3452: 
                   3453: =cut
                   3454: 
                   3455: ###############################################
                   3456: sub pprmlink {
                   3457:     my ($text,$uname,$udom,$symb,$target)=@_;
                   3458:     if (!($uname && $udom)) {
                   3459: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 3460: 	    &Apache::lonnet::whichuser($symb);
1.242     albertel 3461: 	if (!$symb) { $symb=$cursymb; }
                   3462:     }
1.254     matthew  3463:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      3464:     $symb=&escape($symb);
1.242     albertel 3465:     if ($target) { $target="target=\"$target\""; }
1.595     albertel 3466:     return '<a href="/adm/parmset?command=set&amp;'.
                   3467: 	'symb='.$symb.'&amp;uname='.$uname.
                   3468: 	'&amp;udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116     albertel 3469: }
                   3470: ##############################################
1.37      matthew  3471: 
1.112     bowersj2 3472: =pod
                   3473: 
                   3474: =back
                   3475: 
                   3476: =cut
                   3477: 
1.37      matthew  3478: ###############################################
1.51      www      3479: 
                   3480: 
                   3481: sub timehash {
1.687     raeburn  3482:     my ($thistime) = @_;
                   3483:     my $timezone = &Apache::lonlocal::gettimezone();
                   3484:     my $dt = DateTime->from_epoch(epoch => $thistime)
                   3485:                      ->set_time_zone($timezone);
                   3486:     my $wday = $dt->day_of_week();
                   3487:     if ($wday == 7) { $wday = 0; }
                   3488:     return ( 'second' => $dt->second(),
                   3489:              'minute' => $dt->minute(),
                   3490:              'hour'   => $dt->hour(),
                   3491:              'day'     => $dt->day_of_month(),
                   3492:              'month'   => $dt->month(),
                   3493:              'year'    => $dt->year(),
                   3494:              'weekday' => $wday,
                   3495:              'dayyear' => $dt->day_of_year(),
                   3496:              'dlsav'   => $dt->is_dst() );
1.51      www      3497: }
                   3498: 
1.370     www      3499: sub utc_string {
                   3500:     my ($date)=@_;
1.371     www      3501:     return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370     www      3502: }
                   3503: 
1.51      www      3504: sub maketime {
                   3505:     my %th=@_;
1.687     raeburn  3506:     my ($epoch_time,$timezone,$dt);
                   3507:     $timezone = &Apache::lonlocal::gettimezone();
                   3508:     eval {
                   3509:         $dt = DateTime->new( year   => $th{'year'},
                   3510:                              month  => $th{'month'},
                   3511:                              day    => $th{'day'},
                   3512:                              hour   => $th{'hour'},
                   3513:                              minute => $th{'minute'},
                   3514:                              second => $th{'second'},
                   3515:                              time_zone => $timezone,
                   3516:                          );
                   3517:     };
                   3518:     if (!$@) {
                   3519:         $epoch_time = $dt->epoch;
                   3520:         if ($epoch_time) {
                   3521:             return $epoch_time;
                   3522:         }
                   3523:     }
1.51      www      3524:     return POSIX::mktime(
                   3525:         ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210     www      3526:          $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70      www      3527: }
                   3528: 
                   3529: #########################################
1.51      www      3530: 
                   3531: sub findallcourses {
1.482     raeburn  3532:     my ($roles,$uname,$udom) = @_;
1.355     albertel 3533:     my %roles;
                   3534:     if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348     albertel 3535:     my %courses;
1.51      www      3536:     my $now=time;
1.482     raeburn  3537:     if (!defined($uname)) {
                   3538:         $uname = $env{'user.name'};
                   3539:     }
                   3540:     if (!defined($udom)) {
                   3541:         $udom = $env{'user.domain'};
                   3542:     }
                   3543:     if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
                   3544:         my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
                   3545:         if (!%roles) {
                   3546:             %roles = (
                   3547:                        cc => 1,
                   3548:                        in => 1,
                   3549:                        ep => 1,
                   3550:                        ta => 1,
                   3551:                        cr => 1,
                   3552:                        st => 1,
                   3553:              );
                   3554:         }
                   3555:         foreach my $entry (keys(%roleshash)) {
                   3556:             my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
                   3557:             if ($trole =~ /^cr/) { 
                   3558:                 next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
                   3559:             } else {
                   3560:                 next if (!exists($roles{$trole}));
                   3561:             }
                   3562:             if ($tend) {
                   3563:                 next if ($tend < $now);
                   3564:             }
                   3565:             if ($tstart) {
                   3566:                 next if ($tstart > $now);
                   3567:             }
                   3568:             my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
                   3569:             (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
                   3570:             if ($secpart eq '') {
                   3571:                 ($cnum,$role) = split(/_/,$cnumpart); 
                   3572:                 $sec = 'none';
                   3573:                 $realsec = '';
                   3574:             } else {
                   3575:                 $cnum = $cnumpart;
                   3576:                 ($sec,$role) = split(/_/,$secpart);
                   3577:                 $realsec = $sec;
1.490     raeburn  3578:             }
1.482     raeburn  3579:             $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
                   3580:         }
                   3581:     } else {
                   3582:         foreach my $key (keys(%env)) {
1.483     albertel 3583: 	    if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
                   3584:                  $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482     raeburn  3585: 	        my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
                   3586: 	        next if ($role eq 'ca' || $role eq 'aa');
                   3587: 	        next if (%roles && !exists($roles{$role}));
                   3588: 	        my ($starttime,$endtime)=split(/\./,$env{$key});
                   3589:                 my $active=1;
                   3590:                 if ($starttime) {
                   3591: 		    if ($now<$starttime) { $active=0; }
                   3592:                 }
                   3593:                 if ($endtime) {
                   3594:                     if ($now>$endtime) { $active=0; }
                   3595:                 }
                   3596:                 if ($active) {
                   3597:                     if ($sec eq '') {
                   3598:                         $sec = 'none';
                   3599:                     }
                   3600:                     $courses{$cdom.'_'.$cnum}{$sec} = 
                   3601:                                      $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474     raeburn  3602:                 }
                   3603:             }
1.51      www      3604:         }
                   3605:     }
1.474     raeburn  3606:     return %courses;
1.51      www      3607: }
1.37      matthew  3608: 
1.54      www      3609: ###############################################
1.474     raeburn  3610: 
                   3611: sub blockcheck {
1.482     raeburn  3612:     my ($setters,$activity,$uname,$udom) = @_;
1.490     raeburn  3613: 
                   3614:     if (!defined($udom)) {
                   3615:         $udom = $env{'user.domain'};
                   3616:     }
                   3617:     if (!defined($uname)) {
                   3618:         $uname = $env{'user.name'};
                   3619:     }
                   3620: 
                   3621:     # If uname and udom are for a course, check for blocks in the course.
                   3622: 
                   3623:     if (&Apache::lonnet::is_course($udom,$uname)) {
                   3624:         my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502     raeburn  3625:         my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490     raeburn  3626:         return ($startblock,$endblock);
                   3627:     }
1.474     raeburn  3628: 
1.502     raeburn  3629:     my $startblock = 0;
                   3630:     my $endblock = 0;
1.482     raeburn  3631:     my %live_courses = &findallcourses(undef,$uname,$udom);
1.474     raeburn  3632: 
1.490     raeburn  3633:     # If uname is for a user, and activity is course-specific, i.e.,
                   3634:     # boards, chat or groups, check for blocking in current course only.
1.474     raeburn  3635: 
1.490     raeburn  3636:     if (($activity eq 'boards' || $activity eq 'chat' ||
                   3637:          $activity eq 'groups') && ($env{'request.course.id'})) {
                   3638:         foreach my $key (keys(%live_courses)) {
                   3639:             if ($key ne $env{'request.course.id'}) {
                   3640:                 delete($live_courses{$key});
                   3641:             }
                   3642:         }
                   3643:     }
                   3644: 
                   3645:     my $otheruser = 0;
                   3646:     my %own_courses;
                   3647:     if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
                   3648:         # Resource belongs to user other than current user.
                   3649:         $otheruser = 1;
                   3650:         # Gather courses for current user
                   3651:         %own_courses = 
                   3652:             &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
                   3653:     }
                   3654: 
                   3655:     # Gather active course roles - course coordinator, instructor, 
                   3656:     # exam proctor, ta, student, or custom role.
1.474     raeburn  3657: 
                   3658:     foreach my $course (keys(%live_courses)) {
1.482     raeburn  3659:         my ($cdom,$cnum);
                   3660:         if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
                   3661:             $cdom = $env{'course.'.$course.'.domain'};
                   3662:             $cnum = $env{'course.'.$course.'.num'};
                   3663:         } else {
1.490     raeburn  3664:             ($cdom,$cnum) = split(/_/,$course); 
1.482     raeburn  3665:         }
                   3666:         my $no_ownblock = 0;
                   3667:         my $no_userblock = 0;
1.533     raeburn  3668:         if ($otheruser && $activity ne 'com') {
1.490     raeburn  3669:             # Check if current user has 'evb' priv for this
                   3670:             if (defined($own_courses{$course})) {
                   3671:                 foreach my $sec (keys(%{$own_courses{$course}})) {
                   3672:                     my $checkrole = 'cm./'.$cdom.'/'.$cnum;
                   3673:                     if ($sec ne 'none') {
                   3674:                         $checkrole .= '/'.$sec;
                   3675:                     }
                   3676:                     if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   3677:                         $no_ownblock = 1;
                   3678:                         last;
                   3679:                     }
                   3680:                 }
                   3681:             }
                   3682:             # if they have 'evb' priv and are currently not playing student
                   3683:             next if (($no_ownblock) &&
                   3684:                  ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
                   3685:         }
1.474     raeburn  3686:         foreach my $sec (keys(%{$live_courses{$course}})) {
1.482     raeburn  3687:             my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474     raeburn  3688:             if ($sec ne 'none') {
1.482     raeburn  3689:                 $checkrole .= '/'.$sec;
1.474     raeburn  3690:             }
1.490     raeburn  3691:             if ($otheruser) {
                   3692:                 # Resource belongs to user other than current user.
                   3693:                 # Assemble privs for that user, and check for 'evb' priv.
1.482     raeburn  3694:                 my ($trole,$tdom,$tnum,$tsec);
                   3695:                 my $entry = $live_courses{$course}{$sec};
                   3696:                 if ($entry =~ /^cr/) {
                   3697:                     ($trole,$tdom,$tnum,$tsec) = 
                   3698:                       ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
                   3699:                 } else {
                   3700:                     ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
                   3701:                 }
                   3702:                 my ($spec,$area,$trest,%allroles,%userroles);
                   3703:                 $area = '/'.$tdom.'/'.$tnum;
                   3704:                 $trest = $tnum;
                   3705:                 if ($tsec ne '') {
                   3706:                     $area .= '/'.$tsec;
                   3707:                     $trest .= '/'.$tsec;
                   3708:                 }
                   3709:                 $spec = $trole.'.'.$area;
                   3710:                 if ($trole =~ /^cr/) {
                   3711:                     &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
                   3712:                                                       $tdom,$spec,$trest,$area);
                   3713:                 } else {
                   3714:                     &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
                   3715:                                                        $tdom,$spec,$trest,$area);
                   3716:                 }
                   3717:                 my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486     raeburn  3718:                 if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
                   3719:                     if ($1) {
                   3720:                         $no_userblock = 1;
                   3721:                         last;
                   3722:                     }
                   3723:                 }
1.490     raeburn  3724:             } else {
                   3725:                 # Resource belongs to current user
                   3726:                 # Check for 'evb' priv via lonnet::allowed().
1.482     raeburn  3727:                 if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   3728:                     $no_ownblock = 1;
                   3729:                     last;
                   3730:                 }
1.474     raeburn  3731:             }
                   3732:         }
                   3733:         # if they have the evb priv and are currently not playing student
1.482     raeburn  3734:         next if (($no_ownblock) &&
1.491     albertel 3735:                  ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482     raeburn  3736:         next if ($no_userblock);
1.474     raeburn  3737: 
1.490     raeburn  3738:         # Retrieve blocking times and identity of blocker for course
                   3739:         # of specified user, unless user has 'evb' privilege.
1.502     raeburn  3740:         
                   3741:         my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
                   3742:         if (($start != 0) && 
                   3743:             (($startblock == 0) || ($startblock > $start))) {
                   3744:             $startblock = $start;
                   3745:         }
                   3746:         if (($end != 0)  &&
                   3747:             (($endblock == 0) || ($endblock < $end))) {
                   3748:             $endblock = $end;
                   3749:         }
1.490     raeburn  3750:     }
                   3751:     return ($startblock,$endblock);
                   3752: }
                   3753: 
                   3754: sub get_blocks {
                   3755:     my ($setters,$activity,$cdom,$cnum) = @_;
                   3756:     my $startblock = 0;
                   3757:     my $endblock = 0;
                   3758:     my $course = $cdom.'_'.$cnum;
                   3759:     $setters->{$course} = {};
                   3760:     $setters->{$course}{'staff'} = [];
                   3761:     $setters->{$course}{'times'} = [];
                   3762:     my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
                   3763:     foreach my $record (keys(%records)) {
                   3764:         my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
                   3765:         if ($start <= time && $end >= time) {
                   3766:             my ($staff_name,$staff_dom,$title,$blocks) =
                   3767:                 &parse_block_record($records{$record});
                   3768:             if ($blocks->{$activity} eq 'on') {
                   3769:                 push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
                   3770:                 push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491     albertel 3771:                 if ( ($startblock == 0) || ($startblock > $start) ) {
                   3772:                     $startblock = $start;
1.490     raeburn  3773:                 }
1.491     albertel 3774:                 if ( ($endblock == 0) || ($endblock < $end) ) {
                   3775:                     $endblock = $end;
1.474     raeburn  3776:                 }
                   3777:             }
                   3778:         }
                   3779:     }
                   3780:     return ($startblock,$endblock);
                   3781: }
                   3782: 
                   3783: sub parse_block_record {
                   3784:     my ($record) = @_;
                   3785:     my ($setuname,$setudom,$title,$blocks);
                   3786:     if (ref($record) eq 'HASH') {
                   3787:         ($setuname,$setudom) = split(/:/,$record->{'setter'});
                   3788:         $title = &unescape($record->{'event'});
                   3789:         $blocks = $record->{'blocks'};
                   3790:     } else {
                   3791:         my @data = split(/:/,$record,3);
                   3792:         if (scalar(@data) eq 2) {
                   3793:             $title = $data[1];
                   3794:             ($setuname,$setudom) = split(/@/,$data[0]);
                   3795:         } else {
                   3796:             ($setuname,$setudom,$title) = @data;
                   3797:         }
                   3798:         $blocks = { 'com' => 'on' };
                   3799:     }
                   3800:     return ($setuname,$setudom,$title,$blocks);
                   3801: }
                   3802: 
                   3803: sub build_block_table {
                   3804:     my ($startblock,$endblock,$setters) = @_;
                   3805:     my %lt = &Apache::lonlocal::texthash(
                   3806:         'cacb' => 'Currently active communication blocks',
                   3807:         'cour' => 'Course',
                   3808:         'dura' => 'Duration',
                   3809:         'blse' => 'Block set by'
                   3810:     );
                   3811:     my $output;
1.476     raeburn  3812:     $output = '<br />'.$lt{'cacb'}.':<br />';
1.474     raeburn  3813:     $output .= &start_data_table();
                   3814:     $output .= '
                   3815: <tr>
                   3816:  <th>'.$lt{'cour'}.'</th>
                   3817:  <th>'.$lt{'dura'}.'</th>
                   3818:  <th>'.$lt{'blse'}.'</th>
                   3819: </tr>
                   3820: ';
                   3821:     foreach my $course (keys(%{$setters})) {
                   3822:         my %courseinfo=&Apache::lonnet::coursedescription($course);
                   3823:         for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) {
                   3824:             my ($uname,$udom) = @{$$setters{$course}{staff}[$i]};
1.490     raeburn  3825:             my $fullname = &plainname($uname,$udom);
                   3826:             if (defined($env{'user.name'}) && defined($env{'user.domain'})
                   3827:                 && $env{'user.name'} ne 'public' 
                   3828:                 && $env{'user.domain'} ne 'public') {
                   3829:                 $fullname = &aboutmewrapper($fullname,$uname,$udom);
                   3830:             }
1.474     raeburn  3831:             my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]};
                   3832:             $openblock = &Apache::lonlocal::locallocaltime($openblock);
                   3833:             $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
                   3834:             $output .= &Apache::loncommon::start_data_table_row().
                   3835:                        '<td>'.$courseinfo{'description'}.'</td>'.
                   3836:                        '<td>'.$openblock.' to '.$closeblock.'</td>'.
1.490     raeburn  3837:                        '<td>'.$fullname.'</td>'.
1.474     raeburn  3838:                         &Apache::loncommon::end_data_table_row();
                   3839:         }
                   3840:     }
                   3841:     $output .= &end_data_table();
                   3842: }
                   3843: 
1.490     raeburn  3844: sub blocking_status {
                   3845:     my ($activity,$uname,$udom) = @_;
                   3846:     my %setters;
                   3847:     my ($blocked,$output,$ownitem,$is_course);
                   3848:     my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
                   3849:     if ($startblock && $endblock) {
                   3850:         $blocked = 1;
                   3851:         if (wantarray) {
                   3852:             my $category;
                   3853:             if ($activity eq 'boards') {
                   3854:                 $category = 'Discussion posts in this course';
                   3855:             } elsif ($activity eq 'blogs') {
                   3856:                 $category = 'Blogs';
                   3857:             } elsif ($activity eq 'port') {
                   3858:                 if (defined($uname) && defined($udom)) {
                   3859:                     if ($uname eq $env{'user.name'} &&
                   3860:                         $udom eq $env{'user.domain'}) {
                   3861:                         $ownitem = 1;
                   3862:                     }
                   3863:                 }
                   3864:                 $is_course = &Apache::lonnet::is_course($udom,$uname);
                   3865:                 if ($ownitem) { 
                   3866:                     $category = 'Your portfolio files';  
                   3867:                 } elsif ($is_course) {
                   3868:                     my $coursedesc;
                   3869:                     foreach my $course (keys(%setters)) {
                   3870:                         my %courseinfo =
                   3871:                              &Apache::lonnet::coursedescription($course);
                   3872:                         $coursedesc = $courseinfo{'description'};
                   3873:                     }
1.764     weissno  3874:                     $category = "Group portfolio in the course '$coursedesc'";
1.490     raeburn  3875:                 } else {
                   3876:                     $category = 'Portfolio files belonging to ';
                   3877:                     if ($env{'user.name'} eq 'public' && 
                   3878:                         $env{'user.domain'} eq 'public') {
                   3879:                         $category .= &plainname($uname,$udom);
                   3880:                     } else {
                   3881:                         $category .= &aboutmewrapper(&plainname($uname,$udom),$uname,$udom);  
                   3882:                     }
                   3883:                 }
                   3884:             } elsif ($activity eq 'groups') {
                   3885:                 $category = 'Groups in this course';
                   3886:             }
                   3887:             my $showstart = &Apache::lonlocal::locallocaltime($startblock);
                   3888:             my $showend = &Apache::lonlocal::locallocaltime($endblock);
                   3889:             $output = '<br />'.&mt('[_1] will be inaccessible between [_2] and [_3] because communication is being blocked.',$category,$showstart,$showend).'<br />';
                   3890:             if (!($activity eq 'port' && !($ownitem) && !($is_course))) { 
                   3891:                 $output .= &build_block_table($startblock,$endblock,\%setters);
                   3892:             }
                   3893:         }
                   3894:     }
                   3895:     if (wantarray) {
                   3896:         return ($blocked,$output);
                   3897:     } else {
                   3898:         return $blocked;
                   3899:     }
                   3900: }
                   3901: 
1.60      matthew  3902: ###############################################
                   3903: 
1.682     raeburn  3904: sub check_ip_acc {
                   3905:     my ($acc)=@_;
                   3906:     &Apache::lonxml::debug("acc is $acc");
                   3907:     if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
                   3908:         return 1;
                   3909:     }
                   3910:     my $allowed=0;
                   3911:     my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
                   3912: 
                   3913:     my $name;
                   3914:     foreach my $pattern (split(',',$acc)) {
                   3915:         $pattern =~ s/^\s*//;
                   3916:         $pattern =~ s/\s*$//;
                   3917:         if ($pattern =~ /\*$/) {
                   3918:             #35.8.*
                   3919:             $pattern=~s/\*//;
                   3920:             if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
                   3921:         } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
                   3922:             #35.8.3.[34-56]
                   3923:             my $low=$2;
                   3924:             my $high=$3;
                   3925:             $pattern=$1;
                   3926:             if ($ip =~ /^\Q$pattern\E/) {
                   3927:                 my $last=(split(/\./,$ip))[3];
                   3928:                 if ($last <=$high && $last >=$low) { $allowed=1; }
                   3929:             }
                   3930:         } elsif ($pattern =~ /^\*/) {
                   3931:             #*.msu.edu
                   3932:             $pattern=~s/\*//;
                   3933:             if (!defined($name)) {
                   3934:                 use Socket;
                   3935:                 my $netaddr=inet_aton($ip);
                   3936:                 ($name)=gethostbyaddr($netaddr,AF_INET);
                   3937:             }
                   3938:             if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
                   3939:         } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
                   3940:             #127.0.0.1
                   3941:             if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
                   3942:         } else {
                   3943:             #some.name.com
                   3944:             if (!defined($name)) {
                   3945:                 use Socket;
                   3946:                 my $netaddr=inet_aton($ip);
                   3947:                 ($name)=gethostbyaddr($netaddr,AF_INET);
                   3948:             }
                   3949:             if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
                   3950:         }
                   3951:         if ($allowed) { last; }
                   3952:     }
                   3953:     return $allowed;
                   3954: }
                   3955: 
                   3956: ###############################################
                   3957: 
1.60      matthew  3958: =pod
                   3959: 
1.112     bowersj2 3960: =head1 Domain Template Functions
                   3961: 
                   3962: =over 4
                   3963: 
                   3964: =item * &determinedomain()
1.60      matthew  3965: 
                   3966: Inputs: $domain (usually will be undef)
                   3967: 
1.63      www      3968: Returns: Determines which domain should be used for designs
1.60      matthew  3969: 
                   3970: =cut
1.54      www      3971: 
1.60      matthew  3972: ###############################################
1.63      www      3973: sub determinedomain {
                   3974:     my $domain=shift;
1.531     albertel 3975:     if (! $domain) {
1.60      matthew  3976:         # Determine domain if we have not been given one
                   3977:         $domain = $Apache::lonnet::perlvar{'lonDefDomain'};
1.258     albertel 3978:         if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
                   3979:         if ($env{'request.role.domain'}) { 
                   3980:             $domain=$env{'request.role.domain'}; 
1.60      matthew  3981:         }
                   3982:     }
1.63      www      3983:     return $domain;
                   3984: }
                   3985: ###############################################
1.517     raeburn  3986: 
1.518     albertel 3987: sub devalidate_domconfig_cache {
                   3988:     my ($udom)=@_;
                   3989:     &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
                   3990: }
                   3991: 
                   3992: # ---------------------- Get domain configuration for a domain
                   3993: sub get_domainconf {
                   3994:     my ($udom) = @_;
                   3995:     my $cachetime=1800;
                   3996:     my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
                   3997:     if (defined($cached)) { return %{$result}; }
                   3998: 
                   3999:     my %domconfig = &Apache::lonnet::get_dom('configuration',
                   4000: 					     ['login','rolecolors'],$udom);
1.632     raeburn  4001:     my (%designhash,%legacy);
1.518     albertel 4002:     if (keys(%domconfig) > 0) {
                   4003:         if (ref($domconfig{'login'}) eq 'HASH') {
1.632     raeburn  4004:             if (keys(%{$domconfig{'login'}})) {
                   4005:                 foreach my $key (keys(%{$domconfig{'login'}})) {
1.699     raeburn  4006:                     if (ref($domconfig{'login'}{$key}) eq 'HASH') {
                   4007:                         foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
                   4008:                             $designhash{$udom.'.login.'.$key.'_'.$img} = 
                   4009:                                 $domconfig{'login'}{$key}{$img};
                   4010:                         }
                   4011:                     } else {
                   4012:                         $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
                   4013:                     }
1.632     raeburn  4014:                 }
                   4015:             } else {
                   4016:                 $legacy{'login'} = 1;
1.518     albertel 4017:             }
1.632     raeburn  4018:         } else {
                   4019:             $legacy{'login'} = 1;
1.518     albertel 4020:         }
                   4021:         if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632     raeburn  4022:             if (keys(%{$domconfig{'rolecolors'}})) {
                   4023:                 foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
                   4024:                     if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
                   4025:                         foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
                   4026:                             $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
                   4027:                         }
1.518     albertel 4028:                     }
                   4029:                 }
1.632     raeburn  4030:             } else {
                   4031:                 $legacy{'rolecolors'} = 1;
1.518     albertel 4032:             }
1.632     raeburn  4033:         } else {
                   4034:             $legacy{'rolecolors'} = 1;
1.518     albertel 4035:         }
1.632     raeburn  4036:         if (keys(%legacy) > 0) {
                   4037:             my %legacyhash = &get_legacy_domconf($udom);
                   4038:             foreach my $item (keys(%legacyhash)) {
                   4039:                 if ($item =~ /^\Q$udom\E\.login/) {
                   4040:                     if ($legacy{'login'}) { 
                   4041:                         $designhash{$item} = $legacyhash{$item};
                   4042:                     }
                   4043:                 } else {
                   4044:                     if ($legacy{'rolecolors'}) {
                   4045:                         $designhash{$item} = $legacyhash{$item};
                   4046:                     }
1.518     albertel 4047:                 }
                   4048:             }
                   4049:         }
1.632     raeburn  4050:     } else {
                   4051:         %designhash = &get_legacy_domconf($udom); 
1.518     albertel 4052:     }
                   4053:     &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
                   4054: 				  $cachetime);
                   4055:     return %designhash;
                   4056: }
                   4057: 
1.632     raeburn  4058: sub get_legacy_domconf {
                   4059:     my ($udom) = @_;
                   4060:     my %legacyhash;
                   4061:     my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
                   4062:     my $designfile =  $designdir.'/'.$udom.'.tab';
                   4063:     if (-e $designfile) {
                   4064:         if ( open (my $fh,"<$designfile") ) {
                   4065:             while (my $line = <$fh>) {
                   4066:                 next if ($line =~ /^\#/);
                   4067:                 chomp($line);
                   4068:                 my ($key,$val)=(split(/\=/,$line));
                   4069:                 if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
                   4070:             }
                   4071:             close($fh);
                   4072:         }
                   4073:     }
                   4074:     if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
                   4075:         $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
                   4076:     }
                   4077:     return %legacyhash;
                   4078: }
                   4079: 
1.63      www      4080: =pod
                   4081: 
1.112     bowersj2 4082: =item * &domainlogo()
1.63      www      4083: 
                   4084: Inputs: $domain (usually will be undef)
                   4085: 
                   4086: Returns: A link to a domain logo, if the domain logo exists.
                   4087: If the domain logo does not exist, a description of the domain.
                   4088: 
                   4089: =cut
1.112     bowersj2 4090: 
1.63      www      4091: ###############################################
                   4092: sub domainlogo {
1.517     raeburn  4093:     my $domain = &determinedomain(shift);
1.518     albertel 4094:     my %designhash = &get_domainconf($domain);    
1.517     raeburn  4095:     # See if there is a logo
                   4096:     if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519     raeburn  4097:         my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538     albertel 4098:         if ($imgsrc =~ m{^/(adm|res)/}) {
                   4099: 	    if ($imgsrc =~ m{^/res/}) {
                   4100: 		my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
                   4101: 		&Apache::lonnet::repcopy($local_name);
                   4102: 	    }
                   4103: 	   $imgsrc = &lonhttpdurl($imgsrc);
1.519     raeburn  4104:         } 
                   4105:         return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514     albertel 4106:     } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
                   4107:         return &Apache::lonnet::domain($domain,'description');
1.59      www      4108:     } else {
1.60      matthew  4109:         return '';
1.59      www      4110:     }
                   4111: }
1.63      www      4112: ##############################################
                   4113: 
                   4114: =pod
                   4115: 
1.112     bowersj2 4116: =item * &designparm()
1.63      www      4117: 
                   4118: Inputs: $which parameter; $domain (usually will be undef)
                   4119: 
                   4120: Returns: value of designparamter $which
                   4121: 
                   4122: =cut
1.112     bowersj2 4123: 
1.397     albertel 4124: 
1.400     albertel 4125: ##############################################
1.397     albertel 4126: sub designparm {
                   4127:     my ($which,$domain)=@_;
1.258     albertel 4128:     if ($env{'browser.blackwhite'} eq 'on') {
1.635     raeburn  4129: 	if ($which=~/\.(font|alink|vlink|link|textcol)$/) {
1.110     www      4130: 	    return '#000000';
                   4131: 	}
1.635     raeburn  4132: 	if ($which=~/\.(pgbg|sidebg|bgcol)$/) {
1.110     www      4133: 	    return '#FFFFFF';
                   4134: 	}
                   4135: 	if ($which=~/\.tabbg$/) {
                   4136: 	    return '#CCCCCC';
                   4137: 	}
                   4138:     }
1.397     albertel 4139:     if (exists($env{'environment.color.'.$which})) {
1.258     albertel 4140: 	return $env{'environment.color.'.$which};
1.96      www      4141:     }
1.63      www      4142:     $domain=&determinedomain($domain);
1.518     albertel 4143:     my %domdesign = &get_domainconf($domain);
1.520     raeburn  4144:     my $output;
1.517     raeburn  4145:     if ($domdesign{$domain.'.'.$which} ne '') {
1.520     raeburn  4146: 	$output = $domdesign{$domain.'.'.$which};
1.63      www      4147:     } else {
1.520     raeburn  4148:         $output = $defaultdesign{$which};
                   4149:     }
                   4150:     if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635     raeburn  4151:         ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538     albertel 4152:         if ($output =~ m{^/(adm|res)/}) {
                   4153: 	    if ($output =~ m{^/res/}) {
                   4154: 		my $local_name = &Apache::lonnet::filelocation('',$output);
                   4155: 		&Apache::lonnet::repcopy($local_name);
                   4156: 	    }
1.520     raeburn  4157:             $output = &lonhttpdurl($output);
                   4158:         }
1.63      www      4159:     }
1.520     raeburn  4160:     return $output;
1.63      www      4161: }
1.59      www      4162: 
1.60      matthew  4163: ###############################################
                   4164: ###############################################
                   4165: 
                   4166: =pod
                   4167: 
1.112     bowersj2 4168: =back
                   4169: 
1.549     albertel 4170: =head1 HTML Helpers
1.112     bowersj2 4171: 
                   4172: =over 4
                   4173: 
                   4174: =item * &bodytag()
1.60      matthew  4175: 
                   4176: Returns a uniform header for LON-CAPA web pages.
                   4177: 
                   4178: Inputs: 
                   4179: 
1.112     bowersj2 4180: =over 4
                   4181: 
                   4182: =item * $title, A title to be displayed on the page.
                   4183: 
                   4184: =item * $function, the current role (can be undef).
                   4185: 
                   4186: =item * $addentries, extra parameters for the <body> tag.
                   4187: 
                   4188: =item * $bodyonly, if defined, only return the <body> tag.
                   4189: 
                   4190: =item * $domain, if defined, force a given domain.
                   4191: 
                   4192: =item * $forcereg, if page should register as content page (relevant for 
1.86      www      4193:             text interface only)
1.60      matthew  4194: 
1.326     albertel 4195: =item * $customtitle, alternate text to use instead of $title
                   4196:                       in the title box that appears, this text
                   4197:                       is not auto translated like the $title is
1.309     albertel 4198: 
                   4199: =item * $notopbar, if true, keep the 'what is this' info but remove the
                   4200:                    navigational links
1.317     albertel 4201: 
1.338     albertel 4202: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
                   4203: 
                   4204: =item * $notitle, if true keep the nav controls, but remove the title bar
                   4205: 
1.361     albertel 4206: =item * $no_inline_link, if true and in remote mode, don't show the 
                   4207:          'Switch To Inline Menu' link
                   4208: 
1.460     albertel 4209: =item * $args, optional argument valid values are
                   4210:             no_auto_mt_title -> prevents &mt()ing the title arg
1.562     albertel 4211:             inherit_jsmath -> when creating popup window in a page,
                   4212:                               should it have jsmath forced on by the
                   4213:                               current page
1.460     albertel 4214: 
1.112     bowersj2 4215: =back
                   4216: 
1.60      matthew  4217: Returns: A uniform header for LON-CAPA web pages.  
                   4218: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
                   4219: If $bodyonly is undef or zero, an html string containing a <body> tag and 
                   4220: other decorations will be returned.
                   4221: 
                   4222: =cut
                   4223: 
1.54      www      4224: sub bodytag {
1.309     albertel 4225:     my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,$customtitle,
1.460     albertel 4226: 	$notopbar,$bgcolor,$notitle,$no_inline_link,$args)=@_;
1.339     albertel 4227: 
1.460     albertel 4228:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339     albertel 4229: 
1.183     matthew  4230:     $function = &get_users_function() if (!$function);
1.339     albertel 4231:     my $img =    &designparm($function.'.img',$domain);
                   4232:     my $font =   &designparm($function.'.font',$domain);
                   4233:     my $pgbg   = $bgcolor || &designparm($function.'.pgbg',$domain);
                   4234: 
                   4235:     my %design = ( 'style'   => 'margin-top: 0px',
1.535     albertel 4236: 		   'bgcolor' => $pgbg,
1.339     albertel 4237: 		   'text'    => $font,
                   4238:                    'alink'   => &designparm($function.'.alink',$domain),
                   4239: 		   'vlink'   => &designparm($function.'.vlink',$domain),
                   4240: 		   'link'    => &designparm($function.'.link',$domain),);
1.438     albertel 4241:     @design{keys(%$addentries)} = @$addentries{keys(%$addentries)}; 
1.339     albertel 4242: 
1.63      www      4243:  # role and realm
1.378     raeburn  4244:     my ($role,$realm) = split(/\./,$env{'request.role'},2);
                   4245:     if ($role  eq 'ca') {
1.479     albertel 4246:         my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500     albertel 4247:         $realm = &plainname($rname,$rdom);
1.378     raeburn  4248:     } 
1.55      www      4249: # realm
1.258     albertel 4250:     if ($env{'request.course.id'}) {
1.378     raeburn  4251:         if ($env{'request.role'} !~ /^cr/) {
                   4252:             $role = &Apache::lonnet::plaintext($role,&course_type());
                   4253:         }
1.359     albertel 4254: 	$realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378     raeburn  4255:     } else {
                   4256:         $role = &Apache::lonnet::plaintext($role);
1.54      www      4257:     }
1.433     albertel 4258: 
1.359     albertel 4259:     if (!$realm) { $realm='&nbsp;'; }
1.55      www      4260: # Set messages
1.60      matthew  4261:     my $messages=&domainlogo($domain);
1.330     albertel 4262: 
1.438     albertel 4263:     my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329     albertel 4264: 
1.101     www      4265: # construct main body tag
1.359     albertel 4266:     my $bodytag = "<body $extra_body_attr>".
1.562     albertel 4267: 	&Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252     albertel 4268: 
1.530     albertel 4269:     if ($bodyonly) {
1.60      matthew  4270:         return $bodytag;
1.258     albertel 4271:     } elsif ($env{'browser.interface'} eq 'textual') {
1.95      www      4272: # Accessibility
1.224     raeburn  4273:           
1.337     albertel 4274: 	$bodytag.=&Apache::lonmenu::menubuttons($forcereg,$forcereg);
1.338     albertel 4275: 	if (!$notitle) {
1.337     albertel 4276: 	    $bodytag.='<h1>LON-CAPA: '.$title.'</h1>';
                   4277: 	}
                   4278: 	return $bodytag;
1.359     albertel 4279:     }
                   4280: 
1.410     albertel 4281:     my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.433     albertel 4282:     if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
                   4283: 	undef($role);
1.434     albertel 4284:     } else {
                   4285: 	$name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433     albertel 4286:     }
1.359     albertel 4287:     
                   4288:     my $roleinfo=(<<ENDROLE);
                   4289: <td class="LC_title_bar_who">
                   4290: <div class="LC_title_bar_name">
1.410     albertel 4291:     $name
1.361     albertel 4292:     &nbsp;
1.359     albertel 4293: </div>
                   4294: <div class="LC_title_bar_role">
1.361     albertel 4295: $role&nbsp;
1.359     albertel 4296: </div>
                   4297: <div class="LC_title_bar_realm">
1.361     albertel 4298: $realm&nbsp;
1.359     albertel 4299: </div>
1.206     albertel 4300: </td>
                   4301: ENDROLE
1.235     raeburn  4302: 
1.762     bisitz   4303:     my $titleinfo = '<h1>'.$title.'</h1>';
1.359     albertel 4304:     if ($customtitle) {
                   4305:         $titleinfo = $customtitle;
                   4306:     }
                   4307:     #
                   4308:     # Extra info if you are the DC
                   4309:     my $dc_info = '';
                   4310:     if ($env{'user.adv'} && exists($env{'user.role.dc./'.
                   4311:                         $env{'course.'.$env{'request.course.id'}.
                   4312:                                  '.domain'}.'/'})) {
                   4313:         my $cid = $env{'request.course.id'};
                   4314:         $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380     www      4315:         $dc_info =~ s/\s+$//;
1.359     albertel 4316:         $dc_info = '('.$dc_info.')';
                   4317:     }
                   4318: 
1.644     www      4319:     if (($env{'environment.remote'} eq 'off') || ($args->{'suppress_header_logos'})) {
1.359     albertel 4320:         # No Remote
1.258     albertel 4321: 	if ($env{'request.state'} eq 'construct') {
1.359     albertel 4322: 	    $forcereg=1;
                   4323: 	}
                   4324: 
                   4325: 	if (!$customtitle && $env{'request.state'} eq 'construct') {
                   4326: 	    # this is for resources; directories have customtitle, and crumbs
                   4327:             # and select recent are created in lonpubdir.pm  
1.229     albertel 4328: 	    my ($uname,$thisdisfn)=
1.258     albertel 4329: 		($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
1.229     albertel 4330: 	    my $formaction='/priv/'.$uname.'/'.$thisdisfn;
                   4331: 	    $formaction=~s/\/+/\//g;
                   4332: 
1.359     albertel 4333: 	    my $parentpath = '';
                   4334: 	    my $lastitem = '';
                   4335: 	    if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
                   4336: 		$parentpath = $1;
                   4337: 		$lastitem = $2;
                   4338: 	    } else {
                   4339: 		$lastitem = $thisdisfn;
                   4340: 	    }
                   4341: 	    $titleinfo = 
1.640     bisitz   4342: 		&Apache::loncommon::help_open_menu('','',3,'Authoring')
                   4343: 		.'<b>'.&mt('Construction Space').'</b>:&nbsp;'
                   4344: 		.'<form name="dirs" method="post" action="'.$formaction
1.359     albertel 4345: 		.'" target="_top"><tt><b>'
1.705     tempelho 4346: 		.&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."<span class=\"LC_fontsize_big\">$lastitem</span></b></tt><br />"
1.359     albertel 4347: 		.&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
                   4348: 		.'</form>'
                   4349: 		.&Apache::lonmenu::constspaceform();
1.235     raeburn  4350:         }
1.359     albertel 4351: 
1.337     albertel 4352:         my $titletable;
1.338     albertel 4353: 	if (!$notitle) {
1.337     albertel 4354: 	    $titletable =
1.359     albertel 4355: 		'<table id="LC_title_bar">'.
                   4356:                          "<tr><td> $titleinfo $dc_info</td>".$roleinfo.
                   4357: 			 '</tr></table>';
1.337     albertel 4358: 	}
1.359     albertel 4359: 	if ($notopbar) {
                   4360: 	    $bodytag .= $titletable;
                   4361: 	} else {
                   4362: 	    if ($env{'request.state'} eq 'construct') {
1.337     albertel 4363:                 $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg,
                   4364: 							  $titletable);
1.272     raeburn  4365:             } else {
1.336     albertel 4366:                 $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg).
1.359     albertel 4367: 		    $titletable;
1.272     raeburn  4368:             }
1.235     raeburn  4369:         }
                   4370:         return $bodytag;
1.94      www      4371:     }
1.95      www      4372: 
1.93      www      4373: #
1.95      www      4374: # Top frame rendering, Remote is up
1.93      www      4375: #
1.359     albertel 4376: 
1.517     raeburn  4377:     my $imgsrc = $img;
                   4378:     if ($img =~ /^\/adm/) {
1.575     albertel 4379:         $imgsrc = &lonhttpdurl($img);
1.517     raeburn  4380:     }
                   4381:     my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359     albertel 4382: 
1.305     www      4383:     # Explicit link to get inline menu
1.361     albertel 4384:     my $menu= ($no_inline_link?''
                   4385: 	       :'<br /><a href="/adm/remote?action=collapse">'.&mt('Switch to Inline Menu Mode').'</a>');
1.245     matthew  4386:     #
1.338     albertel 4387:     if ($notitle) {
1.337     albertel 4388: 	return $bodytag;
                   4389:     }
1.94      www      4390:     return(<<ENDBODY);
1.60      matthew  4391: $bodytag
1.359     albertel 4392: <table id="LC_title_bar" class="LC_with_remote">
1.791     tempelho 4393: <tr><td>$upperleft</td>
                   4394:     <td>$messages&nbsp;</td>
1.54      www      4395: </tr>
1.359     albertel 4396: <tr><td>$titleinfo $dc_info $menu</td>
                   4397: $roleinfo
1.368     albertel 4398: </tr>
1.356     albertel 4399: </table>
1.54      www      4400: ENDBODY
1.182     matthew  4401: }
                   4402: 
1.330     albertel 4403: sub make_attr_string {
                   4404:     my ($register,$attr_ref) = @_;
                   4405: 
                   4406:     if ($attr_ref && !ref($attr_ref)) {
                   4407: 	die("addentries Must be a hash ref ".
                   4408: 	    join(':',caller(1))." ".
                   4409: 	    join(':',caller(0))." ");
                   4410:     }
                   4411: 
                   4412:     if ($register) {
1.339     albertel 4413: 	my ($on_load,$on_unload);
                   4414: 	foreach my $key (keys(%{$attr_ref})) {
                   4415: 	    if      (lc($key) eq 'onload') {
                   4416: 		$on_load.=$attr_ref->{$key}.';';
                   4417: 		delete($attr_ref->{$key});
                   4418: 
                   4419: 	    } elsif (lc($key) eq 'onunload') {
                   4420: 		$on_unload.=$attr_ref->{$key}.';';
                   4421: 		delete($attr_ref->{$key});
                   4422: 	    }
                   4423: 	}
                   4424: 	$attr_ref->{'onload'}  =
                   4425: 	    &Apache::lonmenu::loadevents().  $on_load;
                   4426: 	$attr_ref->{'onunload'}=
                   4427: 	    &Apache::lonmenu::unloadevents().$on_unload;
                   4428:     }
                   4429: 
                   4430: # Accessibility font enhance
                   4431:     if ($env{'browser.fontenhance'} eq 'on') {
                   4432: 	my $style;
                   4433: 	foreach my $key (keys(%{$attr_ref})) {
                   4434: 	    if (lc($key) eq 'style') {
                   4435: 		$style.=$attr_ref->{$key}.';';
                   4436: 		delete($attr_ref->{$key});
                   4437: 	    }
                   4438: 	}
                   4439: 	$attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330     albertel 4440:     }
1.339     albertel 4441: 
                   4442:     if ($env{'browser.blackwhite'} eq 'on') {
                   4443: 	delete($attr_ref->{'font'});
                   4444: 	delete($attr_ref->{'link'});
                   4445: 	delete($attr_ref->{'alink'});
                   4446: 	delete($attr_ref->{'vlink'});
                   4447: 	delete($attr_ref->{'bgcolor'});
                   4448: 	delete($attr_ref->{'background'});
                   4449:     }
                   4450: 
1.330     albertel 4451:     my $attr_string;
                   4452:     foreach my $attr (keys(%$attr_ref)) {
                   4453: 	$attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
                   4454:     }
                   4455:     return $attr_string;
                   4456: }
                   4457: 
                   4458: 
1.182     matthew  4459: ###############################################
1.251     albertel 4460: ###############################################
                   4461: 
                   4462: =pod
                   4463: 
                   4464: =item * &endbodytag()
                   4465: 
                   4466: Returns a uniform footer for LON-CAPA web pages.
                   4467: 
1.635     raeburn  4468: Inputs: 1 - optional reference to an args hash
                   4469: If in the hash, key for noredirectlink has a value which evaluates to true,
                   4470: a 'Continue' link is not displayed if the page contains an
                   4471: internal redirect in the <head></head> section,
                   4472: i.e., $env{'internal.head.redirect'} exists   
1.251     albertel 4473: 
                   4474: =cut
                   4475: 
                   4476: sub endbodytag {
1.635     raeburn  4477:     my ($args) = @_;
1.251     albertel 4478:     my $endbodytag='</body>';
1.269     albertel 4479:     $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315     albertel 4480:     if ( exists( $env{'internal.head.redirect'} ) ) {
1.635     raeburn  4481:         if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
                   4482: 	    $endbodytag=
                   4483: 	        "<br /><a href=\"$env{'internal.head.redirect'}\">".
                   4484: 	        &mt('Continue').'</a>'.
                   4485: 	        $endbodytag;
                   4486:         }
1.315     albertel 4487:     }
1.251     albertel 4488:     return $endbodytag;
                   4489: }
                   4490: 
1.352     albertel 4491: =pod
                   4492: 
                   4493: =item * &standard_css()
                   4494: 
                   4495: Returns a style sheet
                   4496: 
                   4497: Inputs: (all optional)
                   4498:             domain         -> force to color decorate a page for a specific
                   4499:                                domain
                   4500:             function       -> force usage of a specific rolish color scheme
                   4501:             bgcolor        -> override the default page bgcolor
                   4502: 
                   4503: =cut
                   4504: 
1.343     albertel 4505: sub standard_css {
1.345     albertel 4506:     my ($function,$domain,$bgcolor) = @_;
1.352     albertel 4507:     $function  = &get_users_function() if (!$function);
                   4508:     my $img    = &designparm($function.'.img',   $domain);
                   4509:     my $tabbg  = &designparm($function.'.tabbg', $domain);
                   4510:     my $font   = &designparm($function.'.font',  $domain);
1.791     tempelho 4511: #second colour for later usage
1.345     albertel 4512:     my $sidebg = &designparm($function.'.sidebg',$domain);
1.382     albertel 4513:     my $pgbg_or_bgcolor =
                   4514: 	         $bgcolor ||
1.352     albertel 4515: 	         &designparm($function.'.pgbg',  $domain);
1.382     albertel 4516:     my $pgbg   = &designparm($function.'.pgbg',  $domain);
1.352     albertel 4517:     my $alink  = &designparm($function.'.alink', $domain);
                   4518:     my $vlink  = &designparm($function.'.vlink', $domain);
                   4519:     my $link   = &designparm($function.'.link',  $domain);
                   4520: 
1.704     muellerd 4521:     my $loginbg = &designparm('login.sidebg',$domain);
1.712     muellerd 4522:     my $bgcol = &designparm('login.bgcol',$domain);
                   4523:     my $textcol = &designparm('login.textcol',$domain);
1.704     muellerd 4524: 
1.602     albertel 4525:     my $sans                 = 'Verdana,Arial,Helvetica,sans-serif';
1.395     albertel 4526:     my $mono                 = 'monospace';
1.352     albertel 4527:     my $data_table_head      = $tabbg;
                   4528:     my $data_table_light     = '#EEEEEE';
1.470     banghart 4529:     my $data_table_dark      = '#DDDDDD';
                   4530:     my $data_table_darker    = '#CCCCCC';
1.349     albertel 4531:     my $data_table_highlight = '#FFFF00';
1.352     albertel 4532:     my $mail_new             = '#FFBB77';
                   4533:     my $mail_new_hover       = '#DD9955';
                   4534:     my $mail_read            = '#BBBB77';
                   4535:     my $mail_read_hover      = '#999944';
                   4536:     my $mail_replied         = '#AAAA88';
                   4537:     my $mail_replied_hover   = '#888855';
                   4538:     my $mail_other           = '#99BBBB';
                   4539:     my $mail_other_hover     = '#669999';
1.391     albertel 4540:     my $table_header         = '#DDDDDD';
1.489     raeburn  4541:     my $feedback_link_bg     = '#BBBBBB';
1.701     harmsja  4542:     my $lg_border_color	     = '#C8C8C8';
1.392     albertel 4543: 
1.608     albertel 4544:     my $border = ($env{'browser.type'} eq 'explorer' ||
                   4545: 		  $env{'browser.type'} eq 'safari'     ) ? '0px 2px 0px 2px'
                   4546: 	                                                 : '0px 3px 0px 4px';
1.448     albertel 4547: 
1.523     albertel 4548: 
1.343     albertel 4549:     return <<END;
1.698     harmsja  4550: body{
                   4551:      font-family: $sans;
                   4552:      line-height:130%;
1.701     harmsja  4553:      font-size:0.83em;
1.698     harmsja  4554:      color:$font;
                   4555:   }
1.701     harmsja  4556: a:link, a:visited { font-size:100%; }
1.698     harmsja  4557: 
1.779     bisitz   4558: a:focus { color: red; background: yellow }
1.510     albertel 4559: table.thinborder,
                   4560: table.thinborder tr th {
                   4561:   border-style: solid;
                   4562:   border-width: 1px;
1.698     harmsja  4563:   border-color: $lg_border_color;
1.510     albertel 4564:   background: $tabbg;
                   4565: }
1.523     albertel 4566: table.thinborder tr td {
1.510     albertel 4567:   border-style: solid;
1.698     harmsja  4568:   border-width: 1px;
                   4569:   border-color: $lg_border_color;
1.510     albertel 4570: }
1.426     albertel 4571: 
1.343     albertel 4572: form, .inline { display: inline; }
1.721     harmsja  4573: 
                   4574: .LC_right {text-align:right;}
                   4575: .LC_middle {vertical-align:middle;}
                   4576: 
                   4577: /* just for tests */
1.754     droeschl 4578: .LC_400Box {width:400px; }
1.721     harmsja  4579: /* end */
                   4580: 
1.778     bisitz   4581: .LC_filename {
                   4582:   font-family: $mono;
                   4583:   white-space:pre;
                   4584: }
                   4585: 
                   4586: .LC_fileicon {
                   4587:   border: none;
                   4588:   height: 1.3em;
                   4589:   vertical-align: text-bottom;
                   4590:   margin-right: 0.3em;
                   4591:   text-decoration:none;
                   4592: }
                   4593: 
1.350     albertel 4594: .LC_error {
                   4595:   color: red;
                   4596:   font-size: larger;
                   4597: }
1.457     albertel 4598: .LC_warning,
                   4599: .LC_diff_removed {
1.733     bisitz   4600:   color: red;
1.394     albertel 4601: }
1.532     albertel 4602: 
                   4603: .LC_info,
1.457     albertel 4604: .LC_success,
                   4605: .LC_diff_added {
1.350     albertel 4606:   color: green;
                   4607: }
1.543     albertel 4608: .LC_unknown {
                   4609:   color: yellow;
                   4610: }
                   4611: 
1.440     albertel 4612: .LC_icon {
1.771     droeschl 4613:   border: none;
1.790     droeschl 4614:   vertical-align: middle;
1.771     droeschl 4615: }
                   4616: 
1.539     albertel 4617: .LC_indexer_icon {
                   4618:   border: 0px;
                   4619:   height: 22px;
                   4620: }
1.543     albertel 4621: .LC_docs_spacer {
                   4622:   width: 25px;
                   4623:   height: 1px;
1.771     droeschl 4624:   border: none;
1.543     albertel 4625: }
1.346     albertel 4626: 
1.532     albertel 4627: .LC_internal_info {
1.735     bisitz   4628:   color: #999999;
1.532     albertel 4629: }
                   4630: 
1.794   ! www      4631: .LC_discussion {
        !          4632:    background: $tabbg;
        !          4633:    border: 1px solid black;
        !          4634:    margin: 2px;
        !          4635: }
        !          4636: 
        !          4637: .LC_disc_action_links_bar {
        !          4638:    background: $tabbg;
        !          4639:    font-family: $sans;
        !          4640:    border: 0px;
        !          4641:    margin: 2px;
        !          4642: }
        !          4643: 
        !          4644: .LC_disc_action_left {
        !          4645:    text-align: left;
        !          4646: }
        !          4647: 
        !          4648: .LC_disc_action_right {
        !          4649:    text-align: right;
        !          4650: }
        !          4651: 
        !          4652: .LC_disc_new_item {
        !          4653:    background: white;
        !          4654:    border: 2px solid red;
        !          4655:    margin: 2px;
        !          4656: }
        !          4657: 
        !          4658: .LC_disc_old_item {
        !          4659:    background: white;
        !          4660:    border: 1px solid black;
        !          4661:    margin: 2px;
        !          4662: }
        !          4663: 
1.458     albertel 4664: table.LC_pastsubmission {
                   4665:   border: 1px solid black;
                   4666:   margin: 2px;
                   4667: }
                   4668: 
1.606     albertel 4669: table#LC_top_nav, table#LC_menubuttons,table#LC_nav_location {
1.345     albertel 4670:   width: 100%;
                   4671:   background: $pgbg;
1.392     albertel 4672:   border: 2px;
1.402     albertel 4673:   border-collapse: separate;
1.403     albertel 4674:   padding: 0px;
1.345     albertel 4675: }
1.392     albertel 4676: 
1.779     bisitz   4677: table#LC_title_bar, table.LC_breadcrumbs,
1.393     albertel 4678: table#LC_title_bar.LC_with_remote {
1.359     albertel 4679:   width: 100%;
1.392     albertel 4680:   border-color: $pgbg;
                   4681:   border-style: solid;
                   4682:   border-width: $border;
                   4683: 
1.379     albertel 4684:   background: $pgbg;
                   4685:   font-family: $sans;
1.392     albertel 4686:   border-collapse: collapse;
1.403     albertel 4687:   padding: 0px;
1.359     albertel 4688: }
1.409     albertel 4689: table.LC_docs_path {
                   4690:   width: 100%;
                   4691:   border: 0;
                   4692:   background: $pgbg;
                   4693:   font-family: $sans;
                   4694:   border-collapse: collapse;
                   4695:   padding: 0px;
                   4696: }
                   4697: 
1.359     albertel 4698: table#LC_title_bar td {
                   4699:   background: $tabbg;
                   4700: }
1.773     ehlerst  4701: table#LC_title_bar .LC_title_bar_who {
1.359     albertel 4702:   background: $tabbg;
                   4703:   color: $font;
1.427     albertel 4704:   font: small $sans;
1.359     albertel 4705:   text-align: right;
1.773     ehlerst  4706:   margin: 0px;
                   4707: }
                   4708: table#LC_title_bar .LC_title_bar_name {
                   4709:   margin: 0px;
                   4710: }
                   4711: table#LC_title_bar .LC_title_bar_role {
                   4712:   margin: 0px;
                   4713: }
1.775     bisitz   4714: table#LC_title_bar .LC_title_bar_realm {
1.773     ehlerst  4715:   margin: 0px;
1.359     albertel 4716: }
1.469     banghart 4717: span.LC_metadata {
                   4718:     font-family: $sans;
                   4719: }
1.359     albertel 4720: 
1.706     harmsja  4721: table#LC_menubuttons img{
1.346     albertel 4722:   border: 0px;
                   4723: }
1.345     albertel 4724: table#LC_top_nav td {
                   4725:   background: $tabbg;
1.392     albertel 4726:   border: 0px;
1.407     albertel 4727:   font-size: small;
1.706     harmsja  4728:   vertical-align:top;
                   4729:   padding:2px 5px 2px 5px;
1.345     albertel 4730: }
                   4731: table#LC_top_nav td a, div#LC_top_nav a {
                   4732:   color: $font;
                   4733:   font-family: $sans;
                   4734: }
1.364     albertel 4735: table#LC_top_nav td.LC_top_nav_logo {
                   4736:   background: $tabbg;
1.432     albertel 4737:   text-align: left;
1.408     albertel 4738:   white-space: nowrap;
1.432     albertel 4739:   width: 31px;
1.408     albertel 4740: }
                   4741: table#LC_top_nav td.LC_top_nav_logo img {
1.432     albertel 4742:   border: 0px;
1.408     albertel 4743:   vertical-align: bottom;
1.364     albertel 4744: }
1.777     tempelho 4745: table#LC_top_nav td.LC_top_nav_exit,
1.779     bisitz   4746: table#LC_top_nav td.LC_top_nav_help {
1.777     tempelho 4747:   width: 2.0em;
                   4748: }
1.442     albertel 4749: table#LC_top_nav td.LC_top_nav_login {
                   4750:   width: 4.0em;
                   4751:   text-align: center;
                   4752: }
1.409     albertel 4753: table.LC_breadcrumbs td, table.LC_docs_path td  {
1.357     albertel 4754:   background: $tabbg;
                   4755:   color: $font;
                   4756:   font-family: $sans;
1.358     albertel 4757:   font-size: smaller;
1.357     albertel 4758: }
1.777     tempelho 4759: table.LC_breadcrumbs td.LC_breadcrumbs_component,
                   4760: table.LC_docs_path td.LC_docs_path_component {
1.779     bisitz   4761:   background: $tabbg;
1.777     tempelho 4762:   color: $font;
                   4763:   font-family: $sans;
1.779     bisitz   4764:   font-size: larger;
                   4765:   text-align: right;
1.777     tempelho 4766: }
1.383     albertel 4767: td.LC_table_cell_checkbox {
                   4768:   text-align: center;
                   4769: }
1.779     bisitz   4770: table#LC_mainmenu td.LC_mainmenu_column {
                   4771:     vertical-align: top;
1.777     tempelho 4772: }
1.522     albertel 4773: 
1.705     tempelho 4774: .LC_fontsize_small
                   4775: {
                   4776:  font-size: 70%;
                   4777: }
                   4778: 
                   4779: .LC_fontsize_medium
                   4780: {
                   4781:  font-size: 85%;
                   4782: }
                   4783: 
                   4784: .LC_fontsize_large
                   4785: {
                   4786:  font-size: 120%;
                   4787: }
                   4788: 
1.346     albertel 4789: .LC_menubuttons_inline_text {
                   4790:   color: $font;
                   4791:   font-family: $sans;
1.698     harmsja  4792:   font-size: 90%;
1.701     harmsja  4793:   padding-left:3px;
1.346     albertel 4794: }
                   4795: 
1.526     www      4796: .LC_menubuttons_link {
                   4797:   text-decoration: none;
                   4798: }
1.698     harmsja  4799: /*2008--9-5: new menu style sheet.Changed category*/
1.522     albertel 4800: .LC_menubuttons_category {
1.521     www      4801:   color: $font;
1.526     www      4802:   background: $pgbg;
1.521     www      4803:   font-family: $sans;
                   4804:   font-size: larger;
                   4805:   font-weight: bold;
                   4806: }
                   4807: 
1.346     albertel 4808: td.LC_menubuttons_text {
1.779     bisitz   4809:  	color: $font;
1.346     albertel 4810: }
1.706     harmsja  4811: 
                   4812: 
1.526     www      4813: 
1.346     albertel 4814: .LC_current_location {
                   4815:   font-family: $sans;
                   4816:   background: $tabbg;
                   4817: }
                   4818: .LC_new_mail {
                   4819:   font-family: $sans;
1.634     www      4820:   background: $tabbg;
1.346     albertel 4821:   font-weight: bold;
                   4822: }
1.347     albertel 4823: 
1.526     www      4824: 
1.527     www      4825: .LC_dropadd_labeltext {
                   4826:   font-family: $sans;
                   4827:   text-align: right;
                   4828: }
                   4829: 
                   4830: .LC_preferences_labeltext {
                   4831:   font-family: $sans;
                   4832:   text-align: right;
                   4833: }
                   4834: 
1.666     raeburn  4835: .LC_roleslog_note {
1.701     harmsja  4836:   font-size: small;
1.666     raeburn  4837: }
                   4838: 
1.715     raeburn  4839: .LC_mail_functions {
                   4840:     font-weight: bold;
                   4841: }
                   4842: 
1.440     albertel 4843: table.LC_aboutme_port {
                   4844:   border: 0px;
                   4845:   border-collapse: collapse;
                   4846:   border-spacing: 0px;
                   4847: }
1.349     albertel 4848: table.LC_data_table, table.LC_mail_list {
1.347     albertel 4849:   border: 1px solid #000000;
1.402     albertel 4850:   border-collapse: separate;
1.426     albertel 4851:   border-spacing: 1px;
1.610     albertel 4852:   background: $pgbg;
1.347     albertel 4853: }
1.422     albertel 4854: .LC_data_table_dense {
                   4855:   font-size: small;
                   4856: }
1.507     raeburn  4857: table.LC_nested_outer {
                   4858:   border: 1px solid #000000;
1.589     raeburn  4859:   border-collapse: collapse;
1.507     raeburn  4860:   border-spacing: 0px;
                   4861:   width: 100%;
                   4862: }
                   4863: table.LC_nested {
                   4864:   border: 0px;
1.589     raeburn  4865:   border-collapse: collapse;
1.507     raeburn  4866:   border-spacing: 0px;
                   4867:   width: 100%;
                   4868: }
1.523     albertel 4869: table.LC_data_table tr th, table.LC_calendar tr th, table.LC_mail_list tr th,
                   4870: table.LC_prior_tries tr th {
1.349     albertel 4871:   font-weight: bold;
                   4872:   background-color: $data_table_head;
1.701     harmsja  4873:   font-size:90%;
1.347     albertel 4874: }
1.711     raeburn  4875: table.LC_data_table tr.LC_info_row > td {
1.735     bisitz   4876:   background-color: #CCCCCC;
1.711     raeburn  4877:   font-weight: bold;
                   4878:   text-align: left;
                   4879: }
1.779     bisitz   4880: table.LC_data_table tr.LC_odd_row > td,
1.709     bisitz   4881: table.LC_pick_box tr > td.LC_odd_row,
1.440     albertel 4882: table.LC_aboutme_port tr td {
1.349     albertel 4883:   background-color: $data_table_light;
1.425     albertel 4884:   padding: 2px;
1.347     albertel 4885: }
1.610     albertel 4886: table.LC_data_table tr.LC_even_row > td,
1.709     bisitz   4887: table.LC_pick_box tr > td.LC_even_row,
1.440     albertel 4888: table.LC_aboutme_port tr.LC_even_row td {
1.349     albertel 4889:   background-color: $data_table_dark;
1.709     bisitz   4890:   padding: 2px;
1.347     albertel 4891: }
1.425     albertel 4892: table.LC_data_table tr.LC_data_table_highlight td {
                   4893:   background-color: $data_table_darker;
                   4894: }
1.639     raeburn  4895: table.LC_data_table tr td.LC_leftcol_header {
                   4896:   background-color: $data_table_head;
                   4897:   font-weight: bold;
                   4898: }
1.451     albertel 4899: table.LC_data_table tr.LC_empty_row td,
1.507     raeburn  4900: table.LC_nested tr.LC_empty_row td {
1.347     albertel 4901:   background-color: #FFFFFF;
1.421     albertel 4902:   font-weight: bold;
                   4903:   font-style: italic;
                   4904:   text-align: center;
                   4905:   padding: 8px;
1.347     albertel 4906: }
1.507     raeburn  4907: table.LC_nested tr.LC_empty_row td {
1.465     albertel 4908:   padding: 4ex
                   4909: }
1.507     raeburn  4910: table.LC_nested_outer tr th {
                   4911:   font-weight: bold;
                   4912:   background-color: $data_table_head;
1.701     harmsja  4913:   font-size: small;
1.507     raeburn  4914:   border-bottom: 1px solid #000000;
                   4915: }
                   4916: table.LC_nested_outer tr td.LC_subheader {
                   4917:   background-color: $data_table_head;
                   4918:   font-weight: bold;
                   4919:   font-size: small;
                   4920:   border-bottom: 1px solid #000000;
                   4921:   text-align: right;
1.451     albertel 4922: }
1.507     raeburn  4923: table.LC_nested tr.LC_info_row td {
1.735     bisitz   4924:   background-color: #CCCCCC;
1.451     albertel 4925:   font-weight: bold;
                   4926:   font-size: small;
1.507     raeburn  4927:   text-align: center;
                   4928: }
1.589     raeburn  4929: table.LC_nested tr.LC_info_row td.LC_left_item,
                   4930: table.LC_nested_outer tr th.LC_left_item {
1.507     raeburn  4931:   text-align: left;
1.451     albertel 4932: }
1.507     raeburn  4933: table.LC_nested td {
1.735     bisitz   4934:   background-color: #FFFFFF;
1.451     albertel 4935:   font-size: small;
1.507     raeburn  4936: }
                   4937: table.LC_nested_outer tr th.LC_right_item,
                   4938: table.LC_nested tr.LC_info_row td.LC_right_item,
                   4939: table.LC_nested tr.LC_odd_row td.LC_right_item,
                   4940: table.LC_nested tr td.LC_right_item {
1.451     albertel 4941:   text-align: right;
                   4942: }
                   4943: 
1.507     raeburn  4944: table.LC_nested tr.LC_odd_row td {
1.735     bisitz   4945:   background-color: #EEEEEE;
1.451     albertel 4946: }
                   4947: 
1.473     raeburn  4948: table.LC_createuser {
                   4949: }
                   4950: 
                   4951: table.LC_createuser tr.LC_section_row td {
1.701     harmsja  4952:   font-size: small;
1.473     raeburn  4953: }
                   4954: 
                   4955: table.LC_createuser tr.LC_info_row td  {
1.735     bisitz   4956:   background-color: #CCCCCC;
1.473     raeburn  4957:   font-weight: bold;
                   4958:   text-align: center;
                   4959: }
                   4960: 
1.349     albertel 4961: table.LC_calendar {
                   4962:   border: 1px solid #000000;
                   4963:   border-collapse: collapse;
                   4964: }
                   4965: table.LC_calendar_pickdate {
                   4966:   font-size: xx-small;
                   4967: }
                   4968: table.LC_calendar tr td {
                   4969:   border: 1px solid #000000;
                   4970:   vertical-align: top;
                   4971: }
                   4972: table.LC_calendar tr td.LC_calendar_day_empty {
                   4973:   background-color: $data_table_dark;
                   4974: }
1.779     bisitz   4975: table.LC_calendar tr td.LC_calendar_day_current {
                   4976:   background-color: $data_table_highlight;
1.777     tempelho 4977: }
1.349     albertel 4978: table.LC_mail_list tr.LC_mail_new {
                   4979:   background-color: $mail_new;
                   4980: }
                   4981: table.LC_mail_list tr.LC_mail_new:hover {
                   4982:   background-color: $mail_new_hover;
                   4983: }
1.777     tempelho 4984: table.LC_mail_list tr.LC_mail_even{
                   4985: }
                   4986: table.LC_mail_list tr.LC_mail_odd{
                   4987: }
1.349     albertel 4988: table.LC_mail_list tr.LC_mail_read {
                   4989:   background-color: $mail_read;
                   4990: }
                   4991: table.LC_mail_list tr.LC_mail_read:hover {
                   4992:   background-color: $mail_read_hover;
                   4993: }
                   4994: table.LC_mail_list tr.LC_mail_replied {
                   4995:   background-color: $mail_replied;
                   4996: }
                   4997: table.LC_mail_list tr.LC_mail_replied:hover {
                   4998:   background-color: $mail_replied_hover;
                   4999: }
                   5000: table.LC_mail_list tr.LC_mail_other {
                   5001:   background-color: $mail_other;
                   5002: }
                   5003: table.LC_mail_list tr.LC_mail_other:hover {
                   5004:   background-color: $mail_other_hover;
                   5005: }
1.494     raeburn  5006: 
1.777     tempelho 5007: table.LC_data_table tr > td.LC_browser_file,
                   5008: table.LC_data_table tr > td.LC_browser_file_published {
1.389     albertel 5009:   background: #CCFF88;
                   5010: }
1.777     tempelho 5011: table.LC_data_table tr > td.LC_browser_file_locked,
                   5012: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389     albertel 5013:   background: #FFAA99;
1.387     albertel 5014: }
1.777     tempelho 5015: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.779     bisitz   5016:   background: #AAAAAA;
                   5017: }
1.777     tempelho 5018: table.LC_data_table tr > td.LC_browser_file_modified,
1.779     bisitz   5019: table.LC_data_table tr > td.LC_browser_file_metamodified {
                   5020:   background: #FFFF77;
1.777     tempelho 5021: }
1.696     bisitz   5022: table.LC_data_table tr.LC_browser_folder > td {
1.389     albertel 5023:   background: #CCCCFF;
1.387     albertel 5024: }
1.696     bisitz   5025: 
1.707     bisitz   5026: table.LC_data_table tr > td.LC_roles_is {
                   5027: /*  background: #77FF77; */
                   5028: }
                   5029: table.LC_data_table tr > td.LC_roles_future {
                   5030:   background: #FFFF77;
                   5031: }
                   5032: table.LC_data_table tr > td.LC_roles_will {
                   5033:   background: #FFAA77;
                   5034: }
                   5035: table.LC_data_table tr > td.LC_roles_expired {
                   5036:   background: #FF7777;
                   5037: }
                   5038: table.LC_data_table tr > td.LC_roles_will_not {
                   5039:   background: #AAFF77;
                   5040: }
                   5041: table.LC_data_table tr > td.LC_roles_selected {
                   5042:   background: #11CC55;
                   5043: }
                   5044: 
1.388     albertel 5045: span.LC_current_location {
1.701     harmsja  5046:   font-size:larger;
1.388     albertel 5047:   background: $pgbg;
                   5048: }
1.387     albertel 5049: 
1.395     albertel 5050: span.LC_parm_menu_item {
                   5051:   font-size: larger;
                   5052:   font-family: $sans;
                   5053: }
                   5054: span.LC_parm_scope_all {
                   5055:   color: red;
                   5056: }
                   5057: span.LC_parm_scope_folder {
                   5058:   color: green;
                   5059: }
                   5060: span.LC_parm_scope_resource {
                   5061:   color: orange;
                   5062: }
                   5063: span.LC_parm_part {
                   5064:   color: blue;
                   5065: }
                   5066: span.LC_parm_folder, span.LC_parm_symb {
                   5067:   font-size: x-small;
                   5068:   font-family: $mono;
                   5069:   color: #AAAAAA;
                   5070: }
                   5071: 
1.396     albertel 5072: td.LC_parm_overview_level_menu, td.LC_parm_overview_map_menu,
1.777     tempelho 5073: td.LC_parm_overview_parm_selectors,td.LC_parm_overview_restrictions  {
1.396     albertel 5074:   border: 1px solid black;
                   5075:   border-collapse: collapse;
                   5076: }
                   5077: table.LC_parm_overview_restrictions td {
                   5078:   border-width: 1px 4px 1px 4px;
                   5079:   border-style: solid;
                   5080:   border-color: $pgbg;
                   5081:   text-align: center;
                   5082: }
                   5083: table.LC_parm_overview_restrictions th {
                   5084:   background: $tabbg;
                   5085:   border-width: 1px 4px 1px 4px;
                   5086:   border-style: solid;
                   5087:   border-color: $pgbg;
                   5088: }
1.398     albertel 5089: table#LC_helpmenu {
                   5090:   border: 0px;
                   5091:   height: 55px;
                   5092:   border-spacing: 0px;
                   5093: }
                   5094: 
                   5095: table#LC_helpmenu fieldset legend {
                   5096:   font-size: larger;
                   5097:   font-weight: bold;
                   5098: }
1.397     albertel 5099: table#LC_helpmenu_links {
                   5100:   width: 100%;
                   5101:   border: 1px solid black;
                   5102:   background: $pgbg;
                   5103:   padding: 0px;
                   5104:   border-spacing: 1px;
                   5105: }
                   5106: table#LC_helpmenu_links tr td {
                   5107:   padding: 1px;
                   5108:   background: $tabbg;
1.399     albertel 5109:   text-align: center;
                   5110:   font-weight: bold;
1.397     albertel 5111: }
1.396     albertel 5112: 
1.397     albertel 5113: table#LC_helpmenu_links a:link, table#LC_helpmenu_links a:visited,
                   5114: table#LC_helpmenu_links a:active {
                   5115:   text-decoration: none;
                   5116:   color: $font;
                   5117: }
                   5118: table#LC_helpmenu_links a:hover {
                   5119:   text-decoration: underline;
                   5120:   color: $vlink;
                   5121: }
1.396     albertel 5122: 
1.417     albertel 5123: .LC_chrt_popup_exists {
                   5124:   border: 1px solid #339933;
                   5125:   margin: -1px;
                   5126: }
                   5127: .LC_chrt_popup_up {
                   5128:   border: 1px solid yellow;
                   5129:   margin: -1px;
                   5130: }
                   5131: .LC_chrt_popup {
                   5132:   border: 1px solid #8888FF;
                   5133:   background: #CCCCFF;
                   5134: }
1.421     albertel 5135: table.LC_pick_box {
                   5136:   border-collapse: separate;
                   5137:   background: white;
                   5138:   border: 1px solid black;
                   5139:   border-spacing: 1px;
                   5140: }
                   5141: table.LC_pick_box td.LC_pick_box_title {
                   5142:   background: $tabbg;
                   5143:   font-weight: bold;
                   5144:   text-align: right;
1.740     bisitz   5145:   vertical-align: top;
1.421     albertel 5146:   width: 184px;
                   5147:   padding: 8px;
                   5148: }
1.645     raeburn  5149: table.LC_pick_box td.LC_selfenroll_pick_box_title {
                   5150:   background: $tabbg;
                   5151:   font-weight: bold;
                   5152:   text-align: right;
                   5153:   width: 350px;
                   5154:   padding: 8px;
                   5155: }
                   5156: 
1.579     raeburn  5157: table.LC_pick_box td.LC_pick_box_value {
                   5158:   text-align: left;
                   5159:   padding: 8px;
                   5160: }
                   5161: table.LC_pick_box td.LC_pick_box_select {
                   5162:   text-align: left;
                   5163:   padding: 8px;
                   5164: }
1.424     albertel 5165: table.LC_pick_box td.LC_pick_box_separator {
1.421     albertel 5166:   padding: 0px;
                   5167:   height: 1px;
                   5168:   background: black;
                   5169: }
                   5170: table.LC_pick_box td.LC_pick_box_submit {
                   5171:   text-align: right;
                   5172: }
1.579     raeburn  5173: table.LC_pick_box td.LC_evenrow_value {
                   5174:   text-align: left;
                   5175:   padding: 8px;
                   5176:   background-color: $data_table_light;
                   5177: }
                   5178: table.LC_pick_box td.LC_oddrow_value {
                   5179:   text-align: left;
                   5180:   padding: 8px;
                   5181:   background-color: $data_table_light;
                   5182: }
                   5183: table.LC_helpform_receipt {
                   5184:   width: 620px;
                   5185:   border-collapse: separate;
                   5186:   background: white;
                   5187:   border: 1px solid black;
                   5188:   border-spacing: 1px;
                   5189: }
                   5190: table.LC_helpform_receipt td.LC_pick_box_title {
                   5191:   background: $tabbg;
                   5192:   font-weight: bold;
                   5193:   text-align: right;
                   5194:   width: 184px;
                   5195:   padding: 8px;
                   5196: }
                   5197: table.LC_helpform_receipt td.LC_evenrow_value {
                   5198:   text-align: left;
                   5199:   padding: 8px;
                   5200:   background-color: $data_table_light;
                   5201: }
                   5202: table.LC_helpform_receipt td.LC_oddrow_value {
                   5203:   text-align: left;
                   5204:   padding: 8px;
                   5205:   background-color: $data_table_light;
                   5206: }
                   5207: table.LC_helpform_receipt td.LC_pick_box_separator {
                   5208:   padding: 0px;
                   5209:   height: 1px;
                   5210:   background: black;
                   5211: }
                   5212: span.LC_helpform_receipt_cat {
                   5213:   font-weight: bold;
                   5214: }
1.424     albertel 5215: table.LC_group_priv_box {
                   5216:   background: white;
                   5217:   border: 1px solid black;
                   5218:   border-spacing: 1px;
                   5219: }
                   5220: table.LC_group_priv_box td.LC_pick_box_title {
                   5221:   background: $tabbg;
                   5222:   font-weight: bold;
                   5223:   text-align: right;
                   5224:   width: 184px;
                   5225: }
                   5226: table.LC_group_priv_box td.LC_groups_fixed {
                   5227:   background: $data_table_light;
                   5228:   text-align: center;
                   5229: }
                   5230: table.LC_group_priv_box td.LC_groups_optional {
                   5231:   background: $data_table_dark;
                   5232:   text-align: center;
                   5233: }
                   5234: table.LC_group_priv_box td.LC_groups_functionality {
                   5235:   background: $data_table_darker;
                   5236:   text-align: center;
                   5237:   font-weight: bold;
                   5238: }
                   5239: table.LC_group_priv td {
                   5240:   text-align: left;
                   5241:   padding: 0px;
                   5242: }
                   5243: 
1.421     albertel 5244: table.LC_notify_front_page {
                   5245:   background: white;
                   5246:   border: 1px solid black;
                   5247:   padding: 8px;
                   5248: }
                   5249: table.LC_notify_front_page td {
                   5250:   padding: 8px;
                   5251: }
1.424     albertel 5252: .LC_navbuttons {
                   5253:   margin: 2ex 0ex 2ex 0ex;
                   5254: }
1.423     albertel 5255: .LC_topic_bar {
                   5256:   font-family: $sans;
                   5257:   font-weight: bold;
                   5258:   width: 100%;
                   5259:   background: $tabbg;
                   5260:   vertical-align: middle;
                   5261:   margin: 2ex 0ex 2ex 0ex;
                   5262: }
                   5263: .LC_topic_bar span {
                   5264:   vertical-align: middle;
                   5265: }
                   5266: .LC_topic_bar img {
                   5267:   vertical-align: bottom;
                   5268: }
                   5269: table.LC_course_group_status {
                   5270:   margin: 20px;
                   5271: }
                   5272: table.LC_status_selector td {
                   5273:   vertical-align: top;
                   5274:   text-align: center;
1.424     albertel 5275:   padding: 4px;
                   5276: }
                   5277: table.LC_descriptive_input td.LC_description {
                   5278:   vertical-align: top;
                   5279:   text-align: right;
                   5280:   font-weight: bold;
1.423     albertel 5281: }
1.599     albertel 5282: div.LC_feedback_link {
1.616     albertel 5283:   clear: both;
1.599     albertel 5284:   background: white;
1.779     bisitz   5285:   width: 100%;
1.489     raeburn  5286: }
                   5287: span.LC_feedback_link {
1.599     albertel 5288:   background: $feedback_link_bg;
                   5289:   font-size: larger;
                   5290: }
                   5291: span.LC_message_link {
                   5292:   background: $feedback_link_bg;
                   5293:   font-size: larger;
                   5294:   position: absolute;
                   5295:   right: 1em;
1.489     raeburn  5296: }
1.421     albertel 5297: 
1.515     albertel 5298: table.LC_prior_tries {
1.524     albertel 5299:   border: 1px solid #000000;
                   5300:   border-collapse: separate;
                   5301:   border-spacing: 1px;
1.515     albertel 5302: }
1.523     albertel 5303: 
1.515     albertel 5304: table.LC_prior_tries td {
1.524     albertel 5305:   padding: 2px;
1.515     albertel 5306: }
1.523     albertel 5307: 
                   5308: .LC_answer_correct {
                   5309:   background: #AAFFAA;
                   5310:   color: black;
                   5311: }
                   5312: .LC_answer_charged_try {
                   5313:   background: #FFAAAA ! important;
                   5314:   color: black;
                   5315: }
1.779     bisitz   5316: .LC_answer_not_charged_try,
1.523     albertel 5317: .LC_answer_no_grade,
                   5318: .LC_answer_late {
                   5319:   background: #FFFFAA;
                   5320:   color: black;
                   5321: }
                   5322: .LC_answer_previous {
                   5323:   background: #AAAAFF;
                   5324:   color: black;
                   5325: }
1.779     bisitz   5326: .LC_answer_no_message {
1.777     tempelho 5327:   background: #FFFFFF;
                   5328:   color: black;
1.779     bisitz   5329: }
                   5330: .LC_answer_unknown {
                   5331:   background: orange;
                   5332:   color: black;
1.777     tempelho 5333: }
1.529     albertel 5334: span.LC_prior_numerical,
                   5335: span.LC_prior_string,
                   5336: span.LC_prior_custom,
                   5337: span.LC_prior_reaction,
                   5338: span.LC_prior_math {
1.523     albertel 5339:   font-family: monospace;
                   5340:   white-space: pre;
                   5341: }
                   5342: 
1.525     albertel 5343: span.LC_prior_string {
                   5344:   font-family: monospace;
                   5345:   white-space: pre;
                   5346: }
                   5347: 
1.523     albertel 5348: table.LC_prior_option {
                   5349:   width: 100%;
                   5350:   border-collapse: collapse;
                   5351: }
1.528     albertel 5352: table.LC_prior_rank, table.LC_prior_match {
                   5353:   border-collapse: collapse;
                   5354: }
                   5355: table.LC_prior_option tr td,
                   5356: table.LC_prior_rank tr td,
                   5357: table.LC_prior_match tr td {
1.524     albertel 5358:   border: 1px solid #000000;
1.515     albertel 5359: }
                   5360: 
1.770     droeschl 5361: td.LC_nobreak,
1.519     raeburn  5362: span.LC_nobreak {
1.544     albertel 5363:   white-space: nowrap;
1.519     raeburn  5364: }
                   5365: 
1.576     raeburn  5366: span.LC_cusr_emph {
                   5367:   font-style: italic;
                   5368: }
                   5369: 
1.633     raeburn  5370: span.LC_cusr_subheading {
                   5371:   font-weight: normal;
                   5372:   font-size: 85%;
                   5373: }
                   5374: 
1.545     albertel 5375: table.LC_docs_documents {
                   5376:   background: #BBBBBB;
1.547     albertel 5377:   border-width: 0px;
1.545     albertel 5378:   border-collapse: collapse;
                   5379: }
1.777     tempelho 5380: table.LC_docs_documents td.LC_docs_document {
1.779     bisitz   5381:   border: 2px solid black;
                   5382:   padding: 4px;
1.777     tempelho 5383: }
1.545     albertel 5384: .LC_docs_entry_move {
                   5385:   border: 0px;
                   5386:   border-collapse: collapse;
1.544     albertel 5387: }
                   5388: 
1.545     albertel 5389: .LC_docs_entry_move td {
                   5390:   border: 2px solid #BBBBBB;
                   5391:   background: #DDDDDD;
                   5392: }
                   5393: 
                   5394: .LC_docs_editor td.LC_docs_entry_commands {
                   5395:   background: #DDDDDD;
                   5396:   font-size: x-small;
                   5397: }
1.544     albertel 5398: .LC_docs_copy {
1.545     albertel 5399:   color: #000099;
1.544     albertel 5400: }
                   5401: .LC_docs_cut {
1.545     albertel 5402:   color: #550044;
1.544     albertel 5403: }
                   5404: .LC_docs_rename {
1.545     albertel 5405:   color: #009900;
1.544     albertel 5406: }
                   5407: .LC_docs_remove {
1.545     albertel 5408:   color: #990000;
                   5409: }
                   5410: 
1.547     albertel 5411: .LC_docs_reinit_warn,
                   5412: .LC_docs_ext_edit {
                   5413:   font-size: x-small;
                   5414: }
                   5415: 
1.545     albertel 5416: .LC_docs_editor td.LC_docs_entry_title,
                   5417: .LC_docs_editor td.LC_docs_entry_icon {
                   5418:   background: #FFFFBB;
                   5419: }
                   5420: .LC_docs_editor td.LC_docs_entry_parameter {
                   5421:   background: #BBBBFF;
                   5422:   font-size: x-small;
                   5423:   white-space: nowrap;
                   5424: }
                   5425: 
                   5426: table.LC_docs_adddocs td,
                   5427: table.LC_docs_adddocs th {
                   5428:   border: 1px solid #BBBBBB;
                   5429:   padding: 4px;
                   5430:   background: #DDDDDD;
1.543     albertel 5431: }
                   5432: 
1.584     albertel 5433: table.LC_sty_begin {
                   5434:   background: #BBFFBB;
                   5435: }
                   5436: table.LC_sty_end {
                   5437:   background: #FFBBBB;
                   5438: }
                   5439: 
1.589     raeburn  5440: table.LC_double_column {
                   5441:   border-width: 0px;
                   5442:   border-collapse: collapse;
                   5443:   width: 100%;
                   5444:   padding: 2px;
                   5445: }
                   5446: 
                   5447: table.LC_double_column tr td.LC_left_col {
1.590     raeburn  5448:   top: 2px;
1.589     raeburn  5449:   left: 2px;
                   5450:   width: 47%;
                   5451:   vertical-align: top;
                   5452: }
                   5453: 
                   5454: table.LC_double_column tr td.LC_right_col {
                   5455:   top: 2px;
1.779     bisitz   5456:   right: 2px;
1.589     raeburn  5457:   width: 47%;
                   5458:   vertical-align: top;
                   5459: }
                   5460: 
1.594     raeburn  5461: span.LC_role_level {
                   5462:   font-weight: bold;
                   5463: }
                   5464: 
1.591     raeburn  5465: div.LC_left_float {
                   5466:   float: left;
                   5467:   padding-right: 5%;
1.597     albertel 5468:   padding-bottom: 4px;
1.591     raeburn  5469: }
                   5470: 
                   5471: div.LC_clear_float_header {
1.597     albertel 5472:   padding-bottom: 2px;
1.591     raeburn  5473: }
                   5474: 
                   5475: div.LC_clear_float_footer {
1.597     albertel 5476:   padding-top: 10px;
1.591     raeburn  5477:   clear: both;
                   5478: }
                   5479: 
1.597     albertel 5480: 
                   5481: div.LC_grade_show_user {
                   5482:   margin-top: 20px;
                   5483:   border: 1px solid black;
                   5484: }
                   5485: div.LC_grade_user_name {
                   5486:   background: #DDDDEE;
                   5487:   border-bottom: 1px solid black;
1.705     tempelho 5488:   font-weight: bold;
                   5489:   font-size: large;
1.597     albertel 5490: }
                   5491: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
                   5492:   background: #DDEEDD;
                   5493: }
                   5494: 
                   5495: div.LC_grade_show_problem,
                   5496: div.LC_grade_submissions,
                   5497: div.LC_grade_message_center,
                   5498: div.LC_grade_info_links,
                   5499: div.LC_grade_assign {
                   5500:   margin: 5px;
                   5501:   width: 99%;
                   5502:   background: #FFFFFF;
                   5503: }
                   5504: div.LC_grade_show_problem_header,
                   5505: div.LC_grade_submissions_header,
                   5506: div.LC_grade_message_center_header,
                   5507: div.LC_grade_assign_header {
1.705     tempelho 5508:   font-weight: bold;
                   5509:   font-size: large;
1.597     albertel 5510: }
                   5511: div.LC_grade_show_problem_problem,
                   5512: div.LC_grade_submissions_body,
                   5513: div.LC_grade_message_center_body,
                   5514: div.LC_grade_assign_body {
                   5515:   border: 1px solid black;
                   5516:   width: 99%;
                   5517:   background: #FFFFFF;
                   5518: }
1.598     albertel 5519: span.LC_grade_check_note {
1.705     tempelho 5520:   font-weight: normal;
                   5521:   font-size: medium;
1.598     albertel 5522:   display: inline;
                   5523:   position: absolute;
                   5524:   right: 1em;
                   5525: }
1.597     albertel 5526: 
1.613     albertel 5527: table.LC_scantron_action {
                   5528:   width: 100%;
                   5529: }
                   5530: table.LC_scantron_action tr th {
1.698     harmsja  5531:   font-weight:bold;
                   5532:   font-style:normal;
1.613     albertel 5533: }
1.779     bisitz   5534: .LC_edit_problem_header,
1.614     albertel 5535: div.LC_edit_problem_footer {
1.705     tempelho 5536:   font-weight: normal;
                   5537:   font-size:  medium;
1.602     albertel 5538:   margin: 2px;
1.600     albertel 5539: }
                   5540: div.LC_edit_problem_header,
1.602     albertel 5541: div.LC_edit_problem_header div,
1.614     albertel 5542: div.LC_edit_problem_footer,
                   5543: div.LC_edit_problem_footer div,
1.602     albertel 5544: div.LC_edit_problem_editxml_header,
                   5545: div.LC_edit_problem_editxml_header div {
1.600     albertel 5546:   margin-top: 5px;
                   5547: }
1.602     albertel 5548: div.LC_edit_problem_header_edit_row {
                   5549:   background: $tabbg;
                   5550:   padding: 3px;
                   5551:   margin-bottom: 5px;
                   5552: }
1.600     albertel 5553: div.LC_edit_problem_header_title {
1.705     tempelho 5554:   font-weight: bold;
                   5555:   font-size: larger;
1.602     albertel 5556:   background: $tabbg;
                   5557:   padding: 3px;
                   5558: }
                   5559: table.LC_edit_problem_header_title {
1.705     tempelho 5560:   font-size: larger;
                   5561:   font-weight:  bold;
1.602     albertel 5562:   width: 100%;
                   5563:   border-color: $pgbg;
                   5564:   border-style: solid;
                   5565:   border-width: $border;
                   5566: 
1.600     albertel 5567:   background: $tabbg;
1.602     albertel 5568:   border-collapse: collapse;
                   5569:   padding: 0px
                   5570: }
                   5571: 
                   5572: div.LC_edit_problem_discards {
                   5573:   float: left;
                   5574:   padding-bottom: 5px;
                   5575: }
                   5576: div.LC_edit_problem_saves {
                   5577:   float: right;
                   5578:   padding-bottom: 5px;
1.600     albertel 5579: }
                   5580: hr.LC_edit_problem_divide {
1.602     albertel 5581:   clear: both;
1.600     albertel 5582:   color: $tabbg;
                   5583:   background-color: $tabbg;
                   5584:   height: 3px;
                   5585:   border: 0px;
                   5586: }
1.679     riegler  5587: img.stift{
1.678     riegler  5588:   border-width:0;
1.679     riegler  5589:   vertical-align:middle;
1.677     riegler  5590: }
1.680     riegler  5591: 
1.681     riegler  5592: table#LC_mainmenu{
                   5593:  margin-top:10px;
                   5594:  width:80%;
                   5595: 
                   5596: }
                   5597: 
1.680     riegler  5598: table#LC_mainmenu td.LC_mainmenu_col_fieldset{
                   5599:   vertical-align: top;
                   5600:   width: 45%;
                   5601: }
1.779     bisitz   5602: .LC_mainmenu_fieldset_category {
                   5603:   color: $font;
                   5604:   background: $pgbg;
                   5605:   font-family: $sans;
                   5606:   font-size: small;
                   5607:   font-weight: bold;
1.777     tempelho 5608: }
1.716     raeburn  5609: div.LC_createcourse {
                   5610:     margin: 10px 10px 10px 10px;
                   5611: }
                   5612: 
1.693     droeschl 5613: /* ---- Remove when done ----
                   5614: # The following styles is part of the redesign of LON-CAPA and are
                   5615: # subject to change during this project.
                   5616: # Don't rely on their current functionality as they might be 
                   5617: # changed or removed.
                   5618: # --------------------------*/
                   5619: 
1.698     harmsja  5620: a:hover,
1.721     harmsja  5621: ol.LC_smallMenu a:hover,
                   5622: ol#LC_MenuBreadcrumbs a:hover,
                   5623: ol#LC_PathBreadcrumbs a:hover,
                   5624: ul#LC_TabMainMenuContent a:hover,
                   5625: .LC_FormSectionClearButton input:hover
                   5626: ul.LC_TabContent   li:hover a{
1.698     harmsja  5627: 	color:#BF2317;
                   5628:         text-decoration:none;
1.693     droeschl 5629: }
                   5630: 
1.779     bisitz   5631: h1 {
1.721     harmsja  5632: 	padding:5px 10px 5px 20px;
1.693     droeschl 5633: 	line-height:130%;
                   5634: }
1.698     harmsja  5635: 
1.693     droeschl 5636: h2,h3,h4,h5,h6
                   5637: {
1.721     harmsja  5638: 	margin:5px 0px 5px 0px;
                   5639: 	padding:0px;
                   5640: 	line-height:130%;
1.693     droeschl 5641: }
1.721     harmsja  5642: .LC_hcell{
1.698     harmsja  5643:         padding:3px 15px 3px 15px;
                   5644:         margin:0px;
1.703     harmsja  5645: 	background-color:$tabbg;
1.779     bisitz   5646: 	border-bottom:solid 1px $lg_border_color;
1.693     droeschl 5647: }
1.721     harmsja  5648: .LC_noBorder {
1.698     harmsja  5649:         border:0px;
                   5650: }
1.693     droeschl 5651: 
                   5652: 
1.698     harmsja  5653: /* Main Header with discription of Person, Course, etc. */
1.693     droeschl 5654: 
1.761     tempelho 5655: .LC_Right {
                   5656:         float: right;
                   5657:         margin: 0px;
                   5658:         padding: 0px;
                   5659: }
                   5660: 
1.721     harmsja  5661: .LC_FormSectionClearButton input {
1.779     bisitz   5662:         background-color:transparent;
1.698     harmsja  5663:         border:0px;
                   5664:         cursor:pointer;
                   5665:         text-decoration:underline;
1.693     droeschl 5666: }
1.763     bisitz   5667: 
                   5668: .LC_help_open_topic {
                   5669:         color: #FFFFFF;
                   5670:         background-color: #EEEEFF;
                   5671:         margin: 1px;
                   5672:         padding: 4px;
                   5673:         border: 1px solid #000033;
                   5674:         white-space: nowrap;
1.783     amueller 5675: /*		vertical-align: middle; */
1.759     neumanie 5676: }
1.693     droeschl 5677: 
1.698     harmsja  5678: dl,ul,div,fieldset {
                   5679: 	margin: 10px 10px 10px 0px;
1.693     droeschl 5680: 	overflow:hidden;
                   5681: }
1.721     harmsja  5682: ol.LC_smallMenu, ol#LC_PathBreadcrumbs {
1.698     harmsja  5683: 	margin: 0px;
1.693     droeschl 5684: }
                   5685: 
1.721     harmsja  5686: ol.LC_smallMenu li {
1.693     droeschl 5687: 	display: inline;
                   5688: 	padding: 5px 5px 0px 10px;
                   5689: 	vertical-align: top;
                   5690: }
                   5691: 
1.721     harmsja  5692: ol.LC_smallMenu li img {
1.693     droeschl 5693: 	vertical-align: bottom;
                   5694: }
                   5695: 
1.721     harmsja  5696: ol.LC_smallMenu a {
1.693     droeschl 5697: 	font-size: 90%;
                   5698: 	color: RGB(80, 80, 80);
                   5699: 	text-decoration: none;
                   5700: }
1.760     harmsja  5701: ol#LC_TabMainMenuContent, ul.LC_TabContent ,
1.741     harmsja  5702: ul.LC_TabContentBigger {
1.721     harmsja  5703: 	display:block;
                   5704: 	list-style:none;
1.741     harmsja  5705: 	margin: 0px;
1.693     droeschl 5706: 	padding: 0px;
                   5707: }
                   5708: 
1.744     ehlerst  5709: ol#LC_TabMainMenuContent li, ul.LC_TabContent li,
1.741     harmsja  5710: ul.LC_TabContentBigger li{
1.693     droeschl 5711: 	display: inline;
1.741     harmsja  5712: 	border-right: solid 1px $lg_border_color;
                   5713: 	float:left;
                   5714: 	line-height:140%;
                   5715: 	white-space:nowrap;
                   5716: }
                   5717: ol#LC_TabMainMenuContent li{
1.693     droeschl 5718: 	vertical-align: bottom;
                   5719: 	border-bottom: solid 1px RGB(175, 175, 175);
1.721     harmsja  5720: 	padding: 5px 10px 5px 10px;
1.741     harmsja  5721: 	margin-right:5px;
                   5722: 	margin-bottom:3px;
1.693     droeschl 5723: 	font-weight: bold;
1.723     riegler  5724: 	background: url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
1.693     droeschl 5725: }
                   5726: 
1.721     harmsja  5727: ol#LC_TabMainMenuContent li a{
1.693     droeschl 5728: 	color: RGB(47, 47, 47);
                   5729: 	text-decoration: none;
                   5730: }
1.721     harmsja  5731: ul.LC_TabContent {
1.741     harmsja  5732: 	min-height:1.6em;
1.721     harmsja  5733: }
                   5734: ul.LC_TabContent li{
1.741     harmsja  5735: 	vertical-align:middle;
                   5736: 	padding:0px 10px 0px 10px;
1.745     ehlerst  5737: 	background-color:$tabbg;
                   5738: 	border-bottom:solid 1px $lg_border_color;
1.721     harmsja  5739: }
1.779     bisitz   5740: ul.LC_TabContent li a, ul.LC_TabContent li{
1.721     harmsja  5741: 	color:rgb(47,47,47);
                   5742: 	text-decoration:none;
                   5743: 	font-size:95%;
                   5744: 	font-weight:bold;
1.761     tempelho 5745: 	padding-right: 16px;
1.721     harmsja  5746: }
1.744     ehlerst  5747: ul.LC_TabContent li:hover, ul.LC_TabContent li.active{
1.761     tempelho 5748:         background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.745     ehlerst  5749: 	border-bottom:solid 1px #FFFFFF;
1.761     tempelho 5750: 	padding-right: 16px;
1.744     ehlerst  5751: }
1.741     harmsja  5752: ul.LC_TabContentBigger li{
                   5753: 	vertical-align:bottom;
                   5754: 	border-top:solid 1px $lg_border_color;
                   5755: 	border-left:solid 1px $lg_border_color;
                   5756: 	padding:5px 10px 5px 10px;
                   5757: 	margin-left:2px;
                   5758: 	background:url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
                   5759: }
1.744     ehlerst  5760: ul.LC_TabContentBigger li:hover, ul.LC_TabContentBigger li.active{
                   5761: 	background:url(/adm/lonIcons/lightGreyBG.png) repeat-x right bottom;
                   5762: }
1.741     harmsja  5763: ul.LC_TabContentBigger li, ul.LC_TabContentBigger li a{
                   5764: 	font-size:110%;
                   5765: 	font-weight:bold;
                   5766: }
1.693     droeschl 5767: 
1.783     amueller 5768: ol#LC_MenuBreadcrumbs, ol#LC_PathBreadcrumbs, ul.LC_CourseBreadcrumbs{
1.693     droeschl 5769: 	border-top: solid 1px RGB(255, 255, 255);
                   5770: 	height: 20px;
                   5771: 	line-height: 20px;
                   5772: 	vertical-align: bottom;
                   5773: 	margin: 0px 0px 30px 0px;
                   5774: 	padding-left: 10px;
                   5775: 	list-style-position: inside;
1.723     riegler  5776: 	background: url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
1.693     droeschl 5777: }
                   5778: 
1.783     amueller 5779: ol#LC_MenuBreadcrumbs li, ol#LC_PathBreadcrumbs li, ul.LC_CourseBreadcrumbs li {
1.741     harmsja  5780: /*
1.723     riegler  5781: 	background: url(/adm/lonIcons/arrow_white.png) no-repeat left center;
1.779     bisitz   5782: */
1.693     droeschl 5783: 	display: inline;
                   5784: 	padding: 0px 0px 0px 10px;
1.783     amueller 5785: /*	vertical-align: bottom; */
1.693     droeschl 5786: 	overflow:hidden;
                   5787: }
                   5788: 
1.783     amueller 5789: ol#LC_MenuBreadcrumbs li a, ul.LC_CourseBreadcrumbs li a {
1.693     droeschl 5790: 	text-decoration: none;
                   5791: 	font-size:90%;
                   5792: }
1.721     harmsja  5793: ol#LC_PathBreadcrumbs li a{
1.698     harmsja  5794: 	text-decoration:none;
                   5795: 	font-size:100%;
                   5796: 	font-weight:bold;
1.693     droeschl 5797: }
1.786     neumanie 5798: .LC_BoxPadding
                   5799: {
                   5800: 	padding: 10px;
                   5801: }
1.721     harmsja  5802: .LC_ContentBoxSpecial
1.693     droeschl 5803: {
1.701     harmsja  5804: 	border: solid 1px $lg_border_color;
1.746     neumanie 5805: }
                   5806: .LC_ContentBoxSpecialContactInfo
                   5807: {
                   5808: 	border: solid 1px $lg_border_color;
                   5809: 	max-width:25%;
                   5810: 	min-width:25%;
1.698     harmsja  5811: }
1.747     neumanie 5812: .LC_AboutMe_Image
                   5813: {
                   5814: 	float:left;
                   5815: 	margin-right:10px;
                   5816: }
                   5817: .LC_Clear_AboutMe_Image
                   5818: {
                   5819: 	clear:left;
                   5820: }
1.721     harmsja  5821: dl.LC_ListStyleClean dt {
1.693     droeschl 5822: 	padding-right: 5px;
                   5823: 	display: table-header-group;
                   5824: }
                   5825: 
1.721     harmsja  5826: dl.LC_ListStyleClean dd {
1.693     droeschl 5827: 	display: table-row;
                   5828: }
                   5829: 
1.721     harmsja  5830: .LC_ListStyleClean,
                   5831: .LC_ListStyleSimple,
                   5832: .LC_ListStyleNormal,
1.777     tempelho 5833: .LC_ListStyle_Border,
1.721     harmsja  5834: .LC_ListStyleSpecial
1.693     droeschl 5835: 	{
                   5836: 	/*display:block;	*/
                   5837: 	list-style-position: inside;
                   5838: 	list-style-type: none;
                   5839: 	overflow: hidden;
                   5840: 	padding: 0px;
                   5841: }
                   5842: 
1.721     harmsja  5843: .LC_ListStyleSimple li,
                   5844: .LC_ListStyleSimple dd,
                   5845: .LC_ListStyleNormal li,
                   5846: .LC_ListStyleNormal dd,
                   5847: .LC_ListStyleSpecial li,
                   5848: .LC_ListStyleSpecial dd
1.693     droeschl 5849: 	{
                   5850: 	margin: 0px;
                   5851: 	padding: 5px 5px 5px 10px;
                   5852: 	clear: both;
                   5853: }
                   5854: 
1.721     harmsja  5855: .LC_ListStyleClean li,
                   5856: .LC_ListStyleClean dd {
1.693     droeschl 5857: 	padding-top: 0px;
                   5858: 	padding-bottom: 0px;
                   5859: }
                   5860: 
1.721     harmsja  5861: .LC_ListStyleSimple dd,
                   5862: .LC_ListStyleSimple li{
1.698     harmsja  5863: 	border-bottom: solid 1px $lg_border_color;
1.693     droeschl 5864: }
                   5865: 
1.721     harmsja  5866: .LC_ListStyleSpecial li,
                   5867: .LC_ListStyleSpecial dd {
1.693     droeschl 5868: 	list-style-type: none;
                   5869: 	background-color: RGB(220, 220, 220);
                   5870: 	margin-bottom: 4px;
                   5871: }
                   5872: 
1.721     harmsja  5873: table.LC_SimpleTable {
1.698     harmsja  5874: 	margin:5px;
                   5875: 	border:solid 1px $lg_border_color;
1.693     droeschl 5876: 	}
                   5877: 
1.721     harmsja  5878: table.LC_SimpleTable tr {
1.698     harmsja  5879: 	padding:0px;
                   5880: 	border:solid 1px $lg_border_color;
1.693     droeschl 5881: }
1.721     harmsja  5882: table.LC_SimpleTable thead{
1.698     harmsja  5883: 	 background:rgb(220,220,220);
1.693     droeschl 5884: }
                   5885: 
1.721     harmsja  5886: div.LC_columnSection {
1.693     droeschl 5887: 	display: block;
                   5888: 	clear: both;
                   5889: 	overflow: hidden;
                   5890: 	margin:0px;
                   5891: }
                   5892: 
1.721     harmsja  5893: div.LC_columnSection>* {
1.693     droeschl 5894: 	float: left;
                   5895: 	margin: 10px 20px 10px 0px;
1.747     neumanie 5896: 	overflow:hidden;
1.693     droeschl 5897: }
1.721     harmsja  5898: 
1.719     ehlerst  5899: .ContentBoxSpecialTemplate
                   5900: {
1.747     neumanie 5901:         border: solid 1px $lg_border_color;
1.719     ehlerst  5902: }
                   5903: .ContentBoxTemplate {
                   5904:         padding:10px;
                   5905: }
                   5906: 
1.721     harmsja  5907: div.LC_columnSection > .ContentBoxTemplate,
                   5908: div.LC_columnSection > .ContentBoxSpecialTemplate
1.719     ehlerst  5909:         {
                   5910:         width: 600px;
                   5911: }
1.753     droeschl 5912: 
1.720     ehlerst  5913: .clear{
                   5914: 	clear: both;
                   5915: 	line-height: 0px;
                   5916: 	font-size: 0px;
                   5917: 	height: 0px;
                   5918: }
1.693     droeschl 5919: 
1.694     tempelho 5920: .LC_loginpage_container {
                   5921: 	text-align:left;
                   5922: 	margin : 0 auto;
1.785     tempelho 5923: 	width:90%;
1.694     tempelho 5924: 	padding: 10px;
                   5925: 	height: auto;
1.712     muellerd 5926: 	background-color:#FFFFFF;
1.694     tempelho 5927: 	border:1px solid #CCCCCC;
                   5928: }
                   5929: 
                   5930: 
                   5931: .LC_loginpage_loginContainer {
                   5932: 	float:left;
1.712     muellerd 5933: 	width: 182px;
1.785     tempelho 5934: 	padding: 2px;
1.712     muellerd 5935: 	border:1px solid #CCCCCC;
                   5936: 	background-color:$loginbg;
1.694     tempelho 5937: }
                   5938: 
1.717     tempelho 5939: .LC_loginpage_loginContainer h2{
1.712     muellerd 5940: 	margin-top:0;
                   5941: 	display:block;
                   5942: 	background:$bgcol;
                   5943: 	color:$textcol;
                   5944: 	padding-left:5px;
                   5945: }
1.785     tempelho 5946: 
1.694     tempelho 5947: .LC_loginpage_loginInfo {
                   5948: 	float:left;
1.785     tempelho 5949: 	width:182px;
1.694     tempelho 5950: 	border:1px solid #CCCCCC;
1.785     tempelho 5951: 	padding:2px;
1.712     muellerd 5952: }
                   5953: 
1.694     tempelho 5954: .LC_loginpage_space {
1.754     droeschl 5955: 	clear: both;
                   5956: 	margin-bottom: 20px;
1.694     tempelho 5957: 	border-bottom: 1px solid #CCCCCC;
                   5958: }
                   5959: 
1.785     tempelho 5960: .LC_loginpage_floatLeft {
                   5961: 	float: left;
                   5962: 	width: 200px;
                   5963: 	margin: 0;
                   5964: }
                   5965: 
1.748     schulted 5966: table em{
1.754     droeschl 5967: 	font-weight: bold;
                   5968: 	font-style: normal;
1.748     schulted 5969: }
1.779     bisitz   5970: table.LC_tableBrowseRes,
1.768     schulted 5971: table.LC_tableOfContent{
1.769     schulted 5972:         border:none;
                   5973: 	border-spacing: 1;
1.754     droeschl 5974: 	padding: 3px;
                   5975: 	background-color: #FFFFFF;
                   5976: 	font-size: 90%;
1.753     droeschl 5977: }
1.789     droeschl 5978: 
                   5979: table.LC_tableOfContent{
                   5980:     border-collapse: collapse;
                   5981: }
                   5982: 
1.771     droeschl 5983: table.LC_tableBrowseRes a,
1.768     schulted 5984: table.LC_tableOfContent a {
1.771     droeschl 5985:         background-color: transparent;
1.753     droeschl 5986: 	text-decoration: none;
                   5987: }
                   5988: 
1.771     droeschl 5989: table.LC_tableBrowseRes tr.LC_trOdd,
1.768     schulted 5990: table.LC_tableOfContent tr.LC_trOdd{
1.754     droeschl 5991: 	background-color: #EEEEEE;
1.753     droeschl 5992: }
                   5993: 
1.768     schulted 5994: table.LC_tableOfContent img{
1.753     droeschl 5995: 	border: none;
                   5996: 	height: 1.3em;
                   5997: 	vertical-align: text-bottom;
                   5998: 	margin-right: 0.3em;
                   5999: }
1.757     schulted 6000: 
1.774     ehlerst  6001: a#LC_content_toolbar_firsthomework{
                   6002: 	background-image:url(/res/adm/pages/open-first-problem.gif);
                   6003: }
                   6004: 
                   6005: a#LC_content_toolbar_launchnav{
                   6006: 	background-image:url(/res/adm/pages/start-navigation.gif);
                   6007: }
                   6008: 
                   6009: a#LC_content_toolbar_closenav{
                   6010: 	background-image:url(/res/adm/pages/close-navigation.gif);
                   6011: }
                   6012: 
                   6013: a#LC_content_toolbar_everything{
                   6014: 	background-image:url(/res/adm/pages/show-all.gif);
                   6015: }
                   6016: 
                   6017: a#LC_content_toolbar_uncompleted{
                   6018: 	background-image:url(/res/adm/pages/show-incomplete-problems.gif);
                   6019: }
                   6020: 
                   6021: #LC_content_toolbar_clearbubbles{
                   6022: 	background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
                   6023: }
                   6024: 
1.757     schulted 6025: a#LC_content_toolbar_changefolder{
                   6026: 	background : url(/res/adm/pages/close-all-folders.gif) top center ;
                   6027: }
                   6028: 
                   6029: a#LC_content_toolbar_changefolder_toggled{
                   6030: 	background-image:url(/res/adm/pages/open-all-folders.gif);
                   6031: }
                   6032: 
                   6033: ul#LC_toolbar li a:hover{
                   6034: 	background-position: bottom center;
                   6035: }
                   6036: 
                   6037: ul#LC_toolbar{
1.779     bisitz   6038: 	padding:0;
1.757     schulted 6039: 	margin: 2px;
                   6040: 	list-style:none;
                   6041: 	position:relative;
                   6042: 	background-color:white;
                   6043: }
                   6044: 
                   6045: ul#LC_toolbar li{
                   6046: 	border:1px solid white;
                   6047: 	padding:0;
                   6048: 	margin: 0;
1.767     droeschl 6049:     float: left;
                   6050: 	display:inline;
1.757     schulted 6051: 	vertical-align:middle;
                   6052: }
                   6053: 
1.783     amueller 6054: 
1.757     schulted 6055: a.LC_toolbarItem{
1.767     droeschl 6056: 	display:block;
1.757     schulted 6057: 	padding:0;
                   6058: 	margin:0;
                   6059: 	height: 32px;
                   6060: 	width: 32px;
1.779     bisitz   6061: 	color:white;
                   6062: 	border:0 none;
1.757     schulted 6063: 	background-repeat:no-repeat;
                   6064: 	background-color:transparent;
                   6065: }
                   6066: 
1.782     bisitz   6067: ul.LC_functionslist li {
                   6068:   float: left;
                   6069:   white-space: nowrap;
                   6070:   height: 35px; /* at least as high as heighest list item */
                   6071:   margin: 0px 15px 15px 10px;
                   6072: }
                   6073: 
1.757     schulted 6074: 
1.343     albertel 6075: END
                   6076: }
                   6077: 
1.306     albertel 6078: =pod
                   6079: 
                   6080: =item * &headtag()
                   6081: 
                   6082: Returns a uniform footer for LON-CAPA web pages.
                   6083: 
1.307     albertel 6084: Inputs: $title - optional title for the head
                   6085:         $head_extra - optional extra HTML to put inside the <head>
1.315     albertel 6086:         $args - optional arguments
1.319     albertel 6087:             force_register - if is true call registerurl so the remote is 
                   6088:                              informed
1.415     albertel 6089:             redirect       -> array ref of
                   6090:                                    1- seconds before redirect occurs
                   6091:                                    2- url to redirect to
                   6092:                                    3- whether the side effect should occur
1.315     albertel 6093:                            (side effect of setting 
                   6094:                                $env{'internal.head.redirect'} to the url 
                   6095:                                redirected too)
1.352     albertel 6096:             domain         -> force to color decorate a page for a specific
                   6097:                                domain
                   6098:             function       -> force usage of a specific rolish color scheme
                   6099:             bgcolor        -> override the default page bgcolor
1.460     albertel 6100:             no_auto_mt_title
                   6101:                            -> prevent &mt()ing the title arg
1.464     albertel 6102: 
1.306     albertel 6103: =cut
                   6104: 
                   6105: sub headtag {
1.313     albertel 6106:     my ($title,$head_extra,$args) = @_;
1.306     albertel 6107:     
1.363     albertel 6108:     my $function = $args->{'function'} || &get_users_function();
                   6109:     my $domain   = $args->{'domain'}   || &determinedomain();
                   6110:     my $bgcolor  = $args->{'bgcolor'}  || &designparm($function.'.pgbg',$domain);
1.418     albertel 6111:     my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458     albertel 6112: 		   $Apache::lonnet::perlvar{'lonVersion'},
1.531     albertel 6113: 		   #time(),
1.418     albertel 6114: 		   $env{'environment.color.timestamp'},
1.363     albertel 6115: 		   $function,$domain,$bgcolor);
                   6116: 
1.369     www      6117:     $url = '/adm/css/'.&escape($url).'.css';
1.363     albertel 6118: 
1.308     albertel 6119:     my $result =
                   6120: 	'<head>'.
1.461     albertel 6121: 	&font_settings();
1.319     albertel 6122: 
1.461     albertel 6123:     if (!$args->{'frameset'}) {
                   6124: 	$result .= &Apache::lonhtmlcommon::htmlareaheaders();
                   6125:     }
1.319     albertel 6126:     if ($args->{'force_register'}) {
                   6127: 	$result .= &Apache::lonmenu::registerurl(1);
                   6128:     }
1.436     albertel 6129:     if (!$args->{'no_nav_bar'} 
                   6130: 	&& !$args->{'only_body'}
                   6131: 	&& !$args->{'frameset'}) {
                   6132: 	$result .= &help_menu_js();
                   6133:     }
1.319     albertel 6134: 
1.314     albertel 6135:     if (ref($args->{'redirect'})) {
1.414     albertel 6136: 	my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315     albertel 6137: 	$url = &Apache::lonenc::check_encrypt($url);
1.414     albertel 6138: 	if (!$inhibit_continue) {
                   6139: 	    $env{'internal.head.redirect'} = $url;
                   6140: 	}
1.313     albertel 6141: 	$result.=<<ADDMETA
                   6142: <meta http-equiv="pragma" content="no-cache" />
1.344     albertel 6143: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313     albertel 6144: ADDMETA
                   6145:     }
1.306     albertel 6146:     if (!defined($title)) {
                   6147: 	$title = 'The LearningOnline Network with CAPA';
                   6148:     }
1.460     albertel 6149:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
                   6150:     $result .= '<title> LON-CAPA '.$title.'</title>'
1.414     albertel 6151: 	.'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
                   6152: 	.$head_extra;
1.306     albertel 6153:     return $result;
                   6154: }
                   6155: 
                   6156: =pod
                   6157: 
1.340     albertel 6158: =item * &font_settings()
                   6159: 
                   6160: Returns neccessary <meta> to set the proper encoding
                   6161: 
                   6162: Inputs: none
                   6163: 
                   6164: =cut
                   6165: 
                   6166: sub font_settings {
                   6167:     my $headerstring='';
1.647     www      6168:     if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340     albertel 6169: 	$headerstring.=
                   6170: 	    '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
                   6171:     }
                   6172:     return $headerstring;
                   6173: }
                   6174: 
1.341     albertel 6175: =pod
                   6176: 
                   6177: =item * &xml_begin()
                   6178: 
                   6179: Returns the needed doctype and <html>
                   6180: 
                   6181: Inputs: none
                   6182: 
                   6183: =cut
                   6184: 
                   6185: sub xml_begin {
                   6186:     my $output='';
                   6187: 
1.592     albertel 6188:     if ($env{'internal.start_page'}==1) {
                   6189: 	&Apache::lonhtmlcommon::init_htmlareafields();
                   6190:     }
1.342     albertel 6191: 
1.341     albertel 6192:     if ($env{'browser.mathml'}) {
                   6193: 	$output='<?xml version="1.0"?>'
                   6194:             #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
                   6195: #            .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
                   6196:             
                   6197: #	    .'<!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">] >'
                   6198: 	    .'<!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">'
                   6199:             .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" ' 
                   6200: 	    .'xmlns="http://www.w3.org/1999/xhtml">';
                   6201:     } else {
                   6202: 	$output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>';
                   6203:     }
                   6204:     return $output;
                   6205: }
1.340     albertel 6206: 
                   6207: =pod
                   6208: 
1.306     albertel 6209: =item * &endheadtag()
                   6210: 
                   6211: Returns a uniform </head> for LON-CAPA web pages.
                   6212: 
                   6213: Inputs: none
                   6214: 
                   6215: =cut
                   6216: 
                   6217: sub endheadtag {
                   6218:     return '</head>';
                   6219: }
                   6220: 
                   6221: =pod
                   6222: 
                   6223: =item * &head()
                   6224: 
                   6225: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
                   6226: 
1.648     raeburn  6227: Inputs:
                   6228: 
                   6229: =over 4
                   6230: 
                   6231: $title - optional title for the page
                   6232: 
                   6233: $head_extra - optional extra HTML to put inside the <head>
                   6234: 
                   6235: =back
1.405     albertel 6236: 
1.306     albertel 6237: =cut
                   6238: 
                   6239: sub head {
1.325     albertel 6240:     my ($title,$head_extra,$args) = @_;
                   6241:     return &headtag($title,$head_extra,$args).&endheadtag();
1.306     albertel 6242: }
                   6243: 
                   6244: =pod
                   6245: 
                   6246: =item * &start_page()
                   6247: 
                   6248: Returns a complete <html> .. <body> section for LON-CAPA web pages.
                   6249: 
1.648     raeburn  6250: Inputs:
                   6251: 
                   6252: =over 4
                   6253: 
                   6254: $title - optional title for the page
                   6255: 
                   6256: $head_extra - optional extra HTML to incude inside the <head>
                   6257: 
                   6258: $args - additional optional args supported are:
                   6259: 
                   6260: =over 8
                   6261: 
                   6262:              only_body      -> is true will set &bodytag() onlybodytag
1.317     albertel 6263:                                     arg on
1.648     raeburn  6264:              no_nav_bar     -> is true will set &bodytag() notopbar arg on
                   6265:              add_entries    -> additional attributes to add to the  <body>
                   6266:              domain         -> force to color decorate a page for a 
1.317     albertel 6267:                                     specific domain
1.648     raeburn  6268:              function       -> force usage of a specific rolish color
1.317     albertel 6269:                                     scheme
1.648     raeburn  6270:              redirect       -> see &headtag()
                   6271:              bgcolor        -> override the default page bg color
                   6272:              js_ready       -> return a string ready for being used in 
1.317     albertel 6273:                                     a javascript writeln
1.648     raeburn  6274:              html_encode    -> return a string ready for being used in 
1.320     albertel 6275:                                     a html attribute
1.648     raeburn  6276:              force_register -> if is true will turn on the &bodytag()
1.317     albertel 6277:                                     $forcereg arg
1.648     raeburn  6278:              body_title     -> alternate text to use instead of $title
1.326     albertel 6279:                                     in the title box that appears, this text
                   6280:                                     is not auto translated like the $title is
1.648     raeburn  6281:              frameset       -> if true will start with a <frameset>
1.330     albertel 6282:                                     rather than <body>
1.648     raeburn  6283:              no_title       -> if true the title bar won't be shown
                   6284:              skip_phases    -> hash ref of 
1.338     albertel 6285:                                     head -> skip the <html><head> generation
                   6286:                                     body -> skip all <body> generation
1.648     raeburn  6287:              no_inline_link -> if true and in remote mode, don't show the 
1.361     albertel 6288:                                     'Switch To Inline Menu' link
1.648     raeburn  6289:              no_auto_mt_title -> prevent &mt()ing the title arg
                   6290:              inherit_jsmath -> when creating popup window in a page,
                   6291:                                     should it have jsmath forced on by the
                   6292:                                     current page
1.361     albertel 6293: 
1.648     raeburn  6294: =back
1.460     albertel 6295: 
1.648     raeburn  6296: =back
1.562     albertel 6297: 
1.306     albertel 6298: =cut
                   6299: 
                   6300: sub start_page {
1.309     albertel 6301:     my ($title,$head_extra,$args) = @_;
1.318     albertel 6302:     #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313     albertel 6303:     my %head_args;
1.352     albertel 6304:     foreach my $arg ('redirect','force_register','domain','function',
1.460     albertel 6305: 		     'bgcolor','frameset','no_nav_bar','only_body',
                   6306: 		     'no_auto_mt_title') {
1.319     albertel 6307: 	if (defined($args->{$arg})) {
1.324     raeburn  6308: 	    $head_args{$arg} = $args->{$arg};
1.319     albertel 6309: 	}
1.313     albertel 6310:     }
1.319     albertel 6311: 
1.315     albertel 6312:     $env{'internal.start_page'}++;
1.338     albertel 6313:     my $result;
                   6314:     if (! exists($args->{'skip_phases'}{'head'}) ) {
                   6315: 	$result.=
1.341     albertel 6316: 	    &xml_begin().
1.338     albertel 6317: 	    &headtag($title,$head_extra,\%head_args).&endheadtag();
                   6318:     }
                   6319:     
                   6320:     if (! exists($args->{'skip_phases'}{'body'}) ) {
                   6321: 	if ($args->{'frameset'}) {
                   6322: 	    my $attr_string = &make_attr_string($args->{'force_register'},
                   6323: 						$args->{'add_entries'});
                   6324: 	    $result .= "\n<frameset $attr_string>\n";
                   6325: 	} else {
                   6326: 	    $result .=
                   6327: 		&bodytag($title, 
                   6328: 			 $args->{'function'},       $args->{'add_entries'},
                   6329: 			 $args->{'only_body'},      $args->{'domain'},
                   6330: 			 $args->{'force_register'}, $args->{'body_title'},
                   6331: 			 $args->{'no_nav_bar'},     $args->{'bgcolor'},
1.460     albertel 6332: 			 $args->{'no_title'},       $args->{'no_inline_link'},
                   6333: 			 $args);
1.338     albertel 6334: 	}
1.330     albertel 6335:     }
1.338     albertel 6336: 
1.315     albertel 6337:     if ($args->{'js_ready'}) {
1.713     kaisler  6338: 		$result = &js_ready($result);
1.315     albertel 6339:     }
1.320     albertel 6340:     if ($args->{'html_encode'}) {
1.713     kaisler  6341: 		$result = &html_encode($result);
                   6342:     }
                   6343: 
1.758     kaisler  6344: 	#Breadcrumbs
                   6345:     if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
                   6346: 		&Apache::lonhtmlcommon::clear_breadcrumbs();
                   6347: 		#if any br links exists, add them to the breadcrumbs
                   6348: 		if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {         
                   6349: 			foreach my $crumb (@{$args->{'bread_crumbs'}}){
                   6350: 				&Apache::lonhtmlcommon::add_breadcrumb($crumb);
                   6351: 			}
                   6352: 		}
                   6353: 
                   6354: 		#if bread_crumbs_component exists show it as headline else show only the breadcrumbs
                   6355: 		if(exists($args->{'bread_crumbs_component'})){
                   6356: 			$result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
                   6357: 		}else{
                   6358: 			$result .= &Apache::lonhtmlcommon::breadcrumbs();
                   6359: 		}
1.320     albertel 6360:     }
1.315     albertel 6361:     return $result;
1.306     albertel 6362: }
                   6363: 
1.330     albertel 6364: 
1.306     albertel 6365: =pod
                   6366: 
                   6367: =item * &head()
                   6368: 
                   6369: Returns a complete </body></html> section for LON-CAPA web pages.
                   6370: 
1.315     albertel 6371: Inputs:         $args - additional optional args supported are:
                   6372:                  js_ready     -> return a string ready for being used in 
                   6373:                                  a javascript writeln
1.320     albertel 6374:                  html_encode  -> return a string ready for being used in 
                   6375:                                  a html attribute
1.330     albertel 6376:                  frameset     -> if true will start with a <frameset>
                   6377:                                  rather than <body>
1.493     albertel 6378:                  dicsussion   -> if true will get discussion from
                   6379:                                   lonxml::xmlend
                   6380:                                  (you can pass the target and parser arguments
                   6381:                                   through optional 'target' and 'parser' args
                   6382:                                   to this routine)
1.306     albertel 6383: 
                   6384: =cut
                   6385: 
                   6386: sub end_page {
1.315     albertel 6387:     my ($args) = @_;
                   6388:     $env{'internal.end_page'}++;
1.330     albertel 6389:     my $result;
1.335     albertel 6390:     if ($args->{'discussion'}) {
                   6391: 	my ($target,$parser);
                   6392: 	if (ref($args->{'discussion'})) {
                   6393: 	    ($target,$parser) =($args->{'discussion'}{'target'},
                   6394: 				$args->{'discussion'}{'parser'});
                   6395: 	}
                   6396: 	$result .= &Apache::lonxml::xmlend($target,$parser);
                   6397:     }
                   6398: 
1.330     albertel 6399:     if ($args->{'frameset'}) {
                   6400: 	$result .= '</frameset>';
                   6401:     } else {
1.635     raeburn  6402: 	$result .= &endbodytag($args);
1.330     albertel 6403:     }
                   6404:     $result .= "\n</html>";
                   6405: 
1.315     albertel 6406:     if ($args->{'js_ready'}) {
1.317     albertel 6407: 	$result = &js_ready($result);
1.315     albertel 6408:     }
1.335     albertel 6409: 
1.320     albertel 6410:     if ($args->{'html_encode'}) {
                   6411: 	$result = &html_encode($result);
                   6412:     }
1.335     albertel 6413: 
1.315     albertel 6414:     return $result;
                   6415: }
                   6416: 
1.320     albertel 6417: sub html_encode {
                   6418:     my ($result) = @_;
                   6419: 
1.322     albertel 6420:     $result = &HTML::Entities::encode($result,'<>&"');
1.320     albertel 6421:     
                   6422:     return $result;
                   6423: }
1.317     albertel 6424: sub js_ready {
                   6425:     my ($result) = @_;
                   6426: 
1.323     albertel 6427:     $result =~ s/[\n\r]/ /xmsg;
                   6428:     $result =~ s/\\/\\\\/xmsg;
                   6429:     $result =~ s/'/\\'/xmsg;
1.372     albertel 6430:     $result =~ s{</}{<\\/}xmsg;
1.317     albertel 6431:     
                   6432:     return $result;
                   6433: }
                   6434: 
1.315     albertel 6435: sub validate_page {
                   6436:     if (  exists($env{'internal.start_page'})
1.316     albertel 6437: 	  &&     $env{'internal.start_page'} > 1) {
                   6438: 	&Apache::lonnet::logthis('start_page called multiple times '.
1.318     albertel 6439: 				 $env{'internal.start_page'}.' '.
1.316     albertel 6440: 				 $ENV{'request.filename'});
1.315     albertel 6441:     }
                   6442:     if (  exists($env{'internal.end_page'})
1.316     albertel 6443: 	  &&     $env{'internal.end_page'} > 1) {
                   6444: 	&Apache::lonnet::logthis('end_page called multiple times '.
1.318     albertel 6445: 				 $env{'internal.end_page'}.' '.
1.316     albertel 6446: 				 $env{'request.filename'});
1.315     albertel 6447:     }
                   6448:     if (     exists($env{'internal.start_page'})
                   6449: 	&& ! exists($env{'internal.end_page'})) {
1.316     albertel 6450: 	&Apache::lonnet::logthis('start_page called without end_page '.
                   6451: 				 $env{'request.filename'});
1.315     albertel 6452:     }
                   6453:     if (   ! exists($env{'internal.start_page'})
                   6454: 	&&   exists($env{'internal.end_page'})) {
1.316     albertel 6455: 	&Apache::lonnet::logthis('end_page called without start_page'.
                   6456: 				 $env{'request.filename'});
1.315     albertel 6457:     }
1.306     albertel 6458: }
1.315     albertel 6459: 
1.318     albertel 6460: sub simple_error_page {
                   6461:     my ($r,$title,$msg) = @_;
                   6462:     my $page =
                   6463: 	&Apache::loncommon::start_page($title).
                   6464: 	&mt($msg).
                   6465: 	&Apache::loncommon::end_page();
                   6466:     if (ref($r)) {
                   6467: 	$r->print($page);
1.327     albertel 6468: 	return;
1.318     albertel 6469:     }
                   6470:     return $page;
                   6471: }
1.347     albertel 6472: 
                   6473: {
1.610     albertel 6474:     my @row_count;
1.347     albertel 6475:     sub start_data_table {
1.422     albertel 6476: 	my ($add_class) = @_;
                   6477: 	my $css_class = (join(' ','LC_data_table',$add_class));
1.610     albertel 6478: 	unshift(@row_count,0);
1.422     albertel 6479: 	return '<table class="'.$css_class.'">'."\n";
1.347     albertel 6480:     }
                   6481: 
                   6482:     sub end_data_table {
1.610     albertel 6483: 	shift(@row_count);
1.389     albertel 6484: 	return '</table>'."\n";;
1.347     albertel 6485:     }
                   6486: 
                   6487:     sub start_data_table_row {
1.422     albertel 6488: 	my ($add_class) = @_;
1.610     albertel 6489: 	$row_count[0]++;
                   6490: 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.428     albertel 6491: 	$css_class = (join(' ',$css_class,$add_class));
1.422     albertel 6492: 	return  '<tr class="'.$css_class.'">'."\n";;
1.347     albertel 6493:     }
1.471     banghart 6494:     
                   6495:     sub continue_data_table_row {
                   6496: 	my ($add_class) = @_;
1.610     albertel 6497: 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.471     banghart 6498: 	$css_class = (join(' ',$css_class,$add_class));
                   6499: 	return  '<tr class="'.$css_class.'">'."\n";;
                   6500:     }
1.347     albertel 6501: 
                   6502:     sub end_data_table_row {
1.389     albertel 6503: 	return '</tr>'."\n";;
1.347     albertel 6504:     }
1.367     www      6505: 
1.421     albertel 6506:     sub start_data_table_empty_row {
1.707     bisitz   6507: #	$row_count[0]++;
1.421     albertel 6508: 	return  '<tr class="LC_empty_row" >'."\n";;
                   6509:     }
                   6510: 
                   6511:     sub end_data_table_empty_row {
                   6512: 	return '</tr>'."\n";;
                   6513:     }
                   6514: 
1.367     www      6515:     sub start_data_table_header_row {
1.389     albertel 6516: 	return  '<tr class="LC_header_row">'."\n";;
1.367     www      6517:     }
                   6518: 
                   6519:     sub end_data_table_header_row {
1.389     albertel 6520: 	return '</tr>'."\n";;
1.367     www      6521:     }
1.347     albertel 6522: }
                   6523: 
1.548     albertel 6524: =pod
                   6525: 
                   6526: =item * &inhibit_menu_check($arg)
                   6527: 
                   6528: Checks for a inhibitmenu state and generates output to preserve it
                   6529: 
                   6530: Inputs:         $arg - can be any of
                   6531:                      - undef - in which case the return value is a string 
                   6532:                                to add  into arguments list of a uri
                   6533:                      - 'input' - in which case the return value is a HTML
                   6534:                                  <form> <input> field of type hidden to
                   6535:                                  preserve the value
                   6536:                      - a url - in which case the return value is the url with
                   6537:                                the neccesary cgi args added to preserve the
                   6538:                                inhibitmenu state
                   6539:                      - a ref to a url - no return value, but the string is
                   6540:                                         updated to include the neccessary cgi
                   6541:                                         args to preserve the inhibitmenu state
                   6542: 
                   6543: =cut
                   6544: 
                   6545: sub inhibit_menu_check {
                   6546:     my ($arg) = @_;
                   6547:     &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
                   6548:     if ($arg eq 'input') {
                   6549: 	if ($env{'form.inhibitmenu'}) {
                   6550: 	    return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
                   6551: 	} else {
                   6552: 	    return
                   6553: 	}
                   6554:     }
                   6555:     if ($env{'form.inhibitmenu'}) {
                   6556: 	if (ref($arg)) {
                   6557: 	    $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
                   6558: 	} elsif ($arg eq '') {
                   6559: 	    $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
                   6560: 	} else {
                   6561: 	    $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
                   6562: 	}
                   6563:     }
                   6564:     if (!ref($arg)) {
                   6565: 	return $arg;
                   6566:     }
                   6567: }
                   6568: 
1.251     albertel 6569: ###############################################
1.182     matthew  6570: 
                   6571: =pod
                   6572: 
1.549     albertel 6573: =back
                   6574: 
                   6575: =head1 User Information Routines
                   6576: 
                   6577: =over 4
                   6578: 
1.405     albertel 6579: =item * &get_users_function()
1.182     matthew  6580: 
                   6581: Used by &bodytag to determine the current users primary role.
                   6582: Returns either 'student','coordinator','admin', or 'author'.
                   6583: 
                   6584: =cut
                   6585: 
                   6586: ###############################################
                   6587: sub get_users_function {
                   6588:     my $function = 'student';
1.258     albertel 6589:     if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
1.182     matthew  6590:         $function='coordinator';
                   6591:     }
1.258     albertel 6592:     if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182     matthew  6593:         $function='admin';
                   6594:     }
1.258     albertel 6595:     if (($env{'request.role'}=~/^(au|ca)/) ||
1.182     matthew  6596:         ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
                   6597:         $function='author';
                   6598:     }
                   6599:     return $function;
1.54      www      6600: }
1.99      www      6601: 
                   6602: ###############################################
                   6603: 
1.233     raeburn  6604: =pod
                   6605: 
1.542     raeburn  6606: =item * &check_user_status()
1.274     raeburn  6607: 
                   6608: Determines current status of supplied role for a
                   6609: specific user. Roles can be active, previous or future.
                   6610: 
                   6611: Inputs: 
                   6612: user's domain, user's username, course's domain,
1.375     raeburn  6613: course's number, optional section ID.
1.274     raeburn  6614: 
                   6615: Outputs:
                   6616: role status: active, previous or future. 
                   6617: 
                   6618: =cut
                   6619: 
                   6620: sub check_user_status {
1.412     raeburn  6621:     my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274     raeburn  6622:     my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
                   6623:     my @uroles = keys %userinfo;
                   6624:     my $srchstr;
                   6625:     my $active_chk = 'none';
1.412     raeburn  6626:     my $now = time;
1.274     raeburn  6627:     if (@uroles > 0) {
1.412     raeburn  6628:         if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
1.274     raeburn  6629:             $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
                   6630:         } else {
1.412     raeburn  6631:             $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
                   6632:         }
                   6633:         if (grep/^\Q$srchstr\E$/,@uroles) {
1.274     raeburn  6634:             my $role_end = 0;
                   6635:             my $role_start = 0;
                   6636:             $active_chk = 'active';
1.412     raeburn  6637:             if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
                   6638:                 $role_end = $1;
                   6639:                 if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
                   6640:                     $role_start = $1;
1.274     raeburn  6641:                 }
                   6642:             }
                   6643:             if ($role_start > 0) {
1.412     raeburn  6644:                 if ($now < $role_start) {
1.274     raeburn  6645:                     $active_chk = 'future';
                   6646:                 }
                   6647:             }
                   6648:             if ($role_end > 0) {
1.412     raeburn  6649:                 if ($now > $role_end) {
1.274     raeburn  6650:                     $active_chk = 'previous';
                   6651:                 }
                   6652:             }
                   6653:         }
                   6654:     }
                   6655:     return $active_chk;
                   6656: }
                   6657: 
                   6658: ###############################################
                   6659: 
                   6660: =pod
                   6661: 
1.405     albertel 6662: =item * &get_sections()
1.233     raeburn  6663: 
                   6664: Determines all the sections for a course including
                   6665: sections with students and sections containing other roles.
1.419     raeburn  6666: Incoming parameters: 
                   6667: 
                   6668: 1. domain
                   6669: 2. course number 
                   6670: 3. reference to array containing roles for which sections should 
                   6671: be gathered (optional).
                   6672: 4. reference to array containing status types for which sections 
                   6673: should be gathered (optional).
                   6674: 
                   6675: If the third argument is undefined, sections are gathered for any role. 
                   6676: If the fourth argument is undefined, sections are gathered for any status.
                   6677: Permissible values are 'active' or 'future' or 'previous'.
1.233     raeburn  6678:  
1.374     raeburn  6679: Returns section hash (keys are section IDs, values are
                   6680: number of users in each section), subject to the
1.419     raeburn  6681: optional roles filter, optional status filter 
1.233     raeburn  6682: 
                   6683: =cut
                   6684: 
                   6685: ###############################################
                   6686: sub get_sections {
1.419     raeburn  6687:     my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366     albertel 6688:     if (!defined($cdom) || !defined($cnum)) {
                   6689:         my $cid =  $env{'request.course.id'};
                   6690: 
                   6691: 	return if (!defined($cid));
                   6692: 
                   6693:         $cdom = $env{'course.'.$cid.'.domain'};
                   6694:         $cnum = $env{'course.'.$cid.'.num'};
                   6695:     }
                   6696: 
                   6697:     my %sectioncount;
1.419     raeburn  6698:     my $now = time;
1.240     albertel 6699: 
1.366     albertel 6700:     if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276     albertel 6701: 	my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240     albertel 6702: 	my $sec_index = &Apache::loncoursedata::CL_SECTION();
                   6703: 	my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419     raeburn  6704:         my $start_index = &Apache::loncoursedata::CL_START();
                   6705:         my $end_index = &Apache::loncoursedata::CL_END();
                   6706:         my $status;
1.366     albertel 6707: 	while (my ($student,$data) = each(%$classlist)) {
1.419     raeburn  6708: 	    my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
                   6709: 				                     $data->[$status_index],
                   6710:                                                      $data->[$start_index],
                   6711:                                                      $data->[$end_index]);
                   6712:             if ($stu_status eq 'Active') {
                   6713:                 $status = 'active';
                   6714:             } elsif ($end < $now) {
                   6715:                 $status = 'previous';
                   6716:             } elsif ($start > $now) {
                   6717:                 $status = 'future';
                   6718:             } 
                   6719: 	    if ($section ne '-1' && $section !~ /^\s*$/) {
                   6720:                 if ((!defined($possible_status)) || (($status ne '') && 
                   6721:                     (grep/^\Q$status\E$/,@{$possible_status}))) { 
                   6722: 		    $sectioncount{$section}++;
                   6723:                 }
1.240     albertel 6724: 	    }
                   6725: 	}
                   6726:     }
                   6727:     my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   6728:     foreach my $user (sort(keys(%courseroles))) {
                   6729: 	if ($user !~ /^(\w{2})/) { next; }
                   6730: 	my ($role) = ($user =~ /^(\w{2})/);
                   6731: 	if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419     raeburn  6732: 	my ($section,$status);
1.240     albertel 6733: 	if ($role eq 'cr' &&
                   6734: 	    $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
                   6735: 	    $section=$1;
                   6736: 	}
                   6737: 	if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
                   6738: 	if (!defined($section) || $section eq '-1') { next; }
1.419     raeburn  6739:         my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
                   6740:         if ($end == -1 && $start == -1) {
                   6741:             next; #deleted role
                   6742:         }
                   6743:         if (!defined($possible_status)) { 
                   6744:             $sectioncount{$section}++;
                   6745:         } else {
                   6746:             if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
                   6747:                 $status = 'active';
                   6748:             } elsif ($end < $now) {
                   6749:                 $status = 'future';
                   6750:             } elsif ($start > $now) {
                   6751:                 $status = 'previous';
                   6752:             }
                   6753:             if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
                   6754:                 $sectioncount{$section}++;
                   6755:             }
                   6756:         }
1.233     raeburn  6757:     }
1.366     albertel 6758:     return %sectioncount;
1.233     raeburn  6759: }
                   6760: 
1.274     raeburn  6761: ###############################################
1.294     raeburn  6762: 
                   6763: =pod
1.405     albertel 6764: 
                   6765: =item * &get_course_users()
                   6766: 
1.275     raeburn  6767: Retrieves usernames:domains for users in the specified course
                   6768: with specific role(s), and access status. 
                   6769: 
                   6770: Incoming parameters:
1.277     albertel 6771: 1. course domain
                   6772: 2. course number
                   6773: 3. access status: users must have - either active, 
1.275     raeburn  6774: previous, future, or all.
1.277     albertel 6775: 4. reference to array of permissible roles
1.288     raeburn  6776: 5. reference to array of section restrictions (optional)
                   6777: 6. reference to results object (hash of hashes).
                   6778: 7. reference to optional userdata hash
1.609     raeburn  6779: 8. reference to optional statushash
1.630     raeburn  6780: 9. flag if privileged users (except those set to unhide in
                   6781:    course settings) should be excluded    
1.609     raeburn  6782: Keys of top level results hash are roles.
1.275     raeburn  6783: Keys of inner hashes are username:domain, with 
                   6784: values set to access type.
1.288     raeburn  6785: Optional userdata hash returns an array with arguments in the 
                   6786: same order as loncoursedata::get_classlist() for student data.
                   6787: 
1.609     raeburn  6788: Optional statushash returns
                   6789: 
1.288     raeburn  6790: Entries for end, start, section and status are blank because
                   6791: of the possibility of multiple values for non-student roles.
                   6792: 
1.275     raeburn  6793: =cut
1.405     albertel 6794: 
1.275     raeburn  6795: ###############################################
1.405     albertel 6796: 
1.275     raeburn  6797: sub get_course_users {
1.630     raeburn  6798:     my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288     raeburn  6799:     my %idx = ();
1.419     raeburn  6800:     my %seclists;
1.288     raeburn  6801: 
                   6802:     $idx{udom} = &Apache::loncoursedata::CL_SDOM();
                   6803:     $idx{uname} =  &Apache::loncoursedata::CL_SNAME();
                   6804:     $idx{end} = &Apache::loncoursedata::CL_END();
                   6805:     $idx{start} = &Apache::loncoursedata::CL_START();
                   6806:     $idx{id} = &Apache::loncoursedata::CL_ID();
                   6807:     $idx{section} = &Apache::loncoursedata::CL_SECTION();
                   6808:     $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
                   6809:     $idx{status} = &Apache::loncoursedata::CL_STATUS();
                   6810: 
1.290     albertel 6811:     if (grep(/^st$/,@{$roles})) {
1.276     albertel 6812:         my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278     raeburn  6813:         my $now = time;
1.277     albertel 6814:         foreach my $student (keys(%{$classlist})) {
1.288     raeburn  6815:             my $match = 0;
1.412     raeburn  6816:             my $secmatch = 0;
1.419     raeburn  6817:             my $section = $$classlist{$student}[$idx{section}];
1.609     raeburn  6818:             my $status = $$classlist{$student}[$idx{status}];
1.419     raeburn  6819:             if ($section eq '') {
                   6820:                 $section = 'none';
                   6821:             }
1.291     albertel 6822:             if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 6823:                 if (grep(/^all$/,@{$sections})) {
1.412     raeburn  6824:                     $secmatch = 1;
                   6825:                 } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420     albertel 6826:                     if (grep(/^none$/,@{$sections})) {
1.412     raeburn  6827:                         $secmatch = 1;
                   6828:                     }
                   6829:                 } else {  
1.419     raeburn  6830: 		    if (grep(/^\Q$section\E$/,@{$sections})) {
1.412     raeburn  6831: 		        $secmatch = 1;
                   6832:                     }
1.290     albertel 6833: 		}
1.412     raeburn  6834:                 if (!$secmatch) {
                   6835:                     next;
                   6836:                 }
1.419     raeburn  6837:             }
1.275     raeburn  6838:             if (defined($$types{'active'})) {
1.288     raeburn  6839:                 if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275     raeburn  6840:                     push(@{$$users{st}{$student}},'active');
1.288     raeburn  6841:                     $match = 1;
1.275     raeburn  6842:                 }
                   6843:             }
                   6844:             if (defined($$types{'previous'})) {
1.609     raeburn  6845:                 if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275     raeburn  6846:                     push(@{$$users{st}{$student}},'previous');
1.288     raeburn  6847:                     $match = 1;
1.275     raeburn  6848:                 }
                   6849:             }
                   6850:             if (defined($$types{'future'})) {
1.609     raeburn  6851:                 if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275     raeburn  6852:                     push(@{$$users{st}{$student}},'future');
1.288     raeburn  6853:                     $match = 1;
1.275     raeburn  6854:                 }
                   6855:             }
1.609     raeburn  6856:             if ($match) {
                   6857:                 push(@{$seclists{$student}},$section);
                   6858:                 if (ref($userdata) eq 'HASH') {
                   6859:                     $$userdata{$student} = $$classlist{$student};
                   6860:                 }
                   6861:                 if (ref($statushash) eq 'HASH') {
                   6862:                     $statushash->{$student}{'st'}{$section} = $status;
                   6863:                 }
1.288     raeburn  6864:             }
1.275     raeburn  6865:         }
                   6866:     }
1.412     raeburn  6867:     if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439     raeburn  6868:         my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   6869:         my $now = time;
1.609     raeburn  6870:         my %displaystatus = ( previous => 'Expired',
                   6871:                               active   => 'Active',
                   6872:                               future   => 'Future',
                   6873:                             );
1.630     raeburn  6874:         my %nothide;
                   6875:         if ($hidepriv) {
                   6876:             my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
                   6877:             foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
                   6878:                 if ($user !~ /:/) {
                   6879:                     $nothide{join(':',split(/[\@]/,$user))}=1;
                   6880:                 } else {
                   6881:                     $nothide{$user} = 1;
                   6882:                 }
                   6883:             }
                   6884:         }
1.439     raeburn  6885:         foreach my $person (sort(keys(%coursepersonnel))) {
1.288     raeburn  6886:             my $match = 0;
1.412     raeburn  6887:             my $secmatch = 0;
1.439     raeburn  6888:             my $status;
1.412     raeburn  6889:             my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275     raeburn  6890:             $user =~ s/:$//;
1.439     raeburn  6891:             my ($end,$start) = split(/:/,$coursepersonnel{$person});
                   6892:             if ($end == -1 || $start == -1) {
                   6893:                 next;
                   6894:             }
                   6895:             if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
                   6896:                 (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412     raeburn  6897:                 my ($uname,$udom) = split(/:/,$user);
                   6898:                 if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 6899:                     if (grep(/^all$/,@{$sections})) {
1.412     raeburn  6900:                         $secmatch = 1;
                   6901:                     } elsif ($usec eq '') {
1.420     albertel 6902:                         if (grep(/^none$/,@{$sections})) {
1.412     raeburn  6903:                             $secmatch = 1;
                   6904:                         }
                   6905:                     } else {
                   6906:                         if (grep(/^\Q$usec\E$/,@{$sections})) {
                   6907:                             $secmatch = 1;
                   6908:                         }
                   6909:                     }
                   6910:                     if (!$secmatch) {
                   6911:                         next;
                   6912:                     }
1.288     raeburn  6913:                 }
1.419     raeburn  6914:                 if ($usec eq '') {
                   6915:                     $usec = 'none';
                   6916:                 }
1.275     raeburn  6917:                 if ($uname ne '' && $udom ne '') {
1.630     raeburn  6918:                     if ($hidepriv) {
                   6919:                         if ((&Apache::lonnet::privileged($uname,$udom)) &&
                   6920:                             (!$nothide{$uname.':'.$udom})) {
                   6921:                             next;
                   6922:                         }
                   6923:                     }
1.503     raeburn  6924:                     if ($end > 0 && $end < $now) {
1.439     raeburn  6925:                         $status = 'previous';
                   6926:                     } elsif ($start > $now) {
                   6927:                         $status = 'future';
                   6928:                     } else {
                   6929:                         $status = 'active';
                   6930:                     }
1.277     albertel 6931:                     foreach my $type (keys(%{$types})) { 
1.275     raeburn  6932:                         if ($status eq $type) {
1.420     albertel 6933:                             if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419     raeburn  6934:                                 push(@{$$users{$role}{$user}},$type);
                   6935:                             }
1.288     raeburn  6936:                             $match = 1;
                   6937:                         }
                   6938:                     }
1.419     raeburn  6939:                     if (($match) && (ref($userdata) eq 'HASH')) {
                   6940:                         if (!exists($$userdata{$uname.':'.$udom})) {
                   6941: 			    &get_user_info($udom,$uname,\%idx,$userdata);
                   6942:                         }
1.420     albertel 6943:                         if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419     raeburn  6944:                             push(@{$seclists{$uname.':'.$udom}},$usec);
                   6945:                         }
1.609     raeburn  6946:                         if (ref($statushash) eq 'HASH') {
                   6947:                             $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
                   6948:                         }
1.275     raeburn  6949:                     }
                   6950:                 }
                   6951:             }
                   6952:         }
1.290     albertel 6953:         if (grep(/^ow$/,@{$roles})) {
1.279     raeburn  6954:             if ((defined($cdom)) && (defined($cnum))) {
                   6955:                 my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
                   6956:                 if ( defined($csettings{'internal.courseowner'}) ) {
                   6957:                     my $owner = $csettings{'internal.courseowner'};
1.609     raeburn  6958:                     next if ($owner eq '');
                   6959:                     my ($ownername,$ownerdom);
                   6960:                     if ($owner =~ /^([^:]+):([^:]+)$/) {
                   6961:                         $ownername = $1;
                   6962:                         $ownerdom = $2;
                   6963:                     } else {
                   6964:                         $ownername = $owner;
                   6965:                         $ownerdom = $cdom;
                   6966:                         $owner = $ownername.':'.$ownerdom;
1.439     raeburn  6967:                     }
                   6968:                     @{$$users{'ow'}{$owner}} = 'any';
1.290     albertel 6969:                     if (defined($userdata) && 
1.609     raeburn  6970: 			!exists($$userdata{$owner})) {
                   6971: 			&get_user_info($ownerdom,$ownername,\%idx,$userdata);
                   6972:                         if (!grep(/^none$/,@{$seclists{$owner}})) {
                   6973:                             push(@{$seclists{$owner}},'none');
                   6974:                         }
                   6975:                         if (ref($statushash) eq 'HASH') {
                   6976:                             $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419     raeburn  6977:                         }
1.290     albertel 6978: 		    }
1.279     raeburn  6979:                 }
                   6980:             }
                   6981:         }
1.419     raeburn  6982:         foreach my $user (keys(%seclists)) {
                   6983:             @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
                   6984:             $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
                   6985:         }
1.275     raeburn  6986:     }
                   6987:     return;
                   6988: }
                   6989: 
1.288     raeburn  6990: sub get_user_info {
                   6991:     my ($udom,$uname,$idx,$userdata) = @_;
1.289     albertel 6992:     $$userdata{$uname.':'.$udom}[$$idx{fullname}] = 
                   6993: 	&plainname($uname,$udom,'lastname');
1.291     albertel 6994:     $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297     raeburn  6995:     $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609     raeburn  6996:     my %idhash =  &Apache::lonnet::idrget($udom,($uname));
                   6997:     $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname}; 
1.288     raeburn  6998:     return;
                   6999: }
1.275     raeburn  7000: 
1.472     raeburn  7001: ###############################################
                   7002: 
                   7003: =pod
                   7004: 
                   7005: =item * &get_user_quota()
                   7006: 
                   7007: Retrieves quota assigned for storage of portfolio files for a user  
                   7008: 
                   7009: Incoming parameters:
                   7010: 1. user's username
                   7011: 2. user's domain
                   7012: 
                   7013: Returns:
1.536     raeburn  7014: 1. Disk quota (in Mb) assigned to student.
                   7015: 2. (Optional) Type of setting: custom or default
                   7016:    (individually assigned or default for user's 
                   7017:    institutional status).
                   7018: 3. (Optional) - User's institutional status (e.g., faculty, staff
                   7019:    or student - types as defined in localenroll::inst_usertypes 
                   7020:    for user's domain, which determines default quota for user.
                   7021: 4. (Optional) - Default quota which would apply to the user.
1.472     raeburn  7022: 
                   7023: If a value has been stored in the user's environment, 
1.536     raeburn  7024: it will return that, otherwise it returns the maximal default
                   7025: defined for the user's instituional status(es) in the domain.
1.472     raeburn  7026: 
                   7027: =cut
                   7028: 
                   7029: ###############################################
                   7030: 
                   7031: 
                   7032: sub get_user_quota {
                   7033:     my ($uname,$udom) = @_;
1.536     raeburn  7034:     my ($quota,$quotatype,$settingstatus,$defquota);
1.472     raeburn  7035:     if (!defined($udom)) {
                   7036:         $udom = $env{'user.domain'};
                   7037:     }
                   7038:     if (!defined($uname)) {
                   7039:         $uname = $env{'user.name'};
                   7040:     }
                   7041:     if (($udom eq '' || $uname eq '') ||
                   7042:         ($udom eq 'public') && ($uname eq 'public')) {
                   7043:         $quota = 0;
1.536     raeburn  7044:         $quotatype = 'default';
                   7045:         $defquota = 0; 
1.472     raeburn  7046:     } else {
1.536     raeburn  7047:         my $inststatus;
1.472     raeburn  7048:         if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
                   7049:             $quota = $env{'environment.portfolioquota'};
1.536     raeburn  7050:             $inststatus = $env{'environment.inststatus'};
1.472     raeburn  7051:         } else {
1.536     raeburn  7052:             my %userenv = 
                   7053:                 &Apache::lonnet::get('environment',['portfolioquota',
                   7054:                                      'inststatus'],$udom,$uname);
1.472     raeburn  7055:             my ($tmp) = keys(%userenv);
                   7056:             if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   7057:                 $quota = $userenv{'portfolioquota'};
1.536     raeburn  7058:                 $inststatus = $userenv{'inststatus'};
1.472     raeburn  7059:             } else {
                   7060:                 undef(%userenv);
                   7061:             }
                   7062:         }
1.536     raeburn  7063:         ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472     raeburn  7064:         if ($quota eq '') {
1.536     raeburn  7065:             $quota = $defquota;
                   7066:             $quotatype = 'default';
                   7067:         } else {
                   7068:             $quotatype = 'custom';
1.472     raeburn  7069:         }
                   7070:     }
1.536     raeburn  7071:     if (wantarray) {
                   7072:         return ($quota,$quotatype,$settingstatus,$defquota);
                   7073:     } else {
                   7074:         return $quota;
                   7075:     }
1.472     raeburn  7076: }
                   7077: 
                   7078: ###############################################
                   7079: 
                   7080: =pod
                   7081: 
                   7082: =item * &default_quota()
                   7083: 
1.536     raeburn  7084: Retrieves default quota assigned for storage of user portfolio files,
                   7085: given an (optional) user's institutional status.
1.472     raeburn  7086: 
                   7087: Incoming parameters:
                   7088: 1. domain
1.536     raeburn  7089: 2. (Optional) institutional status(es).  This is a : separated list of 
                   7090:    status types (e.g., faculty, staff, student etc.)
                   7091:    which apply to the user for whom the default is being retrieved.
                   7092:    If the institutional status string in undefined, the domain
                   7093:    default quota will be returned. 
1.472     raeburn  7094: 
                   7095: Returns:
                   7096: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536     raeburn  7097: 2. (Optional) institutional type which determined the value of the
                   7098:    default quota.
1.472     raeburn  7099: 
                   7100: If a value has been stored in the domain's configuration db,
                   7101: it will return that, otherwise it returns 20 (for backwards 
                   7102: compatibility with domains which have not set up a configuration
                   7103: db file; the original statically defined portfolio quota was 20 Mb). 
                   7104: 
1.536     raeburn  7105: If the user's status includes multiple types (e.g., staff and student),
                   7106: the largest default quota which applies to the user determines the
                   7107: default quota returned.
                   7108: 
1.780     raeburn  7109: =back
                   7110: 
1.472     raeburn  7111: =cut
                   7112: 
                   7113: ###############################################
                   7114: 
                   7115: 
                   7116: sub default_quota {
1.536     raeburn  7117:     my ($udom,$inststatus) = @_;
                   7118:     my ($defquota,$settingstatus);
                   7119:     my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622     raeburn  7120:                                             ['quotas'],$udom);
                   7121:     if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536     raeburn  7122:         if ($inststatus ne '') {
1.765     raeburn  7123:             my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536     raeburn  7124:             foreach my $item (@statuses) {
1.711     raeburn  7125:                 if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
                   7126:                     if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
                   7127:                         if ($defquota eq '') {
                   7128:                             $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
                   7129:                             $settingstatus = $item;
                   7130:                         } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
                   7131:                             $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
                   7132:                             $settingstatus = $item;
                   7133:                         }
                   7134:                     }
                   7135:                 } else {
                   7136:                     if ($quotahash{'quotas'}{$item} ne '') {
                   7137:                         if ($defquota eq '') {
                   7138:                             $defquota = $quotahash{'quotas'}{$item};
                   7139:                             $settingstatus = $item;
                   7140:                         } elsif ($quotahash{'quotas'}{$item} > $defquota) {
                   7141:                             $defquota = $quotahash{'quotas'}{$item};
                   7142:                             $settingstatus = $item;
                   7143:                         }
1.536     raeburn  7144:                     }
                   7145:                 }
                   7146:             }
                   7147:         }
                   7148:         if ($defquota eq '') {
1.711     raeburn  7149:             if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
                   7150:                 $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
                   7151:             } else {
                   7152:                 $defquota = $quotahash{'quotas'}{'default'};
                   7153:             }
1.536     raeburn  7154:             $settingstatus = 'default';
                   7155:         }
                   7156:     } else {
                   7157:         $settingstatus = 'default';
                   7158:         $defquota = 20;
                   7159:     }
                   7160:     if (wantarray) {
                   7161:         return ($defquota,$settingstatus);
1.472     raeburn  7162:     } else {
1.536     raeburn  7163:         return $defquota;
1.472     raeburn  7164:     }
                   7165: }
                   7166: 
1.384     raeburn  7167: sub get_secgrprole_info {
                   7168:     my ($cdom,$cnum,$needroles,$type)  = @_;
                   7169:     my %sections_count = &get_sections($cdom,$cnum);
                   7170:     my @sections =  (sort {$a <=> $b} keys(%sections_count));
                   7171:     my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
                   7172:     my @groups = sort(keys(%curr_groups));
                   7173:     my $allroles = [];
                   7174:     my $rolehash;
                   7175:     my $accesshash = {
                   7176:                      active => 'Currently has access',
                   7177:                      future => 'Will have future access',
                   7178:                      previous => 'Previously had access',
                   7179:                   };
                   7180:     if ($needroles) {
                   7181:         $rolehash = {'all' => 'all'};
1.385     albertel 7182:         my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   7183: 	if (&Apache::lonnet::error(%user_roles)) {
                   7184: 	    undef(%user_roles);
                   7185: 	}
                   7186:         foreach my $item (keys(%user_roles)) {
1.384     raeburn  7187:             my ($role)=split(/\:/,$item,2);
                   7188:             if ($role eq 'cr') { next; }
                   7189:             if ($role =~ /^cr/) {
                   7190:                 $$rolehash{$role} = (split('/',$role))[3];
                   7191:             } else {
                   7192:                 $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
                   7193:             }
                   7194:         }
                   7195:         foreach my $key (sort(keys(%{$rolehash}))) {
                   7196:             push(@{$allroles},$key);
                   7197:         }
                   7198:         push (@{$allroles},'st');
                   7199:         $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
                   7200:     }
                   7201:     return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
                   7202: }
                   7203: 
1.555     raeburn  7204: sub user_picker {
1.627     raeburn  7205:     my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555     raeburn  7206:     my $currdom = $dom;
                   7207:     my %curr_selected = (
                   7208:                         srchin => 'dom',
1.580     raeburn  7209:                         srchby => 'lastname',
1.555     raeburn  7210:                       );
                   7211:     my $srchterm;
1.625     raeburn  7212:     if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555     raeburn  7213:         if ($srch->{'srchby'} ne '') {
                   7214:             $curr_selected{'srchby'} = $srch->{'srchby'};
                   7215:         }
                   7216:         if ($srch->{'srchin'} ne '') {
                   7217:             $curr_selected{'srchin'} = $srch->{'srchin'};
                   7218:         }
                   7219:         if ($srch->{'srchtype'} ne '') {
                   7220:             $curr_selected{'srchtype'} = $srch->{'srchtype'};
                   7221:         }
                   7222:         if ($srch->{'srchdomain'} ne '') {
                   7223:             $currdom = $srch->{'srchdomain'};
                   7224:         }
                   7225:         $srchterm = $srch->{'srchterm'};
                   7226:     }
                   7227:     my %lt=&Apache::lonlocal::texthash(
1.573     raeburn  7228:                     'usr'       => 'Search criteria',
1.563     raeburn  7229:                     'doma'      => 'Domain/institution to search',
1.558     albertel 7230:                     'uname'     => 'username',
                   7231:                     'lastname'  => 'last name',
1.555     raeburn  7232:                     'lastfirst' => 'last name, first name',
1.558     albertel 7233:                     'crs'       => 'in this course',
1.576     raeburn  7234:                     'dom'       => 'in selected LON-CAPA domain', 
1.558     albertel 7235:                     'alc'       => 'all LON-CAPA',
1.573     raeburn  7236:                     'instd'     => 'in institutional directory for selected domain',
1.558     albertel 7237:                     'exact'     => 'is',
                   7238:                     'contains'  => 'contains',
1.569     raeburn  7239:                     'begins'    => 'begins with',
1.571     raeburn  7240:                     'youm'      => "You must include some text to search for.",
                   7241:                     'thte'      => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
                   7242:                     'thet'      => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
                   7243:                     'yomc'      => "You must choose a domain when using an institutional directory search.",
                   7244:                     'ymcd'      => "You must choose a domain when using a domain search.",
                   7245:                     'whus'      => "When using searching by last,first you must include a comma as separator between last name and first name.",
                   7246:                     'whse'      => "When searching by last,first you must include at least one character in the first name.",
                   7247:                      'thfo'     => "The following need to be corrected before the search can be run:",
1.555     raeburn  7248:                                        );
1.563     raeburn  7249:     my $domform = &select_dom_form($currdom,'srchdomain',1,1);
                   7250:     my $srchinsel = ' <select name="srchin">';
1.555     raeburn  7251: 
                   7252:     my @srchins = ('crs','dom','alc','instd');
                   7253: 
                   7254:     foreach my $option (@srchins) {
                   7255:         # FIXME 'alc' option unavailable until 
                   7256:         #       loncreateuser::print_user_query_page()
                   7257:         #       has been completed.
                   7258:         next if ($option eq 'alc');
                   7259:         next if ($option eq 'crs' && !$env{'request.course.id'});
1.563     raeburn  7260:         if ($curr_selected{'srchin'} eq $option) {
                   7261:             $srchinsel .= ' 
                   7262:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7263:         } else {
                   7264:             $srchinsel .= '
                   7265:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7266:         }
1.555     raeburn  7267:     }
1.563     raeburn  7268:     $srchinsel .= "\n  </select>\n";
1.555     raeburn  7269: 
                   7270:     my $srchbysel =  ' <select name="srchby">';
1.580     raeburn  7271:     foreach my $option ('lastname','lastfirst','uname') {
1.555     raeburn  7272:         if ($curr_selected{'srchby'} eq $option) {
                   7273:             $srchbysel .= '
                   7274:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7275:         } else {
                   7276:             $srchbysel .= '
                   7277:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7278:          }
                   7279:     }
                   7280:     $srchbysel .= "\n  </select>\n";
                   7281: 
                   7282:     my $srchtypesel = ' <select name="srchtype">';
1.580     raeburn  7283:     foreach my $option ('begins','contains','exact') {
1.555     raeburn  7284:         if ($curr_selected{'srchtype'} eq $option) {
                   7285:             $srchtypesel .= '
                   7286:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7287:         } else {
                   7288:             $srchtypesel .= '
                   7289:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7290:         }
                   7291:     }
                   7292:     $srchtypesel .= "\n  </select>\n";
                   7293: 
1.558     albertel 7294:     my ($newuserscript,$new_user_create);
1.556     raeburn  7295: 
                   7296:     if ($forcenewuser) {
1.576     raeburn  7297:         if (ref($srch) eq 'HASH') {
                   7298:             if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627     raeburn  7299:                 if ($cancreate) {
                   7300:                     $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>';
                   7301:                 } else {
                   7302:                     my $helplink = ' href="javascript:helpMenu('."'display'".')"';
                   7303:                     my %usertypetext = (
                   7304:                         official   => 'institutional',
                   7305:                         unofficial => 'non-institutional',
                   7306:                     );
                   7307:                     $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 />';
                   7308:                 }
1.576     raeburn  7309:             }
                   7310:         }
                   7311: 
1.556     raeburn  7312:         $newuserscript = <<"ENDSCRIPT";
                   7313: 
1.570     raeburn  7314: function setSearch(createnew,callingForm) {
1.556     raeburn  7315:     if (createnew == 1) {
1.570     raeburn  7316:         for (var i=0; i<callingForm.srchby.length; i++) {
                   7317:             if (callingForm.srchby.options[i].value == 'uname') {
                   7318:                 callingForm.srchby.selectedIndex = i;
1.556     raeburn  7319:             }
                   7320:         }
1.570     raeburn  7321:         for (var i=0; i<callingForm.srchin.length; i++) {
                   7322:             if ( callingForm.srchin.options[i].value == 'dom') {
                   7323: 		callingForm.srchin.selectedIndex = i;
1.556     raeburn  7324:             }
                   7325:         }
1.570     raeburn  7326:         for (var i=0; i<callingForm.srchtype.length; i++) {
                   7327:             if (callingForm.srchtype.options[i].value == 'exact') {
                   7328:                 callingForm.srchtype.selectedIndex = i;
1.556     raeburn  7329:             }
                   7330:         }
1.570     raeburn  7331:         for (var i=0; i<callingForm.srchdomain.length; i++) {
                   7332:             if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
                   7333:                 callingForm.srchdomain.selectedIndex = i;
1.556     raeburn  7334:             }
                   7335:         }
                   7336:     }
                   7337: }
                   7338: ENDSCRIPT
1.558     albertel 7339: 
1.556     raeburn  7340:     }
                   7341: 
1.555     raeburn  7342:     my $output = <<"END_BLOCK";
1.556     raeburn  7343: <script type="text/javascript">
1.570     raeburn  7344: function validateEntry(callingForm) {
1.558     albertel 7345: 
1.556     raeburn  7346:     var checkok = 1;
1.558     albertel 7347:     var srchin;
1.570     raeburn  7348:     for (var i=0; i<callingForm.srchin.length; i++) {
                   7349: 	if ( callingForm.srchin[i].checked ) {
                   7350: 	    srchin = callingForm.srchin[i].value;
1.558     albertel 7351: 	}
                   7352:     }
                   7353: 
1.570     raeburn  7354:     var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
                   7355:     var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
                   7356:     var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
                   7357:     var srchterm =  callingForm.srchterm.value;
                   7358:     var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556     raeburn  7359:     var msg = "";
                   7360: 
                   7361:     if (srchterm == "") {
                   7362:         checkok = 0;
1.571     raeburn  7363:         msg += "$lt{'youm'}\\n";
1.556     raeburn  7364:     }
                   7365: 
1.569     raeburn  7366:     if (srchtype== 'begins') {
                   7367:         if (srchterm.length < 2) {
                   7368:             checkok = 0;
1.571     raeburn  7369:             msg += "$lt{'thte'}\\n";
1.569     raeburn  7370:         }
                   7371:     }
                   7372: 
1.556     raeburn  7373:     if (srchtype== 'contains') {
                   7374:         if (srchterm.length < 3) {
                   7375:             checkok = 0;
1.571     raeburn  7376:             msg += "$lt{'thet'}\\n";
1.556     raeburn  7377:         }
                   7378:     }
                   7379:     if (srchin == 'instd') {
                   7380:         if (srchdomain == '') {
                   7381:             checkok = 0;
1.571     raeburn  7382:             msg += "$lt{'yomc'}\\n";
1.556     raeburn  7383:         }
                   7384:     }
                   7385:     if (srchin == 'dom') {
                   7386:         if (srchdomain == '') {
                   7387:             checkok = 0;
1.571     raeburn  7388:             msg += "$lt{'ymcd'}\\n";
1.556     raeburn  7389:         }
                   7390:     }
                   7391:     if (srchby == 'lastfirst') {
                   7392:         if (srchterm.indexOf(",") == -1) {
                   7393:             checkok = 0;
1.571     raeburn  7394:             msg += "$lt{'whus'}\\n";
1.556     raeburn  7395:         }
                   7396:         if (srchterm.indexOf(",") == srchterm.length -1) {
                   7397:             checkok = 0;
1.571     raeburn  7398:             msg += "$lt{'whse'}\\n";
1.556     raeburn  7399:         }
                   7400:     }
                   7401:     if (checkok == 0) {
1.571     raeburn  7402:         alert("$lt{'thfo'}\\n"+msg);
1.556     raeburn  7403:         return;
                   7404:     }
                   7405:     if (checkok == 1) {
1.570     raeburn  7406:         callingForm.submit();
1.556     raeburn  7407:     }
                   7408: }
                   7409: 
                   7410: $newuserscript
                   7411: 
                   7412: </script>
1.558     albertel 7413: 
                   7414: $new_user_create
                   7415: 
1.555     raeburn  7416: <table>
1.558     albertel 7417:  <tr>
1.573     raeburn  7418:   <td>$lt{'doma'}:</td>
                   7419:   <td>$domform</td>
                   7420:   </td>
                   7421:  </tr>
                   7422:  <tr>
                   7423:   <td>$lt{'usr'}:</td>
1.563     raeburn  7424:   <td>$srchbysel
                   7425:       $srchtypesel 
                   7426:       <input type="text" size="15" name="srchterm" value="$srchterm" />
1.564     albertel 7427:       $srchinsel 
1.563     raeburn  7428:   </td>
                   7429:  </tr>
1.555     raeburn  7430: </table>
                   7431: <br />
                   7432: END_BLOCK
1.558     albertel 7433: 
1.555     raeburn  7434:     return $output;
                   7435: }
                   7436: 
1.612     raeburn  7437: sub user_rule_check {
1.615     raeburn  7438:     my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612     raeburn  7439:     my $response;
                   7440:     if (ref($usershash) eq 'HASH') {
                   7441:         foreach my $user (keys(%{$usershash})) {
                   7442:             my ($uname,$udom) = split(/:/,$user);
                   7443:             next if ($udom eq '' || $uname eq '');
1.615     raeburn  7444:             my ($id,$newuser);
1.612     raeburn  7445:             if (ref($usershash->{$user}) eq 'HASH') {
1.615     raeburn  7446:                 $newuser = $usershash->{$user}->{'newuser'};
1.612     raeburn  7447:                 $id = $usershash->{$user}->{'id'};
                   7448:             }
                   7449:             my $inst_response;
                   7450:             if (ref($checks) eq 'HASH') {
                   7451:                 if (defined($checks->{'username'})) {
1.615     raeburn  7452:                     ($inst_response,%{$inst_results->{$user}}) = 
1.612     raeburn  7453:                         &Apache::lonnet::get_instuser($udom,$uname);
                   7454:                 } elsif (defined($checks->{'id'})) {
1.615     raeburn  7455:                     ($inst_response,%{$inst_results->{$user}}) =
1.612     raeburn  7456:                         &Apache::lonnet::get_instuser($udom,undef,$id);
                   7457:                 }
1.615     raeburn  7458:             } else {
                   7459:                 ($inst_response,%{$inst_results->{$user}}) =
                   7460:                     &Apache::lonnet::get_instuser($udom,$uname);
                   7461:                 return;
1.612     raeburn  7462:             }
1.615     raeburn  7463:             if (!$got_rules->{$udom}) {
1.612     raeburn  7464:                 my %domconfig = &Apache::lonnet::get_dom('configuration',
                   7465:                                                   ['usercreation'],$udom);
                   7466:                 if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615     raeburn  7467:                     foreach my $item ('username','id') {
1.612     raeburn  7468:                         if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
                   7469:                             $$curr_rules{$udom}{$item} = 
                   7470:                                 $domconfig{'usercreation'}{$item.'_rule'};
1.585     raeburn  7471:                         }
                   7472:                     }
                   7473:                 }
1.615     raeburn  7474:                 $got_rules->{$udom} = 1;  
1.585     raeburn  7475:             }
1.612     raeburn  7476:             foreach my $item (keys(%{$checks})) {
                   7477:                 if (ref($$curr_rules{$udom}) eq 'HASH') {
                   7478:                     if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
                   7479:                         if (@{$$curr_rules{$udom}{$item}} > 0) {
                   7480:                             my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
                   7481:                             foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
                   7482:                                 if ($rule_check{$rule}) {
                   7483:                                     $$rulematch{$user}{$item} = $rule;
                   7484:                                     if ($inst_response eq 'ok') {
1.615     raeburn  7485:                                         if (ref($inst_results) eq 'HASH') {
                   7486:                                             if (ref($inst_results->{$user}) eq 'HASH') {
                   7487:                                                 if (keys(%{$inst_results->{$user}}) == 0) {
                   7488:                                                     $$alerts{$item}{$udom}{$uname} = 1;
                   7489:                                                 }
1.612     raeburn  7490:                                             }
                   7491:                                         }
1.615     raeburn  7492:                                     }
                   7493:                                     last;
1.585     raeburn  7494:                                 }
                   7495:                             }
                   7496:                         }
                   7497:                     }
                   7498:                 }
                   7499:             }
                   7500:         }
                   7501:     }
1.612     raeburn  7502:     return;
                   7503: }
                   7504: 
                   7505: sub user_rule_formats {
                   7506:     my ($domain,$domdesc,$curr_rules,$check) = @_;
                   7507:     my %text = ( 
                   7508:                  'username' => 'Usernames',
                   7509:                  'id'       => 'IDs',
                   7510:                );
                   7511:     my $output;
                   7512:     my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
                   7513:     if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
                   7514:         if (@{$ruleorder} > 0) {
                   7515:             $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>';
                   7516:             foreach my $rule (@{$ruleorder}) {
                   7517:                 if (ref($curr_rules) eq 'ARRAY') {
                   7518:                     if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
                   7519:                         if (ref($rules->{$rule}) eq 'HASH') {
                   7520:                             $output .= '<li>'.$rules->{$rule}{'name'}.': '.
                   7521:                                         $rules->{$rule}{'desc'}.'</li>';
                   7522:                         }
                   7523:                     }
                   7524:                 }
                   7525:             }
                   7526:             $output .= '</ul>';
                   7527:         }
                   7528:     }
                   7529:     return $output;
                   7530: }
                   7531: 
                   7532: sub instrule_disallow_msg {
1.615     raeburn  7533:     my ($checkitem,$domdesc,$count,$mode) = @_;
1.612     raeburn  7534:     my $response;
                   7535:     my %text = (
                   7536:                   item   => 'username',
                   7537:                   items  => 'usernames',
                   7538:                   match  => 'matches',
                   7539:                   do     => 'does',
                   7540:                   action => 'a username',
                   7541:                   one    => 'one',
                   7542:                );
                   7543:     if ($count > 1) {
                   7544:         $text{'item'} = 'usernames';
                   7545:         $text{'match'} ='match';
                   7546:         $text{'do'} = 'do';
                   7547:         $text{'action'} = 'usernames',
                   7548:         $text{'one'} = 'ones';
                   7549:     }
                   7550:     if ($checkitem eq 'id') {
                   7551:         $text{'items'} = 'IDs';
                   7552:         $text{'item'} = 'ID';
                   7553:         $text{'action'} = 'an ID';
1.615     raeburn  7554:         if ($count > 1) {
                   7555:             $text{'item'} = 'IDs';
                   7556:             $text{'action'} = 'IDs';
                   7557:         }
1.612     raeburn  7558:     }
1.674     bisitz   7559:     $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  7560:     if ($mode eq 'upload') {
                   7561:         if ($checkitem eq 'username') {
                   7562:             $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'}.");
                   7563:         } elsif ($checkitem eq 'id') {
1.674     bisitz   7564:             $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  7565:         }
1.669     raeburn  7566:     } elsif ($mode eq 'selfcreate') {
                   7567:         if ($checkitem eq 'id') {
                   7568:             $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.");
                   7569:         }
1.615     raeburn  7570:     } else {
                   7571:         if ($checkitem eq 'username') {
                   7572:             $response .= &mt("You must choose $text{'action'} with a different format --  $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
                   7573:         } elsif ($checkitem eq 'id') {
                   7574:             $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.");
                   7575:         }
1.612     raeburn  7576:     }
                   7577:     return $response;
1.585     raeburn  7578: }
                   7579: 
1.624     raeburn  7580: sub personal_data_fieldtitles {
                   7581:     my %fieldtitles = &Apache::lonlocal::texthash (
                   7582:                         id => 'Student/Employee ID',
                   7583:                         permanentemail => 'E-mail address',
                   7584:                         lastname => 'Last Name',
                   7585:                         firstname => 'First Name',
                   7586:                         middlename => 'Middle Name',
                   7587:                         generation => 'Generation',
                   7588:                         gen => 'Generation',
1.765     raeburn  7589:                         inststatus => 'Affiliation',
1.624     raeburn  7590:                    );
                   7591:     return %fieldtitles;
                   7592: }
                   7593: 
1.642     raeburn  7594: sub sorted_inst_types {
                   7595:     my ($dom) = @_;
                   7596:     my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
                   7597:     my $othertitle = &mt('All users');
                   7598:     if ($env{'request.course.id'}) {
1.668     raeburn  7599:         $othertitle  = &mt('Any users');
1.642     raeburn  7600:     }
                   7601:     my @types;
                   7602:     if (ref($order) eq 'ARRAY') {
                   7603:         @types = @{$order};
                   7604:     }
                   7605:     if (@types == 0) {
                   7606:         if (ref($usertypes) eq 'HASH') {
                   7607:             @types = sort(keys(%{$usertypes}));
                   7608:         }
                   7609:     }
                   7610:     if (keys(%{$usertypes}) > 0) {
                   7611:         $othertitle = &mt('Other users');
                   7612:     }
                   7613:     return ($othertitle,$usertypes,\@types);
                   7614: }
                   7615: 
1.645     raeburn  7616: sub get_institutional_codes {
                   7617:     my ($settings,$allcourses,$LC_code) = @_;
                   7618: # Get complete list of course sections to update
                   7619:     my @currsections = ();
                   7620:     my @currxlists = ();
                   7621:     my $coursecode = $$settings{'internal.coursecode'};
                   7622: 
                   7623:     if ($$settings{'internal.sectionnums'} ne '') {
                   7624:         @currsections = split(/,/,$$settings{'internal.sectionnums'});
                   7625:     }
                   7626: 
                   7627:     if ($$settings{'internal.crosslistings'} ne '') {
                   7628:         @currxlists = split(/,/,$$settings{'internal.crosslistings'});
                   7629:     }
                   7630: 
                   7631:     if (@currxlists > 0) {
                   7632:         foreach (@currxlists) {
                   7633:             if (m/^([^:]+):(\w*)$/) {
                   7634:                 unless (grep/^$1$/,@{$allcourses}) {
                   7635:                     push @{$allcourses},$1;
                   7636:                     $$LC_code{$1} = $2;
                   7637:                 }
                   7638:             }
                   7639:         }
                   7640:     }
                   7641:  
                   7642:     if (@currsections > 0) {
                   7643:         foreach (@currsections) {
                   7644:             if (m/^(\w+):(\w*)$/) {
                   7645:                 my $sec = $coursecode.$1;
                   7646:                 my $lc_sec = $2;
                   7647:                 unless (grep/^$sec$/,@{$allcourses}) {
                   7648:                     push @{$allcourses},$sec;
                   7649:                     $$LC_code{$sec} = $lc_sec;
                   7650:                 }
                   7651:             }
                   7652:         }
                   7653:     }
                   7654:     return;
                   7655: }
                   7656: 
1.112     bowersj2 7657: =pod
                   7658: 
1.780     raeburn  7659: =head1 Slot Helpers
                   7660: 
                   7661: =over 4
                   7662: 
                   7663: =item * sorted_slots()
                   7664: 
                   7665: Sorts an array of slot names in order of slot start time (earliest first). 
                   7666: 
                   7667: Inputs:
                   7668: 
                   7669: =over 4
                   7670: 
                   7671: slotsarr  - Reference to array of unsorted slot names.
                   7672: 
                   7673: slots     - Reference to hash of hash, where outer hash keys are slot names.
                   7674: 
1.549     albertel 7675: =back
                   7676: 
1.780     raeburn  7677: Returns:
                   7678: 
                   7679: =over 4
                   7680: 
                   7681: sorted   - An array of slot names sorted by the start time of the slot.
                   7682: 
                   7683: =back
                   7684: 
                   7685: =back
                   7686: 
                   7687: =cut
                   7688: 
                   7689: 
                   7690: sub sorted_slots {
                   7691:     my ($slotsarr,$slots) = @_;
                   7692:     my @sorted;
                   7693:     if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
                   7694:         @sorted =
                   7695:             sort {
                   7696:                      if (ref($slots->{$a}) && ref($slots->{$b})) {
                   7697:                          return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
                   7698:                      }
                   7699:                      if (ref($slots->{$a})) { return -1;}
                   7700:                      if (ref($slots->{$b})) { return 1;}
                   7701:                      return 0;
                   7702:                  } @{$slotsarr};
                   7703:     }
                   7704:     return @sorted;
                   7705: }
                   7706: 
                   7707: 
                   7708: =pod
                   7709: 
1.549     albertel 7710: =head1 HTTP Helpers
                   7711: 
                   7712: =over 4
                   7713: 
1.648     raeburn  7714: =item * &get_unprocessed_cgi($query,$possible_names)
1.112     bowersj2 7715: 
1.258     albertel 7716: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112     bowersj2 7717: $query.  The parameters listed in $possible_names (an array reference),
1.258     albertel 7718: will be set in $env{'form.name'} if they do not already exist.
1.112     bowersj2 7719: 
                   7720: Typically called with $ENV{'QUERY_STRING'} as the first parameter.  
                   7721: $possible_names is an ref to an array of form element names.  As an example:
                   7722: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258     albertel 7723: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112     bowersj2 7724: 
                   7725: =cut
1.1       albertel 7726: 
1.6       albertel 7727: sub get_unprocessed_cgi {
1.25      albertel 7728:   my ($query,$possible_names)= @_;
1.26      matthew  7729:   # $Apache::lonxml::debug=1;
1.356     albertel 7730:   foreach my $pair (split(/&/,$query)) {
                   7731:     my ($name, $value) = split(/=/,$pair);
1.369     www      7732:     $name = &unescape($name);
1.25      albertel 7733:     if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
                   7734:       $value =~ tr/+/ /;
                   7735:       $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258     albertel 7736:       unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25      albertel 7737:     }
1.16      harris41 7738:   }
1.6       albertel 7739: }
                   7740: 
1.112     bowersj2 7741: =pod
                   7742: 
1.648     raeburn  7743: =item * &cacheheader() 
1.112     bowersj2 7744: 
                   7745: returns cache-controlling header code
                   7746: 
                   7747: =cut
                   7748: 
1.7       albertel 7749: sub cacheheader {
1.258     albertel 7750:     unless ($env{'request.method'} eq 'GET') { return ''; }
1.216     albertel 7751:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
                   7752:     my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7       albertel 7753:                 <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
                   7754:                 <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216     albertel 7755:     return $output;
1.7       albertel 7756: }
                   7757: 
1.112     bowersj2 7758: =pod
                   7759: 
1.648     raeburn  7760: =item * &no_cache($r) 
1.112     bowersj2 7761: 
                   7762: specifies header code to not have cache
                   7763: 
                   7764: =cut
                   7765: 
1.9       albertel 7766: sub no_cache {
1.216     albertel 7767:     my ($r) = @_;
                   7768:     if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258     albertel 7769: 	$env{'request.method'} ne 'GET') { return ''; }
1.216     albertel 7770:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
                   7771:     $r->no_cache(1);
                   7772:     $r->header_out("Expires" => $date);
                   7773:     $r->header_out("Pragma" => "no-cache");
1.123     www      7774: }
                   7775: 
                   7776: sub content_type {
1.181     albertel 7777:     my ($r,$type,$charset) = @_;
1.299     foxr     7778:     if ($r) {
                   7779: 	#  Note that printout.pl calls this with undef for $r.
                   7780: 	&no_cache($r);
                   7781:     }
1.258     albertel 7782:     if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181     albertel 7783:     unless ($charset) {
                   7784: 	$charset=&Apache::lonlocal::current_encoding;
                   7785:     }
                   7786:     if ($charset) { $type.='; charset='.$charset; }
                   7787:     if ($r) {
                   7788: 	$r->content_type($type);
                   7789:     } else {
                   7790: 	print("Content-type: $type\n\n");
                   7791:     }
1.9       albertel 7792: }
1.25      albertel 7793: 
1.112     bowersj2 7794: =pod
                   7795: 
1.648     raeburn  7796: =item * &add_to_env($name,$value) 
1.112     bowersj2 7797: 
1.258     albertel 7798: adds $name to the %env hash with value
1.112     bowersj2 7799: $value, if $name already exists, the entry is converted to an array
                   7800: reference and $value is added to the array.
                   7801: 
                   7802: =cut
                   7803: 
1.25      albertel 7804: sub add_to_env {
                   7805:   my ($name,$value)=@_;
1.258     albertel 7806:   if (defined($env{$name})) {
                   7807:     if (ref($env{$name})) {
1.25      albertel 7808:       #already have multiple values
1.258     albertel 7809:       push(@{ $env{$name} },$value);
1.25      albertel 7810:     } else {
                   7811:       #first time seeing multiple values, convert hash entry to an arrayref
1.258     albertel 7812:       my $first=$env{$name};
                   7813:       undef($env{$name});
                   7814:       push(@{ $env{$name} },$first,$value);
1.25      albertel 7815:     }
                   7816:   } else {
1.258     albertel 7817:     $env{$name}=$value;
1.25      albertel 7818:   }
1.31      albertel 7819: }
1.149     albertel 7820: 
                   7821: =pod
                   7822: 
1.648     raeburn  7823: =item * &get_env_multiple($name) 
1.149     albertel 7824: 
1.258     albertel 7825: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149     albertel 7826: values may be defined and end up as an array ref.
                   7827: 
                   7828: returns an array of values
                   7829: 
                   7830: =cut
                   7831: 
                   7832: sub get_env_multiple {
                   7833:     my ($name) = @_;
                   7834:     my @values;
1.258     albertel 7835:     if (defined($env{$name})) {
1.149     albertel 7836:         # exists is it an array
1.258     albertel 7837:         if (ref($env{$name})) {
                   7838:             @values=@{ $env{$name} };
1.149     albertel 7839:         } else {
1.258     albertel 7840:             $values[0]=$env{$name};
1.149     albertel 7841:         }
                   7842:     }
                   7843:     return(@values);
                   7844: }
                   7845: 
1.660     raeburn  7846: sub ask_for_embedded_content {
                   7847:     my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
                   7848:     my $upload_output = '
                   7849:    <form name="upload_embedded" action="'.$actionurl.'"
                   7850:                   method="post" enctype="multipart/form-data">';
                   7851:     $upload_output .= $state;
1.661     raeburn  7852:     $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
1.660     raeburn  7853: 
                   7854:     my $num = 0;
                   7855:     foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
                   7856:         $upload_output .= &start_data_table_row().
                   7857:             '<td>'.$embed_file.'</td><td>';
                   7858:         if ($args->{'ignore_remote_references'}
                   7859:             && $embed_file =~ m{^\w+://}) {
                   7860:             $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
                   7861:         } elsif ($args->{'error_on_invalid_names'}
                   7862:             && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
                   7863: 
                   7864:             $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
                   7865: 
                   7866:         } else {
                   7867:             $upload_output .='
1.661     raeburn  7868:            <input name="embedded_item_'.$num.'" type="file" value="" />
1.660     raeburn  7869:            <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
                   7870:             my $attrib = join(':',@{$$allfiles{$embed_file}});
                   7871:             $upload_output .=
                   7872:                 "\n\t\t".
                   7873:                 '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
                   7874:                 $attrib.'" />';
                   7875:             if (exists($$codebase{$embed_file})) {
                   7876:                 $upload_output .=
                   7877:                     "\n\t\t".
                   7878:                     '<input name="codebase_'.$num.'" type="hidden" value="'.
                   7879:                     &escape($$codebase{$embed_file}).'" />';
                   7880:             }
                   7881:         }
                   7882:         $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
                   7883:         $num++;
                   7884:     }
                   7885:     $upload_output .= &Apache::loncommon::end_data_table().'<br />
                   7886:    <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
                   7887:    <input type ="submit" value="'.&mt('Upload Listed Files').'" />
                   7888:    '.&mt('(only files for which a location has been provided will be uploaded)').'
                   7889:    </form>';
                   7890:     return $upload_output;
                   7891: }
                   7892: 
1.661     raeburn  7893: sub upload_embedded {
                   7894:     my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
                   7895:         $current_disk_usage) = @_;
                   7896:     my $output;
                   7897:     for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
                   7898:         next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
                   7899:         my $orig_uploaded_filename =
                   7900:             $env{'form.embedded_item_'.$i.'.filename'};
                   7901: 
                   7902:         $env{'form.embedded_orig_'.$i} =
                   7903:             &unescape($env{'form.embedded_orig_'.$i});
                   7904:         my ($path,$fname) =
                   7905:             ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
                   7906:         # no path, whole string is fname
                   7907:         if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
                   7908: 
                   7909:         $path = $env{'form.currentpath'}.$path;
                   7910:         $fname = &Apache::lonnet::clean_filename($fname);
                   7911:         # See if there is anything left
                   7912:         next if ($fname eq '');
                   7913: 
                   7914:         # Check if file already exists as a file or directory.
                   7915:         my ($state,$msg);
                   7916:         if ($context eq 'portfolio') {
                   7917:             my $port_path = $dirpath;
                   7918:             if ($group ne '') {
                   7919:                 $port_path = "groups/$group/$port_path";
                   7920:             }
                   7921:             ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
                   7922:                                               $dir_root,$port_path,$disk_quota,
                   7923:                                               $current_disk_usage,$uname,$udom);
                   7924:             if ($state eq 'will_exceed_quota'
                   7925:                 || $state eq 'file_locked'
                   7926:                 || $state eq 'file_exists' ) {
                   7927:                 $output .= $msg;
                   7928:                 next;
                   7929:             }
                   7930:         } elsif (($context eq 'author') || ($context eq 'testbank')) {
                   7931:             ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
                   7932:             if ($state eq 'exists') {
                   7933:                 $output .= $msg;
                   7934:                 next;
                   7935:             }
                   7936:         }
                   7937:         # Check if extension is valid
                   7938:         if (($fname =~ /\.(\w+)$/) &&
                   7939:             (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
                   7940:             $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
                   7941:             next;
                   7942:         } elsif (($fname =~ /\.(\w+)$/) &&
                   7943:                  (!defined(&Apache::loncommon::fileembstyle($1)))) {
                   7944:             $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
                   7945:             next;
                   7946:         } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
                   7947:             $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
                   7948:             next;
                   7949:         }
                   7950: 
                   7951:         $env{'form.embedded_item_'.$i.'.filename'}=$fname;
                   7952:         if ($context eq 'portfolio') {
                   7953:             my $result=
                   7954:                 &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
                   7955:                                                 $dirpath.$path);
                   7956:             if ($result !~ m|^/uploaded/|) {
                   7957:                 $output .= '<span class="LC_error">'
                   7958:                       .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
                   7959:                            ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
                   7960:                       .'</span><br />';
                   7961:                 next;
                   7962:             } else {
                   7963:                 $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
                   7964:                            $path.$fname.'</span>').'</p>';     
                   7965:             }
                   7966:         } else {
                   7967: # Save the file
                   7968:             my $target = $env{'form.embedded_item_'.$i};
                   7969:             my $fullpath = $dir_root.$dirpath.'/'.$path;
                   7970:             my $dest = $fullpath.$fname;
                   7971:             my $url = $url_root.$dirpath.'/'.$path.$fname;
                   7972:             my @parts=split(/\//,$fullpath);
                   7973:             my $count;
                   7974:             my $filepath = $dir_root;
                   7975:             for ($count=4;$count<=$#parts;$count++) {
                   7976:                 $filepath .= "/$parts[$count]";
                   7977:                 if ((-e $filepath)!=1) {
                   7978:                     mkdir($filepath,0770);
                   7979:                 }
                   7980:             }
                   7981:             my $fh;
                   7982:             if (!open($fh,'>'.$dest)) {
                   7983:                 &Apache::lonnet::logthis('Failed to create '.$dest);
                   7984:                 $output .= '<span class="LC_error">'.
                   7985:                            &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
                   7986:                            '</span><br />';
                   7987:             } else {
                   7988:                 if (!print $fh $env{'form.embedded_item_'.$i}) {
                   7989:                     &Apache::lonnet::logthis('Failed to write to '.$dest);
                   7990:                     $output .= '<span class="LC_error">'.
                   7991:                               &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
                   7992:                               '</span><br />';
                   7993:                 } else {
                   7994:                     if ($context eq 'testbank') {
                   7995:                         $output .= &mt('Embedded file uploaded successfully:').
                   7996:                                    '&nbsp;<a href="'.$url.'">'.
                   7997:                                    $orig_uploaded_filename.'</a><br />';
                   7998:                     } else {
1.705     tempelho 7999:                         $output .= '<span class=\"LC_fontsize_large\">'.
1.661     raeburn  8000:                                    &mt('View embedded file: [_1]','<a href="'.$url.'">'.
1.705     tempelho 8001:                                    $orig_uploaded_filename.'</a>').'</span><br />';
1.661     raeburn  8002:                     }
                   8003:                 }
                   8004:                 close($fh);
                   8005:             }
                   8006:         }
                   8007:     }
                   8008:     return $output;
                   8009: }
                   8010: 
                   8011: sub check_for_existing {
                   8012:     my ($path,$fname,$element) = @_;
                   8013:     my ($state,$msg);
                   8014:     if (-d $path.'/'.$fname) {
                   8015:         $state = 'exists';
                   8016:         $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
                   8017:     } elsif (-e $path.'/'.$fname) {
                   8018:         $state = 'exists';
                   8019:         $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
                   8020:     }
                   8021:     if ($state eq 'exists') {
                   8022:         $msg = '<span class="LC_error">'.$msg.'</span><br />';
                   8023:     }
                   8024:     return ($state,$msg);
                   8025: }
                   8026: 
                   8027: sub check_for_upload {
                   8028:     my ($path,$fname,$group,$element,$portfolio_root,$port_path,
                   8029:         $disk_quota,$current_disk_usage,$uname,$udom) = @_;
                   8030:     my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
                   8031:     my $getpropath = 1;
                   8032:     my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
                   8033:                                             $getpropath);
                   8034:     my $found_file = 0;
                   8035:     my $locked_file = 0;
                   8036:     foreach my $line (@dir_list) {
                   8037:         my ($file_name)=split(/\&/,$line,2);
                   8038:         if ($file_name eq $fname){
                   8039:             $file_name = $path.$file_name;
                   8040:             if ($group ne '') {
                   8041:                 $file_name = $group.$file_name;
                   8042:             }
                   8043:             $found_file = 1;
                   8044:             if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
                   8045:                 $locked_file = 1;
                   8046:             }
                   8047:         }
                   8048:     }
                   8049:     if (($current_disk_usage + $filesize) > $disk_quota){
                   8050:         my $msg = '<span class="LC_error">'.
                   8051:                 &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
                   8052:                   '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
                   8053:         return ('will_exceed_quota',$msg);
                   8054:     } elsif ($found_file) {
                   8055:         if ($locked_file) {
                   8056:             my $msg = '<span class="LC_error">';
                   8057:             $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>');
                   8058:             $msg .= '</span><br />';
                   8059:             $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
                   8060:             return ('file_locked',$msg);
                   8061:         } else {
                   8062:             my $msg = '<span class="LC_error">';
                   8063:             $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'});
                   8064:             $msg .= '</span>';
                   8065:             $msg .= '<br />';
                   8066:             $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
                   8067:             return ('file_exists',$msg);
                   8068:         }
                   8069:     }
                   8070: }
                   8071: 
1.31      albertel 8072: 
1.41      ng       8073: =pod
1.45      matthew  8074: 
1.464     albertel 8075: =back
1.41      ng       8076: 
1.112     bowersj2 8077: =head1 CSV Upload/Handling functions
1.38      albertel 8078: 
1.41      ng       8079: =over 4
                   8080: 
1.648     raeburn  8081: =item * &upfile_store($r)
1.41      ng       8082: 
                   8083: Store uploaded file, $r should be the HTTP Request object,
1.258     albertel 8084: needs $env{'form.upfile'}
1.41      ng       8085: returns $datatoken to be put into hidden field
                   8086: 
                   8087: =cut
1.31      albertel 8088: 
                   8089: sub upfile_store {
                   8090:     my $r=shift;
1.258     albertel 8091:     $env{'form.upfile'}=~s/\r/\n/gs;
                   8092:     $env{'form.upfile'}=~s/\f/\n/gs;
                   8093:     $env{'form.upfile'}=~s/\n+/\n/gs;
                   8094:     $env{'form.upfile'}=~s/\n+$//gs;
1.31      albertel 8095: 
1.258     albertel 8096:     my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
                   8097: 	'_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31      albertel 8098:     {
1.158     raeburn  8099:         my $datafile = $r->dir_config('lonDaemons').
                   8100:                            '/tmp/'.$datatoken.'.tmp';
                   8101:         if ( open(my $fh,">$datafile") ) {
1.258     albertel 8102:             print $fh $env{'form.upfile'};
1.158     raeburn  8103:             close($fh);
                   8104:         }
1.31      albertel 8105:     }
                   8106:     return $datatoken;
                   8107: }
                   8108: 
1.56      matthew  8109: =pod
                   8110: 
1.648     raeburn  8111: =item * &load_tmp_file($r)
1.41      ng       8112: 
                   8113: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258     albertel 8114: needs $env{'form.datatoken'},
                   8115: sets $env{'form.upfile'} to the contents of the file
1.41      ng       8116: 
                   8117: =cut
1.31      albertel 8118: 
                   8119: sub load_tmp_file {
                   8120:     my $r=shift;
                   8121:     my @studentdata=();
                   8122:     {
1.158     raeburn  8123:         my $studentfile = $r->dir_config('lonDaemons').
1.258     albertel 8124:                               '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158     raeburn  8125:         if ( open(my $fh,"<$studentfile") ) {
                   8126:             @studentdata=<$fh>;
                   8127:             close($fh);
                   8128:         }
1.31      albertel 8129:     }
1.258     albertel 8130:     $env{'form.upfile'}=join('',@studentdata);
1.31      albertel 8131: }
                   8132: 
1.56      matthew  8133: =pod
                   8134: 
1.648     raeburn  8135: =item * &upfile_record_sep()
1.41      ng       8136: 
                   8137: Separate uploaded file into records
                   8138: returns array of records,
1.258     albertel 8139: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41      ng       8140: 
                   8141: =cut
1.31      albertel 8142: 
                   8143: sub upfile_record_sep {
1.258     albertel 8144:     if ($env{'form.upfiletype'} eq 'xml') {
1.31      albertel 8145:     } else {
1.248     albertel 8146: 	my @records;
1.258     albertel 8147: 	foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248     albertel 8148: 	    if ($line=~/^\s*$/) { next; }
                   8149: 	    push(@records,$line);
                   8150: 	}
                   8151: 	return @records;
1.31      albertel 8152:     }
                   8153: }
                   8154: 
1.56      matthew  8155: =pod
                   8156: 
1.648     raeburn  8157: =item * &record_sep($record)
1.41      ng       8158: 
1.258     albertel 8159: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41      ng       8160: 
                   8161: =cut
                   8162: 
1.263     www      8163: sub takeleft {
                   8164:     my $index=shift;
                   8165:     return substr('0000'.$index,-4,4);
                   8166: }
                   8167: 
1.31      albertel 8168: sub record_sep {
                   8169:     my $record=shift;
                   8170:     my %components=();
1.258     albertel 8171:     if ($env{'form.upfiletype'} eq 'xml') {
                   8172:     } elsif ($env{'form.upfiletype'} eq 'space') {
1.31      albertel 8173:         my $i=0;
1.356     albertel 8174:         foreach my $field (split(/\s+/,$record)) {
1.31      albertel 8175:             $field=~s/^(\"|\')//;
                   8176:             $field=~s/(\"|\')$//;
1.263     www      8177:             $components{&takeleft($i)}=$field;
1.31      albertel 8178:             $i++;
                   8179:         }
1.258     albertel 8180:     } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31      albertel 8181:         my $i=0;
1.356     albertel 8182:         foreach my $field (split(/\t/,$record)) {
1.31      albertel 8183:             $field=~s/^(\"|\')//;
                   8184:             $field=~s/(\"|\')$//;
1.263     www      8185:             $components{&takeleft($i)}=$field;
1.31      albertel 8186:             $i++;
                   8187:         }
                   8188:     } else {
1.561     www      8189:         my $separator=',';
1.480     banghart 8190:         if ($env{'form.upfiletype'} eq 'semisv') {
1.561     www      8191:             $separator=';';
1.480     banghart 8192:         }
1.31      albertel 8193:         my $i=0;
1.561     www      8194: # the character we are looking for to indicate the end of a quote or a record 
                   8195:         my $looking_for=$separator;
                   8196: # do not add the characters to the fields
                   8197:         my $ignore=0;
                   8198: # we just encountered a separator (or the beginning of the record)
                   8199:         my $just_found_separator=1;
                   8200: # store the field we are working on here
                   8201:         my $field='';
                   8202: # work our way through all characters in record
                   8203:         foreach my $character ($record=~/(.)/g) {
                   8204:             if ($character eq $looking_for) {
                   8205:                if ($character ne $separator) {
                   8206: # Found the end of a quote, again looking for separator
                   8207:                   $looking_for=$separator;
                   8208:                   $ignore=1;
                   8209:                } else {
                   8210: # Found a separator, store away what we got
                   8211:                   $components{&takeleft($i)}=$field;
                   8212: 	          $i++;
                   8213:                   $just_found_separator=1;
                   8214:                   $ignore=0;
                   8215:                   $field='';
                   8216:                }
                   8217:                next;
                   8218:             }
                   8219: # single or double quotation marks after a separator indicate beginning of a quote
                   8220: # we are now looking for the end of the quote and need to ignore separators
                   8221:             if ((($character eq '"') || ($character eq "'")) && ($just_found_separator))  {
                   8222:                $looking_for=$character;
                   8223:                next;
                   8224:             }
                   8225: # ignore would be true after we reached the end of a quote
                   8226:             if ($ignore) { next; }
                   8227:             if (($just_found_separator) && ($character=~/\s/)) { next; }
                   8228:             $field.=$character;
                   8229:             $just_found_separator=0; 
1.31      albertel 8230:         }
1.561     www      8231: # catch the very last entry, since we never encountered the separator
                   8232:         $components{&takeleft($i)}=$field;
1.31      albertel 8233:     }
                   8234:     return %components;
                   8235: }
                   8236: 
1.144     matthew  8237: ######################################################
                   8238: ######################################################
                   8239: 
1.56      matthew  8240: =pod
                   8241: 
1.648     raeburn  8242: =item * &upfile_select_html()
1.41      ng       8243: 
1.144     matthew  8244: Return HTML code to select a file from the users machine and specify 
                   8245: the file type.
1.41      ng       8246: 
                   8247: =cut
                   8248: 
1.144     matthew  8249: ######################################################
                   8250: ######################################################
1.31      albertel 8251: sub upfile_select_html {
1.144     matthew  8252:     my %Types = (
                   8253:                  csv   => &mt('CSV (comma separated values, spreadsheet)'),
1.480     banghart 8254:                  semisv => &mt('Semicolon separated values'),
1.144     matthew  8255:                  space => &mt('Space separated'),
                   8256:                  tab   => &mt('Tabulator separated'),
                   8257: #                 xml   => &mt('HTML/XML'),
                   8258:                  );
                   8259:     my $Str = '<input type="file" name="upfile" size="50" />'.
1.727     riegler  8260:         '<br />'.&mt('Type').': <select name="upfiletype">';
1.144     matthew  8261:     foreach my $type (sort(keys(%Types))) {
                   8262:         $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
                   8263:     }
                   8264:     $Str .= "</select>\n";
                   8265:     return $Str;
1.31      albertel 8266: }
                   8267: 
1.301     albertel 8268: sub get_samples {
                   8269:     my ($records,$toget) = @_;
                   8270:     my @samples=({});
                   8271:     my $got=0;
                   8272:     foreach my $rec (@$records) {
                   8273: 	my %temp = &record_sep($rec);
                   8274: 	if (! grep(/\S/, values(%temp))) { next; }
                   8275: 	if (%temp) {
                   8276: 	    $samples[$got]=\%temp;
                   8277: 	    $got++;
                   8278: 	    if ($got == $toget) { last; }
                   8279: 	}
                   8280:     }
                   8281:     return \@samples;
                   8282: }
                   8283: 
1.144     matthew  8284: ######################################################
                   8285: ######################################################
                   8286: 
1.56      matthew  8287: =pod
                   8288: 
1.648     raeburn  8289: =item * &csv_print_samples($r,$records)
1.41      ng       8290: 
                   8291: Prints a table of sample values from each column uploaded $r is an
                   8292: Apache Request ref, $records is an arrayref from
                   8293: &Apache::loncommon::upfile_record_sep
                   8294: 
                   8295: =cut
                   8296: 
1.144     matthew  8297: ######################################################
                   8298: ######################################################
1.31      albertel 8299: sub csv_print_samples {
                   8300:     my ($r,$records) = @_;
1.662     bisitz   8301:     my $samples = &get_samples($records,5);
1.301     albertel 8302: 
1.594     raeburn  8303:     $r->print(&mt('Samples').'<br />'.&start_data_table().
                   8304:               &start_data_table_header_row());
1.356     albertel 8305:     foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) { 
                   8306:         $r->print('<th>'.&mt('Column&nbsp;[_1]',($sample+1)).'</th>'); }
1.594     raeburn  8307:     $r->print(&end_data_table_header_row());
1.301     albertel 8308:     foreach my $hash (@$samples) {
1.594     raeburn  8309: 	$r->print(&start_data_table_row());
1.356     albertel 8310: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31      albertel 8311: 	    $r->print('<td>');
1.356     albertel 8312: 	    if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31      albertel 8313: 	    $r->print('</td>');
                   8314: 	}
1.594     raeburn  8315: 	$r->print(&end_data_table_row());
1.31      albertel 8316:     }
1.594     raeburn  8317:     $r->print(&end_data_table().'<br />'."\n");
1.31      albertel 8318: }
                   8319: 
1.144     matthew  8320: ######################################################
                   8321: ######################################################
                   8322: 
1.56      matthew  8323: =pod
                   8324: 
1.648     raeburn  8325: =item * &csv_print_select_table($r,$records,$d)
1.41      ng       8326: 
                   8327: Prints a table to create associations between values and table columns.
1.144     matthew  8328: 
1.41      ng       8329: $r is an Apache Request ref,
                   8330: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174     matthew  8331: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41      ng       8332: 
                   8333: =cut
                   8334: 
1.144     matthew  8335: ######################################################
                   8336: ######################################################
1.31      albertel 8337: sub csv_print_select_table {
                   8338:     my ($r,$records,$d) = @_;
1.301     albertel 8339:     my $i=0;
                   8340:     my $samples = &get_samples($records,1);
1.144     matthew  8341:     $r->print(&mt('Associate columns with student attributes.')."\n".
1.594     raeburn  8342: 	      &start_data_table().&start_data_table_header_row().
1.144     matthew  8343:               '<th>'.&mt('Attribute').'</th>'.
1.594     raeburn  8344:               '<th>'.&mt('Column').'</th>'.
                   8345:               &end_data_table_header_row()."\n");
1.356     albertel 8346:     foreach my $array_ref (@$d) {
                   8347: 	my ($value,$display,$defaultcol)=@{ $array_ref };
1.729     raeburn  8348: 	$r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31      albertel 8349: 
                   8350: 	$r->print('<td><select name=f'.$i.
1.32      matthew  8351: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.31      albertel 8352: 	$r->print('<option value="none"></option>');
1.356     albertel 8353: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
                   8354: 	    $r->print('<option value="'.$sample.'"'.
                   8355:                       ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662     bisitz   8356:                       '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31      albertel 8357: 	}
1.594     raeburn  8358: 	$r->print('</select></td>'.&end_data_table_row()."\n");
1.31      albertel 8359: 	$i++;
                   8360:     }
1.594     raeburn  8361:     $r->print(&end_data_table());
1.31      albertel 8362:     $i--;
                   8363:     return $i;
                   8364: }
1.56      matthew  8365: 
1.144     matthew  8366: ######################################################
                   8367: ######################################################
                   8368: 
1.56      matthew  8369: =pod
1.31      albertel 8370: 
1.648     raeburn  8371: =item * &csv_samples_select_table($r,$records,$d)
1.41      ng       8372: 
                   8373: Prints a table of sample values from the upload and can make associate samples to internal names.
                   8374: 
                   8375: $r is an Apache Request ref,
                   8376: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
                   8377: $d is an array of 2 element arrays (internal name, displayed name)
                   8378: 
                   8379: =cut
                   8380: 
1.144     matthew  8381: ######################################################
                   8382: ######################################################
1.31      albertel 8383: sub csv_samples_select_table {
                   8384:     my ($r,$records,$d) = @_;
                   8385:     my $i=0;
1.144     matthew  8386:     #
1.662     bisitz   8387:     my $max_samples = 5;
                   8388:     my $samples = &get_samples($records,$max_samples);
1.594     raeburn  8389:     $r->print(&start_data_table().
                   8390:               &start_data_table_header_row().'<th>'.
                   8391:               &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
                   8392:               &end_data_table_header_row());
1.301     albertel 8393: 
                   8394:     foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594     raeburn  8395: 	$r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32      matthew  8396: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.301     albertel 8397: 	foreach my $option (@$d) {
                   8398: 	    my ($value,$display,$defaultcol)=@{ $option };
1.174     matthew  8399: 	    $r->print('<option value="'.$value.'"'.
1.253     albertel 8400:                       ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174     matthew  8401:                       $display.'</option>');
1.31      albertel 8402: 	}
                   8403: 	$r->print('</select></td><td>');
1.662     bisitz   8404: 	foreach my $line (0..($max_samples-1)) {
1.301     albertel 8405: 	    if (defined($samples->[$line]{$key})) { 
                   8406: 		$r->print($samples->[$line]{$key}."<br />\n"); 
                   8407: 	    }
                   8408: 	}
1.594     raeburn  8409: 	$r->print('</td>'.&end_data_table_row());
1.31      albertel 8410: 	$i++;
                   8411:     }
1.594     raeburn  8412:     $r->print(&end_data_table());
1.31      albertel 8413:     $i--;
                   8414:     return($i);
1.115     matthew  8415: }
                   8416: 
1.144     matthew  8417: ######################################################
                   8418: ######################################################
                   8419: 
1.115     matthew  8420: =pod
                   8421: 
1.648     raeburn  8422: =item * &clean_excel_name($name)
1.115     matthew  8423: 
                   8424: Returns a replacement for $name which does not contain any illegal characters.
                   8425: 
                   8426: =cut
                   8427: 
1.144     matthew  8428: ######################################################
                   8429: ######################################################
1.115     matthew  8430: sub clean_excel_name {
                   8431:     my ($name) = @_;
                   8432:     $name =~ s/[:\*\?\/\\]//g;
                   8433:     if (length($name) > 31) {
                   8434:         $name = substr($name,0,31);
                   8435:     }
                   8436:     return $name;
1.25      albertel 8437: }
1.84      albertel 8438: 
1.85      albertel 8439: =pod
                   8440: 
1.648     raeburn  8441: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85      albertel 8442: 
                   8443: Returns either 1 or undef
                   8444: 
                   8445: 1 if the part is to be hidden, undef if it is to be shown
                   8446: 
                   8447: Arguments are:
                   8448: 
                   8449: $id the id of the part to be checked
                   8450: $symb, optional the symb of the resource to check
                   8451: $udom, optional the domain of the user to check for
                   8452: $uname, optional the username of the user to check for
                   8453: 
                   8454: =cut
1.84      albertel 8455: 
                   8456: sub check_if_partid_hidden {
                   8457:     my ($id,$symb,$udom,$uname) = @_;
1.133     albertel 8458:     my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84      albertel 8459: 					 $symb,$udom,$uname);
1.141     albertel 8460:     my $truth=1;
                   8461:     #if the string starts with !, then the list is the list to show not hide
                   8462:     if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84      albertel 8463:     my @hiddenlist=split(/,/,$hiddenparts);
                   8464:     foreach my $checkid (@hiddenlist) {
1.141     albertel 8465: 	if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84      albertel 8466:     }
1.141     albertel 8467:     return !$truth;
1.84      albertel 8468: }
1.127     matthew  8469: 
1.138     matthew  8470: 
                   8471: ############################################################
                   8472: ############################################################
                   8473: 
                   8474: =pod
                   8475: 
1.157     matthew  8476: =back 
                   8477: 
1.138     matthew  8478: =head1 cgi-bin script and graphing routines
                   8479: 
1.157     matthew  8480: =over 4
                   8481: 
1.648     raeburn  8482: =item * &get_cgi_id()
1.138     matthew  8483: 
                   8484: Inputs: none
                   8485: 
                   8486: Returns an id which can be used to pass environment variables
                   8487: to various cgi-bin scripts.  These environment variables will
                   8488: be removed from the users environment after a given time by
                   8489: the routine &Apache::lonnet::transfer_profile_to_env.
                   8490: 
                   8491: =cut
                   8492: 
                   8493: ############################################################
                   8494: ############################################################
1.152     albertel 8495: my $uniq=0;
1.136     matthew  8496: sub get_cgi_id {
1.154     albertel 8497:     $uniq=($uniq+1)%100000;
1.280     albertel 8498:     return (time.'_'.$$.'_'.$uniq);
1.136     matthew  8499: }
                   8500: 
1.127     matthew  8501: ############################################################
                   8502: ############################################################
                   8503: 
                   8504: =pod
                   8505: 
1.648     raeburn  8506: =item * &DrawBarGraph()
1.127     matthew  8507: 
1.138     matthew  8508: Facilitates the plotting of data in a (stacked) bar graph.
                   8509: Puts plot definition data into the users environment in order for 
                   8510: graph.png to plot it.  Returns an <img> tag for the plot.
                   8511: The bars on the plot are labeled '1','2',...,'n'.
                   8512: 
                   8513: Inputs:
                   8514: 
                   8515: =over 4
                   8516: 
                   8517: =item $Title: string, the title of the plot
                   8518: 
                   8519: =item $xlabel: string, text describing the X-axis of the plot
                   8520: 
                   8521: =item $ylabel: string, text describing the Y-axis of the plot
                   8522: 
                   8523: =item $Max: scalar, the maximum Y value to use in the plot
                   8524: If $Max is < any data point, the graph will not be rendered.
                   8525: 
1.140     matthew  8526: =item $colors: array ref holding the colors to be used for the data sets when
1.138     matthew  8527: they are plotted.  If undefined, default values will be used.
                   8528: 
1.178     matthew  8529: =item $labels: array ref holding the labels to use on the x-axis for the bars.
                   8530: 
1.138     matthew  8531: =item @Values: An array of array references.  Each array reference holds data
                   8532: to be plotted in a stacked bar chart.
                   8533: 
1.239     matthew  8534: =item If the final element of @Values is a hash reference the key/value
                   8535: pairs will be added to the graph definition.
                   8536: 
1.138     matthew  8537: =back
                   8538: 
                   8539: Returns:
                   8540: 
                   8541: An <img> tag which references graph.png and the appropriate identifying
                   8542: information for the plot.
                   8543: 
1.127     matthew  8544: =cut
                   8545: 
                   8546: ############################################################
                   8547: ############################################################
1.134     matthew  8548: sub DrawBarGraph {
1.178     matthew  8549:     my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134     matthew  8550:     #
                   8551:     if (! defined($colors)) {
                   8552:         $colors = ['#33ff00', 
                   8553:                   '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
                   8554:                   '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
                   8555:                   ]; 
                   8556:     }
1.228     matthew  8557:     my $extra_settings = {};
                   8558:     if (ref($Values[-1]) eq 'HASH') {
                   8559:         $extra_settings = pop(@Values);
                   8560:     }
1.127     matthew  8561:     #
1.136     matthew  8562:     my $identifier = &get_cgi_id();
                   8563:     my $id = 'cgi.'.$identifier;        
1.129     matthew  8564:     if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127     matthew  8565:         return '';
                   8566:     }
1.225     matthew  8567:     #
                   8568:     my @Labels;
                   8569:     if (defined($labels)) {
                   8570:         @Labels = @$labels;
                   8571:     } else {
                   8572:         for (my $i=0;$i<@{$Values[0]};$i++) {
                   8573:             push (@Labels,$i+1);
                   8574:         }
                   8575:     }
                   8576:     #
1.129     matthew  8577:     my $NumBars = scalar(@{$Values[0]});
1.225     matthew  8578:     if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129     matthew  8579:     my %ValuesHash;
                   8580:     my $NumSets=1;
                   8581:     foreach my $array (@Values) {
                   8582:         next if (! ref($array));
1.136     matthew  8583:         $ValuesHash{$id.'.data.'.$NumSets++} = 
1.132     matthew  8584:             join(',',@$array);
1.129     matthew  8585:     }
1.127     matthew  8586:     #
1.136     matthew  8587:     my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225     matthew  8588:     if ($NumBars < 3) {
                   8589:         $width = 120+$NumBars*32;
1.220     matthew  8590:         $xskip = 1;
1.225     matthew  8591:         $bar_width = 30;
                   8592:     } elsif ($NumBars < 5) {
                   8593:         $width = 120+$NumBars*20;
                   8594:         $xskip = 1;
                   8595:         $bar_width = 20;
1.220     matthew  8596:     } elsif ($NumBars < 10) {
1.136     matthew  8597:         $width = 120+$NumBars*15;
                   8598:         $xskip = 1;
                   8599:         $bar_width = 15;
                   8600:     } elsif ($NumBars <= 25) {
                   8601:         $width = 120+$NumBars*11;
                   8602:         $xskip = 5;
                   8603:         $bar_width = 8;
                   8604:     } elsif ($NumBars <= 50) {
                   8605:         $width = 120+$NumBars*8;
                   8606:         $xskip = 5;
                   8607:         $bar_width = 4;
                   8608:     } else {
                   8609:         $width = 120+$NumBars*8;
                   8610:         $xskip = 5;
                   8611:         $bar_width = 4;
                   8612:     }
                   8613:     #
1.137     matthew  8614:     $Max = 1 if ($Max < 1);
                   8615:     if ( int($Max) < $Max ) {
                   8616:         $Max++;
                   8617:         $Max = int($Max);
                   8618:     }
1.127     matthew  8619:     $Title  = '' if (! defined($Title));
                   8620:     $xlabel = '' if (! defined($xlabel));
                   8621:     $ylabel = '' if (! defined($ylabel));
1.369     www      8622:     $ValuesHash{$id.'.title'}    = &escape($Title);
                   8623:     $ValuesHash{$id.'.xlabel'}   = &escape($xlabel);
                   8624:     $ValuesHash{$id.'.ylabel'}   = &escape($ylabel);
1.137     matthew  8625:     $ValuesHash{$id.'.y_max_value'} = $Max;
1.136     matthew  8626:     $ValuesHash{$id.'.NumBars'}  = $NumBars;
                   8627:     $ValuesHash{$id.'.NumSets'}  = $NumSets;
                   8628:     $ValuesHash{$id.'.PlotType'} = 'bar';
                   8629:     $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   8630:     $ValuesHash{$id.'.height'}   = $height;
                   8631:     $ValuesHash{$id.'.width'}    = $width;
                   8632:     $ValuesHash{$id.'.xskip'}    = $xskip;
                   8633:     $ValuesHash{$id.'.bar_width'} = $bar_width;
                   8634:     $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127     matthew  8635:     #
1.228     matthew  8636:     # Deal with other parameters
                   8637:     while (my ($key,$value) = each(%$extra_settings)) {
                   8638:         $ValuesHash{$id.'.'.$key} = $value;
                   8639:     }
                   8640:     #
1.646     raeburn  8641:     &Apache::lonnet::appenv(\%ValuesHash);
1.137     matthew  8642:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   8643: }
                   8644: 
                   8645: ############################################################
                   8646: ############################################################
                   8647: 
                   8648: =pod
                   8649: 
1.648     raeburn  8650: =item * &DrawXYGraph()
1.137     matthew  8651: 
1.138     matthew  8652: Facilitates the plotting of data in an XY graph.
                   8653: Puts plot definition data into the users environment in order for 
                   8654: graph.png to plot it.  Returns an <img> tag for the plot.
                   8655: 
                   8656: Inputs:
                   8657: 
                   8658: =over 4
                   8659: 
                   8660: =item $Title: string, the title of the plot
                   8661: 
                   8662: =item $xlabel: string, text describing the X-axis of the plot
                   8663: 
                   8664: =item $ylabel: string, text describing the Y-axis of the plot
                   8665: 
                   8666: =item $Max: scalar, the maximum Y value to use in the plot
                   8667: If $Max is < any data point, the graph will not be rendered.
                   8668: 
                   8669: =item $colors: Array ref containing the hex color codes for the data to be 
                   8670: plotted in.  If undefined, default values will be used.
                   8671: 
                   8672: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   8673: 
                   8674: =item $Ydata: Array ref containing Array refs.  
1.185     www      8675: Each of the contained arrays will be plotted as a separate curve.
1.138     matthew  8676: 
                   8677: =item %Values: hash indicating or overriding any default values which are 
                   8678: passed to graph.png.  
                   8679: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   8680: 
                   8681: =back
                   8682: 
                   8683: Returns:
                   8684: 
                   8685: An <img> tag which references graph.png and the appropriate identifying
                   8686: information for the plot.
                   8687: 
1.137     matthew  8688: =cut
                   8689: 
                   8690: ############################################################
                   8691: ############################################################
                   8692: sub DrawXYGraph {
                   8693:     my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
                   8694:     #
                   8695:     # Create the identifier for the graph
                   8696:     my $identifier = &get_cgi_id();
                   8697:     my $id = 'cgi.'.$identifier;
                   8698:     #
                   8699:     $Title  = '' if (! defined($Title));
                   8700:     $xlabel = '' if (! defined($xlabel));
                   8701:     $ylabel = '' if (! defined($ylabel));
                   8702:     my %ValuesHash = 
                   8703:         (
1.369     www      8704:          $id.'.title'  => &escape($Title),
                   8705:          $id.'.xlabel' => &escape($xlabel),
                   8706:          $id.'.ylabel' => &escape($ylabel),
1.137     matthew  8707:          $id.'.y_max_value'=> $Max,
                   8708:          $id.'.labels'     => join(',',@$Xlabels),
                   8709:          $id.'.PlotType'   => 'XY',
                   8710:          );
                   8711:     #
                   8712:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   8713:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   8714:     }
                   8715:     #
                   8716:     if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
                   8717:         return '';
                   8718:     }
                   8719:     my $NumSets=1;
1.138     matthew  8720:     foreach my $array (@{$Ydata}){
1.137     matthew  8721:         next if (! ref($array));
                   8722:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
                   8723:     }
1.138     matthew  8724:     $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137     matthew  8725:     #
                   8726:     # Deal with other parameters
                   8727:     while (my ($key,$value) = each(%Values)) {
                   8728:         $ValuesHash{$id.'.'.$key} = $value;
1.127     matthew  8729:     }
                   8730:     #
1.646     raeburn  8731:     &Apache::lonnet::appenv(\%ValuesHash);
1.136     matthew  8732:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   8733: }
                   8734: 
                   8735: ############################################################
                   8736: ############################################################
                   8737: 
                   8738: =pod
                   8739: 
1.648     raeburn  8740: =item * &DrawXYYGraph()
1.138     matthew  8741: 
                   8742: Facilitates the plotting of data in an XY graph with two Y axes.
                   8743: Puts plot definition data into the users environment in order for 
                   8744: graph.png to plot it.  Returns an <img> tag for the plot.
                   8745: 
                   8746: Inputs:
                   8747: 
                   8748: =over 4
                   8749: 
                   8750: =item $Title: string, the title of the plot
                   8751: 
                   8752: =item $xlabel: string, text describing the X-axis of the plot
                   8753: 
                   8754: =item $ylabel: string, text describing the Y-axis of the plot
                   8755: 
                   8756: =item $colors: Array ref containing the hex color codes for the data to be 
                   8757: plotted in.  If undefined, default values will be used.
                   8758: 
                   8759: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   8760: 
                   8761: =item $Ydata1: The first data set
                   8762: 
                   8763: =item $Min1: The minimum value of the left Y-axis
                   8764: 
                   8765: =item $Max1: The maximum value of the left Y-axis
                   8766: 
                   8767: =item $Ydata2: The second data set
                   8768: 
                   8769: =item $Min2: The minimum value of the right Y-axis
                   8770: 
                   8771: =item $Max2: The maximum value of the left Y-axis
                   8772: 
                   8773: =item %Values: hash indicating or overriding any default values which are 
                   8774: passed to graph.png.  
                   8775: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   8776: 
                   8777: =back
                   8778: 
                   8779: Returns:
                   8780: 
                   8781: An <img> tag which references graph.png and the appropriate identifying
                   8782: information for the plot.
1.136     matthew  8783: 
                   8784: =cut
                   8785: 
                   8786: ############################################################
                   8787: ############################################################
1.137     matthew  8788: sub DrawXYYGraph {
                   8789:     my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
                   8790:                                         $Ydata2,$Min2,$Max2,%Values)=@_;
1.136     matthew  8791:     #
                   8792:     # Create the identifier for the graph
                   8793:     my $identifier = &get_cgi_id();
                   8794:     my $id = 'cgi.'.$identifier;
                   8795:     #
                   8796:     $Title  = '' if (! defined($Title));
                   8797:     $xlabel = '' if (! defined($xlabel));
                   8798:     $ylabel = '' if (! defined($ylabel));
                   8799:     my %ValuesHash = 
                   8800:         (
1.369     www      8801:          $id.'.title'  => &escape($Title),
                   8802:          $id.'.xlabel' => &escape($xlabel),
                   8803:          $id.'.ylabel' => &escape($ylabel),
1.136     matthew  8804:          $id.'.labels' => join(',',@$Xlabels),
                   8805:          $id.'.PlotType' => 'XY',
                   8806:          $id.'.NumSets' => 2,
1.137     matthew  8807:          $id.'.two_axes' => 1,
                   8808:          $id.'.y1_max_value' => $Max1,
                   8809:          $id.'.y1_min_value' => $Min1,
                   8810:          $id.'.y2_max_value' => $Max2,
                   8811:          $id.'.y2_min_value' => $Min2,
1.136     matthew  8812:          );
                   8813:     #
1.137     matthew  8814:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   8815:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   8816:     }
                   8817:     #
                   8818:     if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
                   8819:         ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136     matthew  8820:         return '';
                   8821:     }
                   8822:     my $NumSets=1;
1.137     matthew  8823:     foreach my $array ($Ydata1,$Ydata2){
1.136     matthew  8824:         next if (! ref($array));
                   8825:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137     matthew  8826:     }
                   8827:     #
                   8828:     # Deal with other parameters
                   8829:     while (my ($key,$value) = each(%Values)) {
                   8830:         $ValuesHash{$id.'.'.$key} = $value;
1.136     matthew  8831:     }
                   8832:     #
1.646     raeburn  8833:     &Apache::lonnet::appenv(\%ValuesHash);
1.130     albertel 8834:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139     matthew  8835: }
                   8836: 
                   8837: ############################################################
                   8838: ############################################################
                   8839: 
                   8840: =pod
                   8841: 
1.157     matthew  8842: =back 
                   8843: 
1.139     matthew  8844: =head1 Statistics helper routines?  
                   8845: 
                   8846: Bad place for them but what the hell.
                   8847: 
1.157     matthew  8848: =over 4
                   8849: 
1.648     raeburn  8850: =item * &chartlink()
1.139     matthew  8851: 
                   8852: Returns a link to the chart for a specific student.  
                   8853: 
                   8854: Inputs:
                   8855: 
                   8856: =over 4
                   8857: 
                   8858: =item $linktext: The text of the link
                   8859: 
                   8860: =item $sname: The students username
                   8861: 
                   8862: =item $sdomain: The students domain
                   8863: 
                   8864: =back
                   8865: 
1.157     matthew  8866: =back
                   8867: 
1.139     matthew  8868: =cut
                   8869: 
                   8870: ############################################################
                   8871: ############################################################
                   8872: sub chartlink {
                   8873:     my ($linktext, $sname, $sdomain) = @_;
                   8874:     my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369     www      8875:         '&amp;SelectedStudent='.&escape($sname.':'.$sdomain).
1.219     albertel 8876:         '&amp;chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139     matthew  8877:        '">'.$linktext.'</a>';
1.153     matthew  8878: }
                   8879: 
                   8880: #######################################################
                   8881: #######################################################
                   8882: 
                   8883: =pod
                   8884: 
                   8885: =head1 Course Environment Routines
1.157     matthew  8886: 
                   8887: =over 4
1.153     matthew  8888: 
1.648     raeburn  8889: =item * &restore_course_settings()
1.153     matthew  8890: 
1.648     raeburn  8891: =item * &store_course_settings()
1.153     matthew  8892: 
                   8893: Restores/Store indicated form parameters from the course environment.
                   8894: Will not overwrite existing values of the form parameters.
                   8895: 
                   8896: Inputs: 
                   8897: a scalar describing the data (e.g. 'chart', 'problem_analysis')
                   8898: 
                   8899: a hash ref describing the data to be stored.  For example:
                   8900:    
                   8901: %Save_Parameters = ('Status' => 'scalar',
                   8902:     'chartoutputmode' => 'scalar',
                   8903:     'chartoutputdata' => 'scalar',
                   8904:     'Section' => 'array',
1.373     raeburn  8905:     'Group' => 'array',
1.153     matthew  8906:     'StudentData' => 'array',
                   8907:     'Maps' => 'array');
                   8908: 
                   8909: Returns: both routines return nothing
                   8910: 
1.631     raeburn  8911: =back
                   8912: 
1.153     matthew  8913: =cut
                   8914: 
                   8915: #######################################################
                   8916: #######################################################
                   8917: sub store_course_settings {
1.496     albertel 8918:     return &store_settings($env{'request.course.id'},@_);
                   8919: }
                   8920: 
                   8921: sub store_settings {
1.153     matthew  8922:     # save to the environment
                   8923:     # appenv the same items, just to be safe
1.300     albertel 8924:     my $udom  = $env{'user.domain'};
                   8925:     my $uname = $env{'user.name'};
1.496     albertel 8926:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  8927:     my %SaveHash;
                   8928:     my %AppHash;
                   8929:     while (my ($setting,$type) = each(%$Settings)) {
1.496     albertel 8930:         my $basename = join('.','internal',$context,$prefix,$setting);
1.300     albertel 8931:         my $envname = 'environment.'.$basename;
1.258     albertel 8932:         if (exists($env{'form.'.$setting})) {
1.153     matthew  8933:             # Save this value away
                   8934:             if ($type eq 'scalar' &&
1.258     albertel 8935:                 (! exists($env{$envname}) || 
                   8936:                  $env{$envname} ne $env{'form.'.$setting})) {
                   8937:                 $SaveHash{$basename} = $env{'form.'.$setting};
                   8938:                 $AppHash{$envname}   = $env{'form.'.$setting};
1.153     matthew  8939:             } elsif ($type eq 'array') {
                   8940:                 my $stored_form;
1.258     albertel 8941:                 if (ref($env{'form.'.$setting})) {
1.153     matthew  8942:                     $stored_form = join(',',
                   8943:                                         map {
1.369     www      8944:                                             &escape($_);
1.258     albertel 8945:                                         } sort(@{$env{'form.'.$setting}}));
1.153     matthew  8946:                 } else {
                   8947:                     $stored_form = 
1.369     www      8948:                         &escape($env{'form.'.$setting});
1.153     matthew  8949:                 }
                   8950:                 # Determine if the array contents are the same.
1.258     albertel 8951:                 if ($stored_form ne $env{$envname}) {
1.153     matthew  8952:                     $SaveHash{$basename} = $stored_form;
                   8953:                     $AppHash{$envname}   = $stored_form;
                   8954:                 }
                   8955:             }
                   8956:         }
                   8957:     }
                   8958:     my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300     albertel 8959:                                           $udom,$uname);
1.153     matthew  8960:     if ($put_result !~ /^(ok|delayed)/) {
                   8961:         &Apache::lonnet::logthis('unable to save form parameters, '.
                   8962:                                  'got error:'.$put_result);
                   8963:     }
                   8964:     # Make sure these settings stick around in this session, too
1.646     raeburn  8965:     &Apache::lonnet::appenv(\%AppHash);
1.153     matthew  8966:     return;
                   8967: }
                   8968: 
                   8969: sub restore_course_settings {
1.499     albertel 8970:     return &restore_settings($env{'request.course.id'},@_);
1.496     albertel 8971: }
                   8972: 
                   8973: sub restore_settings {
                   8974:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  8975:     while (my ($setting,$type) = each(%$Settings)) {
1.258     albertel 8976:         next if (exists($env{'form.'.$setting}));
1.496     albertel 8977:         my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153     matthew  8978:             '.'.$setting;
1.258     albertel 8979:         if (exists($env{$envname})) {
1.153     matthew  8980:             if ($type eq 'scalar') {
1.258     albertel 8981:                 $env{'form.'.$setting} = $env{$envname};
1.153     matthew  8982:             } elsif ($type eq 'array') {
1.258     albertel 8983:                 $env{'form.'.$setting} = [ 
1.153     matthew  8984:                                            map { 
1.369     www      8985:                                                &unescape($_); 
1.258     albertel 8986:                                            } split(',',$env{$envname})
1.153     matthew  8987:                                            ];
                   8988:             }
                   8989:         }
                   8990:     }
1.127     matthew  8991: }
                   8992: 
1.618     raeburn  8993: #######################################################
                   8994: #######################################################
                   8995: 
                   8996: =pod
                   8997: 
                   8998: =head1 Domain E-mail Routines  
                   8999: 
                   9000: =over 4
                   9001: 
1.648     raeburn  9002: =item * &build_recipient_list()
1.618     raeburn  9003: 
1.766     raeburn  9004: Build recipient lists for four types of e-mail:
                   9005: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
                   9006: (d) Help requests, generated by
                   9007: lonerrorhandler.pm, CHECKRPMS, loncron, and lonsupportreq.pm respectively.
1.618     raeburn  9008: 
                   9009: Inputs:
1.619     raeburn  9010: defmail (scalar - email address of default recipient), 
1.618     raeburn  9011: mailing type (scalar - errormail, packagesmail, or helpdeskmail), 
1.619     raeburn  9012: defdom (domain for which to retrieve configuration settings),
                   9013: origmail (scalar - email address of recipient from loncapa.conf, 
                   9014: i.e., predates configuration by DC via domainprefs.pm 
1.618     raeburn  9015: 
1.655     raeburn  9016: Returns: comma separated list of addresses to which to send e-mail.
                   9017: 
                   9018: =back
1.618     raeburn  9019: 
                   9020: =cut
                   9021: 
                   9022: ############################################################
                   9023: ############################################################
                   9024: sub build_recipient_list {
1.619     raeburn  9025:     my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618     raeburn  9026:     my @recipients;
                   9027:     my $otheremails;
                   9028:     my %domconfig =
                   9029:          &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
                   9030:     if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766     raeburn  9031:         if (exists($domconfig{'contacts'}{$mailing})) {
                   9032:             if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
                   9033:                 my @contacts = ('adminemail','supportemail');
                   9034:                 foreach my $item (@contacts) {
                   9035:                     if ($domconfig{'contacts'}{$mailing}{$item}) {
                   9036:                         my $addr = $domconfig{'contacts'}{$item}; 
                   9037:                         if (!grep(/^\Q$addr\E$/,@recipients)) {
                   9038:                             push(@recipients,$addr);
                   9039:                         }
1.619     raeburn  9040:                     }
1.766     raeburn  9041:                     $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618     raeburn  9042:                 }
                   9043:             }
1.766     raeburn  9044:         } elsif ($origmail ne '') {
                   9045:             push(@recipients,$origmail);
1.618     raeburn  9046:         }
1.619     raeburn  9047:     } elsif ($origmail ne '') {
                   9048:         push(@recipients,$origmail);
1.618     raeburn  9049:     }
1.688     raeburn  9050:     if (defined($defmail)) {
                   9051:         if ($defmail ne '') {
                   9052:             push(@recipients,$defmail);
                   9053:         }
1.618     raeburn  9054:     }
                   9055:     if ($otheremails) {
1.619     raeburn  9056:         my @others;
                   9057:         if ($otheremails =~ /,/) {
                   9058:             @others = split(/,/,$otheremails);
1.618     raeburn  9059:         } else {
1.619     raeburn  9060:             push(@others,$otheremails);
                   9061:         }
                   9062:         foreach my $addr (@others) {
                   9063:             if (!grep(/^\Q$addr\E$/,@recipients)) {
                   9064:                 push(@recipients,$addr);
                   9065:             }
1.618     raeburn  9066:         }
                   9067:     }
1.619     raeburn  9068:     my $recipientlist = join(',',@recipients); 
1.618     raeburn  9069:     return $recipientlist;
                   9070: }
                   9071: 
1.127     matthew  9072: ############################################################
                   9073: ############################################################
1.154     albertel 9074: 
1.655     raeburn  9075: =pod
                   9076: 
                   9077: =head1 Course Catalog Routines
                   9078: 
                   9079: =over 4
                   9080: 
                   9081: =item * &gather_categories()
                   9082: 
                   9083: Converts category definitions - keys of categories hash stored in  
                   9084: coursecategories in configuration.db on the primary library server in a 
                   9085: domain - to an array.  Also generates javascript and idx hash used to 
                   9086: generate Domain Coordinator interface for editing Course Categories.
                   9087: 
                   9088: Inputs:
1.663     raeburn  9089: 
1.655     raeburn  9090: categories (reference to hash of category definitions).
1.663     raeburn  9091: 
1.655     raeburn  9092: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   9093:       categories and subcategories).
1.663     raeburn  9094: 
1.655     raeburn  9095: idx (reference to hash of counters used in Domain Coordinator interface for 
                   9096:       editing Course Categories).
1.663     raeburn  9097: 
1.655     raeburn  9098: jsarray (reference to array of categories used to create Javascript arrays for
                   9099:          Domain Coordinator interface for editing Course Categories).
                   9100: 
                   9101: Returns: nothing
                   9102: 
                   9103: Side effects: populates cats, idx and jsarray. 
                   9104: 
                   9105: =cut
                   9106: 
                   9107: sub gather_categories {
                   9108:     my ($categories,$cats,$idx,$jsarray) = @_;
                   9109:     my %counters;
                   9110:     my $num = 0;
                   9111:     foreach my $item (keys(%{$categories})) {
                   9112:         my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
                   9113:         if ($container eq '' && $depth == 0) {
                   9114:             $cats->[$depth][$categories->{$item}] = $cat;
                   9115:         } else {
                   9116:             $cats->[$depth]{$container}[$categories->{$item}] = $cat;
                   9117:         }
                   9118:         my ($escitem,$tail) = split(/:/,$item,2);
                   9119:         if ($counters{$tail} eq '') {
                   9120:             $counters{$tail} = $num;
                   9121:             $num ++;
                   9122:         }
                   9123:         if (ref($idx) eq 'HASH') {
                   9124:             $idx->{$item} = $counters{$tail};
                   9125:         }
                   9126:         if (ref($jsarray) eq 'ARRAY') {
                   9127:             push(@{$jsarray->[$counters{$tail}]},$item);
                   9128:         }
                   9129:     }
                   9130:     return;
                   9131: }
                   9132: 
                   9133: =pod
                   9134: 
                   9135: =item * &extract_categories()
                   9136: 
                   9137: Used to generate breadcrumb trails for course categories.
                   9138: 
                   9139: Inputs:
1.663     raeburn  9140: 
1.655     raeburn  9141: categories (reference to hash of category definitions).
1.663     raeburn  9142: 
1.655     raeburn  9143: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   9144:       categories and subcategories).
1.663     raeburn  9145: 
1.655     raeburn  9146: trails (reference to array of breacrumb trails for each category).
1.663     raeburn  9147: 
1.655     raeburn  9148: allitems (reference to hash - key is category key 
                   9149:          (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663     raeburn  9150: 
1.655     raeburn  9151: idx (reference to hash of counters used in Domain Coordinator interface for
                   9152:       editing Course Categories).
1.663     raeburn  9153: 
1.655     raeburn  9154: jsarray (reference to array of categories used to create Javascript arrays for
                   9155:          Domain Coordinator interface for editing Course Categories).
                   9156: 
1.665     raeburn  9157: subcats (reference to hash of arrays containing all subcategories within each 
                   9158:          category, -recursive)
                   9159: 
1.655     raeburn  9160: Returns: nothing
                   9161: 
                   9162: Side effects: populates trails and allitems hash references.
                   9163: 
                   9164: =cut
                   9165: 
                   9166: sub extract_categories {
1.665     raeburn  9167:     my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655     raeburn  9168:     if (ref($categories) eq 'HASH') {
                   9169:         &gather_categories($categories,$cats,$idx,$jsarray);
                   9170:         if (ref($cats->[0]) eq 'ARRAY') {
                   9171:             for (my $i=0; $i<@{$cats->[0]}; $i++) {
                   9172:                 my $name = $cats->[0][$i];
                   9173:                 my $item = &escape($name).'::0';
                   9174:                 my $trailstr;
                   9175:                 if ($name eq 'instcode') {
                   9176:                     $trailstr = &mt('Official courses (with institutional codes)');
                   9177:                 } else {
                   9178:                     $trailstr = $name;
                   9179:                 }
                   9180:                 if ($allitems->{$item} eq '') {
                   9181:                     push(@{$trails},$trailstr);
                   9182:                     $allitems->{$item} = scalar(@{$trails})-1;
                   9183:                 }
                   9184:                 my @parents = ($name);
                   9185:                 if (ref($cats->[1]{$name}) eq 'ARRAY') {
                   9186:                     for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
                   9187:                         my $category = $cats->[1]{$name}[$j];
1.665     raeburn  9188:                         if (ref($subcats) eq 'HASH') {
                   9189:                             push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
                   9190:                         }
                   9191:                         &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
                   9192:                     }
                   9193:                 } else {
                   9194:                     if (ref($subcats) eq 'HASH') {
                   9195:                         $subcats->{$item} = [];
1.655     raeburn  9196:                     }
                   9197:                 }
                   9198:             }
                   9199:         }
                   9200:     }
                   9201:     return;
                   9202: }
                   9203: 
                   9204: =pod
                   9205: 
                   9206: =item *&recurse_categories()
                   9207: 
                   9208: Recursively used to generate breadcrumb trails for course categories.
                   9209: 
                   9210: Inputs:
1.663     raeburn  9211: 
1.655     raeburn  9212: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   9213:       categories and subcategories).
1.663     raeburn  9214: 
1.655     raeburn  9215: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663     raeburn  9216: 
                   9217: category (current course category, for which breadcrumb trail is being generated).
                   9218: 
                   9219: trails (reference to array of breadcrumb trails for each category).
                   9220: 
1.655     raeburn  9221: allitems (reference to hash - key is category key
                   9222:          (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663     raeburn  9223: 
1.655     raeburn  9224: parents (array containing containers directories for current category, 
                   9225:          back to top level). 
                   9226: 
                   9227: Returns: nothing
                   9228: 
                   9229: Side effects: populates trails and allitems hash references
                   9230: 
                   9231: =cut
                   9232: 
                   9233: sub recurse_categories {
1.665     raeburn  9234:     my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655     raeburn  9235:     my $shallower = $depth - 1;
                   9236:     if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
                   9237:         for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
                   9238:             my $name = $cats->[$depth]{$category}[$k];
                   9239:             my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
                   9240:             my $trailstr = join(' -&gt; ',(@{$parents},$category));
                   9241:             if ($allitems->{$item} eq '') {
                   9242:                 push(@{$trails},$trailstr);
                   9243:                 $allitems->{$item} = scalar(@{$trails})-1;
                   9244:             }
                   9245:             my $deeper = $depth+1;
                   9246:             push(@{$parents},$category);
1.665     raeburn  9247:             if (ref($subcats) eq 'HASH') {
                   9248:                 my $subcat = &escape($name).':'.$category.':'.$depth;
                   9249:                 for (my $j=@{$parents}; $j>=0; $j--) {
                   9250:                     my $higher;
                   9251:                     if ($j > 0) {
                   9252:                         $higher = &escape($parents->[$j]).':'.
                   9253:                                   &escape($parents->[$j-1]).':'.$j;
                   9254:                     } else {
                   9255:                         $higher = &escape($parents->[$j]).'::'.$j;
                   9256:                     }
                   9257:                     push(@{$subcats->{$higher}},$subcat);
                   9258:                 }
                   9259:             }
                   9260:             &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
                   9261:                                 $subcats);
1.655     raeburn  9262:             pop(@{$parents});
                   9263:         }
                   9264:     } else {
                   9265:         my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
                   9266:         my $trailstr = join(' -&gt; ',(@{$parents},$category));
                   9267:         if ($allitems->{$item} eq '') {
                   9268:             push(@{$trails},$trailstr);
                   9269:             $allitems->{$item} = scalar(@{$trails})-1;
                   9270:         }
                   9271:     }
                   9272:     return;
                   9273: }
                   9274: 
1.663     raeburn  9275: =pod
                   9276: 
                   9277: =item *&assign_categories_table()
                   9278: 
                   9279: Create a datatable for display of hierarchical categories in a domain,
                   9280: with checkboxes to allow a course to be categorized. 
                   9281: 
                   9282: Inputs:
                   9283: 
                   9284: cathash - reference to hash of categories defined for the domain (from
                   9285:           configuration.db)
                   9286: 
                   9287: currcat - scalar with an & separated list of categories assigned to a course. 
                   9288: 
                   9289: Returns: $output (markup to be displayed) 
                   9290: 
                   9291: =cut
                   9292: 
                   9293: sub assign_categories_table {
                   9294:     my ($cathash,$currcat) = @_;
                   9295:     my $output;
                   9296:     if (ref($cathash) eq 'HASH') {
                   9297:         my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
                   9298:         &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
                   9299:         $maxdepth = scalar(@cats);
                   9300:         if (@cats > 0) {
                   9301:             my $itemcount = 0;
                   9302:             if (ref($cats[0]) eq 'ARRAY') {
                   9303:                 $output = &Apache::loncommon::start_data_table();
                   9304:                 my @currcategories;
                   9305:                 if ($currcat ne '') {
                   9306:                     @currcategories = split('&',$currcat);
                   9307:                 }
                   9308:                 for (my $i=0; $i<@{$cats[0]}; $i++) {
                   9309:                     my $parent = $cats[0][$i];
                   9310:                     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   9311:                     next if ($parent eq 'instcode');
                   9312:                     my $item = &escape($parent).'::0';
                   9313:                     my $checked = '';
                   9314:                     if (@currcategories > 0) {
                   9315:                         if (grep(/^\Q$item\E$/,@currcategories)) {
1.772     bisitz   9316:                             $checked = ' checked="checked"';
1.663     raeburn  9317:                         }
                   9318:                     }
1.675     raeburn  9319:                     $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
                   9320:                                '<input type="checkbox" name="usecategory" value="'.
                   9321:                                $item.'"'.$checked.' />'.$parent.'</span>'.
                   9322:                                '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663     raeburn  9323:                     my $depth = 1;
                   9324:                     push(@path,$parent);
                   9325:                     $output .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
                   9326:                     pop(@path);
                   9327:                     $output .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
                   9328:                     $itemcount ++;
                   9329:                 }
                   9330:                 $output .= &Apache::loncommon::end_data_table();
                   9331:             }
                   9332:         }
                   9333:     }
                   9334:     return $output;
                   9335: }
                   9336: 
                   9337: =pod
                   9338: 
                   9339: =item *&assign_category_rows()
                   9340: 
                   9341: Create a datatable row for display of nested categories in a domain,
                   9342: with checkboxes to allow a course to be categorized,called recursively.
                   9343: 
                   9344: Inputs:
                   9345: 
                   9346: itemcount - track row number for alternating colors
                   9347: 
                   9348: cats - reference to array of arrays/hashes which encapsulates hierarchy of
                   9349:       categories and subcategories.
                   9350: 
                   9351: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
                   9352: 
                   9353: parent - parent of current category item
                   9354: 
                   9355: path - Array containing all categories back up through the hierarchy from the
                   9356:        current category to the top level.
                   9357: 
                   9358: currcategories - reference to array of current categories assigned to the course
                   9359: 
                   9360: Returns: $output (markup to be displayed).
                   9361: 
                   9362: =cut
                   9363: 
                   9364: sub assign_category_rows {
                   9365:     my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
                   9366:     my ($text,$name,$item,$chgstr);
                   9367:     if (ref($cats) eq 'ARRAY') {
                   9368:         my $maxdepth = scalar(@{$cats});
                   9369:         if (ref($cats->[$depth]) eq 'HASH') {
                   9370:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   9371:                 my $numchildren = @{$cats->[$depth]{$parent}};
                   9372:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   9373:                 $text .= '<td><table class="LC_datatable">';
                   9374:                 for (my $j=0; $j<$numchildren; $j++) {
                   9375:                     $name = $cats->[$depth]{$parent}[$j];
                   9376:                     $item = &escape($name).':'.&escape($parent).':'.$depth;
                   9377:                     my $deeper = $depth+1;
                   9378:                     my $checked = '';
                   9379:                     if (ref($currcategories) eq 'ARRAY') {
                   9380:                         if (@{$currcategories} > 0) {
                   9381:                             if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772     bisitz   9382:                                 $checked = ' checked="checked"';
1.663     raeburn  9383:                             }
                   9384:                         }
                   9385:                     }
1.664     raeburn  9386:                     $text .= '<tr><td><span class="LC_nobreak"><label>'.
                   9387:                              '<input type="checkbox" name="usecategory" value="'.
1.675     raeburn  9388:                              $item.'"'.$checked.' />'.$name.'</label></span>'.
                   9389:                              '<input type="hidden" name="catname" value="'.$name.'" />'.
                   9390:                              '</td><td>';
1.663     raeburn  9391:                     if (ref($path) eq 'ARRAY') {
                   9392:                         push(@{$path},$name);
                   9393:                         $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
                   9394:                         pop(@{$path});
                   9395:                     }
                   9396:                     $text .= '</td></tr>';
                   9397:                 }
                   9398:                 $text .= '</table></td>';
                   9399:             }
                   9400:         }
                   9401:     }
                   9402:     return $text;
                   9403: }
                   9404: 
1.655     raeburn  9405: ############################################################
                   9406: ############################################################
                   9407: 
                   9408: 
1.443     albertel 9409: sub commit_customrole {
1.664     raeburn  9410:     my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630     raeburn  9411:     my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443     albertel 9412:                          ($start?', '.&mt('starting').' '.localtime($start):'').
                   9413:                          ($end?', ending '.localtime($end):'').': <b>'.
                   9414:               &Apache::lonnet::assigncustomrole(
1.664     raeburn  9415:                  $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443     albertel 9416:                  '</b><br />';
                   9417:     return $output;
                   9418: }
                   9419: 
                   9420: sub commit_standardrole {
1.541     raeburn  9421:     my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
                   9422:     my ($output,$logmsg,$linefeed);
                   9423:     if ($context eq 'auto') {
                   9424:         $linefeed = "\n";
                   9425:     } else {
                   9426:         $linefeed = "<br />\n";
                   9427:     }  
1.443     albertel 9428:     if ($three eq 'st') {
1.541     raeburn  9429:         my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
                   9430:                                          $one,$two,$sec,$context);
                   9431:         if (($result =~ /^error/) || ($result eq 'not_in_class') || 
1.626     raeburn  9432:             ($result eq 'unknown_course') || ($result eq 'refused')) {
                   9433:             $output = $logmsg.' '.&mt('Error: ').$result."\n"; 
1.443     albertel 9434:         } else {
1.541     raeburn  9435:             $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443     albertel 9436:                ($start?', '.&mt('starting').' '.localtime($start):'').
1.541     raeburn  9437:                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
                   9438:             if ($context eq 'auto') {
                   9439:                 $output .= $result.$linefeed.&mt('Add to classlist').': ok';
                   9440:             } else {
                   9441:                $output .= '<b>'.$result.'</b>'.$linefeed.
                   9442:                &mt('Add to classlist').': <b>ok</b>';
                   9443:             }
                   9444:             $output .= $linefeed;
1.443     albertel 9445:         }
                   9446:     } else {
                   9447:         $output = &mt('Assigning').' '.$three.' in '.$url.
                   9448:                ($start?', '.&mt('starting').' '.localtime($start):'').
1.541     raeburn  9449:                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652     raeburn  9450:         my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541     raeburn  9451:         if ($context eq 'auto') {
                   9452:             $output .= $result.$linefeed;
                   9453:         } else {
                   9454:             $output .= '<b>'.$result.'</b>'.$linefeed;
                   9455:         }
1.443     albertel 9456:     }
                   9457:     return $output;
                   9458: }
                   9459: 
                   9460: sub commit_studentrole {
1.541     raeburn  9461:     my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626     raeburn  9462:     my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541     raeburn  9463:     if ($context eq 'auto') {
                   9464:         $linefeed = "\n";
                   9465:     } else {
                   9466:         $linefeed = '<br />'."\n";
                   9467:     }
1.443     albertel 9468:     if (defined($one) && defined($two)) {
                   9469:         my $cid=$one.'_'.$two;
                   9470:         my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
                   9471:         my $secchange = 0;
                   9472:         my $expire_role_result;
                   9473:         my $modify_section_result;
1.628     raeburn  9474:         if ($oldsec ne '-1') { 
                   9475:             if ($oldsec ne $sec) {
1.443     albertel 9476:                 $secchange = 1;
1.628     raeburn  9477:                 my $now = time;
1.443     albertel 9478:                 my $uurl='/'.$cid;
                   9479:                 $uurl=~s/\_/\//g;
                   9480:                 if ($oldsec) {
                   9481:                     $uurl.='/'.$oldsec;
                   9482:                 }
1.626     raeburn  9483:                 $oldsecurl = $uurl;
1.628     raeburn  9484:                 $expire_role_result = 
1.652     raeburn  9485:                     &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628     raeburn  9486:                 if ($env{'request.course.sec'} ne '') { 
                   9487:                     if ($expire_role_result eq 'refused') {
                   9488:                         my @roles = ('st');
                   9489:                         my @statuses = ('previous');
                   9490:                         my @roledoms = ($one);
                   9491:                         my $withsec = 1;
                   9492:                         my %roleshash = 
                   9493:                             &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
                   9494:                                               \@statuses,\@roles,\@roledoms,$withsec);
                   9495:                         if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
                   9496:                             my ($oldstart,$oldend) = 
                   9497:                                 split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
                   9498:                             if ($oldend > 0 && $oldend <= $now) {
                   9499:                                 $expire_role_result = 'ok';
                   9500:                             }
                   9501:                         }
                   9502:                     }
                   9503:                 }
1.443     albertel 9504:                 $result = $expire_role_result;
                   9505:             }
                   9506:         }
                   9507:         if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652     raeburn  9508:             $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443     albertel 9509:             if ($modify_section_result =~ /^ok/) {
                   9510:                 if ($secchange == 1) {
1.628     raeburn  9511:                     if ($sec eq '') {
                   9512:                         $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
                   9513:                     } else {
                   9514:                         $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
                   9515:                     }
1.443     albertel 9516:                 } elsif ($oldsec eq '-1') {
1.628     raeburn  9517:                     if ($sec eq '') {
                   9518:                         $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
                   9519:                     } else {
                   9520:                         $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                   9521:                     }
1.443     albertel 9522:                 } else {
1.628     raeburn  9523:                     if ($sec eq '') {
                   9524:                         $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
                   9525:                     } else {
                   9526:                         $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                   9527:                     }
1.443     albertel 9528:                 }
                   9529:             } else {
1.628     raeburn  9530:                 if ($secchange) {       
                   9531:                     $$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;
                   9532:                 } else {
                   9533:                     $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
                   9534:                 }
1.443     albertel 9535:             }
                   9536:             $result = $modify_section_result;
                   9537:         } elsif ($secchange == 1) {
1.628     raeburn  9538:             if ($oldsec eq '') {
                   9539:                 $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
                   9540:             } else {
                   9541:                 $$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;
                   9542:             }
1.626     raeburn  9543:             if ($expire_role_result eq 'refused') {
                   9544:                 my $newsecurl = '/'.$cid;
                   9545:                 $newsecurl =~ s/\_/\//g;
                   9546:                 if ($sec ne '') {
                   9547:                     $newsecurl.='/'.$sec;
                   9548:                 }
                   9549:                 if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
                   9550:                     if ($sec eq '') {
                   9551:                         $$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;
                   9552:                     } else {
                   9553:                         $$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;
                   9554:                     }
                   9555:                 }
                   9556:             }
1.443     albertel 9557:         }
                   9558:     } else {
1.626     raeburn  9559:         $$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 9560:         $result = "error: incomplete course id\n";
                   9561:     }
                   9562:     return $result;
                   9563: }
                   9564: 
                   9565: ############################################################
                   9566: ############################################################
                   9567: 
1.566     albertel 9568: sub check_clone {
1.578     raeburn  9569:     my ($args,$linefeed) = @_;
1.566     albertel 9570:     my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
                   9571:     my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
                   9572:     my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
                   9573:     my $clonemsg;
                   9574:     my $can_clone = 0;
                   9575: 
                   9576:     if ($clonehome eq 'no_host') {
1.578     raeburn  9577:         $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 9578:     } else {
                   9579: 	my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.568     albertel 9580: 	if ($env{'request.role.domain'} eq $args->{'clonedomain'}) {
1.566     albertel 9581: 	    $can_clone = 1;
                   9582: 	} else {
                   9583: 	    my %clonehash = &Apache::lonnet::get('environment',['cloners'],
                   9584: 						 $args->{'clonedomain'},$args->{'clonecourse'});
                   9585: 	    my @cloners = split(/,/,$clonehash{'cloners'});
1.578     raeburn  9586:             if (grep(/^\*$/,@cloners)) {
                   9587:                 $can_clone = 1;
                   9588:             } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
                   9589:                 $can_clone = 1;
                   9590:             } else {
                   9591: 	        my %roleshash =
                   9592: 		    &Apache::lonnet::get_my_roles($args->{'ccuname'},
                   9593: 					 $args->{'ccdomain'},
                   9594:                                          'userroles',['active'],['cc'],
                   9595: 					 [$args->{'clonedomain'}]);
                   9596: 	        if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
                   9597: 		    $can_clone = 1;
                   9598: 	        } else {
                   9599:                     $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'});
                   9600: 	        }
1.566     albertel 9601: 	    }
1.578     raeburn  9602:         }
1.566     albertel 9603:     }
                   9604:     return ($can_clone, $clonemsg, $cloneid, $clonehome);
                   9605: }
                   9606: 
1.444     albertel 9607: sub construct_course {
1.541     raeburn  9608:     my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context) = @_;
1.444     albertel 9609:     my $outcome;
1.541     raeburn  9610:     my $linefeed =  '<br />'."\n";
                   9611:     if ($context eq 'auto') {
                   9612:         $linefeed = "\n";
                   9613:     }
1.566     albertel 9614: 
                   9615: #
                   9616: # Are we cloning?
                   9617: #
                   9618:     my ($can_clone, $clonemsg, $cloneid, $clonehome);
                   9619:     if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578     raeburn  9620: 	($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566     albertel 9621: 	if ($context ne 'auto') {
1.578     raeburn  9622:             if ($clonemsg ne '') {
                   9623: 	        $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
                   9624:             }
1.566     albertel 9625: 	}
                   9626: 	$outcome .= $clonemsg.$linefeed;
                   9627: 
                   9628:         if (!$can_clone) {
                   9629: 	    return (0,$outcome);
                   9630: 	}
                   9631:     }
                   9632: 
1.444     albertel 9633: #
                   9634: # Open course
                   9635: #
                   9636:     my $crstype = lc($args->{'crstype'});
                   9637:     my %cenv=();
                   9638:     $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
                   9639:                                              $args->{'cdescr'},
                   9640:                                              $args->{'curl'},
                   9641:                                              $args->{'course_home'},
                   9642:                                              $args->{'nonstandard'},
                   9643:                                              $args->{'crscode'},
                   9644:                                              $args->{'ccuname'}.':'.
                   9645:                                              $args->{'ccdomain'},
                   9646:                                              $args->{'crstype'});
                   9647: 
                   9648:     # Note: The testing routines depend on this being output; see 
                   9649:     # Utils::Course. This needs to at least be output as a comment
                   9650:     # if anyone ever decides to not show this, and Utils::Course::new
                   9651:     # will need to be suitably modified.
1.541     raeburn  9652:     $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.444     albertel 9653: #
                   9654: # Check if created correctly
                   9655: #
1.479     albertel 9656:     ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444     albertel 9657:     my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.541     raeburn  9658:     $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566     albertel 9659: 
1.444     albertel 9660: #
1.566     albertel 9661: # Do the cloning
                   9662: #   
                   9663:     if ($can_clone && $cloneid) {
                   9664: 	$clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
                   9665: 	if ($context ne 'auto') {
                   9666: 	    $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
                   9667: 	}
                   9668: 	$outcome .= $clonemsg.$linefeed;
                   9669: 	my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444     albertel 9670: # Copy all files
1.637     www      9671: 	&Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444     albertel 9672: # Restore URL
1.566     albertel 9673: 	$cenv{'url'}=$oldcenv{'url'};
1.444     albertel 9674: # Restore title
1.566     albertel 9675: 	$cenv{'description'}=$oldcenv{'description'};
1.444     albertel 9676: # Mark as cloned
1.566     albertel 9677: 	$cenv{'clonedfrom'}=$cloneid;
1.638     www      9678: # Need to clone grading mode
                   9679:         my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
                   9680:         $cenv{'grading'}=$newenv{'grading'};
                   9681: # Do not clone these environment entries
                   9682:         &Apache::lonnet::del('environment',
                   9683:                   ['default_enrollment_start_date',
                   9684:                    'default_enrollment_end_date',
                   9685:                    'question.email',
                   9686:                    'policy.email',
                   9687:                    'comment.email',
                   9688:                    'pch.users.denied',
1.725     raeburn  9689:                    'plc.users.denied',
                   9690:                    'hidefromcat',
                   9691:                    'categories'],
1.638     www      9692:                    $$crsudom,$$crsunum);
1.444     albertel 9693:     }
1.566     albertel 9694: 
1.444     albertel 9695: #
                   9696: # Set environment (will override cloned, if existing)
                   9697: #
                   9698:     my @sections = ();
                   9699:     my @xlists = ();
                   9700:     if ($args->{'crstype'}) {
                   9701:         $cenv{'type'}=$args->{'crstype'};
                   9702:     }
                   9703:     if ($args->{'crsid'}) {
                   9704:         $cenv{'courseid'}=$args->{'crsid'};
                   9705:     }
                   9706:     if ($args->{'crscode'}) {
                   9707:         $cenv{'internal.coursecode'}=$args->{'crscode'};
                   9708:     }
                   9709:     if ($args->{'crsquota'} ne '') {
                   9710:         $cenv{'internal.coursequota'}=$args->{'crsquota'};
                   9711:     } else {
                   9712:         $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
                   9713:     }
                   9714:     if ($args->{'ccuname'}) {
                   9715:         $cenv{'internal.courseowner'} = $args->{'ccuname'}.
                   9716:                                         ':'.$args->{'ccdomain'};
                   9717:     } else {
                   9718:         $cenv{'internal.courseowner'} = $args->{'curruser'};
                   9719:     }
                   9720:     my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
                   9721:     if ($args->{'crssections'}) {
                   9722:         $cenv{'internal.sectionnums'} = '';
                   9723:         if ($args->{'crssections'} =~ m/,/) {
                   9724:             @sections = split/,/,$args->{'crssections'};
                   9725:         } else {
                   9726:             $sections[0] = $args->{'crssections'};
                   9727:         }
                   9728:         if (@sections > 0) {
                   9729:             foreach my $item (@sections) {
                   9730:                 my ($sec,$gp) = split/:/,$item;
                   9731:                 my $class = $args->{'crscode'}.$sec;
                   9732:                 my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
                   9733:                 $cenv{'internal.sectionnums'} .= $item.',';
                   9734:                 unless ($addcheck eq 'ok') {
                   9735:                     push @badclasses, $class;
                   9736:                 }
                   9737:             }
                   9738:             $cenv{'internal.sectionnums'} =~ s/,$//;
                   9739:         }
                   9740:     }
                   9741: # do not hide course coordinator from staff listing, 
                   9742: # even if privileged
                   9743:     $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   9744: # add crosslistings
                   9745:     if ($args->{'crsxlist'}) {
                   9746:         $cenv{'internal.crosslistings'}='';
                   9747:         if ($args->{'crsxlist'} =~ m/,/) {
                   9748:             @xlists = split/,/,$args->{'crsxlist'};
                   9749:         } else {
                   9750:             $xlists[0] = $args->{'crsxlist'};
                   9751:         }
                   9752:         if (@xlists > 0) {
                   9753:             foreach my $item (@xlists) {
                   9754:                 my ($xl,$gp) = split/:/,$item;
                   9755:                 my $addcheck =  &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
                   9756:                 $cenv{'internal.crosslistings'} .= $item.',';
                   9757:                 unless ($addcheck eq 'ok') {
                   9758:                     push @badclasses, $xl;
                   9759:                 }
                   9760:             }
                   9761:             $cenv{'internal.crosslistings'} =~ s/,$//;
                   9762:         }
                   9763:     }
                   9764:     if ($args->{'autoadds'}) {
                   9765:         $cenv{'internal.autoadds'}=$args->{'autoadds'};
                   9766:     }
                   9767:     if ($args->{'autodrops'}) {
                   9768:         $cenv{'internal.autodrops'}=$args->{'autodrops'};
                   9769:     }
                   9770: # check for notification of enrollment changes
                   9771:     my @notified = ();
                   9772:     if ($args->{'notify_owner'}) {
                   9773:         if ($args->{'ccuname'} ne '') {
                   9774:             push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
                   9775:         }
                   9776:     }
                   9777:     if ($args->{'notify_dc'}) {
                   9778:         if ($uname ne '') { 
1.630     raeburn  9779:             push(@notified,$uname.':'.$udom);
1.444     albertel 9780:         }
                   9781:     }
                   9782:     if (@notified > 0) {
                   9783:         my $notifylist;
                   9784:         if (@notified > 1) {
                   9785:             $notifylist = join(',',@notified);
                   9786:         } else {
                   9787:             $notifylist = $notified[0];
                   9788:         }
                   9789:         $cenv{'internal.notifylist'} = $notifylist;
                   9790:     }
                   9791:     if (@badclasses > 0) {
                   9792:         my %lt=&Apache::lonlocal::texthash(
                   9793:                 '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',
                   9794:                 'dnhr' => 'does not have rights to access enrollment in these classes',
                   9795:                 'adby' => 'as determined by the policies of your institution on access to official classlists'
                   9796:         );
1.541     raeburn  9797:         my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
                   9798:                            ' ('.$lt{'adby'}.')';
                   9799:         if ($context eq 'auto') {
                   9800:             $outcome .= $badclass_msg.$linefeed;
1.566     albertel 9801:             $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541     raeburn  9802:             foreach my $item (@badclasses) {
                   9803:                 if ($context eq 'auto') {
                   9804:                     $outcome .= " - $item\n";
                   9805:                 } else {
                   9806:                     $outcome .= "<li>$item</li>\n";
                   9807:                 }
                   9808:             }
                   9809:             if ($context eq 'auto') {
                   9810:                 $outcome .= $linefeed;
                   9811:             } else {
1.566     albertel 9812:                 $outcome .= "</ul><br /><br /></div>\n";
1.541     raeburn  9813:             }
                   9814:         } 
1.444     albertel 9815:     }
                   9816:     if ($args->{'no_end_date'}) {
                   9817:         $args->{'endaccess'} = 0;
                   9818:     }
                   9819:     $cenv{'internal.autostart'}=$args->{'enrollstart'};
                   9820:     $cenv{'internal.autoend'}=$args->{'enrollend'};
                   9821:     $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
                   9822:     $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
                   9823:     if ($args->{'showphotos'}) {
                   9824:       $cenv{'internal.showphotos'}=$args->{'showphotos'};
                   9825:     }
                   9826:     $cenv{'internal.authtype'} = $args->{'authtype'};
                   9827:     $cenv{'internal.autharg'} = $args->{'autharg'}; 
                   9828:     if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
                   9829:         if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'}  eq '') {
1.541     raeburn  9830:             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'); 
                   9831:             if ($context eq 'auto') {
                   9832:                 $outcome .= $krb_msg;
                   9833:             } else {
1.566     albertel 9834:                 $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541     raeburn  9835:             }
                   9836:             $outcome .= $linefeed;
1.444     albertel 9837:         }
                   9838:     }
                   9839:     if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
                   9840:        if ($args->{'setpolicy'}) {
                   9841:            $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   9842:        }
                   9843:        if ($args->{'setcontent'}) {
                   9844:            $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   9845:        }
                   9846:     }
                   9847:     if ($args->{'reshome'}) {
                   9848: 	$cenv{'reshome'}=$args->{'reshome'}.'/';
                   9849: 	$cenv{'reshome'}=~s/\/+$/\//;
                   9850:     }
                   9851: #
                   9852: # course has keyed access
                   9853: #
                   9854:     if ($args->{'setkeys'}) {
                   9855:        $cenv{'keyaccess'}='yes';
                   9856:     }
                   9857: # if specified, key authority is not course, but user
                   9858: # only active if keyaccess is yes
                   9859:     if ($args->{'keyauth'}) {
1.487     albertel 9860: 	my ($user,$domain) = split(':',$args->{'keyauth'});
                   9861: 	$user = &LONCAPA::clean_username($user);
                   9862: 	$domain = &LONCAPA::clean_username($domain);
1.488     foxr     9863: 	if ($user ne '' && $domain ne '') {
1.487     albertel 9864: 	    $cenv{'keyauth'}=$user.':'.$domain;
1.444     albertel 9865: 	}
                   9866:     }
                   9867: 
                   9868:     if ($args->{'disresdis'}) {
                   9869:         $cenv{'pch.roles.denied'}='st';
                   9870:     }
                   9871:     if ($args->{'disablechat'}) {
                   9872:         $cenv{'plc.roles.denied'}='st';
                   9873:     }
                   9874: 
                   9875:     # Record we've not yet viewed the Course Initialization Helper for this 
                   9876:     # course
                   9877:     $cenv{'course.helper.not.run'} = 1;
                   9878:     #
                   9879:     # Use new Randomseed
                   9880:     #
                   9881:     $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
                   9882:     $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
                   9883:     #
                   9884:     # The encryption code and receipt prefix for this course
                   9885:     #
                   9886:     $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
                   9887:     $cenv{'internal.encpref'}=100+int(9*rand(99));
                   9888:     #
                   9889:     # By default, use standard grading
                   9890:     if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
                   9891: 
1.541     raeburn  9892:     $outcome .= $linefeed.&mt('Setting environment').': '.                 
                   9893:           &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444     albertel 9894: #
                   9895: # Open all assignments
                   9896: #
                   9897:     if ($args->{'openall'}) {
                   9898:        my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
                   9899:        my %storecontent = ($storeunder         => time,
                   9900:                            $storeunder.'.type' => 'date_start');
                   9901:        
                   9902:        $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541     raeburn  9903:                  ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444     albertel 9904:    }
                   9905: #
                   9906: # Set first page
                   9907: #
                   9908:     unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
                   9909: 	    || ($cloneid)) {
1.445     albertel 9910: 	use LONCAPA::map;
1.444     albertel 9911: 	$outcome .= &mt('Setting first resource').': ';
1.445     albertel 9912: 
                   9913: 	my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
                   9914:         my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
                   9915: 
1.444     albertel 9916:         $outcome .= ($fatal?$errtext:'read ok').' - ';
                   9917:         my $title; my $url;
                   9918:         if ($args->{'firstres'} eq 'syl') {
1.690     bisitz   9919: 	    $title=&mt('Syllabus');
1.444     albertel 9920:             $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
                   9921:         } else {
1.690     bisitz   9922:             $title=&mt('Navigate Contents');
1.444     albertel 9923:             $url='/adm/navmaps';
                   9924:         }
1.445     albertel 9925: 
                   9926:         $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
                   9927: 	(my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
                   9928: 
                   9929: 	if ($errtext) { $fatal=2; }
1.541     raeburn  9930:         $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444     albertel 9931:     }
1.566     albertel 9932: 
                   9933:     return (1,$outcome);
1.444     albertel 9934: }
                   9935: 
                   9936: ############################################################
                   9937: ############################################################
                   9938: 
1.378     raeburn  9939: sub course_type {
                   9940:     my ($cid) = @_;
                   9941:     if (!defined($cid)) {
                   9942:         $cid = $env{'request.course.id'};
                   9943:     }
1.404     albertel 9944:     if (defined($env{'course.'.$cid.'.type'})) {
                   9945:         return $env{'course.'.$cid.'.type'};
1.378     raeburn  9946:     } else {
                   9947:         return 'Course';
1.377     raeburn  9948:     }
                   9949: }
1.156     albertel 9950: 
1.406     raeburn  9951: sub group_term {
                   9952:     my $crstype = &course_type();
                   9953:     my %names = (
                   9954:                   'Course' => 'group',
                   9955:                   'Group' => 'team',
                   9956:                 );
                   9957:     return $names{$crstype};
                   9958: }
                   9959: 
1.156     albertel 9960: sub icon {
                   9961:     my ($file)=@_;
1.505     albertel 9962:     my $curfext = lc((split(/\./,$file))[-1]);
1.168     albertel 9963:     my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156     albertel 9964:     my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168     albertel 9965:     if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
                   9966: 	if (-e  $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
                   9967: 	          $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   9968: 	            $curfext.".gif") {
                   9969: 	    $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   9970: 		$curfext.".gif";
                   9971: 	}
                   9972:     }
1.249     albertel 9973:     return &lonhttpdurl($iconname);
1.154     albertel 9974: } 
1.84      albertel 9975: 
1.575     albertel 9976: sub lonhttpdurl {
1.692     www      9977: #
                   9978: # Had been used for "small fry" static images on separate port 8080.
                   9979: # Modify here if lightweight http functionality desired again.
                   9980: # Currently eliminated due to increasing firewall issues.
                   9981: #
1.575     albertel 9982:     my ($url)=@_;
1.692     www      9983:     return $url;
1.215     albertel 9984: }
                   9985: 
1.213     albertel 9986: sub connection_aborted {
                   9987:     my ($r)=@_;
                   9988:     $r->print(" ");$r->rflush();
                   9989:     my $c = $r->connection;
                   9990:     return $c->aborted();
                   9991: }
                   9992: 
1.221     foxr     9993: #    Escapes strings that may have embedded 's that will be put into
1.222     foxr     9994: #    strings as 'strings'.
                   9995: sub escape_single {
1.221     foxr     9996:     my ($input) = @_;
1.223     albertel 9997:     $input =~ s/\\/\\\\/g;	# Escape the \'s..(must be first)>
1.221     foxr     9998:     $input =~ s/\'/\\\'/g;	# Esacpe the 's....
                   9999:     return $input;
                   10000: }
1.223     albertel 10001: 
1.222     foxr     10002: #  Same as escape_single, but escape's "'s  This 
                   10003: #  can be used for  "strings"
                   10004: sub escape_double {
                   10005:     my ($input) = @_;
                   10006:     $input =~ s/\\/\\\\/g;	# Escape the /'s..(must be first)>
                   10007:     $input =~ s/\"/\\\"/g;	# Esacpe the "s....
                   10008:     return $input;
                   10009: }
1.223     albertel 10010:  
1.222     foxr     10011: #   Escapes the last element of a full URL.
                   10012: sub escape_url {
                   10013:     my ($url)   = @_;
1.238     raeburn  10014:     my @urlslices = split(/\//, $url,-1);
1.369     www      10015:     my $lastitem = &escape(pop(@urlslices));
1.223     albertel 10016:     return join('/',@urlslices).'/'.$lastitem;
1.222     foxr     10017: }
1.462     albertel 10018: 
                   10019: # -------------------------------------------------------- Initliaze user login
                   10020: sub init_user_environment {
1.463     albertel 10021:     my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462     albertel 10022:     my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
                   10023: 
                   10024:     my $public=($username eq 'public' && $domain eq 'public');
                   10025: 
                   10026: # See if old ID present, if so, remove
                   10027: 
                   10028:     my ($filename,$cookie,$userroles);
                   10029:     my $now=time;
                   10030: 
                   10031:     if ($public) {
                   10032: 	my $max_public=100;
                   10033: 	my $oldest;
                   10034: 	my $oldest_time=0;
                   10035: 	for(my $next=1;$next<=$max_public;$next++) {
                   10036: 	    if (-e $lonids."/publicuser_$next.id") {
                   10037: 		my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
                   10038: 		if ($mtime<$oldest_time || !$oldest_time) {
                   10039: 		    $oldest_time=$mtime;
                   10040: 		    $oldest=$next;
                   10041: 		}
                   10042: 	    } else {
                   10043: 		$cookie="publicuser_$next";
                   10044: 		last;
                   10045: 	    }
                   10046: 	}
                   10047: 	if (!$cookie) { $cookie="publicuser_$oldest"; }
                   10048:     } else {
1.463     albertel 10049: 	# if this isn't a robot, kill any existing non-robot sessions
                   10050: 	if (!$args->{'robot'}) {
                   10051: 	    opendir(DIR,$lonids);
                   10052: 	    while ($filename=readdir(DIR)) {
                   10053: 		if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
                   10054: 		    unlink($lonids.'/'.$filename);
                   10055: 		}
1.462     albertel 10056: 	    }
1.463     albertel 10057: 	    closedir(DIR);
1.462     albertel 10058: 	}
                   10059: # Give them a new cookie
1.463     albertel 10060: 	my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684     www      10061: 		                   : $now.$$.int(rand(10000)));
1.463     albertel 10062: 	$cookie="$username\_$id\_$domain\_$authhost";
1.462     albertel 10063:     
                   10064: # Initialize roles
                   10065: 
                   10066: 	$userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
                   10067:     }
                   10068: # ------------------------------------ Check browser type and MathML capability
                   10069: 
                   10070:     my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
                   10071:         $clientunicode,$clientos) = &decode_user_agent($r);
                   10072: 
                   10073: # -------------------------------------- Any accessibility options to remember?
                   10074:     if (($form->{'interface'}) && ($form->{'remember'} eq 'true')) {
                   10075: 	foreach my $option ('imagesuppress','appletsuppress',
                   10076: 			    'embedsuppress','fontenhance','blackwhite') {
                   10077: 	    if ($form->{$option} eq 'true') {
                   10078: 		&Apache::lonnet::put('environment',{$option => 'on'},
                   10079: 				     $domain,$username);
                   10080: 	    } else {
                   10081: 		&Apache::lonnet::del('environment',[$option],
                   10082: 				     $domain,$username);
                   10083: 	    }
                   10084: 	}
                   10085:     }
                   10086: # ------------------------------------------------------------- Get environment
                   10087: 
                   10088:     my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
                   10089:     my ($tmp) = keys(%userenv);
                   10090:     if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   10091: 	# default remote control to off
                   10092: 	if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
                   10093:     } else {
                   10094: 	undef(%userenv);
                   10095:     }
                   10096:     if (($userenv{'interface'}) && (!$form->{'interface'})) {
                   10097: 	$form->{'interface'}=$userenv{'interface'};
                   10098:     }
                   10099:     $env{'environment.remote'}=$userenv{'remote'};
                   10100:     if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
                   10101: 
                   10102: # --------------- Do not trust query string to be put directly into environment
                   10103:     foreach my $option ('imagesuppress','appletsuppress',
                   10104: 			'embedsuppress','fontenhance','blackwhite',
                   10105: 			'interface','localpath','localres') {
                   10106: 	$form->{$option}=~s/[\n\r\=]//gs;
                   10107:     }
                   10108: # --------------------------------------------------------- Write first profile
                   10109: 
                   10110:     {
                   10111: 	my %initial_env = 
                   10112: 	    ("user.name"          => $username,
                   10113: 	     "user.domain"        => $domain,
                   10114: 	     "user.home"          => $authhost,
                   10115: 	     "browser.type"       => $clientbrowser,
                   10116: 	     "browser.version"    => $clientversion,
                   10117: 	     "browser.mathml"     => $clientmathml,
                   10118: 	     "browser.unicode"    => $clientunicode,
                   10119: 	     "browser.os"         => $clientos,
                   10120: 	     "server.domain"      => $Apache::lonnet::perlvar{'lonDefDomain'},
                   10121: 	     "request.course.fn"  => '',
                   10122: 	     "request.course.uri" => '',
                   10123: 	     "request.course.sec" => '',
                   10124: 	     "request.role"       => 'cm',
                   10125: 	     "request.role.adv"   => $env{'user.adv'},
                   10126: 	     "request.host"       => $ENV{'REMOTE_ADDR'},);
                   10127: 
                   10128:         if ($form->{'localpath'}) {
                   10129: 	    $initial_env{"browser.localpath"}  = $form->{'localpath'};
                   10130: 	    $initial_env{"browser.localres"}   = $form->{'localres'};
                   10131:         }
                   10132: 	
                   10133: 	if ($public) {
                   10134: 	    $initial_env{"environment.remote"} = "off";
                   10135: 	}
                   10136: 	if ($form->{'interface'}) {
                   10137: 	    $form->{'interface'}=~s/\W//gs;
                   10138: 	    $initial_env{"browser.interface"} = $form->{'interface'};
                   10139: 	    $env{'browser.interface'}=$form->{'interface'};
                   10140: 	    foreach my $option ('imagesuppress','appletsuppress',
                   10141: 				'embedsuppress','fontenhance','blackwhite') {
                   10142: 		if (($form->{$option} eq 'true') ||
                   10143: 		    ($userenv{$option} eq 'on')) {
                   10144: 		    $initial_env{"browser.$option"} = "on";
                   10145: 		}
                   10146: 	    }
                   10147: 	}
                   10148: 
1.724     raeburn  10149:         foreach my $tool ('aboutme','blog','portfolio') {
                   10150:             $userenv{'availabletools.'.$tool} = 
                   10151:                 &Apache::lonnet::usertools_access($username,$domain,$tool,'reload');
                   10152:         }
                   10153: 
1.765     raeburn  10154:         foreach my $crstype ('official','unofficial') {
                   10155:             $userenv{'canrequest.'.$crstype} =
                   10156:                 &Apache::lonnet::usertools_access($username,$domain,$crstype,
                   10157:                                                   'reload','requestcourses');
                   10158:         }
                   10159: 
1.462     albertel 10160: 	$env{'user.environment'} = "$lonids/$cookie.id";
                   10161: 	
                   10162: 	if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
                   10163: 		 &GDBM_WRCREAT(),0640)) {
                   10164: 	    &_add_to_env(\%disk_env,\%initial_env);
                   10165: 	    &_add_to_env(\%disk_env,\%userenv,'environment.');
                   10166: 	    &_add_to_env(\%disk_env,$userroles);
1.463     albertel 10167: 	    if (ref($args->{'extra_env'})) {
                   10168: 		&_add_to_env(\%disk_env,$args->{'extra_env'});
                   10169: 	    }
1.462     albertel 10170: 	    untie(%disk_env);
                   10171: 	} else {
1.705     tempelho 10172: 	    &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
                   10173: 			   'Could not create environment storage in lonauth: '.$!.'</span>');
1.462     albertel 10174: 	    return 'error: '.$!;
                   10175: 	}
                   10176:     }
                   10177:     $env{'request.role'}='cm';
                   10178:     $env{'request.role.adv'}=$env{'user.adv'};
                   10179:     $env{'browser.type'}=$clientbrowser;
                   10180: 
                   10181:     return $cookie;
                   10182: 
                   10183: }
                   10184: 
                   10185: sub _add_to_env {
                   10186:     my ($idf,$env_data,$prefix) = @_;
1.676     raeburn  10187:     if (ref($env_data) eq 'HASH') {
                   10188:         while (my ($key,$value) = each(%$env_data)) {
                   10189: 	    $idf->{$prefix.$key} = $value;
                   10190: 	    $env{$prefix.$key}   = $value;
                   10191:         }
1.462     albertel 10192:     }
                   10193: }
                   10194: 
1.685     tempelho 10195: # --- Get the symbolic name of a problem and the url
                   10196: sub get_symb {
                   10197:     my ($request,$silent) = @_;
1.726     raeburn  10198:     (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685     tempelho 10199:     my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
                   10200:     if ($symb eq '') {
                   10201:         if (!$silent) {
                   10202:             $request->print("Unable to handle ambiguous references:$url:.");
                   10203:             return ();
                   10204:         }
                   10205:     }
                   10206:     &Apache::lonenc::check_decrypt(\$symb);
                   10207:     return ($symb);
                   10208: }
                   10209: 
                   10210: # --------------------------------------------------------------Get annotation
                   10211: 
                   10212: sub get_annotation {
                   10213:     my ($symb,$enc) = @_;
                   10214: 
                   10215:     my $key = $symb;
                   10216:     if (!$enc) {
                   10217:         $key =
                   10218:             &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
                   10219:     }
                   10220:     my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
                   10221:     return $annotation{$key};
                   10222: }
                   10223: 
                   10224: sub clean_symb {
1.731     raeburn  10225:     my ($symb,$delete_enc) = @_;
1.685     tempelho 10226: 
                   10227:     &Apache::lonenc::check_decrypt(\$symb);
                   10228:     my $enc = $env{'request.enc'};
1.731     raeburn  10229:     if ($delete_enc) {
1.730     raeburn  10230:         delete($env{'request.enc'});
                   10231:     }
1.685     tempelho 10232: 
                   10233:     return ($symb,$enc);
                   10234: }
1.462     albertel 10235: 
1.41      ng       10236: =pod
                   10237: 
                   10238: =back
                   10239: 
1.112     bowersj2 10240: =cut
1.41      ng       10241: 
1.112     bowersj2 10242: 1;
                   10243: __END__;
1.41      ng       10244: 

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