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

1.10      albertel    1: # The LearningOnline Network with CAPA
1.1       albertel    2: # a pile of common routines
1.10      albertel    3: #
1.948.2.13! raeburn     4: # $Id: loncommon.pm,v 1.948.2.12 2010/11/09 21:18:16 raeburn Exp $
1.10      albertel    5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
1.1       albertel   28: 
                     29: # Makes a table out of the previous attempts
1.2       albertel   30: # Inputs result_from_symbread, user, domain, course_id
1.16      harris41   31: # Reads in non-network-related .tab files
1.1       albertel   32: 
1.35      matthew    33: # POD header:
                     34: 
1.45      matthew    35: =pod
                     36: 
1.35      matthew    37: =head1 NAME
                     38: 
                     39: Apache::loncommon - pile of common routines
                     40: 
                     41: =head1 SYNOPSIS
                     42: 
1.112     bowersj2   43: Common routines for manipulating connections, student answers,
                     44:     domains, common Javascript fragments, etc.
1.35      matthew    45: 
1.112     bowersj2   46: =head1 OVERVIEW
1.35      matthew    47: 
1.112     bowersj2   48: A collection of commonly used subroutines that don't have a natural
                     49: home anywhere else. This collection helps remove
1.35      matthew    50: redundancy from other modules and increase efficiency of memory usage.
                     51: 
                     52: =cut 
                     53: 
                     54: # End of POD header
1.1       albertel   55: package Apache::loncommon;
                     56: 
                     57: use strict;
1.258     albertel   58: use Apache::lonnet;
1.46      matthew    59: use GDBM_File;
1.51      www        60: use POSIX qw(strftime mktime);
1.82      www        61: use Apache::lonmenu();
1.498     albertel   62: use Apache::lonenc();
1.117     www        63: use Apache::lonlocal;
1.685     tempelho   64: use Apache::lonnet();
1.139     matthew    65: use HTML::Entities;
1.334     albertel   66: use Apache::lonhtmlcommon();
                     67: use Apache::loncoursedata();
1.344     albertel   68: use Apache::lontexconvert();
1.444     albertel   69: use Apache::lonclonecourse();
1.479     albertel   70: use LONCAPA qw(:DEFAULT :match);
1.657     raeburn    71: use DateTime::TimeZone;
1.687     raeburn    72: use DateTime::Locale::Catalog;
1.117     www        73: 
1.517     raeburn    74: # ---------------------------------------------- Designs
                     75: use vars qw(%defaultdesign);
                     76: 
1.22      www        77: my $readit;
                     78: 
1.517     raeburn    79: 
1.157     matthew    80: ##
                     81: ## Global Variables
                     82: ##
1.46      matthew    83: 
1.643     foxr       84: 
                     85: # ----------------------------------------------- SSI with retries:
                     86: #
                     87: 
                     88: =pod
                     89: 
1.648     raeburn    90: =head1 Server Side include with retries:
1.643     foxr       91: 
                     92: =over 4
                     93: 
1.648     raeburn    94: =item * &ssi_with_retries(resource,retries form)
1.643     foxr       95: 
                     96: Performs an ssi with some number of retries.  Retries continue either
                     97: until the result is ok or until the retry count supplied by the
                     98: caller is exhausted.  
                     99: 
                    100: Inputs:
1.648     raeburn   101: 
                    102: =over 4
                    103: 
1.643     foxr      104: resource   - Identifies the resource to insert.
1.648     raeburn   105: 
1.643     foxr      106: retries    - Count of the number of retries allowed.
1.648     raeburn   107: 
1.643     foxr      108: form       - Hash that identifies the rendering options.
                    109: 
1.648     raeburn   110: =back
                    111: 
                    112: Returns:
                    113: 
                    114: =over 4
                    115: 
1.643     foxr      116: content    - The content of the response.  If retries were exhausted this is empty.
1.648     raeburn   117: 
1.643     foxr      118: response   - The response from the last attempt (which may or may not have been successful.
                    119: 
1.648     raeburn   120: =back
                    121: 
                    122: =back
                    123: 
1.643     foxr      124: =cut
                    125: 
                    126: sub ssi_with_retries {
                    127:     my ($resource, $retries, %form) = @_;
                    128: 
                    129: 
                    130:     my $ok = 0;			# True if we got a good response.
                    131:     my $content;
                    132:     my $response;
                    133: 
                    134:     # Try to get the ssi done. within the retries count:
                    135: 
                    136:     do {
                    137: 	($content, $response) = &Apache::lonnet::ssi($resource, %form);
                    138: 	$ok      = $response->is_success;
1.650     www       139:         if (!$ok) {
                    140:             &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
                    141:         }
1.643     foxr      142: 	$retries--;
                    143:     } while (!$ok && ($retries > 0));
                    144: 
                    145:     if (!$ok) {
                    146: 	$content = '';		# On error return an empty content.
                    147:     }
                    148:     return ($content, $response);
                    149: 
                    150: }
                    151: 
                    152: 
                    153: 
1.20      www       154: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12      harris41  155: my %language;
1.124     www       156: my %supported_language;
1.12      harris41  157: my %cprtag;
1.192     taceyjo1  158: my %scprtag;
1.351     www       159: my %fe; my %fd; my %fm;
1.41      ng        160: my %category_extensions;
1.12      harris41  161: 
1.46      matthew   162: # ---------------------------------------------- Thesaurus variables
1.144     matthew   163: #
                    164: # %Keywords:
                    165: #      A hash used by &keyword to determine if a word is considered a keyword.
                    166: # $thesaurus_db_file 
                    167: #      Scalar containing the full path to the thesaurus database.
1.46      matthew   168: 
                    169: my %Keywords;
                    170: my $thesaurus_db_file;
                    171: 
1.144     matthew   172: #
                    173: # Initialize values from language.tab, copyright.tab, filetypes.tab,
                    174: # thesaurus.tab, and filecategories.tab.
                    175: #
1.18      www       176: BEGIN {
1.46      matthew   177:     # Variable initialization
                    178:     $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
                    179:     #
1.22      www       180:     unless ($readit) {
1.12      harris41  181: # ------------------------------------------------------------------- languages
                    182:     {
1.158     raeburn   183:         my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
                    184:                                    '/language.tab';
                    185:         if ( open(my $fh,"<$langtabfile") ) {
1.356     albertel  186:             while (my $line = <$fh>) {
                    187:                 next if ($line=~/^\#/);
                    188:                 chomp($line);
                    189:                 my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$line));
1.158     raeburn   190:                 $language{$key}=$val.' - '.$enc;
                    191:                 if ($sup) {
                    192:                     $supported_language{$key}=$sup;
                    193:                 }
                    194:             }
                    195:             close($fh);
                    196:         }
1.12      harris41  197:     }
                    198: # ------------------------------------------------------------------ copyrights
                    199:     {
1.158     raeburn   200:         my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
                    201:                                   '/copyright.tab';
                    202:         if ( open (my $fh,"<$copyrightfile") ) {
1.356     albertel  203:             while (my $line = <$fh>) {
                    204:                 next if ($line=~/^\#/);
                    205:                 chomp($line);
                    206:                 my ($key,$val)=(split(/\s+/,$line,2));
1.158     raeburn   207:                 $cprtag{$key}=$val;
                    208:             }
                    209:             close($fh);
                    210:         }
1.12      harris41  211:     }
1.351     www       212: # ----------------------------------------------------------- source copyrights
1.192     taceyjo1  213:     {
                    214:         my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
                    215:                                   '/source_copyright.tab';
                    216:         if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356     albertel  217:             while (my $line = <$fh>) {
                    218:                 next if ($line =~ /^\#/);
                    219:                 chomp($line);
                    220:                 my ($key,$val)=(split(/\s+/,$line,2));
1.192     taceyjo1  221:                 $scprtag{$key}=$val;
                    222:             }
                    223:             close($fh);
                    224:         }
                    225:     }
1.63      www       226: 
1.517     raeburn   227: # -------------------------------------------------------------- default domain designs
1.63      www       228:     my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517     raeburn   229:     my $designfile = $designdir.'/default.tab';
                    230:     if ( open (my $fh,"<$designfile") ) {
                    231:         while (my $line = <$fh>) {
                    232:             next if ($line =~ /^\#/);
                    233:             chomp($line);
                    234:             my ($key,$val)=(split(/\=/,$line));
                    235:             if ($val) { $defaultdesign{$key}=$val; }
                    236:         }
                    237:         close($fh);
1.63      www       238:     }
                    239: 
1.15      harris41  240: # ------------------------------------------------------------- file categories
                    241:     {
1.158     raeburn   242:         my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
                    243:                                   '/filecategories.tab';
                    244:         if ( open (my $fh,"<$categoryfile") ) {
1.356     albertel  245: 	    while (my $line = <$fh>) {
                    246: 		next if ($line =~ /^\#/);
                    247: 		chomp($line);
                    248:                 my ($extension,$category)=(split(/\s+/,$line,2));
1.158     raeburn   249:                 push @{$category_extensions{lc($category)}},$extension;
                    250:             }
                    251:             close($fh);
                    252:         }
                    253: 
1.15      harris41  254:     }
1.12      harris41  255: # ------------------------------------------------------------------ file types
                    256:     {
1.158     raeburn   257:         my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
                    258:                '/filetypes.tab';
                    259:         if ( open (my $fh,"<$typesfile") ) {
1.356     albertel  260:             while (my $line = <$fh>) {
                    261: 		next if ($line =~ /^\#/);
                    262: 		chomp($line);
                    263:                 my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158     raeburn   264:                 if ($descr ne '') {
                    265:                     $fe{$ending}=lc($emb);
                    266:                     $fd{$ending}=$descr;
1.351     www       267:                     if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158     raeburn   268:                 }
                    269:             }
                    270:             close($fh);
                    271:         }
1.12      harris41  272:     }
1.22      www       273:     &Apache::lonnet::logthis(
1.705     tempelho  274:              "<span style='color:yellow;'>INFO: Read file types</span>");
1.22      www       275:     $readit=1;
1.46      matthew   276:     }  # end of unless($readit) 
1.32      matthew   277:     
                    278: }
1.112     bowersj2  279: 
1.42      matthew   280: ###############################################################
                    281: ##           HTML and Javascript Helper Functions            ##
                    282: ###############################################################
                    283: 
                    284: =pod 
                    285: 
1.112     bowersj2  286: =head1 HTML and Javascript Functions
1.42      matthew   287: 
1.112     bowersj2  288: =over 4
                    289: 
1.648     raeburn   290: =item * &browser_and_searcher_javascript()
1.112     bowersj2  291: 
                    292: X<browsing, javascript>X<searching, javascript>Returns a string
                    293: containing javascript with two functions, C<openbrowser> and
                    294: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
                    295: tags.
1.42      matthew   296: 
1.648     raeburn   297: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42      matthew   298: 
                    299: inputs: formname, elementname, only, omit
                    300: 
                    301: formname and elementname indicate the name of the html form and name of
                    302: the element that the results of the browsing selection are to be placed in. 
                    303: 
                    304: Specifying 'only' will restrict the browser to displaying only files
1.185     www       305: with the given extension.  Can be a comma separated list.
1.42      matthew   306: 
                    307: Specifying 'omit' will restrict the browser to NOT displaying files
1.185     www       308: with the given extension.  Can be a comma separated list.
1.42      matthew   309: 
1.648     raeburn   310: =item * &opensearcher(formname,elementname) [javascript]
1.42      matthew   311: 
                    312: Inputs: formname, elementname
                    313: 
                    314: formname and elementname specify the name of the html form and the name
                    315: of the element the selection from the search results will be placed in.
1.542     raeburn   316: 
1.42      matthew   317: =cut
                    318: 
                    319: sub browser_and_searcher_javascript {
1.199     albertel  320:     my ($mode)=@_;
                    321:     if (!defined($mode)) { $mode='edit'; }
1.453     albertel  322:     my $resurl=&escape_single(&lastresurl());
1.42      matthew   323:     return <<END;
1.219     albertel  324: // <!-- BEGIN LON-CAPA Internal
1.50      matthew   325:     var editbrowser = null;
1.135     albertel  326:     function openbrowser(formname,elementname,only,omit,titleelement) {
1.170     www       327:         var url = '$resurl/?';
1.42      matthew   328:         if (editbrowser == null) {
                    329:             url += 'launch=1&';
                    330:         }
                    331:         url += 'catalogmode=interactive&';
1.199     albertel  332:         url += 'mode=$mode&';
1.611     albertel  333:         url += 'inhibitmenu=yes&';
1.42      matthew   334:         url += 'form=' + formname + '&';
                    335:         if (only != null) {
                    336:             url += 'only=' + only + '&';
1.217     albertel  337:         } else {
                    338:             url += 'only=&';
                    339: 	}
1.42      matthew   340:         if (omit != null) {
                    341:             url += 'omit=' + omit + '&';
1.217     albertel  342:         } else {
                    343:             url += 'omit=&';
                    344: 	}
1.135     albertel  345:         if (titleelement != null) {
                    346:             url += 'titleelement=' + titleelement + '&';
1.217     albertel  347:         } else {
                    348: 	    url += 'titleelement=&';
                    349: 	}
1.42      matthew   350:         url += 'element=' + elementname + '';
                    351:         var title = 'Browser';
1.435     albertel  352:         var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42      matthew   353:         options += ',width=700,height=600';
                    354:         editbrowser = open(url,title,options,'1');
                    355:         editbrowser.focus();
                    356:     }
                    357:     var editsearcher;
1.135     albertel  358:     function opensearcher(formname,elementname,titleelement) {
1.42      matthew   359:         var url = '/adm/searchcat?';
                    360:         if (editsearcher == null) {
                    361:             url += 'launch=1&';
                    362:         }
                    363:         url += 'catalogmode=interactive&';
1.199     albertel  364:         url += 'mode=$mode&';
1.42      matthew   365:         url += 'form=' + formname + '&';
1.135     albertel  366:         if (titleelement != null) {
                    367:             url += 'titleelement=' + titleelement + '&';
1.217     albertel  368:         } else {
                    369: 	    url += 'titleelement=&';
                    370: 	}
1.42      matthew   371:         url += 'element=' + elementname + '';
                    372:         var title = 'Search';
1.435     albertel  373:         var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42      matthew   374:         options += ',width=700,height=600';
                    375:         editsearcher = open(url,title,options,'1');
                    376:         editsearcher.focus();
                    377:     }
1.219     albertel  378: // END LON-CAPA Internal -->
1.42      matthew   379: END
1.170     www       380: }
                    381: 
                    382: sub lastresurl {
1.258     albertel  383:     if ($env{'environment.lastresurl'}) {
                    384: 	return $env{'environment.lastresurl'}
1.170     www       385:     } else {
                    386: 	return '/res';
                    387:     }
                    388: }
                    389: 
                    390: sub storeresurl {
                    391:     my $resurl=&Apache::lonnet::clutter(shift);
                    392:     unless ($resurl=~/^\/res/) { return 0; }
                    393:     $resurl=~s/\/$//;
                    394:     &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646     raeburn   395:     &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170     www       396:     return 1;
1.42      matthew   397: }
                    398: 
1.74      www       399: sub studentbrowser_javascript {
1.111     www       400:    unless (
1.258     albertel  401:             (($env{'request.course.id'}) && 
1.302     albertel  402:              (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
                    403: 	      || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
                    404: 					  '/'.$env{'request.course.sec'})
                    405: 	      ))
1.258     albertel  406:          || ($env{'request.role'}=~/^(au|dc|su)/)
1.111     www       407:           ) { return ''; }  
1.74      www       408:    return (<<'ENDSTDBRW');
1.776     bisitz    409: <script type="text/javascript" language="Javascript">
1.824     bisitz    410: // <![CDATA[
1.74      www       411:     var stdeditbrowser;
1.793     raeburn   412:     function openstdbrowser(formname,uname,udom,roleflag,ignorefilter,courseadvonly) {
1.74      www       413:         var url = '/adm/pickstudent?';
                    414:         var filter;
1.558     albertel  415: 	if (!ignorefilter) {
                    416: 	    eval('filter=document.'+formname+'.'+uname+'.value;');
                    417: 	}
1.74      www       418:         if (filter != null) {
                    419:            if (filter != '') {
                    420:                url += 'filter='+filter+'&';
                    421: 	   }
                    422:         }
                    423:         url += 'form=' + formname + '&unameelement='+uname+
                    424:                                     '&udomelement='+udom;
1.111     www       425: 	if (roleflag) { url+="&roles=1"; }
1.793     raeburn   426:         if (courseadvonly) { url+="&courseadvonly=1"; }
1.102     www       427:         var title = 'Student_Browser';
1.74      www       428:         var options = 'scrollbars=1,resizable=1,menubar=0';
                    429:         options += ',width=700,height=600';
                    430:         stdeditbrowser = open(url,title,options,'1');
                    431:         stdeditbrowser.focus();
                    432:     }
1.824     bisitz    433: // ]]>
1.74      www       434: </script>
                    435: ENDSTDBRW
                    436: }
1.42      matthew   437: 
1.74      www       438: sub selectstudent_link {
1.793     raeburn   439:    my ($form,$unameele,$udomele,$courseadvonly)=@_;
                    440:    my $callargs = "'".$form."','".$unameele."','".$udomele."'";
1.258     albertel  441:    if ($env{'request.course.id'}) {  
1.302     albertel  442:        if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
                    443: 	   && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
                    444: 					'/'.$env{'request.course.sec'})) {
1.111     www       445: 	   return '';
                    446:        }
1.793     raeburn   447:        if ($courseadvonly)  {
                    448:            $callargs .= ",'',1,1";
                    449:        }
                    450:        return '<span class="LC_nobreak">'.
                    451:               '<a href="javascript:openstdbrowser('.$callargs.');">'.
                    452:               &mt('Select User').'</a></span>';
1.74      www       453:    }
1.258     albertel  454:    if ($env{'request.role'}=~/^(au|dc|su)/) {
1.793     raeburn   455:        $callargs .= ",1"; 
                    456:        return '<span class="LC_nobreak">'.
                    457:               '<a href="javascript:openstdbrowser('.$callargs.');">'.
                    458:               &mt('Select User').'</a></span>';
1.111     www       459:    }
                    460:    return '';
1.91      www       461: }
                    462: 
1.653     raeburn   463: sub authorbrowser_javascript {
                    464:     return <<"ENDAUTHORBRW";
1.776     bisitz    465: <script type="text/javascript" language="JavaScript">
1.824     bisitz    466: // <![CDATA[
1.653     raeburn   467: var stdeditbrowser;
                    468: 
                    469: function openauthorbrowser(formname,udom) {
                    470:     var url = '/adm/pickauthor?';
                    471:     url += 'form='+formname+'&roledom='+udom;
                    472:     var title = 'Author_Browser';
                    473:     var options = 'scrollbars=1,resizable=1,menubar=0';
                    474:     options += ',width=700,height=600';
                    475:     stdeditbrowser = open(url,title,options,'1');
                    476:     stdeditbrowser.focus();
                    477: }
                    478: 
1.824     bisitz    479: // ]]>
1.653     raeburn   480: </script>
                    481: ENDAUTHORBRW
                    482: }
                    483: 
1.91      www       484: sub coursebrowser_javascript {
1.909     raeburn   485:     my ($domainfilter,$sec_element,$formname,$role_element,$crstype) = @_;
1.932     raeburn   486:     my $wintitle = 'Course_Browser';
1.931     raeburn   487:     if ($crstype eq 'Community') {
1.932     raeburn   488:         $wintitle = 'Community_Browser';
1.909     raeburn   489:     }
1.876     raeburn   490:     my $id_functions = &javascript_index_functions();
                    491:     my $output = '
1.776     bisitz    492: <script type="text/javascript" language="JavaScript">
1.824     bisitz    493: // <![CDATA[
1.468     raeburn   494:     var stdeditbrowser;'."\n";
1.876     raeburn   495: 
                    496:     $output .= <<"ENDSTDBRW";
1.909     raeburn   497:     function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91      www       498:         var url = '/adm/pickcourse?';
1.895     raeburn   499:         var formid = getFormIdByName(formname);
1.876     raeburn   500:         var domainfilter = getDomainFromSelectbox(formname,udom);
1.128     albertel  501:         if (domainfilter != null) {
                    502:            if (domainfilter != '') {
                    503:                url += 'domainfilter='+domainfilter+'&';
                    504: 	   }
                    505:         }
1.91      www       506:         url += 'form=' + formname + '&cnumelement='+uname+
1.187     albertel  507: 	                            '&cdomelement='+udom+
                    508:                                     '&cnameelement='+desc;
1.468     raeburn   509:         if (extra_element !=null && extra_element != '') {
1.594     raeburn   510:             if (formname == 'rolechoice' || formname == 'studentform') {
1.468     raeburn   511:                 url += '&roleelement='+extra_element;
                    512:                 if (domainfilter == null || domainfilter == '') {
                    513:                     url += '&domainfilter='+extra_element;
                    514:                 }
1.234     raeburn   515:             }
1.468     raeburn   516:             else {
                    517:                 if (formname == 'portform') {
                    518:                     url += '&setroles='+extra_element;
1.800     raeburn   519:                 } else {
                    520:                     if (formname == 'rules') {
                    521:                         url += '&fixeddom='+extra_element; 
                    522:                     }
1.468     raeburn   523:                 }
                    524:             }     
1.230     raeburn   525:         }
1.909     raeburn   526:         if (type != null && type != '') {
                    527:             url += '&type='+type;
                    528:         }
                    529:         if (type_elem != null && type_elem != '') {
                    530:             url += '&typeelement='+type_elem;
                    531:         }
1.872     raeburn   532:         if (formname == 'ccrs') {
                    533:             var ownername = document.forms[formid].ccuname.value;
                    534:             var ownerdom =  document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
                    535:             url += '&cloner='+ownername+':'+ownerdom;
                    536:         }
1.293     raeburn   537:         if (multflag !=null && multflag != '') {
                    538:             url += '&multiple='+multflag;
                    539:         }
1.909     raeburn   540:         var title = '$wintitle';
1.91      www       541:         var options = 'scrollbars=1,resizable=1,menubar=0';
                    542:         options += ',width=700,height=600';
                    543:         stdeditbrowser = open(url,title,options,'1');
                    544:         stdeditbrowser.focus();
                    545:     }
1.876     raeburn   546: $id_functions
                    547: ENDSTDBRW
1.905     raeburn   548:     if (($sec_element ne '') || ($role_element ne '')) {
                    549:         $output .= &setsec_javascript($sec_element,$formname,$role_element);
1.876     raeburn   550:     }
                    551:     $output .= '
                    552: // ]]>
                    553: </script>';
                    554:     return $output;
                    555: }
                    556: 
                    557: sub javascript_index_functions {
                    558:     return <<"ENDJS";
                    559: 
                    560: function getFormIdByName(formname) {
                    561:     for (var i=0;i<document.forms.length;i++) {
                    562:         if (document.forms[i].name == formname) {
                    563:             return i;
                    564:         }
                    565:     }
                    566:     return -1;
                    567: }
                    568: 
                    569: function getIndexByName(formid,item) {
                    570:     for (var i=0;i<document.forms[formid].elements.length;i++) {
                    571:         if (document.forms[formid].elements[i].name == item) {
                    572:             return i;
                    573:         }
                    574:     }
                    575:     return -1;
                    576: }
1.468     raeburn   577: 
1.876     raeburn   578: function getDomainFromSelectbox(formname,udom) {
                    579:     var userdom;
                    580:     var formid = getFormIdByName(formname);
                    581:     if (formid > -1) {
                    582:         var domid = getIndexByName(formid,udom);
                    583:         if (domid > -1) {
                    584:             if (document.forms[formid].elements[domid].type == 'select-one') {
                    585:                 userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
                    586:             }
                    587:             if (document.forms[formid].elements[domid].type == 'hidden') {
                    588:                 userdom=document.forms[formid].elements[domid].value;
1.468     raeburn   589:             }
                    590:         }
                    591:     }
1.876     raeburn   592:     return userdom;
                    593: }
                    594: 
                    595: ENDJS
1.468     raeburn   596: 
1.876     raeburn   597: }
                    598: 
                    599: sub userbrowser_javascript {
                    600:     my $id_functions = &javascript_index_functions();
                    601:     return <<"ENDUSERBRW";
                    602: 
1.888     raeburn   603: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876     raeburn   604:     var url = '/adm/pickuser?';
                    605:     var userdom = getDomainFromSelectbox(formname,udom);
                    606:     if (userdom != null) {
                    607:        if (userdom != '') {
                    608:            url += 'srchdom='+userdom+'&';
                    609:        }
                    610:     }
                    611:     url += 'form=' + formname + '&unameelement='+uname+
                    612:                                 '&udomelement='+udom+
                    613:                                 '&ulastelement='+ulast+
                    614:                                 '&ufirstelement='+ufirst+
                    615:                                 '&uemailelement='+uemail+
1.881     raeburn   616:                                 '&hideudomelement='+hideudom+
                    617:                                 '&coursedom='+crsdom;
1.888     raeburn   618:     if ((caller != null) && (caller != undefined)) {
                    619:         url += '&caller='+caller;
                    620:     }
1.876     raeburn   621:     var title = 'User_Browser';
                    622:     var options = 'scrollbars=1,resizable=1,menubar=0';
                    623:     options += ',width=700,height=600';
                    624:     var stdeditbrowser = open(url,title,options,'1');
                    625:     stdeditbrowser.focus();
                    626: }
                    627: 
1.888     raeburn   628: function fix_domain (formname,udom,origdom,uname) {
1.876     raeburn   629:     var formid = getFormIdByName(formname);
                    630:     if (formid > -1) {
1.888     raeburn   631:         var unameid = getIndexByName(formid,uname);
1.876     raeburn   632:         var domid = getIndexByName(formid,udom);
                    633:         var hidedomid = getIndexByName(formid,origdom);
                    634:         if (hidedomid > -1) {
                    635:             var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888     raeburn   636:             var unameval = document.forms[formid].elements[unameid].value;
                    637:             if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
                    638:                 if (domid > -1) {
                    639:                     var slct = document.forms[formid].elements[domid];
                    640:                     if (slct.type == 'select-one') {
                    641:                         var i;
                    642:                         for (i=0;i<slct.length;i++) {
                    643:                             if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
                    644:                         }
                    645:                     }
                    646:                     if (slct.type == 'hidden') {
                    647:                         slct.value = fixeddom;
1.876     raeburn   648:                     }
                    649:                 }
1.468     raeburn   650:             }
                    651:         }
                    652:     }
1.876     raeburn   653:     return;
                    654: }
                    655: 
                    656: $id_functions
                    657: ENDUSERBRW
1.468     raeburn   658: }
                    659: 
                    660: sub setsec_javascript {
1.905     raeburn   661:     my ($sec_element,$formname,$role_element) = @_;
                    662:     my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
                    663:         $communityrolestr);
                    664:     if ($role_element ne '') {
                    665:         my @allroles = ('st','ta','ep','in','ad');
                    666:         foreach my $crstype ('Course','Community') {
                    667:             if ($crstype eq 'Community') {
                    668:                 foreach my $role (@allroles) {
                    669:                     push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
                    670:                 }
                    671:                 push(@communityrolenames,&Apache::lonnet::plaintext('co'));
                    672:             } else {
                    673:                 foreach my $role (@allroles) {
                    674:                     push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
                    675:                 }
                    676:                 push(@courserolenames,&Apache::lonnet::plaintext('cc'));
                    677:             }
                    678:         }
                    679:         $rolestr = '"'.join('","',@allroles).'"';
                    680:         $courserolestr = '"'.join('","',@courserolenames).'"';
                    681:         $communityrolestr = '"'.join('","',@communityrolenames).'"';
                    682:     }
1.468     raeburn   683:     my $setsections = qq|
                    684: function setSect(sectionlist) {
1.629     raeburn   685:     var sectionsArray = new Array();
                    686:     if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
                    687:         sectionsArray = sectionlist.split(",");
                    688:     }
1.468     raeburn   689:     var numSections = sectionsArray.length;
                    690:     document.$formname.$sec_element.length = 0;
                    691:     if (numSections == 0) {
                    692:         document.$formname.$sec_element.multiple=false;
                    693:         document.$formname.$sec_element.size=1;
                    694:         document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
                    695:     } else {
                    696:         if (numSections == 1) {
                    697:             document.$formname.$sec_element.multiple=false;
                    698:             document.$formname.$sec_element.size=1;
                    699:             document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
                    700:             document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
                    701:             document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
                    702:         } else {
                    703:             for (var i=0; i<numSections; i++) {
                    704:                 document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
                    705:             }
                    706:             document.$formname.$sec_element.multiple=true
                    707:             if (numSections < 3) {
                    708:                 document.$formname.$sec_element.size=numSections;
                    709:             } else {
                    710:                 document.$formname.$sec_element.size=3;
                    711:             }
                    712:             document.$formname.$sec_element.options[0].selected = false
                    713:         }
                    714:     }
1.91      www       715: }
1.905     raeburn   716: 
                    717: function setRole(crstype) {
1.468     raeburn   718: |;
1.905     raeburn   719:     if ($role_element eq '') {
                    720:         $setsections .= '    return;
                    721: }
                    722: ';
                    723:     } else {
                    724:         $setsections .= qq|
                    725:     var elementLength = document.$formname.$role_element.length;
                    726:     var allroles = Array($rolestr);
                    727:     var courserolenames = Array($courserolestr);
                    728:     var communityrolenames = Array($communityrolestr);
                    729:     if (elementLength != undefined) {
                    730:         if (document.$formname.$role_element.options[5].value == 'cc') {
                    731:             if (crstype == 'Course') {
                    732:                 return;
                    733:             } else {
                    734:                 allroles[5] = 'co';
                    735:                 for (var i=0; i<6; i++) {
                    736:                     document.$formname.$role_element.options[i].value = allroles[i];
                    737:                     document.$formname.$role_element.options[i].text = communityrolenames[i];
                    738:                 }
                    739:             }
                    740:         } else {
                    741:             if (crstype == 'Community') {
                    742:                 return;
                    743:             } else {
                    744:                 allroles[5] = 'cc';
                    745:                 for (var i=0; i<6; i++) {
                    746:                     document.$formname.$role_element.options[i].value = allroles[i];
                    747:                     document.$formname.$role_element.options[i].text = courserolenames[i];
                    748:                 }
                    749:             }
                    750:         }
                    751:     }
                    752:     return;
                    753: }
                    754: |;
                    755:     }
1.468     raeburn   756:     return $setsections;
                    757: }
                    758: 
1.91      www       759: sub selectcourse_link {
1.909     raeburn   760:    my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
                    761:        $typeelement) = @_;
                    762:    my $type = $selecttype;
1.871     raeburn   763:    my $linktext = &mt('Select Course');
                    764:    if ($selecttype eq 'Community') {
1.909     raeburn   765:        $linktext = &mt('Select Community');
1.906     raeburn   766:    } elsif ($selecttype eq 'Course/Community') {
                    767:        $linktext = &mt('Select Course/Community');
1.909     raeburn   768:        $type = '';
1.871     raeburn   769:    }
1.787     bisitz    770:    return '<span class="LC_nobreak">'
                    771:          ."<a href='"
                    772:          .'javascript:opencrsbrowser("'.$form.'","'.$unameele
                    773:          .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909     raeburn   774:          .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871     raeburn   775:          ."'>".$linktext.'</a>'
1.787     bisitz    776:          .'</span>';
1.74      www       777: }
1.42      matthew   778: 
1.653     raeburn   779: sub selectauthor_link {
                    780:    my ($form,$udom)=@_;
                    781:    return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
                    782:           &mt('Select Author').'</a>';
                    783: }
                    784: 
1.876     raeburn   785: sub selectuser_link {
1.881     raeburn   786:     my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888     raeburn   787:         $coursedom,$linktext,$caller) = @_;
1.876     raeburn   788:     return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888     raeburn   789:            "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881     raeburn   790:            ');">'.$linktext.'</a>';
1.876     raeburn   791: }
                    792: 
1.273     raeburn   793: sub check_uncheck_jscript {
                    794:     my $jscript = <<"ENDSCRT";
                    795: function checkAll(field) {
                    796:     if (field.length > 0) {
                    797:         for (i = 0; i < field.length; i++) {
                    798:             field[i].checked = true ;
                    799:         }
                    800:     } else {
                    801:         field.checked = true
                    802:     }
                    803: }
                    804:  
                    805: function uncheckAll(field) {
                    806:     if (field.length > 0) {
                    807:         for (i = 0; i < field.length; i++) {
                    808:             field[i].checked = false ;
1.543     albertel  809:         }
                    810:     } else {
1.273     raeburn   811:         field.checked = false ;
                    812:     }
                    813: }
                    814: ENDSCRT
                    815:     return $jscript;
                    816: }
                    817: 
1.656     www       818: sub select_timezone {
1.659     raeburn   819:    my ($name,$selected,$onchange,$includeempty)=@_;
                    820:    my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
                    821:    if ($includeempty) {
                    822:        $output .= '<option value=""';
                    823:        if (($selected eq '') || ($selected eq 'local')) {
                    824:            $output .= ' selected="selected" ';
                    825:        }
                    826:        $output .= '> </option>';
                    827:    }
1.657     raeburn   828:    my @timezones = DateTime::TimeZone->all_names;
                    829:    foreach my $tzone (@timezones) {
                    830:        $output.= '<option value="'.$tzone.'"';
                    831:        if ($tzone eq $selected) {
                    832:            $output.=' selected="selected"';
                    833:        }
                    834:        $output.=">$tzone</option>\n";
1.656     www       835:    }
                    836:    $output.="</select>";
                    837:    return $output;
                    838: }
1.273     raeburn   839: 
1.687     raeburn   840: sub select_datelocale {
                    841:     my ($name,$selected,$onchange,$includeempty)=@_;
                    842:     my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
                    843:     if ($includeempty) {
                    844:         $output .= '<option value=""';
                    845:         if ($selected eq '') {
                    846:             $output .= ' selected="selected" ';
                    847:         }
                    848:         $output .= '> </option>';
                    849:     }
                    850:     my (@possibles,%locale_names);
                    851:     my @locales = DateTime::Locale::Catalog::Locales;
                    852:     foreach my $locale (@locales) {
                    853:         if (ref($locale) eq 'HASH') {
                    854:             my $id = $locale->{'id'};
                    855:             if ($id ne '') {
                    856:                 my $en_terr = $locale->{'en_territory'};
                    857:                 my $native_terr = $locale->{'native_territory'};
1.695     raeburn   858:                 my @languages = &Apache::lonlocal::preferred_languages();
1.687     raeburn   859:                 if (grep(/^en$/,@languages) || !@languages) {
                    860:                     if ($en_terr ne '') {
                    861:                         $locale_names{$id} = '('.$en_terr.')';
                    862:                     } elsif ($native_terr ne '') {
                    863:                         $locale_names{$id} = $native_terr;
                    864:                     }
                    865:                 } else {
                    866:                     if ($native_terr ne '') {
                    867:                         $locale_names{$id} = $native_terr.' ';
                    868:                     } elsif ($en_terr ne '') {
                    869:                         $locale_names{$id} = '('.$en_terr.')';
                    870:                     }
                    871:                 }
                    872:                 push (@possibles,$id);
                    873:             }
                    874:         }
                    875:     }
                    876:     foreach my $item (sort(@possibles)) {
                    877:         $output.= '<option value="'.$item.'"';
                    878:         if ($item eq $selected) {
                    879:             $output.=' selected="selected"';
                    880:         }
                    881:         $output.=">$item";
                    882:         if ($locale_names{$item} ne '') {
                    883:             $output.="  $locale_names{$item}</option>\n";
                    884:         }
                    885:         $output.="</option>\n";
                    886:     }
                    887:     $output.="</select>";
                    888:     return $output;
                    889: }
                    890: 
1.792     raeburn   891: sub select_language {
                    892:     my ($name,$selected,$includeempty) = @_;
                    893:     my %langchoices;
                    894:     if ($includeempty) {
                    895:         %langchoices = ('' => 'No language preference');
                    896:     }
                    897:     foreach my $id (&languageids()) {
                    898:         my $code = &supportedlanguagecode($id);
                    899:         if ($code) {
                    900:             $langchoices{$code} = &plainlanguagedescription($id);
                    901:         }
                    902:     }
1.948.2.7  raeburn   903:     return &select_form($selected,$name,\%langchoices);
1.792     raeburn   904: }
                    905: 
1.42      matthew   906: =pod
1.36      matthew   907: 
1.648     raeburn   908: =item * &linked_select_forms(...)
1.36      matthew   909: 
                    910: linked_select_forms returns a string containing a <script></script> block
                    911: and html for two <select> menus.  The select menus will be linked in that
                    912: changing the value of the first menu will result in new values being placed
                    913: in the second menu.  The values in the select menu will appear in alphabetical
1.609     raeburn   914: order unless a defined order is provided.
1.36      matthew   915: 
                    916: linked_select_forms takes the following ordered inputs:
                    917: 
                    918: =over 4
                    919: 
1.112     bowersj2  920: =item * $formname, the name of the <form> tag
1.36      matthew   921: 
1.112     bowersj2  922: =item * $middletext, the text which appears between the <select> tags
1.36      matthew   923: 
1.112     bowersj2  924: =item * $firstdefault, the default value for the first menu
1.36      matthew   925: 
1.112     bowersj2  926: =item * $firstselectname, the name of the first <select> tag
1.36      matthew   927: 
1.112     bowersj2  928: =item * $secondselectname, the name of the second <select> tag
1.36      matthew   929: 
1.112     bowersj2  930: =item * $hashref, a reference to a hash containing the data for the menus.
1.36      matthew   931: 
1.609     raeburn   932: =item * $menuorder, the order of values in the first menu
                    933: 
1.41      ng        934: =back 
                    935: 
1.36      matthew   936: Below is an example of such a hash.  Only the 'text', 'default', and 
                    937: 'select2' keys must appear as stated.  keys(%menu) are the possible 
                    938: values for the first select menu.  The text that coincides with the 
1.41      ng        939: first menu value is given in $menu{$choice1}->{'text'}.  The values 
1.36      matthew   940: and text for the second menu are given in the hash pointed to by 
                    941: $menu{$choice1}->{'select2'}.  
                    942: 
1.112     bowersj2  943:  my %menu = ( A1 => { text =>"Choice A1" ,
                    944:                        default => "B3",
                    945:                        select2 => { 
                    946:                            B1 => "Choice B1",
                    947:                            B2 => "Choice B2",
                    948:                            B3 => "Choice B3",
                    949:                            B4 => "Choice B4"
1.609     raeburn   950:                            },
                    951:                        order => ['B4','B3','B1','B2'],
1.112     bowersj2  952:                    },
                    953:                A2 => { text =>"Choice A2" ,
                    954:                        default => "C2",
                    955:                        select2 => { 
                    956:                            C1 => "Choice C1",
                    957:                            C2 => "Choice C2",
                    958:                            C3 => "Choice C3"
1.609     raeburn   959:                            },
                    960:                        order => ['C2','C1','C3'],
1.112     bowersj2  961:                    },
                    962:                A3 => { text =>"Choice A3" ,
                    963:                        default => "D6",
                    964:                        select2 => { 
                    965:                            D1 => "Choice D1",
                    966:                            D2 => "Choice D2",
                    967:                            D3 => "Choice D3",
                    968:                            D4 => "Choice D4",
                    969:                            D5 => "Choice D5",
                    970:                            D6 => "Choice D6",
                    971:                            D7 => "Choice D7"
1.609     raeburn   972:                            },
                    973:                        order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112     bowersj2  974:                    }
                    975:                );
1.36      matthew   976: 
                    977: =cut
                    978: 
                    979: sub linked_select_forms {
                    980:     my ($formname,
                    981:         $middletext,
                    982:         $firstdefault,
                    983:         $firstselectname,
                    984:         $secondselectname, 
1.609     raeburn   985:         $hashref,
                    986:         $menuorder,
1.36      matthew   987:         ) = @_;
                    988:     my $second = "document.$formname.$secondselectname";
                    989:     my $first = "document.$formname.$firstselectname";
                    990:     # output the javascript to do the changing
                    991:     my $result = '';
1.776     bisitz    992:     $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824     bisitz    993:     $result.="// <![CDATA[\n";
1.36      matthew   994:     $result.="var select2data = new Object();\n";
                    995:     $" = '","';
                    996:     my $debug = '';
                    997:     foreach my $s1 (sort(keys(%$hashref))) {
                    998:         $result.="select2data.d_$s1 = new Object();\n";        
                    999:         $result.="select2data.d_$s1.def = new String('".
                   1000:             $hashref->{$s1}->{'default'}."');\n";
1.609     raeburn  1001:         $result.="select2data.d_$s1.values = new Array(";
1.36      matthew  1002:         my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609     raeburn  1003:         if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
                   1004:             @s2values = @{$hashref->{$s1}->{'order'}};
                   1005:         }
1.36      matthew  1006:         $result.="\"@s2values\");\n";
                   1007:         $result.="select2data.d_$s1.texts = new Array(";        
                   1008:         my @s2texts;
                   1009:         foreach my $value (@s2values) {
                   1010:             push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
                   1011:         }
                   1012:         $result.="\"@s2texts\");\n";
                   1013:     }
                   1014:     $"=' ';
                   1015:     $result.= <<"END";
                   1016: 
                   1017: function select1_changed() {
                   1018:     // Determine new choice
                   1019:     var newvalue = "d_" + $first.value;
                   1020:     // update select2
                   1021:     var values     = select2data[newvalue].values;
                   1022:     var texts      = select2data[newvalue].texts;
                   1023:     var select2def = select2data[newvalue].def;
                   1024:     var i;
                   1025:     // out with the old
                   1026:     for (i = 0; i < $second.options.length; i++) {
                   1027:         $second.options[i] = null;
                   1028:     }
                   1029:     // in with the nuclear
                   1030:     for (i=0;i<values.length; i++) {
                   1031:         $second.options[i] = new Option(values[i]);
1.143     matthew  1032:         $second.options[i].value = values[i];
1.36      matthew  1033:         $second.options[i].text = texts[i];
                   1034:         if (values[i] == select2def) {
                   1035:             $second.options[i].selected = true;
                   1036:         }
                   1037:     }
                   1038: }
1.824     bisitz   1039: // ]]>
1.36      matthew  1040: </script>
                   1041: END
                   1042:     # output the initial values for the selection lists
                   1043:     $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609     raeburn  1044:     my @order = sort(keys(%{$hashref}));
                   1045:     if (ref($menuorder) eq 'ARRAY') {
                   1046:         @order = @{$menuorder};
                   1047:     }
                   1048:     foreach my $value (@order) {
1.36      matthew  1049:         $result.="    <option value=\"$value\" ";
1.253     albertel 1050:         $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119     www      1051:         $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36      matthew  1052:     }
                   1053:     $result .= "</select>\n";
                   1054:     my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
                   1055:     $result .= $middletext;
                   1056:     $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
                   1057:     my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609     raeburn  1058:     
                   1059:     my @secondorder = sort(keys(%select2));
                   1060:     if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
                   1061:         @secondorder = @{$hashref->{$firstdefault}->{'order'}};
                   1062:     }
                   1063:     foreach my $value (@secondorder) {
1.36      matthew  1064:         $result.="    <option value=\"$value\" ";        
1.253     albertel 1065:         $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119     www      1066:         $result.=">".&mt($select2{$value})."</option>\n";
1.36      matthew  1067:     }
                   1068:     $result .= "</select>\n";
                   1069:     #    return $debug;
                   1070:     return $result;
                   1071: }   #  end of sub linked_select_forms {
                   1072: 
1.45      matthew  1073: =pod
1.44      bowersj2 1074: 
1.948.2.7  raeburn  1075: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44      bowersj2 1076: 
1.112     bowersj2 1077: Returns a string corresponding to an HTML link to the given help
                   1078: $topic, where $topic corresponds to the name of a .tex file in
                   1079: /home/httpd/html/adm/help/tex, with underscores replaced by
                   1080: spaces. 
                   1081: 
                   1082: $text will optionally be linked to the same topic, allowing you to
                   1083: link text in addition to the graphic. If you do not want to link
                   1084: text, but wish to specify one of the later parameters, pass an
                   1085: empty string. 
                   1086: 
                   1087: $stayOnPage is a value that will be interpreted as a boolean. If true,
                   1088: the link will not open a new window. If false, the link will open
                   1089: a new window using Javascript. (Default is false.) 
                   1090: 
                   1091: $width and $height are optional numerical parameters that will
                   1092: override the width and height of the popped up window, which may
                   1093: be useful for certain help topics with big pictures included. 
1.44      bowersj2 1094: 
                   1095: =cut
                   1096: 
                   1097: sub help_open_topic {
1.948.2.7  raeburn  1098:     my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48      bowersj2 1099:     $text = "" if (not defined $text);
1.44      bowersj2 1100:     $stayOnPage = 0 if (not defined $stayOnPage);
                   1101:     $width = 350 if (not defined $width);
                   1102:     $height = 400 if (not defined $height);
                   1103:     my $filename = $topic;
                   1104:     $filename =~ s/ /_/g;
                   1105: 
1.48      bowersj2 1106:     my $template = "";
                   1107:     my $link;
1.572     banghart 1108:     
1.159     www      1109:     $topic=~s/\W/\_/g;
1.44      bowersj2 1110: 
1.572     banghart 1111:     if (!$stayOnPage) {
1.72      bowersj2 1112: 	$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 1113:     } else {
1.48      bowersj2 1114: 	$link = "/adm/help/${filename}.hlp";
                   1115:     }
                   1116: 
                   1117:     # Add the text
1.755     neumanie 1118:     if ($text ne "") {	
1.763     bisitz   1119: 	$template.='<span class="LC_help_open_topic">'
                   1120:                   .'<a target="_top" href="'.$link.'">'
                   1121:                   .$text.'</a>';
1.48      bowersj2 1122:     }
                   1123: 
1.763     bisitz   1124:     # (Always) Add the graphic
1.179     matthew  1125:     my $title = &mt('Online Help');
1.667     raeburn  1126:     my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.948.2.7  raeburn  1127:     if ($imgid ne '') {
                   1128:         $imgid = ' id="'.$imgid.'"';
                   1129:     }
1.763     bisitz   1130:     $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
                   1131:               .'<img src="'.$helpicon.'" border="0"'
                   1132:               .' alt="'.&mt('Help: [_1]',$topic).'"'
1.948.2.7  raeburn  1133:               .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763     bisitz   1134:               .' /></a>';
1.948.2.7  raeburn  1135:     if ($text ne "") {
1.763     bisitz   1136:         $template.='</span>';
                   1137:     }
1.44      bowersj2 1138:     return $template;
                   1139: 
1.106     bowersj2 1140: }
                   1141: 
                   1142: # This is a quicky function for Latex cheatsheet editing, since it 
                   1143: # appears in at least four places
                   1144: sub helpLatexCheatsheet {
1.732     raeburn  1145:     my ($topic,$text,$not_author) = @_;
                   1146:     my $out;
1.106     bowersj2 1147:     my $addOther = '';
1.732     raeburn  1148:     if ($topic) {
1.763     bisitz   1149: 	$addOther = '<span>'.&Apache::loncommon::help_open_topic($topic,&mt($text),
                   1150: 							       undef, undef, 600).
                   1151: 								   '</span> ';
                   1152:     }
                   1153:     $out = '<span>' # Start cheatsheet
                   1154: 	  .$addOther
                   1155:           .'<span>'
                   1156: 	  .&Apache::loncommon::help_open_topic('Greek_Symbols',&mt('Greek Symbols'),
                   1157: 					       undef,undef,600)
                   1158: 	  .'</span> <span>'
                   1159: 	  .&Apache::loncommon::help_open_topic('Other_Symbols',&mt('Other Symbols'),
                   1160: 					       undef,undef,600)
                   1161: 	  .'</span>';
1.732     raeburn  1162:     unless ($not_author) {
1.763     bisitz   1163:         $out .= ' <span>'
                   1164: 	       .&Apache::loncommon::help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),
                   1165: 	                                            undef,undef,600)
                   1166: 	       .'</span>';
1.732     raeburn  1167:     }
1.763     bisitz   1168:     $out .= '</span>'; # End cheatsheet
1.732     raeburn  1169:     return $out;
1.172     www      1170: }
                   1171: 
1.430     albertel 1172: sub general_help {
                   1173:     my $helptopic='Student_Intro';
                   1174:     if ($env{'request.role'}=~/^(ca|au)/) {
                   1175: 	$helptopic='Authoring_Intro';
1.907     raeburn  1176:     } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430     albertel 1177: 	$helptopic='Course_Coordination_Intro';
1.672     raeburn  1178:     } elsif ($env{'request.role'}=~/^dc/) {
                   1179:         $helptopic='Domain_Coordination_Intro';
1.430     albertel 1180:     }
                   1181:     return $helptopic;
                   1182: }
                   1183: 
                   1184: sub update_help_link {
                   1185:     my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
                   1186:     my $origurl = $ENV{'REQUEST_URI'};
                   1187:     $origurl=~s|^/~|/priv/|;
                   1188:     my $timestamp = time;
                   1189:     foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
                   1190:         $$datum = &escape($$datum);
                   1191:     }
                   1192: 
                   1193:     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";
                   1194:     my $output .= <<"ENDOUTPUT";
                   1195: <script type="text/javascript">
1.824     bisitz   1196: // <![CDATA[
1.430     albertel 1197: banner_link = '$banner_link';
1.824     bisitz   1198: // ]]>
1.430     albertel 1199: </script>
                   1200: ENDOUTPUT
                   1201:     return $output;
                   1202: }
                   1203: 
                   1204: # now just updates the help link and generates a blue icon
1.193     raeburn  1205: sub help_open_menu {
1.430     albertel 1206:     my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text) 
1.552     banghart 1207: 	= @_;    
1.430     albertel 1208:     $stayOnPage = 0 if (not defined $stayOnPage);
1.572     banghart 1209:     # only use pop-up help (stayOnPage == 0)
1.552     banghart 1210:     # if environment.remote is on (using remote control UI)
1.798     tempelho 1211:     if ($env{'environment.remote'} eq 'off' ) {
1.552     banghart 1212:         $stayOnPage=1;
1.430     albertel 1213:     }
                   1214:     my $output;
                   1215:     if ($component_help) {
                   1216: 	if (!$text) {
                   1217: 	    $output=&help_open_topic($component_help,undef,$stayOnPage,
                   1218: 				       $width,$height);
                   1219: 	} else {
                   1220: 	    my $help_text;
                   1221: 	    $help_text=&unescape($topic);
                   1222: 	    $output='<table><tr><td>'.
                   1223: 		&help_open_topic($component_help,$help_text,$stayOnPage,
                   1224: 				 $width,$height).'</td></tr></table>';
                   1225: 	}
                   1226:     }
                   1227:     my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
                   1228:     return $output.$banner_link;
                   1229: }
                   1230: 
                   1231: sub top_nav_help {
                   1232:     my ($text) = @_;
1.436     albertel 1233:     $text = &mt($text);
1.572     banghart 1234:     my $stay_on_page = 
1.798     tempelho 1235: 	($env{'environment.remote'} eq 'off' );
1.572     banghart 1236:     my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436     albertel 1237: 	                     : "javascript:helpMenu('open')";
1.572     banghart 1238:     my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436     albertel 1239: 
1.201     raeburn  1240:     my $title = &mt('Get help');
1.436     albertel 1241: 
                   1242:     return <<"END";
                   1243: $banner_link
                   1244:  <a href="$link" title="$title">$text</a>
                   1245: END
                   1246: }
                   1247: 
                   1248: sub help_menu_js {
                   1249:     my ($text) = @_;
                   1250: 
                   1251:     my $stayOnPage = 
1.798     tempelho 1252: 	($env{'environment.remote'} eq 'off' );
1.436     albertel 1253: 
                   1254:     my $width = 620;
                   1255:     my $height = 600;
1.430     albertel 1256:     my $helptopic=&general_help();
                   1257:     my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261     albertel 1258:     my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331     albertel 1259:     my $start_page =
                   1260:         &Apache::loncommon::start_page('Help Menu', undef,
                   1261: 				       {'frameset'    => 1,
                   1262: 					'js_ready'    => 1,
                   1263: 					'add_entries' => {
                   1264: 					    'border' => '0',
1.579     raeburn  1265: 					    'rows'   => "110,*",},});
1.331     albertel 1266:     my $end_page =
                   1267:         &Apache::loncommon::end_page({'frameset' => 1,
                   1268: 				      'js_ready' => 1,});
                   1269: 
1.436     albertel 1270:     my $template .= <<"ENDTEMPLATE";
                   1271: <script type="text/javascript">
1.877     bisitz   1272: // <![CDATA[
1.253     albertel 1273: // <!-- BEGIN LON-CAPA Internal
1.430     albertel 1274: var banner_link = '';
1.243     raeburn  1275: function helpMenu(target) {
                   1276:     var caller = this;
                   1277:     if (target == 'open') {
                   1278:         var newWindow = null;
                   1279:         try {
1.262     albertel 1280:             newWindow =  window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243     raeburn  1281:         }
                   1282:         catch(error) {
                   1283:             writeHelp(caller);
                   1284:             return;
                   1285:         }
                   1286:         if (newWindow) {
                   1287:             caller = newWindow;
                   1288:         }
1.193     raeburn  1289:     }
1.243     raeburn  1290:     writeHelp(caller);
                   1291:     return;
                   1292: }
                   1293: function writeHelp(caller) {
1.430     albertel 1294:     caller.document.writeln('$start_page<frame name="bannerframe"  src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243     raeburn  1295:     caller.document.close()
                   1296:     caller.focus()
1.193     raeburn  1297: }
1.877     bisitz   1298: // END LON-CAPA Internal -->
1.253     albertel 1299: // ]]>
1.436     albertel 1300: </script>
1.193     raeburn  1301: ENDTEMPLATE
                   1302:     return $template;
                   1303: }
                   1304: 
1.172     www      1305: sub help_open_bug {
                   1306:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258     albertel 1307:     unless ($env{'user.adv'}) { return ''; }
1.172     www      1308:     unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
                   1309:     $text = "" if (not defined $text);
                   1310:     $stayOnPage = 0 if (not defined $stayOnPage);
1.798     tempelho 1311:     if ($env{'environment.remote'} eq 'off' ) {
1.172     www      1312: 	$stayOnPage=1;
                   1313:     }
1.184     albertel 1314:     $width = 600 if (not defined $width);
                   1315:     $height = 600 if (not defined $height);
1.172     www      1316: 
                   1317:     $topic=~s/\W+/\+/g;
                   1318:     my $link='';
                   1319:     my $template='';
1.379     albertel 1320:     my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&amp;bug_file_loc='.
                   1321: 	&escape($ENV{'REQUEST_URI'}).'&amp;component='.$topic;
1.172     www      1322:     if (!$stayOnPage)
                   1323:     {
                   1324: 	$link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
                   1325:     }
                   1326:     else
                   1327:     {
                   1328: 	$link = $url;
                   1329:     }
                   1330:     # Add the text
                   1331:     if ($text ne "")
                   1332:     {
                   1333: 	$template .= 
                   1334:   "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705     tempelho 1335:   "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172     www      1336:     }
                   1337: 
                   1338:     # Add the graphic
1.179     matthew  1339:     my $title = &mt('Report a Bug');
1.215     albertel 1340:     my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172     www      1341:     $template .= <<"ENDTEMPLATE";
1.436     albertel 1342:  <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172     www      1343: ENDTEMPLATE
                   1344:     if ($text ne '') { $template.='</td></tr></table>' };
                   1345:     return $template;
                   1346: 
                   1347: }
                   1348: 
                   1349: sub help_open_faq {
                   1350:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258     albertel 1351:     unless ($env{'user.adv'}) { return ''; }
1.172     www      1352:     unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
                   1353:     $text = "" if (not defined $text);
                   1354:     $stayOnPage = 0 if (not defined $stayOnPage);
1.798     tempelho 1355:     if ($env{'environment.remote'} eq 'off' ) {
1.172     www      1356: 	$stayOnPage=1;
                   1357:     }
                   1358:     $width = 350 if (not defined $width);
                   1359:     $height = 400 if (not defined $height);
                   1360: 
                   1361:     $topic=~s/\W+/\+/g;
                   1362:     my $link='';
                   1363:     my $template='';
                   1364:     my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
                   1365:     if (!$stayOnPage)
                   1366:     {
                   1367: 	$link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
                   1368:     }
                   1369:     else
                   1370:     {
                   1371: 	$link = $url;
                   1372:     }
                   1373: 
                   1374:     # Add the text
                   1375:     if ($text ne "")
                   1376:     {
                   1377: 	$template .= 
1.173     www      1378:   "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705     tempelho 1379:   "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172     www      1380:     }
                   1381: 
                   1382:     # Add the graphic
1.179     matthew  1383:     my $title = &mt('View the FAQ');
1.215     albertel 1384:     my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172     www      1385:     $template .= <<"ENDTEMPLATE";
1.436     albertel 1386:  <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172     www      1387: ENDTEMPLATE
                   1388:     if ($text ne '') { $template.='</td></tr></table>' };
                   1389:     return $template;
                   1390: 
1.44      bowersj2 1391: }
1.37      matthew  1392: 
1.180     matthew  1393: ###############################################################
                   1394: ###############################################################
                   1395: 
1.45      matthew  1396: =pod
                   1397: 
1.648     raeburn  1398: =item * &change_content_javascript():
1.256     matthew  1399: 
                   1400: This and the next function allow you to create small sections of an
                   1401: otherwise static HTML page that you can update on the fly with
                   1402: Javascript, even in Netscape 4.
                   1403: 
                   1404: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
                   1405: must be written to the HTML page once. It will prove the Javascript
                   1406: function "change(name, content)". Calling the change function with the
                   1407: name of the section 
                   1408: you want to update, matching the name passed to C<changable_area>, and
                   1409: the new content you want to put in there, will put the content into
                   1410: that area.
                   1411: 
                   1412: B<Note>: Netscape 4 only reserves enough space for the changable area
                   1413: to contain room for the original contents. You need to "make space"
                   1414: for whatever changes you wish to make, and be B<sure> to check your
                   1415: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
                   1416: it's adequate for updating a one-line status display, but little more.
                   1417: This script will set the space to 100% width, so you only need to
                   1418: worry about height in Netscape 4.
                   1419: 
                   1420: Modern browsers are much less limiting, and if you can commit to the
                   1421: user not using Netscape 4, this feature may be used freely with
                   1422: pretty much any HTML.
                   1423: 
                   1424: =cut
                   1425: 
                   1426: sub change_content_javascript {
                   1427:     # If we're on Netscape 4, we need to use Layer-based code
1.258     albertel 1428:     if ($env{'browser.type'} eq 'netscape' &&
                   1429: 	$env{'browser.version'} =~ /^4\./) {
1.256     matthew  1430: 	return (<<NETSCAPE4);
                   1431: 	function change(name, content) {
                   1432: 	    doc = document.layers[name+"___escape"].layers[0].document;
                   1433: 	    doc.open();
                   1434: 	    doc.write(content);
                   1435: 	    doc.close();
                   1436: 	}
                   1437: NETSCAPE4
                   1438:     } else {
                   1439: 	# Otherwise, we need to use semi-standards-compliant code
                   1440: 	# (technically, "innerHTML" isn't standard but the equivalent
                   1441: 	# is really scary, and every useful browser supports it
                   1442: 	return (<<DOMBASED);
                   1443: 	function change(name, content) {
                   1444: 	    element = document.getElementById(name);
                   1445: 	    element.innerHTML = content;
                   1446: 	}
                   1447: DOMBASED
                   1448:     }
                   1449: }
                   1450: 
                   1451: =pod
                   1452: 
1.648     raeburn  1453: =item * &changable_area($name,$origContent):
1.256     matthew  1454: 
                   1455: This provides a "changable area" that can be modified on the fly via
                   1456: the Javascript code provided in C<change_content_javascript>. $name is
                   1457: the name you will use to reference the area later; do not repeat the
                   1458: same name on a given HTML page more then once. $origContent is what
                   1459: the area will originally contain, which can be left blank.
                   1460: 
                   1461: =cut
                   1462: 
                   1463: sub changable_area {
                   1464:     my ($name, $origContent) = @_;
                   1465: 
1.258     albertel 1466:     if ($env{'browser.type'} eq 'netscape' &&
                   1467: 	$env{'browser.version'} =~ /^4\./) {
1.256     matthew  1468: 	# If this is netscape 4, we need to use the Layer tag
                   1469: 	return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
                   1470:     } else {
                   1471: 	return "<span id='$name'>$origContent</span>";
                   1472:     }
                   1473: }
                   1474: 
                   1475: =pod
                   1476: 
1.648     raeburn  1477: =item * &viewport_geometry_js 
1.590     raeburn  1478: 
                   1479: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
                   1480: 
                   1481: =cut
                   1482: 
                   1483: 
                   1484: sub viewport_geometry_js { 
                   1485:     return <<"GEOMETRY";
                   1486: var Geometry = {};
                   1487: function init_geometry() {
                   1488:     if (Geometry.init) { return };
                   1489:     Geometry.init=1;
                   1490:     if (window.innerHeight) {
                   1491:         Geometry.getViewportHeight   = function() { return window.innerHeight; };
                   1492:         Geometry.getViewportWidth   = function() { return window.innerWidth; };
                   1493:         Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
                   1494:         Geometry.getVerticalScroll   = function() { return window.pageYOffset; };
                   1495:     }
                   1496:     else if (document.documentElement && document.documentElement.clientHeight) {
                   1497:         Geometry.getViewportHeight =
                   1498:             function() { return document.documentElement.clientHeight; };
                   1499:         Geometry.getViewportWidth =
                   1500:             function() { return document.documentElement.clientWidth; };
                   1501: 
                   1502:         Geometry.getHorizontalScroll =
                   1503:             function() { return document.documentElement.scrollLeft; };
                   1504:         Geometry.getVerticalScroll =
                   1505:             function() { return document.documentElement.scrollTop; };
                   1506:     }
                   1507:     else if (document.body.clientHeight) {
                   1508:         Geometry.getViewportHeight =
                   1509:             function() { return document.body.clientHeight; };
                   1510:         Geometry.getViewportWidth =
                   1511:             function() { return document.body.clientWidth; };
                   1512:         Geometry.getHorizontalScroll =
                   1513:             function() { return document.body.scrollLeft; };
                   1514:         Geometry.getVerticalScroll =
                   1515:             function() { return document.body.scrollTop; };
                   1516:     }
                   1517: }
                   1518: 
                   1519: GEOMETRY
                   1520: }
                   1521: 
                   1522: =pod
                   1523: 
1.648     raeburn  1524: =item * &viewport_size_js()
1.590     raeburn  1525: 
                   1526: 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. 
                   1527: 
                   1528: =cut
                   1529: 
                   1530: sub viewport_size_js {
                   1531:     my $geometry = &viewport_geometry_js();
                   1532:     return <<"DIMS";
                   1533: 
                   1534: $geometry
                   1535: 
                   1536: function getViewportDims(width,height) {
                   1537:     init_geometry();
                   1538:     width.value = Geometry.getViewportWidth();
                   1539:     height.value = Geometry.getViewportHeight();
                   1540:     return;
                   1541: }
                   1542: 
                   1543: DIMS
                   1544: }
                   1545: 
                   1546: =pod
                   1547: 
1.648     raeburn  1548: =item * &resize_textarea_js()
1.565     albertel 1549: 
                   1550: emits the needed javascript to resize a textarea to be as big as possible
                   1551: 
                   1552: creates a function resize_textrea that takes two IDs first should be
                   1553: the id of the element to resize, second should be the id of a div that
                   1554: surrounds everything that comes after the textarea, this routine needs
                   1555: to be attached to the <body> for the onload and onresize events.
                   1556: 
1.648     raeburn  1557: =back
1.565     albertel 1558: 
                   1559: =cut
                   1560: 
                   1561: sub resize_textarea_js {
1.590     raeburn  1562:     my $geometry = &viewport_geometry_js();
1.565     albertel 1563:     return <<"RESIZE";
                   1564:     <script type="text/javascript">
1.824     bisitz   1565: // <![CDATA[
1.590     raeburn  1566: $geometry
1.565     albertel 1567: 
1.588     albertel 1568: function getX(element) {
                   1569:     var x = 0;
                   1570:     while (element) {
                   1571: 	x += element.offsetLeft;
                   1572: 	element = element.offsetParent;
                   1573:     }
                   1574:     return x;
                   1575: }
                   1576: function getY(element) {
                   1577:     var y = 0;
                   1578:     while (element) {
                   1579: 	y += element.offsetTop;
                   1580: 	element = element.offsetParent;
                   1581:     }
                   1582:     return y;
                   1583: }
                   1584: 
                   1585: 
1.565     albertel 1586: function resize_textarea(textarea_id,bottom_id) {
                   1587:     init_geometry();
                   1588:     var textarea        = document.getElementById(textarea_id);
                   1589:     //alert(textarea);
                   1590: 
1.588     albertel 1591:     var textarea_top    = getY(textarea);
1.565     albertel 1592:     var textarea_height = textarea.offsetHeight;
                   1593:     var bottom          = document.getElementById(bottom_id);
1.588     albertel 1594:     var bottom_top      = getY(bottom);
1.565     albertel 1595:     var bottom_height   = bottom.offsetHeight;
                   1596:     var window_height   = Geometry.getViewportHeight();
1.588     albertel 1597:     var fudge           = 23;
1.565     albertel 1598:     var new_height      = window_height-fudge-textarea_top-bottom_height;
                   1599:     if (new_height < 300) {
                   1600: 	new_height = 300;
                   1601:     }
                   1602:     textarea.style.height=new_height+'px';
                   1603: }
1.824     bisitz   1604: // ]]>
1.565     albertel 1605: </script>
                   1606: RESIZE
                   1607: 
                   1608: }
                   1609: 
                   1610: =pod
                   1611: 
1.256     matthew  1612: =head1 Excel and CSV file utility routines
                   1613: 
                   1614: =over 4
                   1615: 
                   1616: =cut
                   1617: 
                   1618: ###############################################################
                   1619: ###############################################################
                   1620: 
                   1621: =pod
                   1622: 
1.648     raeburn  1623: =item * &csv_translate($text) 
1.37      matthew  1624: 
1.185     www      1625: Translate $text to allow it to be output as a 'comma separated values' 
1.37      matthew  1626: format.
                   1627: 
                   1628: =cut
                   1629: 
1.180     matthew  1630: ###############################################################
                   1631: ###############################################################
1.37      matthew  1632: sub csv_translate {
                   1633:     my $text = shift;
                   1634:     $text =~ s/\"/\"\"/g;
1.209     albertel 1635:     $text =~ s/\n/ /g;
1.37      matthew  1636:     return $text;
                   1637: }
1.180     matthew  1638: 
                   1639: ###############################################################
                   1640: ###############################################################
                   1641: 
                   1642: =pod
                   1643: 
1.648     raeburn  1644: =item * &define_excel_formats()
1.180     matthew  1645: 
                   1646: Define some commonly used Excel cell formats.
                   1647: 
                   1648: Currently supported formats:
                   1649: 
                   1650: =over 4
                   1651: 
                   1652: =item header
                   1653: 
                   1654: =item bold
                   1655: 
                   1656: =item h1
                   1657: 
                   1658: =item h2
                   1659: 
                   1660: =item h3
                   1661: 
1.256     matthew  1662: =item h4
                   1663: 
                   1664: =item i
                   1665: 
1.180     matthew  1666: =item date
                   1667: 
                   1668: =back
                   1669: 
                   1670: Inputs: $workbook
                   1671: 
                   1672: Returns: $format, a hash reference.
                   1673: 
                   1674: =cut
                   1675: 
                   1676: ###############################################################
                   1677: ###############################################################
                   1678: sub define_excel_formats {
                   1679:     my ($workbook) = @_;
                   1680:     my $format;
                   1681:     $format->{'header'} = $workbook->add_format(bold      => 1, 
                   1682:                                                 bottom    => 1,
                   1683:                                                 align     => 'center');
                   1684:     $format->{'bold'} = $workbook->add_format(bold=>1);
                   1685:     $format->{'h1'}   = $workbook->add_format(bold=>1, size=>18);
                   1686:     $format->{'h2'}   = $workbook->add_format(bold=>1, size=>16);
                   1687:     $format->{'h3'}   = $workbook->add_format(bold=>1, size=>14);
1.255     matthew  1688:     $format->{'h4'}   = $workbook->add_format(bold=>1, size=>12);
1.246     matthew  1689:     $format->{'i'}    = $workbook->add_format(italic=>1);
1.180     matthew  1690:     $format->{'date'} = $workbook->add_format(num_format=>
1.207     matthew  1691:                                             'mm/dd/yyyy hh:mm:ss');
1.180     matthew  1692:     return $format;
                   1693: }
                   1694: 
                   1695: ###############################################################
                   1696: ###############################################################
1.113     bowersj2 1697: 
                   1698: =pod
                   1699: 
1.648     raeburn  1700: =item * &create_workbook()
1.255     matthew  1701: 
                   1702: Create an Excel worksheet.  If it fails, output message on the
                   1703: request object and return undefs.
                   1704: 
                   1705: Inputs: Apache request object
                   1706: 
                   1707: Returns (undef) on failure, 
                   1708:     Excel worksheet object, scalar with filename, and formats 
                   1709:     from &Apache::loncommon::define_excel_formats on success
                   1710: 
                   1711: =cut
                   1712: 
                   1713: ###############################################################
                   1714: ###############################################################
                   1715: sub create_workbook {
                   1716:     my ($r) = @_;
                   1717:         #
                   1718:     # Create the excel spreadsheet
                   1719:     my $filename = '/prtspool/'.
1.258     albertel 1720:         $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255     matthew  1721:         time.'_'.rand(1000000000).'.xls';
                   1722:     my $workbook  = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
                   1723:     if (! defined($workbook)) {
                   1724:         $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928     bisitz   1725:         $r->print(
                   1726:             '<p class="LC_error">'
                   1727:            .&mt('Problems occurred in creating the new Excel file.')
                   1728:            .' '.&mt('This error has been logged.')
                   1729:            .' '.&mt('Please alert your LON-CAPA administrator.')
                   1730:            .'</p>'
                   1731:         );
1.255     matthew  1732:         return (undef);
                   1733:     }
                   1734:     #
                   1735:     $workbook->set_tempdir('/home/httpd/perl/tmp');
                   1736:     #
                   1737:     my $format = &Apache::loncommon::define_excel_formats($workbook);
                   1738:     return ($workbook,$filename,$format);
                   1739: }
                   1740: 
                   1741: ###############################################################
                   1742: ###############################################################
                   1743: 
                   1744: =pod
                   1745: 
1.648     raeburn  1746: =item * &create_text_file()
1.113     bowersj2 1747: 
1.542     raeburn  1748: Create a file to write to and eventually make available to the user.
1.256     matthew  1749: If file creation fails, outputs an error message on the request object and 
                   1750: return undefs.
1.113     bowersj2 1751: 
1.256     matthew  1752: Inputs: Apache request object, and file suffix
1.113     bowersj2 1753: 
1.256     matthew  1754: Returns (undef) on failure, 
                   1755:     Filehandle and filename on success.
1.113     bowersj2 1756: 
                   1757: =cut
                   1758: 
1.256     matthew  1759: ###############################################################
                   1760: ###############################################################
                   1761: sub create_text_file {
                   1762:     my ($r,$suffix) = @_;
                   1763:     if (! defined($suffix)) { $suffix = 'txt'; };
                   1764:     my $fh;
                   1765:     my $filename = '/prtspool/'.
1.258     albertel 1766:         $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256     matthew  1767:         time.'_'.rand(1000000000).'.'.$suffix;
                   1768:     $fh = Apache::File->new('>/home/httpd'.$filename);
                   1769:     if (! defined($fh)) {
                   1770:         $r->log_error("Couldn't open $filename for output $!");
1.928     bisitz   1771:         $r->print(
                   1772:             '<p class="LC_error">'
                   1773:            .&mt('Problems occurred in creating the output file.')
                   1774:            .' '.&mt('This error has been logged.')
                   1775:            .' '.&mt('Please alert your LON-CAPA administrator.')
                   1776:            .'</p>'
                   1777:         );
1.113     bowersj2 1778:     }
1.256     matthew  1779:     return ($fh,$filename)
1.113     bowersj2 1780: }
                   1781: 
                   1782: 
1.256     matthew  1783: =pod 
1.113     bowersj2 1784: 
                   1785: =back
                   1786: 
                   1787: =cut
1.37      matthew  1788: 
                   1789: ###############################################################
1.33      matthew  1790: ##        Home server <option> list generating code          ##
                   1791: ###############################################################
1.35      matthew  1792: 
1.169     www      1793: # ------------------------------------------
                   1794: 
                   1795: sub domain_select {
                   1796:     my ($name,$value,$multiple)=@_;
                   1797:     my %domains=map { 
1.514     albertel 1798: 	$_ => $_.' '. &Apache::lonnet::domain($_,'description') 
1.512     albertel 1799:     } &Apache::lonnet::all_domains();
1.169     www      1800:     if ($multiple) {
                   1801: 	$domains{''}=&mt('Any domain');
1.550     albertel 1802: 	$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287     albertel 1803: 	return &multiple_select_form($name,$value,4,\%domains);
1.169     www      1804:     } else {
1.550     albertel 1805: 	$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.948.2.7  raeburn  1806: 	return &select_form($name,$value,\%domains);
1.169     www      1807:     }
                   1808: }
                   1809: 
1.282     albertel 1810: #-------------------------------------------
                   1811: 
                   1812: =pod
                   1813: 
1.519     raeburn  1814: =head1 Routines for form select boxes
                   1815: 
                   1816: =over 4
                   1817: 
1.648     raeburn  1818: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282     albertel 1819: 
                   1820: Returns a string containing a <select> element int multiple mode
                   1821: 
                   1822: 
                   1823: Args:
                   1824:   $name - name of the <select> element
1.506     raeburn  1825:   $value - scalar or array ref of values that should already be selected
1.282     albertel 1826:   $size - number of rows long the select element is
1.283     albertel 1827:   $hash - the elements should be 'option' => 'shown text'
1.282     albertel 1828:           (shown text should already have been &mt())
1.506     raeburn  1829:   $order - (optional) array ref of the order to show the elements in
1.283     albertel 1830: 
1.282     albertel 1831: =cut
                   1832: 
                   1833: #-------------------------------------------
1.169     www      1834: sub multiple_select_form {
1.284     albertel 1835:     my ($name,$value,$size,$hash,$order)=@_;
1.169     www      1836:     my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
                   1837:     my $output='';
1.191     matthew  1838:     if (! defined($size)) {
                   1839:         $size = 4;
1.283     albertel 1840:         if (scalar(keys(%$hash))<4) {
                   1841:             $size = scalar(keys(%$hash));
1.191     matthew  1842:         }
                   1843:     }
1.734     bisitz   1844:     $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501     banghart 1845:     my @order;
1.506     raeburn  1846:     if (ref($order) eq 'ARRAY')  {
                   1847:         @order = @{$order};
                   1848:     } else {
                   1849:         @order = sort(keys(%$hash));
1.501     banghart 1850:     }
                   1851:     if (exists($$hash{'select_form_order'})) {
                   1852:         @order = @{$$hash{'select_form_order'}};
                   1853:     }
                   1854:         
1.284     albertel 1855:     foreach my $key (@order) {
1.356     albertel 1856:         $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284     albertel 1857:         $output.='selected="selected" ' if ($selected{$key});
                   1858:         $output.='>'.$hash->{$key}."</option>\n";
1.169     www      1859:     }
                   1860:     $output.="</select>\n";
                   1861:     return $output;
                   1862: }
                   1863: 
1.88      www      1864: #-------------------------------------------
                   1865: 
                   1866: =pod
                   1867: 
1.948.2.7  raeburn  1868: =item * &select_form($defdom,$name,$hashref,$onchange)
1.88      www      1869: 
                   1870: Returns a string containing a <select name='$name' size='1'> form to 
1.948.2.7  raeburn  1871: allow a user to select options from a ref to a hash containing:
                   1872: option_name => displayed text. An optional $onchange can include
                   1873: a javascript onchange item, e.g., onchange="this.form.submit();"
                   1874: 
1.88      www      1875: See lonrights.pm for an example invocation and use.
                   1876: 
                   1877: =cut
                   1878: 
                   1879: #-------------------------------------------
                   1880: sub select_form {
1.948.2.7  raeburn  1881:     my ($def,$name,$hashref,$onchange) = @_;
                   1882:     return unless (ref($hashref) eq 'HASH');
                   1883:     if ($onchange) {
                   1884:         $onchange = ' onchange="'.$onchange.'"';
                   1885:     }
                   1886:     my $selectform = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.128     albertel 1887:     my @keys;
1.948.2.7  raeburn  1888:     if (exists($hashref->{'select_form_order'})) {
                   1889:         @keys=@{$hashref->{'select_form_order'}};
1.128     albertel 1890:     } else {
1.948.2.7  raeburn  1891:         @keys=sort(keys(%{$hashref}));
1.128     albertel 1892:     }
1.356     albertel 1893:     foreach my $key (@keys) {
                   1894:         $selectform.=
                   1895: 	    '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
                   1896:             ($key eq $def ? 'selected="selected" ' : '').
1.948.2.7  raeburn  1897:                 ">".$hashref->{$key}."</option>\n";
1.88      www      1898:     }
                   1899:     $selectform.="</select>";
                   1900:     return $selectform;
                   1901: }
                   1902: 
1.475     www      1903: # For display filters
                   1904: 
                   1905: sub display_filter {
                   1906:     if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477     www      1907:     if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.714     bisitz   1908:     return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1.475     www      1909: 			       &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
                   1910: 							   (&mt('all'),10,20,50,100,1000,10000))).
1.714     bisitz   1911: 	   '</label></span> <span class="LC_nobreak">'.
1.475     www      1912:            &mt('Filter [_1]',
1.477     www      1913: 	   &select_form($env{'form.displayfilter'},
                   1914: 			'displayfilter',
1.948.2.7  raeburn  1915: 			{'currentfolder' => 'Current folder/page',
1.477     www      1916: 			 'containing' => 'Containing phrase',
1.948.2.7  raeburn  1917: 			 'none' => 'None'})).
1.714     bisitz   1918: 			 '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1.475     www      1919: }
                   1920: 
1.167     www      1921: sub gradeleveldescription {
                   1922:     my $gradelevel=shift;
                   1923:     my %gradelevels=(0 => 'Not specified',
                   1924: 		     1 => 'Grade 1',
                   1925: 		     2 => 'Grade 2',
                   1926: 		     3 => 'Grade 3',
                   1927: 		     4 => 'Grade 4',
                   1928: 		     5 => 'Grade 5',
                   1929: 		     6 => 'Grade 6',
                   1930: 		     7 => 'Grade 7',
                   1931: 		     8 => 'Grade 8',
                   1932: 		     9 => 'Grade 9',
                   1933: 		     10 => 'Grade 10',
                   1934: 		     11 => 'Grade 11',
                   1935: 		     12 => 'Grade 12',
                   1936: 		     13 => 'Grade 13',
                   1937: 		     14 => '100 Level',
                   1938: 		     15 => '200 Level',
                   1939: 		     16 => '300 Level',
                   1940: 		     17 => '400 Level',
                   1941: 		     18 => 'Graduate Level');
                   1942:     return &mt($gradelevels{$gradelevel});
                   1943: }
                   1944: 
1.163     www      1945: sub select_level_form {
                   1946:     my ($deflevel,$name)=@_;
                   1947:     unless ($deflevel) { $deflevel=0; }
1.167     www      1948:     my $selectform = "<select name=\"$name\" size=\"1\">\n";
                   1949:     for (my $i=0; $i<=18; $i++) {
                   1950:         $selectform.="<option value=\"$i\" ".
1.253     albertel 1951:             ($i==$deflevel ? 'selected="selected" ' : '').
1.167     www      1952:                 ">".&gradeleveldescription($i)."</option>\n";
                   1953:     }
                   1954:     $selectform.="</select>";
                   1955:     return $selectform;
1.163     www      1956: }
1.167     www      1957: 
1.35      matthew  1958: #-------------------------------------------
                   1959: 
1.45      matthew  1960: =pod
                   1961: 
1.910     raeburn  1962: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms)
1.35      matthew  1963: 
                   1964: Returns a string containing a <select name='$name' size='1'> form to 
                   1965: allow a user to select the domain to preform an operation in.  
                   1966: See loncreateuser.pm for an example invocation and use.
                   1967: 
1.90      www      1968: If the $includeempty flag is set, it also includes an empty choice ("no domain
                   1969: selected");
                   1970: 
1.743     raeburn  1971: If the $showdomdesc flag is set, the domain name is followed by the domain description.
                   1972: 
1.910     raeburn  1973: The optional $onchange argument specifies what should occur if the domain selector is changed, e.g., 'this.form.submit()' if the form is to be automatically submitted.
                   1974: 
                   1975: The optional $incdoms is a reference to an array of domains which will be the only available options. 
1.563     raeburn  1976: 
1.35      matthew  1977: =cut
                   1978: 
                   1979: #-------------------------------------------
1.34      matthew  1980: sub select_dom_form {
1.910     raeburn  1981:     my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms) = @_;
1.872     raeburn  1982:     if ($onchange) {
1.874     raeburn  1983:         $onchange = ' onchange="'.$onchange.'"';
1.743     raeburn  1984:     }
1.910     raeburn  1985:     my @domains;
                   1986:     if (ref($incdoms) eq 'ARRAY') {
                   1987:         @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
                   1988:     } else {
                   1989:         @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
                   1990:     }
1.90      www      1991:     if ($includeempty) { @domains=('',@domains); }
1.743     raeburn  1992:     my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356     albertel 1993:     foreach my $dom (@domains) {
                   1994:         $selectdomain.="<option value=\"$dom\" ".
1.563     raeburn  1995:             ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
                   1996:         if ($showdomdesc) {
                   1997:             if ($dom ne '') {
                   1998:                 my $domdesc = &Apache::lonnet::domain($dom,'description');
                   1999:                 if ($domdesc ne '') {
                   2000:                     $selectdomain .= ' ('.$domdesc.')';
                   2001:                 }
                   2002:             } 
                   2003:         }
                   2004:         $selectdomain .= "</option>\n";
1.34      matthew  2005:     }
                   2006:     $selectdomain.="</select>";
                   2007:     return $selectdomain;
                   2008: }
                   2009: 
1.35      matthew  2010: #-------------------------------------------
                   2011: 
1.45      matthew  2012: =pod
                   2013: 
1.648     raeburn  2014: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35      matthew  2015: 
1.586     raeburn  2016: input: 4 arguments (two required, two optional) - 
                   2017:     $domain - domain of new user
                   2018:     $name - name of form element
                   2019:     $default - Value of 'default' causes a default item to be first 
                   2020:                             option, and selected by default. 
                   2021:     $hide - Value of 'hide' causes hiding of the name of the server, 
                   2022:                             if 1 server found, or default, if 0 found.
1.594     raeburn  2023: output: returns 2 items: 
1.586     raeburn  2024: (a) form element which contains either:
                   2025:    (i) <select name="$name">
                   2026:         <option value="$hostid1">$hostid $servers{$hostid}</option>
                   2027:         <option value="$hostid2">$hostid $servers{$hostid}</option>       
                   2028:        </select>
                   2029:        form item if there are multiple library servers in $domain, or
                   2030:    (ii) an <input type="hidden" name="$name" value="$hostid" /> form item 
                   2031:        if there is only one library server in $domain.
                   2032: 
                   2033: (b) number of library servers found.
                   2034: 
                   2035: See loncreateuser.pm for example of use.
1.35      matthew  2036: 
                   2037: =cut
                   2038: 
                   2039: #-------------------------------------------
1.586     raeburn  2040: sub home_server_form_item {
                   2041:     my ($domain,$name,$default,$hide) = @_;
1.513     albertel 2042:     my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586     raeburn  2043:     my $result;
                   2044:     my $numlib = keys(%servers);
                   2045:     if ($numlib > 1) {
                   2046:         $result .= '<select name="'.$name.'" />'."\n";
                   2047:         if ($default) {
1.804     bisitz   2048:             $result .= '<option value="default" selected="selected">'.&mt('default').
1.586     raeburn  2049:                        '</option>'."\n";
                   2050:         }
                   2051:         foreach my $hostid (sort(keys(%servers))) {
                   2052:             $result.= '<option value="'.$hostid.'">'.
                   2053: 	              $hostid.' '.$servers{$hostid}."</option>\n";
                   2054:         }
                   2055:         $result .= '</select>'."\n";
                   2056:     } elsif ($numlib == 1) {
                   2057:         my $hostid;
                   2058:         foreach my $item (keys(%servers)) {
                   2059:             $hostid = $item;
                   2060:         }
                   2061:         $result .= '<input type="hidden" name="'.$name.'" value="'.
                   2062:                    $hostid.'" />';
                   2063:                    if (!$hide) {
                   2064:                        $result .= $hostid.' '.$servers{$hostid};
                   2065:                    }
                   2066:                    $result .= "\n";
                   2067:     } elsif ($default) {
                   2068:         $result .= '<input type="hidden" name="'.$name.
                   2069:                    '" value="default" />';
                   2070:                    if (!$hide) {
                   2071:                        $result .= &mt('default');
                   2072:                    }
                   2073:                    $result .= "\n";
1.33      matthew  2074:     }
1.586     raeburn  2075:     return ($result,$numlib);
1.33      matthew  2076: }
1.112     bowersj2 2077: 
                   2078: =pod
                   2079: 
1.534     albertel 2080: =back 
                   2081: 
1.112     bowersj2 2082: =cut
1.87      matthew  2083: 
                   2084: ###############################################################
1.112     bowersj2 2085: ##                  Decoding User Agent                      ##
1.87      matthew  2086: ###############################################################
                   2087: 
                   2088: =pod
                   2089: 
1.112     bowersj2 2090: =head1 Decoding the User Agent
                   2091: 
                   2092: =over 4
                   2093: 
                   2094: =item * &decode_user_agent()
1.87      matthew  2095: 
                   2096: Inputs: $r
                   2097: 
                   2098: Outputs:
                   2099: 
                   2100: =over 4
                   2101: 
1.112     bowersj2 2102: =item * $httpbrowser
1.87      matthew  2103: 
1.112     bowersj2 2104: =item * $clientbrowser
1.87      matthew  2105: 
1.112     bowersj2 2106: =item * $clientversion
1.87      matthew  2107: 
1.112     bowersj2 2108: =item * $clientmathml
1.87      matthew  2109: 
1.112     bowersj2 2110: =item * $clientunicode
1.87      matthew  2111: 
1.112     bowersj2 2112: =item * $clientos
1.87      matthew  2113: 
                   2114: =back
                   2115: 
1.157     matthew  2116: =back 
                   2117: 
1.87      matthew  2118: =cut
                   2119: 
                   2120: ###############################################################
                   2121: ###############################################################
                   2122: sub decode_user_agent {
1.247     albertel 2123:     my ($r)=@_;
1.87      matthew  2124:     my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
                   2125:     my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
                   2126:     my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247     albertel 2127:     if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87      matthew  2128:     my $clientbrowser='unknown';
                   2129:     my $clientversion='0';
                   2130:     my $clientmathml='';
                   2131:     my $clientunicode='0';
                   2132:     for (my $i=0;$i<=$#browsertype;$i++) {
                   2133:         my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
                   2134: 	if (($httpbrowser=~/$match/i)  && ($httpbrowser!~/$notmatch/i)) {
                   2135: 	    $clientbrowser=$bname;
                   2136:             $httpbrowser=~/$vreg/i;
                   2137: 	    $clientversion=$1;
                   2138:             $clientmathml=($clientversion>=$minv);
                   2139:             $clientunicode=($clientversion>=$univ);
                   2140: 	}
                   2141:     }
                   2142:     my $clientos='unknown';
                   2143:     if (($httpbrowser=~/linux/i) ||
                   2144:         ($httpbrowser=~/unix/i) ||
                   2145:         ($httpbrowser=~/ux/i) ||
                   2146:         ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
                   2147:     if (($httpbrowser=~/vax/i) ||
                   2148:         ($httpbrowser=~/vms/i)) { $clientos='vms'; }
                   2149:     if ($httpbrowser=~/next/i) { $clientos='next'; }
                   2150:     if (($httpbrowser=~/mac/i) ||
                   2151:         ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
                   2152:     if ($httpbrowser=~/win/i) { $clientos='win'; }
                   2153:     if ($httpbrowser=~/embed/i) { $clientos='pda'; }
                   2154:     return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
                   2155:             $clientunicode,$clientos,);
                   2156: }
                   2157: 
1.32      matthew  2158: ###############################################################
                   2159: ##    Authentication changing form generation subroutines    ##
                   2160: ###############################################################
                   2161: ##
                   2162: ## All of the authform_xxxxxxx subroutines take their inputs in a
                   2163: ## hash, and have reasonable default values.
                   2164: ##
                   2165: ##    formname = the name given in the <form> tag.
1.35      matthew  2166: #-------------------------------------------
                   2167: 
1.45      matthew  2168: =pod
                   2169: 
1.112     bowersj2 2170: =head1 Authentication Routines
                   2171: 
                   2172: =over 4
                   2173: 
1.648     raeburn  2174: =item * &authform_xxxxxx()
1.35      matthew  2175: 
                   2176: The authform_xxxxxx subroutines provide javascript and html forms which 
                   2177: handle some of the conveniences required for authentication forms.  
                   2178: This is not an optimal method, but it works.  
                   2179: 
                   2180: =over 4
                   2181: 
1.112     bowersj2 2182: =item * authform_header
1.35      matthew  2183: 
1.112     bowersj2 2184: =item * authform_authorwarning
1.35      matthew  2185: 
1.112     bowersj2 2186: =item * authform_nochange
1.35      matthew  2187: 
1.112     bowersj2 2188: =item * authform_kerberos
1.35      matthew  2189: 
1.112     bowersj2 2190: =item * authform_internal
1.35      matthew  2191: 
1.112     bowersj2 2192: =item * authform_filesystem
1.35      matthew  2193: 
                   2194: =back
                   2195: 
1.648     raeburn  2196: See loncreateuser.pm for invocation and use examples.
1.157     matthew  2197: 
1.35      matthew  2198: =cut
                   2199: 
                   2200: #-------------------------------------------
1.32      matthew  2201: sub authform_header{  
                   2202:     my %in = (
                   2203:         formname => 'cu',
1.80      albertel 2204:         kerb_def_dom => '',
1.32      matthew  2205:         @_,
                   2206:     );
                   2207:     $in{'formname'} = 'document.' . $in{'formname'};
                   2208:     my $result='';
1.80      albertel 2209: 
                   2210: #---------------------------------------------- Code for upper case translation
                   2211:     my $Javascript_toUpperCase;
                   2212:     unless ($in{kerb_def_dom}) {
                   2213:         $Javascript_toUpperCase =<<"END";
                   2214:         switch (choice) {
                   2215:            case 'krb': currentform.elements[choicearg].value =
                   2216:                currentform.elements[choicearg].value.toUpperCase();
                   2217:                break;
                   2218:            default:
                   2219:         }
                   2220: END
                   2221:     } else {
                   2222:         $Javascript_toUpperCase = "";
                   2223:     }
                   2224: 
1.165     raeburn  2225:     my $radioval = "'nochange'";
1.591     raeburn  2226:     if (defined($in{'curr_authtype'})) {
                   2227:         if ($in{'curr_authtype'} ne '') {
                   2228:             $radioval = "'".$in{'curr_authtype'}."arg'";
                   2229:         }
1.174     matthew  2230:     }
1.165     raeburn  2231:     my $argfield = 'null';
1.591     raeburn  2232:     if (defined($in{'mode'})) {
1.165     raeburn  2233:         if ($in{'mode'} eq 'modifycourse')  {
1.591     raeburn  2234:             if (defined($in{'curr_autharg'})) {
                   2235:                 if ($in{'curr_autharg'} ne '') {
1.165     raeburn  2236:                     $argfield = "'$in{'curr_autharg'}'";
                   2237:                 }
                   2238:             }
                   2239:         }
                   2240:     }
                   2241: 
1.32      matthew  2242:     $result.=<<"END";
                   2243: var current = new Object();
1.165     raeburn  2244: current.radiovalue = $radioval;
                   2245: current.argfield = $argfield;
1.32      matthew  2246: 
                   2247: function changed_radio(choice,currentform) {
                   2248:     var choicearg = choice + 'arg';
                   2249:     // If a radio button in changed, we need to change the argfield
                   2250:     if (current.radiovalue != choice) {
                   2251:         current.radiovalue = choice;
                   2252:         if (current.argfield != null) {
                   2253:             currentform.elements[current.argfield].value = '';
                   2254:         }
                   2255:         if (choice == 'nochange') {
                   2256:             current.argfield = null;
                   2257:         } else {
                   2258:             current.argfield = choicearg;
                   2259:             switch(choice) {
                   2260:                 case 'krb': 
                   2261:                     currentform.elements[current.argfield].value = 
                   2262:                         "$in{'kerb_def_dom'}";
                   2263:                 break;
                   2264:               default:
                   2265:                 break;
                   2266:             }
                   2267:         }
                   2268:     }
                   2269:     return;
                   2270: }
1.22      www      2271: 
1.32      matthew  2272: function changed_text(choice,currentform) {
                   2273:     var choicearg = choice + 'arg';
                   2274:     if (currentform.elements[choicearg].value !='') {
1.80      albertel 2275:         $Javascript_toUpperCase
1.32      matthew  2276:         // clear old field
                   2277:         if ((current.argfield != choicearg) && (current.argfield != null)) {
                   2278:             currentform.elements[current.argfield].value = '';
                   2279:         }
                   2280:         current.argfield = choicearg;
                   2281:     }
                   2282:     set_auth_radio_buttons(choice,currentform);
                   2283:     return;
1.20      www      2284: }
1.32      matthew  2285: 
                   2286: function set_auth_radio_buttons(newvalue,currentform) {
1.948.2.13! raeburn  2287:     var numauthchoices = currentform.login.length;
        !          2288:     if (typeof numauthchoices  == "undefined") {
        !          2289:         return;
        !          2290:     }
1.32      matthew  2291:     var i=0;
1.948.2.13! raeburn  2292:     while (i < numauthchoices) {) {
1.32      matthew  2293:         if (currentform.login[i].value == newvalue) { break; }
                   2294:         i++;
                   2295:     }
1.948.2.13! raeburn  2296:     if (i == numauthchoices) {
1.32      matthew  2297:         return;
                   2298:     }
                   2299:     current.radiovalue = newvalue;
                   2300:     currentform.login[i].checked = true;
                   2301:     return;
                   2302: }
                   2303: END
                   2304:     return $result;
                   2305: }
                   2306: 
                   2307: sub authform_authorwarning{
                   2308:     my $result='';
1.144     matthew  2309:     $result='<i>'.
                   2310:         &mt('As a general rule, only authors or co-authors should be '.
                   2311:             'filesystem authenticated '.
                   2312:             '(which allows access to the server filesystem).')."</i>\n";
1.32      matthew  2313:     return $result;
                   2314: }
                   2315: 
                   2316: sub authform_nochange{  
                   2317:     my %in = (
                   2318:               formname => 'document.cu',
                   2319:               kerb_def_dom => 'MSU.EDU',
                   2320:               @_,
                   2321:           );
1.586     raeburn  2322:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'}); 
                   2323:     my $result;
                   2324:     if (keys(%can_assign) == 0) {
                   2325:         $result = &mt('Under you current role you are not permitted to change login settings for this user');  
                   2326:     } else {
                   2327:         $result = '<label>'.&mt('[_1] Do not change login data',
                   2328:                   '<input type="radio" name="login" value="nochange" '.
                   2329:                   'checked="checked" onclick="'.
1.281     albertel 2330:             "javascript:changed_radio('nochange',$in{'formname'});".'" />').
                   2331: 	    '</label>';
1.586     raeburn  2332:     }
1.32      matthew  2333:     return $result;
                   2334: }
                   2335: 
1.591     raeburn  2336: sub authform_kerberos {
1.32      matthew  2337:     my %in = (
                   2338:               formname => 'document.cu',
                   2339:               kerb_def_dom => 'MSU.EDU',
1.80      albertel 2340:               kerb_def_auth => 'krb4',
1.32      matthew  2341:               @_,
                   2342:               );
1.586     raeburn  2343:     my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
                   2344:         $autharg,$jscall);
                   2345:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.80      albertel 2346:     if ($in{'kerb_def_auth'} eq 'krb5') {
1.772     bisitz   2347:        $check5 = ' checked="checked"';
1.80      albertel 2348:     } else {
1.772     bisitz   2349:        $check4 = ' checked="checked"';
1.80      albertel 2350:     }
1.165     raeburn  2351:     $krbarg = $in{'kerb_def_dom'};
1.591     raeburn  2352:     if (defined($in{'curr_authtype'})) {
                   2353:         if ($in{'curr_authtype'} eq 'krb') {
1.772     bisitz   2354:             $krbcheck = ' checked="checked"';
1.623     raeburn  2355:             if (defined($in{'mode'})) {
                   2356:                 if ($in{'mode'} eq 'modifyuser') {
                   2357:                     $krbcheck = '';
                   2358:                 }
                   2359:             }
1.591     raeburn  2360:             if (defined($in{'curr_kerb_ver'})) {
                   2361:                 if ($in{'curr_krb_ver'} eq '5') {
1.772     bisitz   2362:                     $check5 = ' checked="checked"';
1.591     raeburn  2363:                     $check4 = '';
                   2364:                 } else {
1.772     bisitz   2365:                     $check4 = ' checked="checked"';
1.591     raeburn  2366:                     $check5 = '';
                   2367:                 }
1.586     raeburn  2368:             }
1.591     raeburn  2369:             if (defined($in{'curr_autharg'})) {
1.165     raeburn  2370:                 $krbarg = $in{'curr_autharg'};
                   2371:             }
1.586     raeburn  2372:             if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591     raeburn  2373:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2374:                     $result = 
                   2375:     &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
                   2376:         $in{'curr_autharg'},$krbver);
                   2377:                 } else {
                   2378:                     $result =
                   2379:     &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
                   2380:                 }
                   2381:                 return $result; 
                   2382:             }
                   2383:         }
                   2384:     } else {
                   2385:         if ($authnum == 1) {
1.784     bisitz   2386:             $authtype = '<input type="hidden" name="login" value="krb" />';
1.165     raeburn  2387:         }
                   2388:     }
1.586     raeburn  2389:     if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
                   2390:         return;
1.587     raeburn  2391:     } elsif ($authtype eq '') {
1.591     raeburn  2392:         if (defined($in{'mode'})) {
1.587     raeburn  2393:             if ($in{'mode'} eq 'modifycourse') {
                   2394:                 if ($authnum == 1) {
1.784     bisitz   2395:                     $authtype = '<input type="hidden" name="login" value="krb" />';
1.587     raeburn  2396:                 }
                   2397:             }
                   2398:         }
1.586     raeburn  2399:     }
                   2400:     $jscall = "javascript:changed_radio('krb',$in{'formname'});";
                   2401:     if ($authtype eq '') {
                   2402:         $authtype = '<input type="radio" name="login" value="krb" '.
                   2403:                     'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
                   2404:                     $krbcheck.' />';
                   2405:     }
                   2406:     if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
                   2407:         ($can_assign{'krb4'} && !$can_assign{'krb5'} && 
                   2408:          $in{'curr_authtype'} eq 'krb5') ||
                   2409:         (!$can_assign{'krb4'} && $can_assign{'krb5'} && 
                   2410:          $in{'curr_authtype'} eq 'krb4')) {
                   2411:         $result .= &mt
1.144     matthew  2412:         ('[_1] Kerberos authenticated with domain [_2] '.
1.281     albertel 2413:          '[_3] Version 4 [_4] Version 5 [_5]',
1.586     raeburn  2414:          '<label>'.$authtype,
1.281     albertel 2415:          '</label><input type="text" size="10" name="krbarg" '.
1.165     raeburn  2416:              'value="'.$krbarg.'" '.
1.144     matthew  2417:              'onchange="'.$jscall.'" />',
1.281     albertel 2418:          '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
                   2419:          '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
                   2420: 	 '</label>');
1.586     raeburn  2421:     } elsif ($can_assign{'krb4'}) {
                   2422:         $result .= &mt
                   2423:         ('[_1] Kerberos authenticated with domain [_2] '.
                   2424:          '[_3] Version 4 [_4]',
                   2425:          '<label>'.$authtype,
                   2426:          '</label><input type="text" size="10" name="krbarg" '.
                   2427:              'value="'.$krbarg.'" '.
                   2428:              'onchange="'.$jscall.'" />',
                   2429:          '<label><input type="hidden" name="krbver" value="4" />',
                   2430:          '</label>');
                   2431:     } elsif ($can_assign{'krb5'}) {
                   2432:         $result .= &mt
                   2433:         ('[_1] Kerberos authenticated with domain [_2] '.
                   2434:          '[_3] Version 5 [_4]',
                   2435:          '<label>'.$authtype,
                   2436:          '</label><input type="text" size="10" name="krbarg" '.
                   2437:              'value="'.$krbarg.'" '.
                   2438:              'onchange="'.$jscall.'" />',
                   2439:          '<label><input type="hidden" name="krbver" value="5" />',
                   2440:          '</label>');
                   2441:     }
1.32      matthew  2442:     return $result;
                   2443: }
                   2444: 
                   2445: sub authform_internal{  
1.586     raeburn  2446:     my %in = (
1.32      matthew  2447:                 formname => 'document.cu',
                   2448:                 kerb_def_dom => 'MSU.EDU',
                   2449:                 @_,
                   2450:                 );
1.586     raeburn  2451:     my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
                   2452:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2453:     if (defined($in{'curr_authtype'})) {
                   2454:         if ($in{'curr_authtype'} eq 'int') {
1.586     raeburn  2455:             if ($can_assign{'int'}) {
1.772     bisitz   2456:                 $intcheck = 'checked="checked" ';
1.623     raeburn  2457:                 if (defined($in{'mode'})) {
                   2458:                     if ($in{'mode'} eq 'modifyuser') {
                   2459:                         $intcheck = '';
                   2460:                     }
                   2461:                 }
1.591     raeburn  2462:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2463:                     $intarg = $in{'curr_autharg'};
                   2464:                 }
                   2465:             } else {
                   2466:                 $result = &mt('Currently internally authenticated.');
                   2467:                 return $result;
1.165     raeburn  2468:             }
                   2469:         }
1.586     raeburn  2470:     } else {
                   2471:         if ($authnum == 1) {
1.784     bisitz   2472:             $authtype = '<input type="hidden" name="login" value="int" />';
1.586     raeburn  2473:         }
                   2474:     }
                   2475:     if (!$can_assign{'int'}) {
                   2476:         return;
1.587     raeburn  2477:     } elsif ($authtype eq '') {
1.591     raeburn  2478:         if (defined($in{'mode'})) {
1.587     raeburn  2479:             if ($in{'mode'} eq 'modifycourse') {
                   2480:                 if ($authnum == 1) {
1.784     bisitz   2481:                     $authtype = '<input type="hidden" name="login" value="int" />';
1.587     raeburn  2482:                 }
                   2483:             }
                   2484:         }
1.165     raeburn  2485:     }
1.586     raeburn  2486:     $jscall = "javascript:changed_radio('int',$in{'formname'});";
                   2487:     if ($authtype eq '') {
                   2488:         $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
                   2489:                     ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
                   2490:     }
1.605     bisitz   2491:     $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586     raeburn  2492:                $intarg.'" onchange="'.$jscall.'" />';
                   2493:     $result = &mt
1.144     matthew  2494:         ('[_1] Internally authenticated (with initial password [_2])',
1.586     raeburn  2495:          '<label>'.$authtype,'</label>'.$autharg);
1.824     bisitz   2496:     $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  2497:     return $result;
                   2498: }
                   2499: 
                   2500: sub authform_local{  
                   2501:     my %in = (
                   2502:               formname => 'document.cu',
                   2503:               kerb_def_dom => 'MSU.EDU',
                   2504:               @_,
                   2505:               );
1.586     raeburn  2506:     my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
                   2507:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2508:     if (defined($in{'curr_authtype'})) {
                   2509:         if ($in{'curr_authtype'} eq 'loc') {
1.586     raeburn  2510:             if ($can_assign{'loc'}) {
1.772     bisitz   2511:                 $loccheck = 'checked="checked" ';
1.623     raeburn  2512:                 if (defined($in{'mode'})) {
                   2513:                     if ($in{'mode'} eq 'modifyuser') {
                   2514:                         $loccheck = '';
                   2515:                     }
                   2516:                 }
1.591     raeburn  2517:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2518:                     $locarg = $in{'curr_autharg'};
                   2519:                 }
                   2520:             } else {
                   2521:                 $result = &mt('Currently using local (institutional) authentication.');
                   2522:                 return $result;
1.165     raeburn  2523:             }
                   2524:         }
1.586     raeburn  2525:     } else {
                   2526:         if ($authnum == 1) {
1.784     bisitz   2527:             $authtype = '<input type="hidden" name="login" value="loc" />';
1.586     raeburn  2528:         }
                   2529:     }
                   2530:     if (!$can_assign{'loc'}) {
                   2531:         return;
1.587     raeburn  2532:     } elsif ($authtype eq '') {
1.591     raeburn  2533:         if (defined($in{'mode'})) {
1.587     raeburn  2534:             if ($in{'mode'} eq 'modifycourse') {
                   2535:                 if ($authnum == 1) {
1.784     bisitz   2536:                     $authtype = '<input type="hidden" name="login" value="loc" />';
1.587     raeburn  2537:                 }
                   2538:             }
                   2539:         }
1.165     raeburn  2540:     }
1.586     raeburn  2541:     $jscall = "javascript:changed_radio('loc',$in{'formname'});";
                   2542:     if ($authtype eq '') {
                   2543:         $authtype = '<input type="radio" name="login" value="loc" '.
                   2544:                     $loccheck.' onchange="'.$jscall.'" onclick="'.
                   2545:                     $jscall.'" />';
                   2546:     }
                   2547:     $autharg = '<input type="text" size="10" name="locarg" value="'.
                   2548:                $locarg.'" onchange="'.$jscall.'" />';
                   2549:     $result = &mt('[_1] Local Authentication with argument [_2]',
                   2550:                   '<label>'.$authtype,'</label>'.$autharg);
1.32      matthew  2551:     return $result;
                   2552: }
                   2553: 
                   2554: sub authform_filesystem{  
                   2555:     my %in = (
                   2556:               formname => 'document.cu',
                   2557:               kerb_def_dom => 'MSU.EDU',
                   2558:               @_,
                   2559:               );
1.586     raeburn  2560:     my ($fsyscheck,$result,$authtype,$autharg,$jscall);
                   2561:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2562:     if (defined($in{'curr_authtype'})) {
                   2563:         if ($in{'curr_authtype'} eq 'fsys') {
1.586     raeburn  2564:             if ($can_assign{'fsys'}) {
1.772     bisitz   2565:                 $fsyscheck = 'checked="checked" ';
1.623     raeburn  2566:                 if (defined($in{'mode'})) {
                   2567:                     if ($in{'mode'} eq 'modifyuser') {
                   2568:                         $fsyscheck = '';
                   2569:                     }
                   2570:                 }
1.586     raeburn  2571:             } else {
                   2572:                 $result = &mt('Currently Filesystem Authenticated.');
                   2573:                 return $result;
                   2574:             }           
                   2575:         }
                   2576:     } else {
                   2577:         if ($authnum == 1) {
1.784     bisitz   2578:             $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586     raeburn  2579:         }
                   2580:     }
                   2581:     if (!$can_assign{'fsys'}) {
                   2582:         return;
1.587     raeburn  2583:     } elsif ($authtype eq '') {
1.591     raeburn  2584:         if (defined($in{'mode'})) {
1.587     raeburn  2585:             if ($in{'mode'} eq 'modifycourse') {
                   2586:                 if ($authnum == 1) {
1.784     bisitz   2587:                     $authtype = '<input type="hidden" name="login" value="fsys" />';
1.587     raeburn  2588:                 }
                   2589:             }
                   2590:         }
1.586     raeburn  2591:     }
                   2592:     $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
                   2593:     if ($authtype eq '') {
                   2594:         $authtype = '<input type="radio" name="login" value="fsys" '.
                   2595:                     $fsyscheck.' onchange="'.$jscall.'" onclick="'.
                   2596:                     $jscall.'" />';
                   2597:     }
                   2598:     $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
                   2599:                ' onchange="'.$jscall.'" />';
                   2600:     $result = &mt
1.144     matthew  2601:         ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281     albertel 2602:          '<label><input type="radio" name="login" value="fsys" '.
1.586     raeburn  2603:          $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605     bisitz   2604:          '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144     matthew  2605:                   'onchange="'.$jscall.'" />');
1.32      matthew  2606:     return $result;
                   2607: }
                   2608: 
1.586     raeburn  2609: sub get_assignable_auth {
                   2610:     my ($dom) = @_;
                   2611:     if ($dom eq '') {
                   2612:         $dom = $env{'request.role.domain'};
                   2613:     }
                   2614:     my %can_assign = (
                   2615:                           krb4 => 1,
                   2616:                           krb5 => 1,
                   2617:                           int  => 1,
                   2618:                           loc  => 1,
                   2619:                      );
                   2620:     my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
                   2621:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   2622:         if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
                   2623:             my $authhash = $domconfig{'usercreation'}{'authtypes'};
                   2624:             my $context;
                   2625:             if ($env{'request.role'} =~ /^au/) {
                   2626:                 $context = 'author';
                   2627:             } elsif ($env{'request.role'} =~ /^dc/) {
                   2628:                 $context = 'domain';
                   2629:             } elsif ($env{'request.course.id'}) {
                   2630:                 $context = 'course';
                   2631:             }
                   2632:             if ($context) {
                   2633:                 if (ref($authhash->{$context}) eq 'HASH') {
                   2634:                    %can_assign = %{$authhash->{$context}}; 
                   2635:                 }
                   2636:             }
                   2637:         }
                   2638:     }
                   2639:     my $authnum = 0;
                   2640:     foreach my $key (keys(%can_assign)) {
                   2641:         if ($can_assign{$key}) {
                   2642:             $authnum ++;
                   2643:         }
                   2644:     }
                   2645:     if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
                   2646:         $authnum --;
                   2647:     }
                   2648:     return ($authnum,%can_assign);
                   2649: }
                   2650: 
1.80      albertel 2651: ###############################################################
                   2652: ##    Get Kerberos Defaults for Domain                 ##
                   2653: ###############################################################
                   2654: ##
                   2655: ## Returns default kerberos version and an associated argument
                   2656: ## as listed in file domain.tab. If not listed, provides
                   2657: ## appropriate default domain and kerberos version.
                   2658: ##
                   2659: #-------------------------------------------
                   2660: 
                   2661: =pod
                   2662: 
1.648     raeburn  2663: =item * &get_kerberos_defaults()
1.80      albertel 2664: 
                   2665: get_kerberos_defaults($target_domain) returns the default kerberos
1.641     raeburn  2666: version and domain. If not found, it defaults to version 4 and the 
                   2667: domain of the server.
1.80      albertel 2668: 
1.648     raeburn  2669: =over 4
                   2670: 
1.80      albertel 2671: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
                   2672: 
1.648     raeburn  2673: =back
                   2674: 
                   2675: =back
                   2676: 
1.80      albertel 2677: =cut
                   2678: 
                   2679: #-------------------------------------------
                   2680: sub get_kerberos_defaults {
                   2681:     my $domain=shift;
1.641     raeburn  2682:     my ($krbdef,$krbdefdom);
                   2683:     my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
                   2684:     if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
                   2685:         $krbdef = $domdefaults{'auth_def'};
                   2686:         $krbdefdom = $domdefaults{'auth_arg_def'};
                   2687:     } else {
1.80      albertel 2688:         $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
                   2689:         my $krbdefdom=$1;
                   2690:         $krbdefdom=~tr/a-z/A-Z/;
                   2691:         $krbdef = "krb4";
                   2692:     }
                   2693:     return ($krbdef,$krbdefdom);
                   2694: }
1.112     bowersj2 2695: 
1.32      matthew  2696: 
1.46      matthew  2697: ###############################################################
                   2698: ##                Thesaurus Functions                        ##
                   2699: ###############################################################
1.20      www      2700: 
1.46      matthew  2701: =pod
1.20      www      2702: 
1.112     bowersj2 2703: =head1 Thesaurus Functions
                   2704: 
                   2705: =over 4
                   2706: 
1.648     raeburn  2707: =item * &initialize_keywords()
1.46      matthew  2708: 
                   2709: Initializes the package variable %Keywords if it is empty.  Uses the
                   2710: package variable $thesaurus_db_file.
                   2711: 
                   2712: =cut
                   2713: 
                   2714: ###################################################
                   2715: 
                   2716: sub initialize_keywords {
                   2717:     return 1 if (scalar keys(%Keywords));
                   2718:     # If we are here, %Keywords is empty, so fill it up
                   2719:     #   Make sure the file we need exists...
                   2720:     if (! -e $thesaurus_db_file) {
                   2721:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
                   2722:                                  " failed because it does not exist");
                   2723:         return 0;
                   2724:     }
                   2725:     #   Set up the hash as a database
                   2726:     my %thesaurus_db;
                   2727:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 2728:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  2729:         &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
                   2730:                                  $thesaurus_db_file);
                   2731:         return 0;
                   2732:     } 
                   2733:     #  Get the average number of appearances of a word.
                   2734:     my $avecount = $thesaurus_db{'average.count'};
                   2735:     #  Put keywords (those that appear > average) into %Keywords
                   2736:     while (my ($word,$data)=each (%thesaurus_db)) {
                   2737:         my ($count,undef) = split /:/,$data;
                   2738:         $Keywords{$word}++ if ($count > $avecount);
                   2739:     }
                   2740:     untie %thesaurus_db;
                   2741:     # Remove special values from %Keywords.
1.356     albertel 2742:     foreach my $value ('total.count','average.count') {
                   2743:         delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586     raeburn  2744:   }
1.46      matthew  2745:     return 1;
                   2746: }
                   2747: 
                   2748: ###################################################
                   2749: 
                   2750: =pod
                   2751: 
1.648     raeburn  2752: =item * &keyword($word)
1.46      matthew  2753: 
                   2754: Returns true if $word is a keyword.  A keyword is a word that appears more 
                   2755: than the average number of times in the thesaurus database.  Calls 
                   2756: &initialize_keywords
                   2757: 
                   2758: =cut
                   2759: 
                   2760: ###################################################
1.20      www      2761: 
                   2762: sub keyword {
1.46      matthew  2763:     return if (!&initialize_keywords());
                   2764:     my $word=lc(shift());
                   2765:     $word=~s/\W//g;
                   2766:     return exists($Keywords{$word});
1.20      www      2767: }
1.46      matthew  2768: 
                   2769: ###############################################################
                   2770: 
                   2771: =pod 
1.20      www      2772: 
1.648     raeburn  2773: =item * &get_related_words()
1.46      matthew  2774: 
1.160     matthew  2775: Look up a word in the thesaurus.  Takes a scalar argument and returns
1.46      matthew  2776: an array of words.  If the keyword is not in the thesaurus, an empty array
                   2777: will be returned.  The order of the words returned is determined by the
                   2778: database which holds them.
                   2779: 
                   2780: Uses global $thesaurus_db_file.
                   2781: 
                   2782: =cut
                   2783: 
                   2784: ###############################################################
                   2785: sub get_related_words {
                   2786:     my $keyword = shift;
                   2787:     my %thesaurus_db;
                   2788:     if (! -e $thesaurus_db_file) {
                   2789:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
                   2790:                                  "failed because the file does not exist");
                   2791:         return ();
                   2792:     }
                   2793:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 2794:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  2795:         return ();
                   2796:     } 
                   2797:     my @Words=();
1.429     www      2798:     my $count=0;
1.46      matthew  2799:     if (exists($thesaurus_db{$keyword})) {
1.356     albertel 2800: 	# The first element is the number of times
                   2801: 	# the word appears.  We do not need it now.
1.429     www      2802: 	my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
                   2803: 	my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
                   2804: 	my $threshold=$mostfrequentcount/10;
                   2805:         foreach my $possibleword (@RelatedWords) {
                   2806:             my ($word,$wordcount)=split(/\,/,$possibleword);
                   2807:             if ($wordcount>$threshold) {
                   2808: 		push(@Words,$word);
                   2809:                 $count++;
                   2810:                 if ($count>10) { last; }
                   2811: 	    }
1.20      www      2812:         }
                   2813:     }
1.46      matthew  2814:     untie %thesaurus_db;
                   2815:     return @Words;
1.14      harris41 2816: }
1.46      matthew  2817: 
1.112     bowersj2 2818: =pod
                   2819: 
                   2820: =back
                   2821: 
                   2822: =cut
1.61      www      2823: 
                   2824: # -------------------------------------------------------------- Plaintext name
1.81      albertel 2825: =pod
                   2826: 
1.112     bowersj2 2827: =head1 User Name Functions
                   2828: 
                   2829: =over 4
                   2830: 
1.648     raeburn  2831: =item * &plainname($uname,$udom,$first)
1.81      albertel 2832: 
1.112     bowersj2 2833: Takes a users logon name and returns it as a string in
1.226     albertel 2834: "first middle last generation" form 
                   2835: if $first is set to 'lastname' then it returns it as
                   2836: 'lastname generation, firstname middlename' if their is a lastname
1.81      albertel 2837: 
                   2838: =cut
1.61      www      2839: 
1.295     www      2840: 
1.81      albertel 2841: ###############################################################
1.61      www      2842: sub plainname {
1.226     albertel 2843:     my ($uname,$udom,$first)=@_;
1.537     albertel 2844:     return if (!defined($uname) || !defined($udom));
1.295     www      2845:     my %names=&getnames($uname,$udom);
1.226     albertel 2846:     my $name=&Apache::lonnet::format_name($names{'firstname'},
                   2847: 					  $names{'middlename'},
                   2848: 					  $names{'lastname'},
                   2849: 					  $names{'generation'},$first);
                   2850:     $name=~s/^\s+//;
1.62      www      2851:     $name=~s/\s+$//;
                   2852:     $name=~s/\s+/ /g;
1.353     albertel 2853:     if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62      www      2854:     return $name;
1.61      www      2855: }
1.66      www      2856: 
                   2857: # -------------------------------------------------------------------- Nickname
1.81      albertel 2858: =pod
                   2859: 
1.648     raeburn  2860: =item * &nickname($uname,$udom)
1.81      albertel 2861: 
                   2862: Gets a users name and returns it as a string as
                   2863: 
                   2864: "&quot;nickname&quot;"
1.66      www      2865: 
1.81      albertel 2866: if the user has a nickname or
                   2867: 
                   2868: "first middle last generation"
                   2869: 
                   2870: if the user does not
                   2871: 
                   2872: =cut
1.66      www      2873: 
                   2874: sub nickname {
                   2875:     my ($uname,$udom)=@_;
1.537     albertel 2876:     return if (!defined($uname) || !defined($udom));
1.295     www      2877:     my %names=&getnames($uname,$udom);
1.68      albertel 2878:     my $name=$names{'nickname'};
1.66      www      2879:     if ($name) {
                   2880:        $name='&quot;'.$name.'&quot;'; 
                   2881:     } else {
                   2882:        $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
                   2883: 	     $names{'lastname'}.' '.$names{'generation'};
                   2884:        $name=~s/\s+$//;
                   2885:        $name=~s/\s+/ /g;
                   2886:     }
                   2887:     return $name;
                   2888: }
                   2889: 
1.295     www      2890: sub getnames {
                   2891:     my ($uname,$udom)=@_;
1.537     albertel 2892:     return if (!defined($uname) || !defined($udom));
1.433     albertel 2893:     if ($udom eq 'public' && $uname eq 'public') {
                   2894: 	return ('lastname' => &mt('Public'));
                   2895:     }
1.295     www      2896:     my $id=$uname.':'.$udom;
                   2897:     my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
                   2898:     if ($cached) {
                   2899: 	return %{$names};
                   2900:     } else {
                   2901: 	my %loadnames=&Apache::lonnet::get('environment',
                   2902:                     ['firstname','middlename','lastname','generation','nickname'],
                   2903: 					 $udom,$uname);
                   2904: 	&Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
                   2905: 	return %loadnames;
                   2906:     }
                   2907: }
1.61      www      2908: 
1.542     raeburn  2909: # -------------------------------------------------------------------- getemails
1.648     raeburn  2910: 
1.542     raeburn  2911: =pod
                   2912: 
1.648     raeburn  2913: =item * &getemails($uname,$udom)
1.542     raeburn  2914: 
                   2915: Gets a user's email information and returns it as a hash with keys:
                   2916: notification, critnotification, permanentemail
                   2917: 
                   2918: For notification and critnotification, values are comma-separated lists 
1.648     raeburn  2919: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542     raeburn  2920:  
1.648     raeburn  2921: 
1.542     raeburn  2922: =cut
                   2923: 
1.648     raeburn  2924: 
1.466     albertel 2925: sub getemails {
                   2926:     my ($uname,$udom)=@_;
                   2927:     if ($udom eq 'public' && $uname eq 'public') {
                   2928: 	return;
                   2929:     }
1.467     www      2930:     if (!$udom) { $udom=$env{'user.domain'}; }
                   2931:     if (!$uname) { $uname=$env{'user.name'}; }
1.466     albertel 2932:     my $id=$uname.':'.$udom;
                   2933:     my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
                   2934:     if ($cached) {
                   2935: 	return %{$names};
                   2936:     } else {
                   2937: 	my %loadnames=&Apache::lonnet::get('environment',
                   2938:                     			   ['notification','critnotification',
                   2939: 					    'permanentemail'],
                   2940: 					   $udom,$uname);
                   2941: 	&Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
                   2942: 	return %loadnames;
                   2943:     }
                   2944: }
                   2945: 
1.551     albertel 2946: sub flush_email_cache {
                   2947:     my ($uname,$udom)=@_;
                   2948:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2949:     if (!$uname) { $uname=$env{'user.name'};   }
                   2950:     return if ($udom eq 'public' && $uname eq 'public');
                   2951:     my $id=$uname.':'.$udom;
                   2952:     &Apache::lonnet::devalidate_cache_new('emailscache',$id);
                   2953: }
                   2954: 
1.728     raeburn  2955: # -------------------------------------------------------------------- getlangs
                   2956: 
                   2957: =pod
                   2958: 
                   2959: =item * &getlangs($uname,$udom)
                   2960: 
                   2961: Gets a user's language preference and returns it as a hash with key:
                   2962: language.
                   2963: 
                   2964: =cut
                   2965: 
                   2966: 
                   2967: sub getlangs {
                   2968:     my ($uname,$udom) = @_;
                   2969:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2970:     if (!$uname) { $uname=$env{'user.name'};   }
                   2971:     my $id=$uname.':'.$udom;
                   2972:     my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
                   2973:     if ($cached) {
                   2974:         return %{$langs};
                   2975:     } else {
                   2976:         my %loadlangs=&Apache::lonnet::get('environment',['languages'],
                   2977:                                            $udom,$uname);
                   2978:         &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
                   2979:         return %loadlangs;
                   2980:     }
                   2981: }
                   2982: 
                   2983: sub flush_langs_cache {
                   2984:     my ($uname,$udom)=@_;
                   2985:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2986:     if (!$uname) { $uname=$env{'user.name'};   }
                   2987:     return if ($udom eq 'public' && $uname eq 'public');
                   2988:     my $id=$uname.':'.$udom;
                   2989:     &Apache::lonnet::devalidate_cache_new('userlangs',$id);
                   2990: }
                   2991: 
1.61      www      2992: # ------------------------------------------------------------------ Screenname
1.81      albertel 2993: 
                   2994: =pod
                   2995: 
1.648     raeburn  2996: =item * &screenname($uname,$udom)
1.81      albertel 2997: 
                   2998: Gets a users screenname and returns it as a string
                   2999: 
                   3000: =cut
1.61      www      3001: 
                   3002: sub screenname {
                   3003:     my ($uname,$udom)=@_;
1.258     albertel 3004:     if ($uname eq $env{'user.name'} &&
                   3005: 	$udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212     albertel 3006:     my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68      albertel 3007:     return $names{'screenname'};
1.62      www      3008: }
                   3009: 
1.212     albertel 3010: 
1.802     bisitz   3011: # ------------------------------------------------------------- Confirm Wrapper
                   3012: =pod
                   3013: 
                   3014: =item confirmwrapper
                   3015: 
                   3016: Wrap messages about completion of operation in box
                   3017: 
                   3018: =cut
                   3019: 
                   3020: sub confirmwrapper {
                   3021:     my ($message)=@_;
                   3022:     if ($message) {
                   3023:         return "\n".'<div class="LC_confirm_box">'."\n"
                   3024:                .$message."\n"
                   3025:                .'</div>'."\n";
                   3026:     } else {
                   3027:         return $message;
                   3028:     }
                   3029: }
                   3030: 
1.62      www      3031: # ------------------------------------------------------------- Message Wrapper
                   3032: 
                   3033: sub messagewrapper {
1.369     www      3034:     my ($link,$username,$domain,$subject,$text)=@_;
1.62      www      3035:     return 
1.441     albertel 3036:         '<a href="/adm/email?compose=individual&amp;'.
                   3037:         'recname='.$username.'&amp;recdom='.$domain.
                   3038: 	'&amp;subject='.&escape($subject).'&amp;text='.&escape($text).'" '.
1.200     matthew  3039:         'title="'.&mt('Send message').'">'.$link.'</a>';
1.74      www      3040: }
1.802     bisitz   3041: 
1.74      www      3042: # --------------------------------------------------------------- Notes Wrapper
                   3043: 
                   3044: sub noteswrapper {
                   3045:     my ($link,$un,$do)=@_;
                   3046:     return 
1.896     amueller 3047: "<a href='/adm/email?recordftf=retrieve&amp;recname=$un&amp;recdom=$do'>$link</a>";
1.62      www      3048: }
1.802     bisitz   3049: 
1.62      www      3050: # ------------------------------------------------------------- Aboutme Wrapper
                   3051: 
                   3052: sub aboutmewrapper {
1.166     www      3053:     my ($link,$username,$domain,$target)=@_;
1.447     raeburn  3054:     if (!defined($username)  && !defined($domain)) {
                   3055:         return;
                   3056:     }
1.892     amueller 3057:     return '<a href="/adm/'.$domain.'/'.$username.'/aboutme?forcestudent=1"'.
1.756     weissno  3058: 	($target?' target="$target"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62      www      3059: }
                   3060: 
                   3061: # ------------------------------------------------------------ Syllabus Wrapper
                   3062: 
                   3063: sub syllabuswrapper {
1.707     bisitz   3064:     my ($linktext,$coursedir,$domain)=@_;
1.208     matthew  3065:     return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61      www      3066: }
1.14      harris41 3067: 
1.802     bisitz   3068: # -----------------------------------------------------------------------------
                   3069: 
1.208     matthew  3070: sub track_student_link {
1.887     raeburn  3071:     my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268     albertel 3072:     my $link ="/adm/trackstudent?";
1.208     matthew  3073:     my $title = 'View recent activity';
                   3074:     if (defined($sname) && $sname !~ /^\s*$/ &&
                   3075:         defined($sdom)  && $sdom  !~ /^\s*$/) {
1.268     albertel 3076:         $link .= "selected_student=$sname:$sdom";
1.208     matthew  3077:         $title .= ' of this student';
1.268     albertel 3078:     } 
1.208     matthew  3079:     if (defined($target) && $target !~ /^\s*$/) {
                   3080:         $target = qq{target="$target"};
                   3081:     } else {
                   3082:         $target = '';
                   3083:     }
1.268     albertel 3084:     if ($start) { $link.='&amp;start='.$start; }
1.887     raeburn  3085:     if ($only_body) { $link .= '&amp;only_body=1'; }
1.554     albertel 3086:     $title = &mt($title);
                   3087:     $linktext = &mt($linktext);
1.448     albertel 3088:     return qq{<a href="$link" title="$title" $target>$linktext</a>}.
                   3089: 	&help_open_topic('View_recent_activity');
1.208     matthew  3090: }
                   3091: 
1.781     raeburn  3092: sub slot_reservations_link {
                   3093:     my ($linktext,$sname,$sdom,$target) = @_;
                   3094:     my $link ="/adm/slotrequest?command=showresv&amp;origin=aboutme";
                   3095:     my $title = 'View slot reservation history';
                   3096:     if (defined($sname) && $sname !~ /^\s*$/ &&
                   3097:         defined($sdom)  && $sdom  !~ /^\s*$/) {
                   3098:         $link .= "&amp;uname=$sname&amp;udom=$sdom";
                   3099:         $title .= ' of this student';
                   3100:     }
                   3101:     if (defined($target) && $target !~ /^\s*$/) {
                   3102:         $target = qq{target="$target"};
                   3103:     } else {
                   3104:         $target = '';
                   3105:     }
                   3106:     $title = &mt($title);
                   3107:     $linktext = &mt($linktext);
                   3108:     return qq{<a href="$link" title="$title" $target>$linktext</a>};
                   3109: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
                   3110: 
                   3111: }
                   3112: 
1.508     www      3113: # ===================================================== Display a student photo
                   3114: 
                   3115: 
1.509     albertel 3116: sub student_image_tag {
1.508     www      3117:     my ($domain,$user)=@_;
                   3118:     my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
                   3119:     if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
                   3120: 	return '<img src="'.$imgsrc.'" align="right" />';
                   3121:     } else {
                   3122: 	return '';
                   3123:     }
                   3124: }
                   3125: 
1.112     bowersj2 3126: =pod
                   3127: 
                   3128: =back
                   3129: 
                   3130: =head1 Access .tab File Data
                   3131: 
                   3132: =over 4
                   3133: 
1.648     raeburn  3134: =item * &languageids() 
1.112     bowersj2 3135: 
                   3136: returns list of all language ids
                   3137: 
                   3138: =cut
                   3139: 
1.14      harris41 3140: sub languageids {
1.16      harris41 3141:     return sort(keys(%language));
1.14      harris41 3142: }
                   3143: 
1.112     bowersj2 3144: =pod
                   3145: 
1.648     raeburn  3146: =item * &languagedescription() 
1.112     bowersj2 3147: 
                   3148: returns description of a specified language id
                   3149: 
                   3150: =cut
                   3151: 
1.14      harris41 3152: sub languagedescription {
1.125     www      3153:     my $code=shift;
                   3154:     return  ($supported_language{$code}?'* ':'').
                   3155:             $language{$code}.
1.126     www      3156: 	    ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145     www      3157: }
                   3158: 
                   3159: sub plainlanguagedescription {
                   3160:     my $code=shift;
                   3161:     return $language{$code};
                   3162: }
                   3163: 
                   3164: sub supportedlanguagecode {
                   3165:     my $code=shift;
                   3166:     return $supported_language{$code};
1.97      www      3167: }
                   3168: 
1.112     bowersj2 3169: =pod
                   3170: 
1.648     raeburn  3171: =item * &copyrightids() 
1.112     bowersj2 3172: 
                   3173: returns list of all copyrights
                   3174: 
                   3175: =cut
                   3176: 
                   3177: sub copyrightids {
                   3178:     return sort(keys(%cprtag));
                   3179: }
                   3180: 
                   3181: =pod
                   3182: 
1.648     raeburn  3183: =item * &copyrightdescription() 
1.112     bowersj2 3184: 
                   3185: returns description of a specified copyright id
                   3186: 
                   3187: =cut
                   3188: 
                   3189: sub copyrightdescription {
1.166     www      3190:     return &mt($cprtag{shift(@_)});
1.112     bowersj2 3191: }
1.197     matthew  3192: 
                   3193: =pod
                   3194: 
1.648     raeburn  3195: =item * &source_copyrightids() 
1.192     taceyjo1 3196: 
                   3197: returns list of all source copyrights
                   3198: 
                   3199: =cut
                   3200: 
                   3201: sub source_copyrightids {
                   3202:     return sort(keys(%scprtag));
                   3203: }
                   3204: 
                   3205: =pod
                   3206: 
1.648     raeburn  3207: =item * &source_copyrightdescription() 
1.192     taceyjo1 3208: 
                   3209: returns description of a specified source copyright id
                   3210: 
                   3211: =cut
                   3212: 
                   3213: sub source_copyrightdescription {
                   3214:     return &mt($scprtag{shift(@_)});
                   3215: }
1.112     bowersj2 3216: 
                   3217: =pod
                   3218: 
1.648     raeburn  3219: =item * &filecategories() 
1.112     bowersj2 3220: 
                   3221: returns list of all file categories
                   3222: 
                   3223: =cut
                   3224: 
                   3225: sub filecategories {
                   3226:     return sort(keys(%category_extensions));
                   3227: }
                   3228: 
                   3229: =pod
                   3230: 
1.648     raeburn  3231: =item * &filecategorytypes() 
1.112     bowersj2 3232: 
                   3233: returns list of file types belonging to a given file
                   3234: category
                   3235: 
                   3236: =cut
                   3237: 
                   3238: sub filecategorytypes {
1.356     albertel 3239:     my ($cat) = @_;
                   3240:     return @{$category_extensions{lc($cat)}};
1.112     bowersj2 3241: }
                   3242: 
                   3243: =pod
                   3244: 
1.648     raeburn  3245: =item * &fileembstyle() 
1.112     bowersj2 3246: 
                   3247: returns embedding style for a specified file type
                   3248: 
                   3249: =cut
                   3250: 
                   3251: sub fileembstyle {
                   3252:     return $fe{lc(shift(@_))};
1.169     www      3253: }
                   3254: 
1.351     www      3255: sub filemimetype {
                   3256:     return $fm{lc(shift(@_))};
                   3257: }
                   3258: 
1.169     www      3259: 
                   3260: sub filecategoryselect {
                   3261:     my ($name,$value)=@_;
1.189     matthew  3262:     return &select_form($value,$name,
1.169     www      3263: 			'' => &mt('Any category'),
1.948.2.7  raeburn  3264: 			{'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112     bowersj2 3265: }
                   3266: 
                   3267: =pod
                   3268: 
1.648     raeburn  3269: =item * &filedescription() 
1.112     bowersj2 3270: 
                   3271: returns description for a specified file type
                   3272: 
                   3273: =cut
                   3274: 
                   3275: sub filedescription {
1.188     matthew  3276:     my $file_description = $fd{lc(shift())};
                   3277:     $file_description =~ s:([\[\]]):~$1:g;
                   3278:     return &mt($file_description);
1.112     bowersj2 3279: }
                   3280: 
                   3281: =pod
                   3282: 
1.648     raeburn  3283: =item * &filedescriptionex() 
1.112     bowersj2 3284: 
                   3285: returns description for a specified file type with
                   3286: extra formatting
                   3287: 
                   3288: =cut
                   3289: 
                   3290: sub filedescriptionex {
                   3291:     my $ex=shift;
1.188     matthew  3292:     my $file_description = $fd{lc($ex)};
                   3293:     $file_description =~ s:([\[\]]):~$1:g;
                   3294:     return '.'.$ex.' '.&mt($file_description);
1.112     bowersj2 3295: }
                   3296: 
                   3297: # End of .tab access
                   3298: =pod
                   3299: 
                   3300: =back
                   3301: 
                   3302: =cut
                   3303: 
                   3304: # ------------------------------------------------------------------ File Types
                   3305: sub fileextensions {
                   3306:     return sort(keys(%fe));
                   3307: }
                   3308: 
1.97      www      3309: # ----------------------------------------------------------- Display Languages
                   3310: # returns a hash with all desired display languages
                   3311: #
                   3312: 
                   3313: sub display_languages {
                   3314:     my %languages=();
1.695     raeburn  3315:     foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356     albertel 3316: 	$languages{$lang}=1;
1.97      www      3317:     }
                   3318:     &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258     albertel 3319:     if ($env{'form.displaylanguage'}) {
1.356     albertel 3320: 	foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
                   3321: 	    $languages{$lang}=1;
1.97      www      3322:         }
                   3323:     }
                   3324:     return %languages;
1.14      harris41 3325: }
                   3326: 
1.582     albertel 3327: sub languages {
                   3328:     my ($possible_langs) = @_;
1.695     raeburn  3329:     my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582     albertel 3330:     if (!ref($possible_langs)) {
                   3331: 	if( wantarray ) {
                   3332: 	    return @preferred_langs;
                   3333: 	} else {
                   3334: 	    return $preferred_langs[0];
                   3335: 	}
                   3336:     }
                   3337:     my %possibilities = map { $_ => 1 } (@$possible_langs);
                   3338:     my @preferred_possibilities;
                   3339:     foreach my $preferred_lang (@preferred_langs) {
                   3340: 	if (exists($possibilities{$preferred_lang})) {
                   3341: 	    push(@preferred_possibilities, $preferred_lang);
                   3342: 	}
                   3343:     }
                   3344:     if( wantarray ) {
                   3345: 	return @preferred_possibilities;
                   3346:     }
                   3347:     return $preferred_possibilities[0];
                   3348: }
                   3349: 
1.742     raeburn  3350: sub user_lang {
                   3351:     my ($touname,$toudom,$fromcid) = @_;
                   3352:     my @userlangs;
                   3353:     if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
                   3354:         @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
                   3355:                     $env{'course.'.$fromcid.'.languages'}));
                   3356:     } else {
                   3357:         my %langhash = &getlangs($touname,$toudom);
                   3358:         if ($langhash{'languages'} ne '') {
                   3359:             @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
                   3360:         } else {
                   3361:             my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
                   3362:             if ($domdefs{'lang_def'} ne '') {
                   3363:                 @userlangs = ($domdefs{'lang_def'});
                   3364:             }
                   3365:         }
                   3366:     }
                   3367:     my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
                   3368:     my $user_lh = Apache::localize->get_handle(@languages);
                   3369:     return $user_lh;
                   3370: }
                   3371: 
                   3372: 
1.112     bowersj2 3373: ###############################################################
                   3374: ##               Student Answer Attempts                     ##
                   3375: ###############################################################
                   3376: 
                   3377: =pod
                   3378: 
                   3379: =head1 Alternate Problem Views
                   3380: 
                   3381: =over 4
                   3382: 
1.648     raeburn  3383: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112     bowersj2 3384:     $getattempt, $regexp, $gradesub)
                   3385: 
                   3386: Return string with previous attempt on problem. Arguments:
                   3387: 
                   3388: =over 4
                   3389: 
                   3390: =item * $symb: Problem, including path
                   3391: 
                   3392: =item * $username: username of the desired student
                   3393: 
                   3394: =item * $domain: domain of the desired student
1.14      harris41 3395: 
1.112     bowersj2 3396: =item * $course: Course ID
1.14      harris41 3397: 
1.112     bowersj2 3398: =item * $getattempt: Leave blank for all attempts, otherwise put
                   3399:     something
1.14      harris41 3400: 
1.112     bowersj2 3401: =item * $regexp: if string matches this regexp, the string will be
                   3402:     sent to $gradesub
1.14      harris41 3403: 
1.112     bowersj2 3404: =item * $gradesub: routine that processes the string if it matches $regexp
1.14      harris41 3405: 
1.112     bowersj2 3406: =back
1.14      harris41 3407: 
1.112     bowersj2 3408: The output string is a table containing all desired attempts, if any.
1.16      harris41 3409: 
1.112     bowersj2 3410: =cut
1.1       albertel 3411: 
                   3412: sub get_previous_attempt {
1.43      ng       3413:   my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1       albertel 3414:   my $prevattempts='';
1.43      ng       3415:   no strict 'refs';
1.1       albertel 3416:   if ($symb) {
1.3       albertel 3417:     my (%returnhash)=
                   3418:       &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1       albertel 3419:     if ($returnhash{'version'}) {
                   3420:       my %lasthash=();
                   3421:       my $version;
                   3422:       for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356     albertel 3423:         foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
                   3424: 	  $lasthash{$key}=$returnhash{$version.':'.$key};
1.19      harris41 3425:         }
1.1       albertel 3426:       }
1.596     albertel 3427:       $prevattempts=&start_data_table().&start_data_table_header_row();
                   3428:       $prevattempts.='<th>'.&mt('History').'</th>';
1.948.2.8  raeburn  3429:       my (%typeparts,%lasthidden);
1.945     raeburn  3430:       my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356     albertel 3431:       foreach my $key (sort(keys(%lasthash))) {
                   3432: 	my ($ign,@parts) = split(/\./,$key);
1.41      ng       3433: 	if ($#parts > 0) {
1.31      albertel 3434: 	  my $data=$parts[-1];
                   3435: 	  pop(@parts);
1.945     raeburn  3436:           if ($data eq 'type') {
                   3437:               unless ($showsurv) {
                   3438:                   my $id = join(',',@parts);
                   3439:                   $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.948.2.8  raeburn  3440:                   if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
                   3441:                       $lasthidden{$ign.'.'.$id} = 1;
                   3442:                   }
1.945     raeburn  3443:               }
                   3444:               delete($lasthash{$key});
                   3445:           } else {
                   3446: 	      $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.'&nbsp;</th>';
                   3447:           }
1.31      albertel 3448: 	} else {
1.41      ng       3449: 	  if ($#parts == 0) {
                   3450: 	    $prevattempts.='<th>'.$parts[0].'</th>';
                   3451: 	  } else {
                   3452: 	    $prevattempts.='<th>'.$ign.'</th>';
                   3453: 	  }
1.31      albertel 3454: 	}
1.16      harris41 3455:       }
1.596     albertel 3456:       $prevattempts.=&end_data_table_header_row();
1.40      ng       3457:       if ($getattempt eq '') {
                   3458: 	for ($version=1;$version<=$returnhash{'version'};$version++) {
1.945     raeburn  3459:             my @hidden;
                   3460:             if (%typeparts) {
                   3461:                 foreach my $id (keys(%typeparts)) {
                   3462:                     if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') || ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
                   3463:                         push(@hidden,$id);
                   3464:                     }
                   3465:                 }
                   3466:             }
                   3467:             $prevattempts.=&start_data_table_row().
                   3468:                            '<td>'.&mt('Transaction [_1]',$version).'</td>';
                   3469:             if (@hidden) {
                   3470:                 foreach my $key (sort(keys(%lasthash))) {
                   3471:                     my $hide;
                   3472:                     foreach my $id (@hidden) {
                   3473:                         if ($key =~ /^\Q$id\E/) {
                   3474:                             $hide = 1;
                   3475:                             last;
                   3476:                         }
                   3477:                     }
                   3478:                     if ($hide) {
                   3479:                         my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
                   3480:                         if (($data eq 'award') || ($data eq 'awarddetail')) {
                   3481:                             my $value = &format_previous_attempt_value($key,
                   3482:                                              $returnhash{$version.':'.$key});
                   3483:                             $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3484:                         } else {
                   3485:                             $prevattempts.='<td>&nbsp;</td>';
                   3486:                         }
                   3487:                     } else {
                   3488:                         if ($key =~ /\./) {
                   3489:                             my $value = &format_previous_attempt_value($key,
                   3490:                                               $returnhash{$version.':'.$key});
                   3491:                             $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3492:                         } else {
                   3493:                             $prevattempts.='<td>&nbsp;</td>';
                   3494:                         }
                   3495:                     }
                   3496:                 }
                   3497:             } else {
                   3498: 	        foreach my $key (sort(keys(%lasthash))) {
                   3499: 		    my $value = &format_previous_attempt_value($key,
                   3500: 			            $returnhash{$version.':'.$key});
                   3501: 		    $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3502: 	        }
                   3503:             }
                   3504: 	    $prevattempts.=&end_data_table_row();
1.40      ng       3505: 	 }
1.1       albertel 3506:       }
1.945     raeburn  3507:       my @currhidden = keys(%lasthidden);
1.596     albertel 3508:       $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356     albertel 3509:       foreach my $key (sort(keys(%lasthash))) {
1.945     raeburn  3510:           if (%typeparts) {
                   3511:               my $hidden;
                   3512:               foreach my $id (@currhidden) {
                   3513:                   if ($key =~ /^\Q$id\E/) {
                   3514:                       $hidden = 1;
                   3515:                       last;
                   3516:                   }
                   3517:               }
                   3518:               if ($hidden) {
                   3519:                   my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
                   3520:                   if (($data eq 'award') || ($data eq 'awarddetail')) {
                   3521:                       my $value = &format_previous_attempt_value($key,$lasthash{$key});
                   3522:                       if ($key =~/$regexp$/ && (defined &$gradesub)) {
                   3523:                           $value = &$gradesub($value);
                   3524:                       }
                   3525:                       $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3526:                   } else {
                   3527:                       $prevattempts.='<td>&nbsp;</td>';
                   3528:                   }
                   3529:               } else {
                   3530:                   my $value = &format_previous_attempt_value($key,$lasthash{$key});
                   3531:                   if ($key =~/$regexp$/ && (defined &$gradesub)) {
                   3532:                       $value = &$gradesub($value);
                   3533:                   }
                   3534:                   $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3535:               }
                   3536:           } else {
                   3537: 	      my $value = &format_previous_attempt_value($key,$lasthash{$key});
                   3538: 	      if ($key =~/$regexp$/ && (defined &$gradesub)) {
                   3539:                   $value = &$gradesub($value);
                   3540:               }
                   3541: 	      $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3542:           }
1.16      harris41 3543:       }
1.596     albertel 3544:       $prevattempts.= &end_data_table_row().&end_data_table();
1.1       albertel 3545:     } else {
1.596     albertel 3546:       $prevattempts=
                   3547: 	  &start_data_table().&start_data_table_row().
                   3548: 	  '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
                   3549: 	  &end_data_table_row().&end_data_table();
1.1       albertel 3550:     }
                   3551:   } else {
1.596     albertel 3552:     $prevattempts=
                   3553: 	  &start_data_table().&start_data_table_row().
                   3554: 	  '<td>'.&mt('No data.').'</td>'.
                   3555: 	  &end_data_table_row().&end_data_table();
1.1       albertel 3556:   }
1.10      albertel 3557: }
                   3558: 
1.581     albertel 3559: sub format_previous_attempt_value {
                   3560:     my ($key,$value) = @_;
                   3561:     if ($key =~ /timestamp/) {
                   3562: 	$value = &Apache::lonlocal::locallocaltime($value);
                   3563:     } elsif (ref($value) eq 'ARRAY') {
                   3564: 	$value = '('.join(', ', @{ $value }).')';
                   3565:     } else {
                   3566: 	$value = &unescape($value);
                   3567:     }
                   3568:     return $value;
                   3569: }
                   3570: 
                   3571: 
1.107     albertel 3572: sub relative_to_absolute {
                   3573:     my ($url,$output)=@_;
                   3574:     my $parser=HTML::TokeParser->new(\$output);
                   3575:     my $token;
                   3576:     my $thisdir=$url;
                   3577:     my @rlinks=();
                   3578:     while ($token=$parser->get_token) {
                   3579: 	if ($token->[0] eq 'S') {
                   3580: 	    if ($token->[1] eq 'a') {
                   3581: 		if ($token->[2]->{'href'}) {
                   3582: 		    $rlinks[$#rlinks+1]=$token->[2]->{'href'};
                   3583: 		}
                   3584: 	    } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
                   3585: 		$rlinks[$#rlinks+1]=$token->[2]->{'src'};
                   3586: 	    } elsif ($token->[1] eq 'base') {
                   3587: 		$thisdir=$token->[2]->{'href'};
                   3588: 	    }
                   3589: 	}
                   3590:     }
                   3591:     $thisdir=~s-/[^/]*$--;
1.356     albertel 3592:     foreach my $link (@rlinks) {
1.726     raeburn  3593: 	unless (($link=~/^https?\:\/\//i) ||
1.356     albertel 3594: 		($link=~/^\//) ||
                   3595: 		($link=~/^javascript:/i) ||
                   3596: 		($link=~/^mailto:/i) ||
                   3597: 		($link=~/^\#/)) {
                   3598: 	    my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
                   3599: 	    $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107     albertel 3600: 	}
                   3601:     }
                   3602: # -------------------------------------------------- Deal with Applet codebases
                   3603:     $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
                   3604:     return $output;
                   3605: }
                   3606: 
1.112     bowersj2 3607: =pod
                   3608: 
1.648     raeburn  3609: =item * &get_student_view()
1.112     bowersj2 3610: 
                   3611: show a snapshot of what student was looking at
                   3612: 
                   3613: =cut
                   3614: 
1.10      albertel 3615: sub get_student_view {
1.186     albertel 3616:   my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114     www      3617:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 3618:   my (%form);
1.10      albertel 3619:   my @elements=('symb','courseid','domain','username');
                   3620:   foreach my $element (@elements) {
1.186     albertel 3621:       $form{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 3622:   }
1.186     albertel 3623:   if (defined($moreenv)) {
                   3624:       %form=(%form,%{$moreenv});
                   3625:   }
1.236     albertel 3626:   if (defined($target)) { $form{'grade_target'} = $target; }
1.107     albertel 3627:   $feedurl=&Apache::lonnet::clutter($feedurl);
1.650     www      3628:   my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11      albertel 3629:   $userview=~s/\<body[^\>]*\>//gi;
                   3630:   $userview=~s/\<\/body\>//gi;
                   3631:   $userview=~s/\<html\>//gi;
                   3632:   $userview=~s/\<\/html\>//gi;
                   3633:   $userview=~s/\<head\>//gi;
                   3634:   $userview=~s/\<\/head\>//gi;
                   3635:   $userview=~s/action\s*\=/would_be_action\=/gi;
1.107     albertel 3636:   $userview=&relative_to_absolute($feedurl,$userview);
1.650     www      3637:   if (wantarray) {
                   3638:      return ($userview,$response);
                   3639:   } else {
                   3640:      return $userview;
                   3641:   }
                   3642: }
                   3643: 
                   3644: sub get_student_view_with_retries {
                   3645:   my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
                   3646: 
                   3647:     my $ok = 0;                 # True if we got a good response.
                   3648:     my $content;
                   3649:     my $response;
                   3650: 
                   3651:     # Try to get the student_view done. within the retries count:
                   3652:     
                   3653:     do {
                   3654:          ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
                   3655:          $ok      = $response->is_success;
                   3656:          if (!$ok) {
                   3657:             &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
                   3658:          }
                   3659:          $retries--;
                   3660:     } while (!$ok && ($retries > 0));
                   3661:     
                   3662:     if (!$ok) {
                   3663:        $content = '';          # On error return an empty content.
                   3664:     }
1.651     www      3665:     if (wantarray) {
                   3666:        return ($content, $response);
                   3667:     } else {
                   3668:        return $content;
                   3669:     }
1.11      albertel 3670: }
                   3671: 
1.112     bowersj2 3672: =pod
                   3673: 
1.648     raeburn  3674: =item * &get_student_answers() 
1.112     bowersj2 3675: 
                   3676: show a snapshot of how student was answering problem
                   3677: 
                   3678: =cut
                   3679: 
1.11      albertel 3680: sub get_student_answers {
1.100     sakharuk 3681:   my ($symb,$username,$domain,$courseid,%form) = @_;
1.114     www      3682:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 3683:   my (%moreenv);
1.11      albertel 3684:   my @elements=('symb','courseid','domain','username');
                   3685:   foreach my $element (@elements) {
1.186     albertel 3686:     $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 3687:   }
1.186     albertel 3688:   $moreenv{'grade_target'}='answer';
                   3689:   %moreenv=(%form,%moreenv);
1.497     raeburn  3690:   $feedurl = &Apache::lonnet::clutter($feedurl);
                   3691:   my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10      albertel 3692:   return $userview;
1.1       albertel 3693: }
1.116     albertel 3694: 
                   3695: =pod
                   3696: 
                   3697: =item * &submlink()
                   3698: 
1.242     albertel 3699: Inputs: $text $uname $udom $symb $target
1.116     albertel 3700: 
                   3701: Returns: A link to grades.pm such as to see the SUBM view of a student
                   3702: 
                   3703: =cut
                   3704: 
                   3705: ###############################################
                   3706: sub submlink {
1.242     albertel 3707:     my ($text,$uname,$udom,$symb,$target)=@_;
1.116     albertel 3708:     if (!($uname && $udom)) {
                   3709: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 3710: 	    &Apache::lonnet::whichuser($symb);
1.116     albertel 3711: 	if (!$symb) { $symb=$cursymb; }
                   3712:     }
1.254     matthew  3713:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      3714:     $symb=&escape($symb);
1.948.2.4  raeburn  3715:     if ($target) { $target=" target=\"$target\""; }
                   3716:     return
                   3717:         '<a href="/adm/grades?command=submission'.
                   3718:         '&amp;symb='.$symb.
                   3719:         '&amp;student='.$uname.
                   3720:         '&amp;userdom='.$udom.'"'.
                   3721:         $target.'>'.$text.'</a>';
1.242     albertel 3722: }
                   3723: ##############################################
                   3724: 
                   3725: =pod
                   3726: 
                   3727: =item * &pgrdlink()
                   3728: 
                   3729: Inputs: $text $uname $udom $symb $target
                   3730: 
                   3731: Returns: A link to grades.pm such as to see the PGRD view of a student
                   3732: 
                   3733: =cut
                   3734: 
                   3735: ###############################################
                   3736: sub pgrdlink {
                   3737:     my $link=&submlink(@_);
                   3738:     $link=~s/(&command=submission)/$1&showgrading=yes/;
                   3739:     return $link;
                   3740: }
                   3741: ##############################################
                   3742: 
                   3743: =pod
                   3744: 
                   3745: =item * &pprmlink()
                   3746: 
                   3747: Inputs: $text $uname $udom $symb $target
                   3748: 
                   3749: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283     albertel 3750: student and a specific resource
1.242     albertel 3751: 
                   3752: =cut
                   3753: 
                   3754: ###############################################
                   3755: sub pprmlink {
                   3756:     my ($text,$uname,$udom,$symb,$target)=@_;
                   3757:     if (!($uname && $udom)) {
                   3758: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 3759: 	    &Apache::lonnet::whichuser($symb);
1.242     albertel 3760: 	if (!$symb) { $symb=$cursymb; }
                   3761:     }
1.254     matthew  3762:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      3763:     $symb=&escape($symb);
1.242     albertel 3764:     if ($target) { $target="target=\"$target\""; }
1.595     albertel 3765:     return '<a href="/adm/parmset?command=set&amp;'.
                   3766: 	'symb='.$symb.'&amp;uname='.$uname.
                   3767: 	'&amp;udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116     albertel 3768: }
                   3769: ##############################################
1.37      matthew  3770: 
1.112     bowersj2 3771: =pod
                   3772: 
                   3773: =back
                   3774: 
                   3775: =cut
                   3776: 
1.37      matthew  3777: ###############################################
1.51      www      3778: 
                   3779: 
                   3780: sub timehash {
1.687     raeburn  3781:     my ($thistime) = @_;
                   3782:     my $timezone = &Apache::lonlocal::gettimezone();
                   3783:     my $dt = DateTime->from_epoch(epoch => $thistime)
                   3784:                      ->set_time_zone($timezone);
                   3785:     my $wday = $dt->day_of_week();
                   3786:     if ($wday == 7) { $wday = 0; }
                   3787:     return ( 'second' => $dt->second(),
                   3788:              'minute' => $dt->minute(),
                   3789:              'hour'   => $dt->hour(),
                   3790:              'day'     => $dt->day_of_month(),
                   3791:              'month'   => $dt->month(),
                   3792:              'year'    => $dt->year(),
                   3793:              'weekday' => $wday,
                   3794:              'dayyear' => $dt->day_of_year(),
                   3795:              'dlsav'   => $dt->is_dst() );
1.51      www      3796: }
                   3797: 
1.370     www      3798: sub utc_string {
                   3799:     my ($date)=@_;
1.371     www      3800:     return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370     www      3801: }
                   3802: 
1.51      www      3803: sub maketime {
                   3804:     my %th=@_;
1.687     raeburn  3805:     my ($epoch_time,$timezone,$dt);
                   3806:     $timezone = &Apache::lonlocal::gettimezone();
                   3807:     eval {
                   3808:         $dt = DateTime->new( year   => $th{'year'},
                   3809:                              month  => $th{'month'},
                   3810:                              day    => $th{'day'},
                   3811:                              hour   => $th{'hour'},
                   3812:                              minute => $th{'minute'},
                   3813:                              second => $th{'second'},
                   3814:                              time_zone => $timezone,
                   3815:                          );
                   3816:     };
                   3817:     if (!$@) {
                   3818:         $epoch_time = $dt->epoch;
                   3819:         if ($epoch_time) {
                   3820:             return $epoch_time;
                   3821:         }
                   3822:     }
1.51      www      3823:     return POSIX::mktime(
                   3824:         ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210     www      3825:          $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70      www      3826: }
                   3827: 
                   3828: #########################################
1.51      www      3829: 
                   3830: sub findallcourses {
1.482     raeburn  3831:     my ($roles,$uname,$udom) = @_;
1.355     albertel 3832:     my %roles;
                   3833:     if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348     albertel 3834:     my %courses;
1.51      www      3835:     my $now=time;
1.482     raeburn  3836:     if (!defined($uname)) {
                   3837:         $uname = $env{'user.name'};
                   3838:     }
                   3839:     if (!defined($udom)) {
                   3840:         $udom = $env{'user.domain'};
                   3841:     }
                   3842:     if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.948.2.11  raeburn  3843:         my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});
                   3844:         my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname,'.',undef,
                   3845:                                               $extra);
1.482     raeburn  3846:         if (!%roles) {
                   3847:             %roles = (
                   3848:                        cc => 1,
1.907     raeburn  3849:                        co => 1,
1.482     raeburn  3850:                        in => 1,
                   3851:                        ep => 1,
                   3852:                        ta => 1,
                   3853:                        cr => 1,
                   3854:                        st => 1,
                   3855:              );
                   3856:         }
                   3857:         foreach my $entry (keys(%roleshash)) {
                   3858:             my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
                   3859:             if ($trole =~ /^cr/) { 
                   3860:                 next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
                   3861:             } else {
                   3862:                 next if (!exists($roles{$trole}));
                   3863:             }
                   3864:             if ($tend) {
                   3865:                 next if ($tend < $now);
                   3866:             }
                   3867:             if ($tstart) {
                   3868:                 next if ($tstart > $now);
                   3869:             }
                   3870:             my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
                   3871:             (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
                   3872:             if ($secpart eq '') {
                   3873:                 ($cnum,$role) = split(/_/,$cnumpart); 
                   3874:                 $sec = 'none';
                   3875:                 $realsec = '';
                   3876:             } else {
                   3877:                 $cnum = $cnumpart;
                   3878:                 ($sec,$role) = split(/_/,$secpart);
                   3879:                 $realsec = $sec;
1.490     raeburn  3880:             }
1.482     raeburn  3881:             $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
                   3882:         }
                   3883:     } else {
                   3884:         foreach my $key (keys(%env)) {
1.483     albertel 3885: 	    if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
                   3886:                  $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482     raeburn  3887: 	        my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
                   3888: 	        next if ($role eq 'ca' || $role eq 'aa');
                   3889: 	        next if (%roles && !exists($roles{$role}));
                   3890: 	        my ($starttime,$endtime)=split(/\./,$env{$key});
                   3891:                 my $active=1;
                   3892:                 if ($starttime) {
                   3893: 		    if ($now<$starttime) { $active=0; }
                   3894:                 }
                   3895:                 if ($endtime) {
                   3896:                     if ($now>$endtime) { $active=0; }
                   3897:                 }
                   3898:                 if ($active) {
                   3899:                     if ($sec eq '') {
                   3900:                         $sec = 'none';
                   3901:                     }
                   3902:                     $courses{$cdom.'_'.$cnum}{$sec} = 
                   3903:                                      $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474     raeburn  3904:                 }
                   3905:             }
1.51      www      3906:         }
                   3907:     }
1.474     raeburn  3908:     return %courses;
1.51      www      3909: }
1.37      matthew  3910: 
1.54      www      3911: ###############################################
1.474     raeburn  3912: 
                   3913: sub blockcheck {
1.482     raeburn  3914:     my ($setters,$activity,$uname,$udom) = @_;
1.490     raeburn  3915: 
                   3916:     if (!defined($udom)) {
                   3917:         $udom = $env{'user.domain'};
                   3918:     }
                   3919:     if (!defined($uname)) {
                   3920:         $uname = $env{'user.name'};
                   3921:     }
                   3922: 
                   3923:     # If uname and udom are for a course, check for blocks in the course.
                   3924: 
                   3925:     if (&Apache::lonnet::is_course($udom,$uname)) {
                   3926:         my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502     raeburn  3927:         my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490     raeburn  3928:         return ($startblock,$endblock);
                   3929:     }
1.474     raeburn  3930: 
1.502     raeburn  3931:     my $startblock = 0;
                   3932:     my $endblock = 0;
1.482     raeburn  3933:     my %live_courses = &findallcourses(undef,$uname,$udom);
1.474     raeburn  3934: 
1.490     raeburn  3935:     # If uname is for a user, and activity is course-specific, i.e.,
                   3936:     # boards, chat or groups, check for blocking in current course only.
1.474     raeburn  3937: 
1.490     raeburn  3938:     if (($activity eq 'boards' || $activity eq 'chat' ||
                   3939:          $activity eq 'groups') && ($env{'request.course.id'})) {
                   3940:         foreach my $key (keys(%live_courses)) {
                   3941:             if ($key ne $env{'request.course.id'}) {
                   3942:                 delete($live_courses{$key});
                   3943:             }
                   3944:         }
                   3945:     }
                   3946: 
                   3947:     my $otheruser = 0;
                   3948:     my %own_courses;
                   3949:     if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
                   3950:         # Resource belongs to user other than current user.
                   3951:         $otheruser = 1;
                   3952:         # Gather courses for current user
                   3953:         %own_courses = 
                   3954:             &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
                   3955:     }
                   3956: 
                   3957:     # Gather active course roles - course coordinator, instructor, 
                   3958:     # exam proctor, ta, student, or custom role.
1.474     raeburn  3959: 
                   3960:     foreach my $course (keys(%live_courses)) {
1.482     raeburn  3961:         my ($cdom,$cnum);
                   3962:         if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
                   3963:             $cdom = $env{'course.'.$course.'.domain'};
                   3964:             $cnum = $env{'course.'.$course.'.num'};
                   3965:         } else {
1.490     raeburn  3966:             ($cdom,$cnum) = split(/_/,$course); 
1.482     raeburn  3967:         }
                   3968:         my $no_ownblock = 0;
                   3969:         my $no_userblock = 0;
1.533     raeburn  3970:         if ($otheruser && $activity ne 'com') {
1.490     raeburn  3971:             # Check if current user has 'evb' priv for this
                   3972:             if (defined($own_courses{$course})) {
                   3973:                 foreach my $sec (keys(%{$own_courses{$course}})) {
                   3974:                     my $checkrole = 'cm./'.$cdom.'/'.$cnum;
                   3975:                     if ($sec ne 'none') {
                   3976:                         $checkrole .= '/'.$sec;
                   3977:                     }
                   3978:                     if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   3979:                         $no_ownblock = 1;
                   3980:                         last;
                   3981:                     }
                   3982:                 }
                   3983:             }
                   3984:             # if they have 'evb' priv and are currently not playing student
                   3985:             next if (($no_ownblock) &&
                   3986:                  ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
                   3987:         }
1.474     raeburn  3988:         foreach my $sec (keys(%{$live_courses{$course}})) {
1.482     raeburn  3989:             my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474     raeburn  3990:             if ($sec ne 'none') {
1.482     raeburn  3991:                 $checkrole .= '/'.$sec;
1.474     raeburn  3992:             }
1.490     raeburn  3993:             if ($otheruser) {
                   3994:                 # Resource belongs to user other than current user.
                   3995:                 # Assemble privs for that user, and check for 'evb' priv.
1.482     raeburn  3996:                 my ($trole,$tdom,$tnum,$tsec);
                   3997:                 my $entry = $live_courses{$course}{$sec};
                   3998:                 if ($entry =~ /^cr/) {
                   3999:                     ($trole,$tdom,$tnum,$tsec) = 
                   4000:                       ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
                   4001:                 } else {
                   4002:                     ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
                   4003:                 }
                   4004:                 my ($spec,$area,$trest,%allroles,%userroles);
                   4005:                 $area = '/'.$tdom.'/'.$tnum;
                   4006:                 $trest = $tnum;
                   4007:                 if ($tsec ne '') {
                   4008:                     $area .= '/'.$tsec;
                   4009:                     $trest .= '/'.$tsec;
                   4010:                 }
                   4011:                 $spec = $trole.'.'.$area;
                   4012:                 if ($trole =~ /^cr/) {
                   4013:                     &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
                   4014:                                                       $tdom,$spec,$trest,$area);
                   4015:                 } else {
                   4016:                     &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
                   4017:                                                        $tdom,$spec,$trest,$area);
                   4018:                 }
                   4019:                 my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486     raeburn  4020:                 if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
                   4021:                     if ($1) {
                   4022:                         $no_userblock = 1;
                   4023:                         last;
                   4024:                     }
                   4025:                 }
1.490     raeburn  4026:             } else {
                   4027:                 # Resource belongs to current user
                   4028:                 # Check for 'evb' priv via lonnet::allowed().
1.482     raeburn  4029:                 if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   4030:                     $no_ownblock = 1;
                   4031:                     last;
                   4032:                 }
1.474     raeburn  4033:             }
                   4034:         }
                   4035:         # if they have the evb priv and are currently not playing student
1.482     raeburn  4036:         next if (($no_ownblock) &&
1.491     albertel 4037:                  ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482     raeburn  4038:         next if ($no_userblock);
1.474     raeburn  4039: 
1.866     kalberla 4040:         # Retrieve blocking times and identity of locker for course
1.490     raeburn  4041:         # of specified user, unless user has 'evb' privilege.
1.502     raeburn  4042:         
                   4043:         my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
                   4044:         if (($start != 0) && 
                   4045:             (($startblock == 0) || ($startblock > $start))) {
                   4046:             $startblock = $start;
                   4047:         }
                   4048:         if (($end != 0)  &&
                   4049:             (($endblock == 0) || ($endblock < $end))) {
                   4050:             $endblock = $end;
                   4051:         }
1.490     raeburn  4052:     }
                   4053:     return ($startblock,$endblock);
                   4054: }
                   4055: 
                   4056: sub get_blocks {
                   4057:     my ($setters,$activity,$cdom,$cnum) = @_;
                   4058:     my $startblock = 0;
                   4059:     my $endblock = 0;
                   4060:     my $course = $cdom.'_'.$cnum;
                   4061:     $setters->{$course} = {};
                   4062:     $setters->{$course}{'staff'} = [];
                   4063:     $setters->{$course}{'times'} = [];
                   4064:     my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
                   4065:     foreach my $record (keys(%records)) {
                   4066:         my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
                   4067:         if ($start <= time && $end >= time) {
                   4068:             my ($staff_name,$staff_dom,$title,$blocks) =
                   4069:                 &parse_block_record($records{$record});
                   4070:             if ($blocks->{$activity} eq 'on') {
                   4071:                 push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
                   4072:                 push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491     albertel 4073:                 if ( ($startblock == 0) || ($startblock > $start) ) {
                   4074:                     $startblock = $start;
1.490     raeburn  4075:                 }
1.491     albertel 4076:                 if ( ($endblock == 0) || ($endblock < $end) ) {
                   4077:                     $endblock = $end;
1.474     raeburn  4078:                 }
                   4079:             }
                   4080:         }
                   4081:     }
                   4082:     return ($startblock,$endblock);
                   4083: }
                   4084: 
                   4085: sub parse_block_record {
                   4086:     my ($record) = @_;
                   4087:     my ($setuname,$setudom,$title,$blocks);
                   4088:     if (ref($record) eq 'HASH') {
                   4089:         ($setuname,$setudom) = split(/:/,$record->{'setter'});
                   4090:         $title = &unescape($record->{'event'});
                   4091:         $blocks = $record->{'blocks'};
                   4092:     } else {
                   4093:         my @data = split(/:/,$record,3);
                   4094:         if (scalar(@data) eq 2) {
                   4095:             $title = $data[1];
                   4096:             ($setuname,$setudom) = split(/@/,$data[0]);
                   4097:         } else {
                   4098:             ($setuname,$setudom,$title) = @data;
                   4099:         }
                   4100:         $blocks = { 'com' => 'on' };
                   4101:     }
                   4102:     return ($setuname,$setudom,$title,$blocks);
                   4103: }
                   4104: 
1.854     kalberla 4105: sub blocking_status {
                   4106:   my ($activity,$uname,$udom) = @_;
1.867     kalberla 4107:   my %setters;
1.890     droeschl 4108: 
                   4109:   # check for active blocking
1.867     kalberla 4110:   my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
1.854     kalberla 4111: 
1.890     droeschl 4112:   my $blocked = $startblock && $endblock ? 1 : 0;
                   4113: 
                   4114:   # caller just wants to know whether a block is active
                   4115:   if (!wantarray) { return $blocked; }
                   4116: 
                   4117:   # build a link to a popup window containing the details
                   4118:   my $querystring  = "?activity=$activity";
                   4119:   # $uname and $udom decide whose portfolio the user is trying to look at
                   4120:      $querystring .= "&amp;udom=$udom"      if $udom;
                   4121:      $querystring .= "&amp;uname=$uname"    if $uname;
                   4122: 
                   4123:   my $output .= <<'END_MYBLOCK';
1.854     kalberla 4124:     function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
                   4125:         var options = "width=" + w + ",height=" + h + ",";
                   4126:         options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
                   4127:         options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
                   4128:         var newWin = window.open(url, wdwName, options);
                   4129:         newWin.focus();
                   4130:     }
1.890     droeschl 4131: END_MYBLOCK
1.854     kalberla 4132: 
1.890     droeschl 4133:   $output = Apache::lonhtmlcommon::scripttag($output);
                   4134:   
1.854     kalberla 4135:   my $popupUrl = "/adm/blockingstatus/$querystring";
1.890     droeschl 4136:   my $text = mt('Communication Blocked');
                   4137: 
1.867     kalberla 4138:   $output .= <<"END_BLOCK";
                   4139: <div class='LC_comblock'>
1.869     kalberla 4140:   <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890     droeschl 4141:   title='$text'>
                   4142:   <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869     kalberla 4143:   <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring' 
1.890     droeschl 4144:   title='$text'>$text</a>
1.867     kalberla 4145: </div>
                   4146: 
                   4147: END_BLOCK
1.474     raeburn  4148: 
1.854     kalberla 4149:   return ($blocked, $output);
                   4150: }
1.490     raeburn  4151: 
1.60      matthew  4152: ###############################################
                   4153: 
1.682     raeburn  4154: sub check_ip_acc {
                   4155:     my ($acc)=@_;
                   4156:     &Apache::lonxml::debug("acc is $acc");
                   4157:     if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
                   4158:         return 1;
                   4159:     }
                   4160:     my $allowed=0;
                   4161:     my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
                   4162: 
                   4163:     my $name;
                   4164:     foreach my $pattern (split(',',$acc)) {
                   4165:         $pattern =~ s/^\s*//;
                   4166:         $pattern =~ s/\s*$//;
                   4167:         if ($pattern =~ /\*$/) {
                   4168:             #35.8.*
                   4169:             $pattern=~s/\*//;
                   4170:             if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
                   4171:         } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
                   4172:             #35.8.3.[34-56]
                   4173:             my $low=$2;
                   4174:             my $high=$3;
                   4175:             $pattern=$1;
                   4176:             if ($ip =~ /^\Q$pattern\E/) {
                   4177:                 my $last=(split(/\./,$ip))[3];
                   4178:                 if ($last <=$high && $last >=$low) { $allowed=1; }
                   4179:             }
                   4180:         } elsif ($pattern =~ /^\*/) {
                   4181:             #*.msu.edu
                   4182:             $pattern=~s/\*//;
                   4183:             if (!defined($name)) {
                   4184:                 use Socket;
                   4185:                 my $netaddr=inet_aton($ip);
                   4186:                 ($name)=gethostbyaddr($netaddr,AF_INET);
                   4187:             }
                   4188:             if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
                   4189:         } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
                   4190:             #127.0.0.1
                   4191:             if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
                   4192:         } else {
                   4193:             #some.name.com
                   4194:             if (!defined($name)) {
                   4195:                 use Socket;
                   4196:                 my $netaddr=inet_aton($ip);
                   4197:                 ($name)=gethostbyaddr($netaddr,AF_INET);
                   4198:             }
                   4199:             if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
                   4200:         }
                   4201:         if ($allowed) { last; }
                   4202:     }
                   4203:     return $allowed;
                   4204: }
                   4205: 
                   4206: ###############################################
                   4207: 
1.60      matthew  4208: =pod
                   4209: 
1.112     bowersj2 4210: =head1 Domain Template Functions
                   4211: 
                   4212: =over 4
                   4213: 
                   4214: =item * &determinedomain()
1.60      matthew  4215: 
                   4216: Inputs: $domain (usually will be undef)
                   4217: 
1.63      www      4218: Returns: Determines which domain should be used for designs
1.60      matthew  4219: 
                   4220: =cut
1.54      www      4221: 
1.60      matthew  4222: ###############################################
1.63      www      4223: sub determinedomain {
                   4224:     my $domain=shift;
1.531     albertel 4225:     if (! $domain) {
1.60      matthew  4226:         # Determine domain if we have not been given one
1.893     raeburn  4227:         $domain = &Apache::lonnet::default_login_domain();
1.258     albertel 4228:         if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
                   4229:         if ($env{'request.role.domain'}) { 
                   4230:             $domain=$env{'request.role.domain'}; 
1.60      matthew  4231:         }
                   4232:     }
1.63      www      4233:     return $domain;
                   4234: }
                   4235: ###############################################
1.517     raeburn  4236: 
1.518     albertel 4237: sub devalidate_domconfig_cache {
                   4238:     my ($udom)=@_;
                   4239:     &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
                   4240: }
                   4241: 
                   4242: # ---------------------- Get domain configuration for a domain
                   4243: sub get_domainconf {
                   4244:     my ($udom) = @_;
                   4245:     my $cachetime=1800;
                   4246:     my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
                   4247:     if (defined($cached)) { return %{$result}; }
                   4248: 
                   4249:     my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948     raeburn  4250: 					     ['login','rolecolors','autoenroll'],$udom);
1.632     raeburn  4251:     my (%designhash,%legacy);
1.518     albertel 4252:     if (keys(%domconfig) > 0) {
                   4253:         if (ref($domconfig{'login'}) eq 'HASH') {
1.632     raeburn  4254:             if (keys(%{$domconfig{'login'}})) {
                   4255:                 foreach my $key (keys(%{$domconfig{'login'}})) {
1.699     raeburn  4256:                     if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.946     raeburn  4257:                         if ($key eq 'loginvia') {
                   4258:                             if (ref($domconfig{'login'}{'loginvia'}) eq 'HASH') {
                   4259:                                 my @ids = &Apache::lonnet::current_machine_ids();
                   4260:                                 foreach my $hostname (@ids) {
1.948     raeburn  4261:                                     if (ref($domconfig{'login'}{'loginvia'}{$hostname}) eq 'HASH') {
                   4262:                                         if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
                   4263:                                             my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
                   4264:                                             $designhash{$udom.'.login.loginvia'} = $server;
                   4265:                                             if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
                   4266: 
                   4267:                                                 $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
                   4268:                                             } else {
                   4269:                                                  $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
                   4270:                                             }
                   4271:                                             if ($domconfig{'login'}{'loginvia'}{$hostname}{'exempt'}) {
                   4272:                                                 $designhash{$udom.'.login.loginvia_exempt_'.$hostname} = $domconfig{'login'}{'loginvia'}{$hostname}{'exempt'};
                   4273:                                             }
1.946     raeburn  4274:                                         }
                   4275:                                     }
                   4276:                                 }
                   4277:                             }
                   4278:                         } else {
                   4279:                             foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
                   4280:                                 $designhash{$udom.'.login.'.$key.'_'.$img} = 
                   4281:                                     $domconfig{'login'}{$key}{$img};
                   4282:                             }
1.699     raeburn  4283:                         }
                   4284:                     } else {
                   4285:                         $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
                   4286:                     }
1.632     raeburn  4287:                 }
                   4288:             } else {
                   4289:                 $legacy{'login'} = 1;
1.518     albertel 4290:             }
1.632     raeburn  4291:         } else {
                   4292:             $legacy{'login'} = 1;
1.518     albertel 4293:         }
                   4294:         if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632     raeburn  4295:             if (keys(%{$domconfig{'rolecolors'}})) {
                   4296:                 foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
                   4297:                     if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
                   4298:                         foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
                   4299:                             $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
                   4300:                         }
1.518     albertel 4301:                     }
                   4302:                 }
1.632     raeburn  4303:             } else {
                   4304:                 $legacy{'rolecolors'} = 1;
1.518     albertel 4305:             }
1.632     raeburn  4306:         } else {
                   4307:             $legacy{'rolecolors'} = 1;
1.518     albertel 4308:         }
1.948     raeburn  4309:         if (ref($domconfig{'autoenroll'}) eq 'HASH') {
                   4310:             if ($domconfig{'autoenroll'}{'co-owners'}) {
                   4311:                 $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
                   4312:             }
                   4313:         }
1.632     raeburn  4314:         if (keys(%legacy) > 0) {
                   4315:             my %legacyhash = &get_legacy_domconf($udom);
                   4316:             foreach my $item (keys(%legacyhash)) {
                   4317:                 if ($item =~ /^\Q$udom\E\.login/) {
                   4318:                     if ($legacy{'login'}) { 
                   4319:                         $designhash{$item} = $legacyhash{$item};
                   4320:                     }
                   4321:                 } else {
                   4322:                     if ($legacy{'rolecolors'}) {
                   4323:                         $designhash{$item} = $legacyhash{$item};
                   4324:                     }
1.518     albertel 4325:                 }
                   4326:             }
                   4327:         }
1.632     raeburn  4328:     } else {
                   4329:         %designhash = &get_legacy_domconf($udom); 
1.518     albertel 4330:     }
                   4331:     &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
                   4332: 				  $cachetime);
                   4333:     return %designhash;
                   4334: }
                   4335: 
1.632     raeburn  4336: sub get_legacy_domconf {
                   4337:     my ($udom) = @_;
                   4338:     my %legacyhash;
                   4339:     my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
                   4340:     my $designfile =  $designdir.'/'.$udom.'.tab';
                   4341:     if (-e $designfile) {
                   4342:         if ( open (my $fh,"<$designfile") ) {
                   4343:             while (my $line = <$fh>) {
                   4344:                 next if ($line =~ /^\#/);
                   4345:                 chomp($line);
                   4346:                 my ($key,$val)=(split(/\=/,$line));
                   4347:                 if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
                   4348:             }
                   4349:             close($fh);
                   4350:         }
                   4351:     }
                   4352:     if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
                   4353:         $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
                   4354:     }
                   4355:     return %legacyhash;
                   4356: }
                   4357: 
1.63      www      4358: =pod
                   4359: 
1.112     bowersj2 4360: =item * &domainlogo()
1.63      www      4361: 
                   4362: Inputs: $domain (usually will be undef)
                   4363: 
                   4364: Returns: A link to a domain logo, if the domain logo exists.
                   4365: If the domain logo does not exist, a description of the domain.
                   4366: 
                   4367: =cut
1.112     bowersj2 4368: 
1.63      www      4369: ###############################################
                   4370: sub domainlogo {
1.517     raeburn  4371:     my $domain = &determinedomain(shift);
1.518     albertel 4372:     my %designhash = &get_domainconf($domain);    
1.517     raeburn  4373:     # See if there is a logo
                   4374:     if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519     raeburn  4375:         my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538     albertel 4376:         if ($imgsrc =~ m{^/(adm|res)/}) {
                   4377: 	    if ($imgsrc =~ m{^/res/}) {
                   4378: 		my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
                   4379: 		&Apache::lonnet::repcopy($local_name);
                   4380: 	    }
                   4381: 	   $imgsrc = &lonhttpdurl($imgsrc);
1.519     raeburn  4382:         } 
                   4383:         return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514     albertel 4384:     } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
                   4385:         return &Apache::lonnet::domain($domain,'description');
1.59      www      4386:     } else {
1.60      matthew  4387:         return '';
1.59      www      4388:     }
                   4389: }
1.63      www      4390: ##############################################
                   4391: 
                   4392: =pod
                   4393: 
1.112     bowersj2 4394: =item * &designparm()
1.63      www      4395: 
                   4396: Inputs: $which parameter; $domain (usually will be undef)
                   4397: 
                   4398: Returns: value of designparamter $which
                   4399: 
                   4400: =cut
1.112     bowersj2 4401: 
1.397     albertel 4402: 
1.400     albertel 4403: ##############################################
1.397     albertel 4404: sub designparm {
                   4405:     my ($which,$domain)=@_;
                   4406:     if (exists($env{'environment.color.'.$which})) {
1.817     bisitz   4407:         return $env{'environment.color.'.$which};
1.96      www      4408:     }
1.63      www      4409:     $domain=&determinedomain($domain);
1.518     albertel 4410:     my %domdesign = &get_domainconf($domain);
1.520     raeburn  4411:     my $output;
1.517     raeburn  4412:     if ($domdesign{$domain.'.'.$which} ne '') {
1.817     bisitz   4413:         $output = $domdesign{$domain.'.'.$which};
1.63      www      4414:     } else {
1.520     raeburn  4415:         $output = $defaultdesign{$which};
                   4416:     }
                   4417:     if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635     raeburn  4418:         ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538     albertel 4419:         if ($output =~ m{^/(adm|res)/}) {
1.817     bisitz   4420:             if ($output =~ m{^/res/}) {
                   4421:                 my $local_name = &Apache::lonnet::filelocation('',$output);
                   4422:                 &Apache::lonnet::repcopy($local_name);
                   4423:             }
1.520     raeburn  4424:             $output = &lonhttpdurl($output);
                   4425:         }
1.63      www      4426:     }
1.520     raeburn  4427:     return $output;
1.63      www      4428: }
1.59      www      4429: 
1.822     bisitz   4430: ##############################################
                   4431: =pod
                   4432: 
1.832     bisitz   4433: =item * &authorspace()
                   4434: 
                   4435: Inputs: ./.
                   4436: 
                   4437: Returns: Path to the Construction Space of the current user's
                   4438:          accessed author space
                   4439:          The author space will be that of the current user
                   4440:          when accessing the own author space
                   4441:          and that of the co-author/assistent co-author
                   4442:          when accessing the co-author's/assistent co-author's
                   4443:          space
                   4444: 
                   4445: =cut
                   4446: 
                   4447: sub authorspace {
                   4448:     my $caname = '';
                   4449:     if ($env{'request.role'} =~ /^ca|^aa/) {
                   4450:         (undef,$caname) =
                   4451:             ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
                   4452:     } else {
                   4453:         $caname = $env{'user.name'};
                   4454:     }
                   4455:     return '/priv/'.$caname.'/';
                   4456: }
                   4457: 
                   4458: ##############################################
                   4459: =pod
                   4460: 
1.822     bisitz   4461: =item * &head_subbox()
                   4462: 
                   4463: Inputs: $content (contains HTML code with page functions, etc.)
                   4464: 
                   4465: Returns: HTML div with $content
                   4466:          To be included in page header
                   4467: 
                   4468: =cut
                   4469: 
                   4470: sub head_subbox {
                   4471:     my ($content)=@_;
                   4472:     my $output =
1.844     bisitz   4473:         '<div id="LC_head_subbox">'
1.822     bisitz   4474:        .$content
                   4475:        .'</div>'
                   4476: }
                   4477: 
                   4478: ##############################################
                   4479: =pod
                   4480: 
                   4481: =item * &CSTR_pageheader()
                   4482: 
                   4483: Inputs: ./.
                   4484: 
                   4485: Returns: HTML div with CSTR path and recent box
                   4486:          To be included on Construction Space pages
                   4487: 
                   4488: =cut
                   4489: 
                   4490: sub CSTR_pageheader {
                   4491:     # this is for resources; directories have customtitle, and crumbs
                   4492:             # and select recent are created in lonpubdir.pm  
                   4493:     my ($uname,$thisdisfn)=
                   4494:         ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
                   4495:     my $formaction='/priv/'.$uname.'/'.$thisdisfn;
                   4496:     $formaction=~s/\/+/\//g;
                   4497: 
                   4498:     my $parentpath = '';
                   4499:     my $lastitem = '';
                   4500:     if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
                   4501:         $parentpath = $1;
                   4502:         $lastitem = $2;
                   4503:     } else {
                   4504:         $lastitem = $thisdisfn;
                   4505:     }
1.921     bisitz   4506: 
                   4507:     my $output =
1.822     bisitz   4508:          '<div>'
                   4509:         .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
                   4510:         .'<b>'.&mt('Construction Space:').'</b> '
                   4511:         .'<form name="dirs" method="post" action="'.$formaction
1.921     bisitz   4512:         .'" target="_top">' #FIXME lonpubdir: target="_parent"
                   4513:         .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv',undef,undef);
                   4514: 
                   4515:     if ($lastitem) {
                   4516:         $output .=
                   4517:              '<span class="LC_filename">'
                   4518:             .$lastitem
                   4519:             .'</span>';
                   4520:     }
                   4521:     $output .=
                   4522:          '<br />'
1.822     bisitz   4523:         #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
                   4524:         .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
                   4525:         .'</form>'
                   4526:         .&Apache::lonmenu::constspaceform()
                   4527:         .'</div>';
1.921     bisitz   4528: 
                   4529:     return $output;
1.822     bisitz   4530: }
                   4531: 
1.60      matthew  4532: ###############################################
                   4533: ###############################################
                   4534: 
                   4535: =pod
                   4536: 
1.112     bowersj2 4537: =back
                   4538: 
1.549     albertel 4539: =head1 HTML Helpers
1.112     bowersj2 4540: 
                   4541: =over 4
                   4542: 
                   4543: =item * &bodytag()
1.60      matthew  4544: 
                   4545: Returns a uniform header for LON-CAPA web pages.
                   4546: 
                   4547: Inputs: 
                   4548: 
1.112     bowersj2 4549: =over 4
                   4550: 
                   4551: =item * $title, A title to be displayed on the page.
                   4552: 
                   4553: =item * $function, the current role (can be undef).
                   4554: 
                   4555: =item * $addentries, extra parameters for the <body> tag.
                   4556: 
                   4557: =item * $bodyonly, if defined, only return the <body> tag.
                   4558: 
                   4559: =item * $domain, if defined, force a given domain.
                   4560: 
                   4561: =item * $forcereg, if page should register as content page (relevant for 
1.86      www      4562:             text interface only)
1.60      matthew  4563: 
1.814     bisitz   4564: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
                   4565:                      navigational links
1.317     albertel 4566: 
1.338     albertel 4567: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
                   4568: 
1.361     albertel 4569: =item * $no_inline_link, if true and in remote mode, don't show the 
                   4570:          'Switch To Inline Menu' link
                   4571: 
1.460     albertel 4572: =item * $args, optional argument valid values are
                   4573:             no_auto_mt_title -> prevents &mt()ing the title arg
1.562     albertel 4574:             inherit_jsmath -> when creating popup window in a page,
                   4575:                               should it have jsmath forced on by the
                   4576:                               current page
1.460     albertel 4577: 
1.112     bowersj2 4578: =back
                   4579: 
1.60      matthew  4580: Returns: A uniform header for LON-CAPA web pages.  
                   4581: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
                   4582: If $bodyonly is undef or zero, an html string containing a <body> tag and 
                   4583: other decorations will be returned.
                   4584: 
                   4585: =cut
                   4586: 
1.54      www      4587: sub bodytag {
1.831     bisitz   4588:     my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.816     bisitz   4589:         $no_nav_bar,$bgcolor,$no_inline_link,$args)=@_;
1.339     albertel 4590: 
1.948.2.2  raeburn  4591:     my $public;
                   4592:     if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
                   4593:         || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
                   4594:         $public = 1;
                   4595:     }
1.460     albertel 4596:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339     albertel 4597: 
1.183     matthew  4598:     $function = &get_users_function() if (!$function);
1.339     albertel 4599:     my $img =    &designparm($function.'.img',$domain);
                   4600:     my $font =   &designparm($function.'.font',$domain);
                   4601:     my $pgbg   = $bgcolor || &designparm($function.'.pgbg',$domain);
                   4602: 
1.803     bisitz   4603:     my %design = ( 'style'   => 'margin-top: 0',
1.535     albertel 4604: 		   'bgcolor' => $pgbg,
1.339     albertel 4605: 		   'text'    => $font,
                   4606:                    'alink'   => &designparm($function.'.alink',$domain),
                   4607: 		   'vlink'   => &designparm($function.'.vlink',$domain),
                   4608: 		   'link'    => &designparm($function.'.link',$domain),);
1.438     albertel 4609:     @design{keys(%$addentries)} = @$addentries{keys(%$addentries)}; 
1.339     albertel 4610: 
1.63      www      4611:  # role and realm
1.378     raeburn  4612:     my ($role,$realm) = split(/\./,$env{'request.role'},2);
                   4613:     if ($role  eq 'ca') {
1.479     albertel 4614:         my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500     albertel 4615:         $realm = &plainname($rname,$rdom);
1.378     raeburn  4616:     } 
1.55      www      4617: # realm
1.258     albertel 4618:     if ($env{'request.course.id'}) {
1.378     raeburn  4619:         if ($env{'request.role'} !~ /^cr/) {
                   4620:             $role = &Apache::lonnet::plaintext($role,&course_type());
                   4621:         }
1.898     raeburn  4622:         if ($env{'request.course.sec'}) {
                   4623:             $role .= ('&nbsp;'x2).'-&nbsp;'.&mt('section:').'&nbsp;'.$env{'request.course.sec'};
                   4624:         }   
1.359     albertel 4625: 	$realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378     raeburn  4626:     } else {
                   4627:         $role = &Apache::lonnet::plaintext($role);
1.54      www      4628:     }
1.433     albertel 4629: 
1.359     albertel 4630:     if (!$realm) { $realm='&nbsp;'; }
1.55      www      4631: # Set messages
1.60      matthew  4632:     my $messages=&domainlogo($domain);
1.330     albertel 4633: 
1.438     albertel 4634:     my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329     albertel 4635: 
1.101     www      4636: # construct main body tag
1.359     albertel 4637:     my $bodytag = "<body $extra_body_attr>".
1.562     albertel 4638: 	&Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252     albertel 4639: 
1.530     albertel 4640:     if ($bodyonly) {
1.60      matthew  4641:         return $bodytag;
1.798     tempelho 4642:     } 
1.359     albertel 4643: 
1.410     albertel 4644:     my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.948.2.2  raeburn  4645:     if ($public) {
1.433     albertel 4646: 	undef($role);
1.434     albertel 4647:     } else {
                   4648: 	$name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433     albertel 4649:     }
1.948.2.2  raeburn  4650: 
1.762     bisitz   4651:     my $titleinfo = '<h1>'.$title.'</h1>';
1.359     albertel 4652:     #
                   4653:     # Extra info if you are the DC
                   4654:     my $dc_info = '';
                   4655:     if ($env{'user.adv'} && exists($env{'user.role.dc./'.
                   4656:                         $env{'course.'.$env{'request.course.id'}.
                   4657:                                  '.domain'}.'/'})) {
                   4658:         my $cid = $env{'request.course.id'};
1.917     raeburn  4659:         $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380     www      4660:         $dc_info =~ s/\s+$//;
1.359     albertel 4661:     }
                   4662: 
1.898     raeburn  4663:     $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.853     droeschl 4664:     &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
                   4665: 
1.837     bisitz   4666:     if ($env{'environment.remote'} eq 'off') {
1.359     albertel 4667:         # No Remote
1.916     droeschl 4668:         if ($no_nav_bar || $env{'form.inhibitmenu'} eq 'yes') { 
                   4669:             return $bodytag; 
                   4670:         } 
1.903     droeschl 4671: 
                   4672:         if ($env{'request.state'} eq 'construct') { $forcereg=1; }
                   4673: 
                   4674:         #    if ($env{'request.state'} eq 'construct') {
                   4675:         #        $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
                   4676:         #    }
                   4677: 
1.359     albertel 4678: 
                   4679: 
1.916     droeschl 4680:         if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.917     raeburn  4681:              if ($dc_info) {
                   4682:                  $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
                   4683:              }
1.916     droeschl 4684:              $bodytag .= qq|<div id="LC_nav_bar">$name $role<br />
                   4685:                 <em>$realm</em> $dc_info</div>|;
1.903     droeschl 4686:             return $bodytag;
                   4687:         }
1.894     droeschl 4688: 
1.927     raeburn  4689:         unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
                   4690:             $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>|;
                   4691:         }
1.916     droeschl 4692: 
1.903     droeschl 4693:         $bodytag .= Apache::lonhtmlcommon::scripttag(
                   4694:             Apache::lonmenu::utilityfunctions(), 'start');
1.816     bisitz   4695: 
1.903     droeschl 4696:         $bodytag .= Apache::lonmenu::primary_menu();
1.852     droeschl 4697: 
1.917     raeburn  4698:         if ($dc_info) {
                   4699:             $dc_info = &dc_courseid_toggle($dc_info);
                   4700:         }
                   4701:         $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916     droeschl 4702: 
1.903     droeschl 4703:         #don't show menus for public users
1.948.2.2  raeburn  4704:         if (!$public){
1.903     droeschl 4705:             $bodytag .= Apache::lonmenu::secondary_menu();
                   4706:             $bodytag .= Apache::lonmenu::serverform();
1.920     raeburn  4707:             $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
                   4708:             if ($env{'request.state'} eq 'construct') {
                   4709:                 $bodytag .= &Apache::lonmenu::innerregister($forcereg,'',
                   4710:                                 $args->{'bread_crumbs'});
                   4711:             } elsif ($forcereg) { 
                   4712:                 $bodytag .= &Apache::lonmenu::innerregister($forcereg);
                   4713:             }
1.903     droeschl 4714:         }else{
                   4715:             # this is to seperate menu from content when there's no secondary
                   4716:             # menu. Especially needed for public accessible ressources.
                   4717:             $bodytag .= '<hr style="clear:both" />';
                   4718:             $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end'); 
1.235     raeburn  4719:         }
1.903     droeschl 4720: 
1.235     raeburn  4721:         return $bodytag;
1.94      www      4722:     }
1.95      www      4723: 
1.93      www      4724: #
1.95      www      4725: # Top frame rendering, Remote is up
1.93      www      4726: #
1.359     albertel 4727: 
1.517     raeburn  4728:     my $imgsrc = $img;
                   4729:     if ($img =~ /^\/adm/) {
1.575     albertel 4730:         $imgsrc = &lonhttpdurl($img);
1.517     raeburn  4731:     }
                   4732:     my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359     albertel 4733: 
1.305     www      4734:     # Explicit link to get inline menu
1.361     albertel 4735:     my $menu= ($no_inline_link?''
1.883     droeschl 4736: 	       :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
1.917     raeburn  4737: 
                   4738:     if ($dc_info) {
                   4739:         $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
                   4740:     }
                   4741: 
1.916     droeschl 4742:     $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>
1.897     wenzelju 4743:             <ol class="LC_primary_menu LC_right">
1.853     droeschl 4744:                 <li>$menu</li>
1.917     raeburn  4745:             </ol><div id="LC_realm"> $realm $dc_info</div>| unless $env{'form.inhibitmenu'};
1.94      www      4746:     return(<<ENDBODY);
1.60      matthew  4747: $bodytag
1.359     albertel 4748: <table id="LC_title_bar" class="LC_with_remote">
1.791     tempelho 4749: <tr><td>$upperleft</td>
                   4750:     <td>$messages&nbsp;</td>
1.54      www      4751: </tr>
1.359     albertel 4752: <tr><td>$titleinfo $dc_info $menu</td>
1.368     albertel 4753: </tr>
1.356     albertel 4754: </table>
1.54      www      4755: ENDBODY
1.182     matthew  4756: }
                   4757: 
1.917     raeburn  4758: sub dc_courseid_toggle {
                   4759:     my ($dc_info) = @_;
1.948.2.10  raeburn  4760:     return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.917     raeburn  4761:            '<a href="javascript:showCourseID();">'.
                   4762:            &mt('(More ...)').'</a></span>'.
                   4763:            '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
                   4764: }
                   4765: 
1.330     albertel 4766: sub make_attr_string {
                   4767:     my ($register,$attr_ref) = @_;
                   4768: 
                   4769:     if ($attr_ref && !ref($attr_ref)) {
                   4770: 	die("addentries Must be a hash ref ".
                   4771: 	    join(':',caller(1))." ".
                   4772: 	    join(':',caller(0))." ");
                   4773:     }
                   4774: 
                   4775:     if ($register) {
1.339     albertel 4776: 	my ($on_load,$on_unload);
                   4777: 	foreach my $key (keys(%{$attr_ref})) {
                   4778: 	    if      (lc($key) eq 'onload') {
                   4779: 		$on_load.=$attr_ref->{$key}.';';
                   4780: 		delete($attr_ref->{$key});
                   4781: 
                   4782: 	    } elsif (lc($key) eq 'onunload') {
                   4783: 		$on_unload.=$attr_ref->{$key}.';';
                   4784: 		delete($attr_ref->{$key});
                   4785: 	    }
                   4786: 	}
                   4787: 	$attr_ref->{'onload'}  =
                   4788: 	    &Apache::lonmenu::loadevents().  $on_load;
                   4789: 	$attr_ref->{'onunload'}=
                   4790: 	    &Apache::lonmenu::unloadevents().$on_unload;
                   4791:     }
                   4792: 
                   4793: # Accessibility font enhance
                   4794:     if ($env{'browser.fontenhance'} eq 'on') {
                   4795: 	my $style;
                   4796: 	foreach my $key (keys(%{$attr_ref})) {
                   4797: 	    if (lc($key) eq 'style') {
                   4798: 		$style.=$attr_ref->{$key}.';';
                   4799: 		delete($attr_ref->{$key});
                   4800: 	    }
                   4801: 	}
                   4802: 	$attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330     albertel 4803:     }
1.339     albertel 4804: 
1.330     albertel 4805:     my $attr_string;
                   4806:     foreach my $attr (keys(%$attr_ref)) {
                   4807: 	$attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
                   4808:     }
                   4809:     return $attr_string;
                   4810: }
                   4811: 
                   4812: 
1.182     matthew  4813: ###############################################
1.251     albertel 4814: ###############################################
                   4815: 
                   4816: =pod
                   4817: 
                   4818: =item * &endbodytag()
                   4819: 
                   4820: Returns a uniform footer for LON-CAPA web pages.
                   4821: 
1.635     raeburn  4822: Inputs: 1 - optional reference to an args hash
                   4823: If in the hash, key for noredirectlink has a value which evaluates to true,
                   4824: a 'Continue' link is not displayed if the page contains an
                   4825: internal redirect in the <head></head> section,
                   4826: i.e., $env{'internal.head.redirect'} exists   
1.251     albertel 4827: 
                   4828: =cut
                   4829: 
                   4830: sub endbodytag {
1.635     raeburn  4831:     my ($args) = @_;
1.251     albertel 4832:     my $endbodytag='</body>';
1.269     albertel 4833:     $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315     albertel 4834:     if ( exists( $env{'internal.head.redirect'} ) ) {
1.635     raeburn  4835:         if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
                   4836: 	    $endbodytag=
                   4837: 	        "<br /><a href=\"$env{'internal.head.redirect'}\">".
                   4838: 	        &mt('Continue').'</a>'.
                   4839: 	        $endbodytag;
                   4840:         }
1.315     albertel 4841:     }
1.251     albertel 4842:     return $endbodytag;
                   4843: }
                   4844: 
1.352     albertel 4845: =pod
                   4846: 
                   4847: =item * &standard_css()
                   4848: 
                   4849: Returns a style sheet
                   4850: 
                   4851: Inputs: (all optional)
                   4852:             domain         -> force to color decorate a page for a specific
                   4853:                                domain
                   4854:             function       -> force usage of a specific rolish color scheme
                   4855:             bgcolor        -> override the default page bgcolor
                   4856: 
                   4857: =cut
                   4858: 
1.343     albertel 4859: sub standard_css {
1.345     albertel 4860:     my ($function,$domain,$bgcolor) = @_;
1.352     albertel 4861:     $function  = &get_users_function() if (!$function);
                   4862:     my $img    = &designparm($function.'.img',   $domain);
                   4863:     my $tabbg  = &designparm($function.'.tabbg', $domain);
                   4864:     my $font   = &designparm($function.'.font',  $domain);
1.801     tempelho 4865:     my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791     tempelho 4866: #second colour for later usage
1.345     albertel 4867:     my $sidebg = &designparm($function.'.sidebg',$domain);
1.382     albertel 4868:     my $pgbg_or_bgcolor =
                   4869: 	         $bgcolor ||
1.352     albertel 4870: 	         &designparm($function.'.pgbg',  $domain);
1.382     albertel 4871:     my $pgbg   = &designparm($function.'.pgbg',  $domain);
1.352     albertel 4872:     my $alink  = &designparm($function.'.alink', $domain);
                   4873:     my $vlink  = &designparm($function.'.vlink', $domain);
                   4874:     my $link   = &designparm($function.'.link',  $domain);
                   4875: 
1.602     albertel 4876:     my $sans                 = 'Verdana,Arial,Helvetica,sans-serif';
1.395     albertel 4877:     my $mono                 = 'monospace';
1.850     bisitz   4878:     my $data_table_head      = $sidebg;
                   4879:     my $data_table_light     = '#FAFAFA';
                   4880:     my $data_table_dark      = '#F0F0F0';
1.470     banghart 4881:     my $data_table_darker    = '#CCCCCC';
1.349     albertel 4882:     my $data_table_highlight = '#FFFF00';
1.352     albertel 4883:     my $mail_new             = '#FFBB77';
                   4884:     my $mail_new_hover       = '#DD9955';
                   4885:     my $mail_read            = '#BBBB77';
                   4886:     my $mail_read_hover      = '#999944';
                   4887:     my $mail_replied         = '#AAAA88';
                   4888:     my $mail_replied_hover   = '#888855';
                   4889:     my $mail_other           = '#99BBBB';
                   4890:     my $mail_other_hover     = '#669999';
1.391     albertel 4891:     my $table_header         = '#DDDDDD';
1.489     raeburn  4892:     my $feedback_link_bg     = '#BBBBBB';
1.911     bisitz   4893:     my $lg_border_color      = '#C8C8C8';
1.948.2.1  raeburn  4894:     my $button_hover         = '#BF2317';
1.392     albertel 4895: 
1.608     albertel 4896:     my $border = ($env{'browser.type'} eq 'explorer' ||
1.911     bisitz   4897:       $env{'browser.type'} eq 'safari'     ) ? '0 2px 0 2px'
                   4898:                                              : '0 3px 0 4px';
1.448     albertel 4899: 
1.343     albertel 4900:     return <<END;
1.947     droeschl 4901: 
                   4902: /* needed for iframe to allow 100% height in FF */
                   4903: body, html { 
                   4904:     margin: 0;
                   4905:     padding: 0 0.5%;
                   4906:     height: 99%; /* to avoid scrollbars */
                   4907: }
                   4908: 
1.795     www      4909: body {
1.911     bisitz   4910:   font-family: $sans;
                   4911:   line-height:130%;
                   4912:   font-size:0.83em;
                   4913:   color:$font;
1.795     www      4914: }
                   4915: 
1.948.2.9  raeburn  4916: a:focus,
                   4917: a:focus img {
1.795     www      4918:   color: red;
1.911     bisitz   4919:   background: yellow;
1.795     www      4920: }
1.698     harmsja  4921: 
1.911     bisitz   4922: form, .inline {
                   4923:   display: inline;
1.795     www      4924: }
1.721     harmsja  4925: 
1.795     www      4926: .LC_right {
1.911     bisitz   4927:   text-align:right;
1.795     www      4928: }
                   4929: 
                   4930: .LC_middle {
1.911     bisitz   4931:   vertical-align:middle;
1.795     www      4932: }
1.721     harmsja  4933: 
1.911     bisitz   4934: .LC_400Box {
                   4935:   width:400px;
                   4936: }
1.721     harmsja  4937: 
1.947     droeschl 4938: .LC_iframecontainer {
                   4939:     width: 98%;
                   4940:     margin: 0;
                   4941:     position: fixed;
                   4942:     top: 8.5em;
                   4943:     bottom: 0;
                   4944: }
                   4945: 
                   4946: .LC_iframecontainer iframe{
                   4947:     border: none;
                   4948:     width: 100%;
                   4949:     height: 100%;
                   4950: }
                   4951: 
1.778     bisitz   4952: .LC_filename {
                   4953:   font-family: $mono;
                   4954:   white-space:pre;
1.921     bisitz   4955:   font-size: 120%;
1.778     bisitz   4956: }
                   4957: 
                   4958: .LC_fileicon {
                   4959:   border: none;
                   4960:   height: 1.3em;
                   4961:   vertical-align: text-bottom;
                   4962:   margin-right: 0.3em;
                   4963:   text-decoration:none;
                   4964: }
                   4965: 
1.350     albertel 4966: .LC_error {
                   4967:   color: red;
                   4968:   font-size: larger;
                   4969: }
1.795     www      4970: 
1.457     albertel 4971: .LC_warning,
                   4972: .LC_diff_removed {
1.733     bisitz   4973:   color: red;
1.394     albertel 4974: }
1.532     albertel 4975: 
                   4976: .LC_info,
1.457     albertel 4977: .LC_success,
                   4978: .LC_diff_added {
1.350     albertel 4979:   color: green;
                   4980: }
1.795     www      4981: 
1.802     bisitz   4982: div.LC_confirm_box {
                   4983:   background-color: #FAFAFA;
                   4984:   border: 1px solid $lg_border_color;
                   4985:   margin-right: 0;
                   4986:   padding: 5px;
                   4987: }
                   4988: 
                   4989: div.LC_confirm_box .LC_error img,
                   4990: div.LC_confirm_box .LC_success img {
                   4991:   vertical-align: middle;
                   4992: }
                   4993: 
1.440     albertel 4994: .LC_icon {
1.771     droeschl 4995:   border: none;
1.790     droeschl 4996:   vertical-align: middle;
1.771     droeschl 4997: }
                   4998: 
1.543     albertel 4999: .LC_docs_spacer {
                   5000:   width: 25px;
                   5001:   height: 1px;
1.771     droeschl 5002:   border: none;
1.543     albertel 5003: }
1.346     albertel 5004: 
1.532     albertel 5005: .LC_internal_info {
1.735     bisitz   5006:   color: #999999;
1.532     albertel 5007: }
                   5008: 
1.794     www      5009: .LC_discussion {
1.911     bisitz   5010:   background: $tabbg;
                   5011:   border: 1px solid black;
                   5012:   margin: 2px;
1.794     www      5013: }
                   5014: 
                   5015: .LC_disc_action_links_bar {
1.911     bisitz   5016:   background: $tabbg;
                   5017:   border: none;
                   5018:   margin: 4px;
1.794     www      5019: }
                   5020: 
                   5021: .LC_disc_action_left {
1.911     bisitz   5022:   text-align: left;
1.794     www      5023: }
                   5024: 
                   5025: .LC_disc_action_right {
1.911     bisitz   5026:   text-align: right;
1.794     www      5027: }
                   5028: 
                   5029: .LC_disc_new_item {
1.911     bisitz   5030:   background: white;
                   5031:   border: 2px solid red;
                   5032:   margin: 2px;
1.794     www      5033: }
                   5034: 
                   5035: .LC_disc_old_item {
1.911     bisitz   5036:   background: white;
                   5037:   border: 1px solid black;
                   5038:   margin: 2px;
1.794     www      5039: }
                   5040: 
1.458     albertel 5041: table.LC_pastsubmission {
                   5042:   border: 1px solid black;
                   5043:   margin: 2px;
                   5044: }
                   5045: 
1.924     bisitz   5046: table#LC_menubuttons {
1.345     albertel 5047:   width: 100%;
                   5048:   background: $pgbg;
1.392     albertel 5049:   border: 2px;
1.402     albertel 5050:   border-collapse: separate;
1.803     bisitz   5051:   padding: 0;
1.345     albertel 5052: }
1.392     albertel 5053: 
1.801     tempelho 5054: table#LC_title_bar a {
                   5055:   color: $fontmenu;
                   5056: }
1.836     bisitz   5057: 
1.807     droeschl 5058: table#LC_title_bar {
1.819     tempelho 5059:   clear: both;
1.836     bisitz   5060:   display: none;
1.807     droeschl 5061: }
                   5062: 
1.795     www      5063: table#LC_title_bar,
1.933     droeschl 5064: table.LC_breadcrumbs, /* obsolete? */
1.393     albertel 5065: table#LC_title_bar.LC_with_remote {
1.359     albertel 5066:   width: 100%;
1.392     albertel 5067:   border-color: $pgbg;
                   5068:   border-style: solid;
                   5069:   border-width: $border;
1.379     albertel 5070:   background: $pgbg;
1.801     tempelho 5071:   color: $fontmenu;
1.392     albertel 5072:   border-collapse: collapse;
1.803     bisitz   5073:   padding: 0;
1.819     tempelho 5074:   margin: 0;
1.359     albertel 5075: }
1.795     www      5076: 
1.933     droeschl 5077: ul.LC_breadcrumb_tools_outerlist {
1.913     droeschl 5078:     margin: 0;
                   5079:     padding: 0;
1.933     droeschl 5080:     position: relative;
                   5081:     list-style: none;
1.913     droeschl 5082: }
1.933     droeschl 5083: ul.LC_breadcrumb_tools_outerlist li {
1.913     droeschl 5084:     display: inline;
                   5085: }
1.933     droeschl 5086: 
                   5087: .LC_breadcrumb_tools_navigation {
1.913     droeschl 5088:     padding: 0;
1.933     droeschl 5089:     margin: 0;
                   5090:     float: left;
1.913     droeschl 5091: }
1.933     droeschl 5092: .LC_breadcrumb_tools_tools {
                   5093:     padding: 0;
                   5094:     margin: 0;
1.913     droeschl 5095:     float: right;
                   5096: }
                   5097: 
1.359     albertel 5098: table#LC_title_bar td {
                   5099:   background: $tabbg;
                   5100: }
1.795     www      5101: 
1.911     bisitz   5102: table#LC_menubuttons img {
1.803     bisitz   5103:   border: none;
1.346     albertel 5104: }
1.795     www      5105: 
1.842     droeschl 5106: .LC_breadcrumbs_component {
1.911     bisitz   5107:   float: right;
                   5108:   margin: 0 1em;
1.357     albertel 5109: }
1.842     droeschl 5110: .LC_breadcrumbs_component img {
1.911     bisitz   5111:   vertical-align: middle;
1.777     tempelho 5112: }
1.795     www      5113: 
1.383     albertel 5114: td.LC_table_cell_checkbox {
                   5115:   text-align: center;
                   5116: }
1.795     www      5117: 
                   5118: .LC_fontsize_small {
1.911     bisitz   5119:   font-size: 70%;
1.705     tempelho 5120: }
                   5121: 
1.844     bisitz   5122: #LC_breadcrumbs {
1.911     bisitz   5123:   clear:both;
                   5124:   background: $sidebg;
                   5125:   border-bottom: 1px solid $lg_border_color;
                   5126:   line-height: 2.5em;
1.933     droeschl 5127:   overflow: hidden;
1.911     bisitz   5128:   margin: 0;
                   5129:   padding: 0;
1.819     tempelho 5130: }
1.862     bisitz   5131: 
1.839     droeschl 5132: /* Preliminary fix to hide breadcrumbs inside remote control window */
1.844     bisitz   5133: #LC_remote #LC_breadcrumbs {
1.911     bisitz   5134:   display:none;
1.839     droeschl 5135: }
1.819     tempelho 5136: 
1.844     bisitz   5137: #LC_head_subbox {
1.911     bisitz   5138:   clear:both;
                   5139:   background: #F8F8F8; /* $sidebg; */
1.915     droeschl 5140:   border: 1px solid $sidebg;
                   5141:   margin: 0 0 10px 0;      
1.948.2.6  raeburn  5142:   padding: 3px;
1.822     bisitz   5143: }
                   5144: 
1.795     www      5145: .LC_fontsize_medium {
1.911     bisitz   5146:   font-size: 85%;
1.705     tempelho 5147: }
                   5148: 
1.795     www      5149: .LC_fontsize_large {
1.911     bisitz   5150:   font-size: 120%;
1.705     tempelho 5151: }
                   5152: 
1.346     albertel 5153: .LC_menubuttons_inline_text {
                   5154:   color: $font;
1.698     harmsja  5155:   font-size: 90%;
1.701     harmsja  5156:   padding-left:3px;
1.346     albertel 5157: }
                   5158: 
1.934     droeschl 5159: .LC_menubuttons_inline_text img{
                   5160:   vertical-align: middle;
                   5161: }
                   5162: 
1.948.2.1  raeburn  5163: li.LC_menubuttons_inline_text img,a {
                   5164:   cursor:pointer;
                   5165: }
                   5166: 
1.526     www      5167: .LC_menubuttons_link {
                   5168:   text-decoration: none;
                   5169: }
1.795     www      5170: 
1.522     albertel 5171: .LC_menubuttons_category {
1.521     www      5172:   color: $font;
1.526     www      5173:   background: $pgbg;
1.521     www      5174:   font-size: larger;
                   5175:   font-weight: bold;
                   5176: }
                   5177: 
1.346     albertel 5178: td.LC_menubuttons_text {
1.911     bisitz   5179:   color: $font;
1.346     albertel 5180: }
1.706     harmsja  5181: 
1.346     albertel 5182: .LC_current_location {
                   5183:   background: $tabbg;
                   5184: }
1.795     www      5185: 
1.938     bisitz   5186: table.LC_data_table {
1.347     albertel 5187:   border: 1px solid #000000;
1.402     albertel 5188:   border-collapse: separate;
1.426     albertel 5189:   border-spacing: 1px;
1.610     albertel 5190:   background: $pgbg;
1.347     albertel 5191: }
1.795     www      5192: 
1.422     albertel 5193: .LC_data_table_dense {
                   5194:   font-size: small;
                   5195: }
1.795     www      5196: 
1.507     raeburn  5197: table.LC_nested_outer {
                   5198:   border: 1px solid #000000;
1.589     raeburn  5199:   border-collapse: collapse;
1.803     bisitz   5200:   border-spacing: 0;
1.507     raeburn  5201:   width: 100%;
                   5202: }
1.795     www      5203: 
1.879     raeburn  5204: table.LC_innerpickbox,
1.507     raeburn  5205: table.LC_nested {
1.803     bisitz   5206:   border: none;
1.589     raeburn  5207:   border-collapse: collapse;
1.803     bisitz   5208:   border-spacing: 0;
1.507     raeburn  5209:   width: 100%;
                   5210: }
1.795     www      5211: 
1.930     faziophi 5212: .ui-accordion,
                   5213: .ui-accordion table.LC_data_table,
                   5214: .ui-accordion table.LC_nested_outer{
                   5215:   border: 0px;
                   5216:   border-spacing: 0px;
                   5217:   margin: 3px;
                   5218: }
                   5219: 
1.911     bisitz   5220: table.LC_data_table tr th,
                   5221: table.LC_calendar tr th,
1.879     raeburn  5222: table.LC_prior_tries tr th,
                   5223: table.LC_innerpickbox tr th {
1.349     albertel 5224:   font-weight: bold;
                   5225:   background-color: $data_table_head;
1.801     tempelho 5226:   color:$fontmenu;
1.701     harmsja  5227:   font-size:90%;
1.347     albertel 5228: }
1.795     www      5229: 
1.879     raeburn  5230: table.LC_innerpickbox tr th,
                   5231: table.LC_innerpickbox tr td {
                   5232:   vertical-align: top;
                   5233: }
                   5234: 
1.711     raeburn  5235: table.LC_data_table tr.LC_info_row > td {
1.735     bisitz   5236:   background-color: #CCCCCC;
1.711     raeburn  5237:   font-weight: bold;
                   5238:   text-align: left;
                   5239: }
1.795     www      5240: 
1.912     bisitz   5241: table.LC_data_table tr.LC_odd_row > td {
                   5242:   background-color: $data_table_light;
                   5243:   padding: 2px;
                   5244:   vertical-align: top;
                   5245: }
                   5246: 
1.809     bisitz   5247: table.LC_pick_box tr > td.LC_odd_row {
1.349     albertel 5248:   background-color: $data_table_light;
1.912     bisitz   5249:   vertical-align: top;
                   5250: }
                   5251: 
                   5252: table.LC_data_table tr.LC_even_row > td {
                   5253:   background-color: $data_table_dark;
1.425     albertel 5254:   padding: 2px;
1.900     bisitz   5255:   vertical-align: top;
1.347     albertel 5256: }
1.795     www      5257: 
1.809     bisitz   5258: table.LC_pick_box tr > td.LC_even_row {
1.349     albertel 5259:   background-color: $data_table_dark;
1.900     bisitz   5260:   vertical-align: top;
1.347     albertel 5261: }
1.795     www      5262: 
1.425     albertel 5263: table.LC_data_table tr.LC_data_table_highlight td {
                   5264:   background-color: $data_table_darker;
                   5265: }
1.795     www      5266: 
1.639     raeburn  5267: table.LC_data_table tr td.LC_leftcol_header {
                   5268:   background-color: $data_table_head;
                   5269:   font-weight: bold;
                   5270: }
1.795     www      5271: 
1.451     albertel 5272: table.LC_data_table tr.LC_empty_row td,
1.507     raeburn  5273: table.LC_nested tr.LC_empty_row td {
1.421     albertel 5274:   font-weight: bold;
                   5275:   font-style: italic;
                   5276:   text-align: center;
                   5277:   padding: 8px;
1.347     albertel 5278: }
1.795     www      5279: 
1.940     bisitz   5280: table.LC_data_table tr.LC_empty_row td {
                   5281:   background-color: $sidebg;
                   5282: }
                   5283: 
                   5284: table.LC_nested tr.LC_empty_row td {
                   5285:   background-color: #FFFFFF;
                   5286: }
                   5287: 
1.890     droeschl 5288: table.LC_caption {
                   5289: }
                   5290: 
1.507     raeburn  5291: table.LC_nested tr.LC_empty_row td {
1.465     albertel 5292:   padding: 4ex
                   5293: }
1.795     www      5294: 
1.507     raeburn  5295: table.LC_nested_outer tr th {
                   5296:   font-weight: bold;
1.801     tempelho 5297:   color:$fontmenu;
1.507     raeburn  5298:   background-color: $data_table_head;
1.701     harmsja  5299:   font-size: small;
1.507     raeburn  5300:   border-bottom: 1px solid #000000;
                   5301: }
1.795     www      5302: 
1.507     raeburn  5303: table.LC_nested_outer tr td.LC_subheader {
                   5304:   background-color: $data_table_head;
                   5305:   font-weight: bold;
                   5306:   font-size: small;
                   5307:   border-bottom: 1px solid #000000;
                   5308:   text-align: right;
1.451     albertel 5309: }
1.795     www      5310: 
1.507     raeburn  5311: table.LC_nested tr.LC_info_row td {
1.735     bisitz   5312:   background-color: #CCCCCC;
1.451     albertel 5313:   font-weight: bold;
                   5314:   font-size: small;
1.507     raeburn  5315:   text-align: center;
                   5316: }
1.795     www      5317: 
1.589     raeburn  5318: table.LC_nested tr.LC_info_row td.LC_left_item,
                   5319: table.LC_nested_outer tr th.LC_left_item {
1.507     raeburn  5320:   text-align: left;
1.451     albertel 5321: }
1.795     www      5322: 
1.507     raeburn  5323: table.LC_nested td {
1.735     bisitz   5324:   background-color: #FFFFFF;
1.451     albertel 5325:   font-size: small;
1.507     raeburn  5326: }
1.795     www      5327: 
1.507     raeburn  5328: table.LC_nested_outer tr th.LC_right_item,
                   5329: table.LC_nested tr.LC_info_row td.LC_right_item,
                   5330: table.LC_nested tr.LC_odd_row td.LC_right_item,
                   5331: table.LC_nested tr td.LC_right_item {
1.451     albertel 5332:   text-align: right;
                   5333: }
                   5334: 
1.930     faziophi 5335: .ui-accordion table.LC_nested tr.LC_odd_row td.LC_left_item,
                   5336: .ui-accordion table.LC_nested tr.LC_even_row td.LC_left_item {
                   5337:   text-align: right;
                   5338:   width: 40%;
                   5339:   padding-right:10px;
                   5340:   vertical-align: top;
                   5341:   padding: 5px;
                   5342: }
                   5343: 
                   5344: .ui-accordion table.LC_nested tr.LC_odd_row td.LC_right_item,
                   5345: .ui-accordion table.LC_nested tr.LC_even_row td.LC_right_item {
                   5346:   text-align: left;
                   5347:   width: 60%;
                   5348:   padding: 2px 4px;
                   5349: }
                   5350: 
1.507     raeburn  5351: table.LC_nested tr.LC_odd_row td {
1.735     bisitz   5352:   background-color: #EEEEEE;
1.451     albertel 5353: }
                   5354: 
1.473     raeburn  5355: table.LC_createuser {
                   5356: }
                   5357: 
                   5358: table.LC_createuser tr.LC_section_row td {
1.701     harmsja  5359:   font-size: small;
1.473     raeburn  5360: }
                   5361: 
                   5362: table.LC_createuser tr.LC_info_row td  {
1.735     bisitz   5363:   background-color: #CCCCCC;
1.473     raeburn  5364:   font-weight: bold;
                   5365:   text-align: center;
                   5366: }
                   5367: 
1.349     albertel 5368: table.LC_calendar {
                   5369:   border: 1px solid #000000;
                   5370:   border-collapse: collapse;
1.917     raeburn  5371:   width: 98%;
1.349     albertel 5372: }
1.795     www      5373: 
1.349     albertel 5374: table.LC_calendar_pickdate {
                   5375:   font-size: xx-small;
                   5376: }
1.795     www      5377: 
1.349     albertel 5378: table.LC_calendar tr td {
                   5379:   border: 1px solid #000000;
                   5380:   vertical-align: top;
1.917     raeburn  5381:   width: 14%;
1.349     albertel 5382: }
1.795     www      5383: 
1.349     albertel 5384: table.LC_calendar tr td.LC_calendar_day_empty {
                   5385:   background-color: $data_table_dark;
                   5386: }
1.795     www      5387: 
1.779     bisitz   5388: table.LC_calendar tr td.LC_calendar_day_current {
                   5389:   background-color: $data_table_highlight;
1.777     tempelho 5390: }
1.795     www      5391: 
1.938     bisitz   5392: table.LC_data_table tr td.LC_mail_new {
1.349     albertel 5393:   background-color: $mail_new;
                   5394: }
1.795     www      5395: 
1.938     bisitz   5396: table.LC_data_table tr.LC_mail_new:hover {
1.349     albertel 5397:   background-color: $mail_new_hover;
                   5398: }
1.795     www      5399: 
1.938     bisitz   5400: table.LC_data_table tr td.LC_mail_read {
1.349     albertel 5401:   background-color: $mail_read;
                   5402: }
1.795     www      5403: 
1.938     bisitz   5404: /*
                   5405: table.LC_data_table tr.LC_mail_read:hover {
1.349     albertel 5406:   background-color: $mail_read_hover;
                   5407: }
1.938     bisitz   5408: */
1.795     www      5409: 
1.938     bisitz   5410: table.LC_data_table tr td.LC_mail_replied {
1.349     albertel 5411:   background-color: $mail_replied;
                   5412: }
1.795     www      5413: 
1.938     bisitz   5414: /*
                   5415: table.LC_data_table tr.LC_mail_replied:hover {
1.349     albertel 5416:   background-color: $mail_replied_hover;
                   5417: }
1.938     bisitz   5418: */
1.795     www      5419: 
1.938     bisitz   5420: table.LC_data_table tr td.LC_mail_other {
1.349     albertel 5421:   background-color: $mail_other;
                   5422: }
1.795     www      5423: 
1.938     bisitz   5424: /*
                   5425: table.LC_data_table tr.LC_mail_other:hover {
1.349     albertel 5426:   background-color: $mail_other_hover;
                   5427: }
1.938     bisitz   5428: */
1.494     raeburn  5429: 
1.777     tempelho 5430: table.LC_data_table tr > td.LC_browser_file,
                   5431: table.LC_data_table tr > td.LC_browser_file_published {
1.899     bisitz   5432:   background: #AAEE77;
1.389     albertel 5433: }
1.795     www      5434: 
1.777     tempelho 5435: table.LC_data_table tr > td.LC_browser_file_locked,
                   5436: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389     albertel 5437:   background: #FFAA99;
1.387     albertel 5438: }
1.795     www      5439: 
1.777     tempelho 5440: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899     bisitz   5441:   background: #888888;
1.779     bisitz   5442: }
1.795     www      5443: 
1.777     tempelho 5444: table.LC_data_table tr > td.LC_browser_file_modified,
1.779     bisitz   5445: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899     bisitz   5446:   background: #F8F866;
1.777     tempelho 5447: }
1.795     www      5448: 
1.696     bisitz   5449: table.LC_data_table tr.LC_browser_folder > td {
1.899     bisitz   5450:   background: #E0E8FF;
1.387     albertel 5451: }
1.696     bisitz   5452: 
1.707     bisitz   5453: table.LC_data_table tr > td.LC_roles_is {
1.911     bisitz   5454:   /* background: #77FF77; */
1.707     bisitz   5455: }
1.795     www      5456: 
1.707     bisitz   5457: table.LC_data_table tr > td.LC_roles_future {
1.939     bisitz   5458:   border-right: 8px solid #FFFF77;
1.707     bisitz   5459: }
1.795     www      5460: 
1.707     bisitz   5461: table.LC_data_table tr > td.LC_roles_will {
1.939     bisitz   5462:   border-right: 8px solid #FFAA77;
1.707     bisitz   5463: }
1.795     www      5464: 
1.707     bisitz   5465: table.LC_data_table tr > td.LC_roles_expired {
1.939     bisitz   5466:   border-right: 8px solid #FF7777;
1.707     bisitz   5467: }
1.795     www      5468: 
1.707     bisitz   5469: table.LC_data_table tr > td.LC_roles_will_not {
1.939     bisitz   5470:   border-right: 8px solid #AAFF77;
1.707     bisitz   5471: }
1.795     www      5472: 
1.707     bisitz   5473: table.LC_data_table tr > td.LC_roles_selected {
1.939     bisitz   5474:   border-right: 8px solid #11CC55;
1.707     bisitz   5475: }
                   5476: 
1.388     albertel 5477: span.LC_current_location {
1.701     harmsja  5478:   font-size:larger;
1.388     albertel 5479:   background: $pgbg;
                   5480: }
1.387     albertel 5481: 
1.395     albertel 5482: span.LC_parm_menu_item {
                   5483:   font-size: larger;
                   5484: }
1.795     www      5485: 
1.395     albertel 5486: span.LC_parm_scope_all {
                   5487:   color: red;
                   5488: }
1.795     www      5489: 
1.395     albertel 5490: span.LC_parm_scope_folder {
                   5491:   color: green;
                   5492: }
1.795     www      5493: 
1.395     albertel 5494: span.LC_parm_scope_resource {
                   5495:   color: orange;
                   5496: }
1.795     www      5497: 
1.395     albertel 5498: span.LC_parm_part {
                   5499:   color: blue;
                   5500: }
1.795     www      5501: 
1.911     bisitz   5502: span.LC_parm_folder,
                   5503: span.LC_parm_symb {
1.395     albertel 5504:   font-size: x-small;
                   5505:   font-family: $mono;
                   5506:   color: #AAAAAA;
                   5507: }
                   5508: 
1.948.2.8  raeburn  5509: ul.LC_parm_parmlist li {
                   5510:   display: inline-block;
                   5511:   padding: 0.3em 0.8em;
                   5512:   vertical-align: top;
                   5513:   width: 150px;
                   5514:   border-top:1px solid $lg_border_color;
                   5515: }
                   5516: 
1.795     www      5517: td.LC_parm_overview_level_menu,
                   5518: td.LC_parm_overview_map_menu,
                   5519: td.LC_parm_overview_parm_selectors,
                   5520: td.LC_parm_overview_restrictions  {
1.396     albertel 5521:   border: 1px solid black;
                   5522:   border-collapse: collapse;
                   5523: }
1.795     www      5524: 
1.396     albertel 5525: table.LC_parm_overview_restrictions td {
                   5526:   border-width: 1px 4px 1px 4px;
                   5527:   border-style: solid;
                   5528:   border-color: $pgbg;
                   5529:   text-align: center;
                   5530: }
1.795     www      5531: 
1.396     albertel 5532: table.LC_parm_overview_restrictions th {
                   5533:   background: $tabbg;
                   5534:   border-width: 1px 4px 1px 4px;
                   5535:   border-style: solid;
                   5536:   border-color: $pgbg;
                   5537: }
1.795     www      5538: 
1.398     albertel 5539: table#LC_helpmenu {
1.803     bisitz   5540:   border: none;
1.398     albertel 5541:   height: 55px;
1.803     bisitz   5542:   border-spacing: 0;
1.398     albertel 5543: }
                   5544: 
                   5545: table#LC_helpmenu fieldset legend {
                   5546:   font-size: larger;
                   5547: }
1.795     www      5548: 
1.397     albertel 5549: table#LC_helpmenu_links {
                   5550:   width: 100%;
                   5551:   border: 1px solid black;
                   5552:   background: $pgbg;
1.803     bisitz   5553:   padding: 0;
1.397     albertel 5554:   border-spacing: 1px;
                   5555: }
1.795     www      5556: 
1.397     albertel 5557: table#LC_helpmenu_links tr td {
                   5558:   padding: 1px;
                   5559:   background: $tabbg;
1.399     albertel 5560:   text-align: center;
                   5561:   font-weight: bold;
1.397     albertel 5562: }
1.396     albertel 5563: 
1.795     www      5564: table#LC_helpmenu_links a:link,
                   5565: table#LC_helpmenu_links a:visited,
1.397     albertel 5566: table#LC_helpmenu_links a:active {
                   5567:   text-decoration: none;
                   5568:   color: $font;
                   5569: }
1.795     www      5570: 
1.397     albertel 5571: table#LC_helpmenu_links a:hover {
                   5572:   text-decoration: underline;
                   5573:   color: $vlink;
                   5574: }
1.396     albertel 5575: 
1.417     albertel 5576: .LC_chrt_popup_exists {
                   5577:   border: 1px solid #339933;
                   5578:   margin: -1px;
                   5579: }
1.795     www      5580: 
1.417     albertel 5581: .LC_chrt_popup_up {
                   5582:   border: 1px solid yellow;
                   5583:   margin: -1px;
                   5584: }
1.795     www      5585: 
1.417     albertel 5586: .LC_chrt_popup {
                   5587:   border: 1px solid #8888FF;
                   5588:   background: #CCCCFF;
                   5589: }
1.795     www      5590: 
1.421     albertel 5591: table.LC_pick_box {
                   5592:   border-collapse: separate;
                   5593:   background: white;
                   5594:   border: 1px solid black;
                   5595:   border-spacing: 1px;
                   5596: }
1.795     www      5597: 
1.421     albertel 5598: table.LC_pick_box td.LC_pick_box_title {
1.850     bisitz   5599:   background: $sidebg;
1.421     albertel 5600:   font-weight: bold;
1.900     bisitz   5601:   text-align: left;
1.740     bisitz   5602:   vertical-align: top;
1.421     albertel 5603:   width: 184px;
                   5604:   padding: 8px;
                   5605: }
1.795     www      5606: 
1.579     raeburn  5607: table.LC_pick_box td.LC_pick_box_value {
                   5608:   text-align: left;
                   5609:   padding: 8px;
                   5610: }
1.795     www      5611: 
1.579     raeburn  5612: table.LC_pick_box td.LC_pick_box_select {
                   5613:   text-align: left;
                   5614:   padding: 8px;
                   5615: }
1.795     www      5616: 
1.424     albertel 5617: table.LC_pick_box td.LC_pick_box_separator {
1.803     bisitz   5618:   padding: 0;
1.421     albertel 5619:   height: 1px;
                   5620:   background: black;
                   5621: }
1.795     www      5622: 
1.421     albertel 5623: table.LC_pick_box td.LC_pick_box_submit {
                   5624:   text-align: right;
                   5625: }
1.795     www      5626: 
1.579     raeburn  5627: table.LC_pick_box td.LC_evenrow_value {
                   5628:   text-align: left;
                   5629:   padding: 8px;
                   5630:   background-color: $data_table_light;
                   5631: }
1.795     www      5632: 
1.579     raeburn  5633: table.LC_pick_box td.LC_oddrow_value {
                   5634:   text-align: left;
                   5635:   padding: 8px;
                   5636:   background-color: $data_table_light;
                   5637: }
1.795     www      5638: 
1.579     raeburn  5639: span.LC_helpform_receipt_cat {
                   5640:   font-weight: bold;
                   5641: }
1.795     www      5642: 
1.424     albertel 5643: table.LC_group_priv_box {
                   5644:   background: white;
                   5645:   border: 1px solid black;
                   5646:   border-spacing: 1px;
                   5647: }
1.795     www      5648: 
1.424     albertel 5649: table.LC_group_priv_box td.LC_pick_box_title {
                   5650:   background: $tabbg;
                   5651:   font-weight: bold;
                   5652:   text-align: right;
                   5653:   width: 184px;
                   5654: }
1.795     www      5655: 
1.424     albertel 5656: table.LC_group_priv_box td.LC_groups_fixed {
                   5657:   background: $data_table_light;
                   5658:   text-align: center;
                   5659: }
1.795     www      5660: 
1.424     albertel 5661: table.LC_group_priv_box td.LC_groups_optional {
                   5662:   background: $data_table_dark;
                   5663:   text-align: center;
                   5664: }
1.795     www      5665: 
1.424     albertel 5666: table.LC_group_priv_box td.LC_groups_functionality {
                   5667:   background: $data_table_darker;
                   5668:   text-align: center;
                   5669:   font-weight: bold;
                   5670: }
1.795     www      5671: 
1.424     albertel 5672: table.LC_group_priv td {
                   5673:   text-align: left;
1.803     bisitz   5674:   padding: 0;
1.424     albertel 5675: }
                   5676: 
1.421     albertel 5677: table.LC_notify_front_page {
                   5678:   background: white;
                   5679:   border: 1px solid black;
                   5680:   padding: 8px;
                   5681: }
1.795     www      5682: 
1.421     albertel 5683: table.LC_notify_front_page td {
                   5684:   padding: 8px;
                   5685: }
1.795     www      5686: 
1.424     albertel 5687: .LC_navbuttons {
                   5688:   margin: 2ex 0ex 2ex 0ex;
                   5689: }
1.795     www      5690: 
1.423     albertel 5691: .LC_topic_bar {
                   5692:   font-weight: bold;
                   5693:   background: $tabbg;
1.918     wenzelju 5694:   margin: 1em 0em 1em 2em;
1.805     bisitz   5695:   padding: 3px;
1.918     wenzelju 5696:   font-size: 1.2em;
1.423     albertel 5697: }
1.795     www      5698: 
1.423     albertel 5699: .LC_topic_bar span {
1.918     wenzelju 5700:   left: 0.5em;
                   5701:   position: absolute;
1.423     albertel 5702:   vertical-align: middle;
1.918     wenzelju 5703:   font-size: 1.2em;
1.423     albertel 5704: }
1.795     www      5705: 
1.423     albertel 5706: table.LC_course_group_status {
                   5707:   margin: 20px;
                   5708: }
1.795     www      5709: 
1.423     albertel 5710: table.LC_status_selector td {
                   5711:   vertical-align: top;
                   5712:   text-align: center;
1.424     albertel 5713:   padding: 4px;
                   5714: }
1.795     www      5715: 
1.599     albertel 5716: div.LC_feedback_link {
1.616     albertel 5717:   clear: both;
1.829     kalberla 5718:   background: $sidebg;
1.779     bisitz   5719:   width: 100%;
1.829     kalberla 5720:   padding-bottom: 10px;
                   5721:   border: 1px $tabbg solid;
1.833     kalberla 5722:   height: 22px;
                   5723:   line-height: 22px;
                   5724:   padding-top: 5px;
                   5725: }
                   5726: 
                   5727: div.LC_feedback_link img {
                   5728:   height: 22px;
1.867     kalberla 5729:   vertical-align:middle;
1.829     kalberla 5730: }
                   5731: 
1.911     bisitz   5732: div.LC_feedback_link a {
1.829     kalberla 5733:   text-decoration: none;
1.489     raeburn  5734: }
1.795     www      5735: 
1.867     kalberla 5736: div.LC_comblock {
1.911     bisitz   5737:   display:inline;
1.867     kalberla 5738:   color:$font;
                   5739:   font-size:90%;
                   5740: }
                   5741: 
                   5742: div.LC_feedback_link div.LC_comblock {
                   5743:   padding-left:5px;
                   5744: }
                   5745: 
                   5746: div.LC_feedback_link div.LC_comblock a {
                   5747:   color:$font;
                   5748: }
                   5749: 
1.489     raeburn  5750: span.LC_feedback_link {
1.858     bisitz   5751:   /* background: $feedback_link_bg; */
1.599     albertel 5752:   font-size: larger;
                   5753: }
1.795     www      5754: 
1.599     albertel 5755: span.LC_message_link {
1.858     bisitz   5756:   /* background: $feedback_link_bg; */
1.599     albertel 5757:   font-size: larger;
                   5758:   position: absolute;
                   5759:   right: 1em;
1.489     raeburn  5760: }
1.421     albertel 5761: 
1.515     albertel 5762: table.LC_prior_tries {
1.524     albertel 5763:   border: 1px solid #000000;
                   5764:   border-collapse: separate;
                   5765:   border-spacing: 1px;
1.515     albertel 5766: }
1.523     albertel 5767: 
1.515     albertel 5768: table.LC_prior_tries td {
1.524     albertel 5769:   padding: 2px;
1.515     albertel 5770: }
1.523     albertel 5771: 
                   5772: .LC_answer_correct {
1.795     www      5773:   background: lightgreen;
                   5774:   color: darkgreen;
                   5775:   padding: 6px;
1.523     albertel 5776: }
1.795     www      5777: 
1.523     albertel 5778: .LC_answer_charged_try {
1.797     www      5779:   background: #FFAAAA;
1.795     www      5780:   color: darkred;
                   5781:   padding: 6px;
1.523     albertel 5782: }
1.795     www      5783: 
1.779     bisitz   5784: .LC_answer_not_charged_try,
1.523     albertel 5785: .LC_answer_no_grade,
                   5786: .LC_answer_late {
1.795     www      5787:   background: lightyellow;
1.523     albertel 5788:   color: black;
1.795     www      5789:   padding: 6px;
1.523     albertel 5790: }
1.795     www      5791: 
1.523     albertel 5792: .LC_answer_previous {
1.795     www      5793:   background: lightblue;
                   5794:   color: darkblue;
                   5795:   padding: 6px;
1.523     albertel 5796: }
1.795     www      5797: 
1.779     bisitz   5798: .LC_answer_no_message {
1.777     tempelho 5799:   background: #FFFFFF;
                   5800:   color: black;
1.795     www      5801:   padding: 6px;
1.779     bisitz   5802: }
1.795     www      5803: 
1.779     bisitz   5804: .LC_answer_unknown {
                   5805:   background: orange;
                   5806:   color: black;
1.795     www      5807:   padding: 6px;
1.777     tempelho 5808: }
1.795     www      5809: 
1.529     albertel 5810: span.LC_prior_numerical,
                   5811: span.LC_prior_string,
                   5812: span.LC_prior_custom,
                   5813: span.LC_prior_reaction,
                   5814: span.LC_prior_math {
1.925     bisitz   5815:   font-family: $mono;
1.523     albertel 5816:   white-space: pre;
                   5817: }
                   5818: 
1.525     albertel 5819: span.LC_prior_string {
1.925     bisitz   5820:   font-family: $mono;
1.525     albertel 5821:   white-space: pre;
                   5822: }
                   5823: 
1.523     albertel 5824: table.LC_prior_option {
                   5825:   width: 100%;
                   5826:   border-collapse: collapse;
                   5827: }
1.795     www      5828: 
1.911     bisitz   5829: table.LC_prior_rank,
1.795     www      5830: table.LC_prior_match {
1.528     albertel 5831:   border-collapse: collapse;
                   5832: }
1.795     www      5833: 
1.528     albertel 5834: table.LC_prior_option tr td,
                   5835: table.LC_prior_rank tr td,
                   5836: table.LC_prior_match tr td {
1.524     albertel 5837:   border: 1px solid #000000;
1.515     albertel 5838: }
                   5839: 
1.855     bisitz   5840: .LC_nobreak {
1.544     albertel 5841:   white-space: nowrap;
1.519     raeburn  5842: }
                   5843: 
1.576     raeburn  5844: span.LC_cusr_emph {
                   5845:   font-style: italic;
                   5846: }
                   5847: 
1.633     raeburn  5848: span.LC_cusr_subheading {
                   5849:   font-weight: normal;
                   5850:   font-size: 85%;
                   5851: }
                   5852: 
1.861     bisitz   5853: div.LC_docs_entry_move {
1.859     bisitz   5854:   border: 1px solid #BBBBBB;
1.545     albertel 5855:   background: #DDDDDD;
1.861     bisitz   5856:   width: 22px;
1.859     bisitz   5857:   padding: 1px;
                   5858:   margin: 0;
1.545     albertel 5859: }
                   5860: 
1.861     bisitz   5861: table.LC_data_table tr > td.LC_docs_entry_commands,
                   5862: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545     albertel 5863:   background: #DDDDDD;
                   5864:   font-size: x-small;
                   5865: }
1.795     www      5866: 
1.861     bisitz   5867: .LC_docs_entry_parameter {
                   5868:   white-space: nowrap;
                   5869: }
                   5870: 
1.544     albertel 5871: .LC_docs_copy {
1.545     albertel 5872:   color: #000099;
1.544     albertel 5873: }
1.795     www      5874: 
1.544     albertel 5875: .LC_docs_cut {
1.545     albertel 5876:   color: #550044;
1.544     albertel 5877: }
1.795     www      5878: 
1.544     albertel 5879: .LC_docs_rename {
1.545     albertel 5880:   color: #009900;
1.544     albertel 5881: }
1.795     www      5882: 
1.544     albertel 5883: .LC_docs_remove {
1.545     albertel 5884:   color: #990000;
                   5885: }
                   5886: 
1.547     albertel 5887: .LC_docs_reinit_warn,
                   5888: .LC_docs_ext_edit {
                   5889:   font-size: x-small;
                   5890: }
                   5891: 
1.545     albertel 5892: table.LC_docs_adddocs td,
                   5893: table.LC_docs_adddocs th {
                   5894:   border: 1px solid #BBBBBB;
                   5895:   padding: 4px;
                   5896:   background: #DDDDDD;
1.543     albertel 5897: }
                   5898: 
1.584     albertel 5899: table.LC_sty_begin {
                   5900:   background: #BBFFBB;
                   5901: }
1.795     www      5902: 
1.584     albertel 5903: table.LC_sty_end {
                   5904:   background: #FFBBBB;
                   5905: }
                   5906: 
1.589     raeburn  5907: table.LC_double_column {
1.803     bisitz   5908:   border-width: 0;
1.589     raeburn  5909:   border-collapse: collapse;
                   5910:   width: 100%;
                   5911:   padding: 2px;
                   5912: }
                   5913: 
                   5914: table.LC_double_column tr td.LC_left_col {
1.590     raeburn  5915:   top: 2px;
1.589     raeburn  5916:   left: 2px;
                   5917:   width: 47%;
                   5918:   vertical-align: top;
                   5919: }
                   5920: 
                   5921: table.LC_double_column tr td.LC_right_col {
                   5922:   top: 2px;
1.779     bisitz   5923:   right: 2px;
1.589     raeburn  5924:   width: 47%;
                   5925:   vertical-align: top;
                   5926: }
                   5927: 
1.591     raeburn  5928: div.LC_left_float {
                   5929:   float: left;
                   5930:   padding-right: 5%;
1.597     albertel 5931:   padding-bottom: 4px;
1.591     raeburn  5932: }
                   5933: 
                   5934: div.LC_clear_float_header {
1.597     albertel 5935:   padding-bottom: 2px;
1.591     raeburn  5936: }
                   5937: 
                   5938: div.LC_clear_float_footer {
1.597     albertel 5939:   padding-top: 10px;
1.591     raeburn  5940:   clear: both;
                   5941: }
                   5942: 
1.597     albertel 5943: div.LC_grade_show_user {
1.941     bisitz   5944: /*  border-left: 5px solid $sidebg; */
                   5945:   border-top: 5px solid #000000;
                   5946:   margin: 50px 0 0 0;
1.936     bisitz   5947:   padding: 15px 0 5px 10px;
1.597     albertel 5948: }
1.795     www      5949: 
1.936     bisitz   5950: div.LC_grade_show_user_odd_row {
1.941     bisitz   5951: /*  border-left: 5px solid #000000; */
                   5952: }
                   5953: 
                   5954: div.LC_grade_show_user div.LC_Box {
                   5955:   margin-right: 50px;
1.597     albertel 5956: }
                   5957: 
                   5958: div.LC_grade_submissions,
                   5959: div.LC_grade_message_center,
1.936     bisitz   5960: div.LC_grade_info_links {
1.597     albertel 5961:   margin: 5px;
                   5962:   width: 99%;
                   5963:   background: #FFFFFF;
                   5964: }
1.795     www      5965: 
1.597     albertel 5966: div.LC_grade_submissions_header,
1.936     bisitz   5967: div.LC_grade_message_center_header {
1.705     tempelho 5968:   font-weight: bold;
                   5969:   font-size: large;
1.597     albertel 5970: }
1.795     www      5971: 
1.597     albertel 5972: div.LC_grade_submissions_body,
1.936     bisitz   5973: div.LC_grade_message_center_body {
1.597     albertel 5974:   border: 1px solid black;
                   5975:   width: 99%;
                   5976:   background: #FFFFFF;
                   5977: }
1.795     www      5978: 
1.613     albertel 5979: table.LC_scantron_action {
                   5980:   width: 100%;
                   5981: }
1.795     www      5982: 
1.613     albertel 5983: table.LC_scantron_action tr th {
1.698     harmsja  5984:   font-weight:bold;
                   5985:   font-style:normal;
1.613     albertel 5986: }
1.795     www      5987: 
1.779     bisitz   5988: .LC_edit_problem_header,
1.614     albertel 5989: div.LC_edit_problem_footer {
1.705     tempelho 5990:   font-weight: normal;
                   5991:   font-size:  medium;
1.602     albertel 5992:   margin: 2px;
1.600     albertel 5993: }
1.795     www      5994: 
1.600     albertel 5995: div.LC_edit_problem_header,
1.602     albertel 5996: div.LC_edit_problem_header div,
1.614     albertel 5997: div.LC_edit_problem_footer,
                   5998: div.LC_edit_problem_footer div,
1.602     albertel 5999: div.LC_edit_problem_editxml_header,
                   6000: div.LC_edit_problem_editxml_header div {
1.600     albertel 6001:   margin-top: 5px;
                   6002: }
1.795     www      6003: 
1.600     albertel 6004: div.LC_edit_problem_header_title {
1.705     tempelho 6005:   font-weight: bold;
                   6006:   font-size: larger;
1.602     albertel 6007:   background: $tabbg;
                   6008:   padding: 3px;
                   6009: }
1.795     www      6010: 
1.602     albertel 6011: table.LC_edit_problem_header_title {
                   6012:   width: 100%;
1.600     albertel 6013:   background: $tabbg;
1.602     albertel 6014: }
                   6015: 
                   6016: div.LC_edit_problem_discards {
                   6017:   float: left;
                   6018:   padding-bottom: 5px;
                   6019: }
1.795     www      6020: 
1.602     albertel 6021: div.LC_edit_problem_saves {
                   6022:   float: right;
                   6023:   padding-bottom: 5px;
1.600     albertel 6024: }
1.795     www      6025: 
1.911     bisitz   6026: img.stift {
1.803     bisitz   6027:   border-width: 0;
                   6028:   vertical-align: middle;
1.677     riegler  6029: }
1.680     riegler  6030: 
1.923     bisitz   6031: table td.LC_mainmenu_col_fieldset {
1.680     riegler  6032:   vertical-align: top;
1.777     tempelho 6033: }
1.795     www      6034: 
1.716     raeburn  6035: div.LC_createcourse {
1.911     bisitz   6036:   margin: 10px 10px 10px 10px;
1.716     raeburn  6037: }
                   6038: 
1.917     raeburn  6039: .LC_dccid {
                   6040:   margin: 0.2em 0 0 0;
                   6041:   padding: 0;
                   6042:   font-size: 90%;
                   6043:   display:none;
                   6044: }
                   6045: 
1.698     harmsja  6046: a:hover,
1.897     wenzelju 6047: ol.LC_primary_menu a:hover,
1.721     harmsja  6048: ol#LC_MenuBreadcrumbs a:hover,
                   6049: ol#LC_PathBreadcrumbs a:hover,
1.897     wenzelju 6050: ul#LC_secondary_menu a:hover,
1.721     harmsja  6051: .LC_FormSectionClearButton input:hover
1.795     www      6052: ul.LC_TabContent   li:hover a {
1.948.2.1  raeburn  6053:   color:$button_hover;
1.911     bisitz   6054:   text-decoration:none;
1.693     droeschl 6055: }
                   6056: 
1.779     bisitz   6057: h1 {
1.911     bisitz   6058:   padding: 0;
                   6059:   line-height:130%;
1.693     droeschl 6060: }
1.698     harmsja  6061: 
1.911     bisitz   6062: h2,
                   6063: h3,
                   6064: h4,
                   6065: h5,
                   6066: h6 {
                   6067:   margin: 5px 0 5px 0;
                   6068:   padding: 0;
                   6069:   line-height:130%;
1.693     droeschl 6070: }
1.795     www      6071: 
                   6072: .LC_hcell {
1.911     bisitz   6073:   padding:3px 15px 3px 15px;
                   6074:   margin: 0;
                   6075:   background-color:$tabbg;
                   6076:   color:$fontmenu;
                   6077:   border-bottom:solid 1px $lg_border_color;
1.693     droeschl 6078: }
1.795     www      6079: 
1.840     bisitz   6080: .LC_Box > .LC_hcell {
1.911     bisitz   6081:   margin: 0 -10px 10px -10px;
1.835     bisitz   6082: }
                   6083: 
1.721     harmsja  6084: .LC_noBorder {
1.911     bisitz   6085:   border: 0;
1.698     harmsja  6086: }
1.693     droeschl 6087: 
1.721     harmsja  6088: .LC_FormSectionClearButton input {
1.911     bisitz   6089:   background-color:transparent;
                   6090:   border: none;
                   6091:   cursor:pointer;
                   6092:   text-decoration:underline;
1.693     droeschl 6093: }
1.763     bisitz   6094: 
                   6095: .LC_help_open_topic {
1.911     bisitz   6096:   color: #FFFFFF;
                   6097:   background-color: #EEEEFF;
                   6098:   margin: 1px;
                   6099:   padding: 4px;
                   6100:   border: 1px solid #000033;
                   6101:   white-space: nowrap;
                   6102:   /* vertical-align: middle; */
1.759     neumanie 6103: }
1.693     droeschl 6104: 
1.911     bisitz   6105: dl,
                   6106: ul,
                   6107: div,
                   6108: fieldset {
                   6109:   margin: 10px 10px 10px 0;
                   6110:   /* overflow: hidden; */
1.693     droeschl 6111: }
1.795     www      6112: 
1.838     bisitz   6113: fieldset > legend {
1.911     bisitz   6114:   font-weight: bold;
                   6115:   padding: 0 5px 0 5px;
1.838     bisitz   6116: }
                   6117: 
1.813     bisitz   6118: #LC_nav_bar {
1.911     bisitz   6119:   float: left;
1.948.2.6  raeburn  6120:   margin: 0 0 2px 0;
1.807     droeschl 6121: }
                   6122: 
1.916     droeschl 6123: #LC_realm {
                   6124:   margin: 0.2em 0 0 0;
                   6125:   padding: 0;
                   6126:   font-weight: bold;
                   6127:   text-align: center;
                   6128: }
                   6129: 
1.911     bisitz   6130: #LC_nav_bar em {
                   6131:   font-weight: bold;
                   6132:   font-style: normal;
1.807     droeschl 6133: }
                   6134: 
1.948.2.6  raeburn  6135: /* Preliminary fix to hide nav_bar inside bookmarks window */
                   6136: #LC_bookmarks #LC_nav_bar {
                   6137:   display:none;
                   6138: }
                   6139: 
1.897     wenzelju 6140: ol.LC_primary_menu {
1.911     bisitz   6141:   float: right;
1.934     droeschl 6142:   margin: 0;
1.807     droeschl 6143: }
                   6144: 
1.929     wenzelju 6145: span.LC_new_message{
                   6146:   font-weight:bold;
                   6147:   color: darkred;
                   6148: }
                   6149: 
1.852     droeschl 6150: ol#LC_PathBreadcrumbs {
1.911     bisitz   6151:   margin: 0;
1.693     droeschl 6152: }
                   6153: 
1.897     wenzelju 6154: ol.LC_primary_menu li {
1.911     bisitz   6155:   display: inline;
                   6156:   padding: 5px 5px 0 10px;
                   6157:   vertical-align: top;
1.693     droeschl 6158: }
                   6159: 
1.897     wenzelju 6160: ol.LC_primary_menu li img {
1.911     bisitz   6161:   vertical-align: bottom;
1.934     droeschl 6162:   height: 1.1em;
1.693     droeschl 6163: }
                   6164: 
1.897     wenzelju 6165: ol.LC_primary_menu a {
1.911     bisitz   6166:   color: RGB(80, 80, 80);
                   6167:   text-decoration: none;
1.693     droeschl 6168: }
1.795     www      6169: 
1.948.2.7  raeburn  6170: ol.LC_docs_parameters {
                   6171:   margin-left: 0;
                   6172:   padding: 0;
                   6173:   list-style: none;
                   6174: }
                   6175: 
                   6176: ol.LC_docs_parameters li {
                   6177:   margin: 0;
                   6178:   padding-right: 20px;
                   6179:   display: inline;
                   6180: }
                   6181: 
                   6182: ol.LC_docs_parameters li:before {
                   6183:   content: "\\002022 \\0020";
                   6184: }
                   6185: 
                   6186: li.LC_docs_parameters_title {
                   6187:   font-weight: bold;
                   6188: }
                   6189: 
                   6190: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
                   6191:   content: "";
                   6192: }
                   6193: 
1.897     wenzelju 6194: ul#LC_secondary_menu {
1.911     bisitz   6195:   clear: both;
                   6196:   color: $fontmenu;
                   6197:   background: $tabbg;
                   6198:   list-style: none;
                   6199:   padding: 0;
                   6200:   margin: 0;
                   6201:   width: 100%;
1.808     droeschl 6202: }
                   6203: 
1.897     wenzelju 6204: ul#LC_secondary_menu li {
1.911     bisitz   6205:   font-weight: bold;
                   6206:   line-height: 1.8em;
                   6207:   padding: 0 0.8em;
                   6208:   border-right: 1px solid black;
                   6209:   display: inline;
                   6210:   vertical-align: middle;
1.807     droeschl 6211: }
                   6212: 
1.847     tempelho 6213: ul.LC_TabContent {
1.911     bisitz   6214:   display:block;
                   6215:   background: $sidebg;
                   6216:   border-bottom: solid 1px $lg_border_color;
                   6217:   list-style:none;
                   6218:   margin: 0 -10px;
                   6219:   padding: 0;
1.693     droeschl 6220: }
                   6221: 
1.795     www      6222: ul.LC_TabContent li,
                   6223: ul.LC_TabContentBigger li {
1.911     bisitz   6224:   float:left;
1.741     harmsja  6225: }
1.795     www      6226: 
1.897     wenzelju 6227: ul#LC_secondary_menu li a {
1.911     bisitz   6228:   color: $fontmenu;
                   6229:   text-decoration: none;
1.693     droeschl 6230: }
1.795     www      6231: 
1.721     harmsja  6232: ul.LC_TabContent {
1.948.2.1  raeburn  6233:   min-height:20px;
1.721     harmsja  6234: }
1.795     www      6235: 
                   6236: ul.LC_TabContent li {
1.911     bisitz   6237:   vertical-align:middle;
1.948.2.3  raeburn  6238:   padding: 0 16px 0 10px;
1.911     bisitz   6239:   background-color:$tabbg;
                   6240:   border-bottom:solid 1px $lg_border_color;
1.948.2.1  raeburn  6241:   border-right: solid 1px $font;
1.721     harmsja  6242: }
1.795     www      6243: 
1.847     tempelho 6244: ul.LC_TabContent .right {
1.911     bisitz   6245:   float:right;
1.847     tempelho 6246: }
                   6247: 
1.911     bisitz   6248: ul.LC_TabContent li a,
                   6249: ul.LC_TabContent li {
                   6250:   color:rgb(47,47,47);
                   6251:   text-decoration:none;
                   6252:   font-size:95%;
                   6253:   font-weight:bold;
1.948.2.1  raeburn  6254:   min-height:20px;
                   6255: }
                   6256: 
1.948.2.3  raeburn  6257: ul.LC_TabContent li a:hover,
                   6258: ul.LC_TabContent li a:focus {
1.948.2.1  raeburn  6259:   color: $button_hover;
1.948.2.3  raeburn  6260:   background:none;
                   6261:   outline:none;
1.948.2.1  raeburn  6262: }
                   6263: 
                   6264: ul.LC_TabContent li:hover {
                   6265:   color: $button_hover;
                   6266:   cursor:pointer;
1.721     harmsja  6267: }
1.795     www      6268: 
1.911     bisitz   6269: ul.LC_TabContent li.active {
1.948.2.1  raeburn  6270:   color: $font;
1.911     bisitz   6271:   background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.948.2.1  raeburn  6272:   border-bottom:solid 1px #FFFFFF;
                   6273:   cursor: default;
1.744     ehlerst  6274: }
1.795     www      6275: 
1.948.2.3  raeburn  6276: ul.LC_TabContent li.active a {
                   6277:   color:$font;
                   6278:   background:#FFFFFF;
                   6279:   outline: none;
                   6280: }
1.870     tempelho 6281: #maincoursedoc {
1.911     bisitz   6282:   clear:both;
1.870     tempelho 6283: }
                   6284: 
                   6285: ul.LC_TabContentBigger {
1.911     bisitz   6286:   display:block;
                   6287:   list-style:none;
                   6288:   padding: 0;
1.870     tempelho 6289: }
                   6290: 
1.795     www      6291: ul.LC_TabContentBigger li {
1.911     bisitz   6292:   vertical-align:bottom;
                   6293:   height: 30px;
                   6294:   font-size:110%;
                   6295:   font-weight:bold;
                   6296:   color: #737373;
1.841     tempelho 6297: }
                   6298: 
1.948.2.3  raeburn  6299: ul.LC_TabContentBigger li.active {
                   6300:   position: relative;
                   6301:   top: 1px;
                   6302: }
1.870     tempelho 6303: 
                   6304: ul.LC_TabContentBigger li a {
1.911     bisitz   6305:   background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
                   6306:   height: 30px;
                   6307:   line-height: 30px;
                   6308:   text-align: center;
                   6309:   display: block;
                   6310:   text-decoration: none;
1.948.2.3  raeburn  6311:   outline: none;
1.741     harmsja  6312: }
1.795     www      6313: 
1.870     tempelho 6314: ul.LC_TabContentBigger li.active a {
1.911     bisitz   6315:   background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
                   6316:   color:$font;
1.744     ehlerst  6317: }
1.795     www      6318: 
1.870     tempelho 6319: ul.LC_TabContentBigger li b {
1.911     bisitz   6320:   background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
                   6321:   display: block;
                   6322:   float: left;
                   6323:   padding: 0 30px;
1.948.2.3  raeburn  6324:   border-bottom: 1px solid $lg_border_color;
                   6325: }
                   6326: 
                   6327: ul.LC_TabContentBigger li:hover b {
                   6328:   color:$button_hover;
1.870     tempelho 6329: }
                   6330: 
                   6331: ul.LC_TabContentBigger li.active b {
1.911     bisitz   6332:   background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
                   6333:   color:$font;
1.948.2.3  raeburn  6334:   border: 0;
                   6335:   cursor:default;
1.741     harmsja  6336: }
1.693     droeschl 6337: 
1.862     bisitz   6338: ul.LC_CourseBreadcrumbs {
                   6339:   background: $sidebg;
                   6340:   line-height: 32px;
                   6341:   padding-left: 10px;
                   6342:   margin: 0 0 10px 0;
                   6343:   list-style-position: inside;
                   6344: 
                   6345: }
                   6346: 
1.911     bisitz   6347: ol#LC_MenuBreadcrumbs,
1.862     bisitz   6348: ol#LC_PathBreadcrumbs {
1.911     bisitz   6349:   padding-left: 10px;
                   6350:   margin: 0;
1.933     droeschl 6351:   height: 2.5em;  /* equal to #LC_breadcrumbs line-height */
1.693     droeschl 6352: }
                   6353: 
1.911     bisitz   6354: ol#LC_MenuBreadcrumbs li,
                   6355: ol#LC_PathBreadcrumbs li,
1.862     bisitz   6356: ul.LC_CourseBreadcrumbs li {
1.911     bisitz   6357:   display: inline;
1.933     droeschl 6358:   white-space: normal;  
1.693     droeschl 6359: }
                   6360: 
1.823     bisitz   6361: ol#LC_MenuBreadcrumbs li a,
1.862     bisitz   6362: ul.LC_CourseBreadcrumbs li a {
1.911     bisitz   6363:   text-decoration: none;
                   6364:   font-size:90%;
1.693     droeschl 6365: }
1.795     www      6366: 
1.948.2.7  raeburn  6367: ol#LC_MenuBreadcrumbs h1 {
                   6368:   display: inline;
                   6369:   font-size: 90%;
                   6370:   line-height: 2.5em;
                   6371:   margin: 0;
                   6372:   padding: 0;
                   6373: }
                   6374: 
1.795     www      6375: ol#LC_PathBreadcrumbs li a {
1.911     bisitz   6376:   text-decoration:none;
                   6377:   font-size:100%;
                   6378:   font-weight:bold;
1.693     droeschl 6379: }
1.795     www      6380: 
1.840     bisitz   6381: .LC_Box {
1.911     bisitz   6382:   border: solid 1px $lg_border_color;
                   6383:   padding: 0 10px 10px 10px;
1.746     neumanie 6384: }
1.795     www      6385: 
                   6386: .LC_AboutMe_Image {
1.911     bisitz   6387:   float:left;
                   6388:   margin-right:10px;
1.747     neumanie 6389: }
1.795     www      6390: 
                   6391: .LC_Clear_AboutMe_Image {
1.911     bisitz   6392:   clear:left;
1.747     neumanie 6393: }
1.795     www      6394: 
1.721     harmsja  6395: dl.LC_ListStyleClean dt {
1.911     bisitz   6396:   padding-right: 5px;
                   6397:   display: table-header-group;
1.693     droeschl 6398: }
                   6399: 
1.721     harmsja  6400: dl.LC_ListStyleClean dd {
1.911     bisitz   6401:   display: table-row;
1.693     droeschl 6402: }
                   6403: 
1.721     harmsja  6404: .LC_ListStyleClean,
                   6405: .LC_ListStyleSimple,
                   6406: .LC_ListStyleNormal,
1.795     www      6407: .LC_ListStyleSpecial {
1.911     bisitz   6408:   /* display:block; */
                   6409:   list-style-position: inside;
                   6410:   list-style-type: none;
                   6411:   overflow: hidden;
                   6412:   padding: 0;
1.693     droeschl 6413: }
                   6414: 
1.721     harmsja  6415: .LC_ListStyleSimple li,
                   6416: .LC_ListStyleSimple dd,
                   6417: .LC_ListStyleNormal li,
                   6418: .LC_ListStyleNormal dd,
                   6419: .LC_ListStyleSpecial li,
1.795     www      6420: .LC_ListStyleSpecial dd {
1.911     bisitz   6421:   margin: 0;
                   6422:   padding: 5px 5px 5px 10px;
                   6423:   clear: both;
1.693     droeschl 6424: }
                   6425: 
1.721     harmsja  6426: .LC_ListStyleClean li,
                   6427: .LC_ListStyleClean dd {
1.911     bisitz   6428:   padding-top: 0;
                   6429:   padding-bottom: 0;
1.693     droeschl 6430: }
                   6431: 
1.721     harmsja  6432: .LC_ListStyleSimple dd,
1.795     www      6433: .LC_ListStyleSimple li {
1.911     bisitz   6434:   border-bottom: solid 1px $lg_border_color;
1.693     droeschl 6435: }
                   6436: 
1.721     harmsja  6437: .LC_ListStyleSpecial li,
                   6438: .LC_ListStyleSpecial dd {
1.911     bisitz   6439:   list-style-type: none;
                   6440:   background-color: RGB(220, 220, 220);
                   6441:   margin-bottom: 4px;
1.693     droeschl 6442: }
                   6443: 
1.721     harmsja  6444: table.LC_SimpleTable {
1.911     bisitz   6445:   margin:5px;
                   6446:   border:solid 1px $lg_border_color;
1.795     www      6447: }
1.693     droeschl 6448: 
1.721     harmsja  6449: table.LC_SimpleTable tr {
1.911     bisitz   6450:   padding: 0;
                   6451:   border:solid 1px $lg_border_color;
1.693     droeschl 6452: }
1.795     www      6453: 
                   6454: table.LC_SimpleTable thead {
1.911     bisitz   6455:   background:rgb(220,220,220);
1.693     droeschl 6456: }
                   6457: 
1.721     harmsja  6458: div.LC_columnSection {
1.911     bisitz   6459:   display: block;
                   6460:   clear: both;
                   6461:   overflow: hidden;
                   6462:   margin: 0;
1.693     droeschl 6463: }
                   6464: 
1.721     harmsja  6465: div.LC_columnSection>* {
1.911     bisitz   6466:   float: left;
                   6467:   margin: 10px 20px 10px 0;
                   6468:   overflow:hidden;
1.693     droeschl 6469: }
1.721     harmsja  6470: 
1.795     www      6471: table em {
1.911     bisitz   6472:   font-weight: bold;
                   6473:   font-style: normal;
1.748     schulted 6474: }
1.795     www      6475: 
1.779     bisitz   6476: table.LC_tableBrowseRes,
1.795     www      6477: table.LC_tableOfContent {
1.911     bisitz   6478:   border:none;
                   6479:   border-spacing: 1px;
                   6480:   padding: 3px;
                   6481:   background-color: #FFFFFF;
                   6482:   font-size: 90%;
1.753     droeschl 6483: }
1.789     droeschl 6484: 
1.911     bisitz   6485: table.LC_tableOfContent {
                   6486:   border-collapse: collapse;
1.789     droeschl 6487: }
                   6488: 
1.771     droeschl 6489: table.LC_tableBrowseRes a,
1.768     schulted 6490: table.LC_tableOfContent a {
1.911     bisitz   6491:   background-color: transparent;
                   6492:   text-decoration: none;
1.753     droeschl 6493: }
                   6494: 
1.795     www      6495: table.LC_tableOfContent img {
1.911     bisitz   6496:   border: none;
                   6497:   height: 1.3em;
                   6498:   vertical-align: text-bottom;
                   6499:   margin-right: 0.3em;
1.753     droeschl 6500: }
1.757     schulted 6501: 
1.795     www      6502: a#LC_content_toolbar_firsthomework {
1.911     bisitz   6503:   background-image:url(/res/adm/pages/open-first-problem.gif);
1.774     ehlerst  6504: }
                   6505: 
1.795     www      6506: a#LC_content_toolbar_launchnav {
1.911     bisitz   6507:   background-image:url(/res/adm/pages/start-navigation.gif);
1.774     ehlerst  6508: }
                   6509: 
1.795     www      6510: a#LC_content_toolbar_closenav {
1.911     bisitz   6511:   background-image:url(/res/adm/pages/close-navigation.gif);
1.774     ehlerst  6512: }
                   6513: 
1.795     www      6514: a#LC_content_toolbar_everything {
1.911     bisitz   6515:   background-image:url(/res/adm/pages/show-all.gif);
1.774     ehlerst  6516: }
                   6517: 
1.795     www      6518: a#LC_content_toolbar_uncompleted {
1.911     bisitz   6519:   background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774     ehlerst  6520: }
                   6521: 
1.795     www      6522: #LC_content_toolbar_clearbubbles {
1.911     bisitz   6523:   background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774     ehlerst  6524: }
                   6525: 
1.795     www      6526: a#LC_content_toolbar_changefolder {
1.911     bisitz   6527:   background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757     schulted 6528: }
                   6529: 
1.795     www      6530: a#LC_content_toolbar_changefolder_toggled {
1.911     bisitz   6531:   background-image:url(/res/adm/pages/open-all-folders.gif);
1.757     schulted 6532: }
                   6533: 
1.795     www      6534: ul#LC_toolbar li a:hover {
1.911     bisitz   6535:   background-position: bottom center;
1.757     schulted 6536: }
                   6537: 
1.795     www      6538: ul#LC_toolbar {
1.911     bisitz   6539:   padding: 0;
                   6540:   margin: 2px;
                   6541:   list-style:none;
                   6542:   position:relative;
                   6543:   background-color:white;
1.757     schulted 6544: }
                   6545: 
1.795     www      6546: ul#LC_toolbar li {
1.911     bisitz   6547:   border:1px solid white;
                   6548:   padding: 0;
                   6549:   margin: 0;
                   6550:   float: left;
                   6551:   display:inline;
                   6552:   vertical-align:middle;
                   6553: }
1.757     schulted 6554: 
1.783     amueller 6555: 
1.795     www      6556: a.LC_toolbarItem {
1.911     bisitz   6557:   display:block;
                   6558:   padding: 0;
                   6559:   margin: 0;
                   6560:   height: 32px;
                   6561:   width: 32px;
                   6562:   color:white;
                   6563:   border: none;
                   6564:   background-repeat:no-repeat;
                   6565:   background-color:transparent;
1.757     schulted 6566: }
                   6567: 
1.915     droeschl 6568: ul.LC_funclist {
                   6569:     margin: 0;
                   6570:     padding: 0.5em 1em 0.5em 0;
                   6571: }
                   6572: 
1.933     droeschl 6573: ul.LC_funclist > li:first-child {
                   6574:     font-weight:bold; 
                   6575:     margin-left:0.8em;
                   6576: }
                   6577: 
1.915     droeschl 6578: ul.LC_funclist + ul.LC_funclist {
                   6579:     /* 
                   6580:        left border as a seperator if we have more than
                   6581:        one list 
                   6582:     */
                   6583:     border-left: 1px solid $sidebg;
                   6584:     /* 
                   6585:        this hides the left border behind the border of the 
                   6586:        outer box if element is wrapped to the next 'line' 
                   6587:     */
                   6588:     margin-left: -1px;
                   6589: }
                   6590: 
1.843     bisitz   6591: ul.LC_funclist li {
1.915     droeschl 6592:   display: inline;
1.782     bisitz   6593:   white-space: nowrap;
1.915     droeschl 6594:   margin: 0 0 0 25px;
                   6595:   line-height: 150%;
1.782     bisitz   6596: }
                   6597: 
1.930     faziophi 6598: .ui-accordion .LC_advanced_toggle {
                   6599:   float: right;
                   6600:   font-size: 90%;
                   6601:   padding: 0px 4px
                   6602: }
1.757     schulted 6603: 
1.343     albertel 6604: END
                   6605: }
                   6606: 
1.306     albertel 6607: =pod
                   6608: 
                   6609: =item * &headtag()
                   6610: 
                   6611: Returns a uniform footer for LON-CAPA web pages.
                   6612: 
1.307     albertel 6613: Inputs: $title - optional title for the head
                   6614:         $head_extra - optional extra HTML to put inside the <head>
1.315     albertel 6615:         $args - optional arguments
1.319     albertel 6616:             force_register - if is true call registerurl so the remote is 
                   6617:                              informed
1.415     albertel 6618:             redirect       -> array ref of
                   6619:                                    1- seconds before redirect occurs
                   6620:                                    2- url to redirect to
                   6621:                                    3- whether the side effect should occur
1.315     albertel 6622:                            (side effect of setting 
                   6623:                                $env{'internal.head.redirect'} to the url 
                   6624:                                redirected too)
1.352     albertel 6625:             domain         -> force to color decorate a page for a specific
                   6626:                                domain
                   6627:             function       -> force usage of a specific rolish color scheme
                   6628:             bgcolor        -> override the default page bgcolor
1.460     albertel 6629:             no_auto_mt_title
                   6630:                            -> prevent &mt()ing the title arg
1.464     albertel 6631: 
1.306     albertel 6632: =cut
                   6633: 
                   6634: sub headtag {
1.313     albertel 6635:     my ($title,$head_extra,$args) = @_;
1.306     albertel 6636:     
1.363     albertel 6637:     my $function = $args->{'function'} || &get_users_function();
                   6638:     my $domain   = $args->{'domain'}   || &determinedomain();
                   6639:     my $bgcolor  = $args->{'bgcolor'}  || &designparm($function.'.pgbg',$domain);
1.418     albertel 6640:     my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458     albertel 6641: 		   $Apache::lonnet::perlvar{'lonVersion'},
1.531     albertel 6642: 		   #time(),
1.418     albertel 6643: 		   $env{'environment.color.timestamp'},
1.363     albertel 6644: 		   $function,$domain,$bgcolor);
                   6645: 
1.369     www      6646:     $url = '/adm/css/'.&escape($url).'.css';
1.363     albertel 6647: 
1.308     albertel 6648:     my $result =
                   6649: 	'<head>'.
1.461     albertel 6650: 	&font_settings();
1.319     albertel 6651: 
1.461     albertel 6652:     if (!$args->{'frameset'}) {
                   6653: 	$result .= &Apache::lonhtmlcommon::htmlareaheaders();
                   6654:     }
1.319     albertel 6655:     if ($args->{'force_register'}) {
                   6656: 	$result .= &Apache::lonmenu::registerurl(1);
                   6657:     }
1.436     albertel 6658:     if (!$args->{'no_nav_bar'} 
                   6659: 	&& !$args->{'only_body'}
                   6660: 	&& !$args->{'frameset'}) {
                   6661: 	$result .= &help_menu_js();
                   6662:     }
1.319     albertel 6663: 
1.314     albertel 6664:     if (ref($args->{'redirect'})) {
1.414     albertel 6665: 	my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315     albertel 6666: 	$url = &Apache::lonenc::check_encrypt($url);
1.414     albertel 6667: 	if (!$inhibit_continue) {
                   6668: 	    $env{'internal.head.redirect'} = $url;
                   6669: 	}
1.313     albertel 6670: 	$result.=<<ADDMETA
                   6671: <meta http-equiv="pragma" content="no-cache" />
1.344     albertel 6672: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313     albertel 6673: ADDMETA
                   6674:     }
1.306     albertel 6675:     if (!defined($title)) {
                   6676: 	$title = 'The LearningOnline Network with CAPA';
                   6677:     }
1.460     albertel 6678:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
                   6679:     $result .= '<title> LON-CAPA '.$title.'</title>'
1.414     albertel 6680: 	.'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
                   6681: 	.$head_extra;
1.306     albertel 6682:     return $result;
                   6683: }
                   6684: 
                   6685: =pod
                   6686: 
1.340     albertel 6687: =item * &font_settings()
                   6688: 
                   6689: Returns neccessary <meta> to set the proper encoding
                   6690: 
                   6691: Inputs: none
                   6692: 
                   6693: =cut
                   6694: 
                   6695: sub font_settings {
                   6696:     my $headerstring='';
1.647     www      6697:     if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340     albertel 6698: 	$headerstring.=
                   6699: 	    '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
                   6700:     }
                   6701:     return $headerstring;
                   6702: }
                   6703: 
1.341     albertel 6704: =pod
                   6705: 
                   6706: =item * &xml_begin()
                   6707: 
                   6708: Returns the needed doctype and <html>
                   6709: 
                   6710: Inputs: none
                   6711: 
                   6712: =cut
                   6713: 
                   6714: sub xml_begin {
                   6715:     my $output='';
                   6716: 
                   6717:     if ($env{'browser.mathml'}) {
                   6718: 	$output='<?xml version="1.0"?>'
                   6719:             #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
                   6720: #            .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
                   6721:             
                   6722: #	    .'<!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">] >'
                   6723: 	    .'<!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">'
                   6724:             .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" ' 
                   6725: 	    .'xmlns="http://www.w3.org/1999/xhtml">';
                   6726:     } else {
1.849     bisitz   6727: 	$output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
                   6728:            .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1.341     albertel 6729:     }
                   6730:     return $output;
                   6731: }
1.340     albertel 6732: 
                   6733: =pod
                   6734: 
1.306     albertel 6735: =item * &endheadtag()
                   6736: 
                   6737: Returns a uniform </head> for LON-CAPA web pages.
                   6738: 
                   6739: Inputs: none
                   6740: 
                   6741: =cut
                   6742: 
                   6743: sub endheadtag {
                   6744:     return '</head>';
                   6745: }
                   6746: 
                   6747: =pod
                   6748: 
                   6749: =item * &head()
                   6750: 
                   6751: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
                   6752: 
1.648     raeburn  6753: Inputs:
                   6754: 
                   6755: =over 4
                   6756: 
                   6757: $title - optional title for the page
                   6758: 
                   6759: $head_extra - optional extra HTML to put inside the <head>
                   6760: 
                   6761: =back
1.405     albertel 6762: 
1.306     albertel 6763: =cut
                   6764: 
                   6765: sub head {
1.325     albertel 6766:     my ($title,$head_extra,$args) = @_;
                   6767:     return &headtag($title,$head_extra,$args).&endheadtag();
1.306     albertel 6768: }
                   6769: 
                   6770: =pod
                   6771: 
                   6772: =item * &start_page()
                   6773: 
                   6774: Returns a complete <html> .. <body> section for LON-CAPA web pages.
                   6775: 
1.648     raeburn  6776: Inputs:
                   6777: 
                   6778: =over 4
                   6779: 
                   6780: $title - optional title for the page
                   6781: 
                   6782: $head_extra - optional extra HTML to incude inside the <head>
                   6783: 
                   6784: $args - additional optional args supported are:
                   6785: 
                   6786: =over 8
                   6787: 
                   6788:              only_body      -> is true will set &bodytag() onlybodytag
1.317     albertel 6789:                                     arg on
1.814     bisitz   6790:              no_nav_bar     -> is true will set &bodytag() no_nav_bar arg on
1.648     raeburn  6791:              add_entries    -> additional attributes to add to the  <body>
                   6792:              domain         -> force to color decorate a page for a 
1.317     albertel 6793:                                     specific domain
1.648     raeburn  6794:              function       -> force usage of a specific rolish color
1.317     albertel 6795:                                     scheme
1.648     raeburn  6796:              redirect       -> see &headtag()
                   6797:              bgcolor        -> override the default page bg color
                   6798:              js_ready       -> return a string ready for being used in 
1.317     albertel 6799:                                     a javascript writeln
1.648     raeburn  6800:              html_encode    -> return a string ready for being used in 
1.320     albertel 6801:                                     a html attribute
1.648     raeburn  6802:              force_register -> if is true will turn on the &bodytag()
1.317     albertel 6803:                                     $forcereg arg
1.648     raeburn  6804:              frameset       -> if true will start with a <frameset>
1.330     albertel 6805:                                     rather than <body>
1.648     raeburn  6806:              skip_phases    -> hash ref of 
1.338     albertel 6807:                                     head -> skip the <html><head> generation
                   6808:                                     body -> skip all <body> generation
1.648     raeburn  6809:              no_inline_link -> if true and in remote mode, don't show the 
1.361     albertel 6810:                                     'Switch To Inline Menu' link
1.648     raeburn  6811:              no_auto_mt_title -> prevent &mt()ing the title arg
                   6812:              inherit_jsmath -> when creating popup window in a page,
                   6813:                                     should it have jsmath forced on by the
                   6814:                                     current page
1.867     kalberla 6815:              bread_crumbs ->             Array containing breadcrumbs
1.948.2.12  raeburn  6816:              bread_crumbs_component ->  if exists show it as headline else show only the breadcrumbs
1.361     albertel 6817: 
1.648     raeburn  6818: =back
1.460     albertel 6819: 
1.648     raeburn  6820: =back
1.562     albertel 6821: 
1.306     albertel 6822: =cut
                   6823: 
                   6824: sub start_page {
1.309     albertel 6825:     my ($title,$head_extra,$args) = @_;
1.318     albertel 6826:     #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313     albertel 6827:     my %head_args;
1.352     albertel 6828:     foreach my $arg ('redirect','force_register','domain','function',
1.460     albertel 6829: 		     'bgcolor','frameset','no_nav_bar','only_body',
                   6830: 		     'no_auto_mt_title') {
1.319     albertel 6831: 	if (defined($args->{$arg})) {
1.324     raeburn  6832: 	    $head_args{$arg} = $args->{$arg};
1.319     albertel 6833: 	}
1.313     albertel 6834:     }
1.319     albertel 6835: 
1.315     albertel 6836:     $env{'internal.start_page'}++;
1.338     albertel 6837:     my $result;
                   6838:     if (! exists($args->{'skip_phases'}{'head'}) ) {
                   6839: 	$result.=
1.341     albertel 6840: 	    &xml_begin().
1.338     albertel 6841: 	    &headtag($title,$head_extra,\%head_args).&endheadtag();
                   6842:     }
                   6843:     
                   6844:     if (! exists($args->{'skip_phases'}{'body'}) ) {
                   6845: 	if ($args->{'frameset'}) {
                   6846: 	    my $attr_string = &make_attr_string($args->{'force_register'},
                   6847: 						$args->{'add_entries'});
                   6848: 	    $result .= "\n<frameset $attr_string>\n";
1.831     bisitz   6849:         } else {
                   6850:             $result .=
                   6851:                 &bodytag($title, 
                   6852:                          $args->{'function'},       $args->{'add_entries'},
                   6853:                          $args->{'only_body'},      $args->{'domain'},
                   6854:                          $args->{'force_register'}, $args->{'no_nav_bar'},
                   6855:                          $args->{'bgcolor'},        $args->{'no_inline_link'},
                   6856:                          $args);
                   6857:         }
1.330     albertel 6858:     }
1.338     albertel 6859: 
1.315     albertel 6860:     if ($args->{'js_ready'}) {
1.713     kaisler  6861: 		$result = &js_ready($result);
1.315     albertel 6862:     }
1.320     albertel 6863:     if ($args->{'html_encode'}) {
1.713     kaisler  6864: 		$result = &html_encode($result);
                   6865:     }
                   6866: 
1.813     bisitz   6867:     # Preparation for new and consistent functionlist at top of screen
                   6868:     # if ($args->{'functionlist'}) {
                   6869:     #            $result .= &build_functionlist();
                   6870:     #}
                   6871: 
                   6872:     # Don't add anything more if only_body wanted
                   6873:     return $result if $args->{'only_body'};
                   6874: 
1.920     raeburn  6875:     #Breadcrumbs for Construction Space provided by &bodytag. 
                   6876:     if (($env{'environment.remote'} eq 'off') && ($env{'request.state'} eq 'construct')) {
                   6877:         return $result;
                   6878:     }
                   6879:  
1.813     bisitz   6880:     #Breadcrumbs
1.758     kaisler  6881:     if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
                   6882: 		&Apache::lonhtmlcommon::clear_breadcrumbs();
                   6883: 		#if any br links exists, add them to the breadcrumbs
                   6884: 		if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {         
                   6885: 			foreach my $crumb (@{$args->{'bread_crumbs'}}){
                   6886: 				&Apache::lonhtmlcommon::add_breadcrumb($crumb);
                   6887: 			}
                   6888: 		}
                   6889: 
                   6890: 		#if bread_crumbs_component exists show it as headline else show only the breadcrumbs
                   6891: 		if(exists($args->{'bread_crumbs_component'})){
                   6892: 			$result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
                   6893: 		}else{
                   6894: 			$result .= &Apache::lonhtmlcommon::breadcrumbs();
                   6895: 		}
1.320     albertel 6896:     }
1.315     albertel 6897:     return $result;
1.306     albertel 6898: }
                   6899: 
1.330     albertel 6900: 
1.306     albertel 6901: =pod
                   6902: 
                   6903: =item * &head()
                   6904: 
                   6905: Returns a complete </body></html> section for LON-CAPA web pages.
                   6906: 
1.315     albertel 6907: Inputs:         $args - additional optional args supported are:
                   6908:                  js_ready     -> return a string ready for being used in 
                   6909:                                  a javascript writeln
1.320     albertel 6910:                  html_encode  -> return a string ready for being used in 
                   6911:                                  a html attribute
1.330     albertel 6912:                  frameset     -> if true will start with a <frameset>
                   6913:                                  rather than <body>
1.493     albertel 6914:                  dicsussion   -> if true will get discussion from
                   6915:                                   lonxml::xmlend
                   6916:                                  (you can pass the target and parser arguments
                   6917:                                   through optional 'target' and 'parser' args
                   6918:                                   to this routine)
1.306     albertel 6919: 
                   6920: =cut
                   6921: 
                   6922: sub end_page {
1.315     albertel 6923:     my ($args) = @_;
                   6924:     $env{'internal.end_page'}++;
1.330     albertel 6925:     my $result;
1.335     albertel 6926:     if ($args->{'discussion'}) {
                   6927: 	my ($target,$parser);
                   6928: 	if (ref($args->{'discussion'})) {
                   6929: 	    ($target,$parser) =($args->{'discussion'}{'target'},
                   6930: 				$args->{'discussion'}{'parser'});
                   6931: 	}
                   6932: 	$result .= &Apache::lonxml::xmlend($target,$parser);
                   6933:     }
                   6934: 
1.330     albertel 6935:     if ($args->{'frameset'}) {
                   6936: 	$result .= '</frameset>';
                   6937:     } else {
1.635     raeburn  6938: 	$result .= &endbodytag($args);
1.330     albertel 6939:     }
                   6940:     $result .= "\n</html>";
                   6941: 
1.315     albertel 6942:     if ($args->{'js_ready'}) {
1.317     albertel 6943: 	$result = &js_ready($result);
1.315     albertel 6944:     }
1.335     albertel 6945: 
1.320     albertel 6946:     if ($args->{'html_encode'}) {
                   6947: 	$result = &html_encode($result);
                   6948:     }
1.335     albertel 6949: 
1.315     albertel 6950:     return $result;
                   6951: }
                   6952: 
1.320     albertel 6953: sub html_encode {
                   6954:     my ($result) = @_;
                   6955: 
1.322     albertel 6956:     $result = &HTML::Entities::encode($result,'<>&"');
1.320     albertel 6957:     
                   6958:     return $result;
                   6959: }
1.317     albertel 6960: sub js_ready {
                   6961:     my ($result) = @_;
                   6962: 
1.323     albertel 6963:     $result =~ s/[\n\r]/ /xmsg;
                   6964:     $result =~ s/\\/\\\\/xmsg;
                   6965:     $result =~ s/'/\\'/xmsg;
1.372     albertel 6966:     $result =~ s{</}{<\\/}xmsg;
1.317     albertel 6967:     
                   6968:     return $result;
                   6969: }
                   6970: 
1.315     albertel 6971: sub validate_page {
                   6972:     if (  exists($env{'internal.start_page'})
1.316     albertel 6973: 	  &&     $env{'internal.start_page'} > 1) {
                   6974: 	&Apache::lonnet::logthis('start_page called multiple times '.
1.318     albertel 6975: 				 $env{'internal.start_page'}.' '.
1.316     albertel 6976: 				 $ENV{'request.filename'});
1.315     albertel 6977:     }
                   6978:     if (  exists($env{'internal.end_page'})
1.316     albertel 6979: 	  &&     $env{'internal.end_page'} > 1) {
                   6980: 	&Apache::lonnet::logthis('end_page called multiple times '.
1.318     albertel 6981: 				 $env{'internal.end_page'}.' '.
1.316     albertel 6982: 				 $env{'request.filename'});
1.315     albertel 6983:     }
                   6984:     if (     exists($env{'internal.start_page'})
                   6985: 	&& ! exists($env{'internal.end_page'})) {
1.316     albertel 6986: 	&Apache::lonnet::logthis('start_page called without end_page '.
                   6987: 				 $env{'request.filename'});
1.315     albertel 6988:     }
                   6989:     if (   ! exists($env{'internal.start_page'})
                   6990: 	&&   exists($env{'internal.end_page'})) {
1.316     albertel 6991: 	&Apache::lonnet::logthis('end_page called without start_page'.
                   6992: 				 $env{'request.filename'});
1.315     albertel 6993:     }
1.306     albertel 6994: }
1.315     albertel 6995: 
1.318     albertel 6996: sub simple_error_page {
                   6997:     my ($r,$title,$msg) = @_;
                   6998:     my $page =
                   6999: 	&Apache::loncommon::start_page($title).
                   7000: 	&mt($msg).
                   7001: 	&Apache::loncommon::end_page();
                   7002:     if (ref($r)) {
                   7003: 	$r->print($page);
1.327     albertel 7004: 	return;
1.318     albertel 7005:     }
                   7006:     return $page;
                   7007: }
1.347     albertel 7008: 
                   7009: {
1.610     albertel 7010:     my @row_count;
1.948.2.5  raeburn  7011: 
                   7012:     sub start_data_table_count {
                   7013:         unshift(@row_count, 0);
                   7014:         return;
                   7015:     }
                   7016: 
                   7017:     sub end_data_table_count {
                   7018:         shift(@row_count);
                   7019:         return;
                   7020:     }
                   7021: 
1.347     albertel 7022:     sub start_data_table {
1.422     albertel 7023: 	my ($add_class) = @_;
                   7024: 	my $css_class = (join(' ','LC_data_table',$add_class));
1.948.2.5  raeburn  7025:         &start_data_table_count();
1.422     albertel 7026: 	return '<table class="'.$css_class.'">'."\n";
1.347     albertel 7027:     }
                   7028: 
                   7029:     sub end_data_table {
1.948.2.5  raeburn  7030:         &end_data_table_count();
1.389     albertel 7031: 	return '</table>'."\n";;
1.347     albertel 7032:     }
                   7033: 
                   7034:     sub start_data_table_row {
1.422     albertel 7035: 	my ($add_class) = @_;
1.610     albertel 7036: 	$row_count[0]++;
                   7037: 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900     bisitz   7038: 	$css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.422     albertel 7039: 	return  '<tr class="'.$css_class.'">'."\n";;
1.347     albertel 7040:     }
1.471     banghart 7041:     
                   7042:     sub continue_data_table_row {
                   7043: 	my ($add_class) = @_;
1.610     albertel 7044: 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900     bisitz   7045: 	$css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');;
1.471     banghart 7046: 	return  '<tr class="'.$css_class.'">'."\n";;
                   7047:     }
1.347     albertel 7048: 
                   7049:     sub end_data_table_row {
1.389     albertel 7050: 	return '</tr>'."\n";;
1.347     albertel 7051:     }
1.367     www      7052: 
1.421     albertel 7053:     sub start_data_table_empty_row {
1.707     bisitz   7054: #	$row_count[0]++;
1.421     albertel 7055: 	return  '<tr class="LC_empty_row" >'."\n";;
                   7056:     }
                   7057: 
                   7058:     sub end_data_table_empty_row {
                   7059: 	return '</tr>'."\n";;
                   7060:     }
                   7061: 
1.367     www      7062:     sub start_data_table_header_row {
1.389     albertel 7063: 	return  '<tr class="LC_header_row">'."\n";;
1.367     www      7064:     }
                   7065: 
                   7066:     sub end_data_table_header_row {
1.389     albertel 7067: 	return '</tr>'."\n";;
1.367     www      7068:     }
1.890     droeschl 7069: 
                   7070:     sub data_table_caption {
                   7071:         my $caption = shift;
                   7072:         return "<caption class=\"LC_caption\">$caption</caption>";
                   7073:     }
1.347     albertel 7074: }
                   7075: 
1.548     albertel 7076: =pod
                   7077: 
                   7078: =item * &inhibit_menu_check($arg)
                   7079: 
                   7080: Checks for a inhibitmenu state and generates output to preserve it
                   7081: 
                   7082: Inputs:         $arg - can be any of
                   7083:                      - undef - in which case the return value is a string 
                   7084:                                to add  into arguments list of a uri
                   7085:                      - 'input' - in which case the return value is a HTML
                   7086:                                  <form> <input> field of type hidden to
                   7087:                                  preserve the value
                   7088:                      - a url - in which case the return value is the url with
                   7089:                                the neccesary cgi args added to preserve the
                   7090:                                inhibitmenu state
                   7091:                      - a ref to a url - no return value, but the string is
                   7092:                                         updated to include the neccessary cgi
                   7093:                                         args to preserve the inhibitmenu state
                   7094: 
                   7095: =cut
                   7096: 
                   7097: sub inhibit_menu_check {
                   7098:     my ($arg) = @_;
                   7099:     &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
                   7100:     if ($arg eq 'input') {
                   7101: 	if ($env{'form.inhibitmenu'}) {
                   7102: 	    return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
                   7103: 	} else {
                   7104: 	    return
                   7105: 	}
                   7106:     }
                   7107:     if ($env{'form.inhibitmenu'}) {
                   7108: 	if (ref($arg)) {
                   7109: 	    $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
                   7110: 	} elsif ($arg eq '') {
                   7111: 	    $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
                   7112: 	} else {
                   7113: 	    $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
                   7114: 	}
                   7115:     }
                   7116:     if (!ref($arg)) {
                   7117: 	return $arg;
                   7118:     }
                   7119: }
                   7120: 
1.251     albertel 7121: ###############################################
1.182     matthew  7122: 
                   7123: =pod
                   7124: 
1.549     albertel 7125: =back
                   7126: 
                   7127: =head1 User Information Routines
                   7128: 
                   7129: =over 4
                   7130: 
1.405     albertel 7131: =item * &get_users_function()
1.182     matthew  7132: 
                   7133: Used by &bodytag to determine the current users primary role.
                   7134: Returns either 'student','coordinator','admin', or 'author'.
                   7135: 
                   7136: =cut
                   7137: 
                   7138: ###############################################
                   7139: sub get_users_function {
1.815     tempelho 7140:     my $function = 'norole';
1.818     tempelho 7141:     if ($env{'request.role'}=~/^(st)/) {
                   7142:         $function='student';
                   7143:     }
1.907     raeburn  7144:     if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182     matthew  7145:         $function='coordinator';
                   7146:     }
1.258     albertel 7147:     if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182     matthew  7148:         $function='admin';
                   7149:     }
1.826     bisitz   7150:     if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.182     matthew  7151:         ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
                   7152:         $function='author';
                   7153:     }
                   7154:     return $function;
1.54      www      7155: }
1.99      www      7156: 
                   7157: ###############################################
                   7158: 
1.233     raeburn  7159: =pod
                   7160: 
1.821     raeburn  7161: =item * &show_course()
                   7162: 
                   7163: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
                   7164: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
                   7165: 
                   7166: Inputs:
                   7167: None
                   7168: 
                   7169: Outputs:
                   7170: Scalar: 1 if 'Course' to be used, 0 otherwise.
                   7171: 
                   7172: =cut
                   7173: 
                   7174: ###############################################
                   7175: sub show_course {
                   7176:     my $course = !$env{'user.adv'};
                   7177:     if (!$env{'user.adv'}) {
                   7178:         foreach my $env (keys(%env)) {
                   7179:             next if ($env !~ m/^user\.priv\./);
                   7180:             if ($env !~ m/^user\.priv\.(?:st|cm)/) {
                   7181:                 $course = 0;
                   7182:                 last;
                   7183:             }
                   7184:         }
                   7185:     }
                   7186:     return $course;
                   7187: }
                   7188: 
                   7189: ###############################################
                   7190: 
                   7191: =pod
                   7192: 
1.542     raeburn  7193: =item * &check_user_status()
1.274     raeburn  7194: 
                   7195: Determines current status of supplied role for a
                   7196: specific user. Roles can be active, previous or future.
                   7197: 
                   7198: Inputs: 
                   7199: user's domain, user's username, course's domain,
1.375     raeburn  7200: course's number, optional section ID.
1.274     raeburn  7201: 
                   7202: Outputs:
                   7203: role status: active, previous or future. 
                   7204: 
                   7205: =cut
                   7206: 
                   7207: sub check_user_status {
1.412     raeburn  7208:     my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.948.2.11  raeburn  7209:     my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});
                   7210:     my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname,'.',undef,$extra);
1.274     raeburn  7211:     my @uroles = keys %userinfo;
                   7212:     my $srchstr;
                   7213:     my $active_chk = 'none';
1.412     raeburn  7214:     my $now = time;
1.274     raeburn  7215:     if (@uroles > 0) {
1.908     raeburn  7216:         if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274     raeburn  7217:             $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
                   7218:         } else {
1.412     raeburn  7219:             $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
                   7220:         }
                   7221:         if (grep/^\Q$srchstr\E$/,@uroles) {
1.274     raeburn  7222:             my $role_end = 0;
                   7223:             my $role_start = 0;
                   7224:             $active_chk = 'active';
1.412     raeburn  7225:             if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
                   7226:                 $role_end = $1;
                   7227:                 if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
                   7228:                     $role_start = $1;
1.274     raeburn  7229:                 }
                   7230:             }
                   7231:             if ($role_start > 0) {
1.412     raeburn  7232:                 if ($now < $role_start) {
1.274     raeburn  7233:                     $active_chk = 'future';
                   7234:                 }
                   7235:             }
                   7236:             if ($role_end > 0) {
1.412     raeburn  7237:                 if ($now > $role_end) {
1.274     raeburn  7238:                     $active_chk = 'previous';
                   7239:                 }
                   7240:             }
                   7241:         }
                   7242:     }
                   7243:     return $active_chk;
                   7244: }
                   7245: 
                   7246: ###############################################
                   7247: 
                   7248: =pod
                   7249: 
1.405     albertel 7250: =item * &get_sections()
1.233     raeburn  7251: 
                   7252: Determines all the sections for a course including
                   7253: sections with students and sections containing other roles.
1.419     raeburn  7254: Incoming parameters: 
                   7255: 
                   7256: 1. domain
                   7257: 2. course number 
                   7258: 3. reference to array containing roles for which sections should 
                   7259: be gathered (optional).
                   7260: 4. reference to array containing status types for which sections 
                   7261: should be gathered (optional).
                   7262: 
                   7263: If the third argument is undefined, sections are gathered for any role. 
                   7264: If the fourth argument is undefined, sections are gathered for any status.
                   7265: Permissible values are 'active' or 'future' or 'previous'.
1.233     raeburn  7266:  
1.374     raeburn  7267: Returns section hash (keys are section IDs, values are
                   7268: number of users in each section), subject to the
1.419     raeburn  7269: optional roles filter, optional status filter 
1.233     raeburn  7270: 
                   7271: =cut
                   7272: 
                   7273: ###############################################
                   7274: sub get_sections {
1.419     raeburn  7275:     my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366     albertel 7276:     if (!defined($cdom) || !defined($cnum)) {
                   7277:         my $cid =  $env{'request.course.id'};
                   7278: 
                   7279: 	return if (!defined($cid));
                   7280: 
                   7281:         $cdom = $env{'course.'.$cid.'.domain'};
                   7282:         $cnum = $env{'course.'.$cid.'.num'};
                   7283:     }
                   7284: 
                   7285:     my %sectioncount;
1.419     raeburn  7286:     my $now = time;
1.240     albertel 7287: 
1.366     albertel 7288:     if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276     albertel 7289: 	my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240     albertel 7290: 	my $sec_index = &Apache::loncoursedata::CL_SECTION();
                   7291: 	my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419     raeburn  7292:         my $start_index = &Apache::loncoursedata::CL_START();
                   7293:         my $end_index = &Apache::loncoursedata::CL_END();
                   7294:         my $status;
1.366     albertel 7295: 	while (my ($student,$data) = each(%$classlist)) {
1.419     raeburn  7296: 	    my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
                   7297: 				                     $data->[$status_index],
                   7298:                                                      $data->[$start_index],
                   7299:                                                      $data->[$end_index]);
                   7300:             if ($stu_status eq 'Active') {
                   7301:                 $status = 'active';
                   7302:             } elsif ($end < $now) {
                   7303:                 $status = 'previous';
                   7304:             } elsif ($start > $now) {
                   7305:                 $status = 'future';
                   7306:             } 
                   7307: 	    if ($section ne '-1' && $section !~ /^\s*$/) {
                   7308:                 if ((!defined($possible_status)) || (($status ne '') && 
                   7309:                     (grep/^\Q$status\E$/,@{$possible_status}))) { 
                   7310: 		    $sectioncount{$section}++;
                   7311:                 }
1.240     albertel 7312: 	    }
                   7313: 	}
                   7314:     }
                   7315:     my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   7316:     foreach my $user (sort(keys(%courseroles))) {
                   7317: 	if ($user !~ /^(\w{2})/) { next; }
                   7318: 	my ($role) = ($user =~ /^(\w{2})/);
                   7319: 	if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419     raeburn  7320: 	my ($section,$status);
1.240     albertel 7321: 	if ($role eq 'cr' &&
                   7322: 	    $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
                   7323: 	    $section=$1;
                   7324: 	}
                   7325: 	if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
                   7326: 	if (!defined($section) || $section eq '-1') { next; }
1.419     raeburn  7327:         my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
                   7328:         if ($end == -1 && $start == -1) {
                   7329:             next; #deleted role
                   7330:         }
                   7331:         if (!defined($possible_status)) { 
                   7332:             $sectioncount{$section}++;
                   7333:         } else {
                   7334:             if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
                   7335:                 $status = 'active';
                   7336:             } elsif ($end < $now) {
                   7337:                 $status = 'future';
                   7338:             } elsif ($start > $now) {
                   7339:                 $status = 'previous';
                   7340:             }
                   7341:             if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
                   7342:                 $sectioncount{$section}++;
                   7343:             }
                   7344:         }
1.233     raeburn  7345:     }
1.366     albertel 7346:     return %sectioncount;
1.233     raeburn  7347: }
                   7348: 
1.274     raeburn  7349: ###############################################
1.294     raeburn  7350: 
                   7351: =pod
1.405     albertel 7352: 
                   7353: =item * &get_course_users()
                   7354: 
1.275     raeburn  7355: Retrieves usernames:domains for users in the specified course
                   7356: with specific role(s), and access status. 
                   7357: 
                   7358: Incoming parameters:
1.277     albertel 7359: 1. course domain
                   7360: 2. course number
                   7361: 3. access status: users must have - either active, 
1.275     raeburn  7362: previous, future, or all.
1.277     albertel 7363: 4. reference to array of permissible roles
1.288     raeburn  7364: 5. reference to array of section restrictions (optional)
                   7365: 6. reference to results object (hash of hashes).
                   7366: 7. reference to optional userdata hash
1.609     raeburn  7367: 8. reference to optional statushash
1.630     raeburn  7368: 9. flag if privileged users (except those set to unhide in
                   7369:    course settings) should be excluded    
1.609     raeburn  7370: Keys of top level results hash are roles.
1.275     raeburn  7371: Keys of inner hashes are username:domain, with 
                   7372: values set to access type.
1.288     raeburn  7373: Optional userdata hash returns an array with arguments in the 
                   7374: same order as loncoursedata::get_classlist() for student data.
                   7375: 
1.609     raeburn  7376: Optional statushash returns
                   7377: 
1.288     raeburn  7378: Entries for end, start, section and status are blank because
                   7379: of the possibility of multiple values for non-student roles.
                   7380: 
1.275     raeburn  7381: =cut
1.405     albertel 7382: 
1.275     raeburn  7383: ###############################################
1.405     albertel 7384: 
1.275     raeburn  7385: sub get_course_users {
1.630     raeburn  7386:     my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288     raeburn  7387:     my %idx = ();
1.419     raeburn  7388:     my %seclists;
1.288     raeburn  7389: 
                   7390:     $idx{udom} = &Apache::loncoursedata::CL_SDOM();
                   7391:     $idx{uname} =  &Apache::loncoursedata::CL_SNAME();
                   7392:     $idx{end} = &Apache::loncoursedata::CL_END();
                   7393:     $idx{start} = &Apache::loncoursedata::CL_START();
                   7394:     $idx{id} = &Apache::loncoursedata::CL_ID();
                   7395:     $idx{section} = &Apache::loncoursedata::CL_SECTION();
                   7396:     $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
                   7397:     $idx{status} = &Apache::loncoursedata::CL_STATUS();
                   7398: 
1.290     albertel 7399:     if (grep(/^st$/,@{$roles})) {
1.276     albertel 7400:         my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278     raeburn  7401:         my $now = time;
1.277     albertel 7402:         foreach my $student (keys(%{$classlist})) {
1.288     raeburn  7403:             my $match = 0;
1.412     raeburn  7404:             my $secmatch = 0;
1.419     raeburn  7405:             my $section = $$classlist{$student}[$idx{section}];
1.609     raeburn  7406:             my $status = $$classlist{$student}[$idx{status}];
1.419     raeburn  7407:             if ($section eq '') {
                   7408:                 $section = 'none';
                   7409:             }
1.291     albertel 7410:             if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 7411:                 if (grep(/^all$/,@{$sections})) {
1.412     raeburn  7412:                     $secmatch = 1;
                   7413:                 } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420     albertel 7414:                     if (grep(/^none$/,@{$sections})) {
1.412     raeburn  7415:                         $secmatch = 1;
                   7416:                     }
                   7417:                 } else {  
1.419     raeburn  7418: 		    if (grep(/^\Q$section\E$/,@{$sections})) {
1.412     raeburn  7419: 		        $secmatch = 1;
                   7420:                     }
1.290     albertel 7421: 		}
1.412     raeburn  7422:                 if (!$secmatch) {
                   7423:                     next;
                   7424:                 }
1.419     raeburn  7425:             }
1.275     raeburn  7426:             if (defined($$types{'active'})) {
1.288     raeburn  7427:                 if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275     raeburn  7428:                     push(@{$$users{st}{$student}},'active');
1.288     raeburn  7429:                     $match = 1;
1.275     raeburn  7430:                 }
                   7431:             }
                   7432:             if (defined($$types{'previous'})) {
1.609     raeburn  7433:                 if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275     raeburn  7434:                     push(@{$$users{st}{$student}},'previous');
1.288     raeburn  7435:                     $match = 1;
1.275     raeburn  7436:                 }
                   7437:             }
                   7438:             if (defined($$types{'future'})) {
1.609     raeburn  7439:                 if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275     raeburn  7440:                     push(@{$$users{st}{$student}},'future');
1.288     raeburn  7441:                     $match = 1;
1.275     raeburn  7442:                 }
                   7443:             }
1.609     raeburn  7444:             if ($match) {
                   7445:                 push(@{$seclists{$student}},$section);
                   7446:                 if (ref($userdata) eq 'HASH') {
                   7447:                     $$userdata{$student} = $$classlist{$student};
                   7448:                 }
                   7449:                 if (ref($statushash) eq 'HASH') {
                   7450:                     $statushash->{$student}{'st'}{$section} = $status;
                   7451:                 }
1.288     raeburn  7452:             }
1.275     raeburn  7453:         }
                   7454:     }
1.412     raeburn  7455:     if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439     raeburn  7456:         my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   7457:         my $now = time;
1.609     raeburn  7458:         my %displaystatus = ( previous => 'Expired',
                   7459:                               active   => 'Active',
                   7460:                               future   => 'Future',
                   7461:                             );
1.630     raeburn  7462:         my %nothide;
                   7463:         if ($hidepriv) {
                   7464:             my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
                   7465:             foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
                   7466:                 if ($user !~ /:/) {
                   7467:                     $nothide{join(':',split(/[\@]/,$user))}=1;
                   7468:                 } else {
                   7469:                     $nothide{$user} = 1;
                   7470:                 }
                   7471:             }
                   7472:         }
1.439     raeburn  7473:         foreach my $person (sort(keys(%coursepersonnel))) {
1.288     raeburn  7474:             my $match = 0;
1.412     raeburn  7475:             my $secmatch = 0;
1.439     raeburn  7476:             my $status;
1.412     raeburn  7477:             my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275     raeburn  7478:             $user =~ s/:$//;
1.439     raeburn  7479:             my ($end,$start) = split(/:/,$coursepersonnel{$person});
                   7480:             if ($end == -1 || $start == -1) {
                   7481:                 next;
                   7482:             }
                   7483:             if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
                   7484:                 (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412     raeburn  7485:                 my ($uname,$udom) = split(/:/,$user);
                   7486:                 if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 7487:                     if (grep(/^all$/,@{$sections})) {
1.412     raeburn  7488:                         $secmatch = 1;
                   7489:                     } elsif ($usec eq '') {
1.420     albertel 7490:                         if (grep(/^none$/,@{$sections})) {
1.412     raeburn  7491:                             $secmatch = 1;
                   7492:                         }
                   7493:                     } else {
                   7494:                         if (grep(/^\Q$usec\E$/,@{$sections})) {
                   7495:                             $secmatch = 1;
                   7496:                         }
                   7497:                     }
                   7498:                     if (!$secmatch) {
                   7499:                         next;
                   7500:                     }
1.288     raeburn  7501:                 }
1.419     raeburn  7502:                 if ($usec eq '') {
                   7503:                     $usec = 'none';
                   7504:                 }
1.275     raeburn  7505:                 if ($uname ne '' && $udom ne '') {
1.630     raeburn  7506:                     if ($hidepriv) {
                   7507:                         if ((&Apache::lonnet::privileged($uname,$udom)) &&
                   7508:                             (!$nothide{$uname.':'.$udom})) {
                   7509:                             next;
                   7510:                         }
                   7511:                     }
1.503     raeburn  7512:                     if ($end > 0 && $end < $now) {
1.439     raeburn  7513:                         $status = 'previous';
                   7514:                     } elsif ($start > $now) {
                   7515:                         $status = 'future';
                   7516:                     } else {
                   7517:                         $status = 'active';
                   7518:                     }
1.277     albertel 7519:                     foreach my $type (keys(%{$types})) { 
1.275     raeburn  7520:                         if ($status eq $type) {
1.420     albertel 7521:                             if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419     raeburn  7522:                                 push(@{$$users{$role}{$user}},$type);
                   7523:                             }
1.288     raeburn  7524:                             $match = 1;
                   7525:                         }
                   7526:                     }
1.419     raeburn  7527:                     if (($match) && (ref($userdata) eq 'HASH')) {
                   7528:                         if (!exists($$userdata{$uname.':'.$udom})) {
                   7529: 			    &get_user_info($udom,$uname,\%idx,$userdata);
                   7530:                         }
1.420     albertel 7531:                         if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419     raeburn  7532:                             push(@{$seclists{$uname.':'.$udom}},$usec);
                   7533:                         }
1.609     raeburn  7534:                         if (ref($statushash) eq 'HASH') {
                   7535:                             $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
                   7536:                         }
1.275     raeburn  7537:                     }
                   7538:                 }
                   7539:             }
                   7540:         }
1.290     albertel 7541:         if (grep(/^ow$/,@{$roles})) {
1.279     raeburn  7542:             if ((defined($cdom)) && (defined($cnum))) {
                   7543:                 my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
                   7544:                 if ( defined($csettings{'internal.courseowner'}) ) {
                   7545:                     my $owner = $csettings{'internal.courseowner'};
1.609     raeburn  7546:                     next if ($owner eq '');
                   7547:                     my ($ownername,$ownerdom);
                   7548:                     if ($owner =~ /^([^:]+):([^:]+)$/) {
                   7549:                         $ownername = $1;
                   7550:                         $ownerdom = $2;
                   7551:                     } else {
                   7552:                         $ownername = $owner;
                   7553:                         $ownerdom = $cdom;
                   7554:                         $owner = $ownername.':'.$ownerdom;
1.439     raeburn  7555:                     }
                   7556:                     @{$$users{'ow'}{$owner}} = 'any';
1.290     albertel 7557:                     if (defined($userdata) && 
1.609     raeburn  7558: 			!exists($$userdata{$owner})) {
                   7559: 			&get_user_info($ownerdom,$ownername,\%idx,$userdata);
                   7560:                         if (!grep(/^none$/,@{$seclists{$owner}})) {
                   7561:                             push(@{$seclists{$owner}},'none');
                   7562:                         }
                   7563:                         if (ref($statushash) eq 'HASH') {
                   7564:                             $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419     raeburn  7565:                         }
1.290     albertel 7566: 		    }
1.279     raeburn  7567:                 }
                   7568:             }
                   7569:         }
1.419     raeburn  7570:         foreach my $user (keys(%seclists)) {
                   7571:             @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
                   7572:             $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
                   7573:         }
1.275     raeburn  7574:     }
                   7575:     return;
                   7576: }
                   7577: 
1.288     raeburn  7578: sub get_user_info {
                   7579:     my ($udom,$uname,$idx,$userdata) = @_;
1.289     albertel 7580:     $$userdata{$uname.':'.$udom}[$$idx{fullname}] = 
                   7581: 	&plainname($uname,$udom,'lastname');
1.291     albertel 7582:     $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297     raeburn  7583:     $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609     raeburn  7584:     my %idhash =  &Apache::lonnet::idrget($udom,($uname));
                   7585:     $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname}; 
1.288     raeburn  7586:     return;
                   7587: }
1.275     raeburn  7588: 
1.472     raeburn  7589: ###############################################
                   7590: 
                   7591: =pod
                   7592: 
                   7593: =item * &get_user_quota()
                   7594: 
                   7595: Retrieves quota assigned for storage of portfolio files for a user  
                   7596: 
                   7597: Incoming parameters:
                   7598: 1. user's username
                   7599: 2. user's domain
                   7600: 
                   7601: Returns:
1.536     raeburn  7602: 1. Disk quota (in Mb) assigned to student.
                   7603: 2. (Optional) Type of setting: custom or default
                   7604:    (individually assigned or default for user's 
                   7605:    institutional status).
                   7606: 3. (Optional) - User's institutional status (e.g., faculty, staff
                   7607:    or student - types as defined in localenroll::inst_usertypes 
                   7608:    for user's domain, which determines default quota for user.
                   7609: 4. (Optional) - Default quota which would apply to the user.
1.472     raeburn  7610: 
                   7611: If a value has been stored in the user's environment, 
1.536     raeburn  7612: it will return that, otherwise it returns the maximal default
                   7613: defined for the user's instituional status(es) in the domain.
1.472     raeburn  7614: 
                   7615: =cut
                   7616: 
                   7617: ###############################################
                   7618: 
                   7619: 
                   7620: sub get_user_quota {
                   7621:     my ($uname,$udom) = @_;
1.536     raeburn  7622:     my ($quota,$quotatype,$settingstatus,$defquota);
1.472     raeburn  7623:     if (!defined($udom)) {
                   7624:         $udom = $env{'user.domain'};
                   7625:     }
                   7626:     if (!defined($uname)) {
                   7627:         $uname = $env{'user.name'};
                   7628:     }
                   7629:     if (($udom eq '' || $uname eq '') ||
                   7630:         ($udom eq 'public') && ($uname eq 'public')) {
                   7631:         $quota = 0;
1.536     raeburn  7632:         $quotatype = 'default';
                   7633:         $defquota = 0; 
1.472     raeburn  7634:     } else {
1.536     raeburn  7635:         my $inststatus;
1.472     raeburn  7636:         if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
                   7637:             $quota = $env{'environment.portfolioquota'};
1.536     raeburn  7638:             $inststatus = $env{'environment.inststatus'};
1.472     raeburn  7639:         } else {
1.536     raeburn  7640:             my %userenv = 
                   7641:                 &Apache::lonnet::get('environment',['portfolioquota',
                   7642:                                      'inststatus'],$udom,$uname);
1.472     raeburn  7643:             my ($tmp) = keys(%userenv);
                   7644:             if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   7645:                 $quota = $userenv{'portfolioquota'};
1.536     raeburn  7646:                 $inststatus = $userenv{'inststatus'};
1.472     raeburn  7647:             } else {
                   7648:                 undef(%userenv);
                   7649:             }
                   7650:         }
1.536     raeburn  7651:         ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472     raeburn  7652:         if ($quota eq '') {
1.536     raeburn  7653:             $quota = $defquota;
                   7654:             $quotatype = 'default';
                   7655:         } else {
                   7656:             $quotatype = 'custom';
1.472     raeburn  7657:         }
                   7658:     }
1.536     raeburn  7659:     if (wantarray) {
                   7660:         return ($quota,$quotatype,$settingstatus,$defquota);
                   7661:     } else {
                   7662:         return $quota;
                   7663:     }
1.472     raeburn  7664: }
                   7665: 
                   7666: ###############################################
                   7667: 
                   7668: =pod
                   7669: 
                   7670: =item * &default_quota()
                   7671: 
1.536     raeburn  7672: Retrieves default quota assigned for storage of user portfolio files,
                   7673: given an (optional) user's institutional status.
1.472     raeburn  7674: 
                   7675: Incoming parameters:
                   7676: 1. domain
1.536     raeburn  7677: 2. (Optional) institutional status(es).  This is a : separated list of 
                   7678:    status types (e.g., faculty, staff, student etc.)
                   7679:    which apply to the user for whom the default is being retrieved.
                   7680:    If the institutional status string in undefined, the domain
                   7681:    default quota will be returned. 
1.472     raeburn  7682: 
                   7683: Returns:
                   7684: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536     raeburn  7685: 2. (Optional) institutional type which determined the value of the
                   7686:    default quota.
1.472     raeburn  7687: 
                   7688: If a value has been stored in the domain's configuration db,
                   7689: it will return that, otherwise it returns 20 (for backwards 
                   7690: compatibility with domains which have not set up a configuration
                   7691: db file; the original statically defined portfolio quota was 20 Mb). 
                   7692: 
1.536     raeburn  7693: If the user's status includes multiple types (e.g., staff and student),
                   7694: the largest default quota which applies to the user determines the
                   7695: default quota returned.
                   7696: 
1.780     raeburn  7697: =back
                   7698: 
1.472     raeburn  7699: =cut
                   7700: 
                   7701: ###############################################
                   7702: 
                   7703: 
                   7704: sub default_quota {
1.536     raeburn  7705:     my ($udom,$inststatus) = @_;
                   7706:     my ($defquota,$settingstatus);
                   7707:     my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622     raeburn  7708:                                             ['quotas'],$udom);
                   7709:     if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536     raeburn  7710:         if ($inststatus ne '') {
1.765     raeburn  7711:             my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536     raeburn  7712:             foreach my $item (@statuses) {
1.711     raeburn  7713:                 if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
                   7714:                     if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
                   7715:                         if ($defquota eq '') {
                   7716:                             $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
                   7717:                             $settingstatus = $item;
                   7718:                         } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
                   7719:                             $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
                   7720:                             $settingstatus = $item;
                   7721:                         }
                   7722:                     }
                   7723:                 } else {
                   7724:                     if ($quotahash{'quotas'}{$item} ne '') {
                   7725:                         if ($defquota eq '') {
                   7726:                             $defquota = $quotahash{'quotas'}{$item};
                   7727:                             $settingstatus = $item;
                   7728:                         } elsif ($quotahash{'quotas'}{$item} > $defquota) {
                   7729:                             $defquota = $quotahash{'quotas'}{$item};
                   7730:                             $settingstatus = $item;
                   7731:                         }
1.536     raeburn  7732:                     }
                   7733:                 }
                   7734:             }
                   7735:         }
                   7736:         if ($defquota eq '') {
1.711     raeburn  7737:             if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
                   7738:                 $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
                   7739:             } else {
                   7740:                 $defquota = $quotahash{'quotas'}{'default'};
                   7741:             }
1.536     raeburn  7742:             $settingstatus = 'default';
                   7743:         }
                   7744:     } else {
                   7745:         $settingstatus = 'default';
                   7746:         $defquota = 20;
                   7747:     }
                   7748:     if (wantarray) {
                   7749:         return ($defquota,$settingstatus);
1.472     raeburn  7750:     } else {
1.536     raeburn  7751:         return $defquota;
1.472     raeburn  7752:     }
                   7753: }
                   7754: 
1.384     raeburn  7755: sub get_secgrprole_info {
                   7756:     my ($cdom,$cnum,$needroles,$type)  = @_;
                   7757:     my %sections_count = &get_sections($cdom,$cnum);
                   7758:     my @sections =  (sort {$a <=> $b} keys(%sections_count));
                   7759:     my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
                   7760:     my @groups = sort(keys(%curr_groups));
                   7761:     my $allroles = [];
                   7762:     my $rolehash;
                   7763:     my $accesshash = {
                   7764:                      active => 'Currently has access',
                   7765:                      future => 'Will have future access',
                   7766:                      previous => 'Previously had access',
                   7767:                   };
                   7768:     if ($needroles) {
                   7769:         $rolehash = {'all' => 'all'};
1.385     albertel 7770:         my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   7771: 	if (&Apache::lonnet::error(%user_roles)) {
                   7772: 	    undef(%user_roles);
                   7773: 	}
                   7774:         foreach my $item (keys(%user_roles)) {
1.384     raeburn  7775:             my ($role)=split(/\:/,$item,2);
                   7776:             if ($role eq 'cr') { next; }
                   7777:             if ($role =~ /^cr/) {
                   7778:                 $$rolehash{$role} = (split('/',$role))[3];
                   7779:             } else {
                   7780:                 $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
                   7781:             }
                   7782:         }
                   7783:         foreach my $key (sort(keys(%{$rolehash}))) {
                   7784:             push(@{$allroles},$key);
                   7785:         }
                   7786:         push (@{$allroles},'st');
                   7787:         $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
                   7788:     }
                   7789:     return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
                   7790: }
                   7791: 
1.555     raeburn  7792: sub user_picker {
1.627     raeburn  7793:     my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555     raeburn  7794:     my $currdom = $dom;
                   7795:     my %curr_selected = (
                   7796:                         srchin => 'dom',
1.580     raeburn  7797:                         srchby => 'lastname',
1.555     raeburn  7798:                       );
                   7799:     my $srchterm;
1.625     raeburn  7800:     if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555     raeburn  7801:         if ($srch->{'srchby'} ne '') {
                   7802:             $curr_selected{'srchby'} = $srch->{'srchby'};
                   7803:         }
                   7804:         if ($srch->{'srchin'} ne '') {
                   7805:             $curr_selected{'srchin'} = $srch->{'srchin'};
                   7806:         }
                   7807:         if ($srch->{'srchtype'} ne '') {
                   7808:             $curr_selected{'srchtype'} = $srch->{'srchtype'};
                   7809:         }
                   7810:         if ($srch->{'srchdomain'} ne '') {
                   7811:             $currdom = $srch->{'srchdomain'};
                   7812:         }
                   7813:         $srchterm = $srch->{'srchterm'};
                   7814:     }
                   7815:     my %lt=&Apache::lonlocal::texthash(
1.573     raeburn  7816:                     'usr'       => 'Search criteria',
1.563     raeburn  7817:                     'doma'      => 'Domain/institution to search',
1.558     albertel 7818:                     'uname'     => 'username',
                   7819:                     'lastname'  => 'last name',
1.555     raeburn  7820:                     'lastfirst' => 'last name, first name',
1.558     albertel 7821:                     'crs'       => 'in this course',
1.576     raeburn  7822:                     'dom'       => 'in selected LON-CAPA domain', 
1.558     albertel 7823:                     'alc'       => 'all LON-CAPA',
1.573     raeburn  7824:                     'instd'     => 'in institutional directory for selected domain',
1.558     albertel 7825:                     'exact'     => 'is',
                   7826:                     'contains'  => 'contains',
1.569     raeburn  7827:                     'begins'    => 'begins with',
1.571     raeburn  7828:                     'youm'      => "You must include some text to search for.",
                   7829:                     'thte'      => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
                   7830:                     'thet'      => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
                   7831:                     'yomc'      => "You must choose a domain when using an institutional directory search.",
                   7832:                     'ymcd'      => "You must choose a domain when using a domain search.",
                   7833:                     'whus'      => "When using searching by last,first you must include a comma as separator between last name and first name.",
                   7834:                     'whse'      => "When searching by last,first you must include at least one character in the first name.",
                   7835:                      'thfo'     => "The following need to be corrected before the search can be run:",
1.555     raeburn  7836:                                        );
1.563     raeburn  7837:     my $domform = &select_dom_form($currdom,'srchdomain',1,1);
                   7838:     my $srchinsel = ' <select name="srchin">';
1.555     raeburn  7839: 
                   7840:     my @srchins = ('crs','dom','alc','instd');
                   7841: 
                   7842:     foreach my $option (@srchins) {
                   7843:         # FIXME 'alc' option unavailable until 
                   7844:         #       loncreateuser::print_user_query_page()
                   7845:         #       has been completed.
                   7846:         next if ($option eq 'alc');
1.880     raeburn  7847:         next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));  
1.555     raeburn  7848:         next if ($option eq 'crs' && !$env{'request.course.id'});
1.563     raeburn  7849:         if ($curr_selected{'srchin'} eq $option) {
                   7850:             $srchinsel .= ' 
                   7851:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7852:         } else {
                   7853:             $srchinsel .= '
                   7854:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7855:         }
1.555     raeburn  7856:     }
1.563     raeburn  7857:     $srchinsel .= "\n  </select>\n";
1.555     raeburn  7858: 
                   7859:     my $srchbysel =  ' <select name="srchby">';
1.580     raeburn  7860:     foreach my $option ('lastname','lastfirst','uname') {
1.555     raeburn  7861:         if ($curr_selected{'srchby'} eq $option) {
                   7862:             $srchbysel .= '
                   7863:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7864:         } else {
                   7865:             $srchbysel .= '
                   7866:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7867:          }
                   7868:     }
                   7869:     $srchbysel .= "\n  </select>\n";
                   7870: 
                   7871:     my $srchtypesel = ' <select name="srchtype">';
1.580     raeburn  7872:     foreach my $option ('begins','contains','exact') {
1.555     raeburn  7873:         if ($curr_selected{'srchtype'} eq $option) {
                   7874:             $srchtypesel .= '
                   7875:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7876:         } else {
                   7877:             $srchtypesel .= '
                   7878:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7879:         }
                   7880:     }
                   7881:     $srchtypesel .= "\n  </select>\n";
                   7882: 
1.558     albertel 7883:     my ($newuserscript,$new_user_create);
1.556     raeburn  7884: 
                   7885:     if ($forcenewuser) {
1.576     raeburn  7886:         if (ref($srch) eq 'HASH') {
                   7887:             if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627     raeburn  7888:                 if ($cancreate) {
                   7889:                     $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>';
                   7890:                 } else {
1.799     bisitz   7891:                     my $helplink = 'javascript:helpMenu('."'display'".')';
1.627     raeburn  7892:                     my %usertypetext = (
                   7893:                         official   => 'institutional',
                   7894:                         unofficial => 'non-institutional',
                   7895:                     );
1.799     bisitz   7896:                     $new_user_create = '<p class="LC_warning">'
                   7897:                                       .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
                   7898:                                       .' '
                   7899:                                       .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
                   7900:                                           ,'<a href="'.$helplink.'">','</a>')
                   7901:                                       .'</p><br />';
1.627     raeburn  7902:                 }
1.576     raeburn  7903:             }
                   7904:         }
                   7905: 
1.556     raeburn  7906:         $newuserscript = <<"ENDSCRIPT";
                   7907: 
1.570     raeburn  7908: function setSearch(createnew,callingForm) {
1.556     raeburn  7909:     if (createnew == 1) {
1.570     raeburn  7910:         for (var i=0; i<callingForm.srchby.length; i++) {
                   7911:             if (callingForm.srchby.options[i].value == 'uname') {
                   7912:                 callingForm.srchby.selectedIndex = i;
1.556     raeburn  7913:             }
                   7914:         }
1.570     raeburn  7915:         for (var i=0; i<callingForm.srchin.length; i++) {
                   7916:             if ( callingForm.srchin.options[i].value == 'dom') {
                   7917: 		callingForm.srchin.selectedIndex = i;
1.556     raeburn  7918:             }
                   7919:         }
1.570     raeburn  7920:         for (var i=0; i<callingForm.srchtype.length; i++) {
                   7921:             if (callingForm.srchtype.options[i].value == 'exact') {
                   7922:                 callingForm.srchtype.selectedIndex = i;
1.556     raeburn  7923:             }
                   7924:         }
1.570     raeburn  7925:         for (var i=0; i<callingForm.srchdomain.length; i++) {
                   7926:             if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
                   7927:                 callingForm.srchdomain.selectedIndex = i;
1.556     raeburn  7928:             }
                   7929:         }
                   7930:     }
                   7931: }
                   7932: ENDSCRIPT
1.558     albertel 7933: 
1.556     raeburn  7934:     }
                   7935: 
1.555     raeburn  7936:     my $output = <<"END_BLOCK";
1.556     raeburn  7937: <script type="text/javascript">
1.824     bisitz   7938: // <![CDATA[
1.570     raeburn  7939: function validateEntry(callingForm) {
1.558     albertel 7940: 
1.556     raeburn  7941:     var checkok = 1;
1.558     albertel 7942:     var srchin;
1.570     raeburn  7943:     for (var i=0; i<callingForm.srchin.length; i++) {
                   7944: 	if ( callingForm.srchin[i].checked ) {
                   7945: 	    srchin = callingForm.srchin[i].value;
1.558     albertel 7946: 	}
                   7947:     }
                   7948: 
1.570     raeburn  7949:     var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
                   7950:     var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
                   7951:     var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
                   7952:     var srchterm =  callingForm.srchterm.value;
                   7953:     var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556     raeburn  7954:     var msg = "";
                   7955: 
                   7956:     if (srchterm == "") {
                   7957:         checkok = 0;
1.571     raeburn  7958:         msg += "$lt{'youm'}\\n";
1.556     raeburn  7959:     }
                   7960: 
1.569     raeburn  7961:     if (srchtype== 'begins') {
                   7962:         if (srchterm.length < 2) {
                   7963:             checkok = 0;
1.571     raeburn  7964:             msg += "$lt{'thte'}\\n";
1.569     raeburn  7965:         }
                   7966:     }
                   7967: 
1.556     raeburn  7968:     if (srchtype== 'contains') {
                   7969:         if (srchterm.length < 3) {
                   7970:             checkok = 0;
1.571     raeburn  7971:             msg += "$lt{'thet'}\\n";
1.556     raeburn  7972:         }
                   7973:     }
                   7974:     if (srchin == 'instd') {
                   7975:         if (srchdomain == '') {
                   7976:             checkok = 0;
1.571     raeburn  7977:             msg += "$lt{'yomc'}\\n";
1.556     raeburn  7978:         }
                   7979:     }
                   7980:     if (srchin == 'dom') {
                   7981:         if (srchdomain == '') {
                   7982:             checkok = 0;
1.571     raeburn  7983:             msg += "$lt{'ymcd'}\\n";
1.556     raeburn  7984:         }
                   7985:     }
                   7986:     if (srchby == 'lastfirst') {
                   7987:         if (srchterm.indexOf(",") == -1) {
                   7988:             checkok = 0;
1.571     raeburn  7989:             msg += "$lt{'whus'}\\n";
1.556     raeburn  7990:         }
                   7991:         if (srchterm.indexOf(",") == srchterm.length -1) {
                   7992:             checkok = 0;
1.571     raeburn  7993:             msg += "$lt{'whse'}\\n";
1.556     raeburn  7994:         }
                   7995:     }
                   7996:     if (checkok == 0) {
1.571     raeburn  7997:         alert("$lt{'thfo'}\\n"+msg);
1.556     raeburn  7998:         return;
                   7999:     }
                   8000:     if (checkok == 1) {
1.570     raeburn  8001:         callingForm.submit();
1.556     raeburn  8002:     }
                   8003: }
                   8004: 
                   8005: $newuserscript
                   8006: 
1.824     bisitz   8007: // ]]>
1.556     raeburn  8008: </script>
1.558     albertel 8009: 
                   8010: $new_user_create
                   8011: 
1.555     raeburn  8012: END_BLOCK
1.558     albertel 8013: 
1.876     raeburn  8014:     $output .= &Apache::lonhtmlcommon::start_pick_box().
                   8015:                &Apache::lonhtmlcommon::row_title($lt{'doma'}).
                   8016:                $domform.
                   8017:                &Apache::lonhtmlcommon::row_closure().
                   8018:                &Apache::lonhtmlcommon::row_title($lt{'usr'}).
                   8019:                $srchbysel.
                   8020:                $srchtypesel. 
                   8021:                '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
                   8022:                $srchinsel.
                   8023:                &Apache::lonhtmlcommon::row_closure(1). 
                   8024:                &Apache::lonhtmlcommon::end_pick_box().
                   8025:                '<br />';
1.555     raeburn  8026:     return $output;
                   8027: }
                   8028: 
1.612     raeburn  8029: sub user_rule_check {
1.615     raeburn  8030:     my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612     raeburn  8031:     my $response;
                   8032:     if (ref($usershash) eq 'HASH') {
                   8033:         foreach my $user (keys(%{$usershash})) {
                   8034:             my ($uname,$udom) = split(/:/,$user);
                   8035:             next if ($udom eq '' || $uname eq '');
1.615     raeburn  8036:             my ($id,$newuser);
1.612     raeburn  8037:             if (ref($usershash->{$user}) eq 'HASH') {
1.615     raeburn  8038:                 $newuser = $usershash->{$user}->{'newuser'};
1.612     raeburn  8039:                 $id = $usershash->{$user}->{'id'};
                   8040:             }
                   8041:             my $inst_response;
                   8042:             if (ref($checks) eq 'HASH') {
                   8043:                 if (defined($checks->{'username'})) {
1.615     raeburn  8044:                     ($inst_response,%{$inst_results->{$user}}) = 
1.612     raeburn  8045:                         &Apache::lonnet::get_instuser($udom,$uname);
                   8046:                 } elsif (defined($checks->{'id'})) {
1.615     raeburn  8047:                     ($inst_response,%{$inst_results->{$user}}) =
1.612     raeburn  8048:                         &Apache::lonnet::get_instuser($udom,undef,$id);
                   8049:                 }
1.615     raeburn  8050:             } else {
                   8051:                 ($inst_response,%{$inst_results->{$user}}) =
                   8052:                     &Apache::lonnet::get_instuser($udom,$uname);
                   8053:                 return;
1.612     raeburn  8054:             }
1.615     raeburn  8055:             if (!$got_rules->{$udom}) {
1.612     raeburn  8056:                 my %domconfig = &Apache::lonnet::get_dom('configuration',
                   8057:                                                   ['usercreation'],$udom);
                   8058:                 if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615     raeburn  8059:                     foreach my $item ('username','id') {
1.612     raeburn  8060:                         if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
                   8061:                             $$curr_rules{$udom}{$item} = 
                   8062:                                 $domconfig{'usercreation'}{$item.'_rule'};
1.585     raeburn  8063:                         }
                   8064:                     }
                   8065:                 }
1.615     raeburn  8066:                 $got_rules->{$udom} = 1;  
1.585     raeburn  8067:             }
1.612     raeburn  8068:             foreach my $item (keys(%{$checks})) {
                   8069:                 if (ref($$curr_rules{$udom}) eq 'HASH') {
                   8070:                     if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
                   8071:                         if (@{$$curr_rules{$udom}{$item}} > 0) {
                   8072:                             my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
                   8073:                             foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
                   8074:                                 if ($rule_check{$rule}) {
                   8075:                                     $$rulematch{$user}{$item} = $rule;
                   8076:                                     if ($inst_response eq 'ok') {
1.615     raeburn  8077:                                         if (ref($inst_results) eq 'HASH') {
                   8078:                                             if (ref($inst_results->{$user}) eq 'HASH') {
                   8079:                                                 if (keys(%{$inst_results->{$user}}) == 0) {
                   8080:                                                     $$alerts{$item}{$udom}{$uname} = 1;
                   8081:                                                 }
1.612     raeburn  8082:                                             }
                   8083:                                         }
1.615     raeburn  8084:                                     }
                   8085:                                     last;
1.585     raeburn  8086:                                 }
                   8087:                             }
                   8088:                         }
                   8089:                     }
                   8090:                 }
                   8091:             }
                   8092:         }
                   8093:     }
1.612     raeburn  8094:     return;
                   8095: }
                   8096: 
                   8097: sub user_rule_formats {
                   8098:     my ($domain,$domdesc,$curr_rules,$check) = @_;
                   8099:     my %text = ( 
                   8100:                  'username' => 'Usernames',
                   8101:                  'id'       => 'IDs',
                   8102:                );
                   8103:     my $output;
                   8104:     my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
                   8105:     if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
                   8106:         if (@{$ruleorder} > 0) {
                   8107:             $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>';
                   8108:             foreach my $rule (@{$ruleorder}) {
                   8109:                 if (ref($curr_rules) eq 'ARRAY') {
                   8110:                     if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
                   8111:                         if (ref($rules->{$rule}) eq 'HASH') {
                   8112:                             $output .= '<li>'.$rules->{$rule}{'name'}.': '.
                   8113:                                         $rules->{$rule}{'desc'}.'</li>';
                   8114:                         }
                   8115:                     }
                   8116:                 }
                   8117:             }
                   8118:             $output .= '</ul>';
                   8119:         }
                   8120:     }
                   8121:     return $output;
                   8122: }
                   8123: 
                   8124: sub instrule_disallow_msg {
1.615     raeburn  8125:     my ($checkitem,$domdesc,$count,$mode) = @_;
1.612     raeburn  8126:     my $response;
                   8127:     my %text = (
                   8128:                   item   => 'username',
                   8129:                   items  => 'usernames',
                   8130:                   match  => 'matches',
                   8131:                   do     => 'does',
                   8132:                   action => 'a username',
                   8133:                   one    => 'one',
                   8134:                );
                   8135:     if ($count > 1) {
                   8136:         $text{'item'} = 'usernames';
                   8137:         $text{'match'} ='match';
                   8138:         $text{'do'} = 'do';
                   8139:         $text{'action'} = 'usernames',
                   8140:         $text{'one'} = 'ones';
                   8141:     }
                   8142:     if ($checkitem eq 'id') {
                   8143:         $text{'items'} = 'IDs';
                   8144:         $text{'item'} = 'ID';
                   8145:         $text{'action'} = 'an ID';
1.615     raeburn  8146:         if ($count > 1) {
                   8147:             $text{'item'} = 'IDs';
                   8148:             $text{'action'} = 'IDs';
                   8149:         }
1.612     raeburn  8150:     }
1.674     bisitz   8151:     $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  8152:     if ($mode eq 'upload') {
                   8153:         if ($checkitem eq 'username') {
                   8154:             $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'}.");
                   8155:         } elsif ($checkitem eq 'id') {
1.674     bisitz   8156:             $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  8157:         }
1.669     raeburn  8158:     } elsif ($mode eq 'selfcreate') {
                   8159:         if ($checkitem eq 'id') {
                   8160:             $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.");
                   8161:         }
1.615     raeburn  8162:     } else {
                   8163:         if ($checkitem eq 'username') {
                   8164:             $response .= &mt("You must choose $text{'action'} with a different format --  $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
                   8165:         } elsif ($checkitem eq 'id') {
                   8166:             $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.");
                   8167:         }
1.612     raeburn  8168:     }
                   8169:     return $response;
1.585     raeburn  8170: }
                   8171: 
1.624     raeburn  8172: sub personal_data_fieldtitles {
                   8173:     my %fieldtitles = &Apache::lonlocal::texthash (
                   8174:                         id => 'Student/Employee ID',
                   8175:                         permanentemail => 'E-mail address',
                   8176:                         lastname => 'Last Name',
                   8177:                         firstname => 'First Name',
                   8178:                         middlename => 'Middle Name',
                   8179:                         generation => 'Generation',
                   8180:                         gen => 'Generation',
1.765     raeburn  8181:                         inststatus => 'Affiliation',
1.624     raeburn  8182:                    );
                   8183:     return %fieldtitles;
                   8184: }
                   8185: 
1.642     raeburn  8186: sub sorted_inst_types {
                   8187:     my ($dom) = @_;
                   8188:     my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
                   8189:     my $othertitle = &mt('All users');
                   8190:     if ($env{'request.course.id'}) {
1.668     raeburn  8191:         $othertitle  = &mt('Any users');
1.642     raeburn  8192:     }
                   8193:     my @types;
                   8194:     if (ref($order) eq 'ARRAY') {
                   8195:         @types = @{$order};
                   8196:     }
                   8197:     if (@types == 0) {
                   8198:         if (ref($usertypes) eq 'HASH') {
                   8199:             @types = sort(keys(%{$usertypes}));
                   8200:         }
                   8201:     }
                   8202:     if (keys(%{$usertypes}) > 0) {
                   8203:         $othertitle = &mt('Other users');
                   8204:     }
                   8205:     return ($othertitle,$usertypes,\@types);
                   8206: }
                   8207: 
1.645     raeburn  8208: sub get_institutional_codes {
                   8209:     my ($settings,$allcourses,$LC_code) = @_;
                   8210: # Get complete list of course sections to update
                   8211:     my @currsections = ();
                   8212:     my @currxlists = ();
                   8213:     my $coursecode = $$settings{'internal.coursecode'};
                   8214: 
                   8215:     if ($$settings{'internal.sectionnums'} ne '') {
                   8216:         @currsections = split(/,/,$$settings{'internal.sectionnums'});
                   8217:     }
                   8218: 
                   8219:     if ($$settings{'internal.crosslistings'} ne '') {
                   8220:         @currxlists = split(/,/,$$settings{'internal.crosslistings'});
                   8221:     }
                   8222: 
                   8223:     if (@currxlists > 0) {
                   8224:         foreach (@currxlists) {
                   8225:             if (m/^([^:]+):(\w*)$/) {
                   8226:                 unless (grep/^$1$/,@{$allcourses}) {
                   8227:                     push @{$allcourses},$1;
                   8228:                     $$LC_code{$1} = $2;
                   8229:                 }
                   8230:             }
                   8231:         }
                   8232:     }
                   8233:  
                   8234:     if (@currsections > 0) {
                   8235:         foreach (@currsections) {
                   8236:             if (m/^(\w+):(\w*)$/) {
                   8237:                 my $sec = $coursecode.$1;
                   8238:                 my $lc_sec = $2;
                   8239:                 unless (grep/^$sec$/,@{$allcourses}) {
                   8240:                     push @{$allcourses},$sec;
                   8241:                     $$LC_code{$sec} = $lc_sec;
                   8242:                 }
                   8243:             }
                   8244:         }
                   8245:     }
                   8246:     return;
                   8247: }
                   8248: 
1.948.2.7  raeburn  8249: sub get_standard_codeitems {
                   8250:     return ('Year','Semester','Department','Number','Section');
                   8251: }
                   8252: 
1.112     bowersj2 8253: =pod
                   8254: 
1.780     raeburn  8255: =head1 Slot Helpers
                   8256: 
                   8257: =over 4
                   8258: 
                   8259: =item * sorted_slots()
                   8260: 
                   8261: Sorts an array of slot names in order of slot start time (earliest first). 
                   8262: 
                   8263: Inputs:
                   8264: 
                   8265: =over 4
                   8266: 
                   8267: slotsarr  - Reference to array of unsorted slot names.
                   8268: 
                   8269: slots     - Reference to hash of hash, where outer hash keys are slot names.
                   8270: 
1.549     albertel 8271: =back
                   8272: 
1.780     raeburn  8273: Returns:
                   8274: 
                   8275: =over 4
                   8276: 
                   8277: sorted   - An array of slot names sorted by the start time of the slot.
                   8278: 
                   8279: =back
                   8280: 
                   8281: =back
                   8282: 
                   8283: =cut
                   8284: 
                   8285: 
                   8286: sub sorted_slots {
                   8287:     my ($slotsarr,$slots) = @_;
                   8288:     my @sorted;
                   8289:     if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
                   8290:         @sorted =
                   8291:             sort {
                   8292:                      if (ref($slots->{$a}) && ref($slots->{$b})) {
                   8293:                          return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
                   8294:                      }
                   8295:                      if (ref($slots->{$a})) { return -1;}
                   8296:                      if (ref($slots->{$b})) { return 1;}
                   8297:                      return 0;
                   8298:                  } @{$slotsarr};
                   8299:     }
                   8300:     return @sorted;
                   8301: }
                   8302: 
                   8303: 
                   8304: =pod
                   8305: 
1.549     albertel 8306: =head1 HTTP Helpers
                   8307: 
                   8308: =over 4
                   8309: 
1.648     raeburn  8310: =item * &get_unprocessed_cgi($query,$possible_names)
1.112     bowersj2 8311: 
1.258     albertel 8312: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112     bowersj2 8313: $query.  The parameters listed in $possible_names (an array reference),
1.258     albertel 8314: will be set in $env{'form.name'} if they do not already exist.
1.112     bowersj2 8315: 
                   8316: Typically called with $ENV{'QUERY_STRING'} as the first parameter.  
                   8317: $possible_names is an ref to an array of form element names.  As an example:
                   8318: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258     albertel 8319: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112     bowersj2 8320: 
                   8321: =cut
1.1       albertel 8322: 
1.6       albertel 8323: sub get_unprocessed_cgi {
1.25      albertel 8324:   my ($query,$possible_names)= @_;
1.26      matthew  8325:   # $Apache::lonxml::debug=1;
1.356     albertel 8326:   foreach my $pair (split(/&/,$query)) {
                   8327:     my ($name, $value) = split(/=/,$pair);
1.369     www      8328:     $name = &unescape($name);
1.25      albertel 8329:     if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
                   8330:       $value =~ tr/+/ /;
                   8331:       $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258     albertel 8332:       unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25      albertel 8333:     }
1.16      harris41 8334:   }
1.6       albertel 8335: }
                   8336: 
1.112     bowersj2 8337: =pod
                   8338: 
1.648     raeburn  8339: =item * &cacheheader() 
1.112     bowersj2 8340: 
                   8341: returns cache-controlling header code
                   8342: 
                   8343: =cut
                   8344: 
1.7       albertel 8345: sub cacheheader {
1.258     albertel 8346:     unless ($env{'request.method'} eq 'GET') { return ''; }
1.216     albertel 8347:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
                   8348:     my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7       albertel 8349:                 <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
                   8350:                 <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216     albertel 8351:     return $output;
1.7       albertel 8352: }
                   8353: 
1.112     bowersj2 8354: =pod
                   8355: 
1.648     raeburn  8356: =item * &no_cache($r) 
1.112     bowersj2 8357: 
                   8358: specifies header code to not have cache
                   8359: 
                   8360: =cut
                   8361: 
1.9       albertel 8362: sub no_cache {
1.216     albertel 8363:     my ($r) = @_;
                   8364:     if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258     albertel 8365: 	$env{'request.method'} ne 'GET') { return ''; }
1.216     albertel 8366:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
                   8367:     $r->no_cache(1);
                   8368:     $r->header_out("Expires" => $date);
                   8369:     $r->header_out("Pragma" => "no-cache");
1.123     www      8370: }
                   8371: 
                   8372: sub content_type {
1.181     albertel 8373:     my ($r,$type,$charset) = @_;
1.299     foxr     8374:     if ($r) {
                   8375: 	#  Note that printout.pl calls this with undef for $r.
                   8376: 	&no_cache($r);
                   8377:     }
1.258     albertel 8378:     if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181     albertel 8379:     unless ($charset) {
                   8380: 	$charset=&Apache::lonlocal::current_encoding;
                   8381:     }
                   8382:     if ($charset) { $type.='; charset='.$charset; }
                   8383:     if ($r) {
                   8384: 	$r->content_type($type);
                   8385:     } else {
                   8386: 	print("Content-type: $type\n\n");
                   8387:     }
1.9       albertel 8388: }
1.25      albertel 8389: 
1.112     bowersj2 8390: =pod
                   8391: 
1.648     raeburn  8392: =item * &add_to_env($name,$value) 
1.112     bowersj2 8393: 
1.258     albertel 8394: adds $name to the %env hash with value
1.112     bowersj2 8395: $value, if $name already exists, the entry is converted to an array
                   8396: reference and $value is added to the array.
                   8397: 
                   8398: =cut
                   8399: 
1.25      albertel 8400: sub add_to_env {
                   8401:   my ($name,$value)=@_;
1.258     albertel 8402:   if (defined($env{$name})) {
                   8403:     if (ref($env{$name})) {
1.25      albertel 8404:       #already have multiple values
1.258     albertel 8405:       push(@{ $env{$name} },$value);
1.25      albertel 8406:     } else {
                   8407:       #first time seeing multiple values, convert hash entry to an arrayref
1.258     albertel 8408:       my $first=$env{$name};
                   8409:       undef($env{$name});
                   8410:       push(@{ $env{$name} },$first,$value);
1.25      albertel 8411:     }
                   8412:   } else {
1.258     albertel 8413:     $env{$name}=$value;
1.25      albertel 8414:   }
1.31      albertel 8415: }
1.149     albertel 8416: 
                   8417: =pod
                   8418: 
1.648     raeburn  8419: =item * &get_env_multiple($name) 
1.149     albertel 8420: 
1.258     albertel 8421: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149     albertel 8422: values may be defined and end up as an array ref.
                   8423: 
                   8424: returns an array of values
                   8425: 
                   8426: =cut
                   8427: 
                   8428: sub get_env_multiple {
                   8429:     my ($name) = @_;
                   8430:     my @values;
1.258     albertel 8431:     if (defined($env{$name})) {
1.149     albertel 8432:         # exists is it an array
1.258     albertel 8433:         if (ref($env{$name})) {
                   8434:             @values=@{ $env{$name} };
1.149     albertel 8435:         } else {
1.258     albertel 8436:             $values[0]=$env{$name};
1.149     albertel 8437:         }
                   8438:     }
                   8439:     return(@values);
                   8440: }
                   8441: 
1.660     raeburn  8442: sub ask_for_embedded_content {
                   8443:     my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.948.2.12  raeburn  8444:     my (%subdependencies,%dependencies,%newfiles);
1.660     raeburn  8445:     my $num = 0;
1.948.2.12  raeburn  8446:     my $upload_output;
                   8447:     foreach my $embed_file (keys(%{$allfiles})) {
                   8448:         unless ($embed_file =~ m{^\w+://} || $embed_file =~ m{^/}) {
                   8449:             my ($relpath,$fname);
                   8450:             if ($embed_file =~ m{/}) {
                   8451:                 my ($path,$fname) = ($embed_file =~ m{^(.+)/([^/]*)$});
                   8452:                 $subdependencies{$path}{$fname} = 1;
                   8453:             } else {
                   8454:                 $dependencies{$embed_file} = 1;
                   8455:             }
                   8456:         }
                   8457:     }
                   8458:     my ($url,$udom,$uname,$getpropath);
                   8459:     if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
                   8460:         my $current_path='/';
                   8461:         if ($env{'form.currentpath'}) {
                   8462:             $current_path = $env{'form.currentpath'};
                   8463:         }
                   8464:         if ($actionurl eq '/adm/coursegrp_portfolio') {
                   8465:             $udom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   8466:             $uname = $env{'course.'.$env{'request.course.id'}.'.num'};
                   8467:             $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
                   8468:         } else {
                   8469:             $udom = $env{'user.domain'};
                   8470:             $uname = $env{'user.name'};
                   8471:             $url = '/userfiles/portfolio';
                   8472:         }
                   8473:         $url .= $current_path;
                   8474:         $getpropath = 1;
                   8475:     } elsif ($actionurl eq '/adm/upload') {
                   8476:         ($uname,my $rest) = ($args->{'current_path'} =~ m{/priv/($match_username)/?(.*)$});
                   8477:         $url = '/home/'.$uname.'/public_html';
                   8478:         if ($rest ne '') {
                   8479:             $url .= '/'.$rest;
                   8480:         }
                   8481:     }
                   8482:     foreach my $path (keys(%subdependencies)) {
                   8483:         my %currsubfile;
                   8484:         if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
                   8485:             my @subdir_list = &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
                   8486:             foreach my $line (@subdir_list) {
                   8487:                 my ($file_name,$rest) = split(/\&/,$line,2);
                   8488:                 $currsubfile{$file_name} = 1;
                   8489:             }
                   8490:         } elsif ($actionurl eq '/adm/upload') {
                   8491:             if (opendir(my $dir,$url.'/'.$path)) {
                   8492:                 my @subdir_list = grep(!/^\./,readdir($dir));
                   8493:                 map {$currsubfile{$_} = 1;} @subdir_list;
                   8494:             }
                   8495:         }
                   8496:         foreach my $file (keys(%{$subdependencies{$path}})) {
                   8497:             unless ($currsubfile{$file}) {
                   8498:                  $newfiles{$path.'/'.$file} = 1;
                   8499:             }
                   8500:         }
                   8501:     }
                   8502:     my (@dir_list,%currfile);
                   8503:     if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
                   8504:         my @dir_list = &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
                   8505:         foreach my $line (@dir_list) {
                   8506:             my ($file_name,$rest) = split(/\&/,$line,2);
                   8507:             $currfile{$file_name} = 1;
                   8508:         }
                   8509:     } elsif ($actionurl eq '/adm/upload') {
                   8510:         if (opendir(my $dir,$url)) {
                   8511:             @dir_list = grep(!/^\./,readdir($dir));
                   8512:             map {$currfile{$_} = 1;} @dir_list;
                   8513:         }
                   8514:     }
                   8515:     foreach my $file (keys(%dependencies)) {
                   8516:         unless ($currfile{$file}) {
                   8517:             $newfiles{$file} = 1;
                   8518:         }
                   8519:     }
                   8520:     foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.660     raeburn  8521:         $upload_output .= &start_data_table_row().
                   8522:             '<td>'.$embed_file.'</td><td>';
                   8523:         if ($args->{'ignore_remote_references'}
                   8524:             && $embed_file =~ m{^\w+://}) {
                   8525:             $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
                   8526:         } elsif ($args->{'error_on_invalid_names'}
                   8527:             && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
                   8528: 
                   8529:             $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
                   8530: 
                   8531:         } else {
                   8532:             $upload_output .='
1.661     raeburn  8533:            <input name="embedded_item_'.$num.'" type="file" value="" />
1.660     raeburn  8534:            <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
                   8535:             my $attrib = join(':',@{$$allfiles{$embed_file}});
                   8536:             $upload_output .=
                   8537:                 "\n\t\t".
                   8538:                 '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
                   8539:                 $attrib.'" />';
                   8540:             if (exists($$codebase{$embed_file})) {
                   8541:                 $upload_output .=
                   8542:                     "\n\t\t".
                   8543:                     '<input name="codebase_'.$num.'" type="hidden" value="'.
                   8544:                     &escape($$codebase{$embed_file}).'" />';
                   8545:             }
                   8546:         }
1.948.2.12  raeburn  8547:         $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
1.660     raeburn  8548:         $num++;
                   8549:     }
1.948.2.12  raeburn  8550:     if ($num) {
                   8551:         $upload_output = '<form name="upload_embedded" action="'.$actionurl.'"'.
                   8552:                          ' method="post" enctype="multipart/form-data">'."\n".
                   8553:                          $state.
                   8554:                          '<b>Upload embedded files</b>:<br />'.&start_data_table().
                   8555:                          $upload_output.
                   8556:                          &Apache::loncommon::end_data_table().'<br />'."\n".
                   8557:                          '<input type ="hidden" name="number_embedded_items" value="'.$num.'" />'."\n".
                   8558:                          '<input type ="submit" value="'.&mt('Upload Listed Files').'" />'."\n".
                   8559:                          &mt('(only files for which a location has been provided will be uploaded)')."\n".
                   8560:                          '</form>';
                   8561:     }
1.660     raeburn  8562:     return $upload_output;
                   8563: }
                   8564: 
1.661     raeburn  8565: sub upload_embedded {
                   8566:     my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
                   8567:         $current_disk_usage) = @_;
                   8568:     my $output;
                   8569:     for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
                   8570:         next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
                   8571:         my $orig_uploaded_filename =
                   8572:             $env{'form.embedded_item_'.$i.'.filename'};
                   8573: 
                   8574:         $env{'form.embedded_orig_'.$i} =
                   8575:             &unescape($env{'form.embedded_orig_'.$i});
                   8576:         my ($path,$fname) =
                   8577:             ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
                   8578:         # no path, whole string is fname
                   8579:         if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
                   8580: 
                   8581:         $path = $env{'form.currentpath'}.$path;
                   8582:         $fname = &Apache::lonnet::clean_filename($fname);
                   8583:         # See if there is anything left
                   8584:         next if ($fname eq '');
                   8585: 
                   8586:         # Check if file already exists as a file or directory.
                   8587:         my ($state,$msg);
                   8588:         if ($context eq 'portfolio') {
                   8589:             my $port_path = $dirpath;
                   8590:             if ($group ne '') {
                   8591:                 $port_path = "groups/$group/$port_path";
                   8592:             }
                   8593:             ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
                   8594:                                               $dir_root,$port_path,$disk_quota,
                   8595:                                               $current_disk_usage,$uname,$udom);
                   8596:             if ($state eq 'will_exceed_quota'
1.948.2.12  raeburn  8597:                 || $state eq 'file_locked') {
1.661     raeburn  8598:                 $output .= $msg;
                   8599:                 next;
                   8600:             }
                   8601:         } elsif (($context eq 'author') || ($context eq 'testbank')) {
                   8602:             ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
                   8603:             if ($state eq 'exists') {
                   8604:                 $output .= $msg;
                   8605:                 next;
                   8606:             }
                   8607:         }
                   8608:         # Check if extension is valid
                   8609:         if (($fname =~ /\.(\w+)$/) &&
                   8610:             (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
                   8611:             $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
                   8612:             next;
                   8613:         } elsif (($fname =~ /\.(\w+)$/) &&
                   8614:                  (!defined(&Apache::loncommon::fileembstyle($1)))) {
                   8615:             $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
                   8616:             next;
                   8617:         } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
                   8618:             $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
                   8619:             next;
                   8620:         }
                   8621: 
                   8622:         $env{'form.embedded_item_'.$i.'.filename'}=$fname;
                   8623:         if ($context eq 'portfolio') {
1.948.2.12  raeburn  8624:             my $result;
                   8625:             if ($state eq 'existingfile') {
                   8626:                 $result=
                   8627:                     &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
                   8628:                                                     $dirpath.$path,);
1.661     raeburn  8629:             } else {
1.948.2.12  raeburn  8630:                 $result=
                   8631:                     &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
                   8632:                                                     $dirpath.$path);
                   8633:                 if ($result !~ m|^/uploaded/|) {
                   8634:                     $output .= '<span class="LC_error">'
                   8635:                                .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
                   8636:                                ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
                   8637:                                .'</span><br />';
                   8638:                     next;
                   8639:                 } else {
                   8640:                     $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
                   8641:                                $path.$fname.'</span>').'</p>';     
                   8642:                 }
1.661     raeburn  8643:             }
                   8644:         } else {
                   8645: # Save the file
                   8646:             my $target = $env{'form.embedded_item_'.$i};
                   8647:             my $fullpath = $dir_root.$dirpath.'/'.$path;
                   8648:             my $dest = $fullpath.$fname;
                   8649:             my $url = $url_root.$dirpath.'/'.$path.$fname;
                   8650:             my @parts=split(/\//,$fullpath);
                   8651:             my $count;
                   8652:             my $filepath = $dir_root;
                   8653:             for ($count=4;$count<=$#parts;$count++) {
                   8654:                 $filepath .= "/$parts[$count]";
                   8655:                 if ((-e $filepath)!=1) {
                   8656:                     mkdir($filepath,0770);
                   8657:                 }
                   8658:             }
                   8659:             my $fh;
                   8660:             if (!open($fh,'>'.$dest)) {
                   8661:                 &Apache::lonnet::logthis('Failed to create '.$dest);
                   8662:                 $output .= '<span class="LC_error">'.
                   8663:                            &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
                   8664:                            '</span><br />';
                   8665:             } else {
                   8666:                 if (!print $fh $env{'form.embedded_item_'.$i}) {
                   8667:                     &Apache::lonnet::logthis('Failed to write to '.$dest);
                   8668:                     $output .= '<span class="LC_error">'.
                   8669:                               &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
                   8670:                               '</span><br />';
                   8671:                 } else {
                   8672:                     if ($context eq 'testbank') {
                   8673:                         $output .= &mt('Embedded file uploaded successfully:').
                   8674:                                    '&nbsp;<a href="'.$url.'">'.
                   8675:                                    $orig_uploaded_filename.'</a><br />';
                   8676:                     } else {
1.705     tempelho 8677:                         $output .= '<span class=\"LC_fontsize_large\">'.
1.661     raeburn  8678:                                    &mt('View embedded file: [_1]','<a href="'.$url.'">'.
1.705     tempelho 8679:                                    $orig_uploaded_filename.'</a>').'</span><br />';
1.661     raeburn  8680:                     }
                   8681:                 }
                   8682:                 close($fh);
                   8683:             }
                   8684:         }
                   8685:     }
                   8686:     return $output;
                   8687: }
                   8688: 
                   8689: sub check_for_existing {
                   8690:     my ($path,$fname,$element) = @_;
                   8691:     my ($state,$msg);
                   8692:     if (-d $path.'/'.$fname) {
                   8693:         $state = 'exists';
                   8694:         $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
                   8695:     } elsif (-e $path.'/'.$fname) {
                   8696:         $state = 'exists';
                   8697:         $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
                   8698:     }
                   8699:     if ($state eq 'exists') {
                   8700:         $msg = '<span class="LC_error">'.$msg.'</span><br />';
                   8701:     }
                   8702:     return ($state,$msg);
                   8703: }
                   8704: 
                   8705: sub check_for_upload {
                   8706:     my ($path,$fname,$group,$element,$portfolio_root,$port_path,
                   8707:         $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.948.2.12  raeburn  8708:     my $filesize = length($env{'form.'.$element});
                   8709:     if (!$filesize) {
                   8710:         my $msg = '<span class="LC_error">'.
                   8711:                   &mt('Unable to upload [_1]. (size = [_2] bytes)',
                   8712:                       '<span class="LC_filename">'.$fname.'</span>',
                   8713:                       $filesize).'<br />'.
                   8714:                   &mt('Either the file you uploaded was empty, or your web browser was unable to read its contents.').'<br />';
                   8715:                   '</span>';
                   8716:         return ('zero_bytes',$msg);
                   8717:     }
                   8718:     $filesize =  $filesize/1000; #express in k (1024?)
1.661     raeburn  8719:     my $getpropath = 1;
                   8720:     my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
                   8721:                                             $getpropath);
                   8722:     my $found_file = 0;
                   8723:     my $locked_file = 0;
                   8724:     foreach my $line (@dir_list) {
1.948.2.12  raeburn  8725:         my ($file_name,$rest)=split(/\&/,$line,2);
1.661     raeburn  8726:         if ($file_name eq $fname){
                   8727:             $file_name = $path.$file_name;
                   8728:             if ($group ne '') {
                   8729:                 $file_name = $group.$file_name;
                   8730:             }
                   8731:             $found_file = 1;
                   8732:             if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
                   8733:                 $locked_file = 1;
1.948.2.12  raeburn  8734:             } else {
                   8735:                 my @info = split(/\&/,$rest);
                   8736:                 my $currsize = $info[6]/1000;
                   8737:                 if ($currsize < $filesize) {
                   8738:                     my $extra = $filesize - $currsize;
                   8739:                     if (($current_disk_usage + $extra) > $disk_quota) {
                   8740:                         my $msg = '<span class="LC_error">'.
                   8741:                                   &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded if existing (smaller) file with same name (size = [_3] kilobytes) is replaced.',
                   8742:                                       '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</span>'.
                   8743:                                   '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
                   8744:                                                $disk_quota,$current_disk_usage);
                   8745:                         return ('will_exceed_quota',$msg);
                   8746:                     }
                   8747:                 }
1.661     raeburn  8748:             }
                   8749:         }
                   8750:     }
                   8751:     if (($current_disk_usage + $filesize) > $disk_quota){
                   8752:         my $msg = '<span class="LC_error">'.
                   8753:                 &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
                   8754:                   '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
                   8755:         return ('will_exceed_quota',$msg);
                   8756:     } elsif ($found_file) {
                   8757:         if ($locked_file) {
                   8758:             my $msg = '<span class="LC_error">';
                   8759:             $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>');
                   8760:             $msg .= '</span><br />';
                   8761:             $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
                   8762:             return ('file_locked',$msg);
                   8763:         } else {
                   8764:             my $msg = '<span class="LC_error">';
1.948.2.12  raeburn  8765:             $msg .= &mt(' A file by that name: [_1] was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$port_path.$env{'form.currentpath'});
1.661     raeburn  8766:             $msg .= '</span>';
1.948.2.12  raeburn  8767:             return ('existingfile',$msg);
1.661     raeburn  8768:         }
                   8769:     }
                   8770: }
                   8771: 
1.31      albertel 8772: 
1.41      ng       8773: =pod
1.45      matthew  8774: 
1.464     albertel 8775: =back
1.41      ng       8776: 
1.112     bowersj2 8777: =head1 CSV Upload/Handling functions
1.38      albertel 8778: 
1.41      ng       8779: =over 4
                   8780: 
1.648     raeburn  8781: =item * &upfile_store($r)
1.41      ng       8782: 
                   8783: Store uploaded file, $r should be the HTTP Request object,
1.258     albertel 8784: needs $env{'form.upfile'}
1.41      ng       8785: returns $datatoken to be put into hidden field
                   8786: 
                   8787: =cut
1.31      albertel 8788: 
                   8789: sub upfile_store {
                   8790:     my $r=shift;
1.258     albertel 8791:     $env{'form.upfile'}=~s/\r/\n/gs;
                   8792:     $env{'form.upfile'}=~s/\f/\n/gs;
                   8793:     $env{'form.upfile'}=~s/\n+/\n/gs;
                   8794:     $env{'form.upfile'}=~s/\n+$//gs;
1.31      albertel 8795: 
1.258     albertel 8796:     my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
                   8797: 	'_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31      albertel 8798:     {
1.158     raeburn  8799:         my $datafile = $r->dir_config('lonDaemons').
                   8800:                            '/tmp/'.$datatoken.'.tmp';
                   8801:         if ( open(my $fh,">$datafile") ) {
1.258     albertel 8802:             print $fh $env{'form.upfile'};
1.158     raeburn  8803:             close($fh);
                   8804:         }
1.31      albertel 8805:     }
                   8806:     return $datatoken;
                   8807: }
                   8808: 
1.56      matthew  8809: =pod
                   8810: 
1.648     raeburn  8811: =item * &load_tmp_file($r)
1.41      ng       8812: 
                   8813: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258     albertel 8814: needs $env{'form.datatoken'},
                   8815: sets $env{'form.upfile'} to the contents of the file
1.41      ng       8816: 
                   8817: =cut
1.31      albertel 8818: 
                   8819: sub load_tmp_file {
                   8820:     my $r=shift;
                   8821:     my @studentdata=();
                   8822:     {
1.158     raeburn  8823:         my $studentfile = $r->dir_config('lonDaemons').
1.258     albertel 8824:                               '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158     raeburn  8825:         if ( open(my $fh,"<$studentfile") ) {
                   8826:             @studentdata=<$fh>;
                   8827:             close($fh);
                   8828:         }
1.31      albertel 8829:     }
1.258     albertel 8830:     $env{'form.upfile'}=join('',@studentdata);
1.31      albertel 8831: }
                   8832: 
1.56      matthew  8833: =pod
                   8834: 
1.648     raeburn  8835: =item * &upfile_record_sep()
1.41      ng       8836: 
                   8837: Separate uploaded file into records
                   8838: returns array of records,
1.258     albertel 8839: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41      ng       8840: 
                   8841: =cut
1.31      albertel 8842: 
                   8843: sub upfile_record_sep {
1.258     albertel 8844:     if ($env{'form.upfiletype'} eq 'xml') {
1.31      albertel 8845:     } else {
1.248     albertel 8846: 	my @records;
1.258     albertel 8847: 	foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248     albertel 8848: 	    if ($line=~/^\s*$/) { next; }
                   8849: 	    push(@records,$line);
                   8850: 	}
                   8851: 	return @records;
1.31      albertel 8852:     }
                   8853: }
                   8854: 
1.56      matthew  8855: =pod
                   8856: 
1.648     raeburn  8857: =item * &record_sep($record)
1.41      ng       8858: 
1.258     albertel 8859: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41      ng       8860: 
                   8861: =cut
                   8862: 
1.263     www      8863: sub takeleft {
                   8864:     my $index=shift;
                   8865:     return substr('0000'.$index,-4,4);
                   8866: }
                   8867: 
1.31      albertel 8868: sub record_sep {
                   8869:     my $record=shift;
                   8870:     my %components=();
1.258     albertel 8871:     if ($env{'form.upfiletype'} eq 'xml') {
                   8872:     } elsif ($env{'form.upfiletype'} eq 'space') {
1.31      albertel 8873:         my $i=0;
1.356     albertel 8874:         foreach my $field (split(/\s+/,$record)) {
1.31      albertel 8875:             $field=~s/^(\"|\')//;
                   8876:             $field=~s/(\"|\')$//;
1.263     www      8877:             $components{&takeleft($i)}=$field;
1.31      albertel 8878:             $i++;
                   8879:         }
1.258     albertel 8880:     } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31      albertel 8881:         my $i=0;
1.356     albertel 8882:         foreach my $field (split(/\t/,$record)) {
1.31      albertel 8883:             $field=~s/^(\"|\')//;
                   8884:             $field=~s/(\"|\')$//;
1.263     www      8885:             $components{&takeleft($i)}=$field;
1.31      albertel 8886:             $i++;
                   8887:         }
                   8888:     } else {
1.561     www      8889:         my $separator=',';
1.480     banghart 8890:         if ($env{'form.upfiletype'} eq 'semisv') {
1.561     www      8891:             $separator=';';
1.480     banghart 8892:         }
1.31      albertel 8893:         my $i=0;
1.561     www      8894: # the character we are looking for to indicate the end of a quote or a record 
                   8895:         my $looking_for=$separator;
                   8896: # do not add the characters to the fields
                   8897:         my $ignore=0;
                   8898: # we just encountered a separator (or the beginning of the record)
                   8899:         my $just_found_separator=1;
                   8900: # store the field we are working on here
                   8901:         my $field='';
                   8902: # work our way through all characters in record
                   8903:         foreach my $character ($record=~/(.)/g) {
                   8904:             if ($character eq $looking_for) {
                   8905:                if ($character ne $separator) {
                   8906: # Found the end of a quote, again looking for separator
                   8907:                   $looking_for=$separator;
                   8908:                   $ignore=1;
                   8909:                } else {
                   8910: # Found a separator, store away what we got
                   8911:                   $components{&takeleft($i)}=$field;
                   8912: 	          $i++;
                   8913:                   $just_found_separator=1;
                   8914:                   $ignore=0;
                   8915:                   $field='';
                   8916:                }
                   8917:                next;
                   8918:             }
                   8919: # single or double quotation marks after a separator indicate beginning of a quote
                   8920: # we are now looking for the end of the quote and need to ignore separators
                   8921:             if ((($character eq '"') || ($character eq "'")) && ($just_found_separator))  {
                   8922:                $looking_for=$character;
                   8923:                next;
                   8924:             }
                   8925: # ignore would be true after we reached the end of a quote
                   8926:             if ($ignore) { next; }
                   8927:             if (($just_found_separator) && ($character=~/\s/)) { next; }
                   8928:             $field.=$character;
                   8929:             $just_found_separator=0; 
1.31      albertel 8930:         }
1.561     www      8931: # catch the very last entry, since we never encountered the separator
                   8932:         $components{&takeleft($i)}=$field;
1.31      albertel 8933:     }
                   8934:     return %components;
                   8935: }
                   8936: 
1.144     matthew  8937: ######################################################
                   8938: ######################################################
                   8939: 
1.56      matthew  8940: =pod
                   8941: 
1.648     raeburn  8942: =item * &upfile_select_html()
1.41      ng       8943: 
1.144     matthew  8944: Return HTML code to select a file from the users machine and specify 
                   8945: the file type.
1.41      ng       8946: 
                   8947: =cut
                   8948: 
1.144     matthew  8949: ######################################################
                   8950: ######################################################
1.31      albertel 8951: sub upfile_select_html {
1.144     matthew  8952:     my %Types = (
                   8953:                  csv   => &mt('CSV (comma separated values, spreadsheet)'),
1.480     banghart 8954:                  semisv => &mt('Semicolon separated values'),
1.144     matthew  8955:                  space => &mt('Space separated'),
                   8956:                  tab   => &mt('Tabulator separated'),
                   8957: #                 xml   => &mt('HTML/XML'),
                   8958:                  );
                   8959:     my $Str = '<input type="file" name="upfile" size="50" />'.
1.727     riegler  8960:         '<br />'.&mt('Type').': <select name="upfiletype">';
1.144     matthew  8961:     foreach my $type (sort(keys(%Types))) {
                   8962:         $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
                   8963:     }
                   8964:     $Str .= "</select>\n";
                   8965:     return $Str;
1.31      albertel 8966: }
                   8967: 
1.301     albertel 8968: sub get_samples {
                   8969:     my ($records,$toget) = @_;
                   8970:     my @samples=({});
                   8971:     my $got=0;
                   8972:     foreach my $rec (@$records) {
                   8973: 	my %temp = &record_sep($rec);
                   8974: 	if (! grep(/\S/, values(%temp))) { next; }
                   8975: 	if (%temp) {
                   8976: 	    $samples[$got]=\%temp;
                   8977: 	    $got++;
                   8978: 	    if ($got == $toget) { last; }
                   8979: 	}
                   8980:     }
                   8981:     return \@samples;
                   8982: }
                   8983: 
1.144     matthew  8984: ######################################################
                   8985: ######################################################
                   8986: 
1.56      matthew  8987: =pod
                   8988: 
1.648     raeburn  8989: =item * &csv_print_samples($r,$records)
1.41      ng       8990: 
                   8991: Prints a table of sample values from each column uploaded $r is an
                   8992: Apache Request ref, $records is an arrayref from
                   8993: &Apache::loncommon::upfile_record_sep
                   8994: 
                   8995: =cut
                   8996: 
1.144     matthew  8997: ######################################################
                   8998: ######################################################
1.31      albertel 8999: sub csv_print_samples {
                   9000:     my ($r,$records) = @_;
1.662     bisitz   9001:     my $samples = &get_samples($records,5);
1.301     albertel 9002: 
1.594     raeburn  9003:     $r->print(&mt('Samples').'<br />'.&start_data_table().
                   9004:               &start_data_table_header_row());
1.356     albertel 9005:     foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) { 
1.845     bisitz   9006:         $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594     raeburn  9007:     $r->print(&end_data_table_header_row());
1.301     albertel 9008:     foreach my $hash (@$samples) {
1.594     raeburn  9009: 	$r->print(&start_data_table_row());
1.356     albertel 9010: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31      albertel 9011: 	    $r->print('<td>');
1.356     albertel 9012: 	    if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31      albertel 9013: 	    $r->print('</td>');
                   9014: 	}
1.594     raeburn  9015: 	$r->print(&end_data_table_row());
1.31      albertel 9016:     }
1.594     raeburn  9017:     $r->print(&end_data_table().'<br />'."\n");
1.31      albertel 9018: }
                   9019: 
1.144     matthew  9020: ######################################################
                   9021: ######################################################
                   9022: 
1.56      matthew  9023: =pod
                   9024: 
1.648     raeburn  9025: =item * &csv_print_select_table($r,$records,$d)
1.41      ng       9026: 
                   9027: Prints a table to create associations between values and table columns.
1.144     matthew  9028: 
1.41      ng       9029: $r is an Apache Request ref,
                   9030: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174     matthew  9031: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41      ng       9032: 
                   9033: =cut
                   9034: 
1.144     matthew  9035: ######################################################
                   9036: ######################################################
1.31      albertel 9037: sub csv_print_select_table {
                   9038:     my ($r,$records,$d) = @_;
1.301     albertel 9039:     my $i=0;
                   9040:     my $samples = &get_samples($records,1);
1.144     matthew  9041:     $r->print(&mt('Associate columns with student attributes.')."\n".
1.594     raeburn  9042: 	      &start_data_table().&start_data_table_header_row().
1.144     matthew  9043:               '<th>'.&mt('Attribute').'</th>'.
1.594     raeburn  9044:               '<th>'.&mt('Column').'</th>'.
                   9045:               &end_data_table_header_row()."\n");
1.356     albertel 9046:     foreach my $array_ref (@$d) {
                   9047: 	my ($value,$display,$defaultcol)=@{ $array_ref };
1.729     raeburn  9048: 	$r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31      albertel 9049: 
1.875     bisitz   9050: 	$r->print('<td><select name="f'.$i.'"'.
1.32      matthew  9051: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.31      albertel 9052: 	$r->print('<option value="none"></option>');
1.356     albertel 9053: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
                   9054: 	    $r->print('<option value="'.$sample.'"'.
                   9055:                       ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662     bisitz   9056:                       '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31      albertel 9057: 	}
1.594     raeburn  9058: 	$r->print('</select></td>'.&end_data_table_row()."\n");
1.31      albertel 9059: 	$i++;
                   9060:     }
1.594     raeburn  9061:     $r->print(&end_data_table());
1.31      albertel 9062:     $i--;
                   9063:     return $i;
                   9064: }
1.56      matthew  9065: 
1.144     matthew  9066: ######################################################
                   9067: ######################################################
                   9068: 
1.56      matthew  9069: =pod
1.31      albertel 9070: 
1.648     raeburn  9071: =item * &csv_samples_select_table($r,$records,$d)
1.41      ng       9072: 
                   9073: Prints a table of sample values from the upload and can make associate samples to internal names.
                   9074: 
                   9075: $r is an Apache Request ref,
                   9076: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
                   9077: $d is an array of 2 element arrays (internal name, displayed name)
                   9078: 
                   9079: =cut
                   9080: 
1.144     matthew  9081: ######################################################
                   9082: ######################################################
1.31      albertel 9083: sub csv_samples_select_table {
                   9084:     my ($r,$records,$d) = @_;
                   9085:     my $i=0;
1.144     matthew  9086:     #
1.662     bisitz   9087:     my $max_samples = 5;
                   9088:     my $samples = &get_samples($records,$max_samples);
1.594     raeburn  9089:     $r->print(&start_data_table().
                   9090:               &start_data_table_header_row().'<th>'.
                   9091:               &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
                   9092:               &end_data_table_header_row());
1.301     albertel 9093: 
                   9094:     foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594     raeburn  9095: 	$r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32      matthew  9096: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.301     albertel 9097: 	foreach my $option (@$d) {
                   9098: 	    my ($value,$display,$defaultcol)=@{ $option };
1.174     matthew  9099: 	    $r->print('<option value="'.$value.'"'.
1.253     albertel 9100:                       ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174     matthew  9101:                       $display.'</option>');
1.31      albertel 9102: 	}
                   9103: 	$r->print('</select></td><td>');
1.662     bisitz   9104: 	foreach my $line (0..($max_samples-1)) {
1.301     albertel 9105: 	    if (defined($samples->[$line]{$key})) { 
                   9106: 		$r->print($samples->[$line]{$key}."<br />\n"); 
                   9107: 	    }
                   9108: 	}
1.594     raeburn  9109: 	$r->print('</td>'.&end_data_table_row());
1.31      albertel 9110: 	$i++;
                   9111:     }
1.594     raeburn  9112:     $r->print(&end_data_table());
1.31      albertel 9113:     $i--;
                   9114:     return($i);
1.115     matthew  9115: }
                   9116: 
1.144     matthew  9117: ######################################################
                   9118: ######################################################
                   9119: 
1.115     matthew  9120: =pod
                   9121: 
1.648     raeburn  9122: =item * &clean_excel_name($name)
1.115     matthew  9123: 
                   9124: Returns a replacement for $name which does not contain any illegal characters.
                   9125: 
                   9126: =cut
                   9127: 
1.144     matthew  9128: ######################################################
                   9129: ######################################################
1.115     matthew  9130: sub clean_excel_name {
                   9131:     my ($name) = @_;
                   9132:     $name =~ s/[:\*\?\/\\]//g;
                   9133:     if (length($name) > 31) {
                   9134:         $name = substr($name,0,31);
                   9135:     }
                   9136:     return $name;
1.25      albertel 9137: }
1.84      albertel 9138: 
1.85      albertel 9139: =pod
                   9140: 
1.648     raeburn  9141: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85      albertel 9142: 
                   9143: Returns either 1 or undef
                   9144: 
                   9145: 1 if the part is to be hidden, undef if it is to be shown
                   9146: 
                   9147: Arguments are:
                   9148: 
                   9149: $id the id of the part to be checked
                   9150: $symb, optional the symb of the resource to check
                   9151: $udom, optional the domain of the user to check for
                   9152: $uname, optional the username of the user to check for
                   9153: 
                   9154: =cut
1.84      albertel 9155: 
                   9156: sub check_if_partid_hidden {
                   9157:     my ($id,$symb,$udom,$uname) = @_;
1.133     albertel 9158:     my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84      albertel 9159: 					 $symb,$udom,$uname);
1.141     albertel 9160:     my $truth=1;
                   9161:     #if the string starts with !, then the list is the list to show not hide
                   9162:     if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84      albertel 9163:     my @hiddenlist=split(/,/,$hiddenparts);
                   9164:     foreach my $checkid (@hiddenlist) {
1.141     albertel 9165: 	if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84      albertel 9166:     }
1.141     albertel 9167:     return !$truth;
1.84      albertel 9168: }
1.127     matthew  9169: 
1.138     matthew  9170: 
                   9171: ############################################################
                   9172: ############################################################
                   9173: 
                   9174: =pod
                   9175: 
1.157     matthew  9176: =back 
                   9177: 
1.138     matthew  9178: =head1 cgi-bin script and graphing routines
                   9179: 
1.157     matthew  9180: =over 4
                   9181: 
1.648     raeburn  9182: =item * &get_cgi_id()
1.138     matthew  9183: 
                   9184: Inputs: none
                   9185: 
                   9186: Returns an id which can be used to pass environment variables
                   9187: to various cgi-bin scripts.  These environment variables will
                   9188: be removed from the users environment after a given time by
                   9189: the routine &Apache::lonnet::transfer_profile_to_env.
                   9190: 
                   9191: =cut
                   9192: 
                   9193: ############################################################
                   9194: ############################################################
1.152     albertel 9195: my $uniq=0;
1.136     matthew  9196: sub get_cgi_id {
1.154     albertel 9197:     $uniq=($uniq+1)%100000;
1.280     albertel 9198:     return (time.'_'.$$.'_'.$uniq);
1.136     matthew  9199: }
                   9200: 
1.127     matthew  9201: ############################################################
                   9202: ############################################################
                   9203: 
                   9204: =pod
                   9205: 
1.648     raeburn  9206: =item * &DrawBarGraph()
1.127     matthew  9207: 
1.138     matthew  9208: Facilitates the plotting of data in a (stacked) bar graph.
                   9209: Puts plot definition data into the users environment in order for 
                   9210: graph.png to plot it.  Returns an <img> tag for the plot.
                   9211: The bars on the plot are labeled '1','2',...,'n'.
                   9212: 
                   9213: Inputs:
                   9214: 
                   9215: =over 4
                   9216: 
                   9217: =item $Title: string, the title of the plot
                   9218: 
                   9219: =item $xlabel: string, text describing the X-axis of the plot
                   9220: 
                   9221: =item $ylabel: string, text describing the Y-axis of the plot
                   9222: 
                   9223: =item $Max: scalar, the maximum Y value to use in the plot
                   9224: If $Max is < any data point, the graph will not be rendered.
                   9225: 
1.140     matthew  9226: =item $colors: array ref holding the colors to be used for the data sets when
1.138     matthew  9227: they are plotted.  If undefined, default values will be used.
                   9228: 
1.178     matthew  9229: =item $labels: array ref holding the labels to use on the x-axis for the bars.
                   9230: 
1.138     matthew  9231: =item @Values: An array of array references.  Each array reference holds data
                   9232: to be plotted in a stacked bar chart.
                   9233: 
1.239     matthew  9234: =item If the final element of @Values is a hash reference the key/value
                   9235: pairs will be added to the graph definition.
                   9236: 
1.138     matthew  9237: =back
                   9238: 
                   9239: Returns:
                   9240: 
                   9241: An <img> tag which references graph.png and the appropriate identifying
                   9242: information for the plot.
                   9243: 
1.127     matthew  9244: =cut
                   9245: 
                   9246: ############################################################
                   9247: ############################################################
1.134     matthew  9248: sub DrawBarGraph {
1.178     matthew  9249:     my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134     matthew  9250:     #
                   9251:     if (! defined($colors)) {
                   9252:         $colors = ['#33ff00', 
                   9253:                   '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
                   9254:                   '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
                   9255:                   ]; 
                   9256:     }
1.228     matthew  9257:     my $extra_settings = {};
                   9258:     if (ref($Values[-1]) eq 'HASH') {
                   9259:         $extra_settings = pop(@Values);
                   9260:     }
1.127     matthew  9261:     #
1.136     matthew  9262:     my $identifier = &get_cgi_id();
                   9263:     my $id = 'cgi.'.$identifier;        
1.129     matthew  9264:     if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127     matthew  9265:         return '';
                   9266:     }
1.225     matthew  9267:     #
                   9268:     my @Labels;
                   9269:     if (defined($labels)) {
                   9270:         @Labels = @$labels;
                   9271:     } else {
                   9272:         for (my $i=0;$i<@{$Values[0]};$i++) {
                   9273:             push (@Labels,$i+1);
                   9274:         }
                   9275:     }
                   9276:     #
1.129     matthew  9277:     my $NumBars = scalar(@{$Values[0]});
1.225     matthew  9278:     if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129     matthew  9279:     my %ValuesHash;
                   9280:     my $NumSets=1;
                   9281:     foreach my $array (@Values) {
                   9282:         next if (! ref($array));
1.136     matthew  9283:         $ValuesHash{$id.'.data.'.$NumSets++} = 
1.132     matthew  9284:             join(',',@$array);
1.129     matthew  9285:     }
1.127     matthew  9286:     #
1.136     matthew  9287:     my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225     matthew  9288:     if ($NumBars < 3) {
                   9289:         $width = 120+$NumBars*32;
1.220     matthew  9290:         $xskip = 1;
1.225     matthew  9291:         $bar_width = 30;
                   9292:     } elsif ($NumBars < 5) {
                   9293:         $width = 120+$NumBars*20;
                   9294:         $xskip = 1;
                   9295:         $bar_width = 20;
1.220     matthew  9296:     } elsif ($NumBars < 10) {
1.136     matthew  9297:         $width = 120+$NumBars*15;
                   9298:         $xskip = 1;
                   9299:         $bar_width = 15;
                   9300:     } elsif ($NumBars <= 25) {
                   9301:         $width = 120+$NumBars*11;
                   9302:         $xskip = 5;
                   9303:         $bar_width = 8;
                   9304:     } elsif ($NumBars <= 50) {
                   9305:         $width = 120+$NumBars*8;
                   9306:         $xskip = 5;
                   9307:         $bar_width = 4;
                   9308:     } else {
                   9309:         $width = 120+$NumBars*8;
                   9310:         $xskip = 5;
                   9311:         $bar_width = 4;
                   9312:     }
                   9313:     #
1.137     matthew  9314:     $Max = 1 if ($Max < 1);
                   9315:     if ( int($Max) < $Max ) {
                   9316:         $Max++;
                   9317:         $Max = int($Max);
                   9318:     }
1.127     matthew  9319:     $Title  = '' if (! defined($Title));
                   9320:     $xlabel = '' if (! defined($xlabel));
                   9321:     $ylabel = '' if (! defined($ylabel));
1.369     www      9322:     $ValuesHash{$id.'.title'}    = &escape($Title);
                   9323:     $ValuesHash{$id.'.xlabel'}   = &escape($xlabel);
                   9324:     $ValuesHash{$id.'.ylabel'}   = &escape($ylabel);
1.137     matthew  9325:     $ValuesHash{$id.'.y_max_value'} = $Max;
1.136     matthew  9326:     $ValuesHash{$id.'.NumBars'}  = $NumBars;
                   9327:     $ValuesHash{$id.'.NumSets'}  = $NumSets;
                   9328:     $ValuesHash{$id.'.PlotType'} = 'bar';
                   9329:     $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   9330:     $ValuesHash{$id.'.height'}   = $height;
                   9331:     $ValuesHash{$id.'.width'}    = $width;
                   9332:     $ValuesHash{$id.'.xskip'}    = $xskip;
                   9333:     $ValuesHash{$id.'.bar_width'} = $bar_width;
                   9334:     $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127     matthew  9335:     #
1.228     matthew  9336:     # Deal with other parameters
                   9337:     while (my ($key,$value) = each(%$extra_settings)) {
                   9338:         $ValuesHash{$id.'.'.$key} = $value;
                   9339:     }
                   9340:     #
1.646     raeburn  9341:     &Apache::lonnet::appenv(\%ValuesHash);
1.137     matthew  9342:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   9343: }
                   9344: 
                   9345: ############################################################
                   9346: ############################################################
                   9347: 
                   9348: =pod
                   9349: 
1.648     raeburn  9350: =item * &DrawXYGraph()
1.137     matthew  9351: 
1.138     matthew  9352: Facilitates the plotting of data in an XY graph.
                   9353: Puts plot definition data into the users environment in order for 
                   9354: graph.png to plot it.  Returns an <img> tag for the plot.
                   9355: 
                   9356: Inputs:
                   9357: 
                   9358: =over 4
                   9359: 
                   9360: =item $Title: string, the title of the plot
                   9361: 
                   9362: =item $xlabel: string, text describing the X-axis of the plot
                   9363: 
                   9364: =item $ylabel: string, text describing the Y-axis of the plot
                   9365: 
                   9366: =item $Max: scalar, the maximum Y value to use in the plot
                   9367: If $Max is < any data point, the graph will not be rendered.
                   9368: 
                   9369: =item $colors: Array ref containing the hex color codes for the data to be 
                   9370: plotted in.  If undefined, default values will be used.
                   9371: 
                   9372: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   9373: 
                   9374: =item $Ydata: Array ref containing Array refs.  
1.185     www      9375: Each of the contained arrays will be plotted as a separate curve.
1.138     matthew  9376: 
                   9377: =item %Values: hash indicating or overriding any default values which are 
                   9378: passed to graph.png.  
                   9379: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   9380: 
                   9381: =back
                   9382: 
                   9383: Returns:
                   9384: 
                   9385: An <img> tag which references graph.png and the appropriate identifying
                   9386: information for the plot.
                   9387: 
1.137     matthew  9388: =cut
                   9389: 
                   9390: ############################################################
                   9391: ############################################################
                   9392: sub DrawXYGraph {
                   9393:     my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
                   9394:     #
                   9395:     # Create the identifier for the graph
                   9396:     my $identifier = &get_cgi_id();
                   9397:     my $id = 'cgi.'.$identifier;
                   9398:     #
                   9399:     $Title  = '' if (! defined($Title));
                   9400:     $xlabel = '' if (! defined($xlabel));
                   9401:     $ylabel = '' if (! defined($ylabel));
                   9402:     my %ValuesHash = 
                   9403:         (
1.369     www      9404:          $id.'.title'  => &escape($Title),
                   9405:          $id.'.xlabel' => &escape($xlabel),
                   9406:          $id.'.ylabel' => &escape($ylabel),
1.137     matthew  9407:          $id.'.y_max_value'=> $Max,
                   9408:          $id.'.labels'     => join(',',@$Xlabels),
                   9409:          $id.'.PlotType'   => 'XY',
                   9410:          );
                   9411:     #
                   9412:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   9413:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   9414:     }
                   9415:     #
                   9416:     if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
                   9417:         return '';
                   9418:     }
                   9419:     my $NumSets=1;
1.138     matthew  9420:     foreach my $array (@{$Ydata}){
1.137     matthew  9421:         next if (! ref($array));
                   9422:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
                   9423:     }
1.138     matthew  9424:     $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137     matthew  9425:     #
                   9426:     # Deal with other parameters
                   9427:     while (my ($key,$value) = each(%Values)) {
                   9428:         $ValuesHash{$id.'.'.$key} = $value;
1.127     matthew  9429:     }
                   9430:     #
1.646     raeburn  9431:     &Apache::lonnet::appenv(\%ValuesHash);
1.136     matthew  9432:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   9433: }
                   9434: 
                   9435: ############################################################
                   9436: ############################################################
                   9437: 
                   9438: =pod
                   9439: 
1.648     raeburn  9440: =item * &DrawXYYGraph()
1.138     matthew  9441: 
                   9442: Facilitates the plotting of data in an XY graph with two Y axes.
                   9443: Puts plot definition data into the users environment in order for 
                   9444: graph.png to plot it.  Returns an <img> tag for the plot.
                   9445: 
                   9446: Inputs:
                   9447: 
                   9448: =over 4
                   9449: 
                   9450: =item $Title: string, the title of the plot
                   9451: 
                   9452: =item $xlabel: string, text describing the X-axis of the plot
                   9453: 
                   9454: =item $ylabel: string, text describing the Y-axis of the plot
                   9455: 
                   9456: =item $colors: Array ref containing the hex color codes for the data to be 
                   9457: plotted in.  If undefined, default values will be used.
                   9458: 
                   9459: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   9460: 
                   9461: =item $Ydata1: The first data set
                   9462: 
                   9463: =item $Min1: The minimum value of the left Y-axis
                   9464: 
                   9465: =item $Max1: The maximum value of the left Y-axis
                   9466: 
                   9467: =item $Ydata2: The second data set
                   9468: 
                   9469: =item $Min2: The minimum value of the right Y-axis
                   9470: 
                   9471: =item $Max2: The maximum value of the left Y-axis
                   9472: 
                   9473: =item %Values: hash indicating or overriding any default values which are 
                   9474: passed to graph.png.  
                   9475: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   9476: 
                   9477: =back
                   9478: 
                   9479: Returns:
                   9480: 
                   9481: An <img> tag which references graph.png and the appropriate identifying
                   9482: information for the plot.
1.136     matthew  9483: 
                   9484: =cut
                   9485: 
                   9486: ############################################################
                   9487: ############################################################
1.137     matthew  9488: sub DrawXYYGraph {
                   9489:     my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
                   9490:                                         $Ydata2,$Min2,$Max2,%Values)=@_;
1.136     matthew  9491:     #
                   9492:     # Create the identifier for the graph
                   9493:     my $identifier = &get_cgi_id();
                   9494:     my $id = 'cgi.'.$identifier;
                   9495:     #
                   9496:     $Title  = '' if (! defined($Title));
                   9497:     $xlabel = '' if (! defined($xlabel));
                   9498:     $ylabel = '' if (! defined($ylabel));
                   9499:     my %ValuesHash = 
                   9500:         (
1.369     www      9501:          $id.'.title'  => &escape($Title),
                   9502:          $id.'.xlabel' => &escape($xlabel),
                   9503:          $id.'.ylabel' => &escape($ylabel),
1.136     matthew  9504:          $id.'.labels' => join(',',@$Xlabels),
                   9505:          $id.'.PlotType' => 'XY',
                   9506:          $id.'.NumSets' => 2,
1.137     matthew  9507:          $id.'.two_axes' => 1,
                   9508:          $id.'.y1_max_value' => $Max1,
                   9509:          $id.'.y1_min_value' => $Min1,
                   9510:          $id.'.y2_max_value' => $Max2,
                   9511:          $id.'.y2_min_value' => $Min2,
1.136     matthew  9512:          );
                   9513:     #
1.137     matthew  9514:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   9515:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   9516:     }
                   9517:     #
                   9518:     if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
                   9519:         ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136     matthew  9520:         return '';
                   9521:     }
                   9522:     my $NumSets=1;
1.137     matthew  9523:     foreach my $array ($Ydata1,$Ydata2){
1.136     matthew  9524:         next if (! ref($array));
                   9525:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137     matthew  9526:     }
                   9527:     #
                   9528:     # Deal with other parameters
                   9529:     while (my ($key,$value) = each(%Values)) {
                   9530:         $ValuesHash{$id.'.'.$key} = $value;
1.136     matthew  9531:     }
                   9532:     #
1.646     raeburn  9533:     &Apache::lonnet::appenv(\%ValuesHash);
1.130     albertel 9534:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139     matthew  9535: }
                   9536: 
                   9537: ############################################################
                   9538: ############################################################
                   9539: 
                   9540: =pod
                   9541: 
1.157     matthew  9542: =back 
                   9543: 
1.139     matthew  9544: =head1 Statistics helper routines?  
                   9545: 
                   9546: Bad place for them but what the hell.
                   9547: 
1.157     matthew  9548: =over 4
                   9549: 
1.648     raeburn  9550: =item * &chartlink()
1.139     matthew  9551: 
                   9552: Returns a link to the chart for a specific student.  
                   9553: 
                   9554: Inputs:
                   9555: 
                   9556: =over 4
                   9557: 
                   9558: =item $linktext: The text of the link
                   9559: 
                   9560: =item $sname: The students username
                   9561: 
                   9562: =item $sdomain: The students domain
                   9563: 
                   9564: =back
                   9565: 
1.157     matthew  9566: =back
                   9567: 
1.139     matthew  9568: =cut
                   9569: 
                   9570: ############################################################
                   9571: ############################################################
                   9572: sub chartlink {
                   9573:     my ($linktext, $sname, $sdomain) = @_;
                   9574:     my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369     www      9575:         '&amp;SelectedStudent='.&escape($sname.':'.$sdomain).
1.219     albertel 9576:         '&amp;chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139     matthew  9577:        '">'.$linktext.'</a>';
1.153     matthew  9578: }
                   9579: 
                   9580: #######################################################
                   9581: #######################################################
                   9582: 
                   9583: =pod
                   9584: 
                   9585: =head1 Course Environment Routines
1.157     matthew  9586: 
                   9587: =over 4
1.153     matthew  9588: 
1.648     raeburn  9589: =item * &restore_course_settings()
1.153     matthew  9590: 
1.648     raeburn  9591: =item * &store_course_settings()
1.153     matthew  9592: 
                   9593: Restores/Store indicated form parameters from the course environment.
                   9594: Will not overwrite existing values of the form parameters.
                   9595: 
                   9596: Inputs: 
                   9597: a scalar describing the data (e.g. 'chart', 'problem_analysis')
                   9598: 
                   9599: a hash ref describing the data to be stored.  For example:
                   9600:    
                   9601: %Save_Parameters = ('Status' => 'scalar',
                   9602:     'chartoutputmode' => 'scalar',
                   9603:     'chartoutputdata' => 'scalar',
                   9604:     'Section' => 'array',
1.373     raeburn  9605:     'Group' => 'array',
1.153     matthew  9606:     'StudentData' => 'array',
                   9607:     'Maps' => 'array');
                   9608: 
                   9609: Returns: both routines return nothing
                   9610: 
1.631     raeburn  9611: =back
                   9612: 
1.153     matthew  9613: =cut
                   9614: 
                   9615: #######################################################
                   9616: #######################################################
                   9617: sub store_course_settings {
1.496     albertel 9618:     return &store_settings($env{'request.course.id'},@_);
                   9619: }
                   9620: 
                   9621: sub store_settings {
1.153     matthew  9622:     # save to the environment
                   9623:     # appenv the same items, just to be safe
1.300     albertel 9624:     my $udom  = $env{'user.domain'};
                   9625:     my $uname = $env{'user.name'};
1.496     albertel 9626:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  9627:     my %SaveHash;
                   9628:     my %AppHash;
                   9629:     while (my ($setting,$type) = each(%$Settings)) {
1.496     albertel 9630:         my $basename = join('.','internal',$context,$prefix,$setting);
1.300     albertel 9631:         my $envname = 'environment.'.$basename;
1.258     albertel 9632:         if (exists($env{'form.'.$setting})) {
1.153     matthew  9633:             # Save this value away
                   9634:             if ($type eq 'scalar' &&
1.258     albertel 9635:                 (! exists($env{$envname}) || 
                   9636:                  $env{$envname} ne $env{'form.'.$setting})) {
                   9637:                 $SaveHash{$basename} = $env{'form.'.$setting};
                   9638:                 $AppHash{$envname}   = $env{'form.'.$setting};
1.153     matthew  9639:             } elsif ($type eq 'array') {
                   9640:                 my $stored_form;
1.258     albertel 9641:                 if (ref($env{'form.'.$setting})) {
1.153     matthew  9642:                     $stored_form = join(',',
                   9643:                                         map {
1.369     www      9644:                                             &escape($_);
1.258     albertel 9645:                                         } sort(@{$env{'form.'.$setting}}));
1.153     matthew  9646:                 } else {
                   9647:                     $stored_form = 
1.369     www      9648:                         &escape($env{'form.'.$setting});
1.153     matthew  9649:                 }
                   9650:                 # Determine if the array contents are the same.
1.258     albertel 9651:                 if ($stored_form ne $env{$envname}) {
1.153     matthew  9652:                     $SaveHash{$basename} = $stored_form;
                   9653:                     $AppHash{$envname}   = $stored_form;
                   9654:                 }
                   9655:             }
                   9656:         }
                   9657:     }
                   9658:     my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300     albertel 9659:                                           $udom,$uname);
1.153     matthew  9660:     if ($put_result !~ /^(ok|delayed)/) {
                   9661:         &Apache::lonnet::logthis('unable to save form parameters, '.
                   9662:                                  'got error:'.$put_result);
                   9663:     }
                   9664:     # Make sure these settings stick around in this session, too
1.646     raeburn  9665:     &Apache::lonnet::appenv(\%AppHash);
1.153     matthew  9666:     return;
                   9667: }
                   9668: 
                   9669: sub restore_course_settings {
1.499     albertel 9670:     return &restore_settings($env{'request.course.id'},@_);
1.496     albertel 9671: }
                   9672: 
                   9673: sub restore_settings {
                   9674:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  9675:     while (my ($setting,$type) = each(%$Settings)) {
1.258     albertel 9676:         next if (exists($env{'form.'.$setting}));
1.496     albertel 9677:         my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153     matthew  9678:             '.'.$setting;
1.258     albertel 9679:         if (exists($env{$envname})) {
1.153     matthew  9680:             if ($type eq 'scalar') {
1.258     albertel 9681:                 $env{'form.'.$setting} = $env{$envname};
1.153     matthew  9682:             } elsif ($type eq 'array') {
1.258     albertel 9683:                 $env{'form.'.$setting} = [ 
1.153     matthew  9684:                                            map { 
1.369     www      9685:                                                &unescape($_); 
1.258     albertel 9686:                                            } split(',',$env{$envname})
1.153     matthew  9687:                                            ];
                   9688:             }
                   9689:         }
                   9690:     }
1.127     matthew  9691: }
                   9692: 
1.618     raeburn  9693: #######################################################
                   9694: #######################################################
                   9695: 
                   9696: =pod
                   9697: 
                   9698: =head1 Domain E-mail Routines  
                   9699: 
                   9700: =over 4
                   9701: 
1.648     raeburn  9702: =item * &build_recipient_list()
1.618     raeburn  9703: 
1.884     raeburn  9704: Build recipient lists for five types of e-mail:
1.766     raeburn  9705: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.884     raeburn  9706: (d) Help requests, (e) Course requests needing approval,  generated by
                   9707: lonerrorhandler.pm, CHECKRPMS, loncron, lonsupportreq.pm and
                   9708: loncoursequeueadmin.pm respectively.
1.618     raeburn  9709: 
                   9710: Inputs:
1.619     raeburn  9711: defmail (scalar - email address of default recipient), 
1.618     raeburn  9712: mailing type (scalar - errormail, packagesmail, or helpdeskmail), 
1.619     raeburn  9713: defdom (domain for which to retrieve configuration settings),
                   9714: origmail (scalar - email address of recipient from loncapa.conf, 
                   9715: i.e., predates configuration by DC via domainprefs.pm 
1.618     raeburn  9716: 
1.655     raeburn  9717: Returns: comma separated list of addresses to which to send e-mail.
                   9718: 
                   9719: =back
1.618     raeburn  9720: 
                   9721: =cut
                   9722: 
                   9723: ############################################################
                   9724: ############################################################
                   9725: sub build_recipient_list {
1.619     raeburn  9726:     my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618     raeburn  9727:     my @recipients;
                   9728:     my $otheremails;
                   9729:     my %domconfig =
                   9730:          &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
                   9731:     if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766     raeburn  9732:         if (exists($domconfig{'contacts'}{$mailing})) {
                   9733:             if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
                   9734:                 my @contacts = ('adminemail','supportemail');
                   9735:                 foreach my $item (@contacts) {
                   9736:                     if ($domconfig{'contacts'}{$mailing}{$item}) {
                   9737:                         my $addr = $domconfig{'contacts'}{$item}; 
                   9738:                         if (!grep(/^\Q$addr\E$/,@recipients)) {
                   9739:                             push(@recipients,$addr);
                   9740:                         }
1.619     raeburn  9741:                     }
1.766     raeburn  9742:                     $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618     raeburn  9743:                 }
                   9744:             }
1.766     raeburn  9745:         } elsif ($origmail ne '') {
                   9746:             push(@recipients,$origmail);
1.618     raeburn  9747:         }
1.619     raeburn  9748:     } elsif ($origmail ne '') {
                   9749:         push(@recipients,$origmail);
1.618     raeburn  9750:     }
1.688     raeburn  9751:     if (defined($defmail)) {
                   9752:         if ($defmail ne '') {
                   9753:             push(@recipients,$defmail);
                   9754:         }
1.618     raeburn  9755:     }
                   9756:     if ($otheremails) {
1.619     raeburn  9757:         my @others;
                   9758:         if ($otheremails =~ /,/) {
                   9759:             @others = split(/,/,$otheremails);
1.618     raeburn  9760:         } else {
1.619     raeburn  9761:             push(@others,$otheremails);
                   9762:         }
                   9763:         foreach my $addr (@others) {
                   9764:             if (!grep(/^\Q$addr\E$/,@recipients)) {
                   9765:                 push(@recipients,$addr);
                   9766:             }
1.618     raeburn  9767:         }
                   9768:     }
1.619     raeburn  9769:     my $recipientlist = join(',',@recipients); 
1.618     raeburn  9770:     return $recipientlist;
                   9771: }
                   9772: 
1.127     matthew  9773: ############################################################
                   9774: ############################################################
1.154     albertel 9775: 
1.655     raeburn  9776: =pod
                   9777: 
                   9778: =head1 Course Catalog Routines
                   9779: 
                   9780: =over 4
                   9781: 
                   9782: =item * &gather_categories()
                   9783: 
                   9784: Converts category definitions - keys of categories hash stored in  
                   9785: coursecategories in configuration.db on the primary library server in a 
                   9786: domain - to an array.  Also generates javascript and idx hash used to 
                   9787: generate Domain Coordinator interface for editing Course Categories.
                   9788: 
                   9789: Inputs:
1.663     raeburn  9790: 
1.655     raeburn  9791: categories (reference to hash of category definitions).
1.663     raeburn  9792: 
1.655     raeburn  9793: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   9794:       categories and subcategories).
1.663     raeburn  9795: 
1.655     raeburn  9796: idx (reference to hash of counters used in Domain Coordinator interface for 
                   9797:       editing Course Categories).
1.663     raeburn  9798: 
1.655     raeburn  9799: jsarray (reference to array of categories used to create Javascript arrays for
                   9800:          Domain Coordinator interface for editing Course Categories).
                   9801: 
                   9802: Returns: nothing
                   9803: 
                   9804: Side effects: populates cats, idx and jsarray. 
                   9805: 
                   9806: =cut
                   9807: 
                   9808: sub gather_categories {
                   9809:     my ($categories,$cats,$idx,$jsarray) = @_;
                   9810:     my %counters;
                   9811:     my $num = 0;
                   9812:     foreach my $item (keys(%{$categories})) {
                   9813:         my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
                   9814:         if ($container eq '' && $depth == 0) {
                   9815:             $cats->[$depth][$categories->{$item}] = $cat;
                   9816:         } else {
                   9817:             $cats->[$depth]{$container}[$categories->{$item}] = $cat;
                   9818:         }
                   9819:         my ($escitem,$tail) = split(/:/,$item,2);
                   9820:         if ($counters{$tail} eq '') {
                   9821:             $counters{$tail} = $num;
                   9822:             $num ++;
                   9823:         }
                   9824:         if (ref($idx) eq 'HASH') {
                   9825:             $idx->{$item} = $counters{$tail};
                   9826:         }
                   9827:         if (ref($jsarray) eq 'ARRAY') {
                   9828:             push(@{$jsarray->[$counters{$tail}]},$item);
                   9829:         }
                   9830:     }
                   9831:     return;
                   9832: }
                   9833: 
                   9834: =pod
                   9835: 
                   9836: =item * &extract_categories()
                   9837: 
                   9838: Used to generate breadcrumb trails for course categories.
                   9839: 
                   9840: Inputs:
1.663     raeburn  9841: 
1.655     raeburn  9842: categories (reference to hash of category definitions).
1.663     raeburn  9843: 
1.655     raeburn  9844: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   9845:       categories and subcategories).
1.663     raeburn  9846: 
1.655     raeburn  9847: trails (reference to array of breacrumb trails for each category).
1.663     raeburn  9848: 
1.655     raeburn  9849: allitems (reference to hash - key is category key 
                   9850:          (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663     raeburn  9851: 
1.655     raeburn  9852: idx (reference to hash of counters used in Domain Coordinator interface for
                   9853:       editing Course Categories).
1.663     raeburn  9854: 
1.655     raeburn  9855: jsarray (reference to array of categories used to create Javascript arrays for
                   9856:          Domain Coordinator interface for editing Course Categories).
                   9857: 
1.665     raeburn  9858: subcats (reference to hash of arrays containing all subcategories within each 
                   9859:          category, -recursive)
                   9860: 
1.655     raeburn  9861: Returns: nothing
                   9862: 
                   9863: Side effects: populates trails and allitems hash references.
                   9864: 
                   9865: =cut
                   9866: 
                   9867: sub extract_categories {
1.665     raeburn  9868:     my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655     raeburn  9869:     if (ref($categories) eq 'HASH') {
                   9870:         &gather_categories($categories,$cats,$idx,$jsarray);
                   9871:         if (ref($cats->[0]) eq 'ARRAY') {
                   9872:             for (my $i=0; $i<@{$cats->[0]}; $i++) {
                   9873:                 my $name = $cats->[0][$i];
                   9874:                 my $item = &escape($name).'::0';
                   9875:                 my $trailstr;
                   9876:                 if ($name eq 'instcode') {
                   9877:                     $trailstr = &mt('Official courses (with institutional codes)');
1.919     raeburn  9878:                 } elsif ($name eq 'communities') {
                   9879:                     $trailstr = &mt('Communities');
1.655     raeburn  9880:                 } else {
                   9881:                     $trailstr = $name;
                   9882:                 }
                   9883:                 if ($allitems->{$item} eq '') {
                   9884:                     push(@{$trails},$trailstr);
                   9885:                     $allitems->{$item} = scalar(@{$trails})-1;
                   9886:                 }
                   9887:                 my @parents = ($name);
                   9888:                 if (ref($cats->[1]{$name}) eq 'ARRAY') {
                   9889:                     for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
                   9890:                         my $category = $cats->[1]{$name}[$j];
1.665     raeburn  9891:                         if (ref($subcats) eq 'HASH') {
                   9892:                             push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
                   9893:                         }
                   9894:                         &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
                   9895:                     }
                   9896:                 } else {
                   9897:                     if (ref($subcats) eq 'HASH') {
                   9898:                         $subcats->{$item} = [];
1.655     raeburn  9899:                     }
                   9900:                 }
                   9901:             }
                   9902:         }
                   9903:     }
                   9904:     return;
                   9905: }
                   9906: 
                   9907: =pod
                   9908: 
                   9909: =item *&recurse_categories()
                   9910: 
                   9911: Recursively used to generate breadcrumb trails for course categories.
                   9912: 
                   9913: Inputs:
1.663     raeburn  9914: 
1.655     raeburn  9915: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   9916:       categories and subcategories).
1.663     raeburn  9917: 
1.655     raeburn  9918: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663     raeburn  9919: 
                   9920: category (current course category, for which breadcrumb trail is being generated).
                   9921: 
                   9922: trails (reference to array of breadcrumb trails for each category).
                   9923: 
1.655     raeburn  9924: allitems (reference to hash - key is category key
                   9925:          (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663     raeburn  9926: 
1.655     raeburn  9927: parents (array containing containers directories for current category, 
                   9928:          back to top level). 
                   9929: 
                   9930: Returns: nothing
                   9931: 
                   9932: Side effects: populates trails and allitems hash references
                   9933: 
                   9934: =cut
                   9935: 
                   9936: sub recurse_categories {
1.665     raeburn  9937:     my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655     raeburn  9938:     my $shallower = $depth - 1;
                   9939:     if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
                   9940:         for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
                   9941:             my $name = $cats->[$depth]{$category}[$k];
                   9942:             my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
                   9943:             my $trailstr = join(' -&gt; ',(@{$parents},$category));
                   9944:             if ($allitems->{$item} eq '') {
                   9945:                 push(@{$trails},$trailstr);
                   9946:                 $allitems->{$item} = scalar(@{$trails})-1;
                   9947:             }
                   9948:             my $deeper = $depth+1;
                   9949:             push(@{$parents},$category);
1.665     raeburn  9950:             if (ref($subcats) eq 'HASH') {
                   9951:                 my $subcat = &escape($name).':'.$category.':'.$depth;
                   9952:                 for (my $j=@{$parents}; $j>=0; $j--) {
                   9953:                     my $higher;
                   9954:                     if ($j > 0) {
                   9955:                         $higher = &escape($parents->[$j]).':'.
                   9956:                                   &escape($parents->[$j-1]).':'.$j;
                   9957:                     } else {
                   9958:                         $higher = &escape($parents->[$j]).'::'.$j;
                   9959:                     }
                   9960:                     push(@{$subcats->{$higher}},$subcat);
                   9961:                 }
                   9962:             }
                   9963:             &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
                   9964:                                 $subcats);
1.655     raeburn  9965:             pop(@{$parents});
                   9966:         }
                   9967:     } else {
                   9968:         my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
                   9969:         my $trailstr = join(' -&gt; ',(@{$parents},$category));
                   9970:         if ($allitems->{$item} eq '') {
                   9971:             push(@{$trails},$trailstr);
                   9972:             $allitems->{$item} = scalar(@{$trails})-1;
                   9973:         }
                   9974:     }
                   9975:     return;
                   9976: }
                   9977: 
1.663     raeburn  9978: =pod
                   9979: 
                   9980: =item *&assign_categories_table()
                   9981: 
                   9982: Create a datatable for display of hierarchical categories in a domain,
                   9983: with checkboxes to allow a course to be categorized. 
                   9984: 
                   9985: Inputs:
                   9986: 
                   9987: cathash - reference to hash of categories defined for the domain (from
                   9988:           configuration.db)
                   9989: 
                   9990: currcat - scalar with an & separated list of categories assigned to a course. 
                   9991: 
1.919     raeburn  9992: type    - scalar contains course type (Course or Community).
                   9993: 
1.663     raeburn  9994: Returns: $output (markup to be displayed) 
                   9995: 
                   9996: =cut
                   9997: 
                   9998: sub assign_categories_table {
1.919     raeburn  9999:     my ($cathash,$currcat,$type) = @_;
1.663     raeburn  10000:     my $output;
                   10001:     if (ref($cathash) eq 'HASH') {
                   10002:         my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
                   10003:         &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
                   10004:         $maxdepth = scalar(@cats);
                   10005:         if (@cats > 0) {
                   10006:             my $itemcount = 0;
                   10007:             if (ref($cats[0]) eq 'ARRAY') {
                   10008:                 my @currcategories;
                   10009:                 if ($currcat ne '') {
                   10010:                     @currcategories = split('&',$currcat);
                   10011:                 }
1.919     raeburn  10012:                 my $table;
1.663     raeburn  10013:                 for (my $i=0; $i<@{$cats[0]}; $i++) {
                   10014:                     my $parent = $cats[0][$i];
1.919     raeburn  10015:                     next if ($parent eq 'instcode');
                   10016:                     if ($type eq 'Community') {
                   10017:                         next unless ($parent eq 'communities');
                   10018:                     } else {
                   10019:                         next if ($parent eq 'communities');
                   10020:                     }
1.663     raeburn  10021:                     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   10022:                     my $item = &escape($parent).'::0';
                   10023:                     my $checked = '';
                   10024:                     if (@currcategories > 0) {
                   10025:                         if (grep(/^\Q$item\E$/,@currcategories)) {
1.772     bisitz   10026:                             $checked = ' checked="checked"';
1.663     raeburn  10027:                         }
                   10028:                     }
1.919     raeburn  10029:                     my $parent_title = $parent;
                   10030:                     if ($parent eq 'communities') {
                   10031:                         $parent_title = &mt('Communities');
                   10032:                     }
                   10033:                     $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
                   10034:                               '<input type="checkbox" name="usecategory" value="'.
                   10035:                               $item.'"'.$checked.' />'.$parent_title.'</span>'.
                   10036:                               '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663     raeburn  10037:                     my $depth = 1;
                   10038:                     push(@path,$parent);
1.919     raeburn  10039:                     $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663     raeburn  10040:                     pop(@path);
1.919     raeburn  10041:                     $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663     raeburn  10042:                     $itemcount ++;
                   10043:                 }
1.919     raeburn  10044:                 if ($itemcount) {
                   10045:                     $output = &Apache::loncommon::start_data_table().
                   10046:                               $table.
                   10047:                               &Apache::loncommon::end_data_table();
                   10048:                 }
1.663     raeburn  10049:             }
                   10050:         }
                   10051:     }
                   10052:     return $output;
                   10053: }
                   10054: 
                   10055: =pod
                   10056: 
                   10057: =item *&assign_category_rows()
                   10058: 
                   10059: Create a datatable row for display of nested categories in a domain,
                   10060: with checkboxes to allow a course to be categorized,called recursively.
                   10061: 
                   10062: Inputs:
                   10063: 
                   10064: itemcount - track row number for alternating colors
                   10065: 
                   10066: cats - reference to array of arrays/hashes which encapsulates hierarchy of
                   10067:       categories and subcategories.
                   10068: 
                   10069: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
                   10070: 
                   10071: parent - parent of current category item
                   10072: 
                   10073: path - Array containing all categories back up through the hierarchy from the
                   10074:        current category to the top level.
                   10075: 
                   10076: currcategories - reference to array of current categories assigned to the course
                   10077: 
                   10078: Returns: $output (markup to be displayed).
                   10079: 
                   10080: =cut
                   10081: 
                   10082: sub assign_category_rows {
                   10083:     my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
                   10084:     my ($text,$name,$item,$chgstr);
                   10085:     if (ref($cats) eq 'ARRAY') {
                   10086:         my $maxdepth = scalar(@{$cats});
                   10087:         if (ref($cats->[$depth]) eq 'HASH') {
                   10088:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   10089:                 my $numchildren = @{$cats->[$depth]{$parent}};
                   10090:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   10091:                 $text .= '<td><table class="LC_datatable">';
                   10092:                 for (my $j=0; $j<$numchildren; $j++) {
                   10093:                     $name = $cats->[$depth]{$parent}[$j];
                   10094:                     $item = &escape($name).':'.&escape($parent).':'.$depth;
                   10095:                     my $deeper = $depth+1;
                   10096:                     my $checked = '';
                   10097:                     if (ref($currcategories) eq 'ARRAY') {
                   10098:                         if (@{$currcategories} > 0) {
                   10099:                             if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772     bisitz   10100:                                 $checked = ' checked="checked"';
1.663     raeburn  10101:                             }
                   10102:                         }
                   10103:                     }
1.664     raeburn  10104:                     $text .= '<tr><td><span class="LC_nobreak"><label>'.
                   10105:                              '<input type="checkbox" name="usecategory" value="'.
1.675     raeburn  10106:                              $item.'"'.$checked.' />'.$name.'</label></span>'.
                   10107:                              '<input type="hidden" name="catname" value="'.$name.'" />'.
                   10108:                              '</td><td>';
1.663     raeburn  10109:                     if (ref($path) eq 'ARRAY') {
                   10110:                         push(@{$path},$name);
                   10111:                         $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
                   10112:                         pop(@{$path});
                   10113:                     }
                   10114:                     $text .= '</td></tr>';
                   10115:                 }
                   10116:                 $text .= '</table></td>';
                   10117:             }
                   10118:         }
                   10119:     }
                   10120:     return $text;
                   10121: }
                   10122: 
1.655     raeburn  10123: ############################################################
                   10124: ############################################################
                   10125: 
                   10126: 
1.443     albertel 10127: sub commit_customrole {
1.664     raeburn  10128:     my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630     raeburn  10129:     my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443     albertel 10130:                          ($start?', '.&mt('starting').' '.localtime($start):'').
                   10131:                          ($end?', ending '.localtime($end):'').': <b>'.
                   10132:               &Apache::lonnet::assigncustomrole(
1.664     raeburn  10133:                  $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443     albertel 10134:                  '</b><br />';
                   10135:     return $output;
                   10136: }
                   10137: 
                   10138: sub commit_standardrole {
1.541     raeburn  10139:     my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
                   10140:     my ($output,$logmsg,$linefeed);
                   10141:     if ($context eq 'auto') {
                   10142:         $linefeed = "\n";
                   10143:     } else {
                   10144:         $linefeed = "<br />\n";
                   10145:     }  
1.443     albertel 10146:     if ($three eq 'st') {
1.541     raeburn  10147:         my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
                   10148:                                          $one,$two,$sec,$context);
                   10149:         if (($result =~ /^error/) || ($result eq 'not_in_class') || 
1.626     raeburn  10150:             ($result eq 'unknown_course') || ($result eq 'refused')) {
                   10151:             $output = $logmsg.' '.&mt('Error: ').$result."\n"; 
1.443     albertel 10152:         } else {
1.541     raeburn  10153:             $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443     albertel 10154:                ($start?', '.&mt('starting').' '.localtime($start):'').
1.541     raeburn  10155:                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
                   10156:             if ($context eq 'auto') {
                   10157:                 $output .= $result.$linefeed.&mt('Add to classlist').': ok';
                   10158:             } else {
                   10159:                $output .= '<b>'.$result.'</b>'.$linefeed.
                   10160:                &mt('Add to classlist').': <b>ok</b>';
                   10161:             }
                   10162:             $output .= $linefeed;
1.443     albertel 10163:         }
                   10164:     } else {
                   10165:         $output = &mt('Assigning').' '.$three.' in '.$url.
                   10166:                ($start?', '.&mt('starting').' '.localtime($start):'').
1.541     raeburn  10167:                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652     raeburn  10168:         my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541     raeburn  10169:         if ($context eq 'auto') {
                   10170:             $output .= $result.$linefeed;
                   10171:         } else {
                   10172:             $output .= '<b>'.$result.'</b>'.$linefeed;
                   10173:         }
1.443     albertel 10174:     }
                   10175:     return $output;
                   10176: }
                   10177: 
                   10178: sub commit_studentrole {
1.541     raeburn  10179:     my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626     raeburn  10180:     my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541     raeburn  10181:     if ($context eq 'auto') {
                   10182:         $linefeed = "\n";
                   10183:     } else {
                   10184:         $linefeed = '<br />'."\n";
                   10185:     }
1.443     albertel 10186:     if (defined($one) && defined($two)) {
                   10187:         my $cid=$one.'_'.$two;
                   10188:         my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
                   10189:         my $secchange = 0;
                   10190:         my $expire_role_result;
                   10191:         my $modify_section_result;
1.628     raeburn  10192:         if ($oldsec ne '-1') { 
                   10193:             if ($oldsec ne $sec) {
1.443     albertel 10194:                 $secchange = 1;
1.628     raeburn  10195:                 my $now = time;
1.443     albertel 10196:                 my $uurl='/'.$cid;
                   10197:                 $uurl=~s/\_/\//g;
                   10198:                 if ($oldsec) {
                   10199:                     $uurl.='/'.$oldsec;
                   10200:                 }
1.626     raeburn  10201:                 $oldsecurl = $uurl;
1.628     raeburn  10202:                 $expire_role_result = 
1.652     raeburn  10203:                     &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628     raeburn  10204:                 if ($env{'request.course.sec'} ne '') { 
                   10205:                     if ($expire_role_result eq 'refused') {
                   10206:                         my @roles = ('st');
                   10207:                         my @statuses = ('previous');
                   10208:                         my @roledoms = ($one);
                   10209:                         my $withsec = 1;
                   10210:                         my %roleshash = 
                   10211:                             &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
                   10212:                                               \@statuses,\@roles,\@roledoms,$withsec);
                   10213:                         if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
                   10214:                             my ($oldstart,$oldend) = 
                   10215:                                 split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
                   10216:                             if ($oldend > 0 && $oldend <= $now) {
                   10217:                                 $expire_role_result = 'ok';
                   10218:                             }
                   10219:                         }
                   10220:                     }
                   10221:                 }
1.443     albertel 10222:                 $result = $expire_role_result;
                   10223:             }
                   10224:         }
                   10225:         if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652     raeburn  10226:             $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443     albertel 10227:             if ($modify_section_result =~ /^ok/) {
                   10228:                 if ($secchange == 1) {
1.628     raeburn  10229:                     if ($sec eq '') {
                   10230:                         $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
                   10231:                     } else {
                   10232:                         $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
                   10233:                     }
1.443     albertel 10234:                 } elsif ($oldsec eq '-1') {
1.628     raeburn  10235:                     if ($sec eq '') {
                   10236:                         $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
                   10237:                     } else {
                   10238:                         $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                   10239:                     }
1.443     albertel 10240:                 } else {
1.628     raeburn  10241:                     if ($sec eq '') {
                   10242:                         $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
                   10243:                     } else {
                   10244:                         $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                   10245:                     }
1.443     albertel 10246:                 }
                   10247:             } else {
1.628     raeburn  10248:                 if ($secchange) {       
                   10249:                     $$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;
                   10250:                 } else {
                   10251:                     $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
                   10252:                 }
1.443     albertel 10253:             }
                   10254:             $result = $modify_section_result;
                   10255:         } elsif ($secchange == 1) {
1.628     raeburn  10256:             if ($oldsec eq '') {
                   10257:                 $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
                   10258:             } else {
                   10259:                 $$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;
                   10260:             }
1.626     raeburn  10261:             if ($expire_role_result eq 'refused') {
                   10262:                 my $newsecurl = '/'.$cid;
                   10263:                 $newsecurl =~ s/\_/\//g;
                   10264:                 if ($sec ne '') {
                   10265:                     $newsecurl.='/'.$sec;
                   10266:                 }
                   10267:                 if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
                   10268:                     if ($sec eq '') {
                   10269:                         $$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;
                   10270:                     } else {
                   10271:                         $$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;
                   10272:                     }
                   10273:                 }
                   10274:             }
1.443     albertel 10275:         }
                   10276:     } else {
1.626     raeburn  10277:         $$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 10278:         $result = "error: incomplete course id\n";
                   10279:     }
                   10280:     return $result;
                   10281: }
                   10282: 
                   10283: ############################################################
                   10284: ############################################################
                   10285: 
1.566     albertel 10286: sub check_clone {
1.578     raeburn  10287:     my ($args,$linefeed) = @_;
1.566     albertel 10288:     my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
                   10289:     my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
                   10290:     my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
                   10291:     my $clonemsg;
                   10292:     my $can_clone = 0;
1.944     raeburn  10293:     my $lctype = lc($args->{'crstype'});
1.908     raeburn  10294:     if ($lctype ne 'community') {
                   10295:         $lctype = 'course';
                   10296:     }
1.566     albertel 10297:     if ($clonehome eq 'no_host') {
1.944     raeburn  10298:         if ($args->{'crstype'} eq 'Community') {
1.908     raeburn  10299:             $clonemsg = &mt('No new community created.').$linefeed.&mt('A new community could not be cloned from the specified original - [_1] - because it is a non-existent community.',$args->{'clonecourse'}.':'.$args->{'clonedomain'});
                   10300:         } else {
                   10301:             $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'});
                   10302:         }     
1.566     albertel 10303:     } else {
                   10304: 	my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944     raeburn  10305:         if ($args->{'crstype'} eq 'Community') {
1.908     raeburn  10306:             if ($clonedesc{'type'} ne 'Community') {
                   10307:                  $clonemsg = &mt('No new community created.').$linefeed.&mt('A new community could not be cloned from the specified original - [_1] - because it is a course not a community.',$args->{'clonecourse'}.':'.$args->{'clonedomain'});
                   10308:                 return ($can_clone, $clonemsg, $cloneid, $clonehome);
                   10309:             }
                   10310:         }
1.882     raeburn  10311: 	if (($env{'request.role.domain'} eq $args->{'clonedomain'}) && 
                   10312:             (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566     albertel 10313: 	    $can_clone = 1;
                   10314: 	} else {
                   10315: 	    my %clonehash = &Apache::lonnet::get('environment',['cloners'],
                   10316: 						 $args->{'clonedomain'},$args->{'clonecourse'});
                   10317: 	    my @cloners = split(/,/,$clonehash{'cloners'});
1.578     raeburn  10318:             if (grep(/^\*$/,@cloners)) {
                   10319:                 $can_clone = 1;
                   10320:             } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
                   10321:                 $can_clone = 1;
                   10322:             } else {
1.908     raeburn  10323:                 my $ccrole = 'cc';
1.944     raeburn  10324:                 if ($args->{'crstype'} eq 'Community') {
1.908     raeburn  10325:                     $ccrole = 'co';
                   10326:                 }
1.578     raeburn  10327: 	        my %roleshash =
                   10328: 		    &Apache::lonnet::get_my_roles($args->{'ccuname'},
                   10329: 					 $args->{'ccdomain'},
1.908     raeburn  10330:                                          'userroles',['active'],[$ccrole],
1.578     raeburn  10331: 					 [$args->{'clonedomain'}]);
1.908     raeburn  10332: 	        if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
1.942     raeburn  10333:                     $can_clone = 1;
                   10334:                 } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},$args->{'ccuname'},$args->{'ccdomain'})) {
                   10335:                     $can_clone = 1;
                   10336:                 } else {
1.944     raeburn  10337:                     if ($args->{'crstype'} eq 'Community') {
1.908     raeburn  10338:                         $clonemsg = &mt('No new community created.').$linefeed.&mt('The new community could not be cloned from the existing community because the new community owner ([_1]) does not have cloning rights in the existing community ([_2]).',$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'});
                   10339:                     } else {
                   10340:                         $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'});
                   10341:                     }
1.578     raeburn  10342: 	        }
1.566     albertel 10343: 	    }
1.578     raeburn  10344:         }
1.566     albertel 10345:     }
                   10346:     return ($can_clone, $clonemsg, $cloneid, $clonehome);
                   10347: }
                   10348: 
1.444     albertel 10349: sub construct_course {
1.885     raeburn  10350:     my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category) = @_;
1.444     albertel 10351:     my $outcome;
1.541     raeburn  10352:     my $linefeed =  '<br />'."\n";
                   10353:     if ($context eq 'auto') {
                   10354:         $linefeed = "\n";
                   10355:     }
1.566     albertel 10356: 
                   10357: #
                   10358: # Are we cloning?
                   10359: #
                   10360:     my ($can_clone, $clonemsg, $cloneid, $clonehome);
                   10361:     if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578     raeburn  10362: 	($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566     albertel 10363: 	if ($context ne 'auto') {
1.578     raeburn  10364:             if ($clonemsg ne '') {
                   10365: 	        $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
                   10366:             }
1.566     albertel 10367: 	}
                   10368: 	$outcome .= $clonemsg.$linefeed;
                   10369: 
                   10370:         if (!$can_clone) {
                   10371: 	    return (0,$outcome);
                   10372: 	}
                   10373:     }
                   10374: 
1.444     albertel 10375: #
                   10376: # Open course
                   10377: #
                   10378:     my $crstype = lc($args->{'crstype'});
                   10379:     my %cenv=();
                   10380:     $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
                   10381:                                              $args->{'cdescr'},
                   10382:                                              $args->{'curl'},
                   10383:                                              $args->{'course_home'},
                   10384:                                              $args->{'nonstandard'},
                   10385:                                              $args->{'crscode'},
                   10386:                                              $args->{'ccuname'}.':'.
                   10387:                                              $args->{'ccdomain'},
1.882     raeburn  10388:                                              $args->{'crstype'},
1.885     raeburn  10389:                                              $cnum,$context,$category);
1.444     albertel 10390: 
                   10391:     # Note: The testing routines depend on this being output; see 
                   10392:     # Utils::Course. This needs to at least be output as a comment
                   10393:     # if anyone ever decides to not show this, and Utils::Course::new
                   10394:     # will need to be suitably modified.
1.541     raeburn  10395:     $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943     raeburn  10396:     if ($$courseid =~ /^error:/) {
                   10397:         return (0,$outcome);
                   10398:     }
                   10399: 
1.444     albertel 10400: #
                   10401: # Check if created correctly
                   10402: #
1.479     albertel 10403:     ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444     albertel 10404:     my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943     raeburn  10405:     if ($crsuhome eq 'no_host') {
                   10406:         $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
                   10407:         return (0,$outcome);
                   10408:     }
1.541     raeburn  10409:     $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566     albertel 10410: 
1.444     albertel 10411: #
1.566     albertel 10412: # Do the cloning
                   10413: #   
                   10414:     if ($can_clone && $cloneid) {
                   10415: 	$clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
                   10416: 	if ($context ne 'auto') {
                   10417: 	    $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
                   10418: 	}
                   10419: 	$outcome .= $clonemsg.$linefeed;
                   10420: 	my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444     albertel 10421: # Copy all files
1.637     www      10422: 	&Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444     albertel 10423: # Restore URL
1.566     albertel 10424: 	$cenv{'url'}=$oldcenv{'url'};
1.444     albertel 10425: # Restore title
1.566     albertel 10426: 	$cenv{'description'}=$oldcenv{'description'};
1.948.2.2  raeburn  10427: # Restore creation date, creator and creation context.
                   10428:         $cenv{'internal.created'}=$oldcenv{'internal.created'};
                   10429:         $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
                   10430:         $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444     albertel 10431: # Mark as cloned
1.566     albertel 10432: 	$cenv{'clonedfrom'}=$cloneid;
1.638     www      10433: # Need to clone grading mode
                   10434:         my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
                   10435:         $cenv{'grading'}=$newenv{'grading'};
                   10436: # Do not clone these environment entries
                   10437:         &Apache::lonnet::del('environment',
                   10438:                   ['default_enrollment_start_date',
                   10439:                    'default_enrollment_end_date',
                   10440:                    'question.email',
                   10441:                    'policy.email',
                   10442:                    'comment.email',
                   10443:                    'pch.users.denied',
1.725     raeburn  10444:                    'plc.users.denied',
                   10445:                    'hidefromcat',
                   10446:                    'categories'],
1.638     www      10447:                    $$crsudom,$$crsunum);
1.444     albertel 10448:     }
1.566     albertel 10449: 
1.444     albertel 10450: #
                   10451: # Set environment (will override cloned, if existing)
                   10452: #
                   10453:     my @sections = ();
                   10454:     my @xlists = ();
                   10455:     if ($args->{'crstype'}) {
                   10456:         $cenv{'type'}=$args->{'crstype'};
                   10457:     }
                   10458:     if ($args->{'crsid'}) {
                   10459:         $cenv{'courseid'}=$args->{'crsid'};
                   10460:     }
                   10461:     if ($args->{'crscode'}) {
                   10462:         $cenv{'internal.coursecode'}=$args->{'crscode'};
                   10463:     }
                   10464:     if ($args->{'crsquota'} ne '') {
                   10465:         $cenv{'internal.coursequota'}=$args->{'crsquota'};
                   10466:     } else {
                   10467:         $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
                   10468:     }
                   10469:     if ($args->{'ccuname'}) {
                   10470:         $cenv{'internal.courseowner'} = $args->{'ccuname'}.
                   10471:                                         ':'.$args->{'ccdomain'};
                   10472:     } else {
                   10473:         $cenv{'internal.courseowner'} = $args->{'curruser'};
                   10474:     }
                   10475:     my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
                   10476:     if ($args->{'crssections'}) {
                   10477:         $cenv{'internal.sectionnums'} = '';
                   10478:         if ($args->{'crssections'} =~ m/,/) {
                   10479:             @sections = split/,/,$args->{'crssections'};
                   10480:         } else {
                   10481:             $sections[0] = $args->{'crssections'};
                   10482:         }
                   10483:         if (@sections > 0) {
                   10484:             foreach my $item (@sections) {
                   10485:                 my ($sec,$gp) = split/:/,$item;
                   10486:                 my $class = $args->{'crscode'}.$sec;
                   10487:                 my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
                   10488:                 $cenv{'internal.sectionnums'} .= $item.',';
                   10489:                 unless ($addcheck eq 'ok') {
                   10490:                     push @badclasses, $class;
                   10491:                 }
                   10492:             }
                   10493:             $cenv{'internal.sectionnums'} =~ s/,$//;
                   10494:         }
                   10495:     }
                   10496: # do not hide course coordinator from staff listing, 
                   10497: # even if privileged
                   10498:     $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   10499: # add crosslistings
                   10500:     if ($args->{'crsxlist'}) {
                   10501:         $cenv{'internal.crosslistings'}='';
                   10502:         if ($args->{'crsxlist'} =~ m/,/) {
                   10503:             @xlists = split/,/,$args->{'crsxlist'};
                   10504:         } else {
                   10505:             $xlists[0] = $args->{'crsxlist'};
                   10506:         }
                   10507:         if (@xlists > 0) {
                   10508:             foreach my $item (@xlists) {
                   10509:                 my ($xl,$gp) = split/:/,$item;
                   10510:                 my $addcheck =  &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
                   10511:                 $cenv{'internal.crosslistings'} .= $item.',';
                   10512:                 unless ($addcheck eq 'ok') {
                   10513:                     push @badclasses, $xl;
                   10514:                 }
                   10515:             }
                   10516:             $cenv{'internal.crosslistings'} =~ s/,$//;
                   10517:         }
                   10518:     }
                   10519:     if ($args->{'autoadds'}) {
                   10520:         $cenv{'internal.autoadds'}=$args->{'autoadds'};
                   10521:     }
                   10522:     if ($args->{'autodrops'}) {
                   10523:         $cenv{'internal.autodrops'}=$args->{'autodrops'};
                   10524:     }
                   10525: # check for notification of enrollment changes
                   10526:     my @notified = ();
                   10527:     if ($args->{'notify_owner'}) {
                   10528:         if ($args->{'ccuname'} ne '') {
                   10529:             push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
                   10530:         }
                   10531:     }
                   10532:     if ($args->{'notify_dc'}) {
                   10533:         if ($uname ne '') { 
1.630     raeburn  10534:             push(@notified,$uname.':'.$udom);
1.444     albertel 10535:         }
                   10536:     }
                   10537:     if (@notified > 0) {
                   10538:         my $notifylist;
                   10539:         if (@notified > 1) {
                   10540:             $notifylist = join(',',@notified);
                   10541:         } else {
                   10542:             $notifylist = $notified[0];
                   10543:         }
                   10544:         $cenv{'internal.notifylist'} = $notifylist;
                   10545:     }
                   10546:     if (@badclasses > 0) {
                   10547:         my %lt=&Apache::lonlocal::texthash(
                   10548:                 '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',
                   10549:                 'dnhr' => 'does not have rights to access enrollment in these classes',
                   10550:                 'adby' => 'as determined by the policies of your institution on access to official classlists'
                   10551:         );
1.541     raeburn  10552:         my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
                   10553:                            ' ('.$lt{'adby'}.')';
                   10554:         if ($context eq 'auto') {
                   10555:             $outcome .= $badclass_msg.$linefeed;
1.566     albertel 10556:             $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541     raeburn  10557:             foreach my $item (@badclasses) {
                   10558:                 if ($context eq 'auto') {
                   10559:                     $outcome .= " - $item\n";
                   10560:                 } else {
                   10561:                     $outcome .= "<li>$item</li>\n";
                   10562:                 }
                   10563:             }
                   10564:             if ($context eq 'auto') {
                   10565:                 $outcome .= $linefeed;
                   10566:             } else {
1.566     albertel 10567:                 $outcome .= "</ul><br /><br /></div>\n";
1.541     raeburn  10568:             }
                   10569:         } 
1.444     albertel 10570:     }
                   10571:     if ($args->{'no_end_date'}) {
                   10572:         $args->{'endaccess'} = 0;
                   10573:     }
                   10574:     $cenv{'internal.autostart'}=$args->{'enrollstart'};
                   10575:     $cenv{'internal.autoend'}=$args->{'enrollend'};
                   10576:     $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
                   10577:     $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
                   10578:     if ($args->{'showphotos'}) {
                   10579:       $cenv{'internal.showphotos'}=$args->{'showphotos'};
                   10580:     }
                   10581:     $cenv{'internal.authtype'} = $args->{'authtype'};
                   10582:     $cenv{'internal.autharg'} = $args->{'autharg'}; 
                   10583:     if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
                   10584:         if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'}  eq '') {
1.541     raeburn  10585:             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'); 
                   10586:             if ($context eq 'auto') {
                   10587:                 $outcome .= $krb_msg;
                   10588:             } else {
1.566     albertel 10589:                 $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541     raeburn  10590:             }
                   10591:             $outcome .= $linefeed;
1.444     albertel 10592:         }
                   10593:     }
                   10594:     if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
                   10595:        if ($args->{'setpolicy'}) {
                   10596:            $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   10597:        }
                   10598:        if ($args->{'setcontent'}) {
                   10599:            $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   10600:        }
                   10601:     }
                   10602:     if ($args->{'reshome'}) {
                   10603: 	$cenv{'reshome'}=$args->{'reshome'}.'/';
                   10604: 	$cenv{'reshome'}=~s/\/+$/\//;
                   10605:     }
                   10606: #
                   10607: # course has keyed access
                   10608: #
                   10609:     if ($args->{'setkeys'}) {
                   10610:        $cenv{'keyaccess'}='yes';
                   10611:     }
                   10612: # if specified, key authority is not course, but user
                   10613: # only active if keyaccess is yes
                   10614:     if ($args->{'keyauth'}) {
1.487     albertel 10615: 	my ($user,$domain) = split(':',$args->{'keyauth'});
                   10616: 	$user = &LONCAPA::clean_username($user);
                   10617: 	$domain = &LONCAPA::clean_username($domain);
1.488     foxr     10618: 	if ($user ne '' && $domain ne '') {
1.487     albertel 10619: 	    $cenv{'keyauth'}=$user.':'.$domain;
1.444     albertel 10620: 	}
                   10621:     }
                   10622: 
                   10623:     if ($args->{'disresdis'}) {
                   10624:         $cenv{'pch.roles.denied'}='st';
                   10625:     }
                   10626:     if ($args->{'disablechat'}) {
                   10627:         $cenv{'plc.roles.denied'}='st';
                   10628:     }
                   10629: 
                   10630:     # Record we've not yet viewed the Course Initialization Helper for this 
                   10631:     # course
                   10632:     $cenv{'course.helper.not.run'} = 1;
                   10633:     #
                   10634:     # Use new Randomseed
                   10635:     #
                   10636:     $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
                   10637:     $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
                   10638:     #
                   10639:     # The encryption code and receipt prefix for this course
                   10640:     #
                   10641:     $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
                   10642:     $cenv{'internal.encpref'}=100+int(9*rand(99));
                   10643:     #
                   10644:     # By default, use standard grading
                   10645:     if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
                   10646: 
1.541     raeburn  10647:     $outcome .= $linefeed.&mt('Setting environment').': '.                 
                   10648:           &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444     albertel 10649: #
                   10650: # Open all assignments
                   10651: #
                   10652:     if ($args->{'openall'}) {
                   10653:        my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
                   10654:        my %storecontent = ($storeunder         => time,
                   10655:                            $storeunder.'.type' => 'date_start');
                   10656:        
                   10657:        $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541     raeburn  10658:                  ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444     albertel 10659:    }
                   10660: #
                   10661: # Set first page
                   10662: #
                   10663:     unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
                   10664: 	    || ($cloneid)) {
1.445     albertel 10665: 	use LONCAPA::map;
1.444     albertel 10666: 	$outcome .= &mt('Setting first resource').': ';
1.445     albertel 10667: 
                   10668: 	my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
                   10669:         my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
                   10670: 
1.444     albertel 10671:         $outcome .= ($fatal?$errtext:'read ok').' - ';
                   10672:         my $title; my $url;
                   10673:         if ($args->{'firstres'} eq 'syl') {
1.690     bisitz   10674: 	    $title=&mt('Syllabus');
1.444     albertel 10675:             $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
                   10676:         } else {
1.948.2.5  raeburn  10677:             $title=&mt('Table of Contents');
1.444     albertel 10678:             $url='/adm/navmaps';
                   10679:         }
1.445     albertel 10680: 
                   10681:         $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
                   10682: 	(my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
                   10683: 
                   10684: 	if ($errtext) { $fatal=2; }
1.541     raeburn  10685:         $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444     albertel 10686:     }
1.566     albertel 10687: 
                   10688:     return (1,$outcome);
1.444     albertel 10689: }
                   10690: 
                   10691: ############################################################
                   10692: ############################################################
                   10693: 
1.378     raeburn  10694: sub course_type {
                   10695:     my ($cid) = @_;
                   10696:     if (!defined($cid)) {
                   10697:         $cid = $env{'request.course.id'};
                   10698:     }
1.404     albertel 10699:     if (defined($env{'course.'.$cid.'.type'})) {
                   10700:         return $env{'course.'.$cid.'.type'};
1.378     raeburn  10701:     } else {
                   10702:         return 'Course';
1.377     raeburn  10703:     }
                   10704: }
1.156     albertel 10705: 
1.406     raeburn  10706: sub group_term {
                   10707:     my $crstype = &course_type();
                   10708:     my %names = (
                   10709:                   'Course' => 'group',
1.865     raeburn  10710:                   'Community' => 'group',
1.406     raeburn  10711:                 );
                   10712:     return $names{$crstype};
                   10713: }
                   10714: 
1.902     raeburn  10715: sub course_types {
                   10716:     my @types = ('official','unofficial','community');
                   10717:     my %typename = (
                   10718:                          official   => 'Official course',
                   10719:                          unofficial => 'Unofficial course',
                   10720:                          community  => 'Community',
                   10721:                    );
                   10722:     return (\@types,\%typename);
                   10723: }
                   10724: 
1.156     albertel 10725: sub icon {
                   10726:     my ($file)=@_;
1.505     albertel 10727:     my $curfext = lc((split(/\./,$file))[-1]);
1.168     albertel 10728:     my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156     albertel 10729:     my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168     albertel 10730:     if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
                   10731: 	if (-e  $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
                   10732: 	          $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   10733: 	            $curfext.".gif") {
                   10734: 	    $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   10735: 		$curfext.".gif";
                   10736: 	}
                   10737:     }
1.249     albertel 10738:     return &lonhttpdurl($iconname);
1.154     albertel 10739: } 
1.84      albertel 10740: 
1.575     albertel 10741: sub lonhttpdurl {
1.692     www      10742: #
                   10743: # Had been used for "small fry" static images on separate port 8080.
                   10744: # Modify here if lightweight http functionality desired again.
                   10745: # Currently eliminated due to increasing firewall issues.
                   10746: #
1.575     albertel 10747:     my ($url)=@_;
1.692     www      10748:     return $url;
1.215     albertel 10749: }
                   10750: 
1.213     albertel 10751: sub connection_aborted {
                   10752:     my ($r)=@_;
                   10753:     $r->print(" ");$r->rflush();
                   10754:     my $c = $r->connection;
                   10755:     return $c->aborted();
                   10756: }
                   10757: 
1.221     foxr     10758: #    Escapes strings that may have embedded 's that will be put into
1.222     foxr     10759: #    strings as 'strings'.
                   10760: sub escape_single {
1.221     foxr     10761:     my ($input) = @_;
1.223     albertel 10762:     $input =~ s/\\/\\\\/g;	# Escape the \'s..(must be first)>
1.221     foxr     10763:     $input =~ s/\'/\\\'/g;	# Esacpe the 's....
                   10764:     return $input;
                   10765: }
1.223     albertel 10766: 
1.222     foxr     10767: #  Same as escape_single, but escape's "'s  This 
                   10768: #  can be used for  "strings"
                   10769: sub escape_double {
                   10770:     my ($input) = @_;
                   10771:     $input =~ s/\\/\\\\/g;	# Escape the /'s..(must be first)>
                   10772:     $input =~ s/\"/\\\"/g;	# Esacpe the "s....
                   10773:     return $input;
                   10774: }
1.223     albertel 10775:  
1.222     foxr     10776: #   Escapes the last element of a full URL.
                   10777: sub escape_url {
                   10778:     my ($url)   = @_;
1.238     raeburn  10779:     my @urlslices = split(/\//, $url,-1);
1.369     www      10780:     my $lastitem = &escape(pop(@urlslices));
1.223     albertel 10781:     return join('/',@urlslices).'/'.$lastitem;
1.222     foxr     10782: }
1.462     albertel 10783: 
1.820     raeburn  10784: sub compare_arrays {
                   10785:     my ($arrayref1,$arrayref2) = @_;
                   10786:     my (@difference,%count);
                   10787:     @difference = ();
                   10788:     %count = ();
                   10789:     if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
                   10790:         foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
                   10791:         foreach my $element (keys(%count)) {
                   10792:             if ($count{$element} == 1) {
                   10793:                 push(@difference,$element);
                   10794:             }
                   10795:         }
                   10796:     }
                   10797:     return @difference;
                   10798: }
                   10799: 
1.817     bisitz   10800: # -------------------------------------------------------- Initialize user login
1.462     albertel 10801: sub init_user_environment {
1.463     albertel 10802:     my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462     albertel 10803:     my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
                   10804: 
                   10805:     my $public=($username eq 'public' && $domain eq 'public');
                   10806: 
                   10807: # See if old ID present, if so, remove
                   10808: 
                   10809:     my ($filename,$cookie,$userroles);
                   10810:     my $now=time;
                   10811: 
                   10812:     if ($public) {
                   10813: 	my $max_public=100;
                   10814: 	my $oldest;
                   10815: 	my $oldest_time=0;
                   10816: 	for(my $next=1;$next<=$max_public;$next++) {
                   10817: 	    if (-e $lonids."/publicuser_$next.id") {
                   10818: 		my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
                   10819: 		if ($mtime<$oldest_time || !$oldest_time) {
                   10820: 		    $oldest_time=$mtime;
                   10821: 		    $oldest=$next;
                   10822: 		}
                   10823: 	    } else {
                   10824: 		$cookie="publicuser_$next";
                   10825: 		last;
                   10826: 	    }
                   10827: 	}
                   10828: 	if (!$cookie) { $cookie="publicuser_$oldest"; }
                   10829:     } else {
1.463     albertel 10830: 	# if this isn't a robot, kill any existing non-robot sessions
                   10831: 	if (!$args->{'robot'}) {
                   10832: 	    opendir(DIR,$lonids);
                   10833: 	    while ($filename=readdir(DIR)) {
                   10834: 		if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
                   10835: 		    unlink($lonids.'/'.$filename);
                   10836: 		}
1.462     albertel 10837: 	    }
1.463     albertel 10838: 	    closedir(DIR);
1.462     albertel 10839: 	}
                   10840: # Give them a new cookie
1.463     albertel 10841: 	my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684     www      10842: 		                   : $now.$$.int(rand(10000)));
1.463     albertel 10843: 	$cookie="$username\_$id\_$domain\_$authhost";
1.462     albertel 10844:     
                   10845: # Initialize roles
                   10846: 
                   10847: 	$userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
                   10848:     }
                   10849: # ------------------------------------ Check browser type and MathML capability
                   10850: 
                   10851:     my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
                   10852:         $clientunicode,$clientos) = &decode_user_agent($r);
                   10853: 
                   10854: # ------------------------------------------------------------- Get environment
                   10855: 
                   10856:     my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
                   10857:     my ($tmp) = keys(%userenv);
                   10858:     if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   10859: 	# default remote control to off
                   10860: 	if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
                   10861:     } else {
                   10862: 	undef(%userenv);
                   10863:     }
                   10864:     if (($userenv{'interface'}) && (!$form->{'interface'})) {
                   10865: 	$form->{'interface'}=$userenv{'interface'};
                   10866:     }
                   10867:     $env{'environment.remote'}=$userenv{'remote'};
                   10868:     if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
                   10869: 
                   10870: # --------------- Do not trust query string to be put directly into environment
1.817     bisitz   10871:     foreach my $option ('interface','localpath','localres') {
                   10872:         $form->{$option}=~s/[\n\r\=]//gs;
1.462     albertel 10873:     }
                   10874: # --------------------------------------------------------- Write first profile
                   10875: 
                   10876:     {
                   10877: 	my %initial_env = 
                   10878: 	    ("user.name"          => $username,
                   10879: 	     "user.domain"        => $domain,
                   10880: 	     "user.home"          => $authhost,
                   10881: 	     "browser.type"       => $clientbrowser,
                   10882: 	     "browser.version"    => $clientversion,
                   10883: 	     "browser.mathml"     => $clientmathml,
                   10884: 	     "browser.unicode"    => $clientunicode,
                   10885: 	     "browser.os"         => $clientos,
                   10886: 	     "server.domain"      => $Apache::lonnet::perlvar{'lonDefDomain'},
                   10887: 	     "request.course.fn"  => '',
                   10888: 	     "request.course.uri" => '',
                   10889: 	     "request.course.sec" => '',
                   10890: 	     "request.role"       => 'cm',
                   10891: 	     "request.role.adv"   => $env{'user.adv'},
                   10892: 	     "request.host"       => $ENV{'REMOTE_ADDR'},);
                   10893: 
                   10894:         if ($form->{'localpath'}) {
                   10895: 	    $initial_env{"browser.localpath"}  = $form->{'localpath'};
                   10896: 	    $initial_env{"browser.localres"}   = $form->{'localres'};
                   10897:         }
                   10898: 	
                   10899: 	if ($public) {
                   10900: 	    $initial_env{"environment.remote"} = "off";
                   10901: 	}
                   10902: 	if ($form->{'interface'}) {
                   10903: 	    $form->{'interface'}=~s/\W//gs;
                   10904: 	    $initial_env{"browser.interface"} = $form->{'interface'};
                   10905: 	    $env{'browser.interface'}=$form->{'interface'};
                   10906: 	}
1.948.2.11  raeburn  10907:         my %is_adv = ( is_adv => $env{'user.adv'} );
1.948.2.10  raeburn  10908:         my %domdef = &Apache::lonnet::get_domain_defaults($domain);
1.462     albertel 10909: 
1.724     raeburn  10910:         foreach my $tool ('aboutme','blog','portfolio') {
                   10911:             $userenv{'availabletools.'.$tool} = 
1.948.2.10  raeburn  10912:                 &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
                   10913:                                                   undef,\%userenv,\%domdef,\%is_adv);
1.724     raeburn  10914:         }
                   10915: 
1.864     raeburn  10916:         foreach my $crstype ('official','unofficial','community') {
1.765     raeburn  10917:             $userenv{'canrequest.'.$crstype} =
                   10918:                 &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.948.2.10  raeburn  10919:                                                   'reload','requestcourses',
                   10920:                                                   \%userenv,\%domdef,\%is_adv);
1.765     raeburn  10921:         }
                   10922: 
1.462     albertel 10923: 	$env{'user.environment'} = "$lonids/$cookie.id";
                   10924: 	
                   10925: 	if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
                   10926: 		 &GDBM_WRCREAT(),0640)) {
                   10927: 	    &_add_to_env(\%disk_env,\%initial_env);
                   10928: 	    &_add_to_env(\%disk_env,\%userenv,'environment.');
                   10929: 	    &_add_to_env(\%disk_env,$userroles);
1.463     albertel 10930: 	    if (ref($args->{'extra_env'})) {
                   10931: 		&_add_to_env(\%disk_env,$args->{'extra_env'});
                   10932: 	    }
1.462     albertel 10933: 	    untie(%disk_env);
                   10934: 	} else {
1.705     tempelho 10935: 	    &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
                   10936: 			   'Could not create environment storage in lonauth: '.$!.'</span>');
1.462     albertel 10937: 	    return 'error: '.$!;
                   10938: 	}
                   10939:     }
                   10940:     $env{'request.role'}='cm';
                   10941:     $env{'request.role.adv'}=$env{'user.adv'};
                   10942:     $env{'browser.type'}=$clientbrowser;
                   10943: 
                   10944:     return $cookie;
                   10945: 
                   10946: }
                   10947: 
                   10948: sub _add_to_env {
                   10949:     my ($idf,$env_data,$prefix) = @_;
1.676     raeburn  10950:     if (ref($env_data) eq 'HASH') {
                   10951:         while (my ($key,$value) = each(%$env_data)) {
                   10952: 	    $idf->{$prefix.$key} = $value;
                   10953: 	    $env{$prefix.$key}   = $value;
                   10954:         }
1.462     albertel 10955:     }
                   10956: }
                   10957: 
1.685     tempelho 10958: # --- Get the symbolic name of a problem and the url
                   10959: sub get_symb {
                   10960:     my ($request,$silent) = @_;
1.726     raeburn  10961:     (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685     tempelho 10962:     my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
                   10963:     if ($symb eq '') {
                   10964:         if (!$silent) {
                   10965:             $request->print("Unable to handle ambiguous references:$url:.");
                   10966:             return ();
                   10967:         }
                   10968:     }
                   10969:     &Apache::lonenc::check_decrypt(\$symb);
                   10970:     return ($symb);
                   10971: }
                   10972: 
                   10973: # --------------------------------------------------------------Get annotation
                   10974: 
                   10975: sub get_annotation {
                   10976:     my ($symb,$enc) = @_;
                   10977: 
                   10978:     my $key = $symb;
                   10979:     if (!$enc) {
                   10980:         $key =
                   10981:             &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
                   10982:     }
                   10983:     my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
                   10984:     return $annotation{$key};
                   10985: }
                   10986: 
                   10987: sub clean_symb {
1.731     raeburn  10988:     my ($symb,$delete_enc) = @_;
1.685     tempelho 10989: 
                   10990:     &Apache::lonenc::check_decrypt(\$symb);
                   10991:     my $enc = $env{'request.enc'};
1.731     raeburn  10992:     if ($delete_enc) {
1.730     raeburn  10993:         delete($env{'request.enc'});
                   10994:     }
1.685     tempelho 10995: 
                   10996:     return ($symb,$enc);
                   10997: }
1.462     albertel 10998: 
1.41      ng       10999: =pod
                   11000: 
                   11001: =back
                   11002: 
1.112     bowersj2 11003: =cut
1.41      ng       11004: 
1.112     bowersj2 11005: 1;
                   11006: __END__;
1.41      ng       11007: 

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