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

1.10      albertel    1: # The LearningOnline Network with CAPA
1.1       albertel    2: # a pile of common routines
1.10      albertel    3: #
1.791   ! tempelho    4: # $Id: loncommon.pm,v 1.790 2009/04/21 18:27:09 droeschl Exp $
1.10      albertel    5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
1.1       albertel   28: 
                     29: # Makes a table out of the previous attempts
1.2       albertel   30: # Inputs result_from_symbread, user, domain, course_id
1.16      harris41   31: # Reads in non-network-related .tab files
1.1       albertel   32: 
1.35      matthew    33: # POD header:
                     34: 
1.45      matthew    35: =pod
                     36: 
1.35      matthew    37: =head1 NAME
                     38: 
                     39: Apache::loncommon - pile of common routines
                     40: 
                     41: =head1 SYNOPSIS
                     42: 
1.112     bowersj2   43: Common routines for manipulating connections, student answers,
                     44:     domains, common Javascript fragments, etc.
1.35      matthew    45: 
1.112     bowersj2   46: =head1 OVERVIEW
1.35      matthew    47: 
1.112     bowersj2   48: A collection of commonly used subroutines that don't have a natural
                     49: home anywhere else. This collection helps remove
1.35      matthew    50: redundancy from other modules and increase efficiency of memory usage.
                     51: 
                     52: =cut 
                     53: 
                     54: # End of POD header
1.1       albertel   55: package Apache::loncommon;
                     56: 
                     57: use strict;
1.258     albertel   58: use Apache::lonnet;
1.46      matthew    59: use GDBM_File;
1.51      www        60: use POSIX qw(strftime mktime);
1.82      www        61: use Apache::lonmenu();
1.498     albertel   62: use Apache::lonenc();
1.117     www        63: use Apache::lonlocal;
1.685     tempelho   64: use Apache::lonnet();
1.139     matthew    65: use HTML::Entities;
1.334     albertel   66: use Apache::lonhtmlcommon();
                     67: use Apache::loncoursedata();
1.344     albertel   68: use Apache::lontexconvert();
1.444     albertel   69: use Apache::lonclonecourse();
1.479     albertel   70: use LONCAPA qw(:DEFAULT :match);
1.657     raeburn    71: use DateTime::TimeZone;
1.687     raeburn    72: use DateTime::Locale::Catalog;
1.117     www        73: 
1.517     raeburn    74: # ---------------------------------------------- Designs
                     75: use vars qw(%defaultdesign);
                     76: 
1.22      www        77: my $readit;
                     78: 
1.517     raeburn    79: 
1.157     matthew    80: ##
                     81: ## Global Variables
                     82: ##
1.46      matthew    83: 
1.643     foxr       84: 
                     85: # ----------------------------------------------- SSI with retries:
                     86: #
                     87: 
                     88: =pod
                     89: 
1.648     raeburn    90: =head1 Server Side include with retries:
1.643     foxr       91: 
                     92: =over 4
                     93: 
1.648     raeburn    94: =item * &ssi_with_retries(resource,retries form)
1.643     foxr       95: 
                     96: Performs an ssi with some number of retries.  Retries continue either
                     97: until the result is ok or until the retry count supplied by the
                     98: caller is exhausted.  
                     99: 
                    100: Inputs:
1.648     raeburn   101: 
                    102: =over 4
                    103: 
1.643     foxr      104: resource   - Identifies the resource to insert.
1.648     raeburn   105: 
1.643     foxr      106: retries    - Count of the number of retries allowed.
1.648     raeburn   107: 
1.643     foxr      108: form       - Hash that identifies the rendering options.
                    109: 
1.648     raeburn   110: =back
                    111: 
                    112: Returns:
                    113: 
                    114: =over 4
                    115: 
1.643     foxr      116: content    - The content of the response.  If retries were exhausted this is empty.
1.648     raeburn   117: 
1.643     foxr      118: response   - The response from the last attempt (which may or may not have been successful.
                    119: 
1.648     raeburn   120: =back
                    121: 
                    122: =back
                    123: 
1.643     foxr      124: =cut
                    125: 
                    126: sub ssi_with_retries {
                    127:     my ($resource, $retries, %form) = @_;
                    128: 
                    129: 
                    130:     my $ok = 0;			# True if we got a good response.
                    131:     my $content;
                    132:     my $response;
                    133: 
                    134:     # Try to get the ssi done. within the retries count:
                    135: 
                    136:     do {
                    137: 	($content, $response) = &Apache::lonnet::ssi($resource, %form);
                    138: 	$ok      = $response->is_success;
1.650     www       139:         if (!$ok) {
                    140:             &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
                    141:         }
1.643     foxr      142: 	$retries--;
                    143:     } while (!$ok && ($retries > 0));
                    144: 
                    145:     if (!$ok) {
                    146: 	$content = '';		# On error return an empty content.
                    147:     }
                    148:     return ($content, $response);
                    149: 
                    150: }
                    151: 
                    152: 
                    153: 
1.20      www       154: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12      harris41  155: my %language;
1.124     www       156: my %supported_language;
1.12      harris41  157: my %cprtag;
1.192     taceyjo1  158: my %scprtag;
1.351     www       159: my %fe; my %fd; my %fm;
1.41      ng        160: my %category_extensions;
1.12      harris41  161: 
1.46      matthew   162: # ---------------------------------------------- Thesaurus variables
1.144     matthew   163: #
                    164: # %Keywords:
                    165: #      A hash used by &keyword to determine if a word is considered a keyword.
                    166: # $thesaurus_db_file 
                    167: #      Scalar containing the full path to the thesaurus database.
1.46      matthew   168: 
                    169: my %Keywords;
                    170: my $thesaurus_db_file;
                    171: 
1.144     matthew   172: #
                    173: # Initialize values from language.tab, copyright.tab, filetypes.tab,
                    174: # thesaurus.tab, and filecategories.tab.
                    175: #
1.18      www       176: BEGIN {
1.46      matthew   177:     # Variable initialization
                    178:     $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
                    179:     #
1.22      www       180:     unless ($readit) {
1.12      harris41  181: # ------------------------------------------------------------------- languages
                    182:     {
1.158     raeburn   183:         my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
                    184:                                    '/language.tab';
                    185:         if ( open(my $fh,"<$langtabfile") ) {
1.356     albertel  186:             while (my $line = <$fh>) {
                    187:                 next if ($line=~/^\#/);
                    188:                 chomp($line);
                    189:                 my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$line));
1.158     raeburn   190:                 $language{$key}=$val.' - '.$enc;
                    191:                 if ($sup) {
                    192:                     $supported_language{$key}=$sup;
                    193:                 }
                    194:             }
                    195:             close($fh);
                    196:         }
1.12      harris41  197:     }
                    198: # ------------------------------------------------------------------ copyrights
                    199:     {
1.158     raeburn   200:         my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
                    201:                                   '/copyright.tab';
                    202:         if ( open (my $fh,"<$copyrightfile") ) {
1.356     albertel  203:             while (my $line = <$fh>) {
                    204:                 next if ($line=~/^\#/);
                    205:                 chomp($line);
                    206:                 my ($key,$val)=(split(/\s+/,$line,2));
1.158     raeburn   207:                 $cprtag{$key}=$val;
                    208:             }
                    209:             close($fh);
                    210:         }
1.12      harris41  211:     }
1.351     www       212: # ----------------------------------------------------------- source copyrights
1.192     taceyjo1  213:     {
                    214:         my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
                    215:                                   '/source_copyright.tab';
                    216:         if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356     albertel  217:             while (my $line = <$fh>) {
                    218:                 next if ($line =~ /^\#/);
                    219:                 chomp($line);
                    220:                 my ($key,$val)=(split(/\s+/,$line,2));
1.192     taceyjo1  221:                 $scprtag{$key}=$val;
                    222:             }
                    223:             close($fh);
                    224:         }
                    225:     }
1.63      www       226: 
1.517     raeburn   227: # -------------------------------------------------------------- default domain designs
1.63      www       228:     my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517     raeburn   229:     my $designfile = $designdir.'/default.tab';
                    230:     if ( open (my $fh,"<$designfile") ) {
                    231:         while (my $line = <$fh>) {
                    232:             next if ($line =~ /^\#/);
                    233:             chomp($line);
                    234:             my ($key,$val)=(split(/\=/,$line));
                    235:             if ($val) { $defaultdesign{$key}=$val; }
                    236:         }
                    237:         close($fh);
1.63      www       238:     }
                    239: 
1.15      harris41  240: # ------------------------------------------------------------- file categories
                    241:     {
1.158     raeburn   242:         my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
                    243:                                   '/filecategories.tab';
                    244:         if ( open (my $fh,"<$categoryfile") ) {
1.356     albertel  245: 	    while (my $line = <$fh>) {
                    246: 		next if ($line =~ /^\#/);
                    247: 		chomp($line);
                    248:                 my ($extension,$category)=(split(/\s+/,$line,2));
1.158     raeburn   249:                 push @{$category_extensions{lc($category)}},$extension;
                    250:             }
                    251:             close($fh);
                    252:         }
                    253: 
1.15      harris41  254:     }
1.12      harris41  255: # ------------------------------------------------------------------ file types
                    256:     {
1.158     raeburn   257:         my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
                    258:                '/filetypes.tab';
                    259:         if ( open (my $fh,"<$typesfile") ) {
1.356     albertel  260:             while (my $line = <$fh>) {
                    261: 		next if ($line =~ /^\#/);
                    262: 		chomp($line);
                    263:                 my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158     raeburn   264:                 if ($descr ne '') {
                    265:                     $fe{$ending}=lc($emb);
                    266:                     $fd{$ending}=$descr;
1.351     www       267:                     if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158     raeburn   268:                 }
                    269:             }
                    270:             close($fh);
                    271:         }
1.12      harris41  272:     }
1.22      www       273:     &Apache::lonnet::logthis(
1.705     tempelho  274:              "<span style='color:yellow;'>INFO: Read file types</span>");
1.22      www       275:     $readit=1;
1.46      matthew   276:     }  # end of unless($readit) 
1.32      matthew   277:     
                    278: }
1.112     bowersj2  279: 
1.42      matthew   280: ###############################################################
                    281: ##           HTML and Javascript Helper Functions            ##
                    282: ###############################################################
                    283: 
                    284: =pod 
                    285: 
1.112     bowersj2  286: =head1 HTML and Javascript Functions
1.42      matthew   287: 
1.112     bowersj2  288: =over 4
                    289: 
1.648     raeburn   290: =item * &browser_and_searcher_javascript()
1.112     bowersj2  291: 
                    292: X<browsing, javascript>X<searching, javascript>Returns a string
                    293: containing javascript with two functions, C<openbrowser> and
                    294: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
                    295: tags.
1.42      matthew   296: 
1.648     raeburn   297: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42      matthew   298: 
                    299: inputs: formname, elementname, only, omit
                    300: 
                    301: formname and elementname indicate the name of the html form and name of
                    302: the element that the results of the browsing selection are to be placed in. 
                    303: 
                    304: Specifying 'only' will restrict the browser to displaying only files
1.185     www       305: with the given extension.  Can be a comma separated list.
1.42      matthew   306: 
                    307: Specifying 'omit' will restrict the browser to NOT displaying files
1.185     www       308: with the given extension.  Can be a comma separated list.
1.42      matthew   309: 
1.648     raeburn   310: =item * &opensearcher(formname,elementname) [javascript]
1.42      matthew   311: 
                    312: Inputs: formname, elementname
                    313: 
                    314: formname and elementname specify the name of the html form and the name
                    315: of the element the selection from the search results will be placed in.
1.542     raeburn   316: 
1.42      matthew   317: =cut
                    318: 
                    319: sub browser_and_searcher_javascript {
1.199     albertel  320:     my ($mode)=@_;
                    321:     if (!defined($mode)) { $mode='edit'; }
1.453     albertel  322:     my $resurl=&escape_single(&lastresurl());
1.42      matthew   323:     return <<END;
1.219     albertel  324: // <!-- BEGIN LON-CAPA Internal
1.50      matthew   325:     var editbrowser = null;
1.135     albertel  326:     function openbrowser(formname,elementname,only,omit,titleelement) {
1.170     www       327:         var url = '$resurl/?';
1.42      matthew   328:         if (editbrowser == null) {
                    329:             url += 'launch=1&';
                    330:         }
                    331:         url += 'catalogmode=interactive&';
1.199     albertel  332:         url += 'mode=$mode&';
1.611     albertel  333:         url += 'inhibitmenu=yes&';
1.42      matthew   334:         url += 'form=' + formname + '&';
                    335:         if (only != null) {
                    336:             url += 'only=' + only + '&';
1.217     albertel  337:         } else {
                    338:             url += 'only=&';
                    339: 	}
1.42      matthew   340:         if (omit != null) {
                    341:             url += 'omit=' + omit + '&';
1.217     albertel  342:         } else {
                    343:             url += 'omit=&';
                    344: 	}
1.135     albertel  345:         if (titleelement != null) {
                    346:             url += 'titleelement=' + titleelement + '&';
1.217     albertel  347:         } else {
                    348: 	    url += 'titleelement=&';
                    349: 	}
1.42      matthew   350:         url += 'element=' + elementname + '';
                    351:         var title = 'Browser';
1.435     albertel  352:         var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42      matthew   353:         options += ',width=700,height=600';
                    354:         editbrowser = open(url,title,options,'1');
                    355:         editbrowser.focus();
                    356:     }
                    357:     var editsearcher;
1.135     albertel  358:     function opensearcher(formname,elementname,titleelement) {
1.42      matthew   359:         var url = '/adm/searchcat?';
                    360:         if (editsearcher == null) {
                    361:             url += 'launch=1&';
                    362:         }
                    363:         url += 'catalogmode=interactive&';
1.199     albertel  364:         url += 'mode=$mode&';
1.42      matthew   365:         url += 'form=' + formname + '&';
1.135     albertel  366:         if (titleelement != null) {
                    367:             url += 'titleelement=' + titleelement + '&';
1.217     albertel  368:         } else {
                    369: 	    url += 'titleelement=&';
                    370: 	}
1.42      matthew   371:         url += 'element=' + elementname + '';
                    372:         var title = 'Search';
1.435     albertel  373:         var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42      matthew   374:         options += ',width=700,height=600';
                    375:         editsearcher = open(url,title,options,'1');
                    376:         editsearcher.focus();
                    377:     }
1.219     albertel  378: // END LON-CAPA Internal -->
1.42      matthew   379: END
1.170     www       380: }
                    381: 
                    382: sub lastresurl {
1.258     albertel  383:     if ($env{'environment.lastresurl'}) {
                    384: 	return $env{'environment.lastresurl'}
1.170     www       385:     } else {
                    386: 	return '/res';
                    387:     }
                    388: }
                    389: 
                    390: sub storeresurl {
                    391:     my $resurl=&Apache::lonnet::clutter(shift);
                    392:     unless ($resurl=~/^\/res/) { return 0; }
                    393:     $resurl=~s/\/$//;
                    394:     &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646     raeburn   395:     &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170     www       396:     return 1;
1.42      matthew   397: }
                    398: 
1.74      www       399: sub studentbrowser_javascript {
1.111     www       400:    unless (
1.258     albertel  401:             (($env{'request.course.id'}) && 
1.302     albertel  402:              (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
                    403: 	      || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
                    404: 					  '/'.$env{'request.course.sec'})
                    405: 	      ))
1.258     albertel  406:          || ($env{'request.role'}=~/^(au|dc|su)/)
1.111     www       407:           ) { return ''; }  
1.74      www       408:    return (<<'ENDSTDBRW');
1.776     bisitz    409: <script type="text/javascript" language="Javascript">
1.74      www       410:     var stdeditbrowser;
1.558     albertel  411:     function openstdbrowser(formname,uname,udom,roleflag,ignorefilter) {
1.74      www       412:         var url = '/adm/pickstudent?';
                    413:         var filter;
1.558     albertel  414: 	if (!ignorefilter) {
                    415: 	    eval('filter=document.'+formname+'.'+uname+'.value;');
                    416: 	}
1.74      www       417:         if (filter != null) {
                    418:            if (filter != '') {
                    419:                url += 'filter='+filter+'&';
                    420: 	   }
                    421:         }
                    422:         url += 'form=' + formname + '&unameelement='+uname+
                    423:                                     '&udomelement='+udom;
1.111     www       424: 	if (roleflag) { url+="&roles=1"; }
1.102     www       425:         var title = 'Student_Browser';
1.74      www       426:         var options = 'scrollbars=1,resizable=1,menubar=0';
                    427:         options += ',width=700,height=600';
                    428:         stdeditbrowser = open(url,title,options,'1');
                    429:         stdeditbrowser.focus();
                    430:     }
                    431: </script>
                    432: ENDSTDBRW
                    433: }
1.42      matthew   434: 
1.74      www       435: sub selectstudent_link {
1.111     www       436:    my ($form,$unameele,$udomele)=@_;
1.258     albertel  437:    if ($env{'request.course.id'}) {  
1.302     albertel  438:        if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
                    439: 	   && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
                    440: 					'/'.$env{'request.course.sec'})) {
1.111     www       441: 	   return '';
                    442:        }
                    443:        return "<a href='".'javascript:openstdbrowser("'.$form.'","'.$unameele.
1.607     albertel  444:         '","'.$udomele.'");'."'>".&mt('Select User')."</a>";
1.74      www       445:    }
1.258     albertel  446:    if ($env{'request.role'}=~/^(au|dc|su)/) {
1.111     www       447:        return "<a href='".'javascript:openstdbrowser("'.$form.'","'.$unameele.
1.119     www       448:         '","'.$udomele.'",1);'."'>".&mt('Select User')."</a>";
1.111     www       449:    }
                    450:    return '';
1.91      www       451: }
                    452: 
1.653     raeburn   453: sub authorbrowser_javascript {
                    454:     return <<"ENDAUTHORBRW";
1.776     bisitz    455: <script type="text/javascript" language="JavaScript">
1.653     raeburn   456: var stdeditbrowser;
                    457: 
                    458: function openauthorbrowser(formname,udom) {
                    459:     var url = '/adm/pickauthor?';
                    460:     url += 'form='+formname+'&roledom='+udom;
                    461:     var title = 'Author_Browser';
                    462:     var options = 'scrollbars=1,resizable=1,menubar=0';
                    463:     options += ',width=700,height=600';
                    464:     stdeditbrowser = open(url,title,options,'1');
                    465:     stdeditbrowser.focus();
                    466: }
                    467: 
                    468: </script>
                    469: ENDAUTHORBRW
                    470: }
                    471: 
1.91      www       472: sub coursebrowser_javascript {
1.468     raeburn   473:     my ($domainfilter,$sec_element,$formname)=@_;
1.377     raeburn   474:     my $crs_or_grp_alert = &mt('Please select the type of LON-CAPA entity - Course or Group - for which you wish to add/modify a user role');
1.468     raeburn   475:    my $output = '
1.776     bisitz    476: <script type="text/javascript" language="JavaScript">
1.468     raeburn   477:     var stdeditbrowser;'."\n";
                    478:    $output .= <<"ENDSTDBRW";
1.377     raeburn   479:     function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,crstype) {
1.91      www       480:         var url = '/adm/pickcourse?';
1.468     raeburn   481:         var domainfilter = '';
                    482:         var formid = getFormIdByName(formname);
                    483:         if (formid > -1) {
                    484:             var domid = getIndexByName(formid,udom);
                    485:             if (domid > -1) {
                    486:                 if (document.forms[formid].elements[domid].type == 'select-one') {
                    487:                     domainfilter=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
                    488:                 }
                    489:                 if (document.forms[formid].elements[domid].type == 'hidden') {
                    490:                     domainfilter=document.forms[formid].elements[domid].value;
                    491:                 }
                    492:             }
1.91      www       493:         }
1.128     albertel  494:         if (domainfilter != null) {
                    495:            if (domainfilter != '') {
                    496:                url += 'domainfilter='+domainfilter+'&';
                    497: 	   }
                    498:         }
1.91      www       499:         url += 'form=' + formname + '&cnumelement='+uname+
1.187     albertel  500: 	                            '&cdomelement='+udom+
                    501:                                     '&cnameelement='+desc;
1.468     raeburn   502:         if (extra_element !=null && extra_element != '') {
1.594     raeburn   503:             if (formname == 'rolechoice' || formname == 'studentform') {
1.468     raeburn   504:                 url += '&roleelement='+extra_element;
                    505:                 if (domainfilter == null || domainfilter == '') {
                    506:                     url += '&domainfilter='+extra_element;
                    507:                 }
1.234     raeburn   508:             }
1.468     raeburn   509:             else {
                    510:                 if (formname == 'portform') {
                    511:                     url += '&setroles='+extra_element;
                    512:                 }
                    513:             }     
1.230     raeburn   514:         }
1.293     raeburn   515:         if (multflag !=null && multflag != '') {
                    516:             url += '&multiple='+multflag;
                    517:         }
1.377     raeburn   518:         if (crstype == 'Course/Group') {
                    519:             if (formname == 'cu') {
                    520:                 crstype = document.cu.crstype.options[document.cu.crstype.selectedIndex].value; 
                    521:                 if (crstype == "") {
                    522:                     alert("$crs_or_grp_alert");
                    523:                     return;
                    524:                 }
                    525:             }
                    526:         }
                    527:         if (crstype !=null && crstype != '') {
                    528:             url += '&type='+crstype;
                    529:         }
1.102     www       530:         var title = 'Course_Browser';
1.91      www       531:         var options = 'scrollbars=1,resizable=1,menubar=0';
                    532:         options += ',width=700,height=600';
                    533:         stdeditbrowser = open(url,title,options,'1');
                    534:         stdeditbrowser.focus();
                    535:     }
1.468     raeburn   536: 
                    537:     function getFormIdByName(formname) {
                    538:         for (var i=0;i<document.forms.length;i++) {
                    539:             if (document.forms[i].name == formname) {
                    540:                 return i;
                    541:             }
                    542:         }
                    543:         return -1; 
                    544:     }
                    545: 
                    546:     function getIndexByName(formid,item) {
                    547:         for (var i=0;i<document.forms[formid].elements.length;i++) {
                    548:             if (document.forms[formid].elements[i].name == item) {
                    549:                 return i;
                    550:             }
                    551:         }
                    552:         return -1;
                    553:     }
1.91      www       554: ENDSTDBRW
1.468     raeburn   555:     if ($sec_element ne '') {
                    556:         $output .= &setsec_javascript($sec_element,$formname);
                    557:     }
                    558:     $output .= '
                    559: </script>';
                    560:     return $output;
                    561: }
                    562: 
                    563: sub setsec_javascript {
                    564:     my ($sec_element,$formname) = @_;
                    565:     my $setsections = qq|
                    566: function setSect(sectionlist) {
1.629     raeburn   567:     var sectionsArray = new Array();
                    568:     if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
                    569:         sectionsArray = sectionlist.split(",");
                    570:     }
1.468     raeburn   571:     var numSections = sectionsArray.length;
                    572:     document.$formname.$sec_element.length = 0;
                    573:     if (numSections == 0) {
                    574:         document.$formname.$sec_element.multiple=false;
                    575:         document.$formname.$sec_element.size=1;
                    576:         document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
                    577:     } else {
                    578:         if (numSections == 1) {
                    579:             document.$formname.$sec_element.multiple=false;
                    580:             document.$formname.$sec_element.size=1;
                    581:             document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
                    582:             document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
                    583:             document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
                    584:         } else {
                    585:             for (var i=0; i<numSections; i++) {
                    586:                 document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
                    587:             }
                    588:             document.$formname.$sec_element.multiple=true
                    589:             if (numSections < 3) {
                    590:                 document.$formname.$sec_element.size=numSections;
                    591:             } else {
                    592:                 document.$formname.$sec_element.size=3;
                    593:             }
                    594:             document.$formname.$sec_element.options[0].selected = false
                    595:         }
                    596:     }
1.91      www       597: }
1.468     raeburn   598: |;
                    599:     return $setsections;
                    600: }
                    601: 
1.91      www       602: 
                    603: sub selectcourse_link {
1.377     raeburn   604:    my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype)=@_;
1.787     bisitz    605:    return '<span class="LC_nobreak">'
                    606:          ."<a href='"
                    607:          .'javascript:opencrsbrowser("'.$form.'","'.$unameele
                    608:          .'","'.$udomele.'","'.$desc.'","'.$extra_element
                    609:          .'","'.$multflag.'","'.$selecttype.'");'
                    610:          ."'>".&mt('Select Course').'</a>'
                    611:          .'</span>';
1.74      www       612: }
1.42      matthew   613: 
1.653     raeburn   614: sub selectauthor_link {
                    615:    my ($form,$udom)=@_;
                    616:    return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
                    617:           &mt('Select Author').'</a>';
                    618: }
                    619: 
1.273     raeburn   620: sub check_uncheck_jscript {
                    621:     my $jscript = <<"ENDSCRT";
                    622: function checkAll(field) {
                    623:     if (field.length > 0) {
                    624:         for (i = 0; i < field.length; i++) {
                    625:             field[i].checked = true ;
                    626:         }
                    627:     } else {
                    628:         field.checked = true
                    629:     }
                    630: }
                    631:  
                    632: function uncheckAll(field) {
                    633:     if (field.length > 0) {
                    634:         for (i = 0; i < field.length; i++) {
                    635:             field[i].checked = false ;
1.543     albertel  636:         }
                    637:     } else {
1.273     raeburn   638:         field.checked = false ;
                    639:     }
                    640: }
                    641: ENDSCRT
                    642:     return $jscript;
                    643: }
                    644: 
1.656     www       645: sub select_timezone {
1.659     raeburn   646:    my ($name,$selected,$onchange,$includeempty)=@_;
                    647:    my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
                    648:    if ($includeempty) {
                    649:        $output .= '<option value=""';
                    650:        if (($selected eq '') || ($selected eq 'local')) {
                    651:            $output .= ' selected="selected" ';
                    652:        }
                    653:        $output .= '> </option>';
                    654:    }
1.657     raeburn   655:    my @timezones = DateTime::TimeZone->all_names;
                    656:    foreach my $tzone (@timezones) {
                    657:        $output.= '<option value="'.$tzone.'"';
                    658:        if ($tzone eq $selected) {
                    659:            $output.=' selected="selected"';
                    660:        }
                    661:        $output.=">$tzone</option>\n";
1.656     www       662:    }
                    663:    $output.="</select>";
                    664:    return $output;
                    665: }
1.273     raeburn   666: 
1.687     raeburn   667: sub select_datelocale {
                    668:     my ($name,$selected,$onchange,$includeempty)=@_;
                    669:     my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
                    670:     if ($includeempty) {
                    671:         $output .= '<option value=""';
                    672:         if ($selected eq '') {
                    673:             $output .= ' selected="selected" ';
                    674:         }
                    675:         $output .= '> </option>';
                    676:     }
                    677:     my (@possibles,%locale_names);
                    678:     my @locales = DateTime::Locale::Catalog::Locales;
                    679:     foreach my $locale (@locales) {
                    680:         if (ref($locale) eq 'HASH') {
                    681:             my $id = $locale->{'id'};
                    682:             if ($id ne '') {
                    683:                 my $en_terr = $locale->{'en_territory'};
                    684:                 my $native_terr = $locale->{'native_territory'};
1.695     raeburn   685:                 my @languages = &Apache::lonlocal::preferred_languages();
1.687     raeburn   686:                 if (grep(/^en$/,@languages) || !@languages) {
                    687:                     if ($en_terr ne '') {
                    688:                         $locale_names{$id} = '('.$en_terr.')';
                    689:                     } elsif ($native_terr ne '') {
                    690:                         $locale_names{$id} = $native_terr;
                    691:                     }
                    692:                 } else {
                    693:                     if ($native_terr ne '') {
                    694:                         $locale_names{$id} = $native_terr.' ';
                    695:                     } elsif ($en_terr ne '') {
                    696:                         $locale_names{$id} = '('.$en_terr.')';
                    697:                     }
                    698:                 }
                    699:                 push (@possibles,$id);
                    700:             }
                    701:         }
                    702:     }
                    703:     foreach my $item (sort(@possibles)) {
                    704:         $output.= '<option value="'.$item.'"';
                    705:         if ($item eq $selected) {
                    706:             $output.=' selected="selected"';
                    707:         }
                    708:         $output.=">$item";
                    709:         if ($locale_names{$item} ne '') {
                    710:             $output.="  $locale_names{$item}</option>\n";
                    711:         }
                    712:         $output.="</option>\n";
                    713:     }
                    714:     $output.="</select>";
                    715:     return $output;
                    716: }
                    717: 
1.42      matthew   718: =pod
1.36      matthew   719: 
1.648     raeburn   720: =item * &linked_select_forms(...)
1.36      matthew   721: 
                    722: linked_select_forms returns a string containing a <script></script> block
                    723: and html for two <select> menus.  The select menus will be linked in that
                    724: changing the value of the first menu will result in new values being placed
                    725: in the second menu.  The values in the select menu will appear in alphabetical
1.609     raeburn   726: order unless a defined order is provided.
1.36      matthew   727: 
                    728: linked_select_forms takes the following ordered inputs:
                    729: 
                    730: =over 4
                    731: 
1.112     bowersj2  732: =item * $formname, the name of the <form> tag
1.36      matthew   733: 
1.112     bowersj2  734: =item * $middletext, the text which appears between the <select> tags
1.36      matthew   735: 
1.112     bowersj2  736: =item * $firstdefault, the default value for the first menu
1.36      matthew   737: 
1.112     bowersj2  738: =item * $firstselectname, the name of the first <select> tag
1.36      matthew   739: 
1.112     bowersj2  740: =item * $secondselectname, the name of the second <select> tag
1.36      matthew   741: 
1.112     bowersj2  742: =item * $hashref, a reference to a hash containing the data for the menus.
1.36      matthew   743: 
1.609     raeburn   744: =item * $menuorder, the order of values in the first menu
                    745: 
1.41      ng        746: =back 
                    747: 
1.36      matthew   748: Below is an example of such a hash.  Only the 'text', 'default', and 
                    749: 'select2' keys must appear as stated.  keys(%menu) are the possible 
                    750: values for the first select menu.  The text that coincides with the 
1.41      ng        751: first menu value is given in $menu{$choice1}->{'text'}.  The values 
1.36      matthew   752: and text for the second menu are given in the hash pointed to by 
                    753: $menu{$choice1}->{'select2'}.  
                    754: 
1.112     bowersj2  755:  my %menu = ( A1 => { text =>"Choice A1" ,
                    756:                        default => "B3",
                    757:                        select2 => { 
                    758:                            B1 => "Choice B1",
                    759:                            B2 => "Choice B2",
                    760:                            B3 => "Choice B3",
                    761:                            B4 => "Choice B4"
1.609     raeburn   762:                            },
                    763:                        order => ['B4','B3','B1','B2'],
1.112     bowersj2  764:                    },
                    765:                A2 => { text =>"Choice A2" ,
                    766:                        default => "C2",
                    767:                        select2 => { 
                    768:                            C1 => "Choice C1",
                    769:                            C2 => "Choice C2",
                    770:                            C3 => "Choice C3"
1.609     raeburn   771:                            },
                    772:                        order => ['C2','C1','C3'],
1.112     bowersj2  773:                    },
                    774:                A3 => { text =>"Choice A3" ,
                    775:                        default => "D6",
                    776:                        select2 => { 
                    777:                            D1 => "Choice D1",
                    778:                            D2 => "Choice D2",
                    779:                            D3 => "Choice D3",
                    780:                            D4 => "Choice D4",
                    781:                            D5 => "Choice D5",
                    782:                            D6 => "Choice D6",
                    783:                            D7 => "Choice D7"
1.609     raeburn   784:                            },
                    785:                        order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112     bowersj2  786:                    }
                    787:                );
1.36      matthew   788: 
                    789: =cut
                    790: 
                    791: sub linked_select_forms {
                    792:     my ($formname,
                    793:         $middletext,
                    794:         $firstdefault,
                    795:         $firstselectname,
                    796:         $secondselectname, 
1.609     raeburn   797:         $hashref,
                    798:         $menuorder,
1.36      matthew   799:         ) = @_;
                    800:     my $second = "document.$formname.$secondselectname";
                    801:     my $first = "document.$formname.$firstselectname";
                    802:     # output the javascript to do the changing
                    803:     my $result = '';
1.776     bisitz    804:     $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.36      matthew   805:     $result.="var select2data = new Object();\n";
                    806:     $" = '","';
                    807:     my $debug = '';
                    808:     foreach my $s1 (sort(keys(%$hashref))) {
                    809:         $result.="select2data.d_$s1 = new Object();\n";        
                    810:         $result.="select2data.d_$s1.def = new String('".
                    811:             $hashref->{$s1}->{'default'}."');\n";
1.609     raeburn   812:         $result.="select2data.d_$s1.values = new Array(";
1.36      matthew   813:         my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609     raeburn   814:         if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
                    815:             @s2values = @{$hashref->{$s1}->{'order'}};
                    816:         }
1.36      matthew   817:         $result.="\"@s2values\");\n";
                    818:         $result.="select2data.d_$s1.texts = new Array(";        
                    819:         my @s2texts;
                    820:         foreach my $value (@s2values) {
                    821:             push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
                    822:         }
                    823:         $result.="\"@s2texts\");\n";
                    824:     }
                    825:     $"=' ';
                    826:     $result.= <<"END";
                    827: 
                    828: function select1_changed() {
                    829:     // Determine new choice
                    830:     var newvalue = "d_" + $first.value;
                    831:     // update select2
                    832:     var values     = select2data[newvalue].values;
                    833:     var texts      = select2data[newvalue].texts;
                    834:     var select2def = select2data[newvalue].def;
                    835:     var i;
                    836:     // out with the old
                    837:     for (i = 0; i < $second.options.length; i++) {
                    838:         $second.options[i] = null;
                    839:     }
                    840:     // in with the nuclear
                    841:     for (i=0;i<values.length; i++) {
                    842:         $second.options[i] = new Option(values[i]);
1.143     matthew   843:         $second.options[i].value = values[i];
1.36      matthew   844:         $second.options[i].text = texts[i];
                    845:         if (values[i] == select2def) {
                    846:             $second.options[i].selected = true;
                    847:         }
                    848:     }
                    849: }
                    850: </script>
                    851: END
                    852:     # output the initial values for the selection lists
                    853:     $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609     raeburn   854:     my @order = sort(keys(%{$hashref}));
                    855:     if (ref($menuorder) eq 'ARRAY') {
                    856:         @order = @{$menuorder};
                    857:     }
                    858:     foreach my $value (@order) {
1.36      matthew   859:         $result.="    <option value=\"$value\" ";
1.253     albertel  860:         $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119     www       861:         $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36      matthew   862:     }
                    863:     $result .= "</select>\n";
                    864:     my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
                    865:     $result .= $middletext;
                    866:     $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
                    867:     my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609     raeburn   868:     
                    869:     my @secondorder = sort(keys(%select2));
                    870:     if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
                    871:         @secondorder = @{$hashref->{$firstdefault}->{'order'}};
                    872:     }
                    873:     foreach my $value (@secondorder) {
1.36      matthew   874:         $result.="    <option value=\"$value\" ";        
1.253     albertel  875:         $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119     www       876:         $result.=">".&mt($select2{$value})."</option>\n";
1.36      matthew   877:     }
                    878:     $result .= "</select>\n";
                    879:     #    return $debug;
                    880:     return $result;
                    881: }   #  end of sub linked_select_forms {
                    882: 
1.45      matthew   883: =pod
1.44      bowersj2  884: 
1.648     raeburn   885: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height)
1.44      bowersj2  886: 
1.112     bowersj2  887: Returns a string corresponding to an HTML link to the given help
                    888: $topic, where $topic corresponds to the name of a .tex file in
                    889: /home/httpd/html/adm/help/tex, with underscores replaced by
                    890: spaces. 
                    891: 
                    892: $text will optionally be linked to the same topic, allowing you to
                    893: link text in addition to the graphic. If you do not want to link
                    894: text, but wish to specify one of the later parameters, pass an
                    895: empty string. 
                    896: 
                    897: $stayOnPage is a value that will be interpreted as a boolean. If true,
                    898: the link will not open a new window. If false, the link will open
                    899: a new window using Javascript. (Default is false.) 
                    900: 
                    901: $width and $height are optional numerical parameters that will
                    902: override the width and height of the popped up window, which may
                    903: be useful for certain help topics with big pictures included. 
1.44      bowersj2  904: 
                    905: =cut
                    906: 
                    907: sub help_open_topic {
1.48      bowersj2  908:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
                    909:     $text = "" if (not defined $text);
1.44      bowersj2  910:     $stayOnPage = 0 if (not defined $stayOnPage);
1.552     banghart  911:     if ($env{'browser.interface'} eq 'textual') {
1.79      www       912: 	$stayOnPage=1;
                    913:     }
1.44      bowersj2  914:     $width = 350 if (not defined $width);
                    915:     $height = 400 if (not defined $height);
                    916:     my $filename = $topic;
                    917:     $filename =~ s/ /_/g;
                    918: 
1.48      bowersj2  919:     my $template = "";
                    920:     my $link;
1.572     banghart  921:     
1.159     www       922:     $topic=~s/\W/\_/g;
1.44      bowersj2  923: 
1.572     banghart  924:     if (!$stayOnPage) {
1.72      bowersj2  925: 	$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  926:     } else {
1.48      bowersj2  927: 	$link = "/adm/help/${filename}.hlp";
                    928:     }
                    929: 
                    930:     # Add the text
1.755     neumanie  931:     if ($text ne "") {	
1.763     bisitz    932: 	$template.='<span class="LC_help_open_topic">'
                    933:                   .'<a target="_top" href="'.$link.'">'
                    934:                   .$text.'</a>';
1.48      bowersj2  935:     }
                    936: 
1.763     bisitz    937:     # (Always) Add the graphic
1.179     matthew   938:     my $title = &mt('Online Help');
1.667     raeburn   939:     my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.763     bisitz    940:     $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
                    941:               .'<img src="'.$helpicon.'" border="0"'
                    942:               .' alt="'.&mt('Help: [_1]',$topic).'"'
1.783     amueller  943:               .' title="'.$title.'"' 
1.763     bisitz    944:               .' /></a>';
                    945:     if ($text ne "") {	
                    946:         $template.='</span>';
                    947:     }
1.44      bowersj2  948:     return $template;
                    949: 
1.106     bowersj2  950: }
                    951: 
                    952: # This is a quicky function for Latex cheatsheet editing, since it 
                    953: # appears in at least four places
                    954: sub helpLatexCheatsheet {
1.732     raeburn   955:     my ($topic,$text,$not_author) = @_;
                    956:     my $out;
1.106     bowersj2  957:     my $addOther = '';
1.732     raeburn   958:     if ($topic) {
1.763     bisitz    959: 	$addOther = '<span>'.&Apache::loncommon::help_open_topic($topic,&mt($text),
                    960: 							       undef, undef, 600).
                    961: 								   '</span> ';
                    962:     }
                    963:     $out = '<span>' # Start cheatsheet
                    964: 	  .$addOther
                    965:           .'<span>'
                    966: 	  .&Apache::loncommon::help_open_topic('Greek_Symbols',&mt('Greek Symbols'),
                    967: 					       undef,undef,600)
                    968: 	  .'</span> <span>'
                    969: 	  .&Apache::loncommon::help_open_topic('Other_Symbols',&mt('Other Symbols'),
                    970: 					       undef,undef,600)
                    971: 	  .'</span>';
1.732     raeburn   972:     unless ($not_author) {
1.763     bisitz    973:         $out .= ' <span>'
                    974: 	       .&Apache::loncommon::help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),
                    975: 	                                            undef,undef,600)
                    976: 	       .'</span>';
1.732     raeburn   977:     }
1.763     bisitz    978:     $out .= '</span>'; # End cheatsheet
1.732     raeburn   979:     return $out;
1.172     www       980: }
                    981: 
1.430     albertel  982: sub general_help {
                    983:     my $helptopic='Student_Intro';
                    984:     if ($env{'request.role'}=~/^(ca|au)/) {
                    985: 	$helptopic='Authoring_Intro';
                    986:     } elsif ($env{'request.role'}=~/^cc/) {
                    987: 	$helptopic='Course_Coordination_Intro';
1.672     raeburn   988:     } elsif ($env{'request.role'}=~/^dc/) {
                    989:         $helptopic='Domain_Coordination_Intro';
1.430     albertel  990:     }
                    991:     return $helptopic;
                    992: }
                    993: 
                    994: sub update_help_link {
                    995:     my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
                    996:     my $origurl = $ENV{'REQUEST_URI'};
                    997:     $origurl=~s|^/~|/priv/|;
                    998:     my $timestamp = time;
                    999:     foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
                   1000:         $$datum = &escape($$datum);
                   1001:     }
                   1002: 
                   1003:     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";
                   1004:     my $output .= <<"ENDOUTPUT";
                   1005: <script type="text/javascript">
                   1006: banner_link = '$banner_link';
                   1007: </script>
                   1008: ENDOUTPUT
                   1009:     return $output;
                   1010: }
                   1011: 
                   1012: # now just updates the help link and generates a blue icon
1.193     raeburn  1013: sub help_open_menu {
1.430     albertel 1014:     my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text) 
1.552     banghart 1015: 	= @_;    
1.430     albertel 1016:     $stayOnPage = 0 if (not defined $stayOnPage);
1.572     banghart 1017:     # only use pop-up help (stayOnPage == 0)
1.552     banghart 1018:     # if environment.remote is on (using remote control UI)
1.572     banghart 1019:     if ($env{'browser.interface'} eq 'textual' ||
                   1020:     	$env{'environment.remote'} eq 'off' ) {
1.552     banghart 1021:         $stayOnPage=1;
1.430     albertel 1022:     }
                   1023:     my $output;
                   1024:     if ($component_help) {
                   1025: 	if (!$text) {
                   1026: 	    $output=&help_open_topic($component_help,undef,$stayOnPage,
                   1027: 				       $width,$height);
                   1028: 	} else {
                   1029: 	    my $help_text;
                   1030: 	    $help_text=&unescape($topic);
                   1031: 	    $output='<table><tr><td>'.
                   1032: 		&help_open_topic($component_help,$help_text,$stayOnPage,
                   1033: 				 $width,$height).'</td></tr></table>';
                   1034: 	}
                   1035:     }
                   1036:     my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
                   1037:     return $output.$banner_link;
                   1038: }
                   1039: 
                   1040: sub top_nav_help {
                   1041:     my ($text) = @_;
1.436     albertel 1042:     $text = &mt($text);
1.572     banghart 1043:     my $stay_on_page = 
1.436     albertel 1044: 	($env{'browser.interface'}  eq 'textual' ||
                   1045: 	 $env{'environment.remote'} eq 'off' );
1.572     banghart 1046:     my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436     albertel 1047: 	                     : "javascript:helpMenu('open')";
1.572     banghart 1048:     my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436     albertel 1049: 
1.201     raeburn  1050:     my $title = &mt('Get help');
1.436     albertel 1051: 
                   1052:     return <<"END";
                   1053: $banner_link
                   1054:  <a href="$link" title="$title">$text</a>
                   1055: END
                   1056: }
                   1057: 
                   1058: sub help_menu_js {
                   1059:     my ($text) = @_;
                   1060: 
                   1061:     my $stayOnPage = 
                   1062: 	($env{'browser.interface'}  eq 'textual' ||
                   1063: 	 $env{'environment.remote'} eq 'off' );
                   1064: 
                   1065:     my $width = 620;
                   1066:     my $height = 600;
1.430     albertel 1067:     my $helptopic=&general_help();
                   1068:     my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261     albertel 1069:     my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331     albertel 1070:     my $start_page =
                   1071:         &Apache::loncommon::start_page('Help Menu', undef,
                   1072: 				       {'frameset'    => 1,
                   1073: 					'js_ready'    => 1,
                   1074: 					'add_entries' => {
                   1075: 					    'border' => '0',
1.579     raeburn  1076: 					    'rows'   => "110,*",},});
1.331     albertel 1077:     my $end_page =
                   1078:         &Apache::loncommon::end_page({'frameset' => 1,
                   1079: 				      'js_ready' => 1,});
                   1080: 
1.436     albertel 1081:     my $template .= <<"ENDTEMPLATE";
                   1082: <script type="text/javascript">
1.253     albertel 1083: // <!-- BEGIN LON-CAPA Internal
                   1084: // <![CDATA[
1.430     albertel 1085: var banner_link = '';
1.243     raeburn  1086: function helpMenu(target) {
                   1087:     var caller = this;
                   1088:     if (target == 'open') {
                   1089:         var newWindow = null;
                   1090:         try {
1.262     albertel 1091:             newWindow =  window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243     raeburn  1092:         }
                   1093:         catch(error) {
                   1094:             writeHelp(caller);
                   1095:             return;
                   1096:         }
                   1097:         if (newWindow) {
                   1098:             caller = newWindow;
                   1099:         }
1.193     raeburn  1100:     }
1.243     raeburn  1101:     writeHelp(caller);
                   1102:     return;
                   1103: }
                   1104: function writeHelp(caller) {
1.430     albertel 1105:     caller.document.writeln('$start_page<frame name="bannerframe"  src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243     raeburn  1106:     caller.document.close()
                   1107:     caller.focus()
1.193     raeburn  1108: }
1.253     albertel 1109: // ]]>
1.219     albertel 1110: // END LON-CAPA Internal -->
1.436     albertel 1111: </script>
1.193     raeburn  1112: ENDTEMPLATE
                   1113:     return $template;
                   1114: }
                   1115: 
1.172     www      1116: sub help_open_bug {
                   1117:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258     albertel 1118:     unless ($env{'user.adv'}) { return ''; }
1.172     www      1119:     unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
                   1120:     $text = "" if (not defined $text);
                   1121:     $stayOnPage = 0 if (not defined $stayOnPage);
1.258     albertel 1122:     if ($env{'browser.interface'} eq 'textual' ||
                   1123: 	$env{'environment.remote'} eq 'off' ) {
1.172     www      1124: 	$stayOnPage=1;
                   1125:     }
1.184     albertel 1126:     $width = 600 if (not defined $width);
                   1127:     $height = 600 if (not defined $height);
1.172     www      1128: 
                   1129:     $topic=~s/\W+/\+/g;
                   1130:     my $link='';
                   1131:     my $template='';
1.379     albertel 1132:     my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&amp;bug_file_loc='.
                   1133: 	&escape($ENV{'REQUEST_URI'}).'&amp;component='.$topic;
1.172     www      1134:     if (!$stayOnPage)
                   1135:     {
                   1136: 	$link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
                   1137:     }
                   1138:     else
                   1139:     {
                   1140: 	$link = $url;
                   1141:     }
                   1142:     # Add the text
                   1143:     if ($text ne "")
                   1144:     {
                   1145: 	$template .= 
                   1146:   "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705     tempelho 1147:   "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172     www      1148:     }
                   1149: 
                   1150:     # Add the graphic
1.179     matthew  1151:     my $title = &mt('Report a Bug');
1.215     albertel 1152:     my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172     www      1153:     $template .= <<"ENDTEMPLATE";
1.436     albertel 1154:  <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172     www      1155: ENDTEMPLATE
                   1156:     if ($text ne '') { $template.='</td></tr></table>' };
                   1157:     return $template;
                   1158: 
                   1159: }
                   1160: 
                   1161: sub help_open_faq {
                   1162:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258     albertel 1163:     unless ($env{'user.adv'}) { return ''; }
1.172     www      1164:     unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
                   1165:     $text = "" if (not defined $text);
                   1166:     $stayOnPage = 0 if (not defined $stayOnPage);
1.258     albertel 1167:     if ($env{'browser.interface'} eq 'textual' ||
                   1168: 	$env{'environment.remote'} eq 'off' ) {
1.172     www      1169: 	$stayOnPage=1;
                   1170:     }
                   1171:     $width = 350 if (not defined $width);
                   1172:     $height = 400 if (not defined $height);
                   1173: 
                   1174:     $topic=~s/\W+/\+/g;
                   1175:     my $link='';
                   1176:     my $template='';
                   1177:     my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
                   1178:     if (!$stayOnPage)
                   1179:     {
                   1180: 	$link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
                   1181:     }
                   1182:     else
                   1183:     {
                   1184: 	$link = $url;
                   1185:     }
                   1186: 
                   1187:     # Add the text
                   1188:     if ($text ne "")
                   1189:     {
                   1190: 	$template .= 
1.173     www      1191:   "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705     tempelho 1192:   "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172     www      1193:     }
                   1194: 
                   1195:     # Add the graphic
1.179     matthew  1196:     my $title = &mt('View the FAQ');
1.215     albertel 1197:     my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172     www      1198:     $template .= <<"ENDTEMPLATE";
1.436     albertel 1199:  <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172     www      1200: ENDTEMPLATE
                   1201:     if ($text ne '') { $template.='</td></tr></table>' };
                   1202:     return $template;
                   1203: 
1.44      bowersj2 1204: }
1.37      matthew  1205: 
1.180     matthew  1206: ###############################################################
                   1207: ###############################################################
                   1208: 
1.45      matthew  1209: =pod
                   1210: 
1.648     raeburn  1211: =item * &change_content_javascript():
1.256     matthew  1212: 
                   1213: This and the next function allow you to create small sections of an
                   1214: otherwise static HTML page that you can update on the fly with
                   1215: Javascript, even in Netscape 4.
                   1216: 
                   1217: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
                   1218: must be written to the HTML page once. It will prove the Javascript
                   1219: function "change(name, content)". Calling the change function with the
                   1220: name of the section 
                   1221: you want to update, matching the name passed to C<changable_area>, and
                   1222: the new content you want to put in there, will put the content into
                   1223: that area.
                   1224: 
                   1225: B<Note>: Netscape 4 only reserves enough space for the changable area
                   1226: to contain room for the original contents. You need to "make space"
                   1227: for whatever changes you wish to make, and be B<sure> to check your
                   1228: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
                   1229: it's adequate for updating a one-line status display, but little more.
                   1230: This script will set the space to 100% width, so you only need to
                   1231: worry about height in Netscape 4.
                   1232: 
                   1233: Modern browsers are much less limiting, and if you can commit to the
                   1234: user not using Netscape 4, this feature may be used freely with
                   1235: pretty much any HTML.
                   1236: 
                   1237: =cut
                   1238: 
                   1239: sub change_content_javascript {
                   1240:     # If we're on Netscape 4, we need to use Layer-based code
1.258     albertel 1241:     if ($env{'browser.type'} eq 'netscape' &&
                   1242: 	$env{'browser.version'} =~ /^4\./) {
1.256     matthew  1243: 	return (<<NETSCAPE4);
                   1244: 	function change(name, content) {
                   1245: 	    doc = document.layers[name+"___escape"].layers[0].document;
                   1246: 	    doc.open();
                   1247: 	    doc.write(content);
                   1248: 	    doc.close();
                   1249: 	}
                   1250: NETSCAPE4
                   1251:     } else {
                   1252: 	# Otherwise, we need to use semi-standards-compliant code
                   1253: 	# (technically, "innerHTML" isn't standard but the equivalent
                   1254: 	# is really scary, and every useful browser supports it
                   1255: 	return (<<DOMBASED);
                   1256: 	function change(name, content) {
                   1257: 	    element = document.getElementById(name);
                   1258: 	    element.innerHTML = content;
                   1259: 	}
                   1260: DOMBASED
                   1261:     }
                   1262: }
                   1263: 
                   1264: =pod
                   1265: 
1.648     raeburn  1266: =item * &changable_area($name,$origContent):
1.256     matthew  1267: 
                   1268: This provides a "changable area" that can be modified on the fly via
                   1269: the Javascript code provided in C<change_content_javascript>. $name is
                   1270: the name you will use to reference the area later; do not repeat the
                   1271: same name on a given HTML page more then once. $origContent is what
                   1272: the area will originally contain, which can be left blank.
                   1273: 
                   1274: =cut
                   1275: 
                   1276: sub changable_area {
                   1277:     my ($name, $origContent) = @_;
                   1278: 
1.258     albertel 1279:     if ($env{'browser.type'} eq 'netscape' &&
                   1280: 	$env{'browser.version'} =~ /^4\./) {
1.256     matthew  1281: 	# If this is netscape 4, we need to use the Layer tag
                   1282: 	return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
                   1283:     } else {
                   1284: 	return "<span id='$name'>$origContent</span>";
                   1285:     }
                   1286: }
                   1287: 
                   1288: =pod
                   1289: 
1.648     raeburn  1290: =item * &viewport_geometry_js 
1.590     raeburn  1291: 
                   1292: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
                   1293: 
                   1294: =cut
                   1295: 
                   1296: 
                   1297: sub viewport_geometry_js { 
                   1298:     return <<"GEOMETRY";
                   1299: var Geometry = {};
                   1300: function init_geometry() {
                   1301:     if (Geometry.init) { return };
                   1302:     Geometry.init=1;
                   1303:     if (window.innerHeight) {
                   1304:         Geometry.getViewportHeight   = function() { return window.innerHeight; };
                   1305:         Geometry.getViewportWidth   = function() { return window.innerWidth; };
                   1306:         Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
                   1307:         Geometry.getVerticalScroll   = function() { return window.pageYOffset; };
                   1308:     }
                   1309:     else if (document.documentElement && document.documentElement.clientHeight) {
                   1310:         Geometry.getViewportHeight =
                   1311:             function() { return document.documentElement.clientHeight; };
                   1312:         Geometry.getViewportWidth =
                   1313:             function() { return document.documentElement.clientWidth; };
                   1314: 
                   1315:         Geometry.getHorizontalScroll =
                   1316:             function() { return document.documentElement.scrollLeft; };
                   1317:         Geometry.getVerticalScroll =
                   1318:             function() { return document.documentElement.scrollTop; };
                   1319:     }
                   1320:     else if (document.body.clientHeight) {
                   1321:         Geometry.getViewportHeight =
                   1322:             function() { return document.body.clientHeight; };
                   1323:         Geometry.getViewportWidth =
                   1324:             function() { return document.body.clientWidth; };
                   1325:         Geometry.getHorizontalScroll =
                   1326:             function() { return document.body.scrollLeft; };
                   1327:         Geometry.getVerticalScroll =
                   1328:             function() { return document.body.scrollTop; };
                   1329:     }
                   1330: }
                   1331: 
                   1332: GEOMETRY
                   1333: }
                   1334: 
                   1335: =pod
                   1336: 
1.648     raeburn  1337: =item * &viewport_size_js()
1.590     raeburn  1338: 
                   1339: 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. 
                   1340: 
                   1341: =cut
                   1342: 
                   1343: sub viewport_size_js {
                   1344:     my $geometry = &viewport_geometry_js();
                   1345:     return <<"DIMS";
                   1346: 
                   1347: $geometry
                   1348: 
                   1349: function getViewportDims(width,height) {
                   1350:     init_geometry();
                   1351:     width.value = Geometry.getViewportWidth();
                   1352:     height.value = Geometry.getViewportHeight();
                   1353:     return;
                   1354: }
                   1355: 
                   1356: DIMS
                   1357: }
                   1358: 
                   1359: =pod
                   1360: 
1.648     raeburn  1361: =item * &resize_textarea_js()
1.565     albertel 1362: 
                   1363: emits the needed javascript to resize a textarea to be as big as possible
                   1364: 
                   1365: creates a function resize_textrea that takes two IDs first should be
                   1366: the id of the element to resize, second should be the id of a div that
                   1367: surrounds everything that comes after the textarea, this routine needs
                   1368: to be attached to the <body> for the onload and onresize events.
                   1369: 
1.648     raeburn  1370: =back
1.565     albertel 1371: 
                   1372: =cut
                   1373: 
                   1374: sub resize_textarea_js {
1.590     raeburn  1375:     my $geometry = &viewport_geometry_js();
1.565     albertel 1376:     return <<"RESIZE";
                   1377:     <script type="text/javascript">
1.590     raeburn  1378: $geometry
1.565     albertel 1379: 
1.588     albertel 1380: function getX(element) {
                   1381:     var x = 0;
                   1382:     while (element) {
                   1383: 	x += element.offsetLeft;
                   1384: 	element = element.offsetParent;
                   1385:     }
                   1386:     return x;
                   1387: }
                   1388: function getY(element) {
                   1389:     var y = 0;
                   1390:     while (element) {
                   1391: 	y += element.offsetTop;
                   1392: 	element = element.offsetParent;
                   1393:     }
                   1394:     return y;
                   1395: }
                   1396: 
                   1397: 
1.565     albertel 1398: function resize_textarea(textarea_id,bottom_id) {
                   1399:     init_geometry();
                   1400:     var textarea        = document.getElementById(textarea_id);
                   1401:     //alert(textarea);
                   1402: 
1.588     albertel 1403:     var textarea_top    = getY(textarea);
1.565     albertel 1404:     var textarea_height = textarea.offsetHeight;
                   1405:     var bottom          = document.getElementById(bottom_id);
1.588     albertel 1406:     var bottom_top      = getY(bottom);
1.565     albertel 1407:     var bottom_height   = bottom.offsetHeight;
                   1408:     var window_height   = Geometry.getViewportHeight();
1.588     albertel 1409:     var fudge           = 23;
1.565     albertel 1410:     var new_height      = window_height-fudge-textarea_top-bottom_height;
                   1411:     if (new_height < 300) {
                   1412: 	new_height = 300;
                   1413:     }
                   1414:     textarea.style.height=new_height+'px';
                   1415: }
                   1416: </script>
                   1417: RESIZE
                   1418: 
                   1419: }
                   1420: 
                   1421: =pod
                   1422: 
1.256     matthew  1423: =head1 Excel and CSV file utility routines
                   1424: 
                   1425: =over 4
                   1426: 
                   1427: =cut
                   1428: 
                   1429: ###############################################################
                   1430: ###############################################################
                   1431: 
                   1432: =pod
                   1433: 
1.648     raeburn  1434: =item * &csv_translate($text) 
1.37      matthew  1435: 
1.185     www      1436: Translate $text to allow it to be output as a 'comma separated values' 
1.37      matthew  1437: format.
                   1438: 
                   1439: =cut
                   1440: 
1.180     matthew  1441: ###############################################################
                   1442: ###############################################################
1.37      matthew  1443: sub csv_translate {
                   1444:     my $text = shift;
                   1445:     $text =~ s/\"/\"\"/g;
1.209     albertel 1446:     $text =~ s/\n/ /g;
1.37      matthew  1447:     return $text;
                   1448: }
1.180     matthew  1449: 
                   1450: ###############################################################
                   1451: ###############################################################
                   1452: 
                   1453: =pod
                   1454: 
1.648     raeburn  1455: =item * &define_excel_formats()
1.180     matthew  1456: 
                   1457: Define some commonly used Excel cell formats.
                   1458: 
                   1459: Currently supported formats:
                   1460: 
                   1461: =over 4
                   1462: 
                   1463: =item header
                   1464: 
                   1465: =item bold
                   1466: 
                   1467: =item h1
                   1468: 
                   1469: =item h2
                   1470: 
                   1471: =item h3
                   1472: 
1.256     matthew  1473: =item h4
                   1474: 
                   1475: =item i
                   1476: 
1.180     matthew  1477: =item date
                   1478: 
                   1479: =back
                   1480: 
                   1481: Inputs: $workbook
                   1482: 
                   1483: Returns: $format, a hash reference.
                   1484: 
                   1485: =cut
                   1486: 
                   1487: ###############################################################
                   1488: ###############################################################
                   1489: sub define_excel_formats {
                   1490:     my ($workbook) = @_;
                   1491:     my $format;
                   1492:     $format->{'header'} = $workbook->add_format(bold      => 1, 
                   1493:                                                 bottom    => 1,
                   1494:                                                 align     => 'center');
                   1495:     $format->{'bold'} = $workbook->add_format(bold=>1);
                   1496:     $format->{'h1'}   = $workbook->add_format(bold=>1, size=>18);
                   1497:     $format->{'h2'}   = $workbook->add_format(bold=>1, size=>16);
                   1498:     $format->{'h3'}   = $workbook->add_format(bold=>1, size=>14);
1.255     matthew  1499:     $format->{'h4'}   = $workbook->add_format(bold=>1, size=>12);
1.246     matthew  1500:     $format->{'i'}    = $workbook->add_format(italic=>1);
1.180     matthew  1501:     $format->{'date'} = $workbook->add_format(num_format=>
1.207     matthew  1502:                                             'mm/dd/yyyy hh:mm:ss');
1.180     matthew  1503:     return $format;
                   1504: }
                   1505: 
                   1506: ###############################################################
                   1507: ###############################################################
1.113     bowersj2 1508: 
                   1509: =pod
                   1510: 
1.648     raeburn  1511: =item * &create_workbook()
1.255     matthew  1512: 
                   1513: Create an Excel worksheet.  If it fails, output message on the
                   1514: request object and return undefs.
                   1515: 
                   1516: Inputs: Apache request object
                   1517: 
                   1518: Returns (undef) on failure, 
                   1519:     Excel worksheet object, scalar with filename, and formats 
                   1520:     from &Apache::loncommon::define_excel_formats on success
                   1521: 
                   1522: =cut
                   1523: 
                   1524: ###############################################################
                   1525: ###############################################################
                   1526: sub create_workbook {
                   1527:     my ($r) = @_;
                   1528:         #
                   1529:     # Create the excel spreadsheet
                   1530:     my $filename = '/prtspool/'.
1.258     albertel 1531:         $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255     matthew  1532:         time.'_'.rand(1000000000).'.xls';
                   1533:     my $workbook  = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
                   1534:     if (! defined($workbook)) {
                   1535:         $r->log_error("Error creating excel spreadsheet $filename: $!");
                   1536:         $r->print('<p>'.&mt("Unable to create new Excel file.  ".
                   1537:                             "This error has been logged.  ".
                   1538:                             "Please alert your LON-CAPA administrator").
                   1539:                   '</p>');
                   1540:         return (undef);
                   1541:     }
                   1542:     #
                   1543:     $workbook->set_tempdir('/home/httpd/perl/tmp');
                   1544:     #
                   1545:     my $format = &Apache::loncommon::define_excel_formats($workbook);
                   1546:     return ($workbook,$filename,$format);
                   1547: }
                   1548: 
                   1549: ###############################################################
                   1550: ###############################################################
                   1551: 
                   1552: =pod
                   1553: 
1.648     raeburn  1554: =item * &create_text_file()
1.113     bowersj2 1555: 
1.542     raeburn  1556: Create a file to write to and eventually make available to the user.
1.256     matthew  1557: If file creation fails, outputs an error message on the request object and 
                   1558: return undefs.
1.113     bowersj2 1559: 
1.256     matthew  1560: Inputs: Apache request object, and file suffix
1.113     bowersj2 1561: 
1.256     matthew  1562: Returns (undef) on failure, 
                   1563:     Filehandle and filename on success.
1.113     bowersj2 1564: 
                   1565: =cut
                   1566: 
1.256     matthew  1567: ###############################################################
                   1568: ###############################################################
                   1569: sub create_text_file {
                   1570:     my ($r,$suffix) = @_;
                   1571:     if (! defined($suffix)) { $suffix = 'txt'; };
                   1572:     my $fh;
                   1573:     my $filename = '/prtspool/'.
1.258     albertel 1574:         $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256     matthew  1575:         time.'_'.rand(1000000000).'.'.$suffix;
                   1576:     $fh = Apache::File->new('>/home/httpd'.$filename);
                   1577:     if (! defined($fh)) {
                   1578:         $r->log_error("Couldn't open $filename for output $!");
1.683     bisitz   1579:         $r->print(&mt('Problems occurred in creating the output file. '
                   1580:                      .'This error has been logged. '
                   1581:                      .'Please alert your LON-CAPA administrator.'));
1.113     bowersj2 1582:     }
1.256     matthew  1583:     return ($fh,$filename)
1.113     bowersj2 1584: }
                   1585: 
                   1586: 
1.256     matthew  1587: =pod 
1.113     bowersj2 1588: 
                   1589: =back
                   1590: 
                   1591: =cut
1.37      matthew  1592: 
                   1593: ###############################################################
1.33      matthew  1594: ##        Home server <option> list generating code          ##
                   1595: ###############################################################
1.35      matthew  1596: 
1.169     www      1597: # ------------------------------------------
                   1598: 
                   1599: sub domain_select {
                   1600:     my ($name,$value,$multiple)=@_;
                   1601:     my %domains=map { 
1.514     albertel 1602: 	$_ => $_.' '. &Apache::lonnet::domain($_,'description') 
1.512     albertel 1603:     } &Apache::lonnet::all_domains();
1.169     www      1604:     if ($multiple) {
                   1605: 	$domains{''}=&mt('Any domain');
1.550     albertel 1606: 	$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287     albertel 1607: 	return &multiple_select_form($name,$value,4,\%domains);
1.169     www      1608:     } else {
1.550     albertel 1609: 	$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.169     www      1610: 	return &select_form($name,$value,%domains);
                   1611:     }
                   1612: }
                   1613: 
1.282     albertel 1614: #-------------------------------------------
                   1615: 
                   1616: =pod
                   1617: 
1.519     raeburn  1618: =head1 Routines for form select boxes
                   1619: 
                   1620: =over 4
                   1621: 
1.648     raeburn  1622: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282     albertel 1623: 
                   1624: Returns a string containing a <select> element int multiple mode
                   1625: 
                   1626: 
                   1627: Args:
                   1628:   $name - name of the <select> element
1.506     raeburn  1629:   $value - scalar or array ref of values that should already be selected
1.282     albertel 1630:   $size - number of rows long the select element is
1.283     albertel 1631:   $hash - the elements should be 'option' => 'shown text'
1.282     albertel 1632:           (shown text should already have been &mt())
1.506     raeburn  1633:   $order - (optional) array ref of the order to show the elements in
1.283     albertel 1634: 
1.282     albertel 1635: =cut
                   1636: 
                   1637: #-------------------------------------------
1.169     www      1638: sub multiple_select_form {
1.284     albertel 1639:     my ($name,$value,$size,$hash,$order)=@_;
1.169     www      1640:     my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
                   1641:     my $output='';
1.191     matthew  1642:     if (! defined($size)) {
                   1643:         $size = 4;
1.283     albertel 1644:         if (scalar(keys(%$hash))<4) {
                   1645:             $size = scalar(keys(%$hash));
1.191     matthew  1646:         }
                   1647:     }
1.734     bisitz   1648:     $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501     banghart 1649:     my @order;
1.506     raeburn  1650:     if (ref($order) eq 'ARRAY')  {
                   1651:         @order = @{$order};
                   1652:     } else {
                   1653:         @order = sort(keys(%$hash));
1.501     banghart 1654:     }
                   1655:     if (exists($$hash{'select_form_order'})) {
                   1656:         @order = @{$$hash{'select_form_order'}};
                   1657:     }
                   1658:         
1.284     albertel 1659:     foreach my $key (@order) {
1.356     albertel 1660:         $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284     albertel 1661:         $output.='selected="selected" ' if ($selected{$key});
                   1662:         $output.='>'.$hash->{$key}."</option>\n";
1.169     www      1663:     }
                   1664:     $output.="</select>\n";
                   1665:     return $output;
                   1666: }
                   1667: 
1.88      www      1668: #-------------------------------------------
                   1669: 
                   1670: =pod
                   1671: 
1.648     raeburn  1672: =item * &select_form($defdom,$name,%hash)
1.88      www      1673: 
                   1674: Returns a string containing a <select name='$name' size='1'> form to 
                   1675: allow a user to select options from a hash option_name => displayed text.  
                   1676: See lonrights.pm for an example invocation and use.
                   1677: 
                   1678: =cut
                   1679: 
                   1680: #-------------------------------------------
                   1681: sub select_form {
                   1682:     my ($def,$name,%hash) = @_;
                   1683:     my $selectform = "<select name=\"$name\" size=\"1\">\n";
1.128     albertel 1684:     my @keys;
                   1685:     if (exists($hash{'select_form_order'})) {
                   1686: 	@keys=@{$hash{'select_form_order'}};
                   1687:     } else {
                   1688: 	@keys=sort(keys(%hash));
                   1689:     }
1.356     albertel 1690:     foreach my $key (@keys) {
                   1691:         $selectform.=
                   1692: 	    '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
                   1693:             ($key eq $def ? 'selected="selected" ' : '').
                   1694:                 ">".&mt($hash{$key})."</option>\n";
1.88      www      1695:     }
                   1696:     $selectform.="</select>";
                   1697:     return $selectform;
                   1698: }
                   1699: 
1.475     www      1700: # For display filters
                   1701: 
                   1702: sub display_filter {
                   1703:     if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477     www      1704:     if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.714     bisitz   1705:     return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1.475     www      1706: 			       &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
                   1707: 							   (&mt('all'),10,20,50,100,1000,10000))).
1.714     bisitz   1708: 	   '</label></span> <span class="LC_nobreak">'.
1.475     www      1709:            &mt('Filter [_1]',
1.477     www      1710: 	   &select_form($env{'form.displayfilter'},
                   1711: 			'displayfilter',
                   1712: 			('currentfolder' => 'Current folder/page',
                   1713: 			 'containing' => 'Containing phrase',
                   1714: 			 'none' => 'None'))).
1.714     bisitz   1715: 			 '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1.475     www      1716: }
                   1717: 
1.167     www      1718: sub gradeleveldescription {
                   1719:     my $gradelevel=shift;
                   1720:     my %gradelevels=(0 => 'Not specified',
                   1721: 		     1 => 'Grade 1',
                   1722: 		     2 => 'Grade 2',
                   1723: 		     3 => 'Grade 3',
                   1724: 		     4 => 'Grade 4',
                   1725: 		     5 => 'Grade 5',
                   1726: 		     6 => 'Grade 6',
                   1727: 		     7 => 'Grade 7',
                   1728: 		     8 => 'Grade 8',
                   1729: 		     9 => 'Grade 9',
                   1730: 		     10 => 'Grade 10',
                   1731: 		     11 => 'Grade 11',
                   1732: 		     12 => 'Grade 12',
                   1733: 		     13 => 'Grade 13',
                   1734: 		     14 => '100 Level',
                   1735: 		     15 => '200 Level',
                   1736: 		     16 => '300 Level',
                   1737: 		     17 => '400 Level',
                   1738: 		     18 => 'Graduate Level');
                   1739:     return &mt($gradelevels{$gradelevel});
                   1740: }
                   1741: 
1.163     www      1742: sub select_level_form {
                   1743:     my ($deflevel,$name)=@_;
                   1744:     unless ($deflevel) { $deflevel=0; }
1.167     www      1745:     my $selectform = "<select name=\"$name\" size=\"1\">\n";
                   1746:     for (my $i=0; $i<=18; $i++) {
                   1747:         $selectform.="<option value=\"$i\" ".
1.253     albertel 1748:             ($i==$deflevel ? 'selected="selected" ' : '').
1.167     www      1749:                 ">".&gradeleveldescription($i)."</option>\n";
                   1750:     }
                   1751:     $selectform.="</select>";
                   1752:     return $selectform;
1.163     www      1753: }
1.167     www      1754: 
1.35      matthew  1755: #-------------------------------------------
                   1756: 
1.45      matthew  1757: =pod
                   1758: 
1.743     raeburn  1759: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$autosubmit)
1.35      matthew  1760: 
                   1761: Returns a string containing a <select name='$name' size='1'> form to 
                   1762: allow a user to select the domain to preform an operation in.  
                   1763: See loncreateuser.pm for an example invocation and use.
                   1764: 
1.90      www      1765: If the $includeempty flag is set, it also includes an empty choice ("no domain
                   1766: selected");
                   1767: 
1.743     raeburn  1768: If the $showdomdesc flag is set, the domain name is followed by the domain description.
                   1769: 
                   1770: If the $autosubmit flag is set, the form containing the domain selector will be auto-submitted by an onchange action.  
1.563     raeburn  1771: 
1.35      matthew  1772: =cut
                   1773: 
                   1774: #-------------------------------------------
1.34      matthew  1775: sub select_dom_form {
1.743     raeburn  1776:     my ($defdom,$name,$includeempty,$showdomdesc,$autosubmit) = @_;
                   1777:     my $onchange;
                   1778:     if ($autosubmit) {
                   1779:         $onchange = ' onchange="this.form.submit()"';
                   1780:     }
1.550     albertel 1781:     my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1.90      www      1782:     if ($includeempty) { @domains=('',@domains); }
1.743     raeburn  1783:     my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356     albertel 1784:     foreach my $dom (@domains) {
                   1785:         $selectdomain.="<option value=\"$dom\" ".
1.563     raeburn  1786:             ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
                   1787:         if ($showdomdesc) {
                   1788:             if ($dom ne '') {
                   1789:                 my $domdesc = &Apache::lonnet::domain($dom,'description');
                   1790:                 if ($domdesc ne '') {
                   1791:                     $selectdomain .= ' ('.$domdesc.')';
                   1792:                 }
                   1793:             } 
                   1794:         }
                   1795:         $selectdomain .= "</option>\n";
1.34      matthew  1796:     }
                   1797:     $selectdomain.="</select>";
                   1798:     return $selectdomain;
                   1799: }
                   1800: 
1.35      matthew  1801: #-------------------------------------------
                   1802: 
1.45      matthew  1803: =pod
                   1804: 
1.648     raeburn  1805: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35      matthew  1806: 
1.586     raeburn  1807: input: 4 arguments (two required, two optional) - 
                   1808:     $domain - domain of new user
                   1809:     $name - name of form element
                   1810:     $default - Value of 'default' causes a default item to be first 
                   1811:                             option, and selected by default. 
                   1812:     $hide - Value of 'hide' causes hiding of the name of the server, 
                   1813:                             if 1 server found, or default, if 0 found.
1.594     raeburn  1814: output: returns 2 items: 
1.586     raeburn  1815: (a) form element which contains either:
                   1816:    (i) <select name="$name">
                   1817:         <option value="$hostid1">$hostid $servers{$hostid}</option>
                   1818:         <option value="$hostid2">$hostid $servers{$hostid}</option>       
                   1819:        </select>
                   1820:        form item if there are multiple library servers in $domain, or
                   1821:    (ii) an <input type="hidden" name="$name" value="$hostid" /> form item 
                   1822:        if there is only one library server in $domain.
                   1823: 
                   1824: (b) number of library servers found.
                   1825: 
                   1826: See loncreateuser.pm for example of use.
1.35      matthew  1827: 
                   1828: =cut
                   1829: 
                   1830: #-------------------------------------------
1.586     raeburn  1831: sub home_server_form_item {
                   1832:     my ($domain,$name,$default,$hide) = @_;
1.513     albertel 1833:     my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586     raeburn  1834:     my $result;
                   1835:     my $numlib = keys(%servers);
                   1836:     if ($numlib > 1) {
                   1837:         $result .= '<select name="'.$name.'" />'."\n";
                   1838:         if ($default) {
                   1839:             $result .= '<option value="default" selected>'.&mt('default').
                   1840:                        '</option>'."\n";
                   1841:         }
                   1842:         foreach my $hostid (sort(keys(%servers))) {
                   1843:             $result.= '<option value="'.$hostid.'">'.
                   1844: 	              $hostid.' '.$servers{$hostid}."</option>\n";
                   1845:         }
                   1846:         $result .= '</select>'."\n";
                   1847:     } elsif ($numlib == 1) {
                   1848:         my $hostid;
                   1849:         foreach my $item (keys(%servers)) {
                   1850:             $hostid = $item;
                   1851:         }
                   1852:         $result .= '<input type="hidden" name="'.$name.'" value="'.
                   1853:                    $hostid.'" />';
                   1854:                    if (!$hide) {
                   1855:                        $result .= $hostid.' '.$servers{$hostid};
                   1856:                    }
                   1857:                    $result .= "\n";
                   1858:     } elsif ($default) {
                   1859:         $result .= '<input type="hidden" name="'.$name.
                   1860:                    '" value="default" />';
                   1861:                    if (!$hide) {
                   1862:                        $result .= &mt('default');
                   1863:                    }
                   1864:                    $result .= "\n";
1.33      matthew  1865:     }
1.586     raeburn  1866:     return ($result,$numlib);
1.33      matthew  1867: }
1.112     bowersj2 1868: 
                   1869: =pod
                   1870: 
1.534     albertel 1871: =back 
                   1872: 
1.112     bowersj2 1873: =cut
1.87      matthew  1874: 
                   1875: ###############################################################
1.112     bowersj2 1876: ##                  Decoding User Agent                      ##
1.87      matthew  1877: ###############################################################
                   1878: 
                   1879: =pod
                   1880: 
1.112     bowersj2 1881: =head1 Decoding the User Agent
                   1882: 
                   1883: =over 4
                   1884: 
                   1885: =item * &decode_user_agent()
1.87      matthew  1886: 
                   1887: Inputs: $r
                   1888: 
                   1889: Outputs:
                   1890: 
                   1891: =over 4
                   1892: 
1.112     bowersj2 1893: =item * $httpbrowser
1.87      matthew  1894: 
1.112     bowersj2 1895: =item * $clientbrowser
1.87      matthew  1896: 
1.112     bowersj2 1897: =item * $clientversion
1.87      matthew  1898: 
1.112     bowersj2 1899: =item * $clientmathml
1.87      matthew  1900: 
1.112     bowersj2 1901: =item * $clientunicode
1.87      matthew  1902: 
1.112     bowersj2 1903: =item * $clientos
1.87      matthew  1904: 
                   1905: =back
                   1906: 
1.157     matthew  1907: =back 
                   1908: 
1.87      matthew  1909: =cut
                   1910: 
                   1911: ###############################################################
                   1912: ###############################################################
                   1913: sub decode_user_agent {
1.247     albertel 1914:     my ($r)=@_;
1.87      matthew  1915:     my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
                   1916:     my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
                   1917:     my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247     albertel 1918:     if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87      matthew  1919:     my $clientbrowser='unknown';
                   1920:     my $clientversion='0';
                   1921:     my $clientmathml='';
                   1922:     my $clientunicode='0';
                   1923:     for (my $i=0;$i<=$#browsertype;$i++) {
                   1924:         my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
                   1925: 	if (($httpbrowser=~/$match/i)  && ($httpbrowser!~/$notmatch/i)) {
                   1926: 	    $clientbrowser=$bname;
                   1927:             $httpbrowser=~/$vreg/i;
                   1928: 	    $clientversion=$1;
                   1929:             $clientmathml=($clientversion>=$minv);
                   1930:             $clientunicode=($clientversion>=$univ);
                   1931: 	}
                   1932:     }
                   1933:     my $clientos='unknown';
                   1934:     if (($httpbrowser=~/linux/i) ||
                   1935:         ($httpbrowser=~/unix/i) ||
                   1936:         ($httpbrowser=~/ux/i) ||
                   1937:         ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
                   1938:     if (($httpbrowser=~/vax/i) ||
                   1939:         ($httpbrowser=~/vms/i)) { $clientos='vms'; }
                   1940:     if ($httpbrowser=~/next/i) { $clientos='next'; }
                   1941:     if (($httpbrowser=~/mac/i) ||
                   1942:         ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
                   1943:     if ($httpbrowser=~/win/i) { $clientos='win'; }
                   1944:     if ($httpbrowser=~/embed/i) { $clientos='pda'; }
                   1945:     return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
                   1946:             $clientunicode,$clientos,);
                   1947: }
                   1948: 
1.32      matthew  1949: ###############################################################
                   1950: ##    Authentication changing form generation subroutines    ##
                   1951: ###############################################################
                   1952: ##
                   1953: ## All of the authform_xxxxxxx subroutines take their inputs in a
                   1954: ## hash, and have reasonable default values.
                   1955: ##
                   1956: ##    formname = the name given in the <form> tag.
1.35      matthew  1957: #-------------------------------------------
                   1958: 
1.45      matthew  1959: =pod
                   1960: 
1.112     bowersj2 1961: =head1 Authentication Routines
                   1962: 
                   1963: =over 4
                   1964: 
1.648     raeburn  1965: =item * &authform_xxxxxx()
1.35      matthew  1966: 
                   1967: The authform_xxxxxx subroutines provide javascript and html forms which 
                   1968: handle some of the conveniences required for authentication forms.  
                   1969: This is not an optimal method, but it works.  
                   1970: 
                   1971: =over 4
                   1972: 
1.112     bowersj2 1973: =item * authform_header
1.35      matthew  1974: 
1.112     bowersj2 1975: =item * authform_authorwarning
1.35      matthew  1976: 
1.112     bowersj2 1977: =item * authform_nochange
1.35      matthew  1978: 
1.112     bowersj2 1979: =item * authform_kerberos
1.35      matthew  1980: 
1.112     bowersj2 1981: =item * authform_internal
1.35      matthew  1982: 
1.112     bowersj2 1983: =item * authform_filesystem
1.35      matthew  1984: 
                   1985: =back
                   1986: 
1.648     raeburn  1987: See loncreateuser.pm for invocation and use examples.
1.157     matthew  1988: 
1.35      matthew  1989: =cut
                   1990: 
                   1991: #-------------------------------------------
1.32      matthew  1992: sub authform_header{  
                   1993:     my %in = (
                   1994:         formname => 'cu',
1.80      albertel 1995:         kerb_def_dom => '',
1.32      matthew  1996:         @_,
                   1997:     );
                   1998:     $in{'formname'} = 'document.' . $in{'formname'};
                   1999:     my $result='';
1.80      albertel 2000: 
                   2001: #---------------------------------------------- Code for upper case translation
                   2002:     my $Javascript_toUpperCase;
                   2003:     unless ($in{kerb_def_dom}) {
                   2004:         $Javascript_toUpperCase =<<"END";
                   2005:         switch (choice) {
                   2006:            case 'krb': currentform.elements[choicearg].value =
                   2007:                currentform.elements[choicearg].value.toUpperCase();
                   2008:                break;
                   2009:            default:
                   2010:         }
                   2011: END
                   2012:     } else {
                   2013:         $Javascript_toUpperCase = "";
                   2014:     }
                   2015: 
1.165     raeburn  2016:     my $radioval = "'nochange'";
1.591     raeburn  2017:     if (defined($in{'curr_authtype'})) {
                   2018:         if ($in{'curr_authtype'} ne '') {
                   2019:             $radioval = "'".$in{'curr_authtype'}."arg'";
                   2020:         }
1.174     matthew  2021:     }
1.165     raeburn  2022:     my $argfield = 'null';
1.591     raeburn  2023:     if (defined($in{'mode'})) {
1.165     raeburn  2024:         if ($in{'mode'} eq 'modifycourse')  {
1.591     raeburn  2025:             if (defined($in{'curr_autharg'})) {
                   2026:                 if ($in{'curr_autharg'} ne '') {
1.165     raeburn  2027:                     $argfield = "'$in{'curr_autharg'}'";
                   2028:                 }
                   2029:             }
                   2030:         }
                   2031:     }
                   2032: 
1.32      matthew  2033:     $result.=<<"END";
                   2034: var current = new Object();
1.165     raeburn  2035: current.radiovalue = $radioval;
                   2036: current.argfield = $argfield;
1.32      matthew  2037: 
                   2038: function changed_radio(choice,currentform) {
                   2039:     var choicearg = choice + 'arg';
                   2040:     // If a radio button in changed, we need to change the argfield
                   2041:     if (current.radiovalue != choice) {
                   2042:         current.radiovalue = choice;
                   2043:         if (current.argfield != null) {
                   2044:             currentform.elements[current.argfield].value = '';
                   2045:         }
                   2046:         if (choice == 'nochange') {
                   2047:             current.argfield = null;
                   2048:         } else {
                   2049:             current.argfield = choicearg;
                   2050:             switch(choice) {
                   2051:                 case 'krb': 
                   2052:                     currentform.elements[current.argfield].value = 
                   2053:                         "$in{'kerb_def_dom'}";
                   2054:                 break;
                   2055:               default:
                   2056:                 break;
                   2057:             }
                   2058:         }
                   2059:     }
                   2060:     return;
                   2061: }
1.22      www      2062: 
1.32      matthew  2063: function changed_text(choice,currentform) {
                   2064:     var choicearg = choice + 'arg';
                   2065:     if (currentform.elements[choicearg].value !='') {
1.80      albertel 2066:         $Javascript_toUpperCase
1.32      matthew  2067:         // clear old field
                   2068:         if ((current.argfield != choicearg) && (current.argfield != null)) {
                   2069:             currentform.elements[current.argfield].value = '';
                   2070:         }
                   2071:         current.argfield = choicearg;
                   2072:     }
                   2073:     set_auth_radio_buttons(choice,currentform);
                   2074:     return;
1.20      www      2075: }
1.32      matthew  2076: 
                   2077: function set_auth_radio_buttons(newvalue,currentform) {
                   2078:     var i=0;
                   2079:     while (i < currentform.login.length) {
                   2080:         if (currentform.login[i].value == newvalue) { break; }
                   2081:         i++;
                   2082:     }
                   2083:     if (i == currentform.login.length) {
                   2084:         return;
                   2085:     }
                   2086:     current.radiovalue = newvalue;
                   2087:     currentform.login[i].checked = true;
                   2088:     return;
                   2089: }
                   2090: END
                   2091:     return $result;
                   2092: }
                   2093: 
                   2094: sub authform_authorwarning{
                   2095:     my $result='';
1.144     matthew  2096:     $result='<i>'.
                   2097:         &mt('As a general rule, only authors or co-authors should be '.
                   2098:             'filesystem authenticated '.
                   2099:             '(which allows access to the server filesystem).')."</i>\n";
1.32      matthew  2100:     return $result;
                   2101: }
                   2102: 
                   2103: sub authform_nochange{  
                   2104:     my %in = (
                   2105:               formname => 'document.cu',
                   2106:               kerb_def_dom => 'MSU.EDU',
                   2107:               @_,
                   2108:           );
1.586     raeburn  2109:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'}); 
                   2110:     my $result;
                   2111:     if (keys(%can_assign) == 0) {
                   2112:         $result = &mt('Under you current role you are not permitted to change login settings for this user');  
                   2113:     } else {
                   2114:         $result = '<label>'.&mt('[_1] Do not change login data',
                   2115:                   '<input type="radio" name="login" value="nochange" '.
                   2116:                   'checked="checked" onclick="'.
1.281     albertel 2117:             "javascript:changed_radio('nochange',$in{'formname'});".'" />').
                   2118: 	    '</label>';
1.586     raeburn  2119:     }
1.32      matthew  2120:     return $result;
                   2121: }
                   2122: 
1.591     raeburn  2123: sub authform_kerberos {
1.32      matthew  2124:     my %in = (
                   2125:               formname => 'document.cu',
                   2126:               kerb_def_dom => 'MSU.EDU',
1.80      albertel 2127:               kerb_def_auth => 'krb4',
1.32      matthew  2128:               @_,
                   2129:               );
1.586     raeburn  2130:     my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
                   2131:         $autharg,$jscall);
                   2132:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.80      albertel 2133:     if ($in{'kerb_def_auth'} eq 'krb5') {
1.772     bisitz   2134:        $check5 = ' checked="checked"';
1.80      albertel 2135:     } else {
1.772     bisitz   2136:        $check4 = ' checked="checked"';
1.80      albertel 2137:     }
1.165     raeburn  2138:     $krbarg = $in{'kerb_def_dom'};
1.591     raeburn  2139:     if (defined($in{'curr_authtype'})) {
                   2140:         if ($in{'curr_authtype'} eq 'krb') {
1.772     bisitz   2141:             $krbcheck = ' checked="checked"';
1.623     raeburn  2142:             if (defined($in{'mode'})) {
                   2143:                 if ($in{'mode'} eq 'modifyuser') {
                   2144:                     $krbcheck = '';
                   2145:                 }
                   2146:             }
1.591     raeburn  2147:             if (defined($in{'curr_kerb_ver'})) {
                   2148:                 if ($in{'curr_krb_ver'} eq '5') {
1.772     bisitz   2149:                     $check5 = ' checked="checked"';
1.591     raeburn  2150:                     $check4 = '';
                   2151:                 } else {
1.772     bisitz   2152:                     $check4 = ' checked="checked"';
1.591     raeburn  2153:                     $check5 = '';
                   2154:                 }
1.586     raeburn  2155:             }
1.591     raeburn  2156:             if (defined($in{'curr_autharg'})) {
1.165     raeburn  2157:                 $krbarg = $in{'curr_autharg'};
                   2158:             }
1.586     raeburn  2159:             if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591     raeburn  2160:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2161:                     $result = 
                   2162:     &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
                   2163:         $in{'curr_autharg'},$krbver);
                   2164:                 } else {
                   2165:                     $result =
                   2166:     &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
                   2167:                 }
                   2168:                 return $result; 
                   2169:             }
                   2170:         }
                   2171:     } else {
                   2172:         if ($authnum == 1) {
1.784     bisitz   2173:             $authtype = '<input type="hidden" name="login" value="krb" />';
1.165     raeburn  2174:         }
                   2175:     }
1.586     raeburn  2176:     if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
                   2177:         return;
1.587     raeburn  2178:     } elsif ($authtype eq '') {
1.591     raeburn  2179:         if (defined($in{'mode'})) {
1.587     raeburn  2180:             if ($in{'mode'} eq 'modifycourse') {
                   2181:                 if ($authnum == 1) {
1.784     bisitz   2182:                     $authtype = '<input type="hidden" name="login" value="krb" />';
1.587     raeburn  2183:                 }
                   2184:             }
                   2185:         }
1.586     raeburn  2186:     }
                   2187:     $jscall = "javascript:changed_radio('krb',$in{'formname'});";
                   2188:     if ($authtype eq '') {
                   2189:         $authtype = '<input type="radio" name="login" value="krb" '.
                   2190:                     'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
                   2191:                     $krbcheck.' />';
                   2192:     }
                   2193:     if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
                   2194:         ($can_assign{'krb4'} && !$can_assign{'krb5'} && 
                   2195:          $in{'curr_authtype'} eq 'krb5') ||
                   2196:         (!$can_assign{'krb4'} && $can_assign{'krb5'} && 
                   2197:          $in{'curr_authtype'} eq 'krb4')) {
                   2198:         $result .= &mt
1.144     matthew  2199:         ('[_1] Kerberos authenticated with domain [_2] '.
1.281     albertel 2200:          '[_3] Version 4 [_4] Version 5 [_5]',
1.586     raeburn  2201:          '<label>'.$authtype,
1.281     albertel 2202:          '</label><input type="text" size="10" name="krbarg" '.
1.165     raeburn  2203:              'value="'.$krbarg.'" '.
1.144     matthew  2204:              'onchange="'.$jscall.'" />',
1.281     albertel 2205:          '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
                   2206:          '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
                   2207: 	 '</label>');
1.586     raeburn  2208:     } elsif ($can_assign{'krb4'}) {
                   2209:         $result .= &mt
                   2210:         ('[_1] Kerberos authenticated with domain [_2] '.
                   2211:          '[_3] Version 4 [_4]',
                   2212:          '<label>'.$authtype,
                   2213:          '</label><input type="text" size="10" name="krbarg" '.
                   2214:              'value="'.$krbarg.'" '.
                   2215:              'onchange="'.$jscall.'" />',
                   2216:          '<label><input type="hidden" name="krbver" value="4" />',
                   2217:          '</label>');
                   2218:     } elsif ($can_assign{'krb5'}) {
                   2219:         $result .= &mt
                   2220:         ('[_1] Kerberos authenticated with domain [_2] '.
                   2221:          '[_3] Version 5 [_4]',
                   2222:          '<label>'.$authtype,
                   2223:          '</label><input type="text" size="10" name="krbarg" '.
                   2224:              'value="'.$krbarg.'" '.
                   2225:              'onchange="'.$jscall.'" />',
                   2226:          '<label><input type="hidden" name="krbver" value="5" />',
                   2227:          '</label>');
                   2228:     }
1.32      matthew  2229:     return $result;
                   2230: }
                   2231: 
                   2232: sub authform_internal{  
1.586     raeburn  2233:     my %in = (
1.32      matthew  2234:                 formname => 'document.cu',
                   2235:                 kerb_def_dom => 'MSU.EDU',
                   2236:                 @_,
                   2237:                 );
1.586     raeburn  2238:     my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
                   2239:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2240:     if (defined($in{'curr_authtype'})) {
                   2241:         if ($in{'curr_authtype'} eq 'int') {
1.586     raeburn  2242:             if ($can_assign{'int'}) {
1.772     bisitz   2243:                 $intcheck = 'checked="checked" ';
1.623     raeburn  2244:                 if (defined($in{'mode'})) {
                   2245:                     if ($in{'mode'} eq 'modifyuser') {
                   2246:                         $intcheck = '';
                   2247:                     }
                   2248:                 }
1.591     raeburn  2249:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2250:                     $intarg = $in{'curr_autharg'};
                   2251:                 }
                   2252:             } else {
                   2253:                 $result = &mt('Currently internally authenticated.');
                   2254:                 return $result;
1.165     raeburn  2255:             }
                   2256:         }
1.586     raeburn  2257:     } else {
                   2258:         if ($authnum == 1) {
1.784     bisitz   2259:             $authtype = '<input type="hidden" name="login" value="int" />';
1.586     raeburn  2260:         }
                   2261:     }
                   2262:     if (!$can_assign{'int'}) {
                   2263:         return;
1.587     raeburn  2264:     } elsif ($authtype eq '') {
1.591     raeburn  2265:         if (defined($in{'mode'})) {
1.587     raeburn  2266:             if ($in{'mode'} eq 'modifycourse') {
                   2267:                 if ($authnum == 1) {
1.784     bisitz   2268:                     $authtype = '<input type="hidden" name="login" value="int" />';
1.587     raeburn  2269:                 }
                   2270:             }
                   2271:         }
1.165     raeburn  2272:     }
1.586     raeburn  2273:     $jscall = "javascript:changed_radio('int',$in{'formname'});";
                   2274:     if ($authtype eq '') {
                   2275:         $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
                   2276:                     ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
                   2277:     }
1.605     bisitz   2278:     $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586     raeburn  2279:                $intarg.'" onchange="'.$jscall.'" />';
                   2280:     $result = &mt
1.144     matthew  2281:         ('[_1] Internally authenticated (with initial password [_2])',
1.586     raeburn  2282:          '<label>'.$authtype,'</label>'.$autharg);
1.620     www      2283:     $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  2284:     return $result;
                   2285: }
                   2286: 
                   2287: sub authform_local{  
                   2288:     my %in = (
                   2289:               formname => 'document.cu',
                   2290:               kerb_def_dom => 'MSU.EDU',
                   2291:               @_,
                   2292:               );
1.586     raeburn  2293:     my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
                   2294:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2295:     if (defined($in{'curr_authtype'})) {
                   2296:         if ($in{'curr_authtype'} eq 'loc') {
1.586     raeburn  2297:             if ($can_assign{'loc'}) {
1.772     bisitz   2298:                 $loccheck = 'checked="checked" ';
1.623     raeburn  2299:                 if (defined($in{'mode'})) {
                   2300:                     if ($in{'mode'} eq 'modifyuser') {
                   2301:                         $loccheck = '';
                   2302:                     }
                   2303:                 }
1.591     raeburn  2304:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2305:                     $locarg = $in{'curr_autharg'};
                   2306:                 }
                   2307:             } else {
                   2308:                 $result = &mt('Currently using local (institutional) authentication.');
                   2309:                 return $result;
1.165     raeburn  2310:             }
                   2311:         }
1.586     raeburn  2312:     } else {
                   2313:         if ($authnum == 1) {
1.784     bisitz   2314:             $authtype = '<input type="hidden" name="login" value="loc" />';
1.586     raeburn  2315:         }
                   2316:     }
                   2317:     if (!$can_assign{'loc'}) {
                   2318:         return;
1.587     raeburn  2319:     } elsif ($authtype eq '') {
1.591     raeburn  2320:         if (defined($in{'mode'})) {
1.587     raeburn  2321:             if ($in{'mode'} eq 'modifycourse') {
                   2322:                 if ($authnum == 1) {
1.784     bisitz   2323:                     $authtype = '<input type="hidden" name="login" value="loc" />';
1.587     raeburn  2324:                 }
                   2325:             }
                   2326:         }
1.165     raeburn  2327:     }
1.586     raeburn  2328:     $jscall = "javascript:changed_radio('loc',$in{'formname'});";
                   2329:     if ($authtype eq '') {
                   2330:         $authtype = '<input type="radio" name="login" value="loc" '.
                   2331:                     $loccheck.' onchange="'.$jscall.'" onclick="'.
                   2332:                     $jscall.'" />';
                   2333:     }
                   2334:     $autharg = '<input type="text" size="10" name="locarg" value="'.
                   2335:                $locarg.'" onchange="'.$jscall.'" />';
                   2336:     $result = &mt('[_1] Local Authentication with argument [_2]',
                   2337:                   '<label>'.$authtype,'</label>'.$autharg);
1.32      matthew  2338:     return $result;
                   2339: }
                   2340: 
                   2341: sub authform_filesystem{  
                   2342:     my %in = (
                   2343:               formname => 'document.cu',
                   2344:               kerb_def_dom => 'MSU.EDU',
                   2345:               @_,
                   2346:               );
1.586     raeburn  2347:     my ($fsyscheck,$result,$authtype,$autharg,$jscall);
                   2348:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2349:     if (defined($in{'curr_authtype'})) {
                   2350:         if ($in{'curr_authtype'} eq 'fsys') {
1.586     raeburn  2351:             if ($can_assign{'fsys'}) {
1.772     bisitz   2352:                 $fsyscheck = 'checked="checked" ';
1.623     raeburn  2353:                 if (defined($in{'mode'})) {
                   2354:                     if ($in{'mode'} eq 'modifyuser') {
                   2355:                         $fsyscheck = '';
                   2356:                     }
                   2357:                 }
1.586     raeburn  2358:             } else {
                   2359:                 $result = &mt('Currently Filesystem Authenticated.');
                   2360:                 return $result;
                   2361:             }           
                   2362:         }
                   2363:     } else {
                   2364:         if ($authnum == 1) {
1.784     bisitz   2365:             $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586     raeburn  2366:         }
                   2367:     }
                   2368:     if (!$can_assign{'fsys'}) {
                   2369:         return;
1.587     raeburn  2370:     } elsif ($authtype eq '') {
1.591     raeburn  2371:         if (defined($in{'mode'})) {
1.587     raeburn  2372:             if ($in{'mode'} eq 'modifycourse') {
                   2373:                 if ($authnum == 1) {
1.784     bisitz   2374:                     $authtype = '<input type="hidden" name="login" value="fsys" />';
1.587     raeburn  2375:                 }
                   2376:             }
                   2377:         }
1.586     raeburn  2378:     }
                   2379:     $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
                   2380:     if ($authtype eq '') {
                   2381:         $authtype = '<input type="radio" name="login" value="fsys" '.
                   2382:                     $fsyscheck.' onchange="'.$jscall.'" onclick="'.
                   2383:                     $jscall.'" />';
                   2384:     }
                   2385:     $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
                   2386:                ' onchange="'.$jscall.'" />';
                   2387:     $result = &mt
1.144     matthew  2388:         ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281     albertel 2389:          '<label><input type="radio" name="login" value="fsys" '.
1.586     raeburn  2390:          $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605     bisitz   2391:          '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144     matthew  2392:                   'onchange="'.$jscall.'" />');
1.32      matthew  2393:     return $result;
                   2394: }
                   2395: 
1.586     raeburn  2396: sub get_assignable_auth {
                   2397:     my ($dom) = @_;
                   2398:     if ($dom eq '') {
                   2399:         $dom = $env{'request.role.domain'};
                   2400:     }
                   2401:     my %can_assign = (
                   2402:                           krb4 => 1,
                   2403:                           krb5 => 1,
                   2404:                           int  => 1,
                   2405:                           loc  => 1,
                   2406:                      );
                   2407:     my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
                   2408:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   2409:         if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
                   2410:             my $authhash = $domconfig{'usercreation'}{'authtypes'};
                   2411:             my $context;
                   2412:             if ($env{'request.role'} =~ /^au/) {
                   2413:                 $context = 'author';
                   2414:             } elsif ($env{'request.role'} =~ /^dc/) {
                   2415:                 $context = 'domain';
                   2416:             } elsif ($env{'request.course.id'}) {
                   2417:                 $context = 'course';
                   2418:             }
                   2419:             if ($context) {
                   2420:                 if (ref($authhash->{$context}) eq 'HASH') {
                   2421:                    %can_assign = %{$authhash->{$context}}; 
                   2422:                 }
                   2423:             }
                   2424:         }
                   2425:     }
                   2426:     my $authnum = 0;
                   2427:     foreach my $key (keys(%can_assign)) {
                   2428:         if ($can_assign{$key}) {
                   2429:             $authnum ++;
                   2430:         }
                   2431:     }
                   2432:     if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
                   2433:         $authnum --;
                   2434:     }
                   2435:     return ($authnum,%can_assign);
                   2436: }
                   2437: 
1.80      albertel 2438: ###############################################################
                   2439: ##    Get Kerberos Defaults for Domain                 ##
                   2440: ###############################################################
                   2441: ##
                   2442: ## Returns default kerberos version and an associated argument
                   2443: ## as listed in file domain.tab. If not listed, provides
                   2444: ## appropriate default domain and kerberos version.
                   2445: ##
                   2446: #-------------------------------------------
                   2447: 
                   2448: =pod
                   2449: 
1.648     raeburn  2450: =item * &get_kerberos_defaults()
1.80      albertel 2451: 
                   2452: get_kerberos_defaults($target_domain) returns the default kerberos
1.641     raeburn  2453: version and domain. If not found, it defaults to version 4 and the 
                   2454: domain of the server.
1.80      albertel 2455: 
1.648     raeburn  2456: =over 4
                   2457: 
1.80      albertel 2458: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
                   2459: 
1.648     raeburn  2460: =back
                   2461: 
                   2462: =back
                   2463: 
1.80      albertel 2464: =cut
                   2465: 
                   2466: #-------------------------------------------
                   2467: sub get_kerberos_defaults {
                   2468:     my $domain=shift;
1.641     raeburn  2469:     my ($krbdef,$krbdefdom);
                   2470:     my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
                   2471:     if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
                   2472:         $krbdef = $domdefaults{'auth_def'};
                   2473:         $krbdefdom = $domdefaults{'auth_arg_def'};
                   2474:     } else {
1.80      albertel 2475:         $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
                   2476:         my $krbdefdom=$1;
                   2477:         $krbdefdom=~tr/a-z/A-Z/;
                   2478:         $krbdef = "krb4";
                   2479:     }
                   2480:     return ($krbdef,$krbdefdom);
                   2481: }
1.112     bowersj2 2482: 
1.32      matthew  2483: 
1.46      matthew  2484: ###############################################################
                   2485: ##                Thesaurus Functions                        ##
                   2486: ###############################################################
1.20      www      2487: 
1.46      matthew  2488: =pod
1.20      www      2489: 
1.112     bowersj2 2490: =head1 Thesaurus Functions
                   2491: 
                   2492: =over 4
                   2493: 
1.648     raeburn  2494: =item * &initialize_keywords()
1.46      matthew  2495: 
                   2496: Initializes the package variable %Keywords if it is empty.  Uses the
                   2497: package variable $thesaurus_db_file.
                   2498: 
                   2499: =cut
                   2500: 
                   2501: ###################################################
                   2502: 
                   2503: sub initialize_keywords {
                   2504:     return 1 if (scalar keys(%Keywords));
                   2505:     # If we are here, %Keywords is empty, so fill it up
                   2506:     #   Make sure the file we need exists...
                   2507:     if (! -e $thesaurus_db_file) {
                   2508:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
                   2509:                                  " failed because it does not exist");
                   2510:         return 0;
                   2511:     }
                   2512:     #   Set up the hash as a database
                   2513:     my %thesaurus_db;
                   2514:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 2515:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  2516:         &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
                   2517:                                  $thesaurus_db_file);
                   2518:         return 0;
                   2519:     } 
                   2520:     #  Get the average number of appearances of a word.
                   2521:     my $avecount = $thesaurus_db{'average.count'};
                   2522:     #  Put keywords (those that appear > average) into %Keywords
                   2523:     while (my ($word,$data)=each (%thesaurus_db)) {
                   2524:         my ($count,undef) = split /:/,$data;
                   2525:         $Keywords{$word}++ if ($count > $avecount);
                   2526:     }
                   2527:     untie %thesaurus_db;
                   2528:     # Remove special values from %Keywords.
1.356     albertel 2529:     foreach my $value ('total.count','average.count') {
                   2530:         delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586     raeburn  2531:   }
1.46      matthew  2532:     return 1;
                   2533: }
                   2534: 
                   2535: ###################################################
                   2536: 
                   2537: =pod
                   2538: 
1.648     raeburn  2539: =item * &keyword($word)
1.46      matthew  2540: 
                   2541: Returns true if $word is a keyword.  A keyword is a word that appears more 
                   2542: than the average number of times in the thesaurus database.  Calls 
                   2543: &initialize_keywords
                   2544: 
                   2545: =cut
                   2546: 
                   2547: ###################################################
1.20      www      2548: 
                   2549: sub keyword {
1.46      matthew  2550:     return if (!&initialize_keywords());
                   2551:     my $word=lc(shift());
                   2552:     $word=~s/\W//g;
                   2553:     return exists($Keywords{$word});
1.20      www      2554: }
1.46      matthew  2555: 
                   2556: ###############################################################
                   2557: 
                   2558: =pod 
1.20      www      2559: 
1.648     raeburn  2560: =item * &get_related_words()
1.46      matthew  2561: 
1.160     matthew  2562: Look up a word in the thesaurus.  Takes a scalar argument and returns
1.46      matthew  2563: an array of words.  If the keyword is not in the thesaurus, an empty array
                   2564: will be returned.  The order of the words returned is determined by the
                   2565: database which holds them.
                   2566: 
                   2567: Uses global $thesaurus_db_file.
                   2568: 
                   2569: =cut
                   2570: 
                   2571: ###############################################################
                   2572: sub get_related_words {
                   2573:     my $keyword = shift;
                   2574:     my %thesaurus_db;
                   2575:     if (! -e $thesaurus_db_file) {
                   2576:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
                   2577:                                  "failed because the file does not exist");
                   2578:         return ();
                   2579:     }
                   2580:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 2581:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  2582:         return ();
                   2583:     } 
                   2584:     my @Words=();
1.429     www      2585:     my $count=0;
1.46      matthew  2586:     if (exists($thesaurus_db{$keyword})) {
1.356     albertel 2587: 	# The first element is the number of times
                   2588: 	# the word appears.  We do not need it now.
1.429     www      2589: 	my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
                   2590: 	my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
                   2591: 	my $threshold=$mostfrequentcount/10;
                   2592:         foreach my $possibleword (@RelatedWords) {
                   2593:             my ($word,$wordcount)=split(/\,/,$possibleword);
                   2594:             if ($wordcount>$threshold) {
                   2595: 		push(@Words,$word);
                   2596:                 $count++;
                   2597:                 if ($count>10) { last; }
                   2598: 	    }
1.20      www      2599:         }
                   2600:     }
1.46      matthew  2601:     untie %thesaurus_db;
                   2602:     return @Words;
1.14      harris41 2603: }
1.46      matthew  2604: 
1.112     bowersj2 2605: =pod
                   2606: 
                   2607: =back
                   2608: 
                   2609: =cut
1.61      www      2610: 
                   2611: # -------------------------------------------------------------- Plaintext name
1.81      albertel 2612: =pod
                   2613: 
1.112     bowersj2 2614: =head1 User Name Functions
                   2615: 
                   2616: =over 4
                   2617: 
1.648     raeburn  2618: =item * &plainname($uname,$udom,$first)
1.81      albertel 2619: 
1.112     bowersj2 2620: Takes a users logon name and returns it as a string in
1.226     albertel 2621: "first middle last generation" form 
                   2622: if $first is set to 'lastname' then it returns it as
                   2623: 'lastname generation, firstname middlename' if their is a lastname
1.81      albertel 2624: 
                   2625: =cut
1.61      www      2626: 
1.295     www      2627: 
1.81      albertel 2628: ###############################################################
1.61      www      2629: sub plainname {
1.226     albertel 2630:     my ($uname,$udom,$first)=@_;
1.537     albertel 2631:     return if (!defined($uname) || !defined($udom));
1.295     www      2632:     my %names=&getnames($uname,$udom);
1.226     albertel 2633:     my $name=&Apache::lonnet::format_name($names{'firstname'},
                   2634: 					  $names{'middlename'},
                   2635: 					  $names{'lastname'},
                   2636: 					  $names{'generation'},$first);
                   2637:     $name=~s/^\s+//;
1.62      www      2638:     $name=~s/\s+$//;
                   2639:     $name=~s/\s+/ /g;
1.353     albertel 2640:     if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62      www      2641:     return $name;
1.61      www      2642: }
1.66      www      2643: 
                   2644: # -------------------------------------------------------------------- Nickname
1.81      albertel 2645: =pod
                   2646: 
1.648     raeburn  2647: =item * &nickname($uname,$udom)
1.81      albertel 2648: 
                   2649: Gets a users name and returns it as a string as
                   2650: 
                   2651: "&quot;nickname&quot;"
1.66      www      2652: 
1.81      albertel 2653: if the user has a nickname or
                   2654: 
                   2655: "first middle last generation"
                   2656: 
                   2657: if the user does not
                   2658: 
                   2659: =cut
1.66      www      2660: 
                   2661: sub nickname {
                   2662:     my ($uname,$udom)=@_;
1.537     albertel 2663:     return if (!defined($uname) || !defined($udom));
1.295     www      2664:     my %names=&getnames($uname,$udom);
1.68      albertel 2665:     my $name=$names{'nickname'};
1.66      www      2666:     if ($name) {
                   2667:        $name='&quot;'.$name.'&quot;'; 
                   2668:     } else {
                   2669:        $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
                   2670: 	     $names{'lastname'}.' '.$names{'generation'};
                   2671:        $name=~s/\s+$//;
                   2672:        $name=~s/\s+/ /g;
                   2673:     }
                   2674:     return $name;
                   2675: }
                   2676: 
1.295     www      2677: sub getnames {
                   2678:     my ($uname,$udom)=@_;
1.537     albertel 2679:     return if (!defined($uname) || !defined($udom));
1.433     albertel 2680:     if ($udom eq 'public' && $uname eq 'public') {
                   2681: 	return ('lastname' => &mt('Public'));
                   2682:     }
1.295     www      2683:     my $id=$uname.':'.$udom;
                   2684:     my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
                   2685:     if ($cached) {
                   2686: 	return %{$names};
                   2687:     } else {
                   2688: 	my %loadnames=&Apache::lonnet::get('environment',
                   2689:                     ['firstname','middlename','lastname','generation','nickname'],
                   2690: 					 $udom,$uname);
                   2691: 	&Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
                   2692: 	return %loadnames;
                   2693:     }
                   2694: }
1.61      www      2695: 
1.542     raeburn  2696: # -------------------------------------------------------------------- getemails
1.648     raeburn  2697: 
1.542     raeburn  2698: =pod
                   2699: 
1.648     raeburn  2700: =item * &getemails($uname,$udom)
1.542     raeburn  2701: 
                   2702: Gets a user's email information and returns it as a hash with keys:
                   2703: notification, critnotification, permanentemail
                   2704: 
                   2705: For notification and critnotification, values are comma-separated lists 
1.648     raeburn  2706: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542     raeburn  2707:  
1.648     raeburn  2708: 
1.542     raeburn  2709: =cut
                   2710: 
1.648     raeburn  2711: 
1.466     albertel 2712: sub getemails {
                   2713:     my ($uname,$udom)=@_;
                   2714:     if ($udom eq 'public' && $uname eq 'public') {
                   2715: 	return;
                   2716:     }
1.467     www      2717:     if (!$udom) { $udom=$env{'user.domain'}; }
                   2718:     if (!$uname) { $uname=$env{'user.name'}; }
1.466     albertel 2719:     my $id=$uname.':'.$udom;
                   2720:     my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
                   2721:     if ($cached) {
                   2722: 	return %{$names};
                   2723:     } else {
                   2724: 	my %loadnames=&Apache::lonnet::get('environment',
                   2725:                     			   ['notification','critnotification',
                   2726: 					    'permanentemail'],
                   2727: 					   $udom,$uname);
                   2728: 	&Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
                   2729: 	return %loadnames;
                   2730:     }
                   2731: }
                   2732: 
1.551     albertel 2733: sub flush_email_cache {
                   2734:     my ($uname,$udom)=@_;
                   2735:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2736:     if (!$uname) { $uname=$env{'user.name'};   }
                   2737:     return if ($udom eq 'public' && $uname eq 'public');
                   2738:     my $id=$uname.':'.$udom;
                   2739:     &Apache::lonnet::devalidate_cache_new('emailscache',$id);
                   2740: }
                   2741: 
1.728     raeburn  2742: # -------------------------------------------------------------------- getlangs
                   2743: 
                   2744: =pod
                   2745: 
                   2746: =item * &getlangs($uname,$udom)
                   2747: 
                   2748: Gets a user's language preference and returns it as a hash with key:
                   2749: language.
                   2750: 
                   2751: =cut
                   2752: 
                   2753: 
                   2754: sub getlangs {
                   2755:     my ($uname,$udom) = @_;
                   2756:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2757:     if (!$uname) { $uname=$env{'user.name'};   }
                   2758:     my $id=$uname.':'.$udom;
                   2759:     my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
                   2760:     if ($cached) {
                   2761:         return %{$langs};
                   2762:     } else {
                   2763:         my %loadlangs=&Apache::lonnet::get('environment',['languages'],
                   2764:                                            $udom,$uname);
                   2765:         &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
                   2766:         return %loadlangs;
                   2767:     }
                   2768: }
                   2769: 
                   2770: sub flush_langs_cache {
                   2771:     my ($uname,$udom)=@_;
                   2772:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2773:     if (!$uname) { $uname=$env{'user.name'};   }
                   2774:     return if ($udom eq 'public' && $uname eq 'public');
                   2775:     my $id=$uname.':'.$udom;
                   2776:     &Apache::lonnet::devalidate_cache_new('userlangs',$id);
                   2777: }
                   2778: 
1.61      www      2779: # ------------------------------------------------------------------ Screenname
1.81      albertel 2780: 
                   2781: =pod
                   2782: 
1.648     raeburn  2783: =item * &screenname($uname,$udom)
1.81      albertel 2784: 
                   2785: Gets a users screenname and returns it as a string
                   2786: 
                   2787: =cut
1.61      www      2788: 
                   2789: sub screenname {
                   2790:     my ($uname,$udom)=@_;
1.258     albertel 2791:     if ($uname eq $env{'user.name'} &&
                   2792: 	$udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212     albertel 2793:     my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68      albertel 2794:     return $names{'screenname'};
1.62      www      2795: }
                   2796: 
1.212     albertel 2797: 
1.62      www      2798: # ------------------------------------------------------------- Message Wrapper
                   2799: 
                   2800: sub messagewrapper {
1.369     www      2801:     my ($link,$username,$domain,$subject,$text)=@_;
1.62      www      2802:     return 
1.441     albertel 2803:         '<a href="/adm/email?compose=individual&amp;'.
                   2804:         'recname='.$username.'&amp;recdom='.$domain.
                   2805: 	'&amp;subject='.&escape($subject).'&amp;text='.&escape($text).'" '.
1.200     matthew  2806:         'title="'.&mt('Send message').'">'.$link.'</a>';
1.74      www      2807: }
                   2808: # --------------------------------------------------------------- Notes Wrapper
                   2809: 
                   2810: sub noteswrapper {
                   2811:     my ($link,$un,$do)=@_;
                   2812:     return 
                   2813: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62      www      2814: }
                   2815: # ------------------------------------------------------------- Aboutme Wrapper
                   2816: 
                   2817: sub aboutmewrapper {
1.166     www      2818:     my ($link,$username,$domain,$target)=@_;
1.447     raeburn  2819:     if (!defined($username)  && !defined($domain)) {
                   2820:         return;
                   2821:     }
1.205     www      2822:     return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.756     weissno  2823: 	($target?' target="$target"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62      www      2824: }
                   2825: 
                   2826: # ------------------------------------------------------------ Syllabus Wrapper
                   2827: 
                   2828: 
                   2829: sub syllabuswrapper {
1.707     bisitz   2830:     my ($linktext,$coursedir,$domain)=@_;
1.208     matthew  2831:     return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61      www      2832: }
1.14      harris41 2833: 
1.208     matthew  2834: sub track_student_link {
1.268     albertel 2835:     my ($linktext,$sname,$sdom,$target,$start) = @_;
                   2836:     my $link ="/adm/trackstudent?";
1.208     matthew  2837:     my $title = 'View recent activity';
                   2838:     if (defined($sname) && $sname !~ /^\s*$/ &&
                   2839:         defined($sdom)  && $sdom  !~ /^\s*$/) {
1.268     albertel 2840:         $link .= "selected_student=$sname:$sdom";
1.208     matthew  2841:         $title .= ' of this student';
1.268     albertel 2842:     } 
1.208     matthew  2843:     if (defined($target) && $target !~ /^\s*$/) {
                   2844:         $target = qq{target="$target"};
                   2845:     } else {
                   2846:         $target = '';
                   2847:     }
1.268     albertel 2848:     if ($start) { $link.='&amp;start='.$start; }
1.554     albertel 2849:     $title = &mt($title);
                   2850:     $linktext = &mt($linktext);
1.448     albertel 2851:     return qq{<a href="$link" title="$title" $target>$linktext</a>}.
                   2852: 	&help_open_topic('View_recent_activity');
1.208     matthew  2853: }
                   2854: 
1.781     raeburn  2855: sub slot_reservations_link {
                   2856:     my ($linktext,$sname,$sdom,$target) = @_;
                   2857:     my $link ="/adm/slotrequest?command=showresv&amp;origin=aboutme";
                   2858:     my $title = 'View slot reservation history';
                   2859:     if (defined($sname) && $sname !~ /^\s*$/ &&
                   2860:         defined($sdom)  && $sdom  !~ /^\s*$/) {
                   2861:         $link .= "&amp;uname=$sname&amp;udom=$sdom";
                   2862:         $title .= ' of this student';
                   2863:     }
                   2864:     if (defined($target) && $target !~ /^\s*$/) {
                   2865:         $target = qq{target="$target"};
                   2866:     } else {
                   2867:         $target = '';
                   2868:     }
                   2869:     $title = &mt($title);
                   2870:     $linktext = &mt($linktext);
                   2871:     return qq{<a href="$link" title="$title" $target>$linktext</a>};
                   2872: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
                   2873: 
                   2874: }
                   2875: 
1.508     www      2876: # ===================================================== Display a student photo
                   2877: 
                   2878: 
1.509     albertel 2879: sub student_image_tag {
1.508     www      2880:     my ($domain,$user)=@_;
                   2881:     my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
                   2882:     if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
                   2883: 	return '<img src="'.$imgsrc.'" align="right" />';
                   2884:     } else {
                   2885: 	return '';
                   2886:     }
                   2887: }
                   2888: 
1.112     bowersj2 2889: =pod
                   2890: 
                   2891: =back
                   2892: 
                   2893: =head1 Access .tab File Data
                   2894: 
                   2895: =over 4
                   2896: 
1.648     raeburn  2897: =item * &languageids() 
1.112     bowersj2 2898: 
                   2899: returns list of all language ids
                   2900: 
                   2901: =cut
                   2902: 
1.14      harris41 2903: sub languageids {
1.16      harris41 2904:     return sort(keys(%language));
1.14      harris41 2905: }
                   2906: 
1.112     bowersj2 2907: =pod
                   2908: 
1.648     raeburn  2909: =item * &languagedescription() 
1.112     bowersj2 2910: 
                   2911: returns description of a specified language id
                   2912: 
                   2913: =cut
                   2914: 
1.14      harris41 2915: sub languagedescription {
1.125     www      2916:     my $code=shift;
                   2917:     return  ($supported_language{$code}?'* ':'').
                   2918:             $language{$code}.
1.126     www      2919: 	    ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145     www      2920: }
                   2921: 
                   2922: sub plainlanguagedescription {
                   2923:     my $code=shift;
                   2924:     return $language{$code};
                   2925: }
                   2926: 
                   2927: sub supportedlanguagecode {
                   2928:     my $code=shift;
                   2929:     return $supported_language{$code};
1.97      www      2930: }
                   2931: 
1.112     bowersj2 2932: =pod
                   2933: 
1.648     raeburn  2934: =item * &copyrightids() 
1.112     bowersj2 2935: 
                   2936: returns list of all copyrights
                   2937: 
                   2938: =cut
                   2939: 
                   2940: sub copyrightids {
                   2941:     return sort(keys(%cprtag));
                   2942: }
                   2943: 
                   2944: =pod
                   2945: 
1.648     raeburn  2946: =item * &copyrightdescription() 
1.112     bowersj2 2947: 
                   2948: returns description of a specified copyright id
                   2949: 
                   2950: =cut
                   2951: 
                   2952: sub copyrightdescription {
1.166     www      2953:     return &mt($cprtag{shift(@_)});
1.112     bowersj2 2954: }
1.197     matthew  2955: 
                   2956: =pod
                   2957: 
1.648     raeburn  2958: =item * &source_copyrightids() 
1.192     taceyjo1 2959: 
                   2960: returns list of all source copyrights
                   2961: 
                   2962: =cut
                   2963: 
                   2964: sub source_copyrightids {
                   2965:     return sort(keys(%scprtag));
                   2966: }
                   2967: 
                   2968: =pod
                   2969: 
1.648     raeburn  2970: =item * &source_copyrightdescription() 
1.192     taceyjo1 2971: 
                   2972: returns description of a specified source copyright id
                   2973: 
                   2974: =cut
                   2975: 
                   2976: sub source_copyrightdescription {
                   2977:     return &mt($scprtag{shift(@_)});
                   2978: }
1.112     bowersj2 2979: 
                   2980: =pod
                   2981: 
1.648     raeburn  2982: =item * &filecategories() 
1.112     bowersj2 2983: 
                   2984: returns list of all file categories
                   2985: 
                   2986: =cut
                   2987: 
                   2988: sub filecategories {
                   2989:     return sort(keys(%category_extensions));
                   2990: }
                   2991: 
                   2992: =pod
                   2993: 
1.648     raeburn  2994: =item * &filecategorytypes() 
1.112     bowersj2 2995: 
                   2996: returns list of file types belonging to a given file
                   2997: category
                   2998: 
                   2999: =cut
                   3000: 
                   3001: sub filecategorytypes {
1.356     albertel 3002:     my ($cat) = @_;
                   3003:     return @{$category_extensions{lc($cat)}};
1.112     bowersj2 3004: }
                   3005: 
                   3006: =pod
                   3007: 
1.648     raeburn  3008: =item * &fileembstyle() 
1.112     bowersj2 3009: 
                   3010: returns embedding style for a specified file type
                   3011: 
                   3012: =cut
                   3013: 
                   3014: sub fileembstyle {
                   3015:     return $fe{lc(shift(@_))};
1.169     www      3016: }
                   3017: 
1.351     www      3018: sub filemimetype {
                   3019:     return $fm{lc(shift(@_))};
                   3020: }
                   3021: 
1.169     www      3022: 
                   3023: sub filecategoryselect {
                   3024:     my ($name,$value)=@_;
1.189     matthew  3025:     return &select_form($value,$name,
1.169     www      3026: 			'' => &mt('Any category'),
                   3027: 			map { $_,$_ } sort(keys(%category_extensions)));
1.112     bowersj2 3028: }
                   3029: 
                   3030: =pod
                   3031: 
1.648     raeburn  3032: =item * &filedescription() 
1.112     bowersj2 3033: 
                   3034: returns description for a specified file type
                   3035: 
                   3036: =cut
                   3037: 
                   3038: sub filedescription {
1.188     matthew  3039:     my $file_description = $fd{lc(shift())};
                   3040:     $file_description =~ s:([\[\]]):~$1:g;
                   3041:     return &mt($file_description);
1.112     bowersj2 3042: }
                   3043: 
                   3044: =pod
                   3045: 
1.648     raeburn  3046: =item * &filedescriptionex() 
1.112     bowersj2 3047: 
                   3048: returns description for a specified file type with
                   3049: extra formatting
                   3050: 
                   3051: =cut
                   3052: 
                   3053: sub filedescriptionex {
                   3054:     my $ex=shift;
1.188     matthew  3055:     my $file_description = $fd{lc($ex)};
                   3056:     $file_description =~ s:([\[\]]):~$1:g;
                   3057:     return '.'.$ex.' '.&mt($file_description);
1.112     bowersj2 3058: }
                   3059: 
                   3060: # End of .tab access
                   3061: =pod
                   3062: 
                   3063: =back
                   3064: 
                   3065: =cut
                   3066: 
                   3067: # ------------------------------------------------------------------ File Types
                   3068: sub fileextensions {
                   3069:     return sort(keys(%fe));
                   3070: }
                   3071: 
1.97      www      3072: # ----------------------------------------------------------- Display Languages
                   3073: # returns a hash with all desired display languages
                   3074: #
                   3075: 
                   3076: sub display_languages {
                   3077:     my %languages=();
1.695     raeburn  3078:     foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356     albertel 3079: 	$languages{$lang}=1;
1.97      www      3080:     }
                   3081:     &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258     albertel 3082:     if ($env{'form.displaylanguage'}) {
1.356     albertel 3083: 	foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
                   3084: 	    $languages{$lang}=1;
1.97      www      3085:         }
                   3086:     }
                   3087:     return %languages;
1.14      harris41 3088: }
                   3089: 
1.582     albertel 3090: sub languages {
                   3091:     my ($possible_langs) = @_;
1.695     raeburn  3092:     my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582     albertel 3093:     if (!ref($possible_langs)) {
                   3094: 	if( wantarray ) {
                   3095: 	    return @preferred_langs;
                   3096: 	} else {
                   3097: 	    return $preferred_langs[0];
                   3098: 	}
                   3099:     }
                   3100:     my %possibilities = map { $_ => 1 } (@$possible_langs);
                   3101:     my @preferred_possibilities;
                   3102:     foreach my $preferred_lang (@preferred_langs) {
                   3103: 	if (exists($possibilities{$preferred_lang})) {
                   3104: 	    push(@preferred_possibilities, $preferred_lang);
                   3105: 	}
                   3106:     }
                   3107:     if( wantarray ) {
                   3108: 	return @preferred_possibilities;
                   3109:     }
                   3110:     return $preferred_possibilities[0];
                   3111: }
                   3112: 
1.742     raeburn  3113: sub user_lang {
                   3114:     my ($touname,$toudom,$fromcid) = @_;
                   3115:     my @userlangs;
                   3116:     if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
                   3117:         @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
                   3118:                     $env{'course.'.$fromcid.'.languages'}));
                   3119:     } else {
                   3120:         my %langhash = &getlangs($touname,$toudom);
                   3121:         if ($langhash{'languages'} ne '') {
                   3122:             @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
                   3123:         } else {
                   3124:             my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
                   3125:             if ($domdefs{'lang_def'} ne '') {
                   3126:                 @userlangs = ($domdefs{'lang_def'});
                   3127:             }
                   3128:         }
                   3129:     }
                   3130:     my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
                   3131:     my $user_lh = Apache::localize->get_handle(@languages);
                   3132:     return $user_lh;
                   3133: }
                   3134: 
                   3135: 
1.112     bowersj2 3136: ###############################################################
                   3137: ##               Student Answer Attempts                     ##
                   3138: ###############################################################
                   3139: 
                   3140: =pod
                   3141: 
                   3142: =head1 Alternate Problem Views
                   3143: 
                   3144: =over 4
                   3145: 
1.648     raeburn  3146: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112     bowersj2 3147:     $getattempt, $regexp, $gradesub)
                   3148: 
                   3149: Return string with previous attempt on problem. Arguments:
                   3150: 
                   3151: =over 4
                   3152: 
                   3153: =item * $symb: Problem, including path
                   3154: 
                   3155: =item * $username: username of the desired student
                   3156: 
                   3157: =item * $domain: domain of the desired student
1.14      harris41 3158: 
1.112     bowersj2 3159: =item * $course: Course ID
1.14      harris41 3160: 
1.112     bowersj2 3161: =item * $getattempt: Leave blank for all attempts, otherwise put
                   3162:     something
1.14      harris41 3163: 
1.112     bowersj2 3164: =item * $regexp: if string matches this regexp, the string will be
                   3165:     sent to $gradesub
1.14      harris41 3166: 
1.112     bowersj2 3167: =item * $gradesub: routine that processes the string if it matches $regexp
1.14      harris41 3168: 
1.112     bowersj2 3169: =back
1.14      harris41 3170: 
1.112     bowersj2 3171: The output string is a table containing all desired attempts, if any.
1.16      harris41 3172: 
1.112     bowersj2 3173: =cut
1.1       albertel 3174: 
                   3175: sub get_previous_attempt {
1.43      ng       3176:   my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1       albertel 3177:   my $prevattempts='';
1.43      ng       3178:   no strict 'refs';
1.1       albertel 3179:   if ($symb) {
1.3       albertel 3180:     my (%returnhash)=
                   3181:       &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1       albertel 3182:     if ($returnhash{'version'}) {
                   3183:       my %lasthash=();
                   3184:       my $version;
                   3185:       for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356     albertel 3186:         foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
                   3187: 	  $lasthash{$key}=$returnhash{$version.':'.$key};
1.19      harris41 3188:         }
1.1       albertel 3189:       }
1.596     albertel 3190:       $prevattempts=&start_data_table().&start_data_table_header_row();
                   3191:       $prevattempts.='<th>'.&mt('History').'</th>';
1.356     albertel 3192:       foreach my $key (sort(keys(%lasthash))) {
                   3193: 	my ($ign,@parts) = split(/\./,$key);
1.41      ng       3194: 	if ($#parts > 0) {
1.31      albertel 3195: 	  my $data=$parts[-1];
                   3196: 	  pop(@parts);
1.596     albertel 3197: 	  $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.'&nbsp;</th>';
1.31      albertel 3198: 	} else {
1.41      ng       3199: 	  if ($#parts == 0) {
                   3200: 	    $prevattempts.='<th>'.$parts[0].'</th>';
                   3201: 	  } else {
                   3202: 	    $prevattempts.='<th>'.$ign.'</th>';
                   3203: 	  }
1.31      albertel 3204: 	}
1.16      harris41 3205:       }
1.596     albertel 3206:       $prevattempts.=&end_data_table_header_row();
1.40      ng       3207:       if ($getattempt eq '') {
                   3208: 	for ($version=1;$version<=$returnhash{'version'};$version++) {
1.596     albertel 3209: 	  $prevattempts.=&start_data_table_row().
                   3210: 	      '<td>'.&mt('Transaction [_1]',$version).'</td>';
1.356     albertel 3211: 	    foreach my $key (sort(keys(%lasthash))) {
1.581     albertel 3212: 		my $value = &format_previous_attempt_value($key,
                   3213: 							   $returnhash{$version.':'.$key});
                   3214: 		$prevattempts.='<td>'.$value.'&nbsp;</td>';   
1.40      ng       3215: 	    }
1.596     albertel 3216: 	  $prevattempts.=&end_data_table_row();
1.40      ng       3217: 	 }
1.1       albertel 3218:       }
1.596     albertel 3219:       $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356     albertel 3220:       foreach my $key (sort(keys(%lasthash))) {
1.581     albertel 3221: 	my $value = &format_previous_attempt_value($key,$lasthash{$key});
1.356     albertel 3222: 	if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
1.40      ng       3223: 	$prevattempts.='<td>'.$value.'&nbsp;</td>';
1.16      harris41 3224:       }
1.596     albertel 3225:       $prevattempts.= &end_data_table_row().&end_data_table();
1.1       albertel 3226:     } else {
1.596     albertel 3227:       $prevattempts=
                   3228: 	  &start_data_table().&start_data_table_row().
                   3229: 	  '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
                   3230: 	  &end_data_table_row().&end_data_table();
1.1       albertel 3231:     }
                   3232:   } else {
1.596     albertel 3233:     $prevattempts=
                   3234: 	  &start_data_table().&start_data_table_row().
                   3235: 	  '<td>'.&mt('No data.').'</td>'.
                   3236: 	  &end_data_table_row().&end_data_table();
1.1       albertel 3237:   }
1.10      albertel 3238: }
                   3239: 
1.581     albertel 3240: sub format_previous_attempt_value {
                   3241:     my ($key,$value) = @_;
                   3242:     if ($key =~ /timestamp/) {
                   3243: 	$value = &Apache::lonlocal::locallocaltime($value);
                   3244:     } elsif (ref($value) eq 'ARRAY') {
                   3245: 	$value = '('.join(', ', @{ $value }).')';
                   3246:     } else {
                   3247: 	$value = &unescape($value);
                   3248:     }
                   3249:     return $value;
                   3250: }
                   3251: 
                   3252: 
1.107     albertel 3253: sub relative_to_absolute {
                   3254:     my ($url,$output)=@_;
                   3255:     my $parser=HTML::TokeParser->new(\$output);
                   3256:     my $token;
                   3257:     my $thisdir=$url;
                   3258:     my @rlinks=();
                   3259:     while ($token=$parser->get_token) {
                   3260: 	if ($token->[0] eq 'S') {
                   3261: 	    if ($token->[1] eq 'a') {
                   3262: 		if ($token->[2]->{'href'}) {
                   3263: 		    $rlinks[$#rlinks+1]=$token->[2]->{'href'};
                   3264: 		}
                   3265: 	    } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
                   3266: 		$rlinks[$#rlinks+1]=$token->[2]->{'src'};
                   3267: 	    } elsif ($token->[1] eq 'base') {
                   3268: 		$thisdir=$token->[2]->{'href'};
                   3269: 	    }
                   3270: 	}
                   3271:     }
                   3272:     $thisdir=~s-/[^/]*$--;
1.356     albertel 3273:     foreach my $link (@rlinks) {
1.726     raeburn  3274: 	unless (($link=~/^https?\:\/\//i) ||
1.356     albertel 3275: 		($link=~/^\//) ||
                   3276: 		($link=~/^javascript:/i) ||
                   3277: 		($link=~/^mailto:/i) ||
                   3278: 		($link=~/^\#/)) {
                   3279: 	    my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
                   3280: 	    $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107     albertel 3281: 	}
                   3282:     }
                   3283: # -------------------------------------------------- Deal with Applet codebases
                   3284:     $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
                   3285:     return $output;
                   3286: }
                   3287: 
1.112     bowersj2 3288: =pod
                   3289: 
1.648     raeburn  3290: =item * &get_student_view()
1.112     bowersj2 3291: 
                   3292: show a snapshot of what student was looking at
                   3293: 
                   3294: =cut
                   3295: 
1.10      albertel 3296: sub get_student_view {
1.186     albertel 3297:   my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114     www      3298:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 3299:   my (%form);
1.10      albertel 3300:   my @elements=('symb','courseid','domain','username');
                   3301:   foreach my $element (@elements) {
1.186     albertel 3302:       $form{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 3303:   }
1.186     albertel 3304:   if (defined($moreenv)) {
                   3305:       %form=(%form,%{$moreenv});
                   3306:   }
1.236     albertel 3307:   if (defined($target)) { $form{'grade_target'} = $target; }
1.107     albertel 3308:   $feedurl=&Apache::lonnet::clutter($feedurl);
1.650     www      3309:   my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11      albertel 3310:   $userview=~s/\<body[^\>]*\>//gi;
                   3311:   $userview=~s/\<\/body\>//gi;
                   3312:   $userview=~s/\<html\>//gi;
                   3313:   $userview=~s/\<\/html\>//gi;
                   3314:   $userview=~s/\<head\>//gi;
                   3315:   $userview=~s/\<\/head\>//gi;
                   3316:   $userview=~s/action\s*\=/would_be_action\=/gi;
1.107     albertel 3317:   $userview=&relative_to_absolute($feedurl,$userview);
1.650     www      3318:   if (wantarray) {
                   3319:      return ($userview,$response);
                   3320:   } else {
                   3321:      return $userview;
                   3322:   }
                   3323: }
                   3324: 
                   3325: sub get_student_view_with_retries {
                   3326:   my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
                   3327: 
                   3328:     my $ok = 0;                 # True if we got a good response.
                   3329:     my $content;
                   3330:     my $response;
                   3331: 
                   3332:     # Try to get the student_view done. within the retries count:
                   3333:     
                   3334:     do {
                   3335:          ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
                   3336:          $ok      = $response->is_success;
                   3337:          if (!$ok) {
                   3338:             &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
                   3339:          }
                   3340:          $retries--;
                   3341:     } while (!$ok && ($retries > 0));
                   3342:     
                   3343:     if (!$ok) {
                   3344:        $content = '';          # On error return an empty content.
                   3345:     }
1.651     www      3346:     if (wantarray) {
                   3347:        return ($content, $response);
                   3348:     } else {
                   3349:        return $content;
                   3350:     }
1.11      albertel 3351: }
                   3352: 
1.112     bowersj2 3353: =pod
                   3354: 
1.648     raeburn  3355: =item * &get_student_answers() 
1.112     bowersj2 3356: 
                   3357: show a snapshot of how student was answering problem
                   3358: 
                   3359: =cut
                   3360: 
1.11      albertel 3361: sub get_student_answers {
1.100     sakharuk 3362:   my ($symb,$username,$domain,$courseid,%form) = @_;
1.114     www      3363:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 3364:   my (%moreenv);
1.11      albertel 3365:   my @elements=('symb','courseid','domain','username');
                   3366:   foreach my $element (@elements) {
1.186     albertel 3367:     $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 3368:   }
1.186     albertel 3369:   $moreenv{'grade_target'}='answer';
                   3370:   %moreenv=(%form,%moreenv);
1.497     raeburn  3371:   $feedurl = &Apache::lonnet::clutter($feedurl);
                   3372:   my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10      albertel 3373:   return $userview;
1.1       albertel 3374: }
1.116     albertel 3375: 
                   3376: =pod
                   3377: 
                   3378: =item * &submlink()
                   3379: 
1.242     albertel 3380: Inputs: $text $uname $udom $symb $target
1.116     albertel 3381: 
                   3382: Returns: A link to grades.pm such as to see the SUBM view of a student
                   3383: 
                   3384: =cut
                   3385: 
                   3386: ###############################################
                   3387: sub submlink {
1.242     albertel 3388:     my ($text,$uname,$udom,$symb,$target)=@_;
1.116     albertel 3389:     if (!($uname && $udom)) {
                   3390: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 3391: 	    &Apache::lonnet::whichuser($symb);
1.116     albertel 3392: 	if (!$symb) { $symb=$cursymb; }
                   3393:     }
1.254     matthew  3394:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      3395:     $symb=&escape($symb);
1.242     albertel 3396:     if ($target) { $target="target=\"$target\""; }
                   3397:     return '<a href="/adm/grades?&command=submission&'.
                   3398: 	'symb='.$symb.'&student='.$uname.
                   3399: 	'&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
                   3400: }
                   3401: ##############################################
                   3402: 
                   3403: =pod
                   3404: 
                   3405: =item * &pgrdlink()
                   3406: 
                   3407: Inputs: $text $uname $udom $symb $target
                   3408: 
                   3409: Returns: A link to grades.pm such as to see the PGRD view of a student
                   3410: 
                   3411: =cut
                   3412: 
                   3413: ###############################################
                   3414: sub pgrdlink {
                   3415:     my $link=&submlink(@_);
                   3416:     $link=~s/(&command=submission)/$1&showgrading=yes/;
                   3417:     return $link;
                   3418: }
                   3419: ##############################################
                   3420: 
                   3421: =pod
                   3422: 
                   3423: =item * &pprmlink()
                   3424: 
                   3425: Inputs: $text $uname $udom $symb $target
                   3426: 
                   3427: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283     albertel 3428: student and a specific resource
1.242     albertel 3429: 
                   3430: =cut
                   3431: 
                   3432: ###############################################
                   3433: sub pprmlink {
                   3434:     my ($text,$uname,$udom,$symb,$target)=@_;
                   3435:     if (!($uname && $udom)) {
                   3436: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 3437: 	    &Apache::lonnet::whichuser($symb);
1.242     albertel 3438: 	if (!$symb) { $symb=$cursymb; }
                   3439:     }
1.254     matthew  3440:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      3441:     $symb=&escape($symb);
1.242     albertel 3442:     if ($target) { $target="target=\"$target\""; }
1.595     albertel 3443:     return '<a href="/adm/parmset?command=set&amp;'.
                   3444: 	'symb='.$symb.'&amp;uname='.$uname.
                   3445: 	'&amp;udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116     albertel 3446: }
                   3447: ##############################################
1.37      matthew  3448: 
1.112     bowersj2 3449: =pod
                   3450: 
                   3451: =back
                   3452: 
                   3453: =cut
                   3454: 
1.37      matthew  3455: ###############################################
1.51      www      3456: 
                   3457: 
                   3458: sub timehash {
1.687     raeburn  3459:     my ($thistime) = @_;
                   3460:     my $timezone = &Apache::lonlocal::gettimezone();
                   3461:     my $dt = DateTime->from_epoch(epoch => $thistime)
                   3462:                      ->set_time_zone($timezone);
                   3463:     my $wday = $dt->day_of_week();
                   3464:     if ($wday == 7) { $wday = 0; }
                   3465:     return ( 'second' => $dt->second(),
                   3466:              'minute' => $dt->minute(),
                   3467:              'hour'   => $dt->hour(),
                   3468:              'day'     => $dt->day_of_month(),
                   3469:              'month'   => $dt->month(),
                   3470:              'year'    => $dt->year(),
                   3471:              'weekday' => $wday,
                   3472:              'dayyear' => $dt->day_of_year(),
                   3473:              'dlsav'   => $dt->is_dst() );
1.51      www      3474: }
                   3475: 
1.370     www      3476: sub utc_string {
                   3477:     my ($date)=@_;
1.371     www      3478:     return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370     www      3479: }
                   3480: 
1.51      www      3481: sub maketime {
                   3482:     my %th=@_;
1.687     raeburn  3483:     my ($epoch_time,$timezone,$dt);
                   3484:     $timezone = &Apache::lonlocal::gettimezone();
                   3485:     eval {
                   3486:         $dt = DateTime->new( year   => $th{'year'},
                   3487:                              month  => $th{'month'},
                   3488:                              day    => $th{'day'},
                   3489:                              hour   => $th{'hour'},
                   3490:                              minute => $th{'minute'},
                   3491:                              second => $th{'second'},
                   3492:                              time_zone => $timezone,
                   3493:                          );
                   3494:     };
                   3495:     if (!$@) {
                   3496:         $epoch_time = $dt->epoch;
                   3497:         if ($epoch_time) {
                   3498:             return $epoch_time;
                   3499:         }
                   3500:     }
1.51      www      3501:     return POSIX::mktime(
                   3502:         ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210     www      3503:          $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70      www      3504: }
                   3505: 
                   3506: #########################################
1.51      www      3507: 
                   3508: sub findallcourses {
1.482     raeburn  3509:     my ($roles,$uname,$udom) = @_;
1.355     albertel 3510:     my %roles;
                   3511:     if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348     albertel 3512:     my %courses;
1.51      www      3513:     my $now=time;
1.482     raeburn  3514:     if (!defined($uname)) {
                   3515:         $uname = $env{'user.name'};
                   3516:     }
                   3517:     if (!defined($udom)) {
                   3518:         $udom = $env{'user.domain'};
                   3519:     }
                   3520:     if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
                   3521:         my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
                   3522:         if (!%roles) {
                   3523:             %roles = (
                   3524:                        cc => 1,
                   3525:                        in => 1,
                   3526:                        ep => 1,
                   3527:                        ta => 1,
                   3528:                        cr => 1,
                   3529:                        st => 1,
                   3530:              );
                   3531:         }
                   3532:         foreach my $entry (keys(%roleshash)) {
                   3533:             my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
                   3534:             if ($trole =~ /^cr/) { 
                   3535:                 next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
                   3536:             } else {
                   3537:                 next if (!exists($roles{$trole}));
                   3538:             }
                   3539:             if ($tend) {
                   3540:                 next if ($tend < $now);
                   3541:             }
                   3542:             if ($tstart) {
                   3543:                 next if ($tstart > $now);
                   3544:             }
                   3545:             my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
                   3546:             (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
                   3547:             if ($secpart eq '') {
                   3548:                 ($cnum,$role) = split(/_/,$cnumpart); 
                   3549:                 $sec = 'none';
                   3550:                 $realsec = '';
                   3551:             } else {
                   3552:                 $cnum = $cnumpart;
                   3553:                 ($sec,$role) = split(/_/,$secpart);
                   3554:                 $realsec = $sec;
1.490     raeburn  3555:             }
1.482     raeburn  3556:             $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
                   3557:         }
                   3558:     } else {
                   3559:         foreach my $key (keys(%env)) {
1.483     albertel 3560: 	    if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
                   3561:                  $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482     raeburn  3562: 	        my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
                   3563: 	        next if ($role eq 'ca' || $role eq 'aa');
                   3564: 	        next if (%roles && !exists($roles{$role}));
                   3565: 	        my ($starttime,$endtime)=split(/\./,$env{$key});
                   3566:                 my $active=1;
                   3567:                 if ($starttime) {
                   3568: 		    if ($now<$starttime) { $active=0; }
                   3569:                 }
                   3570:                 if ($endtime) {
                   3571:                     if ($now>$endtime) { $active=0; }
                   3572:                 }
                   3573:                 if ($active) {
                   3574:                     if ($sec eq '') {
                   3575:                         $sec = 'none';
                   3576:                     }
                   3577:                     $courses{$cdom.'_'.$cnum}{$sec} = 
                   3578:                                      $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474     raeburn  3579:                 }
                   3580:             }
1.51      www      3581:         }
                   3582:     }
1.474     raeburn  3583:     return %courses;
1.51      www      3584: }
1.37      matthew  3585: 
1.54      www      3586: ###############################################
1.474     raeburn  3587: 
                   3588: sub blockcheck {
1.482     raeburn  3589:     my ($setters,$activity,$uname,$udom) = @_;
1.490     raeburn  3590: 
                   3591:     if (!defined($udom)) {
                   3592:         $udom = $env{'user.domain'};
                   3593:     }
                   3594:     if (!defined($uname)) {
                   3595:         $uname = $env{'user.name'};
                   3596:     }
                   3597: 
                   3598:     # If uname and udom are for a course, check for blocks in the course.
                   3599: 
                   3600:     if (&Apache::lonnet::is_course($udom,$uname)) {
                   3601:         my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502     raeburn  3602:         my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490     raeburn  3603:         return ($startblock,$endblock);
                   3604:     }
1.474     raeburn  3605: 
1.502     raeburn  3606:     my $startblock = 0;
                   3607:     my $endblock = 0;
1.482     raeburn  3608:     my %live_courses = &findallcourses(undef,$uname,$udom);
1.474     raeburn  3609: 
1.490     raeburn  3610:     # If uname is for a user, and activity is course-specific, i.e.,
                   3611:     # boards, chat or groups, check for blocking in current course only.
1.474     raeburn  3612: 
1.490     raeburn  3613:     if (($activity eq 'boards' || $activity eq 'chat' ||
                   3614:          $activity eq 'groups') && ($env{'request.course.id'})) {
                   3615:         foreach my $key (keys(%live_courses)) {
                   3616:             if ($key ne $env{'request.course.id'}) {
                   3617:                 delete($live_courses{$key});
                   3618:             }
                   3619:         }
                   3620:     }
                   3621: 
                   3622:     my $otheruser = 0;
                   3623:     my %own_courses;
                   3624:     if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
                   3625:         # Resource belongs to user other than current user.
                   3626:         $otheruser = 1;
                   3627:         # Gather courses for current user
                   3628:         %own_courses = 
                   3629:             &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
                   3630:     }
                   3631: 
                   3632:     # Gather active course roles - course coordinator, instructor, 
                   3633:     # exam proctor, ta, student, or custom role.
1.474     raeburn  3634: 
                   3635:     foreach my $course (keys(%live_courses)) {
1.482     raeburn  3636:         my ($cdom,$cnum);
                   3637:         if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
                   3638:             $cdom = $env{'course.'.$course.'.domain'};
                   3639:             $cnum = $env{'course.'.$course.'.num'};
                   3640:         } else {
1.490     raeburn  3641:             ($cdom,$cnum) = split(/_/,$course); 
1.482     raeburn  3642:         }
                   3643:         my $no_ownblock = 0;
                   3644:         my $no_userblock = 0;
1.533     raeburn  3645:         if ($otheruser && $activity ne 'com') {
1.490     raeburn  3646:             # Check if current user has 'evb' priv for this
                   3647:             if (defined($own_courses{$course})) {
                   3648:                 foreach my $sec (keys(%{$own_courses{$course}})) {
                   3649:                     my $checkrole = 'cm./'.$cdom.'/'.$cnum;
                   3650:                     if ($sec ne 'none') {
                   3651:                         $checkrole .= '/'.$sec;
                   3652:                     }
                   3653:                     if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   3654:                         $no_ownblock = 1;
                   3655:                         last;
                   3656:                     }
                   3657:                 }
                   3658:             }
                   3659:             # if they have 'evb' priv and are currently not playing student
                   3660:             next if (($no_ownblock) &&
                   3661:                  ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
                   3662:         }
1.474     raeburn  3663:         foreach my $sec (keys(%{$live_courses{$course}})) {
1.482     raeburn  3664:             my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474     raeburn  3665:             if ($sec ne 'none') {
1.482     raeburn  3666:                 $checkrole .= '/'.$sec;
1.474     raeburn  3667:             }
1.490     raeburn  3668:             if ($otheruser) {
                   3669:                 # Resource belongs to user other than current user.
                   3670:                 # Assemble privs for that user, and check for 'evb' priv.
1.482     raeburn  3671:                 my ($trole,$tdom,$tnum,$tsec);
                   3672:                 my $entry = $live_courses{$course}{$sec};
                   3673:                 if ($entry =~ /^cr/) {
                   3674:                     ($trole,$tdom,$tnum,$tsec) = 
                   3675:                       ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
                   3676:                 } else {
                   3677:                     ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
                   3678:                 }
                   3679:                 my ($spec,$area,$trest,%allroles,%userroles);
                   3680:                 $area = '/'.$tdom.'/'.$tnum;
                   3681:                 $trest = $tnum;
                   3682:                 if ($tsec ne '') {
                   3683:                     $area .= '/'.$tsec;
                   3684:                     $trest .= '/'.$tsec;
                   3685:                 }
                   3686:                 $spec = $trole.'.'.$area;
                   3687:                 if ($trole =~ /^cr/) {
                   3688:                     &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
                   3689:                                                       $tdom,$spec,$trest,$area);
                   3690:                 } else {
                   3691:                     &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
                   3692:                                                        $tdom,$spec,$trest,$area);
                   3693:                 }
                   3694:                 my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486     raeburn  3695:                 if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
                   3696:                     if ($1) {
                   3697:                         $no_userblock = 1;
                   3698:                         last;
                   3699:                     }
                   3700:                 }
1.490     raeburn  3701:             } else {
                   3702:                 # Resource belongs to current user
                   3703:                 # Check for 'evb' priv via lonnet::allowed().
1.482     raeburn  3704:                 if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   3705:                     $no_ownblock = 1;
                   3706:                     last;
                   3707:                 }
1.474     raeburn  3708:             }
                   3709:         }
                   3710:         # if they have the evb priv and are currently not playing student
1.482     raeburn  3711:         next if (($no_ownblock) &&
1.491     albertel 3712:                  ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482     raeburn  3713:         next if ($no_userblock);
1.474     raeburn  3714: 
1.490     raeburn  3715:         # Retrieve blocking times and identity of blocker for course
                   3716:         # of specified user, unless user has 'evb' privilege.
1.502     raeburn  3717:         
                   3718:         my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
                   3719:         if (($start != 0) && 
                   3720:             (($startblock == 0) || ($startblock > $start))) {
                   3721:             $startblock = $start;
                   3722:         }
                   3723:         if (($end != 0)  &&
                   3724:             (($endblock == 0) || ($endblock < $end))) {
                   3725:             $endblock = $end;
                   3726:         }
1.490     raeburn  3727:     }
                   3728:     return ($startblock,$endblock);
                   3729: }
                   3730: 
                   3731: sub get_blocks {
                   3732:     my ($setters,$activity,$cdom,$cnum) = @_;
                   3733:     my $startblock = 0;
                   3734:     my $endblock = 0;
                   3735:     my $course = $cdom.'_'.$cnum;
                   3736:     $setters->{$course} = {};
                   3737:     $setters->{$course}{'staff'} = [];
                   3738:     $setters->{$course}{'times'} = [];
                   3739:     my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
                   3740:     foreach my $record (keys(%records)) {
                   3741:         my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
                   3742:         if ($start <= time && $end >= time) {
                   3743:             my ($staff_name,$staff_dom,$title,$blocks) =
                   3744:                 &parse_block_record($records{$record});
                   3745:             if ($blocks->{$activity} eq 'on') {
                   3746:                 push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
                   3747:                 push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491     albertel 3748:                 if ( ($startblock == 0) || ($startblock > $start) ) {
                   3749:                     $startblock = $start;
1.490     raeburn  3750:                 }
1.491     albertel 3751:                 if ( ($endblock == 0) || ($endblock < $end) ) {
                   3752:                     $endblock = $end;
1.474     raeburn  3753:                 }
                   3754:             }
                   3755:         }
                   3756:     }
                   3757:     return ($startblock,$endblock);
                   3758: }
                   3759: 
                   3760: sub parse_block_record {
                   3761:     my ($record) = @_;
                   3762:     my ($setuname,$setudom,$title,$blocks);
                   3763:     if (ref($record) eq 'HASH') {
                   3764:         ($setuname,$setudom) = split(/:/,$record->{'setter'});
                   3765:         $title = &unescape($record->{'event'});
                   3766:         $blocks = $record->{'blocks'};
                   3767:     } else {
                   3768:         my @data = split(/:/,$record,3);
                   3769:         if (scalar(@data) eq 2) {
                   3770:             $title = $data[1];
                   3771:             ($setuname,$setudom) = split(/@/,$data[0]);
                   3772:         } else {
                   3773:             ($setuname,$setudom,$title) = @data;
                   3774:         }
                   3775:         $blocks = { 'com' => 'on' };
                   3776:     }
                   3777:     return ($setuname,$setudom,$title,$blocks);
                   3778: }
                   3779: 
                   3780: sub build_block_table {
                   3781:     my ($startblock,$endblock,$setters) = @_;
                   3782:     my %lt = &Apache::lonlocal::texthash(
                   3783:         'cacb' => 'Currently active communication blocks',
                   3784:         'cour' => 'Course',
                   3785:         'dura' => 'Duration',
                   3786:         'blse' => 'Block set by'
                   3787:     );
                   3788:     my $output;
1.476     raeburn  3789:     $output = '<br />'.$lt{'cacb'}.':<br />';
1.474     raeburn  3790:     $output .= &start_data_table();
                   3791:     $output .= '
                   3792: <tr>
                   3793:  <th>'.$lt{'cour'}.'</th>
                   3794:  <th>'.$lt{'dura'}.'</th>
                   3795:  <th>'.$lt{'blse'}.'</th>
                   3796: </tr>
                   3797: ';
                   3798:     foreach my $course (keys(%{$setters})) {
                   3799:         my %courseinfo=&Apache::lonnet::coursedescription($course);
                   3800:         for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) {
                   3801:             my ($uname,$udom) = @{$$setters{$course}{staff}[$i]};
1.490     raeburn  3802:             my $fullname = &plainname($uname,$udom);
                   3803:             if (defined($env{'user.name'}) && defined($env{'user.domain'})
                   3804:                 && $env{'user.name'} ne 'public' 
                   3805:                 && $env{'user.domain'} ne 'public') {
                   3806:                 $fullname = &aboutmewrapper($fullname,$uname,$udom);
                   3807:             }
1.474     raeburn  3808:             my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]};
                   3809:             $openblock = &Apache::lonlocal::locallocaltime($openblock);
                   3810:             $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
                   3811:             $output .= &Apache::loncommon::start_data_table_row().
                   3812:                        '<td>'.$courseinfo{'description'}.'</td>'.
                   3813:                        '<td>'.$openblock.' to '.$closeblock.'</td>'.
1.490     raeburn  3814:                        '<td>'.$fullname.'</td>'.
1.474     raeburn  3815:                         &Apache::loncommon::end_data_table_row();
                   3816:         }
                   3817:     }
                   3818:     $output .= &end_data_table();
                   3819: }
                   3820: 
1.490     raeburn  3821: sub blocking_status {
                   3822:     my ($activity,$uname,$udom) = @_;
                   3823:     my %setters;
                   3824:     my ($blocked,$output,$ownitem,$is_course);
                   3825:     my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
                   3826:     if ($startblock && $endblock) {
                   3827:         $blocked = 1;
                   3828:         if (wantarray) {
                   3829:             my $category;
                   3830:             if ($activity eq 'boards') {
                   3831:                 $category = 'Discussion posts in this course';
                   3832:             } elsif ($activity eq 'blogs') {
                   3833:                 $category = 'Blogs';
                   3834:             } elsif ($activity eq 'port') {
                   3835:                 if (defined($uname) && defined($udom)) {
                   3836:                     if ($uname eq $env{'user.name'} &&
                   3837:                         $udom eq $env{'user.domain'}) {
                   3838:                         $ownitem = 1;
                   3839:                     }
                   3840:                 }
                   3841:                 $is_course = &Apache::lonnet::is_course($udom,$uname);
                   3842:                 if ($ownitem) { 
                   3843:                     $category = 'Your portfolio files';  
                   3844:                 } elsif ($is_course) {
                   3845:                     my $coursedesc;
                   3846:                     foreach my $course (keys(%setters)) {
                   3847:                         my %courseinfo =
                   3848:                              &Apache::lonnet::coursedescription($course);
                   3849:                         $coursedesc = $courseinfo{'description'};
                   3850:                     }
1.764     weissno  3851:                     $category = "Group portfolio in the course '$coursedesc'";
1.490     raeburn  3852:                 } else {
                   3853:                     $category = 'Portfolio files belonging to ';
                   3854:                     if ($env{'user.name'} eq 'public' && 
                   3855:                         $env{'user.domain'} eq 'public') {
                   3856:                         $category .= &plainname($uname,$udom);
                   3857:                     } else {
                   3858:                         $category .= &aboutmewrapper(&plainname($uname,$udom),$uname,$udom);  
                   3859:                     }
                   3860:                 }
                   3861:             } elsif ($activity eq 'groups') {
                   3862:                 $category = 'Groups in this course';
                   3863:             }
                   3864:             my $showstart = &Apache::lonlocal::locallocaltime($startblock);
                   3865:             my $showend = &Apache::lonlocal::locallocaltime($endblock);
                   3866:             $output = '<br />'.&mt('[_1] will be inaccessible between [_2] and [_3] because communication is being blocked.',$category,$showstart,$showend).'<br />';
                   3867:             if (!($activity eq 'port' && !($ownitem) && !($is_course))) { 
                   3868:                 $output .= &build_block_table($startblock,$endblock,\%setters);
                   3869:             }
                   3870:         }
                   3871:     }
                   3872:     if (wantarray) {
                   3873:         return ($blocked,$output);
                   3874:     } else {
                   3875:         return $blocked;
                   3876:     }
                   3877: }
                   3878: 
1.60      matthew  3879: ###############################################
                   3880: 
1.682     raeburn  3881: sub check_ip_acc {
                   3882:     my ($acc)=@_;
                   3883:     &Apache::lonxml::debug("acc is $acc");
                   3884:     if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
                   3885:         return 1;
                   3886:     }
                   3887:     my $allowed=0;
                   3888:     my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
                   3889: 
                   3890:     my $name;
                   3891:     foreach my $pattern (split(',',$acc)) {
                   3892:         $pattern =~ s/^\s*//;
                   3893:         $pattern =~ s/\s*$//;
                   3894:         if ($pattern =~ /\*$/) {
                   3895:             #35.8.*
                   3896:             $pattern=~s/\*//;
                   3897:             if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
                   3898:         } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
                   3899:             #35.8.3.[34-56]
                   3900:             my $low=$2;
                   3901:             my $high=$3;
                   3902:             $pattern=$1;
                   3903:             if ($ip =~ /^\Q$pattern\E/) {
                   3904:                 my $last=(split(/\./,$ip))[3];
                   3905:                 if ($last <=$high && $last >=$low) { $allowed=1; }
                   3906:             }
                   3907:         } elsif ($pattern =~ /^\*/) {
                   3908:             #*.msu.edu
                   3909:             $pattern=~s/\*//;
                   3910:             if (!defined($name)) {
                   3911:                 use Socket;
                   3912:                 my $netaddr=inet_aton($ip);
                   3913:                 ($name)=gethostbyaddr($netaddr,AF_INET);
                   3914:             }
                   3915:             if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
                   3916:         } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
                   3917:             #127.0.0.1
                   3918:             if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
                   3919:         } else {
                   3920:             #some.name.com
                   3921:             if (!defined($name)) {
                   3922:                 use Socket;
                   3923:                 my $netaddr=inet_aton($ip);
                   3924:                 ($name)=gethostbyaddr($netaddr,AF_INET);
                   3925:             }
                   3926:             if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
                   3927:         }
                   3928:         if ($allowed) { last; }
                   3929:     }
                   3930:     return $allowed;
                   3931: }
                   3932: 
                   3933: ###############################################
                   3934: 
1.60      matthew  3935: =pod
                   3936: 
1.112     bowersj2 3937: =head1 Domain Template Functions
                   3938: 
                   3939: =over 4
                   3940: 
                   3941: =item * &determinedomain()
1.60      matthew  3942: 
                   3943: Inputs: $domain (usually will be undef)
                   3944: 
1.63      www      3945: Returns: Determines which domain should be used for designs
1.60      matthew  3946: 
                   3947: =cut
1.54      www      3948: 
1.60      matthew  3949: ###############################################
1.63      www      3950: sub determinedomain {
                   3951:     my $domain=shift;
1.531     albertel 3952:     if (! $domain) {
1.60      matthew  3953:         # Determine domain if we have not been given one
                   3954:         $domain = $Apache::lonnet::perlvar{'lonDefDomain'};
1.258     albertel 3955:         if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
                   3956:         if ($env{'request.role.domain'}) { 
                   3957:             $domain=$env{'request.role.domain'}; 
1.60      matthew  3958:         }
                   3959:     }
1.63      www      3960:     return $domain;
                   3961: }
                   3962: ###############################################
1.517     raeburn  3963: 
1.518     albertel 3964: sub devalidate_domconfig_cache {
                   3965:     my ($udom)=@_;
                   3966:     &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
                   3967: }
                   3968: 
                   3969: # ---------------------- Get domain configuration for a domain
                   3970: sub get_domainconf {
                   3971:     my ($udom) = @_;
                   3972:     my $cachetime=1800;
                   3973:     my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
                   3974:     if (defined($cached)) { return %{$result}; }
                   3975: 
                   3976:     my %domconfig = &Apache::lonnet::get_dom('configuration',
                   3977: 					     ['login','rolecolors'],$udom);
1.632     raeburn  3978:     my (%designhash,%legacy);
1.518     albertel 3979:     if (keys(%domconfig) > 0) {
                   3980:         if (ref($domconfig{'login'}) eq 'HASH') {
1.632     raeburn  3981:             if (keys(%{$domconfig{'login'}})) {
                   3982:                 foreach my $key (keys(%{$domconfig{'login'}})) {
1.699     raeburn  3983:                     if (ref($domconfig{'login'}{$key}) eq 'HASH') {
                   3984:                         foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
                   3985:                             $designhash{$udom.'.login.'.$key.'_'.$img} = 
                   3986:                                 $domconfig{'login'}{$key}{$img};
                   3987:                         }
                   3988:                     } else {
                   3989:                         $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
                   3990:                     }
1.632     raeburn  3991:                 }
                   3992:             } else {
                   3993:                 $legacy{'login'} = 1;
1.518     albertel 3994:             }
1.632     raeburn  3995:         } else {
                   3996:             $legacy{'login'} = 1;
1.518     albertel 3997:         }
                   3998:         if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632     raeburn  3999:             if (keys(%{$domconfig{'rolecolors'}})) {
                   4000:                 foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
                   4001:                     if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
                   4002:                         foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
                   4003:                             $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
                   4004:                         }
1.518     albertel 4005:                     }
                   4006:                 }
1.632     raeburn  4007:             } else {
                   4008:                 $legacy{'rolecolors'} = 1;
1.518     albertel 4009:             }
1.632     raeburn  4010:         } else {
                   4011:             $legacy{'rolecolors'} = 1;
1.518     albertel 4012:         }
1.632     raeburn  4013:         if (keys(%legacy) > 0) {
                   4014:             my %legacyhash = &get_legacy_domconf($udom);
                   4015:             foreach my $item (keys(%legacyhash)) {
                   4016:                 if ($item =~ /^\Q$udom\E\.login/) {
                   4017:                     if ($legacy{'login'}) { 
                   4018:                         $designhash{$item} = $legacyhash{$item};
                   4019:                     }
                   4020:                 } else {
                   4021:                     if ($legacy{'rolecolors'}) {
                   4022:                         $designhash{$item} = $legacyhash{$item};
                   4023:                     }
1.518     albertel 4024:                 }
                   4025:             }
                   4026:         }
1.632     raeburn  4027:     } else {
                   4028:         %designhash = &get_legacy_domconf($udom); 
1.518     albertel 4029:     }
                   4030:     &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
                   4031: 				  $cachetime);
                   4032:     return %designhash;
                   4033: }
                   4034: 
1.632     raeburn  4035: sub get_legacy_domconf {
                   4036:     my ($udom) = @_;
                   4037:     my %legacyhash;
                   4038:     my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
                   4039:     my $designfile =  $designdir.'/'.$udom.'.tab';
                   4040:     if (-e $designfile) {
                   4041:         if ( open (my $fh,"<$designfile") ) {
                   4042:             while (my $line = <$fh>) {
                   4043:                 next if ($line =~ /^\#/);
                   4044:                 chomp($line);
                   4045:                 my ($key,$val)=(split(/\=/,$line));
                   4046:                 if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
                   4047:             }
                   4048:             close($fh);
                   4049:         }
                   4050:     }
                   4051:     if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
                   4052:         $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
                   4053:     }
                   4054:     return %legacyhash;
                   4055: }
                   4056: 
1.63      www      4057: =pod
                   4058: 
1.112     bowersj2 4059: =item * &domainlogo()
1.63      www      4060: 
                   4061: Inputs: $domain (usually will be undef)
                   4062: 
                   4063: Returns: A link to a domain logo, if the domain logo exists.
                   4064: If the domain logo does not exist, a description of the domain.
                   4065: 
                   4066: =cut
1.112     bowersj2 4067: 
1.63      www      4068: ###############################################
                   4069: sub domainlogo {
1.517     raeburn  4070:     my $domain = &determinedomain(shift);
1.518     albertel 4071:     my %designhash = &get_domainconf($domain);    
1.517     raeburn  4072:     # See if there is a logo
                   4073:     if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519     raeburn  4074:         my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538     albertel 4075:         if ($imgsrc =~ m{^/(adm|res)/}) {
                   4076: 	    if ($imgsrc =~ m{^/res/}) {
                   4077: 		my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
                   4078: 		&Apache::lonnet::repcopy($local_name);
                   4079: 	    }
                   4080: 	   $imgsrc = &lonhttpdurl($imgsrc);
1.519     raeburn  4081:         } 
                   4082:         return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514     albertel 4083:     } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
                   4084:         return &Apache::lonnet::domain($domain,'description');
1.59      www      4085:     } else {
1.60      matthew  4086:         return '';
1.59      www      4087:     }
                   4088: }
1.63      www      4089: ##############################################
                   4090: 
                   4091: =pod
                   4092: 
1.112     bowersj2 4093: =item * &designparm()
1.63      www      4094: 
                   4095: Inputs: $which parameter; $domain (usually will be undef)
                   4096: 
                   4097: Returns: value of designparamter $which
                   4098: 
                   4099: =cut
1.112     bowersj2 4100: 
1.397     albertel 4101: 
1.400     albertel 4102: ##############################################
1.397     albertel 4103: sub designparm {
                   4104:     my ($which,$domain)=@_;
1.258     albertel 4105:     if ($env{'browser.blackwhite'} eq 'on') {
1.635     raeburn  4106: 	if ($which=~/\.(font|alink|vlink|link|textcol)$/) {
1.110     www      4107: 	    return '#000000';
                   4108: 	}
1.635     raeburn  4109: 	if ($which=~/\.(pgbg|sidebg|bgcol)$/) {
1.110     www      4110: 	    return '#FFFFFF';
                   4111: 	}
                   4112: 	if ($which=~/\.tabbg$/) {
                   4113: 	    return '#CCCCCC';
                   4114: 	}
                   4115:     }
1.397     albertel 4116:     if (exists($env{'environment.color.'.$which})) {
1.258     albertel 4117: 	return $env{'environment.color.'.$which};
1.96      www      4118:     }
1.63      www      4119:     $domain=&determinedomain($domain);
1.518     albertel 4120:     my %domdesign = &get_domainconf($domain);
1.520     raeburn  4121:     my $output;
1.517     raeburn  4122:     if ($domdesign{$domain.'.'.$which} ne '') {
1.520     raeburn  4123: 	$output = $domdesign{$domain.'.'.$which};
1.63      www      4124:     } else {
1.520     raeburn  4125:         $output = $defaultdesign{$which};
                   4126:     }
                   4127:     if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635     raeburn  4128:         ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538     albertel 4129:         if ($output =~ m{^/(adm|res)/}) {
                   4130: 	    if ($output =~ m{^/res/}) {
                   4131: 		my $local_name = &Apache::lonnet::filelocation('',$output);
                   4132: 		&Apache::lonnet::repcopy($local_name);
                   4133: 	    }
1.520     raeburn  4134:             $output = &lonhttpdurl($output);
                   4135:         }
1.63      www      4136:     }
1.520     raeburn  4137:     return $output;
1.63      www      4138: }
1.59      www      4139: 
1.60      matthew  4140: ###############################################
                   4141: ###############################################
                   4142: 
                   4143: =pod
                   4144: 
1.112     bowersj2 4145: =back
                   4146: 
1.549     albertel 4147: =head1 HTML Helpers
1.112     bowersj2 4148: 
                   4149: =over 4
                   4150: 
                   4151: =item * &bodytag()
1.60      matthew  4152: 
                   4153: Returns a uniform header for LON-CAPA web pages.
                   4154: 
                   4155: Inputs: 
                   4156: 
1.112     bowersj2 4157: =over 4
                   4158: 
                   4159: =item * $title, A title to be displayed on the page.
                   4160: 
                   4161: =item * $function, the current role (can be undef).
                   4162: 
                   4163: =item * $addentries, extra parameters for the <body> tag.
                   4164: 
                   4165: =item * $bodyonly, if defined, only return the <body> tag.
                   4166: 
                   4167: =item * $domain, if defined, force a given domain.
                   4168: 
                   4169: =item * $forcereg, if page should register as content page (relevant for 
1.86      www      4170:             text interface only)
1.60      matthew  4171: 
1.326     albertel 4172: =item * $customtitle, alternate text to use instead of $title
                   4173:                       in the title box that appears, this text
                   4174:                       is not auto translated like the $title is
1.309     albertel 4175: 
                   4176: =item * $notopbar, if true, keep the 'what is this' info but remove the
                   4177:                    navigational links
1.317     albertel 4178: 
1.338     albertel 4179: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
                   4180: 
                   4181: =item * $notitle, if true keep the nav controls, but remove the title bar
                   4182: 
1.361     albertel 4183: =item * $no_inline_link, if true and in remote mode, don't show the 
                   4184:          'Switch To Inline Menu' link
                   4185: 
1.460     albertel 4186: =item * $args, optional argument valid values are
                   4187:             no_auto_mt_title -> prevents &mt()ing the title arg
1.562     albertel 4188:             inherit_jsmath -> when creating popup window in a page,
                   4189:                               should it have jsmath forced on by the
                   4190:                               current page
1.460     albertel 4191: 
1.112     bowersj2 4192: =back
                   4193: 
1.60      matthew  4194: Returns: A uniform header for LON-CAPA web pages.  
                   4195: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
                   4196: If $bodyonly is undef or zero, an html string containing a <body> tag and 
                   4197: other decorations will be returned.
                   4198: 
                   4199: =cut
                   4200: 
1.54      www      4201: sub bodytag {
1.309     albertel 4202:     my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,$customtitle,
1.460     albertel 4203: 	$notopbar,$bgcolor,$notitle,$no_inline_link,$args)=@_;
1.339     albertel 4204: 
1.460     albertel 4205:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339     albertel 4206: 
1.183     matthew  4207:     $function = &get_users_function() if (!$function);
1.339     albertel 4208:     my $img =    &designparm($function.'.img',$domain);
                   4209:     my $font =   &designparm($function.'.font',$domain);
                   4210:     my $pgbg   = $bgcolor || &designparm($function.'.pgbg',$domain);
                   4211: 
                   4212:     my %design = ( 'style'   => 'margin-top: 0px',
1.535     albertel 4213: 		   'bgcolor' => $pgbg,
1.339     albertel 4214: 		   'text'    => $font,
                   4215:                    'alink'   => &designparm($function.'.alink',$domain),
                   4216: 		   'vlink'   => &designparm($function.'.vlink',$domain),
                   4217: 		   'link'    => &designparm($function.'.link',$domain),);
1.438     albertel 4218:     @design{keys(%$addentries)} = @$addentries{keys(%$addentries)}; 
1.339     albertel 4219: 
1.63      www      4220:  # role and realm
1.378     raeburn  4221:     my ($role,$realm) = split(/\./,$env{'request.role'},2);
                   4222:     if ($role  eq 'ca') {
1.479     albertel 4223:         my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500     albertel 4224:         $realm = &plainname($rname,$rdom);
1.378     raeburn  4225:     } 
1.55      www      4226: # realm
1.258     albertel 4227:     if ($env{'request.course.id'}) {
1.378     raeburn  4228:         if ($env{'request.role'} !~ /^cr/) {
                   4229:             $role = &Apache::lonnet::plaintext($role,&course_type());
                   4230:         }
1.359     albertel 4231: 	$realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378     raeburn  4232:     } else {
                   4233:         $role = &Apache::lonnet::plaintext($role);
1.54      www      4234:     }
1.433     albertel 4235: 
1.359     albertel 4236:     if (!$realm) { $realm='&nbsp;'; }
1.55      www      4237: # Set messages
1.60      matthew  4238:     my $messages=&domainlogo($domain);
1.330     albertel 4239: 
1.438     albertel 4240:     my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329     albertel 4241: 
1.101     www      4242: # construct main body tag
1.359     albertel 4243:     my $bodytag = "<body $extra_body_attr>".
1.562     albertel 4244: 	&Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252     albertel 4245: 
1.530     albertel 4246:     if ($bodyonly) {
1.60      matthew  4247:         return $bodytag;
1.258     albertel 4248:     } elsif ($env{'browser.interface'} eq 'textual') {
1.95      www      4249: # Accessibility
1.224     raeburn  4250:           
1.337     albertel 4251: 	$bodytag.=&Apache::lonmenu::menubuttons($forcereg,$forcereg);
1.338     albertel 4252: 	if (!$notitle) {
1.337     albertel 4253: 	    $bodytag.='<h1>LON-CAPA: '.$title.'</h1>';
                   4254: 	}
                   4255: 	return $bodytag;
1.359     albertel 4256:     }
                   4257: 
1.410     albertel 4258:     my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.433     albertel 4259:     if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
                   4260: 	undef($role);
1.434     albertel 4261:     } else {
                   4262: 	$name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433     albertel 4263:     }
1.359     albertel 4264:     
                   4265:     my $roleinfo=(<<ENDROLE);
                   4266: <td class="LC_title_bar_who">
                   4267: <div class="LC_title_bar_name">
1.410     albertel 4268:     $name
1.361     albertel 4269:     &nbsp;
1.359     albertel 4270: </div>
                   4271: <div class="LC_title_bar_role">
1.361     albertel 4272: $role&nbsp;
1.359     albertel 4273: </div>
                   4274: <div class="LC_title_bar_realm">
1.361     albertel 4275: $realm&nbsp;
1.359     albertel 4276: </div>
1.206     albertel 4277: </td>
                   4278: ENDROLE
1.235     raeburn  4279: 
1.762     bisitz   4280:     my $titleinfo = '<h1>'.$title.'</h1>';
1.359     albertel 4281:     if ($customtitle) {
                   4282:         $titleinfo = $customtitle;
                   4283:     }
                   4284:     #
                   4285:     # Extra info if you are the DC
                   4286:     my $dc_info = '';
                   4287:     if ($env{'user.adv'} && exists($env{'user.role.dc./'.
                   4288:                         $env{'course.'.$env{'request.course.id'}.
                   4289:                                  '.domain'}.'/'})) {
                   4290:         my $cid = $env{'request.course.id'};
                   4291:         $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380     www      4292:         $dc_info =~ s/\s+$//;
1.359     albertel 4293:         $dc_info = '('.$dc_info.')';
                   4294:     }
                   4295: 
1.644     www      4296:     if (($env{'environment.remote'} eq 'off') || ($args->{'suppress_header_logos'})) {
1.359     albertel 4297:         # No Remote
1.258     albertel 4298: 	if ($env{'request.state'} eq 'construct') {
1.359     albertel 4299: 	    $forcereg=1;
                   4300: 	}
                   4301: 
                   4302: 	if (!$customtitle && $env{'request.state'} eq 'construct') {
                   4303: 	    # this is for resources; directories have customtitle, and crumbs
                   4304:             # and select recent are created in lonpubdir.pm  
1.229     albertel 4305: 	    my ($uname,$thisdisfn)=
1.258     albertel 4306: 		($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
1.229     albertel 4307: 	    my $formaction='/priv/'.$uname.'/'.$thisdisfn;
                   4308: 	    $formaction=~s/\/+/\//g;
                   4309: 
1.359     albertel 4310: 	    my $parentpath = '';
                   4311: 	    my $lastitem = '';
                   4312: 	    if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
                   4313: 		$parentpath = $1;
                   4314: 		$lastitem = $2;
                   4315: 	    } else {
                   4316: 		$lastitem = $thisdisfn;
                   4317: 	    }
                   4318: 	    $titleinfo = 
1.640     bisitz   4319: 		&Apache::loncommon::help_open_menu('','',3,'Authoring')
                   4320: 		.'<b>'.&mt('Construction Space').'</b>:&nbsp;'
                   4321: 		.'<form name="dirs" method="post" action="'.$formaction
1.359     albertel 4322: 		.'" target="_top"><tt><b>'
1.705     tempelho 4323: 		.&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."<span class=\"LC_fontsize_big\">$lastitem</span></b></tt><br />"
1.359     albertel 4324: 		.&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
                   4325: 		.'</form>'
                   4326: 		.&Apache::lonmenu::constspaceform();
1.235     raeburn  4327:         }
1.359     albertel 4328: 
1.337     albertel 4329:         my $titletable;
1.338     albertel 4330: 	if (!$notitle) {
1.337     albertel 4331: 	    $titletable =
1.359     albertel 4332: 		'<table id="LC_title_bar">'.
                   4333:                          "<tr><td> $titleinfo $dc_info</td>".$roleinfo.
                   4334: 			 '</tr></table>';
1.337     albertel 4335: 	}
1.359     albertel 4336: 	if ($notopbar) {
                   4337: 	    $bodytag .= $titletable;
                   4338: 	} else {
                   4339: 	    if ($env{'request.state'} eq 'construct') {
1.337     albertel 4340:                 $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg,
                   4341: 							  $titletable);
1.272     raeburn  4342:             } else {
1.336     albertel 4343:                 $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg).
1.359     albertel 4344: 		    $titletable;
1.272     raeburn  4345:             }
1.235     raeburn  4346:         }
                   4347:         return $bodytag;
1.94      www      4348:     }
1.95      www      4349: 
1.93      www      4350: #
1.95      www      4351: # Top frame rendering, Remote is up
1.93      www      4352: #
1.359     albertel 4353: 
1.517     raeburn  4354:     my $imgsrc = $img;
                   4355:     if ($img =~ /^\/adm/) {
1.575     albertel 4356:         $imgsrc = &lonhttpdurl($img);
1.517     raeburn  4357:     }
                   4358:     my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359     albertel 4359: 
1.305     www      4360:     # Explicit link to get inline menu
1.361     albertel 4361:     my $menu= ($no_inline_link?''
                   4362: 	       :'<br /><a href="/adm/remote?action=collapse">'.&mt('Switch to Inline Menu Mode').'</a>');
1.245     matthew  4363:     #
1.338     albertel 4364:     if ($notitle) {
1.337     albertel 4365: 	return $bodytag;
                   4366:     }
1.94      www      4367:     return(<<ENDBODY);
1.60      matthew  4368: $bodytag
1.359     albertel 4369: <table id="LC_title_bar" class="LC_with_remote">
1.791   ! tempelho 4370: <tr><td>$upperleft</td>
        !          4371:     <td>$messages&nbsp;</td>
1.54      www      4372: </tr>
1.359     albertel 4373: <tr><td>$titleinfo $dc_info $menu</td>
                   4374: $roleinfo
1.368     albertel 4375: </tr>
1.356     albertel 4376: </table>
1.54      www      4377: ENDBODY
1.182     matthew  4378: }
                   4379: 
1.330     albertel 4380: sub make_attr_string {
                   4381:     my ($register,$attr_ref) = @_;
                   4382: 
                   4383:     if ($attr_ref && !ref($attr_ref)) {
                   4384: 	die("addentries Must be a hash ref ".
                   4385: 	    join(':',caller(1))." ".
                   4386: 	    join(':',caller(0))." ");
                   4387:     }
                   4388: 
                   4389:     if ($register) {
1.339     albertel 4390: 	my ($on_load,$on_unload);
                   4391: 	foreach my $key (keys(%{$attr_ref})) {
                   4392: 	    if      (lc($key) eq 'onload') {
                   4393: 		$on_load.=$attr_ref->{$key}.';';
                   4394: 		delete($attr_ref->{$key});
                   4395: 
                   4396: 	    } elsif (lc($key) eq 'onunload') {
                   4397: 		$on_unload.=$attr_ref->{$key}.';';
                   4398: 		delete($attr_ref->{$key});
                   4399: 	    }
                   4400: 	}
                   4401: 	$attr_ref->{'onload'}  =
                   4402: 	    &Apache::lonmenu::loadevents().  $on_load;
                   4403: 	$attr_ref->{'onunload'}=
                   4404: 	    &Apache::lonmenu::unloadevents().$on_unload;
                   4405:     }
                   4406: 
                   4407: # Accessibility font enhance
                   4408:     if ($env{'browser.fontenhance'} eq 'on') {
                   4409: 	my $style;
                   4410: 	foreach my $key (keys(%{$attr_ref})) {
                   4411: 	    if (lc($key) eq 'style') {
                   4412: 		$style.=$attr_ref->{$key}.';';
                   4413: 		delete($attr_ref->{$key});
                   4414: 	    }
                   4415: 	}
                   4416: 	$attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330     albertel 4417:     }
1.339     albertel 4418: 
                   4419:     if ($env{'browser.blackwhite'} eq 'on') {
                   4420: 	delete($attr_ref->{'font'});
                   4421: 	delete($attr_ref->{'link'});
                   4422: 	delete($attr_ref->{'alink'});
                   4423: 	delete($attr_ref->{'vlink'});
                   4424: 	delete($attr_ref->{'bgcolor'});
                   4425: 	delete($attr_ref->{'background'});
                   4426:     }
                   4427: 
1.330     albertel 4428:     my $attr_string;
                   4429:     foreach my $attr (keys(%$attr_ref)) {
                   4430: 	$attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
                   4431:     }
                   4432:     return $attr_string;
                   4433: }
                   4434: 
                   4435: 
1.182     matthew  4436: ###############################################
1.251     albertel 4437: ###############################################
                   4438: 
                   4439: =pod
                   4440: 
                   4441: =item * &endbodytag()
                   4442: 
                   4443: Returns a uniform footer for LON-CAPA web pages.
                   4444: 
1.635     raeburn  4445: Inputs: 1 - optional reference to an args hash
                   4446: If in the hash, key for noredirectlink has a value which evaluates to true,
                   4447: a 'Continue' link is not displayed if the page contains an
                   4448: internal redirect in the <head></head> section,
                   4449: i.e., $env{'internal.head.redirect'} exists   
1.251     albertel 4450: 
                   4451: =cut
                   4452: 
                   4453: sub endbodytag {
1.635     raeburn  4454:     my ($args) = @_;
1.251     albertel 4455:     my $endbodytag='</body>';
1.269     albertel 4456:     $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315     albertel 4457:     if ( exists( $env{'internal.head.redirect'} ) ) {
1.635     raeburn  4458:         if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
                   4459: 	    $endbodytag=
                   4460: 	        "<br /><a href=\"$env{'internal.head.redirect'}\">".
                   4461: 	        &mt('Continue').'</a>'.
                   4462: 	        $endbodytag;
                   4463:         }
1.315     albertel 4464:     }
1.251     albertel 4465:     return $endbodytag;
                   4466: }
                   4467: 
1.352     albertel 4468: =pod
                   4469: 
                   4470: =item * &standard_css()
                   4471: 
                   4472: Returns a style sheet
                   4473: 
                   4474: Inputs: (all optional)
                   4475:             domain         -> force to color decorate a page for a specific
                   4476:                                domain
                   4477:             function       -> force usage of a specific rolish color scheme
                   4478:             bgcolor        -> override the default page bgcolor
                   4479: 
                   4480: =cut
                   4481: 
1.343     albertel 4482: sub standard_css {
1.345     albertel 4483:     my ($function,$domain,$bgcolor) = @_;
1.352     albertel 4484:     $function  = &get_users_function() if (!$function);
                   4485:     my $img    = &designparm($function.'.img',   $domain);
                   4486:     my $tabbg  = &designparm($function.'.tabbg', $domain);
                   4487:     my $font   = &designparm($function.'.font',  $domain);
1.791   ! tempelho 4488: #second colour for later usage
1.345     albertel 4489:     my $sidebg = &designparm($function.'.sidebg',$domain);
1.382     albertel 4490:     my $pgbg_or_bgcolor =
                   4491: 	         $bgcolor ||
1.352     albertel 4492: 	         &designparm($function.'.pgbg',  $domain);
1.382     albertel 4493:     my $pgbg   = &designparm($function.'.pgbg',  $domain);
1.352     albertel 4494:     my $alink  = &designparm($function.'.alink', $domain);
                   4495:     my $vlink  = &designparm($function.'.vlink', $domain);
                   4496:     my $link   = &designparm($function.'.link',  $domain);
                   4497: 
1.704     muellerd 4498:     my $loginbg = &designparm('login.sidebg',$domain);
1.712     muellerd 4499:     my $bgcol = &designparm('login.bgcol',$domain);
                   4500:     my $textcol = &designparm('login.textcol',$domain);
1.704     muellerd 4501: 
1.602     albertel 4502:     my $sans                 = 'Verdana,Arial,Helvetica,sans-serif';
1.395     albertel 4503:     my $mono                 = 'monospace';
1.352     albertel 4504:     my $data_table_head      = $tabbg;
                   4505:     my $data_table_light     = '#EEEEEE';
1.470     banghart 4506:     my $data_table_dark      = '#DDDDDD';
                   4507:     my $data_table_darker    = '#CCCCCC';
1.349     albertel 4508:     my $data_table_highlight = '#FFFF00';
1.352     albertel 4509:     my $mail_new             = '#FFBB77';
                   4510:     my $mail_new_hover       = '#DD9955';
                   4511:     my $mail_read            = '#BBBB77';
                   4512:     my $mail_read_hover      = '#999944';
                   4513:     my $mail_replied         = '#AAAA88';
                   4514:     my $mail_replied_hover   = '#888855';
                   4515:     my $mail_other           = '#99BBBB';
                   4516:     my $mail_other_hover     = '#669999';
1.391     albertel 4517:     my $table_header         = '#DDDDDD';
1.489     raeburn  4518:     my $feedback_link_bg     = '#BBBBBB';
1.701     harmsja  4519:     my $lg_border_color	     = '#C8C8C8';
1.392     albertel 4520: 
1.608     albertel 4521:     my $border = ($env{'browser.type'} eq 'explorer' ||
                   4522: 		  $env{'browser.type'} eq 'safari'     ) ? '0px 2px 0px 2px'
                   4523: 	                                                 : '0px 3px 0px 4px';
1.448     albertel 4524: 
1.523     albertel 4525: 
1.343     albertel 4526:     return <<END;
1.698     harmsja  4527: body{
                   4528:      font-family: $sans;
                   4529:      line-height:130%;
1.701     harmsja  4530:      font-size:0.83em;
1.698     harmsja  4531:      color:$font;
                   4532:   }
1.701     harmsja  4533: a:link, a:visited { font-size:100%; }
1.698     harmsja  4534: 
1.779     bisitz   4535: a:focus { color: red; background: yellow }
1.510     albertel 4536: table.thinborder,
                   4537: table.thinborder tr th {
                   4538:   border-style: solid;
                   4539:   border-width: 1px;
1.698     harmsja  4540:   border-color: $lg_border_color;
1.510     albertel 4541:   background: $tabbg;
                   4542: }
1.523     albertel 4543: table.thinborder tr td {
1.510     albertel 4544:   border-style: solid;
1.698     harmsja  4545:   border-width: 1px;
                   4546:   border-color: $lg_border_color;
1.510     albertel 4547: }
1.426     albertel 4548: 
1.343     albertel 4549: form, .inline { display: inline; }
1.721     harmsja  4550: 
                   4551: .LC_right {text-align:right;}
                   4552: .LC_middle {vertical-align:middle;}
                   4553: 
                   4554: /* just for tests */
1.754     droeschl 4555: .LC_400Box {width:400px; }
1.721     harmsja  4556: /* end */
                   4557: 
1.778     bisitz   4558: .LC_filename {
                   4559:   font-family: $mono;
                   4560:   white-space:pre;
                   4561: }
                   4562: 
                   4563: .LC_fileicon {
                   4564:   border: none;
                   4565:   height: 1.3em;
                   4566:   vertical-align: text-bottom;
                   4567:   margin-right: 0.3em;
                   4568:   text-decoration:none;
                   4569: }
                   4570: 
1.350     albertel 4571: .LC_error {
                   4572:   color: red;
                   4573:   font-size: larger;
                   4574: }
1.457     albertel 4575: .LC_warning,
                   4576: .LC_diff_removed {
1.733     bisitz   4577:   color: red;
1.394     albertel 4578: }
1.532     albertel 4579: 
                   4580: .LC_info,
1.457     albertel 4581: .LC_success,
                   4582: .LC_diff_added {
1.350     albertel 4583:   color: green;
                   4584: }
1.543     albertel 4585: .LC_unknown {
                   4586:   color: yellow;
                   4587: }
                   4588: 
1.440     albertel 4589: .LC_icon {
1.771     droeschl 4590:   border: none;
1.790     droeschl 4591:   vertical-align: middle;
1.771     droeschl 4592: }
                   4593: 
1.539     albertel 4594: .LC_indexer_icon {
                   4595:   border: 0px;
                   4596:   height: 22px;
                   4597: }
1.543     albertel 4598: .LC_docs_spacer {
                   4599:   width: 25px;
                   4600:   height: 1px;
1.771     droeschl 4601:   border: none;
1.543     albertel 4602: }
1.346     albertel 4603: 
1.532     albertel 4604: .LC_internal_info {
1.735     bisitz   4605:   color: #999999;
1.532     albertel 4606: }
                   4607: 
1.458     albertel 4608: table.LC_pastsubmission {
                   4609:   border: 1px solid black;
                   4610:   margin: 2px;
                   4611: }
                   4612: 
1.606     albertel 4613: table#LC_top_nav, table#LC_menubuttons,table#LC_nav_location {
1.345     albertel 4614:   width: 100%;
                   4615:   background: $pgbg;
1.392     albertel 4616:   border: 2px;
1.402     albertel 4617:   border-collapse: separate;
1.403     albertel 4618:   padding: 0px;
1.345     albertel 4619: }
1.392     albertel 4620: 
1.779     bisitz   4621: table#LC_title_bar, table.LC_breadcrumbs,
1.393     albertel 4622: table#LC_title_bar.LC_with_remote {
1.359     albertel 4623:   width: 100%;
1.392     albertel 4624:   border-color: $pgbg;
                   4625:   border-style: solid;
                   4626:   border-width: $border;
                   4627: 
1.379     albertel 4628:   background: $pgbg;
                   4629:   font-family: $sans;
1.392     albertel 4630:   border-collapse: collapse;
1.403     albertel 4631:   padding: 0px;
1.359     albertel 4632: }
1.409     albertel 4633: table.LC_docs_path {
                   4634:   width: 100%;
                   4635:   border: 0;
                   4636:   background: $pgbg;
                   4637:   font-family: $sans;
                   4638:   border-collapse: collapse;
                   4639:   padding: 0px;
                   4640: }
                   4641: 
1.359     albertel 4642: table#LC_title_bar td {
                   4643:   background: $tabbg;
                   4644: }
1.773     ehlerst  4645: table#LC_title_bar .LC_title_bar_who {
1.359     albertel 4646:   background: $tabbg;
                   4647:   color: $font;
1.427     albertel 4648:   font: small $sans;
1.359     albertel 4649:   text-align: right;
1.773     ehlerst  4650:   margin: 0px;
                   4651: }
                   4652: table#LC_title_bar .LC_title_bar_name {
                   4653:   margin: 0px;
                   4654: }
                   4655: table#LC_title_bar .LC_title_bar_role {
                   4656:   margin: 0px;
                   4657: }
1.775     bisitz   4658: table#LC_title_bar .LC_title_bar_realm {
1.773     ehlerst  4659:   margin: 0px;
1.359     albertel 4660: }
1.469     banghart 4661: span.LC_metadata {
                   4662:     font-family: $sans;
                   4663: }
1.359     albertel 4664: 
1.706     harmsja  4665: table#LC_menubuttons img{
1.346     albertel 4666:   border: 0px;
                   4667: }
1.345     albertel 4668: table#LC_top_nav td {
                   4669:   background: $tabbg;
1.392     albertel 4670:   border: 0px;
1.407     albertel 4671:   font-size: small;
1.706     harmsja  4672:   vertical-align:top;
                   4673:   padding:2px 5px 2px 5px;
1.345     albertel 4674: }
                   4675: table#LC_top_nav td a, div#LC_top_nav a {
                   4676:   color: $font;
                   4677:   font-family: $sans;
                   4678: }
1.364     albertel 4679: table#LC_top_nav td.LC_top_nav_logo {
                   4680:   background: $tabbg;
1.432     albertel 4681:   text-align: left;
1.408     albertel 4682:   white-space: nowrap;
1.432     albertel 4683:   width: 31px;
1.408     albertel 4684: }
                   4685: table#LC_top_nav td.LC_top_nav_logo img {
1.432     albertel 4686:   border: 0px;
1.408     albertel 4687:   vertical-align: bottom;
1.364     albertel 4688: }
1.777     tempelho 4689: table#LC_top_nav td.LC_top_nav_exit,
1.779     bisitz   4690: table#LC_top_nav td.LC_top_nav_help {
1.777     tempelho 4691:   width: 2.0em;
                   4692: }
1.442     albertel 4693: table#LC_top_nav td.LC_top_nav_login {
                   4694:   width: 4.0em;
                   4695:   text-align: center;
                   4696: }
1.409     albertel 4697: table.LC_breadcrumbs td, table.LC_docs_path td  {
1.357     albertel 4698:   background: $tabbg;
                   4699:   color: $font;
                   4700:   font-family: $sans;
1.358     albertel 4701:   font-size: smaller;
1.357     albertel 4702: }
1.777     tempelho 4703: table.LC_breadcrumbs td.LC_breadcrumbs_component,
                   4704: table.LC_docs_path td.LC_docs_path_component {
1.779     bisitz   4705:   background: $tabbg;
1.777     tempelho 4706:   color: $font;
                   4707:   font-family: $sans;
1.779     bisitz   4708:   font-size: larger;
                   4709:   text-align: right;
1.777     tempelho 4710: }
1.383     albertel 4711: td.LC_table_cell_checkbox {
                   4712:   text-align: center;
                   4713: }
1.779     bisitz   4714: table#LC_mainmenu td.LC_mainmenu_column {
                   4715:     vertical-align: top;
1.777     tempelho 4716: }
1.522     albertel 4717: 
1.705     tempelho 4718: .LC_fontsize_small
                   4719: {
                   4720:  font-size: 70%;
                   4721: }
                   4722: 
                   4723: .LC_fontsize_medium
                   4724: {
                   4725:  font-size: 85%;
                   4726: }
                   4727: 
                   4728: .LC_fontsize_large
                   4729: {
                   4730:  font-size: 120%;
                   4731: }
                   4732: 
1.346     albertel 4733: .LC_menubuttons_inline_text {
                   4734:   color: $font;
                   4735:   font-family: $sans;
1.698     harmsja  4736:   font-size: 90%;
1.701     harmsja  4737:   padding-left:3px;
1.346     albertel 4738: }
                   4739: 
1.526     www      4740: .LC_menubuttons_link {
                   4741:   text-decoration: none;
                   4742: }
1.698     harmsja  4743: /*2008--9-5: new menu style sheet.Changed category*/
1.522     albertel 4744: .LC_menubuttons_category {
1.521     www      4745:   color: $font;
1.526     www      4746:   background: $pgbg;
1.521     www      4747:   font-family: $sans;
                   4748:   font-size: larger;
                   4749:   font-weight: bold;
                   4750: }
                   4751: 
1.346     albertel 4752: td.LC_menubuttons_text {
1.779     bisitz   4753:  	color: $font;
1.346     albertel 4754: }
1.706     harmsja  4755: 
                   4756: 
1.526     www      4757: 
1.346     albertel 4758: .LC_current_location {
                   4759:   font-family: $sans;
                   4760:   background: $tabbg;
                   4761: }
                   4762: .LC_new_mail {
                   4763:   font-family: $sans;
1.634     www      4764:   background: $tabbg;
1.346     albertel 4765:   font-weight: bold;
                   4766: }
1.347     albertel 4767: 
1.526     www      4768: 
1.527     www      4769: .LC_dropadd_labeltext {
                   4770:   font-family: $sans;
                   4771:   text-align: right;
                   4772: }
                   4773: 
                   4774: .LC_preferences_labeltext {
                   4775:   font-family: $sans;
                   4776:   text-align: right;
                   4777: }
                   4778: 
1.666     raeburn  4779: .LC_roleslog_note {
1.701     harmsja  4780:   font-size: small;
1.666     raeburn  4781: }
                   4782: 
1.715     raeburn  4783: .LC_mail_functions {
                   4784:     font-weight: bold;
                   4785: }
                   4786: 
1.440     albertel 4787: table.LC_aboutme_port {
                   4788:   border: 0px;
                   4789:   border-collapse: collapse;
                   4790:   border-spacing: 0px;
                   4791: }
1.349     albertel 4792: table.LC_data_table, table.LC_mail_list {
1.347     albertel 4793:   border: 1px solid #000000;
1.402     albertel 4794:   border-collapse: separate;
1.426     albertel 4795:   border-spacing: 1px;
1.610     albertel 4796:   background: $pgbg;
1.347     albertel 4797: }
1.422     albertel 4798: .LC_data_table_dense {
                   4799:   font-size: small;
                   4800: }
1.507     raeburn  4801: table.LC_nested_outer {
                   4802:   border: 1px solid #000000;
1.589     raeburn  4803:   border-collapse: collapse;
1.507     raeburn  4804:   border-spacing: 0px;
                   4805:   width: 100%;
                   4806: }
                   4807: table.LC_nested {
                   4808:   border: 0px;
1.589     raeburn  4809:   border-collapse: collapse;
1.507     raeburn  4810:   border-spacing: 0px;
                   4811:   width: 100%;
                   4812: }
1.523     albertel 4813: table.LC_data_table tr th, table.LC_calendar tr th, table.LC_mail_list tr th,
                   4814: table.LC_prior_tries tr th {
1.349     albertel 4815:   font-weight: bold;
                   4816:   background-color: $data_table_head;
1.701     harmsja  4817:   font-size:90%;
1.347     albertel 4818: }
1.711     raeburn  4819: table.LC_data_table tr.LC_info_row > td {
1.735     bisitz   4820:   background-color: #CCCCCC;
1.711     raeburn  4821:   font-weight: bold;
                   4822:   text-align: left;
                   4823: }
1.779     bisitz   4824: table.LC_data_table tr.LC_odd_row > td,
1.709     bisitz   4825: table.LC_pick_box tr > td.LC_odd_row,
1.440     albertel 4826: table.LC_aboutme_port tr td {
1.349     albertel 4827:   background-color: $data_table_light;
1.425     albertel 4828:   padding: 2px;
1.347     albertel 4829: }
1.610     albertel 4830: table.LC_data_table tr.LC_even_row > td,
1.709     bisitz   4831: table.LC_pick_box tr > td.LC_even_row,
1.440     albertel 4832: table.LC_aboutme_port tr.LC_even_row td {
1.349     albertel 4833:   background-color: $data_table_dark;
1.709     bisitz   4834:   padding: 2px;
1.347     albertel 4835: }
1.425     albertel 4836: table.LC_data_table tr.LC_data_table_highlight td {
                   4837:   background-color: $data_table_darker;
                   4838: }
1.639     raeburn  4839: table.LC_data_table tr td.LC_leftcol_header {
                   4840:   background-color: $data_table_head;
                   4841:   font-weight: bold;
                   4842: }
1.451     albertel 4843: table.LC_data_table tr.LC_empty_row td,
1.507     raeburn  4844: table.LC_nested tr.LC_empty_row td {
1.347     albertel 4845:   background-color: #FFFFFF;
1.421     albertel 4846:   font-weight: bold;
                   4847:   font-style: italic;
                   4848:   text-align: center;
                   4849:   padding: 8px;
1.347     albertel 4850: }
1.507     raeburn  4851: table.LC_nested tr.LC_empty_row td {
1.465     albertel 4852:   padding: 4ex
                   4853: }
1.507     raeburn  4854: table.LC_nested_outer tr th {
                   4855:   font-weight: bold;
                   4856:   background-color: $data_table_head;
1.701     harmsja  4857:   font-size: small;
1.507     raeburn  4858:   border-bottom: 1px solid #000000;
                   4859: }
                   4860: table.LC_nested_outer tr td.LC_subheader {
                   4861:   background-color: $data_table_head;
                   4862:   font-weight: bold;
                   4863:   font-size: small;
                   4864:   border-bottom: 1px solid #000000;
                   4865:   text-align: right;
1.451     albertel 4866: }
1.507     raeburn  4867: table.LC_nested tr.LC_info_row td {
1.735     bisitz   4868:   background-color: #CCCCCC;
1.451     albertel 4869:   font-weight: bold;
                   4870:   font-size: small;
1.507     raeburn  4871:   text-align: center;
                   4872: }
1.589     raeburn  4873: table.LC_nested tr.LC_info_row td.LC_left_item,
                   4874: table.LC_nested_outer tr th.LC_left_item {
1.507     raeburn  4875:   text-align: left;
1.451     albertel 4876: }
1.507     raeburn  4877: table.LC_nested td {
1.735     bisitz   4878:   background-color: #FFFFFF;
1.451     albertel 4879:   font-size: small;
1.507     raeburn  4880: }
                   4881: table.LC_nested_outer tr th.LC_right_item,
                   4882: table.LC_nested tr.LC_info_row td.LC_right_item,
                   4883: table.LC_nested tr.LC_odd_row td.LC_right_item,
                   4884: table.LC_nested tr td.LC_right_item {
1.451     albertel 4885:   text-align: right;
                   4886: }
                   4887: 
1.507     raeburn  4888: table.LC_nested tr.LC_odd_row td {
1.735     bisitz   4889:   background-color: #EEEEEE;
1.451     albertel 4890: }
                   4891: 
1.473     raeburn  4892: table.LC_createuser {
                   4893: }
                   4894: 
                   4895: table.LC_createuser tr.LC_section_row td {
1.701     harmsja  4896:   font-size: small;
1.473     raeburn  4897: }
                   4898: 
                   4899: table.LC_createuser tr.LC_info_row td  {
1.735     bisitz   4900:   background-color: #CCCCCC;
1.473     raeburn  4901:   font-weight: bold;
                   4902:   text-align: center;
                   4903: }
                   4904: 
1.349     albertel 4905: table.LC_calendar {
                   4906:   border: 1px solid #000000;
                   4907:   border-collapse: collapse;
                   4908: }
                   4909: table.LC_calendar_pickdate {
                   4910:   font-size: xx-small;
                   4911: }
                   4912: table.LC_calendar tr td {
                   4913:   border: 1px solid #000000;
                   4914:   vertical-align: top;
                   4915: }
                   4916: table.LC_calendar tr td.LC_calendar_day_empty {
                   4917:   background-color: $data_table_dark;
                   4918: }
1.779     bisitz   4919: table.LC_calendar tr td.LC_calendar_day_current {
                   4920:   background-color: $data_table_highlight;
1.777     tempelho 4921: }
1.349     albertel 4922: table.LC_mail_list tr.LC_mail_new {
                   4923:   background-color: $mail_new;
                   4924: }
                   4925: table.LC_mail_list tr.LC_mail_new:hover {
                   4926:   background-color: $mail_new_hover;
                   4927: }
1.777     tempelho 4928: table.LC_mail_list tr.LC_mail_even{
                   4929: }
                   4930: table.LC_mail_list tr.LC_mail_odd{
                   4931: }
1.349     albertel 4932: table.LC_mail_list tr.LC_mail_read {
                   4933:   background-color: $mail_read;
                   4934: }
                   4935: table.LC_mail_list tr.LC_mail_read:hover {
                   4936:   background-color: $mail_read_hover;
                   4937: }
                   4938: table.LC_mail_list tr.LC_mail_replied {
                   4939:   background-color: $mail_replied;
                   4940: }
                   4941: table.LC_mail_list tr.LC_mail_replied:hover {
                   4942:   background-color: $mail_replied_hover;
                   4943: }
                   4944: table.LC_mail_list tr.LC_mail_other {
                   4945:   background-color: $mail_other;
                   4946: }
                   4947: table.LC_mail_list tr.LC_mail_other:hover {
                   4948:   background-color: $mail_other_hover;
                   4949: }
1.494     raeburn  4950: 
1.777     tempelho 4951: table.LC_data_table tr > td.LC_browser_file,
                   4952: table.LC_data_table tr > td.LC_browser_file_published {
1.389     albertel 4953:   background: #CCFF88;
                   4954: }
1.777     tempelho 4955: table.LC_data_table tr > td.LC_browser_file_locked,
                   4956: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389     albertel 4957:   background: #FFAA99;
1.387     albertel 4958: }
1.777     tempelho 4959: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.779     bisitz   4960:   background: #AAAAAA;
                   4961: }
1.777     tempelho 4962: table.LC_data_table tr > td.LC_browser_file_modified,
1.779     bisitz   4963: table.LC_data_table tr > td.LC_browser_file_metamodified {
                   4964:   background: #FFFF77;
1.777     tempelho 4965: }
1.696     bisitz   4966: table.LC_data_table tr.LC_browser_folder > td {
1.389     albertel 4967:   background: #CCCCFF;
1.387     albertel 4968: }
1.696     bisitz   4969: 
1.707     bisitz   4970: table.LC_data_table tr > td.LC_roles_is {
                   4971: /*  background: #77FF77; */
                   4972: }
                   4973: table.LC_data_table tr > td.LC_roles_future {
                   4974:   background: #FFFF77;
                   4975: }
                   4976: table.LC_data_table tr > td.LC_roles_will {
                   4977:   background: #FFAA77;
                   4978: }
                   4979: table.LC_data_table tr > td.LC_roles_expired {
                   4980:   background: #FF7777;
                   4981: }
                   4982: table.LC_data_table tr > td.LC_roles_will_not {
                   4983:   background: #AAFF77;
                   4984: }
                   4985: table.LC_data_table tr > td.LC_roles_selected {
                   4986:   background: #11CC55;
                   4987: }
                   4988: 
1.388     albertel 4989: span.LC_current_location {
1.701     harmsja  4990:   font-size:larger;
1.388     albertel 4991:   background: $pgbg;
                   4992: }
1.387     albertel 4993: 
1.395     albertel 4994: span.LC_parm_menu_item {
                   4995:   font-size: larger;
                   4996:   font-family: $sans;
                   4997: }
                   4998: span.LC_parm_scope_all {
                   4999:   color: red;
                   5000: }
                   5001: span.LC_parm_scope_folder {
                   5002:   color: green;
                   5003: }
                   5004: span.LC_parm_scope_resource {
                   5005:   color: orange;
                   5006: }
                   5007: span.LC_parm_part {
                   5008:   color: blue;
                   5009: }
                   5010: span.LC_parm_folder, span.LC_parm_symb {
                   5011:   font-size: x-small;
                   5012:   font-family: $mono;
                   5013:   color: #AAAAAA;
                   5014: }
                   5015: 
1.396     albertel 5016: td.LC_parm_overview_level_menu, td.LC_parm_overview_map_menu,
1.777     tempelho 5017: td.LC_parm_overview_parm_selectors,td.LC_parm_overview_restrictions  {
1.396     albertel 5018:   border: 1px solid black;
                   5019:   border-collapse: collapse;
                   5020: }
                   5021: table.LC_parm_overview_restrictions td {
                   5022:   border-width: 1px 4px 1px 4px;
                   5023:   border-style: solid;
                   5024:   border-color: $pgbg;
                   5025:   text-align: center;
                   5026: }
                   5027: table.LC_parm_overview_restrictions th {
                   5028:   background: $tabbg;
                   5029:   border-width: 1px 4px 1px 4px;
                   5030:   border-style: solid;
                   5031:   border-color: $pgbg;
                   5032: }
1.398     albertel 5033: table#LC_helpmenu {
                   5034:   border: 0px;
                   5035:   height: 55px;
                   5036:   border-spacing: 0px;
                   5037: }
                   5038: 
                   5039: table#LC_helpmenu fieldset legend {
                   5040:   font-size: larger;
                   5041:   font-weight: bold;
                   5042: }
1.397     albertel 5043: table#LC_helpmenu_links {
                   5044:   width: 100%;
                   5045:   border: 1px solid black;
                   5046:   background: $pgbg;
                   5047:   padding: 0px;
                   5048:   border-spacing: 1px;
                   5049: }
                   5050: table#LC_helpmenu_links tr td {
                   5051:   padding: 1px;
                   5052:   background: $tabbg;
1.399     albertel 5053:   text-align: center;
                   5054:   font-weight: bold;
1.397     albertel 5055: }
1.396     albertel 5056: 
1.397     albertel 5057: table#LC_helpmenu_links a:link, table#LC_helpmenu_links a:visited,
                   5058: table#LC_helpmenu_links a:active {
                   5059:   text-decoration: none;
                   5060:   color: $font;
                   5061: }
                   5062: table#LC_helpmenu_links a:hover {
                   5063:   text-decoration: underline;
                   5064:   color: $vlink;
                   5065: }
1.396     albertel 5066: 
1.417     albertel 5067: .LC_chrt_popup_exists {
                   5068:   border: 1px solid #339933;
                   5069:   margin: -1px;
                   5070: }
                   5071: .LC_chrt_popup_up {
                   5072:   border: 1px solid yellow;
                   5073:   margin: -1px;
                   5074: }
                   5075: .LC_chrt_popup {
                   5076:   border: 1px solid #8888FF;
                   5077:   background: #CCCCFF;
                   5078: }
1.421     albertel 5079: table.LC_pick_box {
                   5080:   border-collapse: separate;
                   5081:   background: white;
                   5082:   border: 1px solid black;
                   5083:   border-spacing: 1px;
                   5084: }
                   5085: table.LC_pick_box td.LC_pick_box_title {
                   5086:   background: $tabbg;
                   5087:   font-weight: bold;
                   5088:   text-align: right;
1.740     bisitz   5089:   vertical-align: top;
1.421     albertel 5090:   width: 184px;
                   5091:   padding: 8px;
                   5092: }
1.645     raeburn  5093: table.LC_pick_box td.LC_selfenroll_pick_box_title {
                   5094:   background: $tabbg;
                   5095:   font-weight: bold;
                   5096:   text-align: right;
                   5097:   width: 350px;
                   5098:   padding: 8px;
                   5099: }
                   5100: 
1.579     raeburn  5101: table.LC_pick_box td.LC_pick_box_value {
                   5102:   text-align: left;
                   5103:   padding: 8px;
                   5104: }
                   5105: table.LC_pick_box td.LC_pick_box_select {
                   5106:   text-align: left;
                   5107:   padding: 8px;
                   5108: }
1.424     albertel 5109: table.LC_pick_box td.LC_pick_box_separator {
1.421     albertel 5110:   padding: 0px;
                   5111:   height: 1px;
                   5112:   background: black;
                   5113: }
                   5114: table.LC_pick_box td.LC_pick_box_submit {
                   5115:   text-align: right;
                   5116: }
1.579     raeburn  5117: table.LC_pick_box td.LC_evenrow_value {
                   5118:   text-align: left;
                   5119:   padding: 8px;
                   5120:   background-color: $data_table_light;
                   5121: }
                   5122: table.LC_pick_box td.LC_oddrow_value {
                   5123:   text-align: left;
                   5124:   padding: 8px;
                   5125:   background-color: $data_table_light;
                   5126: }
                   5127: table.LC_helpform_receipt {
                   5128:   width: 620px;
                   5129:   border-collapse: separate;
                   5130:   background: white;
                   5131:   border: 1px solid black;
                   5132:   border-spacing: 1px;
                   5133: }
                   5134: table.LC_helpform_receipt td.LC_pick_box_title {
                   5135:   background: $tabbg;
                   5136:   font-weight: bold;
                   5137:   text-align: right;
                   5138:   width: 184px;
                   5139:   padding: 8px;
                   5140: }
                   5141: table.LC_helpform_receipt td.LC_evenrow_value {
                   5142:   text-align: left;
                   5143:   padding: 8px;
                   5144:   background-color: $data_table_light;
                   5145: }
                   5146: table.LC_helpform_receipt td.LC_oddrow_value {
                   5147:   text-align: left;
                   5148:   padding: 8px;
                   5149:   background-color: $data_table_light;
                   5150: }
                   5151: table.LC_helpform_receipt td.LC_pick_box_separator {
                   5152:   padding: 0px;
                   5153:   height: 1px;
                   5154:   background: black;
                   5155: }
                   5156: span.LC_helpform_receipt_cat {
                   5157:   font-weight: bold;
                   5158: }
1.424     albertel 5159: table.LC_group_priv_box {
                   5160:   background: white;
                   5161:   border: 1px solid black;
                   5162:   border-spacing: 1px;
                   5163: }
                   5164: table.LC_group_priv_box td.LC_pick_box_title {
                   5165:   background: $tabbg;
                   5166:   font-weight: bold;
                   5167:   text-align: right;
                   5168:   width: 184px;
                   5169: }
                   5170: table.LC_group_priv_box td.LC_groups_fixed {
                   5171:   background: $data_table_light;
                   5172:   text-align: center;
                   5173: }
                   5174: table.LC_group_priv_box td.LC_groups_optional {
                   5175:   background: $data_table_dark;
                   5176:   text-align: center;
                   5177: }
                   5178: table.LC_group_priv_box td.LC_groups_functionality {
                   5179:   background: $data_table_darker;
                   5180:   text-align: center;
                   5181:   font-weight: bold;
                   5182: }
                   5183: table.LC_group_priv td {
                   5184:   text-align: left;
                   5185:   padding: 0px;
                   5186: }
                   5187: 
1.421     albertel 5188: table.LC_notify_front_page {
                   5189:   background: white;
                   5190:   border: 1px solid black;
                   5191:   padding: 8px;
                   5192: }
                   5193: table.LC_notify_front_page td {
                   5194:   padding: 8px;
                   5195: }
1.424     albertel 5196: .LC_navbuttons {
                   5197:   margin: 2ex 0ex 2ex 0ex;
                   5198: }
1.423     albertel 5199: .LC_topic_bar {
                   5200:   font-family: $sans;
                   5201:   font-weight: bold;
                   5202:   width: 100%;
                   5203:   background: $tabbg;
                   5204:   vertical-align: middle;
                   5205:   margin: 2ex 0ex 2ex 0ex;
                   5206: }
                   5207: .LC_topic_bar span {
                   5208:   vertical-align: middle;
                   5209: }
                   5210: .LC_topic_bar img {
                   5211:   vertical-align: bottom;
                   5212: }
                   5213: table.LC_course_group_status {
                   5214:   margin: 20px;
                   5215: }
                   5216: table.LC_status_selector td {
                   5217:   vertical-align: top;
                   5218:   text-align: center;
1.424     albertel 5219:   padding: 4px;
                   5220: }
                   5221: table.LC_descriptive_input td.LC_description {
                   5222:   vertical-align: top;
                   5223:   text-align: right;
                   5224:   font-weight: bold;
1.423     albertel 5225: }
1.599     albertel 5226: div.LC_feedback_link {
1.616     albertel 5227:   clear: both;
1.599     albertel 5228:   background: white;
1.779     bisitz   5229:   width: 100%;
1.489     raeburn  5230: }
                   5231: span.LC_feedback_link {
1.599     albertel 5232:   background: $feedback_link_bg;
                   5233:   font-size: larger;
                   5234: }
                   5235: span.LC_message_link {
                   5236:   background: $feedback_link_bg;
                   5237:   font-size: larger;
                   5238:   position: absolute;
                   5239:   right: 1em;
1.489     raeburn  5240: }
1.421     albertel 5241: 
1.515     albertel 5242: table.LC_prior_tries {
1.524     albertel 5243:   border: 1px solid #000000;
                   5244:   border-collapse: separate;
                   5245:   border-spacing: 1px;
1.515     albertel 5246: }
1.523     albertel 5247: 
1.515     albertel 5248: table.LC_prior_tries td {
1.524     albertel 5249:   padding: 2px;
1.515     albertel 5250: }
1.523     albertel 5251: 
                   5252: .LC_answer_correct {
                   5253:   background: #AAFFAA;
                   5254:   color: black;
                   5255: }
                   5256: .LC_answer_charged_try {
                   5257:   background: #FFAAAA ! important;
                   5258:   color: black;
                   5259: }
1.779     bisitz   5260: .LC_answer_not_charged_try,
1.523     albertel 5261: .LC_answer_no_grade,
                   5262: .LC_answer_late {
                   5263:   background: #FFFFAA;
                   5264:   color: black;
                   5265: }
                   5266: .LC_answer_previous {
                   5267:   background: #AAAAFF;
                   5268:   color: black;
                   5269: }
1.779     bisitz   5270: .LC_answer_no_message {
1.777     tempelho 5271:   background: #FFFFFF;
                   5272:   color: black;
1.779     bisitz   5273: }
                   5274: .LC_answer_unknown {
                   5275:   background: orange;
                   5276:   color: black;
1.777     tempelho 5277: }
1.529     albertel 5278: span.LC_prior_numerical,
                   5279: span.LC_prior_string,
                   5280: span.LC_prior_custom,
                   5281: span.LC_prior_reaction,
                   5282: span.LC_prior_math {
1.523     albertel 5283:   font-family: monospace;
                   5284:   white-space: pre;
                   5285: }
                   5286: 
1.525     albertel 5287: span.LC_prior_string {
                   5288:   font-family: monospace;
                   5289:   white-space: pre;
                   5290: }
                   5291: 
1.523     albertel 5292: table.LC_prior_option {
                   5293:   width: 100%;
                   5294:   border-collapse: collapse;
                   5295: }
1.528     albertel 5296: table.LC_prior_rank, table.LC_prior_match {
                   5297:   border-collapse: collapse;
                   5298: }
                   5299: table.LC_prior_option tr td,
                   5300: table.LC_prior_rank tr td,
                   5301: table.LC_prior_match tr td {
1.524     albertel 5302:   border: 1px solid #000000;
1.515     albertel 5303: }
                   5304: 
1.770     droeschl 5305: td.LC_nobreak,
1.519     raeburn  5306: span.LC_nobreak {
1.544     albertel 5307:   white-space: nowrap;
1.519     raeburn  5308: }
                   5309: 
1.576     raeburn  5310: span.LC_cusr_emph {
                   5311:   font-style: italic;
                   5312: }
                   5313: 
1.633     raeburn  5314: span.LC_cusr_subheading {
                   5315:   font-weight: normal;
                   5316:   font-size: 85%;
                   5317: }
                   5318: 
1.545     albertel 5319: table.LC_docs_documents {
                   5320:   background: #BBBBBB;
1.547     albertel 5321:   border-width: 0px;
1.545     albertel 5322:   border-collapse: collapse;
                   5323: }
1.777     tempelho 5324: table.LC_docs_documents td.LC_docs_document {
1.779     bisitz   5325:   border: 2px solid black;
                   5326:   padding: 4px;
1.777     tempelho 5327: }
1.545     albertel 5328: .LC_docs_entry_move {
                   5329:   border: 0px;
                   5330:   border-collapse: collapse;
1.544     albertel 5331: }
                   5332: 
1.545     albertel 5333: .LC_docs_entry_move td {
                   5334:   border: 2px solid #BBBBBB;
                   5335:   background: #DDDDDD;
                   5336: }
                   5337: 
                   5338: .LC_docs_editor td.LC_docs_entry_commands {
                   5339:   background: #DDDDDD;
                   5340:   font-size: x-small;
                   5341: }
1.544     albertel 5342: .LC_docs_copy {
1.545     albertel 5343:   color: #000099;
1.544     albertel 5344: }
                   5345: .LC_docs_cut {
1.545     albertel 5346:   color: #550044;
1.544     albertel 5347: }
                   5348: .LC_docs_rename {
1.545     albertel 5349:   color: #009900;
1.544     albertel 5350: }
                   5351: .LC_docs_remove {
1.545     albertel 5352:   color: #990000;
                   5353: }
                   5354: 
1.547     albertel 5355: .LC_docs_reinit_warn,
                   5356: .LC_docs_ext_edit {
                   5357:   font-size: x-small;
                   5358: }
                   5359: 
1.545     albertel 5360: .LC_docs_editor td.LC_docs_entry_title,
                   5361: .LC_docs_editor td.LC_docs_entry_icon {
                   5362:   background: #FFFFBB;
                   5363: }
                   5364: .LC_docs_editor td.LC_docs_entry_parameter {
                   5365:   background: #BBBBFF;
                   5366:   font-size: x-small;
                   5367:   white-space: nowrap;
                   5368: }
                   5369: 
                   5370: table.LC_docs_adddocs td,
                   5371: table.LC_docs_adddocs th {
                   5372:   border: 1px solid #BBBBBB;
                   5373:   padding: 4px;
                   5374:   background: #DDDDDD;
1.543     albertel 5375: }
                   5376: 
1.584     albertel 5377: table.LC_sty_begin {
                   5378:   background: #BBFFBB;
                   5379: }
                   5380: table.LC_sty_end {
                   5381:   background: #FFBBBB;
                   5382: }
                   5383: 
1.589     raeburn  5384: table.LC_double_column {
                   5385:   border-width: 0px;
                   5386:   border-collapse: collapse;
                   5387:   width: 100%;
                   5388:   padding: 2px;
                   5389: }
                   5390: 
                   5391: table.LC_double_column tr td.LC_left_col {
1.590     raeburn  5392:   top: 2px;
1.589     raeburn  5393:   left: 2px;
                   5394:   width: 47%;
                   5395:   vertical-align: top;
                   5396: }
                   5397: 
                   5398: table.LC_double_column tr td.LC_right_col {
                   5399:   top: 2px;
1.779     bisitz   5400:   right: 2px;
1.589     raeburn  5401:   width: 47%;
                   5402:   vertical-align: top;
                   5403: }
                   5404: 
1.594     raeburn  5405: span.LC_role_level {
                   5406:   font-weight: bold;
                   5407: }
                   5408: 
1.591     raeburn  5409: div.LC_left_float {
                   5410:   float: left;
                   5411:   padding-right: 5%;
1.597     albertel 5412:   padding-bottom: 4px;
1.591     raeburn  5413: }
                   5414: 
                   5415: div.LC_clear_float_header {
1.597     albertel 5416:   padding-bottom: 2px;
1.591     raeburn  5417: }
                   5418: 
                   5419: div.LC_clear_float_footer {
1.597     albertel 5420:   padding-top: 10px;
1.591     raeburn  5421:   clear: both;
                   5422: }
                   5423: 
1.597     albertel 5424: 
                   5425: div.LC_grade_show_user {
                   5426:   margin-top: 20px;
                   5427:   border: 1px solid black;
                   5428: }
                   5429: div.LC_grade_user_name {
                   5430:   background: #DDDDEE;
                   5431:   border-bottom: 1px solid black;
1.705     tempelho 5432:   font-weight: bold;
                   5433:   font-size: large;
1.597     albertel 5434: }
                   5435: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
                   5436:   background: #DDEEDD;
                   5437: }
                   5438: 
                   5439: div.LC_grade_show_problem,
                   5440: div.LC_grade_submissions,
                   5441: div.LC_grade_message_center,
                   5442: div.LC_grade_info_links,
                   5443: div.LC_grade_assign {
                   5444:   margin: 5px;
                   5445:   width: 99%;
                   5446:   background: #FFFFFF;
                   5447: }
                   5448: div.LC_grade_show_problem_header,
                   5449: div.LC_grade_submissions_header,
                   5450: div.LC_grade_message_center_header,
                   5451: div.LC_grade_assign_header {
1.705     tempelho 5452:   font-weight: bold;
                   5453:   font-size: large;
1.597     albertel 5454: }
                   5455: div.LC_grade_show_problem_problem,
                   5456: div.LC_grade_submissions_body,
                   5457: div.LC_grade_message_center_body,
                   5458: div.LC_grade_assign_body {
                   5459:   border: 1px solid black;
                   5460:   width: 99%;
                   5461:   background: #FFFFFF;
                   5462: }
1.598     albertel 5463: span.LC_grade_check_note {
1.705     tempelho 5464:   font-weight: normal;
                   5465:   font-size: medium;
1.598     albertel 5466:   display: inline;
                   5467:   position: absolute;
                   5468:   right: 1em;
                   5469: }
1.597     albertel 5470: 
1.613     albertel 5471: table.LC_scantron_action {
                   5472:   width: 100%;
                   5473: }
                   5474: table.LC_scantron_action tr th {
1.698     harmsja  5475:   font-weight:bold;
                   5476:   font-style:normal;
1.613     albertel 5477: }
1.779     bisitz   5478: .LC_edit_problem_header,
1.614     albertel 5479: div.LC_edit_problem_footer {
1.705     tempelho 5480:   font-weight: normal;
                   5481:   font-size:  medium;
1.602     albertel 5482:   margin: 2px;
1.600     albertel 5483: }
                   5484: div.LC_edit_problem_header,
1.602     albertel 5485: div.LC_edit_problem_header div,
1.614     albertel 5486: div.LC_edit_problem_footer,
                   5487: div.LC_edit_problem_footer div,
1.602     albertel 5488: div.LC_edit_problem_editxml_header,
                   5489: div.LC_edit_problem_editxml_header div {
1.600     albertel 5490:   margin-top: 5px;
                   5491: }
1.602     albertel 5492: div.LC_edit_problem_header_edit_row {
                   5493:   background: $tabbg;
                   5494:   padding: 3px;
                   5495:   margin-bottom: 5px;
                   5496: }
1.600     albertel 5497: div.LC_edit_problem_header_title {
1.705     tempelho 5498:   font-weight: bold;
                   5499:   font-size: larger;
1.602     albertel 5500:   background: $tabbg;
                   5501:   padding: 3px;
                   5502: }
                   5503: table.LC_edit_problem_header_title {
1.705     tempelho 5504:   font-size: larger;
                   5505:   font-weight:  bold;
1.602     albertel 5506:   width: 100%;
                   5507:   border-color: $pgbg;
                   5508:   border-style: solid;
                   5509:   border-width: $border;
                   5510: 
1.600     albertel 5511:   background: $tabbg;
1.602     albertel 5512:   border-collapse: collapse;
                   5513:   padding: 0px
                   5514: }
                   5515: 
                   5516: div.LC_edit_problem_discards {
                   5517:   float: left;
                   5518:   padding-bottom: 5px;
                   5519: }
                   5520: div.LC_edit_problem_saves {
                   5521:   float: right;
                   5522:   padding-bottom: 5px;
1.600     albertel 5523: }
                   5524: hr.LC_edit_problem_divide {
1.602     albertel 5525:   clear: both;
1.600     albertel 5526:   color: $tabbg;
                   5527:   background-color: $tabbg;
                   5528:   height: 3px;
                   5529:   border: 0px;
                   5530: }
1.679     riegler  5531: img.stift{
1.678     riegler  5532:   border-width:0;
1.679     riegler  5533:   vertical-align:middle;
1.677     riegler  5534: }
1.680     riegler  5535: 
1.681     riegler  5536: table#LC_mainmenu{
                   5537:  margin-top:10px;
                   5538:  width:80%;
                   5539: 
                   5540: }
                   5541: 
1.680     riegler  5542: table#LC_mainmenu td.LC_mainmenu_col_fieldset{
                   5543:   vertical-align: top;
                   5544:   width: 45%;
                   5545: }
1.779     bisitz   5546: .LC_mainmenu_fieldset_category {
                   5547:   color: $font;
                   5548:   background: $pgbg;
                   5549:   font-family: $sans;
                   5550:   font-size: small;
                   5551:   font-weight: bold;
1.777     tempelho 5552: }
1.716     raeburn  5553: div.LC_createcourse {
                   5554:     margin: 10px 10px 10px 10px;
                   5555: }
                   5556: 
1.693     droeschl 5557: /* ---- Remove when done ----
                   5558: # The following styles is part of the redesign of LON-CAPA and are
                   5559: # subject to change during this project.
                   5560: # Don't rely on their current functionality as they might be 
                   5561: # changed or removed.
                   5562: # --------------------------*/
                   5563: 
1.698     harmsja  5564: a:hover,
1.721     harmsja  5565: ol.LC_smallMenu a:hover,
                   5566: ol#LC_MenuBreadcrumbs a:hover,
                   5567: ol#LC_PathBreadcrumbs a:hover,
                   5568: ul#LC_TabMainMenuContent a:hover,
                   5569: .LC_FormSectionClearButton input:hover
                   5570: ul.LC_TabContent   li:hover a{
1.698     harmsja  5571: 	color:#BF2317;
                   5572:         text-decoration:none;
1.693     droeschl 5573: }
                   5574: 
1.779     bisitz   5575: h1 {
1.721     harmsja  5576: 	padding:5px 10px 5px 20px;
1.693     droeschl 5577: 	line-height:130%;
                   5578: }
1.698     harmsja  5579: 
1.693     droeschl 5580: h2,h3,h4,h5,h6
                   5581: {
1.721     harmsja  5582: 	margin:5px 0px 5px 0px;
                   5583: 	padding:0px;
                   5584: 	line-height:130%;
1.693     droeschl 5585: }
1.721     harmsja  5586: .LC_hcell{
1.698     harmsja  5587:         padding:3px 15px 3px 15px;
                   5588:         margin:0px;
1.703     harmsja  5589: 	background-color:$tabbg;
1.779     bisitz   5590: 	border-bottom:solid 1px $lg_border_color;
1.693     droeschl 5591: }
1.721     harmsja  5592: .LC_noBorder {
1.698     harmsja  5593:         border:0px;
                   5594: }
1.693     droeschl 5595: 
                   5596: 
1.698     harmsja  5597: /* Main Header with discription of Person, Course, etc. */
1.693     droeschl 5598: 
1.761     tempelho 5599: .LC_Right {
                   5600:         float: right;
                   5601:         margin: 0px;
                   5602:         padding: 0px;
                   5603: }
                   5604: 
1.721     harmsja  5605: p, .LC_ContentBox {
1.698     harmsja  5606: 	padding: 10px;
                   5607: 
                   5608: }
1.721     harmsja  5609: .LC_FormSectionClearButton input {
1.779     bisitz   5610:         background-color:transparent;
1.698     harmsja  5611:         border:0px;
                   5612:         cursor:pointer;
                   5613:         text-decoration:underline;
1.693     droeschl 5614: }
1.763     bisitz   5615: 
                   5616: .LC_help_open_topic {
                   5617:         color: #FFFFFF;
                   5618:         background-color: #EEEEFF;
                   5619:         margin: 1px;
                   5620:         padding: 4px;
                   5621:         border: 1px solid #000033;
                   5622:         white-space: nowrap;
1.783     amueller 5623: /*		vertical-align: middle; */
1.759     neumanie 5624: }
1.693     droeschl 5625: 
1.698     harmsja  5626: dl,ul,div,fieldset {
                   5627: 	margin: 10px 10px 10px 0px;
1.693     droeschl 5628: 	overflow:hidden;
                   5629: }
1.721     harmsja  5630: ol.LC_smallMenu, ol#LC_PathBreadcrumbs {
1.698     harmsja  5631: 	margin: 0px;
1.693     droeschl 5632: }
                   5633: 
1.721     harmsja  5634: ol.LC_smallMenu li {
1.693     droeschl 5635: 	display: inline;
                   5636: 	padding: 5px 5px 0px 10px;
                   5637: 	vertical-align: top;
                   5638: }
                   5639: 
1.721     harmsja  5640: ol.LC_smallMenu li img {
1.693     droeschl 5641: 	vertical-align: bottom;
                   5642: }
                   5643: 
1.721     harmsja  5644: ol.LC_smallMenu a {
1.693     droeschl 5645: 	font-size: 90%;
                   5646: 	color: RGB(80, 80, 80);
                   5647: 	text-decoration: none;
                   5648: }
1.760     harmsja  5649: ol#LC_TabMainMenuContent, ul.LC_TabContent ,
1.741     harmsja  5650: ul.LC_TabContentBigger {
1.721     harmsja  5651: 	display:block;
                   5652: 	list-style:none;
1.741     harmsja  5653: 	margin: 0px;
1.693     droeschl 5654: 	padding: 0px;
                   5655: }
                   5656: 
1.744     ehlerst  5657: ol#LC_TabMainMenuContent li, ul.LC_TabContent li,
1.741     harmsja  5658: ul.LC_TabContentBigger li{
1.693     droeschl 5659: 	display: inline;
1.741     harmsja  5660: 	border-right: solid 1px $lg_border_color;
                   5661: 	float:left;
                   5662: 	line-height:140%;
                   5663: 	white-space:nowrap;
                   5664: }
                   5665: ol#LC_TabMainMenuContent li{
1.693     droeschl 5666: 	vertical-align: bottom;
                   5667: 	border-bottom: solid 1px RGB(175, 175, 175);
1.721     harmsja  5668: 	padding: 5px 10px 5px 10px;
1.741     harmsja  5669: 	margin-right:5px;
                   5670: 	margin-bottom:3px;
1.693     droeschl 5671: 	font-weight: bold;
1.723     riegler  5672: 	background: url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
1.693     droeschl 5673: }
                   5674: 
1.721     harmsja  5675: ol#LC_TabMainMenuContent li a{
1.693     droeschl 5676: 	color: RGB(47, 47, 47);
                   5677: 	text-decoration: none;
                   5678: }
1.721     harmsja  5679: ul.LC_TabContent {
1.741     harmsja  5680: 	min-height:1.6em;
1.721     harmsja  5681: }
                   5682: ul.LC_TabContent li{
1.741     harmsja  5683: 	vertical-align:middle;
                   5684: 	padding:0px 10px 0px 10px;
1.745     ehlerst  5685: 	background-color:$tabbg;
                   5686: 	border-bottom:solid 1px $lg_border_color;
1.721     harmsja  5687: }
1.779     bisitz   5688: ul.LC_TabContent li a, ul.LC_TabContent li{
1.721     harmsja  5689: 	color:rgb(47,47,47);
                   5690: 	text-decoration:none;
                   5691: 	font-size:95%;
                   5692: 	font-weight:bold;
1.761     tempelho 5693: 	padding-right: 16px;
1.721     harmsja  5694: }
1.744     ehlerst  5695: ul.LC_TabContent li:hover, ul.LC_TabContent li.active{
1.761     tempelho 5696:         background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.745     ehlerst  5697: 	border-bottom:solid 1px #FFFFFF;
1.761     tempelho 5698: 	padding-right: 16px;
1.744     ehlerst  5699: }
1.741     harmsja  5700: ul.LC_TabContentBigger li{
                   5701: 	vertical-align:bottom;
                   5702: 	border-top:solid 1px $lg_border_color;
                   5703: 	border-left:solid 1px $lg_border_color;
                   5704: 	padding:5px 10px 5px 10px;
                   5705: 	margin-left:2px;
                   5706: 	background:url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
                   5707: }
1.744     ehlerst  5708: ul.LC_TabContentBigger li:hover, ul.LC_TabContentBigger li.active{
                   5709: 	background:url(/adm/lonIcons/lightGreyBG.png) repeat-x right bottom;
                   5710: }
1.741     harmsja  5711: ul.LC_TabContentBigger li, ul.LC_TabContentBigger li a{
                   5712: 	font-size:110%;
                   5713: 	font-weight:bold;
                   5714: }
1.693     droeschl 5715: 
1.783     amueller 5716: ol#LC_MenuBreadcrumbs, ol#LC_PathBreadcrumbs, ul.LC_CourseBreadcrumbs{
1.693     droeschl 5717: 	border-top: solid 1px RGB(255, 255, 255);
                   5718: 	height: 20px;
                   5719: 	line-height: 20px;
                   5720: 	vertical-align: bottom;
                   5721: 	margin: 0px 0px 30px 0px;
                   5722: 	padding-left: 10px;
                   5723: 	list-style-position: inside;
1.723     riegler  5724: 	background: url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
1.693     droeschl 5725: }
                   5726: 
1.783     amueller 5727: ol#LC_MenuBreadcrumbs li, ol#LC_PathBreadcrumbs li, ul.LC_CourseBreadcrumbs li {
1.741     harmsja  5728: /*
1.723     riegler  5729: 	background: url(/adm/lonIcons/arrow_white.png) no-repeat left center;
1.779     bisitz   5730: */
1.693     droeschl 5731: 	display: inline;
                   5732: 	padding: 0px 0px 0px 10px;
1.783     amueller 5733: /*	vertical-align: bottom; */
1.693     droeschl 5734: 	overflow:hidden;
                   5735: }
                   5736: 
1.783     amueller 5737: ol#LC_MenuBreadcrumbs li a, ul.LC_CourseBreadcrumbs li a {
1.693     droeschl 5738: 	text-decoration: none;
                   5739: 	font-size:90%;
                   5740: }
1.721     harmsja  5741: ol#LC_PathBreadcrumbs li a{
1.698     harmsja  5742: 	text-decoration:none;
                   5743: 	font-size:100%;
                   5744: 	font-weight:bold;
1.693     droeschl 5745: }
1.786     neumanie 5746: .LC_BoxPadding
                   5747: {
                   5748: 	padding: 10px;
                   5749: }
1.721     harmsja  5750: .LC_ContentBoxSpecial
1.693     droeschl 5751: {
1.701     harmsja  5752: 	border: solid 1px $lg_border_color;
1.746     neumanie 5753: }
                   5754: .LC_ContentBoxSpecialContactInfo
                   5755: {
                   5756: 	border: solid 1px $lg_border_color;
                   5757: 	max-width:25%;
                   5758: 	min-width:25%;
1.698     harmsja  5759: }
1.747     neumanie 5760: .LC_AboutMe_Image
                   5761: {
                   5762: 	float:left;
                   5763: 	margin-right:10px;
                   5764: }
                   5765: .LC_Clear_AboutMe_Image
                   5766: {
                   5767: 	clear:left;
                   5768: }
1.721     harmsja  5769: dl.LC_ListStyleClean dt {
1.693     droeschl 5770: 	padding-right: 5px;
                   5771: 	display: table-header-group;
                   5772: }
                   5773: 
1.721     harmsja  5774: dl.LC_ListStyleClean dd {
1.693     droeschl 5775: 	display: table-row;
                   5776: }
                   5777: 
1.721     harmsja  5778: .LC_ListStyleClean,
                   5779: .LC_ListStyleSimple,
                   5780: .LC_ListStyleNormal,
1.777     tempelho 5781: .LC_ListStyle_Border,
1.721     harmsja  5782: .LC_ListStyleSpecial
1.693     droeschl 5783: 	{
                   5784: 	/*display:block;	*/
                   5785: 	list-style-position: inside;
                   5786: 	list-style-type: none;
                   5787: 	overflow: hidden;
                   5788: 	padding: 0px;
                   5789: }
                   5790: 
1.721     harmsja  5791: .LC_ListStyleSimple li,
                   5792: .LC_ListStyleSimple dd,
                   5793: .LC_ListStyleNormal li,
                   5794: .LC_ListStyleNormal dd,
                   5795: .LC_ListStyleSpecial li,
                   5796: .LC_ListStyleSpecial dd
1.693     droeschl 5797: 	{
                   5798: 	margin: 0px;
                   5799: 	padding: 5px 5px 5px 10px;
                   5800: 	clear: both;
                   5801: }
                   5802: 
1.721     harmsja  5803: .LC_ListStyleClean li,
                   5804: .LC_ListStyleClean dd {
1.693     droeschl 5805: 	padding-top: 0px;
                   5806: 	padding-bottom: 0px;
                   5807: }
                   5808: 
1.721     harmsja  5809: .LC_ListStyleSimple dd,
                   5810: .LC_ListStyleSimple li{
1.698     harmsja  5811: 	border-bottom: solid 1px $lg_border_color;
1.693     droeschl 5812: }
                   5813: 
1.721     harmsja  5814: .LC_ListStyleSpecial li,
                   5815: .LC_ListStyleSpecial dd {
1.693     droeschl 5816: 	list-style-type: none;
                   5817: 	background-color: RGB(220, 220, 220);
                   5818: 	margin-bottom: 4px;
                   5819: }
                   5820: 
1.721     harmsja  5821: table.LC_SimpleTable {
1.698     harmsja  5822: 	margin:5px;
                   5823: 	border:solid 1px $lg_border_color;
1.693     droeschl 5824: 	}
                   5825: 
1.721     harmsja  5826: table.LC_SimpleTable tr {
1.698     harmsja  5827: 	padding:0px;
                   5828: 	border:solid 1px $lg_border_color;
1.693     droeschl 5829: }
1.721     harmsja  5830: table.LC_SimpleTable thead{
1.698     harmsja  5831: 	 background:rgb(220,220,220);
1.693     droeschl 5832: }
                   5833: 
1.721     harmsja  5834: div.LC_columnSection {
1.693     droeschl 5835: 	display: block;
                   5836: 	clear: both;
                   5837: 	overflow: hidden;
                   5838: 	margin:0px;
                   5839: }
                   5840: 
1.721     harmsja  5841: div.LC_columnSection>* {
1.693     droeschl 5842: 	float: left;
                   5843: 	margin: 10px 20px 10px 0px;
1.747     neumanie 5844: 	overflow:hidden;
1.693     droeschl 5845: }
1.721     harmsja  5846: 
1.719     ehlerst  5847: .ContentBoxSpecialTemplate
                   5848: {
1.747     neumanie 5849:         border: solid 1px $lg_border_color;
1.719     ehlerst  5850: }
                   5851: .ContentBoxTemplate {
                   5852:         padding:10px;
                   5853: }
                   5854: 
1.721     harmsja  5855: div.LC_columnSection > .ContentBoxTemplate,
                   5856: div.LC_columnSection > .ContentBoxSpecialTemplate
1.719     ehlerst  5857:         {
                   5858:         width: 600px;
                   5859: }
1.753     droeschl 5860: 
1.720     ehlerst  5861: .clear{
                   5862: 	clear: both;
                   5863: 	line-height: 0px;
                   5864: 	font-size: 0px;
                   5865: 	height: 0px;
                   5866: }
1.693     droeschl 5867: 
1.694     tempelho 5868: .LC_loginpage_container {
                   5869: 	text-align:left;
                   5870: 	margin : 0 auto;
1.785     tempelho 5871: 	width:90%;
1.694     tempelho 5872: 	padding: 10px;
                   5873: 	height: auto;
1.712     muellerd 5874: 	background-color:#FFFFFF;
1.694     tempelho 5875: 	border:1px solid #CCCCCC;
                   5876: }
                   5877: 
                   5878: 
                   5879: .LC_loginpage_loginContainer {
                   5880: 	float:left;
1.712     muellerd 5881: 	width: 182px;
1.785     tempelho 5882: 	padding: 2px;
1.712     muellerd 5883: 	border:1px solid #CCCCCC;
                   5884: 	background-color:$loginbg;
1.694     tempelho 5885: }
                   5886: 
1.717     tempelho 5887: .LC_loginpage_loginContainer h2{
1.712     muellerd 5888: 	margin-top:0;
                   5889: 	display:block;
                   5890: 	background:$bgcol;
                   5891: 	color:$textcol;
                   5892: 	padding-left:5px;
                   5893: }
1.785     tempelho 5894: 
1.694     tempelho 5895: .LC_loginpage_loginInfo {
                   5896: 	float:left;
1.785     tempelho 5897: 	width:182px;
1.694     tempelho 5898: 	border:1px solid #CCCCCC;
1.785     tempelho 5899: 	padding:2px;
1.712     muellerd 5900: }
                   5901: 
1.694     tempelho 5902: .LC_loginpage_space {
1.754     droeschl 5903: 	clear: both;
                   5904: 	margin-bottom: 20px;
1.694     tempelho 5905: 	border-bottom: 1px solid #CCCCCC;
                   5906: }
                   5907: 
1.785     tempelho 5908: .LC_loginpage_floatLeft {
                   5909: 	float: left;
                   5910: 	width: 200px;
                   5911: 	margin: 0;
                   5912: }
                   5913: 
1.748     schulted 5914: table em{
1.754     droeschl 5915: 	font-weight: bold;
                   5916: 	font-style: normal;
1.748     schulted 5917: }
1.779     bisitz   5918: table.LC_tableBrowseRes,
1.768     schulted 5919: table.LC_tableOfContent{
1.769     schulted 5920:         border:none;
                   5921: 	border-spacing: 1;
1.754     droeschl 5922: 	padding: 3px;
                   5923: 	background-color: #FFFFFF;
                   5924: 	font-size: 90%;
1.753     droeschl 5925: }
1.789     droeschl 5926: 
                   5927: table.LC_tableOfContent{
                   5928:     border-collapse: collapse;
                   5929: }
                   5930: 
1.771     droeschl 5931: table.LC_tableBrowseRes a,
1.768     schulted 5932: table.LC_tableOfContent a {
1.771     droeschl 5933:         background-color: transparent;
1.753     droeschl 5934: 	text-decoration: none;
                   5935: }
                   5936: 
1.771     droeschl 5937: table.LC_tableBrowseRes tr.LC_trOdd,
1.768     schulted 5938: table.LC_tableOfContent tr.LC_trOdd{
1.754     droeschl 5939: 	background-color: #EEEEEE;
1.753     droeschl 5940: }
                   5941: 
1.768     schulted 5942: table.LC_tableOfContent img{
1.753     droeschl 5943: 	border: none;
                   5944: 	height: 1.3em;
                   5945: 	vertical-align: text-bottom;
                   5946: 	margin-right: 0.3em;
                   5947: }
1.757     schulted 5948: 
1.774     ehlerst  5949: a#LC_content_toolbar_firsthomework{
                   5950: 	background-image:url(/res/adm/pages/open-first-problem.gif);
                   5951: }
                   5952: 
                   5953: a#LC_content_toolbar_launchnav{
                   5954: 	background-image:url(/res/adm/pages/start-navigation.gif);
                   5955: }
                   5956: 
                   5957: a#LC_content_toolbar_closenav{
                   5958: 	background-image:url(/res/adm/pages/close-navigation.gif);
                   5959: }
                   5960: 
                   5961: a#LC_content_toolbar_everything{
                   5962: 	background-image:url(/res/adm/pages/show-all.gif);
                   5963: }
                   5964: 
                   5965: a#LC_content_toolbar_uncompleted{
                   5966: 	background-image:url(/res/adm/pages/show-incomplete-problems.gif);
                   5967: }
                   5968: 
                   5969: #LC_content_toolbar_clearbubbles{
                   5970: 	background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
                   5971: }
                   5972: 
1.757     schulted 5973: a#LC_content_toolbar_changefolder{
                   5974: 	background : url(/res/adm/pages/close-all-folders.gif) top center ;
                   5975: }
                   5976: 
                   5977: a#LC_content_toolbar_changefolder_toggled{
                   5978: 	background-image:url(/res/adm/pages/open-all-folders.gif);
                   5979: }
                   5980: 
                   5981: ul#LC_toolbar li a:hover{
                   5982: 	background-position: bottom center;
                   5983: }
                   5984: 
                   5985: ul#LC_toolbar{
1.779     bisitz   5986: 	padding:0;
1.757     schulted 5987: 	margin: 2px;
                   5988: 	list-style:none;
                   5989: 	position:relative;
                   5990: 	background-color:white;
                   5991: }
                   5992: 
                   5993: ul#LC_toolbar li{
                   5994: 	border:1px solid white;
                   5995: 	padding:0;
                   5996: 	margin: 0;
1.767     droeschl 5997:     float: left;
                   5998: 	display:inline;
1.757     schulted 5999: 	vertical-align:middle;
                   6000: }
                   6001: 
1.783     amueller 6002: 
1.757     schulted 6003: a.LC_toolbarItem{
1.767     droeschl 6004: 	display:block;
1.757     schulted 6005: 	padding:0;
                   6006: 	margin:0;
                   6007: 	height: 32px;
                   6008: 	width: 32px;
1.779     bisitz   6009: 	color:white;
                   6010: 	border:0 none;
1.757     schulted 6011: 	background-repeat:no-repeat;
                   6012: 	background-color:transparent;
                   6013: }
                   6014: 
1.782     bisitz   6015: ul.LC_functionslist li {
                   6016:   float: left;
                   6017:   white-space: nowrap;
                   6018:   height: 35px; /* at least as high as heighest list item */
                   6019:   margin: 0px 15px 15px 10px;
                   6020: }
                   6021: 
1.757     schulted 6022: 
1.343     albertel 6023: END
                   6024: }
                   6025: 
1.306     albertel 6026: =pod
                   6027: 
                   6028: =item * &headtag()
                   6029: 
                   6030: Returns a uniform footer for LON-CAPA web pages.
                   6031: 
1.307     albertel 6032: Inputs: $title - optional title for the head
                   6033:         $head_extra - optional extra HTML to put inside the <head>
1.315     albertel 6034:         $args - optional arguments
1.319     albertel 6035:             force_register - if is true call registerurl so the remote is 
                   6036:                              informed
1.415     albertel 6037:             redirect       -> array ref of
                   6038:                                    1- seconds before redirect occurs
                   6039:                                    2- url to redirect to
                   6040:                                    3- whether the side effect should occur
1.315     albertel 6041:                            (side effect of setting 
                   6042:                                $env{'internal.head.redirect'} to the url 
                   6043:                                redirected too)
1.352     albertel 6044:             domain         -> force to color decorate a page for a specific
                   6045:                                domain
                   6046:             function       -> force usage of a specific rolish color scheme
                   6047:             bgcolor        -> override the default page bgcolor
1.460     albertel 6048:             no_auto_mt_title
                   6049:                            -> prevent &mt()ing the title arg
1.464     albertel 6050: 
1.306     albertel 6051: =cut
                   6052: 
                   6053: sub headtag {
1.313     albertel 6054:     my ($title,$head_extra,$args) = @_;
1.306     albertel 6055:     
1.363     albertel 6056:     my $function = $args->{'function'} || &get_users_function();
                   6057:     my $domain   = $args->{'domain'}   || &determinedomain();
                   6058:     my $bgcolor  = $args->{'bgcolor'}  || &designparm($function.'.pgbg',$domain);
1.418     albertel 6059:     my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458     albertel 6060: 		   $Apache::lonnet::perlvar{'lonVersion'},
1.531     albertel 6061: 		   #time(),
1.418     albertel 6062: 		   $env{'environment.color.timestamp'},
1.363     albertel 6063: 		   $function,$domain,$bgcolor);
                   6064: 
1.369     www      6065:     $url = '/adm/css/'.&escape($url).'.css';
1.363     albertel 6066: 
1.308     albertel 6067:     my $result =
                   6068: 	'<head>'.
1.461     albertel 6069: 	&font_settings();
1.319     albertel 6070: 
1.461     albertel 6071:     if (!$args->{'frameset'}) {
                   6072: 	$result .= &Apache::lonhtmlcommon::htmlareaheaders();
                   6073:     }
1.319     albertel 6074:     if ($args->{'force_register'}) {
                   6075: 	$result .= &Apache::lonmenu::registerurl(1);
                   6076:     }
1.436     albertel 6077:     if (!$args->{'no_nav_bar'} 
                   6078: 	&& !$args->{'only_body'}
                   6079: 	&& !$args->{'frameset'}) {
                   6080: 	$result .= &help_menu_js();
                   6081:     }
1.319     albertel 6082: 
1.314     albertel 6083:     if (ref($args->{'redirect'})) {
1.414     albertel 6084: 	my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315     albertel 6085: 	$url = &Apache::lonenc::check_encrypt($url);
1.414     albertel 6086: 	if (!$inhibit_continue) {
                   6087: 	    $env{'internal.head.redirect'} = $url;
                   6088: 	}
1.313     albertel 6089: 	$result.=<<ADDMETA
                   6090: <meta http-equiv="pragma" content="no-cache" />
1.344     albertel 6091: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313     albertel 6092: ADDMETA
                   6093:     }
1.306     albertel 6094:     if (!defined($title)) {
                   6095: 	$title = 'The LearningOnline Network with CAPA';
                   6096:     }
1.460     albertel 6097:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
                   6098:     $result .= '<title> LON-CAPA '.$title.'</title>'
1.414     albertel 6099: 	.'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
                   6100: 	.$head_extra;
1.306     albertel 6101:     return $result;
                   6102: }
                   6103: 
                   6104: =pod
                   6105: 
1.340     albertel 6106: =item * &font_settings()
                   6107: 
                   6108: Returns neccessary <meta> to set the proper encoding
                   6109: 
                   6110: Inputs: none
                   6111: 
                   6112: =cut
                   6113: 
                   6114: sub font_settings {
                   6115:     my $headerstring='';
1.647     www      6116:     if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340     albertel 6117: 	$headerstring.=
                   6118: 	    '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
                   6119:     }
                   6120:     return $headerstring;
                   6121: }
                   6122: 
1.341     albertel 6123: =pod
                   6124: 
                   6125: =item * &xml_begin()
                   6126: 
                   6127: Returns the needed doctype and <html>
                   6128: 
                   6129: Inputs: none
                   6130: 
                   6131: =cut
                   6132: 
                   6133: sub xml_begin {
                   6134:     my $output='';
                   6135: 
1.592     albertel 6136:     if ($env{'internal.start_page'}==1) {
                   6137: 	&Apache::lonhtmlcommon::init_htmlareafields();
                   6138:     }
1.342     albertel 6139: 
1.341     albertel 6140:     if ($env{'browser.mathml'}) {
                   6141: 	$output='<?xml version="1.0"?>'
                   6142:             #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
                   6143: #            .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
                   6144:             
                   6145: #	    .'<!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">] >'
                   6146: 	    .'<!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">'
                   6147:             .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" ' 
                   6148: 	    .'xmlns="http://www.w3.org/1999/xhtml">';
                   6149:     } else {
                   6150: 	$output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>';
                   6151:     }
                   6152:     return $output;
                   6153: }
1.340     albertel 6154: 
                   6155: =pod
                   6156: 
1.306     albertel 6157: =item * &endheadtag()
                   6158: 
                   6159: Returns a uniform </head> for LON-CAPA web pages.
                   6160: 
                   6161: Inputs: none
                   6162: 
                   6163: =cut
                   6164: 
                   6165: sub endheadtag {
                   6166:     return '</head>';
                   6167: }
                   6168: 
                   6169: =pod
                   6170: 
                   6171: =item * &head()
                   6172: 
                   6173: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
                   6174: 
1.648     raeburn  6175: Inputs:
                   6176: 
                   6177: =over 4
                   6178: 
                   6179: $title - optional title for the page
                   6180: 
                   6181: $head_extra - optional extra HTML to put inside the <head>
                   6182: 
                   6183: =back
1.405     albertel 6184: 
1.306     albertel 6185: =cut
                   6186: 
                   6187: sub head {
1.325     albertel 6188:     my ($title,$head_extra,$args) = @_;
                   6189:     return &headtag($title,$head_extra,$args).&endheadtag();
1.306     albertel 6190: }
                   6191: 
                   6192: =pod
                   6193: 
                   6194: =item * &start_page()
                   6195: 
                   6196: Returns a complete <html> .. <body> section for LON-CAPA web pages.
                   6197: 
1.648     raeburn  6198: Inputs:
                   6199: 
                   6200: =over 4
                   6201: 
                   6202: $title - optional title for the page
                   6203: 
                   6204: $head_extra - optional extra HTML to incude inside the <head>
                   6205: 
                   6206: $args - additional optional args supported are:
                   6207: 
                   6208: =over 8
                   6209: 
                   6210:              only_body      -> is true will set &bodytag() onlybodytag
1.317     albertel 6211:                                     arg on
1.648     raeburn  6212:              no_nav_bar     -> is true will set &bodytag() notopbar arg on
                   6213:              add_entries    -> additional attributes to add to the  <body>
                   6214:              domain         -> force to color decorate a page for a 
1.317     albertel 6215:                                     specific domain
1.648     raeburn  6216:              function       -> force usage of a specific rolish color
1.317     albertel 6217:                                     scheme
1.648     raeburn  6218:              redirect       -> see &headtag()
                   6219:              bgcolor        -> override the default page bg color
                   6220:              js_ready       -> return a string ready for being used in 
1.317     albertel 6221:                                     a javascript writeln
1.648     raeburn  6222:              html_encode    -> return a string ready for being used in 
1.320     albertel 6223:                                     a html attribute
1.648     raeburn  6224:              force_register -> if is true will turn on the &bodytag()
1.317     albertel 6225:                                     $forcereg arg
1.648     raeburn  6226:              body_title     -> alternate text to use instead of $title
1.326     albertel 6227:                                     in the title box that appears, this text
                   6228:                                     is not auto translated like the $title is
1.648     raeburn  6229:              frameset       -> if true will start with a <frameset>
1.330     albertel 6230:                                     rather than <body>
1.648     raeburn  6231:              no_title       -> if true the title bar won't be shown
                   6232:              skip_phases    -> hash ref of 
1.338     albertel 6233:                                     head -> skip the <html><head> generation
                   6234:                                     body -> skip all <body> generation
1.648     raeburn  6235:              no_inline_link -> if true and in remote mode, don't show the 
1.361     albertel 6236:                                     'Switch To Inline Menu' link
1.648     raeburn  6237:              no_auto_mt_title -> prevent &mt()ing the title arg
                   6238:              inherit_jsmath -> when creating popup window in a page,
                   6239:                                     should it have jsmath forced on by the
                   6240:                                     current page
1.361     albertel 6241: 
1.648     raeburn  6242: =back
1.460     albertel 6243: 
1.648     raeburn  6244: =back
1.562     albertel 6245: 
1.306     albertel 6246: =cut
                   6247: 
                   6248: sub start_page {
1.309     albertel 6249:     my ($title,$head_extra,$args) = @_;
1.318     albertel 6250:     #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313     albertel 6251:     my %head_args;
1.352     albertel 6252:     foreach my $arg ('redirect','force_register','domain','function',
1.460     albertel 6253: 		     'bgcolor','frameset','no_nav_bar','only_body',
                   6254: 		     'no_auto_mt_title') {
1.319     albertel 6255: 	if (defined($args->{$arg})) {
1.324     raeburn  6256: 	    $head_args{$arg} = $args->{$arg};
1.319     albertel 6257: 	}
1.313     albertel 6258:     }
1.319     albertel 6259: 
1.315     albertel 6260:     $env{'internal.start_page'}++;
1.338     albertel 6261:     my $result;
                   6262:     if (! exists($args->{'skip_phases'}{'head'}) ) {
                   6263: 	$result.=
1.341     albertel 6264: 	    &xml_begin().
1.338     albertel 6265: 	    &headtag($title,$head_extra,\%head_args).&endheadtag();
                   6266:     }
                   6267:     
                   6268:     if (! exists($args->{'skip_phases'}{'body'}) ) {
                   6269: 	if ($args->{'frameset'}) {
                   6270: 	    my $attr_string = &make_attr_string($args->{'force_register'},
                   6271: 						$args->{'add_entries'});
                   6272: 	    $result .= "\n<frameset $attr_string>\n";
                   6273: 	} else {
                   6274: 	    $result .=
                   6275: 		&bodytag($title, 
                   6276: 			 $args->{'function'},       $args->{'add_entries'},
                   6277: 			 $args->{'only_body'},      $args->{'domain'},
                   6278: 			 $args->{'force_register'}, $args->{'body_title'},
                   6279: 			 $args->{'no_nav_bar'},     $args->{'bgcolor'},
1.460     albertel 6280: 			 $args->{'no_title'},       $args->{'no_inline_link'},
                   6281: 			 $args);
1.338     albertel 6282: 	}
1.330     albertel 6283:     }
1.338     albertel 6284: 
1.315     albertel 6285:     if ($args->{'js_ready'}) {
1.713     kaisler  6286: 		$result = &js_ready($result);
1.315     albertel 6287:     }
1.320     albertel 6288:     if ($args->{'html_encode'}) {
1.713     kaisler  6289: 		$result = &html_encode($result);
                   6290:     }
                   6291: 
1.758     kaisler  6292: 	#Breadcrumbs
                   6293:     if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
                   6294: 		&Apache::lonhtmlcommon::clear_breadcrumbs();
                   6295: 		#if any br links exists, add them to the breadcrumbs
                   6296: 		if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {         
                   6297: 			foreach my $crumb (@{$args->{'bread_crumbs'}}){
                   6298: 				&Apache::lonhtmlcommon::add_breadcrumb($crumb);
                   6299: 			}
                   6300: 		}
                   6301: 
                   6302: 		#if bread_crumbs_component exists show it as headline else show only the breadcrumbs
                   6303: 		if(exists($args->{'bread_crumbs_component'})){
                   6304: 			$result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
                   6305: 		}else{
                   6306: 			$result .= &Apache::lonhtmlcommon::breadcrumbs();
                   6307: 		}
1.320     albertel 6308:     }
1.315     albertel 6309:     return $result;
1.306     albertel 6310: }
                   6311: 
1.330     albertel 6312: 
1.306     albertel 6313: =pod
                   6314: 
                   6315: =item * &head()
                   6316: 
                   6317: Returns a complete </body></html> section for LON-CAPA web pages.
                   6318: 
1.315     albertel 6319: Inputs:         $args - additional optional args supported are:
                   6320:                  js_ready     -> return a string ready for being used in 
                   6321:                                  a javascript writeln
1.320     albertel 6322:                  html_encode  -> return a string ready for being used in 
                   6323:                                  a html attribute
1.330     albertel 6324:                  frameset     -> if true will start with a <frameset>
                   6325:                                  rather than <body>
1.493     albertel 6326:                  dicsussion   -> if true will get discussion from
                   6327:                                   lonxml::xmlend
                   6328:                                  (you can pass the target and parser arguments
                   6329:                                   through optional 'target' and 'parser' args
                   6330:                                   to this routine)
1.306     albertel 6331: 
                   6332: =cut
                   6333: 
                   6334: sub end_page {
1.315     albertel 6335:     my ($args) = @_;
                   6336:     $env{'internal.end_page'}++;
1.330     albertel 6337:     my $result;
1.335     albertel 6338:     if ($args->{'discussion'}) {
                   6339: 	my ($target,$parser);
                   6340: 	if (ref($args->{'discussion'})) {
                   6341: 	    ($target,$parser) =($args->{'discussion'}{'target'},
                   6342: 				$args->{'discussion'}{'parser'});
                   6343: 	}
                   6344: 	$result .= &Apache::lonxml::xmlend($target,$parser);
                   6345:     }
                   6346: 
1.330     albertel 6347:     if ($args->{'frameset'}) {
                   6348: 	$result .= '</frameset>';
                   6349:     } else {
1.635     raeburn  6350: 	$result .= &endbodytag($args);
1.330     albertel 6351:     }
                   6352:     $result .= "\n</html>";
                   6353: 
1.315     albertel 6354:     if ($args->{'js_ready'}) {
1.317     albertel 6355: 	$result = &js_ready($result);
1.315     albertel 6356:     }
1.335     albertel 6357: 
1.320     albertel 6358:     if ($args->{'html_encode'}) {
                   6359: 	$result = &html_encode($result);
                   6360:     }
1.335     albertel 6361: 
1.315     albertel 6362:     return $result;
                   6363: }
                   6364: 
1.320     albertel 6365: sub html_encode {
                   6366:     my ($result) = @_;
                   6367: 
1.322     albertel 6368:     $result = &HTML::Entities::encode($result,'<>&"');
1.320     albertel 6369:     
                   6370:     return $result;
                   6371: }
1.317     albertel 6372: sub js_ready {
                   6373:     my ($result) = @_;
                   6374: 
1.323     albertel 6375:     $result =~ s/[\n\r]/ /xmsg;
                   6376:     $result =~ s/\\/\\\\/xmsg;
                   6377:     $result =~ s/'/\\'/xmsg;
1.372     albertel 6378:     $result =~ s{</}{<\\/}xmsg;
1.317     albertel 6379:     
                   6380:     return $result;
                   6381: }
                   6382: 
1.315     albertel 6383: sub validate_page {
                   6384:     if (  exists($env{'internal.start_page'})
1.316     albertel 6385: 	  &&     $env{'internal.start_page'} > 1) {
                   6386: 	&Apache::lonnet::logthis('start_page called multiple times '.
1.318     albertel 6387: 				 $env{'internal.start_page'}.' '.
1.316     albertel 6388: 				 $ENV{'request.filename'});
1.315     albertel 6389:     }
                   6390:     if (  exists($env{'internal.end_page'})
1.316     albertel 6391: 	  &&     $env{'internal.end_page'} > 1) {
                   6392: 	&Apache::lonnet::logthis('end_page called multiple times '.
1.318     albertel 6393: 				 $env{'internal.end_page'}.' '.
1.316     albertel 6394: 				 $env{'request.filename'});
1.315     albertel 6395:     }
                   6396:     if (     exists($env{'internal.start_page'})
                   6397: 	&& ! exists($env{'internal.end_page'})) {
1.316     albertel 6398: 	&Apache::lonnet::logthis('start_page called without end_page '.
                   6399: 				 $env{'request.filename'});
1.315     albertel 6400:     }
                   6401:     if (   ! exists($env{'internal.start_page'})
                   6402: 	&&   exists($env{'internal.end_page'})) {
1.316     albertel 6403: 	&Apache::lonnet::logthis('end_page called without start_page'.
                   6404: 				 $env{'request.filename'});
1.315     albertel 6405:     }
1.306     albertel 6406: }
1.315     albertel 6407: 
1.318     albertel 6408: sub simple_error_page {
                   6409:     my ($r,$title,$msg) = @_;
                   6410:     my $page =
                   6411: 	&Apache::loncommon::start_page($title).
                   6412: 	&mt($msg).
                   6413: 	&Apache::loncommon::end_page();
                   6414:     if (ref($r)) {
                   6415: 	$r->print($page);
1.327     albertel 6416: 	return;
1.318     albertel 6417:     }
                   6418:     return $page;
                   6419: }
1.347     albertel 6420: 
                   6421: {
1.610     albertel 6422:     my @row_count;
1.347     albertel 6423:     sub start_data_table {
1.422     albertel 6424: 	my ($add_class) = @_;
                   6425: 	my $css_class = (join(' ','LC_data_table',$add_class));
1.610     albertel 6426: 	unshift(@row_count,0);
1.422     albertel 6427: 	return '<table class="'.$css_class.'">'."\n";
1.347     albertel 6428:     }
                   6429: 
                   6430:     sub end_data_table {
1.610     albertel 6431: 	shift(@row_count);
1.389     albertel 6432: 	return '</table>'."\n";;
1.347     albertel 6433:     }
                   6434: 
                   6435:     sub start_data_table_row {
1.422     albertel 6436: 	my ($add_class) = @_;
1.610     albertel 6437: 	$row_count[0]++;
                   6438: 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.428     albertel 6439: 	$css_class = (join(' ',$css_class,$add_class));
1.422     albertel 6440: 	return  '<tr class="'.$css_class.'">'."\n";;
1.347     albertel 6441:     }
1.471     banghart 6442:     
                   6443:     sub continue_data_table_row {
                   6444: 	my ($add_class) = @_;
1.610     albertel 6445: 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.471     banghart 6446: 	$css_class = (join(' ',$css_class,$add_class));
                   6447: 	return  '<tr class="'.$css_class.'">'."\n";;
                   6448:     }
1.347     albertel 6449: 
                   6450:     sub end_data_table_row {
1.389     albertel 6451: 	return '</tr>'."\n";;
1.347     albertel 6452:     }
1.367     www      6453: 
1.421     albertel 6454:     sub start_data_table_empty_row {
1.707     bisitz   6455: #	$row_count[0]++;
1.421     albertel 6456: 	return  '<tr class="LC_empty_row" >'."\n";;
                   6457:     }
                   6458: 
                   6459:     sub end_data_table_empty_row {
                   6460: 	return '</tr>'."\n";;
                   6461:     }
                   6462: 
1.367     www      6463:     sub start_data_table_header_row {
1.389     albertel 6464: 	return  '<tr class="LC_header_row">'."\n";;
1.367     www      6465:     }
                   6466: 
                   6467:     sub end_data_table_header_row {
1.389     albertel 6468: 	return '</tr>'."\n";;
1.367     www      6469:     }
1.347     albertel 6470: }
                   6471: 
1.548     albertel 6472: =pod
                   6473: 
                   6474: =item * &inhibit_menu_check($arg)
                   6475: 
                   6476: Checks for a inhibitmenu state and generates output to preserve it
                   6477: 
                   6478: Inputs:         $arg - can be any of
                   6479:                      - undef - in which case the return value is a string 
                   6480:                                to add  into arguments list of a uri
                   6481:                      - 'input' - in which case the return value is a HTML
                   6482:                                  <form> <input> field of type hidden to
                   6483:                                  preserve the value
                   6484:                      - a url - in which case the return value is the url with
                   6485:                                the neccesary cgi args added to preserve the
                   6486:                                inhibitmenu state
                   6487:                      - a ref to a url - no return value, but the string is
                   6488:                                         updated to include the neccessary cgi
                   6489:                                         args to preserve the inhibitmenu state
                   6490: 
                   6491: =cut
                   6492: 
                   6493: sub inhibit_menu_check {
                   6494:     my ($arg) = @_;
                   6495:     &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
                   6496:     if ($arg eq 'input') {
                   6497: 	if ($env{'form.inhibitmenu'}) {
                   6498: 	    return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
                   6499: 	} else {
                   6500: 	    return
                   6501: 	}
                   6502:     }
                   6503:     if ($env{'form.inhibitmenu'}) {
                   6504: 	if (ref($arg)) {
                   6505: 	    $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
                   6506: 	} elsif ($arg eq '') {
                   6507: 	    $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
                   6508: 	} else {
                   6509: 	    $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
                   6510: 	}
                   6511:     }
                   6512:     if (!ref($arg)) {
                   6513: 	return $arg;
                   6514:     }
                   6515: }
                   6516: 
1.251     albertel 6517: ###############################################
1.182     matthew  6518: 
                   6519: =pod
                   6520: 
1.549     albertel 6521: =back
                   6522: 
                   6523: =head1 User Information Routines
                   6524: 
                   6525: =over 4
                   6526: 
1.405     albertel 6527: =item * &get_users_function()
1.182     matthew  6528: 
                   6529: Used by &bodytag to determine the current users primary role.
                   6530: Returns either 'student','coordinator','admin', or 'author'.
                   6531: 
                   6532: =cut
                   6533: 
                   6534: ###############################################
                   6535: sub get_users_function {
                   6536:     my $function = 'student';
1.258     albertel 6537:     if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
1.182     matthew  6538:         $function='coordinator';
                   6539:     }
1.258     albertel 6540:     if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182     matthew  6541:         $function='admin';
                   6542:     }
1.258     albertel 6543:     if (($env{'request.role'}=~/^(au|ca)/) ||
1.182     matthew  6544:         ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
                   6545:         $function='author';
                   6546:     }
                   6547:     return $function;
1.54      www      6548: }
1.99      www      6549: 
                   6550: ###############################################
                   6551: 
1.233     raeburn  6552: =pod
                   6553: 
1.542     raeburn  6554: =item * &check_user_status()
1.274     raeburn  6555: 
                   6556: Determines current status of supplied role for a
                   6557: specific user. Roles can be active, previous or future.
                   6558: 
                   6559: Inputs: 
                   6560: user's domain, user's username, course's domain,
1.375     raeburn  6561: course's number, optional section ID.
1.274     raeburn  6562: 
                   6563: Outputs:
                   6564: role status: active, previous or future. 
                   6565: 
                   6566: =cut
                   6567: 
                   6568: sub check_user_status {
1.412     raeburn  6569:     my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274     raeburn  6570:     my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
                   6571:     my @uroles = keys %userinfo;
                   6572:     my $srchstr;
                   6573:     my $active_chk = 'none';
1.412     raeburn  6574:     my $now = time;
1.274     raeburn  6575:     if (@uroles > 0) {
1.412     raeburn  6576:         if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
1.274     raeburn  6577:             $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
                   6578:         } else {
1.412     raeburn  6579:             $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
                   6580:         }
                   6581:         if (grep/^\Q$srchstr\E$/,@uroles) {
1.274     raeburn  6582:             my $role_end = 0;
                   6583:             my $role_start = 0;
                   6584:             $active_chk = 'active';
1.412     raeburn  6585:             if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
                   6586:                 $role_end = $1;
                   6587:                 if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
                   6588:                     $role_start = $1;
1.274     raeburn  6589:                 }
                   6590:             }
                   6591:             if ($role_start > 0) {
1.412     raeburn  6592:                 if ($now < $role_start) {
1.274     raeburn  6593:                     $active_chk = 'future';
                   6594:                 }
                   6595:             }
                   6596:             if ($role_end > 0) {
1.412     raeburn  6597:                 if ($now > $role_end) {
1.274     raeburn  6598:                     $active_chk = 'previous';
                   6599:                 }
                   6600:             }
                   6601:         }
                   6602:     }
                   6603:     return $active_chk;
                   6604: }
                   6605: 
                   6606: ###############################################
                   6607: 
                   6608: =pod
                   6609: 
1.405     albertel 6610: =item * &get_sections()
1.233     raeburn  6611: 
                   6612: Determines all the sections for a course including
                   6613: sections with students and sections containing other roles.
1.419     raeburn  6614: Incoming parameters: 
                   6615: 
                   6616: 1. domain
                   6617: 2. course number 
                   6618: 3. reference to array containing roles for which sections should 
                   6619: be gathered (optional).
                   6620: 4. reference to array containing status types for which sections 
                   6621: should be gathered (optional).
                   6622: 
                   6623: If the third argument is undefined, sections are gathered for any role. 
                   6624: If the fourth argument is undefined, sections are gathered for any status.
                   6625: Permissible values are 'active' or 'future' or 'previous'.
1.233     raeburn  6626:  
1.374     raeburn  6627: Returns section hash (keys are section IDs, values are
                   6628: number of users in each section), subject to the
1.419     raeburn  6629: optional roles filter, optional status filter 
1.233     raeburn  6630: 
                   6631: =cut
                   6632: 
                   6633: ###############################################
                   6634: sub get_sections {
1.419     raeburn  6635:     my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366     albertel 6636:     if (!defined($cdom) || !defined($cnum)) {
                   6637:         my $cid =  $env{'request.course.id'};
                   6638: 
                   6639: 	return if (!defined($cid));
                   6640: 
                   6641:         $cdom = $env{'course.'.$cid.'.domain'};
                   6642:         $cnum = $env{'course.'.$cid.'.num'};
                   6643:     }
                   6644: 
                   6645:     my %sectioncount;
1.419     raeburn  6646:     my $now = time;
1.240     albertel 6647: 
1.366     albertel 6648:     if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276     albertel 6649: 	my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240     albertel 6650: 	my $sec_index = &Apache::loncoursedata::CL_SECTION();
                   6651: 	my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419     raeburn  6652:         my $start_index = &Apache::loncoursedata::CL_START();
                   6653:         my $end_index = &Apache::loncoursedata::CL_END();
                   6654:         my $status;
1.366     albertel 6655: 	while (my ($student,$data) = each(%$classlist)) {
1.419     raeburn  6656: 	    my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
                   6657: 				                     $data->[$status_index],
                   6658:                                                      $data->[$start_index],
                   6659:                                                      $data->[$end_index]);
                   6660:             if ($stu_status eq 'Active') {
                   6661:                 $status = 'active';
                   6662:             } elsif ($end < $now) {
                   6663:                 $status = 'previous';
                   6664:             } elsif ($start > $now) {
                   6665:                 $status = 'future';
                   6666:             } 
                   6667: 	    if ($section ne '-1' && $section !~ /^\s*$/) {
                   6668:                 if ((!defined($possible_status)) || (($status ne '') && 
                   6669:                     (grep/^\Q$status\E$/,@{$possible_status}))) { 
                   6670: 		    $sectioncount{$section}++;
                   6671:                 }
1.240     albertel 6672: 	    }
                   6673: 	}
                   6674:     }
                   6675:     my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   6676:     foreach my $user (sort(keys(%courseroles))) {
                   6677: 	if ($user !~ /^(\w{2})/) { next; }
                   6678: 	my ($role) = ($user =~ /^(\w{2})/);
                   6679: 	if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419     raeburn  6680: 	my ($section,$status);
1.240     albertel 6681: 	if ($role eq 'cr' &&
                   6682: 	    $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
                   6683: 	    $section=$1;
                   6684: 	}
                   6685: 	if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
                   6686: 	if (!defined($section) || $section eq '-1') { next; }
1.419     raeburn  6687:         my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
                   6688:         if ($end == -1 && $start == -1) {
                   6689:             next; #deleted role
                   6690:         }
                   6691:         if (!defined($possible_status)) { 
                   6692:             $sectioncount{$section}++;
                   6693:         } else {
                   6694:             if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
                   6695:                 $status = 'active';
                   6696:             } elsif ($end < $now) {
                   6697:                 $status = 'future';
                   6698:             } elsif ($start > $now) {
                   6699:                 $status = 'previous';
                   6700:             }
                   6701:             if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
                   6702:                 $sectioncount{$section}++;
                   6703:             }
                   6704:         }
1.233     raeburn  6705:     }
1.366     albertel 6706:     return %sectioncount;
1.233     raeburn  6707: }
                   6708: 
1.274     raeburn  6709: ###############################################
1.294     raeburn  6710: 
                   6711: =pod
1.405     albertel 6712: 
                   6713: =item * &get_course_users()
                   6714: 
1.275     raeburn  6715: Retrieves usernames:domains for users in the specified course
                   6716: with specific role(s), and access status. 
                   6717: 
                   6718: Incoming parameters:
1.277     albertel 6719: 1. course domain
                   6720: 2. course number
                   6721: 3. access status: users must have - either active, 
1.275     raeburn  6722: previous, future, or all.
1.277     albertel 6723: 4. reference to array of permissible roles
1.288     raeburn  6724: 5. reference to array of section restrictions (optional)
                   6725: 6. reference to results object (hash of hashes).
                   6726: 7. reference to optional userdata hash
1.609     raeburn  6727: 8. reference to optional statushash
1.630     raeburn  6728: 9. flag if privileged users (except those set to unhide in
                   6729:    course settings) should be excluded    
1.609     raeburn  6730: Keys of top level results hash are roles.
1.275     raeburn  6731: Keys of inner hashes are username:domain, with 
                   6732: values set to access type.
1.288     raeburn  6733: Optional userdata hash returns an array with arguments in the 
                   6734: same order as loncoursedata::get_classlist() for student data.
                   6735: 
1.609     raeburn  6736: Optional statushash returns
                   6737: 
1.288     raeburn  6738: Entries for end, start, section and status are blank because
                   6739: of the possibility of multiple values for non-student roles.
                   6740: 
1.275     raeburn  6741: =cut
1.405     albertel 6742: 
1.275     raeburn  6743: ###############################################
1.405     albertel 6744: 
1.275     raeburn  6745: sub get_course_users {
1.630     raeburn  6746:     my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288     raeburn  6747:     my %idx = ();
1.419     raeburn  6748:     my %seclists;
1.288     raeburn  6749: 
                   6750:     $idx{udom} = &Apache::loncoursedata::CL_SDOM();
                   6751:     $idx{uname} =  &Apache::loncoursedata::CL_SNAME();
                   6752:     $idx{end} = &Apache::loncoursedata::CL_END();
                   6753:     $idx{start} = &Apache::loncoursedata::CL_START();
                   6754:     $idx{id} = &Apache::loncoursedata::CL_ID();
                   6755:     $idx{section} = &Apache::loncoursedata::CL_SECTION();
                   6756:     $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
                   6757:     $idx{status} = &Apache::loncoursedata::CL_STATUS();
                   6758: 
1.290     albertel 6759:     if (grep(/^st$/,@{$roles})) {
1.276     albertel 6760:         my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278     raeburn  6761:         my $now = time;
1.277     albertel 6762:         foreach my $student (keys(%{$classlist})) {
1.288     raeburn  6763:             my $match = 0;
1.412     raeburn  6764:             my $secmatch = 0;
1.419     raeburn  6765:             my $section = $$classlist{$student}[$idx{section}];
1.609     raeburn  6766:             my $status = $$classlist{$student}[$idx{status}];
1.419     raeburn  6767:             if ($section eq '') {
                   6768:                 $section = 'none';
                   6769:             }
1.291     albertel 6770:             if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 6771:                 if (grep(/^all$/,@{$sections})) {
1.412     raeburn  6772:                     $secmatch = 1;
                   6773:                 } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420     albertel 6774:                     if (grep(/^none$/,@{$sections})) {
1.412     raeburn  6775:                         $secmatch = 1;
                   6776:                     }
                   6777:                 } else {  
1.419     raeburn  6778: 		    if (grep(/^\Q$section\E$/,@{$sections})) {
1.412     raeburn  6779: 		        $secmatch = 1;
                   6780:                     }
1.290     albertel 6781: 		}
1.412     raeburn  6782:                 if (!$secmatch) {
                   6783:                     next;
                   6784:                 }
1.419     raeburn  6785:             }
1.275     raeburn  6786:             if (defined($$types{'active'})) {
1.288     raeburn  6787:                 if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275     raeburn  6788:                     push(@{$$users{st}{$student}},'active');
1.288     raeburn  6789:                     $match = 1;
1.275     raeburn  6790:                 }
                   6791:             }
                   6792:             if (defined($$types{'previous'})) {
1.609     raeburn  6793:                 if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275     raeburn  6794:                     push(@{$$users{st}{$student}},'previous');
1.288     raeburn  6795:                     $match = 1;
1.275     raeburn  6796:                 }
                   6797:             }
                   6798:             if (defined($$types{'future'})) {
1.609     raeburn  6799:                 if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275     raeburn  6800:                     push(@{$$users{st}{$student}},'future');
1.288     raeburn  6801:                     $match = 1;
1.275     raeburn  6802:                 }
                   6803:             }
1.609     raeburn  6804:             if ($match) {
                   6805:                 push(@{$seclists{$student}},$section);
                   6806:                 if (ref($userdata) eq 'HASH') {
                   6807:                     $$userdata{$student} = $$classlist{$student};
                   6808:                 }
                   6809:                 if (ref($statushash) eq 'HASH') {
                   6810:                     $statushash->{$student}{'st'}{$section} = $status;
                   6811:                 }
1.288     raeburn  6812:             }
1.275     raeburn  6813:         }
                   6814:     }
1.412     raeburn  6815:     if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439     raeburn  6816:         my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   6817:         my $now = time;
1.609     raeburn  6818:         my %displaystatus = ( previous => 'Expired',
                   6819:                               active   => 'Active',
                   6820:                               future   => 'Future',
                   6821:                             );
1.630     raeburn  6822:         my %nothide;
                   6823:         if ($hidepriv) {
                   6824:             my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
                   6825:             foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
                   6826:                 if ($user !~ /:/) {
                   6827:                     $nothide{join(':',split(/[\@]/,$user))}=1;
                   6828:                 } else {
                   6829:                     $nothide{$user} = 1;
                   6830:                 }
                   6831:             }
                   6832:         }
1.439     raeburn  6833:         foreach my $person (sort(keys(%coursepersonnel))) {
1.288     raeburn  6834:             my $match = 0;
1.412     raeburn  6835:             my $secmatch = 0;
1.439     raeburn  6836:             my $status;
1.412     raeburn  6837:             my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275     raeburn  6838:             $user =~ s/:$//;
1.439     raeburn  6839:             my ($end,$start) = split(/:/,$coursepersonnel{$person});
                   6840:             if ($end == -1 || $start == -1) {
                   6841:                 next;
                   6842:             }
                   6843:             if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
                   6844:                 (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412     raeburn  6845:                 my ($uname,$udom) = split(/:/,$user);
                   6846:                 if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 6847:                     if (grep(/^all$/,@{$sections})) {
1.412     raeburn  6848:                         $secmatch = 1;
                   6849:                     } elsif ($usec eq '') {
1.420     albertel 6850:                         if (grep(/^none$/,@{$sections})) {
1.412     raeburn  6851:                             $secmatch = 1;
                   6852:                         }
                   6853:                     } else {
                   6854:                         if (grep(/^\Q$usec\E$/,@{$sections})) {
                   6855:                             $secmatch = 1;
                   6856:                         }
                   6857:                     }
                   6858:                     if (!$secmatch) {
                   6859:                         next;
                   6860:                     }
1.288     raeburn  6861:                 }
1.419     raeburn  6862:                 if ($usec eq '') {
                   6863:                     $usec = 'none';
                   6864:                 }
1.275     raeburn  6865:                 if ($uname ne '' && $udom ne '') {
1.630     raeburn  6866:                     if ($hidepriv) {
                   6867:                         if ((&Apache::lonnet::privileged($uname,$udom)) &&
                   6868:                             (!$nothide{$uname.':'.$udom})) {
                   6869:                             next;
                   6870:                         }
                   6871:                     }
1.503     raeburn  6872:                     if ($end > 0 && $end < $now) {
1.439     raeburn  6873:                         $status = 'previous';
                   6874:                     } elsif ($start > $now) {
                   6875:                         $status = 'future';
                   6876:                     } else {
                   6877:                         $status = 'active';
                   6878:                     }
1.277     albertel 6879:                     foreach my $type (keys(%{$types})) { 
1.275     raeburn  6880:                         if ($status eq $type) {
1.420     albertel 6881:                             if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419     raeburn  6882:                                 push(@{$$users{$role}{$user}},$type);
                   6883:                             }
1.288     raeburn  6884:                             $match = 1;
                   6885:                         }
                   6886:                     }
1.419     raeburn  6887:                     if (($match) && (ref($userdata) eq 'HASH')) {
                   6888:                         if (!exists($$userdata{$uname.':'.$udom})) {
                   6889: 			    &get_user_info($udom,$uname,\%idx,$userdata);
                   6890:                         }
1.420     albertel 6891:                         if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419     raeburn  6892:                             push(@{$seclists{$uname.':'.$udom}},$usec);
                   6893:                         }
1.609     raeburn  6894:                         if (ref($statushash) eq 'HASH') {
                   6895:                             $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
                   6896:                         }
1.275     raeburn  6897:                     }
                   6898:                 }
                   6899:             }
                   6900:         }
1.290     albertel 6901:         if (grep(/^ow$/,@{$roles})) {
1.279     raeburn  6902:             if ((defined($cdom)) && (defined($cnum))) {
                   6903:                 my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
                   6904:                 if ( defined($csettings{'internal.courseowner'}) ) {
                   6905:                     my $owner = $csettings{'internal.courseowner'};
1.609     raeburn  6906:                     next if ($owner eq '');
                   6907:                     my ($ownername,$ownerdom);
                   6908:                     if ($owner =~ /^([^:]+):([^:]+)$/) {
                   6909:                         $ownername = $1;
                   6910:                         $ownerdom = $2;
                   6911:                     } else {
                   6912:                         $ownername = $owner;
                   6913:                         $ownerdom = $cdom;
                   6914:                         $owner = $ownername.':'.$ownerdom;
1.439     raeburn  6915:                     }
                   6916:                     @{$$users{'ow'}{$owner}} = 'any';
1.290     albertel 6917:                     if (defined($userdata) && 
1.609     raeburn  6918: 			!exists($$userdata{$owner})) {
                   6919: 			&get_user_info($ownerdom,$ownername,\%idx,$userdata);
                   6920:                         if (!grep(/^none$/,@{$seclists{$owner}})) {
                   6921:                             push(@{$seclists{$owner}},'none');
                   6922:                         }
                   6923:                         if (ref($statushash) eq 'HASH') {
                   6924:                             $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419     raeburn  6925:                         }
1.290     albertel 6926: 		    }
1.279     raeburn  6927:                 }
                   6928:             }
                   6929:         }
1.419     raeburn  6930:         foreach my $user (keys(%seclists)) {
                   6931:             @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
                   6932:             $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
                   6933:         }
1.275     raeburn  6934:     }
                   6935:     return;
                   6936: }
                   6937: 
1.288     raeburn  6938: sub get_user_info {
                   6939:     my ($udom,$uname,$idx,$userdata) = @_;
1.289     albertel 6940:     $$userdata{$uname.':'.$udom}[$$idx{fullname}] = 
                   6941: 	&plainname($uname,$udom,'lastname');
1.291     albertel 6942:     $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297     raeburn  6943:     $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609     raeburn  6944:     my %idhash =  &Apache::lonnet::idrget($udom,($uname));
                   6945:     $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname}; 
1.288     raeburn  6946:     return;
                   6947: }
1.275     raeburn  6948: 
1.472     raeburn  6949: ###############################################
                   6950: 
                   6951: =pod
                   6952: 
                   6953: =item * &get_user_quota()
                   6954: 
                   6955: Retrieves quota assigned for storage of portfolio files for a user  
                   6956: 
                   6957: Incoming parameters:
                   6958: 1. user's username
                   6959: 2. user's domain
                   6960: 
                   6961: Returns:
1.536     raeburn  6962: 1. Disk quota (in Mb) assigned to student.
                   6963: 2. (Optional) Type of setting: custom or default
                   6964:    (individually assigned or default for user's 
                   6965:    institutional status).
                   6966: 3. (Optional) - User's institutional status (e.g., faculty, staff
                   6967:    or student - types as defined in localenroll::inst_usertypes 
                   6968:    for user's domain, which determines default quota for user.
                   6969: 4. (Optional) - Default quota which would apply to the user.
1.472     raeburn  6970: 
                   6971: If a value has been stored in the user's environment, 
1.536     raeburn  6972: it will return that, otherwise it returns the maximal default
                   6973: defined for the user's instituional status(es) in the domain.
1.472     raeburn  6974: 
                   6975: =cut
                   6976: 
                   6977: ###############################################
                   6978: 
                   6979: 
                   6980: sub get_user_quota {
                   6981:     my ($uname,$udom) = @_;
1.536     raeburn  6982:     my ($quota,$quotatype,$settingstatus,$defquota);
1.472     raeburn  6983:     if (!defined($udom)) {
                   6984:         $udom = $env{'user.domain'};
                   6985:     }
                   6986:     if (!defined($uname)) {
                   6987:         $uname = $env{'user.name'};
                   6988:     }
                   6989:     if (($udom eq '' || $uname eq '') ||
                   6990:         ($udom eq 'public') && ($uname eq 'public')) {
                   6991:         $quota = 0;
1.536     raeburn  6992:         $quotatype = 'default';
                   6993:         $defquota = 0; 
1.472     raeburn  6994:     } else {
1.536     raeburn  6995:         my $inststatus;
1.472     raeburn  6996:         if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
                   6997:             $quota = $env{'environment.portfolioquota'};
1.536     raeburn  6998:             $inststatus = $env{'environment.inststatus'};
1.472     raeburn  6999:         } else {
1.536     raeburn  7000:             my %userenv = 
                   7001:                 &Apache::lonnet::get('environment',['portfolioquota',
                   7002:                                      'inststatus'],$udom,$uname);
1.472     raeburn  7003:             my ($tmp) = keys(%userenv);
                   7004:             if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   7005:                 $quota = $userenv{'portfolioquota'};
1.536     raeburn  7006:                 $inststatus = $userenv{'inststatus'};
1.472     raeburn  7007:             } else {
                   7008:                 undef(%userenv);
                   7009:             }
                   7010:         }
1.536     raeburn  7011:         ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472     raeburn  7012:         if ($quota eq '') {
1.536     raeburn  7013:             $quota = $defquota;
                   7014:             $quotatype = 'default';
                   7015:         } else {
                   7016:             $quotatype = 'custom';
1.472     raeburn  7017:         }
                   7018:     }
1.536     raeburn  7019:     if (wantarray) {
                   7020:         return ($quota,$quotatype,$settingstatus,$defquota);
                   7021:     } else {
                   7022:         return $quota;
                   7023:     }
1.472     raeburn  7024: }
                   7025: 
                   7026: ###############################################
                   7027: 
                   7028: =pod
                   7029: 
                   7030: =item * &default_quota()
                   7031: 
1.536     raeburn  7032: Retrieves default quota assigned for storage of user portfolio files,
                   7033: given an (optional) user's institutional status.
1.472     raeburn  7034: 
                   7035: Incoming parameters:
                   7036: 1. domain
1.536     raeburn  7037: 2. (Optional) institutional status(es).  This is a : separated list of 
                   7038:    status types (e.g., faculty, staff, student etc.)
                   7039:    which apply to the user for whom the default is being retrieved.
                   7040:    If the institutional status string in undefined, the domain
                   7041:    default quota will be returned. 
1.472     raeburn  7042: 
                   7043: Returns:
                   7044: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536     raeburn  7045: 2. (Optional) institutional type which determined the value of the
                   7046:    default quota.
1.472     raeburn  7047: 
                   7048: If a value has been stored in the domain's configuration db,
                   7049: it will return that, otherwise it returns 20 (for backwards 
                   7050: compatibility with domains which have not set up a configuration
                   7051: db file; the original statically defined portfolio quota was 20 Mb). 
                   7052: 
1.536     raeburn  7053: If the user's status includes multiple types (e.g., staff and student),
                   7054: the largest default quota which applies to the user determines the
                   7055: default quota returned.
                   7056: 
1.780     raeburn  7057: =back
                   7058: 
1.472     raeburn  7059: =cut
                   7060: 
                   7061: ###############################################
                   7062: 
                   7063: 
                   7064: sub default_quota {
1.536     raeburn  7065:     my ($udom,$inststatus) = @_;
                   7066:     my ($defquota,$settingstatus);
                   7067:     my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622     raeburn  7068:                                             ['quotas'],$udom);
                   7069:     if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536     raeburn  7070:         if ($inststatus ne '') {
1.765     raeburn  7071:             my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536     raeburn  7072:             foreach my $item (@statuses) {
1.711     raeburn  7073:                 if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
                   7074:                     if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
                   7075:                         if ($defquota eq '') {
                   7076:                             $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
                   7077:                             $settingstatus = $item;
                   7078:                         } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
                   7079:                             $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
                   7080:                             $settingstatus = $item;
                   7081:                         }
                   7082:                     }
                   7083:                 } else {
                   7084:                     if ($quotahash{'quotas'}{$item} ne '') {
                   7085:                         if ($defquota eq '') {
                   7086:                             $defquota = $quotahash{'quotas'}{$item};
                   7087:                             $settingstatus = $item;
                   7088:                         } elsif ($quotahash{'quotas'}{$item} > $defquota) {
                   7089:                             $defquota = $quotahash{'quotas'}{$item};
                   7090:                             $settingstatus = $item;
                   7091:                         }
1.536     raeburn  7092:                     }
                   7093:                 }
                   7094:             }
                   7095:         }
                   7096:         if ($defquota eq '') {
1.711     raeburn  7097:             if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
                   7098:                 $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
                   7099:             } else {
                   7100:                 $defquota = $quotahash{'quotas'}{'default'};
                   7101:             }
1.536     raeburn  7102:             $settingstatus = 'default';
                   7103:         }
                   7104:     } else {
                   7105:         $settingstatus = 'default';
                   7106:         $defquota = 20;
                   7107:     }
                   7108:     if (wantarray) {
                   7109:         return ($defquota,$settingstatus);
1.472     raeburn  7110:     } else {
1.536     raeburn  7111:         return $defquota;
1.472     raeburn  7112:     }
                   7113: }
                   7114: 
1.384     raeburn  7115: sub get_secgrprole_info {
                   7116:     my ($cdom,$cnum,$needroles,$type)  = @_;
                   7117:     my %sections_count = &get_sections($cdom,$cnum);
                   7118:     my @sections =  (sort {$a <=> $b} keys(%sections_count));
                   7119:     my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
                   7120:     my @groups = sort(keys(%curr_groups));
                   7121:     my $allroles = [];
                   7122:     my $rolehash;
                   7123:     my $accesshash = {
                   7124:                      active => 'Currently has access',
                   7125:                      future => 'Will have future access',
                   7126:                      previous => 'Previously had access',
                   7127:                   };
                   7128:     if ($needroles) {
                   7129:         $rolehash = {'all' => 'all'};
1.385     albertel 7130:         my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   7131: 	if (&Apache::lonnet::error(%user_roles)) {
                   7132: 	    undef(%user_roles);
                   7133: 	}
                   7134:         foreach my $item (keys(%user_roles)) {
1.384     raeburn  7135:             my ($role)=split(/\:/,$item,2);
                   7136:             if ($role eq 'cr') { next; }
                   7137:             if ($role =~ /^cr/) {
                   7138:                 $$rolehash{$role} = (split('/',$role))[3];
                   7139:             } else {
                   7140:                 $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
                   7141:             }
                   7142:         }
                   7143:         foreach my $key (sort(keys(%{$rolehash}))) {
                   7144:             push(@{$allroles},$key);
                   7145:         }
                   7146:         push (@{$allroles},'st');
                   7147:         $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
                   7148:     }
                   7149:     return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
                   7150: }
                   7151: 
1.555     raeburn  7152: sub user_picker {
1.627     raeburn  7153:     my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555     raeburn  7154:     my $currdom = $dom;
                   7155:     my %curr_selected = (
                   7156:                         srchin => 'dom',
1.580     raeburn  7157:                         srchby => 'lastname',
1.555     raeburn  7158:                       );
                   7159:     my $srchterm;
1.625     raeburn  7160:     if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555     raeburn  7161:         if ($srch->{'srchby'} ne '') {
                   7162:             $curr_selected{'srchby'} = $srch->{'srchby'};
                   7163:         }
                   7164:         if ($srch->{'srchin'} ne '') {
                   7165:             $curr_selected{'srchin'} = $srch->{'srchin'};
                   7166:         }
                   7167:         if ($srch->{'srchtype'} ne '') {
                   7168:             $curr_selected{'srchtype'} = $srch->{'srchtype'};
                   7169:         }
                   7170:         if ($srch->{'srchdomain'} ne '') {
                   7171:             $currdom = $srch->{'srchdomain'};
                   7172:         }
                   7173:         $srchterm = $srch->{'srchterm'};
                   7174:     }
                   7175:     my %lt=&Apache::lonlocal::texthash(
1.573     raeburn  7176:                     'usr'       => 'Search criteria',
1.563     raeburn  7177:                     'doma'      => 'Domain/institution to search',
1.558     albertel 7178:                     'uname'     => 'username',
                   7179:                     'lastname'  => 'last name',
1.555     raeburn  7180:                     'lastfirst' => 'last name, first name',
1.558     albertel 7181:                     'crs'       => 'in this course',
1.576     raeburn  7182:                     'dom'       => 'in selected LON-CAPA domain', 
1.558     albertel 7183:                     'alc'       => 'all LON-CAPA',
1.573     raeburn  7184:                     'instd'     => 'in institutional directory for selected domain',
1.558     albertel 7185:                     'exact'     => 'is',
                   7186:                     'contains'  => 'contains',
1.569     raeburn  7187:                     'begins'    => 'begins with',
1.571     raeburn  7188:                     'youm'      => "You must include some text to search for.",
                   7189:                     'thte'      => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
                   7190:                     'thet'      => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
                   7191:                     'yomc'      => "You must choose a domain when using an institutional directory search.",
                   7192:                     'ymcd'      => "You must choose a domain when using a domain search.",
                   7193:                     'whus'      => "When using searching by last,first you must include a comma as separator between last name and first name.",
                   7194:                     'whse'      => "When searching by last,first you must include at least one character in the first name.",
                   7195:                      'thfo'     => "The following need to be corrected before the search can be run:",
1.555     raeburn  7196:                                        );
1.563     raeburn  7197:     my $domform = &select_dom_form($currdom,'srchdomain',1,1);
                   7198:     my $srchinsel = ' <select name="srchin">';
1.555     raeburn  7199: 
                   7200:     my @srchins = ('crs','dom','alc','instd');
                   7201: 
                   7202:     foreach my $option (@srchins) {
                   7203:         # FIXME 'alc' option unavailable until 
                   7204:         #       loncreateuser::print_user_query_page()
                   7205:         #       has been completed.
                   7206:         next if ($option eq 'alc');
                   7207:         next if ($option eq 'crs' && !$env{'request.course.id'});
1.563     raeburn  7208:         if ($curr_selected{'srchin'} eq $option) {
                   7209:             $srchinsel .= ' 
                   7210:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7211:         } else {
                   7212:             $srchinsel .= '
                   7213:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7214:         }
1.555     raeburn  7215:     }
1.563     raeburn  7216:     $srchinsel .= "\n  </select>\n";
1.555     raeburn  7217: 
                   7218:     my $srchbysel =  ' <select name="srchby">';
1.580     raeburn  7219:     foreach my $option ('lastname','lastfirst','uname') {
1.555     raeburn  7220:         if ($curr_selected{'srchby'} eq $option) {
                   7221:             $srchbysel .= '
                   7222:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7223:         } else {
                   7224:             $srchbysel .= '
                   7225:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7226:          }
                   7227:     }
                   7228:     $srchbysel .= "\n  </select>\n";
                   7229: 
                   7230:     my $srchtypesel = ' <select name="srchtype">';
1.580     raeburn  7231:     foreach my $option ('begins','contains','exact') {
1.555     raeburn  7232:         if ($curr_selected{'srchtype'} eq $option) {
                   7233:             $srchtypesel .= '
                   7234:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7235:         } else {
                   7236:             $srchtypesel .= '
                   7237:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7238:         }
                   7239:     }
                   7240:     $srchtypesel .= "\n  </select>\n";
                   7241: 
1.558     albertel 7242:     my ($newuserscript,$new_user_create);
1.556     raeburn  7243: 
                   7244:     if ($forcenewuser) {
1.576     raeburn  7245:         if (ref($srch) eq 'HASH') {
                   7246:             if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627     raeburn  7247:                 if ($cancreate) {
                   7248:                     $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>';
                   7249:                 } else {
                   7250:                     my $helplink = ' href="javascript:helpMenu('."'display'".')"';
                   7251:                     my %usertypetext = (
                   7252:                         official   => 'institutional',
                   7253:                         unofficial => 'non-institutional',
                   7254:                     );
                   7255:                     $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 />';
                   7256:                 }
1.576     raeburn  7257:             }
                   7258:         }
                   7259: 
1.556     raeburn  7260:         $newuserscript = <<"ENDSCRIPT";
                   7261: 
1.570     raeburn  7262: function setSearch(createnew,callingForm) {
1.556     raeburn  7263:     if (createnew == 1) {
1.570     raeburn  7264:         for (var i=0; i<callingForm.srchby.length; i++) {
                   7265:             if (callingForm.srchby.options[i].value == 'uname') {
                   7266:                 callingForm.srchby.selectedIndex = i;
1.556     raeburn  7267:             }
                   7268:         }
1.570     raeburn  7269:         for (var i=0; i<callingForm.srchin.length; i++) {
                   7270:             if ( callingForm.srchin.options[i].value == 'dom') {
                   7271: 		callingForm.srchin.selectedIndex = i;
1.556     raeburn  7272:             }
                   7273:         }
1.570     raeburn  7274:         for (var i=0; i<callingForm.srchtype.length; i++) {
                   7275:             if (callingForm.srchtype.options[i].value == 'exact') {
                   7276:                 callingForm.srchtype.selectedIndex = i;
1.556     raeburn  7277:             }
                   7278:         }
1.570     raeburn  7279:         for (var i=0; i<callingForm.srchdomain.length; i++) {
                   7280:             if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
                   7281:                 callingForm.srchdomain.selectedIndex = i;
1.556     raeburn  7282:             }
                   7283:         }
                   7284:     }
                   7285: }
                   7286: ENDSCRIPT
1.558     albertel 7287: 
1.556     raeburn  7288:     }
                   7289: 
1.555     raeburn  7290:     my $output = <<"END_BLOCK";
1.556     raeburn  7291: <script type="text/javascript">
1.570     raeburn  7292: function validateEntry(callingForm) {
1.558     albertel 7293: 
1.556     raeburn  7294:     var checkok = 1;
1.558     albertel 7295:     var srchin;
1.570     raeburn  7296:     for (var i=0; i<callingForm.srchin.length; i++) {
                   7297: 	if ( callingForm.srchin[i].checked ) {
                   7298: 	    srchin = callingForm.srchin[i].value;
1.558     albertel 7299: 	}
                   7300:     }
                   7301: 
1.570     raeburn  7302:     var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
                   7303:     var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
                   7304:     var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
                   7305:     var srchterm =  callingForm.srchterm.value;
                   7306:     var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556     raeburn  7307:     var msg = "";
                   7308: 
                   7309:     if (srchterm == "") {
                   7310:         checkok = 0;
1.571     raeburn  7311:         msg += "$lt{'youm'}\\n";
1.556     raeburn  7312:     }
                   7313: 
1.569     raeburn  7314:     if (srchtype== 'begins') {
                   7315:         if (srchterm.length < 2) {
                   7316:             checkok = 0;
1.571     raeburn  7317:             msg += "$lt{'thte'}\\n";
1.569     raeburn  7318:         }
                   7319:     }
                   7320: 
1.556     raeburn  7321:     if (srchtype== 'contains') {
                   7322:         if (srchterm.length < 3) {
                   7323:             checkok = 0;
1.571     raeburn  7324:             msg += "$lt{'thet'}\\n";
1.556     raeburn  7325:         }
                   7326:     }
                   7327:     if (srchin == 'instd') {
                   7328:         if (srchdomain == '') {
                   7329:             checkok = 0;
1.571     raeburn  7330:             msg += "$lt{'yomc'}\\n";
1.556     raeburn  7331:         }
                   7332:     }
                   7333:     if (srchin == 'dom') {
                   7334:         if (srchdomain == '') {
                   7335:             checkok = 0;
1.571     raeburn  7336:             msg += "$lt{'ymcd'}\\n";
1.556     raeburn  7337:         }
                   7338:     }
                   7339:     if (srchby == 'lastfirst') {
                   7340:         if (srchterm.indexOf(",") == -1) {
                   7341:             checkok = 0;
1.571     raeburn  7342:             msg += "$lt{'whus'}\\n";
1.556     raeburn  7343:         }
                   7344:         if (srchterm.indexOf(",") == srchterm.length -1) {
                   7345:             checkok = 0;
1.571     raeburn  7346:             msg += "$lt{'whse'}\\n";
1.556     raeburn  7347:         }
                   7348:     }
                   7349:     if (checkok == 0) {
1.571     raeburn  7350:         alert("$lt{'thfo'}\\n"+msg);
1.556     raeburn  7351:         return;
                   7352:     }
                   7353:     if (checkok == 1) {
1.570     raeburn  7354:         callingForm.submit();
1.556     raeburn  7355:     }
                   7356: }
                   7357: 
                   7358: $newuserscript
                   7359: 
                   7360: </script>
1.558     albertel 7361: 
                   7362: $new_user_create
                   7363: 
1.555     raeburn  7364: <table>
1.558     albertel 7365:  <tr>
1.573     raeburn  7366:   <td>$lt{'doma'}:</td>
                   7367:   <td>$domform</td>
                   7368:   </td>
                   7369:  </tr>
                   7370:  <tr>
                   7371:   <td>$lt{'usr'}:</td>
1.563     raeburn  7372:   <td>$srchbysel
                   7373:       $srchtypesel 
                   7374:       <input type="text" size="15" name="srchterm" value="$srchterm" />
1.564     albertel 7375:       $srchinsel 
1.563     raeburn  7376:   </td>
                   7377:  </tr>
1.555     raeburn  7378: </table>
                   7379: <br />
                   7380: END_BLOCK
1.558     albertel 7381: 
1.555     raeburn  7382:     return $output;
                   7383: }
                   7384: 
1.612     raeburn  7385: sub user_rule_check {
1.615     raeburn  7386:     my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612     raeburn  7387:     my $response;
                   7388:     if (ref($usershash) eq 'HASH') {
                   7389:         foreach my $user (keys(%{$usershash})) {
                   7390:             my ($uname,$udom) = split(/:/,$user);
                   7391:             next if ($udom eq '' || $uname eq '');
1.615     raeburn  7392:             my ($id,$newuser);
1.612     raeburn  7393:             if (ref($usershash->{$user}) eq 'HASH') {
1.615     raeburn  7394:                 $newuser = $usershash->{$user}->{'newuser'};
1.612     raeburn  7395:                 $id = $usershash->{$user}->{'id'};
                   7396:             }
                   7397:             my $inst_response;
                   7398:             if (ref($checks) eq 'HASH') {
                   7399:                 if (defined($checks->{'username'})) {
1.615     raeburn  7400:                     ($inst_response,%{$inst_results->{$user}}) = 
1.612     raeburn  7401:                         &Apache::lonnet::get_instuser($udom,$uname);
                   7402:                 } elsif (defined($checks->{'id'})) {
1.615     raeburn  7403:                     ($inst_response,%{$inst_results->{$user}}) =
1.612     raeburn  7404:                         &Apache::lonnet::get_instuser($udom,undef,$id);
                   7405:                 }
1.615     raeburn  7406:             } else {
                   7407:                 ($inst_response,%{$inst_results->{$user}}) =
                   7408:                     &Apache::lonnet::get_instuser($udom,$uname);
                   7409:                 return;
1.612     raeburn  7410:             }
1.615     raeburn  7411:             if (!$got_rules->{$udom}) {
1.612     raeburn  7412:                 my %domconfig = &Apache::lonnet::get_dom('configuration',
                   7413:                                                   ['usercreation'],$udom);
                   7414:                 if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615     raeburn  7415:                     foreach my $item ('username','id') {
1.612     raeburn  7416:                         if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
                   7417:                             $$curr_rules{$udom}{$item} = 
                   7418:                                 $domconfig{'usercreation'}{$item.'_rule'};
1.585     raeburn  7419:                         }
                   7420:                     }
                   7421:                 }
1.615     raeburn  7422:                 $got_rules->{$udom} = 1;  
1.585     raeburn  7423:             }
1.612     raeburn  7424:             foreach my $item (keys(%{$checks})) {
                   7425:                 if (ref($$curr_rules{$udom}) eq 'HASH') {
                   7426:                     if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
                   7427:                         if (@{$$curr_rules{$udom}{$item}} > 0) {
                   7428:                             my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
                   7429:                             foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
                   7430:                                 if ($rule_check{$rule}) {
                   7431:                                     $$rulematch{$user}{$item} = $rule;
                   7432:                                     if ($inst_response eq 'ok') {
1.615     raeburn  7433:                                         if (ref($inst_results) eq 'HASH') {
                   7434:                                             if (ref($inst_results->{$user}) eq 'HASH') {
                   7435:                                                 if (keys(%{$inst_results->{$user}}) == 0) {
                   7436:                                                     $$alerts{$item}{$udom}{$uname} = 1;
                   7437:                                                 }
1.612     raeburn  7438:                                             }
                   7439:                                         }
1.615     raeburn  7440:                                     }
                   7441:                                     last;
1.585     raeburn  7442:                                 }
                   7443:                             }
                   7444:                         }
                   7445:                     }
                   7446:                 }
                   7447:             }
                   7448:         }
                   7449:     }
1.612     raeburn  7450:     return;
                   7451: }
                   7452: 
                   7453: sub user_rule_formats {
                   7454:     my ($domain,$domdesc,$curr_rules,$check) = @_;
                   7455:     my %text = ( 
                   7456:                  'username' => 'Usernames',
                   7457:                  'id'       => 'IDs',
                   7458:                );
                   7459:     my $output;
                   7460:     my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
                   7461:     if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
                   7462:         if (@{$ruleorder} > 0) {
                   7463:             $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>';
                   7464:             foreach my $rule (@{$ruleorder}) {
                   7465:                 if (ref($curr_rules) eq 'ARRAY') {
                   7466:                     if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
                   7467:                         if (ref($rules->{$rule}) eq 'HASH') {
                   7468:                             $output .= '<li>'.$rules->{$rule}{'name'}.': '.
                   7469:                                         $rules->{$rule}{'desc'}.'</li>';
                   7470:                         }
                   7471:                     }
                   7472:                 }
                   7473:             }
                   7474:             $output .= '</ul>';
                   7475:         }
                   7476:     }
                   7477:     return $output;
                   7478: }
                   7479: 
                   7480: sub instrule_disallow_msg {
1.615     raeburn  7481:     my ($checkitem,$domdesc,$count,$mode) = @_;
1.612     raeburn  7482:     my $response;
                   7483:     my %text = (
                   7484:                   item   => 'username',
                   7485:                   items  => 'usernames',
                   7486:                   match  => 'matches',
                   7487:                   do     => 'does',
                   7488:                   action => 'a username',
                   7489:                   one    => 'one',
                   7490:                );
                   7491:     if ($count > 1) {
                   7492:         $text{'item'} = 'usernames';
                   7493:         $text{'match'} ='match';
                   7494:         $text{'do'} = 'do';
                   7495:         $text{'action'} = 'usernames',
                   7496:         $text{'one'} = 'ones';
                   7497:     }
                   7498:     if ($checkitem eq 'id') {
                   7499:         $text{'items'} = 'IDs';
                   7500:         $text{'item'} = 'ID';
                   7501:         $text{'action'} = 'an ID';
1.615     raeburn  7502:         if ($count > 1) {
                   7503:             $text{'item'} = 'IDs';
                   7504:             $text{'action'} = 'IDs';
                   7505:         }
1.612     raeburn  7506:     }
1.674     bisitz   7507:     $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  7508:     if ($mode eq 'upload') {
                   7509:         if ($checkitem eq 'username') {
                   7510:             $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'}.");
                   7511:         } elsif ($checkitem eq 'id') {
1.674     bisitz   7512:             $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  7513:         }
1.669     raeburn  7514:     } elsif ($mode eq 'selfcreate') {
                   7515:         if ($checkitem eq 'id') {
                   7516:             $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.");
                   7517:         }
1.615     raeburn  7518:     } else {
                   7519:         if ($checkitem eq 'username') {
                   7520:             $response .= &mt("You must choose $text{'action'} with a different format --  $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
                   7521:         } elsif ($checkitem eq 'id') {
                   7522:             $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.");
                   7523:         }
1.612     raeburn  7524:     }
                   7525:     return $response;
1.585     raeburn  7526: }
                   7527: 
1.624     raeburn  7528: sub personal_data_fieldtitles {
                   7529:     my %fieldtitles = &Apache::lonlocal::texthash (
                   7530:                         id => 'Student/Employee ID',
                   7531:                         permanentemail => 'E-mail address',
                   7532:                         lastname => 'Last Name',
                   7533:                         firstname => 'First Name',
                   7534:                         middlename => 'Middle Name',
                   7535:                         generation => 'Generation',
                   7536:                         gen => 'Generation',
1.765     raeburn  7537:                         inststatus => 'Affiliation',
1.624     raeburn  7538:                    );
                   7539:     return %fieldtitles;
                   7540: }
                   7541: 
1.642     raeburn  7542: sub sorted_inst_types {
                   7543:     my ($dom) = @_;
                   7544:     my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
                   7545:     my $othertitle = &mt('All users');
                   7546:     if ($env{'request.course.id'}) {
1.668     raeburn  7547:         $othertitle  = &mt('Any users');
1.642     raeburn  7548:     }
                   7549:     my @types;
                   7550:     if (ref($order) eq 'ARRAY') {
                   7551:         @types = @{$order};
                   7552:     }
                   7553:     if (@types == 0) {
                   7554:         if (ref($usertypes) eq 'HASH') {
                   7555:             @types = sort(keys(%{$usertypes}));
                   7556:         }
                   7557:     }
                   7558:     if (keys(%{$usertypes}) > 0) {
                   7559:         $othertitle = &mt('Other users');
                   7560:     }
                   7561:     return ($othertitle,$usertypes,\@types);
                   7562: }
                   7563: 
1.645     raeburn  7564: sub get_institutional_codes {
                   7565:     my ($settings,$allcourses,$LC_code) = @_;
                   7566: # Get complete list of course sections to update
                   7567:     my @currsections = ();
                   7568:     my @currxlists = ();
                   7569:     my $coursecode = $$settings{'internal.coursecode'};
                   7570: 
                   7571:     if ($$settings{'internal.sectionnums'} ne '') {
                   7572:         @currsections = split(/,/,$$settings{'internal.sectionnums'});
                   7573:     }
                   7574: 
                   7575:     if ($$settings{'internal.crosslistings'} ne '') {
                   7576:         @currxlists = split(/,/,$$settings{'internal.crosslistings'});
                   7577:     }
                   7578: 
                   7579:     if (@currxlists > 0) {
                   7580:         foreach (@currxlists) {
                   7581:             if (m/^([^:]+):(\w*)$/) {
                   7582:                 unless (grep/^$1$/,@{$allcourses}) {
                   7583:                     push @{$allcourses},$1;
                   7584:                     $$LC_code{$1} = $2;
                   7585:                 }
                   7586:             }
                   7587:         }
                   7588:     }
                   7589:  
                   7590:     if (@currsections > 0) {
                   7591:         foreach (@currsections) {
                   7592:             if (m/^(\w+):(\w*)$/) {
                   7593:                 my $sec = $coursecode.$1;
                   7594:                 my $lc_sec = $2;
                   7595:                 unless (grep/^$sec$/,@{$allcourses}) {
                   7596:                     push @{$allcourses},$sec;
                   7597:                     $$LC_code{$sec} = $lc_sec;
                   7598:                 }
                   7599:             }
                   7600:         }
                   7601:     }
                   7602:     return;
                   7603: }
                   7604: 
1.112     bowersj2 7605: =pod
                   7606: 
1.780     raeburn  7607: =head1 Slot Helpers
                   7608: 
                   7609: =over 4
                   7610: 
                   7611: =item * sorted_slots()
                   7612: 
                   7613: Sorts an array of slot names in order of slot start time (earliest first). 
                   7614: 
                   7615: Inputs:
                   7616: 
                   7617: =over 4
                   7618: 
                   7619: slotsarr  - Reference to array of unsorted slot names.
                   7620: 
                   7621: slots     - Reference to hash of hash, where outer hash keys are slot names.
                   7622: 
1.549     albertel 7623: =back
                   7624: 
1.780     raeburn  7625: Returns:
                   7626: 
                   7627: =over 4
                   7628: 
                   7629: sorted   - An array of slot names sorted by the start time of the slot.
                   7630: 
                   7631: =back
                   7632: 
                   7633: =back
                   7634: 
                   7635: =cut
                   7636: 
                   7637: 
                   7638: sub sorted_slots {
                   7639:     my ($slotsarr,$slots) = @_;
                   7640:     my @sorted;
                   7641:     if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
                   7642:         @sorted =
                   7643:             sort {
                   7644:                      if (ref($slots->{$a}) && ref($slots->{$b})) {
                   7645:                          return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
                   7646:                      }
                   7647:                      if (ref($slots->{$a})) { return -1;}
                   7648:                      if (ref($slots->{$b})) { return 1;}
                   7649:                      return 0;
                   7650:                  } @{$slotsarr};
                   7651:     }
                   7652:     return @sorted;
                   7653: }
                   7654: 
                   7655: 
                   7656: =pod
                   7657: 
1.549     albertel 7658: =head1 HTTP Helpers
                   7659: 
                   7660: =over 4
                   7661: 
1.648     raeburn  7662: =item * &get_unprocessed_cgi($query,$possible_names)
1.112     bowersj2 7663: 
1.258     albertel 7664: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112     bowersj2 7665: $query.  The parameters listed in $possible_names (an array reference),
1.258     albertel 7666: will be set in $env{'form.name'} if they do not already exist.
1.112     bowersj2 7667: 
                   7668: Typically called with $ENV{'QUERY_STRING'} as the first parameter.  
                   7669: $possible_names is an ref to an array of form element names.  As an example:
                   7670: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258     albertel 7671: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112     bowersj2 7672: 
                   7673: =cut
1.1       albertel 7674: 
1.6       albertel 7675: sub get_unprocessed_cgi {
1.25      albertel 7676:   my ($query,$possible_names)= @_;
1.26      matthew  7677:   # $Apache::lonxml::debug=1;
1.356     albertel 7678:   foreach my $pair (split(/&/,$query)) {
                   7679:     my ($name, $value) = split(/=/,$pair);
1.369     www      7680:     $name = &unescape($name);
1.25      albertel 7681:     if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
                   7682:       $value =~ tr/+/ /;
                   7683:       $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258     albertel 7684:       unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25      albertel 7685:     }
1.16      harris41 7686:   }
1.6       albertel 7687: }
                   7688: 
1.112     bowersj2 7689: =pod
                   7690: 
1.648     raeburn  7691: =item * &cacheheader() 
1.112     bowersj2 7692: 
                   7693: returns cache-controlling header code
                   7694: 
                   7695: =cut
                   7696: 
1.7       albertel 7697: sub cacheheader {
1.258     albertel 7698:     unless ($env{'request.method'} eq 'GET') { return ''; }
1.216     albertel 7699:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
                   7700:     my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7       albertel 7701:                 <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
                   7702:                 <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216     albertel 7703:     return $output;
1.7       albertel 7704: }
                   7705: 
1.112     bowersj2 7706: =pod
                   7707: 
1.648     raeburn  7708: =item * &no_cache($r) 
1.112     bowersj2 7709: 
                   7710: specifies header code to not have cache
                   7711: 
                   7712: =cut
                   7713: 
1.9       albertel 7714: sub no_cache {
1.216     albertel 7715:     my ($r) = @_;
                   7716:     if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258     albertel 7717: 	$env{'request.method'} ne 'GET') { return ''; }
1.216     albertel 7718:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
                   7719:     $r->no_cache(1);
                   7720:     $r->header_out("Expires" => $date);
                   7721:     $r->header_out("Pragma" => "no-cache");
1.123     www      7722: }
                   7723: 
                   7724: sub content_type {
1.181     albertel 7725:     my ($r,$type,$charset) = @_;
1.299     foxr     7726:     if ($r) {
                   7727: 	#  Note that printout.pl calls this with undef for $r.
                   7728: 	&no_cache($r);
                   7729:     }
1.258     albertel 7730:     if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181     albertel 7731:     unless ($charset) {
                   7732: 	$charset=&Apache::lonlocal::current_encoding;
                   7733:     }
                   7734:     if ($charset) { $type.='; charset='.$charset; }
                   7735:     if ($r) {
                   7736: 	$r->content_type($type);
                   7737:     } else {
                   7738: 	print("Content-type: $type\n\n");
                   7739:     }
1.9       albertel 7740: }
1.25      albertel 7741: 
1.112     bowersj2 7742: =pod
                   7743: 
1.648     raeburn  7744: =item * &add_to_env($name,$value) 
1.112     bowersj2 7745: 
1.258     albertel 7746: adds $name to the %env hash with value
1.112     bowersj2 7747: $value, if $name already exists, the entry is converted to an array
                   7748: reference and $value is added to the array.
                   7749: 
                   7750: =cut
                   7751: 
1.25      albertel 7752: sub add_to_env {
                   7753:   my ($name,$value)=@_;
1.258     albertel 7754:   if (defined($env{$name})) {
                   7755:     if (ref($env{$name})) {
1.25      albertel 7756:       #already have multiple values
1.258     albertel 7757:       push(@{ $env{$name} },$value);
1.25      albertel 7758:     } else {
                   7759:       #first time seeing multiple values, convert hash entry to an arrayref
1.258     albertel 7760:       my $first=$env{$name};
                   7761:       undef($env{$name});
                   7762:       push(@{ $env{$name} },$first,$value);
1.25      albertel 7763:     }
                   7764:   } else {
1.258     albertel 7765:     $env{$name}=$value;
1.25      albertel 7766:   }
1.31      albertel 7767: }
1.149     albertel 7768: 
                   7769: =pod
                   7770: 
1.648     raeburn  7771: =item * &get_env_multiple($name) 
1.149     albertel 7772: 
1.258     albertel 7773: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149     albertel 7774: values may be defined and end up as an array ref.
                   7775: 
                   7776: returns an array of values
                   7777: 
                   7778: =cut
                   7779: 
                   7780: sub get_env_multiple {
                   7781:     my ($name) = @_;
                   7782:     my @values;
1.258     albertel 7783:     if (defined($env{$name})) {
1.149     albertel 7784:         # exists is it an array
1.258     albertel 7785:         if (ref($env{$name})) {
                   7786:             @values=@{ $env{$name} };
1.149     albertel 7787:         } else {
1.258     albertel 7788:             $values[0]=$env{$name};
1.149     albertel 7789:         }
                   7790:     }
                   7791:     return(@values);
                   7792: }
                   7793: 
1.660     raeburn  7794: sub ask_for_embedded_content {
                   7795:     my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
                   7796:     my $upload_output = '
                   7797:    <form name="upload_embedded" action="'.$actionurl.'"
                   7798:                   method="post" enctype="multipart/form-data">';
                   7799:     $upload_output .= $state;
1.661     raeburn  7800:     $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
1.660     raeburn  7801: 
                   7802:     my $num = 0;
                   7803:     foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
                   7804:         $upload_output .= &start_data_table_row().
                   7805:             '<td>'.$embed_file.'</td><td>';
                   7806:         if ($args->{'ignore_remote_references'}
                   7807:             && $embed_file =~ m{^\w+://}) {
                   7808:             $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
                   7809:         } elsif ($args->{'error_on_invalid_names'}
                   7810:             && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
                   7811: 
                   7812:             $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
                   7813: 
                   7814:         } else {
                   7815:             $upload_output .='
1.661     raeburn  7816:            <input name="embedded_item_'.$num.'" type="file" value="" />
1.660     raeburn  7817:            <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
                   7818:             my $attrib = join(':',@{$$allfiles{$embed_file}});
                   7819:             $upload_output .=
                   7820:                 "\n\t\t".
                   7821:                 '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
                   7822:                 $attrib.'" />';
                   7823:             if (exists($$codebase{$embed_file})) {
                   7824:                 $upload_output .=
                   7825:                     "\n\t\t".
                   7826:                     '<input name="codebase_'.$num.'" type="hidden" value="'.
                   7827:                     &escape($$codebase{$embed_file}).'" />';
                   7828:             }
                   7829:         }
                   7830:         $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
                   7831:         $num++;
                   7832:     }
                   7833:     $upload_output .= &Apache::loncommon::end_data_table().'<br />
                   7834:    <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
                   7835:    <input type ="submit" value="'.&mt('Upload Listed Files').'" />
                   7836:    '.&mt('(only files for which a location has been provided will be uploaded)').'
                   7837:    </form>';
                   7838:     return $upload_output;
                   7839: }
                   7840: 
1.661     raeburn  7841: sub upload_embedded {
                   7842:     my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
                   7843:         $current_disk_usage) = @_;
                   7844:     my $output;
                   7845:     for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
                   7846:         next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
                   7847:         my $orig_uploaded_filename =
                   7848:             $env{'form.embedded_item_'.$i.'.filename'};
                   7849: 
                   7850:         $env{'form.embedded_orig_'.$i} =
                   7851:             &unescape($env{'form.embedded_orig_'.$i});
                   7852:         my ($path,$fname) =
                   7853:             ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
                   7854:         # no path, whole string is fname
                   7855:         if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
                   7856: 
                   7857:         $path = $env{'form.currentpath'}.$path;
                   7858:         $fname = &Apache::lonnet::clean_filename($fname);
                   7859:         # See if there is anything left
                   7860:         next if ($fname eq '');
                   7861: 
                   7862:         # Check if file already exists as a file or directory.
                   7863:         my ($state,$msg);
                   7864:         if ($context eq 'portfolio') {
                   7865:             my $port_path = $dirpath;
                   7866:             if ($group ne '') {
                   7867:                 $port_path = "groups/$group/$port_path";
                   7868:             }
                   7869:             ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
                   7870:                                               $dir_root,$port_path,$disk_quota,
                   7871:                                               $current_disk_usage,$uname,$udom);
                   7872:             if ($state eq 'will_exceed_quota'
                   7873:                 || $state eq 'file_locked'
                   7874:                 || $state eq 'file_exists' ) {
                   7875:                 $output .= $msg;
                   7876:                 next;
                   7877:             }
                   7878:         } elsif (($context eq 'author') || ($context eq 'testbank')) {
                   7879:             ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
                   7880:             if ($state eq 'exists') {
                   7881:                 $output .= $msg;
                   7882:                 next;
                   7883:             }
                   7884:         }
                   7885:         # Check if extension is valid
                   7886:         if (($fname =~ /\.(\w+)$/) &&
                   7887:             (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
                   7888:             $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
                   7889:             next;
                   7890:         } elsif (($fname =~ /\.(\w+)$/) &&
                   7891:                  (!defined(&Apache::loncommon::fileembstyle($1)))) {
                   7892:             $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
                   7893:             next;
                   7894:         } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
                   7895:             $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
                   7896:             next;
                   7897:         }
                   7898: 
                   7899:         $env{'form.embedded_item_'.$i.'.filename'}=$fname;
                   7900:         if ($context eq 'portfolio') {
                   7901:             my $result=
                   7902:                 &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
                   7903:                                                 $dirpath.$path);
                   7904:             if ($result !~ m|^/uploaded/|) {
                   7905:                 $output .= '<span class="LC_error">'
                   7906:                       .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
                   7907:                            ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
                   7908:                       .'</span><br />';
                   7909:                 next;
                   7910:             } else {
                   7911:                 $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
                   7912:                            $path.$fname.'</span>').'</p>';     
                   7913:             }
                   7914:         } else {
                   7915: # Save the file
                   7916:             my $target = $env{'form.embedded_item_'.$i};
                   7917:             my $fullpath = $dir_root.$dirpath.'/'.$path;
                   7918:             my $dest = $fullpath.$fname;
                   7919:             my $url = $url_root.$dirpath.'/'.$path.$fname;
                   7920:             my @parts=split(/\//,$fullpath);
                   7921:             my $count;
                   7922:             my $filepath = $dir_root;
                   7923:             for ($count=4;$count<=$#parts;$count++) {
                   7924:                 $filepath .= "/$parts[$count]";
                   7925:                 if ((-e $filepath)!=1) {
                   7926:                     mkdir($filepath,0770);
                   7927:                 }
                   7928:             }
                   7929:             my $fh;
                   7930:             if (!open($fh,'>'.$dest)) {
                   7931:                 &Apache::lonnet::logthis('Failed to create '.$dest);
                   7932:                 $output .= '<span class="LC_error">'.
                   7933:                            &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
                   7934:                            '</span><br />';
                   7935:             } else {
                   7936:                 if (!print $fh $env{'form.embedded_item_'.$i}) {
                   7937:                     &Apache::lonnet::logthis('Failed to write to '.$dest);
                   7938:                     $output .= '<span class="LC_error">'.
                   7939:                               &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
                   7940:                               '</span><br />';
                   7941:                 } else {
                   7942:                     if ($context eq 'testbank') {
                   7943:                         $output .= &mt('Embedded file uploaded successfully:').
                   7944:                                    '&nbsp;<a href="'.$url.'">'.
                   7945:                                    $orig_uploaded_filename.'</a><br />';
                   7946:                     } else {
1.705     tempelho 7947:                         $output .= '<span class=\"LC_fontsize_large\">'.
1.661     raeburn  7948:                                    &mt('View embedded file: [_1]','<a href="'.$url.'">'.
1.705     tempelho 7949:                                    $orig_uploaded_filename.'</a>').'</span><br />';
1.661     raeburn  7950:                     }
                   7951:                 }
                   7952:                 close($fh);
                   7953:             }
                   7954:         }
                   7955:     }
                   7956:     return $output;
                   7957: }
                   7958: 
                   7959: sub check_for_existing {
                   7960:     my ($path,$fname,$element) = @_;
                   7961:     my ($state,$msg);
                   7962:     if (-d $path.'/'.$fname) {
                   7963:         $state = 'exists';
                   7964:         $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
                   7965:     } elsif (-e $path.'/'.$fname) {
                   7966:         $state = 'exists';
                   7967:         $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
                   7968:     }
                   7969:     if ($state eq 'exists') {
                   7970:         $msg = '<span class="LC_error">'.$msg.'</span><br />';
                   7971:     }
                   7972:     return ($state,$msg);
                   7973: }
                   7974: 
                   7975: sub check_for_upload {
                   7976:     my ($path,$fname,$group,$element,$portfolio_root,$port_path,
                   7977:         $disk_quota,$current_disk_usage,$uname,$udom) = @_;
                   7978:     my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
                   7979:     my $getpropath = 1;
                   7980:     my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
                   7981:                                             $getpropath);
                   7982:     my $found_file = 0;
                   7983:     my $locked_file = 0;
                   7984:     foreach my $line (@dir_list) {
                   7985:         my ($file_name)=split(/\&/,$line,2);
                   7986:         if ($file_name eq $fname){
                   7987:             $file_name = $path.$file_name;
                   7988:             if ($group ne '') {
                   7989:                 $file_name = $group.$file_name;
                   7990:             }
                   7991:             $found_file = 1;
                   7992:             if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
                   7993:                 $locked_file = 1;
                   7994:             }
                   7995:         }
                   7996:     }
                   7997:     if (($current_disk_usage + $filesize) > $disk_quota){
                   7998:         my $msg = '<span class="LC_error">'.
                   7999:                 &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
                   8000:                   '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
                   8001:         return ('will_exceed_quota',$msg);
                   8002:     } elsif ($found_file) {
                   8003:         if ($locked_file) {
                   8004:             my $msg = '<span class="LC_error">';
                   8005:             $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>');
                   8006:             $msg .= '</span><br />';
                   8007:             $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
                   8008:             return ('file_locked',$msg);
                   8009:         } else {
                   8010:             my $msg = '<span class="LC_error">';
                   8011:             $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'});
                   8012:             $msg .= '</span>';
                   8013:             $msg .= '<br />';
                   8014:             $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
                   8015:             return ('file_exists',$msg);
                   8016:         }
                   8017:     }
                   8018: }
                   8019: 
1.31      albertel 8020: 
1.41      ng       8021: =pod
1.45      matthew  8022: 
1.464     albertel 8023: =back
1.41      ng       8024: 
1.112     bowersj2 8025: =head1 CSV Upload/Handling functions
1.38      albertel 8026: 
1.41      ng       8027: =over 4
                   8028: 
1.648     raeburn  8029: =item * &upfile_store($r)
1.41      ng       8030: 
                   8031: Store uploaded file, $r should be the HTTP Request object,
1.258     albertel 8032: needs $env{'form.upfile'}
1.41      ng       8033: returns $datatoken to be put into hidden field
                   8034: 
                   8035: =cut
1.31      albertel 8036: 
                   8037: sub upfile_store {
                   8038:     my $r=shift;
1.258     albertel 8039:     $env{'form.upfile'}=~s/\r/\n/gs;
                   8040:     $env{'form.upfile'}=~s/\f/\n/gs;
                   8041:     $env{'form.upfile'}=~s/\n+/\n/gs;
                   8042:     $env{'form.upfile'}=~s/\n+$//gs;
1.31      albertel 8043: 
1.258     albertel 8044:     my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
                   8045: 	'_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31      albertel 8046:     {
1.158     raeburn  8047:         my $datafile = $r->dir_config('lonDaemons').
                   8048:                            '/tmp/'.$datatoken.'.tmp';
                   8049:         if ( open(my $fh,">$datafile") ) {
1.258     albertel 8050:             print $fh $env{'form.upfile'};
1.158     raeburn  8051:             close($fh);
                   8052:         }
1.31      albertel 8053:     }
                   8054:     return $datatoken;
                   8055: }
                   8056: 
1.56      matthew  8057: =pod
                   8058: 
1.648     raeburn  8059: =item * &load_tmp_file($r)
1.41      ng       8060: 
                   8061: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258     albertel 8062: needs $env{'form.datatoken'},
                   8063: sets $env{'form.upfile'} to the contents of the file
1.41      ng       8064: 
                   8065: =cut
1.31      albertel 8066: 
                   8067: sub load_tmp_file {
                   8068:     my $r=shift;
                   8069:     my @studentdata=();
                   8070:     {
1.158     raeburn  8071:         my $studentfile = $r->dir_config('lonDaemons').
1.258     albertel 8072:                               '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158     raeburn  8073:         if ( open(my $fh,"<$studentfile") ) {
                   8074:             @studentdata=<$fh>;
                   8075:             close($fh);
                   8076:         }
1.31      albertel 8077:     }
1.258     albertel 8078:     $env{'form.upfile'}=join('',@studentdata);
1.31      albertel 8079: }
                   8080: 
1.56      matthew  8081: =pod
                   8082: 
1.648     raeburn  8083: =item * &upfile_record_sep()
1.41      ng       8084: 
                   8085: Separate uploaded file into records
                   8086: returns array of records,
1.258     albertel 8087: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41      ng       8088: 
                   8089: =cut
1.31      albertel 8090: 
                   8091: sub upfile_record_sep {
1.258     albertel 8092:     if ($env{'form.upfiletype'} eq 'xml') {
1.31      albertel 8093:     } else {
1.248     albertel 8094: 	my @records;
1.258     albertel 8095: 	foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248     albertel 8096: 	    if ($line=~/^\s*$/) { next; }
                   8097: 	    push(@records,$line);
                   8098: 	}
                   8099: 	return @records;
1.31      albertel 8100:     }
                   8101: }
                   8102: 
1.56      matthew  8103: =pod
                   8104: 
1.648     raeburn  8105: =item * &record_sep($record)
1.41      ng       8106: 
1.258     albertel 8107: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41      ng       8108: 
                   8109: =cut
                   8110: 
1.263     www      8111: sub takeleft {
                   8112:     my $index=shift;
                   8113:     return substr('0000'.$index,-4,4);
                   8114: }
                   8115: 
1.31      albertel 8116: sub record_sep {
                   8117:     my $record=shift;
                   8118:     my %components=();
1.258     albertel 8119:     if ($env{'form.upfiletype'} eq 'xml') {
                   8120:     } elsif ($env{'form.upfiletype'} eq 'space') {
1.31      albertel 8121:         my $i=0;
1.356     albertel 8122:         foreach my $field (split(/\s+/,$record)) {
1.31      albertel 8123:             $field=~s/^(\"|\')//;
                   8124:             $field=~s/(\"|\')$//;
1.263     www      8125:             $components{&takeleft($i)}=$field;
1.31      albertel 8126:             $i++;
                   8127:         }
1.258     albertel 8128:     } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31      albertel 8129:         my $i=0;
1.356     albertel 8130:         foreach my $field (split(/\t/,$record)) {
1.31      albertel 8131:             $field=~s/^(\"|\')//;
                   8132:             $field=~s/(\"|\')$//;
1.263     www      8133:             $components{&takeleft($i)}=$field;
1.31      albertel 8134:             $i++;
                   8135:         }
                   8136:     } else {
1.561     www      8137:         my $separator=',';
1.480     banghart 8138:         if ($env{'form.upfiletype'} eq 'semisv') {
1.561     www      8139:             $separator=';';
1.480     banghart 8140:         }
1.31      albertel 8141:         my $i=0;
1.561     www      8142: # the character we are looking for to indicate the end of a quote or a record 
                   8143:         my $looking_for=$separator;
                   8144: # do not add the characters to the fields
                   8145:         my $ignore=0;
                   8146: # we just encountered a separator (or the beginning of the record)
                   8147:         my $just_found_separator=1;
                   8148: # store the field we are working on here
                   8149:         my $field='';
                   8150: # work our way through all characters in record
                   8151:         foreach my $character ($record=~/(.)/g) {
                   8152:             if ($character eq $looking_for) {
                   8153:                if ($character ne $separator) {
                   8154: # Found the end of a quote, again looking for separator
                   8155:                   $looking_for=$separator;
                   8156:                   $ignore=1;
                   8157:                } else {
                   8158: # Found a separator, store away what we got
                   8159:                   $components{&takeleft($i)}=$field;
                   8160: 	          $i++;
                   8161:                   $just_found_separator=1;
                   8162:                   $ignore=0;
                   8163:                   $field='';
                   8164:                }
                   8165:                next;
                   8166:             }
                   8167: # single or double quotation marks after a separator indicate beginning of a quote
                   8168: # we are now looking for the end of the quote and need to ignore separators
                   8169:             if ((($character eq '"') || ($character eq "'")) && ($just_found_separator))  {
                   8170:                $looking_for=$character;
                   8171:                next;
                   8172:             }
                   8173: # ignore would be true after we reached the end of a quote
                   8174:             if ($ignore) { next; }
                   8175:             if (($just_found_separator) && ($character=~/\s/)) { next; }
                   8176:             $field.=$character;
                   8177:             $just_found_separator=0; 
1.31      albertel 8178:         }
1.561     www      8179: # catch the very last entry, since we never encountered the separator
                   8180:         $components{&takeleft($i)}=$field;
1.31      albertel 8181:     }
                   8182:     return %components;
                   8183: }
                   8184: 
1.144     matthew  8185: ######################################################
                   8186: ######################################################
                   8187: 
1.56      matthew  8188: =pod
                   8189: 
1.648     raeburn  8190: =item * &upfile_select_html()
1.41      ng       8191: 
1.144     matthew  8192: Return HTML code to select a file from the users machine and specify 
                   8193: the file type.
1.41      ng       8194: 
                   8195: =cut
                   8196: 
1.144     matthew  8197: ######################################################
                   8198: ######################################################
1.31      albertel 8199: sub upfile_select_html {
1.144     matthew  8200:     my %Types = (
                   8201:                  csv   => &mt('CSV (comma separated values, spreadsheet)'),
1.480     banghart 8202:                  semisv => &mt('Semicolon separated values'),
1.144     matthew  8203:                  space => &mt('Space separated'),
                   8204:                  tab   => &mt('Tabulator separated'),
                   8205: #                 xml   => &mt('HTML/XML'),
                   8206:                  );
                   8207:     my $Str = '<input type="file" name="upfile" size="50" />'.
1.727     riegler  8208:         '<br />'.&mt('Type').': <select name="upfiletype">';
1.144     matthew  8209:     foreach my $type (sort(keys(%Types))) {
                   8210:         $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
                   8211:     }
                   8212:     $Str .= "</select>\n";
                   8213:     return $Str;
1.31      albertel 8214: }
                   8215: 
1.301     albertel 8216: sub get_samples {
                   8217:     my ($records,$toget) = @_;
                   8218:     my @samples=({});
                   8219:     my $got=0;
                   8220:     foreach my $rec (@$records) {
                   8221: 	my %temp = &record_sep($rec);
                   8222: 	if (! grep(/\S/, values(%temp))) { next; }
                   8223: 	if (%temp) {
                   8224: 	    $samples[$got]=\%temp;
                   8225: 	    $got++;
                   8226: 	    if ($got == $toget) { last; }
                   8227: 	}
                   8228:     }
                   8229:     return \@samples;
                   8230: }
                   8231: 
1.144     matthew  8232: ######################################################
                   8233: ######################################################
                   8234: 
1.56      matthew  8235: =pod
                   8236: 
1.648     raeburn  8237: =item * &csv_print_samples($r,$records)
1.41      ng       8238: 
                   8239: Prints a table of sample values from each column uploaded $r is an
                   8240: Apache Request ref, $records is an arrayref from
                   8241: &Apache::loncommon::upfile_record_sep
                   8242: 
                   8243: =cut
                   8244: 
1.144     matthew  8245: ######################################################
                   8246: ######################################################
1.31      albertel 8247: sub csv_print_samples {
                   8248:     my ($r,$records) = @_;
1.662     bisitz   8249:     my $samples = &get_samples($records,5);
1.301     albertel 8250: 
1.594     raeburn  8251:     $r->print(&mt('Samples').'<br />'.&start_data_table().
                   8252:               &start_data_table_header_row());
1.356     albertel 8253:     foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) { 
                   8254:         $r->print('<th>'.&mt('Column&nbsp;[_1]',($sample+1)).'</th>'); }
1.594     raeburn  8255:     $r->print(&end_data_table_header_row());
1.301     albertel 8256:     foreach my $hash (@$samples) {
1.594     raeburn  8257: 	$r->print(&start_data_table_row());
1.356     albertel 8258: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31      albertel 8259: 	    $r->print('<td>');
1.356     albertel 8260: 	    if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31      albertel 8261: 	    $r->print('</td>');
                   8262: 	}
1.594     raeburn  8263: 	$r->print(&end_data_table_row());
1.31      albertel 8264:     }
1.594     raeburn  8265:     $r->print(&end_data_table().'<br />'."\n");
1.31      albertel 8266: }
                   8267: 
1.144     matthew  8268: ######################################################
                   8269: ######################################################
                   8270: 
1.56      matthew  8271: =pod
                   8272: 
1.648     raeburn  8273: =item * &csv_print_select_table($r,$records,$d)
1.41      ng       8274: 
                   8275: Prints a table to create associations between values and table columns.
1.144     matthew  8276: 
1.41      ng       8277: $r is an Apache Request ref,
                   8278: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174     matthew  8279: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41      ng       8280: 
                   8281: =cut
                   8282: 
1.144     matthew  8283: ######################################################
                   8284: ######################################################
1.31      albertel 8285: sub csv_print_select_table {
                   8286:     my ($r,$records,$d) = @_;
1.301     albertel 8287:     my $i=0;
                   8288:     my $samples = &get_samples($records,1);
1.144     matthew  8289:     $r->print(&mt('Associate columns with student attributes.')."\n".
1.594     raeburn  8290: 	      &start_data_table().&start_data_table_header_row().
1.144     matthew  8291:               '<th>'.&mt('Attribute').'</th>'.
1.594     raeburn  8292:               '<th>'.&mt('Column').'</th>'.
                   8293:               &end_data_table_header_row()."\n");
1.356     albertel 8294:     foreach my $array_ref (@$d) {
                   8295: 	my ($value,$display,$defaultcol)=@{ $array_ref };
1.729     raeburn  8296: 	$r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31      albertel 8297: 
                   8298: 	$r->print('<td><select name=f'.$i.
1.32      matthew  8299: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.31      albertel 8300: 	$r->print('<option value="none"></option>');
1.356     albertel 8301: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
                   8302: 	    $r->print('<option value="'.$sample.'"'.
                   8303:                       ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662     bisitz   8304:                       '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31      albertel 8305: 	}
1.594     raeburn  8306: 	$r->print('</select></td>'.&end_data_table_row()."\n");
1.31      albertel 8307: 	$i++;
                   8308:     }
1.594     raeburn  8309:     $r->print(&end_data_table());
1.31      albertel 8310:     $i--;
                   8311:     return $i;
                   8312: }
1.56      matthew  8313: 
1.144     matthew  8314: ######################################################
                   8315: ######################################################
                   8316: 
1.56      matthew  8317: =pod
1.31      albertel 8318: 
1.648     raeburn  8319: =item * &csv_samples_select_table($r,$records,$d)
1.41      ng       8320: 
                   8321: Prints a table of sample values from the upload and can make associate samples to internal names.
                   8322: 
                   8323: $r is an Apache Request ref,
                   8324: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
                   8325: $d is an array of 2 element arrays (internal name, displayed name)
                   8326: 
                   8327: =cut
                   8328: 
1.144     matthew  8329: ######################################################
                   8330: ######################################################
1.31      albertel 8331: sub csv_samples_select_table {
                   8332:     my ($r,$records,$d) = @_;
                   8333:     my $i=0;
1.144     matthew  8334:     #
1.662     bisitz   8335:     my $max_samples = 5;
                   8336:     my $samples = &get_samples($records,$max_samples);
1.594     raeburn  8337:     $r->print(&start_data_table().
                   8338:               &start_data_table_header_row().'<th>'.
                   8339:               &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
                   8340:               &end_data_table_header_row());
1.301     albertel 8341: 
                   8342:     foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594     raeburn  8343: 	$r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32      matthew  8344: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.301     albertel 8345: 	foreach my $option (@$d) {
                   8346: 	    my ($value,$display,$defaultcol)=@{ $option };
1.174     matthew  8347: 	    $r->print('<option value="'.$value.'"'.
1.253     albertel 8348:                       ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174     matthew  8349:                       $display.'</option>');
1.31      albertel 8350: 	}
                   8351: 	$r->print('</select></td><td>');
1.662     bisitz   8352: 	foreach my $line (0..($max_samples-1)) {
1.301     albertel 8353: 	    if (defined($samples->[$line]{$key})) { 
                   8354: 		$r->print($samples->[$line]{$key}."<br />\n"); 
                   8355: 	    }
                   8356: 	}
1.594     raeburn  8357: 	$r->print('</td>'.&end_data_table_row());
1.31      albertel 8358: 	$i++;
                   8359:     }
1.594     raeburn  8360:     $r->print(&end_data_table());
1.31      albertel 8361:     $i--;
                   8362:     return($i);
1.115     matthew  8363: }
                   8364: 
1.144     matthew  8365: ######################################################
                   8366: ######################################################
                   8367: 
1.115     matthew  8368: =pod
                   8369: 
1.648     raeburn  8370: =item * &clean_excel_name($name)
1.115     matthew  8371: 
                   8372: Returns a replacement for $name which does not contain any illegal characters.
                   8373: 
                   8374: =cut
                   8375: 
1.144     matthew  8376: ######################################################
                   8377: ######################################################
1.115     matthew  8378: sub clean_excel_name {
                   8379:     my ($name) = @_;
                   8380:     $name =~ s/[:\*\?\/\\]//g;
                   8381:     if (length($name) > 31) {
                   8382:         $name = substr($name,0,31);
                   8383:     }
                   8384:     return $name;
1.25      albertel 8385: }
1.84      albertel 8386: 
1.85      albertel 8387: =pod
                   8388: 
1.648     raeburn  8389: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85      albertel 8390: 
                   8391: Returns either 1 or undef
                   8392: 
                   8393: 1 if the part is to be hidden, undef if it is to be shown
                   8394: 
                   8395: Arguments are:
                   8396: 
                   8397: $id the id of the part to be checked
                   8398: $symb, optional the symb of the resource to check
                   8399: $udom, optional the domain of the user to check for
                   8400: $uname, optional the username of the user to check for
                   8401: 
                   8402: =cut
1.84      albertel 8403: 
                   8404: sub check_if_partid_hidden {
                   8405:     my ($id,$symb,$udom,$uname) = @_;
1.133     albertel 8406:     my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84      albertel 8407: 					 $symb,$udom,$uname);
1.141     albertel 8408:     my $truth=1;
                   8409:     #if the string starts with !, then the list is the list to show not hide
                   8410:     if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84      albertel 8411:     my @hiddenlist=split(/,/,$hiddenparts);
                   8412:     foreach my $checkid (@hiddenlist) {
1.141     albertel 8413: 	if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84      albertel 8414:     }
1.141     albertel 8415:     return !$truth;
1.84      albertel 8416: }
1.127     matthew  8417: 
1.138     matthew  8418: 
                   8419: ############################################################
                   8420: ############################################################
                   8421: 
                   8422: =pod
                   8423: 
1.157     matthew  8424: =back 
                   8425: 
1.138     matthew  8426: =head1 cgi-bin script and graphing routines
                   8427: 
1.157     matthew  8428: =over 4
                   8429: 
1.648     raeburn  8430: =item * &get_cgi_id()
1.138     matthew  8431: 
                   8432: Inputs: none
                   8433: 
                   8434: Returns an id which can be used to pass environment variables
                   8435: to various cgi-bin scripts.  These environment variables will
                   8436: be removed from the users environment after a given time by
                   8437: the routine &Apache::lonnet::transfer_profile_to_env.
                   8438: 
                   8439: =cut
                   8440: 
                   8441: ############################################################
                   8442: ############################################################
1.152     albertel 8443: my $uniq=0;
1.136     matthew  8444: sub get_cgi_id {
1.154     albertel 8445:     $uniq=($uniq+1)%100000;
1.280     albertel 8446:     return (time.'_'.$$.'_'.$uniq);
1.136     matthew  8447: }
                   8448: 
1.127     matthew  8449: ############################################################
                   8450: ############################################################
                   8451: 
                   8452: =pod
                   8453: 
1.648     raeburn  8454: =item * &DrawBarGraph()
1.127     matthew  8455: 
1.138     matthew  8456: Facilitates the plotting of data in a (stacked) bar graph.
                   8457: Puts plot definition data into the users environment in order for 
                   8458: graph.png to plot it.  Returns an <img> tag for the plot.
                   8459: The bars on the plot are labeled '1','2',...,'n'.
                   8460: 
                   8461: Inputs:
                   8462: 
                   8463: =over 4
                   8464: 
                   8465: =item $Title: string, the title of the plot
                   8466: 
                   8467: =item $xlabel: string, text describing the X-axis of the plot
                   8468: 
                   8469: =item $ylabel: string, text describing the Y-axis of the plot
                   8470: 
                   8471: =item $Max: scalar, the maximum Y value to use in the plot
                   8472: If $Max is < any data point, the graph will not be rendered.
                   8473: 
1.140     matthew  8474: =item $colors: array ref holding the colors to be used for the data sets when
1.138     matthew  8475: they are plotted.  If undefined, default values will be used.
                   8476: 
1.178     matthew  8477: =item $labels: array ref holding the labels to use on the x-axis for the bars.
                   8478: 
1.138     matthew  8479: =item @Values: An array of array references.  Each array reference holds data
                   8480: to be plotted in a stacked bar chart.
                   8481: 
1.239     matthew  8482: =item If the final element of @Values is a hash reference the key/value
                   8483: pairs will be added to the graph definition.
                   8484: 
1.138     matthew  8485: =back
                   8486: 
                   8487: Returns:
                   8488: 
                   8489: An <img> tag which references graph.png and the appropriate identifying
                   8490: information for the plot.
                   8491: 
1.127     matthew  8492: =cut
                   8493: 
                   8494: ############################################################
                   8495: ############################################################
1.134     matthew  8496: sub DrawBarGraph {
1.178     matthew  8497:     my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134     matthew  8498:     #
                   8499:     if (! defined($colors)) {
                   8500:         $colors = ['#33ff00', 
                   8501:                   '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
                   8502:                   '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
                   8503:                   ]; 
                   8504:     }
1.228     matthew  8505:     my $extra_settings = {};
                   8506:     if (ref($Values[-1]) eq 'HASH') {
                   8507:         $extra_settings = pop(@Values);
                   8508:     }
1.127     matthew  8509:     #
1.136     matthew  8510:     my $identifier = &get_cgi_id();
                   8511:     my $id = 'cgi.'.$identifier;        
1.129     matthew  8512:     if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127     matthew  8513:         return '';
                   8514:     }
1.225     matthew  8515:     #
                   8516:     my @Labels;
                   8517:     if (defined($labels)) {
                   8518:         @Labels = @$labels;
                   8519:     } else {
                   8520:         for (my $i=0;$i<@{$Values[0]};$i++) {
                   8521:             push (@Labels,$i+1);
                   8522:         }
                   8523:     }
                   8524:     #
1.129     matthew  8525:     my $NumBars = scalar(@{$Values[0]});
1.225     matthew  8526:     if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129     matthew  8527:     my %ValuesHash;
                   8528:     my $NumSets=1;
                   8529:     foreach my $array (@Values) {
                   8530:         next if (! ref($array));
1.136     matthew  8531:         $ValuesHash{$id.'.data.'.$NumSets++} = 
1.132     matthew  8532:             join(',',@$array);
1.129     matthew  8533:     }
1.127     matthew  8534:     #
1.136     matthew  8535:     my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225     matthew  8536:     if ($NumBars < 3) {
                   8537:         $width = 120+$NumBars*32;
1.220     matthew  8538:         $xskip = 1;
1.225     matthew  8539:         $bar_width = 30;
                   8540:     } elsif ($NumBars < 5) {
                   8541:         $width = 120+$NumBars*20;
                   8542:         $xskip = 1;
                   8543:         $bar_width = 20;
1.220     matthew  8544:     } elsif ($NumBars < 10) {
1.136     matthew  8545:         $width = 120+$NumBars*15;
                   8546:         $xskip = 1;
                   8547:         $bar_width = 15;
                   8548:     } elsif ($NumBars <= 25) {
                   8549:         $width = 120+$NumBars*11;
                   8550:         $xskip = 5;
                   8551:         $bar_width = 8;
                   8552:     } elsif ($NumBars <= 50) {
                   8553:         $width = 120+$NumBars*8;
                   8554:         $xskip = 5;
                   8555:         $bar_width = 4;
                   8556:     } else {
                   8557:         $width = 120+$NumBars*8;
                   8558:         $xskip = 5;
                   8559:         $bar_width = 4;
                   8560:     }
                   8561:     #
1.137     matthew  8562:     $Max = 1 if ($Max < 1);
                   8563:     if ( int($Max) < $Max ) {
                   8564:         $Max++;
                   8565:         $Max = int($Max);
                   8566:     }
1.127     matthew  8567:     $Title  = '' if (! defined($Title));
                   8568:     $xlabel = '' if (! defined($xlabel));
                   8569:     $ylabel = '' if (! defined($ylabel));
1.369     www      8570:     $ValuesHash{$id.'.title'}    = &escape($Title);
                   8571:     $ValuesHash{$id.'.xlabel'}   = &escape($xlabel);
                   8572:     $ValuesHash{$id.'.ylabel'}   = &escape($ylabel);
1.137     matthew  8573:     $ValuesHash{$id.'.y_max_value'} = $Max;
1.136     matthew  8574:     $ValuesHash{$id.'.NumBars'}  = $NumBars;
                   8575:     $ValuesHash{$id.'.NumSets'}  = $NumSets;
                   8576:     $ValuesHash{$id.'.PlotType'} = 'bar';
                   8577:     $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   8578:     $ValuesHash{$id.'.height'}   = $height;
                   8579:     $ValuesHash{$id.'.width'}    = $width;
                   8580:     $ValuesHash{$id.'.xskip'}    = $xskip;
                   8581:     $ValuesHash{$id.'.bar_width'} = $bar_width;
                   8582:     $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127     matthew  8583:     #
1.228     matthew  8584:     # Deal with other parameters
                   8585:     while (my ($key,$value) = each(%$extra_settings)) {
                   8586:         $ValuesHash{$id.'.'.$key} = $value;
                   8587:     }
                   8588:     #
1.646     raeburn  8589:     &Apache::lonnet::appenv(\%ValuesHash);
1.137     matthew  8590:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   8591: }
                   8592: 
                   8593: ############################################################
                   8594: ############################################################
                   8595: 
                   8596: =pod
                   8597: 
1.648     raeburn  8598: =item * &DrawXYGraph()
1.137     matthew  8599: 
1.138     matthew  8600: Facilitates the plotting of data in an XY graph.
                   8601: Puts plot definition data into the users environment in order for 
                   8602: graph.png to plot it.  Returns an <img> tag for the plot.
                   8603: 
                   8604: Inputs:
                   8605: 
                   8606: =over 4
                   8607: 
                   8608: =item $Title: string, the title of the plot
                   8609: 
                   8610: =item $xlabel: string, text describing the X-axis of the plot
                   8611: 
                   8612: =item $ylabel: string, text describing the Y-axis of the plot
                   8613: 
                   8614: =item $Max: scalar, the maximum Y value to use in the plot
                   8615: If $Max is < any data point, the graph will not be rendered.
                   8616: 
                   8617: =item $colors: Array ref containing the hex color codes for the data to be 
                   8618: plotted in.  If undefined, default values will be used.
                   8619: 
                   8620: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   8621: 
                   8622: =item $Ydata: Array ref containing Array refs.  
1.185     www      8623: Each of the contained arrays will be plotted as a separate curve.
1.138     matthew  8624: 
                   8625: =item %Values: hash indicating or overriding any default values which are 
                   8626: passed to graph.png.  
                   8627: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   8628: 
                   8629: =back
                   8630: 
                   8631: Returns:
                   8632: 
                   8633: An <img> tag which references graph.png and the appropriate identifying
                   8634: information for the plot.
                   8635: 
1.137     matthew  8636: =cut
                   8637: 
                   8638: ############################################################
                   8639: ############################################################
                   8640: sub DrawXYGraph {
                   8641:     my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
                   8642:     #
                   8643:     # Create the identifier for the graph
                   8644:     my $identifier = &get_cgi_id();
                   8645:     my $id = 'cgi.'.$identifier;
                   8646:     #
                   8647:     $Title  = '' if (! defined($Title));
                   8648:     $xlabel = '' if (! defined($xlabel));
                   8649:     $ylabel = '' if (! defined($ylabel));
                   8650:     my %ValuesHash = 
                   8651:         (
1.369     www      8652:          $id.'.title'  => &escape($Title),
                   8653:          $id.'.xlabel' => &escape($xlabel),
                   8654:          $id.'.ylabel' => &escape($ylabel),
1.137     matthew  8655:          $id.'.y_max_value'=> $Max,
                   8656:          $id.'.labels'     => join(',',@$Xlabels),
                   8657:          $id.'.PlotType'   => 'XY',
                   8658:          );
                   8659:     #
                   8660:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   8661:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   8662:     }
                   8663:     #
                   8664:     if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
                   8665:         return '';
                   8666:     }
                   8667:     my $NumSets=1;
1.138     matthew  8668:     foreach my $array (@{$Ydata}){
1.137     matthew  8669:         next if (! ref($array));
                   8670:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
                   8671:     }
1.138     matthew  8672:     $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137     matthew  8673:     #
                   8674:     # Deal with other parameters
                   8675:     while (my ($key,$value) = each(%Values)) {
                   8676:         $ValuesHash{$id.'.'.$key} = $value;
1.127     matthew  8677:     }
                   8678:     #
1.646     raeburn  8679:     &Apache::lonnet::appenv(\%ValuesHash);
1.136     matthew  8680:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   8681: }
                   8682: 
                   8683: ############################################################
                   8684: ############################################################
                   8685: 
                   8686: =pod
                   8687: 
1.648     raeburn  8688: =item * &DrawXYYGraph()
1.138     matthew  8689: 
                   8690: Facilitates the plotting of data in an XY graph with two Y axes.
                   8691: Puts plot definition data into the users environment in order for 
                   8692: graph.png to plot it.  Returns an <img> tag for the plot.
                   8693: 
                   8694: Inputs:
                   8695: 
                   8696: =over 4
                   8697: 
                   8698: =item $Title: string, the title of the plot
                   8699: 
                   8700: =item $xlabel: string, text describing the X-axis of the plot
                   8701: 
                   8702: =item $ylabel: string, text describing the Y-axis of the plot
                   8703: 
                   8704: =item $colors: Array ref containing the hex color codes for the data to be 
                   8705: plotted in.  If undefined, default values will be used.
                   8706: 
                   8707: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   8708: 
                   8709: =item $Ydata1: The first data set
                   8710: 
                   8711: =item $Min1: The minimum value of the left Y-axis
                   8712: 
                   8713: =item $Max1: The maximum value of the left Y-axis
                   8714: 
                   8715: =item $Ydata2: The second data set
                   8716: 
                   8717: =item $Min2: The minimum value of the right Y-axis
                   8718: 
                   8719: =item $Max2: The maximum value of the left Y-axis
                   8720: 
                   8721: =item %Values: hash indicating or overriding any default values which are 
                   8722: passed to graph.png.  
                   8723: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   8724: 
                   8725: =back
                   8726: 
                   8727: Returns:
                   8728: 
                   8729: An <img> tag which references graph.png and the appropriate identifying
                   8730: information for the plot.
1.136     matthew  8731: 
                   8732: =cut
                   8733: 
                   8734: ############################################################
                   8735: ############################################################
1.137     matthew  8736: sub DrawXYYGraph {
                   8737:     my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
                   8738:                                         $Ydata2,$Min2,$Max2,%Values)=@_;
1.136     matthew  8739:     #
                   8740:     # Create the identifier for the graph
                   8741:     my $identifier = &get_cgi_id();
                   8742:     my $id = 'cgi.'.$identifier;
                   8743:     #
                   8744:     $Title  = '' if (! defined($Title));
                   8745:     $xlabel = '' if (! defined($xlabel));
                   8746:     $ylabel = '' if (! defined($ylabel));
                   8747:     my %ValuesHash = 
                   8748:         (
1.369     www      8749:          $id.'.title'  => &escape($Title),
                   8750:          $id.'.xlabel' => &escape($xlabel),
                   8751:          $id.'.ylabel' => &escape($ylabel),
1.136     matthew  8752:          $id.'.labels' => join(',',@$Xlabels),
                   8753:          $id.'.PlotType' => 'XY',
                   8754:          $id.'.NumSets' => 2,
1.137     matthew  8755:          $id.'.two_axes' => 1,
                   8756:          $id.'.y1_max_value' => $Max1,
                   8757:          $id.'.y1_min_value' => $Min1,
                   8758:          $id.'.y2_max_value' => $Max2,
                   8759:          $id.'.y2_min_value' => $Min2,
1.136     matthew  8760:          );
                   8761:     #
1.137     matthew  8762:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   8763:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   8764:     }
                   8765:     #
                   8766:     if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
                   8767:         ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136     matthew  8768:         return '';
                   8769:     }
                   8770:     my $NumSets=1;
1.137     matthew  8771:     foreach my $array ($Ydata1,$Ydata2){
1.136     matthew  8772:         next if (! ref($array));
                   8773:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137     matthew  8774:     }
                   8775:     #
                   8776:     # Deal with other parameters
                   8777:     while (my ($key,$value) = each(%Values)) {
                   8778:         $ValuesHash{$id.'.'.$key} = $value;
1.136     matthew  8779:     }
                   8780:     #
1.646     raeburn  8781:     &Apache::lonnet::appenv(\%ValuesHash);
1.130     albertel 8782:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139     matthew  8783: }
                   8784: 
                   8785: ############################################################
                   8786: ############################################################
                   8787: 
                   8788: =pod
                   8789: 
1.157     matthew  8790: =back 
                   8791: 
1.139     matthew  8792: =head1 Statistics helper routines?  
                   8793: 
                   8794: Bad place for them but what the hell.
                   8795: 
1.157     matthew  8796: =over 4
                   8797: 
1.648     raeburn  8798: =item * &chartlink()
1.139     matthew  8799: 
                   8800: Returns a link to the chart for a specific student.  
                   8801: 
                   8802: Inputs:
                   8803: 
                   8804: =over 4
                   8805: 
                   8806: =item $linktext: The text of the link
                   8807: 
                   8808: =item $sname: The students username
                   8809: 
                   8810: =item $sdomain: The students domain
                   8811: 
                   8812: =back
                   8813: 
1.157     matthew  8814: =back
                   8815: 
1.139     matthew  8816: =cut
                   8817: 
                   8818: ############################################################
                   8819: ############################################################
                   8820: sub chartlink {
                   8821:     my ($linktext, $sname, $sdomain) = @_;
                   8822:     my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369     www      8823:         '&amp;SelectedStudent='.&escape($sname.':'.$sdomain).
1.219     albertel 8824:         '&amp;chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139     matthew  8825:        '">'.$linktext.'</a>';
1.153     matthew  8826: }
                   8827: 
                   8828: #######################################################
                   8829: #######################################################
                   8830: 
                   8831: =pod
                   8832: 
                   8833: =head1 Course Environment Routines
1.157     matthew  8834: 
                   8835: =over 4
1.153     matthew  8836: 
1.648     raeburn  8837: =item * &restore_course_settings()
1.153     matthew  8838: 
1.648     raeburn  8839: =item * &store_course_settings()
1.153     matthew  8840: 
                   8841: Restores/Store indicated form parameters from the course environment.
                   8842: Will not overwrite existing values of the form parameters.
                   8843: 
                   8844: Inputs: 
                   8845: a scalar describing the data (e.g. 'chart', 'problem_analysis')
                   8846: 
                   8847: a hash ref describing the data to be stored.  For example:
                   8848:    
                   8849: %Save_Parameters = ('Status' => 'scalar',
                   8850:     'chartoutputmode' => 'scalar',
                   8851:     'chartoutputdata' => 'scalar',
                   8852:     'Section' => 'array',
1.373     raeburn  8853:     'Group' => 'array',
1.153     matthew  8854:     'StudentData' => 'array',
                   8855:     'Maps' => 'array');
                   8856: 
                   8857: Returns: both routines return nothing
                   8858: 
1.631     raeburn  8859: =back
                   8860: 
1.153     matthew  8861: =cut
                   8862: 
                   8863: #######################################################
                   8864: #######################################################
                   8865: sub store_course_settings {
1.496     albertel 8866:     return &store_settings($env{'request.course.id'},@_);
                   8867: }
                   8868: 
                   8869: sub store_settings {
1.153     matthew  8870:     # save to the environment
                   8871:     # appenv the same items, just to be safe
1.300     albertel 8872:     my $udom  = $env{'user.domain'};
                   8873:     my $uname = $env{'user.name'};
1.496     albertel 8874:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  8875:     my %SaveHash;
                   8876:     my %AppHash;
                   8877:     while (my ($setting,$type) = each(%$Settings)) {
1.496     albertel 8878:         my $basename = join('.','internal',$context,$prefix,$setting);
1.300     albertel 8879:         my $envname = 'environment.'.$basename;
1.258     albertel 8880:         if (exists($env{'form.'.$setting})) {
1.153     matthew  8881:             # Save this value away
                   8882:             if ($type eq 'scalar' &&
1.258     albertel 8883:                 (! exists($env{$envname}) || 
                   8884:                  $env{$envname} ne $env{'form.'.$setting})) {
                   8885:                 $SaveHash{$basename} = $env{'form.'.$setting};
                   8886:                 $AppHash{$envname}   = $env{'form.'.$setting};
1.153     matthew  8887:             } elsif ($type eq 'array') {
                   8888:                 my $stored_form;
1.258     albertel 8889:                 if (ref($env{'form.'.$setting})) {
1.153     matthew  8890:                     $stored_form = join(',',
                   8891:                                         map {
1.369     www      8892:                                             &escape($_);
1.258     albertel 8893:                                         } sort(@{$env{'form.'.$setting}}));
1.153     matthew  8894:                 } else {
                   8895:                     $stored_form = 
1.369     www      8896:                         &escape($env{'form.'.$setting});
1.153     matthew  8897:                 }
                   8898:                 # Determine if the array contents are the same.
1.258     albertel 8899:                 if ($stored_form ne $env{$envname}) {
1.153     matthew  8900:                     $SaveHash{$basename} = $stored_form;
                   8901:                     $AppHash{$envname}   = $stored_form;
                   8902:                 }
                   8903:             }
                   8904:         }
                   8905:     }
                   8906:     my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300     albertel 8907:                                           $udom,$uname);
1.153     matthew  8908:     if ($put_result !~ /^(ok|delayed)/) {
                   8909:         &Apache::lonnet::logthis('unable to save form parameters, '.
                   8910:                                  'got error:'.$put_result);
                   8911:     }
                   8912:     # Make sure these settings stick around in this session, too
1.646     raeburn  8913:     &Apache::lonnet::appenv(\%AppHash);
1.153     matthew  8914:     return;
                   8915: }
                   8916: 
                   8917: sub restore_course_settings {
1.499     albertel 8918:     return &restore_settings($env{'request.course.id'},@_);
1.496     albertel 8919: }
                   8920: 
                   8921: sub restore_settings {
                   8922:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  8923:     while (my ($setting,$type) = each(%$Settings)) {
1.258     albertel 8924:         next if (exists($env{'form.'.$setting}));
1.496     albertel 8925:         my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153     matthew  8926:             '.'.$setting;
1.258     albertel 8927:         if (exists($env{$envname})) {
1.153     matthew  8928:             if ($type eq 'scalar') {
1.258     albertel 8929:                 $env{'form.'.$setting} = $env{$envname};
1.153     matthew  8930:             } elsif ($type eq 'array') {
1.258     albertel 8931:                 $env{'form.'.$setting} = [ 
1.153     matthew  8932:                                            map { 
1.369     www      8933:                                                &unescape($_); 
1.258     albertel 8934:                                            } split(',',$env{$envname})
1.153     matthew  8935:                                            ];
                   8936:             }
                   8937:         }
                   8938:     }
1.127     matthew  8939: }
                   8940: 
1.618     raeburn  8941: #######################################################
                   8942: #######################################################
                   8943: 
                   8944: =pod
                   8945: 
                   8946: =head1 Domain E-mail Routines  
                   8947: 
                   8948: =over 4
                   8949: 
1.648     raeburn  8950: =item * &build_recipient_list()
1.618     raeburn  8951: 
1.766     raeburn  8952: Build recipient lists for four types of e-mail:
                   8953: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
                   8954: (d) Help requests, generated by
                   8955: lonerrorhandler.pm, CHECKRPMS, loncron, and lonsupportreq.pm respectively.
1.618     raeburn  8956: 
                   8957: Inputs:
1.619     raeburn  8958: defmail (scalar - email address of default recipient), 
1.618     raeburn  8959: mailing type (scalar - errormail, packagesmail, or helpdeskmail), 
1.619     raeburn  8960: defdom (domain for which to retrieve configuration settings),
                   8961: origmail (scalar - email address of recipient from loncapa.conf, 
                   8962: i.e., predates configuration by DC via domainprefs.pm 
1.618     raeburn  8963: 
1.655     raeburn  8964: Returns: comma separated list of addresses to which to send e-mail.
                   8965: 
                   8966: =back
1.618     raeburn  8967: 
                   8968: =cut
                   8969: 
                   8970: ############################################################
                   8971: ############################################################
                   8972: sub build_recipient_list {
1.619     raeburn  8973:     my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618     raeburn  8974:     my @recipients;
                   8975:     my $otheremails;
                   8976:     my %domconfig =
                   8977:          &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
                   8978:     if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766     raeburn  8979:         if (exists($domconfig{'contacts'}{$mailing})) {
                   8980:             if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
                   8981:                 my @contacts = ('adminemail','supportemail');
                   8982:                 foreach my $item (@contacts) {
                   8983:                     if ($domconfig{'contacts'}{$mailing}{$item}) {
                   8984:                         my $addr = $domconfig{'contacts'}{$item}; 
                   8985:                         if (!grep(/^\Q$addr\E$/,@recipients)) {
                   8986:                             push(@recipients,$addr);
                   8987:                         }
1.619     raeburn  8988:                     }
1.766     raeburn  8989:                     $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618     raeburn  8990:                 }
                   8991:             }
1.766     raeburn  8992:         } elsif ($origmail ne '') {
                   8993:             push(@recipients,$origmail);
1.618     raeburn  8994:         }
1.619     raeburn  8995:     } elsif ($origmail ne '') {
                   8996:         push(@recipients,$origmail);
1.618     raeburn  8997:     }
1.688     raeburn  8998:     if (defined($defmail)) {
                   8999:         if ($defmail ne '') {
                   9000:             push(@recipients,$defmail);
                   9001:         }
1.618     raeburn  9002:     }
                   9003:     if ($otheremails) {
1.619     raeburn  9004:         my @others;
                   9005:         if ($otheremails =~ /,/) {
                   9006:             @others = split(/,/,$otheremails);
1.618     raeburn  9007:         } else {
1.619     raeburn  9008:             push(@others,$otheremails);
                   9009:         }
                   9010:         foreach my $addr (@others) {
                   9011:             if (!grep(/^\Q$addr\E$/,@recipients)) {
                   9012:                 push(@recipients,$addr);
                   9013:             }
1.618     raeburn  9014:         }
                   9015:     }
1.619     raeburn  9016:     my $recipientlist = join(',',@recipients); 
1.618     raeburn  9017:     return $recipientlist;
                   9018: }
                   9019: 
1.127     matthew  9020: ############################################################
                   9021: ############################################################
1.154     albertel 9022: 
1.655     raeburn  9023: =pod
                   9024: 
                   9025: =head1 Course Catalog Routines
                   9026: 
                   9027: =over 4
                   9028: 
                   9029: =item * &gather_categories()
                   9030: 
                   9031: Converts category definitions - keys of categories hash stored in  
                   9032: coursecategories in configuration.db on the primary library server in a 
                   9033: domain - to an array.  Also generates javascript and idx hash used to 
                   9034: generate Domain Coordinator interface for editing Course Categories.
                   9035: 
                   9036: Inputs:
1.663     raeburn  9037: 
1.655     raeburn  9038: categories (reference to hash of category definitions).
1.663     raeburn  9039: 
1.655     raeburn  9040: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   9041:       categories and subcategories).
1.663     raeburn  9042: 
1.655     raeburn  9043: idx (reference to hash of counters used in Domain Coordinator interface for 
                   9044:       editing Course Categories).
1.663     raeburn  9045: 
1.655     raeburn  9046: jsarray (reference to array of categories used to create Javascript arrays for
                   9047:          Domain Coordinator interface for editing Course Categories).
                   9048: 
                   9049: Returns: nothing
                   9050: 
                   9051: Side effects: populates cats, idx and jsarray. 
                   9052: 
                   9053: =cut
                   9054: 
                   9055: sub gather_categories {
                   9056:     my ($categories,$cats,$idx,$jsarray) = @_;
                   9057:     my %counters;
                   9058:     my $num = 0;
                   9059:     foreach my $item (keys(%{$categories})) {
                   9060:         my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
                   9061:         if ($container eq '' && $depth == 0) {
                   9062:             $cats->[$depth][$categories->{$item}] = $cat;
                   9063:         } else {
                   9064:             $cats->[$depth]{$container}[$categories->{$item}] = $cat;
                   9065:         }
                   9066:         my ($escitem,$tail) = split(/:/,$item,2);
                   9067:         if ($counters{$tail} eq '') {
                   9068:             $counters{$tail} = $num;
                   9069:             $num ++;
                   9070:         }
                   9071:         if (ref($idx) eq 'HASH') {
                   9072:             $idx->{$item} = $counters{$tail};
                   9073:         }
                   9074:         if (ref($jsarray) eq 'ARRAY') {
                   9075:             push(@{$jsarray->[$counters{$tail}]},$item);
                   9076:         }
                   9077:     }
                   9078:     return;
                   9079: }
                   9080: 
                   9081: =pod
                   9082: 
                   9083: =item * &extract_categories()
                   9084: 
                   9085: Used to generate breadcrumb trails for course categories.
                   9086: 
                   9087: Inputs:
1.663     raeburn  9088: 
1.655     raeburn  9089: categories (reference to hash of category definitions).
1.663     raeburn  9090: 
1.655     raeburn  9091: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   9092:       categories and subcategories).
1.663     raeburn  9093: 
1.655     raeburn  9094: trails (reference to array of breacrumb trails for each category).
1.663     raeburn  9095: 
1.655     raeburn  9096: allitems (reference to hash - key is category key 
                   9097:          (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663     raeburn  9098: 
1.655     raeburn  9099: idx (reference to hash of counters used in Domain Coordinator interface for
                   9100:       editing Course Categories).
1.663     raeburn  9101: 
1.655     raeburn  9102: jsarray (reference to array of categories used to create Javascript arrays for
                   9103:          Domain Coordinator interface for editing Course Categories).
                   9104: 
1.665     raeburn  9105: subcats (reference to hash of arrays containing all subcategories within each 
                   9106:          category, -recursive)
                   9107: 
1.655     raeburn  9108: Returns: nothing
                   9109: 
                   9110: Side effects: populates trails and allitems hash references.
                   9111: 
                   9112: =cut
                   9113: 
                   9114: sub extract_categories {
1.665     raeburn  9115:     my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655     raeburn  9116:     if (ref($categories) eq 'HASH') {
                   9117:         &gather_categories($categories,$cats,$idx,$jsarray);
                   9118:         if (ref($cats->[0]) eq 'ARRAY') {
                   9119:             for (my $i=0; $i<@{$cats->[0]}; $i++) {
                   9120:                 my $name = $cats->[0][$i];
                   9121:                 my $item = &escape($name).'::0';
                   9122:                 my $trailstr;
                   9123:                 if ($name eq 'instcode') {
                   9124:                     $trailstr = &mt('Official courses (with institutional codes)');
                   9125:                 } else {
                   9126:                     $trailstr = $name;
                   9127:                 }
                   9128:                 if ($allitems->{$item} eq '') {
                   9129:                     push(@{$trails},$trailstr);
                   9130:                     $allitems->{$item} = scalar(@{$trails})-1;
                   9131:                 }
                   9132:                 my @parents = ($name);
                   9133:                 if (ref($cats->[1]{$name}) eq 'ARRAY') {
                   9134:                     for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
                   9135:                         my $category = $cats->[1]{$name}[$j];
1.665     raeburn  9136:                         if (ref($subcats) eq 'HASH') {
                   9137:                             push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
                   9138:                         }
                   9139:                         &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
                   9140:                     }
                   9141:                 } else {
                   9142:                     if (ref($subcats) eq 'HASH') {
                   9143:                         $subcats->{$item} = [];
1.655     raeburn  9144:                     }
                   9145:                 }
                   9146:             }
                   9147:         }
                   9148:     }
                   9149:     return;
                   9150: }
                   9151: 
                   9152: =pod
                   9153: 
                   9154: =item *&recurse_categories()
                   9155: 
                   9156: Recursively used to generate breadcrumb trails for course categories.
                   9157: 
                   9158: Inputs:
1.663     raeburn  9159: 
1.655     raeburn  9160: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   9161:       categories and subcategories).
1.663     raeburn  9162: 
1.655     raeburn  9163: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663     raeburn  9164: 
                   9165: category (current course category, for which breadcrumb trail is being generated).
                   9166: 
                   9167: trails (reference to array of breadcrumb trails for each category).
                   9168: 
1.655     raeburn  9169: allitems (reference to hash - key is category key
                   9170:          (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663     raeburn  9171: 
1.655     raeburn  9172: parents (array containing containers directories for current category, 
                   9173:          back to top level). 
                   9174: 
                   9175: Returns: nothing
                   9176: 
                   9177: Side effects: populates trails and allitems hash references
                   9178: 
                   9179: =cut
                   9180: 
                   9181: sub recurse_categories {
1.665     raeburn  9182:     my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655     raeburn  9183:     my $shallower = $depth - 1;
                   9184:     if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
                   9185:         for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
                   9186:             my $name = $cats->[$depth]{$category}[$k];
                   9187:             my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
                   9188:             my $trailstr = join(' -&gt; ',(@{$parents},$category));
                   9189:             if ($allitems->{$item} eq '') {
                   9190:                 push(@{$trails},$trailstr);
                   9191:                 $allitems->{$item} = scalar(@{$trails})-1;
                   9192:             }
                   9193:             my $deeper = $depth+1;
                   9194:             push(@{$parents},$category);
1.665     raeburn  9195:             if (ref($subcats) eq 'HASH') {
                   9196:                 my $subcat = &escape($name).':'.$category.':'.$depth;
                   9197:                 for (my $j=@{$parents}; $j>=0; $j--) {
                   9198:                     my $higher;
                   9199:                     if ($j > 0) {
                   9200:                         $higher = &escape($parents->[$j]).':'.
                   9201:                                   &escape($parents->[$j-1]).':'.$j;
                   9202:                     } else {
                   9203:                         $higher = &escape($parents->[$j]).'::'.$j;
                   9204:                     }
                   9205:                     push(@{$subcats->{$higher}},$subcat);
                   9206:                 }
                   9207:             }
                   9208:             &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
                   9209:                                 $subcats);
1.655     raeburn  9210:             pop(@{$parents});
                   9211:         }
                   9212:     } else {
                   9213:         my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
                   9214:         my $trailstr = join(' -&gt; ',(@{$parents},$category));
                   9215:         if ($allitems->{$item} eq '') {
                   9216:             push(@{$trails},$trailstr);
                   9217:             $allitems->{$item} = scalar(@{$trails})-1;
                   9218:         }
                   9219:     }
                   9220:     return;
                   9221: }
                   9222: 
1.663     raeburn  9223: =pod
                   9224: 
                   9225: =item *&assign_categories_table()
                   9226: 
                   9227: Create a datatable for display of hierarchical categories in a domain,
                   9228: with checkboxes to allow a course to be categorized. 
                   9229: 
                   9230: Inputs:
                   9231: 
                   9232: cathash - reference to hash of categories defined for the domain (from
                   9233:           configuration.db)
                   9234: 
                   9235: currcat - scalar with an & separated list of categories assigned to a course. 
                   9236: 
                   9237: Returns: $output (markup to be displayed) 
                   9238: 
                   9239: =cut
                   9240: 
                   9241: sub assign_categories_table {
                   9242:     my ($cathash,$currcat) = @_;
                   9243:     my $output;
                   9244:     if (ref($cathash) eq 'HASH') {
                   9245:         my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
                   9246:         &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
                   9247:         $maxdepth = scalar(@cats);
                   9248:         if (@cats > 0) {
                   9249:             my $itemcount = 0;
                   9250:             if (ref($cats[0]) eq 'ARRAY') {
                   9251:                 $output = &Apache::loncommon::start_data_table();
                   9252:                 my @currcategories;
                   9253:                 if ($currcat ne '') {
                   9254:                     @currcategories = split('&',$currcat);
                   9255:                 }
                   9256:                 for (my $i=0; $i<@{$cats[0]}; $i++) {
                   9257:                     my $parent = $cats[0][$i];
                   9258:                     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   9259:                     next if ($parent eq 'instcode');
                   9260:                     my $item = &escape($parent).'::0';
                   9261:                     my $checked = '';
                   9262:                     if (@currcategories > 0) {
                   9263:                         if (grep(/^\Q$item\E$/,@currcategories)) {
1.772     bisitz   9264:                             $checked = ' checked="checked"';
1.663     raeburn  9265:                         }
                   9266:                     }
1.675     raeburn  9267:                     $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
                   9268:                                '<input type="checkbox" name="usecategory" value="'.
                   9269:                                $item.'"'.$checked.' />'.$parent.'</span>'.
                   9270:                                '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663     raeburn  9271:                     my $depth = 1;
                   9272:                     push(@path,$parent);
                   9273:                     $output .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
                   9274:                     pop(@path);
                   9275:                     $output .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
                   9276:                     $itemcount ++;
                   9277:                 }
                   9278:                 $output .= &Apache::loncommon::end_data_table();
                   9279:             }
                   9280:         }
                   9281:     }
                   9282:     return $output;
                   9283: }
                   9284: 
                   9285: =pod
                   9286: 
                   9287: =item *&assign_category_rows()
                   9288: 
                   9289: Create a datatable row for display of nested categories in a domain,
                   9290: with checkboxes to allow a course to be categorized,called recursively.
                   9291: 
                   9292: Inputs:
                   9293: 
                   9294: itemcount - track row number for alternating colors
                   9295: 
                   9296: cats - reference to array of arrays/hashes which encapsulates hierarchy of
                   9297:       categories and subcategories.
                   9298: 
                   9299: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
                   9300: 
                   9301: parent - parent of current category item
                   9302: 
                   9303: path - Array containing all categories back up through the hierarchy from the
                   9304:        current category to the top level.
                   9305: 
                   9306: currcategories - reference to array of current categories assigned to the course
                   9307: 
                   9308: Returns: $output (markup to be displayed).
                   9309: 
                   9310: =cut
                   9311: 
                   9312: sub assign_category_rows {
                   9313:     my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
                   9314:     my ($text,$name,$item,$chgstr);
                   9315:     if (ref($cats) eq 'ARRAY') {
                   9316:         my $maxdepth = scalar(@{$cats});
                   9317:         if (ref($cats->[$depth]) eq 'HASH') {
                   9318:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   9319:                 my $numchildren = @{$cats->[$depth]{$parent}};
                   9320:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   9321:                 $text .= '<td><table class="LC_datatable">';
                   9322:                 for (my $j=0; $j<$numchildren; $j++) {
                   9323:                     $name = $cats->[$depth]{$parent}[$j];
                   9324:                     $item = &escape($name).':'.&escape($parent).':'.$depth;
                   9325:                     my $deeper = $depth+1;
                   9326:                     my $checked = '';
                   9327:                     if (ref($currcategories) eq 'ARRAY') {
                   9328:                         if (@{$currcategories} > 0) {
                   9329:                             if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772     bisitz   9330:                                 $checked = ' checked="checked"';
1.663     raeburn  9331:                             }
                   9332:                         }
                   9333:                     }
1.664     raeburn  9334:                     $text .= '<tr><td><span class="LC_nobreak"><label>'.
                   9335:                              '<input type="checkbox" name="usecategory" value="'.
1.675     raeburn  9336:                              $item.'"'.$checked.' />'.$name.'</label></span>'.
                   9337:                              '<input type="hidden" name="catname" value="'.$name.'" />'.
                   9338:                              '</td><td>';
1.663     raeburn  9339:                     if (ref($path) eq 'ARRAY') {
                   9340:                         push(@{$path},$name);
                   9341:                         $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
                   9342:                         pop(@{$path});
                   9343:                     }
                   9344:                     $text .= '</td></tr>';
                   9345:                 }
                   9346:                 $text .= '</table></td>';
                   9347:             }
                   9348:         }
                   9349:     }
                   9350:     return $text;
                   9351: }
                   9352: 
1.655     raeburn  9353: ############################################################
                   9354: ############################################################
                   9355: 
                   9356: 
1.443     albertel 9357: sub commit_customrole {
1.664     raeburn  9358:     my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630     raeburn  9359:     my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443     albertel 9360:                          ($start?', '.&mt('starting').' '.localtime($start):'').
                   9361:                          ($end?', ending '.localtime($end):'').': <b>'.
                   9362:               &Apache::lonnet::assigncustomrole(
1.664     raeburn  9363:                  $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443     albertel 9364:                  '</b><br />';
                   9365:     return $output;
                   9366: }
                   9367: 
                   9368: sub commit_standardrole {
1.541     raeburn  9369:     my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
                   9370:     my ($output,$logmsg,$linefeed);
                   9371:     if ($context eq 'auto') {
                   9372:         $linefeed = "\n";
                   9373:     } else {
                   9374:         $linefeed = "<br />\n";
                   9375:     }  
1.443     albertel 9376:     if ($three eq 'st') {
1.541     raeburn  9377:         my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
                   9378:                                          $one,$two,$sec,$context);
                   9379:         if (($result =~ /^error/) || ($result eq 'not_in_class') || 
1.626     raeburn  9380:             ($result eq 'unknown_course') || ($result eq 'refused')) {
                   9381:             $output = $logmsg.' '.&mt('Error: ').$result."\n"; 
1.443     albertel 9382:         } else {
1.541     raeburn  9383:             $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443     albertel 9384:                ($start?', '.&mt('starting').' '.localtime($start):'').
1.541     raeburn  9385:                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
                   9386:             if ($context eq 'auto') {
                   9387:                 $output .= $result.$linefeed.&mt('Add to classlist').': ok';
                   9388:             } else {
                   9389:                $output .= '<b>'.$result.'</b>'.$linefeed.
                   9390:                &mt('Add to classlist').': <b>ok</b>';
                   9391:             }
                   9392:             $output .= $linefeed;
1.443     albertel 9393:         }
                   9394:     } else {
                   9395:         $output = &mt('Assigning').' '.$three.' in '.$url.
                   9396:                ($start?', '.&mt('starting').' '.localtime($start):'').
1.541     raeburn  9397:                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652     raeburn  9398:         my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541     raeburn  9399:         if ($context eq 'auto') {
                   9400:             $output .= $result.$linefeed;
                   9401:         } else {
                   9402:             $output .= '<b>'.$result.'</b>'.$linefeed;
                   9403:         }
1.443     albertel 9404:     }
                   9405:     return $output;
                   9406: }
                   9407: 
                   9408: sub commit_studentrole {
1.541     raeburn  9409:     my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626     raeburn  9410:     my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541     raeburn  9411:     if ($context eq 'auto') {
                   9412:         $linefeed = "\n";
                   9413:     } else {
                   9414:         $linefeed = '<br />'."\n";
                   9415:     }
1.443     albertel 9416:     if (defined($one) && defined($two)) {
                   9417:         my $cid=$one.'_'.$two;
                   9418:         my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
                   9419:         my $secchange = 0;
                   9420:         my $expire_role_result;
                   9421:         my $modify_section_result;
1.628     raeburn  9422:         if ($oldsec ne '-1') { 
                   9423:             if ($oldsec ne $sec) {
1.443     albertel 9424:                 $secchange = 1;
1.628     raeburn  9425:                 my $now = time;
1.443     albertel 9426:                 my $uurl='/'.$cid;
                   9427:                 $uurl=~s/\_/\//g;
                   9428:                 if ($oldsec) {
                   9429:                     $uurl.='/'.$oldsec;
                   9430:                 }
1.626     raeburn  9431:                 $oldsecurl = $uurl;
1.628     raeburn  9432:                 $expire_role_result = 
1.652     raeburn  9433:                     &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628     raeburn  9434:                 if ($env{'request.course.sec'} ne '') { 
                   9435:                     if ($expire_role_result eq 'refused') {
                   9436:                         my @roles = ('st');
                   9437:                         my @statuses = ('previous');
                   9438:                         my @roledoms = ($one);
                   9439:                         my $withsec = 1;
                   9440:                         my %roleshash = 
                   9441:                             &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
                   9442:                                               \@statuses,\@roles,\@roledoms,$withsec);
                   9443:                         if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
                   9444:                             my ($oldstart,$oldend) = 
                   9445:                                 split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
                   9446:                             if ($oldend > 0 && $oldend <= $now) {
                   9447:                                 $expire_role_result = 'ok';
                   9448:                             }
                   9449:                         }
                   9450:                     }
                   9451:                 }
1.443     albertel 9452:                 $result = $expire_role_result;
                   9453:             }
                   9454:         }
                   9455:         if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652     raeburn  9456:             $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443     albertel 9457:             if ($modify_section_result =~ /^ok/) {
                   9458:                 if ($secchange == 1) {
1.628     raeburn  9459:                     if ($sec eq '') {
                   9460:                         $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
                   9461:                     } else {
                   9462:                         $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
                   9463:                     }
1.443     albertel 9464:                 } elsif ($oldsec eq '-1') {
1.628     raeburn  9465:                     if ($sec eq '') {
                   9466:                         $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
                   9467:                     } else {
                   9468:                         $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                   9469:                     }
1.443     albertel 9470:                 } else {
1.628     raeburn  9471:                     if ($sec eq '') {
                   9472:                         $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
                   9473:                     } else {
                   9474:                         $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                   9475:                     }
1.443     albertel 9476:                 }
                   9477:             } else {
1.628     raeburn  9478:                 if ($secchange) {       
                   9479:                     $$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;
                   9480:                 } else {
                   9481:                     $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
                   9482:                 }
1.443     albertel 9483:             }
                   9484:             $result = $modify_section_result;
                   9485:         } elsif ($secchange == 1) {
1.628     raeburn  9486:             if ($oldsec eq '') {
                   9487:                 $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
                   9488:             } else {
                   9489:                 $$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;
                   9490:             }
1.626     raeburn  9491:             if ($expire_role_result eq 'refused') {
                   9492:                 my $newsecurl = '/'.$cid;
                   9493:                 $newsecurl =~ s/\_/\//g;
                   9494:                 if ($sec ne '') {
                   9495:                     $newsecurl.='/'.$sec;
                   9496:                 }
                   9497:                 if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
                   9498:                     if ($sec eq '') {
                   9499:                         $$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;
                   9500:                     } else {
                   9501:                         $$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;
                   9502:                     }
                   9503:                 }
                   9504:             }
1.443     albertel 9505:         }
                   9506:     } else {
1.626     raeburn  9507:         $$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 9508:         $result = "error: incomplete course id\n";
                   9509:     }
                   9510:     return $result;
                   9511: }
                   9512: 
                   9513: ############################################################
                   9514: ############################################################
                   9515: 
1.566     albertel 9516: sub check_clone {
1.578     raeburn  9517:     my ($args,$linefeed) = @_;
1.566     albertel 9518:     my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
                   9519:     my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
                   9520:     my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
                   9521:     my $clonemsg;
                   9522:     my $can_clone = 0;
                   9523: 
                   9524:     if ($clonehome eq 'no_host') {
1.578     raeburn  9525:         $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 9526:     } else {
                   9527: 	my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.568     albertel 9528: 	if ($env{'request.role.domain'} eq $args->{'clonedomain'}) {
1.566     albertel 9529: 	    $can_clone = 1;
                   9530: 	} else {
                   9531: 	    my %clonehash = &Apache::lonnet::get('environment',['cloners'],
                   9532: 						 $args->{'clonedomain'},$args->{'clonecourse'});
                   9533: 	    my @cloners = split(/,/,$clonehash{'cloners'});
1.578     raeburn  9534:             if (grep(/^\*$/,@cloners)) {
                   9535:                 $can_clone = 1;
                   9536:             } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
                   9537:                 $can_clone = 1;
                   9538:             } else {
                   9539: 	        my %roleshash =
                   9540: 		    &Apache::lonnet::get_my_roles($args->{'ccuname'},
                   9541: 					 $args->{'ccdomain'},
                   9542:                                          'userroles',['active'],['cc'],
                   9543: 					 [$args->{'clonedomain'}]);
                   9544: 	        if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
                   9545: 		    $can_clone = 1;
                   9546: 	        } else {
                   9547:                     $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'});
                   9548: 	        }
1.566     albertel 9549: 	    }
1.578     raeburn  9550:         }
1.566     albertel 9551:     }
                   9552:     return ($can_clone, $clonemsg, $cloneid, $clonehome);
                   9553: }
                   9554: 
1.444     albertel 9555: sub construct_course {
1.541     raeburn  9556:     my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context) = @_;
1.444     albertel 9557:     my $outcome;
1.541     raeburn  9558:     my $linefeed =  '<br />'."\n";
                   9559:     if ($context eq 'auto') {
                   9560:         $linefeed = "\n";
                   9561:     }
1.566     albertel 9562: 
                   9563: #
                   9564: # Are we cloning?
                   9565: #
                   9566:     my ($can_clone, $clonemsg, $cloneid, $clonehome);
                   9567:     if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578     raeburn  9568: 	($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566     albertel 9569: 	if ($context ne 'auto') {
1.578     raeburn  9570:             if ($clonemsg ne '') {
                   9571: 	        $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
                   9572:             }
1.566     albertel 9573: 	}
                   9574: 	$outcome .= $clonemsg.$linefeed;
                   9575: 
                   9576:         if (!$can_clone) {
                   9577: 	    return (0,$outcome);
                   9578: 	}
                   9579:     }
                   9580: 
1.444     albertel 9581: #
                   9582: # Open course
                   9583: #
                   9584:     my $crstype = lc($args->{'crstype'});
                   9585:     my %cenv=();
                   9586:     $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
                   9587:                                              $args->{'cdescr'},
                   9588:                                              $args->{'curl'},
                   9589:                                              $args->{'course_home'},
                   9590:                                              $args->{'nonstandard'},
                   9591:                                              $args->{'crscode'},
                   9592:                                              $args->{'ccuname'}.':'.
                   9593:                                              $args->{'ccdomain'},
                   9594:                                              $args->{'crstype'});
                   9595: 
                   9596:     # Note: The testing routines depend on this being output; see 
                   9597:     # Utils::Course. This needs to at least be output as a comment
                   9598:     # if anyone ever decides to not show this, and Utils::Course::new
                   9599:     # will need to be suitably modified.
1.541     raeburn  9600:     $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.444     albertel 9601: #
                   9602: # Check if created correctly
                   9603: #
1.479     albertel 9604:     ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444     albertel 9605:     my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.541     raeburn  9606:     $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566     albertel 9607: 
1.444     albertel 9608: #
1.566     albertel 9609: # Do the cloning
                   9610: #   
                   9611:     if ($can_clone && $cloneid) {
                   9612: 	$clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
                   9613: 	if ($context ne 'auto') {
                   9614: 	    $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
                   9615: 	}
                   9616: 	$outcome .= $clonemsg.$linefeed;
                   9617: 	my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444     albertel 9618: # Copy all files
1.637     www      9619: 	&Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444     albertel 9620: # Restore URL
1.566     albertel 9621: 	$cenv{'url'}=$oldcenv{'url'};
1.444     albertel 9622: # Restore title
1.566     albertel 9623: 	$cenv{'description'}=$oldcenv{'description'};
1.444     albertel 9624: # Mark as cloned
1.566     albertel 9625: 	$cenv{'clonedfrom'}=$cloneid;
1.638     www      9626: # Need to clone grading mode
                   9627:         my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
                   9628:         $cenv{'grading'}=$newenv{'grading'};
                   9629: # Do not clone these environment entries
                   9630:         &Apache::lonnet::del('environment',
                   9631:                   ['default_enrollment_start_date',
                   9632:                    'default_enrollment_end_date',
                   9633:                    'question.email',
                   9634:                    'policy.email',
                   9635:                    'comment.email',
                   9636:                    'pch.users.denied',
1.725     raeburn  9637:                    'plc.users.denied',
                   9638:                    'hidefromcat',
                   9639:                    'categories'],
1.638     www      9640:                    $$crsudom,$$crsunum);
1.444     albertel 9641:     }
1.566     albertel 9642: 
1.444     albertel 9643: #
                   9644: # Set environment (will override cloned, if existing)
                   9645: #
                   9646:     my @sections = ();
                   9647:     my @xlists = ();
                   9648:     if ($args->{'crstype'}) {
                   9649:         $cenv{'type'}=$args->{'crstype'};
                   9650:     }
                   9651:     if ($args->{'crsid'}) {
                   9652:         $cenv{'courseid'}=$args->{'crsid'};
                   9653:     }
                   9654:     if ($args->{'crscode'}) {
                   9655:         $cenv{'internal.coursecode'}=$args->{'crscode'};
                   9656:     }
                   9657:     if ($args->{'crsquota'} ne '') {
                   9658:         $cenv{'internal.coursequota'}=$args->{'crsquota'};
                   9659:     } else {
                   9660:         $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
                   9661:     }
                   9662:     if ($args->{'ccuname'}) {
                   9663:         $cenv{'internal.courseowner'} = $args->{'ccuname'}.
                   9664:                                         ':'.$args->{'ccdomain'};
                   9665:     } else {
                   9666:         $cenv{'internal.courseowner'} = $args->{'curruser'};
                   9667:     }
                   9668:     my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
                   9669:     if ($args->{'crssections'}) {
                   9670:         $cenv{'internal.sectionnums'} = '';
                   9671:         if ($args->{'crssections'} =~ m/,/) {
                   9672:             @sections = split/,/,$args->{'crssections'};
                   9673:         } else {
                   9674:             $sections[0] = $args->{'crssections'};
                   9675:         }
                   9676:         if (@sections > 0) {
                   9677:             foreach my $item (@sections) {
                   9678:                 my ($sec,$gp) = split/:/,$item;
                   9679:                 my $class = $args->{'crscode'}.$sec;
                   9680:                 my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
                   9681:                 $cenv{'internal.sectionnums'} .= $item.',';
                   9682:                 unless ($addcheck eq 'ok') {
                   9683:                     push @badclasses, $class;
                   9684:                 }
                   9685:             }
                   9686:             $cenv{'internal.sectionnums'} =~ s/,$//;
                   9687:         }
                   9688:     }
                   9689: # do not hide course coordinator from staff listing, 
                   9690: # even if privileged
                   9691:     $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   9692: # add crosslistings
                   9693:     if ($args->{'crsxlist'}) {
                   9694:         $cenv{'internal.crosslistings'}='';
                   9695:         if ($args->{'crsxlist'} =~ m/,/) {
                   9696:             @xlists = split/,/,$args->{'crsxlist'};
                   9697:         } else {
                   9698:             $xlists[0] = $args->{'crsxlist'};
                   9699:         }
                   9700:         if (@xlists > 0) {
                   9701:             foreach my $item (@xlists) {
                   9702:                 my ($xl,$gp) = split/:/,$item;
                   9703:                 my $addcheck =  &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
                   9704:                 $cenv{'internal.crosslistings'} .= $item.',';
                   9705:                 unless ($addcheck eq 'ok') {
                   9706:                     push @badclasses, $xl;
                   9707:                 }
                   9708:             }
                   9709:             $cenv{'internal.crosslistings'} =~ s/,$//;
                   9710:         }
                   9711:     }
                   9712:     if ($args->{'autoadds'}) {
                   9713:         $cenv{'internal.autoadds'}=$args->{'autoadds'};
                   9714:     }
                   9715:     if ($args->{'autodrops'}) {
                   9716:         $cenv{'internal.autodrops'}=$args->{'autodrops'};
                   9717:     }
                   9718: # check for notification of enrollment changes
                   9719:     my @notified = ();
                   9720:     if ($args->{'notify_owner'}) {
                   9721:         if ($args->{'ccuname'} ne '') {
                   9722:             push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
                   9723:         }
                   9724:     }
                   9725:     if ($args->{'notify_dc'}) {
                   9726:         if ($uname ne '') { 
1.630     raeburn  9727:             push(@notified,$uname.':'.$udom);
1.444     albertel 9728:         }
                   9729:     }
                   9730:     if (@notified > 0) {
                   9731:         my $notifylist;
                   9732:         if (@notified > 1) {
                   9733:             $notifylist = join(',',@notified);
                   9734:         } else {
                   9735:             $notifylist = $notified[0];
                   9736:         }
                   9737:         $cenv{'internal.notifylist'} = $notifylist;
                   9738:     }
                   9739:     if (@badclasses > 0) {
                   9740:         my %lt=&Apache::lonlocal::texthash(
                   9741:                 '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',
                   9742:                 'dnhr' => 'does not have rights to access enrollment in these classes',
                   9743:                 'adby' => 'as determined by the policies of your institution on access to official classlists'
                   9744:         );
1.541     raeburn  9745:         my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
                   9746:                            ' ('.$lt{'adby'}.')';
                   9747:         if ($context eq 'auto') {
                   9748:             $outcome .= $badclass_msg.$linefeed;
1.566     albertel 9749:             $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541     raeburn  9750:             foreach my $item (@badclasses) {
                   9751:                 if ($context eq 'auto') {
                   9752:                     $outcome .= " - $item\n";
                   9753:                 } else {
                   9754:                     $outcome .= "<li>$item</li>\n";
                   9755:                 }
                   9756:             }
                   9757:             if ($context eq 'auto') {
                   9758:                 $outcome .= $linefeed;
                   9759:             } else {
1.566     albertel 9760:                 $outcome .= "</ul><br /><br /></div>\n";
1.541     raeburn  9761:             }
                   9762:         } 
1.444     albertel 9763:     }
                   9764:     if ($args->{'no_end_date'}) {
                   9765:         $args->{'endaccess'} = 0;
                   9766:     }
                   9767:     $cenv{'internal.autostart'}=$args->{'enrollstart'};
                   9768:     $cenv{'internal.autoend'}=$args->{'enrollend'};
                   9769:     $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
                   9770:     $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
                   9771:     if ($args->{'showphotos'}) {
                   9772:       $cenv{'internal.showphotos'}=$args->{'showphotos'};
                   9773:     }
                   9774:     $cenv{'internal.authtype'} = $args->{'authtype'};
                   9775:     $cenv{'internal.autharg'} = $args->{'autharg'}; 
                   9776:     if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
                   9777:         if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'}  eq '') {
1.541     raeburn  9778:             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'); 
                   9779:             if ($context eq 'auto') {
                   9780:                 $outcome .= $krb_msg;
                   9781:             } else {
1.566     albertel 9782:                 $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541     raeburn  9783:             }
                   9784:             $outcome .= $linefeed;
1.444     albertel 9785:         }
                   9786:     }
                   9787:     if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
                   9788:        if ($args->{'setpolicy'}) {
                   9789:            $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   9790:        }
                   9791:        if ($args->{'setcontent'}) {
                   9792:            $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   9793:        }
                   9794:     }
                   9795:     if ($args->{'reshome'}) {
                   9796: 	$cenv{'reshome'}=$args->{'reshome'}.'/';
                   9797: 	$cenv{'reshome'}=~s/\/+$/\//;
                   9798:     }
                   9799: #
                   9800: # course has keyed access
                   9801: #
                   9802:     if ($args->{'setkeys'}) {
                   9803:        $cenv{'keyaccess'}='yes';
                   9804:     }
                   9805: # if specified, key authority is not course, but user
                   9806: # only active if keyaccess is yes
                   9807:     if ($args->{'keyauth'}) {
1.487     albertel 9808: 	my ($user,$domain) = split(':',$args->{'keyauth'});
                   9809: 	$user = &LONCAPA::clean_username($user);
                   9810: 	$domain = &LONCAPA::clean_username($domain);
1.488     foxr     9811: 	if ($user ne '' && $domain ne '') {
1.487     albertel 9812: 	    $cenv{'keyauth'}=$user.':'.$domain;
1.444     albertel 9813: 	}
                   9814:     }
                   9815: 
                   9816:     if ($args->{'disresdis'}) {
                   9817:         $cenv{'pch.roles.denied'}='st';
                   9818:     }
                   9819:     if ($args->{'disablechat'}) {
                   9820:         $cenv{'plc.roles.denied'}='st';
                   9821:     }
                   9822: 
                   9823:     # Record we've not yet viewed the Course Initialization Helper for this 
                   9824:     # course
                   9825:     $cenv{'course.helper.not.run'} = 1;
                   9826:     #
                   9827:     # Use new Randomseed
                   9828:     #
                   9829:     $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
                   9830:     $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
                   9831:     #
                   9832:     # The encryption code and receipt prefix for this course
                   9833:     #
                   9834:     $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
                   9835:     $cenv{'internal.encpref'}=100+int(9*rand(99));
                   9836:     #
                   9837:     # By default, use standard grading
                   9838:     if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
                   9839: 
1.541     raeburn  9840:     $outcome .= $linefeed.&mt('Setting environment').': '.                 
                   9841:           &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444     albertel 9842: #
                   9843: # Open all assignments
                   9844: #
                   9845:     if ($args->{'openall'}) {
                   9846:        my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
                   9847:        my %storecontent = ($storeunder         => time,
                   9848:                            $storeunder.'.type' => 'date_start');
                   9849:        
                   9850:        $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541     raeburn  9851:                  ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444     albertel 9852:    }
                   9853: #
                   9854: # Set first page
                   9855: #
                   9856:     unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
                   9857: 	    || ($cloneid)) {
1.445     albertel 9858: 	use LONCAPA::map;
1.444     albertel 9859: 	$outcome .= &mt('Setting first resource').': ';
1.445     albertel 9860: 
                   9861: 	my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
                   9862:         my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
                   9863: 
1.444     albertel 9864:         $outcome .= ($fatal?$errtext:'read ok').' - ';
                   9865:         my $title; my $url;
                   9866:         if ($args->{'firstres'} eq 'syl') {
1.690     bisitz   9867: 	    $title=&mt('Syllabus');
1.444     albertel 9868:             $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
                   9869:         } else {
1.690     bisitz   9870:             $title=&mt('Navigate Contents');
1.444     albertel 9871:             $url='/adm/navmaps';
                   9872:         }
1.445     albertel 9873: 
                   9874:         $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
                   9875: 	(my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
                   9876: 
                   9877: 	if ($errtext) { $fatal=2; }
1.541     raeburn  9878:         $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444     albertel 9879:     }
1.566     albertel 9880: 
                   9881:     return (1,$outcome);
1.444     albertel 9882: }
                   9883: 
                   9884: ############################################################
                   9885: ############################################################
                   9886: 
1.378     raeburn  9887: sub course_type {
                   9888:     my ($cid) = @_;
                   9889:     if (!defined($cid)) {
                   9890:         $cid = $env{'request.course.id'};
                   9891:     }
1.404     albertel 9892:     if (defined($env{'course.'.$cid.'.type'})) {
                   9893:         return $env{'course.'.$cid.'.type'};
1.378     raeburn  9894:     } else {
                   9895:         return 'Course';
1.377     raeburn  9896:     }
                   9897: }
1.156     albertel 9898: 
1.406     raeburn  9899: sub group_term {
                   9900:     my $crstype = &course_type();
                   9901:     my %names = (
                   9902:                   'Course' => 'group',
                   9903:                   'Group' => 'team',
                   9904:                 );
                   9905:     return $names{$crstype};
                   9906: }
                   9907: 
1.156     albertel 9908: sub icon {
                   9909:     my ($file)=@_;
1.505     albertel 9910:     my $curfext = lc((split(/\./,$file))[-1]);
1.168     albertel 9911:     my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156     albertel 9912:     my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168     albertel 9913:     if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
                   9914: 	if (-e  $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
                   9915: 	          $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   9916: 	            $curfext.".gif") {
                   9917: 	    $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   9918: 		$curfext.".gif";
                   9919: 	}
                   9920:     }
1.249     albertel 9921:     return &lonhttpdurl($iconname);
1.154     albertel 9922: } 
1.84      albertel 9923: 
1.575     albertel 9924: sub lonhttpdurl {
1.692     www      9925: #
                   9926: # Had been used for "small fry" static images on separate port 8080.
                   9927: # Modify here if lightweight http functionality desired again.
                   9928: # Currently eliminated due to increasing firewall issues.
                   9929: #
1.575     albertel 9930:     my ($url)=@_;
1.692     www      9931:     return $url;
1.215     albertel 9932: }
                   9933: 
1.213     albertel 9934: sub connection_aborted {
                   9935:     my ($r)=@_;
                   9936:     $r->print(" ");$r->rflush();
                   9937:     my $c = $r->connection;
                   9938:     return $c->aborted();
                   9939: }
                   9940: 
1.221     foxr     9941: #    Escapes strings that may have embedded 's that will be put into
1.222     foxr     9942: #    strings as 'strings'.
                   9943: sub escape_single {
1.221     foxr     9944:     my ($input) = @_;
1.223     albertel 9945:     $input =~ s/\\/\\\\/g;	# Escape the \'s..(must be first)>
1.221     foxr     9946:     $input =~ s/\'/\\\'/g;	# Esacpe the 's....
                   9947:     return $input;
                   9948: }
1.223     albertel 9949: 
1.222     foxr     9950: #  Same as escape_single, but escape's "'s  This 
                   9951: #  can be used for  "strings"
                   9952: sub escape_double {
                   9953:     my ($input) = @_;
                   9954:     $input =~ s/\\/\\\\/g;	# Escape the /'s..(must be first)>
                   9955:     $input =~ s/\"/\\\"/g;	# Esacpe the "s....
                   9956:     return $input;
                   9957: }
1.223     albertel 9958:  
1.222     foxr     9959: #   Escapes the last element of a full URL.
                   9960: sub escape_url {
                   9961:     my ($url)   = @_;
1.238     raeburn  9962:     my @urlslices = split(/\//, $url,-1);
1.369     www      9963:     my $lastitem = &escape(pop(@urlslices));
1.223     albertel 9964:     return join('/',@urlslices).'/'.$lastitem;
1.222     foxr     9965: }
1.462     albertel 9966: 
                   9967: # -------------------------------------------------------- Initliaze user login
                   9968: sub init_user_environment {
1.463     albertel 9969:     my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462     albertel 9970:     my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
                   9971: 
                   9972:     my $public=($username eq 'public' && $domain eq 'public');
                   9973: 
                   9974: # See if old ID present, if so, remove
                   9975: 
                   9976:     my ($filename,$cookie,$userroles);
                   9977:     my $now=time;
                   9978: 
                   9979:     if ($public) {
                   9980: 	my $max_public=100;
                   9981: 	my $oldest;
                   9982: 	my $oldest_time=0;
                   9983: 	for(my $next=1;$next<=$max_public;$next++) {
                   9984: 	    if (-e $lonids."/publicuser_$next.id") {
                   9985: 		my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
                   9986: 		if ($mtime<$oldest_time || !$oldest_time) {
                   9987: 		    $oldest_time=$mtime;
                   9988: 		    $oldest=$next;
                   9989: 		}
                   9990: 	    } else {
                   9991: 		$cookie="publicuser_$next";
                   9992: 		last;
                   9993: 	    }
                   9994: 	}
                   9995: 	if (!$cookie) { $cookie="publicuser_$oldest"; }
                   9996:     } else {
1.463     albertel 9997: 	# if this isn't a robot, kill any existing non-robot sessions
                   9998: 	if (!$args->{'robot'}) {
                   9999: 	    opendir(DIR,$lonids);
                   10000: 	    while ($filename=readdir(DIR)) {
                   10001: 		if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
                   10002: 		    unlink($lonids.'/'.$filename);
                   10003: 		}
1.462     albertel 10004: 	    }
1.463     albertel 10005: 	    closedir(DIR);
1.462     albertel 10006: 	}
                   10007: # Give them a new cookie
1.463     albertel 10008: 	my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684     www      10009: 		                   : $now.$$.int(rand(10000)));
1.463     albertel 10010: 	$cookie="$username\_$id\_$domain\_$authhost";
1.462     albertel 10011:     
                   10012: # Initialize roles
                   10013: 
                   10014: 	$userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
                   10015:     }
                   10016: # ------------------------------------ Check browser type and MathML capability
                   10017: 
                   10018:     my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
                   10019:         $clientunicode,$clientos) = &decode_user_agent($r);
                   10020: 
                   10021: # -------------------------------------- Any accessibility options to remember?
                   10022:     if (($form->{'interface'}) && ($form->{'remember'} eq 'true')) {
                   10023: 	foreach my $option ('imagesuppress','appletsuppress',
                   10024: 			    'embedsuppress','fontenhance','blackwhite') {
                   10025: 	    if ($form->{$option} eq 'true') {
                   10026: 		&Apache::lonnet::put('environment',{$option => 'on'},
                   10027: 				     $domain,$username);
                   10028: 	    } else {
                   10029: 		&Apache::lonnet::del('environment',[$option],
                   10030: 				     $domain,$username);
                   10031: 	    }
                   10032: 	}
                   10033:     }
                   10034: # ------------------------------------------------------------- Get environment
                   10035: 
                   10036:     my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
                   10037:     my ($tmp) = keys(%userenv);
                   10038:     if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   10039: 	# default remote control to off
                   10040: 	if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
                   10041:     } else {
                   10042: 	undef(%userenv);
                   10043:     }
                   10044:     if (($userenv{'interface'}) && (!$form->{'interface'})) {
                   10045: 	$form->{'interface'}=$userenv{'interface'};
                   10046:     }
                   10047:     $env{'environment.remote'}=$userenv{'remote'};
                   10048:     if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
                   10049: 
                   10050: # --------------- Do not trust query string to be put directly into environment
                   10051:     foreach my $option ('imagesuppress','appletsuppress',
                   10052: 			'embedsuppress','fontenhance','blackwhite',
                   10053: 			'interface','localpath','localres') {
                   10054: 	$form->{$option}=~s/[\n\r\=]//gs;
                   10055:     }
                   10056: # --------------------------------------------------------- Write first profile
                   10057: 
                   10058:     {
                   10059: 	my %initial_env = 
                   10060: 	    ("user.name"          => $username,
                   10061: 	     "user.domain"        => $domain,
                   10062: 	     "user.home"          => $authhost,
                   10063: 	     "browser.type"       => $clientbrowser,
                   10064: 	     "browser.version"    => $clientversion,
                   10065: 	     "browser.mathml"     => $clientmathml,
                   10066: 	     "browser.unicode"    => $clientunicode,
                   10067: 	     "browser.os"         => $clientos,
                   10068: 	     "server.domain"      => $Apache::lonnet::perlvar{'lonDefDomain'},
                   10069: 	     "request.course.fn"  => '',
                   10070: 	     "request.course.uri" => '',
                   10071: 	     "request.course.sec" => '',
                   10072: 	     "request.role"       => 'cm',
                   10073: 	     "request.role.adv"   => $env{'user.adv'},
                   10074: 	     "request.host"       => $ENV{'REMOTE_ADDR'},);
                   10075: 
                   10076:         if ($form->{'localpath'}) {
                   10077: 	    $initial_env{"browser.localpath"}  = $form->{'localpath'};
                   10078: 	    $initial_env{"browser.localres"}   = $form->{'localres'};
                   10079:         }
                   10080: 	
                   10081: 	if ($public) {
                   10082: 	    $initial_env{"environment.remote"} = "off";
                   10083: 	}
                   10084: 	if ($form->{'interface'}) {
                   10085: 	    $form->{'interface'}=~s/\W//gs;
                   10086: 	    $initial_env{"browser.interface"} = $form->{'interface'};
                   10087: 	    $env{'browser.interface'}=$form->{'interface'};
                   10088: 	    foreach my $option ('imagesuppress','appletsuppress',
                   10089: 				'embedsuppress','fontenhance','blackwhite') {
                   10090: 		if (($form->{$option} eq 'true') ||
                   10091: 		    ($userenv{$option} eq 'on')) {
                   10092: 		    $initial_env{"browser.$option"} = "on";
                   10093: 		}
                   10094: 	    }
                   10095: 	}
                   10096: 
1.724     raeburn  10097:         foreach my $tool ('aboutme','blog','portfolio') {
                   10098:             $userenv{'availabletools.'.$tool} = 
                   10099:                 &Apache::lonnet::usertools_access($username,$domain,$tool,'reload');
                   10100:         }
                   10101: 
1.765     raeburn  10102:         foreach my $crstype ('official','unofficial') {
                   10103:             $userenv{'canrequest.'.$crstype} =
                   10104:                 &Apache::lonnet::usertools_access($username,$domain,$crstype,
                   10105:                                                   'reload','requestcourses');
                   10106:         }
                   10107: 
1.462     albertel 10108: 	$env{'user.environment'} = "$lonids/$cookie.id";
                   10109: 	
                   10110: 	if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
                   10111: 		 &GDBM_WRCREAT(),0640)) {
                   10112: 	    &_add_to_env(\%disk_env,\%initial_env);
                   10113: 	    &_add_to_env(\%disk_env,\%userenv,'environment.');
                   10114: 	    &_add_to_env(\%disk_env,$userroles);
1.463     albertel 10115: 	    if (ref($args->{'extra_env'})) {
                   10116: 		&_add_to_env(\%disk_env,$args->{'extra_env'});
                   10117: 	    }
1.462     albertel 10118: 	    untie(%disk_env);
                   10119: 	} else {
1.705     tempelho 10120: 	    &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
                   10121: 			   'Could not create environment storage in lonauth: '.$!.'</span>');
1.462     albertel 10122: 	    return 'error: '.$!;
                   10123: 	}
                   10124:     }
                   10125:     $env{'request.role'}='cm';
                   10126:     $env{'request.role.adv'}=$env{'user.adv'};
                   10127:     $env{'browser.type'}=$clientbrowser;
                   10128: 
                   10129:     return $cookie;
                   10130: 
                   10131: }
                   10132: 
                   10133: sub _add_to_env {
                   10134:     my ($idf,$env_data,$prefix) = @_;
1.676     raeburn  10135:     if (ref($env_data) eq 'HASH') {
                   10136:         while (my ($key,$value) = each(%$env_data)) {
                   10137: 	    $idf->{$prefix.$key} = $value;
                   10138: 	    $env{$prefix.$key}   = $value;
                   10139:         }
1.462     albertel 10140:     }
                   10141: }
                   10142: 
1.685     tempelho 10143: # --- Get the symbolic name of a problem and the url
                   10144: sub get_symb {
                   10145:     my ($request,$silent) = @_;
1.726     raeburn  10146:     (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685     tempelho 10147:     my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
                   10148:     if ($symb eq '') {
                   10149:         if (!$silent) {
                   10150:             $request->print("Unable to handle ambiguous references:$url:.");
                   10151:             return ();
                   10152:         }
                   10153:     }
                   10154:     &Apache::lonenc::check_decrypt(\$symb);
                   10155:     return ($symb);
                   10156: }
                   10157: 
                   10158: # --------------------------------------------------------------Get annotation
                   10159: 
                   10160: sub get_annotation {
                   10161:     my ($symb,$enc) = @_;
                   10162: 
                   10163:     my $key = $symb;
                   10164:     if (!$enc) {
                   10165:         $key =
                   10166:             &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
                   10167:     }
                   10168:     my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
                   10169:     return $annotation{$key};
                   10170: }
                   10171: 
                   10172: sub clean_symb {
1.731     raeburn  10173:     my ($symb,$delete_enc) = @_;
1.685     tempelho 10174: 
                   10175:     &Apache::lonenc::check_decrypt(\$symb);
                   10176:     my $enc = $env{'request.enc'};
1.731     raeburn  10177:     if ($delete_enc) {
1.730     raeburn  10178:         delete($env{'request.enc'});
                   10179:     }
1.685     tempelho 10180: 
                   10181:     return ($symb,$enc);
                   10182: }
1.462     albertel 10183: 
1.41      ng       10184: =pod
                   10185: 
                   10186: =back
                   10187: 
1.112     bowersj2 10188: =cut
1.41      ng       10189: 
1.112     bowersj2 10190: 1;
                   10191: __END__;
1.41      ng       10192: 

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