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

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.7! raeburn     4: # $Id: loncommon.pm,v 1.948.2.6 2010/05/18 03:48:44 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) {
                   2287:     var i=0;
                   2288:     while (i < currentform.login.length) {
                   2289:         if (currentform.login[i].value == newvalue) { break; }
                   2290:         i++;
                   2291:     }
                   2292:     if (i == currentform.login.length) {
                   2293:         return;
                   2294:     }
                   2295:     current.radiovalue = newvalue;
                   2296:     currentform.login[i].checked = true;
                   2297:     return;
                   2298: }
                   2299: END
                   2300:     return $result;
                   2301: }
                   2302: 
                   2303: sub authform_authorwarning{
                   2304:     my $result='';
1.144     matthew  2305:     $result='<i>'.
                   2306:         &mt('As a general rule, only authors or co-authors should be '.
                   2307:             'filesystem authenticated '.
                   2308:             '(which allows access to the server filesystem).')."</i>\n";
1.32      matthew  2309:     return $result;
                   2310: }
                   2311: 
                   2312: sub authform_nochange{  
                   2313:     my %in = (
                   2314:               formname => 'document.cu',
                   2315:               kerb_def_dom => 'MSU.EDU',
                   2316:               @_,
                   2317:           );
1.586     raeburn  2318:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'}); 
                   2319:     my $result;
                   2320:     if (keys(%can_assign) == 0) {
                   2321:         $result = &mt('Under you current role you are not permitted to change login settings for this user');  
                   2322:     } else {
                   2323:         $result = '<label>'.&mt('[_1] Do not change login data',
                   2324:                   '<input type="radio" name="login" value="nochange" '.
                   2325:                   'checked="checked" onclick="'.
1.281     albertel 2326:             "javascript:changed_radio('nochange',$in{'formname'});".'" />').
                   2327: 	    '</label>';
1.586     raeburn  2328:     }
1.32      matthew  2329:     return $result;
                   2330: }
                   2331: 
1.591     raeburn  2332: sub authform_kerberos {
1.32      matthew  2333:     my %in = (
                   2334:               formname => 'document.cu',
                   2335:               kerb_def_dom => 'MSU.EDU',
1.80      albertel 2336:               kerb_def_auth => 'krb4',
1.32      matthew  2337:               @_,
                   2338:               );
1.586     raeburn  2339:     my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
                   2340:         $autharg,$jscall);
                   2341:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.80      albertel 2342:     if ($in{'kerb_def_auth'} eq 'krb5') {
1.772     bisitz   2343:        $check5 = ' checked="checked"';
1.80      albertel 2344:     } else {
1.772     bisitz   2345:        $check4 = ' checked="checked"';
1.80      albertel 2346:     }
1.165     raeburn  2347:     $krbarg = $in{'kerb_def_dom'};
1.591     raeburn  2348:     if (defined($in{'curr_authtype'})) {
                   2349:         if ($in{'curr_authtype'} eq 'krb') {
1.772     bisitz   2350:             $krbcheck = ' checked="checked"';
1.623     raeburn  2351:             if (defined($in{'mode'})) {
                   2352:                 if ($in{'mode'} eq 'modifyuser') {
                   2353:                     $krbcheck = '';
                   2354:                 }
                   2355:             }
1.591     raeburn  2356:             if (defined($in{'curr_kerb_ver'})) {
                   2357:                 if ($in{'curr_krb_ver'} eq '5') {
1.772     bisitz   2358:                     $check5 = ' checked="checked"';
1.591     raeburn  2359:                     $check4 = '';
                   2360:                 } else {
1.772     bisitz   2361:                     $check4 = ' checked="checked"';
1.591     raeburn  2362:                     $check5 = '';
                   2363:                 }
1.586     raeburn  2364:             }
1.591     raeburn  2365:             if (defined($in{'curr_autharg'})) {
1.165     raeburn  2366:                 $krbarg = $in{'curr_autharg'};
                   2367:             }
1.586     raeburn  2368:             if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591     raeburn  2369:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2370:                     $result = 
                   2371:     &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
                   2372:         $in{'curr_autharg'},$krbver);
                   2373:                 } else {
                   2374:                     $result =
                   2375:     &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
                   2376:                 }
                   2377:                 return $result; 
                   2378:             }
                   2379:         }
                   2380:     } else {
                   2381:         if ($authnum == 1) {
1.784     bisitz   2382:             $authtype = '<input type="hidden" name="login" value="krb" />';
1.165     raeburn  2383:         }
                   2384:     }
1.586     raeburn  2385:     if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
                   2386:         return;
1.587     raeburn  2387:     } elsif ($authtype eq '') {
1.591     raeburn  2388:         if (defined($in{'mode'})) {
1.587     raeburn  2389:             if ($in{'mode'} eq 'modifycourse') {
                   2390:                 if ($authnum == 1) {
1.784     bisitz   2391:                     $authtype = '<input type="hidden" name="login" value="krb" />';
1.587     raeburn  2392:                 }
                   2393:             }
                   2394:         }
1.586     raeburn  2395:     }
                   2396:     $jscall = "javascript:changed_radio('krb',$in{'formname'});";
                   2397:     if ($authtype eq '') {
                   2398:         $authtype = '<input type="radio" name="login" value="krb" '.
                   2399:                     'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
                   2400:                     $krbcheck.' />';
                   2401:     }
                   2402:     if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
                   2403:         ($can_assign{'krb4'} && !$can_assign{'krb5'} && 
                   2404:          $in{'curr_authtype'} eq 'krb5') ||
                   2405:         (!$can_assign{'krb4'} && $can_assign{'krb5'} && 
                   2406:          $in{'curr_authtype'} eq 'krb4')) {
                   2407:         $result .= &mt
1.144     matthew  2408:         ('[_1] Kerberos authenticated with domain [_2] '.
1.281     albertel 2409:          '[_3] Version 4 [_4] Version 5 [_5]',
1.586     raeburn  2410:          '<label>'.$authtype,
1.281     albertel 2411:          '</label><input type="text" size="10" name="krbarg" '.
1.165     raeburn  2412:              'value="'.$krbarg.'" '.
1.144     matthew  2413:              'onchange="'.$jscall.'" />',
1.281     albertel 2414:          '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
                   2415:          '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
                   2416: 	 '</label>');
1.586     raeburn  2417:     } elsif ($can_assign{'krb4'}) {
                   2418:         $result .= &mt
                   2419:         ('[_1] Kerberos authenticated with domain [_2] '.
                   2420:          '[_3] Version 4 [_4]',
                   2421:          '<label>'.$authtype,
                   2422:          '</label><input type="text" size="10" name="krbarg" '.
                   2423:              'value="'.$krbarg.'" '.
                   2424:              'onchange="'.$jscall.'" />',
                   2425:          '<label><input type="hidden" name="krbver" value="4" />',
                   2426:          '</label>');
                   2427:     } elsif ($can_assign{'krb5'}) {
                   2428:         $result .= &mt
                   2429:         ('[_1] Kerberos authenticated with domain [_2] '.
                   2430:          '[_3] Version 5 [_4]',
                   2431:          '<label>'.$authtype,
                   2432:          '</label><input type="text" size="10" name="krbarg" '.
                   2433:              'value="'.$krbarg.'" '.
                   2434:              'onchange="'.$jscall.'" />',
                   2435:          '<label><input type="hidden" name="krbver" value="5" />',
                   2436:          '</label>');
                   2437:     }
1.32      matthew  2438:     return $result;
                   2439: }
                   2440: 
                   2441: sub authform_internal{  
1.586     raeburn  2442:     my %in = (
1.32      matthew  2443:                 formname => 'document.cu',
                   2444:                 kerb_def_dom => 'MSU.EDU',
                   2445:                 @_,
                   2446:                 );
1.586     raeburn  2447:     my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
                   2448:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2449:     if (defined($in{'curr_authtype'})) {
                   2450:         if ($in{'curr_authtype'} eq 'int') {
1.586     raeburn  2451:             if ($can_assign{'int'}) {
1.772     bisitz   2452:                 $intcheck = 'checked="checked" ';
1.623     raeburn  2453:                 if (defined($in{'mode'})) {
                   2454:                     if ($in{'mode'} eq 'modifyuser') {
                   2455:                         $intcheck = '';
                   2456:                     }
                   2457:                 }
1.591     raeburn  2458:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2459:                     $intarg = $in{'curr_autharg'};
                   2460:                 }
                   2461:             } else {
                   2462:                 $result = &mt('Currently internally authenticated.');
                   2463:                 return $result;
1.165     raeburn  2464:             }
                   2465:         }
1.586     raeburn  2466:     } else {
                   2467:         if ($authnum == 1) {
1.784     bisitz   2468:             $authtype = '<input type="hidden" name="login" value="int" />';
1.586     raeburn  2469:         }
                   2470:     }
                   2471:     if (!$can_assign{'int'}) {
                   2472:         return;
1.587     raeburn  2473:     } elsif ($authtype eq '') {
1.591     raeburn  2474:         if (defined($in{'mode'})) {
1.587     raeburn  2475:             if ($in{'mode'} eq 'modifycourse') {
                   2476:                 if ($authnum == 1) {
1.784     bisitz   2477:                     $authtype = '<input type="hidden" name="login" value="int" />';
1.587     raeburn  2478:                 }
                   2479:             }
                   2480:         }
1.165     raeburn  2481:     }
1.586     raeburn  2482:     $jscall = "javascript:changed_radio('int',$in{'formname'});";
                   2483:     if ($authtype eq '') {
                   2484:         $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
                   2485:                     ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
                   2486:     }
1.605     bisitz   2487:     $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586     raeburn  2488:                $intarg.'" onchange="'.$jscall.'" />';
                   2489:     $result = &mt
1.144     matthew  2490:         ('[_1] Internally authenticated (with initial password [_2])',
1.586     raeburn  2491:          '<label>'.$authtype,'</label>'.$autharg);
1.824     bisitz   2492:     $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  2493:     return $result;
                   2494: }
                   2495: 
                   2496: sub authform_local{  
                   2497:     my %in = (
                   2498:               formname => 'document.cu',
                   2499:               kerb_def_dom => 'MSU.EDU',
                   2500:               @_,
                   2501:               );
1.586     raeburn  2502:     my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
                   2503:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2504:     if (defined($in{'curr_authtype'})) {
                   2505:         if ($in{'curr_authtype'} eq 'loc') {
1.586     raeburn  2506:             if ($can_assign{'loc'}) {
1.772     bisitz   2507:                 $loccheck = 'checked="checked" ';
1.623     raeburn  2508:                 if (defined($in{'mode'})) {
                   2509:                     if ($in{'mode'} eq 'modifyuser') {
                   2510:                         $loccheck = '';
                   2511:                     }
                   2512:                 }
1.591     raeburn  2513:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2514:                     $locarg = $in{'curr_autharg'};
                   2515:                 }
                   2516:             } else {
                   2517:                 $result = &mt('Currently using local (institutional) authentication.');
                   2518:                 return $result;
1.165     raeburn  2519:             }
                   2520:         }
1.586     raeburn  2521:     } else {
                   2522:         if ($authnum == 1) {
1.784     bisitz   2523:             $authtype = '<input type="hidden" name="login" value="loc" />';
1.586     raeburn  2524:         }
                   2525:     }
                   2526:     if (!$can_assign{'loc'}) {
                   2527:         return;
1.587     raeburn  2528:     } elsif ($authtype eq '') {
1.591     raeburn  2529:         if (defined($in{'mode'})) {
1.587     raeburn  2530:             if ($in{'mode'} eq 'modifycourse') {
                   2531:                 if ($authnum == 1) {
1.784     bisitz   2532:                     $authtype = '<input type="hidden" name="login" value="loc" />';
1.587     raeburn  2533:                 }
                   2534:             }
                   2535:         }
1.165     raeburn  2536:     }
1.586     raeburn  2537:     $jscall = "javascript:changed_radio('loc',$in{'formname'});";
                   2538:     if ($authtype eq '') {
                   2539:         $authtype = '<input type="radio" name="login" value="loc" '.
                   2540:                     $loccheck.' onchange="'.$jscall.'" onclick="'.
                   2541:                     $jscall.'" />';
                   2542:     }
                   2543:     $autharg = '<input type="text" size="10" name="locarg" value="'.
                   2544:                $locarg.'" onchange="'.$jscall.'" />';
                   2545:     $result = &mt('[_1] Local Authentication with argument [_2]',
                   2546:                   '<label>'.$authtype,'</label>'.$autharg);
1.32      matthew  2547:     return $result;
                   2548: }
                   2549: 
                   2550: sub authform_filesystem{  
                   2551:     my %in = (
                   2552:               formname => 'document.cu',
                   2553:               kerb_def_dom => 'MSU.EDU',
                   2554:               @_,
                   2555:               );
1.586     raeburn  2556:     my ($fsyscheck,$result,$authtype,$autharg,$jscall);
                   2557:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2558:     if (defined($in{'curr_authtype'})) {
                   2559:         if ($in{'curr_authtype'} eq 'fsys') {
1.586     raeburn  2560:             if ($can_assign{'fsys'}) {
1.772     bisitz   2561:                 $fsyscheck = 'checked="checked" ';
1.623     raeburn  2562:                 if (defined($in{'mode'})) {
                   2563:                     if ($in{'mode'} eq 'modifyuser') {
                   2564:                         $fsyscheck = '';
                   2565:                     }
                   2566:                 }
1.586     raeburn  2567:             } else {
                   2568:                 $result = &mt('Currently Filesystem Authenticated.');
                   2569:                 return $result;
                   2570:             }           
                   2571:         }
                   2572:     } else {
                   2573:         if ($authnum == 1) {
1.784     bisitz   2574:             $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586     raeburn  2575:         }
                   2576:     }
                   2577:     if (!$can_assign{'fsys'}) {
                   2578:         return;
1.587     raeburn  2579:     } elsif ($authtype eq '') {
1.591     raeburn  2580:         if (defined($in{'mode'})) {
1.587     raeburn  2581:             if ($in{'mode'} eq 'modifycourse') {
                   2582:                 if ($authnum == 1) {
1.784     bisitz   2583:                     $authtype = '<input type="hidden" name="login" value="fsys" />';
1.587     raeburn  2584:                 }
                   2585:             }
                   2586:         }
1.586     raeburn  2587:     }
                   2588:     $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
                   2589:     if ($authtype eq '') {
                   2590:         $authtype = '<input type="radio" name="login" value="fsys" '.
                   2591:                     $fsyscheck.' onchange="'.$jscall.'" onclick="'.
                   2592:                     $jscall.'" />';
                   2593:     }
                   2594:     $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
                   2595:                ' onchange="'.$jscall.'" />';
                   2596:     $result = &mt
1.144     matthew  2597:         ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281     albertel 2598:          '<label><input type="radio" name="login" value="fsys" '.
1.586     raeburn  2599:          $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605     bisitz   2600:          '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144     matthew  2601:                   'onchange="'.$jscall.'" />');
1.32      matthew  2602:     return $result;
                   2603: }
                   2604: 
1.586     raeburn  2605: sub get_assignable_auth {
                   2606:     my ($dom) = @_;
                   2607:     if ($dom eq '') {
                   2608:         $dom = $env{'request.role.domain'};
                   2609:     }
                   2610:     my %can_assign = (
                   2611:                           krb4 => 1,
                   2612:                           krb5 => 1,
                   2613:                           int  => 1,
                   2614:                           loc  => 1,
                   2615:                      );
                   2616:     my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
                   2617:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   2618:         if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
                   2619:             my $authhash = $domconfig{'usercreation'}{'authtypes'};
                   2620:             my $context;
                   2621:             if ($env{'request.role'} =~ /^au/) {
                   2622:                 $context = 'author';
                   2623:             } elsif ($env{'request.role'} =~ /^dc/) {
                   2624:                 $context = 'domain';
                   2625:             } elsif ($env{'request.course.id'}) {
                   2626:                 $context = 'course';
                   2627:             }
                   2628:             if ($context) {
                   2629:                 if (ref($authhash->{$context}) eq 'HASH') {
                   2630:                    %can_assign = %{$authhash->{$context}}; 
                   2631:                 }
                   2632:             }
                   2633:         }
                   2634:     }
                   2635:     my $authnum = 0;
                   2636:     foreach my $key (keys(%can_assign)) {
                   2637:         if ($can_assign{$key}) {
                   2638:             $authnum ++;
                   2639:         }
                   2640:     }
                   2641:     if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
                   2642:         $authnum --;
                   2643:     }
                   2644:     return ($authnum,%can_assign);
                   2645: }
                   2646: 
1.80      albertel 2647: ###############################################################
                   2648: ##    Get Kerberos Defaults for Domain                 ##
                   2649: ###############################################################
                   2650: ##
                   2651: ## Returns default kerberos version and an associated argument
                   2652: ## as listed in file domain.tab. If not listed, provides
                   2653: ## appropriate default domain and kerberos version.
                   2654: ##
                   2655: #-------------------------------------------
                   2656: 
                   2657: =pod
                   2658: 
1.648     raeburn  2659: =item * &get_kerberos_defaults()
1.80      albertel 2660: 
                   2661: get_kerberos_defaults($target_domain) returns the default kerberos
1.641     raeburn  2662: version and domain. If not found, it defaults to version 4 and the 
                   2663: domain of the server.
1.80      albertel 2664: 
1.648     raeburn  2665: =over 4
                   2666: 
1.80      albertel 2667: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
                   2668: 
1.648     raeburn  2669: =back
                   2670: 
                   2671: =back
                   2672: 
1.80      albertel 2673: =cut
                   2674: 
                   2675: #-------------------------------------------
                   2676: sub get_kerberos_defaults {
                   2677:     my $domain=shift;
1.641     raeburn  2678:     my ($krbdef,$krbdefdom);
                   2679:     my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
                   2680:     if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
                   2681:         $krbdef = $domdefaults{'auth_def'};
                   2682:         $krbdefdom = $domdefaults{'auth_arg_def'};
                   2683:     } else {
1.80      albertel 2684:         $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
                   2685:         my $krbdefdom=$1;
                   2686:         $krbdefdom=~tr/a-z/A-Z/;
                   2687:         $krbdef = "krb4";
                   2688:     }
                   2689:     return ($krbdef,$krbdefdom);
                   2690: }
1.112     bowersj2 2691: 
1.32      matthew  2692: 
1.46      matthew  2693: ###############################################################
                   2694: ##                Thesaurus Functions                        ##
                   2695: ###############################################################
1.20      www      2696: 
1.46      matthew  2697: =pod
1.20      www      2698: 
1.112     bowersj2 2699: =head1 Thesaurus Functions
                   2700: 
                   2701: =over 4
                   2702: 
1.648     raeburn  2703: =item * &initialize_keywords()
1.46      matthew  2704: 
                   2705: Initializes the package variable %Keywords if it is empty.  Uses the
                   2706: package variable $thesaurus_db_file.
                   2707: 
                   2708: =cut
                   2709: 
                   2710: ###################################################
                   2711: 
                   2712: sub initialize_keywords {
                   2713:     return 1 if (scalar keys(%Keywords));
                   2714:     # If we are here, %Keywords is empty, so fill it up
                   2715:     #   Make sure the file we need exists...
                   2716:     if (! -e $thesaurus_db_file) {
                   2717:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
                   2718:                                  " failed because it does not exist");
                   2719:         return 0;
                   2720:     }
                   2721:     #   Set up the hash as a database
                   2722:     my %thesaurus_db;
                   2723:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 2724:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  2725:         &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
                   2726:                                  $thesaurus_db_file);
                   2727:         return 0;
                   2728:     } 
                   2729:     #  Get the average number of appearances of a word.
                   2730:     my $avecount = $thesaurus_db{'average.count'};
                   2731:     #  Put keywords (those that appear > average) into %Keywords
                   2732:     while (my ($word,$data)=each (%thesaurus_db)) {
                   2733:         my ($count,undef) = split /:/,$data;
                   2734:         $Keywords{$word}++ if ($count > $avecount);
                   2735:     }
                   2736:     untie %thesaurus_db;
                   2737:     # Remove special values from %Keywords.
1.356     albertel 2738:     foreach my $value ('total.count','average.count') {
                   2739:         delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586     raeburn  2740:   }
1.46      matthew  2741:     return 1;
                   2742: }
                   2743: 
                   2744: ###################################################
                   2745: 
                   2746: =pod
                   2747: 
1.648     raeburn  2748: =item * &keyword($word)
1.46      matthew  2749: 
                   2750: Returns true if $word is a keyword.  A keyword is a word that appears more 
                   2751: than the average number of times in the thesaurus database.  Calls 
                   2752: &initialize_keywords
                   2753: 
                   2754: =cut
                   2755: 
                   2756: ###################################################
1.20      www      2757: 
                   2758: sub keyword {
1.46      matthew  2759:     return if (!&initialize_keywords());
                   2760:     my $word=lc(shift());
                   2761:     $word=~s/\W//g;
                   2762:     return exists($Keywords{$word});
1.20      www      2763: }
1.46      matthew  2764: 
                   2765: ###############################################################
                   2766: 
                   2767: =pod 
1.20      www      2768: 
1.648     raeburn  2769: =item * &get_related_words()
1.46      matthew  2770: 
1.160     matthew  2771: Look up a word in the thesaurus.  Takes a scalar argument and returns
1.46      matthew  2772: an array of words.  If the keyword is not in the thesaurus, an empty array
                   2773: will be returned.  The order of the words returned is determined by the
                   2774: database which holds them.
                   2775: 
                   2776: Uses global $thesaurus_db_file.
                   2777: 
                   2778: =cut
                   2779: 
                   2780: ###############################################################
                   2781: sub get_related_words {
                   2782:     my $keyword = shift;
                   2783:     my %thesaurus_db;
                   2784:     if (! -e $thesaurus_db_file) {
                   2785:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
                   2786:                                  "failed because the file does not exist");
                   2787:         return ();
                   2788:     }
                   2789:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 2790:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  2791:         return ();
                   2792:     } 
                   2793:     my @Words=();
1.429     www      2794:     my $count=0;
1.46      matthew  2795:     if (exists($thesaurus_db{$keyword})) {
1.356     albertel 2796: 	# The first element is the number of times
                   2797: 	# the word appears.  We do not need it now.
1.429     www      2798: 	my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
                   2799: 	my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
                   2800: 	my $threshold=$mostfrequentcount/10;
                   2801:         foreach my $possibleword (@RelatedWords) {
                   2802:             my ($word,$wordcount)=split(/\,/,$possibleword);
                   2803:             if ($wordcount>$threshold) {
                   2804: 		push(@Words,$word);
                   2805:                 $count++;
                   2806:                 if ($count>10) { last; }
                   2807: 	    }
1.20      www      2808:         }
                   2809:     }
1.46      matthew  2810:     untie %thesaurus_db;
                   2811:     return @Words;
1.14      harris41 2812: }
1.46      matthew  2813: 
1.112     bowersj2 2814: =pod
                   2815: 
                   2816: =back
                   2817: 
                   2818: =cut
1.61      www      2819: 
                   2820: # -------------------------------------------------------------- Plaintext name
1.81      albertel 2821: =pod
                   2822: 
1.112     bowersj2 2823: =head1 User Name Functions
                   2824: 
                   2825: =over 4
                   2826: 
1.648     raeburn  2827: =item * &plainname($uname,$udom,$first)
1.81      albertel 2828: 
1.112     bowersj2 2829: Takes a users logon name and returns it as a string in
1.226     albertel 2830: "first middle last generation" form 
                   2831: if $first is set to 'lastname' then it returns it as
                   2832: 'lastname generation, firstname middlename' if their is a lastname
1.81      albertel 2833: 
                   2834: =cut
1.61      www      2835: 
1.295     www      2836: 
1.81      albertel 2837: ###############################################################
1.61      www      2838: sub plainname {
1.226     albertel 2839:     my ($uname,$udom,$first)=@_;
1.537     albertel 2840:     return if (!defined($uname) || !defined($udom));
1.295     www      2841:     my %names=&getnames($uname,$udom);
1.226     albertel 2842:     my $name=&Apache::lonnet::format_name($names{'firstname'},
                   2843: 					  $names{'middlename'},
                   2844: 					  $names{'lastname'},
                   2845: 					  $names{'generation'},$first);
                   2846:     $name=~s/^\s+//;
1.62      www      2847:     $name=~s/\s+$//;
                   2848:     $name=~s/\s+/ /g;
1.353     albertel 2849:     if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62      www      2850:     return $name;
1.61      www      2851: }
1.66      www      2852: 
                   2853: # -------------------------------------------------------------------- Nickname
1.81      albertel 2854: =pod
                   2855: 
1.648     raeburn  2856: =item * &nickname($uname,$udom)
1.81      albertel 2857: 
                   2858: Gets a users name and returns it as a string as
                   2859: 
                   2860: "&quot;nickname&quot;"
1.66      www      2861: 
1.81      albertel 2862: if the user has a nickname or
                   2863: 
                   2864: "first middle last generation"
                   2865: 
                   2866: if the user does not
                   2867: 
                   2868: =cut
1.66      www      2869: 
                   2870: sub nickname {
                   2871:     my ($uname,$udom)=@_;
1.537     albertel 2872:     return if (!defined($uname) || !defined($udom));
1.295     www      2873:     my %names=&getnames($uname,$udom);
1.68      albertel 2874:     my $name=$names{'nickname'};
1.66      www      2875:     if ($name) {
                   2876:        $name='&quot;'.$name.'&quot;'; 
                   2877:     } else {
                   2878:        $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
                   2879: 	     $names{'lastname'}.' '.$names{'generation'};
                   2880:        $name=~s/\s+$//;
                   2881:        $name=~s/\s+/ /g;
                   2882:     }
                   2883:     return $name;
                   2884: }
                   2885: 
1.295     www      2886: sub getnames {
                   2887:     my ($uname,$udom)=@_;
1.537     albertel 2888:     return if (!defined($uname) || !defined($udom));
1.433     albertel 2889:     if ($udom eq 'public' && $uname eq 'public') {
                   2890: 	return ('lastname' => &mt('Public'));
                   2891:     }
1.295     www      2892:     my $id=$uname.':'.$udom;
                   2893:     my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
                   2894:     if ($cached) {
                   2895: 	return %{$names};
                   2896:     } else {
                   2897: 	my %loadnames=&Apache::lonnet::get('environment',
                   2898:                     ['firstname','middlename','lastname','generation','nickname'],
                   2899: 					 $udom,$uname);
                   2900: 	&Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
                   2901: 	return %loadnames;
                   2902:     }
                   2903: }
1.61      www      2904: 
1.542     raeburn  2905: # -------------------------------------------------------------------- getemails
1.648     raeburn  2906: 
1.542     raeburn  2907: =pod
                   2908: 
1.648     raeburn  2909: =item * &getemails($uname,$udom)
1.542     raeburn  2910: 
                   2911: Gets a user's email information and returns it as a hash with keys:
                   2912: notification, critnotification, permanentemail
                   2913: 
                   2914: For notification and critnotification, values are comma-separated lists 
1.648     raeburn  2915: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542     raeburn  2916:  
1.648     raeburn  2917: 
1.542     raeburn  2918: =cut
                   2919: 
1.648     raeburn  2920: 
1.466     albertel 2921: sub getemails {
                   2922:     my ($uname,$udom)=@_;
                   2923:     if ($udom eq 'public' && $uname eq 'public') {
                   2924: 	return;
                   2925:     }
1.467     www      2926:     if (!$udom) { $udom=$env{'user.domain'}; }
                   2927:     if (!$uname) { $uname=$env{'user.name'}; }
1.466     albertel 2928:     my $id=$uname.':'.$udom;
                   2929:     my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
                   2930:     if ($cached) {
                   2931: 	return %{$names};
                   2932:     } else {
                   2933: 	my %loadnames=&Apache::lonnet::get('environment',
                   2934:                     			   ['notification','critnotification',
                   2935: 					    'permanentemail'],
                   2936: 					   $udom,$uname);
                   2937: 	&Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
                   2938: 	return %loadnames;
                   2939:     }
                   2940: }
                   2941: 
1.551     albertel 2942: sub flush_email_cache {
                   2943:     my ($uname,$udom)=@_;
                   2944:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2945:     if (!$uname) { $uname=$env{'user.name'};   }
                   2946:     return if ($udom eq 'public' && $uname eq 'public');
                   2947:     my $id=$uname.':'.$udom;
                   2948:     &Apache::lonnet::devalidate_cache_new('emailscache',$id);
                   2949: }
                   2950: 
1.728     raeburn  2951: # -------------------------------------------------------------------- getlangs
                   2952: 
                   2953: =pod
                   2954: 
                   2955: =item * &getlangs($uname,$udom)
                   2956: 
                   2957: Gets a user's language preference and returns it as a hash with key:
                   2958: language.
                   2959: 
                   2960: =cut
                   2961: 
                   2962: 
                   2963: sub getlangs {
                   2964:     my ($uname,$udom) = @_;
                   2965:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2966:     if (!$uname) { $uname=$env{'user.name'};   }
                   2967:     my $id=$uname.':'.$udom;
                   2968:     my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
                   2969:     if ($cached) {
                   2970:         return %{$langs};
                   2971:     } else {
                   2972:         my %loadlangs=&Apache::lonnet::get('environment',['languages'],
                   2973:                                            $udom,$uname);
                   2974:         &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
                   2975:         return %loadlangs;
                   2976:     }
                   2977: }
                   2978: 
                   2979: sub flush_langs_cache {
                   2980:     my ($uname,$udom)=@_;
                   2981:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2982:     if (!$uname) { $uname=$env{'user.name'};   }
                   2983:     return if ($udom eq 'public' && $uname eq 'public');
                   2984:     my $id=$uname.':'.$udom;
                   2985:     &Apache::lonnet::devalidate_cache_new('userlangs',$id);
                   2986: }
                   2987: 
1.61      www      2988: # ------------------------------------------------------------------ Screenname
1.81      albertel 2989: 
                   2990: =pod
                   2991: 
1.648     raeburn  2992: =item * &screenname($uname,$udom)
1.81      albertel 2993: 
                   2994: Gets a users screenname and returns it as a string
                   2995: 
                   2996: =cut
1.61      www      2997: 
                   2998: sub screenname {
                   2999:     my ($uname,$udom)=@_;
1.258     albertel 3000:     if ($uname eq $env{'user.name'} &&
                   3001: 	$udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212     albertel 3002:     my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68      albertel 3003:     return $names{'screenname'};
1.62      www      3004: }
                   3005: 
1.212     albertel 3006: 
1.802     bisitz   3007: # ------------------------------------------------------------- Confirm Wrapper
                   3008: =pod
                   3009: 
                   3010: =item confirmwrapper
                   3011: 
                   3012: Wrap messages about completion of operation in box
                   3013: 
                   3014: =cut
                   3015: 
                   3016: sub confirmwrapper {
                   3017:     my ($message)=@_;
                   3018:     if ($message) {
                   3019:         return "\n".'<div class="LC_confirm_box">'."\n"
                   3020:                .$message."\n"
                   3021:                .'</div>'."\n";
                   3022:     } else {
                   3023:         return $message;
                   3024:     }
                   3025: }
                   3026: 
1.62      www      3027: # ------------------------------------------------------------- Message Wrapper
                   3028: 
                   3029: sub messagewrapper {
1.369     www      3030:     my ($link,$username,$domain,$subject,$text)=@_;
1.62      www      3031:     return 
1.441     albertel 3032:         '<a href="/adm/email?compose=individual&amp;'.
                   3033:         'recname='.$username.'&amp;recdom='.$domain.
                   3034: 	'&amp;subject='.&escape($subject).'&amp;text='.&escape($text).'" '.
1.200     matthew  3035:         'title="'.&mt('Send message').'">'.$link.'</a>';
1.74      www      3036: }
1.802     bisitz   3037: 
1.74      www      3038: # --------------------------------------------------------------- Notes Wrapper
                   3039: 
                   3040: sub noteswrapper {
                   3041:     my ($link,$un,$do)=@_;
                   3042:     return 
1.896     amueller 3043: "<a href='/adm/email?recordftf=retrieve&amp;recname=$un&amp;recdom=$do'>$link</a>";
1.62      www      3044: }
1.802     bisitz   3045: 
1.62      www      3046: # ------------------------------------------------------------- Aboutme Wrapper
                   3047: 
                   3048: sub aboutmewrapper {
1.166     www      3049:     my ($link,$username,$domain,$target)=@_;
1.447     raeburn  3050:     if (!defined($username)  && !defined($domain)) {
                   3051:         return;
                   3052:     }
1.892     amueller 3053:     return '<a href="/adm/'.$domain.'/'.$username.'/aboutme?forcestudent=1"'.
1.756     weissno  3054: 	($target?' target="$target"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62      www      3055: }
                   3056: 
                   3057: # ------------------------------------------------------------ Syllabus Wrapper
                   3058: 
                   3059: sub syllabuswrapper {
1.707     bisitz   3060:     my ($linktext,$coursedir,$domain)=@_;
1.208     matthew  3061:     return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61      www      3062: }
1.14      harris41 3063: 
1.802     bisitz   3064: # -----------------------------------------------------------------------------
                   3065: 
1.208     matthew  3066: sub track_student_link {
1.887     raeburn  3067:     my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268     albertel 3068:     my $link ="/adm/trackstudent?";
1.208     matthew  3069:     my $title = 'View recent activity';
                   3070:     if (defined($sname) && $sname !~ /^\s*$/ &&
                   3071:         defined($sdom)  && $sdom  !~ /^\s*$/) {
1.268     albertel 3072:         $link .= "selected_student=$sname:$sdom";
1.208     matthew  3073:         $title .= ' of this student';
1.268     albertel 3074:     } 
1.208     matthew  3075:     if (defined($target) && $target !~ /^\s*$/) {
                   3076:         $target = qq{target="$target"};
                   3077:     } else {
                   3078:         $target = '';
                   3079:     }
1.268     albertel 3080:     if ($start) { $link.='&amp;start='.$start; }
1.887     raeburn  3081:     if ($only_body) { $link .= '&amp;only_body=1'; }
1.554     albertel 3082:     $title = &mt($title);
                   3083:     $linktext = &mt($linktext);
1.448     albertel 3084:     return qq{<a href="$link" title="$title" $target>$linktext</a>}.
                   3085: 	&help_open_topic('View_recent_activity');
1.208     matthew  3086: }
                   3087: 
1.781     raeburn  3088: sub slot_reservations_link {
                   3089:     my ($linktext,$sname,$sdom,$target) = @_;
                   3090:     my $link ="/adm/slotrequest?command=showresv&amp;origin=aboutme";
                   3091:     my $title = 'View slot reservation history';
                   3092:     if (defined($sname) && $sname !~ /^\s*$/ &&
                   3093:         defined($sdom)  && $sdom  !~ /^\s*$/) {
                   3094:         $link .= "&amp;uname=$sname&amp;udom=$sdom";
                   3095:         $title .= ' of this student';
                   3096:     }
                   3097:     if (defined($target) && $target !~ /^\s*$/) {
                   3098:         $target = qq{target="$target"};
                   3099:     } else {
                   3100:         $target = '';
                   3101:     }
                   3102:     $title = &mt($title);
                   3103:     $linktext = &mt($linktext);
                   3104:     return qq{<a href="$link" title="$title" $target>$linktext</a>};
                   3105: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
                   3106: 
                   3107: }
                   3108: 
1.508     www      3109: # ===================================================== Display a student photo
                   3110: 
                   3111: 
1.509     albertel 3112: sub student_image_tag {
1.508     www      3113:     my ($domain,$user)=@_;
                   3114:     my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
                   3115:     if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
                   3116: 	return '<img src="'.$imgsrc.'" align="right" />';
                   3117:     } else {
                   3118: 	return '';
                   3119:     }
                   3120: }
                   3121: 
1.112     bowersj2 3122: =pod
                   3123: 
                   3124: =back
                   3125: 
                   3126: =head1 Access .tab File Data
                   3127: 
                   3128: =over 4
                   3129: 
1.648     raeburn  3130: =item * &languageids() 
1.112     bowersj2 3131: 
                   3132: returns list of all language ids
                   3133: 
                   3134: =cut
                   3135: 
1.14      harris41 3136: sub languageids {
1.16      harris41 3137:     return sort(keys(%language));
1.14      harris41 3138: }
                   3139: 
1.112     bowersj2 3140: =pod
                   3141: 
1.648     raeburn  3142: =item * &languagedescription() 
1.112     bowersj2 3143: 
                   3144: returns description of a specified language id
                   3145: 
                   3146: =cut
                   3147: 
1.14      harris41 3148: sub languagedescription {
1.125     www      3149:     my $code=shift;
                   3150:     return  ($supported_language{$code}?'* ':'').
                   3151:             $language{$code}.
1.126     www      3152: 	    ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145     www      3153: }
                   3154: 
                   3155: sub plainlanguagedescription {
                   3156:     my $code=shift;
                   3157:     return $language{$code};
                   3158: }
                   3159: 
                   3160: sub supportedlanguagecode {
                   3161:     my $code=shift;
                   3162:     return $supported_language{$code};
1.97      www      3163: }
                   3164: 
1.112     bowersj2 3165: =pod
                   3166: 
1.648     raeburn  3167: =item * &copyrightids() 
1.112     bowersj2 3168: 
                   3169: returns list of all copyrights
                   3170: 
                   3171: =cut
                   3172: 
                   3173: sub copyrightids {
                   3174:     return sort(keys(%cprtag));
                   3175: }
                   3176: 
                   3177: =pod
                   3178: 
1.648     raeburn  3179: =item * &copyrightdescription() 
1.112     bowersj2 3180: 
                   3181: returns description of a specified copyright id
                   3182: 
                   3183: =cut
                   3184: 
                   3185: sub copyrightdescription {
1.166     www      3186:     return &mt($cprtag{shift(@_)});
1.112     bowersj2 3187: }
1.197     matthew  3188: 
                   3189: =pod
                   3190: 
1.648     raeburn  3191: =item * &source_copyrightids() 
1.192     taceyjo1 3192: 
                   3193: returns list of all source copyrights
                   3194: 
                   3195: =cut
                   3196: 
                   3197: sub source_copyrightids {
                   3198:     return sort(keys(%scprtag));
                   3199: }
                   3200: 
                   3201: =pod
                   3202: 
1.648     raeburn  3203: =item * &source_copyrightdescription() 
1.192     taceyjo1 3204: 
                   3205: returns description of a specified source copyright id
                   3206: 
                   3207: =cut
                   3208: 
                   3209: sub source_copyrightdescription {
                   3210:     return &mt($scprtag{shift(@_)});
                   3211: }
1.112     bowersj2 3212: 
                   3213: =pod
                   3214: 
1.648     raeburn  3215: =item * &filecategories() 
1.112     bowersj2 3216: 
                   3217: returns list of all file categories
                   3218: 
                   3219: =cut
                   3220: 
                   3221: sub filecategories {
                   3222:     return sort(keys(%category_extensions));
                   3223: }
                   3224: 
                   3225: =pod
                   3226: 
1.648     raeburn  3227: =item * &filecategorytypes() 
1.112     bowersj2 3228: 
                   3229: returns list of file types belonging to a given file
                   3230: category
                   3231: 
                   3232: =cut
                   3233: 
                   3234: sub filecategorytypes {
1.356     albertel 3235:     my ($cat) = @_;
                   3236:     return @{$category_extensions{lc($cat)}};
1.112     bowersj2 3237: }
                   3238: 
                   3239: =pod
                   3240: 
1.648     raeburn  3241: =item * &fileembstyle() 
1.112     bowersj2 3242: 
                   3243: returns embedding style for a specified file type
                   3244: 
                   3245: =cut
                   3246: 
                   3247: sub fileembstyle {
                   3248:     return $fe{lc(shift(@_))};
1.169     www      3249: }
                   3250: 
1.351     www      3251: sub filemimetype {
                   3252:     return $fm{lc(shift(@_))};
                   3253: }
                   3254: 
1.169     www      3255: 
                   3256: sub filecategoryselect {
                   3257:     my ($name,$value)=@_;
1.189     matthew  3258:     return &select_form($value,$name,
1.169     www      3259: 			'' => &mt('Any category'),
1.948.2.7! raeburn  3260: 			{'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112     bowersj2 3261: }
                   3262: 
                   3263: =pod
                   3264: 
1.648     raeburn  3265: =item * &filedescription() 
1.112     bowersj2 3266: 
                   3267: returns description for a specified file type
                   3268: 
                   3269: =cut
                   3270: 
                   3271: sub filedescription {
1.188     matthew  3272:     my $file_description = $fd{lc(shift())};
                   3273:     $file_description =~ s:([\[\]]):~$1:g;
                   3274:     return &mt($file_description);
1.112     bowersj2 3275: }
                   3276: 
                   3277: =pod
                   3278: 
1.648     raeburn  3279: =item * &filedescriptionex() 
1.112     bowersj2 3280: 
                   3281: returns description for a specified file type with
                   3282: extra formatting
                   3283: 
                   3284: =cut
                   3285: 
                   3286: sub filedescriptionex {
                   3287:     my $ex=shift;
1.188     matthew  3288:     my $file_description = $fd{lc($ex)};
                   3289:     $file_description =~ s:([\[\]]):~$1:g;
                   3290:     return '.'.$ex.' '.&mt($file_description);
1.112     bowersj2 3291: }
                   3292: 
                   3293: # End of .tab access
                   3294: =pod
                   3295: 
                   3296: =back
                   3297: 
                   3298: =cut
                   3299: 
                   3300: # ------------------------------------------------------------------ File Types
                   3301: sub fileextensions {
                   3302:     return sort(keys(%fe));
                   3303: }
                   3304: 
1.97      www      3305: # ----------------------------------------------------------- Display Languages
                   3306: # returns a hash with all desired display languages
                   3307: #
                   3308: 
                   3309: sub display_languages {
                   3310:     my %languages=();
1.695     raeburn  3311:     foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356     albertel 3312: 	$languages{$lang}=1;
1.97      www      3313:     }
                   3314:     &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258     albertel 3315:     if ($env{'form.displaylanguage'}) {
1.356     albertel 3316: 	foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
                   3317: 	    $languages{$lang}=1;
1.97      www      3318:         }
                   3319:     }
                   3320:     return %languages;
1.14      harris41 3321: }
                   3322: 
1.582     albertel 3323: sub languages {
                   3324:     my ($possible_langs) = @_;
1.695     raeburn  3325:     my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582     albertel 3326:     if (!ref($possible_langs)) {
                   3327: 	if( wantarray ) {
                   3328: 	    return @preferred_langs;
                   3329: 	} else {
                   3330: 	    return $preferred_langs[0];
                   3331: 	}
                   3332:     }
                   3333:     my %possibilities = map { $_ => 1 } (@$possible_langs);
                   3334:     my @preferred_possibilities;
                   3335:     foreach my $preferred_lang (@preferred_langs) {
                   3336: 	if (exists($possibilities{$preferred_lang})) {
                   3337: 	    push(@preferred_possibilities, $preferred_lang);
                   3338: 	}
                   3339:     }
                   3340:     if( wantarray ) {
                   3341: 	return @preferred_possibilities;
                   3342:     }
                   3343:     return $preferred_possibilities[0];
                   3344: }
                   3345: 
1.742     raeburn  3346: sub user_lang {
                   3347:     my ($touname,$toudom,$fromcid) = @_;
                   3348:     my @userlangs;
                   3349:     if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
                   3350:         @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
                   3351:                     $env{'course.'.$fromcid.'.languages'}));
                   3352:     } else {
                   3353:         my %langhash = &getlangs($touname,$toudom);
                   3354:         if ($langhash{'languages'} ne '') {
                   3355:             @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
                   3356:         } else {
                   3357:             my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
                   3358:             if ($domdefs{'lang_def'} ne '') {
                   3359:                 @userlangs = ($domdefs{'lang_def'});
                   3360:             }
                   3361:         }
                   3362:     }
                   3363:     my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
                   3364:     my $user_lh = Apache::localize->get_handle(@languages);
                   3365:     return $user_lh;
                   3366: }
                   3367: 
                   3368: 
1.112     bowersj2 3369: ###############################################################
                   3370: ##               Student Answer Attempts                     ##
                   3371: ###############################################################
                   3372: 
                   3373: =pod
                   3374: 
                   3375: =head1 Alternate Problem Views
                   3376: 
                   3377: =over 4
                   3378: 
1.648     raeburn  3379: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112     bowersj2 3380:     $getattempt, $regexp, $gradesub)
                   3381: 
                   3382: Return string with previous attempt on problem. Arguments:
                   3383: 
                   3384: =over 4
                   3385: 
                   3386: =item * $symb: Problem, including path
                   3387: 
                   3388: =item * $username: username of the desired student
                   3389: 
                   3390: =item * $domain: domain of the desired student
1.14      harris41 3391: 
1.112     bowersj2 3392: =item * $course: Course ID
1.14      harris41 3393: 
1.112     bowersj2 3394: =item * $getattempt: Leave blank for all attempts, otherwise put
                   3395:     something
1.14      harris41 3396: 
1.112     bowersj2 3397: =item * $regexp: if string matches this regexp, the string will be
                   3398:     sent to $gradesub
1.14      harris41 3399: 
1.112     bowersj2 3400: =item * $gradesub: routine that processes the string if it matches $regexp
1.14      harris41 3401: 
1.112     bowersj2 3402: =back
1.14      harris41 3403: 
1.112     bowersj2 3404: The output string is a table containing all desired attempts, if any.
1.16      harris41 3405: 
1.112     bowersj2 3406: =cut
1.1       albertel 3407: 
                   3408: sub get_previous_attempt {
1.43      ng       3409:   my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1       albertel 3410:   my $prevattempts='';
1.43      ng       3411:   no strict 'refs';
1.1       albertel 3412:   if ($symb) {
1.3       albertel 3413:     my (%returnhash)=
                   3414:       &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1       albertel 3415:     if ($returnhash{'version'}) {
                   3416:       my %lasthash=();
                   3417:       my $version;
                   3418:       for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356     albertel 3419:         foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
                   3420: 	  $lasthash{$key}=$returnhash{$version.':'.$key};
1.19      harris41 3421:         }
1.1       albertel 3422:       }
1.596     albertel 3423:       $prevattempts=&start_data_table().&start_data_table_header_row();
                   3424:       $prevattempts.='<th>'.&mt('History').'</th>';
1.945     raeburn  3425:       my %typeparts;
                   3426:       my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356     albertel 3427:       foreach my $key (sort(keys(%lasthash))) {
                   3428: 	my ($ign,@parts) = split(/\./,$key);
1.41      ng       3429: 	if ($#parts > 0) {
1.31      albertel 3430: 	  my $data=$parts[-1];
                   3431: 	  pop(@parts);
1.945     raeburn  3432:           if ($data eq 'type') {
                   3433:               unless ($showsurv) {
                   3434:                   my $id = join(',',@parts);
                   3435:                   $typeparts{$ign.'.'.$id} = $lasthash{$key};
                   3436:               }
                   3437:               delete($lasthash{$key});
                   3438:           } else {
                   3439: 	      $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.'&nbsp;</th>';
                   3440:           }
1.31      albertel 3441: 	} else {
1.41      ng       3442: 	  if ($#parts == 0) {
                   3443: 	    $prevattempts.='<th>'.$parts[0].'</th>';
                   3444: 	  } else {
                   3445: 	    $prevattempts.='<th>'.$ign.'</th>';
                   3446: 	  }
1.31      albertel 3447: 	}
1.16      harris41 3448:       }
1.596     albertel 3449:       $prevattempts.=&end_data_table_header_row();
1.945     raeburn  3450:       my %lasthidden;
1.40      ng       3451:       if ($getattempt eq '') {
                   3452: 	for ($version=1;$version<=$returnhash{'version'};$version++) {
1.945     raeburn  3453:             my @hidden;
                   3454:             if (%typeparts) {
                   3455:                 foreach my $id (keys(%typeparts)) {
                   3456:                     if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') || ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
                   3457:                         push(@hidden,$id);
                   3458:                         $lasthidden{$id} = 1;
                   3459:                     } elsif ($lasthidden{$id}) {
                   3460:                         if (exists($returnhash{$version.':'.$id.'.award'})) {
                   3461:                             delete($lasthidden{$id});
                   3462:                         }
                   3463:                     }
                   3464:                 }
                   3465:             }
                   3466:             $prevattempts.=&start_data_table_row().
                   3467:                            '<td>'.&mt('Transaction [_1]',$version).'</td>';
                   3468:             if (@hidden) {
                   3469:                 foreach my $key (sort(keys(%lasthash))) {
                   3470:                     my $hide;
                   3471:                     foreach my $id (@hidden) {
                   3472:                         if ($key =~ /^\Q$id\E/) {
                   3473:                             $hide = 1;
                   3474:                             last;
                   3475:                         }
                   3476:                     }
                   3477:                     if ($hide) {
                   3478:                         my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
                   3479:                         if (($data eq 'award') || ($data eq 'awarddetail')) {
                   3480:                             my $value = &format_previous_attempt_value($key,
                   3481:                                              $returnhash{$version.':'.$key});
                   3482:                             $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3483:                         } else {
                   3484:                             $prevattempts.='<td>&nbsp;</td>';
                   3485:                         }
                   3486:                     } else {
                   3487:                         if ($key =~ /\./) {
                   3488:                             my $value = &format_previous_attempt_value($key,
                   3489:                                               $returnhash{$version.':'.$key});
                   3490:                             $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3491:                         } else {
                   3492:                             $prevattempts.='<td>&nbsp;</td>';
                   3493:                         }
                   3494:                     }
                   3495:                 }
                   3496:             } else {
                   3497: 	        foreach my $key (sort(keys(%lasthash))) {
                   3498: 		    my $value = &format_previous_attempt_value($key,
                   3499: 			            $returnhash{$version.':'.$key});
                   3500: 		    $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3501: 	        }
                   3502:             }
                   3503: 	    $prevattempts.=&end_data_table_row();
1.40      ng       3504: 	 }
1.1       albertel 3505:       }
1.945     raeburn  3506:       my @currhidden = keys(%lasthidden);
1.596     albertel 3507:       $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356     albertel 3508:       foreach my $key (sort(keys(%lasthash))) {
1.945     raeburn  3509:           if (%typeparts) {
                   3510:               my $hidden;
                   3511:               foreach my $id (@currhidden) {
                   3512:                   if ($key =~ /^\Q$id\E/) {
                   3513:                       $hidden = 1;
                   3514:                       last;
                   3515:                   }
                   3516:               }
                   3517:               if ($hidden) {
                   3518:                   my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
                   3519:                   if (($data eq 'award') || ($data eq 'awarddetail')) {
                   3520:                       my $value = &format_previous_attempt_value($key,$lasthash{$key});
                   3521:                       if ($key =~/$regexp$/ && (defined &$gradesub)) {
                   3522:                           $value = &$gradesub($value);
                   3523:                       }
                   3524:                       $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3525:                   } else {
                   3526:                       $prevattempts.='<td>&nbsp;</td>';
                   3527:                   }
                   3528:               } else {
                   3529:                   my $value = &format_previous_attempt_value($key,$lasthash{$key});
                   3530:                   if ($key =~/$regexp$/ && (defined &$gradesub)) {
                   3531:                       $value = &$gradesub($value);
                   3532:                   }
                   3533:                   $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3534:               }
                   3535:           } else {
                   3536: 	      my $value = &format_previous_attempt_value($key,$lasthash{$key});
                   3537: 	      if ($key =~/$regexp$/ && (defined &$gradesub)) {
                   3538:                   $value = &$gradesub($value);
                   3539:               }
                   3540: 	      $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3541:           }
1.16      harris41 3542:       }
1.596     albertel 3543:       $prevattempts.= &end_data_table_row().&end_data_table();
1.1       albertel 3544:     } else {
1.596     albertel 3545:       $prevattempts=
                   3546: 	  &start_data_table().&start_data_table_row().
                   3547: 	  '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
                   3548: 	  &end_data_table_row().&end_data_table();
1.1       albertel 3549:     }
                   3550:   } else {
1.596     albertel 3551:     $prevattempts=
                   3552: 	  &start_data_table().&start_data_table_row().
                   3553: 	  '<td>'.&mt('No data.').'</td>'.
                   3554: 	  &end_data_table_row().&end_data_table();
1.1       albertel 3555:   }
1.10      albertel 3556: }
                   3557: 
1.581     albertel 3558: sub format_previous_attempt_value {
                   3559:     my ($key,$value) = @_;
                   3560:     if ($key =~ /timestamp/) {
                   3561: 	$value = &Apache::lonlocal::locallocaltime($value);
                   3562:     } elsif (ref($value) eq 'ARRAY') {
                   3563: 	$value = '('.join(', ', @{ $value }).')';
                   3564:     } else {
                   3565: 	$value = &unescape($value);
                   3566:     }
                   3567:     return $value;
                   3568: }
                   3569: 
                   3570: 
1.107     albertel 3571: sub relative_to_absolute {
                   3572:     my ($url,$output)=@_;
                   3573:     my $parser=HTML::TokeParser->new(\$output);
                   3574:     my $token;
                   3575:     my $thisdir=$url;
                   3576:     my @rlinks=();
                   3577:     while ($token=$parser->get_token) {
                   3578: 	if ($token->[0] eq 'S') {
                   3579: 	    if ($token->[1] eq 'a') {
                   3580: 		if ($token->[2]->{'href'}) {
                   3581: 		    $rlinks[$#rlinks+1]=$token->[2]->{'href'};
                   3582: 		}
                   3583: 	    } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
                   3584: 		$rlinks[$#rlinks+1]=$token->[2]->{'src'};
                   3585: 	    } elsif ($token->[1] eq 'base') {
                   3586: 		$thisdir=$token->[2]->{'href'};
                   3587: 	    }
                   3588: 	}
                   3589:     }
                   3590:     $thisdir=~s-/[^/]*$--;
1.356     albertel 3591:     foreach my $link (@rlinks) {
1.726     raeburn  3592: 	unless (($link=~/^https?\:\/\//i) ||
1.356     albertel 3593: 		($link=~/^\//) ||
                   3594: 		($link=~/^javascript:/i) ||
                   3595: 		($link=~/^mailto:/i) ||
                   3596: 		($link=~/^\#/)) {
                   3597: 	    my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
                   3598: 	    $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107     albertel 3599: 	}
                   3600:     }
                   3601: # -------------------------------------------------- Deal with Applet codebases
                   3602:     $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
                   3603:     return $output;
                   3604: }
                   3605: 
1.112     bowersj2 3606: =pod
                   3607: 
1.648     raeburn  3608: =item * &get_student_view()
1.112     bowersj2 3609: 
                   3610: show a snapshot of what student was looking at
                   3611: 
                   3612: =cut
                   3613: 
1.10      albertel 3614: sub get_student_view {
1.186     albertel 3615:   my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114     www      3616:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 3617:   my (%form);
1.10      albertel 3618:   my @elements=('symb','courseid','domain','username');
                   3619:   foreach my $element (@elements) {
1.186     albertel 3620:       $form{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 3621:   }
1.186     albertel 3622:   if (defined($moreenv)) {
                   3623:       %form=(%form,%{$moreenv});
                   3624:   }
1.236     albertel 3625:   if (defined($target)) { $form{'grade_target'} = $target; }
1.107     albertel 3626:   $feedurl=&Apache::lonnet::clutter($feedurl);
1.650     www      3627:   my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11      albertel 3628:   $userview=~s/\<body[^\>]*\>//gi;
                   3629:   $userview=~s/\<\/body\>//gi;
                   3630:   $userview=~s/\<html\>//gi;
                   3631:   $userview=~s/\<\/html\>//gi;
                   3632:   $userview=~s/\<head\>//gi;
                   3633:   $userview=~s/\<\/head\>//gi;
                   3634:   $userview=~s/action\s*\=/would_be_action\=/gi;
1.107     albertel 3635:   $userview=&relative_to_absolute($feedurl,$userview);
1.650     www      3636:   if (wantarray) {
                   3637:      return ($userview,$response);
                   3638:   } else {
                   3639:      return $userview;
                   3640:   }
                   3641: }
                   3642: 
                   3643: sub get_student_view_with_retries {
                   3644:   my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
                   3645: 
                   3646:     my $ok = 0;                 # True if we got a good response.
                   3647:     my $content;
                   3648:     my $response;
                   3649: 
                   3650:     # Try to get the student_view done. within the retries count:
                   3651:     
                   3652:     do {
                   3653:          ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
                   3654:          $ok      = $response->is_success;
                   3655:          if (!$ok) {
                   3656:             &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
                   3657:          }
                   3658:          $retries--;
                   3659:     } while (!$ok && ($retries > 0));
                   3660:     
                   3661:     if (!$ok) {
                   3662:        $content = '';          # On error return an empty content.
                   3663:     }
1.651     www      3664:     if (wantarray) {
                   3665:        return ($content, $response);
                   3666:     } else {
                   3667:        return $content;
                   3668:     }
1.11      albertel 3669: }
                   3670: 
1.112     bowersj2 3671: =pod
                   3672: 
1.648     raeburn  3673: =item * &get_student_answers() 
1.112     bowersj2 3674: 
                   3675: show a snapshot of how student was answering problem
                   3676: 
                   3677: =cut
                   3678: 
1.11      albertel 3679: sub get_student_answers {
1.100     sakharuk 3680:   my ($symb,$username,$domain,$courseid,%form) = @_;
1.114     www      3681:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 3682:   my (%moreenv);
1.11      albertel 3683:   my @elements=('symb','courseid','domain','username');
                   3684:   foreach my $element (@elements) {
1.186     albertel 3685:     $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 3686:   }
1.186     albertel 3687:   $moreenv{'grade_target'}='answer';
                   3688:   %moreenv=(%form,%moreenv);
1.497     raeburn  3689:   $feedurl = &Apache::lonnet::clutter($feedurl);
                   3690:   my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10      albertel 3691:   return $userview;
1.1       albertel 3692: }
1.116     albertel 3693: 
                   3694: =pod
                   3695: 
                   3696: =item * &submlink()
                   3697: 
1.242     albertel 3698: Inputs: $text $uname $udom $symb $target
1.116     albertel 3699: 
                   3700: Returns: A link to grades.pm such as to see the SUBM view of a student
                   3701: 
                   3702: =cut
                   3703: 
                   3704: ###############################################
                   3705: sub submlink {
1.242     albertel 3706:     my ($text,$uname,$udom,$symb,$target)=@_;
1.116     albertel 3707:     if (!($uname && $udom)) {
                   3708: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 3709: 	    &Apache::lonnet::whichuser($symb);
1.116     albertel 3710: 	if (!$symb) { $symb=$cursymb; }
                   3711:     }
1.254     matthew  3712:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      3713:     $symb=&escape($symb);
1.948.2.4  raeburn  3714:     if ($target) { $target=" target=\"$target\""; }
                   3715:     return
                   3716:         '<a href="/adm/grades?command=submission'.
                   3717:         '&amp;symb='.$symb.
                   3718:         '&amp;student='.$uname.
                   3719:         '&amp;userdom='.$udom.'"'.
                   3720:         $target.'>'.$text.'</a>';
1.242     albertel 3721: }
                   3722: ##############################################
                   3723: 
                   3724: =pod
                   3725: 
                   3726: =item * &pgrdlink()
                   3727: 
                   3728: Inputs: $text $uname $udom $symb $target
                   3729: 
                   3730: Returns: A link to grades.pm such as to see the PGRD view of a student
                   3731: 
                   3732: =cut
                   3733: 
                   3734: ###############################################
                   3735: sub pgrdlink {
                   3736:     my $link=&submlink(@_);
                   3737:     $link=~s/(&command=submission)/$1&showgrading=yes/;
                   3738:     return $link;
                   3739: }
                   3740: ##############################################
                   3741: 
                   3742: =pod
                   3743: 
                   3744: =item * &pprmlink()
                   3745: 
                   3746: Inputs: $text $uname $udom $symb $target
                   3747: 
                   3748: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283     albertel 3749: student and a specific resource
1.242     albertel 3750: 
                   3751: =cut
                   3752: 
                   3753: ###############################################
                   3754: sub pprmlink {
                   3755:     my ($text,$uname,$udom,$symb,$target)=@_;
                   3756:     if (!($uname && $udom)) {
                   3757: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 3758: 	    &Apache::lonnet::whichuser($symb);
1.242     albertel 3759: 	if (!$symb) { $symb=$cursymb; }
                   3760:     }
1.254     matthew  3761:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      3762:     $symb=&escape($symb);
1.242     albertel 3763:     if ($target) { $target="target=\"$target\""; }
1.595     albertel 3764:     return '<a href="/adm/parmset?command=set&amp;'.
                   3765: 	'symb='.$symb.'&amp;uname='.$uname.
                   3766: 	'&amp;udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116     albertel 3767: }
                   3768: ##############################################
1.37      matthew  3769: 
1.112     bowersj2 3770: =pod
                   3771: 
                   3772: =back
                   3773: 
                   3774: =cut
                   3775: 
1.37      matthew  3776: ###############################################
1.51      www      3777: 
                   3778: 
                   3779: sub timehash {
1.687     raeburn  3780:     my ($thistime) = @_;
                   3781:     my $timezone = &Apache::lonlocal::gettimezone();
                   3782:     my $dt = DateTime->from_epoch(epoch => $thistime)
                   3783:                      ->set_time_zone($timezone);
                   3784:     my $wday = $dt->day_of_week();
                   3785:     if ($wday == 7) { $wday = 0; }
                   3786:     return ( 'second' => $dt->second(),
                   3787:              'minute' => $dt->minute(),
                   3788:              'hour'   => $dt->hour(),
                   3789:              'day'     => $dt->day_of_month(),
                   3790:              'month'   => $dt->month(),
                   3791:              'year'    => $dt->year(),
                   3792:              'weekday' => $wday,
                   3793:              'dayyear' => $dt->day_of_year(),
                   3794:              'dlsav'   => $dt->is_dst() );
1.51      www      3795: }
                   3796: 
1.370     www      3797: sub utc_string {
                   3798:     my ($date)=@_;
1.371     www      3799:     return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370     www      3800: }
                   3801: 
1.51      www      3802: sub maketime {
                   3803:     my %th=@_;
1.687     raeburn  3804:     my ($epoch_time,$timezone,$dt);
                   3805:     $timezone = &Apache::lonlocal::gettimezone();
                   3806:     eval {
                   3807:         $dt = DateTime->new( year   => $th{'year'},
                   3808:                              month  => $th{'month'},
                   3809:                              day    => $th{'day'},
                   3810:                              hour   => $th{'hour'},
                   3811:                              minute => $th{'minute'},
                   3812:                              second => $th{'second'},
                   3813:                              time_zone => $timezone,
                   3814:                          );
                   3815:     };
                   3816:     if (!$@) {
                   3817:         $epoch_time = $dt->epoch;
                   3818:         if ($epoch_time) {
                   3819:             return $epoch_time;
                   3820:         }
                   3821:     }
1.51      www      3822:     return POSIX::mktime(
                   3823:         ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210     www      3824:          $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70      www      3825: }
                   3826: 
                   3827: #########################################
1.51      www      3828: 
                   3829: sub findallcourses {
1.482     raeburn  3830:     my ($roles,$uname,$udom) = @_;
1.355     albertel 3831:     my %roles;
                   3832:     if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348     albertel 3833:     my %courses;
1.51      www      3834:     my $now=time;
1.482     raeburn  3835:     if (!defined($uname)) {
                   3836:         $uname = $env{'user.name'};
                   3837:     }
                   3838:     if (!defined($udom)) {
                   3839:         $udom = $env{'user.domain'};
                   3840:     }
                   3841:     if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
                   3842:         my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
                   3843:         if (!%roles) {
                   3844:             %roles = (
                   3845:                        cc => 1,
1.907     raeburn  3846:                        co => 1,
1.482     raeburn  3847:                        in => 1,
                   3848:                        ep => 1,
                   3849:                        ta => 1,
                   3850:                        cr => 1,
                   3851:                        st => 1,
                   3852:              );
                   3853:         }
                   3854:         foreach my $entry (keys(%roleshash)) {
                   3855:             my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
                   3856:             if ($trole =~ /^cr/) { 
                   3857:                 next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
                   3858:             } else {
                   3859:                 next if (!exists($roles{$trole}));
                   3860:             }
                   3861:             if ($tend) {
                   3862:                 next if ($tend < $now);
                   3863:             }
                   3864:             if ($tstart) {
                   3865:                 next if ($tstart > $now);
                   3866:             }
                   3867:             my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
                   3868:             (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
                   3869:             if ($secpart eq '') {
                   3870:                 ($cnum,$role) = split(/_/,$cnumpart); 
                   3871:                 $sec = 'none';
                   3872:                 $realsec = '';
                   3873:             } else {
                   3874:                 $cnum = $cnumpart;
                   3875:                 ($sec,$role) = split(/_/,$secpart);
                   3876:                 $realsec = $sec;
1.490     raeburn  3877:             }
1.482     raeburn  3878:             $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
                   3879:         }
                   3880:     } else {
                   3881:         foreach my $key (keys(%env)) {
1.483     albertel 3882: 	    if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
                   3883:                  $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482     raeburn  3884: 	        my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
                   3885: 	        next if ($role eq 'ca' || $role eq 'aa');
                   3886: 	        next if (%roles && !exists($roles{$role}));
                   3887: 	        my ($starttime,$endtime)=split(/\./,$env{$key});
                   3888:                 my $active=1;
                   3889:                 if ($starttime) {
                   3890: 		    if ($now<$starttime) { $active=0; }
                   3891:                 }
                   3892:                 if ($endtime) {
                   3893:                     if ($now>$endtime) { $active=0; }
                   3894:                 }
                   3895:                 if ($active) {
                   3896:                     if ($sec eq '') {
                   3897:                         $sec = 'none';
                   3898:                     }
                   3899:                     $courses{$cdom.'_'.$cnum}{$sec} = 
                   3900:                                      $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474     raeburn  3901:                 }
                   3902:             }
1.51      www      3903:         }
                   3904:     }
1.474     raeburn  3905:     return %courses;
1.51      www      3906: }
1.37      matthew  3907: 
1.54      www      3908: ###############################################
1.474     raeburn  3909: 
                   3910: sub blockcheck {
1.482     raeburn  3911:     my ($setters,$activity,$uname,$udom) = @_;
1.490     raeburn  3912: 
                   3913:     if (!defined($udom)) {
                   3914:         $udom = $env{'user.domain'};
                   3915:     }
                   3916:     if (!defined($uname)) {
                   3917:         $uname = $env{'user.name'};
                   3918:     }
                   3919: 
                   3920:     # If uname and udom are for a course, check for blocks in the course.
                   3921: 
                   3922:     if (&Apache::lonnet::is_course($udom,$uname)) {
                   3923:         my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502     raeburn  3924:         my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490     raeburn  3925:         return ($startblock,$endblock);
                   3926:     }
1.474     raeburn  3927: 
1.502     raeburn  3928:     my $startblock = 0;
                   3929:     my $endblock = 0;
1.482     raeburn  3930:     my %live_courses = &findallcourses(undef,$uname,$udom);
1.474     raeburn  3931: 
1.490     raeburn  3932:     # If uname is for a user, and activity is course-specific, i.e.,
                   3933:     # boards, chat or groups, check for blocking in current course only.
1.474     raeburn  3934: 
1.490     raeburn  3935:     if (($activity eq 'boards' || $activity eq 'chat' ||
                   3936:          $activity eq 'groups') && ($env{'request.course.id'})) {
                   3937:         foreach my $key (keys(%live_courses)) {
                   3938:             if ($key ne $env{'request.course.id'}) {
                   3939:                 delete($live_courses{$key});
                   3940:             }
                   3941:         }
                   3942:     }
                   3943: 
                   3944:     my $otheruser = 0;
                   3945:     my %own_courses;
                   3946:     if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
                   3947:         # Resource belongs to user other than current user.
                   3948:         $otheruser = 1;
                   3949:         # Gather courses for current user
                   3950:         %own_courses = 
                   3951:             &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
                   3952:     }
                   3953: 
                   3954:     # Gather active course roles - course coordinator, instructor, 
                   3955:     # exam proctor, ta, student, or custom role.
1.474     raeburn  3956: 
                   3957:     foreach my $course (keys(%live_courses)) {
1.482     raeburn  3958:         my ($cdom,$cnum);
                   3959:         if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
                   3960:             $cdom = $env{'course.'.$course.'.domain'};
                   3961:             $cnum = $env{'course.'.$course.'.num'};
                   3962:         } else {
1.490     raeburn  3963:             ($cdom,$cnum) = split(/_/,$course); 
1.482     raeburn  3964:         }
                   3965:         my $no_ownblock = 0;
                   3966:         my $no_userblock = 0;
1.533     raeburn  3967:         if ($otheruser && $activity ne 'com') {
1.490     raeburn  3968:             # Check if current user has 'evb' priv for this
                   3969:             if (defined($own_courses{$course})) {
                   3970:                 foreach my $sec (keys(%{$own_courses{$course}})) {
                   3971:                     my $checkrole = 'cm./'.$cdom.'/'.$cnum;
                   3972:                     if ($sec ne 'none') {
                   3973:                         $checkrole .= '/'.$sec;
                   3974:                     }
                   3975:                     if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   3976:                         $no_ownblock = 1;
                   3977:                         last;
                   3978:                     }
                   3979:                 }
                   3980:             }
                   3981:             # if they have 'evb' priv and are currently not playing student
                   3982:             next if (($no_ownblock) &&
                   3983:                  ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
                   3984:         }
1.474     raeburn  3985:         foreach my $sec (keys(%{$live_courses{$course}})) {
1.482     raeburn  3986:             my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474     raeburn  3987:             if ($sec ne 'none') {
1.482     raeburn  3988:                 $checkrole .= '/'.$sec;
1.474     raeburn  3989:             }
1.490     raeburn  3990:             if ($otheruser) {
                   3991:                 # Resource belongs to user other than current user.
                   3992:                 # Assemble privs for that user, and check for 'evb' priv.
1.482     raeburn  3993:                 my ($trole,$tdom,$tnum,$tsec);
                   3994:                 my $entry = $live_courses{$course}{$sec};
                   3995:                 if ($entry =~ /^cr/) {
                   3996:                     ($trole,$tdom,$tnum,$tsec) = 
                   3997:                       ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
                   3998:                 } else {
                   3999:                     ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
                   4000:                 }
                   4001:                 my ($spec,$area,$trest,%allroles,%userroles);
                   4002:                 $area = '/'.$tdom.'/'.$tnum;
                   4003:                 $trest = $tnum;
                   4004:                 if ($tsec ne '') {
                   4005:                     $area .= '/'.$tsec;
                   4006:                     $trest .= '/'.$tsec;
                   4007:                 }
                   4008:                 $spec = $trole.'.'.$area;
                   4009:                 if ($trole =~ /^cr/) {
                   4010:                     &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
                   4011:                                                       $tdom,$spec,$trest,$area);
                   4012:                 } else {
                   4013:                     &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
                   4014:                                                        $tdom,$spec,$trest,$area);
                   4015:                 }
                   4016:                 my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486     raeburn  4017:                 if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
                   4018:                     if ($1) {
                   4019:                         $no_userblock = 1;
                   4020:                         last;
                   4021:                     }
                   4022:                 }
1.490     raeburn  4023:             } else {
                   4024:                 # Resource belongs to current user
                   4025:                 # Check for 'evb' priv via lonnet::allowed().
1.482     raeburn  4026:                 if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   4027:                     $no_ownblock = 1;
                   4028:                     last;
                   4029:                 }
1.474     raeburn  4030:             }
                   4031:         }
                   4032:         # if they have the evb priv and are currently not playing student
1.482     raeburn  4033:         next if (($no_ownblock) &&
1.491     albertel 4034:                  ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482     raeburn  4035:         next if ($no_userblock);
1.474     raeburn  4036: 
1.866     kalberla 4037:         # Retrieve blocking times and identity of locker for course
1.490     raeburn  4038:         # of specified user, unless user has 'evb' privilege.
1.502     raeburn  4039:         
                   4040:         my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
                   4041:         if (($start != 0) && 
                   4042:             (($startblock == 0) || ($startblock > $start))) {
                   4043:             $startblock = $start;
                   4044:         }
                   4045:         if (($end != 0)  &&
                   4046:             (($endblock == 0) || ($endblock < $end))) {
                   4047:             $endblock = $end;
                   4048:         }
1.490     raeburn  4049:     }
                   4050:     return ($startblock,$endblock);
                   4051: }
                   4052: 
                   4053: sub get_blocks {
                   4054:     my ($setters,$activity,$cdom,$cnum) = @_;
                   4055:     my $startblock = 0;
                   4056:     my $endblock = 0;
                   4057:     my $course = $cdom.'_'.$cnum;
                   4058:     $setters->{$course} = {};
                   4059:     $setters->{$course}{'staff'} = [];
                   4060:     $setters->{$course}{'times'} = [];
                   4061:     my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
                   4062:     foreach my $record (keys(%records)) {
                   4063:         my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
                   4064:         if ($start <= time && $end >= time) {
                   4065:             my ($staff_name,$staff_dom,$title,$blocks) =
                   4066:                 &parse_block_record($records{$record});
                   4067:             if ($blocks->{$activity} eq 'on') {
                   4068:                 push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
                   4069:                 push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491     albertel 4070:                 if ( ($startblock == 0) || ($startblock > $start) ) {
                   4071:                     $startblock = $start;
1.490     raeburn  4072:                 }
1.491     albertel 4073:                 if ( ($endblock == 0) || ($endblock < $end) ) {
                   4074:                     $endblock = $end;
1.474     raeburn  4075:                 }
                   4076:             }
                   4077:         }
                   4078:     }
                   4079:     return ($startblock,$endblock);
                   4080: }
                   4081: 
                   4082: sub parse_block_record {
                   4083:     my ($record) = @_;
                   4084:     my ($setuname,$setudom,$title,$blocks);
                   4085:     if (ref($record) eq 'HASH') {
                   4086:         ($setuname,$setudom) = split(/:/,$record->{'setter'});
                   4087:         $title = &unescape($record->{'event'});
                   4088:         $blocks = $record->{'blocks'};
                   4089:     } else {
                   4090:         my @data = split(/:/,$record,3);
                   4091:         if (scalar(@data) eq 2) {
                   4092:             $title = $data[1];
                   4093:             ($setuname,$setudom) = split(/@/,$data[0]);
                   4094:         } else {
                   4095:             ($setuname,$setudom,$title) = @data;
                   4096:         }
                   4097:         $blocks = { 'com' => 'on' };
                   4098:     }
                   4099:     return ($setuname,$setudom,$title,$blocks);
                   4100: }
                   4101: 
1.854     kalberla 4102: sub blocking_status {
                   4103:   my ($activity,$uname,$udom) = @_;
1.867     kalberla 4104:   my %setters;
1.890     droeschl 4105: 
                   4106:   # check for active blocking
1.867     kalberla 4107:   my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
1.854     kalberla 4108: 
1.890     droeschl 4109:   my $blocked = $startblock && $endblock ? 1 : 0;
                   4110: 
                   4111:   # caller just wants to know whether a block is active
                   4112:   if (!wantarray) { return $blocked; }
                   4113: 
                   4114:   # build a link to a popup window containing the details
                   4115:   my $querystring  = "?activity=$activity";
                   4116:   # $uname and $udom decide whose portfolio the user is trying to look at
                   4117:      $querystring .= "&amp;udom=$udom"      if $udom;
                   4118:      $querystring .= "&amp;uname=$uname"    if $uname;
                   4119: 
                   4120:   my $output .= <<'END_MYBLOCK';
1.854     kalberla 4121:     function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
                   4122:         var options = "width=" + w + ",height=" + h + ",";
                   4123:         options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
                   4124:         options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
                   4125:         var newWin = window.open(url, wdwName, options);
                   4126:         newWin.focus();
                   4127:     }
1.890     droeschl 4128: END_MYBLOCK
1.854     kalberla 4129: 
1.890     droeschl 4130:   $output = Apache::lonhtmlcommon::scripttag($output);
                   4131:   
1.854     kalberla 4132:   my $popupUrl = "/adm/blockingstatus/$querystring";
1.890     droeschl 4133:   my $text = mt('Communication Blocked');
                   4134: 
1.867     kalberla 4135:   $output .= <<"END_BLOCK";
                   4136: <div class='LC_comblock'>
1.869     kalberla 4137:   <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890     droeschl 4138:   title='$text'>
                   4139:   <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
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'>$text</a>
1.867     kalberla 4142: </div>
                   4143: 
                   4144: END_BLOCK
1.474     raeburn  4145: 
1.854     kalberla 4146:   return ($blocked, $output);
                   4147: }
1.490     raeburn  4148: 
1.60      matthew  4149: ###############################################
                   4150: 
1.682     raeburn  4151: sub check_ip_acc {
                   4152:     my ($acc)=@_;
                   4153:     &Apache::lonxml::debug("acc is $acc");
                   4154:     if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
                   4155:         return 1;
                   4156:     }
                   4157:     my $allowed=0;
                   4158:     my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
                   4159: 
                   4160:     my $name;
                   4161:     foreach my $pattern (split(',',$acc)) {
                   4162:         $pattern =~ s/^\s*//;
                   4163:         $pattern =~ s/\s*$//;
                   4164:         if ($pattern =~ /\*$/) {
                   4165:             #35.8.*
                   4166:             $pattern=~s/\*//;
                   4167:             if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
                   4168:         } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
                   4169:             #35.8.3.[34-56]
                   4170:             my $low=$2;
                   4171:             my $high=$3;
                   4172:             $pattern=$1;
                   4173:             if ($ip =~ /^\Q$pattern\E/) {
                   4174:                 my $last=(split(/\./,$ip))[3];
                   4175:                 if ($last <=$high && $last >=$low) { $allowed=1; }
                   4176:             }
                   4177:         } elsif ($pattern =~ /^\*/) {
                   4178:             #*.msu.edu
                   4179:             $pattern=~s/\*//;
                   4180:             if (!defined($name)) {
                   4181:                 use Socket;
                   4182:                 my $netaddr=inet_aton($ip);
                   4183:                 ($name)=gethostbyaddr($netaddr,AF_INET);
                   4184:             }
                   4185:             if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
                   4186:         } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
                   4187:             #127.0.0.1
                   4188:             if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
                   4189:         } else {
                   4190:             #some.name.com
                   4191:             if (!defined($name)) {
                   4192:                 use Socket;
                   4193:                 my $netaddr=inet_aton($ip);
                   4194:                 ($name)=gethostbyaddr($netaddr,AF_INET);
                   4195:             }
                   4196:             if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
                   4197:         }
                   4198:         if ($allowed) { last; }
                   4199:     }
                   4200:     return $allowed;
                   4201: }
                   4202: 
                   4203: ###############################################
                   4204: 
1.60      matthew  4205: =pod
                   4206: 
1.112     bowersj2 4207: =head1 Domain Template Functions
                   4208: 
                   4209: =over 4
                   4210: 
                   4211: =item * &determinedomain()
1.60      matthew  4212: 
                   4213: Inputs: $domain (usually will be undef)
                   4214: 
1.63      www      4215: Returns: Determines which domain should be used for designs
1.60      matthew  4216: 
                   4217: =cut
1.54      www      4218: 
1.60      matthew  4219: ###############################################
1.63      www      4220: sub determinedomain {
                   4221:     my $domain=shift;
1.531     albertel 4222:     if (! $domain) {
1.60      matthew  4223:         # Determine domain if we have not been given one
1.893     raeburn  4224:         $domain = &Apache::lonnet::default_login_domain();
1.258     albertel 4225:         if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
                   4226:         if ($env{'request.role.domain'}) { 
                   4227:             $domain=$env{'request.role.domain'}; 
1.60      matthew  4228:         }
                   4229:     }
1.63      www      4230:     return $domain;
                   4231: }
                   4232: ###############################################
1.517     raeburn  4233: 
1.518     albertel 4234: sub devalidate_domconfig_cache {
                   4235:     my ($udom)=@_;
                   4236:     &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
                   4237: }
                   4238: 
                   4239: # ---------------------- Get domain configuration for a domain
                   4240: sub get_domainconf {
                   4241:     my ($udom) = @_;
                   4242:     my $cachetime=1800;
                   4243:     my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
                   4244:     if (defined($cached)) { return %{$result}; }
                   4245: 
                   4246:     my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948     raeburn  4247: 					     ['login','rolecolors','autoenroll'],$udom);
1.632     raeburn  4248:     my (%designhash,%legacy);
1.518     albertel 4249:     if (keys(%domconfig) > 0) {
                   4250:         if (ref($domconfig{'login'}) eq 'HASH') {
1.632     raeburn  4251:             if (keys(%{$domconfig{'login'}})) {
                   4252:                 foreach my $key (keys(%{$domconfig{'login'}})) {
1.699     raeburn  4253:                     if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.946     raeburn  4254:                         if ($key eq 'loginvia') {
                   4255:                             if (ref($domconfig{'login'}{'loginvia'}) eq 'HASH') {
                   4256:                                 my @ids = &Apache::lonnet::current_machine_ids();
                   4257:                                 foreach my $hostname (@ids) {
1.948     raeburn  4258:                                     if (ref($domconfig{'login'}{'loginvia'}{$hostname}) eq 'HASH') {
                   4259:                                         if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
                   4260:                                             my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
                   4261:                                             $designhash{$udom.'.login.loginvia'} = $server;
                   4262:                                             if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
                   4263: 
                   4264:                                                 $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
                   4265:                                             } else {
                   4266:                                                  $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
                   4267:                                             }
                   4268:                                             if ($domconfig{'login'}{'loginvia'}{$hostname}{'exempt'}) {
                   4269:                                                 $designhash{$udom.'.login.loginvia_exempt_'.$hostname} = $domconfig{'login'}{'loginvia'}{$hostname}{'exempt'};
                   4270:                                             }
1.946     raeburn  4271:                                         }
                   4272:                                     }
                   4273:                                 }
                   4274:                             }
                   4275:                         } else {
                   4276:                             foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
                   4277:                                 $designhash{$udom.'.login.'.$key.'_'.$img} = 
                   4278:                                     $domconfig{'login'}{$key}{$img};
                   4279:                             }
1.699     raeburn  4280:                         }
                   4281:                     } else {
                   4282:                         $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
                   4283:                     }
1.632     raeburn  4284:                 }
                   4285:             } else {
                   4286:                 $legacy{'login'} = 1;
1.518     albertel 4287:             }
1.632     raeburn  4288:         } else {
                   4289:             $legacy{'login'} = 1;
1.518     albertel 4290:         }
                   4291:         if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632     raeburn  4292:             if (keys(%{$domconfig{'rolecolors'}})) {
                   4293:                 foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
                   4294:                     if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
                   4295:                         foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
                   4296:                             $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
                   4297:                         }
1.518     albertel 4298:                     }
                   4299:                 }
1.632     raeburn  4300:             } else {
                   4301:                 $legacy{'rolecolors'} = 1;
1.518     albertel 4302:             }
1.632     raeburn  4303:         } else {
                   4304:             $legacy{'rolecolors'} = 1;
1.518     albertel 4305:         }
1.948     raeburn  4306:         if (ref($domconfig{'autoenroll'}) eq 'HASH') {
                   4307:             if ($domconfig{'autoenroll'}{'co-owners'}) {
                   4308:                 $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
                   4309:             }
                   4310:         }
1.632     raeburn  4311:         if (keys(%legacy) > 0) {
                   4312:             my %legacyhash = &get_legacy_domconf($udom);
                   4313:             foreach my $item (keys(%legacyhash)) {
                   4314:                 if ($item =~ /^\Q$udom\E\.login/) {
                   4315:                     if ($legacy{'login'}) { 
                   4316:                         $designhash{$item} = $legacyhash{$item};
                   4317:                     }
                   4318:                 } else {
                   4319:                     if ($legacy{'rolecolors'}) {
                   4320:                         $designhash{$item} = $legacyhash{$item};
                   4321:                     }
1.518     albertel 4322:                 }
                   4323:             }
                   4324:         }
1.632     raeburn  4325:     } else {
                   4326:         %designhash = &get_legacy_domconf($udom); 
1.518     albertel 4327:     }
                   4328:     &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
                   4329: 				  $cachetime);
                   4330:     return %designhash;
                   4331: }
                   4332: 
1.632     raeburn  4333: sub get_legacy_domconf {
                   4334:     my ($udom) = @_;
                   4335:     my %legacyhash;
                   4336:     my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
                   4337:     my $designfile =  $designdir.'/'.$udom.'.tab';
                   4338:     if (-e $designfile) {
                   4339:         if ( open (my $fh,"<$designfile") ) {
                   4340:             while (my $line = <$fh>) {
                   4341:                 next if ($line =~ /^\#/);
                   4342:                 chomp($line);
                   4343:                 my ($key,$val)=(split(/\=/,$line));
                   4344:                 if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
                   4345:             }
                   4346:             close($fh);
                   4347:         }
                   4348:     }
                   4349:     if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
                   4350:         $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
                   4351:     }
                   4352:     return %legacyhash;
                   4353: }
                   4354: 
1.63      www      4355: =pod
                   4356: 
1.112     bowersj2 4357: =item * &domainlogo()
1.63      www      4358: 
                   4359: Inputs: $domain (usually will be undef)
                   4360: 
                   4361: Returns: A link to a domain logo, if the domain logo exists.
                   4362: If the domain logo does not exist, a description of the domain.
                   4363: 
                   4364: =cut
1.112     bowersj2 4365: 
1.63      www      4366: ###############################################
                   4367: sub domainlogo {
1.517     raeburn  4368:     my $domain = &determinedomain(shift);
1.518     albertel 4369:     my %designhash = &get_domainconf($domain);    
1.517     raeburn  4370:     # See if there is a logo
                   4371:     if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519     raeburn  4372:         my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538     albertel 4373:         if ($imgsrc =~ m{^/(adm|res)/}) {
                   4374: 	    if ($imgsrc =~ m{^/res/}) {
                   4375: 		my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
                   4376: 		&Apache::lonnet::repcopy($local_name);
                   4377: 	    }
                   4378: 	   $imgsrc = &lonhttpdurl($imgsrc);
1.519     raeburn  4379:         } 
                   4380:         return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514     albertel 4381:     } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
                   4382:         return &Apache::lonnet::domain($domain,'description');
1.59      www      4383:     } else {
1.60      matthew  4384:         return '';
1.59      www      4385:     }
                   4386: }
1.63      www      4387: ##############################################
                   4388: 
                   4389: =pod
                   4390: 
1.112     bowersj2 4391: =item * &designparm()
1.63      www      4392: 
                   4393: Inputs: $which parameter; $domain (usually will be undef)
                   4394: 
                   4395: Returns: value of designparamter $which
                   4396: 
                   4397: =cut
1.112     bowersj2 4398: 
1.397     albertel 4399: 
1.400     albertel 4400: ##############################################
1.397     albertel 4401: sub designparm {
                   4402:     my ($which,$domain)=@_;
                   4403:     if (exists($env{'environment.color.'.$which})) {
1.817     bisitz   4404:         return $env{'environment.color.'.$which};
1.96      www      4405:     }
1.63      www      4406:     $domain=&determinedomain($domain);
1.518     albertel 4407:     my %domdesign = &get_domainconf($domain);
1.520     raeburn  4408:     my $output;
1.517     raeburn  4409:     if ($domdesign{$domain.'.'.$which} ne '') {
1.817     bisitz   4410:         $output = $domdesign{$domain.'.'.$which};
1.63      www      4411:     } else {
1.520     raeburn  4412:         $output = $defaultdesign{$which};
                   4413:     }
                   4414:     if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635     raeburn  4415:         ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538     albertel 4416:         if ($output =~ m{^/(adm|res)/}) {
1.817     bisitz   4417:             if ($output =~ m{^/res/}) {
                   4418:                 my $local_name = &Apache::lonnet::filelocation('',$output);
                   4419:                 &Apache::lonnet::repcopy($local_name);
                   4420:             }
1.520     raeburn  4421:             $output = &lonhttpdurl($output);
                   4422:         }
1.63      www      4423:     }
1.520     raeburn  4424:     return $output;
1.63      www      4425: }
1.59      www      4426: 
1.822     bisitz   4427: ##############################################
                   4428: =pod
                   4429: 
1.832     bisitz   4430: =item * &authorspace()
                   4431: 
                   4432: Inputs: ./.
                   4433: 
                   4434: Returns: Path to the Construction Space of the current user's
                   4435:          accessed author space
                   4436:          The author space will be that of the current user
                   4437:          when accessing the own author space
                   4438:          and that of the co-author/assistent co-author
                   4439:          when accessing the co-author's/assistent co-author's
                   4440:          space
                   4441: 
                   4442: =cut
                   4443: 
                   4444: sub authorspace {
                   4445:     my $caname = '';
                   4446:     if ($env{'request.role'} =~ /^ca|^aa/) {
                   4447:         (undef,$caname) =
                   4448:             ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
                   4449:     } else {
                   4450:         $caname = $env{'user.name'};
                   4451:     }
                   4452:     return '/priv/'.$caname.'/';
                   4453: }
                   4454: 
                   4455: ##############################################
                   4456: =pod
                   4457: 
1.822     bisitz   4458: =item * &head_subbox()
                   4459: 
                   4460: Inputs: $content (contains HTML code with page functions, etc.)
                   4461: 
                   4462: Returns: HTML div with $content
                   4463:          To be included in page header
                   4464: 
                   4465: =cut
                   4466: 
                   4467: sub head_subbox {
                   4468:     my ($content)=@_;
                   4469:     my $output =
1.844     bisitz   4470:         '<div id="LC_head_subbox">'
1.822     bisitz   4471:        .$content
                   4472:        .'</div>'
                   4473: }
                   4474: 
                   4475: ##############################################
                   4476: =pod
                   4477: 
                   4478: =item * &CSTR_pageheader()
                   4479: 
                   4480: Inputs: ./.
                   4481: 
                   4482: Returns: HTML div with CSTR path and recent box
                   4483:          To be included on Construction Space pages
                   4484: 
                   4485: =cut
                   4486: 
                   4487: sub CSTR_pageheader {
                   4488:     # this is for resources; directories have customtitle, and crumbs
                   4489:             # and select recent are created in lonpubdir.pm  
                   4490:     my ($uname,$thisdisfn)=
                   4491:         ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
                   4492:     my $formaction='/priv/'.$uname.'/'.$thisdisfn;
                   4493:     $formaction=~s/\/+/\//g;
                   4494: 
                   4495:     my $parentpath = '';
                   4496:     my $lastitem = '';
                   4497:     if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
                   4498:         $parentpath = $1;
                   4499:         $lastitem = $2;
                   4500:     } else {
                   4501:         $lastitem = $thisdisfn;
                   4502:     }
1.921     bisitz   4503: 
                   4504:     my $output =
1.822     bisitz   4505:          '<div>'
                   4506:         .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
                   4507:         .'<b>'.&mt('Construction Space:').'</b> '
                   4508:         .'<form name="dirs" method="post" action="'.$formaction
1.921     bisitz   4509:         .'" target="_top">' #FIXME lonpubdir: target="_parent"
                   4510:         .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv',undef,undef);
                   4511: 
                   4512:     if ($lastitem) {
                   4513:         $output .=
                   4514:              '<span class="LC_filename">'
                   4515:             .$lastitem
                   4516:             .'</span>';
                   4517:     }
                   4518:     $output .=
                   4519:          '<br />'
1.822     bisitz   4520:         #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
                   4521:         .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
                   4522:         .'</form>'
                   4523:         .&Apache::lonmenu::constspaceform()
                   4524:         .'</div>';
1.921     bisitz   4525: 
                   4526:     return $output;
1.822     bisitz   4527: }
                   4528: 
1.60      matthew  4529: ###############################################
                   4530: ###############################################
                   4531: 
                   4532: =pod
                   4533: 
1.112     bowersj2 4534: =back
                   4535: 
1.549     albertel 4536: =head1 HTML Helpers
1.112     bowersj2 4537: 
                   4538: =over 4
                   4539: 
                   4540: =item * &bodytag()
1.60      matthew  4541: 
                   4542: Returns a uniform header for LON-CAPA web pages.
                   4543: 
                   4544: Inputs: 
                   4545: 
1.112     bowersj2 4546: =over 4
                   4547: 
                   4548: =item * $title, A title to be displayed on the page.
                   4549: 
                   4550: =item * $function, the current role (can be undef).
                   4551: 
                   4552: =item * $addentries, extra parameters for the <body> tag.
                   4553: 
                   4554: =item * $bodyonly, if defined, only return the <body> tag.
                   4555: 
                   4556: =item * $domain, if defined, force a given domain.
                   4557: 
                   4558: =item * $forcereg, if page should register as content page (relevant for 
1.86      www      4559:             text interface only)
1.60      matthew  4560: 
1.814     bisitz   4561: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
                   4562:                      navigational links
1.317     albertel 4563: 
1.338     albertel 4564: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
                   4565: 
1.361     albertel 4566: =item * $no_inline_link, if true and in remote mode, don't show the 
                   4567:          'Switch To Inline Menu' link
                   4568: 
1.460     albertel 4569: =item * $args, optional argument valid values are
                   4570:             no_auto_mt_title -> prevents &mt()ing the title arg
1.562     albertel 4571:             inherit_jsmath -> when creating popup window in a page,
                   4572:                               should it have jsmath forced on by the
                   4573:                               current page
1.460     albertel 4574: 
1.112     bowersj2 4575: =back
                   4576: 
1.60      matthew  4577: Returns: A uniform header for LON-CAPA web pages.  
                   4578: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
                   4579: If $bodyonly is undef or zero, an html string containing a <body> tag and 
                   4580: other decorations will be returned.
                   4581: 
                   4582: =cut
                   4583: 
1.54      www      4584: sub bodytag {
1.831     bisitz   4585:     my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.816     bisitz   4586:         $no_nav_bar,$bgcolor,$no_inline_link,$args)=@_;
1.339     albertel 4587: 
1.948.2.2  raeburn  4588:     my $public;
                   4589:     if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
                   4590:         || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
                   4591:         $public = 1;
                   4592:     }
1.460     albertel 4593:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339     albertel 4594: 
1.183     matthew  4595:     $function = &get_users_function() if (!$function);
1.339     albertel 4596:     my $img =    &designparm($function.'.img',$domain);
                   4597:     my $font =   &designparm($function.'.font',$domain);
                   4598:     my $pgbg   = $bgcolor || &designparm($function.'.pgbg',$domain);
                   4599: 
1.803     bisitz   4600:     my %design = ( 'style'   => 'margin-top: 0',
1.535     albertel 4601: 		   'bgcolor' => $pgbg,
1.339     albertel 4602: 		   'text'    => $font,
                   4603:                    'alink'   => &designparm($function.'.alink',$domain),
                   4604: 		   'vlink'   => &designparm($function.'.vlink',$domain),
                   4605: 		   'link'    => &designparm($function.'.link',$domain),);
1.438     albertel 4606:     @design{keys(%$addentries)} = @$addentries{keys(%$addentries)}; 
1.339     albertel 4607: 
1.63      www      4608:  # role and realm
1.378     raeburn  4609:     my ($role,$realm) = split(/\./,$env{'request.role'},2);
                   4610:     if ($role  eq 'ca') {
1.479     albertel 4611:         my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500     albertel 4612:         $realm = &plainname($rname,$rdom);
1.378     raeburn  4613:     } 
1.55      www      4614: # realm
1.258     albertel 4615:     if ($env{'request.course.id'}) {
1.378     raeburn  4616:         if ($env{'request.role'} !~ /^cr/) {
                   4617:             $role = &Apache::lonnet::plaintext($role,&course_type());
                   4618:         }
1.898     raeburn  4619:         if ($env{'request.course.sec'}) {
                   4620:             $role .= ('&nbsp;'x2).'-&nbsp;'.&mt('section:').'&nbsp;'.$env{'request.course.sec'};
                   4621:         }   
1.359     albertel 4622: 	$realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378     raeburn  4623:     } else {
                   4624:         $role = &Apache::lonnet::plaintext($role);
1.54      www      4625:     }
1.433     albertel 4626: 
1.359     albertel 4627:     if (!$realm) { $realm='&nbsp;'; }
1.55      www      4628: # Set messages
1.60      matthew  4629:     my $messages=&domainlogo($domain);
1.330     albertel 4630: 
1.438     albertel 4631:     my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329     albertel 4632: 
1.101     www      4633: # construct main body tag
1.359     albertel 4634:     my $bodytag = "<body $extra_body_attr>".
1.562     albertel 4635: 	&Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252     albertel 4636: 
1.530     albertel 4637:     if ($bodyonly) {
1.60      matthew  4638:         return $bodytag;
1.798     tempelho 4639:     } 
1.359     albertel 4640: 
1.410     albertel 4641:     my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.948.2.2  raeburn  4642:     if ($public) {
1.433     albertel 4643: 	undef($role);
1.434     albertel 4644:     } else {
                   4645: 	$name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433     albertel 4646:     }
1.948.2.2  raeburn  4647: 
1.762     bisitz   4648:     my $titleinfo = '<h1>'.$title.'</h1>';
1.359     albertel 4649:     #
                   4650:     # Extra info if you are the DC
                   4651:     my $dc_info = '';
                   4652:     if ($env{'user.adv'} && exists($env{'user.role.dc./'.
                   4653:                         $env{'course.'.$env{'request.course.id'}.
                   4654:                                  '.domain'}.'/'})) {
                   4655:         my $cid = $env{'request.course.id'};
1.917     raeburn  4656:         $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380     www      4657:         $dc_info =~ s/\s+$//;
1.359     albertel 4658:     }
                   4659: 
1.898     raeburn  4660:     $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.853     droeschl 4661:     &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
                   4662: 
1.837     bisitz   4663:     if ($env{'environment.remote'} eq 'off') {
1.359     albertel 4664:         # No Remote
1.916     droeschl 4665:         if ($no_nav_bar || $env{'form.inhibitmenu'} eq 'yes') { 
                   4666:             return $bodytag; 
                   4667:         } 
1.903     droeschl 4668: 
                   4669:         if ($env{'request.state'} eq 'construct') { $forcereg=1; }
                   4670: 
                   4671:         #    if ($env{'request.state'} eq 'construct') {
                   4672:         #        $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
                   4673:         #    }
                   4674: 
1.359     albertel 4675: 
                   4676: 
1.916     droeschl 4677:         if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.917     raeburn  4678:              if ($dc_info) {
                   4679:                  $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
                   4680:              }
1.916     droeschl 4681:              $bodytag .= qq|<div id="LC_nav_bar">$name $role<br />
                   4682:                 <em>$realm</em> $dc_info</div>|;
1.903     droeschl 4683:             return $bodytag;
                   4684:         }
1.894     droeschl 4685: 
1.927     raeburn  4686:         unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
                   4687:             $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>|;
                   4688:         }
1.916     droeschl 4689: 
1.903     droeschl 4690:         $bodytag .= Apache::lonhtmlcommon::scripttag(
                   4691:             Apache::lonmenu::utilityfunctions(), 'start');
1.816     bisitz   4692: 
1.903     droeschl 4693:         $bodytag .= Apache::lonmenu::primary_menu();
1.852     droeschl 4694: 
1.917     raeburn  4695:         if ($dc_info) {
                   4696:             $dc_info = &dc_courseid_toggle($dc_info);
                   4697:         }
                   4698:         $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916     droeschl 4699: 
1.903     droeschl 4700:         #don't show menus for public users
1.948.2.2  raeburn  4701:         if (!$public){
1.903     droeschl 4702:             $bodytag .= Apache::lonmenu::secondary_menu();
                   4703:             $bodytag .= Apache::lonmenu::serverform();
1.920     raeburn  4704:             $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
                   4705:             if ($env{'request.state'} eq 'construct') {
                   4706:                 $bodytag .= &Apache::lonmenu::innerregister($forcereg,'',
                   4707:                                 $args->{'bread_crumbs'});
                   4708:             } elsif ($forcereg) { 
                   4709:                 $bodytag .= &Apache::lonmenu::innerregister($forcereg);
                   4710:             }
1.903     droeschl 4711:         }else{
                   4712:             # this is to seperate menu from content when there's no secondary
                   4713:             # menu. Especially needed for public accessible ressources.
                   4714:             $bodytag .= '<hr style="clear:both" />';
                   4715:             $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end'); 
1.235     raeburn  4716:         }
1.903     droeschl 4717: 
1.235     raeburn  4718:         return $bodytag;
1.94      www      4719:     }
1.95      www      4720: 
1.93      www      4721: #
1.95      www      4722: # Top frame rendering, Remote is up
1.93      www      4723: #
1.359     albertel 4724: 
1.517     raeburn  4725:     my $imgsrc = $img;
                   4726:     if ($img =~ /^\/adm/) {
1.575     albertel 4727:         $imgsrc = &lonhttpdurl($img);
1.517     raeburn  4728:     }
                   4729:     my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359     albertel 4730: 
1.305     www      4731:     # Explicit link to get inline menu
1.361     albertel 4732:     my $menu= ($no_inline_link?''
1.883     droeschl 4733: 	       :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
1.917     raeburn  4734: 
                   4735:     if ($dc_info) {
                   4736:         $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
                   4737:     }
                   4738: 
1.916     droeschl 4739:     $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>
1.897     wenzelju 4740:             <ol class="LC_primary_menu LC_right">
1.853     droeschl 4741:                 <li>$menu</li>
1.917     raeburn  4742:             </ol><div id="LC_realm"> $realm $dc_info</div>| unless $env{'form.inhibitmenu'};
1.94      www      4743:     return(<<ENDBODY);
1.60      matthew  4744: $bodytag
1.359     albertel 4745: <table id="LC_title_bar" class="LC_with_remote">
1.791     tempelho 4746: <tr><td>$upperleft</td>
                   4747:     <td>$messages&nbsp;</td>
1.54      www      4748: </tr>
1.359     albertel 4749: <tr><td>$titleinfo $dc_info $menu</td>
1.368     albertel 4750: </tr>
1.356     albertel 4751: </table>
1.54      www      4752: ENDBODY
1.182     matthew  4753: }
                   4754: 
1.917     raeburn  4755: sub dc_courseid_toggle {
                   4756:     my ($dc_info) = @_;
                   4757:     return ' <span id="dccidtext" class="LC_cusr_subheading">'.
                   4758:            '<a href="javascript:showCourseID();">'.
                   4759:            &mt('(More ...)').'</a></span>'.
                   4760:            '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
                   4761: }
                   4762: 
1.330     albertel 4763: sub make_attr_string {
                   4764:     my ($register,$attr_ref) = @_;
                   4765: 
                   4766:     if ($attr_ref && !ref($attr_ref)) {
                   4767: 	die("addentries Must be a hash ref ".
                   4768: 	    join(':',caller(1))." ".
                   4769: 	    join(':',caller(0))." ");
                   4770:     }
                   4771: 
                   4772:     if ($register) {
1.339     albertel 4773: 	my ($on_load,$on_unload);
                   4774: 	foreach my $key (keys(%{$attr_ref})) {
                   4775: 	    if      (lc($key) eq 'onload') {
                   4776: 		$on_load.=$attr_ref->{$key}.';';
                   4777: 		delete($attr_ref->{$key});
                   4778: 
                   4779: 	    } elsif (lc($key) eq 'onunload') {
                   4780: 		$on_unload.=$attr_ref->{$key}.';';
                   4781: 		delete($attr_ref->{$key});
                   4782: 	    }
                   4783: 	}
                   4784: 	$attr_ref->{'onload'}  =
                   4785: 	    &Apache::lonmenu::loadevents().  $on_load;
                   4786: 	$attr_ref->{'onunload'}=
                   4787: 	    &Apache::lonmenu::unloadevents().$on_unload;
                   4788:     }
                   4789: 
                   4790: # Accessibility font enhance
                   4791:     if ($env{'browser.fontenhance'} eq 'on') {
                   4792: 	my $style;
                   4793: 	foreach my $key (keys(%{$attr_ref})) {
                   4794: 	    if (lc($key) eq 'style') {
                   4795: 		$style.=$attr_ref->{$key}.';';
                   4796: 		delete($attr_ref->{$key});
                   4797: 	    }
                   4798: 	}
                   4799: 	$attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330     albertel 4800:     }
1.339     albertel 4801: 
1.330     albertel 4802:     my $attr_string;
                   4803:     foreach my $attr (keys(%$attr_ref)) {
                   4804: 	$attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
                   4805:     }
                   4806:     return $attr_string;
                   4807: }
                   4808: 
                   4809: 
1.182     matthew  4810: ###############################################
1.251     albertel 4811: ###############################################
                   4812: 
                   4813: =pod
                   4814: 
                   4815: =item * &endbodytag()
                   4816: 
                   4817: Returns a uniform footer for LON-CAPA web pages.
                   4818: 
1.635     raeburn  4819: Inputs: 1 - optional reference to an args hash
                   4820: If in the hash, key for noredirectlink has a value which evaluates to true,
                   4821: a 'Continue' link is not displayed if the page contains an
                   4822: internal redirect in the <head></head> section,
                   4823: i.e., $env{'internal.head.redirect'} exists   
1.251     albertel 4824: 
                   4825: =cut
                   4826: 
                   4827: sub endbodytag {
1.635     raeburn  4828:     my ($args) = @_;
1.251     albertel 4829:     my $endbodytag='</body>';
1.269     albertel 4830:     $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315     albertel 4831:     if ( exists( $env{'internal.head.redirect'} ) ) {
1.635     raeburn  4832:         if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
                   4833: 	    $endbodytag=
                   4834: 	        "<br /><a href=\"$env{'internal.head.redirect'}\">".
                   4835: 	        &mt('Continue').'</a>'.
                   4836: 	        $endbodytag;
                   4837:         }
1.315     albertel 4838:     }
1.251     albertel 4839:     return $endbodytag;
                   4840: }
                   4841: 
1.352     albertel 4842: =pod
                   4843: 
                   4844: =item * &standard_css()
                   4845: 
                   4846: Returns a style sheet
                   4847: 
                   4848: Inputs: (all optional)
                   4849:             domain         -> force to color decorate a page for a specific
                   4850:                                domain
                   4851:             function       -> force usage of a specific rolish color scheme
                   4852:             bgcolor        -> override the default page bgcolor
                   4853: 
                   4854: =cut
                   4855: 
1.343     albertel 4856: sub standard_css {
1.345     albertel 4857:     my ($function,$domain,$bgcolor) = @_;
1.352     albertel 4858:     $function  = &get_users_function() if (!$function);
                   4859:     my $img    = &designparm($function.'.img',   $domain);
                   4860:     my $tabbg  = &designparm($function.'.tabbg', $domain);
                   4861:     my $font   = &designparm($function.'.font',  $domain);
1.801     tempelho 4862:     my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791     tempelho 4863: #second colour for later usage
1.345     albertel 4864:     my $sidebg = &designparm($function.'.sidebg',$domain);
1.382     albertel 4865:     my $pgbg_or_bgcolor =
                   4866: 	         $bgcolor ||
1.352     albertel 4867: 	         &designparm($function.'.pgbg',  $domain);
1.382     albertel 4868:     my $pgbg   = &designparm($function.'.pgbg',  $domain);
1.352     albertel 4869:     my $alink  = &designparm($function.'.alink', $domain);
                   4870:     my $vlink  = &designparm($function.'.vlink', $domain);
                   4871:     my $link   = &designparm($function.'.link',  $domain);
                   4872: 
1.602     albertel 4873:     my $sans                 = 'Verdana,Arial,Helvetica,sans-serif';
1.395     albertel 4874:     my $mono                 = 'monospace';
1.850     bisitz   4875:     my $data_table_head      = $sidebg;
                   4876:     my $data_table_light     = '#FAFAFA';
                   4877:     my $data_table_dark      = '#F0F0F0';
1.470     banghart 4878:     my $data_table_darker    = '#CCCCCC';
1.349     albertel 4879:     my $data_table_highlight = '#FFFF00';
1.352     albertel 4880:     my $mail_new             = '#FFBB77';
                   4881:     my $mail_new_hover       = '#DD9955';
                   4882:     my $mail_read            = '#BBBB77';
                   4883:     my $mail_read_hover      = '#999944';
                   4884:     my $mail_replied         = '#AAAA88';
                   4885:     my $mail_replied_hover   = '#888855';
                   4886:     my $mail_other           = '#99BBBB';
                   4887:     my $mail_other_hover     = '#669999';
1.391     albertel 4888:     my $table_header         = '#DDDDDD';
1.489     raeburn  4889:     my $feedback_link_bg     = '#BBBBBB';
1.911     bisitz   4890:     my $lg_border_color      = '#C8C8C8';
1.948.2.1  raeburn  4891:     my $button_hover         = '#BF2317';
1.392     albertel 4892: 
1.608     albertel 4893:     my $border = ($env{'browser.type'} eq 'explorer' ||
1.911     bisitz   4894:       $env{'browser.type'} eq 'safari'     ) ? '0 2px 0 2px'
                   4895:                                              : '0 3px 0 4px';
1.448     albertel 4896: 
1.343     albertel 4897:     return <<END;
1.947     droeschl 4898: 
                   4899: /* needed for iframe to allow 100% height in FF */
                   4900: body, html { 
                   4901:     margin: 0;
                   4902:     padding: 0 0.5%;
                   4903:     height: 99%; /* to avoid scrollbars */
                   4904: }
                   4905: 
1.795     www      4906: body {
1.911     bisitz   4907:   font-family: $sans;
                   4908:   line-height:130%;
                   4909:   font-size:0.83em;
                   4910:   color:$font;
1.795     www      4911: }
                   4912: 
1.948.2.3  raeburn  4913: +a:focus,
                   4914: +a:focus img {
1.795     www      4915:   color: red;
1.911     bisitz   4916:   background: yellow;
1.795     www      4917: }
1.698     harmsja  4918: 
1.911     bisitz   4919: form, .inline {
                   4920:   display: inline;
1.795     www      4921: }
1.721     harmsja  4922: 
1.795     www      4923: .LC_right {
1.911     bisitz   4924:   text-align:right;
1.795     www      4925: }
                   4926: 
                   4927: .LC_middle {
1.911     bisitz   4928:   vertical-align:middle;
1.795     www      4929: }
1.721     harmsja  4930: 
1.911     bisitz   4931: .LC_400Box {
                   4932:   width:400px;
                   4933: }
1.721     harmsja  4934: 
1.947     droeschl 4935: .LC_iframecontainer {
                   4936:     width: 98%;
                   4937:     margin: 0;
                   4938:     position: fixed;
                   4939:     top: 8.5em;
                   4940:     bottom: 0;
                   4941: }
                   4942: 
                   4943: .LC_iframecontainer iframe{
                   4944:     border: none;
                   4945:     width: 100%;
                   4946:     height: 100%;
                   4947: }
                   4948: 
1.778     bisitz   4949: .LC_filename {
                   4950:   font-family: $mono;
                   4951:   white-space:pre;
1.921     bisitz   4952:   font-size: 120%;
1.778     bisitz   4953: }
                   4954: 
                   4955: .LC_fileicon {
                   4956:   border: none;
                   4957:   height: 1.3em;
                   4958:   vertical-align: text-bottom;
                   4959:   margin-right: 0.3em;
                   4960:   text-decoration:none;
                   4961: }
                   4962: 
1.350     albertel 4963: .LC_error {
                   4964:   color: red;
                   4965:   font-size: larger;
                   4966: }
1.795     www      4967: 
1.457     albertel 4968: .LC_warning,
                   4969: .LC_diff_removed {
1.733     bisitz   4970:   color: red;
1.394     albertel 4971: }
1.532     albertel 4972: 
                   4973: .LC_info,
1.457     albertel 4974: .LC_success,
                   4975: .LC_diff_added {
1.350     albertel 4976:   color: green;
                   4977: }
1.795     www      4978: 
1.802     bisitz   4979: div.LC_confirm_box {
                   4980:   background-color: #FAFAFA;
                   4981:   border: 1px solid $lg_border_color;
                   4982:   margin-right: 0;
                   4983:   padding: 5px;
                   4984: }
                   4985: 
                   4986: div.LC_confirm_box .LC_error img,
                   4987: div.LC_confirm_box .LC_success img {
                   4988:   vertical-align: middle;
                   4989: }
                   4990: 
1.440     albertel 4991: .LC_icon {
1.771     droeschl 4992:   border: none;
1.790     droeschl 4993:   vertical-align: middle;
1.771     droeschl 4994: }
                   4995: 
1.543     albertel 4996: .LC_docs_spacer {
                   4997:   width: 25px;
                   4998:   height: 1px;
1.771     droeschl 4999:   border: none;
1.543     albertel 5000: }
1.346     albertel 5001: 
1.532     albertel 5002: .LC_internal_info {
1.735     bisitz   5003:   color: #999999;
1.532     albertel 5004: }
                   5005: 
1.794     www      5006: .LC_discussion {
1.911     bisitz   5007:   background: $tabbg;
                   5008:   border: 1px solid black;
                   5009:   margin: 2px;
1.794     www      5010: }
                   5011: 
                   5012: .LC_disc_action_links_bar {
1.911     bisitz   5013:   background: $tabbg;
                   5014:   border: none;
                   5015:   margin: 4px;
1.794     www      5016: }
                   5017: 
                   5018: .LC_disc_action_left {
1.911     bisitz   5019:   text-align: left;
1.794     www      5020: }
                   5021: 
                   5022: .LC_disc_action_right {
1.911     bisitz   5023:   text-align: right;
1.794     www      5024: }
                   5025: 
                   5026: .LC_disc_new_item {
1.911     bisitz   5027:   background: white;
                   5028:   border: 2px solid red;
                   5029:   margin: 2px;
1.794     www      5030: }
                   5031: 
                   5032: .LC_disc_old_item {
1.911     bisitz   5033:   background: white;
                   5034:   border: 1px solid black;
                   5035:   margin: 2px;
1.794     www      5036: }
                   5037: 
1.458     albertel 5038: table.LC_pastsubmission {
                   5039:   border: 1px solid black;
                   5040:   margin: 2px;
                   5041: }
                   5042: 
1.924     bisitz   5043: table#LC_menubuttons {
1.345     albertel 5044:   width: 100%;
                   5045:   background: $pgbg;
1.392     albertel 5046:   border: 2px;
1.402     albertel 5047:   border-collapse: separate;
1.803     bisitz   5048:   padding: 0;
1.345     albertel 5049: }
1.392     albertel 5050: 
1.801     tempelho 5051: table#LC_title_bar a {
                   5052:   color: $fontmenu;
                   5053: }
1.836     bisitz   5054: 
1.807     droeschl 5055: table#LC_title_bar {
1.819     tempelho 5056:   clear: both;
1.836     bisitz   5057:   display: none;
1.807     droeschl 5058: }
                   5059: 
1.795     www      5060: table#LC_title_bar,
1.933     droeschl 5061: table.LC_breadcrumbs, /* obsolete? */
1.393     albertel 5062: table#LC_title_bar.LC_with_remote {
1.359     albertel 5063:   width: 100%;
1.392     albertel 5064:   border-color: $pgbg;
                   5065:   border-style: solid;
                   5066:   border-width: $border;
1.379     albertel 5067:   background: $pgbg;
1.801     tempelho 5068:   color: $fontmenu;
1.392     albertel 5069:   border-collapse: collapse;
1.803     bisitz   5070:   padding: 0;
1.819     tempelho 5071:   margin: 0;
1.359     albertel 5072: }
1.795     www      5073: 
1.933     droeschl 5074: ul.LC_breadcrumb_tools_outerlist {
1.913     droeschl 5075:     margin: 0;
                   5076:     padding: 0;
1.933     droeschl 5077:     position: relative;
                   5078:     list-style: none;
1.913     droeschl 5079: }
1.933     droeschl 5080: ul.LC_breadcrumb_tools_outerlist li {
1.913     droeschl 5081:     display: inline;
                   5082: }
1.933     droeschl 5083: 
                   5084: .LC_breadcrumb_tools_navigation {
1.913     droeschl 5085:     padding: 0;
1.933     droeschl 5086:     margin: 0;
                   5087:     float: left;
1.913     droeschl 5088: }
1.933     droeschl 5089: .LC_breadcrumb_tools_tools {
                   5090:     padding: 0;
                   5091:     margin: 0;
1.913     droeschl 5092:     float: right;
                   5093: }
                   5094: 
1.359     albertel 5095: table#LC_title_bar td {
                   5096:   background: $tabbg;
                   5097: }
1.795     www      5098: 
1.911     bisitz   5099: table#LC_menubuttons img {
1.803     bisitz   5100:   border: none;
1.346     albertel 5101: }
1.795     www      5102: 
1.842     droeschl 5103: .LC_breadcrumbs_component {
1.911     bisitz   5104:   float: right;
                   5105:   margin: 0 1em;
1.357     albertel 5106: }
1.842     droeschl 5107: .LC_breadcrumbs_component img {
1.911     bisitz   5108:   vertical-align: middle;
1.777     tempelho 5109: }
1.795     www      5110: 
1.383     albertel 5111: td.LC_table_cell_checkbox {
                   5112:   text-align: center;
                   5113: }
1.795     www      5114: 
                   5115: .LC_fontsize_small {
1.911     bisitz   5116:   font-size: 70%;
1.705     tempelho 5117: }
                   5118: 
1.844     bisitz   5119: #LC_breadcrumbs {
1.911     bisitz   5120:   clear:both;
                   5121:   background: $sidebg;
                   5122:   border-bottom: 1px solid $lg_border_color;
                   5123:   line-height: 2.5em;
1.933     droeschl 5124:   overflow: hidden;
1.911     bisitz   5125:   margin: 0;
                   5126:   padding: 0;
1.819     tempelho 5127: }
1.862     bisitz   5128: 
1.839     droeschl 5129: /* Preliminary fix to hide breadcrumbs inside remote control window */
1.844     bisitz   5130: #LC_remote #LC_breadcrumbs {
1.911     bisitz   5131:   display:none;
1.839     droeschl 5132: }
1.819     tempelho 5133: 
1.844     bisitz   5134: #LC_head_subbox {
1.911     bisitz   5135:   clear:both;
                   5136:   background: #F8F8F8; /* $sidebg; */
1.915     droeschl 5137:   border: 1px solid $sidebg;
                   5138:   margin: 0 0 10px 0;      
1.948.2.6  raeburn  5139:   padding: 3px;
1.822     bisitz   5140: }
                   5141: 
1.795     www      5142: .LC_fontsize_medium {
1.911     bisitz   5143:   font-size: 85%;
1.705     tempelho 5144: }
                   5145: 
1.795     www      5146: .LC_fontsize_large {
1.911     bisitz   5147:   font-size: 120%;
1.705     tempelho 5148: }
                   5149: 
1.346     albertel 5150: .LC_menubuttons_inline_text {
                   5151:   color: $font;
1.698     harmsja  5152:   font-size: 90%;
1.701     harmsja  5153:   padding-left:3px;
1.346     albertel 5154: }
                   5155: 
1.934     droeschl 5156: .LC_menubuttons_inline_text img{
                   5157:   vertical-align: middle;
                   5158: }
                   5159: 
1.948.2.1  raeburn  5160: li.LC_menubuttons_inline_text img,a {
                   5161:   cursor:pointer;
                   5162: }
                   5163: 
1.526     www      5164: .LC_menubuttons_link {
                   5165:   text-decoration: none;
                   5166: }
1.795     www      5167: 
1.522     albertel 5168: .LC_menubuttons_category {
1.521     www      5169:   color: $font;
1.526     www      5170:   background: $pgbg;
1.521     www      5171:   font-size: larger;
                   5172:   font-weight: bold;
                   5173: }
                   5174: 
1.346     albertel 5175: td.LC_menubuttons_text {
1.911     bisitz   5176:   color: $font;
1.346     albertel 5177: }
1.706     harmsja  5178: 
1.346     albertel 5179: .LC_current_location {
                   5180:   background: $tabbg;
                   5181: }
1.795     www      5182: 
1.938     bisitz   5183: table.LC_data_table {
1.347     albertel 5184:   border: 1px solid #000000;
1.402     albertel 5185:   border-collapse: separate;
1.426     albertel 5186:   border-spacing: 1px;
1.610     albertel 5187:   background: $pgbg;
1.347     albertel 5188: }
1.795     www      5189: 
1.422     albertel 5190: .LC_data_table_dense {
                   5191:   font-size: small;
                   5192: }
1.795     www      5193: 
1.507     raeburn  5194: table.LC_nested_outer {
                   5195:   border: 1px solid #000000;
1.589     raeburn  5196:   border-collapse: collapse;
1.803     bisitz   5197:   border-spacing: 0;
1.507     raeburn  5198:   width: 100%;
                   5199: }
1.795     www      5200: 
1.879     raeburn  5201: table.LC_innerpickbox,
1.507     raeburn  5202: table.LC_nested {
1.803     bisitz   5203:   border: none;
1.589     raeburn  5204:   border-collapse: collapse;
1.803     bisitz   5205:   border-spacing: 0;
1.507     raeburn  5206:   width: 100%;
                   5207: }
1.795     www      5208: 
1.930     faziophi 5209: .ui-accordion,
                   5210: .ui-accordion table.LC_data_table,
                   5211: .ui-accordion table.LC_nested_outer{
                   5212:   border: 0px;
                   5213:   border-spacing: 0px;
                   5214:   margin: 3px;
                   5215: }
                   5216: 
1.911     bisitz   5217: table.LC_data_table tr th,
                   5218: table.LC_calendar tr th,
1.879     raeburn  5219: table.LC_prior_tries tr th,
                   5220: table.LC_innerpickbox tr th {
1.349     albertel 5221:   font-weight: bold;
                   5222:   background-color: $data_table_head;
1.801     tempelho 5223:   color:$fontmenu;
1.701     harmsja  5224:   font-size:90%;
1.347     albertel 5225: }
1.795     www      5226: 
1.879     raeburn  5227: table.LC_innerpickbox tr th,
                   5228: table.LC_innerpickbox tr td {
                   5229:   vertical-align: top;
                   5230: }
                   5231: 
1.711     raeburn  5232: table.LC_data_table tr.LC_info_row > td {
1.735     bisitz   5233:   background-color: #CCCCCC;
1.711     raeburn  5234:   font-weight: bold;
                   5235:   text-align: left;
                   5236: }
1.795     www      5237: 
1.912     bisitz   5238: table.LC_data_table tr.LC_odd_row > td {
                   5239:   background-color: $data_table_light;
                   5240:   padding: 2px;
                   5241:   vertical-align: top;
                   5242: }
                   5243: 
1.809     bisitz   5244: table.LC_pick_box tr > td.LC_odd_row {
1.349     albertel 5245:   background-color: $data_table_light;
1.912     bisitz   5246:   vertical-align: top;
                   5247: }
                   5248: 
                   5249: table.LC_data_table tr.LC_even_row > td {
                   5250:   background-color: $data_table_dark;
1.425     albertel 5251:   padding: 2px;
1.900     bisitz   5252:   vertical-align: top;
1.347     albertel 5253: }
1.795     www      5254: 
1.809     bisitz   5255: table.LC_pick_box tr > td.LC_even_row {
1.349     albertel 5256:   background-color: $data_table_dark;
1.900     bisitz   5257:   vertical-align: top;
1.347     albertel 5258: }
1.795     www      5259: 
1.425     albertel 5260: table.LC_data_table tr.LC_data_table_highlight td {
                   5261:   background-color: $data_table_darker;
                   5262: }
1.795     www      5263: 
1.639     raeburn  5264: table.LC_data_table tr td.LC_leftcol_header {
                   5265:   background-color: $data_table_head;
                   5266:   font-weight: bold;
                   5267: }
1.795     www      5268: 
1.451     albertel 5269: table.LC_data_table tr.LC_empty_row td,
1.507     raeburn  5270: table.LC_nested tr.LC_empty_row td {
1.421     albertel 5271:   font-weight: bold;
                   5272:   font-style: italic;
                   5273:   text-align: center;
                   5274:   padding: 8px;
1.347     albertel 5275: }
1.795     www      5276: 
1.940     bisitz   5277: table.LC_data_table tr.LC_empty_row td {
                   5278:   background-color: $sidebg;
                   5279: }
                   5280: 
                   5281: table.LC_nested tr.LC_empty_row td {
                   5282:   background-color: #FFFFFF;
                   5283: }
                   5284: 
1.890     droeschl 5285: table.LC_caption {
                   5286: }
                   5287: 
1.507     raeburn  5288: table.LC_nested tr.LC_empty_row td {
1.465     albertel 5289:   padding: 4ex
                   5290: }
1.795     www      5291: 
1.507     raeburn  5292: table.LC_nested_outer tr th {
                   5293:   font-weight: bold;
1.801     tempelho 5294:   color:$fontmenu;
1.507     raeburn  5295:   background-color: $data_table_head;
1.701     harmsja  5296:   font-size: small;
1.507     raeburn  5297:   border-bottom: 1px solid #000000;
                   5298: }
1.795     www      5299: 
1.507     raeburn  5300: table.LC_nested_outer tr td.LC_subheader {
                   5301:   background-color: $data_table_head;
                   5302:   font-weight: bold;
                   5303:   font-size: small;
                   5304:   border-bottom: 1px solid #000000;
                   5305:   text-align: right;
1.451     albertel 5306: }
1.795     www      5307: 
1.507     raeburn  5308: table.LC_nested tr.LC_info_row td {
1.735     bisitz   5309:   background-color: #CCCCCC;
1.451     albertel 5310:   font-weight: bold;
                   5311:   font-size: small;
1.507     raeburn  5312:   text-align: center;
                   5313: }
1.795     www      5314: 
1.589     raeburn  5315: table.LC_nested tr.LC_info_row td.LC_left_item,
                   5316: table.LC_nested_outer tr th.LC_left_item {
1.507     raeburn  5317:   text-align: left;
1.451     albertel 5318: }
1.795     www      5319: 
1.507     raeburn  5320: table.LC_nested td {
1.735     bisitz   5321:   background-color: #FFFFFF;
1.451     albertel 5322:   font-size: small;
1.507     raeburn  5323: }
1.795     www      5324: 
1.507     raeburn  5325: table.LC_nested_outer tr th.LC_right_item,
                   5326: table.LC_nested tr.LC_info_row td.LC_right_item,
                   5327: table.LC_nested tr.LC_odd_row td.LC_right_item,
                   5328: table.LC_nested tr td.LC_right_item {
1.451     albertel 5329:   text-align: right;
                   5330: }
                   5331: 
1.930     faziophi 5332: .ui-accordion table.LC_nested tr.LC_odd_row td.LC_left_item,
                   5333: .ui-accordion table.LC_nested tr.LC_even_row td.LC_left_item {
                   5334:   text-align: right;
                   5335:   width: 40%;
                   5336:   padding-right:10px;
                   5337:   vertical-align: top;
                   5338:   padding: 5px;
                   5339: }
                   5340: 
                   5341: .ui-accordion table.LC_nested tr.LC_odd_row td.LC_right_item,
                   5342: .ui-accordion table.LC_nested tr.LC_even_row td.LC_right_item {
                   5343:   text-align: left;
                   5344:   width: 60%;
                   5345:   padding: 2px 4px;
                   5346: }
                   5347: 
1.507     raeburn  5348: table.LC_nested tr.LC_odd_row td {
1.735     bisitz   5349:   background-color: #EEEEEE;
1.451     albertel 5350: }
                   5351: 
1.473     raeburn  5352: table.LC_createuser {
                   5353: }
                   5354: 
                   5355: table.LC_createuser tr.LC_section_row td {
1.701     harmsja  5356:   font-size: small;
1.473     raeburn  5357: }
                   5358: 
                   5359: table.LC_createuser tr.LC_info_row td  {
1.735     bisitz   5360:   background-color: #CCCCCC;
1.473     raeburn  5361:   font-weight: bold;
                   5362:   text-align: center;
                   5363: }
                   5364: 
1.349     albertel 5365: table.LC_calendar {
                   5366:   border: 1px solid #000000;
                   5367:   border-collapse: collapse;
1.917     raeburn  5368:   width: 98%;
1.349     albertel 5369: }
1.795     www      5370: 
1.349     albertel 5371: table.LC_calendar_pickdate {
                   5372:   font-size: xx-small;
                   5373: }
1.795     www      5374: 
1.349     albertel 5375: table.LC_calendar tr td {
                   5376:   border: 1px solid #000000;
                   5377:   vertical-align: top;
1.917     raeburn  5378:   width: 14%;
1.349     albertel 5379: }
1.795     www      5380: 
1.349     albertel 5381: table.LC_calendar tr td.LC_calendar_day_empty {
                   5382:   background-color: $data_table_dark;
                   5383: }
1.795     www      5384: 
1.779     bisitz   5385: table.LC_calendar tr td.LC_calendar_day_current {
                   5386:   background-color: $data_table_highlight;
1.777     tempelho 5387: }
1.795     www      5388: 
1.938     bisitz   5389: table.LC_data_table tr td.LC_mail_new {
1.349     albertel 5390:   background-color: $mail_new;
                   5391: }
1.795     www      5392: 
1.938     bisitz   5393: table.LC_data_table tr.LC_mail_new:hover {
1.349     albertel 5394:   background-color: $mail_new_hover;
                   5395: }
1.795     www      5396: 
1.938     bisitz   5397: table.LC_data_table tr td.LC_mail_read {
1.349     albertel 5398:   background-color: $mail_read;
                   5399: }
1.795     www      5400: 
1.938     bisitz   5401: /*
                   5402: table.LC_data_table tr.LC_mail_read:hover {
1.349     albertel 5403:   background-color: $mail_read_hover;
                   5404: }
1.938     bisitz   5405: */
1.795     www      5406: 
1.938     bisitz   5407: table.LC_data_table tr td.LC_mail_replied {
1.349     albertel 5408:   background-color: $mail_replied;
                   5409: }
1.795     www      5410: 
1.938     bisitz   5411: /*
                   5412: table.LC_data_table tr.LC_mail_replied:hover {
1.349     albertel 5413:   background-color: $mail_replied_hover;
                   5414: }
1.938     bisitz   5415: */
1.795     www      5416: 
1.938     bisitz   5417: table.LC_data_table tr td.LC_mail_other {
1.349     albertel 5418:   background-color: $mail_other;
                   5419: }
1.795     www      5420: 
1.938     bisitz   5421: /*
                   5422: table.LC_data_table tr.LC_mail_other:hover {
1.349     albertel 5423:   background-color: $mail_other_hover;
                   5424: }
1.938     bisitz   5425: */
1.494     raeburn  5426: 
1.777     tempelho 5427: table.LC_data_table tr > td.LC_browser_file,
                   5428: table.LC_data_table tr > td.LC_browser_file_published {
1.899     bisitz   5429:   background: #AAEE77;
1.389     albertel 5430: }
1.795     www      5431: 
1.777     tempelho 5432: table.LC_data_table tr > td.LC_browser_file_locked,
                   5433: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389     albertel 5434:   background: #FFAA99;
1.387     albertel 5435: }
1.795     www      5436: 
1.777     tempelho 5437: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899     bisitz   5438:   background: #888888;
1.779     bisitz   5439: }
1.795     www      5440: 
1.777     tempelho 5441: table.LC_data_table tr > td.LC_browser_file_modified,
1.779     bisitz   5442: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899     bisitz   5443:   background: #F8F866;
1.777     tempelho 5444: }
1.795     www      5445: 
1.696     bisitz   5446: table.LC_data_table tr.LC_browser_folder > td {
1.899     bisitz   5447:   background: #E0E8FF;
1.387     albertel 5448: }
1.696     bisitz   5449: 
1.707     bisitz   5450: table.LC_data_table tr > td.LC_roles_is {
1.911     bisitz   5451:   /* background: #77FF77; */
1.707     bisitz   5452: }
1.795     www      5453: 
1.707     bisitz   5454: table.LC_data_table tr > td.LC_roles_future {
1.939     bisitz   5455:   border-right: 8px solid #FFFF77;
1.707     bisitz   5456: }
1.795     www      5457: 
1.707     bisitz   5458: table.LC_data_table tr > td.LC_roles_will {
1.939     bisitz   5459:   border-right: 8px solid #FFAA77;
1.707     bisitz   5460: }
1.795     www      5461: 
1.707     bisitz   5462: table.LC_data_table tr > td.LC_roles_expired {
1.939     bisitz   5463:   border-right: 8px solid #FF7777;
1.707     bisitz   5464: }
1.795     www      5465: 
1.707     bisitz   5466: table.LC_data_table tr > td.LC_roles_will_not {
1.939     bisitz   5467:   border-right: 8px solid #AAFF77;
1.707     bisitz   5468: }
1.795     www      5469: 
1.707     bisitz   5470: table.LC_data_table tr > td.LC_roles_selected {
1.939     bisitz   5471:   border-right: 8px solid #11CC55;
1.707     bisitz   5472: }
                   5473: 
1.388     albertel 5474: span.LC_current_location {
1.701     harmsja  5475:   font-size:larger;
1.388     albertel 5476:   background: $pgbg;
                   5477: }
1.387     albertel 5478: 
1.395     albertel 5479: span.LC_parm_menu_item {
                   5480:   font-size: larger;
                   5481: }
1.795     www      5482: 
1.395     albertel 5483: span.LC_parm_scope_all {
                   5484:   color: red;
                   5485: }
1.795     www      5486: 
1.395     albertel 5487: span.LC_parm_scope_folder {
                   5488:   color: green;
                   5489: }
1.795     www      5490: 
1.395     albertel 5491: span.LC_parm_scope_resource {
                   5492:   color: orange;
                   5493: }
1.795     www      5494: 
1.395     albertel 5495: span.LC_parm_part {
                   5496:   color: blue;
                   5497: }
1.795     www      5498: 
1.911     bisitz   5499: span.LC_parm_folder,
                   5500: span.LC_parm_symb {
1.395     albertel 5501:   font-size: x-small;
                   5502:   font-family: $mono;
                   5503:   color: #AAAAAA;
                   5504: }
                   5505: 
1.795     www      5506: td.LC_parm_overview_level_menu,
                   5507: td.LC_parm_overview_map_menu,
                   5508: td.LC_parm_overview_parm_selectors,
                   5509: td.LC_parm_overview_restrictions  {
1.396     albertel 5510:   border: 1px solid black;
                   5511:   border-collapse: collapse;
                   5512: }
1.795     www      5513: 
1.396     albertel 5514: table.LC_parm_overview_restrictions td {
                   5515:   border-width: 1px 4px 1px 4px;
                   5516:   border-style: solid;
                   5517:   border-color: $pgbg;
                   5518:   text-align: center;
                   5519: }
1.795     www      5520: 
1.396     albertel 5521: table.LC_parm_overview_restrictions th {
                   5522:   background: $tabbg;
                   5523:   border-width: 1px 4px 1px 4px;
                   5524:   border-style: solid;
                   5525:   border-color: $pgbg;
                   5526: }
1.795     www      5527: 
1.398     albertel 5528: table#LC_helpmenu {
1.803     bisitz   5529:   border: none;
1.398     albertel 5530:   height: 55px;
1.803     bisitz   5531:   border-spacing: 0;
1.398     albertel 5532: }
                   5533: 
                   5534: table#LC_helpmenu fieldset legend {
                   5535:   font-size: larger;
                   5536: }
1.795     www      5537: 
1.397     albertel 5538: table#LC_helpmenu_links {
                   5539:   width: 100%;
                   5540:   border: 1px solid black;
                   5541:   background: $pgbg;
1.803     bisitz   5542:   padding: 0;
1.397     albertel 5543:   border-spacing: 1px;
                   5544: }
1.795     www      5545: 
1.397     albertel 5546: table#LC_helpmenu_links tr td {
                   5547:   padding: 1px;
                   5548:   background: $tabbg;
1.399     albertel 5549:   text-align: center;
                   5550:   font-weight: bold;
1.397     albertel 5551: }
1.396     albertel 5552: 
1.795     www      5553: table#LC_helpmenu_links a:link,
                   5554: table#LC_helpmenu_links a:visited,
1.397     albertel 5555: table#LC_helpmenu_links a:active {
                   5556:   text-decoration: none;
                   5557:   color: $font;
                   5558: }
1.795     www      5559: 
1.397     albertel 5560: table#LC_helpmenu_links a:hover {
                   5561:   text-decoration: underline;
                   5562:   color: $vlink;
                   5563: }
1.396     albertel 5564: 
1.417     albertel 5565: .LC_chrt_popup_exists {
                   5566:   border: 1px solid #339933;
                   5567:   margin: -1px;
                   5568: }
1.795     www      5569: 
1.417     albertel 5570: .LC_chrt_popup_up {
                   5571:   border: 1px solid yellow;
                   5572:   margin: -1px;
                   5573: }
1.795     www      5574: 
1.417     albertel 5575: .LC_chrt_popup {
                   5576:   border: 1px solid #8888FF;
                   5577:   background: #CCCCFF;
                   5578: }
1.795     www      5579: 
1.421     albertel 5580: table.LC_pick_box {
                   5581:   border-collapse: separate;
                   5582:   background: white;
                   5583:   border: 1px solid black;
                   5584:   border-spacing: 1px;
                   5585: }
1.795     www      5586: 
1.421     albertel 5587: table.LC_pick_box td.LC_pick_box_title {
1.850     bisitz   5588:   background: $sidebg;
1.421     albertel 5589:   font-weight: bold;
1.900     bisitz   5590:   text-align: left;
1.740     bisitz   5591:   vertical-align: top;
1.421     albertel 5592:   width: 184px;
                   5593:   padding: 8px;
                   5594: }
1.795     www      5595: 
1.579     raeburn  5596: table.LC_pick_box td.LC_pick_box_value {
                   5597:   text-align: left;
                   5598:   padding: 8px;
                   5599: }
1.795     www      5600: 
1.579     raeburn  5601: table.LC_pick_box td.LC_pick_box_select {
                   5602:   text-align: left;
                   5603:   padding: 8px;
                   5604: }
1.795     www      5605: 
1.424     albertel 5606: table.LC_pick_box td.LC_pick_box_separator {
1.803     bisitz   5607:   padding: 0;
1.421     albertel 5608:   height: 1px;
                   5609:   background: black;
                   5610: }
1.795     www      5611: 
1.421     albertel 5612: table.LC_pick_box td.LC_pick_box_submit {
                   5613:   text-align: right;
                   5614: }
1.795     www      5615: 
1.579     raeburn  5616: table.LC_pick_box td.LC_evenrow_value {
                   5617:   text-align: left;
                   5618:   padding: 8px;
                   5619:   background-color: $data_table_light;
                   5620: }
1.795     www      5621: 
1.579     raeburn  5622: table.LC_pick_box td.LC_oddrow_value {
                   5623:   text-align: left;
                   5624:   padding: 8px;
                   5625:   background-color: $data_table_light;
                   5626: }
1.795     www      5627: 
1.579     raeburn  5628: span.LC_helpform_receipt_cat {
                   5629:   font-weight: bold;
                   5630: }
1.795     www      5631: 
1.424     albertel 5632: table.LC_group_priv_box {
                   5633:   background: white;
                   5634:   border: 1px solid black;
                   5635:   border-spacing: 1px;
                   5636: }
1.795     www      5637: 
1.424     albertel 5638: table.LC_group_priv_box td.LC_pick_box_title {
                   5639:   background: $tabbg;
                   5640:   font-weight: bold;
                   5641:   text-align: right;
                   5642:   width: 184px;
                   5643: }
1.795     www      5644: 
1.424     albertel 5645: table.LC_group_priv_box td.LC_groups_fixed {
                   5646:   background: $data_table_light;
                   5647:   text-align: center;
                   5648: }
1.795     www      5649: 
1.424     albertel 5650: table.LC_group_priv_box td.LC_groups_optional {
                   5651:   background: $data_table_dark;
                   5652:   text-align: center;
                   5653: }
1.795     www      5654: 
1.424     albertel 5655: table.LC_group_priv_box td.LC_groups_functionality {
                   5656:   background: $data_table_darker;
                   5657:   text-align: center;
                   5658:   font-weight: bold;
                   5659: }
1.795     www      5660: 
1.424     albertel 5661: table.LC_group_priv td {
                   5662:   text-align: left;
1.803     bisitz   5663:   padding: 0;
1.424     albertel 5664: }
                   5665: 
1.421     albertel 5666: table.LC_notify_front_page {
                   5667:   background: white;
                   5668:   border: 1px solid black;
                   5669:   padding: 8px;
                   5670: }
1.795     www      5671: 
1.421     albertel 5672: table.LC_notify_front_page td {
                   5673:   padding: 8px;
                   5674: }
1.795     www      5675: 
1.424     albertel 5676: .LC_navbuttons {
                   5677:   margin: 2ex 0ex 2ex 0ex;
                   5678: }
1.795     www      5679: 
1.423     albertel 5680: .LC_topic_bar {
                   5681:   font-weight: bold;
                   5682:   background: $tabbg;
1.918     wenzelju 5683:   margin: 1em 0em 1em 2em;
1.805     bisitz   5684:   padding: 3px;
1.918     wenzelju 5685:   font-size: 1.2em;
1.423     albertel 5686: }
1.795     www      5687: 
1.423     albertel 5688: .LC_topic_bar span {
1.918     wenzelju 5689:   left: 0.5em;
                   5690:   position: absolute;
1.423     albertel 5691:   vertical-align: middle;
1.918     wenzelju 5692:   font-size: 1.2em;
1.423     albertel 5693: }
1.795     www      5694: 
1.423     albertel 5695: table.LC_course_group_status {
                   5696:   margin: 20px;
                   5697: }
1.795     www      5698: 
1.423     albertel 5699: table.LC_status_selector td {
                   5700:   vertical-align: top;
                   5701:   text-align: center;
1.424     albertel 5702:   padding: 4px;
                   5703: }
1.795     www      5704: 
1.599     albertel 5705: div.LC_feedback_link {
1.616     albertel 5706:   clear: both;
1.829     kalberla 5707:   background: $sidebg;
1.779     bisitz   5708:   width: 100%;
1.829     kalberla 5709:   padding-bottom: 10px;
                   5710:   border: 1px $tabbg solid;
1.833     kalberla 5711:   height: 22px;
                   5712:   line-height: 22px;
                   5713:   padding-top: 5px;
                   5714: }
                   5715: 
                   5716: div.LC_feedback_link img {
                   5717:   height: 22px;
1.867     kalberla 5718:   vertical-align:middle;
1.829     kalberla 5719: }
                   5720: 
1.911     bisitz   5721: div.LC_feedback_link a {
1.829     kalberla 5722:   text-decoration: none;
1.489     raeburn  5723: }
1.795     www      5724: 
1.867     kalberla 5725: div.LC_comblock {
1.911     bisitz   5726:   display:inline;
1.867     kalberla 5727:   color:$font;
                   5728:   font-size:90%;
                   5729: }
                   5730: 
                   5731: div.LC_feedback_link div.LC_comblock {
                   5732:   padding-left:5px;
                   5733: }
                   5734: 
                   5735: div.LC_feedback_link div.LC_comblock a {
                   5736:   color:$font;
                   5737: }
                   5738: 
1.489     raeburn  5739: span.LC_feedback_link {
1.858     bisitz   5740:   /* background: $feedback_link_bg; */
1.599     albertel 5741:   font-size: larger;
                   5742: }
1.795     www      5743: 
1.599     albertel 5744: span.LC_message_link {
1.858     bisitz   5745:   /* background: $feedback_link_bg; */
1.599     albertel 5746:   font-size: larger;
                   5747:   position: absolute;
                   5748:   right: 1em;
1.489     raeburn  5749: }
1.421     albertel 5750: 
1.515     albertel 5751: table.LC_prior_tries {
1.524     albertel 5752:   border: 1px solid #000000;
                   5753:   border-collapse: separate;
                   5754:   border-spacing: 1px;
1.515     albertel 5755: }
1.523     albertel 5756: 
1.515     albertel 5757: table.LC_prior_tries td {
1.524     albertel 5758:   padding: 2px;
1.515     albertel 5759: }
1.523     albertel 5760: 
                   5761: .LC_answer_correct {
1.795     www      5762:   background: lightgreen;
                   5763:   color: darkgreen;
                   5764:   padding: 6px;
1.523     albertel 5765: }
1.795     www      5766: 
1.523     albertel 5767: .LC_answer_charged_try {
1.797     www      5768:   background: #FFAAAA;
1.795     www      5769:   color: darkred;
                   5770:   padding: 6px;
1.523     albertel 5771: }
1.795     www      5772: 
1.779     bisitz   5773: .LC_answer_not_charged_try,
1.523     albertel 5774: .LC_answer_no_grade,
                   5775: .LC_answer_late {
1.795     www      5776:   background: lightyellow;
1.523     albertel 5777:   color: black;
1.795     www      5778:   padding: 6px;
1.523     albertel 5779: }
1.795     www      5780: 
1.523     albertel 5781: .LC_answer_previous {
1.795     www      5782:   background: lightblue;
                   5783:   color: darkblue;
                   5784:   padding: 6px;
1.523     albertel 5785: }
1.795     www      5786: 
1.779     bisitz   5787: .LC_answer_no_message {
1.777     tempelho 5788:   background: #FFFFFF;
                   5789:   color: black;
1.795     www      5790:   padding: 6px;
1.779     bisitz   5791: }
1.795     www      5792: 
1.779     bisitz   5793: .LC_answer_unknown {
                   5794:   background: orange;
                   5795:   color: black;
1.795     www      5796:   padding: 6px;
1.777     tempelho 5797: }
1.795     www      5798: 
1.529     albertel 5799: span.LC_prior_numerical,
                   5800: span.LC_prior_string,
                   5801: span.LC_prior_custom,
                   5802: span.LC_prior_reaction,
                   5803: span.LC_prior_math {
1.925     bisitz   5804:   font-family: $mono;
1.523     albertel 5805:   white-space: pre;
                   5806: }
                   5807: 
1.525     albertel 5808: span.LC_prior_string {
1.925     bisitz   5809:   font-family: $mono;
1.525     albertel 5810:   white-space: pre;
                   5811: }
                   5812: 
1.523     albertel 5813: table.LC_prior_option {
                   5814:   width: 100%;
                   5815:   border-collapse: collapse;
                   5816: }
1.795     www      5817: 
1.911     bisitz   5818: table.LC_prior_rank,
1.795     www      5819: table.LC_prior_match {
1.528     albertel 5820:   border-collapse: collapse;
                   5821: }
1.795     www      5822: 
1.528     albertel 5823: table.LC_prior_option tr td,
                   5824: table.LC_prior_rank tr td,
                   5825: table.LC_prior_match tr td {
1.524     albertel 5826:   border: 1px solid #000000;
1.515     albertel 5827: }
                   5828: 
1.855     bisitz   5829: .LC_nobreak {
1.544     albertel 5830:   white-space: nowrap;
1.519     raeburn  5831: }
                   5832: 
1.576     raeburn  5833: span.LC_cusr_emph {
                   5834:   font-style: italic;
                   5835: }
                   5836: 
1.633     raeburn  5837: span.LC_cusr_subheading {
                   5838:   font-weight: normal;
                   5839:   font-size: 85%;
                   5840: }
                   5841: 
1.861     bisitz   5842: div.LC_docs_entry_move {
1.859     bisitz   5843:   border: 1px solid #BBBBBB;
1.545     albertel 5844:   background: #DDDDDD;
1.861     bisitz   5845:   width: 22px;
1.859     bisitz   5846:   padding: 1px;
                   5847:   margin: 0;
1.545     albertel 5848: }
                   5849: 
1.861     bisitz   5850: table.LC_data_table tr > td.LC_docs_entry_commands,
                   5851: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545     albertel 5852:   background: #DDDDDD;
                   5853:   font-size: x-small;
                   5854: }
1.795     www      5855: 
1.861     bisitz   5856: .LC_docs_entry_parameter {
                   5857:   white-space: nowrap;
                   5858: }
                   5859: 
1.544     albertel 5860: .LC_docs_copy {
1.545     albertel 5861:   color: #000099;
1.544     albertel 5862: }
1.795     www      5863: 
1.544     albertel 5864: .LC_docs_cut {
1.545     albertel 5865:   color: #550044;
1.544     albertel 5866: }
1.795     www      5867: 
1.544     albertel 5868: .LC_docs_rename {
1.545     albertel 5869:   color: #009900;
1.544     albertel 5870: }
1.795     www      5871: 
1.544     albertel 5872: .LC_docs_remove {
1.545     albertel 5873:   color: #990000;
                   5874: }
                   5875: 
1.547     albertel 5876: .LC_docs_reinit_warn,
                   5877: .LC_docs_ext_edit {
                   5878:   font-size: x-small;
                   5879: }
                   5880: 
1.545     albertel 5881: table.LC_docs_adddocs td,
                   5882: table.LC_docs_adddocs th {
                   5883:   border: 1px solid #BBBBBB;
                   5884:   padding: 4px;
                   5885:   background: #DDDDDD;
1.543     albertel 5886: }
                   5887: 
1.584     albertel 5888: table.LC_sty_begin {
                   5889:   background: #BBFFBB;
                   5890: }
1.795     www      5891: 
1.584     albertel 5892: table.LC_sty_end {
                   5893:   background: #FFBBBB;
                   5894: }
                   5895: 
1.589     raeburn  5896: table.LC_double_column {
1.803     bisitz   5897:   border-width: 0;
1.589     raeburn  5898:   border-collapse: collapse;
                   5899:   width: 100%;
                   5900:   padding: 2px;
                   5901: }
                   5902: 
                   5903: table.LC_double_column tr td.LC_left_col {
1.590     raeburn  5904:   top: 2px;
1.589     raeburn  5905:   left: 2px;
                   5906:   width: 47%;
                   5907:   vertical-align: top;
                   5908: }
                   5909: 
                   5910: table.LC_double_column tr td.LC_right_col {
                   5911:   top: 2px;
1.779     bisitz   5912:   right: 2px;
1.589     raeburn  5913:   width: 47%;
                   5914:   vertical-align: top;
                   5915: }
                   5916: 
1.591     raeburn  5917: div.LC_left_float {
                   5918:   float: left;
                   5919:   padding-right: 5%;
1.597     albertel 5920:   padding-bottom: 4px;
1.591     raeburn  5921: }
                   5922: 
                   5923: div.LC_clear_float_header {
1.597     albertel 5924:   padding-bottom: 2px;
1.591     raeburn  5925: }
                   5926: 
                   5927: div.LC_clear_float_footer {
1.597     albertel 5928:   padding-top: 10px;
1.591     raeburn  5929:   clear: both;
                   5930: }
                   5931: 
1.597     albertel 5932: div.LC_grade_show_user {
1.941     bisitz   5933: /*  border-left: 5px solid $sidebg; */
                   5934:   border-top: 5px solid #000000;
                   5935:   margin: 50px 0 0 0;
1.936     bisitz   5936:   padding: 15px 0 5px 10px;
1.597     albertel 5937: }
1.795     www      5938: 
1.936     bisitz   5939: div.LC_grade_show_user_odd_row {
1.941     bisitz   5940: /*  border-left: 5px solid #000000; */
                   5941: }
                   5942: 
                   5943: div.LC_grade_show_user div.LC_Box {
                   5944:   margin-right: 50px;
1.597     albertel 5945: }
                   5946: 
                   5947: div.LC_grade_submissions,
                   5948: div.LC_grade_message_center,
1.936     bisitz   5949: div.LC_grade_info_links {
1.597     albertel 5950:   margin: 5px;
                   5951:   width: 99%;
                   5952:   background: #FFFFFF;
                   5953: }
1.795     www      5954: 
1.597     albertel 5955: div.LC_grade_submissions_header,
1.936     bisitz   5956: div.LC_grade_message_center_header {
1.705     tempelho 5957:   font-weight: bold;
                   5958:   font-size: large;
1.597     albertel 5959: }
1.795     www      5960: 
1.597     albertel 5961: div.LC_grade_submissions_body,
1.936     bisitz   5962: div.LC_grade_message_center_body {
1.597     albertel 5963:   border: 1px solid black;
                   5964:   width: 99%;
                   5965:   background: #FFFFFF;
                   5966: }
1.795     www      5967: 
1.613     albertel 5968: table.LC_scantron_action {
                   5969:   width: 100%;
                   5970: }
1.795     www      5971: 
1.613     albertel 5972: table.LC_scantron_action tr th {
1.698     harmsja  5973:   font-weight:bold;
                   5974:   font-style:normal;
1.613     albertel 5975: }
1.795     www      5976: 
1.779     bisitz   5977: .LC_edit_problem_header,
1.614     albertel 5978: div.LC_edit_problem_footer {
1.705     tempelho 5979:   font-weight: normal;
                   5980:   font-size:  medium;
1.602     albertel 5981:   margin: 2px;
1.600     albertel 5982: }
1.795     www      5983: 
1.600     albertel 5984: div.LC_edit_problem_header,
1.602     albertel 5985: div.LC_edit_problem_header div,
1.614     albertel 5986: div.LC_edit_problem_footer,
                   5987: div.LC_edit_problem_footer div,
1.602     albertel 5988: div.LC_edit_problem_editxml_header,
                   5989: div.LC_edit_problem_editxml_header div {
1.600     albertel 5990:   margin-top: 5px;
                   5991: }
1.795     www      5992: 
1.600     albertel 5993: div.LC_edit_problem_header_title {
1.705     tempelho 5994:   font-weight: bold;
                   5995:   font-size: larger;
1.602     albertel 5996:   background: $tabbg;
                   5997:   padding: 3px;
                   5998: }
1.795     www      5999: 
1.602     albertel 6000: table.LC_edit_problem_header_title {
                   6001:   width: 100%;
1.600     albertel 6002:   background: $tabbg;
1.602     albertel 6003: }
                   6004: 
                   6005: div.LC_edit_problem_discards {
                   6006:   float: left;
                   6007:   padding-bottom: 5px;
                   6008: }
1.795     www      6009: 
1.602     albertel 6010: div.LC_edit_problem_saves {
                   6011:   float: right;
                   6012:   padding-bottom: 5px;
1.600     albertel 6013: }
1.795     www      6014: 
1.911     bisitz   6015: img.stift {
1.803     bisitz   6016:   border-width: 0;
                   6017:   vertical-align: middle;
1.677     riegler  6018: }
1.680     riegler  6019: 
1.923     bisitz   6020: table td.LC_mainmenu_col_fieldset {
1.680     riegler  6021:   vertical-align: top;
1.777     tempelho 6022: }
1.795     www      6023: 
1.716     raeburn  6024: div.LC_createcourse {
1.911     bisitz   6025:   margin: 10px 10px 10px 10px;
1.716     raeburn  6026: }
                   6027: 
1.917     raeburn  6028: .LC_dccid {
                   6029:   margin: 0.2em 0 0 0;
                   6030:   padding: 0;
                   6031:   font-size: 90%;
                   6032:   display:none;
                   6033: }
                   6034: 
1.698     harmsja  6035: a:hover,
1.897     wenzelju 6036: ol.LC_primary_menu a:hover,
1.721     harmsja  6037: ol#LC_MenuBreadcrumbs a:hover,
                   6038: ol#LC_PathBreadcrumbs a:hover,
1.897     wenzelju 6039: ul#LC_secondary_menu a:hover,
1.721     harmsja  6040: .LC_FormSectionClearButton input:hover
1.795     www      6041: ul.LC_TabContent   li:hover a {
1.948.2.1  raeburn  6042:   color:$button_hover;
1.911     bisitz   6043:   text-decoration:none;
1.693     droeschl 6044: }
                   6045: 
1.779     bisitz   6046: h1 {
1.911     bisitz   6047:   padding: 0;
                   6048:   line-height:130%;
1.693     droeschl 6049: }
1.698     harmsja  6050: 
1.911     bisitz   6051: h2,
                   6052: h3,
                   6053: h4,
                   6054: h5,
                   6055: h6 {
                   6056:   margin: 5px 0 5px 0;
                   6057:   padding: 0;
                   6058:   line-height:130%;
1.693     droeschl 6059: }
1.795     www      6060: 
                   6061: .LC_hcell {
1.911     bisitz   6062:   padding:3px 15px 3px 15px;
                   6063:   margin: 0;
                   6064:   background-color:$tabbg;
                   6065:   color:$fontmenu;
                   6066:   border-bottom:solid 1px $lg_border_color;
1.693     droeschl 6067: }
1.795     www      6068: 
1.840     bisitz   6069: .LC_Box > .LC_hcell {
1.911     bisitz   6070:   margin: 0 -10px 10px -10px;
1.835     bisitz   6071: }
                   6072: 
1.721     harmsja  6073: .LC_noBorder {
1.911     bisitz   6074:   border: 0;
1.698     harmsja  6075: }
1.693     droeschl 6076: 
1.721     harmsja  6077: .LC_FormSectionClearButton input {
1.911     bisitz   6078:   background-color:transparent;
                   6079:   border: none;
                   6080:   cursor:pointer;
                   6081:   text-decoration:underline;
1.693     droeschl 6082: }
1.763     bisitz   6083: 
                   6084: .LC_help_open_topic {
1.911     bisitz   6085:   color: #FFFFFF;
                   6086:   background-color: #EEEEFF;
                   6087:   margin: 1px;
                   6088:   padding: 4px;
                   6089:   border: 1px solid #000033;
                   6090:   white-space: nowrap;
                   6091:   /* vertical-align: middle; */
1.759     neumanie 6092: }
1.693     droeschl 6093: 
1.911     bisitz   6094: dl,
                   6095: ul,
                   6096: div,
                   6097: fieldset {
                   6098:   margin: 10px 10px 10px 0;
                   6099:   /* overflow: hidden; */
1.693     droeschl 6100: }
1.795     www      6101: 
1.838     bisitz   6102: fieldset > legend {
1.911     bisitz   6103:   font-weight: bold;
                   6104:   padding: 0 5px 0 5px;
1.838     bisitz   6105: }
                   6106: 
1.813     bisitz   6107: #LC_nav_bar {
1.911     bisitz   6108:   float: left;
1.948.2.6  raeburn  6109:   margin: 0 0 2px 0;
1.807     droeschl 6110: }
                   6111: 
1.916     droeschl 6112: #LC_realm {
                   6113:   margin: 0.2em 0 0 0;
                   6114:   padding: 0;
                   6115:   font-weight: bold;
                   6116:   text-align: center;
                   6117: }
                   6118: 
1.911     bisitz   6119: #LC_nav_bar em {
                   6120:   font-weight: bold;
                   6121:   font-style: normal;
1.807     droeschl 6122: }
                   6123: 
1.948.2.6  raeburn  6124: /* Preliminary fix to hide nav_bar inside bookmarks window */
                   6125: #LC_bookmarks #LC_nav_bar {
                   6126:   display:none;
                   6127: }
                   6128: 
1.897     wenzelju 6129: ol.LC_primary_menu {
1.911     bisitz   6130:   float: right;
1.934     droeschl 6131:   margin: 0;
1.807     droeschl 6132: }
                   6133: 
1.929     wenzelju 6134: span.LC_new_message{
                   6135:   font-weight:bold;
                   6136:   color: darkred;
                   6137: }
                   6138: 
1.852     droeschl 6139: ol#LC_PathBreadcrumbs {
1.911     bisitz   6140:   margin: 0;
1.693     droeschl 6141: }
                   6142: 
1.897     wenzelju 6143: ol.LC_primary_menu li {
1.911     bisitz   6144:   display: inline;
                   6145:   padding: 5px 5px 0 10px;
                   6146:   vertical-align: top;
1.693     droeschl 6147: }
                   6148: 
1.897     wenzelju 6149: ol.LC_primary_menu li img {
1.911     bisitz   6150:   vertical-align: bottom;
1.934     droeschl 6151:   height: 1.1em;
1.693     droeschl 6152: }
                   6153: 
1.897     wenzelju 6154: ol.LC_primary_menu a {
1.911     bisitz   6155:   color: RGB(80, 80, 80);
                   6156:   text-decoration: none;
1.693     droeschl 6157: }
1.795     www      6158: 
1.948.2.7! raeburn  6159: ol.LC_docs_parameters {
        !          6160:   margin-left: 0;
        !          6161:   padding: 0;
        !          6162:   list-style: none;
        !          6163: }
        !          6164: 
        !          6165: ol.LC_docs_parameters li {
        !          6166:   margin: 0;
        !          6167:   padding-right: 20px;
        !          6168:   display: inline;
        !          6169: }
        !          6170: 
        !          6171: ol.LC_docs_parameters li:before {
        !          6172:   content: "\\002022 \\0020";
        !          6173: }
        !          6174: 
        !          6175: li.LC_docs_parameters_title {
        !          6176:   font-weight: bold;
        !          6177: }
        !          6178: 
        !          6179: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
        !          6180:   content: "";
        !          6181: }
        !          6182: 
1.897     wenzelju 6183: ul#LC_secondary_menu {
1.911     bisitz   6184:   clear: both;
                   6185:   color: $fontmenu;
                   6186:   background: $tabbg;
                   6187:   list-style: none;
                   6188:   padding: 0;
                   6189:   margin: 0;
                   6190:   width: 100%;
1.808     droeschl 6191: }
                   6192: 
1.897     wenzelju 6193: ul#LC_secondary_menu li {
1.911     bisitz   6194:   font-weight: bold;
                   6195:   line-height: 1.8em;
                   6196:   padding: 0 0.8em;
                   6197:   border-right: 1px solid black;
                   6198:   display: inline;
                   6199:   vertical-align: middle;
1.807     droeschl 6200: }
                   6201: 
1.847     tempelho 6202: ul.LC_TabContent {
1.911     bisitz   6203:   display:block;
                   6204:   background: $sidebg;
                   6205:   border-bottom: solid 1px $lg_border_color;
                   6206:   list-style:none;
                   6207:   margin: 0 -10px;
                   6208:   padding: 0;
1.693     droeschl 6209: }
                   6210: 
1.795     www      6211: ul.LC_TabContent li,
                   6212: ul.LC_TabContentBigger li {
1.911     bisitz   6213:   float:left;
1.741     harmsja  6214: }
1.795     www      6215: 
1.897     wenzelju 6216: ul#LC_secondary_menu li a {
1.911     bisitz   6217:   color: $fontmenu;
                   6218:   text-decoration: none;
1.693     droeschl 6219: }
1.795     www      6220: 
1.721     harmsja  6221: ul.LC_TabContent {
1.948.2.1  raeburn  6222:   min-height:20px;
1.721     harmsja  6223: }
1.795     www      6224: 
                   6225: ul.LC_TabContent li {
1.911     bisitz   6226:   vertical-align:middle;
1.948.2.3  raeburn  6227:   padding: 0 16px 0 10px;
1.911     bisitz   6228:   background-color:$tabbg;
                   6229:   border-bottom:solid 1px $lg_border_color;
1.948.2.1  raeburn  6230:   border-right: solid 1px $font;
1.721     harmsja  6231: }
1.795     www      6232: 
1.847     tempelho 6233: ul.LC_TabContent .right {
1.911     bisitz   6234:   float:right;
1.847     tempelho 6235: }
                   6236: 
1.911     bisitz   6237: ul.LC_TabContent li a,
                   6238: ul.LC_TabContent li {
                   6239:   color:rgb(47,47,47);
                   6240:   text-decoration:none;
                   6241:   font-size:95%;
                   6242:   font-weight:bold;
1.948.2.1  raeburn  6243:   min-height:20px;
                   6244: }
                   6245: 
1.948.2.3  raeburn  6246: ul.LC_TabContent li a:hover,
                   6247: ul.LC_TabContent li a:focus {
1.948.2.1  raeburn  6248:   color: $button_hover;
1.948.2.3  raeburn  6249:   background:none;
                   6250:   outline:none;
1.948.2.1  raeburn  6251: }
                   6252: 
                   6253: ul.LC_TabContent li:hover {
                   6254:   color: $button_hover;
                   6255:   cursor:pointer;
1.721     harmsja  6256: }
1.795     www      6257: 
1.911     bisitz   6258: ul.LC_TabContent li.active {
1.948.2.1  raeburn  6259:   color: $font;
1.911     bisitz   6260:   background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.948.2.1  raeburn  6261:   border-bottom:solid 1px #FFFFFF;
                   6262:   cursor: default;
1.744     ehlerst  6263: }
1.795     www      6264: 
1.948.2.3  raeburn  6265: ul.LC_TabContent li.active a {
                   6266:   color:$font;
                   6267:   background:#FFFFFF;
                   6268:   outline: none;
                   6269: }
1.870     tempelho 6270: #maincoursedoc {
1.911     bisitz   6271:   clear:both;
1.870     tempelho 6272: }
                   6273: 
                   6274: ul.LC_TabContentBigger {
1.911     bisitz   6275:   display:block;
                   6276:   list-style:none;
                   6277:   padding: 0;
1.870     tempelho 6278: }
                   6279: 
1.795     www      6280: ul.LC_TabContentBigger li {
1.911     bisitz   6281:   vertical-align:bottom;
                   6282:   height: 30px;
                   6283:   font-size:110%;
                   6284:   font-weight:bold;
                   6285:   color: #737373;
1.841     tempelho 6286: }
                   6287: 
1.948.2.3  raeburn  6288: ul.LC_TabContentBigger li.active {
                   6289:   position: relative;
                   6290:   top: 1px;
                   6291: }
1.870     tempelho 6292: 
                   6293: ul.LC_TabContentBigger li a {
1.911     bisitz   6294:   background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
                   6295:   height: 30px;
                   6296:   line-height: 30px;
                   6297:   text-align: center;
                   6298:   display: block;
                   6299:   text-decoration: none;
1.948.2.3  raeburn  6300:   outline: none;
1.741     harmsja  6301: }
1.795     www      6302: 
1.870     tempelho 6303: ul.LC_TabContentBigger li.active a {
1.911     bisitz   6304:   background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
                   6305:   color:$font;
1.744     ehlerst  6306: }
1.795     www      6307: 
1.870     tempelho 6308: ul.LC_TabContentBigger li b {
1.911     bisitz   6309:   background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
                   6310:   display: block;
                   6311:   float: left;
                   6312:   padding: 0 30px;
1.948.2.3  raeburn  6313:   border-bottom: 1px solid $lg_border_color;
                   6314: }
                   6315: 
                   6316: ul.LC_TabContentBigger li:hover b {
                   6317:   color:$button_hover;
1.870     tempelho 6318: }
                   6319: 
                   6320: ul.LC_TabContentBigger li.active b {
1.911     bisitz   6321:   background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
                   6322:   color:$font;
1.948.2.3  raeburn  6323:   border: 0;
                   6324:   cursor:default;
1.741     harmsja  6325: }
1.693     droeschl 6326: 
1.862     bisitz   6327: ul.LC_CourseBreadcrumbs {
                   6328:   background: $sidebg;
                   6329:   line-height: 32px;
                   6330:   padding-left: 10px;
                   6331:   margin: 0 0 10px 0;
                   6332:   list-style-position: inside;
                   6333: 
                   6334: }
                   6335: 
1.911     bisitz   6336: ol#LC_MenuBreadcrumbs,
1.862     bisitz   6337: ol#LC_PathBreadcrumbs {
1.911     bisitz   6338:   padding-left: 10px;
                   6339:   margin: 0;
1.933     droeschl 6340:   height: 2.5em;  /* equal to #LC_breadcrumbs line-height */
1.693     droeschl 6341: }
                   6342: 
1.911     bisitz   6343: ol#LC_MenuBreadcrumbs li,
                   6344: ol#LC_PathBreadcrumbs li,
1.862     bisitz   6345: ul.LC_CourseBreadcrumbs li {
1.911     bisitz   6346:   display: inline;
1.933     droeschl 6347:   white-space: normal;  
1.693     droeschl 6348: }
                   6349: 
1.823     bisitz   6350: ol#LC_MenuBreadcrumbs li a,
1.862     bisitz   6351: ul.LC_CourseBreadcrumbs li a {
1.911     bisitz   6352:   text-decoration: none;
                   6353:   font-size:90%;
1.693     droeschl 6354: }
1.795     www      6355: 
1.948.2.7! raeburn  6356: ol#LC_MenuBreadcrumbs h1 {
        !          6357:   display: inline;
        !          6358:   font-size: 90%;
        !          6359:   line-height: 2.5em;
        !          6360:   margin: 0;
        !          6361:   padding: 0;
        !          6362: }
        !          6363: 
1.795     www      6364: ol#LC_PathBreadcrumbs li a {
1.911     bisitz   6365:   text-decoration:none;
                   6366:   font-size:100%;
                   6367:   font-weight:bold;
1.693     droeschl 6368: }
1.795     www      6369: 
1.840     bisitz   6370: .LC_Box {
1.911     bisitz   6371:   border: solid 1px $lg_border_color;
                   6372:   padding: 0 10px 10px 10px;
1.746     neumanie 6373: }
1.795     www      6374: 
                   6375: .LC_AboutMe_Image {
1.911     bisitz   6376:   float:left;
                   6377:   margin-right:10px;
1.747     neumanie 6378: }
1.795     www      6379: 
                   6380: .LC_Clear_AboutMe_Image {
1.911     bisitz   6381:   clear:left;
1.747     neumanie 6382: }
1.795     www      6383: 
1.721     harmsja  6384: dl.LC_ListStyleClean dt {
1.911     bisitz   6385:   padding-right: 5px;
                   6386:   display: table-header-group;
1.693     droeschl 6387: }
                   6388: 
1.721     harmsja  6389: dl.LC_ListStyleClean dd {
1.911     bisitz   6390:   display: table-row;
1.693     droeschl 6391: }
                   6392: 
1.721     harmsja  6393: .LC_ListStyleClean,
                   6394: .LC_ListStyleSimple,
                   6395: .LC_ListStyleNormal,
1.795     www      6396: .LC_ListStyleSpecial {
1.911     bisitz   6397:   /* display:block; */
                   6398:   list-style-position: inside;
                   6399:   list-style-type: none;
                   6400:   overflow: hidden;
                   6401:   padding: 0;
1.693     droeschl 6402: }
                   6403: 
1.721     harmsja  6404: .LC_ListStyleSimple li,
                   6405: .LC_ListStyleSimple dd,
                   6406: .LC_ListStyleNormal li,
                   6407: .LC_ListStyleNormal dd,
                   6408: .LC_ListStyleSpecial li,
1.795     www      6409: .LC_ListStyleSpecial dd {
1.911     bisitz   6410:   margin: 0;
                   6411:   padding: 5px 5px 5px 10px;
                   6412:   clear: both;
1.693     droeschl 6413: }
                   6414: 
1.721     harmsja  6415: .LC_ListStyleClean li,
                   6416: .LC_ListStyleClean dd {
1.911     bisitz   6417:   padding-top: 0;
                   6418:   padding-bottom: 0;
1.693     droeschl 6419: }
                   6420: 
1.721     harmsja  6421: .LC_ListStyleSimple dd,
1.795     www      6422: .LC_ListStyleSimple li {
1.911     bisitz   6423:   border-bottom: solid 1px $lg_border_color;
1.693     droeschl 6424: }
                   6425: 
1.721     harmsja  6426: .LC_ListStyleSpecial li,
                   6427: .LC_ListStyleSpecial dd {
1.911     bisitz   6428:   list-style-type: none;
                   6429:   background-color: RGB(220, 220, 220);
                   6430:   margin-bottom: 4px;
1.693     droeschl 6431: }
                   6432: 
1.721     harmsja  6433: table.LC_SimpleTable {
1.911     bisitz   6434:   margin:5px;
                   6435:   border:solid 1px $lg_border_color;
1.795     www      6436: }
1.693     droeschl 6437: 
1.721     harmsja  6438: table.LC_SimpleTable tr {
1.911     bisitz   6439:   padding: 0;
                   6440:   border:solid 1px $lg_border_color;
1.693     droeschl 6441: }
1.795     www      6442: 
                   6443: table.LC_SimpleTable thead {
1.911     bisitz   6444:   background:rgb(220,220,220);
1.693     droeschl 6445: }
                   6446: 
1.721     harmsja  6447: div.LC_columnSection {
1.911     bisitz   6448:   display: block;
                   6449:   clear: both;
                   6450:   overflow: hidden;
                   6451:   margin: 0;
1.693     droeschl 6452: }
                   6453: 
1.721     harmsja  6454: div.LC_columnSection>* {
1.911     bisitz   6455:   float: left;
                   6456:   margin: 10px 20px 10px 0;
                   6457:   overflow:hidden;
1.693     droeschl 6458: }
1.721     harmsja  6459: 
1.795     www      6460: table em {
1.911     bisitz   6461:   font-weight: bold;
                   6462:   font-style: normal;
1.748     schulted 6463: }
1.795     www      6464: 
1.779     bisitz   6465: table.LC_tableBrowseRes,
1.795     www      6466: table.LC_tableOfContent {
1.911     bisitz   6467:   border:none;
                   6468:   border-spacing: 1px;
                   6469:   padding: 3px;
                   6470:   background-color: #FFFFFF;
                   6471:   font-size: 90%;
1.753     droeschl 6472: }
1.789     droeschl 6473: 
1.911     bisitz   6474: table.LC_tableOfContent {
                   6475:   border-collapse: collapse;
1.789     droeschl 6476: }
                   6477: 
1.771     droeschl 6478: table.LC_tableBrowseRes a,
1.768     schulted 6479: table.LC_tableOfContent a {
1.911     bisitz   6480:   background-color: transparent;
                   6481:   text-decoration: none;
1.753     droeschl 6482: }
                   6483: 
1.795     www      6484: table.LC_tableOfContent img {
1.911     bisitz   6485:   border: none;
                   6486:   height: 1.3em;
                   6487:   vertical-align: text-bottom;
                   6488:   margin-right: 0.3em;
1.753     droeschl 6489: }
1.757     schulted 6490: 
1.795     www      6491: a#LC_content_toolbar_firsthomework {
1.911     bisitz   6492:   background-image:url(/res/adm/pages/open-first-problem.gif);
1.774     ehlerst  6493: }
                   6494: 
1.795     www      6495: a#LC_content_toolbar_launchnav {
1.911     bisitz   6496:   background-image:url(/res/adm/pages/start-navigation.gif);
1.774     ehlerst  6497: }
                   6498: 
1.795     www      6499: a#LC_content_toolbar_closenav {
1.911     bisitz   6500:   background-image:url(/res/adm/pages/close-navigation.gif);
1.774     ehlerst  6501: }
                   6502: 
1.795     www      6503: a#LC_content_toolbar_everything {
1.911     bisitz   6504:   background-image:url(/res/adm/pages/show-all.gif);
1.774     ehlerst  6505: }
                   6506: 
1.795     www      6507: a#LC_content_toolbar_uncompleted {
1.911     bisitz   6508:   background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774     ehlerst  6509: }
                   6510: 
1.795     www      6511: #LC_content_toolbar_clearbubbles {
1.911     bisitz   6512:   background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774     ehlerst  6513: }
                   6514: 
1.795     www      6515: a#LC_content_toolbar_changefolder {
1.911     bisitz   6516:   background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757     schulted 6517: }
                   6518: 
1.795     www      6519: a#LC_content_toolbar_changefolder_toggled {
1.911     bisitz   6520:   background-image:url(/res/adm/pages/open-all-folders.gif);
1.757     schulted 6521: }
                   6522: 
1.795     www      6523: ul#LC_toolbar li a:hover {
1.911     bisitz   6524:   background-position: bottom center;
1.757     schulted 6525: }
                   6526: 
1.795     www      6527: ul#LC_toolbar {
1.911     bisitz   6528:   padding: 0;
                   6529:   margin: 2px;
                   6530:   list-style:none;
                   6531:   position:relative;
                   6532:   background-color:white;
1.757     schulted 6533: }
                   6534: 
1.795     www      6535: ul#LC_toolbar li {
1.911     bisitz   6536:   border:1px solid white;
                   6537:   padding: 0;
                   6538:   margin: 0;
                   6539:   float: left;
                   6540:   display:inline;
                   6541:   vertical-align:middle;
                   6542: }
1.757     schulted 6543: 
1.783     amueller 6544: 
1.795     www      6545: a.LC_toolbarItem {
1.911     bisitz   6546:   display:block;
                   6547:   padding: 0;
                   6548:   margin: 0;
                   6549:   height: 32px;
                   6550:   width: 32px;
                   6551:   color:white;
                   6552:   border: none;
                   6553:   background-repeat:no-repeat;
                   6554:   background-color:transparent;
1.757     schulted 6555: }
                   6556: 
1.915     droeschl 6557: ul.LC_funclist {
                   6558:     margin: 0;
                   6559:     padding: 0.5em 1em 0.5em 0;
                   6560: }
                   6561: 
1.933     droeschl 6562: ul.LC_funclist > li:first-child {
                   6563:     font-weight:bold; 
                   6564:     margin-left:0.8em;
                   6565: }
                   6566: 
1.915     droeschl 6567: ul.LC_funclist + ul.LC_funclist {
                   6568:     /* 
                   6569:        left border as a seperator if we have more than
                   6570:        one list 
                   6571:     */
                   6572:     border-left: 1px solid $sidebg;
                   6573:     /* 
                   6574:        this hides the left border behind the border of the 
                   6575:        outer box if element is wrapped to the next 'line' 
                   6576:     */
                   6577:     margin-left: -1px;
                   6578: }
                   6579: 
1.843     bisitz   6580: ul.LC_funclist li {
1.915     droeschl 6581:   display: inline;
1.782     bisitz   6582:   white-space: nowrap;
1.915     droeschl 6583:   margin: 0 0 0 25px;
                   6584:   line-height: 150%;
1.782     bisitz   6585: }
                   6586: 
1.930     faziophi 6587: .ui-accordion .LC_advanced_toggle {
                   6588:   float: right;
                   6589:   font-size: 90%;
                   6590:   padding: 0px 4px
                   6591: }
1.757     schulted 6592: 
1.343     albertel 6593: END
                   6594: }
                   6595: 
1.306     albertel 6596: =pod
                   6597: 
                   6598: =item * &headtag()
                   6599: 
                   6600: Returns a uniform footer for LON-CAPA web pages.
                   6601: 
1.307     albertel 6602: Inputs: $title - optional title for the head
                   6603:         $head_extra - optional extra HTML to put inside the <head>
1.315     albertel 6604:         $args - optional arguments
1.319     albertel 6605:             force_register - if is true call registerurl so the remote is 
                   6606:                              informed
1.415     albertel 6607:             redirect       -> array ref of
                   6608:                                    1- seconds before redirect occurs
                   6609:                                    2- url to redirect to
                   6610:                                    3- whether the side effect should occur
1.315     albertel 6611:                            (side effect of setting 
                   6612:                                $env{'internal.head.redirect'} to the url 
                   6613:                                redirected too)
1.352     albertel 6614:             domain         -> force to color decorate a page for a specific
                   6615:                                domain
                   6616:             function       -> force usage of a specific rolish color scheme
                   6617:             bgcolor        -> override the default page bgcolor
1.460     albertel 6618:             no_auto_mt_title
                   6619:                            -> prevent &mt()ing the title arg
1.464     albertel 6620: 
1.306     albertel 6621: =cut
                   6622: 
                   6623: sub headtag {
1.313     albertel 6624:     my ($title,$head_extra,$args) = @_;
1.306     albertel 6625:     
1.363     albertel 6626:     my $function = $args->{'function'} || &get_users_function();
                   6627:     my $domain   = $args->{'domain'}   || &determinedomain();
                   6628:     my $bgcolor  = $args->{'bgcolor'}  || &designparm($function.'.pgbg',$domain);
1.418     albertel 6629:     my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458     albertel 6630: 		   $Apache::lonnet::perlvar{'lonVersion'},
1.531     albertel 6631: 		   #time(),
1.418     albertel 6632: 		   $env{'environment.color.timestamp'},
1.363     albertel 6633: 		   $function,$domain,$bgcolor);
                   6634: 
1.369     www      6635:     $url = '/adm/css/'.&escape($url).'.css';
1.363     albertel 6636: 
1.308     albertel 6637:     my $result =
                   6638: 	'<head>'.
1.461     albertel 6639: 	&font_settings();
1.319     albertel 6640: 
1.461     albertel 6641:     if (!$args->{'frameset'}) {
                   6642: 	$result .= &Apache::lonhtmlcommon::htmlareaheaders();
                   6643:     }
1.319     albertel 6644:     if ($args->{'force_register'}) {
                   6645: 	$result .= &Apache::lonmenu::registerurl(1);
                   6646:     }
1.436     albertel 6647:     if (!$args->{'no_nav_bar'} 
                   6648: 	&& !$args->{'only_body'}
                   6649: 	&& !$args->{'frameset'}) {
                   6650: 	$result .= &help_menu_js();
                   6651:     }
1.319     albertel 6652: 
1.314     albertel 6653:     if (ref($args->{'redirect'})) {
1.414     albertel 6654: 	my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315     albertel 6655: 	$url = &Apache::lonenc::check_encrypt($url);
1.414     albertel 6656: 	if (!$inhibit_continue) {
                   6657: 	    $env{'internal.head.redirect'} = $url;
                   6658: 	}
1.313     albertel 6659: 	$result.=<<ADDMETA
                   6660: <meta http-equiv="pragma" content="no-cache" />
1.344     albertel 6661: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313     albertel 6662: ADDMETA
                   6663:     }
1.306     albertel 6664:     if (!defined($title)) {
                   6665: 	$title = 'The LearningOnline Network with CAPA';
                   6666:     }
1.460     albertel 6667:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
                   6668:     $result .= '<title> LON-CAPA '.$title.'</title>'
1.414     albertel 6669: 	.'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
                   6670: 	.$head_extra;
1.306     albertel 6671:     return $result;
                   6672: }
                   6673: 
                   6674: =pod
                   6675: 
1.340     albertel 6676: =item * &font_settings()
                   6677: 
                   6678: Returns neccessary <meta> to set the proper encoding
                   6679: 
                   6680: Inputs: none
                   6681: 
                   6682: =cut
                   6683: 
                   6684: sub font_settings {
                   6685:     my $headerstring='';
1.647     www      6686:     if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340     albertel 6687: 	$headerstring.=
                   6688: 	    '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
                   6689:     }
                   6690:     return $headerstring;
                   6691: }
                   6692: 
1.341     albertel 6693: =pod
                   6694: 
                   6695: =item * &xml_begin()
                   6696: 
                   6697: Returns the needed doctype and <html>
                   6698: 
                   6699: Inputs: none
                   6700: 
                   6701: =cut
                   6702: 
                   6703: sub xml_begin {
                   6704:     my $output='';
                   6705: 
                   6706:     if ($env{'browser.mathml'}) {
                   6707: 	$output='<?xml version="1.0"?>'
                   6708:             #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
                   6709: #            .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
                   6710:             
                   6711: #	    .'<!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">] >'
                   6712: 	    .'<!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">'
                   6713:             .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" ' 
                   6714: 	    .'xmlns="http://www.w3.org/1999/xhtml">';
                   6715:     } else {
1.849     bisitz   6716: 	$output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
                   6717:            .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1.341     albertel 6718:     }
                   6719:     return $output;
                   6720: }
1.340     albertel 6721: 
                   6722: =pod
                   6723: 
1.306     albertel 6724: =item * &endheadtag()
                   6725: 
                   6726: Returns a uniform </head> for LON-CAPA web pages.
                   6727: 
                   6728: Inputs: none
                   6729: 
                   6730: =cut
                   6731: 
                   6732: sub endheadtag {
                   6733:     return '</head>';
                   6734: }
                   6735: 
                   6736: =pod
                   6737: 
                   6738: =item * &head()
                   6739: 
                   6740: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
                   6741: 
1.648     raeburn  6742: Inputs:
                   6743: 
                   6744: =over 4
                   6745: 
                   6746: $title - optional title for the page
                   6747: 
                   6748: $head_extra - optional extra HTML to put inside the <head>
                   6749: 
                   6750: =back
1.405     albertel 6751: 
1.306     albertel 6752: =cut
                   6753: 
                   6754: sub head {
1.325     albertel 6755:     my ($title,$head_extra,$args) = @_;
                   6756:     return &headtag($title,$head_extra,$args).&endheadtag();
1.306     albertel 6757: }
                   6758: 
                   6759: =pod
                   6760: 
                   6761: =item * &start_page()
                   6762: 
                   6763: Returns a complete <html> .. <body> section for LON-CAPA web pages.
                   6764: 
1.648     raeburn  6765: Inputs:
                   6766: 
                   6767: =over 4
                   6768: 
                   6769: $title - optional title for the page
                   6770: 
                   6771: $head_extra - optional extra HTML to incude inside the <head>
                   6772: 
                   6773: $args - additional optional args supported are:
                   6774: 
                   6775: =over 8
                   6776: 
                   6777:              only_body      -> is true will set &bodytag() onlybodytag
1.317     albertel 6778:                                     arg on
1.814     bisitz   6779:              no_nav_bar     -> is true will set &bodytag() no_nav_bar arg on
1.648     raeburn  6780:              add_entries    -> additional attributes to add to the  <body>
                   6781:              domain         -> force to color decorate a page for a 
1.317     albertel 6782:                                     specific domain
1.648     raeburn  6783:              function       -> force usage of a specific rolish color
1.317     albertel 6784:                                     scheme
1.648     raeburn  6785:              redirect       -> see &headtag()
                   6786:              bgcolor        -> override the default page bg color
                   6787:              js_ready       -> return a string ready for being used in 
1.317     albertel 6788:                                     a javascript writeln
1.648     raeburn  6789:              html_encode    -> return a string ready for being used in 
1.320     albertel 6790:                                     a html attribute
1.648     raeburn  6791:              force_register -> if is true will turn on the &bodytag()
1.317     albertel 6792:                                     $forcereg arg
1.648     raeburn  6793:              frameset       -> if true will start with a <frameset>
1.330     albertel 6794:                                     rather than <body>
1.648     raeburn  6795:              skip_phases    -> hash ref of 
1.338     albertel 6796:                                     head -> skip the <html><head> generation
                   6797:                                     body -> skip all <body> generation
1.648     raeburn  6798:              no_inline_link -> if true and in remote mode, don't show the 
1.361     albertel 6799:                                     'Switch To Inline Menu' link
1.648     raeburn  6800:              no_auto_mt_title -> prevent &mt()ing the title arg
                   6801:              inherit_jsmath -> when creating popup window in a page,
                   6802:                                     should it have jsmath forced on by the
                   6803:                                     current page
1.867     kalberla 6804:              bread_crumbs ->             Array containing breadcrumbs
                   6805:              bread_crumbs_components ->  if exists show it as headline else show only the breadcrumbs
1.361     albertel 6806: 
1.648     raeburn  6807: =back
1.460     albertel 6808: 
1.648     raeburn  6809: =back
1.562     albertel 6810: 
1.306     albertel 6811: =cut
                   6812: 
                   6813: sub start_page {
1.309     albertel 6814:     my ($title,$head_extra,$args) = @_;
1.318     albertel 6815:     #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313     albertel 6816:     my %head_args;
1.352     albertel 6817:     foreach my $arg ('redirect','force_register','domain','function',
1.460     albertel 6818: 		     'bgcolor','frameset','no_nav_bar','only_body',
                   6819: 		     'no_auto_mt_title') {
1.319     albertel 6820: 	if (defined($args->{$arg})) {
1.324     raeburn  6821: 	    $head_args{$arg} = $args->{$arg};
1.319     albertel 6822: 	}
1.313     albertel 6823:     }
1.319     albertel 6824: 
1.315     albertel 6825:     $env{'internal.start_page'}++;
1.338     albertel 6826:     my $result;
                   6827:     if (! exists($args->{'skip_phases'}{'head'}) ) {
                   6828: 	$result.=
1.341     albertel 6829: 	    &xml_begin().
1.338     albertel 6830: 	    &headtag($title,$head_extra,\%head_args).&endheadtag();
                   6831:     }
                   6832:     
                   6833:     if (! exists($args->{'skip_phases'}{'body'}) ) {
                   6834: 	if ($args->{'frameset'}) {
                   6835: 	    my $attr_string = &make_attr_string($args->{'force_register'},
                   6836: 						$args->{'add_entries'});
                   6837: 	    $result .= "\n<frameset $attr_string>\n";
1.831     bisitz   6838:         } else {
                   6839:             $result .=
                   6840:                 &bodytag($title, 
                   6841:                          $args->{'function'},       $args->{'add_entries'},
                   6842:                          $args->{'only_body'},      $args->{'domain'},
                   6843:                          $args->{'force_register'}, $args->{'no_nav_bar'},
                   6844:                          $args->{'bgcolor'},        $args->{'no_inline_link'},
                   6845:                          $args);
                   6846:         }
1.330     albertel 6847:     }
1.338     albertel 6848: 
1.315     albertel 6849:     if ($args->{'js_ready'}) {
1.713     kaisler  6850: 		$result = &js_ready($result);
1.315     albertel 6851:     }
1.320     albertel 6852:     if ($args->{'html_encode'}) {
1.713     kaisler  6853: 		$result = &html_encode($result);
                   6854:     }
                   6855: 
1.813     bisitz   6856:     # Preparation for new and consistent functionlist at top of screen
                   6857:     # if ($args->{'functionlist'}) {
                   6858:     #            $result .= &build_functionlist();
                   6859:     #}
                   6860: 
                   6861:     # Don't add anything more if only_body wanted
                   6862:     return $result if $args->{'only_body'};
                   6863: 
1.920     raeburn  6864:     #Breadcrumbs for Construction Space provided by &bodytag. 
                   6865:     if (($env{'environment.remote'} eq 'off') && ($env{'request.state'} eq 'construct')) {
                   6866:         return $result;
                   6867:     }
                   6868:  
1.813     bisitz   6869:     #Breadcrumbs
1.758     kaisler  6870:     if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
                   6871: 		&Apache::lonhtmlcommon::clear_breadcrumbs();
                   6872: 		#if any br links exists, add them to the breadcrumbs
                   6873: 		if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {         
                   6874: 			foreach my $crumb (@{$args->{'bread_crumbs'}}){
                   6875: 				&Apache::lonhtmlcommon::add_breadcrumb($crumb);
                   6876: 			}
                   6877: 		}
                   6878: 
                   6879: 		#if bread_crumbs_component exists show it as headline else show only the breadcrumbs
                   6880: 		if(exists($args->{'bread_crumbs_component'})){
                   6881: 			$result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
                   6882: 		}else{
                   6883: 			$result .= &Apache::lonhtmlcommon::breadcrumbs();
                   6884: 		}
1.320     albertel 6885:     }
1.315     albertel 6886:     return $result;
1.306     albertel 6887: }
                   6888: 
1.330     albertel 6889: 
1.306     albertel 6890: =pod
                   6891: 
                   6892: =item * &head()
                   6893: 
                   6894: Returns a complete </body></html> section for LON-CAPA web pages.
                   6895: 
1.315     albertel 6896: Inputs:         $args - additional optional args supported are:
                   6897:                  js_ready     -> return a string ready for being used in 
                   6898:                                  a javascript writeln
1.320     albertel 6899:                  html_encode  -> return a string ready for being used in 
                   6900:                                  a html attribute
1.330     albertel 6901:                  frameset     -> if true will start with a <frameset>
                   6902:                                  rather than <body>
1.493     albertel 6903:                  dicsussion   -> if true will get discussion from
                   6904:                                   lonxml::xmlend
                   6905:                                  (you can pass the target and parser arguments
                   6906:                                   through optional 'target' and 'parser' args
                   6907:                                   to this routine)
1.306     albertel 6908: 
                   6909: =cut
                   6910: 
                   6911: sub end_page {
1.315     albertel 6912:     my ($args) = @_;
                   6913:     $env{'internal.end_page'}++;
1.330     albertel 6914:     my $result;
1.335     albertel 6915:     if ($args->{'discussion'}) {
                   6916: 	my ($target,$parser);
                   6917: 	if (ref($args->{'discussion'})) {
                   6918: 	    ($target,$parser) =($args->{'discussion'}{'target'},
                   6919: 				$args->{'discussion'}{'parser'});
                   6920: 	}
                   6921: 	$result .= &Apache::lonxml::xmlend($target,$parser);
                   6922:     }
                   6923: 
1.330     albertel 6924:     if ($args->{'frameset'}) {
                   6925: 	$result .= '</frameset>';
                   6926:     } else {
1.635     raeburn  6927: 	$result .= &endbodytag($args);
1.330     albertel 6928:     }
                   6929:     $result .= "\n</html>";
                   6930: 
1.315     albertel 6931:     if ($args->{'js_ready'}) {
1.317     albertel 6932: 	$result = &js_ready($result);
1.315     albertel 6933:     }
1.335     albertel 6934: 
1.320     albertel 6935:     if ($args->{'html_encode'}) {
                   6936: 	$result = &html_encode($result);
                   6937:     }
1.335     albertel 6938: 
1.315     albertel 6939:     return $result;
                   6940: }
                   6941: 
1.320     albertel 6942: sub html_encode {
                   6943:     my ($result) = @_;
                   6944: 
1.322     albertel 6945:     $result = &HTML::Entities::encode($result,'<>&"');
1.320     albertel 6946:     
                   6947:     return $result;
                   6948: }
1.317     albertel 6949: sub js_ready {
                   6950:     my ($result) = @_;
                   6951: 
1.323     albertel 6952:     $result =~ s/[\n\r]/ /xmsg;
                   6953:     $result =~ s/\\/\\\\/xmsg;
                   6954:     $result =~ s/'/\\'/xmsg;
1.372     albertel 6955:     $result =~ s{</}{<\\/}xmsg;
1.317     albertel 6956:     
                   6957:     return $result;
                   6958: }
                   6959: 
1.315     albertel 6960: sub validate_page {
                   6961:     if (  exists($env{'internal.start_page'})
1.316     albertel 6962: 	  &&     $env{'internal.start_page'} > 1) {
                   6963: 	&Apache::lonnet::logthis('start_page called multiple times '.
1.318     albertel 6964: 				 $env{'internal.start_page'}.' '.
1.316     albertel 6965: 				 $ENV{'request.filename'});
1.315     albertel 6966:     }
                   6967:     if (  exists($env{'internal.end_page'})
1.316     albertel 6968: 	  &&     $env{'internal.end_page'} > 1) {
                   6969: 	&Apache::lonnet::logthis('end_page called multiple times '.
1.318     albertel 6970: 				 $env{'internal.end_page'}.' '.
1.316     albertel 6971: 				 $env{'request.filename'});
1.315     albertel 6972:     }
                   6973:     if (     exists($env{'internal.start_page'})
                   6974: 	&& ! exists($env{'internal.end_page'})) {
1.316     albertel 6975: 	&Apache::lonnet::logthis('start_page called without end_page '.
                   6976: 				 $env{'request.filename'});
1.315     albertel 6977:     }
                   6978:     if (   ! exists($env{'internal.start_page'})
                   6979: 	&&   exists($env{'internal.end_page'})) {
1.316     albertel 6980: 	&Apache::lonnet::logthis('end_page called without start_page'.
                   6981: 				 $env{'request.filename'});
1.315     albertel 6982:     }
1.306     albertel 6983: }
1.315     albertel 6984: 
1.318     albertel 6985: sub simple_error_page {
                   6986:     my ($r,$title,$msg) = @_;
                   6987:     my $page =
                   6988: 	&Apache::loncommon::start_page($title).
                   6989: 	&mt($msg).
                   6990: 	&Apache::loncommon::end_page();
                   6991:     if (ref($r)) {
                   6992: 	$r->print($page);
1.327     albertel 6993: 	return;
1.318     albertel 6994:     }
                   6995:     return $page;
                   6996: }
1.347     albertel 6997: 
                   6998: {
1.610     albertel 6999:     my @row_count;
1.948.2.5  raeburn  7000: 
                   7001:     sub start_data_table_count {
                   7002:         unshift(@row_count, 0);
                   7003:         return;
                   7004:     }
                   7005: 
                   7006:     sub end_data_table_count {
                   7007:         shift(@row_count);
                   7008:         return;
                   7009:     }
                   7010: 
1.347     albertel 7011:     sub start_data_table {
1.422     albertel 7012: 	my ($add_class) = @_;
                   7013: 	my $css_class = (join(' ','LC_data_table',$add_class));
1.948.2.5  raeburn  7014:         &start_data_table_count();
1.422     albertel 7015: 	return '<table class="'.$css_class.'">'."\n";
1.347     albertel 7016:     }
                   7017: 
                   7018:     sub end_data_table {
1.948.2.5  raeburn  7019:         &end_data_table_count();
1.389     albertel 7020: 	return '</table>'."\n";;
1.347     albertel 7021:     }
                   7022: 
                   7023:     sub start_data_table_row {
1.422     albertel 7024: 	my ($add_class) = @_;
1.610     albertel 7025: 	$row_count[0]++;
                   7026: 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900     bisitz   7027: 	$css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.422     albertel 7028: 	return  '<tr class="'.$css_class.'">'."\n";;
1.347     albertel 7029:     }
1.471     banghart 7030:     
                   7031:     sub continue_data_table_row {
                   7032: 	my ($add_class) = @_;
1.610     albertel 7033: 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900     bisitz   7034: 	$css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');;
1.471     banghart 7035: 	return  '<tr class="'.$css_class.'">'."\n";;
                   7036:     }
1.347     albertel 7037: 
                   7038:     sub end_data_table_row {
1.389     albertel 7039: 	return '</tr>'."\n";;
1.347     albertel 7040:     }
1.367     www      7041: 
1.421     albertel 7042:     sub start_data_table_empty_row {
1.707     bisitz   7043: #	$row_count[0]++;
1.421     albertel 7044: 	return  '<tr class="LC_empty_row" >'."\n";;
                   7045:     }
                   7046: 
                   7047:     sub end_data_table_empty_row {
                   7048: 	return '</tr>'."\n";;
                   7049:     }
                   7050: 
1.367     www      7051:     sub start_data_table_header_row {
1.389     albertel 7052: 	return  '<tr class="LC_header_row">'."\n";;
1.367     www      7053:     }
                   7054: 
                   7055:     sub end_data_table_header_row {
1.389     albertel 7056: 	return '</tr>'."\n";;
1.367     www      7057:     }
1.890     droeschl 7058: 
                   7059:     sub data_table_caption {
                   7060:         my $caption = shift;
                   7061:         return "<caption class=\"LC_caption\">$caption</caption>";
                   7062:     }
1.347     albertel 7063: }
                   7064: 
1.548     albertel 7065: =pod
                   7066: 
                   7067: =item * &inhibit_menu_check($arg)
                   7068: 
                   7069: Checks for a inhibitmenu state and generates output to preserve it
                   7070: 
                   7071: Inputs:         $arg - can be any of
                   7072:                      - undef - in which case the return value is a string 
                   7073:                                to add  into arguments list of a uri
                   7074:                      - 'input' - in which case the return value is a HTML
                   7075:                                  <form> <input> field of type hidden to
                   7076:                                  preserve the value
                   7077:                      - a url - in which case the return value is the url with
                   7078:                                the neccesary cgi args added to preserve the
                   7079:                                inhibitmenu state
                   7080:                      - a ref to a url - no return value, but the string is
                   7081:                                         updated to include the neccessary cgi
                   7082:                                         args to preserve the inhibitmenu state
                   7083: 
                   7084: =cut
                   7085: 
                   7086: sub inhibit_menu_check {
                   7087:     my ($arg) = @_;
                   7088:     &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
                   7089:     if ($arg eq 'input') {
                   7090: 	if ($env{'form.inhibitmenu'}) {
                   7091: 	    return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
                   7092: 	} else {
                   7093: 	    return
                   7094: 	}
                   7095:     }
                   7096:     if ($env{'form.inhibitmenu'}) {
                   7097: 	if (ref($arg)) {
                   7098: 	    $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
                   7099: 	} elsif ($arg eq '') {
                   7100: 	    $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
                   7101: 	} else {
                   7102: 	    $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
                   7103: 	}
                   7104:     }
                   7105:     if (!ref($arg)) {
                   7106: 	return $arg;
                   7107:     }
                   7108: }
                   7109: 
1.251     albertel 7110: ###############################################
1.182     matthew  7111: 
                   7112: =pod
                   7113: 
1.549     albertel 7114: =back
                   7115: 
                   7116: =head1 User Information Routines
                   7117: 
                   7118: =over 4
                   7119: 
1.405     albertel 7120: =item * &get_users_function()
1.182     matthew  7121: 
                   7122: Used by &bodytag to determine the current users primary role.
                   7123: Returns either 'student','coordinator','admin', or 'author'.
                   7124: 
                   7125: =cut
                   7126: 
                   7127: ###############################################
                   7128: sub get_users_function {
1.815     tempelho 7129:     my $function = 'norole';
1.818     tempelho 7130:     if ($env{'request.role'}=~/^(st)/) {
                   7131:         $function='student';
                   7132:     }
1.907     raeburn  7133:     if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182     matthew  7134:         $function='coordinator';
                   7135:     }
1.258     albertel 7136:     if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182     matthew  7137:         $function='admin';
                   7138:     }
1.826     bisitz   7139:     if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.182     matthew  7140:         ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
                   7141:         $function='author';
                   7142:     }
                   7143:     return $function;
1.54      www      7144: }
1.99      www      7145: 
                   7146: ###############################################
                   7147: 
1.233     raeburn  7148: =pod
                   7149: 
1.821     raeburn  7150: =item * &show_course()
                   7151: 
                   7152: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
                   7153: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
                   7154: 
                   7155: Inputs:
                   7156: None
                   7157: 
                   7158: Outputs:
                   7159: Scalar: 1 if 'Course' to be used, 0 otherwise.
                   7160: 
                   7161: =cut
                   7162: 
                   7163: ###############################################
                   7164: sub show_course {
                   7165:     my $course = !$env{'user.adv'};
                   7166:     if (!$env{'user.adv'}) {
                   7167:         foreach my $env (keys(%env)) {
                   7168:             next if ($env !~ m/^user\.priv\./);
                   7169:             if ($env !~ m/^user\.priv\.(?:st|cm)/) {
                   7170:                 $course = 0;
                   7171:                 last;
                   7172:             }
                   7173:         }
                   7174:     }
                   7175:     return $course;
                   7176: }
                   7177: 
                   7178: ###############################################
                   7179: 
                   7180: =pod
                   7181: 
1.542     raeburn  7182: =item * &check_user_status()
1.274     raeburn  7183: 
                   7184: Determines current status of supplied role for a
                   7185: specific user. Roles can be active, previous or future.
                   7186: 
                   7187: Inputs: 
                   7188: user's domain, user's username, course's domain,
1.375     raeburn  7189: course's number, optional section ID.
1.274     raeburn  7190: 
                   7191: Outputs:
                   7192: role status: active, previous or future. 
                   7193: 
                   7194: =cut
                   7195: 
                   7196: sub check_user_status {
1.412     raeburn  7197:     my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274     raeburn  7198:     my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
                   7199:     my @uroles = keys %userinfo;
                   7200:     my $srchstr;
                   7201:     my $active_chk = 'none';
1.412     raeburn  7202:     my $now = time;
1.274     raeburn  7203:     if (@uroles > 0) {
1.908     raeburn  7204:         if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274     raeburn  7205:             $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
                   7206:         } else {
1.412     raeburn  7207:             $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
                   7208:         }
                   7209:         if (grep/^\Q$srchstr\E$/,@uroles) {
1.274     raeburn  7210:             my $role_end = 0;
                   7211:             my $role_start = 0;
                   7212:             $active_chk = 'active';
1.412     raeburn  7213:             if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
                   7214:                 $role_end = $1;
                   7215:                 if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
                   7216:                     $role_start = $1;
1.274     raeburn  7217:                 }
                   7218:             }
                   7219:             if ($role_start > 0) {
1.412     raeburn  7220:                 if ($now < $role_start) {
1.274     raeburn  7221:                     $active_chk = 'future';
                   7222:                 }
                   7223:             }
                   7224:             if ($role_end > 0) {
1.412     raeburn  7225:                 if ($now > $role_end) {
1.274     raeburn  7226:                     $active_chk = 'previous';
                   7227:                 }
                   7228:             }
                   7229:         }
                   7230:     }
                   7231:     return $active_chk;
                   7232: }
                   7233: 
                   7234: ###############################################
                   7235: 
                   7236: =pod
                   7237: 
1.405     albertel 7238: =item * &get_sections()
1.233     raeburn  7239: 
                   7240: Determines all the sections for a course including
                   7241: sections with students and sections containing other roles.
1.419     raeburn  7242: Incoming parameters: 
                   7243: 
                   7244: 1. domain
                   7245: 2. course number 
                   7246: 3. reference to array containing roles for which sections should 
                   7247: be gathered (optional).
                   7248: 4. reference to array containing status types for which sections 
                   7249: should be gathered (optional).
                   7250: 
                   7251: If the third argument is undefined, sections are gathered for any role. 
                   7252: If the fourth argument is undefined, sections are gathered for any status.
                   7253: Permissible values are 'active' or 'future' or 'previous'.
1.233     raeburn  7254:  
1.374     raeburn  7255: Returns section hash (keys are section IDs, values are
                   7256: number of users in each section), subject to the
1.419     raeburn  7257: optional roles filter, optional status filter 
1.233     raeburn  7258: 
                   7259: =cut
                   7260: 
                   7261: ###############################################
                   7262: sub get_sections {
1.419     raeburn  7263:     my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366     albertel 7264:     if (!defined($cdom) || !defined($cnum)) {
                   7265:         my $cid =  $env{'request.course.id'};
                   7266: 
                   7267: 	return if (!defined($cid));
                   7268: 
                   7269:         $cdom = $env{'course.'.$cid.'.domain'};
                   7270:         $cnum = $env{'course.'.$cid.'.num'};
                   7271:     }
                   7272: 
                   7273:     my %sectioncount;
1.419     raeburn  7274:     my $now = time;
1.240     albertel 7275: 
1.366     albertel 7276:     if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276     albertel 7277: 	my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240     albertel 7278: 	my $sec_index = &Apache::loncoursedata::CL_SECTION();
                   7279: 	my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419     raeburn  7280:         my $start_index = &Apache::loncoursedata::CL_START();
                   7281:         my $end_index = &Apache::loncoursedata::CL_END();
                   7282:         my $status;
1.366     albertel 7283: 	while (my ($student,$data) = each(%$classlist)) {
1.419     raeburn  7284: 	    my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
                   7285: 				                     $data->[$status_index],
                   7286:                                                      $data->[$start_index],
                   7287:                                                      $data->[$end_index]);
                   7288:             if ($stu_status eq 'Active') {
                   7289:                 $status = 'active';
                   7290:             } elsif ($end < $now) {
                   7291:                 $status = 'previous';
                   7292:             } elsif ($start > $now) {
                   7293:                 $status = 'future';
                   7294:             } 
                   7295: 	    if ($section ne '-1' && $section !~ /^\s*$/) {
                   7296:                 if ((!defined($possible_status)) || (($status ne '') && 
                   7297:                     (grep/^\Q$status\E$/,@{$possible_status}))) { 
                   7298: 		    $sectioncount{$section}++;
                   7299:                 }
1.240     albertel 7300: 	    }
                   7301: 	}
                   7302:     }
                   7303:     my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   7304:     foreach my $user (sort(keys(%courseroles))) {
                   7305: 	if ($user !~ /^(\w{2})/) { next; }
                   7306: 	my ($role) = ($user =~ /^(\w{2})/);
                   7307: 	if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419     raeburn  7308: 	my ($section,$status);
1.240     albertel 7309: 	if ($role eq 'cr' &&
                   7310: 	    $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
                   7311: 	    $section=$1;
                   7312: 	}
                   7313: 	if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
                   7314: 	if (!defined($section) || $section eq '-1') { next; }
1.419     raeburn  7315:         my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
                   7316:         if ($end == -1 && $start == -1) {
                   7317:             next; #deleted role
                   7318:         }
                   7319:         if (!defined($possible_status)) { 
                   7320:             $sectioncount{$section}++;
                   7321:         } else {
                   7322:             if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
                   7323:                 $status = 'active';
                   7324:             } elsif ($end < $now) {
                   7325:                 $status = 'future';
                   7326:             } elsif ($start > $now) {
                   7327:                 $status = 'previous';
                   7328:             }
                   7329:             if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
                   7330:                 $sectioncount{$section}++;
                   7331:             }
                   7332:         }
1.233     raeburn  7333:     }
1.366     albertel 7334:     return %sectioncount;
1.233     raeburn  7335: }
                   7336: 
1.274     raeburn  7337: ###############################################
1.294     raeburn  7338: 
                   7339: =pod
1.405     albertel 7340: 
                   7341: =item * &get_course_users()
                   7342: 
1.275     raeburn  7343: Retrieves usernames:domains for users in the specified course
                   7344: with specific role(s), and access status. 
                   7345: 
                   7346: Incoming parameters:
1.277     albertel 7347: 1. course domain
                   7348: 2. course number
                   7349: 3. access status: users must have - either active, 
1.275     raeburn  7350: previous, future, or all.
1.277     albertel 7351: 4. reference to array of permissible roles
1.288     raeburn  7352: 5. reference to array of section restrictions (optional)
                   7353: 6. reference to results object (hash of hashes).
                   7354: 7. reference to optional userdata hash
1.609     raeburn  7355: 8. reference to optional statushash
1.630     raeburn  7356: 9. flag if privileged users (except those set to unhide in
                   7357:    course settings) should be excluded    
1.609     raeburn  7358: Keys of top level results hash are roles.
1.275     raeburn  7359: Keys of inner hashes are username:domain, with 
                   7360: values set to access type.
1.288     raeburn  7361: Optional userdata hash returns an array with arguments in the 
                   7362: same order as loncoursedata::get_classlist() for student data.
                   7363: 
1.609     raeburn  7364: Optional statushash returns
                   7365: 
1.288     raeburn  7366: Entries for end, start, section and status are blank because
                   7367: of the possibility of multiple values for non-student roles.
                   7368: 
1.275     raeburn  7369: =cut
1.405     albertel 7370: 
1.275     raeburn  7371: ###############################################
1.405     albertel 7372: 
1.275     raeburn  7373: sub get_course_users {
1.630     raeburn  7374:     my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288     raeburn  7375:     my %idx = ();
1.419     raeburn  7376:     my %seclists;
1.288     raeburn  7377: 
                   7378:     $idx{udom} = &Apache::loncoursedata::CL_SDOM();
                   7379:     $idx{uname} =  &Apache::loncoursedata::CL_SNAME();
                   7380:     $idx{end} = &Apache::loncoursedata::CL_END();
                   7381:     $idx{start} = &Apache::loncoursedata::CL_START();
                   7382:     $idx{id} = &Apache::loncoursedata::CL_ID();
                   7383:     $idx{section} = &Apache::loncoursedata::CL_SECTION();
                   7384:     $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
                   7385:     $idx{status} = &Apache::loncoursedata::CL_STATUS();
                   7386: 
1.290     albertel 7387:     if (grep(/^st$/,@{$roles})) {
1.276     albertel 7388:         my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278     raeburn  7389:         my $now = time;
1.277     albertel 7390:         foreach my $student (keys(%{$classlist})) {
1.288     raeburn  7391:             my $match = 0;
1.412     raeburn  7392:             my $secmatch = 0;
1.419     raeburn  7393:             my $section = $$classlist{$student}[$idx{section}];
1.609     raeburn  7394:             my $status = $$classlist{$student}[$idx{status}];
1.419     raeburn  7395:             if ($section eq '') {
                   7396:                 $section = 'none';
                   7397:             }
1.291     albertel 7398:             if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 7399:                 if (grep(/^all$/,@{$sections})) {
1.412     raeburn  7400:                     $secmatch = 1;
                   7401:                 } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420     albertel 7402:                     if (grep(/^none$/,@{$sections})) {
1.412     raeburn  7403:                         $secmatch = 1;
                   7404:                     }
                   7405:                 } else {  
1.419     raeburn  7406: 		    if (grep(/^\Q$section\E$/,@{$sections})) {
1.412     raeburn  7407: 		        $secmatch = 1;
                   7408:                     }
1.290     albertel 7409: 		}
1.412     raeburn  7410:                 if (!$secmatch) {
                   7411:                     next;
                   7412:                 }
1.419     raeburn  7413:             }
1.275     raeburn  7414:             if (defined($$types{'active'})) {
1.288     raeburn  7415:                 if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275     raeburn  7416:                     push(@{$$users{st}{$student}},'active');
1.288     raeburn  7417:                     $match = 1;
1.275     raeburn  7418:                 }
                   7419:             }
                   7420:             if (defined($$types{'previous'})) {
1.609     raeburn  7421:                 if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275     raeburn  7422:                     push(@{$$users{st}{$student}},'previous');
1.288     raeburn  7423:                     $match = 1;
1.275     raeburn  7424:                 }
                   7425:             }
                   7426:             if (defined($$types{'future'})) {
1.609     raeburn  7427:                 if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275     raeburn  7428:                     push(@{$$users{st}{$student}},'future');
1.288     raeburn  7429:                     $match = 1;
1.275     raeburn  7430:                 }
                   7431:             }
1.609     raeburn  7432:             if ($match) {
                   7433:                 push(@{$seclists{$student}},$section);
                   7434:                 if (ref($userdata) eq 'HASH') {
                   7435:                     $$userdata{$student} = $$classlist{$student};
                   7436:                 }
                   7437:                 if (ref($statushash) eq 'HASH') {
                   7438:                     $statushash->{$student}{'st'}{$section} = $status;
                   7439:                 }
1.288     raeburn  7440:             }
1.275     raeburn  7441:         }
                   7442:     }
1.412     raeburn  7443:     if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439     raeburn  7444:         my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   7445:         my $now = time;
1.609     raeburn  7446:         my %displaystatus = ( previous => 'Expired',
                   7447:                               active   => 'Active',
                   7448:                               future   => 'Future',
                   7449:                             );
1.630     raeburn  7450:         my %nothide;
                   7451:         if ($hidepriv) {
                   7452:             my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
                   7453:             foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
                   7454:                 if ($user !~ /:/) {
                   7455:                     $nothide{join(':',split(/[\@]/,$user))}=1;
                   7456:                 } else {
                   7457:                     $nothide{$user} = 1;
                   7458:                 }
                   7459:             }
                   7460:         }
1.439     raeburn  7461:         foreach my $person (sort(keys(%coursepersonnel))) {
1.288     raeburn  7462:             my $match = 0;
1.412     raeburn  7463:             my $secmatch = 0;
1.439     raeburn  7464:             my $status;
1.412     raeburn  7465:             my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275     raeburn  7466:             $user =~ s/:$//;
1.439     raeburn  7467:             my ($end,$start) = split(/:/,$coursepersonnel{$person});
                   7468:             if ($end == -1 || $start == -1) {
                   7469:                 next;
                   7470:             }
                   7471:             if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
                   7472:                 (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412     raeburn  7473:                 my ($uname,$udom) = split(/:/,$user);
                   7474:                 if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 7475:                     if (grep(/^all$/,@{$sections})) {
1.412     raeburn  7476:                         $secmatch = 1;
                   7477:                     } elsif ($usec eq '') {
1.420     albertel 7478:                         if (grep(/^none$/,@{$sections})) {
1.412     raeburn  7479:                             $secmatch = 1;
                   7480:                         }
                   7481:                     } else {
                   7482:                         if (grep(/^\Q$usec\E$/,@{$sections})) {
                   7483:                             $secmatch = 1;
                   7484:                         }
                   7485:                     }
                   7486:                     if (!$secmatch) {
                   7487:                         next;
                   7488:                     }
1.288     raeburn  7489:                 }
1.419     raeburn  7490:                 if ($usec eq '') {
                   7491:                     $usec = 'none';
                   7492:                 }
1.275     raeburn  7493:                 if ($uname ne '' && $udom ne '') {
1.630     raeburn  7494:                     if ($hidepriv) {
                   7495:                         if ((&Apache::lonnet::privileged($uname,$udom)) &&
                   7496:                             (!$nothide{$uname.':'.$udom})) {
                   7497:                             next;
                   7498:                         }
                   7499:                     }
1.503     raeburn  7500:                     if ($end > 0 && $end < $now) {
1.439     raeburn  7501:                         $status = 'previous';
                   7502:                     } elsif ($start > $now) {
                   7503:                         $status = 'future';
                   7504:                     } else {
                   7505:                         $status = 'active';
                   7506:                     }
1.277     albertel 7507:                     foreach my $type (keys(%{$types})) { 
1.275     raeburn  7508:                         if ($status eq $type) {
1.420     albertel 7509:                             if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419     raeburn  7510:                                 push(@{$$users{$role}{$user}},$type);
                   7511:                             }
1.288     raeburn  7512:                             $match = 1;
                   7513:                         }
                   7514:                     }
1.419     raeburn  7515:                     if (($match) && (ref($userdata) eq 'HASH')) {
                   7516:                         if (!exists($$userdata{$uname.':'.$udom})) {
                   7517: 			    &get_user_info($udom,$uname,\%idx,$userdata);
                   7518:                         }
1.420     albertel 7519:                         if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419     raeburn  7520:                             push(@{$seclists{$uname.':'.$udom}},$usec);
                   7521:                         }
1.609     raeburn  7522:                         if (ref($statushash) eq 'HASH') {
                   7523:                             $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
                   7524:                         }
1.275     raeburn  7525:                     }
                   7526:                 }
                   7527:             }
                   7528:         }
1.290     albertel 7529:         if (grep(/^ow$/,@{$roles})) {
1.279     raeburn  7530:             if ((defined($cdom)) && (defined($cnum))) {
                   7531:                 my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
                   7532:                 if ( defined($csettings{'internal.courseowner'}) ) {
                   7533:                     my $owner = $csettings{'internal.courseowner'};
1.609     raeburn  7534:                     next if ($owner eq '');
                   7535:                     my ($ownername,$ownerdom);
                   7536:                     if ($owner =~ /^([^:]+):([^:]+)$/) {
                   7537:                         $ownername = $1;
                   7538:                         $ownerdom = $2;
                   7539:                     } else {
                   7540:                         $ownername = $owner;
                   7541:                         $ownerdom = $cdom;
                   7542:                         $owner = $ownername.':'.$ownerdom;
1.439     raeburn  7543:                     }
                   7544:                     @{$$users{'ow'}{$owner}} = 'any';
1.290     albertel 7545:                     if (defined($userdata) && 
1.609     raeburn  7546: 			!exists($$userdata{$owner})) {
                   7547: 			&get_user_info($ownerdom,$ownername,\%idx,$userdata);
                   7548:                         if (!grep(/^none$/,@{$seclists{$owner}})) {
                   7549:                             push(@{$seclists{$owner}},'none');
                   7550:                         }
                   7551:                         if (ref($statushash) eq 'HASH') {
                   7552:                             $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419     raeburn  7553:                         }
1.290     albertel 7554: 		    }
1.279     raeburn  7555:                 }
                   7556:             }
                   7557:         }
1.419     raeburn  7558:         foreach my $user (keys(%seclists)) {
                   7559:             @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
                   7560:             $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
                   7561:         }
1.275     raeburn  7562:     }
                   7563:     return;
                   7564: }
                   7565: 
1.288     raeburn  7566: sub get_user_info {
                   7567:     my ($udom,$uname,$idx,$userdata) = @_;
1.289     albertel 7568:     $$userdata{$uname.':'.$udom}[$$idx{fullname}] = 
                   7569: 	&plainname($uname,$udom,'lastname');
1.291     albertel 7570:     $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297     raeburn  7571:     $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609     raeburn  7572:     my %idhash =  &Apache::lonnet::idrget($udom,($uname));
                   7573:     $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname}; 
1.288     raeburn  7574:     return;
                   7575: }
1.275     raeburn  7576: 
1.472     raeburn  7577: ###############################################
                   7578: 
                   7579: =pod
                   7580: 
                   7581: =item * &get_user_quota()
                   7582: 
                   7583: Retrieves quota assigned for storage of portfolio files for a user  
                   7584: 
                   7585: Incoming parameters:
                   7586: 1. user's username
                   7587: 2. user's domain
                   7588: 
                   7589: Returns:
1.536     raeburn  7590: 1. Disk quota (in Mb) assigned to student.
                   7591: 2. (Optional) Type of setting: custom or default
                   7592:    (individually assigned or default for user's 
                   7593:    institutional status).
                   7594: 3. (Optional) - User's institutional status (e.g., faculty, staff
                   7595:    or student - types as defined in localenroll::inst_usertypes 
                   7596:    for user's domain, which determines default quota for user.
                   7597: 4. (Optional) - Default quota which would apply to the user.
1.472     raeburn  7598: 
                   7599: If a value has been stored in the user's environment, 
1.536     raeburn  7600: it will return that, otherwise it returns the maximal default
                   7601: defined for the user's instituional status(es) in the domain.
1.472     raeburn  7602: 
                   7603: =cut
                   7604: 
                   7605: ###############################################
                   7606: 
                   7607: 
                   7608: sub get_user_quota {
                   7609:     my ($uname,$udom) = @_;
1.536     raeburn  7610:     my ($quota,$quotatype,$settingstatus,$defquota);
1.472     raeburn  7611:     if (!defined($udom)) {
                   7612:         $udom = $env{'user.domain'};
                   7613:     }
                   7614:     if (!defined($uname)) {
                   7615:         $uname = $env{'user.name'};
                   7616:     }
                   7617:     if (($udom eq '' || $uname eq '') ||
                   7618:         ($udom eq 'public') && ($uname eq 'public')) {
                   7619:         $quota = 0;
1.536     raeburn  7620:         $quotatype = 'default';
                   7621:         $defquota = 0; 
1.472     raeburn  7622:     } else {
1.536     raeburn  7623:         my $inststatus;
1.472     raeburn  7624:         if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
                   7625:             $quota = $env{'environment.portfolioquota'};
1.536     raeburn  7626:             $inststatus = $env{'environment.inststatus'};
1.472     raeburn  7627:         } else {
1.536     raeburn  7628:             my %userenv = 
                   7629:                 &Apache::lonnet::get('environment',['portfolioquota',
                   7630:                                      'inststatus'],$udom,$uname);
1.472     raeburn  7631:             my ($tmp) = keys(%userenv);
                   7632:             if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   7633:                 $quota = $userenv{'portfolioquota'};
1.536     raeburn  7634:                 $inststatus = $userenv{'inststatus'};
1.472     raeburn  7635:             } else {
                   7636:                 undef(%userenv);
                   7637:             }
                   7638:         }
1.536     raeburn  7639:         ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472     raeburn  7640:         if ($quota eq '') {
1.536     raeburn  7641:             $quota = $defquota;
                   7642:             $quotatype = 'default';
                   7643:         } else {
                   7644:             $quotatype = 'custom';
1.472     raeburn  7645:         }
                   7646:     }
1.536     raeburn  7647:     if (wantarray) {
                   7648:         return ($quota,$quotatype,$settingstatus,$defquota);
                   7649:     } else {
                   7650:         return $quota;
                   7651:     }
1.472     raeburn  7652: }
                   7653: 
                   7654: ###############################################
                   7655: 
                   7656: =pod
                   7657: 
                   7658: =item * &default_quota()
                   7659: 
1.536     raeburn  7660: Retrieves default quota assigned for storage of user portfolio files,
                   7661: given an (optional) user's institutional status.
1.472     raeburn  7662: 
                   7663: Incoming parameters:
                   7664: 1. domain
1.536     raeburn  7665: 2. (Optional) institutional status(es).  This is a : separated list of 
                   7666:    status types (e.g., faculty, staff, student etc.)
                   7667:    which apply to the user for whom the default is being retrieved.
                   7668:    If the institutional status string in undefined, the domain
                   7669:    default quota will be returned. 
1.472     raeburn  7670: 
                   7671: Returns:
                   7672: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536     raeburn  7673: 2. (Optional) institutional type which determined the value of the
                   7674:    default quota.
1.472     raeburn  7675: 
                   7676: If a value has been stored in the domain's configuration db,
                   7677: it will return that, otherwise it returns 20 (for backwards 
                   7678: compatibility with domains which have not set up a configuration
                   7679: db file; the original statically defined portfolio quota was 20 Mb). 
                   7680: 
1.536     raeburn  7681: If the user's status includes multiple types (e.g., staff and student),
                   7682: the largest default quota which applies to the user determines the
                   7683: default quota returned.
                   7684: 
1.780     raeburn  7685: =back
                   7686: 
1.472     raeburn  7687: =cut
                   7688: 
                   7689: ###############################################
                   7690: 
                   7691: 
                   7692: sub default_quota {
1.536     raeburn  7693:     my ($udom,$inststatus) = @_;
                   7694:     my ($defquota,$settingstatus);
                   7695:     my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622     raeburn  7696:                                             ['quotas'],$udom);
                   7697:     if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536     raeburn  7698:         if ($inststatus ne '') {
1.765     raeburn  7699:             my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536     raeburn  7700:             foreach my $item (@statuses) {
1.711     raeburn  7701:                 if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
                   7702:                     if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
                   7703:                         if ($defquota eq '') {
                   7704:                             $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
                   7705:                             $settingstatus = $item;
                   7706:                         } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
                   7707:                             $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
                   7708:                             $settingstatus = $item;
                   7709:                         }
                   7710:                     }
                   7711:                 } else {
                   7712:                     if ($quotahash{'quotas'}{$item} ne '') {
                   7713:                         if ($defquota eq '') {
                   7714:                             $defquota = $quotahash{'quotas'}{$item};
                   7715:                             $settingstatus = $item;
                   7716:                         } elsif ($quotahash{'quotas'}{$item} > $defquota) {
                   7717:                             $defquota = $quotahash{'quotas'}{$item};
                   7718:                             $settingstatus = $item;
                   7719:                         }
1.536     raeburn  7720:                     }
                   7721:                 }
                   7722:             }
                   7723:         }
                   7724:         if ($defquota eq '') {
1.711     raeburn  7725:             if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
                   7726:                 $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
                   7727:             } else {
                   7728:                 $defquota = $quotahash{'quotas'}{'default'};
                   7729:             }
1.536     raeburn  7730:             $settingstatus = 'default';
                   7731:         }
                   7732:     } else {
                   7733:         $settingstatus = 'default';
                   7734:         $defquota = 20;
                   7735:     }
                   7736:     if (wantarray) {
                   7737:         return ($defquota,$settingstatus);
1.472     raeburn  7738:     } else {
1.536     raeburn  7739:         return $defquota;
1.472     raeburn  7740:     }
                   7741: }
                   7742: 
1.384     raeburn  7743: sub get_secgrprole_info {
                   7744:     my ($cdom,$cnum,$needroles,$type)  = @_;
                   7745:     my %sections_count = &get_sections($cdom,$cnum);
                   7746:     my @sections =  (sort {$a <=> $b} keys(%sections_count));
                   7747:     my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
                   7748:     my @groups = sort(keys(%curr_groups));
                   7749:     my $allroles = [];
                   7750:     my $rolehash;
                   7751:     my $accesshash = {
                   7752:                      active => 'Currently has access',
                   7753:                      future => 'Will have future access',
                   7754:                      previous => 'Previously had access',
                   7755:                   };
                   7756:     if ($needroles) {
                   7757:         $rolehash = {'all' => 'all'};
1.385     albertel 7758:         my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   7759: 	if (&Apache::lonnet::error(%user_roles)) {
                   7760: 	    undef(%user_roles);
                   7761: 	}
                   7762:         foreach my $item (keys(%user_roles)) {
1.384     raeburn  7763:             my ($role)=split(/\:/,$item,2);
                   7764:             if ($role eq 'cr') { next; }
                   7765:             if ($role =~ /^cr/) {
                   7766:                 $$rolehash{$role} = (split('/',$role))[3];
                   7767:             } else {
                   7768:                 $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
                   7769:             }
                   7770:         }
                   7771:         foreach my $key (sort(keys(%{$rolehash}))) {
                   7772:             push(@{$allroles},$key);
                   7773:         }
                   7774:         push (@{$allroles},'st');
                   7775:         $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
                   7776:     }
                   7777:     return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
                   7778: }
                   7779: 
1.555     raeburn  7780: sub user_picker {
1.627     raeburn  7781:     my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555     raeburn  7782:     my $currdom = $dom;
                   7783:     my %curr_selected = (
                   7784:                         srchin => 'dom',
1.580     raeburn  7785:                         srchby => 'lastname',
1.555     raeburn  7786:                       );
                   7787:     my $srchterm;
1.625     raeburn  7788:     if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555     raeburn  7789:         if ($srch->{'srchby'} ne '') {
                   7790:             $curr_selected{'srchby'} = $srch->{'srchby'};
                   7791:         }
                   7792:         if ($srch->{'srchin'} ne '') {
                   7793:             $curr_selected{'srchin'} = $srch->{'srchin'};
                   7794:         }
                   7795:         if ($srch->{'srchtype'} ne '') {
                   7796:             $curr_selected{'srchtype'} = $srch->{'srchtype'};
                   7797:         }
                   7798:         if ($srch->{'srchdomain'} ne '') {
                   7799:             $currdom = $srch->{'srchdomain'};
                   7800:         }
                   7801:         $srchterm = $srch->{'srchterm'};
                   7802:     }
                   7803:     my %lt=&Apache::lonlocal::texthash(
1.573     raeburn  7804:                     'usr'       => 'Search criteria',
1.563     raeburn  7805:                     'doma'      => 'Domain/institution to search',
1.558     albertel 7806:                     'uname'     => 'username',
                   7807:                     'lastname'  => 'last name',
1.555     raeburn  7808:                     'lastfirst' => 'last name, first name',
1.558     albertel 7809:                     'crs'       => 'in this course',
1.576     raeburn  7810:                     'dom'       => 'in selected LON-CAPA domain', 
1.558     albertel 7811:                     'alc'       => 'all LON-CAPA',
1.573     raeburn  7812:                     'instd'     => 'in institutional directory for selected domain',
1.558     albertel 7813:                     'exact'     => 'is',
                   7814:                     'contains'  => 'contains',
1.569     raeburn  7815:                     'begins'    => 'begins with',
1.571     raeburn  7816:                     'youm'      => "You must include some text to search for.",
                   7817:                     'thte'      => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
                   7818:                     'thet'      => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
                   7819:                     'yomc'      => "You must choose a domain when using an institutional directory search.",
                   7820:                     'ymcd'      => "You must choose a domain when using a domain search.",
                   7821:                     'whus'      => "When using searching by last,first you must include a comma as separator between last name and first name.",
                   7822:                     'whse'      => "When searching by last,first you must include at least one character in the first name.",
                   7823:                      'thfo'     => "The following need to be corrected before the search can be run:",
1.555     raeburn  7824:                                        );
1.563     raeburn  7825:     my $domform = &select_dom_form($currdom,'srchdomain',1,1);
                   7826:     my $srchinsel = ' <select name="srchin">';
1.555     raeburn  7827: 
                   7828:     my @srchins = ('crs','dom','alc','instd');
                   7829: 
                   7830:     foreach my $option (@srchins) {
                   7831:         # FIXME 'alc' option unavailable until 
                   7832:         #       loncreateuser::print_user_query_page()
                   7833:         #       has been completed.
                   7834:         next if ($option eq 'alc');
1.880     raeburn  7835:         next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));  
1.555     raeburn  7836:         next if ($option eq 'crs' && !$env{'request.course.id'});
1.563     raeburn  7837:         if ($curr_selected{'srchin'} eq $option) {
                   7838:             $srchinsel .= ' 
                   7839:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7840:         } else {
                   7841:             $srchinsel .= '
                   7842:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7843:         }
1.555     raeburn  7844:     }
1.563     raeburn  7845:     $srchinsel .= "\n  </select>\n";
1.555     raeburn  7846: 
                   7847:     my $srchbysel =  ' <select name="srchby">';
1.580     raeburn  7848:     foreach my $option ('lastname','lastfirst','uname') {
1.555     raeburn  7849:         if ($curr_selected{'srchby'} eq $option) {
                   7850:             $srchbysel .= '
                   7851:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7852:         } else {
                   7853:             $srchbysel .= '
                   7854:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7855:          }
                   7856:     }
                   7857:     $srchbysel .= "\n  </select>\n";
                   7858: 
                   7859:     my $srchtypesel = ' <select name="srchtype">';
1.580     raeburn  7860:     foreach my $option ('begins','contains','exact') {
1.555     raeburn  7861:         if ($curr_selected{'srchtype'} eq $option) {
                   7862:             $srchtypesel .= '
                   7863:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7864:         } else {
                   7865:             $srchtypesel .= '
                   7866:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7867:         }
                   7868:     }
                   7869:     $srchtypesel .= "\n  </select>\n";
                   7870: 
1.558     albertel 7871:     my ($newuserscript,$new_user_create);
1.556     raeburn  7872: 
                   7873:     if ($forcenewuser) {
1.576     raeburn  7874:         if (ref($srch) eq 'HASH') {
                   7875:             if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627     raeburn  7876:                 if ($cancreate) {
                   7877:                     $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>';
                   7878:                 } else {
1.799     bisitz   7879:                     my $helplink = 'javascript:helpMenu('."'display'".')';
1.627     raeburn  7880:                     my %usertypetext = (
                   7881:                         official   => 'institutional',
                   7882:                         unofficial => 'non-institutional',
                   7883:                     );
1.799     bisitz   7884:                     $new_user_create = '<p class="LC_warning">'
                   7885:                                       .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
                   7886:                                       .' '
                   7887:                                       .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
                   7888:                                           ,'<a href="'.$helplink.'">','</a>')
                   7889:                                       .'</p><br />';
1.627     raeburn  7890:                 }
1.576     raeburn  7891:             }
                   7892:         }
                   7893: 
1.556     raeburn  7894:         $newuserscript = <<"ENDSCRIPT";
                   7895: 
1.570     raeburn  7896: function setSearch(createnew,callingForm) {
1.556     raeburn  7897:     if (createnew == 1) {
1.570     raeburn  7898:         for (var i=0; i<callingForm.srchby.length; i++) {
                   7899:             if (callingForm.srchby.options[i].value == 'uname') {
                   7900:                 callingForm.srchby.selectedIndex = i;
1.556     raeburn  7901:             }
                   7902:         }
1.570     raeburn  7903:         for (var i=0; i<callingForm.srchin.length; i++) {
                   7904:             if ( callingForm.srchin.options[i].value == 'dom') {
                   7905: 		callingForm.srchin.selectedIndex = i;
1.556     raeburn  7906:             }
                   7907:         }
1.570     raeburn  7908:         for (var i=0; i<callingForm.srchtype.length; i++) {
                   7909:             if (callingForm.srchtype.options[i].value == 'exact') {
                   7910:                 callingForm.srchtype.selectedIndex = i;
1.556     raeburn  7911:             }
                   7912:         }
1.570     raeburn  7913:         for (var i=0; i<callingForm.srchdomain.length; i++) {
                   7914:             if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
                   7915:                 callingForm.srchdomain.selectedIndex = i;
1.556     raeburn  7916:             }
                   7917:         }
                   7918:     }
                   7919: }
                   7920: ENDSCRIPT
1.558     albertel 7921: 
1.556     raeburn  7922:     }
                   7923: 
1.555     raeburn  7924:     my $output = <<"END_BLOCK";
1.556     raeburn  7925: <script type="text/javascript">
1.824     bisitz   7926: // <![CDATA[
1.570     raeburn  7927: function validateEntry(callingForm) {
1.558     albertel 7928: 
1.556     raeburn  7929:     var checkok = 1;
1.558     albertel 7930:     var srchin;
1.570     raeburn  7931:     for (var i=0; i<callingForm.srchin.length; i++) {
                   7932: 	if ( callingForm.srchin[i].checked ) {
                   7933: 	    srchin = callingForm.srchin[i].value;
1.558     albertel 7934: 	}
                   7935:     }
                   7936: 
1.570     raeburn  7937:     var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
                   7938:     var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
                   7939:     var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
                   7940:     var srchterm =  callingForm.srchterm.value;
                   7941:     var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556     raeburn  7942:     var msg = "";
                   7943: 
                   7944:     if (srchterm == "") {
                   7945:         checkok = 0;
1.571     raeburn  7946:         msg += "$lt{'youm'}\\n";
1.556     raeburn  7947:     }
                   7948: 
1.569     raeburn  7949:     if (srchtype== 'begins') {
                   7950:         if (srchterm.length < 2) {
                   7951:             checkok = 0;
1.571     raeburn  7952:             msg += "$lt{'thte'}\\n";
1.569     raeburn  7953:         }
                   7954:     }
                   7955: 
1.556     raeburn  7956:     if (srchtype== 'contains') {
                   7957:         if (srchterm.length < 3) {
                   7958:             checkok = 0;
1.571     raeburn  7959:             msg += "$lt{'thet'}\\n";
1.556     raeburn  7960:         }
                   7961:     }
                   7962:     if (srchin == 'instd') {
                   7963:         if (srchdomain == '') {
                   7964:             checkok = 0;
1.571     raeburn  7965:             msg += "$lt{'yomc'}\\n";
1.556     raeburn  7966:         }
                   7967:     }
                   7968:     if (srchin == 'dom') {
                   7969:         if (srchdomain == '') {
                   7970:             checkok = 0;
1.571     raeburn  7971:             msg += "$lt{'ymcd'}\\n";
1.556     raeburn  7972:         }
                   7973:     }
                   7974:     if (srchby == 'lastfirst') {
                   7975:         if (srchterm.indexOf(",") == -1) {
                   7976:             checkok = 0;
1.571     raeburn  7977:             msg += "$lt{'whus'}\\n";
1.556     raeburn  7978:         }
                   7979:         if (srchterm.indexOf(",") == srchterm.length -1) {
                   7980:             checkok = 0;
1.571     raeburn  7981:             msg += "$lt{'whse'}\\n";
1.556     raeburn  7982:         }
                   7983:     }
                   7984:     if (checkok == 0) {
1.571     raeburn  7985:         alert("$lt{'thfo'}\\n"+msg);
1.556     raeburn  7986:         return;
                   7987:     }
                   7988:     if (checkok == 1) {
1.570     raeburn  7989:         callingForm.submit();
1.556     raeburn  7990:     }
                   7991: }
                   7992: 
                   7993: $newuserscript
                   7994: 
1.824     bisitz   7995: // ]]>
1.556     raeburn  7996: </script>
1.558     albertel 7997: 
                   7998: $new_user_create
                   7999: 
1.555     raeburn  8000: END_BLOCK
1.558     albertel 8001: 
1.876     raeburn  8002:     $output .= &Apache::lonhtmlcommon::start_pick_box().
                   8003:                &Apache::lonhtmlcommon::row_title($lt{'doma'}).
                   8004:                $domform.
                   8005:                &Apache::lonhtmlcommon::row_closure().
                   8006:                &Apache::lonhtmlcommon::row_title($lt{'usr'}).
                   8007:                $srchbysel.
                   8008:                $srchtypesel. 
                   8009:                '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
                   8010:                $srchinsel.
                   8011:                &Apache::lonhtmlcommon::row_closure(1). 
                   8012:                &Apache::lonhtmlcommon::end_pick_box().
                   8013:                '<br />';
1.555     raeburn  8014:     return $output;
                   8015: }
                   8016: 
1.612     raeburn  8017: sub user_rule_check {
1.615     raeburn  8018:     my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612     raeburn  8019:     my $response;
                   8020:     if (ref($usershash) eq 'HASH') {
                   8021:         foreach my $user (keys(%{$usershash})) {
                   8022:             my ($uname,$udom) = split(/:/,$user);
                   8023:             next if ($udom eq '' || $uname eq '');
1.615     raeburn  8024:             my ($id,$newuser);
1.612     raeburn  8025:             if (ref($usershash->{$user}) eq 'HASH') {
1.615     raeburn  8026:                 $newuser = $usershash->{$user}->{'newuser'};
1.612     raeburn  8027:                 $id = $usershash->{$user}->{'id'};
                   8028:             }
                   8029:             my $inst_response;
                   8030:             if (ref($checks) eq 'HASH') {
                   8031:                 if (defined($checks->{'username'})) {
1.615     raeburn  8032:                     ($inst_response,%{$inst_results->{$user}}) = 
1.612     raeburn  8033:                         &Apache::lonnet::get_instuser($udom,$uname);
                   8034:                 } elsif (defined($checks->{'id'})) {
1.615     raeburn  8035:                     ($inst_response,%{$inst_results->{$user}}) =
1.612     raeburn  8036:                         &Apache::lonnet::get_instuser($udom,undef,$id);
                   8037:                 }
1.615     raeburn  8038:             } else {
                   8039:                 ($inst_response,%{$inst_results->{$user}}) =
                   8040:                     &Apache::lonnet::get_instuser($udom,$uname);
                   8041:                 return;
1.612     raeburn  8042:             }
1.615     raeburn  8043:             if (!$got_rules->{$udom}) {
1.612     raeburn  8044:                 my %domconfig = &Apache::lonnet::get_dom('configuration',
                   8045:                                                   ['usercreation'],$udom);
                   8046:                 if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615     raeburn  8047:                     foreach my $item ('username','id') {
1.612     raeburn  8048:                         if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
                   8049:                             $$curr_rules{$udom}{$item} = 
                   8050:                                 $domconfig{'usercreation'}{$item.'_rule'};
1.585     raeburn  8051:                         }
                   8052:                     }
                   8053:                 }
1.615     raeburn  8054:                 $got_rules->{$udom} = 1;  
1.585     raeburn  8055:             }
1.612     raeburn  8056:             foreach my $item (keys(%{$checks})) {
                   8057:                 if (ref($$curr_rules{$udom}) eq 'HASH') {
                   8058:                     if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
                   8059:                         if (@{$$curr_rules{$udom}{$item}} > 0) {
                   8060:                             my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
                   8061:                             foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
                   8062:                                 if ($rule_check{$rule}) {
                   8063:                                     $$rulematch{$user}{$item} = $rule;
                   8064:                                     if ($inst_response eq 'ok') {
1.615     raeburn  8065:                                         if (ref($inst_results) eq 'HASH') {
                   8066:                                             if (ref($inst_results->{$user}) eq 'HASH') {
                   8067:                                                 if (keys(%{$inst_results->{$user}}) == 0) {
                   8068:                                                     $$alerts{$item}{$udom}{$uname} = 1;
                   8069:                                                 }
1.612     raeburn  8070:                                             }
                   8071:                                         }
1.615     raeburn  8072:                                     }
                   8073:                                     last;
1.585     raeburn  8074:                                 }
                   8075:                             }
                   8076:                         }
                   8077:                     }
                   8078:                 }
                   8079:             }
                   8080:         }
                   8081:     }
1.612     raeburn  8082:     return;
                   8083: }
                   8084: 
                   8085: sub user_rule_formats {
                   8086:     my ($domain,$domdesc,$curr_rules,$check) = @_;
                   8087:     my %text = ( 
                   8088:                  'username' => 'Usernames',
                   8089:                  'id'       => 'IDs',
                   8090:                );
                   8091:     my $output;
                   8092:     my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
                   8093:     if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
                   8094:         if (@{$ruleorder} > 0) {
                   8095:             $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>';
                   8096:             foreach my $rule (@{$ruleorder}) {
                   8097:                 if (ref($curr_rules) eq 'ARRAY') {
                   8098:                     if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
                   8099:                         if (ref($rules->{$rule}) eq 'HASH') {
                   8100:                             $output .= '<li>'.$rules->{$rule}{'name'}.': '.
                   8101:                                         $rules->{$rule}{'desc'}.'</li>';
                   8102:                         }
                   8103:                     }
                   8104:                 }
                   8105:             }
                   8106:             $output .= '</ul>';
                   8107:         }
                   8108:     }
                   8109:     return $output;
                   8110: }
                   8111: 
                   8112: sub instrule_disallow_msg {
1.615     raeburn  8113:     my ($checkitem,$domdesc,$count,$mode) = @_;
1.612     raeburn  8114:     my $response;
                   8115:     my %text = (
                   8116:                   item   => 'username',
                   8117:                   items  => 'usernames',
                   8118:                   match  => 'matches',
                   8119:                   do     => 'does',
                   8120:                   action => 'a username',
                   8121:                   one    => 'one',
                   8122:                );
                   8123:     if ($count > 1) {
                   8124:         $text{'item'} = 'usernames';
                   8125:         $text{'match'} ='match';
                   8126:         $text{'do'} = 'do';
                   8127:         $text{'action'} = 'usernames',
                   8128:         $text{'one'} = 'ones';
                   8129:     }
                   8130:     if ($checkitem eq 'id') {
                   8131:         $text{'items'} = 'IDs';
                   8132:         $text{'item'} = 'ID';
                   8133:         $text{'action'} = 'an ID';
1.615     raeburn  8134:         if ($count > 1) {
                   8135:             $text{'item'} = 'IDs';
                   8136:             $text{'action'} = 'IDs';
                   8137:         }
1.612     raeburn  8138:     }
1.674     bisitz   8139:     $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  8140:     if ($mode eq 'upload') {
                   8141:         if ($checkitem eq 'username') {
                   8142:             $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'}.");
                   8143:         } elsif ($checkitem eq 'id') {
1.674     bisitz   8144:             $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  8145:         }
1.669     raeburn  8146:     } elsif ($mode eq 'selfcreate') {
                   8147:         if ($checkitem eq 'id') {
                   8148:             $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.");
                   8149:         }
1.615     raeburn  8150:     } else {
                   8151:         if ($checkitem eq 'username') {
                   8152:             $response .= &mt("You must choose $text{'action'} with a different format --  $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
                   8153:         } elsif ($checkitem eq 'id') {
                   8154:             $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.");
                   8155:         }
1.612     raeburn  8156:     }
                   8157:     return $response;
1.585     raeburn  8158: }
                   8159: 
1.624     raeburn  8160: sub personal_data_fieldtitles {
                   8161:     my %fieldtitles = &Apache::lonlocal::texthash (
                   8162:                         id => 'Student/Employee ID',
                   8163:                         permanentemail => 'E-mail address',
                   8164:                         lastname => 'Last Name',
                   8165:                         firstname => 'First Name',
                   8166:                         middlename => 'Middle Name',
                   8167:                         generation => 'Generation',
                   8168:                         gen => 'Generation',
1.765     raeburn  8169:                         inststatus => 'Affiliation',
1.624     raeburn  8170:                    );
                   8171:     return %fieldtitles;
                   8172: }
                   8173: 
1.642     raeburn  8174: sub sorted_inst_types {
                   8175:     my ($dom) = @_;
                   8176:     my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
                   8177:     my $othertitle = &mt('All users');
                   8178:     if ($env{'request.course.id'}) {
1.668     raeburn  8179:         $othertitle  = &mt('Any users');
1.642     raeburn  8180:     }
                   8181:     my @types;
                   8182:     if (ref($order) eq 'ARRAY') {
                   8183:         @types = @{$order};
                   8184:     }
                   8185:     if (@types == 0) {
                   8186:         if (ref($usertypes) eq 'HASH') {
                   8187:             @types = sort(keys(%{$usertypes}));
                   8188:         }
                   8189:     }
                   8190:     if (keys(%{$usertypes}) > 0) {
                   8191:         $othertitle = &mt('Other users');
                   8192:     }
                   8193:     return ($othertitle,$usertypes,\@types);
                   8194: }
                   8195: 
1.645     raeburn  8196: sub get_institutional_codes {
                   8197:     my ($settings,$allcourses,$LC_code) = @_;
                   8198: # Get complete list of course sections to update
                   8199:     my @currsections = ();
                   8200:     my @currxlists = ();
                   8201:     my $coursecode = $$settings{'internal.coursecode'};
                   8202: 
                   8203:     if ($$settings{'internal.sectionnums'} ne '') {
                   8204:         @currsections = split(/,/,$$settings{'internal.sectionnums'});
                   8205:     }
                   8206: 
                   8207:     if ($$settings{'internal.crosslistings'} ne '') {
                   8208:         @currxlists = split(/,/,$$settings{'internal.crosslistings'});
                   8209:     }
                   8210: 
                   8211:     if (@currxlists > 0) {
                   8212:         foreach (@currxlists) {
                   8213:             if (m/^([^:]+):(\w*)$/) {
                   8214:                 unless (grep/^$1$/,@{$allcourses}) {
                   8215:                     push @{$allcourses},$1;
                   8216:                     $$LC_code{$1} = $2;
                   8217:                 }
                   8218:             }
                   8219:         }
                   8220:     }
                   8221:  
                   8222:     if (@currsections > 0) {
                   8223:         foreach (@currsections) {
                   8224:             if (m/^(\w+):(\w*)$/) {
                   8225:                 my $sec = $coursecode.$1;
                   8226:                 my $lc_sec = $2;
                   8227:                 unless (grep/^$sec$/,@{$allcourses}) {
                   8228:                     push @{$allcourses},$sec;
                   8229:                     $$LC_code{$sec} = $lc_sec;
                   8230:                 }
                   8231:             }
                   8232:         }
                   8233:     }
                   8234:     return;
                   8235: }
                   8236: 
1.948.2.7! raeburn  8237: sub get_standard_codeitems {
        !          8238:     return ('Year','Semester','Department','Number','Section');
        !          8239: }
        !          8240: 
1.112     bowersj2 8241: =pod
                   8242: 
1.780     raeburn  8243: =head1 Slot Helpers
                   8244: 
                   8245: =over 4
                   8246: 
                   8247: =item * sorted_slots()
                   8248: 
                   8249: Sorts an array of slot names in order of slot start time (earliest first). 
                   8250: 
                   8251: Inputs:
                   8252: 
                   8253: =over 4
                   8254: 
                   8255: slotsarr  - Reference to array of unsorted slot names.
                   8256: 
                   8257: slots     - Reference to hash of hash, where outer hash keys are slot names.
                   8258: 
1.549     albertel 8259: =back
                   8260: 
1.780     raeburn  8261: Returns:
                   8262: 
                   8263: =over 4
                   8264: 
                   8265: sorted   - An array of slot names sorted by the start time of the slot.
                   8266: 
                   8267: =back
                   8268: 
                   8269: =back
                   8270: 
                   8271: =cut
                   8272: 
                   8273: 
                   8274: sub sorted_slots {
                   8275:     my ($slotsarr,$slots) = @_;
                   8276:     my @sorted;
                   8277:     if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
                   8278:         @sorted =
                   8279:             sort {
                   8280:                      if (ref($slots->{$a}) && ref($slots->{$b})) {
                   8281:                          return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
                   8282:                      }
                   8283:                      if (ref($slots->{$a})) { return -1;}
                   8284:                      if (ref($slots->{$b})) { return 1;}
                   8285:                      return 0;
                   8286:                  } @{$slotsarr};
                   8287:     }
                   8288:     return @sorted;
                   8289: }
                   8290: 
                   8291: 
                   8292: =pod
                   8293: 
1.549     albertel 8294: =head1 HTTP Helpers
                   8295: 
                   8296: =over 4
                   8297: 
1.648     raeburn  8298: =item * &get_unprocessed_cgi($query,$possible_names)
1.112     bowersj2 8299: 
1.258     albertel 8300: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112     bowersj2 8301: $query.  The parameters listed in $possible_names (an array reference),
1.258     albertel 8302: will be set in $env{'form.name'} if they do not already exist.
1.112     bowersj2 8303: 
                   8304: Typically called with $ENV{'QUERY_STRING'} as the first parameter.  
                   8305: $possible_names is an ref to an array of form element names.  As an example:
                   8306: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258     albertel 8307: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112     bowersj2 8308: 
                   8309: =cut
1.1       albertel 8310: 
1.6       albertel 8311: sub get_unprocessed_cgi {
1.25      albertel 8312:   my ($query,$possible_names)= @_;
1.26      matthew  8313:   # $Apache::lonxml::debug=1;
1.356     albertel 8314:   foreach my $pair (split(/&/,$query)) {
                   8315:     my ($name, $value) = split(/=/,$pair);
1.369     www      8316:     $name = &unescape($name);
1.25      albertel 8317:     if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
                   8318:       $value =~ tr/+/ /;
                   8319:       $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258     albertel 8320:       unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25      albertel 8321:     }
1.16      harris41 8322:   }
1.6       albertel 8323: }
                   8324: 
1.112     bowersj2 8325: =pod
                   8326: 
1.648     raeburn  8327: =item * &cacheheader() 
1.112     bowersj2 8328: 
                   8329: returns cache-controlling header code
                   8330: 
                   8331: =cut
                   8332: 
1.7       albertel 8333: sub cacheheader {
1.258     albertel 8334:     unless ($env{'request.method'} eq 'GET') { return ''; }
1.216     albertel 8335:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
                   8336:     my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7       albertel 8337:                 <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
                   8338:                 <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216     albertel 8339:     return $output;
1.7       albertel 8340: }
                   8341: 
1.112     bowersj2 8342: =pod
                   8343: 
1.648     raeburn  8344: =item * &no_cache($r) 
1.112     bowersj2 8345: 
                   8346: specifies header code to not have cache
                   8347: 
                   8348: =cut
                   8349: 
1.9       albertel 8350: sub no_cache {
1.216     albertel 8351:     my ($r) = @_;
                   8352:     if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258     albertel 8353: 	$env{'request.method'} ne 'GET') { return ''; }
1.216     albertel 8354:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
                   8355:     $r->no_cache(1);
                   8356:     $r->header_out("Expires" => $date);
                   8357:     $r->header_out("Pragma" => "no-cache");
1.123     www      8358: }
                   8359: 
                   8360: sub content_type {
1.181     albertel 8361:     my ($r,$type,$charset) = @_;
1.299     foxr     8362:     if ($r) {
                   8363: 	#  Note that printout.pl calls this with undef for $r.
                   8364: 	&no_cache($r);
                   8365:     }
1.258     albertel 8366:     if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181     albertel 8367:     unless ($charset) {
                   8368: 	$charset=&Apache::lonlocal::current_encoding;
                   8369:     }
                   8370:     if ($charset) { $type.='; charset='.$charset; }
                   8371:     if ($r) {
                   8372: 	$r->content_type($type);
                   8373:     } else {
                   8374: 	print("Content-type: $type\n\n");
                   8375:     }
1.9       albertel 8376: }
1.25      albertel 8377: 
1.112     bowersj2 8378: =pod
                   8379: 
1.648     raeburn  8380: =item * &add_to_env($name,$value) 
1.112     bowersj2 8381: 
1.258     albertel 8382: adds $name to the %env hash with value
1.112     bowersj2 8383: $value, if $name already exists, the entry is converted to an array
                   8384: reference and $value is added to the array.
                   8385: 
                   8386: =cut
                   8387: 
1.25      albertel 8388: sub add_to_env {
                   8389:   my ($name,$value)=@_;
1.258     albertel 8390:   if (defined($env{$name})) {
                   8391:     if (ref($env{$name})) {
1.25      albertel 8392:       #already have multiple values
1.258     albertel 8393:       push(@{ $env{$name} },$value);
1.25      albertel 8394:     } else {
                   8395:       #first time seeing multiple values, convert hash entry to an arrayref
1.258     albertel 8396:       my $first=$env{$name};
                   8397:       undef($env{$name});
                   8398:       push(@{ $env{$name} },$first,$value);
1.25      albertel 8399:     }
                   8400:   } else {
1.258     albertel 8401:     $env{$name}=$value;
1.25      albertel 8402:   }
1.31      albertel 8403: }
1.149     albertel 8404: 
                   8405: =pod
                   8406: 
1.648     raeburn  8407: =item * &get_env_multiple($name) 
1.149     albertel 8408: 
1.258     albertel 8409: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149     albertel 8410: values may be defined and end up as an array ref.
                   8411: 
                   8412: returns an array of values
                   8413: 
                   8414: =cut
                   8415: 
                   8416: sub get_env_multiple {
                   8417:     my ($name) = @_;
                   8418:     my @values;
1.258     albertel 8419:     if (defined($env{$name})) {
1.149     albertel 8420:         # exists is it an array
1.258     albertel 8421:         if (ref($env{$name})) {
                   8422:             @values=@{ $env{$name} };
1.149     albertel 8423:         } else {
1.258     albertel 8424:             $values[0]=$env{$name};
1.149     albertel 8425:         }
                   8426:     }
                   8427:     return(@values);
                   8428: }
                   8429: 
1.660     raeburn  8430: sub ask_for_embedded_content {
                   8431:     my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
                   8432:     my $upload_output = '
                   8433:    <form name="upload_embedded" action="'.$actionurl.'"
                   8434:                   method="post" enctype="multipart/form-data">';
                   8435:     $upload_output .= $state;
1.661     raeburn  8436:     $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
1.660     raeburn  8437: 
                   8438:     my $num = 0;
                   8439:     foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
                   8440:         $upload_output .= &start_data_table_row().
                   8441:             '<td>'.$embed_file.'</td><td>';
                   8442:         if ($args->{'ignore_remote_references'}
                   8443:             && $embed_file =~ m{^\w+://}) {
                   8444:             $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
                   8445:         } elsif ($args->{'error_on_invalid_names'}
                   8446:             && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
                   8447: 
                   8448:             $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
                   8449: 
                   8450:         } else {
                   8451:             $upload_output .='
1.661     raeburn  8452:            <input name="embedded_item_'.$num.'" type="file" value="" />
1.660     raeburn  8453:            <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
                   8454:             my $attrib = join(':',@{$$allfiles{$embed_file}});
                   8455:             $upload_output .=
                   8456:                 "\n\t\t".
                   8457:                 '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
                   8458:                 $attrib.'" />';
                   8459:             if (exists($$codebase{$embed_file})) {
                   8460:                 $upload_output .=
                   8461:                     "\n\t\t".
                   8462:                     '<input name="codebase_'.$num.'" type="hidden" value="'.
                   8463:                     &escape($$codebase{$embed_file}).'" />';
                   8464:             }
                   8465:         }
                   8466:         $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
                   8467:         $num++;
                   8468:     }
                   8469:     $upload_output .= &Apache::loncommon::end_data_table().'<br />
                   8470:    <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
                   8471:    <input type ="submit" value="'.&mt('Upload Listed Files').'" />
                   8472:    '.&mt('(only files for which a location has been provided will be uploaded)').'
                   8473:    </form>';
                   8474:     return $upload_output;
                   8475: }
                   8476: 
1.661     raeburn  8477: sub upload_embedded {
                   8478:     my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
                   8479:         $current_disk_usage) = @_;
                   8480:     my $output;
                   8481:     for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
                   8482:         next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
                   8483:         my $orig_uploaded_filename =
                   8484:             $env{'form.embedded_item_'.$i.'.filename'};
                   8485: 
                   8486:         $env{'form.embedded_orig_'.$i} =
                   8487:             &unescape($env{'form.embedded_orig_'.$i});
                   8488:         my ($path,$fname) =
                   8489:             ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
                   8490:         # no path, whole string is fname
                   8491:         if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
                   8492: 
                   8493:         $path = $env{'form.currentpath'}.$path;
                   8494:         $fname = &Apache::lonnet::clean_filename($fname);
                   8495:         # See if there is anything left
                   8496:         next if ($fname eq '');
                   8497: 
                   8498:         # Check if file already exists as a file or directory.
                   8499:         my ($state,$msg);
                   8500:         if ($context eq 'portfolio') {
                   8501:             my $port_path = $dirpath;
                   8502:             if ($group ne '') {
                   8503:                 $port_path = "groups/$group/$port_path";
                   8504:             }
                   8505:             ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
                   8506:                                               $dir_root,$port_path,$disk_quota,
                   8507:                                               $current_disk_usage,$uname,$udom);
                   8508:             if ($state eq 'will_exceed_quota'
                   8509:                 || $state eq 'file_locked'
                   8510:                 || $state eq 'file_exists' ) {
                   8511:                 $output .= $msg;
                   8512:                 next;
                   8513:             }
                   8514:         } elsif (($context eq 'author') || ($context eq 'testbank')) {
                   8515:             ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
                   8516:             if ($state eq 'exists') {
                   8517:                 $output .= $msg;
                   8518:                 next;
                   8519:             }
                   8520:         }
                   8521:         # Check if extension is valid
                   8522:         if (($fname =~ /\.(\w+)$/) &&
                   8523:             (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
                   8524:             $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
                   8525:             next;
                   8526:         } elsif (($fname =~ /\.(\w+)$/) &&
                   8527:                  (!defined(&Apache::loncommon::fileembstyle($1)))) {
                   8528:             $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
                   8529:             next;
                   8530:         } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
                   8531:             $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
                   8532:             next;
                   8533:         }
                   8534: 
                   8535:         $env{'form.embedded_item_'.$i.'.filename'}=$fname;
                   8536:         if ($context eq 'portfolio') {
                   8537:             my $result=
                   8538:                 &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
                   8539:                                                 $dirpath.$path);
                   8540:             if ($result !~ m|^/uploaded/|) {
                   8541:                 $output .= '<span class="LC_error">'
                   8542:                       .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
                   8543:                            ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
                   8544:                       .'</span><br />';
                   8545:                 next;
                   8546:             } else {
                   8547:                 $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
                   8548:                            $path.$fname.'</span>').'</p>';     
                   8549:             }
                   8550:         } else {
                   8551: # Save the file
                   8552:             my $target = $env{'form.embedded_item_'.$i};
                   8553:             my $fullpath = $dir_root.$dirpath.'/'.$path;
                   8554:             my $dest = $fullpath.$fname;
                   8555:             my $url = $url_root.$dirpath.'/'.$path.$fname;
                   8556:             my @parts=split(/\//,$fullpath);
                   8557:             my $count;
                   8558:             my $filepath = $dir_root;
                   8559:             for ($count=4;$count<=$#parts;$count++) {
                   8560:                 $filepath .= "/$parts[$count]";
                   8561:                 if ((-e $filepath)!=1) {
                   8562:                     mkdir($filepath,0770);
                   8563:                 }
                   8564:             }
                   8565:             my $fh;
                   8566:             if (!open($fh,'>'.$dest)) {
                   8567:                 &Apache::lonnet::logthis('Failed to create '.$dest);
                   8568:                 $output .= '<span class="LC_error">'.
                   8569:                            &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
                   8570:                            '</span><br />';
                   8571:             } else {
                   8572:                 if (!print $fh $env{'form.embedded_item_'.$i}) {
                   8573:                     &Apache::lonnet::logthis('Failed to write to '.$dest);
                   8574:                     $output .= '<span class="LC_error">'.
                   8575:                               &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
                   8576:                               '</span><br />';
                   8577:                 } else {
                   8578:                     if ($context eq 'testbank') {
                   8579:                         $output .= &mt('Embedded file uploaded successfully:').
                   8580:                                    '&nbsp;<a href="'.$url.'">'.
                   8581:                                    $orig_uploaded_filename.'</a><br />';
                   8582:                     } else {
1.705     tempelho 8583:                         $output .= '<span class=\"LC_fontsize_large\">'.
1.661     raeburn  8584:                                    &mt('View embedded file: [_1]','<a href="'.$url.'">'.
1.705     tempelho 8585:                                    $orig_uploaded_filename.'</a>').'</span><br />';
1.661     raeburn  8586:                     }
                   8587:                 }
                   8588:                 close($fh);
                   8589:             }
                   8590:         }
                   8591:     }
                   8592:     return $output;
                   8593: }
                   8594: 
                   8595: sub check_for_existing {
                   8596:     my ($path,$fname,$element) = @_;
                   8597:     my ($state,$msg);
                   8598:     if (-d $path.'/'.$fname) {
                   8599:         $state = 'exists';
                   8600:         $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
                   8601:     } elsif (-e $path.'/'.$fname) {
                   8602:         $state = 'exists';
                   8603:         $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
                   8604:     }
                   8605:     if ($state eq 'exists') {
                   8606:         $msg = '<span class="LC_error">'.$msg.'</span><br />';
                   8607:     }
                   8608:     return ($state,$msg);
                   8609: }
                   8610: 
                   8611: sub check_for_upload {
                   8612:     my ($path,$fname,$group,$element,$portfolio_root,$port_path,
                   8613:         $disk_quota,$current_disk_usage,$uname,$udom) = @_;
                   8614:     my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
                   8615:     my $getpropath = 1;
                   8616:     my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
                   8617:                                             $getpropath);
                   8618:     my $found_file = 0;
                   8619:     my $locked_file = 0;
                   8620:     foreach my $line (@dir_list) {
                   8621:         my ($file_name)=split(/\&/,$line,2);
                   8622:         if ($file_name eq $fname){
                   8623:             $file_name = $path.$file_name;
                   8624:             if ($group ne '') {
                   8625:                 $file_name = $group.$file_name;
                   8626:             }
                   8627:             $found_file = 1;
                   8628:             if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
                   8629:                 $locked_file = 1;
                   8630:             }
                   8631:         }
                   8632:     }
                   8633:     if (($current_disk_usage + $filesize) > $disk_quota){
                   8634:         my $msg = '<span class="LC_error">'.
                   8635:                 &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
                   8636:                   '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
                   8637:         return ('will_exceed_quota',$msg);
                   8638:     } elsif ($found_file) {
                   8639:         if ($locked_file) {
                   8640:             my $msg = '<span class="LC_error">';
                   8641:             $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>');
                   8642:             $msg .= '</span><br />';
                   8643:             $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
                   8644:             return ('file_locked',$msg);
                   8645:         } else {
                   8646:             my $msg = '<span class="LC_error">';
                   8647:             $msg .= &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$port_path.$env{'form.currentpath'});
                   8648:             $msg .= '</span>';
                   8649:             $msg .= '<br />';
                   8650:             $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
                   8651:             return ('file_exists',$msg);
                   8652:         }
                   8653:     }
                   8654: }
                   8655: 
1.31      albertel 8656: 
1.41      ng       8657: =pod
1.45      matthew  8658: 
1.464     albertel 8659: =back
1.41      ng       8660: 
1.112     bowersj2 8661: =head1 CSV Upload/Handling functions
1.38      albertel 8662: 
1.41      ng       8663: =over 4
                   8664: 
1.648     raeburn  8665: =item * &upfile_store($r)
1.41      ng       8666: 
                   8667: Store uploaded file, $r should be the HTTP Request object,
1.258     albertel 8668: needs $env{'form.upfile'}
1.41      ng       8669: returns $datatoken to be put into hidden field
                   8670: 
                   8671: =cut
1.31      albertel 8672: 
                   8673: sub upfile_store {
                   8674:     my $r=shift;
1.258     albertel 8675:     $env{'form.upfile'}=~s/\r/\n/gs;
                   8676:     $env{'form.upfile'}=~s/\f/\n/gs;
                   8677:     $env{'form.upfile'}=~s/\n+/\n/gs;
                   8678:     $env{'form.upfile'}=~s/\n+$//gs;
1.31      albertel 8679: 
1.258     albertel 8680:     my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
                   8681: 	'_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31      albertel 8682:     {
1.158     raeburn  8683:         my $datafile = $r->dir_config('lonDaemons').
                   8684:                            '/tmp/'.$datatoken.'.tmp';
                   8685:         if ( open(my $fh,">$datafile") ) {
1.258     albertel 8686:             print $fh $env{'form.upfile'};
1.158     raeburn  8687:             close($fh);
                   8688:         }
1.31      albertel 8689:     }
                   8690:     return $datatoken;
                   8691: }
                   8692: 
1.56      matthew  8693: =pod
                   8694: 
1.648     raeburn  8695: =item * &load_tmp_file($r)
1.41      ng       8696: 
                   8697: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258     albertel 8698: needs $env{'form.datatoken'},
                   8699: sets $env{'form.upfile'} to the contents of the file
1.41      ng       8700: 
                   8701: =cut
1.31      albertel 8702: 
                   8703: sub load_tmp_file {
                   8704:     my $r=shift;
                   8705:     my @studentdata=();
                   8706:     {
1.158     raeburn  8707:         my $studentfile = $r->dir_config('lonDaemons').
1.258     albertel 8708:                               '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158     raeburn  8709:         if ( open(my $fh,"<$studentfile") ) {
                   8710:             @studentdata=<$fh>;
                   8711:             close($fh);
                   8712:         }
1.31      albertel 8713:     }
1.258     albertel 8714:     $env{'form.upfile'}=join('',@studentdata);
1.31      albertel 8715: }
                   8716: 
1.56      matthew  8717: =pod
                   8718: 
1.648     raeburn  8719: =item * &upfile_record_sep()
1.41      ng       8720: 
                   8721: Separate uploaded file into records
                   8722: returns array of records,
1.258     albertel 8723: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41      ng       8724: 
                   8725: =cut
1.31      albertel 8726: 
                   8727: sub upfile_record_sep {
1.258     albertel 8728:     if ($env{'form.upfiletype'} eq 'xml') {
1.31      albertel 8729:     } else {
1.248     albertel 8730: 	my @records;
1.258     albertel 8731: 	foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248     albertel 8732: 	    if ($line=~/^\s*$/) { next; }
                   8733: 	    push(@records,$line);
                   8734: 	}
                   8735: 	return @records;
1.31      albertel 8736:     }
                   8737: }
                   8738: 
1.56      matthew  8739: =pod
                   8740: 
1.648     raeburn  8741: =item * &record_sep($record)
1.41      ng       8742: 
1.258     albertel 8743: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41      ng       8744: 
                   8745: =cut
                   8746: 
1.263     www      8747: sub takeleft {
                   8748:     my $index=shift;
                   8749:     return substr('0000'.$index,-4,4);
                   8750: }
                   8751: 
1.31      albertel 8752: sub record_sep {
                   8753:     my $record=shift;
                   8754:     my %components=();
1.258     albertel 8755:     if ($env{'form.upfiletype'} eq 'xml') {
                   8756:     } elsif ($env{'form.upfiletype'} eq 'space') {
1.31      albertel 8757:         my $i=0;
1.356     albertel 8758:         foreach my $field (split(/\s+/,$record)) {
1.31      albertel 8759:             $field=~s/^(\"|\')//;
                   8760:             $field=~s/(\"|\')$//;
1.263     www      8761:             $components{&takeleft($i)}=$field;
1.31      albertel 8762:             $i++;
                   8763:         }
1.258     albertel 8764:     } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31      albertel 8765:         my $i=0;
1.356     albertel 8766:         foreach my $field (split(/\t/,$record)) {
1.31      albertel 8767:             $field=~s/^(\"|\')//;
                   8768:             $field=~s/(\"|\')$//;
1.263     www      8769:             $components{&takeleft($i)}=$field;
1.31      albertel 8770:             $i++;
                   8771:         }
                   8772:     } else {
1.561     www      8773:         my $separator=',';
1.480     banghart 8774:         if ($env{'form.upfiletype'} eq 'semisv') {
1.561     www      8775:             $separator=';';
1.480     banghart 8776:         }
1.31      albertel 8777:         my $i=0;
1.561     www      8778: # the character we are looking for to indicate the end of a quote or a record 
                   8779:         my $looking_for=$separator;
                   8780: # do not add the characters to the fields
                   8781:         my $ignore=0;
                   8782: # we just encountered a separator (or the beginning of the record)
                   8783:         my $just_found_separator=1;
                   8784: # store the field we are working on here
                   8785:         my $field='';
                   8786: # work our way through all characters in record
                   8787:         foreach my $character ($record=~/(.)/g) {
                   8788:             if ($character eq $looking_for) {
                   8789:                if ($character ne $separator) {
                   8790: # Found the end of a quote, again looking for separator
                   8791:                   $looking_for=$separator;
                   8792:                   $ignore=1;
                   8793:                } else {
                   8794: # Found a separator, store away what we got
                   8795:                   $components{&takeleft($i)}=$field;
                   8796: 	          $i++;
                   8797:                   $just_found_separator=1;
                   8798:                   $ignore=0;
                   8799:                   $field='';
                   8800:                }
                   8801:                next;
                   8802:             }
                   8803: # single or double quotation marks after a separator indicate beginning of a quote
                   8804: # we are now looking for the end of the quote and need to ignore separators
                   8805:             if ((($character eq '"') || ($character eq "'")) && ($just_found_separator))  {
                   8806:                $looking_for=$character;
                   8807:                next;
                   8808:             }
                   8809: # ignore would be true after we reached the end of a quote
                   8810:             if ($ignore) { next; }
                   8811:             if (($just_found_separator) && ($character=~/\s/)) { next; }
                   8812:             $field.=$character;
                   8813:             $just_found_separator=0; 
1.31      albertel 8814:         }
1.561     www      8815: # catch the very last entry, since we never encountered the separator
                   8816:         $components{&takeleft($i)}=$field;
1.31      albertel 8817:     }
                   8818:     return %components;
                   8819: }
                   8820: 
1.144     matthew  8821: ######################################################
                   8822: ######################################################
                   8823: 
1.56      matthew  8824: =pod
                   8825: 
1.648     raeburn  8826: =item * &upfile_select_html()
1.41      ng       8827: 
1.144     matthew  8828: Return HTML code to select a file from the users machine and specify 
                   8829: the file type.
1.41      ng       8830: 
                   8831: =cut
                   8832: 
1.144     matthew  8833: ######################################################
                   8834: ######################################################
1.31      albertel 8835: sub upfile_select_html {
1.144     matthew  8836:     my %Types = (
                   8837:                  csv   => &mt('CSV (comma separated values, spreadsheet)'),
1.480     banghart 8838:                  semisv => &mt('Semicolon separated values'),
1.144     matthew  8839:                  space => &mt('Space separated'),
                   8840:                  tab   => &mt('Tabulator separated'),
                   8841: #                 xml   => &mt('HTML/XML'),
                   8842:                  );
                   8843:     my $Str = '<input type="file" name="upfile" size="50" />'.
1.727     riegler  8844:         '<br />'.&mt('Type').': <select name="upfiletype">';
1.144     matthew  8845:     foreach my $type (sort(keys(%Types))) {
                   8846:         $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
                   8847:     }
                   8848:     $Str .= "</select>\n";
                   8849:     return $Str;
1.31      albertel 8850: }
                   8851: 
1.301     albertel 8852: sub get_samples {
                   8853:     my ($records,$toget) = @_;
                   8854:     my @samples=({});
                   8855:     my $got=0;
                   8856:     foreach my $rec (@$records) {
                   8857: 	my %temp = &record_sep($rec);
                   8858: 	if (! grep(/\S/, values(%temp))) { next; }
                   8859: 	if (%temp) {
                   8860: 	    $samples[$got]=\%temp;
                   8861: 	    $got++;
                   8862: 	    if ($got == $toget) { last; }
                   8863: 	}
                   8864:     }
                   8865:     return \@samples;
                   8866: }
                   8867: 
1.144     matthew  8868: ######################################################
                   8869: ######################################################
                   8870: 
1.56      matthew  8871: =pod
                   8872: 
1.648     raeburn  8873: =item * &csv_print_samples($r,$records)
1.41      ng       8874: 
                   8875: Prints a table of sample values from each column uploaded $r is an
                   8876: Apache Request ref, $records is an arrayref from
                   8877: &Apache::loncommon::upfile_record_sep
                   8878: 
                   8879: =cut
                   8880: 
1.144     matthew  8881: ######################################################
                   8882: ######################################################
1.31      albertel 8883: sub csv_print_samples {
                   8884:     my ($r,$records) = @_;
1.662     bisitz   8885:     my $samples = &get_samples($records,5);
1.301     albertel 8886: 
1.594     raeburn  8887:     $r->print(&mt('Samples').'<br />'.&start_data_table().
                   8888:               &start_data_table_header_row());
1.356     albertel 8889:     foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) { 
1.845     bisitz   8890:         $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594     raeburn  8891:     $r->print(&end_data_table_header_row());
1.301     albertel 8892:     foreach my $hash (@$samples) {
1.594     raeburn  8893: 	$r->print(&start_data_table_row());
1.356     albertel 8894: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31      albertel 8895: 	    $r->print('<td>');
1.356     albertel 8896: 	    if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31      albertel 8897: 	    $r->print('</td>');
                   8898: 	}
1.594     raeburn  8899: 	$r->print(&end_data_table_row());
1.31      albertel 8900:     }
1.594     raeburn  8901:     $r->print(&end_data_table().'<br />'."\n");
1.31      albertel 8902: }
                   8903: 
1.144     matthew  8904: ######################################################
                   8905: ######################################################
                   8906: 
1.56      matthew  8907: =pod
                   8908: 
1.648     raeburn  8909: =item * &csv_print_select_table($r,$records,$d)
1.41      ng       8910: 
                   8911: Prints a table to create associations between values and table columns.
1.144     matthew  8912: 
1.41      ng       8913: $r is an Apache Request ref,
                   8914: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174     matthew  8915: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41      ng       8916: 
                   8917: =cut
                   8918: 
1.144     matthew  8919: ######################################################
                   8920: ######################################################
1.31      albertel 8921: sub csv_print_select_table {
                   8922:     my ($r,$records,$d) = @_;
1.301     albertel 8923:     my $i=0;
                   8924:     my $samples = &get_samples($records,1);
1.144     matthew  8925:     $r->print(&mt('Associate columns with student attributes.')."\n".
1.594     raeburn  8926: 	      &start_data_table().&start_data_table_header_row().
1.144     matthew  8927:               '<th>'.&mt('Attribute').'</th>'.
1.594     raeburn  8928:               '<th>'.&mt('Column').'</th>'.
                   8929:               &end_data_table_header_row()."\n");
1.356     albertel 8930:     foreach my $array_ref (@$d) {
                   8931: 	my ($value,$display,$defaultcol)=@{ $array_ref };
1.729     raeburn  8932: 	$r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31      albertel 8933: 
1.875     bisitz   8934: 	$r->print('<td><select name="f'.$i.'"'.
1.32      matthew  8935: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.31      albertel 8936: 	$r->print('<option value="none"></option>');
1.356     albertel 8937: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
                   8938: 	    $r->print('<option value="'.$sample.'"'.
                   8939:                       ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662     bisitz   8940:                       '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31      albertel 8941: 	}
1.594     raeburn  8942: 	$r->print('</select></td>'.&end_data_table_row()."\n");
1.31      albertel 8943: 	$i++;
                   8944:     }
1.594     raeburn  8945:     $r->print(&end_data_table());
1.31      albertel 8946:     $i--;
                   8947:     return $i;
                   8948: }
1.56      matthew  8949: 
1.144     matthew  8950: ######################################################
                   8951: ######################################################
                   8952: 
1.56      matthew  8953: =pod
1.31      albertel 8954: 
1.648     raeburn  8955: =item * &csv_samples_select_table($r,$records,$d)
1.41      ng       8956: 
                   8957: Prints a table of sample values from the upload and can make associate samples to internal names.
                   8958: 
                   8959: $r is an Apache Request ref,
                   8960: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
                   8961: $d is an array of 2 element arrays (internal name, displayed name)
                   8962: 
                   8963: =cut
                   8964: 
1.144     matthew  8965: ######################################################
                   8966: ######################################################
1.31      albertel 8967: sub csv_samples_select_table {
                   8968:     my ($r,$records,$d) = @_;
                   8969:     my $i=0;
1.144     matthew  8970:     #
1.662     bisitz   8971:     my $max_samples = 5;
                   8972:     my $samples = &get_samples($records,$max_samples);
1.594     raeburn  8973:     $r->print(&start_data_table().
                   8974:               &start_data_table_header_row().'<th>'.
                   8975:               &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
                   8976:               &end_data_table_header_row());
1.301     albertel 8977: 
                   8978:     foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594     raeburn  8979: 	$r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32      matthew  8980: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.301     albertel 8981: 	foreach my $option (@$d) {
                   8982: 	    my ($value,$display,$defaultcol)=@{ $option };
1.174     matthew  8983: 	    $r->print('<option value="'.$value.'"'.
1.253     albertel 8984:                       ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174     matthew  8985:                       $display.'</option>');
1.31      albertel 8986: 	}
                   8987: 	$r->print('</select></td><td>');
1.662     bisitz   8988: 	foreach my $line (0..($max_samples-1)) {
1.301     albertel 8989: 	    if (defined($samples->[$line]{$key})) { 
                   8990: 		$r->print($samples->[$line]{$key}."<br />\n"); 
                   8991: 	    }
                   8992: 	}
1.594     raeburn  8993: 	$r->print('</td>'.&end_data_table_row());
1.31      albertel 8994: 	$i++;
                   8995:     }
1.594     raeburn  8996:     $r->print(&end_data_table());
1.31      albertel 8997:     $i--;
                   8998:     return($i);
1.115     matthew  8999: }
                   9000: 
1.144     matthew  9001: ######################################################
                   9002: ######################################################
                   9003: 
1.115     matthew  9004: =pod
                   9005: 
1.648     raeburn  9006: =item * &clean_excel_name($name)
1.115     matthew  9007: 
                   9008: Returns a replacement for $name which does not contain any illegal characters.
                   9009: 
                   9010: =cut
                   9011: 
1.144     matthew  9012: ######################################################
                   9013: ######################################################
1.115     matthew  9014: sub clean_excel_name {
                   9015:     my ($name) = @_;
                   9016:     $name =~ s/[:\*\?\/\\]//g;
                   9017:     if (length($name) > 31) {
                   9018:         $name = substr($name,0,31);
                   9019:     }
                   9020:     return $name;
1.25      albertel 9021: }
1.84      albertel 9022: 
1.85      albertel 9023: =pod
                   9024: 
1.648     raeburn  9025: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85      albertel 9026: 
                   9027: Returns either 1 or undef
                   9028: 
                   9029: 1 if the part is to be hidden, undef if it is to be shown
                   9030: 
                   9031: Arguments are:
                   9032: 
                   9033: $id the id of the part to be checked
                   9034: $symb, optional the symb of the resource to check
                   9035: $udom, optional the domain of the user to check for
                   9036: $uname, optional the username of the user to check for
                   9037: 
                   9038: =cut
1.84      albertel 9039: 
                   9040: sub check_if_partid_hidden {
                   9041:     my ($id,$symb,$udom,$uname) = @_;
1.133     albertel 9042:     my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84      albertel 9043: 					 $symb,$udom,$uname);
1.141     albertel 9044:     my $truth=1;
                   9045:     #if the string starts with !, then the list is the list to show not hide
                   9046:     if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84      albertel 9047:     my @hiddenlist=split(/,/,$hiddenparts);
                   9048:     foreach my $checkid (@hiddenlist) {
1.141     albertel 9049: 	if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84      albertel 9050:     }
1.141     albertel 9051:     return !$truth;
1.84      albertel 9052: }
1.127     matthew  9053: 
1.138     matthew  9054: 
                   9055: ############################################################
                   9056: ############################################################
                   9057: 
                   9058: =pod
                   9059: 
1.157     matthew  9060: =back 
                   9061: 
1.138     matthew  9062: =head1 cgi-bin script and graphing routines
                   9063: 
1.157     matthew  9064: =over 4
                   9065: 
1.648     raeburn  9066: =item * &get_cgi_id()
1.138     matthew  9067: 
                   9068: Inputs: none
                   9069: 
                   9070: Returns an id which can be used to pass environment variables
                   9071: to various cgi-bin scripts.  These environment variables will
                   9072: be removed from the users environment after a given time by
                   9073: the routine &Apache::lonnet::transfer_profile_to_env.
                   9074: 
                   9075: =cut
                   9076: 
                   9077: ############################################################
                   9078: ############################################################
1.152     albertel 9079: my $uniq=0;
1.136     matthew  9080: sub get_cgi_id {
1.154     albertel 9081:     $uniq=($uniq+1)%100000;
1.280     albertel 9082:     return (time.'_'.$$.'_'.$uniq);
1.136     matthew  9083: }
                   9084: 
1.127     matthew  9085: ############################################################
                   9086: ############################################################
                   9087: 
                   9088: =pod
                   9089: 
1.648     raeburn  9090: =item * &DrawBarGraph()
1.127     matthew  9091: 
1.138     matthew  9092: Facilitates the plotting of data in a (stacked) bar graph.
                   9093: Puts plot definition data into the users environment in order for 
                   9094: graph.png to plot it.  Returns an <img> tag for the plot.
                   9095: The bars on the plot are labeled '1','2',...,'n'.
                   9096: 
                   9097: Inputs:
                   9098: 
                   9099: =over 4
                   9100: 
                   9101: =item $Title: string, the title of the plot
                   9102: 
                   9103: =item $xlabel: string, text describing the X-axis of the plot
                   9104: 
                   9105: =item $ylabel: string, text describing the Y-axis of the plot
                   9106: 
                   9107: =item $Max: scalar, the maximum Y value to use in the plot
                   9108: If $Max is < any data point, the graph will not be rendered.
                   9109: 
1.140     matthew  9110: =item $colors: array ref holding the colors to be used for the data sets when
1.138     matthew  9111: they are plotted.  If undefined, default values will be used.
                   9112: 
1.178     matthew  9113: =item $labels: array ref holding the labels to use on the x-axis for the bars.
                   9114: 
1.138     matthew  9115: =item @Values: An array of array references.  Each array reference holds data
                   9116: to be plotted in a stacked bar chart.
                   9117: 
1.239     matthew  9118: =item If the final element of @Values is a hash reference the key/value
                   9119: pairs will be added to the graph definition.
                   9120: 
1.138     matthew  9121: =back
                   9122: 
                   9123: Returns:
                   9124: 
                   9125: An <img> tag which references graph.png and the appropriate identifying
                   9126: information for the plot.
                   9127: 
1.127     matthew  9128: =cut
                   9129: 
                   9130: ############################################################
                   9131: ############################################################
1.134     matthew  9132: sub DrawBarGraph {
1.178     matthew  9133:     my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134     matthew  9134:     #
                   9135:     if (! defined($colors)) {
                   9136:         $colors = ['#33ff00', 
                   9137:                   '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
                   9138:                   '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
                   9139:                   ]; 
                   9140:     }
1.228     matthew  9141:     my $extra_settings = {};
                   9142:     if (ref($Values[-1]) eq 'HASH') {
                   9143:         $extra_settings = pop(@Values);
                   9144:     }
1.127     matthew  9145:     #
1.136     matthew  9146:     my $identifier = &get_cgi_id();
                   9147:     my $id = 'cgi.'.$identifier;        
1.129     matthew  9148:     if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127     matthew  9149:         return '';
                   9150:     }
1.225     matthew  9151:     #
                   9152:     my @Labels;
                   9153:     if (defined($labels)) {
                   9154:         @Labels = @$labels;
                   9155:     } else {
                   9156:         for (my $i=0;$i<@{$Values[0]};$i++) {
                   9157:             push (@Labels,$i+1);
                   9158:         }
                   9159:     }
                   9160:     #
1.129     matthew  9161:     my $NumBars = scalar(@{$Values[0]});
1.225     matthew  9162:     if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129     matthew  9163:     my %ValuesHash;
                   9164:     my $NumSets=1;
                   9165:     foreach my $array (@Values) {
                   9166:         next if (! ref($array));
1.136     matthew  9167:         $ValuesHash{$id.'.data.'.$NumSets++} = 
1.132     matthew  9168:             join(',',@$array);
1.129     matthew  9169:     }
1.127     matthew  9170:     #
1.136     matthew  9171:     my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225     matthew  9172:     if ($NumBars < 3) {
                   9173:         $width = 120+$NumBars*32;
1.220     matthew  9174:         $xskip = 1;
1.225     matthew  9175:         $bar_width = 30;
                   9176:     } elsif ($NumBars < 5) {
                   9177:         $width = 120+$NumBars*20;
                   9178:         $xskip = 1;
                   9179:         $bar_width = 20;
1.220     matthew  9180:     } elsif ($NumBars < 10) {
1.136     matthew  9181:         $width = 120+$NumBars*15;
                   9182:         $xskip = 1;
                   9183:         $bar_width = 15;
                   9184:     } elsif ($NumBars <= 25) {
                   9185:         $width = 120+$NumBars*11;
                   9186:         $xskip = 5;
                   9187:         $bar_width = 8;
                   9188:     } elsif ($NumBars <= 50) {
                   9189:         $width = 120+$NumBars*8;
                   9190:         $xskip = 5;
                   9191:         $bar_width = 4;
                   9192:     } else {
                   9193:         $width = 120+$NumBars*8;
                   9194:         $xskip = 5;
                   9195:         $bar_width = 4;
                   9196:     }
                   9197:     #
1.137     matthew  9198:     $Max = 1 if ($Max < 1);
                   9199:     if ( int($Max) < $Max ) {
                   9200:         $Max++;
                   9201:         $Max = int($Max);
                   9202:     }
1.127     matthew  9203:     $Title  = '' if (! defined($Title));
                   9204:     $xlabel = '' if (! defined($xlabel));
                   9205:     $ylabel = '' if (! defined($ylabel));
1.369     www      9206:     $ValuesHash{$id.'.title'}    = &escape($Title);
                   9207:     $ValuesHash{$id.'.xlabel'}   = &escape($xlabel);
                   9208:     $ValuesHash{$id.'.ylabel'}   = &escape($ylabel);
1.137     matthew  9209:     $ValuesHash{$id.'.y_max_value'} = $Max;
1.136     matthew  9210:     $ValuesHash{$id.'.NumBars'}  = $NumBars;
                   9211:     $ValuesHash{$id.'.NumSets'}  = $NumSets;
                   9212:     $ValuesHash{$id.'.PlotType'} = 'bar';
                   9213:     $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   9214:     $ValuesHash{$id.'.height'}   = $height;
                   9215:     $ValuesHash{$id.'.width'}    = $width;
                   9216:     $ValuesHash{$id.'.xskip'}    = $xskip;
                   9217:     $ValuesHash{$id.'.bar_width'} = $bar_width;
                   9218:     $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127     matthew  9219:     #
1.228     matthew  9220:     # Deal with other parameters
                   9221:     while (my ($key,$value) = each(%$extra_settings)) {
                   9222:         $ValuesHash{$id.'.'.$key} = $value;
                   9223:     }
                   9224:     #
1.646     raeburn  9225:     &Apache::lonnet::appenv(\%ValuesHash);
1.137     matthew  9226:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   9227: }
                   9228: 
                   9229: ############################################################
                   9230: ############################################################
                   9231: 
                   9232: =pod
                   9233: 
1.648     raeburn  9234: =item * &DrawXYGraph()
1.137     matthew  9235: 
1.138     matthew  9236: Facilitates the plotting of data in an XY graph.
                   9237: Puts plot definition data into the users environment in order for 
                   9238: graph.png to plot it.  Returns an <img> tag for the plot.
                   9239: 
                   9240: Inputs:
                   9241: 
                   9242: =over 4
                   9243: 
                   9244: =item $Title: string, the title of the plot
                   9245: 
                   9246: =item $xlabel: string, text describing the X-axis of the plot
                   9247: 
                   9248: =item $ylabel: string, text describing the Y-axis of the plot
                   9249: 
                   9250: =item $Max: scalar, the maximum Y value to use in the plot
                   9251: If $Max is < any data point, the graph will not be rendered.
                   9252: 
                   9253: =item $colors: Array ref containing the hex color codes for the data to be 
                   9254: plotted in.  If undefined, default values will be used.
                   9255: 
                   9256: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   9257: 
                   9258: =item $Ydata: Array ref containing Array refs.  
1.185     www      9259: Each of the contained arrays will be plotted as a separate curve.
1.138     matthew  9260: 
                   9261: =item %Values: hash indicating or overriding any default values which are 
                   9262: passed to graph.png.  
                   9263: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   9264: 
                   9265: =back
                   9266: 
                   9267: Returns:
                   9268: 
                   9269: An <img> tag which references graph.png and the appropriate identifying
                   9270: information for the plot.
                   9271: 
1.137     matthew  9272: =cut
                   9273: 
                   9274: ############################################################
                   9275: ############################################################
                   9276: sub DrawXYGraph {
                   9277:     my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
                   9278:     #
                   9279:     # Create the identifier for the graph
                   9280:     my $identifier = &get_cgi_id();
                   9281:     my $id = 'cgi.'.$identifier;
                   9282:     #
                   9283:     $Title  = '' if (! defined($Title));
                   9284:     $xlabel = '' if (! defined($xlabel));
                   9285:     $ylabel = '' if (! defined($ylabel));
                   9286:     my %ValuesHash = 
                   9287:         (
1.369     www      9288:          $id.'.title'  => &escape($Title),
                   9289:          $id.'.xlabel' => &escape($xlabel),
                   9290:          $id.'.ylabel' => &escape($ylabel),
1.137     matthew  9291:          $id.'.y_max_value'=> $Max,
                   9292:          $id.'.labels'     => join(',',@$Xlabels),
                   9293:          $id.'.PlotType'   => 'XY',
                   9294:          );
                   9295:     #
                   9296:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   9297:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   9298:     }
                   9299:     #
                   9300:     if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
                   9301:         return '';
                   9302:     }
                   9303:     my $NumSets=1;
1.138     matthew  9304:     foreach my $array (@{$Ydata}){
1.137     matthew  9305:         next if (! ref($array));
                   9306:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
                   9307:     }
1.138     matthew  9308:     $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137     matthew  9309:     #
                   9310:     # Deal with other parameters
                   9311:     while (my ($key,$value) = each(%Values)) {
                   9312:         $ValuesHash{$id.'.'.$key} = $value;
1.127     matthew  9313:     }
                   9314:     #
1.646     raeburn  9315:     &Apache::lonnet::appenv(\%ValuesHash);
1.136     matthew  9316:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   9317: }
                   9318: 
                   9319: ############################################################
                   9320: ############################################################
                   9321: 
                   9322: =pod
                   9323: 
1.648     raeburn  9324: =item * &DrawXYYGraph()
1.138     matthew  9325: 
                   9326: Facilitates the plotting of data in an XY graph with two Y axes.
                   9327: Puts plot definition data into the users environment in order for 
                   9328: graph.png to plot it.  Returns an <img> tag for the plot.
                   9329: 
                   9330: Inputs:
                   9331: 
                   9332: =over 4
                   9333: 
                   9334: =item $Title: string, the title of the plot
                   9335: 
                   9336: =item $xlabel: string, text describing the X-axis of the plot
                   9337: 
                   9338: =item $ylabel: string, text describing the Y-axis of the plot
                   9339: 
                   9340: =item $colors: Array ref containing the hex color codes for the data to be 
                   9341: plotted in.  If undefined, default values will be used.
                   9342: 
                   9343: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   9344: 
                   9345: =item $Ydata1: The first data set
                   9346: 
                   9347: =item $Min1: The minimum value of the left Y-axis
                   9348: 
                   9349: =item $Max1: The maximum value of the left Y-axis
                   9350: 
                   9351: =item $Ydata2: The second data set
                   9352: 
                   9353: =item $Min2: The minimum value of the right Y-axis
                   9354: 
                   9355: =item $Max2: The maximum value of the left Y-axis
                   9356: 
                   9357: =item %Values: hash indicating or overriding any default values which are 
                   9358: passed to graph.png.  
                   9359: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   9360: 
                   9361: =back
                   9362: 
                   9363: Returns:
                   9364: 
                   9365: An <img> tag which references graph.png and the appropriate identifying
                   9366: information for the plot.
1.136     matthew  9367: 
                   9368: =cut
                   9369: 
                   9370: ############################################################
                   9371: ############################################################
1.137     matthew  9372: sub DrawXYYGraph {
                   9373:     my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
                   9374:                                         $Ydata2,$Min2,$Max2,%Values)=@_;
1.136     matthew  9375:     #
                   9376:     # Create the identifier for the graph
                   9377:     my $identifier = &get_cgi_id();
                   9378:     my $id = 'cgi.'.$identifier;
                   9379:     #
                   9380:     $Title  = '' if (! defined($Title));
                   9381:     $xlabel = '' if (! defined($xlabel));
                   9382:     $ylabel = '' if (! defined($ylabel));
                   9383:     my %ValuesHash = 
                   9384:         (
1.369     www      9385:          $id.'.title'  => &escape($Title),
                   9386:          $id.'.xlabel' => &escape($xlabel),
                   9387:          $id.'.ylabel' => &escape($ylabel),
1.136     matthew  9388:          $id.'.labels' => join(',',@$Xlabels),
                   9389:          $id.'.PlotType' => 'XY',
                   9390:          $id.'.NumSets' => 2,
1.137     matthew  9391:          $id.'.two_axes' => 1,
                   9392:          $id.'.y1_max_value' => $Max1,
                   9393:          $id.'.y1_min_value' => $Min1,
                   9394:          $id.'.y2_max_value' => $Max2,
                   9395:          $id.'.y2_min_value' => $Min2,
1.136     matthew  9396:          );
                   9397:     #
1.137     matthew  9398:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   9399:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   9400:     }
                   9401:     #
                   9402:     if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
                   9403:         ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136     matthew  9404:         return '';
                   9405:     }
                   9406:     my $NumSets=1;
1.137     matthew  9407:     foreach my $array ($Ydata1,$Ydata2){
1.136     matthew  9408:         next if (! ref($array));
                   9409:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137     matthew  9410:     }
                   9411:     #
                   9412:     # Deal with other parameters
                   9413:     while (my ($key,$value) = each(%Values)) {
                   9414:         $ValuesHash{$id.'.'.$key} = $value;
1.136     matthew  9415:     }
                   9416:     #
1.646     raeburn  9417:     &Apache::lonnet::appenv(\%ValuesHash);
1.130     albertel 9418:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139     matthew  9419: }
                   9420: 
                   9421: ############################################################
                   9422: ############################################################
                   9423: 
                   9424: =pod
                   9425: 
1.157     matthew  9426: =back 
                   9427: 
1.139     matthew  9428: =head1 Statistics helper routines?  
                   9429: 
                   9430: Bad place for them but what the hell.
                   9431: 
1.157     matthew  9432: =over 4
                   9433: 
1.648     raeburn  9434: =item * &chartlink()
1.139     matthew  9435: 
                   9436: Returns a link to the chart for a specific student.  
                   9437: 
                   9438: Inputs:
                   9439: 
                   9440: =over 4
                   9441: 
                   9442: =item $linktext: The text of the link
                   9443: 
                   9444: =item $sname: The students username
                   9445: 
                   9446: =item $sdomain: The students domain
                   9447: 
                   9448: =back
                   9449: 
1.157     matthew  9450: =back
                   9451: 
1.139     matthew  9452: =cut
                   9453: 
                   9454: ############################################################
                   9455: ############################################################
                   9456: sub chartlink {
                   9457:     my ($linktext, $sname, $sdomain) = @_;
                   9458:     my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369     www      9459:         '&amp;SelectedStudent='.&escape($sname.':'.$sdomain).
1.219     albertel 9460:         '&amp;chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139     matthew  9461:        '">'.$linktext.'</a>';
1.153     matthew  9462: }
                   9463: 
                   9464: #######################################################
                   9465: #######################################################
                   9466: 
                   9467: =pod
                   9468: 
                   9469: =head1 Course Environment Routines
1.157     matthew  9470: 
                   9471: =over 4
1.153     matthew  9472: 
1.648     raeburn  9473: =item * &restore_course_settings()
1.153     matthew  9474: 
1.648     raeburn  9475: =item * &store_course_settings()
1.153     matthew  9476: 
                   9477: Restores/Store indicated form parameters from the course environment.
                   9478: Will not overwrite existing values of the form parameters.
                   9479: 
                   9480: Inputs: 
                   9481: a scalar describing the data (e.g. 'chart', 'problem_analysis')
                   9482: 
                   9483: a hash ref describing the data to be stored.  For example:
                   9484:    
                   9485: %Save_Parameters = ('Status' => 'scalar',
                   9486:     'chartoutputmode' => 'scalar',
                   9487:     'chartoutputdata' => 'scalar',
                   9488:     'Section' => 'array',
1.373     raeburn  9489:     'Group' => 'array',
1.153     matthew  9490:     'StudentData' => 'array',
                   9491:     'Maps' => 'array');
                   9492: 
                   9493: Returns: both routines return nothing
                   9494: 
1.631     raeburn  9495: =back
                   9496: 
1.153     matthew  9497: =cut
                   9498: 
                   9499: #######################################################
                   9500: #######################################################
                   9501: sub store_course_settings {
1.496     albertel 9502:     return &store_settings($env{'request.course.id'},@_);
                   9503: }
                   9504: 
                   9505: sub store_settings {
1.153     matthew  9506:     # save to the environment
                   9507:     # appenv the same items, just to be safe
1.300     albertel 9508:     my $udom  = $env{'user.domain'};
                   9509:     my $uname = $env{'user.name'};
1.496     albertel 9510:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  9511:     my %SaveHash;
                   9512:     my %AppHash;
                   9513:     while (my ($setting,$type) = each(%$Settings)) {
1.496     albertel 9514:         my $basename = join('.','internal',$context,$prefix,$setting);
1.300     albertel 9515:         my $envname = 'environment.'.$basename;
1.258     albertel 9516:         if (exists($env{'form.'.$setting})) {
1.153     matthew  9517:             # Save this value away
                   9518:             if ($type eq 'scalar' &&
1.258     albertel 9519:                 (! exists($env{$envname}) || 
                   9520:                  $env{$envname} ne $env{'form.'.$setting})) {
                   9521:                 $SaveHash{$basename} = $env{'form.'.$setting};
                   9522:                 $AppHash{$envname}   = $env{'form.'.$setting};
1.153     matthew  9523:             } elsif ($type eq 'array') {
                   9524:                 my $stored_form;
1.258     albertel 9525:                 if (ref($env{'form.'.$setting})) {
1.153     matthew  9526:                     $stored_form = join(',',
                   9527:                                         map {
1.369     www      9528:                                             &escape($_);
1.258     albertel 9529:                                         } sort(@{$env{'form.'.$setting}}));
1.153     matthew  9530:                 } else {
                   9531:                     $stored_form = 
1.369     www      9532:                         &escape($env{'form.'.$setting});
1.153     matthew  9533:                 }
                   9534:                 # Determine if the array contents are the same.
1.258     albertel 9535:                 if ($stored_form ne $env{$envname}) {
1.153     matthew  9536:                     $SaveHash{$basename} = $stored_form;
                   9537:                     $AppHash{$envname}   = $stored_form;
                   9538:                 }
                   9539:             }
                   9540:         }
                   9541:     }
                   9542:     my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300     albertel 9543:                                           $udom,$uname);
1.153     matthew  9544:     if ($put_result !~ /^(ok|delayed)/) {
                   9545:         &Apache::lonnet::logthis('unable to save form parameters, '.
                   9546:                                  'got error:'.$put_result);
                   9547:     }
                   9548:     # Make sure these settings stick around in this session, too
1.646     raeburn  9549:     &Apache::lonnet::appenv(\%AppHash);
1.153     matthew  9550:     return;
                   9551: }
                   9552: 
                   9553: sub restore_course_settings {
1.499     albertel 9554:     return &restore_settings($env{'request.course.id'},@_);
1.496     albertel 9555: }
                   9556: 
                   9557: sub restore_settings {
                   9558:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  9559:     while (my ($setting,$type) = each(%$Settings)) {
1.258     albertel 9560:         next if (exists($env{'form.'.$setting}));
1.496     albertel 9561:         my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153     matthew  9562:             '.'.$setting;
1.258     albertel 9563:         if (exists($env{$envname})) {
1.153     matthew  9564:             if ($type eq 'scalar') {
1.258     albertel 9565:                 $env{'form.'.$setting} = $env{$envname};
1.153     matthew  9566:             } elsif ($type eq 'array') {
1.258     albertel 9567:                 $env{'form.'.$setting} = [ 
1.153     matthew  9568:                                            map { 
1.369     www      9569:                                                &unescape($_); 
1.258     albertel 9570:                                            } split(',',$env{$envname})
1.153     matthew  9571:                                            ];
                   9572:             }
                   9573:         }
                   9574:     }
1.127     matthew  9575: }
                   9576: 
1.618     raeburn  9577: #######################################################
                   9578: #######################################################
                   9579: 
                   9580: =pod
                   9581: 
                   9582: =head1 Domain E-mail Routines  
                   9583: 
                   9584: =over 4
                   9585: 
1.648     raeburn  9586: =item * &build_recipient_list()
1.618     raeburn  9587: 
1.884     raeburn  9588: Build recipient lists for five types of e-mail:
1.766     raeburn  9589: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.884     raeburn  9590: (d) Help requests, (e) Course requests needing approval,  generated by
                   9591: lonerrorhandler.pm, CHECKRPMS, loncron, lonsupportreq.pm and
                   9592: loncoursequeueadmin.pm respectively.
1.618     raeburn  9593: 
                   9594: Inputs:
1.619     raeburn  9595: defmail (scalar - email address of default recipient), 
1.618     raeburn  9596: mailing type (scalar - errormail, packagesmail, or helpdeskmail), 
1.619     raeburn  9597: defdom (domain for which to retrieve configuration settings),
                   9598: origmail (scalar - email address of recipient from loncapa.conf, 
                   9599: i.e., predates configuration by DC via domainprefs.pm 
1.618     raeburn  9600: 
1.655     raeburn  9601: Returns: comma separated list of addresses to which to send e-mail.
                   9602: 
                   9603: =back
1.618     raeburn  9604: 
                   9605: =cut
                   9606: 
                   9607: ############################################################
                   9608: ############################################################
                   9609: sub build_recipient_list {
1.619     raeburn  9610:     my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618     raeburn  9611:     my @recipients;
                   9612:     my $otheremails;
                   9613:     my %domconfig =
                   9614:          &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
                   9615:     if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766     raeburn  9616:         if (exists($domconfig{'contacts'}{$mailing})) {
                   9617:             if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
                   9618:                 my @contacts = ('adminemail','supportemail');
                   9619:                 foreach my $item (@contacts) {
                   9620:                     if ($domconfig{'contacts'}{$mailing}{$item}) {
                   9621:                         my $addr = $domconfig{'contacts'}{$item}; 
                   9622:                         if (!grep(/^\Q$addr\E$/,@recipients)) {
                   9623:                             push(@recipients,$addr);
                   9624:                         }
1.619     raeburn  9625:                     }
1.766     raeburn  9626:                     $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618     raeburn  9627:                 }
                   9628:             }
1.766     raeburn  9629:         } elsif ($origmail ne '') {
                   9630:             push(@recipients,$origmail);
1.618     raeburn  9631:         }
1.619     raeburn  9632:     } elsif ($origmail ne '') {
                   9633:         push(@recipients,$origmail);
1.618     raeburn  9634:     }
1.688     raeburn  9635:     if (defined($defmail)) {
                   9636:         if ($defmail ne '') {
                   9637:             push(@recipients,$defmail);
                   9638:         }
1.618     raeburn  9639:     }
                   9640:     if ($otheremails) {
1.619     raeburn  9641:         my @others;
                   9642:         if ($otheremails =~ /,/) {
                   9643:             @others = split(/,/,$otheremails);
1.618     raeburn  9644:         } else {
1.619     raeburn  9645:             push(@others,$otheremails);
                   9646:         }
                   9647:         foreach my $addr (@others) {
                   9648:             if (!grep(/^\Q$addr\E$/,@recipients)) {
                   9649:                 push(@recipients,$addr);
                   9650:             }
1.618     raeburn  9651:         }
                   9652:     }
1.619     raeburn  9653:     my $recipientlist = join(',',@recipients); 
1.618     raeburn  9654:     return $recipientlist;
                   9655: }
                   9656: 
1.127     matthew  9657: ############################################################
                   9658: ############################################################
1.154     albertel 9659: 
1.655     raeburn  9660: =pod
                   9661: 
                   9662: =head1 Course Catalog Routines
                   9663: 
                   9664: =over 4
                   9665: 
                   9666: =item * &gather_categories()
                   9667: 
                   9668: Converts category definitions - keys of categories hash stored in  
                   9669: coursecategories in configuration.db on the primary library server in a 
                   9670: domain - to an array.  Also generates javascript and idx hash used to 
                   9671: generate Domain Coordinator interface for editing Course Categories.
                   9672: 
                   9673: Inputs:
1.663     raeburn  9674: 
1.655     raeburn  9675: categories (reference to hash of category definitions).
1.663     raeburn  9676: 
1.655     raeburn  9677: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   9678:       categories and subcategories).
1.663     raeburn  9679: 
1.655     raeburn  9680: idx (reference to hash of counters used in Domain Coordinator interface for 
                   9681:       editing Course Categories).
1.663     raeburn  9682: 
1.655     raeburn  9683: jsarray (reference to array of categories used to create Javascript arrays for
                   9684:          Domain Coordinator interface for editing Course Categories).
                   9685: 
                   9686: Returns: nothing
                   9687: 
                   9688: Side effects: populates cats, idx and jsarray. 
                   9689: 
                   9690: =cut
                   9691: 
                   9692: sub gather_categories {
                   9693:     my ($categories,$cats,$idx,$jsarray) = @_;
                   9694:     my %counters;
                   9695:     my $num = 0;
                   9696:     foreach my $item (keys(%{$categories})) {
                   9697:         my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
                   9698:         if ($container eq '' && $depth == 0) {
                   9699:             $cats->[$depth][$categories->{$item}] = $cat;
                   9700:         } else {
                   9701:             $cats->[$depth]{$container}[$categories->{$item}] = $cat;
                   9702:         }
                   9703:         my ($escitem,$tail) = split(/:/,$item,2);
                   9704:         if ($counters{$tail} eq '') {
                   9705:             $counters{$tail} = $num;
                   9706:             $num ++;
                   9707:         }
                   9708:         if (ref($idx) eq 'HASH') {
                   9709:             $idx->{$item} = $counters{$tail};
                   9710:         }
                   9711:         if (ref($jsarray) eq 'ARRAY') {
                   9712:             push(@{$jsarray->[$counters{$tail}]},$item);
                   9713:         }
                   9714:     }
                   9715:     return;
                   9716: }
                   9717: 
                   9718: =pod
                   9719: 
                   9720: =item * &extract_categories()
                   9721: 
                   9722: Used to generate breadcrumb trails for course categories.
                   9723: 
                   9724: Inputs:
1.663     raeburn  9725: 
1.655     raeburn  9726: categories (reference to hash of category definitions).
1.663     raeburn  9727: 
1.655     raeburn  9728: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   9729:       categories and subcategories).
1.663     raeburn  9730: 
1.655     raeburn  9731: trails (reference to array of breacrumb trails for each category).
1.663     raeburn  9732: 
1.655     raeburn  9733: allitems (reference to hash - key is category key 
                   9734:          (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663     raeburn  9735: 
1.655     raeburn  9736: idx (reference to hash of counters used in Domain Coordinator interface for
                   9737:       editing Course Categories).
1.663     raeburn  9738: 
1.655     raeburn  9739: jsarray (reference to array of categories used to create Javascript arrays for
                   9740:          Domain Coordinator interface for editing Course Categories).
                   9741: 
1.665     raeburn  9742: subcats (reference to hash of arrays containing all subcategories within each 
                   9743:          category, -recursive)
                   9744: 
1.655     raeburn  9745: Returns: nothing
                   9746: 
                   9747: Side effects: populates trails and allitems hash references.
                   9748: 
                   9749: =cut
                   9750: 
                   9751: sub extract_categories {
1.665     raeburn  9752:     my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655     raeburn  9753:     if (ref($categories) eq 'HASH') {
                   9754:         &gather_categories($categories,$cats,$idx,$jsarray);
                   9755:         if (ref($cats->[0]) eq 'ARRAY') {
                   9756:             for (my $i=0; $i<@{$cats->[0]}; $i++) {
                   9757:                 my $name = $cats->[0][$i];
                   9758:                 my $item = &escape($name).'::0';
                   9759:                 my $trailstr;
                   9760:                 if ($name eq 'instcode') {
                   9761:                     $trailstr = &mt('Official courses (with institutional codes)');
1.919     raeburn  9762:                 } elsif ($name eq 'communities') {
                   9763:                     $trailstr = &mt('Communities');
1.655     raeburn  9764:                 } else {
                   9765:                     $trailstr = $name;
                   9766:                 }
                   9767:                 if ($allitems->{$item} eq '') {
                   9768:                     push(@{$trails},$trailstr);
                   9769:                     $allitems->{$item} = scalar(@{$trails})-1;
                   9770:                 }
                   9771:                 my @parents = ($name);
                   9772:                 if (ref($cats->[1]{$name}) eq 'ARRAY') {
                   9773:                     for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
                   9774:                         my $category = $cats->[1]{$name}[$j];
1.665     raeburn  9775:                         if (ref($subcats) eq 'HASH') {
                   9776:                             push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
                   9777:                         }
                   9778:                         &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
                   9779:                     }
                   9780:                 } else {
                   9781:                     if (ref($subcats) eq 'HASH') {
                   9782:                         $subcats->{$item} = [];
1.655     raeburn  9783:                     }
                   9784:                 }
                   9785:             }
                   9786:         }
                   9787:     }
                   9788:     return;
                   9789: }
                   9790: 
                   9791: =pod
                   9792: 
                   9793: =item *&recurse_categories()
                   9794: 
                   9795: Recursively used to generate breadcrumb trails for course categories.
                   9796: 
                   9797: Inputs:
1.663     raeburn  9798: 
1.655     raeburn  9799: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   9800:       categories and subcategories).
1.663     raeburn  9801: 
1.655     raeburn  9802: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663     raeburn  9803: 
                   9804: category (current course category, for which breadcrumb trail is being generated).
                   9805: 
                   9806: trails (reference to array of breadcrumb trails for each category).
                   9807: 
1.655     raeburn  9808: allitems (reference to hash - key is category key
                   9809:          (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663     raeburn  9810: 
1.655     raeburn  9811: parents (array containing containers directories for current category, 
                   9812:          back to top level). 
                   9813: 
                   9814: Returns: nothing
                   9815: 
                   9816: Side effects: populates trails and allitems hash references
                   9817: 
                   9818: =cut
                   9819: 
                   9820: sub recurse_categories {
1.665     raeburn  9821:     my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655     raeburn  9822:     my $shallower = $depth - 1;
                   9823:     if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
                   9824:         for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
                   9825:             my $name = $cats->[$depth]{$category}[$k];
                   9826:             my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
                   9827:             my $trailstr = join(' -&gt; ',(@{$parents},$category));
                   9828:             if ($allitems->{$item} eq '') {
                   9829:                 push(@{$trails},$trailstr);
                   9830:                 $allitems->{$item} = scalar(@{$trails})-1;
                   9831:             }
                   9832:             my $deeper = $depth+1;
                   9833:             push(@{$parents},$category);
1.665     raeburn  9834:             if (ref($subcats) eq 'HASH') {
                   9835:                 my $subcat = &escape($name).':'.$category.':'.$depth;
                   9836:                 for (my $j=@{$parents}; $j>=0; $j--) {
                   9837:                     my $higher;
                   9838:                     if ($j > 0) {
                   9839:                         $higher = &escape($parents->[$j]).':'.
                   9840:                                   &escape($parents->[$j-1]).':'.$j;
                   9841:                     } else {
                   9842:                         $higher = &escape($parents->[$j]).'::'.$j;
                   9843:                     }
                   9844:                     push(@{$subcats->{$higher}},$subcat);
                   9845:                 }
                   9846:             }
                   9847:             &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
                   9848:                                 $subcats);
1.655     raeburn  9849:             pop(@{$parents});
                   9850:         }
                   9851:     } else {
                   9852:         my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
                   9853:         my $trailstr = join(' -&gt; ',(@{$parents},$category));
                   9854:         if ($allitems->{$item} eq '') {
                   9855:             push(@{$trails},$trailstr);
                   9856:             $allitems->{$item} = scalar(@{$trails})-1;
                   9857:         }
                   9858:     }
                   9859:     return;
                   9860: }
                   9861: 
1.663     raeburn  9862: =pod
                   9863: 
                   9864: =item *&assign_categories_table()
                   9865: 
                   9866: Create a datatable for display of hierarchical categories in a domain,
                   9867: with checkboxes to allow a course to be categorized. 
                   9868: 
                   9869: Inputs:
                   9870: 
                   9871: cathash - reference to hash of categories defined for the domain (from
                   9872:           configuration.db)
                   9873: 
                   9874: currcat - scalar with an & separated list of categories assigned to a course. 
                   9875: 
1.919     raeburn  9876: type    - scalar contains course type (Course or Community).
                   9877: 
1.663     raeburn  9878: Returns: $output (markup to be displayed) 
                   9879: 
                   9880: =cut
                   9881: 
                   9882: sub assign_categories_table {
1.919     raeburn  9883:     my ($cathash,$currcat,$type) = @_;
1.663     raeburn  9884:     my $output;
                   9885:     if (ref($cathash) eq 'HASH') {
                   9886:         my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
                   9887:         &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
                   9888:         $maxdepth = scalar(@cats);
                   9889:         if (@cats > 0) {
                   9890:             my $itemcount = 0;
                   9891:             if (ref($cats[0]) eq 'ARRAY') {
                   9892:                 my @currcategories;
                   9893:                 if ($currcat ne '') {
                   9894:                     @currcategories = split('&',$currcat);
                   9895:                 }
1.919     raeburn  9896:                 my $table;
1.663     raeburn  9897:                 for (my $i=0; $i<@{$cats[0]}; $i++) {
                   9898:                     my $parent = $cats[0][$i];
1.919     raeburn  9899:                     next if ($parent eq 'instcode');
                   9900:                     if ($type eq 'Community') {
                   9901:                         next unless ($parent eq 'communities');
                   9902:                     } else {
                   9903:                         next if ($parent eq 'communities');
                   9904:                     }
1.663     raeburn  9905:                     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   9906:                     my $item = &escape($parent).'::0';
                   9907:                     my $checked = '';
                   9908:                     if (@currcategories > 0) {
                   9909:                         if (grep(/^\Q$item\E$/,@currcategories)) {
1.772     bisitz   9910:                             $checked = ' checked="checked"';
1.663     raeburn  9911:                         }
                   9912:                     }
1.919     raeburn  9913:                     my $parent_title = $parent;
                   9914:                     if ($parent eq 'communities') {
                   9915:                         $parent_title = &mt('Communities');
                   9916:                     }
                   9917:                     $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
                   9918:                               '<input type="checkbox" name="usecategory" value="'.
                   9919:                               $item.'"'.$checked.' />'.$parent_title.'</span>'.
                   9920:                               '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663     raeburn  9921:                     my $depth = 1;
                   9922:                     push(@path,$parent);
1.919     raeburn  9923:                     $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663     raeburn  9924:                     pop(@path);
1.919     raeburn  9925:                     $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663     raeburn  9926:                     $itemcount ++;
                   9927:                 }
1.919     raeburn  9928:                 if ($itemcount) {
                   9929:                     $output = &Apache::loncommon::start_data_table().
                   9930:                               $table.
                   9931:                               &Apache::loncommon::end_data_table();
                   9932:                 }
1.663     raeburn  9933:             }
                   9934:         }
                   9935:     }
                   9936:     return $output;
                   9937: }
                   9938: 
                   9939: =pod
                   9940: 
                   9941: =item *&assign_category_rows()
                   9942: 
                   9943: Create a datatable row for display of nested categories in a domain,
                   9944: with checkboxes to allow a course to be categorized,called recursively.
                   9945: 
                   9946: Inputs:
                   9947: 
                   9948: itemcount - track row number for alternating colors
                   9949: 
                   9950: cats - reference to array of arrays/hashes which encapsulates hierarchy of
                   9951:       categories and subcategories.
                   9952: 
                   9953: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
                   9954: 
                   9955: parent - parent of current category item
                   9956: 
                   9957: path - Array containing all categories back up through the hierarchy from the
                   9958:        current category to the top level.
                   9959: 
                   9960: currcategories - reference to array of current categories assigned to the course
                   9961: 
                   9962: Returns: $output (markup to be displayed).
                   9963: 
                   9964: =cut
                   9965: 
                   9966: sub assign_category_rows {
                   9967:     my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
                   9968:     my ($text,$name,$item,$chgstr);
                   9969:     if (ref($cats) eq 'ARRAY') {
                   9970:         my $maxdepth = scalar(@{$cats});
                   9971:         if (ref($cats->[$depth]) eq 'HASH') {
                   9972:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   9973:                 my $numchildren = @{$cats->[$depth]{$parent}};
                   9974:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   9975:                 $text .= '<td><table class="LC_datatable">';
                   9976:                 for (my $j=0; $j<$numchildren; $j++) {
                   9977:                     $name = $cats->[$depth]{$parent}[$j];
                   9978:                     $item = &escape($name).':'.&escape($parent).':'.$depth;
                   9979:                     my $deeper = $depth+1;
                   9980:                     my $checked = '';
                   9981:                     if (ref($currcategories) eq 'ARRAY') {
                   9982:                         if (@{$currcategories} > 0) {
                   9983:                             if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772     bisitz   9984:                                 $checked = ' checked="checked"';
1.663     raeburn  9985:                             }
                   9986:                         }
                   9987:                     }
1.664     raeburn  9988:                     $text .= '<tr><td><span class="LC_nobreak"><label>'.
                   9989:                              '<input type="checkbox" name="usecategory" value="'.
1.675     raeburn  9990:                              $item.'"'.$checked.' />'.$name.'</label></span>'.
                   9991:                              '<input type="hidden" name="catname" value="'.$name.'" />'.
                   9992:                              '</td><td>';
1.663     raeburn  9993:                     if (ref($path) eq 'ARRAY') {
                   9994:                         push(@{$path},$name);
                   9995:                         $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
                   9996:                         pop(@{$path});
                   9997:                     }
                   9998:                     $text .= '</td></tr>';
                   9999:                 }
                   10000:                 $text .= '</table></td>';
                   10001:             }
                   10002:         }
                   10003:     }
                   10004:     return $text;
                   10005: }
                   10006: 
1.655     raeburn  10007: ############################################################
                   10008: ############################################################
                   10009: 
                   10010: 
1.443     albertel 10011: sub commit_customrole {
1.664     raeburn  10012:     my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630     raeburn  10013:     my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443     albertel 10014:                          ($start?', '.&mt('starting').' '.localtime($start):'').
                   10015:                          ($end?', ending '.localtime($end):'').': <b>'.
                   10016:               &Apache::lonnet::assigncustomrole(
1.664     raeburn  10017:                  $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443     albertel 10018:                  '</b><br />';
                   10019:     return $output;
                   10020: }
                   10021: 
                   10022: sub commit_standardrole {
1.541     raeburn  10023:     my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
                   10024:     my ($output,$logmsg,$linefeed);
                   10025:     if ($context eq 'auto') {
                   10026:         $linefeed = "\n";
                   10027:     } else {
                   10028:         $linefeed = "<br />\n";
                   10029:     }  
1.443     albertel 10030:     if ($three eq 'st') {
1.541     raeburn  10031:         my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
                   10032:                                          $one,$two,$sec,$context);
                   10033:         if (($result =~ /^error/) || ($result eq 'not_in_class') || 
1.626     raeburn  10034:             ($result eq 'unknown_course') || ($result eq 'refused')) {
                   10035:             $output = $logmsg.' '.&mt('Error: ').$result."\n"; 
1.443     albertel 10036:         } else {
1.541     raeburn  10037:             $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443     albertel 10038:                ($start?', '.&mt('starting').' '.localtime($start):'').
1.541     raeburn  10039:                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
                   10040:             if ($context eq 'auto') {
                   10041:                 $output .= $result.$linefeed.&mt('Add to classlist').': ok';
                   10042:             } else {
                   10043:                $output .= '<b>'.$result.'</b>'.$linefeed.
                   10044:                &mt('Add to classlist').': <b>ok</b>';
                   10045:             }
                   10046:             $output .= $linefeed;
1.443     albertel 10047:         }
                   10048:     } else {
                   10049:         $output = &mt('Assigning').' '.$three.' in '.$url.
                   10050:                ($start?', '.&mt('starting').' '.localtime($start):'').
1.541     raeburn  10051:                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652     raeburn  10052:         my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541     raeburn  10053:         if ($context eq 'auto') {
                   10054:             $output .= $result.$linefeed;
                   10055:         } else {
                   10056:             $output .= '<b>'.$result.'</b>'.$linefeed;
                   10057:         }
1.443     albertel 10058:     }
                   10059:     return $output;
                   10060: }
                   10061: 
                   10062: sub commit_studentrole {
1.541     raeburn  10063:     my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626     raeburn  10064:     my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541     raeburn  10065:     if ($context eq 'auto') {
                   10066:         $linefeed = "\n";
                   10067:     } else {
                   10068:         $linefeed = '<br />'."\n";
                   10069:     }
1.443     albertel 10070:     if (defined($one) && defined($two)) {
                   10071:         my $cid=$one.'_'.$two;
                   10072:         my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
                   10073:         my $secchange = 0;
                   10074:         my $expire_role_result;
                   10075:         my $modify_section_result;
1.628     raeburn  10076:         if ($oldsec ne '-1') { 
                   10077:             if ($oldsec ne $sec) {
1.443     albertel 10078:                 $secchange = 1;
1.628     raeburn  10079:                 my $now = time;
1.443     albertel 10080:                 my $uurl='/'.$cid;
                   10081:                 $uurl=~s/\_/\//g;
                   10082:                 if ($oldsec) {
                   10083:                     $uurl.='/'.$oldsec;
                   10084:                 }
1.626     raeburn  10085:                 $oldsecurl = $uurl;
1.628     raeburn  10086:                 $expire_role_result = 
1.652     raeburn  10087:                     &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628     raeburn  10088:                 if ($env{'request.course.sec'} ne '') { 
                   10089:                     if ($expire_role_result eq 'refused') {
                   10090:                         my @roles = ('st');
                   10091:                         my @statuses = ('previous');
                   10092:                         my @roledoms = ($one);
                   10093:                         my $withsec = 1;
                   10094:                         my %roleshash = 
                   10095:                             &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
                   10096:                                               \@statuses,\@roles,\@roledoms,$withsec);
                   10097:                         if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
                   10098:                             my ($oldstart,$oldend) = 
                   10099:                                 split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
                   10100:                             if ($oldend > 0 && $oldend <= $now) {
                   10101:                                 $expire_role_result = 'ok';
                   10102:                             }
                   10103:                         }
                   10104:                     }
                   10105:                 }
1.443     albertel 10106:                 $result = $expire_role_result;
                   10107:             }
                   10108:         }
                   10109:         if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652     raeburn  10110:             $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443     albertel 10111:             if ($modify_section_result =~ /^ok/) {
                   10112:                 if ($secchange == 1) {
1.628     raeburn  10113:                     if ($sec eq '') {
                   10114:                         $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
                   10115:                     } else {
                   10116:                         $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
                   10117:                     }
1.443     albertel 10118:                 } elsif ($oldsec eq '-1') {
1.628     raeburn  10119:                     if ($sec eq '') {
                   10120:                         $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
                   10121:                     } else {
                   10122:                         $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                   10123:                     }
1.443     albertel 10124:                 } else {
1.628     raeburn  10125:                     if ($sec eq '') {
                   10126:                         $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
                   10127:                     } else {
                   10128:                         $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                   10129:                     }
1.443     albertel 10130:                 }
                   10131:             } else {
1.628     raeburn  10132:                 if ($secchange) {       
                   10133:                     $$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;
                   10134:                 } else {
                   10135:                     $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
                   10136:                 }
1.443     albertel 10137:             }
                   10138:             $result = $modify_section_result;
                   10139:         } elsif ($secchange == 1) {
1.628     raeburn  10140:             if ($oldsec eq '') {
                   10141:                 $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
                   10142:             } else {
                   10143:                 $$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;
                   10144:             }
1.626     raeburn  10145:             if ($expire_role_result eq 'refused') {
                   10146:                 my $newsecurl = '/'.$cid;
                   10147:                 $newsecurl =~ s/\_/\//g;
                   10148:                 if ($sec ne '') {
                   10149:                     $newsecurl.='/'.$sec;
                   10150:                 }
                   10151:                 if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
                   10152:                     if ($sec eq '') {
                   10153:                         $$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;
                   10154:                     } else {
                   10155:                         $$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;
                   10156:                     }
                   10157:                 }
                   10158:             }
1.443     albertel 10159:         }
                   10160:     } else {
1.626     raeburn  10161:         $$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 10162:         $result = "error: incomplete course id\n";
                   10163:     }
                   10164:     return $result;
                   10165: }
                   10166: 
                   10167: ############################################################
                   10168: ############################################################
                   10169: 
1.566     albertel 10170: sub check_clone {
1.578     raeburn  10171:     my ($args,$linefeed) = @_;
1.566     albertel 10172:     my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
                   10173:     my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
                   10174:     my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
                   10175:     my $clonemsg;
                   10176:     my $can_clone = 0;
1.944     raeburn  10177:     my $lctype = lc($args->{'crstype'});
1.908     raeburn  10178:     if ($lctype ne 'community') {
                   10179:         $lctype = 'course';
                   10180:     }
1.566     albertel 10181:     if ($clonehome eq 'no_host') {
1.944     raeburn  10182:         if ($args->{'crstype'} eq 'Community') {
1.908     raeburn  10183:             $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'});
                   10184:         } else {
                   10185:             $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'});
                   10186:         }     
1.566     albertel 10187:     } else {
                   10188: 	my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944     raeburn  10189:         if ($args->{'crstype'} eq 'Community') {
1.908     raeburn  10190:             if ($clonedesc{'type'} ne 'Community') {
                   10191:                  $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'});
                   10192:                 return ($can_clone, $clonemsg, $cloneid, $clonehome);
                   10193:             }
                   10194:         }
1.882     raeburn  10195: 	if (($env{'request.role.domain'} eq $args->{'clonedomain'}) && 
                   10196:             (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566     albertel 10197: 	    $can_clone = 1;
                   10198: 	} else {
                   10199: 	    my %clonehash = &Apache::lonnet::get('environment',['cloners'],
                   10200: 						 $args->{'clonedomain'},$args->{'clonecourse'});
                   10201: 	    my @cloners = split(/,/,$clonehash{'cloners'});
1.578     raeburn  10202:             if (grep(/^\*$/,@cloners)) {
                   10203:                 $can_clone = 1;
                   10204:             } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
                   10205:                 $can_clone = 1;
                   10206:             } else {
1.908     raeburn  10207:                 my $ccrole = 'cc';
1.944     raeburn  10208:                 if ($args->{'crstype'} eq 'Community') {
1.908     raeburn  10209:                     $ccrole = 'co';
                   10210:                 }
1.578     raeburn  10211: 	        my %roleshash =
                   10212: 		    &Apache::lonnet::get_my_roles($args->{'ccuname'},
                   10213: 					 $args->{'ccdomain'},
1.908     raeburn  10214:                                          'userroles',['active'],[$ccrole],
1.578     raeburn  10215: 					 [$args->{'clonedomain'}]);
1.908     raeburn  10216: 	        if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
1.942     raeburn  10217:                     $can_clone = 1;
                   10218:                 } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},$args->{'ccuname'},$args->{'ccdomain'})) {
                   10219:                     $can_clone = 1;
                   10220:                 } else {
1.944     raeburn  10221:                     if ($args->{'crstype'} eq 'Community') {
1.908     raeburn  10222:                         $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'});
                   10223:                     } else {
                   10224:                         $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'});
                   10225:                     }
1.578     raeburn  10226: 	        }
1.566     albertel 10227: 	    }
1.578     raeburn  10228:         }
1.566     albertel 10229:     }
                   10230:     return ($can_clone, $clonemsg, $cloneid, $clonehome);
                   10231: }
                   10232: 
1.444     albertel 10233: sub construct_course {
1.885     raeburn  10234:     my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category) = @_;
1.444     albertel 10235:     my $outcome;
1.541     raeburn  10236:     my $linefeed =  '<br />'."\n";
                   10237:     if ($context eq 'auto') {
                   10238:         $linefeed = "\n";
                   10239:     }
1.566     albertel 10240: 
                   10241: #
                   10242: # Are we cloning?
                   10243: #
                   10244:     my ($can_clone, $clonemsg, $cloneid, $clonehome);
                   10245:     if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578     raeburn  10246: 	($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566     albertel 10247: 	if ($context ne 'auto') {
1.578     raeburn  10248:             if ($clonemsg ne '') {
                   10249: 	        $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
                   10250:             }
1.566     albertel 10251: 	}
                   10252: 	$outcome .= $clonemsg.$linefeed;
                   10253: 
                   10254:         if (!$can_clone) {
                   10255: 	    return (0,$outcome);
                   10256: 	}
                   10257:     }
                   10258: 
1.444     albertel 10259: #
                   10260: # Open course
                   10261: #
                   10262:     my $crstype = lc($args->{'crstype'});
                   10263:     my %cenv=();
                   10264:     $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
                   10265:                                              $args->{'cdescr'},
                   10266:                                              $args->{'curl'},
                   10267:                                              $args->{'course_home'},
                   10268:                                              $args->{'nonstandard'},
                   10269:                                              $args->{'crscode'},
                   10270:                                              $args->{'ccuname'}.':'.
                   10271:                                              $args->{'ccdomain'},
1.882     raeburn  10272:                                              $args->{'crstype'},
1.885     raeburn  10273:                                              $cnum,$context,$category);
1.444     albertel 10274: 
                   10275:     # Note: The testing routines depend on this being output; see 
                   10276:     # Utils::Course. This needs to at least be output as a comment
                   10277:     # if anyone ever decides to not show this, and Utils::Course::new
                   10278:     # will need to be suitably modified.
1.541     raeburn  10279:     $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943     raeburn  10280:     if ($$courseid =~ /^error:/) {
                   10281:         return (0,$outcome);
                   10282:     }
                   10283: 
1.444     albertel 10284: #
                   10285: # Check if created correctly
                   10286: #
1.479     albertel 10287:     ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444     albertel 10288:     my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943     raeburn  10289:     if ($crsuhome eq 'no_host') {
                   10290:         $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
                   10291:         return (0,$outcome);
                   10292:     }
1.541     raeburn  10293:     $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566     albertel 10294: 
1.444     albertel 10295: #
1.566     albertel 10296: # Do the cloning
                   10297: #   
                   10298:     if ($can_clone && $cloneid) {
                   10299: 	$clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
                   10300: 	if ($context ne 'auto') {
                   10301: 	    $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
                   10302: 	}
                   10303: 	$outcome .= $clonemsg.$linefeed;
                   10304: 	my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444     albertel 10305: # Copy all files
1.637     www      10306: 	&Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444     albertel 10307: # Restore URL
1.566     albertel 10308: 	$cenv{'url'}=$oldcenv{'url'};
1.444     albertel 10309: # Restore title
1.566     albertel 10310: 	$cenv{'description'}=$oldcenv{'description'};
1.948.2.2  raeburn  10311: # Restore creation date, creator and creation context.
                   10312:         $cenv{'internal.created'}=$oldcenv{'internal.created'};
                   10313:         $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
                   10314:         $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444     albertel 10315: # Mark as cloned
1.566     albertel 10316: 	$cenv{'clonedfrom'}=$cloneid;
1.638     www      10317: # Need to clone grading mode
                   10318:         my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
                   10319:         $cenv{'grading'}=$newenv{'grading'};
                   10320: # Do not clone these environment entries
                   10321:         &Apache::lonnet::del('environment',
                   10322:                   ['default_enrollment_start_date',
                   10323:                    'default_enrollment_end_date',
                   10324:                    'question.email',
                   10325:                    'policy.email',
                   10326:                    'comment.email',
                   10327:                    'pch.users.denied',
1.725     raeburn  10328:                    'plc.users.denied',
                   10329:                    'hidefromcat',
                   10330:                    'categories'],
1.638     www      10331:                    $$crsudom,$$crsunum);
1.444     albertel 10332:     }
1.566     albertel 10333: 
1.444     albertel 10334: #
                   10335: # Set environment (will override cloned, if existing)
                   10336: #
                   10337:     my @sections = ();
                   10338:     my @xlists = ();
                   10339:     if ($args->{'crstype'}) {
                   10340:         $cenv{'type'}=$args->{'crstype'};
                   10341:     }
                   10342:     if ($args->{'crsid'}) {
                   10343:         $cenv{'courseid'}=$args->{'crsid'};
                   10344:     }
                   10345:     if ($args->{'crscode'}) {
                   10346:         $cenv{'internal.coursecode'}=$args->{'crscode'};
                   10347:     }
                   10348:     if ($args->{'crsquota'} ne '') {
                   10349:         $cenv{'internal.coursequota'}=$args->{'crsquota'};
                   10350:     } else {
                   10351:         $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
                   10352:     }
                   10353:     if ($args->{'ccuname'}) {
                   10354:         $cenv{'internal.courseowner'} = $args->{'ccuname'}.
                   10355:                                         ':'.$args->{'ccdomain'};
                   10356:     } else {
                   10357:         $cenv{'internal.courseowner'} = $args->{'curruser'};
                   10358:     }
                   10359:     my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
                   10360:     if ($args->{'crssections'}) {
                   10361:         $cenv{'internal.sectionnums'} = '';
                   10362:         if ($args->{'crssections'} =~ m/,/) {
                   10363:             @sections = split/,/,$args->{'crssections'};
                   10364:         } else {
                   10365:             $sections[0] = $args->{'crssections'};
                   10366:         }
                   10367:         if (@sections > 0) {
                   10368:             foreach my $item (@sections) {
                   10369:                 my ($sec,$gp) = split/:/,$item;
                   10370:                 my $class = $args->{'crscode'}.$sec;
                   10371:                 my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
                   10372:                 $cenv{'internal.sectionnums'} .= $item.',';
                   10373:                 unless ($addcheck eq 'ok') {
                   10374:                     push @badclasses, $class;
                   10375:                 }
                   10376:             }
                   10377:             $cenv{'internal.sectionnums'} =~ s/,$//;
                   10378:         }
                   10379:     }
                   10380: # do not hide course coordinator from staff listing, 
                   10381: # even if privileged
                   10382:     $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   10383: # add crosslistings
                   10384:     if ($args->{'crsxlist'}) {
                   10385:         $cenv{'internal.crosslistings'}='';
                   10386:         if ($args->{'crsxlist'} =~ m/,/) {
                   10387:             @xlists = split/,/,$args->{'crsxlist'};
                   10388:         } else {
                   10389:             $xlists[0] = $args->{'crsxlist'};
                   10390:         }
                   10391:         if (@xlists > 0) {
                   10392:             foreach my $item (@xlists) {
                   10393:                 my ($xl,$gp) = split/:/,$item;
                   10394:                 my $addcheck =  &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
                   10395:                 $cenv{'internal.crosslistings'} .= $item.',';
                   10396:                 unless ($addcheck eq 'ok') {
                   10397:                     push @badclasses, $xl;
                   10398:                 }
                   10399:             }
                   10400:             $cenv{'internal.crosslistings'} =~ s/,$//;
                   10401:         }
                   10402:     }
                   10403:     if ($args->{'autoadds'}) {
                   10404:         $cenv{'internal.autoadds'}=$args->{'autoadds'};
                   10405:     }
                   10406:     if ($args->{'autodrops'}) {
                   10407:         $cenv{'internal.autodrops'}=$args->{'autodrops'};
                   10408:     }
                   10409: # check for notification of enrollment changes
                   10410:     my @notified = ();
                   10411:     if ($args->{'notify_owner'}) {
                   10412:         if ($args->{'ccuname'} ne '') {
                   10413:             push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
                   10414:         }
                   10415:     }
                   10416:     if ($args->{'notify_dc'}) {
                   10417:         if ($uname ne '') { 
1.630     raeburn  10418:             push(@notified,$uname.':'.$udom);
1.444     albertel 10419:         }
                   10420:     }
                   10421:     if (@notified > 0) {
                   10422:         my $notifylist;
                   10423:         if (@notified > 1) {
                   10424:             $notifylist = join(',',@notified);
                   10425:         } else {
                   10426:             $notifylist = $notified[0];
                   10427:         }
                   10428:         $cenv{'internal.notifylist'} = $notifylist;
                   10429:     }
                   10430:     if (@badclasses > 0) {
                   10431:         my %lt=&Apache::lonlocal::texthash(
                   10432:                 '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',
                   10433:                 'dnhr' => 'does not have rights to access enrollment in these classes',
                   10434:                 'adby' => 'as determined by the policies of your institution on access to official classlists'
                   10435:         );
1.541     raeburn  10436:         my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
                   10437:                            ' ('.$lt{'adby'}.')';
                   10438:         if ($context eq 'auto') {
                   10439:             $outcome .= $badclass_msg.$linefeed;
1.566     albertel 10440:             $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541     raeburn  10441:             foreach my $item (@badclasses) {
                   10442:                 if ($context eq 'auto') {
                   10443:                     $outcome .= " - $item\n";
                   10444:                 } else {
                   10445:                     $outcome .= "<li>$item</li>\n";
                   10446:                 }
                   10447:             }
                   10448:             if ($context eq 'auto') {
                   10449:                 $outcome .= $linefeed;
                   10450:             } else {
1.566     albertel 10451:                 $outcome .= "</ul><br /><br /></div>\n";
1.541     raeburn  10452:             }
                   10453:         } 
1.444     albertel 10454:     }
                   10455:     if ($args->{'no_end_date'}) {
                   10456:         $args->{'endaccess'} = 0;
                   10457:     }
                   10458:     $cenv{'internal.autostart'}=$args->{'enrollstart'};
                   10459:     $cenv{'internal.autoend'}=$args->{'enrollend'};
                   10460:     $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
                   10461:     $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
                   10462:     if ($args->{'showphotos'}) {
                   10463:       $cenv{'internal.showphotos'}=$args->{'showphotos'};
                   10464:     }
                   10465:     $cenv{'internal.authtype'} = $args->{'authtype'};
                   10466:     $cenv{'internal.autharg'} = $args->{'autharg'}; 
                   10467:     if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
                   10468:         if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'}  eq '') {
1.541     raeburn  10469:             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'); 
                   10470:             if ($context eq 'auto') {
                   10471:                 $outcome .= $krb_msg;
                   10472:             } else {
1.566     albertel 10473:                 $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541     raeburn  10474:             }
                   10475:             $outcome .= $linefeed;
1.444     albertel 10476:         }
                   10477:     }
                   10478:     if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
                   10479:        if ($args->{'setpolicy'}) {
                   10480:            $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   10481:        }
                   10482:        if ($args->{'setcontent'}) {
                   10483:            $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   10484:        }
                   10485:     }
                   10486:     if ($args->{'reshome'}) {
                   10487: 	$cenv{'reshome'}=$args->{'reshome'}.'/';
                   10488: 	$cenv{'reshome'}=~s/\/+$/\//;
                   10489:     }
                   10490: #
                   10491: # course has keyed access
                   10492: #
                   10493:     if ($args->{'setkeys'}) {
                   10494:        $cenv{'keyaccess'}='yes';
                   10495:     }
                   10496: # if specified, key authority is not course, but user
                   10497: # only active if keyaccess is yes
                   10498:     if ($args->{'keyauth'}) {
1.487     albertel 10499: 	my ($user,$domain) = split(':',$args->{'keyauth'});
                   10500: 	$user = &LONCAPA::clean_username($user);
                   10501: 	$domain = &LONCAPA::clean_username($domain);
1.488     foxr     10502: 	if ($user ne '' && $domain ne '') {
1.487     albertel 10503: 	    $cenv{'keyauth'}=$user.':'.$domain;
1.444     albertel 10504: 	}
                   10505:     }
                   10506: 
                   10507:     if ($args->{'disresdis'}) {
                   10508:         $cenv{'pch.roles.denied'}='st';
                   10509:     }
                   10510:     if ($args->{'disablechat'}) {
                   10511:         $cenv{'plc.roles.denied'}='st';
                   10512:     }
                   10513: 
                   10514:     # Record we've not yet viewed the Course Initialization Helper for this 
                   10515:     # course
                   10516:     $cenv{'course.helper.not.run'} = 1;
                   10517:     #
                   10518:     # Use new Randomseed
                   10519:     #
                   10520:     $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
                   10521:     $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
                   10522:     #
                   10523:     # The encryption code and receipt prefix for this course
                   10524:     #
                   10525:     $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
                   10526:     $cenv{'internal.encpref'}=100+int(9*rand(99));
                   10527:     #
                   10528:     # By default, use standard grading
                   10529:     if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
                   10530: 
1.541     raeburn  10531:     $outcome .= $linefeed.&mt('Setting environment').': '.                 
                   10532:           &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444     albertel 10533: #
                   10534: # Open all assignments
                   10535: #
                   10536:     if ($args->{'openall'}) {
                   10537:        my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
                   10538:        my %storecontent = ($storeunder         => time,
                   10539:                            $storeunder.'.type' => 'date_start');
                   10540:        
                   10541:        $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541     raeburn  10542:                  ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444     albertel 10543:    }
                   10544: #
                   10545: # Set first page
                   10546: #
                   10547:     unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
                   10548: 	    || ($cloneid)) {
1.445     albertel 10549: 	use LONCAPA::map;
1.444     albertel 10550: 	$outcome .= &mt('Setting first resource').': ';
1.445     albertel 10551: 
                   10552: 	my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
                   10553:         my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
                   10554: 
1.444     albertel 10555:         $outcome .= ($fatal?$errtext:'read ok').' - ';
                   10556:         my $title; my $url;
                   10557:         if ($args->{'firstres'} eq 'syl') {
1.690     bisitz   10558: 	    $title=&mt('Syllabus');
1.444     albertel 10559:             $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
                   10560:         } else {
1.948.2.5  raeburn  10561:             $title=&mt('Table of Contents');
1.444     albertel 10562:             $url='/adm/navmaps';
                   10563:         }
1.445     albertel 10564: 
                   10565:         $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
                   10566: 	(my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
                   10567: 
                   10568: 	if ($errtext) { $fatal=2; }
1.541     raeburn  10569:         $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444     albertel 10570:     }
1.566     albertel 10571: 
                   10572:     return (1,$outcome);
1.444     albertel 10573: }
                   10574: 
                   10575: ############################################################
                   10576: ############################################################
                   10577: 
1.378     raeburn  10578: sub course_type {
                   10579:     my ($cid) = @_;
                   10580:     if (!defined($cid)) {
                   10581:         $cid = $env{'request.course.id'};
                   10582:     }
1.404     albertel 10583:     if (defined($env{'course.'.$cid.'.type'})) {
                   10584:         return $env{'course.'.$cid.'.type'};
1.378     raeburn  10585:     } else {
                   10586:         return 'Course';
1.377     raeburn  10587:     }
                   10588: }
1.156     albertel 10589: 
1.406     raeburn  10590: sub group_term {
                   10591:     my $crstype = &course_type();
                   10592:     my %names = (
                   10593:                   'Course' => 'group',
1.865     raeburn  10594:                   'Community' => 'group',
1.406     raeburn  10595:                 );
                   10596:     return $names{$crstype};
                   10597: }
                   10598: 
1.902     raeburn  10599: sub course_types {
                   10600:     my @types = ('official','unofficial','community');
                   10601:     my %typename = (
                   10602:                          official   => 'Official course',
                   10603:                          unofficial => 'Unofficial course',
                   10604:                          community  => 'Community',
                   10605:                    );
                   10606:     return (\@types,\%typename);
                   10607: }
                   10608: 
1.156     albertel 10609: sub icon {
                   10610:     my ($file)=@_;
1.505     albertel 10611:     my $curfext = lc((split(/\./,$file))[-1]);
1.168     albertel 10612:     my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156     albertel 10613:     my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168     albertel 10614:     if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
                   10615: 	if (-e  $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
                   10616: 	          $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   10617: 	            $curfext.".gif") {
                   10618: 	    $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   10619: 		$curfext.".gif";
                   10620: 	}
                   10621:     }
1.249     albertel 10622:     return &lonhttpdurl($iconname);
1.154     albertel 10623: } 
1.84      albertel 10624: 
1.575     albertel 10625: sub lonhttpdurl {
1.692     www      10626: #
                   10627: # Had been used for "small fry" static images on separate port 8080.
                   10628: # Modify here if lightweight http functionality desired again.
                   10629: # Currently eliminated due to increasing firewall issues.
                   10630: #
1.575     albertel 10631:     my ($url)=@_;
1.692     www      10632:     return $url;
1.215     albertel 10633: }
                   10634: 
1.213     albertel 10635: sub connection_aborted {
                   10636:     my ($r)=@_;
                   10637:     $r->print(" ");$r->rflush();
                   10638:     my $c = $r->connection;
                   10639:     return $c->aborted();
                   10640: }
                   10641: 
1.221     foxr     10642: #    Escapes strings that may have embedded 's that will be put into
1.222     foxr     10643: #    strings as 'strings'.
                   10644: sub escape_single {
1.221     foxr     10645:     my ($input) = @_;
1.223     albertel 10646:     $input =~ s/\\/\\\\/g;	# Escape the \'s..(must be first)>
1.221     foxr     10647:     $input =~ s/\'/\\\'/g;	# Esacpe the 's....
                   10648:     return $input;
                   10649: }
1.223     albertel 10650: 
1.222     foxr     10651: #  Same as escape_single, but escape's "'s  This 
                   10652: #  can be used for  "strings"
                   10653: sub escape_double {
                   10654:     my ($input) = @_;
                   10655:     $input =~ s/\\/\\\\/g;	# Escape the /'s..(must be first)>
                   10656:     $input =~ s/\"/\\\"/g;	# Esacpe the "s....
                   10657:     return $input;
                   10658: }
1.223     albertel 10659:  
1.222     foxr     10660: #   Escapes the last element of a full URL.
                   10661: sub escape_url {
                   10662:     my ($url)   = @_;
1.238     raeburn  10663:     my @urlslices = split(/\//, $url,-1);
1.369     www      10664:     my $lastitem = &escape(pop(@urlslices));
1.223     albertel 10665:     return join('/',@urlslices).'/'.$lastitem;
1.222     foxr     10666: }
1.462     albertel 10667: 
1.820     raeburn  10668: sub compare_arrays {
                   10669:     my ($arrayref1,$arrayref2) = @_;
                   10670:     my (@difference,%count);
                   10671:     @difference = ();
                   10672:     %count = ();
                   10673:     if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
                   10674:         foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
                   10675:         foreach my $element (keys(%count)) {
                   10676:             if ($count{$element} == 1) {
                   10677:                 push(@difference,$element);
                   10678:             }
                   10679:         }
                   10680:     }
                   10681:     return @difference;
                   10682: }
                   10683: 
1.817     bisitz   10684: # -------------------------------------------------------- Initialize user login
1.462     albertel 10685: sub init_user_environment {
1.463     albertel 10686:     my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462     albertel 10687:     my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
                   10688: 
                   10689:     my $public=($username eq 'public' && $domain eq 'public');
                   10690: 
                   10691: # See if old ID present, if so, remove
                   10692: 
                   10693:     my ($filename,$cookie,$userroles);
                   10694:     my $now=time;
                   10695: 
                   10696:     if ($public) {
                   10697: 	my $max_public=100;
                   10698: 	my $oldest;
                   10699: 	my $oldest_time=0;
                   10700: 	for(my $next=1;$next<=$max_public;$next++) {
                   10701: 	    if (-e $lonids."/publicuser_$next.id") {
                   10702: 		my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
                   10703: 		if ($mtime<$oldest_time || !$oldest_time) {
                   10704: 		    $oldest_time=$mtime;
                   10705: 		    $oldest=$next;
                   10706: 		}
                   10707: 	    } else {
                   10708: 		$cookie="publicuser_$next";
                   10709: 		last;
                   10710: 	    }
                   10711: 	}
                   10712: 	if (!$cookie) { $cookie="publicuser_$oldest"; }
                   10713:     } else {
1.463     albertel 10714: 	# if this isn't a robot, kill any existing non-robot sessions
                   10715: 	if (!$args->{'robot'}) {
                   10716: 	    opendir(DIR,$lonids);
                   10717: 	    while ($filename=readdir(DIR)) {
                   10718: 		if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
                   10719: 		    unlink($lonids.'/'.$filename);
                   10720: 		}
1.462     albertel 10721: 	    }
1.463     albertel 10722: 	    closedir(DIR);
1.462     albertel 10723: 	}
                   10724: # Give them a new cookie
1.463     albertel 10725: 	my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684     www      10726: 		                   : $now.$$.int(rand(10000)));
1.463     albertel 10727: 	$cookie="$username\_$id\_$domain\_$authhost";
1.462     albertel 10728:     
                   10729: # Initialize roles
                   10730: 
                   10731: 	$userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
                   10732:     }
                   10733: # ------------------------------------ Check browser type and MathML capability
                   10734: 
                   10735:     my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
                   10736:         $clientunicode,$clientos) = &decode_user_agent($r);
                   10737: 
                   10738: # ------------------------------------------------------------- Get environment
                   10739: 
                   10740:     my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
                   10741:     my ($tmp) = keys(%userenv);
                   10742:     if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   10743: 	# default remote control to off
                   10744: 	if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
                   10745:     } else {
                   10746: 	undef(%userenv);
                   10747:     }
                   10748:     if (($userenv{'interface'}) && (!$form->{'interface'})) {
                   10749: 	$form->{'interface'}=$userenv{'interface'};
                   10750:     }
                   10751:     $env{'environment.remote'}=$userenv{'remote'};
                   10752:     if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
                   10753: 
                   10754: # --------------- Do not trust query string to be put directly into environment
1.817     bisitz   10755:     foreach my $option ('interface','localpath','localres') {
                   10756:         $form->{$option}=~s/[\n\r\=]//gs;
1.462     albertel 10757:     }
                   10758: # --------------------------------------------------------- Write first profile
                   10759: 
                   10760:     {
                   10761: 	my %initial_env = 
                   10762: 	    ("user.name"          => $username,
                   10763: 	     "user.domain"        => $domain,
                   10764: 	     "user.home"          => $authhost,
                   10765: 	     "browser.type"       => $clientbrowser,
                   10766: 	     "browser.version"    => $clientversion,
                   10767: 	     "browser.mathml"     => $clientmathml,
                   10768: 	     "browser.unicode"    => $clientunicode,
                   10769: 	     "browser.os"         => $clientos,
                   10770: 	     "server.domain"      => $Apache::lonnet::perlvar{'lonDefDomain'},
                   10771: 	     "request.course.fn"  => '',
                   10772: 	     "request.course.uri" => '',
                   10773: 	     "request.course.sec" => '',
                   10774: 	     "request.role"       => 'cm',
                   10775: 	     "request.role.adv"   => $env{'user.adv'},
                   10776: 	     "request.host"       => $ENV{'REMOTE_ADDR'},);
                   10777: 
                   10778:         if ($form->{'localpath'}) {
                   10779: 	    $initial_env{"browser.localpath"}  = $form->{'localpath'};
                   10780: 	    $initial_env{"browser.localres"}   = $form->{'localres'};
                   10781:         }
                   10782: 	
                   10783: 	if ($public) {
                   10784: 	    $initial_env{"environment.remote"} = "off";
                   10785: 	}
                   10786: 	if ($form->{'interface'}) {
                   10787: 	    $form->{'interface'}=~s/\W//gs;
                   10788: 	    $initial_env{"browser.interface"} = $form->{'interface'};
                   10789: 	    $env{'browser.interface'}=$form->{'interface'};
                   10790: 	}
                   10791: 
1.724     raeburn  10792:         foreach my $tool ('aboutme','blog','portfolio') {
                   10793:             $userenv{'availabletools.'.$tool} = 
                   10794:                 &Apache::lonnet::usertools_access($username,$domain,$tool,'reload');
                   10795:         }
                   10796: 
1.864     raeburn  10797:         foreach my $crstype ('official','unofficial','community') {
1.765     raeburn  10798:             $userenv{'canrequest.'.$crstype} =
                   10799:                 &Apache::lonnet::usertools_access($username,$domain,$crstype,
                   10800:                                                   'reload','requestcourses');
                   10801:         }
                   10802: 
1.462     albertel 10803: 	$env{'user.environment'} = "$lonids/$cookie.id";
                   10804: 	
                   10805: 	if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
                   10806: 		 &GDBM_WRCREAT(),0640)) {
                   10807: 	    &_add_to_env(\%disk_env,\%initial_env);
                   10808: 	    &_add_to_env(\%disk_env,\%userenv,'environment.');
                   10809: 	    &_add_to_env(\%disk_env,$userroles);
1.463     albertel 10810: 	    if (ref($args->{'extra_env'})) {
                   10811: 		&_add_to_env(\%disk_env,$args->{'extra_env'});
                   10812: 	    }
1.462     albertel 10813: 	    untie(%disk_env);
                   10814: 	} else {
1.705     tempelho 10815: 	    &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
                   10816: 			   'Could not create environment storage in lonauth: '.$!.'</span>');
1.462     albertel 10817: 	    return 'error: '.$!;
                   10818: 	}
                   10819:     }
                   10820:     $env{'request.role'}='cm';
                   10821:     $env{'request.role.adv'}=$env{'user.adv'};
                   10822:     $env{'browser.type'}=$clientbrowser;
                   10823: 
                   10824:     return $cookie;
                   10825: 
                   10826: }
                   10827: 
                   10828: sub _add_to_env {
                   10829:     my ($idf,$env_data,$prefix) = @_;
1.676     raeburn  10830:     if (ref($env_data) eq 'HASH') {
                   10831:         while (my ($key,$value) = each(%$env_data)) {
                   10832: 	    $idf->{$prefix.$key} = $value;
                   10833: 	    $env{$prefix.$key}   = $value;
                   10834:         }
1.462     albertel 10835:     }
                   10836: }
                   10837: 
1.685     tempelho 10838: # --- Get the symbolic name of a problem and the url
                   10839: sub get_symb {
                   10840:     my ($request,$silent) = @_;
1.726     raeburn  10841:     (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685     tempelho 10842:     my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
                   10843:     if ($symb eq '') {
                   10844:         if (!$silent) {
                   10845:             $request->print("Unable to handle ambiguous references:$url:.");
                   10846:             return ();
                   10847:         }
                   10848:     }
                   10849:     &Apache::lonenc::check_decrypt(\$symb);
                   10850:     return ($symb);
                   10851: }
                   10852: 
                   10853: # --------------------------------------------------------------Get annotation
                   10854: 
                   10855: sub get_annotation {
                   10856:     my ($symb,$enc) = @_;
                   10857: 
                   10858:     my $key = $symb;
                   10859:     if (!$enc) {
                   10860:         $key =
                   10861:             &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
                   10862:     }
                   10863:     my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
                   10864:     return $annotation{$key};
                   10865: }
                   10866: 
                   10867: sub clean_symb {
1.731     raeburn  10868:     my ($symb,$delete_enc) = @_;
1.685     tempelho 10869: 
                   10870:     &Apache::lonenc::check_decrypt(\$symb);
                   10871:     my $enc = $env{'request.enc'};
1.731     raeburn  10872:     if ($delete_enc) {
1.730     raeburn  10873:         delete($env{'request.enc'});
                   10874:     }
1.685     tempelho 10875: 
                   10876:     return ($symb,$enc);
                   10877: }
1.462     albertel 10878: 
1.41      ng       10879: =pod
                   10880: 
                   10881: =back
                   10882: 
1.112     bowersj2 10883: =cut
1.41      ng       10884: 
1.112     bowersj2 10885: 1;
                   10886: __END__;
1.41      ng       10887: 

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