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

1.10      albertel    1: # The LearningOnline Network with CAPA
1.1       albertel    2: # a pile of common routines
1.10      albertel    3: #
1.963   ! raeburn     4: # $Id: loncommon.pm,v 1.962 2010/03/22 20:11:22 droeschl Exp $
1.10      albertel    5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
1.1       albertel   28: 
                     29: # Makes a table out of the previous attempts
1.2       albertel   30: # Inputs result_from_symbread, user, domain, course_id
1.16      harris41   31: # Reads in non-network-related .tab files
1.1       albertel   32: 
1.35      matthew    33: # POD header:
                     34: 
1.45      matthew    35: =pod
                     36: 
1.35      matthew    37: =head1 NAME
                     38: 
                     39: Apache::loncommon - pile of common routines
                     40: 
                     41: =head1 SYNOPSIS
                     42: 
1.112     bowersj2   43: Common routines for manipulating connections, student answers,
                     44:     domains, common Javascript fragments, etc.
1.35      matthew    45: 
1.112     bowersj2   46: =head1 OVERVIEW
1.35      matthew    47: 
1.112     bowersj2   48: A collection of commonly used subroutines that don't have a natural
                     49: home anywhere else. This collection helps remove
1.35      matthew    50: redundancy from other modules and increase efficiency of memory usage.
                     51: 
                     52: =cut 
                     53: 
                     54: # End of POD header
1.1       albertel   55: package Apache::loncommon;
                     56: 
                     57: use strict;
1.258     albertel   58: use Apache::lonnet;
1.46      matthew    59: use GDBM_File;
1.51      www        60: use POSIX qw(strftime mktime);
1.82      www        61: use Apache::lonmenu();
1.498     albertel   62: use Apache::lonenc();
1.117     www        63: use Apache::lonlocal;
1.685     tempelho   64: use Apache::lonnet();
1.139     matthew    65: use HTML::Entities;
1.334     albertel   66: use Apache::lonhtmlcommon();
                     67: use Apache::loncoursedata();
1.344     albertel   68: use Apache::lontexconvert();
1.444     albertel   69: use Apache::lonclonecourse();
1.479     albertel   70: use LONCAPA qw(:DEFAULT :match);
1.657     raeburn    71: use DateTime::TimeZone;
1.687     raeburn    72: use DateTime::Locale::Catalog;
1.117     www        73: 
1.517     raeburn    74: # ---------------------------------------------- Designs
                     75: use vars qw(%defaultdesign);
                     76: 
1.22      www        77: my $readit;
                     78: 
1.517     raeburn    79: 
1.157     matthew    80: ##
                     81: ## Global Variables
                     82: ##
1.46      matthew    83: 
1.643     foxr       84: 
                     85: # ----------------------------------------------- SSI with retries:
                     86: #
                     87: 
                     88: =pod
                     89: 
1.648     raeburn    90: =head1 Server Side include with retries:
1.643     foxr       91: 
                     92: =over 4
                     93: 
1.648     raeburn    94: =item * &ssi_with_retries(resource,retries form)
1.643     foxr       95: 
                     96: Performs an ssi with some number of retries.  Retries continue either
                     97: until the result is ok or until the retry count supplied by the
                     98: caller is exhausted.  
                     99: 
                    100: Inputs:
1.648     raeburn   101: 
                    102: =over 4
                    103: 
1.643     foxr      104: resource   - Identifies the resource to insert.
1.648     raeburn   105: 
1.643     foxr      106: retries    - Count of the number of retries allowed.
1.648     raeburn   107: 
1.643     foxr      108: form       - Hash that identifies the rendering options.
                    109: 
1.648     raeburn   110: =back
                    111: 
                    112: Returns:
                    113: 
                    114: =over 4
                    115: 
1.643     foxr      116: content    - The content of the response.  If retries were exhausted this is empty.
1.648     raeburn   117: 
1.643     foxr      118: response   - The response from the last attempt (which may or may not have been successful.
                    119: 
1.648     raeburn   120: =back
                    121: 
                    122: =back
                    123: 
1.643     foxr      124: =cut
                    125: 
                    126: sub ssi_with_retries {
                    127:     my ($resource, $retries, %form) = @_;
                    128: 
                    129: 
                    130:     my $ok = 0;			# True if we got a good response.
                    131:     my $content;
                    132:     my $response;
                    133: 
                    134:     # Try to get the ssi done. within the retries count:
                    135: 
                    136:     do {
                    137: 	($content, $response) = &Apache::lonnet::ssi($resource, %form);
                    138: 	$ok      = $response->is_success;
1.650     www       139:         if (!$ok) {
                    140:             &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
                    141:         }
1.643     foxr      142: 	$retries--;
                    143:     } while (!$ok && ($retries > 0));
                    144: 
                    145:     if (!$ok) {
                    146: 	$content = '';		# On error return an empty content.
                    147:     }
                    148:     return ($content, $response);
                    149: 
                    150: }
                    151: 
                    152: 
                    153: 
1.20      www       154: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12      harris41  155: my %language;
1.124     www       156: my %supported_language;
1.12      harris41  157: my %cprtag;
1.192     taceyjo1  158: my %scprtag;
1.351     www       159: my %fe; my %fd; my %fm;
1.41      ng        160: my %category_extensions;
1.12      harris41  161: 
1.46      matthew   162: # ---------------------------------------------- Thesaurus variables
1.144     matthew   163: #
                    164: # %Keywords:
                    165: #      A hash used by &keyword to determine if a word is considered a keyword.
                    166: # $thesaurus_db_file 
                    167: #      Scalar containing the full path to the thesaurus database.
1.46      matthew   168: 
                    169: my %Keywords;
                    170: my $thesaurus_db_file;
                    171: 
1.144     matthew   172: #
                    173: # Initialize values from language.tab, copyright.tab, filetypes.tab,
                    174: # thesaurus.tab, and filecategories.tab.
                    175: #
1.18      www       176: BEGIN {
1.46      matthew   177:     # Variable initialization
                    178:     $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
                    179:     #
1.22      www       180:     unless ($readit) {
1.12      harris41  181: # ------------------------------------------------------------------- languages
                    182:     {
1.158     raeburn   183:         my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
                    184:                                    '/language.tab';
                    185:         if ( open(my $fh,"<$langtabfile") ) {
1.356     albertel  186:             while (my $line = <$fh>) {
                    187:                 next if ($line=~/^\#/);
                    188:                 chomp($line);
                    189:                 my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$line));
1.158     raeburn   190:                 $language{$key}=$val.' - '.$enc;
                    191:                 if ($sup) {
                    192:                     $supported_language{$key}=$sup;
                    193:                 }
                    194:             }
                    195:             close($fh);
                    196:         }
1.12      harris41  197:     }
                    198: # ------------------------------------------------------------------ copyrights
                    199:     {
1.158     raeburn   200:         my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
                    201:                                   '/copyright.tab';
                    202:         if ( open (my $fh,"<$copyrightfile") ) {
1.356     albertel  203:             while (my $line = <$fh>) {
                    204:                 next if ($line=~/^\#/);
                    205:                 chomp($line);
                    206:                 my ($key,$val)=(split(/\s+/,$line,2));
1.158     raeburn   207:                 $cprtag{$key}=$val;
                    208:             }
                    209:             close($fh);
                    210:         }
1.12      harris41  211:     }
1.351     www       212: # ----------------------------------------------------------- source copyrights
1.192     taceyjo1  213:     {
                    214:         my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
                    215:                                   '/source_copyright.tab';
                    216:         if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356     albertel  217:             while (my $line = <$fh>) {
                    218:                 next if ($line =~ /^\#/);
                    219:                 chomp($line);
                    220:                 my ($key,$val)=(split(/\s+/,$line,2));
1.192     taceyjo1  221:                 $scprtag{$key}=$val;
                    222:             }
                    223:             close($fh);
                    224:         }
                    225:     }
1.63      www       226: 
1.517     raeburn   227: # -------------------------------------------------------------- default domain designs
1.63      www       228:     my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517     raeburn   229:     my $designfile = $designdir.'/default.tab';
                    230:     if ( open (my $fh,"<$designfile") ) {
                    231:         while (my $line = <$fh>) {
                    232:             next if ($line =~ /^\#/);
                    233:             chomp($line);
                    234:             my ($key,$val)=(split(/\=/,$line));
                    235:             if ($val) { $defaultdesign{$key}=$val; }
                    236:         }
                    237:         close($fh);
1.63      www       238:     }
                    239: 
1.15      harris41  240: # ------------------------------------------------------------- file categories
                    241:     {
1.158     raeburn   242:         my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
                    243:                                   '/filecategories.tab';
                    244:         if ( open (my $fh,"<$categoryfile") ) {
1.356     albertel  245: 	    while (my $line = <$fh>) {
                    246: 		next if ($line =~ /^\#/);
                    247: 		chomp($line);
                    248:                 my ($extension,$category)=(split(/\s+/,$line,2));
1.158     raeburn   249:                 push @{$category_extensions{lc($category)}},$extension;
                    250:             }
                    251:             close($fh);
                    252:         }
                    253: 
1.15      harris41  254:     }
1.12      harris41  255: # ------------------------------------------------------------------ file types
                    256:     {
1.158     raeburn   257:         my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
                    258:                '/filetypes.tab';
                    259:         if ( open (my $fh,"<$typesfile") ) {
1.356     albertel  260:             while (my $line = <$fh>) {
                    261: 		next if ($line =~ /^\#/);
                    262: 		chomp($line);
                    263:                 my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158     raeburn   264:                 if ($descr ne '') {
                    265:                     $fe{$ending}=lc($emb);
                    266:                     $fd{$ending}=$descr;
1.351     www       267:                     if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158     raeburn   268:                 }
                    269:             }
                    270:             close($fh);
                    271:         }
1.12      harris41  272:     }
1.22      www       273:     &Apache::lonnet::logthis(
1.705     tempelho  274:              "<span style='color:yellow;'>INFO: Read file types</span>");
1.22      www       275:     $readit=1;
1.46      matthew   276:     }  # end of unless($readit) 
1.32      matthew   277:     
                    278: }
1.112     bowersj2  279: 
1.42      matthew   280: ###############################################################
                    281: ##           HTML and Javascript Helper Functions            ##
                    282: ###############################################################
                    283: 
                    284: =pod 
                    285: 
1.112     bowersj2  286: =head1 HTML and Javascript Functions
1.42      matthew   287: 
1.112     bowersj2  288: =over 4
                    289: 
1.648     raeburn   290: =item * &browser_and_searcher_javascript()
1.112     bowersj2  291: 
                    292: X<browsing, javascript>X<searching, javascript>Returns a string
                    293: containing javascript with two functions, C<openbrowser> and
                    294: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
                    295: tags.
1.42      matthew   296: 
1.648     raeburn   297: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42      matthew   298: 
                    299: inputs: formname, elementname, only, omit
                    300: 
                    301: formname and elementname indicate the name of the html form and name of
                    302: the element that the results of the browsing selection are to be placed in. 
                    303: 
                    304: Specifying 'only' will restrict the browser to displaying only files
1.185     www       305: with the given extension.  Can be a comma separated list.
1.42      matthew   306: 
                    307: Specifying 'omit' will restrict the browser to NOT displaying files
1.185     www       308: with the given extension.  Can be a comma separated list.
1.42      matthew   309: 
1.648     raeburn   310: =item * &opensearcher(formname,elementname) [javascript]
1.42      matthew   311: 
                    312: Inputs: formname, elementname
                    313: 
                    314: formname and elementname specify the name of the html form and the name
                    315: of the element the selection from the search results will be placed in.
1.542     raeburn   316: 
1.42      matthew   317: =cut
                    318: 
                    319: sub browser_and_searcher_javascript {
1.199     albertel  320:     my ($mode)=@_;
                    321:     if (!defined($mode)) { $mode='edit'; }
1.453     albertel  322:     my $resurl=&escape_single(&lastresurl());
1.42      matthew   323:     return <<END;
1.219     albertel  324: // <!-- BEGIN LON-CAPA Internal
1.50      matthew   325:     var editbrowser = null;
1.135     albertel  326:     function openbrowser(formname,elementname,only,omit,titleelement) {
1.170     www       327:         var url = '$resurl/?';
1.42      matthew   328:         if (editbrowser == null) {
                    329:             url += 'launch=1&';
                    330:         }
                    331:         url += 'catalogmode=interactive&';
1.199     albertel  332:         url += 'mode=$mode&';
1.611     albertel  333:         url += 'inhibitmenu=yes&';
1.42      matthew   334:         url += 'form=' + formname + '&';
                    335:         if (only != null) {
                    336:             url += 'only=' + only + '&';
1.217     albertel  337:         } else {
                    338:             url += 'only=&';
                    339: 	}
1.42      matthew   340:         if (omit != null) {
                    341:             url += 'omit=' + omit + '&';
1.217     albertel  342:         } else {
                    343:             url += 'omit=&';
                    344: 	}
1.135     albertel  345:         if (titleelement != null) {
                    346:             url += 'titleelement=' + titleelement + '&';
1.217     albertel  347:         } else {
                    348: 	    url += 'titleelement=&';
                    349: 	}
1.42      matthew   350:         url += 'element=' + elementname + '';
                    351:         var title = 'Browser';
1.435     albertel  352:         var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42      matthew   353:         options += ',width=700,height=600';
                    354:         editbrowser = open(url,title,options,'1');
                    355:         editbrowser.focus();
                    356:     }
                    357:     var editsearcher;
1.135     albertel  358:     function opensearcher(formname,elementname,titleelement) {
1.42      matthew   359:         var url = '/adm/searchcat?';
                    360:         if (editsearcher == null) {
                    361:             url += 'launch=1&';
                    362:         }
                    363:         url += 'catalogmode=interactive&';
1.199     albertel  364:         url += 'mode=$mode&';
1.42      matthew   365:         url += 'form=' + formname + '&';
1.135     albertel  366:         if (titleelement != null) {
                    367:             url += 'titleelement=' + titleelement + '&';
1.217     albertel  368:         } else {
                    369: 	    url += 'titleelement=&';
                    370: 	}
1.42      matthew   371:         url += 'element=' + elementname + '';
                    372:         var title = 'Search';
1.435     albertel  373:         var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42      matthew   374:         options += ',width=700,height=600';
                    375:         editsearcher = open(url,title,options,'1');
                    376:         editsearcher.focus();
                    377:     }
1.219     albertel  378: // END LON-CAPA Internal -->
1.42      matthew   379: END
1.170     www       380: }
                    381: 
                    382: sub lastresurl {
1.258     albertel  383:     if ($env{'environment.lastresurl'}) {
                    384: 	return $env{'environment.lastresurl'}
1.170     www       385:     } else {
                    386: 	return '/res';
                    387:     }
                    388: }
                    389: 
                    390: sub storeresurl {
                    391:     my $resurl=&Apache::lonnet::clutter(shift);
                    392:     unless ($resurl=~/^\/res/) { return 0; }
                    393:     $resurl=~s/\/$//;
                    394:     &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646     raeburn   395:     &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170     www       396:     return 1;
1.42      matthew   397: }
                    398: 
1.74      www       399: sub studentbrowser_javascript {
1.111     www       400:    unless (
1.258     albertel  401:             (($env{'request.course.id'}) && 
1.302     albertel  402:              (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
                    403: 	      || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
                    404: 					  '/'.$env{'request.course.sec'})
                    405: 	      ))
1.258     albertel  406:          || ($env{'request.role'}=~/^(au|dc|su)/)
1.111     www       407:           ) { return ''; }  
1.74      www       408:    return (<<'ENDSTDBRW');
1.776     bisitz    409: <script type="text/javascript" language="Javascript">
1.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:     }
                    903:     return &select_form($selected,$name,%langchoices);
                    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.648     raeburn  1075: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height)
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.48      bowersj2 1098:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
                   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.763     bisitz   1127:     $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
                   1128:               .'<img src="'.$helpicon.'" border="0"'
                   1129:               .' alt="'.&mt('Help: [_1]',$topic).'"'
1.934     droeschl 1130:               .' title="'.$title.'" style="vertical-align:middle;"' 
1.763     bisitz   1131:               .' /></a>';
                   1132:     if ($text ne "") {	
                   1133:         $template.='</span>';
                   1134:     }
1.44      bowersj2 1135:     return $template;
                   1136: 
1.106     bowersj2 1137: }
                   1138: 
                   1139: # This is a quicky function for Latex cheatsheet editing, since it 
                   1140: # appears in at least four places
                   1141: sub helpLatexCheatsheet {
1.732     raeburn  1142:     my ($topic,$text,$not_author) = @_;
                   1143:     my $out;
1.106     bowersj2 1144:     my $addOther = '';
1.732     raeburn  1145:     if ($topic) {
1.763     bisitz   1146: 	$addOther = '<span>'.&Apache::loncommon::help_open_topic($topic,&mt($text),
                   1147: 							       undef, undef, 600).
                   1148: 								   '</span> ';
                   1149:     }
                   1150:     $out = '<span>' # Start cheatsheet
                   1151: 	  .$addOther
                   1152:           .'<span>'
                   1153: 	  .&Apache::loncommon::help_open_topic('Greek_Symbols',&mt('Greek Symbols'),
                   1154: 					       undef,undef,600)
                   1155: 	  .'</span> <span>'
                   1156: 	  .&Apache::loncommon::help_open_topic('Other_Symbols',&mt('Other Symbols'),
                   1157: 					       undef,undef,600)
                   1158: 	  .'</span>';
1.732     raeburn  1159:     unless ($not_author) {
1.763     bisitz   1160:         $out .= ' <span>'
                   1161: 	       .&Apache::loncommon::help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),
                   1162: 	                                            undef,undef,600)
                   1163: 	       .'</span>';
1.732     raeburn  1164:     }
1.763     bisitz   1165:     $out .= '</span>'; # End cheatsheet
1.732     raeburn  1166:     return $out;
1.172     www      1167: }
                   1168: 
1.430     albertel 1169: sub general_help {
                   1170:     my $helptopic='Student_Intro';
                   1171:     if ($env{'request.role'}=~/^(ca|au)/) {
                   1172: 	$helptopic='Authoring_Intro';
1.907     raeburn  1173:     } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430     albertel 1174: 	$helptopic='Course_Coordination_Intro';
1.672     raeburn  1175:     } elsif ($env{'request.role'}=~/^dc/) {
                   1176:         $helptopic='Domain_Coordination_Intro';
1.430     albertel 1177:     }
                   1178:     return $helptopic;
                   1179: }
                   1180: 
                   1181: sub update_help_link {
                   1182:     my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
                   1183:     my $origurl = $ENV{'REQUEST_URI'};
                   1184:     $origurl=~s|^/~|/priv/|;
                   1185:     my $timestamp = time;
                   1186:     foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
                   1187:         $$datum = &escape($$datum);
                   1188:     }
                   1189: 
                   1190:     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";
                   1191:     my $output .= <<"ENDOUTPUT";
                   1192: <script type="text/javascript">
1.824     bisitz   1193: // <![CDATA[
1.430     albertel 1194: banner_link = '$banner_link';
1.824     bisitz   1195: // ]]>
1.430     albertel 1196: </script>
                   1197: ENDOUTPUT
                   1198:     return $output;
                   1199: }
                   1200: 
                   1201: # now just updates the help link and generates a blue icon
1.193     raeburn  1202: sub help_open_menu {
1.430     albertel 1203:     my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text) 
1.552     banghart 1204: 	= @_;    
1.949     droeschl 1205:     $stayOnPage = 1;
1.430     albertel 1206:     my $output;
                   1207:     if ($component_help) {
                   1208: 	if (!$text) {
                   1209: 	    $output=&help_open_topic($component_help,undef,$stayOnPage,
                   1210: 				       $width,$height);
                   1211: 	} else {
                   1212: 	    my $help_text;
                   1213: 	    $help_text=&unescape($topic);
                   1214: 	    $output='<table><tr><td>'.
                   1215: 		&help_open_topic($component_help,$help_text,$stayOnPage,
                   1216: 				 $width,$height).'</td></tr></table>';
                   1217: 	}
                   1218:     }
                   1219:     my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
                   1220:     return $output.$banner_link;
                   1221: }
                   1222: 
                   1223: sub top_nav_help {
                   1224:     my ($text) = @_;
1.436     albertel 1225:     $text = &mt($text);
1.949     droeschl 1226:     my $stay_on_page = 1;
                   1227: 
1.572     banghart 1228:     my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436     albertel 1229: 	                     : "javascript:helpMenu('open')";
1.572     banghart 1230:     my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436     albertel 1231: 
1.201     raeburn  1232:     my $title = &mt('Get help');
1.436     albertel 1233: 
                   1234:     return <<"END";
                   1235: $banner_link
                   1236:  <a href="$link" title="$title">$text</a>
                   1237: END
                   1238: }
                   1239: 
                   1240: sub help_menu_js {
                   1241:     my ($text) = @_;
1.949     droeschl 1242:     my $stayOnPage = 1;
1.436     albertel 1243:     my $width = 620;
                   1244:     my $height = 600;
1.430     albertel 1245:     my $helptopic=&general_help();
                   1246:     my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261     albertel 1247:     my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331     albertel 1248:     my $start_page =
                   1249:         &Apache::loncommon::start_page('Help Menu', undef,
                   1250: 				       {'frameset'    => 1,
                   1251: 					'js_ready'    => 1,
                   1252: 					'add_entries' => {
                   1253: 					    'border' => '0',
1.579     raeburn  1254: 					    'rows'   => "110,*",},});
1.331     albertel 1255:     my $end_page =
                   1256:         &Apache::loncommon::end_page({'frameset' => 1,
                   1257: 				      'js_ready' => 1,});
                   1258: 
1.436     albertel 1259:     my $template .= <<"ENDTEMPLATE";
                   1260: <script type="text/javascript">
1.877     bisitz   1261: // <![CDATA[
1.253     albertel 1262: // <!-- BEGIN LON-CAPA Internal
1.430     albertel 1263: var banner_link = '';
1.243     raeburn  1264: function helpMenu(target) {
                   1265:     var caller = this;
                   1266:     if (target == 'open') {
                   1267:         var newWindow = null;
                   1268:         try {
1.262     albertel 1269:             newWindow =  window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243     raeburn  1270:         }
                   1271:         catch(error) {
                   1272:             writeHelp(caller);
                   1273:             return;
                   1274:         }
                   1275:         if (newWindow) {
                   1276:             caller = newWindow;
                   1277:         }
1.193     raeburn  1278:     }
1.243     raeburn  1279:     writeHelp(caller);
                   1280:     return;
                   1281: }
                   1282: function writeHelp(caller) {
1.430     albertel 1283:     caller.document.writeln('$start_page<frame name="bannerframe"  src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243     raeburn  1284:     caller.document.close()
                   1285:     caller.focus()
1.193     raeburn  1286: }
1.877     bisitz   1287: // END LON-CAPA Internal -->
1.253     albertel 1288: // ]]>
1.436     albertel 1289: </script>
1.193     raeburn  1290: ENDTEMPLATE
                   1291:     return $template;
                   1292: }
                   1293: 
1.172     www      1294: sub help_open_bug {
                   1295:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258     albertel 1296:     unless ($env{'user.adv'}) { return ''; }
1.172     www      1297:     unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
                   1298:     $text = "" if (not defined $text);
                   1299: 	$stayOnPage=1;
1.184     albertel 1300:     $width = 600 if (not defined $width);
                   1301:     $height = 600 if (not defined $height);
1.172     www      1302: 
                   1303:     $topic=~s/\W+/\+/g;
                   1304:     my $link='';
                   1305:     my $template='';
1.379     albertel 1306:     my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&amp;bug_file_loc='.
                   1307: 	&escape($ENV{'REQUEST_URI'}).'&amp;component='.$topic;
1.172     www      1308:     if (!$stayOnPage)
                   1309:     {
                   1310: 	$link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
                   1311:     }
                   1312:     else
                   1313:     {
                   1314: 	$link = $url;
                   1315:     }
                   1316:     # Add the text
                   1317:     if ($text ne "")
                   1318:     {
                   1319: 	$template .= 
                   1320:   "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705     tempelho 1321:   "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172     www      1322:     }
                   1323: 
                   1324:     # Add the graphic
1.179     matthew  1325:     my $title = &mt('Report a Bug');
1.215     albertel 1326:     my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172     www      1327:     $template .= <<"ENDTEMPLATE";
1.436     albertel 1328:  <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172     www      1329: ENDTEMPLATE
                   1330:     if ($text ne '') { $template.='</td></tr></table>' };
                   1331:     return $template;
                   1332: 
                   1333: }
                   1334: 
                   1335: sub help_open_faq {
                   1336:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258     albertel 1337:     unless ($env{'user.adv'}) { return ''; }
1.172     www      1338:     unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
                   1339:     $text = "" if (not defined $text);
                   1340: 	$stayOnPage=1;
                   1341:     $width = 350 if (not defined $width);
                   1342:     $height = 400 if (not defined $height);
                   1343: 
                   1344:     $topic=~s/\W+/\+/g;
                   1345:     my $link='';
                   1346:     my $template='';
                   1347:     my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
                   1348:     if (!$stayOnPage)
                   1349:     {
                   1350: 	$link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
                   1351:     }
                   1352:     else
                   1353:     {
                   1354: 	$link = $url;
                   1355:     }
                   1356: 
                   1357:     # Add the text
                   1358:     if ($text ne "")
                   1359:     {
                   1360: 	$template .= 
1.173     www      1361:   "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705     tempelho 1362:   "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172     www      1363:     }
                   1364: 
                   1365:     # Add the graphic
1.179     matthew  1366:     my $title = &mt('View the FAQ');
1.215     albertel 1367:     my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172     www      1368:     $template .= <<"ENDTEMPLATE";
1.436     albertel 1369:  <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172     www      1370: ENDTEMPLATE
                   1371:     if ($text ne '') { $template.='</td></tr></table>' };
                   1372:     return $template;
                   1373: 
1.44      bowersj2 1374: }
1.37      matthew  1375: 
1.180     matthew  1376: ###############################################################
                   1377: ###############################################################
                   1378: 
1.45      matthew  1379: =pod
                   1380: 
1.648     raeburn  1381: =item * &change_content_javascript():
1.256     matthew  1382: 
                   1383: This and the next function allow you to create small sections of an
                   1384: otherwise static HTML page that you can update on the fly with
                   1385: Javascript, even in Netscape 4.
                   1386: 
                   1387: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
                   1388: must be written to the HTML page once. It will prove the Javascript
                   1389: function "change(name, content)". Calling the change function with the
                   1390: name of the section 
                   1391: you want to update, matching the name passed to C<changable_area>, and
                   1392: the new content you want to put in there, will put the content into
                   1393: that area.
                   1394: 
                   1395: B<Note>: Netscape 4 only reserves enough space for the changable area
                   1396: to contain room for the original contents. You need to "make space"
                   1397: for whatever changes you wish to make, and be B<sure> to check your
                   1398: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
                   1399: it's adequate for updating a one-line status display, but little more.
                   1400: This script will set the space to 100% width, so you only need to
                   1401: worry about height in Netscape 4.
                   1402: 
                   1403: Modern browsers are much less limiting, and if you can commit to the
                   1404: user not using Netscape 4, this feature may be used freely with
                   1405: pretty much any HTML.
                   1406: 
                   1407: =cut
                   1408: 
                   1409: sub change_content_javascript {
                   1410:     # If we're on Netscape 4, we need to use Layer-based code
1.258     albertel 1411:     if ($env{'browser.type'} eq 'netscape' &&
                   1412: 	$env{'browser.version'} =~ /^4\./) {
1.256     matthew  1413: 	return (<<NETSCAPE4);
                   1414: 	function change(name, content) {
                   1415: 	    doc = document.layers[name+"___escape"].layers[0].document;
                   1416: 	    doc.open();
                   1417: 	    doc.write(content);
                   1418: 	    doc.close();
                   1419: 	}
                   1420: NETSCAPE4
                   1421:     } else {
                   1422: 	# Otherwise, we need to use semi-standards-compliant code
                   1423: 	# (technically, "innerHTML" isn't standard but the equivalent
                   1424: 	# is really scary, and every useful browser supports it
                   1425: 	return (<<DOMBASED);
                   1426: 	function change(name, content) {
                   1427: 	    element = document.getElementById(name);
                   1428: 	    element.innerHTML = content;
                   1429: 	}
                   1430: DOMBASED
                   1431:     }
                   1432: }
                   1433: 
                   1434: =pod
                   1435: 
1.648     raeburn  1436: =item * &changable_area($name,$origContent):
1.256     matthew  1437: 
                   1438: This provides a "changable area" that can be modified on the fly via
                   1439: the Javascript code provided in C<change_content_javascript>. $name is
                   1440: the name you will use to reference the area later; do not repeat the
                   1441: same name on a given HTML page more then once. $origContent is what
                   1442: the area will originally contain, which can be left blank.
                   1443: 
                   1444: =cut
                   1445: 
                   1446: sub changable_area {
                   1447:     my ($name, $origContent) = @_;
                   1448: 
1.258     albertel 1449:     if ($env{'browser.type'} eq 'netscape' &&
                   1450: 	$env{'browser.version'} =~ /^4\./) {
1.256     matthew  1451: 	# If this is netscape 4, we need to use the Layer tag
                   1452: 	return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
                   1453:     } else {
                   1454: 	return "<span id='$name'>$origContent</span>";
                   1455:     }
                   1456: }
                   1457: 
                   1458: =pod
                   1459: 
1.648     raeburn  1460: =item * &viewport_geometry_js 
1.590     raeburn  1461: 
                   1462: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
                   1463: 
                   1464: =cut
                   1465: 
                   1466: 
                   1467: sub viewport_geometry_js { 
                   1468:     return <<"GEOMETRY";
                   1469: var Geometry = {};
                   1470: function init_geometry() {
                   1471:     if (Geometry.init) { return };
                   1472:     Geometry.init=1;
                   1473:     if (window.innerHeight) {
                   1474:         Geometry.getViewportHeight   = function() { return window.innerHeight; };
                   1475:         Geometry.getViewportWidth   = function() { return window.innerWidth; };
                   1476:         Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
                   1477:         Geometry.getVerticalScroll   = function() { return window.pageYOffset; };
                   1478:     }
                   1479:     else if (document.documentElement && document.documentElement.clientHeight) {
                   1480:         Geometry.getViewportHeight =
                   1481:             function() { return document.documentElement.clientHeight; };
                   1482:         Geometry.getViewportWidth =
                   1483:             function() { return document.documentElement.clientWidth; };
                   1484: 
                   1485:         Geometry.getHorizontalScroll =
                   1486:             function() { return document.documentElement.scrollLeft; };
                   1487:         Geometry.getVerticalScroll =
                   1488:             function() { return document.documentElement.scrollTop; };
                   1489:     }
                   1490:     else if (document.body.clientHeight) {
                   1491:         Geometry.getViewportHeight =
                   1492:             function() { return document.body.clientHeight; };
                   1493:         Geometry.getViewportWidth =
                   1494:             function() { return document.body.clientWidth; };
                   1495:         Geometry.getHorizontalScroll =
                   1496:             function() { return document.body.scrollLeft; };
                   1497:         Geometry.getVerticalScroll =
                   1498:             function() { return document.body.scrollTop; };
                   1499:     }
                   1500: }
                   1501: 
                   1502: GEOMETRY
                   1503: }
                   1504: 
                   1505: =pod
                   1506: 
1.648     raeburn  1507: =item * &viewport_size_js()
1.590     raeburn  1508: 
                   1509: 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. 
                   1510: 
                   1511: =cut
                   1512: 
                   1513: sub viewport_size_js {
                   1514:     my $geometry = &viewport_geometry_js();
                   1515:     return <<"DIMS";
                   1516: 
                   1517: $geometry
                   1518: 
                   1519: function getViewportDims(width,height) {
                   1520:     init_geometry();
                   1521:     width.value = Geometry.getViewportWidth();
                   1522:     height.value = Geometry.getViewportHeight();
                   1523:     return;
                   1524: }
                   1525: 
                   1526: DIMS
                   1527: }
                   1528: 
                   1529: =pod
                   1530: 
1.648     raeburn  1531: =item * &resize_textarea_js()
1.565     albertel 1532: 
                   1533: emits the needed javascript to resize a textarea to be as big as possible
                   1534: 
                   1535: creates a function resize_textrea that takes two IDs first should be
                   1536: the id of the element to resize, second should be the id of a div that
                   1537: surrounds everything that comes after the textarea, this routine needs
                   1538: to be attached to the <body> for the onload and onresize events.
                   1539: 
1.648     raeburn  1540: =back
1.565     albertel 1541: 
                   1542: =cut
                   1543: 
                   1544: sub resize_textarea_js {
1.590     raeburn  1545:     my $geometry = &viewport_geometry_js();
1.565     albertel 1546:     return <<"RESIZE";
                   1547:     <script type="text/javascript">
1.824     bisitz   1548: // <![CDATA[
1.590     raeburn  1549: $geometry
1.565     albertel 1550: 
1.588     albertel 1551: function getX(element) {
                   1552:     var x = 0;
                   1553:     while (element) {
                   1554: 	x += element.offsetLeft;
                   1555: 	element = element.offsetParent;
                   1556:     }
                   1557:     return x;
                   1558: }
                   1559: function getY(element) {
                   1560:     var y = 0;
                   1561:     while (element) {
                   1562: 	y += element.offsetTop;
                   1563: 	element = element.offsetParent;
                   1564:     }
                   1565:     return y;
                   1566: }
                   1567: 
                   1568: 
1.565     albertel 1569: function resize_textarea(textarea_id,bottom_id) {
                   1570:     init_geometry();
                   1571:     var textarea        = document.getElementById(textarea_id);
                   1572:     //alert(textarea);
                   1573: 
1.588     albertel 1574:     var textarea_top    = getY(textarea);
1.565     albertel 1575:     var textarea_height = textarea.offsetHeight;
                   1576:     var bottom          = document.getElementById(bottom_id);
1.588     albertel 1577:     var bottom_top      = getY(bottom);
1.565     albertel 1578:     var bottom_height   = bottom.offsetHeight;
                   1579:     var window_height   = Geometry.getViewportHeight();
1.588     albertel 1580:     var fudge           = 23;
1.565     albertel 1581:     var new_height      = window_height-fudge-textarea_top-bottom_height;
                   1582:     if (new_height < 300) {
                   1583: 	new_height = 300;
                   1584:     }
                   1585:     textarea.style.height=new_height+'px';
                   1586: }
1.824     bisitz   1587: // ]]>
1.565     albertel 1588: </script>
                   1589: RESIZE
                   1590: 
                   1591: }
                   1592: 
                   1593: =pod
                   1594: 
1.256     matthew  1595: =head1 Excel and CSV file utility routines
                   1596: 
                   1597: =over 4
                   1598: 
                   1599: =cut
                   1600: 
                   1601: ###############################################################
                   1602: ###############################################################
                   1603: 
                   1604: =pod
                   1605: 
1.648     raeburn  1606: =item * &csv_translate($text) 
1.37      matthew  1607: 
1.185     www      1608: Translate $text to allow it to be output as a 'comma separated values' 
1.37      matthew  1609: format.
                   1610: 
                   1611: =cut
                   1612: 
1.180     matthew  1613: ###############################################################
                   1614: ###############################################################
1.37      matthew  1615: sub csv_translate {
                   1616:     my $text = shift;
                   1617:     $text =~ s/\"/\"\"/g;
1.209     albertel 1618:     $text =~ s/\n/ /g;
1.37      matthew  1619:     return $text;
                   1620: }
1.180     matthew  1621: 
                   1622: ###############################################################
                   1623: ###############################################################
                   1624: 
                   1625: =pod
                   1626: 
1.648     raeburn  1627: =item * &define_excel_formats()
1.180     matthew  1628: 
                   1629: Define some commonly used Excel cell formats.
                   1630: 
                   1631: Currently supported formats:
                   1632: 
                   1633: =over 4
                   1634: 
                   1635: =item header
                   1636: 
                   1637: =item bold
                   1638: 
                   1639: =item h1
                   1640: 
                   1641: =item h2
                   1642: 
                   1643: =item h3
                   1644: 
1.256     matthew  1645: =item h4
                   1646: 
                   1647: =item i
                   1648: 
1.180     matthew  1649: =item date
                   1650: 
                   1651: =back
                   1652: 
                   1653: Inputs: $workbook
                   1654: 
                   1655: Returns: $format, a hash reference.
                   1656: 
                   1657: =cut
                   1658: 
                   1659: ###############################################################
                   1660: ###############################################################
                   1661: sub define_excel_formats {
                   1662:     my ($workbook) = @_;
                   1663:     my $format;
                   1664:     $format->{'header'} = $workbook->add_format(bold      => 1, 
                   1665:                                                 bottom    => 1,
                   1666:                                                 align     => 'center');
                   1667:     $format->{'bold'} = $workbook->add_format(bold=>1);
                   1668:     $format->{'h1'}   = $workbook->add_format(bold=>1, size=>18);
                   1669:     $format->{'h2'}   = $workbook->add_format(bold=>1, size=>16);
                   1670:     $format->{'h3'}   = $workbook->add_format(bold=>1, size=>14);
1.255     matthew  1671:     $format->{'h4'}   = $workbook->add_format(bold=>1, size=>12);
1.246     matthew  1672:     $format->{'i'}    = $workbook->add_format(italic=>1);
1.180     matthew  1673:     $format->{'date'} = $workbook->add_format(num_format=>
1.207     matthew  1674:                                             'mm/dd/yyyy hh:mm:ss');
1.180     matthew  1675:     return $format;
                   1676: }
                   1677: 
                   1678: ###############################################################
                   1679: ###############################################################
1.113     bowersj2 1680: 
                   1681: =pod
                   1682: 
1.648     raeburn  1683: =item * &create_workbook()
1.255     matthew  1684: 
                   1685: Create an Excel worksheet.  If it fails, output message on the
                   1686: request object and return undefs.
                   1687: 
                   1688: Inputs: Apache request object
                   1689: 
                   1690: Returns (undef) on failure, 
                   1691:     Excel worksheet object, scalar with filename, and formats 
                   1692:     from &Apache::loncommon::define_excel_formats on success
                   1693: 
                   1694: =cut
                   1695: 
                   1696: ###############################################################
                   1697: ###############################################################
                   1698: sub create_workbook {
                   1699:     my ($r) = @_;
                   1700:         #
                   1701:     # Create the excel spreadsheet
                   1702:     my $filename = '/prtspool/'.
1.258     albertel 1703:         $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255     matthew  1704:         time.'_'.rand(1000000000).'.xls';
                   1705:     my $workbook  = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
                   1706:     if (! defined($workbook)) {
                   1707:         $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928     bisitz   1708:         $r->print(
                   1709:             '<p class="LC_error">'
                   1710:            .&mt('Problems occurred in creating the new Excel file.')
                   1711:            .' '.&mt('This error has been logged.')
                   1712:            .' '.&mt('Please alert your LON-CAPA administrator.')
                   1713:            .'</p>'
                   1714:         );
1.255     matthew  1715:         return (undef);
                   1716:     }
                   1717:     #
                   1718:     $workbook->set_tempdir('/home/httpd/perl/tmp');
                   1719:     #
                   1720:     my $format = &Apache::loncommon::define_excel_formats($workbook);
                   1721:     return ($workbook,$filename,$format);
                   1722: }
                   1723: 
                   1724: ###############################################################
                   1725: ###############################################################
                   1726: 
                   1727: =pod
                   1728: 
1.648     raeburn  1729: =item * &create_text_file()
1.113     bowersj2 1730: 
1.542     raeburn  1731: Create a file to write to and eventually make available to the user.
1.256     matthew  1732: If file creation fails, outputs an error message on the request object and 
                   1733: return undefs.
1.113     bowersj2 1734: 
1.256     matthew  1735: Inputs: Apache request object, and file suffix
1.113     bowersj2 1736: 
1.256     matthew  1737: Returns (undef) on failure, 
                   1738:     Filehandle and filename on success.
1.113     bowersj2 1739: 
                   1740: =cut
                   1741: 
1.256     matthew  1742: ###############################################################
                   1743: ###############################################################
                   1744: sub create_text_file {
                   1745:     my ($r,$suffix) = @_;
                   1746:     if (! defined($suffix)) { $suffix = 'txt'; };
                   1747:     my $fh;
                   1748:     my $filename = '/prtspool/'.
1.258     albertel 1749:         $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256     matthew  1750:         time.'_'.rand(1000000000).'.'.$suffix;
                   1751:     $fh = Apache::File->new('>/home/httpd'.$filename);
                   1752:     if (! defined($fh)) {
                   1753:         $r->log_error("Couldn't open $filename for output $!");
1.928     bisitz   1754:         $r->print(
                   1755:             '<p class="LC_error">'
                   1756:            .&mt('Problems occurred in creating the output file.')
                   1757:            .' '.&mt('This error has been logged.')
                   1758:            .' '.&mt('Please alert your LON-CAPA administrator.')
                   1759:            .'</p>'
                   1760:         );
1.113     bowersj2 1761:     }
1.256     matthew  1762:     return ($fh,$filename)
1.113     bowersj2 1763: }
                   1764: 
                   1765: 
1.256     matthew  1766: =pod 
1.113     bowersj2 1767: 
                   1768: =back
                   1769: 
                   1770: =cut
1.37      matthew  1771: 
                   1772: ###############################################################
1.33      matthew  1773: ##        Home server <option> list generating code          ##
                   1774: ###############################################################
1.35      matthew  1775: 
1.169     www      1776: # ------------------------------------------
                   1777: 
                   1778: sub domain_select {
                   1779:     my ($name,$value,$multiple)=@_;
                   1780:     my %domains=map { 
1.514     albertel 1781: 	$_ => $_.' '. &Apache::lonnet::domain($_,'description') 
1.512     albertel 1782:     } &Apache::lonnet::all_domains();
1.169     www      1783:     if ($multiple) {
                   1784: 	$domains{''}=&mt('Any domain');
1.550     albertel 1785: 	$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287     albertel 1786: 	return &multiple_select_form($name,$value,4,\%domains);
1.169     www      1787:     } else {
1.550     albertel 1788: 	$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.169     www      1789: 	return &select_form($name,$value,%domains);
                   1790:     }
                   1791: }
                   1792: 
1.282     albertel 1793: #-------------------------------------------
                   1794: 
                   1795: =pod
                   1796: 
1.519     raeburn  1797: =head1 Routines for form select boxes
                   1798: 
                   1799: =over 4
                   1800: 
1.648     raeburn  1801: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282     albertel 1802: 
                   1803: Returns a string containing a <select> element int multiple mode
                   1804: 
                   1805: 
                   1806: Args:
                   1807:   $name - name of the <select> element
1.506     raeburn  1808:   $value - scalar or array ref of values that should already be selected
1.282     albertel 1809:   $size - number of rows long the select element is
1.283     albertel 1810:   $hash - the elements should be 'option' => 'shown text'
1.282     albertel 1811:           (shown text should already have been &mt())
1.506     raeburn  1812:   $order - (optional) array ref of the order to show the elements in
1.283     albertel 1813: 
1.282     albertel 1814: =cut
                   1815: 
                   1816: #-------------------------------------------
1.169     www      1817: sub multiple_select_form {
1.284     albertel 1818:     my ($name,$value,$size,$hash,$order)=@_;
1.169     www      1819:     my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
                   1820:     my $output='';
1.191     matthew  1821:     if (! defined($size)) {
                   1822:         $size = 4;
1.283     albertel 1823:         if (scalar(keys(%$hash))<4) {
                   1824:             $size = scalar(keys(%$hash));
1.191     matthew  1825:         }
                   1826:     }
1.734     bisitz   1827:     $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501     banghart 1828:     my @order;
1.506     raeburn  1829:     if (ref($order) eq 'ARRAY')  {
                   1830:         @order = @{$order};
                   1831:     } else {
                   1832:         @order = sort(keys(%$hash));
1.501     banghart 1833:     }
                   1834:     if (exists($$hash{'select_form_order'})) {
                   1835:         @order = @{$$hash{'select_form_order'}};
                   1836:     }
                   1837:         
1.284     albertel 1838:     foreach my $key (@order) {
1.356     albertel 1839:         $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284     albertel 1840:         $output.='selected="selected" ' if ($selected{$key});
                   1841:         $output.='>'.$hash->{$key}."</option>\n";
1.169     www      1842:     }
                   1843:     $output.="</select>\n";
                   1844:     return $output;
                   1845: }
                   1846: 
1.88      www      1847: #-------------------------------------------
                   1848: 
                   1849: =pod
                   1850: 
1.648     raeburn  1851: =item * &select_form($defdom,$name,%hash)
1.88      www      1852: 
                   1853: Returns a string containing a <select name='$name' size='1'> form to 
                   1854: allow a user to select options from a hash option_name => displayed text.  
                   1855: See lonrights.pm for an example invocation and use.
                   1856: 
                   1857: =cut
                   1858: 
                   1859: #-------------------------------------------
                   1860: sub select_form {
                   1861:     my ($def,$name,%hash) = @_;
                   1862:     my $selectform = "<select name=\"$name\" size=\"1\">\n";
1.128     albertel 1863:     my @keys;
                   1864:     if (exists($hash{'select_form_order'})) {
                   1865: 	@keys=@{$hash{'select_form_order'}};
                   1866:     } else {
                   1867: 	@keys=sort(keys(%hash));
                   1868:     }
1.356     albertel 1869:     foreach my $key (@keys) {
                   1870:         $selectform.=
                   1871: 	    '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
                   1872:             ($key eq $def ? 'selected="selected" ' : '').
1.922     bisitz   1873:                 ">".$hash{$key}."</option>\n";
1.88      www      1874:     }
                   1875:     $selectform.="</select>";
                   1876:     return $selectform;
                   1877: }
                   1878: 
1.475     www      1879: # For display filters
                   1880: 
                   1881: sub display_filter {
                   1882:     if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477     www      1883:     if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.714     bisitz   1884:     return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1.475     www      1885: 			       &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
                   1886: 							   (&mt('all'),10,20,50,100,1000,10000))).
1.714     bisitz   1887: 	   '</label></span> <span class="LC_nobreak">'.
1.475     www      1888:            &mt('Filter [_1]',
1.477     www      1889: 	   &select_form($env{'form.displayfilter'},
                   1890: 			'displayfilter',
                   1891: 			('currentfolder' => 'Current folder/page',
                   1892: 			 'containing' => 'Containing phrase',
                   1893: 			 'none' => 'None'))).
1.714     bisitz   1894: 			 '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1.475     www      1895: }
                   1896: 
1.167     www      1897: sub gradeleveldescription {
                   1898:     my $gradelevel=shift;
                   1899:     my %gradelevels=(0 => 'Not specified',
                   1900: 		     1 => 'Grade 1',
                   1901: 		     2 => 'Grade 2',
                   1902: 		     3 => 'Grade 3',
                   1903: 		     4 => 'Grade 4',
                   1904: 		     5 => 'Grade 5',
                   1905: 		     6 => 'Grade 6',
                   1906: 		     7 => 'Grade 7',
                   1907: 		     8 => 'Grade 8',
                   1908: 		     9 => 'Grade 9',
                   1909: 		     10 => 'Grade 10',
                   1910: 		     11 => 'Grade 11',
                   1911: 		     12 => 'Grade 12',
                   1912: 		     13 => 'Grade 13',
                   1913: 		     14 => '100 Level',
                   1914: 		     15 => '200 Level',
                   1915: 		     16 => '300 Level',
                   1916: 		     17 => '400 Level',
                   1917: 		     18 => 'Graduate Level');
                   1918:     return &mt($gradelevels{$gradelevel});
                   1919: }
                   1920: 
1.163     www      1921: sub select_level_form {
                   1922:     my ($deflevel,$name)=@_;
                   1923:     unless ($deflevel) { $deflevel=0; }
1.167     www      1924:     my $selectform = "<select name=\"$name\" size=\"1\">\n";
                   1925:     for (my $i=0; $i<=18; $i++) {
                   1926:         $selectform.="<option value=\"$i\" ".
1.253     albertel 1927:             ($i==$deflevel ? 'selected="selected" ' : '').
1.167     www      1928:                 ">".&gradeleveldescription($i)."</option>\n";
                   1929:     }
                   1930:     $selectform.="</select>";
                   1931:     return $selectform;
1.163     www      1932: }
1.167     www      1933: 
1.35      matthew  1934: #-------------------------------------------
                   1935: 
1.45      matthew  1936: =pod
                   1937: 
1.910     raeburn  1938: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms)
1.35      matthew  1939: 
                   1940: Returns a string containing a <select name='$name' size='1'> form to 
                   1941: allow a user to select the domain to preform an operation in.  
                   1942: See loncreateuser.pm for an example invocation and use.
                   1943: 
1.90      www      1944: If the $includeempty flag is set, it also includes an empty choice ("no domain
                   1945: selected");
                   1946: 
1.743     raeburn  1947: If the $showdomdesc flag is set, the domain name is followed by the domain description.
                   1948: 
1.910     raeburn  1949: 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.
                   1950: 
                   1951: The optional $incdoms is a reference to an array of domains which will be the only available options. 
1.563     raeburn  1952: 
1.35      matthew  1953: =cut
                   1954: 
                   1955: #-------------------------------------------
1.34      matthew  1956: sub select_dom_form {
1.910     raeburn  1957:     my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms) = @_;
1.872     raeburn  1958:     if ($onchange) {
1.874     raeburn  1959:         $onchange = ' onchange="'.$onchange.'"';
1.743     raeburn  1960:     }
1.910     raeburn  1961:     my @domains;
                   1962:     if (ref($incdoms) eq 'ARRAY') {
                   1963:         @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
                   1964:     } else {
                   1965:         @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
                   1966:     }
1.90      www      1967:     if ($includeempty) { @domains=('',@domains); }
1.743     raeburn  1968:     my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356     albertel 1969:     foreach my $dom (@domains) {
                   1970:         $selectdomain.="<option value=\"$dom\" ".
1.563     raeburn  1971:             ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
                   1972:         if ($showdomdesc) {
                   1973:             if ($dom ne '') {
                   1974:                 my $domdesc = &Apache::lonnet::domain($dom,'description');
                   1975:                 if ($domdesc ne '') {
                   1976:                     $selectdomain .= ' ('.$domdesc.')';
                   1977:                 }
                   1978:             } 
                   1979:         }
                   1980:         $selectdomain .= "</option>\n";
1.34      matthew  1981:     }
                   1982:     $selectdomain.="</select>";
                   1983:     return $selectdomain;
                   1984: }
                   1985: 
1.35      matthew  1986: #-------------------------------------------
                   1987: 
1.45      matthew  1988: =pod
                   1989: 
1.648     raeburn  1990: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35      matthew  1991: 
1.586     raeburn  1992: input: 4 arguments (two required, two optional) - 
                   1993:     $domain - domain of new user
                   1994:     $name - name of form element
                   1995:     $default - Value of 'default' causes a default item to be first 
                   1996:                             option, and selected by default. 
                   1997:     $hide - Value of 'hide' causes hiding of the name of the server, 
                   1998:                             if 1 server found, or default, if 0 found.
1.594     raeburn  1999: output: returns 2 items: 
1.586     raeburn  2000: (a) form element which contains either:
                   2001:    (i) <select name="$name">
                   2002:         <option value="$hostid1">$hostid $servers{$hostid}</option>
                   2003:         <option value="$hostid2">$hostid $servers{$hostid}</option>       
                   2004:        </select>
                   2005:        form item if there are multiple library servers in $domain, or
                   2006:    (ii) an <input type="hidden" name="$name" value="$hostid" /> form item 
                   2007:        if there is only one library server in $domain.
                   2008: 
                   2009: (b) number of library servers found.
                   2010: 
                   2011: See loncreateuser.pm for example of use.
1.35      matthew  2012: 
                   2013: =cut
                   2014: 
                   2015: #-------------------------------------------
1.586     raeburn  2016: sub home_server_form_item {
                   2017:     my ($domain,$name,$default,$hide) = @_;
1.513     albertel 2018:     my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586     raeburn  2019:     my $result;
                   2020:     my $numlib = keys(%servers);
                   2021:     if ($numlib > 1) {
                   2022:         $result .= '<select name="'.$name.'" />'."\n";
                   2023:         if ($default) {
1.804     bisitz   2024:             $result .= '<option value="default" selected="selected">'.&mt('default').
1.586     raeburn  2025:                        '</option>'."\n";
                   2026:         }
                   2027:         foreach my $hostid (sort(keys(%servers))) {
                   2028:             $result.= '<option value="'.$hostid.'">'.
                   2029: 	              $hostid.' '.$servers{$hostid}."</option>\n";
                   2030:         }
                   2031:         $result .= '</select>'."\n";
                   2032:     } elsif ($numlib == 1) {
                   2033:         my $hostid;
                   2034:         foreach my $item (keys(%servers)) {
                   2035:             $hostid = $item;
                   2036:         }
                   2037:         $result .= '<input type="hidden" name="'.$name.'" value="'.
                   2038:                    $hostid.'" />';
                   2039:                    if (!$hide) {
                   2040:                        $result .= $hostid.' '.$servers{$hostid};
                   2041:                    }
                   2042:                    $result .= "\n";
                   2043:     } elsif ($default) {
                   2044:         $result .= '<input type="hidden" name="'.$name.
                   2045:                    '" value="default" />';
                   2046:                    if (!$hide) {
                   2047:                        $result .= &mt('default');
                   2048:                    }
                   2049:                    $result .= "\n";
1.33      matthew  2050:     }
1.586     raeburn  2051:     return ($result,$numlib);
1.33      matthew  2052: }
1.112     bowersj2 2053: 
                   2054: =pod
                   2055: 
1.534     albertel 2056: =back 
                   2057: 
1.112     bowersj2 2058: =cut
1.87      matthew  2059: 
                   2060: ###############################################################
1.112     bowersj2 2061: ##                  Decoding User Agent                      ##
1.87      matthew  2062: ###############################################################
                   2063: 
                   2064: =pod
                   2065: 
1.112     bowersj2 2066: =head1 Decoding the User Agent
                   2067: 
                   2068: =over 4
                   2069: 
                   2070: =item * &decode_user_agent()
1.87      matthew  2071: 
                   2072: Inputs: $r
                   2073: 
                   2074: Outputs:
                   2075: 
                   2076: =over 4
                   2077: 
1.112     bowersj2 2078: =item * $httpbrowser
1.87      matthew  2079: 
1.112     bowersj2 2080: =item * $clientbrowser
1.87      matthew  2081: 
1.112     bowersj2 2082: =item * $clientversion
1.87      matthew  2083: 
1.112     bowersj2 2084: =item * $clientmathml
1.87      matthew  2085: 
1.112     bowersj2 2086: =item * $clientunicode
1.87      matthew  2087: 
1.112     bowersj2 2088: =item * $clientos
1.87      matthew  2089: 
                   2090: =back
                   2091: 
1.157     matthew  2092: =back 
                   2093: 
1.87      matthew  2094: =cut
                   2095: 
                   2096: ###############################################################
                   2097: ###############################################################
                   2098: sub decode_user_agent {
1.247     albertel 2099:     my ($r)=@_;
1.87      matthew  2100:     my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
                   2101:     my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
                   2102:     my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247     albertel 2103:     if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87      matthew  2104:     my $clientbrowser='unknown';
                   2105:     my $clientversion='0';
                   2106:     my $clientmathml='';
                   2107:     my $clientunicode='0';
                   2108:     for (my $i=0;$i<=$#browsertype;$i++) {
                   2109:         my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
                   2110: 	if (($httpbrowser=~/$match/i)  && ($httpbrowser!~/$notmatch/i)) {
                   2111: 	    $clientbrowser=$bname;
                   2112:             $httpbrowser=~/$vreg/i;
                   2113: 	    $clientversion=$1;
                   2114:             $clientmathml=($clientversion>=$minv);
                   2115:             $clientunicode=($clientversion>=$univ);
                   2116: 	}
                   2117:     }
                   2118:     my $clientos='unknown';
                   2119:     if (($httpbrowser=~/linux/i) ||
                   2120:         ($httpbrowser=~/unix/i) ||
                   2121:         ($httpbrowser=~/ux/i) ||
                   2122:         ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
                   2123:     if (($httpbrowser=~/vax/i) ||
                   2124:         ($httpbrowser=~/vms/i)) { $clientos='vms'; }
                   2125:     if ($httpbrowser=~/next/i) { $clientos='next'; }
                   2126:     if (($httpbrowser=~/mac/i) ||
                   2127:         ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
                   2128:     if ($httpbrowser=~/win/i) { $clientos='win'; }
                   2129:     if ($httpbrowser=~/embed/i) { $clientos='pda'; }
                   2130:     return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
                   2131:             $clientunicode,$clientos,);
                   2132: }
                   2133: 
1.32      matthew  2134: ###############################################################
                   2135: ##    Authentication changing form generation subroutines    ##
                   2136: ###############################################################
                   2137: ##
                   2138: ## All of the authform_xxxxxxx subroutines take their inputs in a
                   2139: ## hash, and have reasonable default values.
                   2140: ##
                   2141: ##    formname = the name given in the <form> tag.
1.35      matthew  2142: #-------------------------------------------
                   2143: 
1.45      matthew  2144: =pod
                   2145: 
1.112     bowersj2 2146: =head1 Authentication Routines
                   2147: 
                   2148: =over 4
                   2149: 
1.648     raeburn  2150: =item * &authform_xxxxxx()
1.35      matthew  2151: 
                   2152: The authform_xxxxxx subroutines provide javascript and html forms which 
                   2153: handle some of the conveniences required for authentication forms.  
                   2154: This is not an optimal method, but it works.  
                   2155: 
                   2156: =over 4
                   2157: 
1.112     bowersj2 2158: =item * authform_header
1.35      matthew  2159: 
1.112     bowersj2 2160: =item * authform_authorwarning
1.35      matthew  2161: 
1.112     bowersj2 2162: =item * authform_nochange
1.35      matthew  2163: 
1.112     bowersj2 2164: =item * authform_kerberos
1.35      matthew  2165: 
1.112     bowersj2 2166: =item * authform_internal
1.35      matthew  2167: 
1.112     bowersj2 2168: =item * authform_filesystem
1.35      matthew  2169: 
                   2170: =back
                   2171: 
1.648     raeburn  2172: See loncreateuser.pm for invocation and use examples.
1.157     matthew  2173: 
1.35      matthew  2174: =cut
                   2175: 
                   2176: #-------------------------------------------
1.32      matthew  2177: sub authform_header{  
                   2178:     my %in = (
                   2179:         formname => 'cu',
1.80      albertel 2180:         kerb_def_dom => '',
1.32      matthew  2181:         @_,
                   2182:     );
                   2183:     $in{'formname'} = 'document.' . $in{'formname'};
                   2184:     my $result='';
1.80      albertel 2185: 
                   2186: #---------------------------------------------- Code for upper case translation
                   2187:     my $Javascript_toUpperCase;
                   2188:     unless ($in{kerb_def_dom}) {
                   2189:         $Javascript_toUpperCase =<<"END";
                   2190:         switch (choice) {
                   2191:            case 'krb': currentform.elements[choicearg].value =
                   2192:                currentform.elements[choicearg].value.toUpperCase();
                   2193:                break;
                   2194:            default:
                   2195:         }
                   2196: END
                   2197:     } else {
                   2198:         $Javascript_toUpperCase = "";
                   2199:     }
                   2200: 
1.165     raeburn  2201:     my $radioval = "'nochange'";
1.591     raeburn  2202:     if (defined($in{'curr_authtype'})) {
                   2203:         if ($in{'curr_authtype'} ne '') {
                   2204:             $radioval = "'".$in{'curr_authtype'}."arg'";
                   2205:         }
1.174     matthew  2206:     }
1.165     raeburn  2207:     my $argfield = 'null';
1.591     raeburn  2208:     if (defined($in{'mode'})) {
1.165     raeburn  2209:         if ($in{'mode'} eq 'modifycourse')  {
1.591     raeburn  2210:             if (defined($in{'curr_autharg'})) {
                   2211:                 if ($in{'curr_autharg'} ne '') {
1.165     raeburn  2212:                     $argfield = "'$in{'curr_autharg'}'";
                   2213:                 }
                   2214:             }
                   2215:         }
                   2216:     }
                   2217: 
1.32      matthew  2218:     $result.=<<"END";
                   2219: var current = new Object();
1.165     raeburn  2220: current.radiovalue = $radioval;
                   2221: current.argfield = $argfield;
1.32      matthew  2222: 
                   2223: function changed_radio(choice,currentform) {
                   2224:     var choicearg = choice + 'arg';
                   2225:     // If a radio button in changed, we need to change the argfield
                   2226:     if (current.radiovalue != choice) {
                   2227:         current.radiovalue = choice;
                   2228:         if (current.argfield != null) {
                   2229:             currentform.elements[current.argfield].value = '';
                   2230:         }
                   2231:         if (choice == 'nochange') {
                   2232:             current.argfield = null;
                   2233:         } else {
                   2234:             current.argfield = choicearg;
                   2235:             switch(choice) {
                   2236:                 case 'krb': 
                   2237:                     currentform.elements[current.argfield].value = 
                   2238:                         "$in{'kerb_def_dom'}";
                   2239:                 break;
                   2240:               default:
                   2241:                 break;
                   2242:             }
                   2243:         }
                   2244:     }
                   2245:     return;
                   2246: }
1.22      www      2247: 
1.32      matthew  2248: function changed_text(choice,currentform) {
                   2249:     var choicearg = choice + 'arg';
                   2250:     if (currentform.elements[choicearg].value !='') {
1.80      albertel 2251:         $Javascript_toUpperCase
1.32      matthew  2252:         // clear old field
                   2253:         if ((current.argfield != choicearg) && (current.argfield != null)) {
                   2254:             currentform.elements[current.argfield].value = '';
                   2255:         }
                   2256:         current.argfield = choicearg;
                   2257:     }
                   2258:     set_auth_radio_buttons(choice,currentform);
                   2259:     return;
1.20      www      2260: }
1.32      matthew  2261: 
                   2262: function set_auth_radio_buttons(newvalue,currentform) {
                   2263:     var i=0;
                   2264:     while (i < currentform.login.length) {
                   2265:         if (currentform.login[i].value == newvalue) { break; }
                   2266:         i++;
                   2267:     }
                   2268:     if (i == currentform.login.length) {
                   2269:         return;
                   2270:     }
                   2271:     current.radiovalue = newvalue;
                   2272:     currentform.login[i].checked = true;
                   2273:     return;
                   2274: }
                   2275: END
                   2276:     return $result;
                   2277: }
                   2278: 
                   2279: sub authform_authorwarning{
                   2280:     my $result='';
1.144     matthew  2281:     $result='<i>'.
                   2282:         &mt('As a general rule, only authors or co-authors should be '.
                   2283:             'filesystem authenticated '.
                   2284:             '(which allows access to the server filesystem).')."</i>\n";
1.32      matthew  2285:     return $result;
                   2286: }
                   2287: 
                   2288: sub authform_nochange{  
                   2289:     my %in = (
                   2290:               formname => 'document.cu',
                   2291:               kerb_def_dom => 'MSU.EDU',
                   2292:               @_,
                   2293:           );
1.586     raeburn  2294:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'}); 
                   2295:     my $result;
                   2296:     if (keys(%can_assign) == 0) {
                   2297:         $result = &mt('Under you current role you are not permitted to change login settings for this user');  
                   2298:     } else {
                   2299:         $result = '<label>'.&mt('[_1] Do not change login data',
                   2300:                   '<input type="radio" name="login" value="nochange" '.
                   2301:                   'checked="checked" onclick="'.
1.281     albertel 2302:             "javascript:changed_radio('nochange',$in{'formname'});".'" />').
                   2303: 	    '</label>';
1.586     raeburn  2304:     }
1.32      matthew  2305:     return $result;
                   2306: }
                   2307: 
1.591     raeburn  2308: sub authform_kerberos {
1.32      matthew  2309:     my %in = (
                   2310:               formname => 'document.cu',
                   2311:               kerb_def_dom => 'MSU.EDU',
1.80      albertel 2312:               kerb_def_auth => 'krb4',
1.32      matthew  2313:               @_,
                   2314:               );
1.586     raeburn  2315:     my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
                   2316:         $autharg,$jscall);
                   2317:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.80      albertel 2318:     if ($in{'kerb_def_auth'} eq 'krb5') {
1.772     bisitz   2319:        $check5 = ' checked="checked"';
1.80      albertel 2320:     } else {
1.772     bisitz   2321:        $check4 = ' checked="checked"';
1.80      albertel 2322:     }
1.165     raeburn  2323:     $krbarg = $in{'kerb_def_dom'};
1.591     raeburn  2324:     if (defined($in{'curr_authtype'})) {
                   2325:         if ($in{'curr_authtype'} eq 'krb') {
1.772     bisitz   2326:             $krbcheck = ' checked="checked"';
1.623     raeburn  2327:             if (defined($in{'mode'})) {
                   2328:                 if ($in{'mode'} eq 'modifyuser') {
                   2329:                     $krbcheck = '';
                   2330:                 }
                   2331:             }
1.591     raeburn  2332:             if (defined($in{'curr_kerb_ver'})) {
                   2333:                 if ($in{'curr_krb_ver'} eq '5') {
1.772     bisitz   2334:                     $check5 = ' checked="checked"';
1.591     raeburn  2335:                     $check4 = '';
                   2336:                 } else {
1.772     bisitz   2337:                     $check4 = ' checked="checked"';
1.591     raeburn  2338:                     $check5 = '';
                   2339:                 }
1.586     raeburn  2340:             }
1.591     raeburn  2341:             if (defined($in{'curr_autharg'})) {
1.165     raeburn  2342:                 $krbarg = $in{'curr_autharg'};
                   2343:             }
1.586     raeburn  2344:             if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591     raeburn  2345:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2346:                     $result = 
                   2347:     &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
                   2348:         $in{'curr_autharg'},$krbver);
                   2349:                 } else {
                   2350:                     $result =
                   2351:     &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
                   2352:                 }
                   2353:                 return $result; 
                   2354:             }
                   2355:         }
                   2356:     } else {
                   2357:         if ($authnum == 1) {
1.784     bisitz   2358:             $authtype = '<input type="hidden" name="login" value="krb" />';
1.165     raeburn  2359:         }
                   2360:     }
1.586     raeburn  2361:     if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
                   2362:         return;
1.587     raeburn  2363:     } elsif ($authtype eq '') {
1.591     raeburn  2364:         if (defined($in{'mode'})) {
1.587     raeburn  2365:             if ($in{'mode'} eq 'modifycourse') {
                   2366:                 if ($authnum == 1) {
1.784     bisitz   2367:                     $authtype = '<input type="hidden" name="login" value="krb" />';
1.587     raeburn  2368:                 }
                   2369:             }
                   2370:         }
1.586     raeburn  2371:     }
                   2372:     $jscall = "javascript:changed_radio('krb',$in{'formname'});";
                   2373:     if ($authtype eq '') {
                   2374:         $authtype = '<input type="radio" name="login" value="krb" '.
                   2375:                     'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
                   2376:                     $krbcheck.' />';
                   2377:     }
                   2378:     if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
                   2379:         ($can_assign{'krb4'} && !$can_assign{'krb5'} && 
                   2380:          $in{'curr_authtype'} eq 'krb5') ||
                   2381:         (!$can_assign{'krb4'} && $can_assign{'krb5'} && 
                   2382:          $in{'curr_authtype'} eq 'krb4')) {
                   2383:         $result .= &mt
1.144     matthew  2384:         ('[_1] Kerberos authenticated with domain [_2] '.
1.281     albertel 2385:          '[_3] Version 4 [_4] Version 5 [_5]',
1.586     raeburn  2386:          '<label>'.$authtype,
1.281     albertel 2387:          '</label><input type="text" size="10" name="krbarg" '.
1.165     raeburn  2388:              'value="'.$krbarg.'" '.
1.144     matthew  2389:              'onchange="'.$jscall.'" />',
1.281     albertel 2390:          '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
                   2391:          '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
                   2392: 	 '</label>');
1.586     raeburn  2393:     } elsif ($can_assign{'krb4'}) {
                   2394:         $result .= &mt
                   2395:         ('[_1] Kerberos authenticated with domain [_2] '.
                   2396:          '[_3] Version 4 [_4]',
                   2397:          '<label>'.$authtype,
                   2398:          '</label><input type="text" size="10" name="krbarg" '.
                   2399:              'value="'.$krbarg.'" '.
                   2400:              'onchange="'.$jscall.'" />',
                   2401:          '<label><input type="hidden" name="krbver" value="4" />',
                   2402:          '</label>');
                   2403:     } elsif ($can_assign{'krb5'}) {
                   2404:         $result .= &mt
                   2405:         ('[_1] Kerberos authenticated with domain [_2] '.
                   2406:          '[_3] Version 5 [_4]',
                   2407:          '<label>'.$authtype,
                   2408:          '</label><input type="text" size="10" name="krbarg" '.
                   2409:              'value="'.$krbarg.'" '.
                   2410:              'onchange="'.$jscall.'" />',
                   2411:          '<label><input type="hidden" name="krbver" value="5" />',
                   2412:          '</label>');
                   2413:     }
1.32      matthew  2414:     return $result;
                   2415: }
                   2416: 
                   2417: sub authform_internal{  
1.586     raeburn  2418:     my %in = (
1.32      matthew  2419:                 formname => 'document.cu',
                   2420:                 kerb_def_dom => 'MSU.EDU',
                   2421:                 @_,
                   2422:                 );
1.586     raeburn  2423:     my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
                   2424:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2425:     if (defined($in{'curr_authtype'})) {
                   2426:         if ($in{'curr_authtype'} eq 'int') {
1.586     raeburn  2427:             if ($can_assign{'int'}) {
1.772     bisitz   2428:                 $intcheck = 'checked="checked" ';
1.623     raeburn  2429:                 if (defined($in{'mode'})) {
                   2430:                     if ($in{'mode'} eq 'modifyuser') {
                   2431:                         $intcheck = '';
                   2432:                     }
                   2433:                 }
1.591     raeburn  2434:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2435:                     $intarg = $in{'curr_autharg'};
                   2436:                 }
                   2437:             } else {
                   2438:                 $result = &mt('Currently internally authenticated.');
                   2439:                 return $result;
1.165     raeburn  2440:             }
                   2441:         }
1.586     raeburn  2442:     } else {
                   2443:         if ($authnum == 1) {
1.784     bisitz   2444:             $authtype = '<input type="hidden" name="login" value="int" />';
1.586     raeburn  2445:         }
                   2446:     }
                   2447:     if (!$can_assign{'int'}) {
                   2448:         return;
1.587     raeburn  2449:     } elsif ($authtype eq '') {
1.591     raeburn  2450:         if (defined($in{'mode'})) {
1.587     raeburn  2451:             if ($in{'mode'} eq 'modifycourse') {
                   2452:                 if ($authnum == 1) {
1.784     bisitz   2453:                     $authtype = '<input type="hidden" name="login" value="int" />';
1.587     raeburn  2454:                 }
                   2455:             }
                   2456:         }
1.165     raeburn  2457:     }
1.586     raeburn  2458:     $jscall = "javascript:changed_radio('int',$in{'formname'});";
                   2459:     if ($authtype eq '') {
                   2460:         $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
                   2461:                     ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
                   2462:     }
1.605     bisitz   2463:     $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586     raeburn  2464:                $intarg.'" onchange="'.$jscall.'" />';
                   2465:     $result = &mt
1.144     matthew  2466:         ('[_1] Internally authenticated (with initial password [_2])',
1.586     raeburn  2467:          '<label>'.$authtype,'</label>'.$autharg);
1.824     bisitz   2468:     $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  2469:     return $result;
                   2470: }
                   2471: 
                   2472: sub authform_local{  
                   2473:     my %in = (
                   2474:               formname => 'document.cu',
                   2475:               kerb_def_dom => 'MSU.EDU',
                   2476:               @_,
                   2477:               );
1.586     raeburn  2478:     my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
                   2479:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2480:     if (defined($in{'curr_authtype'})) {
                   2481:         if ($in{'curr_authtype'} eq 'loc') {
1.586     raeburn  2482:             if ($can_assign{'loc'}) {
1.772     bisitz   2483:                 $loccheck = 'checked="checked" ';
1.623     raeburn  2484:                 if (defined($in{'mode'})) {
                   2485:                     if ($in{'mode'} eq 'modifyuser') {
                   2486:                         $loccheck = '';
                   2487:                     }
                   2488:                 }
1.591     raeburn  2489:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2490:                     $locarg = $in{'curr_autharg'};
                   2491:                 }
                   2492:             } else {
                   2493:                 $result = &mt('Currently using local (institutional) authentication.');
                   2494:                 return $result;
1.165     raeburn  2495:             }
                   2496:         }
1.586     raeburn  2497:     } else {
                   2498:         if ($authnum == 1) {
1.784     bisitz   2499:             $authtype = '<input type="hidden" name="login" value="loc" />';
1.586     raeburn  2500:         }
                   2501:     }
                   2502:     if (!$can_assign{'loc'}) {
                   2503:         return;
1.587     raeburn  2504:     } elsif ($authtype eq '') {
1.591     raeburn  2505:         if (defined($in{'mode'})) {
1.587     raeburn  2506:             if ($in{'mode'} eq 'modifycourse') {
                   2507:                 if ($authnum == 1) {
1.784     bisitz   2508:                     $authtype = '<input type="hidden" name="login" value="loc" />';
1.587     raeburn  2509:                 }
                   2510:             }
                   2511:         }
1.165     raeburn  2512:     }
1.586     raeburn  2513:     $jscall = "javascript:changed_radio('loc',$in{'formname'});";
                   2514:     if ($authtype eq '') {
                   2515:         $authtype = '<input type="radio" name="login" value="loc" '.
                   2516:                     $loccheck.' onchange="'.$jscall.'" onclick="'.
                   2517:                     $jscall.'" />';
                   2518:     }
                   2519:     $autharg = '<input type="text" size="10" name="locarg" value="'.
                   2520:                $locarg.'" onchange="'.$jscall.'" />';
                   2521:     $result = &mt('[_1] Local Authentication with argument [_2]',
                   2522:                   '<label>'.$authtype,'</label>'.$autharg);
1.32      matthew  2523:     return $result;
                   2524: }
                   2525: 
                   2526: sub authform_filesystem{  
                   2527:     my %in = (
                   2528:               formname => 'document.cu',
                   2529:               kerb_def_dom => 'MSU.EDU',
                   2530:               @_,
                   2531:               );
1.586     raeburn  2532:     my ($fsyscheck,$result,$authtype,$autharg,$jscall);
                   2533:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2534:     if (defined($in{'curr_authtype'})) {
                   2535:         if ($in{'curr_authtype'} eq 'fsys') {
1.586     raeburn  2536:             if ($can_assign{'fsys'}) {
1.772     bisitz   2537:                 $fsyscheck = 'checked="checked" ';
1.623     raeburn  2538:                 if (defined($in{'mode'})) {
                   2539:                     if ($in{'mode'} eq 'modifyuser') {
                   2540:                         $fsyscheck = '';
                   2541:                     }
                   2542:                 }
1.586     raeburn  2543:             } else {
                   2544:                 $result = &mt('Currently Filesystem Authenticated.');
                   2545:                 return $result;
                   2546:             }           
                   2547:         }
                   2548:     } else {
                   2549:         if ($authnum == 1) {
1.784     bisitz   2550:             $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586     raeburn  2551:         }
                   2552:     }
                   2553:     if (!$can_assign{'fsys'}) {
                   2554:         return;
1.587     raeburn  2555:     } elsif ($authtype eq '') {
1.591     raeburn  2556:         if (defined($in{'mode'})) {
1.587     raeburn  2557:             if ($in{'mode'} eq 'modifycourse') {
                   2558:                 if ($authnum == 1) {
1.784     bisitz   2559:                     $authtype = '<input type="hidden" name="login" value="fsys" />';
1.587     raeburn  2560:                 }
                   2561:             }
                   2562:         }
1.586     raeburn  2563:     }
                   2564:     $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
                   2565:     if ($authtype eq '') {
                   2566:         $authtype = '<input type="radio" name="login" value="fsys" '.
                   2567:                     $fsyscheck.' onchange="'.$jscall.'" onclick="'.
                   2568:                     $jscall.'" />';
                   2569:     }
                   2570:     $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
                   2571:                ' onchange="'.$jscall.'" />';
                   2572:     $result = &mt
1.144     matthew  2573:         ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281     albertel 2574:          '<label><input type="radio" name="login" value="fsys" '.
1.586     raeburn  2575:          $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605     bisitz   2576:          '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144     matthew  2577:                   'onchange="'.$jscall.'" />');
1.32      matthew  2578:     return $result;
                   2579: }
                   2580: 
1.586     raeburn  2581: sub get_assignable_auth {
                   2582:     my ($dom) = @_;
                   2583:     if ($dom eq '') {
                   2584:         $dom = $env{'request.role.domain'};
                   2585:     }
                   2586:     my %can_assign = (
                   2587:                           krb4 => 1,
                   2588:                           krb5 => 1,
                   2589:                           int  => 1,
                   2590:                           loc  => 1,
                   2591:                      );
                   2592:     my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
                   2593:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   2594:         if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
                   2595:             my $authhash = $domconfig{'usercreation'}{'authtypes'};
                   2596:             my $context;
                   2597:             if ($env{'request.role'} =~ /^au/) {
                   2598:                 $context = 'author';
                   2599:             } elsif ($env{'request.role'} =~ /^dc/) {
                   2600:                 $context = 'domain';
                   2601:             } elsif ($env{'request.course.id'}) {
                   2602:                 $context = 'course';
                   2603:             }
                   2604:             if ($context) {
                   2605:                 if (ref($authhash->{$context}) eq 'HASH') {
                   2606:                    %can_assign = %{$authhash->{$context}}; 
                   2607:                 }
                   2608:             }
                   2609:         }
                   2610:     }
                   2611:     my $authnum = 0;
                   2612:     foreach my $key (keys(%can_assign)) {
                   2613:         if ($can_assign{$key}) {
                   2614:             $authnum ++;
                   2615:         }
                   2616:     }
                   2617:     if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
                   2618:         $authnum --;
                   2619:     }
                   2620:     return ($authnum,%can_assign);
                   2621: }
                   2622: 
1.80      albertel 2623: ###############################################################
                   2624: ##    Get Kerberos Defaults for Domain                 ##
                   2625: ###############################################################
                   2626: ##
                   2627: ## Returns default kerberos version and an associated argument
                   2628: ## as listed in file domain.tab. If not listed, provides
                   2629: ## appropriate default domain and kerberos version.
                   2630: ##
                   2631: #-------------------------------------------
                   2632: 
                   2633: =pod
                   2634: 
1.648     raeburn  2635: =item * &get_kerberos_defaults()
1.80      albertel 2636: 
                   2637: get_kerberos_defaults($target_domain) returns the default kerberos
1.641     raeburn  2638: version and domain. If not found, it defaults to version 4 and the 
                   2639: domain of the server.
1.80      albertel 2640: 
1.648     raeburn  2641: =over 4
                   2642: 
1.80      albertel 2643: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
                   2644: 
1.648     raeburn  2645: =back
                   2646: 
                   2647: =back
                   2648: 
1.80      albertel 2649: =cut
                   2650: 
                   2651: #-------------------------------------------
                   2652: sub get_kerberos_defaults {
                   2653:     my $domain=shift;
1.641     raeburn  2654:     my ($krbdef,$krbdefdom);
                   2655:     my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
                   2656:     if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
                   2657:         $krbdef = $domdefaults{'auth_def'};
                   2658:         $krbdefdom = $domdefaults{'auth_arg_def'};
                   2659:     } else {
1.80      albertel 2660:         $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
                   2661:         my $krbdefdom=$1;
                   2662:         $krbdefdom=~tr/a-z/A-Z/;
                   2663:         $krbdef = "krb4";
                   2664:     }
                   2665:     return ($krbdef,$krbdefdom);
                   2666: }
1.112     bowersj2 2667: 
1.32      matthew  2668: 
1.46      matthew  2669: ###############################################################
                   2670: ##                Thesaurus Functions                        ##
                   2671: ###############################################################
1.20      www      2672: 
1.46      matthew  2673: =pod
1.20      www      2674: 
1.112     bowersj2 2675: =head1 Thesaurus Functions
                   2676: 
                   2677: =over 4
                   2678: 
1.648     raeburn  2679: =item * &initialize_keywords()
1.46      matthew  2680: 
                   2681: Initializes the package variable %Keywords if it is empty.  Uses the
                   2682: package variable $thesaurus_db_file.
                   2683: 
                   2684: =cut
                   2685: 
                   2686: ###################################################
                   2687: 
                   2688: sub initialize_keywords {
                   2689:     return 1 if (scalar keys(%Keywords));
                   2690:     # If we are here, %Keywords is empty, so fill it up
                   2691:     #   Make sure the file we need exists...
                   2692:     if (! -e $thesaurus_db_file) {
                   2693:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
                   2694:                                  " failed because it does not exist");
                   2695:         return 0;
                   2696:     }
                   2697:     #   Set up the hash as a database
                   2698:     my %thesaurus_db;
                   2699:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 2700:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  2701:         &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
                   2702:                                  $thesaurus_db_file);
                   2703:         return 0;
                   2704:     } 
                   2705:     #  Get the average number of appearances of a word.
                   2706:     my $avecount = $thesaurus_db{'average.count'};
                   2707:     #  Put keywords (those that appear > average) into %Keywords
                   2708:     while (my ($word,$data)=each (%thesaurus_db)) {
                   2709:         my ($count,undef) = split /:/,$data;
                   2710:         $Keywords{$word}++ if ($count > $avecount);
                   2711:     }
                   2712:     untie %thesaurus_db;
                   2713:     # Remove special values from %Keywords.
1.356     albertel 2714:     foreach my $value ('total.count','average.count') {
                   2715:         delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586     raeburn  2716:   }
1.46      matthew  2717:     return 1;
                   2718: }
                   2719: 
                   2720: ###################################################
                   2721: 
                   2722: =pod
                   2723: 
1.648     raeburn  2724: =item * &keyword($word)
1.46      matthew  2725: 
                   2726: Returns true if $word is a keyword.  A keyword is a word that appears more 
                   2727: than the average number of times in the thesaurus database.  Calls 
                   2728: &initialize_keywords
                   2729: 
                   2730: =cut
                   2731: 
                   2732: ###################################################
1.20      www      2733: 
                   2734: sub keyword {
1.46      matthew  2735:     return if (!&initialize_keywords());
                   2736:     my $word=lc(shift());
                   2737:     $word=~s/\W//g;
                   2738:     return exists($Keywords{$word});
1.20      www      2739: }
1.46      matthew  2740: 
                   2741: ###############################################################
                   2742: 
                   2743: =pod 
1.20      www      2744: 
1.648     raeburn  2745: =item * &get_related_words()
1.46      matthew  2746: 
1.160     matthew  2747: Look up a word in the thesaurus.  Takes a scalar argument and returns
1.46      matthew  2748: an array of words.  If the keyword is not in the thesaurus, an empty array
                   2749: will be returned.  The order of the words returned is determined by the
                   2750: database which holds them.
                   2751: 
                   2752: Uses global $thesaurus_db_file.
                   2753: 
                   2754: =cut
                   2755: 
                   2756: ###############################################################
                   2757: sub get_related_words {
                   2758:     my $keyword = shift;
                   2759:     my %thesaurus_db;
                   2760:     if (! -e $thesaurus_db_file) {
                   2761:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
                   2762:                                  "failed because the file does not exist");
                   2763:         return ();
                   2764:     }
                   2765:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 2766:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  2767:         return ();
                   2768:     } 
                   2769:     my @Words=();
1.429     www      2770:     my $count=0;
1.46      matthew  2771:     if (exists($thesaurus_db{$keyword})) {
1.356     albertel 2772: 	# The first element is the number of times
                   2773: 	# the word appears.  We do not need it now.
1.429     www      2774: 	my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
                   2775: 	my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
                   2776: 	my $threshold=$mostfrequentcount/10;
                   2777:         foreach my $possibleword (@RelatedWords) {
                   2778:             my ($word,$wordcount)=split(/\,/,$possibleword);
                   2779:             if ($wordcount>$threshold) {
                   2780: 		push(@Words,$word);
                   2781:                 $count++;
                   2782:                 if ($count>10) { last; }
                   2783: 	    }
1.20      www      2784:         }
                   2785:     }
1.46      matthew  2786:     untie %thesaurus_db;
                   2787:     return @Words;
1.14      harris41 2788: }
1.46      matthew  2789: 
1.112     bowersj2 2790: =pod
                   2791: 
                   2792: =back
                   2793: 
                   2794: =cut
1.61      www      2795: 
                   2796: # -------------------------------------------------------------- Plaintext name
1.81      albertel 2797: =pod
                   2798: 
1.112     bowersj2 2799: =head1 User Name Functions
                   2800: 
                   2801: =over 4
                   2802: 
1.648     raeburn  2803: =item * &plainname($uname,$udom,$first)
1.81      albertel 2804: 
1.112     bowersj2 2805: Takes a users logon name and returns it as a string in
1.226     albertel 2806: "first middle last generation" form 
                   2807: if $first is set to 'lastname' then it returns it as
                   2808: 'lastname generation, firstname middlename' if their is a lastname
1.81      albertel 2809: 
                   2810: =cut
1.61      www      2811: 
1.295     www      2812: 
1.81      albertel 2813: ###############################################################
1.61      www      2814: sub plainname {
1.226     albertel 2815:     my ($uname,$udom,$first)=@_;
1.537     albertel 2816:     return if (!defined($uname) || !defined($udom));
1.295     www      2817:     my %names=&getnames($uname,$udom);
1.226     albertel 2818:     my $name=&Apache::lonnet::format_name($names{'firstname'},
                   2819: 					  $names{'middlename'},
                   2820: 					  $names{'lastname'},
                   2821: 					  $names{'generation'},$first);
                   2822:     $name=~s/^\s+//;
1.62      www      2823:     $name=~s/\s+$//;
                   2824:     $name=~s/\s+/ /g;
1.353     albertel 2825:     if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62      www      2826:     return $name;
1.61      www      2827: }
1.66      www      2828: 
                   2829: # -------------------------------------------------------------------- Nickname
1.81      albertel 2830: =pod
                   2831: 
1.648     raeburn  2832: =item * &nickname($uname,$udom)
1.81      albertel 2833: 
                   2834: Gets a users name and returns it as a string as
                   2835: 
                   2836: "&quot;nickname&quot;"
1.66      www      2837: 
1.81      albertel 2838: if the user has a nickname or
                   2839: 
                   2840: "first middle last generation"
                   2841: 
                   2842: if the user does not
                   2843: 
                   2844: =cut
1.66      www      2845: 
                   2846: sub nickname {
                   2847:     my ($uname,$udom)=@_;
1.537     albertel 2848:     return if (!defined($uname) || !defined($udom));
1.295     www      2849:     my %names=&getnames($uname,$udom);
1.68      albertel 2850:     my $name=$names{'nickname'};
1.66      www      2851:     if ($name) {
                   2852:        $name='&quot;'.$name.'&quot;'; 
                   2853:     } else {
                   2854:        $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
                   2855: 	     $names{'lastname'}.' '.$names{'generation'};
                   2856:        $name=~s/\s+$//;
                   2857:        $name=~s/\s+/ /g;
                   2858:     }
                   2859:     return $name;
                   2860: }
                   2861: 
1.295     www      2862: sub getnames {
                   2863:     my ($uname,$udom)=@_;
1.537     albertel 2864:     return if (!defined($uname) || !defined($udom));
1.433     albertel 2865:     if ($udom eq 'public' && $uname eq 'public') {
                   2866: 	return ('lastname' => &mt('Public'));
                   2867:     }
1.295     www      2868:     my $id=$uname.':'.$udom;
                   2869:     my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
                   2870:     if ($cached) {
                   2871: 	return %{$names};
                   2872:     } else {
                   2873: 	my %loadnames=&Apache::lonnet::get('environment',
                   2874:                     ['firstname','middlename','lastname','generation','nickname'],
                   2875: 					 $udom,$uname);
                   2876: 	&Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
                   2877: 	return %loadnames;
                   2878:     }
                   2879: }
1.61      www      2880: 
1.542     raeburn  2881: # -------------------------------------------------------------------- getemails
1.648     raeburn  2882: 
1.542     raeburn  2883: =pod
                   2884: 
1.648     raeburn  2885: =item * &getemails($uname,$udom)
1.542     raeburn  2886: 
                   2887: Gets a user's email information and returns it as a hash with keys:
                   2888: notification, critnotification, permanentemail
                   2889: 
                   2890: For notification and critnotification, values are comma-separated lists 
1.648     raeburn  2891: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542     raeburn  2892:  
1.648     raeburn  2893: 
1.542     raeburn  2894: =cut
                   2895: 
1.648     raeburn  2896: 
1.466     albertel 2897: sub getemails {
                   2898:     my ($uname,$udom)=@_;
                   2899:     if ($udom eq 'public' && $uname eq 'public') {
                   2900: 	return;
                   2901:     }
1.467     www      2902:     if (!$udom) { $udom=$env{'user.domain'}; }
                   2903:     if (!$uname) { $uname=$env{'user.name'}; }
1.466     albertel 2904:     my $id=$uname.':'.$udom;
                   2905:     my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
                   2906:     if ($cached) {
                   2907: 	return %{$names};
                   2908:     } else {
                   2909: 	my %loadnames=&Apache::lonnet::get('environment',
                   2910:                     			   ['notification','critnotification',
                   2911: 					    'permanentemail'],
                   2912: 					   $udom,$uname);
                   2913: 	&Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
                   2914: 	return %loadnames;
                   2915:     }
                   2916: }
                   2917: 
1.551     albertel 2918: sub flush_email_cache {
                   2919:     my ($uname,$udom)=@_;
                   2920:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2921:     if (!$uname) { $uname=$env{'user.name'};   }
                   2922:     return if ($udom eq 'public' && $uname eq 'public');
                   2923:     my $id=$uname.':'.$udom;
                   2924:     &Apache::lonnet::devalidate_cache_new('emailscache',$id);
                   2925: }
                   2926: 
1.728     raeburn  2927: # -------------------------------------------------------------------- getlangs
                   2928: 
                   2929: =pod
                   2930: 
                   2931: =item * &getlangs($uname,$udom)
                   2932: 
                   2933: Gets a user's language preference and returns it as a hash with key:
                   2934: language.
                   2935: 
                   2936: =cut
                   2937: 
                   2938: 
                   2939: sub getlangs {
                   2940:     my ($uname,$udom) = @_;
                   2941:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2942:     if (!$uname) { $uname=$env{'user.name'};   }
                   2943:     my $id=$uname.':'.$udom;
                   2944:     my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
                   2945:     if ($cached) {
                   2946:         return %{$langs};
                   2947:     } else {
                   2948:         my %loadlangs=&Apache::lonnet::get('environment',['languages'],
                   2949:                                            $udom,$uname);
                   2950:         &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
                   2951:         return %loadlangs;
                   2952:     }
                   2953: }
                   2954: 
                   2955: sub flush_langs_cache {
                   2956:     my ($uname,$udom)=@_;
                   2957:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2958:     if (!$uname) { $uname=$env{'user.name'};   }
                   2959:     return if ($udom eq 'public' && $uname eq 'public');
                   2960:     my $id=$uname.':'.$udom;
                   2961:     &Apache::lonnet::devalidate_cache_new('userlangs',$id);
                   2962: }
                   2963: 
1.61      www      2964: # ------------------------------------------------------------------ Screenname
1.81      albertel 2965: 
                   2966: =pod
                   2967: 
1.648     raeburn  2968: =item * &screenname($uname,$udom)
1.81      albertel 2969: 
                   2970: Gets a users screenname and returns it as a string
                   2971: 
                   2972: =cut
1.61      www      2973: 
                   2974: sub screenname {
                   2975:     my ($uname,$udom)=@_;
1.258     albertel 2976:     if ($uname eq $env{'user.name'} &&
                   2977: 	$udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212     albertel 2978:     my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68      albertel 2979:     return $names{'screenname'};
1.62      www      2980: }
                   2981: 
1.212     albertel 2982: 
1.802     bisitz   2983: # ------------------------------------------------------------- Confirm Wrapper
                   2984: =pod
                   2985: 
                   2986: =item confirmwrapper
                   2987: 
                   2988: Wrap messages about completion of operation in box
                   2989: 
                   2990: =cut
                   2991: 
                   2992: sub confirmwrapper {
                   2993:     my ($message)=@_;
                   2994:     if ($message) {
                   2995:         return "\n".'<div class="LC_confirm_box">'."\n"
                   2996:                .$message."\n"
                   2997:                .'</div>'."\n";
                   2998:     } else {
                   2999:         return $message;
                   3000:     }
                   3001: }
                   3002: 
1.62      www      3003: # ------------------------------------------------------------- Message Wrapper
                   3004: 
                   3005: sub messagewrapper {
1.369     www      3006:     my ($link,$username,$domain,$subject,$text)=@_;
1.62      www      3007:     return 
1.441     albertel 3008:         '<a href="/adm/email?compose=individual&amp;'.
                   3009:         'recname='.$username.'&amp;recdom='.$domain.
                   3010: 	'&amp;subject='.&escape($subject).'&amp;text='.&escape($text).'" '.
1.200     matthew  3011:         'title="'.&mt('Send message').'">'.$link.'</a>';
1.74      www      3012: }
1.802     bisitz   3013: 
1.74      www      3014: # --------------------------------------------------------------- Notes Wrapper
                   3015: 
                   3016: sub noteswrapper {
                   3017:     my ($link,$un,$do)=@_;
                   3018:     return 
1.896     amueller 3019: "<a href='/adm/email?recordftf=retrieve&amp;recname=$un&amp;recdom=$do'>$link</a>";
1.62      www      3020: }
1.802     bisitz   3021: 
1.62      www      3022: # ------------------------------------------------------------- Aboutme Wrapper
                   3023: 
                   3024: sub aboutmewrapper {
1.166     www      3025:     my ($link,$username,$domain,$target)=@_;
1.447     raeburn  3026:     if (!defined($username)  && !defined($domain)) {
                   3027:         return;
                   3028:     }
1.892     amueller 3029:     return '<a href="/adm/'.$domain.'/'.$username.'/aboutme?forcestudent=1"'.
1.756     weissno  3030: 	($target?' target="$target"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62      www      3031: }
                   3032: 
                   3033: # ------------------------------------------------------------ Syllabus Wrapper
                   3034: 
                   3035: sub syllabuswrapper {
1.707     bisitz   3036:     my ($linktext,$coursedir,$domain)=@_;
1.208     matthew  3037:     return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61      www      3038: }
1.14      harris41 3039: 
1.802     bisitz   3040: # -----------------------------------------------------------------------------
                   3041: 
1.208     matthew  3042: sub track_student_link {
1.887     raeburn  3043:     my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268     albertel 3044:     my $link ="/adm/trackstudent?";
1.208     matthew  3045:     my $title = 'View recent activity';
                   3046:     if (defined($sname) && $sname !~ /^\s*$/ &&
                   3047:         defined($sdom)  && $sdom  !~ /^\s*$/) {
1.268     albertel 3048:         $link .= "selected_student=$sname:$sdom";
1.208     matthew  3049:         $title .= ' of this student';
1.268     albertel 3050:     } 
1.208     matthew  3051:     if (defined($target) && $target !~ /^\s*$/) {
                   3052:         $target = qq{target="$target"};
                   3053:     } else {
                   3054:         $target = '';
                   3055:     }
1.268     albertel 3056:     if ($start) { $link.='&amp;start='.$start; }
1.887     raeburn  3057:     if ($only_body) { $link .= '&amp;only_body=1'; }
1.554     albertel 3058:     $title = &mt($title);
                   3059:     $linktext = &mt($linktext);
1.448     albertel 3060:     return qq{<a href="$link" title="$title" $target>$linktext</a>}.
                   3061: 	&help_open_topic('View_recent_activity');
1.208     matthew  3062: }
                   3063: 
1.781     raeburn  3064: sub slot_reservations_link {
                   3065:     my ($linktext,$sname,$sdom,$target) = @_;
                   3066:     my $link ="/adm/slotrequest?command=showresv&amp;origin=aboutme";
                   3067:     my $title = 'View slot reservation history';
                   3068:     if (defined($sname) && $sname !~ /^\s*$/ &&
                   3069:         defined($sdom)  && $sdom  !~ /^\s*$/) {
                   3070:         $link .= "&amp;uname=$sname&amp;udom=$sdom";
                   3071:         $title .= ' of this student';
                   3072:     }
                   3073:     if (defined($target) && $target !~ /^\s*$/) {
                   3074:         $target = qq{target="$target"};
                   3075:     } else {
                   3076:         $target = '';
                   3077:     }
                   3078:     $title = &mt($title);
                   3079:     $linktext = &mt($linktext);
                   3080:     return qq{<a href="$link" title="$title" $target>$linktext</a>};
                   3081: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
                   3082: 
                   3083: }
                   3084: 
1.508     www      3085: # ===================================================== Display a student photo
                   3086: 
                   3087: 
1.509     albertel 3088: sub student_image_tag {
1.508     www      3089:     my ($domain,$user)=@_;
                   3090:     my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
                   3091:     if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
                   3092: 	return '<img src="'.$imgsrc.'" align="right" />';
                   3093:     } else {
                   3094: 	return '';
                   3095:     }
                   3096: }
                   3097: 
1.112     bowersj2 3098: =pod
                   3099: 
                   3100: =back
                   3101: 
                   3102: =head1 Access .tab File Data
                   3103: 
                   3104: =over 4
                   3105: 
1.648     raeburn  3106: =item * &languageids() 
1.112     bowersj2 3107: 
                   3108: returns list of all language ids
                   3109: 
                   3110: =cut
                   3111: 
1.14      harris41 3112: sub languageids {
1.16      harris41 3113:     return sort(keys(%language));
1.14      harris41 3114: }
                   3115: 
1.112     bowersj2 3116: =pod
                   3117: 
1.648     raeburn  3118: =item * &languagedescription() 
1.112     bowersj2 3119: 
                   3120: returns description of a specified language id
                   3121: 
                   3122: =cut
                   3123: 
1.14      harris41 3124: sub languagedescription {
1.125     www      3125:     my $code=shift;
                   3126:     return  ($supported_language{$code}?'* ':'').
                   3127:             $language{$code}.
1.126     www      3128: 	    ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145     www      3129: }
                   3130: 
                   3131: sub plainlanguagedescription {
                   3132:     my $code=shift;
                   3133:     return $language{$code};
                   3134: }
                   3135: 
                   3136: sub supportedlanguagecode {
                   3137:     my $code=shift;
                   3138:     return $supported_language{$code};
1.97      www      3139: }
                   3140: 
1.112     bowersj2 3141: =pod
                   3142: 
1.648     raeburn  3143: =item * &copyrightids() 
1.112     bowersj2 3144: 
                   3145: returns list of all copyrights
                   3146: 
                   3147: =cut
                   3148: 
                   3149: sub copyrightids {
                   3150:     return sort(keys(%cprtag));
                   3151: }
                   3152: 
                   3153: =pod
                   3154: 
1.648     raeburn  3155: =item * &copyrightdescription() 
1.112     bowersj2 3156: 
                   3157: returns description of a specified copyright id
                   3158: 
                   3159: =cut
                   3160: 
                   3161: sub copyrightdescription {
1.166     www      3162:     return &mt($cprtag{shift(@_)});
1.112     bowersj2 3163: }
1.197     matthew  3164: 
                   3165: =pod
                   3166: 
1.648     raeburn  3167: =item * &source_copyrightids() 
1.192     taceyjo1 3168: 
                   3169: returns list of all source copyrights
                   3170: 
                   3171: =cut
                   3172: 
                   3173: sub source_copyrightids {
                   3174:     return sort(keys(%scprtag));
                   3175: }
                   3176: 
                   3177: =pod
                   3178: 
1.648     raeburn  3179: =item * &source_copyrightdescription() 
1.192     taceyjo1 3180: 
                   3181: returns description of a specified source copyright id
                   3182: 
                   3183: =cut
                   3184: 
                   3185: sub source_copyrightdescription {
                   3186:     return &mt($scprtag{shift(@_)});
                   3187: }
1.112     bowersj2 3188: 
                   3189: =pod
                   3190: 
1.648     raeburn  3191: =item * &filecategories() 
1.112     bowersj2 3192: 
                   3193: returns list of all file categories
                   3194: 
                   3195: =cut
                   3196: 
                   3197: sub filecategories {
                   3198:     return sort(keys(%category_extensions));
                   3199: }
                   3200: 
                   3201: =pod
                   3202: 
1.648     raeburn  3203: =item * &filecategorytypes() 
1.112     bowersj2 3204: 
                   3205: returns list of file types belonging to a given file
                   3206: category
                   3207: 
                   3208: =cut
                   3209: 
                   3210: sub filecategorytypes {
1.356     albertel 3211:     my ($cat) = @_;
                   3212:     return @{$category_extensions{lc($cat)}};
1.112     bowersj2 3213: }
                   3214: 
                   3215: =pod
                   3216: 
1.648     raeburn  3217: =item * &fileembstyle() 
1.112     bowersj2 3218: 
                   3219: returns embedding style for a specified file type
                   3220: 
                   3221: =cut
                   3222: 
                   3223: sub fileembstyle {
                   3224:     return $fe{lc(shift(@_))};
1.169     www      3225: }
                   3226: 
1.351     www      3227: sub filemimetype {
                   3228:     return $fm{lc(shift(@_))};
                   3229: }
                   3230: 
1.169     www      3231: 
                   3232: sub filecategoryselect {
                   3233:     my ($name,$value)=@_;
1.189     matthew  3234:     return &select_form($value,$name,
1.169     www      3235: 			'' => &mt('Any category'),
                   3236: 			map { $_,$_ } sort(keys(%category_extensions)));
1.112     bowersj2 3237: }
                   3238: 
                   3239: =pod
                   3240: 
1.648     raeburn  3241: =item * &filedescription() 
1.112     bowersj2 3242: 
                   3243: returns description for a specified file type
                   3244: 
                   3245: =cut
                   3246: 
                   3247: sub filedescription {
1.188     matthew  3248:     my $file_description = $fd{lc(shift())};
                   3249:     $file_description =~ s:([\[\]]):~$1:g;
                   3250:     return &mt($file_description);
1.112     bowersj2 3251: }
                   3252: 
                   3253: =pod
                   3254: 
1.648     raeburn  3255: =item * &filedescriptionex() 
1.112     bowersj2 3256: 
                   3257: returns description for a specified file type with
                   3258: extra formatting
                   3259: 
                   3260: =cut
                   3261: 
                   3262: sub filedescriptionex {
                   3263:     my $ex=shift;
1.188     matthew  3264:     my $file_description = $fd{lc($ex)};
                   3265:     $file_description =~ s:([\[\]]):~$1:g;
                   3266:     return '.'.$ex.' '.&mt($file_description);
1.112     bowersj2 3267: }
                   3268: 
                   3269: # End of .tab access
                   3270: =pod
                   3271: 
                   3272: =back
                   3273: 
                   3274: =cut
                   3275: 
                   3276: # ------------------------------------------------------------------ File Types
                   3277: sub fileextensions {
                   3278:     return sort(keys(%fe));
                   3279: }
                   3280: 
1.97      www      3281: # ----------------------------------------------------------- Display Languages
                   3282: # returns a hash with all desired display languages
                   3283: #
                   3284: 
                   3285: sub display_languages {
                   3286:     my %languages=();
1.695     raeburn  3287:     foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356     albertel 3288: 	$languages{$lang}=1;
1.97      www      3289:     }
                   3290:     &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258     albertel 3291:     if ($env{'form.displaylanguage'}) {
1.356     albertel 3292: 	foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
                   3293: 	    $languages{$lang}=1;
1.97      www      3294:         }
                   3295:     }
                   3296:     return %languages;
1.14      harris41 3297: }
                   3298: 
1.582     albertel 3299: sub languages {
                   3300:     my ($possible_langs) = @_;
1.695     raeburn  3301:     my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582     albertel 3302:     if (!ref($possible_langs)) {
                   3303: 	if( wantarray ) {
                   3304: 	    return @preferred_langs;
                   3305: 	} else {
                   3306: 	    return $preferred_langs[0];
                   3307: 	}
                   3308:     }
                   3309:     my %possibilities = map { $_ => 1 } (@$possible_langs);
                   3310:     my @preferred_possibilities;
                   3311:     foreach my $preferred_lang (@preferred_langs) {
                   3312: 	if (exists($possibilities{$preferred_lang})) {
                   3313: 	    push(@preferred_possibilities, $preferred_lang);
                   3314: 	}
                   3315:     }
                   3316:     if( wantarray ) {
                   3317: 	return @preferred_possibilities;
                   3318:     }
                   3319:     return $preferred_possibilities[0];
                   3320: }
                   3321: 
1.742     raeburn  3322: sub user_lang {
                   3323:     my ($touname,$toudom,$fromcid) = @_;
                   3324:     my @userlangs;
                   3325:     if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
                   3326:         @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
                   3327:                     $env{'course.'.$fromcid.'.languages'}));
                   3328:     } else {
                   3329:         my %langhash = &getlangs($touname,$toudom);
                   3330:         if ($langhash{'languages'} ne '') {
                   3331:             @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
                   3332:         } else {
                   3333:             my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
                   3334:             if ($domdefs{'lang_def'} ne '') {
                   3335:                 @userlangs = ($domdefs{'lang_def'});
                   3336:             }
                   3337:         }
                   3338:     }
                   3339:     my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
                   3340:     my $user_lh = Apache::localize->get_handle(@languages);
                   3341:     return $user_lh;
                   3342: }
                   3343: 
                   3344: 
1.112     bowersj2 3345: ###############################################################
                   3346: ##               Student Answer Attempts                     ##
                   3347: ###############################################################
                   3348: 
                   3349: =pod
                   3350: 
                   3351: =head1 Alternate Problem Views
                   3352: 
                   3353: =over 4
                   3354: 
1.648     raeburn  3355: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112     bowersj2 3356:     $getattempt, $regexp, $gradesub)
                   3357: 
                   3358: Return string with previous attempt on problem. Arguments:
                   3359: 
                   3360: =over 4
                   3361: 
                   3362: =item * $symb: Problem, including path
                   3363: 
                   3364: =item * $username: username of the desired student
                   3365: 
                   3366: =item * $domain: domain of the desired student
1.14      harris41 3367: 
1.112     bowersj2 3368: =item * $course: Course ID
1.14      harris41 3369: 
1.112     bowersj2 3370: =item * $getattempt: Leave blank for all attempts, otherwise put
                   3371:     something
1.14      harris41 3372: 
1.112     bowersj2 3373: =item * $regexp: if string matches this regexp, the string will be
                   3374:     sent to $gradesub
1.14      harris41 3375: 
1.112     bowersj2 3376: =item * $gradesub: routine that processes the string if it matches $regexp
1.14      harris41 3377: 
1.112     bowersj2 3378: =back
1.14      harris41 3379: 
1.112     bowersj2 3380: The output string is a table containing all desired attempts, if any.
1.16      harris41 3381: 
1.112     bowersj2 3382: =cut
1.1       albertel 3383: 
                   3384: sub get_previous_attempt {
1.43      ng       3385:   my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1       albertel 3386:   my $prevattempts='';
1.43      ng       3387:   no strict 'refs';
1.1       albertel 3388:   if ($symb) {
1.3       albertel 3389:     my (%returnhash)=
                   3390:       &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1       albertel 3391:     if ($returnhash{'version'}) {
                   3392:       my %lasthash=();
                   3393:       my $version;
                   3394:       for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356     albertel 3395:         foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
                   3396: 	  $lasthash{$key}=$returnhash{$version.':'.$key};
1.19      harris41 3397:         }
1.1       albertel 3398:       }
1.596     albertel 3399:       $prevattempts=&start_data_table().&start_data_table_header_row();
                   3400:       $prevattempts.='<th>'.&mt('History').'</th>';
1.945     raeburn  3401:       my %typeparts;
                   3402:       my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356     albertel 3403:       foreach my $key (sort(keys(%lasthash))) {
                   3404: 	my ($ign,@parts) = split(/\./,$key);
1.41      ng       3405: 	if ($#parts > 0) {
1.31      albertel 3406: 	  my $data=$parts[-1];
                   3407: 	  pop(@parts);
1.945     raeburn  3408:           if ($data eq 'type') {
                   3409:               unless ($showsurv) {
                   3410:                   my $id = join(',',@parts);
                   3411:                   $typeparts{$ign.'.'.$id} = $lasthash{$key};
                   3412:               }
                   3413:               delete($lasthash{$key});
                   3414:           } else {
                   3415: 	      $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.'&nbsp;</th>';
                   3416:           }
1.31      albertel 3417: 	} else {
1.41      ng       3418: 	  if ($#parts == 0) {
                   3419: 	    $prevattempts.='<th>'.$parts[0].'</th>';
                   3420: 	  } else {
                   3421: 	    $prevattempts.='<th>'.$ign.'</th>';
                   3422: 	  }
1.31      albertel 3423: 	}
1.16      harris41 3424:       }
1.596     albertel 3425:       $prevattempts.=&end_data_table_header_row();
1.945     raeburn  3426:       my %lasthidden;
1.40      ng       3427:       if ($getattempt eq '') {
                   3428: 	for ($version=1;$version<=$returnhash{'version'};$version++) {
1.945     raeburn  3429:             my @hidden;
                   3430:             if (%typeparts) {
                   3431:                 foreach my $id (keys(%typeparts)) {
                   3432:                     if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') || ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
                   3433:                         push(@hidden,$id);
                   3434:                         $lasthidden{$id} = 1;
                   3435:                     } elsif ($lasthidden{$id}) {
                   3436:                         if (exists($returnhash{$version.':'.$id.'.award'})) {
                   3437:                             delete($lasthidden{$id});
                   3438:                         }
                   3439:                     }
                   3440:                 }
                   3441:             }
                   3442:             $prevattempts.=&start_data_table_row().
                   3443:                            '<td>'.&mt('Transaction [_1]',$version).'</td>';
                   3444:             if (@hidden) {
                   3445:                 foreach my $key (sort(keys(%lasthash))) {
                   3446:                     my $hide;
                   3447:                     foreach my $id (@hidden) {
                   3448:                         if ($key =~ /^\Q$id\E/) {
                   3449:                             $hide = 1;
                   3450:                             last;
                   3451:                         }
                   3452:                     }
                   3453:                     if ($hide) {
                   3454:                         my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
                   3455:                         if (($data eq 'award') || ($data eq 'awarddetail')) {
                   3456:                             my $value = &format_previous_attempt_value($key,
                   3457:                                              $returnhash{$version.':'.$key});
                   3458:                             $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3459:                         } else {
                   3460:                             $prevattempts.='<td>&nbsp;</td>';
                   3461:                         }
                   3462:                     } else {
                   3463:                         if ($key =~ /\./) {
                   3464:                             my $value = &format_previous_attempt_value($key,
                   3465:                                               $returnhash{$version.':'.$key});
                   3466:                             $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3467:                         } else {
                   3468:                             $prevattempts.='<td>&nbsp;</td>';
                   3469:                         }
                   3470:                     }
                   3471:                 }
                   3472:             } else {
                   3473: 	        foreach my $key (sort(keys(%lasthash))) {
                   3474: 		    my $value = &format_previous_attempt_value($key,
                   3475: 			            $returnhash{$version.':'.$key});
                   3476: 		    $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3477: 	        }
                   3478:             }
                   3479: 	    $prevattempts.=&end_data_table_row();
1.40      ng       3480: 	 }
1.1       albertel 3481:       }
1.945     raeburn  3482:       my @currhidden = keys(%lasthidden);
1.596     albertel 3483:       $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356     albertel 3484:       foreach my $key (sort(keys(%lasthash))) {
1.945     raeburn  3485:           if (%typeparts) {
                   3486:               my $hidden;
                   3487:               foreach my $id (@currhidden) {
                   3488:                   if ($key =~ /^\Q$id\E/) {
                   3489:                       $hidden = 1;
                   3490:                       last;
                   3491:                   }
                   3492:               }
                   3493:               if ($hidden) {
                   3494:                   my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
                   3495:                   if (($data eq 'award') || ($data eq 'awarddetail')) {
                   3496:                       my $value = &format_previous_attempt_value($key,$lasthash{$key});
                   3497:                       if ($key =~/$regexp$/ && (defined &$gradesub)) {
                   3498:                           $value = &$gradesub($value);
                   3499:                       }
                   3500:                       $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3501:                   } else {
                   3502:                       $prevattempts.='<td>&nbsp;</td>';
                   3503:                   }
                   3504:               } else {
                   3505:                   my $value = &format_previous_attempt_value($key,$lasthash{$key});
                   3506:                   if ($key =~/$regexp$/ && (defined &$gradesub)) {
                   3507:                       $value = &$gradesub($value);
                   3508:                   }
                   3509:                   $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3510:               }
                   3511:           } else {
                   3512: 	      my $value = &format_previous_attempt_value($key,$lasthash{$key});
                   3513: 	      if ($key =~/$regexp$/ && (defined &$gradesub)) {
                   3514:                   $value = &$gradesub($value);
                   3515:               }
                   3516: 	      $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3517:           }
1.16      harris41 3518:       }
1.596     albertel 3519:       $prevattempts.= &end_data_table_row().&end_data_table();
1.1       albertel 3520:     } else {
1.596     albertel 3521:       $prevattempts=
                   3522: 	  &start_data_table().&start_data_table_row().
                   3523: 	  '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
                   3524: 	  &end_data_table_row().&end_data_table();
1.1       albertel 3525:     }
                   3526:   } else {
1.596     albertel 3527:     $prevattempts=
                   3528: 	  &start_data_table().&start_data_table_row().
                   3529: 	  '<td>'.&mt('No data.').'</td>'.
                   3530: 	  &end_data_table_row().&end_data_table();
1.1       albertel 3531:   }
1.10      albertel 3532: }
                   3533: 
1.581     albertel 3534: sub format_previous_attempt_value {
                   3535:     my ($key,$value) = @_;
                   3536:     if ($key =~ /timestamp/) {
                   3537: 	$value = &Apache::lonlocal::locallocaltime($value);
                   3538:     } elsif (ref($value) eq 'ARRAY') {
                   3539: 	$value = '('.join(', ', @{ $value }).')';
                   3540:     } else {
                   3541: 	$value = &unescape($value);
                   3542:     }
                   3543:     return $value;
                   3544: }
                   3545: 
                   3546: 
1.107     albertel 3547: sub relative_to_absolute {
                   3548:     my ($url,$output)=@_;
                   3549:     my $parser=HTML::TokeParser->new(\$output);
                   3550:     my $token;
                   3551:     my $thisdir=$url;
                   3552:     my @rlinks=();
                   3553:     while ($token=$parser->get_token) {
                   3554: 	if ($token->[0] eq 'S') {
                   3555: 	    if ($token->[1] eq 'a') {
                   3556: 		if ($token->[2]->{'href'}) {
                   3557: 		    $rlinks[$#rlinks+1]=$token->[2]->{'href'};
                   3558: 		}
                   3559: 	    } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
                   3560: 		$rlinks[$#rlinks+1]=$token->[2]->{'src'};
                   3561: 	    } elsif ($token->[1] eq 'base') {
                   3562: 		$thisdir=$token->[2]->{'href'};
                   3563: 	    }
                   3564: 	}
                   3565:     }
                   3566:     $thisdir=~s-/[^/]*$--;
1.356     albertel 3567:     foreach my $link (@rlinks) {
1.726     raeburn  3568: 	unless (($link=~/^https?\:\/\//i) ||
1.356     albertel 3569: 		($link=~/^\//) ||
                   3570: 		($link=~/^javascript:/i) ||
                   3571: 		($link=~/^mailto:/i) ||
                   3572: 		($link=~/^\#/)) {
                   3573: 	    my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
                   3574: 	    $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107     albertel 3575: 	}
                   3576:     }
                   3577: # -------------------------------------------------- Deal with Applet codebases
                   3578:     $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
                   3579:     return $output;
                   3580: }
                   3581: 
1.112     bowersj2 3582: =pod
                   3583: 
1.648     raeburn  3584: =item * &get_student_view()
1.112     bowersj2 3585: 
                   3586: show a snapshot of what student was looking at
                   3587: 
                   3588: =cut
                   3589: 
1.10      albertel 3590: sub get_student_view {
1.186     albertel 3591:   my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114     www      3592:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 3593:   my (%form);
1.10      albertel 3594:   my @elements=('symb','courseid','domain','username');
                   3595:   foreach my $element (@elements) {
1.186     albertel 3596:       $form{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 3597:   }
1.186     albertel 3598:   if (defined($moreenv)) {
                   3599:       %form=(%form,%{$moreenv});
                   3600:   }
1.236     albertel 3601:   if (defined($target)) { $form{'grade_target'} = $target; }
1.107     albertel 3602:   $feedurl=&Apache::lonnet::clutter($feedurl);
1.650     www      3603:   my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11      albertel 3604:   $userview=~s/\<body[^\>]*\>//gi;
                   3605:   $userview=~s/\<\/body\>//gi;
                   3606:   $userview=~s/\<html\>//gi;
                   3607:   $userview=~s/\<\/html\>//gi;
                   3608:   $userview=~s/\<head\>//gi;
                   3609:   $userview=~s/\<\/head\>//gi;
                   3610:   $userview=~s/action\s*\=/would_be_action\=/gi;
1.107     albertel 3611:   $userview=&relative_to_absolute($feedurl,$userview);
1.650     www      3612:   if (wantarray) {
                   3613:      return ($userview,$response);
                   3614:   } else {
                   3615:      return $userview;
                   3616:   }
                   3617: }
                   3618: 
                   3619: sub get_student_view_with_retries {
                   3620:   my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
                   3621: 
                   3622:     my $ok = 0;                 # True if we got a good response.
                   3623:     my $content;
                   3624:     my $response;
                   3625: 
                   3626:     # Try to get the student_view done. within the retries count:
                   3627:     
                   3628:     do {
                   3629:          ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
                   3630:          $ok      = $response->is_success;
                   3631:          if (!$ok) {
                   3632:             &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
                   3633:          }
                   3634:          $retries--;
                   3635:     } while (!$ok && ($retries > 0));
                   3636:     
                   3637:     if (!$ok) {
                   3638:        $content = '';          # On error return an empty content.
                   3639:     }
1.651     www      3640:     if (wantarray) {
                   3641:        return ($content, $response);
                   3642:     } else {
                   3643:        return $content;
                   3644:     }
1.11      albertel 3645: }
                   3646: 
1.112     bowersj2 3647: =pod
                   3648: 
1.648     raeburn  3649: =item * &get_student_answers() 
1.112     bowersj2 3650: 
                   3651: show a snapshot of how student was answering problem
                   3652: 
                   3653: =cut
                   3654: 
1.11      albertel 3655: sub get_student_answers {
1.100     sakharuk 3656:   my ($symb,$username,$domain,$courseid,%form) = @_;
1.114     www      3657:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 3658:   my (%moreenv);
1.11      albertel 3659:   my @elements=('symb','courseid','domain','username');
                   3660:   foreach my $element (@elements) {
1.186     albertel 3661:     $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 3662:   }
1.186     albertel 3663:   $moreenv{'grade_target'}='answer';
                   3664:   %moreenv=(%form,%moreenv);
1.497     raeburn  3665:   $feedurl = &Apache::lonnet::clutter($feedurl);
                   3666:   my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10      albertel 3667:   return $userview;
1.1       albertel 3668: }
1.116     albertel 3669: 
                   3670: =pod
                   3671: 
                   3672: =item * &submlink()
                   3673: 
1.242     albertel 3674: Inputs: $text $uname $udom $symb $target
1.116     albertel 3675: 
                   3676: Returns: A link to grades.pm such as to see the SUBM view of a student
                   3677: 
                   3678: =cut
                   3679: 
                   3680: ###############################################
                   3681: sub submlink {
1.242     albertel 3682:     my ($text,$uname,$udom,$symb,$target)=@_;
1.116     albertel 3683:     if (!($uname && $udom)) {
                   3684: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 3685: 	    &Apache::lonnet::whichuser($symb);
1.116     albertel 3686: 	if (!$symb) { $symb=$cursymb; }
                   3687:     }
1.254     matthew  3688:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      3689:     $symb=&escape($symb);
1.960     bisitz   3690:     if ($target) { $target=" target=\"$target\""; }
                   3691:     return
                   3692:         '<a href="/adm/grades?command=submission'.
                   3693:         '&amp;symb='.$symb.
                   3694:         '&amp;student='.$uname.
                   3695:         '&amp;userdom='.$udom.'"'.
                   3696:         $target.'>'.$text.'</a>';
1.242     albertel 3697: }
                   3698: ##############################################
                   3699: 
                   3700: =pod
                   3701: 
                   3702: =item * &pgrdlink()
                   3703: 
                   3704: Inputs: $text $uname $udom $symb $target
                   3705: 
                   3706: Returns: A link to grades.pm such as to see the PGRD view of a student
                   3707: 
                   3708: =cut
                   3709: 
                   3710: ###############################################
                   3711: sub pgrdlink {
                   3712:     my $link=&submlink(@_);
                   3713:     $link=~s/(&command=submission)/$1&showgrading=yes/;
                   3714:     return $link;
                   3715: }
                   3716: ##############################################
                   3717: 
                   3718: =pod
                   3719: 
                   3720: =item * &pprmlink()
                   3721: 
                   3722: Inputs: $text $uname $udom $symb $target
                   3723: 
                   3724: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283     albertel 3725: student and a specific resource
1.242     albertel 3726: 
                   3727: =cut
                   3728: 
                   3729: ###############################################
                   3730: sub pprmlink {
                   3731:     my ($text,$uname,$udom,$symb,$target)=@_;
                   3732:     if (!($uname && $udom)) {
                   3733: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 3734: 	    &Apache::lonnet::whichuser($symb);
1.242     albertel 3735: 	if (!$symb) { $symb=$cursymb; }
                   3736:     }
1.254     matthew  3737:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      3738:     $symb=&escape($symb);
1.242     albertel 3739:     if ($target) { $target="target=\"$target\""; }
1.595     albertel 3740:     return '<a href="/adm/parmset?command=set&amp;'.
                   3741: 	'symb='.$symb.'&amp;uname='.$uname.
                   3742: 	'&amp;udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116     albertel 3743: }
                   3744: ##############################################
1.37      matthew  3745: 
1.112     bowersj2 3746: =pod
                   3747: 
                   3748: =back
                   3749: 
                   3750: =cut
                   3751: 
1.37      matthew  3752: ###############################################
1.51      www      3753: 
                   3754: 
                   3755: sub timehash {
1.687     raeburn  3756:     my ($thistime) = @_;
                   3757:     my $timezone = &Apache::lonlocal::gettimezone();
                   3758:     my $dt = DateTime->from_epoch(epoch => $thistime)
                   3759:                      ->set_time_zone($timezone);
                   3760:     my $wday = $dt->day_of_week();
                   3761:     if ($wday == 7) { $wday = 0; }
                   3762:     return ( 'second' => $dt->second(),
                   3763:              'minute' => $dt->minute(),
                   3764:              'hour'   => $dt->hour(),
                   3765:              'day'     => $dt->day_of_month(),
                   3766:              'month'   => $dt->month(),
                   3767:              'year'    => $dt->year(),
                   3768:              'weekday' => $wday,
                   3769:              'dayyear' => $dt->day_of_year(),
                   3770:              'dlsav'   => $dt->is_dst() );
1.51      www      3771: }
                   3772: 
1.370     www      3773: sub utc_string {
                   3774:     my ($date)=@_;
1.371     www      3775:     return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370     www      3776: }
                   3777: 
1.51      www      3778: sub maketime {
                   3779:     my %th=@_;
1.687     raeburn  3780:     my ($epoch_time,$timezone,$dt);
                   3781:     $timezone = &Apache::lonlocal::gettimezone();
                   3782:     eval {
                   3783:         $dt = DateTime->new( year   => $th{'year'},
                   3784:                              month  => $th{'month'},
                   3785:                              day    => $th{'day'},
                   3786:                              hour   => $th{'hour'},
                   3787:                              minute => $th{'minute'},
                   3788:                              second => $th{'second'},
                   3789:                              time_zone => $timezone,
                   3790:                          );
                   3791:     };
                   3792:     if (!$@) {
                   3793:         $epoch_time = $dt->epoch;
                   3794:         if ($epoch_time) {
                   3795:             return $epoch_time;
                   3796:         }
                   3797:     }
1.51      www      3798:     return POSIX::mktime(
                   3799:         ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210     www      3800:          $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70      www      3801: }
                   3802: 
                   3803: #########################################
1.51      www      3804: 
                   3805: sub findallcourses {
1.482     raeburn  3806:     my ($roles,$uname,$udom) = @_;
1.355     albertel 3807:     my %roles;
                   3808:     if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348     albertel 3809:     my %courses;
1.51      www      3810:     my $now=time;
1.482     raeburn  3811:     if (!defined($uname)) {
                   3812:         $uname = $env{'user.name'};
                   3813:     }
                   3814:     if (!defined($udom)) {
                   3815:         $udom = $env{'user.domain'};
                   3816:     }
                   3817:     if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
                   3818:         my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
                   3819:         if (!%roles) {
                   3820:             %roles = (
                   3821:                        cc => 1,
1.907     raeburn  3822:                        co => 1,
1.482     raeburn  3823:                        in => 1,
                   3824:                        ep => 1,
                   3825:                        ta => 1,
                   3826:                        cr => 1,
                   3827:                        st => 1,
                   3828:              );
                   3829:         }
                   3830:         foreach my $entry (keys(%roleshash)) {
                   3831:             my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
                   3832:             if ($trole =~ /^cr/) { 
                   3833:                 next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
                   3834:             } else {
                   3835:                 next if (!exists($roles{$trole}));
                   3836:             }
                   3837:             if ($tend) {
                   3838:                 next if ($tend < $now);
                   3839:             }
                   3840:             if ($tstart) {
                   3841:                 next if ($tstart > $now);
                   3842:             }
                   3843:             my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
                   3844:             (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
                   3845:             if ($secpart eq '') {
                   3846:                 ($cnum,$role) = split(/_/,$cnumpart); 
                   3847:                 $sec = 'none';
                   3848:                 $realsec = '';
                   3849:             } else {
                   3850:                 $cnum = $cnumpart;
                   3851:                 ($sec,$role) = split(/_/,$secpart);
                   3852:                 $realsec = $sec;
1.490     raeburn  3853:             }
1.482     raeburn  3854:             $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
                   3855:         }
                   3856:     } else {
                   3857:         foreach my $key (keys(%env)) {
1.483     albertel 3858: 	    if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
                   3859:                  $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482     raeburn  3860: 	        my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
                   3861: 	        next if ($role eq 'ca' || $role eq 'aa');
                   3862: 	        next if (%roles && !exists($roles{$role}));
                   3863: 	        my ($starttime,$endtime)=split(/\./,$env{$key});
                   3864:                 my $active=1;
                   3865:                 if ($starttime) {
                   3866: 		    if ($now<$starttime) { $active=0; }
                   3867:                 }
                   3868:                 if ($endtime) {
                   3869:                     if ($now>$endtime) { $active=0; }
                   3870:                 }
                   3871:                 if ($active) {
                   3872:                     if ($sec eq '') {
                   3873:                         $sec = 'none';
                   3874:                     }
                   3875:                     $courses{$cdom.'_'.$cnum}{$sec} = 
                   3876:                                      $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474     raeburn  3877:                 }
                   3878:             }
1.51      www      3879:         }
                   3880:     }
1.474     raeburn  3881:     return %courses;
1.51      www      3882: }
1.37      matthew  3883: 
1.54      www      3884: ###############################################
1.474     raeburn  3885: 
                   3886: sub blockcheck {
1.482     raeburn  3887:     my ($setters,$activity,$uname,$udom) = @_;
1.490     raeburn  3888: 
                   3889:     if (!defined($udom)) {
                   3890:         $udom = $env{'user.domain'};
                   3891:     }
                   3892:     if (!defined($uname)) {
                   3893:         $uname = $env{'user.name'};
                   3894:     }
                   3895: 
                   3896:     # If uname and udom are for a course, check for blocks in the course.
                   3897: 
                   3898:     if (&Apache::lonnet::is_course($udom,$uname)) {
                   3899:         my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502     raeburn  3900:         my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490     raeburn  3901:         return ($startblock,$endblock);
                   3902:     }
1.474     raeburn  3903: 
1.502     raeburn  3904:     my $startblock = 0;
                   3905:     my $endblock = 0;
1.482     raeburn  3906:     my %live_courses = &findallcourses(undef,$uname,$udom);
1.474     raeburn  3907: 
1.490     raeburn  3908:     # If uname is for a user, and activity is course-specific, i.e.,
                   3909:     # boards, chat or groups, check for blocking in current course only.
1.474     raeburn  3910: 
1.490     raeburn  3911:     if (($activity eq 'boards' || $activity eq 'chat' ||
                   3912:          $activity eq 'groups') && ($env{'request.course.id'})) {
                   3913:         foreach my $key (keys(%live_courses)) {
                   3914:             if ($key ne $env{'request.course.id'}) {
                   3915:                 delete($live_courses{$key});
                   3916:             }
                   3917:         }
                   3918:     }
                   3919: 
                   3920:     my $otheruser = 0;
                   3921:     my %own_courses;
                   3922:     if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
                   3923:         # Resource belongs to user other than current user.
                   3924:         $otheruser = 1;
                   3925:         # Gather courses for current user
                   3926:         %own_courses = 
                   3927:             &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
                   3928:     }
                   3929: 
                   3930:     # Gather active course roles - course coordinator, instructor, 
                   3931:     # exam proctor, ta, student, or custom role.
1.474     raeburn  3932: 
                   3933:     foreach my $course (keys(%live_courses)) {
1.482     raeburn  3934:         my ($cdom,$cnum);
                   3935:         if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
                   3936:             $cdom = $env{'course.'.$course.'.domain'};
                   3937:             $cnum = $env{'course.'.$course.'.num'};
                   3938:         } else {
1.490     raeburn  3939:             ($cdom,$cnum) = split(/_/,$course); 
1.482     raeburn  3940:         }
                   3941:         my $no_ownblock = 0;
                   3942:         my $no_userblock = 0;
1.533     raeburn  3943:         if ($otheruser && $activity ne 'com') {
1.490     raeburn  3944:             # Check if current user has 'evb' priv for this
                   3945:             if (defined($own_courses{$course})) {
                   3946:                 foreach my $sec (keys(%{$own_courses{$course}})) {
                   3947:                     my $checkrole = 'cm./'.$cdom.'/'.$cnum;
                   3948:                     if ($sec ne 'none') {
                   3949:                         $checkrole .= '/'.$sec;
                   3950:                     }
                   3951:                     if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   3952:                         $no_ownblock = 1;
                   3953:                         last;
                   3954:                     }
                   3955:                 }
                   3956:             }
                   3957:             # if they have 'evb' priv and are currently not playing student
                   3958:             next if (($no_ownblock) &&
                   3959:                  ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
                   3960:         }
1.474     raeburn  3961:         foreach my $sec (keys(%{$live_courses{$course}})) {
1.482     raeburn  3962:             my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474     raeburn  3963:             if ($sec ne 'none') {
1.482     raeburn  3964:                 $checkrole .= '/'.$sec;
1.474     raeburn  3965:             }
1.490     raeburn  3966:             if ($otheruser) {
                   3967:                 # Resource belongs to user other than current user.
                   3968:                 # Assemble privs for that user, and check for 'evb' priv.
1.482     raeburn  3969:                 my ($trole,$tdom,$tnum,$tsec);
                   3970:                 my $entry = $live_courses{$course}{$sec};
                   3971:                 if ($entry =~ /^cr/) {
                   3972:                     ($trole,$tdom,$tnum,$tsec) = 
                   3973:                       ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
                   3974:                 } else {
                   3975:                     ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
                   3976:                 }
                   3977:                 my ($spec,$area,$trest,%allroles,%userroles);
                   3978:                 $area = '/'.$tdom.'/'.$tnum;
                   3979:                 $trest = $tnum;
                   3980:                 if ($tsec ne '') {
                   3981:                     $area .= '/'.$tsec;
                   3982:                     $trest .= '/'.$tsec;
                   3983:                 }
                   3984:                 $spec = $trole.'.'.$area;
                   3985:                 if ($trole =~ /^cr/) {
                   3986:                     &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
                   3987:                                                       $tdom,$spec,$trest,$area);
                   3988:                 } else {
                   3989:                     &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
                   3990:                                                        $tdom,$spec,$trest,$area);
                   3991:                 }
                   3992:                 my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486     raeburn  3993:                 if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
                   3994:                     if ($1) {
                   3995:                         $no_userblock = 1;
                   3996:                         last;
                   3997:                     }
                   3998:                 }
1.490     raeburn  3999:             } else {
                   4000:                 # Resource belongs to current user
                   4001:                 # Check for 'evb' priv via lonnet::allowed().
1.482     raeburn  4002:                 if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   4003:                     $no_ownblock = 1;
                   4004:                     last;
                   4005:                 }
1.474     raeburn  4006:             }
                   4007:         }
                   4008:         # if they have the evb priv and are currently not playing student
1.482     raeburn  4009:         next if (($no_ownblock) &&
1.491     albertel 4010:                  ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482     raeburn  4011:         next if ($no_userblock);
1.474     raeburn  4012: 
1.866     kalberla 4013:         # Retrieve blocking times and identity of locker for course
1.490     raeburn  4014:         # of specified user, unless user has 'evb' privilege.
1.502     raeburn  4015:         
                   4016:         my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
                   4017:         if (($start != 0) && 
                   4018:             (($startblock == 0) || ($startblock > $start))) {
                   4019:             $startblock = $start;
                   4020:         }
                   4021:         if (($end != 0)  &&
                   4022:             (($endblock == 0) || ($endblock < $end))) {
                   4023:             $endblock = $end;
                   4024:         }
1.490     raeburn  4025:     }
                   4026:     return ($startblock,$endblock);
                   4027: }
                   4028: 
                   4029: sub get_blocks {
                   4030:     my ($setters,$activity,$cdom,$cnum) = @_;
                   4031:     my $startblock = 0;
                   4032:     my $endblock = 0;
                   4033:     my $course = $cdom.'_'.$cnum;
                   4034:     $setters->{$course} = {};
                   4035:     $setters->{$course}{'staff'} = [];
                   4036:     $setters->{$course}{'times'} = [];
                   4037:     my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
                   4038:     foreach my $record (keys(%records)) {
                   4039:         my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
                   4040:         if ($start <= time && $end >= time) {
                   4041:             my ($staff_name,$staff_dom,$title,$blocks) =
                   4042:                 &parse_block_record($records{$record});
                   4043:             if ($blocks->{$activity} eq 'on') {
                   4044:                 push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
                   4045:                 push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491     albertel 4046:                 if ( ($startblock == 0) || ($startblock > $start) ) {
                   4047:                     $startblock = $start;
1.490     raeburn  4048:                 }
1.491     albertel 4049:                 if ( ($endblock == 0) || ($endblock < $end) ) {
                   4050:                     $endblock = $end;
1.474     raeburn  4051:                 }
                   4052:             }
                   4053:         }
                   4054:     }
                   4055:     return ($startblock,$endblock);
                   4056: }
                   4057: 
                   4058: sub parse_block_record {
                   4059:     my ($record) = @_;
                   4060:     my ($setuname,$setudom,$title,$blocks);
                   4061:     if (ref($record) eq 'HASH') {
                   4062:         ($setuname,$setudom) = split(/:/,$record->{'setter'});
                   4063:         $title = &unescape($record->{'event'});
                   4064:         $blocks = $record->{'blocks'};
                   4065:     } else {
                   4066:         my @data = split(/:/,$record,3);
                   4067:         if (scalar(@data) eq 2) {
                   4068:             $title = $data[1];
                   4069:             ($setuname,$setudom) = split(/@/,$data[0]);
                   4070:         } else {
                   4071:             ($setuname,$setudom,$title) = @data;
                   4072:         }
                   4073:         $blocks = { 'com' => 'on' };
                   4074:     }
                   4075:     return ($setuname,$setudom,$title,$blocks);
                   4076: }
                   4077: 
1.854     kalberla 4078: sub blocking_status {
                   4079:   my ($activity,$uname,$udom) = @_;
1.867     kalberla 4080:   my %setters;
1.890     droeschl 4081: 
                   4082:   # check for active blocking
1.867     kalberla 4083:   my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
1.854     kalberla 4084: 
1.890     droeschl 4085:   my $blocked = $startblock && $endblock ? 1 : 0;
                   4086: 
                   4087:   # caller just wants to know whether a block is active
                   4088:   if (!wantarray) { return $blocked; }
                   4089: 
                   4090:   # build a link to a popup window containing the details
                   4091:   my $querystring  = "?activity=$activity";
                   4092:   # $uname and $udom decide whose portfolio the user is trying to look at
                   4093:      $querystring .= "&amp;udom=$udom"      if $udom;
                   4094:      $querystring .= "&amp;uname=$uname"    if $uname;
                   4095: 
                   4096:   my $output .= <<'END_MYBLOCK';
1.854     kalberla 4097:     function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
                   4098:         var options = "width=" + w + ",height=" + h + ",";
                   4099:         options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
                   4100:         options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
                   4101:         var newWin = window.open(url, wdwName, options);
                   4102:         newWin.focus();
                   4103:     }
1.890     droeschl 4104: END_MYBLOCK
1.854     kalberla 4105: 
1.890     droeschl 4106:   $output = Apache::lonhtmlcommon::scripttag($output);
                   4107:   
1.854     kalberla 4108:   my $popupUrl = "/adm/blockingstatus/$querystring";
1.890     droeschl 4109:   my $text = mt('Communication Blocked');
                   4110: 
1.867     kalberla 4111:   $output .= <<"END_BLOCK";
                   4112: <div class='LC_comblock'>
1.869     kalberla 4113:   <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890     droeschl 4114:   title='$text'>
                   4115:   <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869     kalberla 4116:   <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring' 
1.890     droeschl 4117:   title='$text'>$text</a>
1.867     kalberla 4118: </div>
                   4119: 
                   4120: END_BLOCK
1.474     raeburn  4121: 
1.854     kalberla 4122:   return ($blocked, $output);
                   4123: }
1.490     raeburn  4124: 
1.60      matthew  4125: ###############################################
                   4126: 
1.682     raeburn  4127: sub check_ip_acc {
                   4128:     my ($acc)=@_;
                   4129:     &Apache::lonxml::debug("acc is $acc");
                   4130:     if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
                   4131:         return 1;
                   4132:     }
                   4133:     my $allowed=0;
                   4134:     my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
                   4135: 
                   4136:     my $name;
                   4137:     foreach my $pattern (split(',',$acc)) {
                   4138:         $pattern =~ s/^\s*//;
                   4139:         $pattern =~ s/\s*$//;
                   4140:         if ($pattern =~ /\*$/) {
                   4141:             #35.8.*
                   4142:             $pattern=~s/\*//;
                   4143:             if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
                   4144:         } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
                   4145:             #35.8.3.[34-56]
                   4146:             my $low=$2;
                   4147:             my $high=$3;
                   4148:             $pattern=$1;
                   4149:             if ($ip =~ /^\Q$pattern\E/) {
                   4150:                 my $last=(split(/\./,$ip))[3];
                   4151:                 if ($last <=$high && $last >=$low) { $allowed=1; }
                   4152:             }
                   4153:         } elsif ($pattern =~ /^\*/) {
                   4154:             #*.msu.edu
                   4155:             $pattern=~s/\*//;
                   4156:             if (!defined($name)) {
                   4157:                 use Socket;
                   4158:                 my $netaddr=inet_aton($ip);
                   4159:                 ($name)=gethostbyaddr($netaddr,AF_INET);
                   4160:             }
                   4161:             if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
                   4162:         } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
                   4163:             #127.0.0.1
                   4164:             if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
                   4165:         } else {
                   4166:             #some.name.com
                   4167:             if (!defined($name)) {
                   4168:                 use Socket;
                   4169:                 my $netaddr=inet_aton($ip);
                   4170:                 ($name)=gethostbyaddr($netaddr,AF_INET);
                   4171:             }
                   4172:             if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
                   4173:         }
                   4174:         if ($allowed) { last; }
                   4175:     }
                   4176:     return $allowed;
                   4177: }
                   4178: 
                   4179: ###############################################
                   4180: 
1.60      matthew  4181: =pod
                   4182: 
1.112     bowersj2 4183: =head1 Domain Template Functions
                   4184: 
                   4185: =over 4
                   4186: 
                   4187: =item * &determinedomain()
1.60      matthew  4188: 
                   4189: Inputs: $domain (usually will be undef)
                   4190: 
1.63      www      4191: Returns: Determines which domain should be used for designs
1.60      matthew  4192: 
                   4193: =cut
1.54      www      4194: 
1.60      matthew  4195: ###############################################
1.63      www      4196: sub determinedomain {
                   4197:     my $domain=shift;
1.531     albertel 4198:     if (! $domain) {
1.60      matthew  4199:         # Determine domain if we have not been given one
1.893     raeburn  4200:         $domain = &Apache::lonnet::default_login_domain();
1.258     albertel 4201:         if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
                   4202:         if ($env{'request.role.domain'}) { 
                   4203:             $domain=$env{'request.role.domain'}; 
1.60      matthew  4204:         }
                   4205:     }
1.63      www      4206:     return $domain;
                   4207: }
                   4208: ###############################################
1.517     raeburn  4209: 
1.518     albertel 4210: sub devalidate_domconfig_cache {
                   4211:     my ($udom)=@_;
                   4212:     &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
                   4213: }
                   4214: 
                   4215: # ---------------------- Get domain configuration for a domain
                   4216: sub get_domainconf {
                   4217:     my ($udom) = @_;
                   4218:     my $cachetime=1800;
                   4219:     my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
                   4220:     if (defined($cached)) { return %{$result}; }
                   4221: 
                   4222:     my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948     raeburn  4223: 					     ['login','rolecolors','autoenroll'],$udom);
1.632     raeburn  4224:     my (%designhash,%legacy);
1.518     albertel 4225:     if (keys(%domconfig) > 0) {
                   4226:         if (ref($domconfig{'login'}) eq 'HASH') {
1.632     raeburn  4227:             if (keys(%{$domconfig{'login'}})) {
                   4228:                 foreach my $key (keys(%{$domconfig{'login'}})) {
1.699     raeburn  4229:                     if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.946     raeburn  4230:                         if ($key eq 'loginvia') {
                   4231:                             if (ref($domconfig{'login'}{'loginvia'}) eq 'HASH') {
                   4232:                                 my @ids = &Apache::lonnet::current_machine_ids();
                   4233:                                 foreach my $hostname (@ids) {
1.948     raeburn  4234:                                     if (ref($domconfig{'login'}{'loginvia'}{$hostname}) eq 'HASH') {
                   4235:                                         if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
                   4236:                                             my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
                   4237:                                             $designhash{$udom.'.login.loginvia'} = $server;
                   4238:                                             if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
                   4239: 
                   4240:                                                 $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
                   4241:                                             } else {
                   4242:                                                  $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
                   4243:                                             }
                   4244:                                             if ($domconfig{'login'}{'loginvia'}{$hostname}{'exempt'}) {
                   4245:                                                 $designhash{$udom.'.login.loginvia_exempt_'.$hostname} = $domconfig{'login'}{'loginvia'}{$hostname}{'exempt'};
                   4246:                                             }
1.946     raeburn  4247:                                         }
                   4248:                                     }
                   4249:                                 }
                   4250:                             }
                   4251:                         } else {
                   4252:                             foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
                   4253:                                 $designhash{$udom.'.login.'.$key.'_'.$img} = 
                   4254:                                     $domconfig{'login'}{$key}{$img};
                   4255:                             }
1.699     raeburn  4256:                         }
                   4257:                     } else {
                   4258:                         $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
                   4259:                     }
1.632     raeburn  4260:                 }
                   4261:             } else {
                   4262:                 $legacy{'login'} = 1;
1.518     albertel 4263:             }
1.632     raeburn  4264:         } else {
                   4265:             $legacy{'login'} = 1;
1.518     albertel 4266:         }
                   4267:         if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632     raeburn  4268:             if (keys(%{$domconfig{'rolecolors'}})) {
                   4269:                 foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
                   4270:                     if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
                   4271:                         foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
                   4272:                             $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
                   4273:                         }
1.518     albertel 4274:                     }
                   4275:                 }
1.632     raeburn  4276:             } else {
                   4277:                 $legacy{'rolecolors'} = 1;
1.518     albertel 4278:             }
1.632     raeburn  4279:         } else {
                   4280:             $legacy{'rolecolors'} = 1;
1.518     albertel 4281:         }
1.948     raeburn  4282:         if (ref($domconfig{'autoenroll'}) eq 'HASH') {
                   4283:             if ($domconfig{'autoenroll'}{'co-owners'}) {
                   4284:                 $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
                   4285:             }
                   4286:         }
1.632     raeburn  4287:         if (keys(%legacy) > 0) {
                   4288:             my %legacyhash = &get_legacy_domconf($udom);
                   4289:             foreach my $item (keys(%legacyhash)) {
                   4290:                 if ($item =~ /^\Q$udom\E\.login/) {
                   4291:                     if ($legacy{'login'}) { 
                   4292:                         $designhash{$item} = $legacyhash{$item};
                   4293:                     }
                   4294:                 } else {
                   4295:                     if ($legacy{'rolecolors'}) {
                   4296:                         $designhash{$item} = $legacyhash{$item};
                   4297:                     }
1.518     albertel 4298:                 }
                   4299:             }
                   4300:         }
1.632     raeburn  4301:     } else {
                   4302:         %designhash = &get_legacy_domconf($udom); 
1.518     albertel 4303:     }
                   4304:     &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
                   4305: 				  $cachetime);
                   4306:     return %designhash;
                   4307: }
                   4308: 
1.632     raeburn  4309: sub get_legacy_domconf {
                   4310:     my ($udom) = @_;
                   4311:     my %legacyhash;
                   4312:     my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
                   4313:     my $designfile =  $designdir.'/'.$udom.'.tab';
                   4314:     if (-e $designfile) {
                   4315:         if ( open (my $fh,"<$designfile") ) {
                   4316:             while (my $line = <$fh>) {
                   4317:                 next if ($line =~ /^\#/);
                   4318:                 chomp($line);
                   4319:                 my ($key,$val)=(split(/\=/,$line));
                   4320:                 if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
                   4321:             }
                   4322:             close($fh);
                   4323:         }
                   4324:     }
                   4325:     if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
                   4326:         $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
                   4327:     }
                   4328:     return %legacyhash;
                   4329: }
                   4330: 
1.63      www      4331: =pod
                   4332: 
1.112     bowersj2 4333: =item * &domainlogo()
1.63      www      4334: 
                   4335: Inputs: $domain (usually will be undef)
                   4336: 
                   4337: Returns: A link to a domain logo, if the domain logo exists.
                   4338: If the domain logo does not exist, a description of the domain.
                   4339: 
                   4340: =cut
1.112     bowersj2 4341: 
1.63      www      4342: ###############################################
                   4343: sub domainlogo {
1.517     raeburn  4344:     my $domain = &determinedomain(shift);
1.518     albertel 4345:     my %designhash = &get_domainconf($domain);    
1.517     raeburn  4346:     # See if there is a logo
                   4347:     if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519     raeburn  4348:         my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538     albertel 4349:         if ($imgsrc =~ m{^/(adm|res)/}) {
                   4350: 	    if ($imgsrc =~ m{^/res/}) {
                   4351: 		my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
                   4352: 		&Apache::lonnet::repcopy($local_name);
                   4353: 	    }
                   4354: 	   $imgsrc = &lonhttpdurl($imgsrc);
1.519     raeburn  4355:         } 
                   4356:         return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514     albertel 4357:     } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
                   4358:         return &Apache::lonnet::domain($domain,'description');
1.59      www      4359:     } else {
1.60      matthew  4360:         return '';
1.59      www      4361:     }
                   4362: }
1.63      www      4363: ##############################################
                   4364: 
                   4365: =pod
                   4366: 
1.112     bowersj2 4367: =item * &designparm()
1.63      www      4368: 
                   4369: Inputs: $which parameter; $domain (usually will be undef)
                   4370: 
                   4371: Returns: value of designparamter $which
                   4372: 
                   4373: =cut
1.112     bowersj2 4374: 
1.397     albertel 4375: 
1.400     albertel 4376: ##############################################
1.397     albertel 4377: sub designparm {
                   4378:     my ($which,$domain)=@_;
                   4379:     if (exists($env{'environment.color.'.$which})) {
1.817     bisitz   4380:         return $env{'environment.color.'.$which};
1.96      www      4381:     }
1.63      www      4382:     $domain=&determinedomain($domain);
1.518     albertel 4383:     my %domdesign = &get_domainconf($domain);
1.520     raeburn  4384:     my $output;
1.517     raeburn  4385:     if ($domdesign{$domain.'.'.$which} ne '') {
1.817     bisitz   4386:         $output = $domdesign{$domain.'.'.$which};
1.63      www      4387:     } else {
1.520     raeburn  4388:         $output = $defaultdesign{$which};
                   4389:     }
                   4390:     if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635     raeburn  4391:         ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538     albertel 4392:         if ($output =~ m{^/(adm|res)/}) {
1.817     bisitz   4393:             if ($output =~ m{^/res/}) {
                   4394:                 my $local_name = &Apache::lonnet::filelocation('',$output);
                   4395:                 &Apache::lonnet::repcopy($local_name);
                   4396:             }
1.520     raeburn  4397:             $output = &lonhttpdurl($output);
                   4398:         }
1.63      www      4399:     }
1.520     raeburn  4400:     return $output;
1.63      www      4401: }
1.59      www      4402: 
1.822     bisitz   4403: ##############################################
                   4404: =pod
                   4405: 
1.832     bisitz   4406: =item * &authorspace()
                   4407: 
                   4408: Inputs: ./.
                   4409: 
                   4410: Returns: Path to the Construction Space of the current user's
                   4411:          accessed author space
                   4412:          The author space will be that of the current user
                   4413:          when accessing the own author space
                   4414:          and that of the co-author/assistent co-author
                   4415:          when accessing the co-author's/assistent co-author's
                   4416:          space
                   4417: 
                   4418: =cut
                   4419: 
                   4420: sub authorspace {
                   4421:     my $caname = '';
                   4422:     if ($env{'request.role'} =~ /^ca|^aa/) {
                   4423:         (undef,$caname) =
                   4424:             ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
                   4425:     } else {
                   4426:         $caname = $env{'user.name'};
                   4427:     }
                   4428:     return '/priv/'.$caname.'/';
                   4429: }
                   4430: 
                   4431: ##############################################
                   4432: =pod
                   4433: 
1.822     bisitz   4434: =item * &head_subbox()
                   4435: 
                   4436: Inputs: $content (contains HTML code with page functions, etc.)
                   4437: 
                   4438: Returns: HTML div with $content
                   4439:          To be included in page header
                   4440: 
                   4441: =cut
                   4442: 
                   4443: sub head_subbox {
                   4444:     my ($content)=@_;
                   4445:     my $output =
1.844     bisitz   4446:         '<div id="LC_head_subbox">'
1.822     bisitz   4447:        .$content
                   4448:        .'</div>'
                   4449: }
                   4450: 
                   4451: ##############################################
                   4452: =pod
                   4453: 
                   4454: =item * &CSTR_pageheader()
                   4455: 
                   4456: Inputs: ./.
                   4457: 
                   4458: Returns: HTML div with CSTR path and recent box
                   4459:          To be included on Construction Space pages
                   4460: 
                   4461: =cut
                   4462: 
                   4463: sub CSTR_pageheader {
                   4464:     # this is for resources; directories have customtitle, and crumbs
                   4465:             # and select recent are created in lonpubdir.pm  
                   4466:     my ($uname,$thisdisfn)=
                   4467:         ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
                   4468:     my $formaction='/priv/'.$uname.'/'.$thisdisfn;
                   4469:     $formaction=~s/\/+/\//g;
                   4470: 
                   4471:     my $parentpath = '';
                   4472:     my $lastitem = '';
                   4473:     if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
                   4474:         $parentpath = $1;
                   4475:         $lastitem = $2;
                   4476:     } else {
                   4477:         $lastitem = $thisdisfn;
                   4478:     }
1.921     bisitz   4479: 
                   4480:     my $output =
1.822     bisitz   4481:          '<div>'
                   4482:         .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
                   4483:         .'<b>'.&mt('Construction Space:').'</b> '
                   4484:         .'<form name="dirs" method="post" action="'.$formaction
1.921     bisitz   4485:         .'" target="_top">' #FIXME lonpubdir: target="_parent"
                   4486:         .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv',undef,undef);
                   4487: 
                   4488:     if ($lastitem) {
                   4489:         $output .=
                   4490:              '<span class="LC_filename">'
                   4491:             .$lastitem
                   4492:             .'</span>';
                   4493:     }
                   4494:     $output .=
                   4495:          '<br />'
1.822     bisitz   4496:         #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
                   4497:         .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
                   4498:         .'</form>'
                   4499:         .&Apache::lonmenu::constspaceform()
                   4500:         .'</div>';
1.921     bisitz   4501: 
                   4502:     return $output;
1.822     bisitz   4503: }
                   4504: 
1.60      matthew  4505: ###############################################
                   4506: ###############################################
                   4507: 
                   4508: =pod
                   4509: 
1.112     bowersj2 4510: =back
                   4511: 
1.549     albertel 4512: =head1 HTML Helpers
1.112     bowersj2 4513: 
                   4514: =over 4
                   4515: 
                   4516: =item * &bodytag()
1.60      matthew  4517: 
                   4518: Returns a uniform header for LON-CAPA web pages.
                   4519: 
                   4520: Inputs: 
                   4521: 
1.112     bowersj2 4522: =over 4
                   4523: 
                   4524: =item * $title, A title to be displayed on the page.
                   4525: 
                   4526: =item * $function, the current role (can be undef).
                   4527: 
                   4528: =item * $addentries, extra parameters for the <body> tag.
                   4529: 
                   4530: =item * $bodyonly, if defined, only return the <body> tag.
                   4531: 
                   4532: =item * $domain, if defined, force a given domain.
                   4533: 
                   4534: =item * $forcereg, if page should register as content page (relevant for 
1.86      www      4535:             text interface only)
1.60      matthew  4536: 
1.814     bisitz   4537: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
                   4538:                      navigational links
1.317     albertel 4539: 
1.338     albertel 4540: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
                   4541: 
1.460     albertel 4542: =item * $args, optional argument valid values are
                   4543:             no_auto_mt_title -> prevents &mt()ing the title arg
1.562     albertel 4544:             inherit_jsmath -> when creating popup window in a page,
                   4545:                               should it have jsmath forced on by the
                   4546:                               current page
1.460     albertel 4547: 
1.112     bowersj2 4548: =back
                   4549: 
1.60      matthew  4550: Returns: A uniform header for LON-CAPA web pages.  
                   4551: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
                   4552: If $bodyonly is undef or zero, an html string containing a <body> tag and 
                   4553: other decorations will be returned.
                   4554: 
                   4555: =cut
                   4556: 
1.54      www      4557: sub bodytag {
1.831     bisitz   4558:     my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.962     droeschl 4559:         $no_nav_bar,$bgcolor,$args)=@_;
1.339     albertel 4560: 
1.954     raeburn  4561:     my $public;
                   4562:     if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
                   4563:         || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
                   4564:         $public = 1;
                   4565:     }
1.460     albertel 4566:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339     albertel 4567: 
1.183     matthew  4568:     $function = &get_users_function() if (!$function);
1.339     albertel 4569:     my $img =    &designparm($function.'.img',$domain);
                   4570:     my $font =   &designparm($function.'.font',$domain);
                   4571:     my $pgbg   = $bgcolor || &designparm($function.'.pgbg',$domain);
                   4572: 
1.803     bisitz   4573:     my %design = ( 'style'   => 'margin-top: 0',
1.535     albertel 4574: 		   'bgcolor' => $pgbg,
1.339     albertel 4575: 		   'text'    => $font,
                   4576:                    'alink'   => &designparm($function.'.alink',$domain),
                   4577: 		   'vlink'   => &designparm($function.'.vlink',$domain),
                   4578: 		   'link'    => &designparm($function.'.link',$domain),);
1.438     albertel 4579:     @design{keys(%$addentries)} = @$addentries{keys(%$addentries)}; 
1.339     albertel 4580: 
1.63      www      4581:  # role and realm
1.378     raeburn  4582:     my ($role,$realm) = split(/\./,$env{'request.role'},2);
                   4583:     if ($role  eq 'ca') {
1.479     albertel 4584:         my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500     albertel 4585:         $realm = &plainname($rname,$rdom);
1.378     raeburn  4586:     } 
1.55      www      4587: # realm
1.258     albertel 4588:     if ($env{'request.course.id'}) {
1.378     raeburn  4589:         if ($env{'request.role'} !~ /^cr/) {
                   4590:             $role = &Apache::lonnet::plaintext($role,&course_type());
                   4591:         }
1.898     raeburn  4592:         if ($env{'request.course.sec'}) {
                   4593:             $role .= ('&nbsp;'x2).'-&nbsp;'.&mt('section:').'&nbsp;'.$env{'request.course.sec'};
                   4594:         }   
1.359     albertel 4595: 	$realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378     raeburn  4596:     } else {
                   4597:         $role = &Apache::lonnet::plaintext($role);
1.54      www      4598:     }
1.433     albertel 4599: 
1.359     albertel 4600:     if (!$realm) { $realm='&nbsp;'; }
1.55      www      4601: # Set messages
1.60      matthew  4602:     my $messages=&domainlogo($domain);
1.330     albertel 4603: 
1.438     albertel 4604:     my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329     albertel 4605: 
1.101     www      4606: # construct main body tag
1.359     albertel 4607:     my $bodytag = "<body $extra_body_attr>".
1.562     albertel 4608: 	&Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252     albertel 4609: 
1.530     albertel 4610:     if ($bodyonly) {
1.60      matthew  4611:         return $bodytag;
1.798     tempelho 4612:     } 
1.359     albertel 4613: 
1.410     albertel 4614:     my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.954     raeburn  4615:     if ($public) {
1.433     albertel 4616: 	undef($role);
1.434     albertel 4617:     } else {
                   4618: 	$name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433     albertel 4619:     }
1.359     albertel 4620:     
1.762     bisitz   4621:     my $titleinfo = '<h1>'.$title.'</h1>';
1.359     albertel 4622:     #
                   4623:     # Extra info if you are the DC
                   4624:     my $dc_info = '';
                   4625:     if ($env{'user.adv'} && exists($env{'user.role.dc./'.
                   4626:                         $env{'course.'.$env{'request.course.id'}.
                   4627:                                  '.domain'}.'/'})) {
                   4628:         my $cid = $env{'request.course.id'};
1.917     raeburn  4629:         $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380     www      4630:         $dc_info =~ s/\s+$//;
1.359     albertel 4631:     }
                   4632: 
1.898     raeburn  4633:     $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.853     droeschl 4634:     &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
                   4635: 
1.916     droeschl 4636:         if ($no_nav_bar || $env{'form.inhibitmenu'} eq 'yes') { 
                   4637:             return $bodytag; 
                   4638:         } 
1.903     droeschl 4639: 
                   4640:         if ($env{'request.state'} eq 'construct') { $forcereg=1; }
                   4641: 
                   4642:         #    if ($env{'request.state'} eq 'construct') {
                   4643:         #        $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
                   4644:         #    }
                   4645: 
1.359     albertel 4646: 
                   4647: 
1.916     droeschl 4648:         if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.917     raeburn  4649:              if ($dc_info) {
                   4650:                  $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
                   4651:              }
1.916     droeschl 4652:              $bodytag .= qq|<div id="LC_nav_bar">$name $role<br />
                   4653:                 <em>$realm</em> $dc_info</div>|;
1.903     droeschl 4654:             return $bodytag;
                   4655:         }
1.894     droeschl 4656: 
1.927     raeburn  4657:         unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
                   4658:             $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>|;
                   4659:         }
1.916     droeschl 4660: 
1.903     droeschl 4661:         $bodytag .= Apache::lonhtmlcommon::scripttag(
                   4662:             Apache::lonmenu::utilityfunctions(), 'start');
1.816     bisitz   4663: 
1.903     droeschl 4664:         $bodytag .= Apache::lonmenu::primary_menu();
1.852     droeschl 4665: 
1.917     raeburn  4666:         if ($dc_info) {
                   4667:             $dc_info = &dc_courseid_toggle($dc_info);
                   4668:         }
                   4669:         $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916     droeschl 4670: 
1.903     droeschl 4671:         #don't show menus for public users
1.954     raeburn  4672:         if (!$public){
1.903     droeschl 4673:             $bodytag .= Apache::lonmenu::secondary_menu();
                   4674:             $bodytag .= Apache::lonmenu::serverform();
1.920     raeburn  4675:             $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
                   4676:             if ($env{'request.state'} eq 'construct') {
1.962     droeschl 4677:                 $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920     raeburn  4678:                                 $args->{'bread_crumbs'});
                   4679:             } elsif ($forcereg) { 
                   4680:                 $bodytag .= &Apache::lonmenu::innerregister($forcereg);
                   4681:             }
1.903     droeschl 4682:         }else{
                   4683:             # this is to seperate menu from content when there's no secondary
                   4684:             # menu. Especially needed for public accessible ressources.
                   4685:             $bodytag .= '<hr style="clear:both" />';
                   4686:             $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end'); 
1.235     raeburn  4687:         }
1.903     droeschl 4688: 
1.235     raeburn  4689:         return $bodytag;
1.182     matthew  4690: }
                   4691: 
1.917     raeburn  4692: sub dc_courseid_toggle {
                   4693:     my ($dc_info) = @_;
                   4694:     return ' <span id="dccidtext" class="LC_cusr_subheading">'.
                   4695:            '<a href="javascript:showCourseID();">'.
                   4696:            &mt('(More ...)').'</a></span>'.
                   4697:            '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
                   4698: }
                   4699: 
1.330     albertel 4700: sub make_attr_string {
                   4701:     my ($register,$attr_ref) = @_;
                   4702: 
                   4703:     if ($attr_ref && !ref($attr_ref)) {
                   4704: 	die("addentries Must be a hash ref ".
                   4705: 	    join(':',caller(1))." ".
                   4706: 	    join(':',caller(0))." ");
                   4707:     }
                   4708: 
                   4709:     if ($register) {
1.339     albertel 4710: 	my ($on_load,$on_unload);
                   4711: 	foreach my $key (keys(%{$attr_ref})) {
                   4712: 	    if      (lc($key) eq 'onload') {
                   4713: 		$on_load.=$attr_ref->{$key}.';';
                   4714: 		delete($attr_ref->{$key});
                   4715: 
                   4716: 	    } elsif (lc($key) eq 'onunload') {
                   4717: 		$on_unload.=$attr_ref->{$key}.';';
                   4718: 		delete($attr_ref->{$key});
                   4719: 	    }
                   4720: 	}
1.953     droeschl 4721: 	$attr_ref->{'onload'}  = $on_load;
                   4722: 	$attr_ref->{'onunload'}= $on_unload;
1.330     albertel 4723:     }
1.339     albertel 4724: 
1.330     albertel 4725:     my $attr_string;
                   4726:     foreach my $attr (keys(%$attr_ref)) {
                   4727: 	$attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
                   4728:     }
                   4729:     return $attr_string;
                   4730: }
                   4731: 
                   4732: 
1.182     matthew  4733: ###############################################
1.251     albertel 4734: ###############################################
                   4735: 
                   4736: =pod
                   4737: 
                   4738: =item * &endbodytag()
                   4739: 
                   4740: Returns a uniform footer for LON-CAPA web pages.
                   4741: 
1.635     raeburn  4742: Inputs: 1 - optional reference to an args hash
                   4743: If in the hash, key for noredirectlink has a value which evaluates to true,
                   4744: a 'Continue' link is not displayed if the page contains an
                   4745: internal redirect in the <head></head> section,
                   4746: i.e., $env{'internal.head.redirect'} exists   
1.251     albertel 4747: 
                   4748: =cut
                   4749: 
                   4750: sub endbodytag {
1.635     raeburn  4751:     my ($args) = @_;
1.251     albertel 4752:     my $endbodytag='</body>';
1.269     albertel 4753:     $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315     albertel 4754:     if ( exists( $env{'internal.head.redirect'} ) ) {
1.635     raeburn  4755:         if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
                   4756: 	    $endbodytag=
                   4757: 	        "<br /><a href=\"$env{'internal.head.redirect'}\">".
                   4758: 	        &mt('Continue').'</a>'.
                   4759: 	        $endbodytag;
                   4760:         }
1.315     albertel 4761:     }
1.251     albertel 4762:     return $endbodytag;
                   4763: }
                   4764: 
1.352     albertel 4765: =pod
                   4766: 
                   4767: =item * &standard_css()
                   4768: 
                   4769: Returns a style sheet
                   4770: 
                   4771: Inputs: (all optional)
                   4772:             domain         -> force to color decorate a page for a specific
                   4773:                                domain
                   4774:             function       -> force usage of a specific rolish color scheme
                   4775:             bgcolor        -> override the default page bgcolor
                   4776: 
                   4777: =cut
                   4778: 
1.343     albertel 4779: sub standard_css {
1.345     albertel 4780:     my ($function,$domain,$bgcolor) = @_;
1.352     albertel 4781:     $function  = &get_users_function() if (!$function);
                   4782:     my $img    = &designparm($function.'.img',   $domain);
                   4783:     my $tabbg  = &designparm($function.'.tabbg', $domain);
                   4784:     my $font   = &designparm($function.'.font',  $domain);
1.801     tempelho 4785:     my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791     tempelho 4786: #second colour for later usage
1.345     albertel 4787:     my $sidebg = &designparm($function.'.sidebg',$domain);
1.382     albertel 4788:     my $pgbg_or_bgcolor =
                   4789: 	         $bgcolor ||
1.352     albertel 4790: 	         &designparm($function.'.pgbg',  $domain);
1.382     albertel 4791:     my $pgbg   = &designparm($function.'.pgbg',  $domain);
1.352     albertel 4792:     my $alink  = &designparm($function.'.alink', $domain);
                   4793:     my $vlink  = &designparm($function.'.vlink', $domain);
                   4794:     my $link   = &designparm($function.'.link',  $domain);
                   4795: 
1.704     muellerd 4796:     my $loginbg = &designparm('login.sidebg',$domain);
1.712     muellerd 4797:     my $bgcol = &designparm('login.bgcol',$domain);
                   4798:     my $textcol = &designparm('login.textcol',$domain);
1.704     muellerd 4799: 
1.602     albertel 4800:     my $sans                 = 'Verdana,Arial,Helvetica,sans-serif';
1.395     albertel 4801:     my $mono                 = 'monospace';
1.850     bisitz   4802:     my $data_table_head      = $sidebg;
                   4803:     my $data_table_light     = '#FAFAFA';
                   4804:     my $data_table_dark      = '#F0F0F0';
1.470     banghart 4805:     my $data_table_darker    = '#CCCCCC';
1.349     albertel 4806:     my $data_table_highlight = '#FFFF00';
1.352     albertel 4807:     my $mail_new             = '#FFBB77';
                   4808:     my $mail_new_hover       = '#DD9955';
                   4809:     my $mail_read            = '#BBBB77';
                   4810:     my $mail_read_hover      = '#999944';
                   4811:     my $mail_replied         = '#AAAA88';
                   4812:     my $mail_replied_hover   = '#888855';
                   4813:     my $mail_other           = '#99BBBB';
                   4814:     my $mail_other_hover     = '#669999';
1.391     albertel 4815:     my $table_header         = '#DDDDDD';
1.489     raeburn  4816:     my $feedback_link_bg     = '#BBBBBB';
1.911     bisitz   4817:     my $lg_border_color      = '#C8C8C8';
1.952     onken    4818:     my $button_hover         = '#BF2317';
1.392     albertel 4819: 
1.608     albertel 4820:     my $border = ($env{'browser.type'} eq 'explorer' ||
1.911     bisitz   4821:       $env{'browser.type'} eq 'safari'     ) ? '0 2px 0 2px'
                   4822:                                              : '0 3px 0 4px';
1.448     albertel 4823: 
1.523     albertel 4824: 
1.343     albertel 4825:     return <<END;
1.947     droeschl 4826: 
                   4827: /* needed for iframe to allow 100% height in FF */
                   4828: body, html { 
                   4829:     margin: 0;
                   4830:     padding: 0 0.5%;
                   4831:     height: 99%; /* to avoid scrollbars */
                   4832: }
                   4833: 
1.795     www      4834: body {
1.911     bisitz   4835:   font-family: $sans;
                   4836:   line-height:130%;
                   4837:   font-size:0.83em;
                   4838:   color:$font;
1.795     www      4839: }
                   4840: 
1.959     onken    4841: a:focus,
                   4842: a:focus img {
1.795     www      4843:   color: red;
1.911     bisitz   4844:   background: yellow;
1.795     www      4845: }
1.698     harmsja  4846: 
1.911     bisitz   4847: form, .inline {
                   4848:   display: inline;
1.795     www      4849: }
1.721     harmsja  4850: 
1.795     www      4851: .LC_right {
1.911     bisitz   4852:   text-align:right;
1.795     www      4853: }
                   4854: 
                   4855: .LC_middle {
1.911     bisitz   4856:   vertical-align:middle;
1.795     www      4857: }
1.721     harmsja  4858: 
1.911     bisitz   4859: .LC_400Box {
                   4860:   width:400px;
                   4861: }
1.721     harmsja  4862: 
1.947     droeschl 4863: .LC_iframecontainer {
                   4864:     width: 98%;
                   4865:     margin: 0;
                   4866:     position: fixed;
                   4867:     top: 8.5em;
                   4868:     bottom: 0;
                   4869: }
                   4870: 
                   4871: .LC_iframecontainer iframe{
                   4872:     border: none;
                   4873:     width: 100%;
                   4874:     height: 100%;
                   4875: }
                   4876: 
1.778     bisitz   4877: .LC_filename {
                   4878:   font-family: $mono;
                   4879:   white-space:pre;
1.921     bisitz   4880:   font-size: 120%;
1.778     bisitz   4881: }
                   4882: 
                   4883: .LC_fileicon {
                   4884:   border: none;
                   4885:   height: 1.3em;
                   4886:   vertical-align: text-bottom;
                   4887:   margin-right: 0.3em;
                   4888:   text-decoration:none;
                   4889: }
                   4890: 
1.350     albertel 4891: .LC_error {
                   4892:   color: red;
                   4893:   font-size: larger;
                   4894: }
1.795     www      4895: 
1.457     albertel 4896: .LC_warning,
                   4897: .LC_diff_removed {
1.733     bisitz   4898:   color: red;
1.394     albertel 4899: }
1.532     albertel 4900: 
                   4901: .LC_info,
1.457     albertel 4902: .LC_success,
                   4903: .LC_diff_added {
1.350     albertel 4904:   color: green;
                   4905: }
1.795     www      4906: 
1.802     bisitz   4907: div.LC_confirm_box {
                   4908:   background-color: #FAFAFA;
                   4909:   border: 1px solid $lg_border_color;
                   4910:   margin-right: 0;
                   4911:   padding: 5px;
                   4912: }
                   4913: 
                   4914: div.LC_confirm_box .LC_error img,
                   4915: div.LC_confirm_box .LC_success img {
                   4916:   vertical-align: middle;
                   4917: }
                   4918: 
1.440     albertel 4919: .LC_icon {
1.771     droeschl 4920:   border: none;
1.790     droeschl 4921:   vertical-align: middle;
1.771     droeschl 4922: }
                   4923: 
1.543     albertel 4924: .LC_docs_spacer {
                   4925:   width: 25px;
                   4926:   height: 1px;
1.771     droeschl 4927:   border: none;
1.543     albertel 4928: }
1.346     albertel 4929: 
1.532     albertel 4930: .LC_internal_info {
1.735     bisitz   4931:   color: #999999;
1.532     albertel 4932: }
                   4933: 
1.794     www      4934: .LC_discussion {
1.911     bisitz   4935:   background: $tabbg;
                   4936:   border: 1px solid black;
                   4937:   margin: 2px;
1.794     www      4938: }
                   4939: 
                   4940: .LC_disc_action_links_bar {
1.911     bisitz   4941:   background: $tabbg;
                   4942:   border: none;
                   4943:   margin: 4px;
1.794     www      4944: }
                   4945: 
                   4946: .LC_disc_action_left {
1.911     bisitz   4947:   text-align: left;
1.794     www      4948: }
                   4949: 
                   4950: .LC_disc_action_right {
1.911     bisitz   4951:   text-align: right;
1.794     www      4952: }
                   4953: 
                   4954: .LC_disc_new_item {
1.911     bisitz   4955:   background: white;
                   4956:   border: 2px solid red;
                   4957:   margin: 2px;
1.794     www      4958: }
                   4959: 
                   4960: .LC_disc_old_item {
1.911     bisitz   4961:   background: white;
                   4962:   border: 1px solid black;
                   4963:   margin: 2px;
1.794     www      4964: }
                   4965: 
1.458     albertel 4966: table.LC_pastsubmission {
                   4967:   border: 1px solid black;
                   4968:   margin: 2px;
                   4969: }
                   4970: 
1.924     bisitz   4971: table#LC_menubuttons {
1.345     albertel 4972:   width: 100%;
                   4973:   background: $pgbg;
1.392     albertel 4974:   border: 2px;
1.402     albertel 4975:   border-collapse: separate;
1.803     bisitz   4976:   padding: 0;
1.345     albertel 4977: }
1.392     albertel 4978: 
1.801     tempelho 4979: table#LC_title_bar a {
                   4980:   color: $fontmenu;
                   4981: }
1.836     bisitz   4982: 
1.807     droeschl 4983: table#LC_title_bar {
1.819     tempelho 4984:   clear: both;
1.836     bisitz   4985:   display: none;
1.807     droeschl 4986: }
                   4987: 
1.795     www      4988: table#LC_title_bar,
1.933     droeschl 4989: table.LC_breadcrumbs, /* obsolete? */
1.393     albertel 4990: table#LC_title_bar.LC_with_remote {
1.359     albertel 4991:   width: 100%;
1.392     albertel 4992:   border-color: $pgbg;
                   4993:   border-style: solid;
                   4994:   border-width: $border;
1.379     albertel 4995:   background: $pgbg;
1.801     tempelho 4996:   color: $fontmenu;
1.392     albertel 4997:   border-collapse: collapse;
1.803     bisitz   4998:   padding: 0;
1.819     tempelho 4999:   margin: 0;
1.359     albertel 5000: }
1.795     www      5001: 
1.933     droeschl 5002: ul.LC_breadcrumb_tools_outerlist {
1.913     droeschl 5003:     margin: 0;
                   5004:     padding: 0;
1.933     droeschl 5005:     position: relative;
                   5006:     list-style: none;
1.913     droeschl 5007: }
1.933     droeschl 5008: ul.LC_breadcrumb_tools_outerlist li {
1.913     droeschl 5009:     display: inline;
                   5010: }
1.933     droeschl 5011: 
                   5012: .LC_breadcrumb_tools_navigation {
1.913     droeschl 5013:     padding: 0;
1.933     droeschl 5014:     margin: 0;
                   5015:     float: left;
1.913     droeschl 5016: }
1.933     droeschl 5017: .LC_breadcrumb_tools_tools {
                   5018:     padding: 0;
                   5019:     margin: 0;
1.913     droeschl 5020:     float: right;
                   5021: }
                   5022: 
1.359     albertel 5023: table#LC_title_bar td {
                   5024:   background: $tabbg;
                   5025: }
1.795     www      5026: 
1.911     bisitz   5027: table#LC_menubuttons img {
1.803     bisitz   5028:   border: none;
1.346     albertel 5029: }
1.795     www      5030: 
1.842     droeschl 5031: .LC_breadcrumbs_component {
1.911     bisitz   5032:   float: right;
                   5033:   margin: 0 1em;
1.357     albertel 5034: }
1.842     droeschl 5035: .LC_breadcrumbs_component img {
1.911     bisitz   5036:   vertical-align: middle;
1.777     tempelho 5037: }
1.795     www      5038: 
1.383     albertel 5039: td.LC_table_cell_checkbox {
                   5040:   text-align: center;
                   5041: }
1.795     www      5042: 
                   5043: .LC_fontsize_small {
1.911     bisitz   5044:   font-size: 70%;
1.705     tempelho 5045: }
                   5046: 
1.844     bisitz   5047: #LC_breadcrumbs {
1.911     bisitz   5048:   clear:both;
                   5049:   background: $sidebg;
                   5050:   border-bottom: 1px solid $lg_border_color;
                   5051:   line-height: 2.5em;
1.933     droeschl 5052:   overflow: hidden;
1.911     bisitz   5053:   margin: 0;
                   5054:   padding: 0;
1.819     tempelho 5055: }
1.862     bisitz   5056: 
1.844     bisitz   5057: #LC_head_subbox {
1.911     bisitz   5058:   clear:both;
                   5059:   background: #F8F8F8; /* $sidebg; */
1.915     droeschl 5060:   border: 1px solid $sidebg;
                   5061:   margin: 0 0 10px 0;      
1.822     bisitz   5062: }
                   5063: 
1.795     www      5064: .LC_fontsize_medium {
1.911     bisitz   5065:   font-size: 85%;
1.705     tempelho 5066: }
                   5067: 
1.795     www      5068: .LC_fontsize_large {
1.911     bisitz   5069:   font-size: 120%;
1.705     tempelho 5070: }
                   5071: 
1.346     albertel 5072: .LC_menubuttons_inline_text {
                   5073:   color: $font;
1.698     harmsja  5074:   font-size: 90%;
1.701     harmsja  5075:   padding-left:3px;
1.346     albertel 5076: }
                   5077: 
1.934     droeschl 5078: .LC_menubuttons_inline_text img{
                   5079:   vertical-align: middle;
                   5080: }
                   5081: 
1.951     onken    5082: li.LC_menubuttons_inline_text img,a {
                   5083:   cursor:pointer;
                   5084: }
                   5085: 
1.526     www      5086: .LC_menubuttons_link {
                   5087:   text-decoration: none;
                   5088: }
1.795     www      5089: 
1.522     albertel 5090: .LC_menubuttons_category {
1.521     www      5091:   color: $font;
1.526     www      5092:   background: $pgbg;
1.521     www      5093:   font-size: larger;
                   5094:   font-weight: bold;
                   5095: }
                   5096: 
1.346     albertel 5097: td.LC_menubuttons_text {
1.911     bisitz   5098:   color: $font;
1.346     albertel 5099: }
1.706     harmsja  5100: 
1.346     albertel 5101: .LC_current_location {
                   5102:   background: $tabbg;
                   5103: }
1.795     www      5104: 
1.938     bisitz   5105: table.LC_data_table {
1.347     albertel 5106:   border: 1px solid #000000;
1.402     albertel 5107:   border-collapse: separate;
1.426     albertel 5108:   border-spacing: 1px;
1.610     albertel 5109:   background: $pgbg;
1.347     albertel 5110: }
1.795     www      5111: 
1.422     albertel 5112: .LC_data_table_dense {
                   5113:   font-size: small;
                   5114: }
1.795     www      5115: 
1.507     raeburn  5116: table.LC_nested_outer {
                   5117:   border: 1px solid #000000;
1.589     raeburn  5118:   border-collapse: collapse;
1.803     bisitz   5119:   border-spacing: 0;
1.507     raeburn  5120:   width: 100%;
                   5121: }
1.795     www      5122: 
1.879     raeburn  5123: table.LC_innerpickbox,
1.507     raeburn  5124: table.LC_nested {
1.803     bisitz   5125:   border: none;
1.589     raeburn  5126:   border-collapse: collapse;
1.803     bisitz   5127:   border-spacing: 0;
1.507     raeburn  5128:   width: 100%;
                   5129: }
1.795     www      5130: 
1.930     faziophi 5131: .ui-accordion,
                   5132: .ui-accordion table.LC_data_table,
                   5133: .ui-accordion table.LC_nested_outer{
                   5134:   border: 0px;
                   5135:   border-spacing: 0px;
                   5136:   margin: 3px;
                   5137: }
                   5138: 
1.911     bisitz   5139: table.LC_data_table tr th,
                   5140: table.LC_calendar tr th,
1.879     raeburn  5141: table.LC_prior_tries tr th,
                   5142: table.LC_innerpickbox tr th {
1.349     albertel 5143:   font-weight: bold;
                   5144:   background-color: $data_table_head;
1.801     tempelho 5145:   color:$fontmenu;
1.701     harmsja  5146:   font-size:90%;
1.347     albertel 5147: }
1.795     www      5148: 
1.879     raeburn  5149: table.LC_innerpickbox tr th,
                   5150: table.LC_innerpickbox tr td {
                   5151:   vertical-align: top;
                   5152: }
                   5153: 
1.711     raeburn  5154: table.LC_data_table tr.LC_info_row > td {
1.735     bisitz   5155:   background-color: #CCCCCC;
1.711     raeburn  5156:   font-weight: bold;
                   5157:   text-align: left;
                   5158: }
1.795     www      5159: 
1.912     bisitz   5160: table.LC_data_table tr.LC_odd_row > td {
                   5161:   background-color: $data_table_light;
                   5162:   padding: 2px;
                   5163:   vertical-align: top;
                   5164: }
                   5165: 
1.809     bisitz   5166: table.LC_pick_box tr > td.LC_odd_row {
1.349     albertel 5167:   background-color: $data_table_light;
1.912     bisitz   5168:   vertical-align: top;
                   5169: }
                   5170: 
                   5171: table.LC_data_table tr.LC_even_row > td {
                   5172:   background-color: $data_table_dark;
1.425     albertel 5173:   padding: 2px;
1.900     bisitz   5174:   vertical-align: top;
1.347     albertel 5175: }
1.795     www      5176: 
1.809     bisitz   5177: table.LC_pick_box tr > td.LC_even_row {
1.349     albertel 5178:   background-color: $data_table_dark;
1.900     bisitz   5179:   vertical-align: top;
1.347     albertel 5180: }
1.795     www      5181: 
1.425     albertel 5182: table.LC_data_table tr.LC_data_table_highlight td {
                   5183:   background-color: $data_table_darker;
                   5184: }
1.795     www      5185: 
1.639     raeburn  5186: table.LC_data_table tr td.LC_leftcol_header {
                   5187:   background-color: $data_table_head;
                   5188:   font-weight: bold;
                   5189: }
1.795     www      5190: 
1.451     albertel 5191: table.LC_data_table tr.LC_empty_row td,
1.507     raeburn  5192: table.LC_nested tr.LC_empty_row td {
1.421     albertel 5193:   font-weight: bold;
                   5194:   font-style: italic;
                   5195:   text-align: center;
                   5196:   padding: 8px;
1.347     albertel 5197: }
1.795     www      5198: 
1.940     bisitz   5199: table.LC_data_table tr.LC_empty_row td {
                   5200:   background-color: $sidebg;
                   5201: }
                   5202: 
                   5203: table.LC_nested tr.LC_empty_row td {
                   5204:   background-color: #FFFFFF;
                   5205: }
                   5206: 
1.890     droeschl 5207: table.LC_caption {
                   5208: }
                   5209: 
1.507     raeburn  5210: table.LC_nested tr.LC_empty_row td {
1.465     albertel 5211:   padding: 4ex
                   5212: }
1.795     www      5213: 
1.507     raeburn  5214: table.LC_nested_outer tr th {
                   5215:   font-weight: bold;
1.801     tempelho 5216:   color:$fontmenu;
1.507     raeburn  5217:   background-color: $data_table_head;
1.701     harmsja  5218:   font-size: small;
1.507     raeburn  5219:   border-bottom: 1px solid #000000;
                   5220: }
1.795     www      5221: 
1.507     raeburn  5222: table.LC_nested_outer tr td.LC_subheader {
                   5223:   background-color: $data_table_head;
                   5224:   font-weight: bold;
                   5225:   font-size: small;
                   5226:   border-bottom: 1px solid #000000;
                   5227:   text-align: right;
1.451     albertel 5228: }
1.795     www      5229: 
1.507     raeburn  5230: table.LC_nested tr.LC_info_row td {
1.735     bisitz   5231:   background-color: #CCCCCC;
1.451     albertel 5232:   font-weight: bold;
                   5233:   font-size: small;
1.507     raeburn  5234:   text-align: center;
                   5235: }
1.795     www      5236: 
1.589     raeburn  5237: table.LC_nested tr.LC_info_row td.LC_left_item,
                   5238: table.LC_nested_outer tr th.LC_left_item {
1.507     raeburn  5239:   text-align: left;
1.451     albertel 5240: }
1.795     www      5241: 
1.507     raeburn  5242: table.LC_nested td {
1.735     bisitz   5243:   background-color: #FFFFFF;
1.451     albertel 5244:   font-size: small;
1.507     raeburn  5245: }
1.795     www      5246: 
1.507     raeburn  5247: table.LC_nested_outer tr th.LC_right_item,
                   5248: table.LC_nested tr.LC_info_row td.LC_right_item,
                   5249: table.LC_nested tr.LC_odd_row td.LC_right_item,
                   5250: table.LC_nested tr td.LC_right_item {
1.451     albertel 5251:   text-align: right;
                   5252: }
                   5253: 
1.930     faziophi 5254: .ui-accordion table.LC_nested tr.LC_odd_row td.LC_left_item,
                   5255: .ui-accordion table.LC_nested tr.LC_even_row td.LC_left_item {
                   5256:   text-align: right;
                   5257:   width: 40%;
                   5258:   padding-right:10px;
                   5259:   vertical-align: top;
                   5260:   padding: 5px;
                   5261: }
                   5262: 
                   5263: .ui-accordion table.LC_nested tr.LC_odd_row td.LC_right_item,
                   5264: .ui-accordion table.LC_nested tr.LC_even_row td.LC_right_item {
                   5265:   text-align: left;
                   5266:   width: 60%;
                   5267:   padding: 2px 4px;
                   5268: }
                   5269: 
1.507     raeburn  5270: table.LC_nested tr.LC_odd_row td {
1.735     bisitz   5271:   background-color: #EEEEEE;
1.451     albertel 5272: }
                   5273: 
1.473     raeburn  5274: table.LC_createuser {
                   5275: }
                   5276: 
                   5277: table.LC_createuser tr.LC_section_row td {
1.701     harmsja  5278:   font-size: small;
1.473     raeburn  5279: }
                   5280: 
                   5281: table.LC_createuser tr.LC_info_row td  {
1.735     bisitz   5282:   background-color: #CCCCCC;
1.473     raeburn  5283:   font-weight: bold;
                   5284:   text-align: center;
                   5285: }
                   5286: 
1.349     albertel 5287: table.LC_calendar {
                   5288:   border: 1px solid #000000;
                   5289:   border-collapse: collapse;
1.917     raeburn  5290:   width: 98%;
1.349     albertel 5291: }
1.795     www      5292: 
1.349     albertel 5293: table.LC_calendar_pickdate {
                   5294:   font-size: xx-small;
                   5295: }
1.795     www      5296: 
1.349     albertel 5297: table.LC_calendar tr td {
                   5298:   border: 1px solid #000000;
                   5299:   vertical-align: top;
1.917     raeburn  5300:   width: 14%;
1.349     albertel 5301: }
1.795     www      5302: 
1.349     albertel 5303: table.LC_calendar tr td.LC_calendar_day_empty {
                   5304:   background-color: $data_table_dark;
                   5305: }
1.795     www      5306: 
1.779     bisitz   5307: table.LC_calendar tr td.LC_calendar_day_current {
                   5308:   background-color: $data_table_highlight;
1.777     tempelho 5309: }
1.795     www      5310: 
1.938     bisitz   5311: table.LC_data_table tr td.LC_mail_new {
1.349     albertel 5312:   background-color: $mail_new;
                   5313: }
1.795     www      5314: 
1.938     bisitz   5315: table.LC_data_table tr.LC_mail_new:hover {
1.349     albertel 5316:   background-color: $mail_new_hover;
                   5317: }
1.795     www      5318: 
1.938     bisitz   5319: table.LC_data_table tr td.LC_mail_read {
1.349     albertel 5320:   background-color: $mail_read;
                   5321: }
1.795     www      5322: 
1.938     bisitz   5323: /*
                   5324: table.LC_data_table tr.LC_mail_read:hover {
1.349     albertel 5325:   background-color: $mail_read_hover;
                   5326: }
1.938     bisitz   5327: */
1.795     www      5328: 
1.938     bisitz   5329: table.LC_data_table tr td.LC_mail_replied {
1.349     albertel 5330:   background-color: $mail_replied;
                   5331: }
1.795     www      5332: 
1.938     bisitz   5333: /*
                   5334: table.LC_data_table tr.LC_mail_replied:hover {
1.349     albertel 5335:   background-color: $mail_replied_hover;
                   5336: }
1.938     bisitz   5337: */
1.795     www      5338: 
1.938     bisitz   5339: table.LC_data_table tr td.LC_mail_other {
1.349     albertel 5340:   background-color: $mail_other;
                   5341: }
1.795     www      5342: 
1.938     bisitz   5343: /*
                   5344: table.LC_data_table tr.LC_mail_other:hover {
1.349     albertel 5345:   background-color: $mail_other_hover;
                   5346: }
1.938     bisitz   5347: */
1.494     raeburn  5348: 
1.777     tempelho 5349: table.LC_data_table tr > td.LC_browser_file,
                   5350: table.LC_data_table tr > td.LC_browser_file_published {
1.899     bisitz   5351:   background: #AAEE77;
1.389     albertel 5352: }
1.795     www      5353: 
1.777     tempelho 5354: table.LC_data_table tr > td.LC_browser_file_locked,
                   5355: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389     albertel 5356:   background: #FFAA99;
1.387     albertel 5357: }
1.795     www      5358: 
1.777     tempelho 5359: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899     bisitz   5360:   background: #888888;
1.779     bisitz   5361: }
1.795     www      5362: 
1.777     tempelho 5363: table.LC_data_table tr > td.LC_browser_file_modified,
1.779     bisitz   5364: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899     bisitz   5365:   background: #F8F866;
1.777     tempelho 5366: }
1.795     www      5367: 
1.696     bisitz   5368: table.LC_data_table tr.LC_browser_folder > td {
1.899     bisitz   5369:   background: #E0E8FF;
1.387     albertel 5370: }
1.696     bisitz   5371: 
1.707     bisitz   5372: table.LC_data_table tr > td.LC_roles_is {
1.911     bisitz   5373:   /* background: #77FF77; */
1.707     bisitz   5374: }
1.795     www      5375: 
1.707     bisitz   5376: table.LC_data_table tr > td.LC_roles_future {
1.939     bisitz   5377:   border-right: 8px solid #FFFF77;
1.707     bisitz   5378: }
1.795     www      5379: 
1.707     bisitz   5380: table.LC_data_table tr > td.LC_roles_will {
1.939     bisitz   5381:   border-right: 8px solid #FFAA77;
1.707     bisitz   5382: }
1.795     www      5383: 
1.707     bisitz   5384: table.LC_data_table tr > td.LC_roles_expired {
1.939     bisitz   5385:   border-right: 8px solid #FF7777;
1.707     bisitz   5386: }
1.795     www      5387: 
1.707     bisitz   5388: table.LC_data_table tr > td.LC_roles_will_not {
1.939     bisitz   5389:   border-right: 8px solid #AAFF77;
1.707     bisitz   5390: }
1.795     www      5391: 
1.707     bisitz   5392: table.LC_data_table tr > td.LC_roles_selected {
1.939     bisitz   5393:   border-right: 8px solid #11CC55;
1.707     bisitz   5394: }
                   5395: 
1.388     albertel 5396: span.LC_current_location {
1.701     harmsja  5397:   font-size:larger;
1.388     albertel 5398:   background: $pgbg;
                   5399: }
1.387     albertel 5400: 
1.395     albertel 5401: span.LC_parm_menu_item {
                   5402:   font-size: larger;
                   5403: }
1.795     www      5404: 
1.395     albertel 5405: span.LC_parm_scope_all {
                   5406:   color: red;
                   5407: }
1.795     www      5408: 
1.395     albertel 5409: span.LC_parm_scope_folder {
                   5410:   color: green;
                   5411: }
1.795     www      5412: 
1.395     albertel 5413: span.LC_parm_scope_resource {
                   5414:   color: orange;
                   5415: }
1.795     www      5416: 
1.395     albertel 5417: span.LC_parm_part {
                   5418:   color: blue;
                   5419: }
1.795     www      5420: 
1.911     bisitz   5421: span.LC_parm_folder,
                   5422: span.LC_parm_symb {
1.395     albertel 5423:   font-size: x-small;
                   5424:   font-family: $mono;
                   5425:   color: #AAAAAA;
                   5426: }
                   5427: 
1.795     www      5428: td.LC_parm_overview_level_menu,
                   5429: td.LC_parm_overview_map_menu,
                   5430: td.LC_parm_overview_parm_selectors,
                   5431: td.LC_parm_overview_restrictions  {
1.396     albertel 5432:   border: 1px solid black;
                   5433:   border-collapse: collapse;
                   5434: }
1.795     www      5435: 
1.396     albertel 5436: table.LC_parm_overview_restrictions td {
                   5437:   border-width: 1px 4px 1px 4px;
                   5438:   border-style: solid;
                   5439:   border-color: $pgbg;
                   5440:   text-align: center;
                   5441: }
1.795     www      5442: 
1.396     albertel 5443: table.LC_parm_overview_restrictions th {
                   5444:   background: $tabbg;
                   5445:   border-width: 1px 4px 1px 4px;
                   5446:   border-style: solid;
                   5447:   border-color: $pgbg;
                   5448: }
1.795     www      5449: 
1.398     albertel 5450: table#LC_helpmenu {
1.803     bisitz   5451:   border: none;
1.398     albertel 5452:   height: 55px;
1.803     bisitz   5453:   border-spacing: 0;
1.398     albertel 5454: }
                   5455: 
                   5456: table#LC_helpmenu fieldset legend {
                   5457:   font-size: larger;
                   5458: }
1.795     www      5459: 
1.397     albertel 5460: table#LC_helpmenu_links {
                   5461:   width: 100%;
                   5462:   border: 1px solid black;
                   5463:   background: $pgbg;
1.803     bisitz   5464:   padding: 0;
1.397     albertel 5465:   border-spacing: 1px;
                   5466: }
1.795     www      5467: 
1.397     albertel 5468: table#LC_helpmenu_links tr td {
                   5469:   padding: 1px;
                   5470:   background: $tabbg;
1.399     albertel 5471:   text-align: center;
                   5472:   font-weight: bold;
1.397     albertel 5473: }
1.396     albertel 5474: 
1.795     www      5475: table#LC_helpmenu_links a:link,
                   5476: table#LC_helpmenu_links a:visited,
1.397     albertel 5477: table#LC_helpmenu_links a:active {
                   5478:   text-decoration: none;
                   5479:   color: $font;
                   5480: }
1.795     www      5481: 
1.397     albertel 5482: table#LC_helpmenu_links a:hover {
                   5483:   text-decoration: underline;
                   5484:   color: $vlink;
                   5485: }
1.396     albertel 5486: 
1.417     albertel 5487: .LC_chrt_popup_exists {
                   5488:   border: 1px solid #339933;
                   5489:   margin: -1px;
                   5490: }
1.795     www      5491: 
1.417     albertel 5492: .LC_chrt_popup_up {
                   5493:   border: 1px solid yellow;
                   5494:   margin: -1px;
                   5495: }
1.795     www      5496: 
1.417     albertel 5497: .LC_chrt_popup {
                   5498:   border: 1px solid #8888FF;
                   5499:   background: #CCCCFF;
                   5500: }
1.795     www      5501: 
1.421     albertel 5502: table.LC_pick_box {
                   5503:   border-collapse: separate;
                   5504:   background: white;
                   5505:   border: 1px solid black;
                   5506:   border-spacing: 1px;
                   5507: }
1.795     www      5508: 
1.421     albertel 5509: table.LC_pick_box td.LC_pick_box_title {
1.850     bisitz   5510:   background: $sidebg;
1.421     albertel 5511:   font-weight: bold;
1.900     bisitz   5512:   text-align: left;
1.740     bisitz   5513:   vertical-align: top;
1.421     albertel 5514:   width: 184px;
                   5515:   padding: 8px;
                   5516: }
1.795     www      5517: 
1.579     raeburn  5518: table.LC_pick_box td.LC_pick_box_value {
                   5519:   text-align: left;
                   5520:   padding: 8px;
                   5521: }
1.795     www      5522: 
1.579     raeburn  5523: table.LC_pick_box td.LC_pick_box_select {
                   5524:   text-align: left;
                   5525:   padding: 8px;
                   5526: }
1.795     www      5527: 
1.424     albertel 5528: table.LC_pick_box td.LC_pick_box_separator {
1.803     bisitz   5529:   padding: 0;
1.421     albertel 5530:   height: 1px;
                   5531:   background: black;
                   5532: }
1.795     www      5533: 
1.421     albertel 5534: table.LC_pick_box td.LC_pick_box_submit {
                   5535:   text-align: right;
                   5536: }
1.795     www      5537: 
1.579     raeburn  5538: table.LC_pick_box td.LC_evenrow_value {
                   5539:   text-align: left;
                   5540:   padding: 8px;
                   5541:   background-color: $data_table_light;
                   5542: }
1.795     www      5543: 
1.579     raeburn  5544: table.LC_pick_box td.LC_oddrow_value {
                   5545:   text-align: left;
                   5546:   padding: 8px;
                   5547:   background-color: $data_table_light;
                   5548: }
1.795     www      5549: 
1.579     raeburn  5550: span.LC_helpform_receipt_cat {
                   5551:   font-weight: bold;
                   5552: }
1.795     www      5553: 
1.424     albertel 5554: table.LC_group_priv_box {
                   5555:   background: white;
                   5556:   border: 1px solid black;
                   5557:   border-spacing: 1px;
                   5558: }
1.795     www      5559: 
1.424     albertel 5560: table.LC_group_priv_box td.LC_pick_box_title {
                   5561:   background: $tabbg;
                   5562:   font-weight: bold;
                   5563:   text-align: right;
                   5564:   width: 184px;
                   5565: }
1.795     www      5566: 
1.424     albertel 5567: table.LC_group_priv_box td.LC_groups_fixed {
                   5568:   background: $data_table_light;
                   5569:   text-align: center;
                   5570: }
1.795     www      5571: 
1.424     albertel 5572: table.LC_group_priv_box td.LC_groups_optional {
                   5573:   background: $data_table_dark;
                   5574:   text-align: center;
                   5575: }
1.795     www      5576: 
1.424     albertel 5577: table.LC_group_priv_box td.LC_groups_functionality {
                   5578:   background: $data_table_darker;
                   5579:   text-align: center;
                   5580:   font-weight: bold;
                   5581: }
1.795     www      5582: 
1.424     albertel 5583: table.LC_group_priv td {
                   5584:   text-align: left;
1.803     bisitz   5585:   padding: 0;
1.424     albertel 5586: }
                   5587: 
1.421     albertel 5588: table.LC_notify_front_page {
                   5589:   background: white;
                   5590:   border: 1px solid black;
                   5591:   padding: 8px;
                   5592: }
1.795     www      5593: 
1.421     albertel 5594: table.LC_notify_front_page td {
                   5595:   padding: 8px;
                   5596: }
1.795     www      5597: 
1.424     albertel 5598: .LC_navbuttons {
                   5599:   margin: 2ex 0ex 2ex 0ex;
                   5600: }
1.795     www      5601: 
1.423     albertel 5602: .LC_topic_bar {
                   5603:   font-weight: bold;
                   5604:   background: $tabbg;
1.918     wenzelju 5605:   margin: 1em 0em 1em 2em;
1.805     bisitz   5606:   padding: 3px;
1.918     wenzelju 5607:   font-size: 1.2em;
1.423     albertel 5608: }
1.795     www      5609: 
1.423     albertel 5610: .LC_topic_bar span {
1.918     wenzelju 5611:   left: 0.5em;
                   5612:   position: absolute;
1.423     albertel 5613:   vertical-align: middle;
1.918     wenzelju 5614:   font-size: 1.2em;
1.423     albertel 5615: }
1.795     www      5616: 
1.423     albertel 5617: table.LC_course_group_status {
                   5618:   margin: 20px;
                   5619: }
1.795     www      5620: 
1.423     albertel 5621: table.LC_status_selector td {
                   5622:   vertical-align: top;
                   5623:   text-align: center;
1.424     albertel 5624:   padding: 4px;
                   5625: }
1.795     www      5626: 
1.599     albertel 5627: div.LC_feedback_link {
1.616     albertel 5628:   clear: both;
1.829     kalberla 5629:   background: $sidebg;
1.779     bisitz   5630:   width: 100%;
1.829     kalberla 5631:   padding-bottom: 10px;
                   5632:   border: 1px $tabbg solid;
1.833     kalberla 5633:   height: 22px;
                   5634:   line-height: 22px;
                   5635:   padding-top: 5px;
                   5636: }
                   5637: 
                   5638: div.LC_feedback_link img {
                   5639:   height: 22px;
1.867     kalberla 5640:   vertical-align:middle;
1.829     kalberla 5641: }
                   5642: 
1.911     bisitz   5643: div.LC_feedback_link a {
1.829     kalberla 5644:   text-decoration: none;
1.489     raeburn  5645: }
1.795     www      5646: 
1.867     kalberla 5647: div.LC_comblock {
1.911     bisitz   5648:   display:inline;
1.867     kalberla 5649:   color:$font;
                   5650:   font-size:90%;
                   5651: }
                   5652: 
                   5653: div.LC_feedback_link div.LC_comblock {
                   5654:   padding-left:5px;
                   5655: }
                   5656: 
                   5657: div.LC_feedback_link div.LC_comblock a {
                   5658:   color:$font;
                   5659: }
                   5660: 
1.489     raeburn  5661: span.LC_feedback_link {
1.858     bisitz   5662:   /* background: $feedback_link_bg; */
1.599     albertel 5663:   font-size: larger;
                   5664: }
1.795     www      5665: 
1.599     albertel 5666: span.LC_message_link {
1.858     bisitz   5667:   /* background: $feedback_link_bg; */
1.599     albertel 5668:   font-size: larger;
                   5669:   position: absolute;
                   5670:   right: 1em;
1.489     raeburn  5671: }
1.421     albertel 5672: 
1.515     albertel 5673: table.LC_prior_tries {
1.524     albertel 5674:   border: 1px solid #000000;
                   5675:   border-collapse: separate;
                   5676:   border-spacing: 1px;
1.515     albertel 5677: }
1.523     albertel 5678: 
1.515     albertel 5679: table.LC_prior_tries td {
1.524     albertel 5680:   padding: 2px;
1.515     albertel 5681: }
1.523     albertel 5682: 
                   5683: .LC_answer_correct {
1.795     www      5684:   background: lightgreen;
                   5685:   color: darkgreen;
                   5686:   padding: 6px;
1.523     albertel 5687: }
1.795     www      5688: 
1.523     albertel 5689: .LC_answer_charged_try {
1.797     www      5690:   background: #FFAAAA;
1.795     www      5691:   color: darkred;
                   5692:   padding: 6px;
1.523     albertel 5693: }
1.795     www      5694: 
1.779     bisitz   5695: .LC_answer_not_charged_try,
1.523     albertel 5696: .LC_answer_no_grade,
                   5697: .LC_answer_late {
1.795     www      5698:   background: lightyellow;
1.523     albertel 5699:   color: black;
1.795     www      5700:   padding: 6px;
1.523     albertel 5701: }
1.795     www      5702: 
1.523     albertel 5703: .LC_answer_previous {
1.795     www      5704:   background: lightblue;
                   5705:   color: darkblue;
                   5706:   padding: 6px;
1.523     albertel 5707: }
1.795     www      5708: 
1.779     bisitz   5709: .LC_answer_no_message {
1.777     tempelho 5710:   background: #FFFFFF;
                   5711:   color: black;
1.795     www      5712:   padding: 6px;
1.779     bisitz   5713: }
1.795     www      5714: 
1.779     bisitz   5715: .LC_answer_unknown {
                   5716:   background: orange;
                   5717:   color: black;
1.795     www      5718:   padding: 6px;
1.777     tempelho 5719: }
1.795     www      5720: 
1.529     albertel 5721: span.LC_prior_numerical,
                   5722: span.LC_prior_string,
                   5723: span.LC_prior_custom,
                   5724: span.LC_prior_reaction,
                   5725: span.LC_prior_math {
1.925     bisitz   5726:   font-family: $mono;
1.523     albertel 5727:   white-space: pre;
                   5728: }
                   5729: 
1.525     albertel 5730: span.LC_prior_string {
1.925     bisitz   5731:   font-family: $mono;
1.525     albertel 5732:   white-space: pre;
                   5733: }
                   5734: 
1.523     albertel 5735: table.LC_prior_option {
                   5736:   width: 100%;
                   5737:   border-collapse: collapse;
                   5738: }
1.795     www      5739: 
1.911     bisitz   5740: table.LC_prior_rank,
1.795     www      5741: table.LC_prior_match {
1.528     albertel 5742:   border-collapse: collapse;
                   5743: }
1.795     www      5744: 
1.528     albertel 5745: table.LC_prior_option tr td,
                   5746: table.LC_prior_rank tr td,
                   5747: table.LC_prior_match tr td {
1.524     albertel 5748:   border: 1px solid #000000;
1.515     albertel 5749: }
                   5750: 
1.855     bisitz   5751: .LC_nobreak {
1.544     albertel 5752:   white-space: nowrap;
1.519     raeburn  5753: }
                   5754: 
1.576     raeburn  5755: span.LC_cusr_emph {
                   5756:   font-style: italic;
                   5757: }
                   5758: 
1.633     raeburn  5759: span.LC_cusr_subheading {
                   5760:   font-weight: normal;
                   5761:   font-size: 85%;
                   5762: }
                   5763: 
1.861     bisitz   5764: div.LC_docs_entry_move {
1.859     bisitz   5765:   border: 1px solid #BBBBBB;
1.545     albertel 5766:   background: #DDDDDD;
1.861     bisitz   5767:   width: 22px;
1.859     bisitz   5768:   padding: 1px;
                   5769:   margin: 0;
1.545     albertel 5770: }
                   5771: 
1.861     bisitz   5772: table.LC_data_table tr > td.LC_docs_entry_commands,
                   5773: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545     albertel 5774:   background: #DDDDDD;
                   5775:   font-size: x-small;
                   5776: }
1.795     www      5777: 
1.861     bisitz   5778: .LC_docs_entry_parameter {
                   5779:   white-space: nowrap;
                   5780: }
                   5781: 
1.544     albertel 5782: .LC_docs_copy {
1.545     albertel 5783:   color: #000099;
1.544     albertel 5784: }
1.795     www      5785: 
1.544     albertel 5786: .LC_docs_cut {
1.545     albertel 5787:   color: #550044;
1.544     albertel 5788: }
1.795     www      5789: 
1.544     albertel 5790: .LC_docs_rename {
1.545     albertel 5791:   color: #009900;
1.544     albertel 5792: }
1.795     www      5793: 
1.544     albertel 5794: .LC_docs_remove {
1.545     albertel 5795:   color: #990000;
                   5796: }
                   5797: 
1.547     albertel 5798: .LC_docs_reinit_warn,
                   5799: .LC_docs_ext_edit {
                   5800:   font-size: x-small;
                   5801: }
                   5802: 
1.545     albertel 5803: table.LC_docs_adddocs td,
                   5804: table.LC_docs_adddocs th {
                   5805:   border: 1px solid #BBBBBB;
                   5806:   padding: 4px;
                   5807:   background: #DDDDDD;
1.543     albertel 5808: }
                   5809: 
1.584     albertel 5810: table.LC_sty_begin {
                   5811:   background: #BBFFBB;
                   5812: }
1.795     www      5813: 
1.584     albertel 5814: table.LC_sty_end {
                   5815:   background: #FFBBBB;
                   5816: }
                   5817: 
1.589     raeburn  5818: table.LC_double_column {
1.803     bisitz   5819:   border-width: 0;
1.589     raeburn  5820:   border-collapse: collapse;
                   5821:   width: 100%;
                   5822:   padding: 2px;
                   5823: }
                   5824: 
                   5825: table.LC_double_column tr td.LC_left_col {
1.590     raeburn  5826:   top: 2px;
1.589     raeburn  5827:   left: 2px;
                   5828:   width: 47%;
                   5829:   vertical-align: top;
                   5830: }
                   5831: 
                   5832: table.LC_double_column tr td.LC_right_col {
                   5833:   top: 2px;
1.779     bisitz   5834:   right: 2px;
1.589     raeburn  5835:   width: 47%;
                   5836:   vertical-align: top;
                   5837: }
                   5838: 
1.591     raeburn  5839: div.LC_left_float {
                   5840:   float: left;
                   5841:   padding-right: 5%;
1.597     albertel 5842:   padding-bottom: 4px;
1.591     raeburn  5843: }
                   5844: 
                   5845: div.LC_clear_float_header {
1.597     albertel 5846:   padding-bottom: 2px;
1.591     raeburn  5847: }
                   5848: 
                   5849: div.LC_clear_float_footer {
1.597     albertel 5850:   padding-top: 10px;
1.591     raeburn  5851:   clear: both;
                   5852: }
                   5853: 
1.597     albertel 5854: div.LC_grade_show_user {
1.941     bisitz   5855: /*  border-left: 5px solid $sidebg; */
                   5856:   border-top: 5px solid #000000;
                   5857:   margin: 50px 0 0 0;
1.936     bisitz   5858:   padding: 15px 0 5px 10px;
1.597     albertel 5859: }
1.795     www      5860: 
1.936     bisitz   5861: div.LC_grade_show_user_odd_row {
1.941     bisitz   5862: /*  border-left: 5px solid #000000; */
                   5863: }
                   5864: 
                   5865: div.LC_grade_show_user div.LC_Box {
                   5866:   margin-right: 50px;
1.597     albertel 5867: }
                   5868: 
                   5869: div.LC_grade_submissions,
                   5870: div.LC_grade_message_center,
1.936     bisitz   5871: div.LC_grade_info_links {
1.597     albertel 5872:   margin: 5px;
                   5873:   width: 99%;
                   5874:   background: #FFFFFF;
                   5875: }
1.795     www      5876: 
1.597     albertel 5877: div.LC_grade_submissions_header,
1.936     bisitz   5878: div.LC_grade_message_center_header {
1.705     tempelho 5879:   font-weight: bold;
                   5880:   font-size: large;
1.597     albertel 5881: }
1.795     www      5882: 
1.597     albertel 5883: div.LC_grade_submissions_body,
1.936     bisitz   5884: div.LC_grade_message_center_body {
1.597     albertel 5885:   border: 1px solid black;
                   5886:   width: 99%;
                   5887:   background: #FFFFFF;
                   5888: }
1.795     www      5889: 
1.613     albertel 5890: table.LC_scantron_action {
                   5891:   width: 100%;
                   5892: }
1.795     www      5893: 
1.613     albertel 5894: table.LC_scantron_action tr th {
1.698     harmsja  5895:   font-weight:bold;
                   5896:   font-style:normal;
1.613     albertel 5897: }
1.795     www      5898: 
1.779     bisitz   5899: .LC_edit_problem_header,
1.614     albertel 5900: div.LC_edit_problem_footer {
1.705     tempelho 5901:   font-weight: normal;
                   5902:   font-size:  medium;
1.602     albertel 5903:   margin: 2px;
1.600     albertel 5904: }
1.795     www      5905: 
1.600     albertel 5906: div.LC_edit_problem_header,
1.602     albertel 5907: div.LC_edit_problem_header div,
1.614     albertel 5908: div.LC_edit_problem_footer,
                   5909: div.LC_edit_problem_footer div,
1.602     albertel 5910: div.LC_edit_problem_editxml_header,
                   5911: div.LC_edit_problem_editxml_header div {
1.600     albertel 5912:   margin-top: 5px;
                   5913: }
1.795     www      5914: 
1.600     albertel 5915: div.LC_edit_problem_header_title {
1.705     tempelho 5916:   font-weight: bold;
                   5917:   font-size: larger;
1.602     albertel 5918:   background: $tabbg;
                   5919:   padding: 3px;
                   5920: }
1.795     www      5921: 
1.602     albertel 5922: table.LC_edit_problem_header_title {
                   5923:   width: 100%;
1.600     albertel 5924:   background: $tabbg;
1.602     albertel 5925: }
                   5926: 
                   5927: div.LC_edit_problem_discards {
                   5928:   float: left;
                   5929:   padding-bottom: 5px;
                   5930: }
1.795     www      5931: 
1.602     albertel 5932: div.LC_edit_problem_saves {
                   5933:   float: right;
                   5934:   padding-bottom: 5px;
1.600     albertel 5935: }
1.795     www      5936: 
1.911     bisitz   5937: img.stift {
1.803     bisitz   5938:   border-width: 0;
                   5939:   vertical-align: middle;
1.677     riegler  5940: }
1.680     riegler  5941: 
1.923     bisitz   5942: table td.LC_mainmenu_col_fieldset {
1.680     riegler  5943:   vertical-align: top;
1.777     tempelho 5944: }
1.795     www      5945: 
1.716     raeburn  5946: div.LC_createcourse {
1.911     bisitz   5947:   margin: 10px 10px 10px 10px;
1.716     raeburn  5948: }
                   5949: 
1.917     raeburn  5950: .LC_dccid {
                   5951:   margin: 0.2em 0 0 0;
                   5952:   padding: 0;
                   5953:   font-size: 90%;
                   5954:   display:none;
                   5955: }
                   5956: 
1.698     harmsja  5957: a:hover,
1.897     wenzelju 5958: ol.LC_primary_menu a:hover,
1.721     harmsja  5959: ol#LC_MenuBreadcrumbs a:hover,
                   5960: ol#LC_PathBreadcrumbs a:hover,
1.897     wenzelju 5961: ul#LC_secondary_menu a:hover,
1.721     harmsja  5962: .LC_FormSectionClearButton input:hover
1.795     www      5963: ul.LC_TabContent   li:hover a {
1.952     onken    5964:   color:$button_hover;
1.911     bisitz   5965:   text-decoration:none;
1.693     droeschl 5966: }
                   5967: 
1.779     bisitz   5968: h1 {
1.911     bisitz   5969:   padding: 0;
                   5970:   line-height:130%;
1.693     droeschl 5971: }
1.698     harmsja  5972: 
1.911     bisitz   5973: h2,
                   5974: h3,
                   5975: h4,
                   5976: h5,
                   5977: h6 {
                   5978:   margin: 5px 0 5px 0;
                   5979:   padding: 0;
                   5980:   line-height:130%;
1.693     droeschl 5981: }
1.795     www      5982: 
                   5983: .LC_hcell {
1.911     bisitz   5984:   padding:3px 15px 3px 15px;
                   5985:   margin: 0;
                   5986:   background-color:$tabbg;
                   5987:   color:$fontmenu;
                   5988:   border-bottom:solid 1px $lg_border_color;
1.693     droeschl 5989: }
1.795     www      5990: 
1.840     bisitz   5991: .LC_Box > .LC_hcell {
1.911     bisitz   5992:   margin: 0 -10px 10px -10px;
1.835     bisitz   5993: }
                   5994: 
1.721     harmsja  5995: .LC_noBorder {
1.911     bisitz   5996:   border: 0;
1.698     harmsja  5997: }
1.693     droeschl 5998: 
1.721     harmsja  5999: .LC_FormSectionClearButton input {
1.911     bisitz   6000:   background-color:transparent;
                   6001:   border: none;
                   6002:   cursor:pointer;
                   6003:   text-decoration:underline;
1.693     droeschl 6004: }
1.763     bisitz   6005: 
                   6006: .LC_help_open_topic {
1.911     bisitz   6007:   color: #FFFFFF;
                   6008:   background-color: #EEEEFF;
                   6009:   margin: 1px;
                   6010:   padding: 4px;
                   6011:   border: 1px solid #000033;
                   6012:   white-space: nowrap;
                   6013:   /* vertical-align: middle; */
1.759     neumanie 6014: }
1.693     droeschl 6015: 
1.911     bisitz   6016: dl,
                   6017: ul,
                   6018: div,
                   6019: fieldset {
                   6020:   margin: 10px 10px 10px 0;
                   6021:   /* overflow: hidden; */
1.693     droeschl 6022: }
1.795     www      6023: 
1.838     bisitz   6024: fieldset > legend {
1.911     bisitz   6025:   font-weight: bold;
                   6026:   padding: 0 5px 0 5px;
1.838     bisitz   6027: }
                   6028: 
1.813     bisitz   6029: #LC_nav_bar {
1.911     bisitz   6030:   float: left;
1.934     droeschl 6031:   margin: 0;
1.807     droeschl 6032: }
                   6033: 
1.916     droeschl 6034: #LC_realm {
                   6035:   margin: 0.2em 0 0 0;
                   6036:   padding: 0;
                   6037:   font-weight: bold;
                   6038:   text-align: center;
                   6039: }
                   6040: 
1.911     bisitz   6041: #LC_nav_bar em {
                   6042:   font-weight: bold;
                   6043:   font-style: normal;
1.807     droeschl 6044: }
                   6045: 
1.897     wenzelju 6046: ol.LC_primary_menu {
1.911     bisitz   6047:   float: right;
1.934     droeschl 6048:   margin: 0;
1.807     droeschl 6049: }
                   6050: 
1.852     droeschl 6051: ol#LC_PathBreadcrumbs {
1.911     bisitz   6052:   margin: 0;
1.693     droeschl 6053: }
                   6054: 
1.897     wenzelju 6055: ol.LC_primary_menu li {
1.911     bisitz   6056:   display: inline;
                   6057:   padding: 5px 5px 0 10px;
                   6058:   vertical-align: top;
1.693     droeschl 6059: }
                   6060: 
1.897     wenzelju 6061: ol.LC_primary_menu li img {
1.911     bisitz   6062:   vertical-align: bottom;
1.934     droeschl 6063:   height: 1.1em;
1.693     droeschl 6064: }
                   6065: 
1.897     wenzelju 6066: ol.LC_primary_menu a {
1.911     bisitz   6067:   color: RGB(80, 80, 80);
                   6068:   text-decoration: none;
1.693     droeschl 6069: }
1.795     www      6070: 
1.949     droeschl 6071: ol.LC_primary_menu a.LC_new_message {
                   6072:   font-weight:bold;
                   6073:   color: darkred;
                   6074: }
                   6075: 
1.897     wenzelju 6076: ul#LC_secondary_menu {
1.911     bisitz   6077:   clear: both;
                   6078:   color: $fontmenu;
                   6079:   background: $tabbg;
                   6080:   list-style: none;
                   6081:   padding: 0;
                   6082:   margin: 0;
                   6083:   width: 100%;
1.808     droeschl 6084: }
                   6085: 
1.897     wenzelju 6086: ul#LC_secondary_menu li {
1.911     bisitz   6087:   font-weight: bold;
                   6088:   line-height: 1.8em;
                   6089:   padding: 0 0.8em;
                   6090:   border-right: 1px solid black;
                   6091:   display: inline;
                   6092:   vertical-align: middle;
1.807     droeschl 6093: }
                   6094: 
1.847     tempelho 6095: ul.LC_TabContent {
1.911     bisitz   6096:   display:block;
                   6097:   background: $sidebg;
                   6098:   border-bottom: solid 1px $lg_border_color;
                   6099:   list-style:none;
                   6100:   margin: 0 -10px;
                   6101:   padding: 0;
1.693     droeschl 6102: }
                   6103: 
1.795     www      6104: ul.LC_TabContent li,
                   6105: ul.LC_TabContentBigger li {
1.911     bisitz   6106:   float:left;
1.741     harmsja  6107: }
1.795     www      6108: 
1.897     wenzelju 6109: ul#LC_secondary_menu li a {
1.911     bisitz   6110:   color: $fontmenu;
                   6111:   text-decoration: none;
1.693     droeschl 6112: }
1.795     www      6113: 
1.721     harmsja  6114: ul.LC_TabContent {
1.952     onken    6115:   min-height:20px;
1.721     harmsja  6116: }
1.795     www      6117: 
                   6118: ul.LC_TabContent li {
1.911     bisitz   6119:   vertical-align:middle;
1.959     onken    6120:   padding: 0 16px 0 10px;
1.911     bisitz   6121:   background-color:$tabbg;
                   6122:   border-bottom:solid 1px $lg_border_color;
1.952     onken    6123:   border-right: solid 1px $font;
1.721     harmsja  6124: }
1.795     www      6125: 
1.847     tempelho 6126: ul.LC_TabContent .right {
1.911     bisitz   6127:   float:right;
1.847     tempelho 6128: }
                   6129: 
1.911     bisitz   6130: ul.LC_TabContent li a,
                   6131: ul.LC_TabContent li {
                   6132:   color:rgb(47,47,47);
                   6133:   text-decoration:none;
                   6134:   font-size:95%;
                   6135:   font-weight:bold;
1.952     onken    6136:   min-height:20px;
                   6137: }
                   6138: 
1.959     onken    6139: ul.LC_TabContent li a:hover,
                   6140: ul.LC_TabContent li a:focus {
1.952     onken    6141:   color: $button_hover;
1.959     onken    6142:   background:none;
                   6143:   outline:none;
1.952     onken    6144: }
                   6145: 
                   6146: ul.LC_TabContent li:hover {
                   6147:   color: $button_hover;
                   6148:   cursor:pointer;
1.721     harmsja  6149: }
1.795     www      6150: 
1.911     bisitz   6151: ul.LC_TabContent li.active {
1.952     onken    6152:   color: $font;
1.911     bisitz   6153:   background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952     onken    6154:   border-bottom:solid 1px #FFFFFF;
                   6155:   cursor: default;
1.744     ehlerst  6156: }
1.795     www      6157: 
1.959     onken    6158: ul.LC_TabContent li.active a {
                   6159:   color:$font;
                   6160:   background:#FFFFFF;
                   6161:   outline: none;
                   6162: }
1.870     tempelho 6163: #maincoursedoc {
1.911     bisitz   6164:   clear:both;
1.870     tempelho 6165: }
                   6166: 
                   6167: ul.LC_TabContentBigger {
1.911     bisitz   6168:   display:block;
                   6169:   list-style:none;
                   6170:   padding: 0;
1.870     tempelho 6171: }
                   6172: 
1.795     www      6173: ul.LC_TabContentBigger li {
1.911     bisitz   6174:   vertical-align:bottom;
                   6175:   height: 30px;
                   6176:   font-size:110%;
                   6177:   font-weight:bold;
                   6178:   color: #737373;
1.841     tempelho 6179: }
                   6180: 
1.957     onken    6181: ul.LC_TabContentBigger li.active {
                   6182:   position: relative;
                   6183:   top: 1px;
                   6184: }
                   6185: 
1.870     tempelho 6186: ul.LC_TabContentBigger li a {
1.911     bisitz   6187:   background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
                   6188:   height: 30px;
                   6189:   line-height: 30px;
                   6190:   text-align: center;
                   6191:   display: block;
                   6192:   text-decoration: none;
1.958     onken    6193:   outline: none;  
1.741     harmsja  6194: }
1.795     www      6195: 
1.870     tempelho 6196: ul.LC_TabContentBigger li.active a {
1.911     bisitz   6197:   background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
                   6198:   color:$font;
1.744     ehlerst  6199: }
1.795     www      6200: 
1.870     tempelho 6201: ul.LC_TabContentBigger li b {
1.911     bisitz   6202:   background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
                   6203:   display: block;
                   6204:   float: left;
                   6205:   padding: 0 30px;
1.957     onken    6206:   border-bottom: 1px solid $lg_border_color;
1.870     tempelho 6207: }
                   6208: 
1.956     onken    6209: ul.LC_TabContentBigger li:hover b {
                   6210:   color:$button_hover;
                   6211: }
                   6212: 
1.870     tempelho 6213: ul.LC_TabContentBigger li.active b {
1.911     bisitz   6214:   background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
                   6215:   color:$font;
1.957     onken    6216:   border: 0;
1.956     onken    6217:   cursor:default;
1.741     harmsja  6218: }
1.693     droeschl 6219: 
1.870     tempelho 6220: 
1.862     bisitz   6221: ul.LC_CourseBreadcrumbs {
                   6222:   background: $sidebg;
                   6223:   line-height: 32px;
                   6224:   padding-left: 10px;
                   6225:   margin: 0 0 10px 0;
                   6226:   list-style-position: inside;
                   6227: 
                   6228: }
                   6229: 
1.911     bisitz   6230: ol#LC_MenuBreadcrumbs,
1.862     bisitz   6231: ol#LC_PathBreadcrumbs {
1.911     bisitz   6232:   padding-left: 10px;
                   6233:   margin: 0;
1.933     droeschl 6234:   height: 2.5em;  /* equal to #LC_breadcrumbs line-height */
1.693     droeschl 6235: }
                   6236: 
1.911     bisitz   6237: ol#LC_MenuBreadcrumbs li,
                   6238: ol#LC_PathBreadcrumbs li,
1.862     bisitz   6239: ul.LC_CourseBreadcrumbs li {
1.911     bisitz   6240:   display: inline;
1.933     droeschl 6241:   white-space: normal;  
1.693     droeschl 6242: }
                   6243: 
1.823     bisitz   6244: ol#LC_MenuBreadcrumbs li a,
1.862     bisitz   6245: ul.LC_CourseBreadcrumbs li a {
1.911     bisitz   6246:   text-decoration: none;
                   6247:   font-size:90%;
1.693     droeschl 6248: }
1.795     www      6249: 
                   6250: ol#LC_PathBreadcrumbs li a {
1.911     bisitz   6251:   text-decoration:none;
                   6252:   font-size:100%;
                   6253:   font-weight:bold;
1.693     droeschl 6254: }
1.795     www      6255: 
1.840     bisitz   6256: .LC_Box {
1.911     bisitz   6257:   border: solid 1px $lg_border_color;
                   6258:   padding: 0 10px 10px 10px;
1.746     neumanie 6259: }
1.795     www      6260: 
                   6261: .LC_AboutMe_Image {
1.911     bisitz   6262:   float:left;
                   6263:   margin-right:10px;
1.747     neumanie 6264: }
1.795     www      6265: 
                   6266: .LC_Clear_AboutMe_Image {
1.911     bisitz   6267:   clear:left;
1.747     neumanie 6268: }
1.795     www      6269: 
1.721     harmsja  6270: dl.LC_ListStyleClean dt {
1.911     bisitz   6271:   padding-right: 5px;
                   6272:   display: table-header-group;
1.693     droeschl 6273: }
                   6274: 
1.721     harmsja  6275: dl.LC_ListStyleClean dd {
1.911     bisitz   6276:   display: table-row;
1.693     droeschl 6277: }
                   6278: 
1.721     harmsja  6279: .LC_ListStyleClean,
                   6280: .LC_ListStyleSimple,
                   6281: .LC_ListStyleNormal,
1.795     www      6282: .LC_ListStyleSpecial {
1.911     bisitz   6283:   /* display:block; */
                   6284:   list-style-position: inside;
                   6285:   list-style-type: none;
                   6286:   overflow: hidden;
                   6287:   padding: 0;
1.693     droeschl 6288: }
                   6289: 
1.721     harmsja  6290: .LC_ListStyleSimple li,
                   6291: .LC_ListStyleSimple dd,
                   6292: .LC_ListStyleNormal li,
                   6293: .LC_ListStyleNormal dd,
                   6294: .LC_ListStyleSpecial li,
1.795     www      6295: .LC_ListStyleSpecial dd {
1.911     bisitz   6296:   margin: 0;
                   6297:   padding: 5px 5px 5px 10px;
                   6298:   clear: both;
1.693     droeschl 6299: }
                   6300: 
1.721     harmsja  6301: .LC_ListStyleClean li,
                   6302: .LC_ListStyleClean dd {
1.911     bisitz   6303:   padding-top: 0;
                   6304:   padding-bottom: 0;
1.693     droeschl 6305: }
                   6306: 
1.721     harmsja  6307: .LC_ListStyleSimple dd,
1.795     www      6308: .LC_ListStyleSimple li {
1.911     bisitz   6309:   border-bottom: solid 1px $lg_border_color;
1.693     droeschl 6310: }
                   6311: 
1.721     harmsja  6312: .LC_ListStyleSpecial li,
                   6313: .LC_ListStyleSpecial dd {
1.911     bisitz   6314:   list-style-type: none;
                   6315:   background-color: RGB(220, 220, 220);
                   6316:   margin-bottom: 4px;
1.693     droeschl 6317: }
                   6318: 
1.721     harmsja  6319: table.LC_SimpleTable {
1.911     bisitz   6320:   margin:5px;
                   6321:   border:solid 1px $lg_border_color;
1.795     www      6322: }
1.693     droeschl 6323: 
1.721     harmsja  6324: table.LC_SimpleTable tr {
1.911     bisitz   6325:   padding: 0;
                   6326:   border:solid 1px $lg_border_color;
1.693     droeschl 6327: }
1.795     www      6328: 
                   6329: table.LC_SimpleTable thead {
1.911     bisitz   6330:   background:rgb(220,220,220);
1.693     droeschl 6331: }
                   6332: 
1.721     harmsja  6333: div.LC_columnSection {
1.911     bisitz   6334:   display: block;
                   6335:   clear: both;
                   6336:   overflow: hidden;
                   6337:   margin: 0;
1.693     droeschl 6338: }
                   6339: 
1.721     harmsja  6340: div.LC_columnSection>* {
1.911     bisitz   6341:   float: left;
                   6342:   margin: 10px 20px 10px 0;
                   6343:   overflow:hidden;
1.693     droeschl 6344: }
1.721     harmsja  6345: 
1.694     tempelho 6346: .LC_loginpage_container {
1.911     bisitz   6347:   text-align:left;
                   6348:   margin : 0 auto;
                   6349:   width:90%;
                   6350:   padding: 10px;
                   6351:   height: auto;
                   6352:   background-color:#FFFFFF;
                   6353:   border:1px solid #CCCCCC;
1.694     tempelho 6354: }
                   6355: 
                   6356: 
                   6357: .LC_loginpage_loginContainer {
1.911     bisitz   6358:   float:left;
                   6359:   width: 182px;
                   6360:   padding: 2px;
                   6361:   border:1px solid #CCCCCC;
                   6362:   background-color:$loginbg;
1.694     tempelho 6363: }
                   6364: 
1.795     www      6365: .LC_loginpage_loginContainer h2 {
1.911     bisitz   6366:   margin-top: 0;
                   6367:   display:block;
                   6368:   background:$bgcol;
                   6369:   color:$textcol;
                   6370:   padding-left:5px;
1.712     muellerd 6371: }
1.785     tempelho 6372: 
1.694     tempelho 6373: .LC_loginpage_loginInfo {
1.911     bisitz   6374:   float:left;
                   6375:   width:182px;
                   6376:   border:1px solid #CCCCCC;
                   6377:   padding:2px;
1.712     muellerd 6378: }
                   6379: 
1.694     tempelho 6380: .LC_loginpage_space {
1.911     bisitz   6381:   clear: both;
                   6382:   margin-bottom: 20px;
                   6383:   border-bottom: 1px solid #CCCCCC;
1.694     tempelho 6384: }
                   6385: 
1.785     tempelho 6386: .LC_loginpage_floatLeft {
1.911     bisitz   6387:   float: left;
                   6388:   width: 200px;
                   6389:   margin: 0;
1.785     tempelho 6390: }
                   6391: 
1.795     www      6392: table em {
1.911     bisitz   6393:   font-weight: bold;
                   6394:   font-style: normal;
1.748     schulted 6395: }
1.795     www      6396: 
1.779     bisitz   6397: table.LC_tableBrowseRes,
1.795     www      6398: table.LC_tableOfContent {
1.911     bisitz   6399:   border:none;
                   6400:   border-spacing: 1px;
                   6401:   padding: 3px;
                   6402:   background-color: #FFFFFF;
                   6403:   font-size: 90%;
1.753     droeschl 6404: }
1.789     droeschl 6405: 
1.911     bisitz   6406: table.LC_tableOfContent {
                   6407:   border-collapse: collapse;
1.789     droeschl 6408: }
                   6409: 
1.771     droeschl 6410: table.LC_tableBrowseRes a,
1.768     schulted 6411: table.LC_tableOfContent a {
1.911     bisitz   6412:   background-color: transparent;
                   6413:   text-decoration: none;
1.753     droeschl 6414: }
                   6415: 
1.795     www      6416: table.LC_tableOfContent img {
1.911     bisitz   6417:   border: none;
                   6418:   height: 1.3em;
                   6419:   vertical-align: text-bottom;
                   6420:   margin-right: 0.3em;
1.753     droeschl 6421: }
1.757     schulted 6422: 
1.795     www      6423: a#LC_content_toolbar_firsthomework {
1.911     bisitz   6424:   background-image:url(/res/adm/pages/open-first-problem.gif);
1.774     ehlerst  6425: }
                   6426: 
1.795     www      6427: a#LC_content_toolbar_everything {
1.911     bisitz   6428:   background-image:url(/res/adm/pages/show-all.gif);
1.774     ehlerst  6429: }
                   6430: 
1.795     www      6431: a#LC_content_toolbar_uncompleted {
1.911     bisitz   6432:   background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774     ehlerst  6433: }
                   6434: 
1.795     www      6435: #LC_content_toolbar_clearbubbles {
1.911     bisitz   6436:   background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774     ehlerst  6437: }
                   6438: 
1.795     www      6439: a#LC_content_toolbar_changefolder {
1.911     bisitz   6440:   background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757     schulted 6441: }
                   6442: 
1.795     www      6443: a#LC_content_toolbar_changefolder_toggled {
1.911     bisitz   6444:   background-image:url(/res/adm/pages/open-all-folders.gif);
1.757     schulted 6445: }
                   6446: 
1.795     www      6447: ul#LC_toolbar li a:hover {
1.911     bisitz   6448:   background-position: bottom center;
1.757     schulted 6449: }
                   6450: 
1.795     www      6451: ul#LC_toolbar {
1.911     bisitz   6452:   padding: 0;
                   6453:   margin: 2px;
                   6454:   list-style:none;
                   6455:   position:relative;
                   6456:   background-color:white;
1.757     schulted 6457: }
                   6458: 
1.795     www      6459: ul#LC_toolbar li {
1.911     bisitz   6460:   border:1px solid white;
                   6461:   padding: 0;
                   6462:   margin: 0;
                   6463:   float: left;
                   6464:   display:inline;
                   6465:   vertical-align:middle;
                   6466: }
1.757     schulted 6467: 
1.783     amueller 6468: 
1.795     www      6469: a.LC_toolbarItem {
1.911     bisitz   6470:   display:block;
                   6471:   padding: 0;
                   6472:   margin: 0;
                   6473:   height: 32px;
                   6474:   width: 32px;
                   6475:   color:white;
                   6476:   border: none;
                   6477:   background-repeat:no-repeat;
                   6478:   background-color:transparent;
1.757     schulted 6479: }
                   6480: 
1.915     droeschl 6481: ul.LC_funclist {
                   6482:     margin: 0;
                   6483:     padding: 0.5em 1em 0.5em 0;
                   6484: }
                   6485: 
1.933     droeschl 6486: ul.LC_funclist > li:first-child {
                   6487:     font-weight:bold; 
                   6488:     margin-left:0.8em;
                   6489: }
                   6490: 
1.915     droeschl 6491: ul.LC_funclist + ul.LC_funclist {
                   6492:     /* 
                   6493:        left border as a seperator if we have more than
                   6494:        one list 
                   6495:     */
                   6496:     border-left: 1px solid $sidebg;
                   6497:     /* 
                   6498:        this hides the left border behind the border of the 
                   6499:        outer box if element is wrapped to the next 'line' 
                   6500:     */
                   6501:     margin-left: -1px;
                   6502: }
                   6503: 
1.843     bisitz   6504: ul.LC_funclist li {
1.915     droeschl 6505:   display: inline;
1.782     bisitz   6506:   white-space: nowrap;
1.915     droeschl 6507:   margin: 0 0 0 25px;
                   6508:   line-height: 150%;
1.782     bisitz   6509: }
                   6510: 
1.930     faziophi 6511: .ui-accordion .LC_advanced_toggle {
                   6512:   float: right;
                   6513:   font-size: 90%;
                   6514:   padding: 0px 4px
                   6515: }
1.757     schulted 6516: 
1.343     albertel 6517: END
                   6518: }
                   6519: 
1.306     albertel 6520: =pod
                   6521: 
                   6522: =item * &headtag()
                   6523: 
                   6524: Returns a uniform footer for LON-CAPA web pages.
                   6525: 
1.307     albertel 6526: Inputs: $title - optional title for the head
                   6527:         $head_extra - optional extra HTML to put inside the <head>
1.315     albertel 6528:         $args - optional arguments
1.319     albertel 6529:             force_register - if is true call registerurl so the remote is 
                   6530:                              informed
1.415     albertel 6531:             redirect       -> array ref of
                   6532:                                    1- seconds before redirect occurs
                   6533:                                    2- url to redirect to
                   6534:                                    3- whether the side effect should occur
1.315     albertel 6535:                            (side effect of setting 
                   6536:                                $env{'internal.head.redirect'} to the url 
                   6537:                                redirected too)
1.352     albertel 6538:             domain         -> force to color decorate a page for a specific
                   6539:                                domain
                   6540:             function       -> force usage of a specific rolish color scheme
                   6541:             bgcolor        -> override the default page bgcolor
1.460     albertel 6542:             no_auto_mt_title
                   6543:                            -> prevent &mt()ing the title arg
1.464     albertel 6544: 
1.306     albertel 6545: =cut
                   6546: 
                   6547: sub headtag {
1.313     albertel 6548:     my ($title,$head_extra,$args) = @_;
1.306     albertel 6549:     
1.363     albertel 6550:     my $function = $args->{'function'} || &get_users_function();
                   6551:     my $domain   = $args->{'domain'}   || &determinedomain();
                   6552:     my $bgcolor  = $args->{'bgcolor'}  || &designparm($function.'.pgbg',$domain);
1.418     albertel 6553:     my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458     albertel 6554: 		   $Apache::lonnet::perlvar{'lonVersion'},
1.531     albertel 6555: 		   #time(),
1.418     albertel 6556: 		   $env{'environment.color.timestamp'},
1.363     albertel 6557: 		   $function,$domain,$bgcolor);
                   6558: 
1.369     www      6559:     $url = '/adm/css/'.&escape($url).'.css';
1.363     albertel 6560: 
1.308     albertel 6561:     my $result =
                   6562: 	'<head>'.
1.461     albertel 6563: 	&font_settings();
1.319     albertel 6564: 
1.461     albertel 6565:     if (!$args->{'frameset'}) {
                   6566: 	$result .= &Apache::lonhtmlcommon::htmlareaheaders();
                   6567:     }
1.962     droeschl 6568:     if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
                   6569:         $result .= Apache::lonxml::display_title();
1.319     albertel 6570:     }
1.436     albertel 6571:     if (!$args->{'no_nav_bar'} 
                   6572: 	&& !$args->{'only_body'}
                   6573: 	&& !$args->{'frameset'}) {
                   6574: 	$result .= &help_menu_js();
                   6575:     }
1.319     albertel 6576: 
1.314     albertel 6577:     if (ref($args->{'redirect'})) {
1.414     albertel 6578: 	my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315     albertel 6579: 	$url = &Apache::lonenc::check_encrypt($url);
1.414     albertel 6580: 	if (!$inhibit_continue) {
                   6581: 	    $env{'internal.head.redirect'} = $url;
                   6582: 	}
1.313     albertel 6583: 	$result.=<<ADDMETA
                   6584: <meta http-equiv="pragma" content="no-cache" />
1.344     albertel 6585: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313     albertel 6586: ADDMETA
                   6587:     }
1.306     albertel 6588:     if (!defined($title)) {
                   6589: 	$title = 'The LearningOnline Network with CAPA';
                   6590:     }
1.460     albertel 6591:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
                   6592:     $result .= '<title> LON-CAPA '.$title.'</title>'
1.414     albertel 6593: 	.'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
                   6594: 	.$head_extra;
1.962     droeschl 6595:     return $result.'</head>';
1.306     albertel 6596: }
                   6597: 
                   6598: =pod
                   6599: 
1.340     albertel 6600: =item * &font_settings()
                   6601: 
                   6602: Returns neccessary <meta> to set the proper encoding
                   6603: 
                   6604: Inputs: none
                   6605: 
                   6606: =cut
                   6607: 
                   6608: sub font_settings {
                   6609:     my $headerstring='';
1.647     www      6610:     if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340     albertel 6611: 	$headerstring.=
                   6612: 	    '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
                   6613:     }
                   6614:     return $headerstring;
                   6615: }
                   6616: 
1.341     albertel 6617: =pod
                   6618: 
                   6619: =item * &xml_begin()
                   6620: 
                   6621: Returns the needed doctype and <html>
                   6622: 
                   6623: Inputs: none
                   6624: 
                   6625: =cut
                   6626: 
                   6627: sub xml_begin {
                   6628:     my $output='';
                   6629: 
1.592     albertel 6630:     if ($env{'internal.start_page'}==1) {
                   6631: 	&Apache::lonhtmlcommon::init_htmlareafields();
                   6632:     }
1.342     albertel 6633: 
1.341     albertel 6634:     if ($env{'browser.mathml'}) {
                   6635: 	$output='<?xml version="1.0"?>'
                   6636:             #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
                   6637: #            .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
                   6638:             
                   6639: #	    .'<!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">] >'
                   6640: 	    .'<!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">'
                   6641:             .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" ' 
                   6642: 	    .'xmlns="http://www.w3.org/1999/xhtml">';
                   6643:     } else {
1.849     bisitz   6644: 	$output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
                   6645:            .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1.341     albertel 6646:     }
                   6647:     return $output;
                   6648: }
1.340     albertel 6649: 
                   6650: =pod
                   6651: 
1.306     albertel 6652: =item * &start_page()
                   6653: 
                   6654: Returns a complete <html> .. <body> section for LON-CAPA web pages.
                   6655: 
1.648     raeburn  6656: Inputs:
                   6657: 
                   6658: =over 4
                   6659: 
                   6660: $title - optional title for the page
                   6661: 
                   6662: $head_extra - optional extra HTML to incude inside the <head>
                   6663: 
                   6664: $args - additional optional args supported are:
                   6665: 
                   6666: =over 8
                   6667: 
                   6668:              only_body      -> is true will set &bodytag() onlybodytag
1.317     albertel 6669:                                     arg on
1.814     bisitz   6670:              no_nav_bar     -> is true will set &bodytag() no_nav_bar arg on
1.648     raeburn  6671:              add_entries    -> additional attributes to add to the  <body>
                   6672:              domain         -> force to color decorate a page for a 
1.317     albertel 6673:                                     specific domain
1.648     raeburn  6674:              function       -> force usage of a specific rolish color
1.317     albertel 6675:                                     scheme
1.648     raeburn  6676:              redirect       -> see &headtag()
                   6677:              bgcolor        -> override the default page bg color
                   6678:              js_ready       -> return a string ready for being used in 
1.317     albertel 6679:                                     a javascript writeln
1.648     raeburn  6680:              html_encode    -> return a string ready for being used in 
1.320     albertel 6681:                                     a html attribute
1.648     raeburn  6682:              force_register -> if is true will turn on the &bodytag()
1.317     albertel 6683:                                     $forcereg arg
1.648     raeburn  6684:              frameset       -> if true will start with a <frameset>
1.330     albertel 6685:                                     rather than <body>
1.648     raeburn  6686:              skip_phases    -> hash ref of 
1.338     albertel 6687:                                     head -> skip the <html><head> generation
                   6688:                                     body -> skip all <body> generation
1.648     raeburn  6689:              no_auto_mt_title -> prevent &mt()ing the title arg
                   6690:              inherit_jsmath -> when creating popup window in a page,
                   6691:                                     should it have jsmath forced on by the
                   6692:                                     current page
1.867     kalberla 6693:              bread_crumbs ->             Array containing breadcrumbs
                   6694:              bread_crumbs_components ->  if exists show it as headline else show only the breadcrumbs
1.361     albertel 6695: 
1.648     raeburn  6696: =back
1.460     albertel 6697: 
1.648     raeburn  6698: =back
1.562     albertel 6699: 
1.306     albertel 6700: =cut
                   6701: 
                   6702: sub start_page {
1.309     albertel 6703:     my ($title,$head_extra,$args) = @_;
1.318     albertel 6704:     #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313     albertel 6705:     my %head_args;
1.352     albertel 6706:     foreach my $arg ('redirect','force_register','domain','function',
1.460     albertel 6707: 		     'bgcolor','frameset','no_nav_bar','only_body',
                   6708: 		     'no_auto_mt_title') {
1.319     albertel 6709: 	if (defined($args->{$arg})) {
1.324     raeburn  6710: 	    $head_args{$arg} = $args->{$arg};
1.319     albertel 6711: 	}
1.313     albertel 6712:     }
1.319     albertel 6713: 
1.315     albertel 6714:     $env{'internal.start_page'}++;
1.338     albertel 6715:     my $result;
                   6716:     if (! exists($args->{'skip_phases'}{'head'}) ) {
                   6717: 	$result.=
1.341     albertel 6718: 	    &xml_begin().
1.962     droeschl 6719:         &headtag($title,$head_extra,\%head_args);
1.338     albertel 6720:     }
                   6721:     
                   6722:     if (! exists($args->{'skip_phases'}{'body'}) ) {
                   6723: 	if ($args->{'frameset'}) {
                   6724: 	    my $attr_string = &make_attr_string($args->{'force_register'},
                   6725: 						$args->{'add_entries'});
                   6726: 	    $result .= "\n<frameset $attr_string>\n";
1.831     bisitz   6727:         } else {
                   6728:             $result .=
                   6729:                 &bodytag($title, 
                   6730:                          $args->{'function'},       $args->{'add_entries'},
                   6731:                          $args->{'only_body'},      $args->{'domain'},
                   6732:                          $args->{'force_register'}, $args->{'no_nav_bar'},
1.962     droeschl 6733:                          $args->{'bgcolor'},        $args);
1.831     bisitz   6734:         }
1.330     albertel 6735:     }
1.338     albertel 6736: 
1.315     albertel 6737:     if ($args->{'js_ready'}) {
1.713     kaisler  6738: 		$result = &js_ready($result);
1.315     albertel 6739:     }
1.320     albertel 6740:     if ($args->{'html_encode'}) {
1.713     kaisler  6741: 		$result = &html_encode($result);
                   6742:     }
                   6743: 
1.813     bisitz   6744:     # Preparation for new and consistent functionlist at top of screen
                   6745:     # if ($args->{'functionlist'}) {
                   6746:     #            $result .= &build_functionlist();
                   6747:     #}
                   6748: 
                   6749:     # Don't add anything more if only_body wanted
                   6750:     return $result if $args->{'only_body'};
                   6751: 
1.920     raeburn  6752:     #Breadcrumbs for Construction Space provided by &bodytag. 
1.949     droeschl 6753:     if (
                   6754:         $env{'request.state'} eq 'construct') {
1.920     raeburn  6755:         return $result;
                   6756:     }
                   6757:  
1.813     bisitz   6758:     #Breadcrumbs
1.758     kaisler  6759:     if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
                   6760: 		&Apache::lonhtmlcommon::clear_breadcrumbs();
                   6761: 		#if any br links exists, add them to the breadcrumbs
                   6762: 		if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {         
                   6763: 			foreach my $crumb (@{$args->{'bread_crumbs'}}){
                   6764: 				&Apache::lonhtmlcommon::add_breadcrumb($crumb);
                   6765: 			}
                   6766: 		}
                   6767: 
                   6768: 		#if bread_crumbs_component exists show it as headline else show only the breadcrumbs
                   6769: 		if(exists($args->{'bread_crumbs_component'})){
                   6770: 			$result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
                   6771: 		}else{
                   6772: 			$result .= &Apache::lonhtmlcommon::breadcrumbs();
                   6773: 		}
1.320     albertel 6774:     }
1.315     albertel 6775:     return $result;
1.306     albertel 6776: }
                   6777: 
                   6778: sub end_page {
1.315     albertel 6779:     my ($args) = @_;
                   6780:     $env{'internal.end_page'}++;
1.330     albertel 6781:     my $result;
1.335     albertel 6782:     if ($args->{'discussion'}) {
                   6783: 	my ($target,$parser);
                   6784: 	if (ref($args->{'discussion'})) {
                   6785: 	    ($target,$parser) =($args->{'discussion'}{'target'},
                   6786: 				$args->{'discussion'}{'parser'});
                   6787: 	}
                   6788: 	$result .= &Apache::lonxml::xmlend($target,$parser);
                   6789:     }
                   6790: 
1.330     albertel 6791:     if ($args->{'frameset'}) {
                   6792: 	$result .= '</frameset>';
                   6793:     } else {
1.635     raeburn  6794: 	$result .= &endbodytag($args);
1.330     albertel 6795:     }
                   6796:     $result .= "\n</html>";
                   6797: 
1.315     albertel 6798:     if ($args->{'js_ready'}) {
1.317     albertel 6799: 	$result = &js_ready($result);
1.315     albertel 6800:     }
1.335     albertel 6801: 
1.320     albertel 6802:     if ($args->{'html_encode'}) {
                   6803: 	$result = &html_encode($result);
                   6804:     }
1.335     albertel 6805: 
1.315     albertel 6806:     return $result;
                   6807: }
                   6808: 
1.320     albertel 6809: sub html_encode {
                   6810:     my ($result) = @_;
                   6811: 
1.322     albertel 6812:     $result = &HTML::Entities::encode($result,'<>&"');
1.320     albertel 6813:     
                   6814:     return $result;
                   6815: }
1.317     albertel 6816: sub js_ready {
                   6817:     my ($result) = @_;
                   6818: 
1.323     albertel 6819:     $result =~ s/[\n\r]/ /xmsg;
                   6820:     $result =~ s/\\/\\\\/xmsg;
                   6821:     $result =~ s/'/\\'/xmsg;
1.372     albertel 6822:     $result =~ s{</}{<\\/}xmsg;
1.317     albertel 6823:     
                   6824:     return $result;
                   6825: }
                   6826: 
1.315     albertel 6827: sub validate_page {
                   6828:     if (  exists($env{'internal.start_page'})
1.316     albertel 6829: 	  &&     $env{'internal.start_page'} > 1) {
                   6830: 	&Apache::lonnet::logthis('start_page called multiple times '.
1.318     albertel 6831: 				 $env{'internal.start_page'}.' '.
1.316     albertel 6832: 				 $ENV{'request.filename'});
1.315     albertel 6833:     }
                   6834:     if (  exists($env{'internal.end_page'})
1.316     albertel 6835: 	  &&     $env{'internal.end_page'} > 1) {
                   6836: 	&Apache::lonnet::logthis('end_page called multiple times '.
1.318     albertel 6837: 				 $env{'internal.end_page'}.' '.
1.316     albertel 6838: 				 $env{'request.filename'});
1.315     albertel 6839:     }
                   6840:     if (     exists($env{'internal.start_page'})
                   6841: 	&& ! exists($env{'internal.end_page'})) {
1.316     albertel 6842: 	&Apache::lonnet::logthis('start_page called without end_page '.
                   6843: 				 $env{'request.filename'});
1.315     albertel 6844:     }
                   6845:     if (   ! exists($env{'internal.start_page'})
                   6846: 	&&   exists($env{'internal.end_page'})) {
1.316     albertel 6847: 	&Apache::lonnet::logthis('end_page called without start_page'.
                   6848: 				 $env{'request.filename'});
1.315     albertel 6849:     }
1.306     albertel 6850: }
1.315     albertel 6851: 
1.318     albertel 6852: sub simple_error_page {
                   6853:     my ($r,$title,$msg) = @_;
                   6854:     my $page =
                   6855: 	&Apache::loncommon::start_page($title).
                   6856: 	&mt($msg).
                   6857: 	&Apache::loncommon::end_page();
                   6858:     if (ref($r)) {
                   6859: 	$r->print($page);
1.327     albertel 6860: 	return;
1.318     albertel 6861:     }
                   6862:     return $page;
                   6863: }
1.347     albertel 6864: 
                   6865: {
1.610     albertel 6866:     my @row_count;
1.961     onken    6867: 
                   6868:     sub start_data_table_count {
                   6869:         unshift(@row_count, 0);
                   6870:         return;
                   6871:     }
                   6872: 
                   6873:     sub end_data_table_count {
                   6874:         shift(@row_count);
                   6875:         return;
                   6876:     }
                   6877: 
1.347     albertel 6878:     sub start_data_table {
1.422     albertel 6879: 	my ($add_class) = @_;
                   6880: 	my $css_class = (join(' ','LC_data_table',$add_class));
1.961     onken    6881: 	&start_data_table_count();
1.422     albertel 6882: 	return '<table class="'.$css_class.'">'."\n";
1.347     albertel 6883:     }
                   6884: 
                   6885:     sub end_data_table {
1.961     onken    6886: 	&end_data_table_count();
1.389     albertel 6887: 	return '</table>'."\n";;
1.347     albertel 6888:     }
                   6889: 
                   6890:     sub start_data_table_row {
1.422     albertel 6891: 	my ($add_class) = @_;
1.610     albertel 6892: 	$row_count[0]++;
                   6893: 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900     bisitz   6894: 	$css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.422     albertel 6895: 	return  '<tr class="'.$css_class.'">'."\n";;
1.347     albertel 6896:     }
1.471     banghart 6897:     
                   6898:     sub continue_data_table_row {
                   6899: 	my ($add_class) = @_;
1.610     albertel 6900: 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900     bisitz   6901: 	$css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');;
1.471     banghart 6902: 	return  '<tr class="'.$css_class.'">'."\n";;
                   6903:     }
1.347     albertel 6904: 
                   6905:     sub end_data_table_row {
1.389     albertel 6906: 	return '</tr>'."\n";;
1.347     albertel 6907:     }
1.367     www      6908: 
1.421     albertel 6909:     sub start_data_table_empty_row {
1.707     bisitz   6910: #	$row_count[0]++;
1.421     albertel 6911: 	return  '<tr class="LC_empty_row" >'."\n";;
                   6912:     }
                   6913: 
                   6914:     sub end_data_table_empty_row {
                   6915: 	return '</tr>'."\n";;
                   6916:     }
                   6917: 
1.367     www      6918:     sub start_data_table_header_row {
1.389     albertel 6919: 	return  '<tr class="LC_header_row">'."\n";;
1.367     www      6920:     }
                   6921: 
                   6922:     sub end_data_table_header_row {
1.389     albertel 6923: 	return '</tr>'."\n";;
1.367     www      6924:     }
1.890     droeschl 6925: 
                   6926:     sub data_table_caption {
                   6927:         my $caption = shift;
                   6928:         return "<caption class=\"LC_caption\">$caption</caption>";
                   6929:     }
1.347     albertel 6930: }
                   6931: 
1.548     albertel 6932: =pod
                   6933: 
                   6934: =item * &inhibit_menu_check($arg)
                   6935: 
                   6936: Checks for a inhibitmenu state and generates output to preserve it
                   6937: 
                   6938: Inputs:         $arg - can be any of
                   6939:                      - undef - in which case the return value is a string 
                   6940:                                to add  into arguments list of a uri
                   6941:                      - 'input' - in which case the return value is a HTML
                   6942:                                  <form> <input> field of type hidden to
                   6943:                                  preserve the value
                   6944:                      - a url - in which case the return value is the url with
                   6945:                                the neccesary cgi args added to preserve the
                   6946:                                inhibitmenu state
                   6947:                      - a ref to a url - no return value, but the string is
                   6948:                                         updated to include the neccessary cgi
                   6949:                                         args to preserve the inhibitmenu state
                   6950: 
                   6951: =cut
                   6952: 
                   6953: sub inhibit_menu_check {
                   6954:     my ($arg) = @_;
                   6955:     &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
                   6956:     if ($arg eq 'input') {
                   6957: 	if ($env{'form.inhibitmenu'}) {
                   6958: 	    return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
                   6959: 	} else {
                   6960: 	    return
                   6961: 	}
                   6962:     }
                   6963:     if ($env{'form.inhibitmenu'}) {
                   6964: 	if (ref($arg)) {
                   6965: 	    $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
                   6966: 	} elsif ($arg eq '') {
                   6967: 	    $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
                   6968: 	} else {
                   6969: 	    $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
                   6970: 	}
                   6971:     }
                   6972:     if (!ref($arg)) {
                   6973: 	return $arg;
                   6974:     }
                   6975: }
                   6976: 
1.251     albertel 6977: ###############################################
1.182     matthew  6978: 
                   6979: =pod
                   6980: 
1.549     albertel 6981: =back
                   6982: 
                   6983: =head1 User Information Routines
                   6984: 
                   6985: =over 4
                   6986: 
1.405     albertel 6987: =item * &get_users_function()
1.182     matthew  6988: 
                   6989: Used by &bodytag to determine the current users primary role.
                   6990: Returns either 'student','coordinator','admin', or 'author'.
                   6991: 
                   6992: =cut
                   6993: 
                   6994: ###############################################
                   6995: sub get_users_function {
1.815     tempelho 6996:     my $function = 'norole';
1.818     tempelho 6997:     if ($env{'request.role'}=~/^(st)/) {
                   6998:         $function='student';
                   6999:     }
1.907     raeburn  7000:     if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182     matthew  7001:         $function='coordinator';
                   7002:     }
1.258     albertel 7003:     if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182     matthew  7004:         $function='admin';
                   7005:     }
1.826     bisitz   7006:     if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.182     matthew  7007:         ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
                   7008:         $function='author';
                   7009:     }
                   7010:     return $function;
1.54      www      7011: }
1.99      www      7012: 
                   7013: ###############################################
                   7014: 
1.233     raeburn  7015: =pod
                   7016: 
1.821     raeburn  7017: =item * &show_course()
                   7018: 
                   7019: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
                   7020: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
                   7021: 
                   7022: Inputs:
                   7023: None
                   7024: 
                   7025: Outputs:
                   7026: Scalar: 1 if 'Course' to be used, 0 otherwise.
                   7027: 
                   7028: =cut
                   7029: 
                   7030: ###############################################
                   7031: sub show_course {
                   7032:     my $course = !$env{'user.adv'};
                   7033:     if (!$env{'user.adv'}) {
                   7034:         foreach my $env (keys(%env)) {
                   7035:             next if ($env !~ m/^user\.priv\./);
                   7036:             if ($env !~ m/^user\.priv\.(?:st|cm)/) {
                   7037:                 $course = 0;
                   7038:                 last;
                   7039:             }
                   7040:         }
                   7041:     }
                   7042:     return $course;
                   7043: }
                   7044: 
                   7045: ###############################################
                   7046: 
                   7047: =pod
                   7048: 
1.542     raeburn  7049: =item * &check_user_status()
1.274     raeburn  7050: 
                   7051: Determines current status of supplied role for a
                   7052: specific user. Roles can be active, previous or future.
                   7053: 
                   7054: Inputs: 
                   7055: user's domain, user's username, course's domain,
1.375     raeburn  7056: course's number, optional section ID.
1.274     raeburn  7057: 
                   7058: Outputs:
                   7059: role status: active, previous or future. 
                   7060: 
                   7061: =cut
                   7062: 
                   7063: sub check_user_status {
1.412     raeburn  7064:     my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274     raeburn  7065:     my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
                   7066:     my @uroles = keys %userinfo;
                   7067:     my $srchstr;
                   7068:     my $active_chk = 'none';
1.412     raeburn  7069:     my $now = time;
1.274     raeburn  7070:     if (@uroles > 0) {
1.908     raeburn  7071:         if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274     raeburn  7072:             $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
                   7073:         } else {
1.412     raeburn  7074:             $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
                   7075:         }
                   7076:         if (grep/^\Q$srchstr\E$/,@uroles) {
1.274     raeburn  7077:             my $role_end = 0;
                   7078:             my $role_start = 0;
                   7079:             $active_chk = 'active';
1.412     raeburn  7080:             if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
                   7081:                 $role_end = $1;
                   7082:                 if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
                   7083:                     $role_start = $1;
1.274     raeburn  7084:                 }
                   7085:             }
                   7086:             if ($role_start > 0) {
1.412     raeburn  7087:                 if ($now < $role_start) {
1.274     raeburn  7088:                     $active_chk = 'future';
                   7089:                 }
                   7090:             }
                   7091:             if ($role_end > 0) {
1.412     raeburn  7092:                 if ($now > $role_end) {
1.274     raeburn  7093:                     $active_chk = 'previous';
                   7094:                 }
                   7095:             }
                   7096:         }
                   7097:     }
                   7098:     return $active_chk;
                   7099: }
                   7100: 
                   7101: ###############################################
                   7102: 
                   7103: =pod
                   7104: 
1.405     albertel 7105: =item * &get_sections()
1.233     raeburn  7106: 
                   7107: Determines all the sections for a course including
                   7108: sections with students and sections containing other roles.
1.419     raeburn  7109: Incoming parameters: 
                   7110: 
                   7111: 1. domain
                   7112: 2. course number 
                   7113: 3. reference to array containing roles for which sections should 
                   7114: be gathered (optional).
                   7115: 4. reference to array containing status types for which sections 
                   7116: should be gathered (optional).
                   7117: 
                   7118: If the third argument is undefined, sections are gathered for any role. 
                   7119: If the fourth argument is undefined, sections are gathered for any status.
                   7120: Permissible values are 'active' or 'future' or 'previous'.
1.233     raeburn  7121:  
1.374     raeburn  7122: Returns section hash (keys are section IDs, values are
                   7123: number of users in each section), subject to the
1.419     raeburn  7124: optional roles filter, optional status filter 
1.233     raeburn  7125: 
                   7126: =cut
                   7127: 
                   7128: ###############################################
                   7129: sub get_sections {
1.419     raeburn  7130:     my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366     albertel 7131:     if (!defined($cdom) || !defined($cnum)) {
                   7132:         my $cid =  $env{'request.course.id'};
                   7133: 
                   7134: 	return if (!defined($cid));
                   7135: 
                   7136:         $cdom = $env{'course.'.$cid.'.domain'};
                   7137:         $cnum = $env{'course.'.$cid.'.num'};
                   7138:     }
                   7139: 
                   7140:     my %sectioncount;
1.419     raeburn  7141:     my $now = time;
1.240     albertel 7142: 
1.366     albertel 7143:     if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276     albertel 7144: 	my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240     albertel 7145: 	my $sec_index = &Apache::loncoursedata::CL_SECTION();
                   7146: 	my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419     raeburn  7147:         my $start_index = &Apache::loncoursedata::CL_START();
                   7148:         my $end_index = &Apache::loncoursedata::CL_END();
                   7149:         my $status;
1.366     albertel 7150: 	while (my ($student,$data) = each(%$classlist)) {
1.419     raeburn  7151: 	    my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
                   7152: 				                     $data->[$status_index],
                   7153:                                                      $data->[$start_index],
                   7154:                                                      $data->[$end_index]);
                   7155:             if ($stu_status eq 'Active') {
                   7156:                 $status = 'active';
                   7157:             } elsif ($end < $now) {
                   7158:                 $status = 'previous';
                   7159:             } elsif ($start > $now) {
                   7160:                 $status = 'future';
                   7161:             } 
                   7162: 	    if ($section ne '-1' && $section !~ /^\s*$/) {
                   7163:                 if ((!defined($possible_status)) || (($status ne '') && 
                   7164:                     (grep/^\Q$status\E$/,@{$possible_status}))) { 
                   7165: 		    $sectioncount{$section}++;
                   7166:                 }
1.240     albertel 7167: 	    }
                   7168: 	}
                   7169:     }
                   7170:     my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   7171:     foreach my $user (sort(keys(%courseroles))) {
                   7172: 	if ($user !~ /^(\w{2})/) { next; }
                   7173: 	my ($role) = ($user =~ /^(\w{2})/);
                   7174: 	if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419     raeburn  7175: 	my ($section,$status);
1.240     albertel 7176: 	if ($role eq 'cr' &&
                   7177: 	    $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
                   7178: 	    $section=$1;
                   7179: 	}
                   7180: 	if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
                   7181: 	if (!defined($section) || $section eq '-1') { next; }
1.419     raeburn  7182:         my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
                   7183:         if ($end == -1 && $start == -1) {
                   7184:             next; #deleted role
                   7185:         }
                   7186:         if (!defined($possible_status)) { 
                   7187:             $sectioncount{$section}++;
                   7188:         } else {
                   7189:             if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
                   7190:                 $status = 'active';
                   7191:             } elsif ($end < $now) {
                   7192:                 $status = 'future';
                   7193:             } elsif ($start > $now) {
                   7194:                 $status = 'previous';
                   7195:             }
                   7196:             if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
                   7197:                 $sectioncount{$section}++;
                   7198:             }
                   7199:         }
1.233     raeburn  7200:     }
1.366     albertel 7201:     return %sectioncount;
1.233     raeburn  7202: }
                   7203: 
1.274     raeburn  7204: ###############################################
1.294     raeburn  7205: 
                   7206: =pod
1.405     albertel 7207: 
                   7208: =item * &get_course_users()
                   7209: 
1.275     raeburn  7210: Retrieves usernames:domains for users in the specified course
                   7211: with specific role(s), and access status. 
                   7212: 
                   7213: Incoming parameters:
1.277     albertel 7214: 1. course domain
                   7215: 2. course number
                   7216: 3. access status: users must have - either active, 
1.275     raeburn  7217: previous, future, or all.
1.277     albertel 7218: 4. reference to array of permissible roles
1.288     raeburn  7219: 5. reference to array of section restrictions (optional)
                   7220: 6. reference to results object (hash of hashes).
                   7221: 7. reference to optional userdata hash
1.609     raeburn  7222: 8. reference to optional statushash
1.630     raeburn  7223: 9. flag if privileged users (except those set to unhide in
                   7224:    course settings) should be excluded    
1.609     raeburn  7225: Keys of top level results hash are roles.
1.275     raeburn  7226: Keys of inner hashes are username:domain, with 
                   7227: values set to access type.
1.288     raeburn  7228: Optional userdata hash returns an array with arguments in the 
                   7229: same order as loncoursedata::get_classlist() for student data.
                   7230: 
1.609     raeburn  7231: Optional statushash returns
                   7232: 
1.288     raeburn  7233: Entries for end, start, section and status are blank because
                   7234: of the possibility of multiple values for non-student roles.
                   7235: 
1.275     raeburn  7236: =cut
1.405     albertel 7237: 
1.275     raeburn  7238: ###############################################
1.405     albertel 7239: 
1.275     raeburn  7240: sub get_course_users {
1.630     raeburn  7241:     my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288     raeburn  7242:     my %idx = ();
1.419     raeburn  7243:     my %seclists;
1.288     raeburn  7244: 
                   7245:     $idx{udom} = &Apache::loncoursedata::CL_SDOM();
                   7246:     $idx{uname} =  &Apache::loncoursedata::CL_SNAME();
                   7247:     $idx{end} = &Apache::loncoursedata::CL_END();
                   7248:     $idx{start} = &Apache::loncoursedata::CL_START();
                   7249:     $idx{id} = &Apache::loncoursedata::CL_ID();
                   7250:     $idx{section} = &Apache::loncoursedata::CL_SECTION();
                   7251:     $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
                   7252:     $idx{status} = &Apache::loncoursedata::CL_STATUS();
                   7253: 
1.290     albertel 7254:     if (grep(/^st$/,@{$roles})) {
1.276     albertel 7255:         my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278     raeburn  7256:         my $now = time;
1.277     albertel 7257:         foreach my $student (keys(%{$classlist})) {
1.288     raeburn  7258:             my $match = 0;
1.412     raeburn  7259:             my $secmatch = 0;
1.419     raeburn  7260:             my $section = $$classlist{$student}[$idx{section}];
1.609     raeburn  7261:             my $status = $$classlist{$student}[$idx{status}];
1.419     raeburn  7262:             if ($section eq '') {
                   7263:                 $section = 'none';
                   7264:             }
1.291     albertel 7265:             if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 7266:                 if (grep(/^all$/,@{$sections})) {
1.412     raeburn  7267:                     $secmatch = 1;
                   7268:                 } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420     albertel 7269:                     if (grep(/^none$/,@{$sections})) {
1.412     raeburn  7270:                         $secmatch = 1;
                   7271:                     }
                   7272:                 } else {  
1.419     raeburn  7273: 		    if (grep(/^\Q$section\E$/,@{$sections})) {
1.412     raeburn  7274: 		        $secmatch = 1;
                   7275:                     }
1.290     albertel 7276: 		}
1.412     raeburn  7277:                 if (!$secmatch) {
                   7278:                     next;
                   7279:                 }
1.419     raeburn  7280:             }
1.275     raeburn  7281:             if (defined($$types{'active'})) {
1.288     raeburn  7282:                 if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275     raeburn  7283:                     push(@{$$users{st}{$student}},'active');
1.288     raeburn  7284:                     $match = 1;
1.275     raeburn  7285:                 }
                   7286:             }
                   7287:             if (defined($$types{'previous'})) {
1.609     raeburn  7288:                 if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275     raeburn  7289:                     push(@{$$users{st}{$student}},'previous');
1.288     raeburn  7290:                     $match = 1;
1.275     raeburn  7291:                 }
                   7292:             }
                   7293:             if (defined($$types{'future'})) {
1.609     raeburn  7294:                 if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275     raeburn  7295:                     push(@{$$users{st}{$student}},'future');
1.288     raeburn  7296:                     $match = 1;
1.275     raeburn  7297:                 }
                   7298:             }
1.609     raeburn  7299:             if ($match) {
                   7300:                 push(@{$seclists{$student}},$section);
                   7301:                 if (ref($userdata) eq 'HASH') {
                   7302:                     $$userdata{$student} = $$classlist{$student};
                   7303:                 }
                   7304:                 if (ref($statushash) eq 'HASH') {
                   7305:                     $statushash->{$student}{'st'}{$section} = $status;
                   7306:                 }
1.288     raeburn  7307:             }
1.275     raeburn  7308:         }
                   7309:     }
1.412     raeburn  7310:     if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439     raeburn  7311:         my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   7312:         my $now = time;
1.609     raeburn  7313:         my %displaystatus = ( previous => 'Expired',
                   7314:                               active   => 'Active',
                   7315:                               future   => 'Future',
                   7316:                             );
1.630     raeburn  7317:         my %nothide;
                   7318:         if ($hidepriv) {
                   7319:             my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
                   7320:             foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
                   7321:                 if ($user !~ /:/) {
                   7322:                     $nothide{join(':',split(/[\@]/,$user))}=1;
                   7323:                 } else {
                   7324:                     $nothide{$user} = 1;
                   7325:                 }
                   7326:             }
                   7327:         }
1.439     raeburn  7328:         foreach my $person (sort(keys(%coursepersonnel))) {
1.288     raeburn  7329:             my $match = 0;
1.412     raeburn  7330:             my $secmatch = 0;
1.439     raeburn  7331:             my $status;
1.412     raeburn  7332:             my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275     raeburn  7333:             $user =~ s/:$//;
1.439     raeburn  7334:             my ($end,$start) = split(/:/,$coursepersonnel{$person});
                   7335:             if ($end == -1 || $start == -1) {
                   7336:                 next;
                   7337:             }
                   7338:             if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
                   7339:                 (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412     raeburn  7340:                 my ($uname,$udom) = split(/:/,$user);
                   7341:                 if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 7342:                     if (grep(/^all$/,@{$sections})) {
1.412     raeburn  7343:                         $secmatch = 1;
                   7344:                     } elsif ($usec eq '') {
1.420     albertel 7345:                         if (grep(/^none$/,@{$sections})) {
1.412     raeburn  7346:                             $secmatch = 1;
                   7347:                         }
                   7348:                     } else {
                   7349:                         if (grep(/^\Q$usec\E$/,@{$sections})) {
                   7350:                             $secmatch = 1;
                   7351:                         }
                   7352:                     }
                   7353:                     if (!$secmatch) {
                   7354:                         next;
                   7355:                     }
1.288     raeburn  7356:                 }
1.419     raeburn  7357:                 if ($usec eq '') {
                   7358:                     $usec = 'none';
                   7359:                 }
1.275     raeburn  7360:                 if ($uname ne '' && $udom ne '') {
1.630     raeburn  7361:                     if ($hidepriv) {
                   7362:                         if ((&Apache::lonnet::privileged($uname,$udom)) &&
                   7363:                             (!$nothide{$uname.':'.$udom})) {
                   7364:                             next;
                   7365:                         }
                   7366:                     }
1.503     raeburn  7367:                     if ($end > 0 && $end < $now) {
1.439     raeburn  7368:                         $status = 'previous';
                   7369:                     } elsif ($start > $now) {
                   7370:                         $status = 'future';
                   7371:                     } else {
                   7372:                         $status = 'active';
                   7373:                     }
1.277     albertel 7374:                     foreach my $type (keys(%{$types})) { 
1.275     raeburn  7375:                         if ($status eq $type) {
1.420     albertel 7376:                             if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419     raeburn  7377:                                 push(@{$$users{$role}{$user}},$type);
                   7378:                             }
1.288     raeburn  7379:                             $match = 1;
                   7380:                         }
                   7381:                     }
1.419     raeburn  7382:                     if (($match) && (ref($userdata) eq 'HASH')) {
                   7383:                         if (!exists($$userdata{$uname.':'.$udom})) {
                   7384: 			    &get_user_info($udom,$uname,\%idx,$userdata);
                   7385:                         }
1.420     albertel 7386:                         if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419     raeburn  7387:                             push(@{$seclists{$uname.':'.$udom}},$usec);
                   7388:                         }
1.609     raeburn  7389:                         if (ref($statushash) eq 'HASH') {
                   7390:                             $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
                   7391:                         }
1.275     raeburn  7392:                     }
                   7393:                 }
                   7394:             }
                   7395:         }
1.290     albertel 7396:         if (grep(/^ow$/,@{$roles})) {
1.279     raeburn  7397:             if ((defined($cdom)) && (defined($cnum))) {
                   7398:                 my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
                   7399:                 if ( defined($csettings{'internal.courseowner'}) ) {
                   7400:                     my $owner = $csettings{'internal.courseowner'};
1.609     raeburn  7401:                     next if ($owner eq '');
                   7402:                     my ($ownername,$ownerdom);
                   7403:                     if ($owner =~ /^([^:]+):([^:]+)$/) {
                   7404:                         $ownername = $1;
                   7405:                         $ownerdom = $2;
                   7406:                     } else {
                   7407:                         $ownername = $owner;
                   7408:                         $ownerdom = $cdom;
                   7409:                         $owner = $ownername.':'.$ownerdom;
1.439     raeburn  7410:                     }
                   7411:                     @{$$users{'ow'}{$owner}} = 'any';
1.290     albertel 7412:                     if (defined($userdata) && 
1.609     raeburn  7413: 			!exists($$userdata{$owner})) {
                   7414: 			&get_user_info($ownerdom,$ownername,\%idx,$userdata);
                   7415:                         if (!grep(/^none$/,@{$seclists{$owner}})) {
                   7416:                             push(@{$seclists{$owner}},'none');
                   7417:                         }
                   7418:                         if (ref($statushash) eq 'HASH') {
                   7419:                             $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419     raeburn  7420:                         }
1.290     albertel 7421: 		    }
1.279     raeburn  7422:                 }
                   7423:             }
                   7424:         }
1.419     raeburn  7425:         foreach my $user (keys(%seclists)) {
                   7426:             @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
                   7427:             $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
                   7428:         }
1.275     raeburn  7429:     }
                   7430:     return;
                   7431: }
                   7432: 
1.288     raeburn  7433: sub get_user_info {
                   7434:     my ($udom,$uname,$idx,$userdata) = @_;
1.289     albertel 7435:     $$userdata{$uname.':'.$udom}[$$idx{fullname}] = 
                   7436: 	&plainname($uname,$udom,'lastname');
1.291     albertel 7437:     $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297     raeburn  7438:     $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609     raeburn  7439:     my %idhash =  &Apache::lonnet::idrget($udom,($uname));
                   7440:     $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname}; 
1.288     raeburn  7441:     return;
                   7442: }
1.275     raeburn  7443: 
1.472     raeburn  7444: ###############################################
                   7445: 
                   7446: =pod
                   7447: 
                   7448: =item * &get_user_quota()
                   7449: 
                   7450: Retrieves quota assigned for storage of portfolio files for a user  
                   7451: 
                   7452: Incoming parameters:
                   7453: 1. user's username
                   7454: 2. user's domain
                   7455: 
                   7456: Returns:
1.536     raeburn  7457: 1. Disk quota (in Mb) assigned to student.
                   7458: 2. (Optional) Type of setting: custom or default
                   7459:    (individually assigned or default for user's 
                   7460:    institutional status).
                   7461: 3. (Optional) - User's institutional status (e.g., faculty, staff
                   7462:    or student - types as defined in localenroll::inst_usertypes 
                   7463:    for user's domain, which determines default quota for user.
                   7464: 4. (Optional) - Default quota which would apply to the user.
1.472     raeburn  7465: 
                   7466: If a value has been stored in the user's environment, 
1.536     raeburn  7467: it will return that, otherwise it returns the maximal default
                   7468: defined for the user's instituional status(es) in the domain.
1.472     raeburn  7469: 
                   7470: =cut
                   7471: 
                   7472: ###############################################
                   7473: 
                   7474: 
                   7475: sub get_user_quota {
                   7476:     my ($uname,$udom) = @_;
1.536     raeburn  7477:     my ($quota,$quotatype,$settingstatus,$defquota);
1.472     raeburn  7478:     if (!defined($udom)) {
                   7479:         $udom = $env{'user.domain'};
                   7480:     }
                   7481:     if (!defined($uname)) {
                   7482:         $uname = $env{'user.name'};
                   7483:     }
                   7484:     if (($udom eq '' || $uname eq '') ||
                   7485:         ($udom eq 'public') && ($uname eq 'public')) {
                   7486:         $quota = 0;
1.536     raeburn  7487:         $quotatype = 'default';
                   7488:         $defquota = 0; 
1.472     raeburn  7489:     } else {
1.536     raeburn  7490:         my $inststatus;
1.472     raeburn  7491:         if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
                   7492:             $quota = $env{'environment.portfolioquota'};
1.536     raeburn  7493:             $inststatus = $env{'environment.inststatus'};
1.472     raeburn  7494:         } else {
1.536     raeburn  7495:             my %userenv = 
                   7496:                 &Apache::lonnet::get('environment',['portfolioquota',
                   7497:                                      'inststatus'],$udom,$uname);
1.472     raeburn  7498:             my ($tmp) = keys(%userenv);
                   7499:             if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   7500:                 $quota = $userenv{'portfolioquota'};
1.536     raeburn  7501:                 $inststatus = $userenv{'inststatus'};
1.472     raeburn  7502:             } else {
                   7503:                 undef(%userenv);
                   7504:             }
                   7505:         }
1.536     raeburn  7506:         ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472     raeburn  7507:         if ($quota eq '') {
1.536     raeburn  7508:             $quota = $defquota;
                   7509:             $quotatype = 'default';
                   7510:         } else {
                   7511:             $quotatype = 'custom';
1.472     raeburn  7512:         }
                   7513:     }
1.536     raeburn  7514:     if (wantarray) {
                   7515:         return ($quota,$quotatype,$settingstatus,$defquota);
                   7516:     } else {
                   7517:         return $quota;
                   7518:     }
1.472     raeburn  7519: }
                   7520: 
                   7521: ###############################################
                   7522: 
                   7523: =pod
                   7524: 
                   7525: =item * &default_quota()
                   7526: 
1.536     raeburn  7527: Retrieves default quota assigned for storage of user portfolio files,
                   7528: given an (optional) user's institutional status.
1.472     raeburn  7529: 
                   7530: Incoming parameters:
                   7531: 1. domain
1.536     raeburn  7532: 2. (Optional) institutional status(es).  This is a : separated list of 
                   7533:    status types (e.g., faculty, staff, student etc.)
                   7534:    which apply to the user for whom the default is being retrieved.
                   7535:    If the institutional status string in undefined, the domain
                   7536:    default quota will be returned. 
1.472     raeburn  7537: 
                   7538: Returns:
                   7539: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536     raeburn  7540: 2. (Optional) institutional type which determined the value of the
                   7541:    default quota.
1.472     raeburn  7542: 
                   7543: If a value has been stored in the domain's configuration db,
                   7544: it will return that, otherwise it returns 20 (for backwards 
                   7545: compatibility with domains which have not set up a configuration
                   7546: db file; the original statically defined portfolio quota was 20 Mb). 
                   7547: 
1.536     raeburn  7548: If the user's status includes multiple types (e.g., staff and student),
                   7549: the largest default quota which applies to the user determines the
                   7550: default quota returned.
                   7551: 
1.780     raeburn  7552: =back
                   7553: 
1.472     raeburn  7554: =cut
                   7555: 
                   7556: ###############################################
                   7557: 
                   7558: 
                   7559: sub default_quota {
1.536     raeburn  7560:     my ($udom,$inststatus) = @_;
                   7561:     my ($defquota,$settingstatus);
                   7562:     my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622     raeburn  7563:                                             ['quotas'],$udom);
                   7564:     if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536     raeburn  7565:         if ($inststatus ne '') {
1.765     raeburn  7566:             my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536     raeburn  7567:             foreach my $item (@statuses) {
1.711     raeburn  7568:                 if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
                   7569:                     if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
                   7570:                         if ($defquota eq '') {
                   7571:                             $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
                   7572:                             $settingstatus = $item;
                   7573:                         } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
                   7574:                             $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
                   7575:                             $settingstatus = $item;
                   7576:                         }
                   7577:                     }
                   7578:                 } else {
                   7579:                     if ($quotahash{'quotas'}{$item} ne '') {
                   7580:                         if ($defquota eq '') {
                   7581:                             $defquota = $quotahash{'quotas'}{$item};
                   7582:                             $settingstatus = $item;
                   7583:                         } elsif ($quotahash{'quotas'}{$item} > $defquota) {
                   7584:                             $defquota = $quotahash{'quotas'}{$item};
                   7585:                             $settingstatus = $item;
                   7586:                         }
1.536     raeburn  7587:                     }
                   7588:                 }
                   7589:             }
                   7590:         }
                   7591:         if ($defquota eq '') {
1.711     raeburn  7592:             if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
                   7593:                 $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
                   7594:             } else {
                   7595:                 $defquota = $quotahash{'quotas'}{'default'};
                   7596:             }
1.536     raeburn  7597:             $settingstatus = 'default';
                   7598:         }
                   7599:     } else {
                   7600:         $settingstatus = 'default';
                   7601:         $defquota = 20;
                   7602:     }
                   7603:     if (wantarray) {
                   7604:         return ($defquota,$settingstatus);
1.472     raeburn  7605:     } else {
1.536     raeburn  7606:         return $defquota;
1.472     raeburn  7607:     }
                   7608: }
                   7609: 
1.384     raeburn  7610: sub get_secgrprole_info {
                   7611:     my ($cdom,$cnum,$needroles,$type)  = @_;
                   7612:     my %sections_count = &get_sections($cdom,$cnum);
                   7613:     my @sections =  (sort {$a <=> $b} keys(%sections_count));
                   7614:     my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
                   7615:     my @groups = sort(keys(%curr_groups));
                   7616:     my $allroles = [];
                   7617:     my $rolehash;
                   7618:     my $accesshash = {
                   7619:                      active => 'Currently has access',
                   7620:                      future => 'Will have future access',
                   7621:                      previous => 'Previously had access',
                   7622:                   };
                   7623:     if ($needroles) {
                   7624:         $rolehash = {'all' => 'all'};
1.385     albertel 7625:         my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   7626: 	if (&Apache::lonnet::error(%user_roles)) {
                   7627: 	    undef(%user_roles);
                   7628: 	}
                   7629:         foreach my $item (keys(%user_roles)) {
1.384     raeburn  7630:             my ($role)=split(/\:/,$item,2);
                   7631:             if ($role eq 'cr') { next; }
                   7632:             if ($role =~ /^cr/) {
                   7633:                 $$rolehash{$role} = (split('/',$role))[3];
                   7634:             } else {
                   7635:                 $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
                   7636:             }
                   7637:         }
                   7638:         foreach my $key (sort(keys(%{$rolehash}))) {
                   7639:             push(@{$allroles},$key);
                   7640:         }
                   7641:         push (@{$allroles},'st');
                   7642:         $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
                   7643:     }
                   7644:     return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
                   7645: }
                   7646: 
1.555     raeburn  7647: sub user_picker {
1.627     raeburn  7648:     my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555     raeburn  7649:     my $currdom = $dom;
                   7650:     my %curr_selected = (
                   7651:                         srchin => 'dom',
1.580     raeburn  7652:                         srchby => 'lastname',
1.555     raeburn  7653:                       );
                   7654:     my $srchterm;
1.625     raeburn  7655:     if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555     raeburn  7656:         if ($srch->{'srchby'} ne '') {
                   7657:             $curr_selected{'srchby'} = $srch->{'srchby'};
                   7658:         }
                   7659:         if ($srch->{'srchin'} ne '') {
                   7660:             $curr_selected{'srchin'} = $srch->{'srchin'};
                   7661:         }
                   7662:         if ($srch->{'srchtype'} ne '') {
                   7663:             $curr_selected{'srchtype'} = $srch->{'srchtype'};
                   7664:         }
                   7665:         if ($srch->{'srchdomain'} ne '') {
                   7666:             $currdom = $srch->{'srchdomain'};
                   7667:         }
                   7668:         $srchterm = $srch->{'srchterm'};
                   7669:     }
                   7670:     my %lt=&Apache::lonlocal::texthash(
1.573     raeburn  7671:                     'usr'       => 'Search criteria',
1.563     raeburn  7672:                     'doma'      => 'Domain/institution to search',
1.558     albertel 7673:                     'uname'     => 'username',
                   7674:                     'lastname'  => 'last name',
1.555     raeburn  7675:                     'lastfirst' => 'last name, first name',
1.558     albertel 7676:                     'crs'       => 'in this course',
1.576     raeburn  7677:                     'dom'       => 'in selected LON-CAPA domain', 
1.558     albertel 7678:                     'alc'       => 'all LON-CAPA',
1.573     raeburn  7679:                     'instd'     => 'in institutional directory for selected domain',
1.558     albertel 7680:                     'exact'     => 'is',
                   7681:                     'contains'  => 'contains',
1.569     raeburn  7682:                     'begins'    => 'begins with',
1.571     raeburn  7683:                     'youm'      => "You must include some text to search for.",
                   7684:                     'thte'      => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
                   7685:                     'thet'      => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
                   7686:                     'yomc'      => "You must choose a domain when using an institutional directory search.",
                   7687:                     'ymcd'      => "You must choose a domain when using a domain search.",
                   7688:                     'whus'      => "When using searching by last,first you must include a comma as separator between last name and first name.",
                   7689:                     'whse'      => "When searching by last,first you must include at least one character in the first name.",
                   7690:                      'thfo'     => "The following need to be corrected before the search can be run:",
1.555     raeburn  7691:                                        );
1.563     raeburn  7692:     my $domform = &select_dom_form($currdom,'srchdomain',1,1);
                   7693:     my $srchinsel = ' <select name="srchin">';
1.555     raeburn  7694: 
                   7695:     my @srchins = ('crs','dom','alc','instd');
                   7696: 
                   7697:     foreach my $option (@srchins) {
                   7698:         # FIXME 'alc' option unavailable until 
                   7699:         #       loncreateuser::print_user_query_page()
                   7700:         #       has been completed.
                   7701:         next if ($option eq 'alc');
1.880     raeburn  7702:         next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));  
1.555     raeburn  7703:         next if ($option eq 'crs' && !$env{'request.course.id'});
1.563     raeburn  7704:         if ($curr_selected{'srchin'} eq $option) {
                   7705:             $srchinsel .= ' 
                   7706:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7707:         } else {
                   7708:             $srchinsel .= '
                   7709:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7710:         }
1.555     raeburn  7711:     }
1.563     raeburn  7712:     $srchinsel .= "\n  </select>\n";
1.555     raeburn  7713: 
                   7714:     my $srchbysel =  ' <select name="srchby">';
1.580     raeburn  7715:     foreach my $option ('lastname','lastfirst','uname') {
1.555     raeburn  7716:         if ($curr_selected{'srchby'} eq $option) {
                   7717:             $srchbysel .= '
                   7718:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7719:         } else {
                   7720:             $srchbysel .= '
                   7721:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7722:          }
                   7723:     }
                   7724:     $srchbysel .= "\n  </select>\n";
                   7725: 
                   7726:     my $srchtypesel = ' <select name="srchtype">';
1.580     raeburn  7727:     foreach my $option ('begins','contains','exact') {
1.555     raeburn  7728:         if ($curr_selected{'srchtype'} eq $option) {
                   7729:             $srchtypesel .= '
                   7730:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7731:         } else {
                   7732:             $srchtypesel .= '
                   7733:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7734:         }
                   7735:     }
                   7736:     $srchtypesel .= "\n  </select>\n";
                   7737: 
1.558     albertel 7738:     my ($newuserscript,$new_user_create);
1.556     raeburn  7739: 
                   7740:     if ($forcenewuser) {
1.576     raeburn  7741:         if (ref($srch) eq 'HASH') {
                   7742:             if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627     raeburn  7743:                 if ($cancreate) {
                   7744:                     $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>';
                   7745:                 } else {
1.799     bisitz   7746:                     my $helplink = 'javascript:helpMenu('."'display'".')';
1.627     raeburn  7747:                     my %usertypetext = (
                   7748:                         official   => 'institutional',
                   7749:                         unofficial => 'non-institutional',
                   7750:                     );
1.799     bisitz   7751:                     $new_user_create = '<p class="LC_warning">'
                   7752:                                       .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
                   7753:                                       .' '
                   7754:                                       .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
                   7755:                                           ,'<a href="'.$helplink.'">','</a>')
                   7756:                                       .'</p><br />';
1.627     raeburn  7757:                 }
1.576     raeburn  7758:             }
                   7759:         }
                   7760: 
1.556     raeburn  7761:         $newuserscript = <<"ENDSCRIPT";
                   7762: 
1.570     raeburn  7763: function setSearch(createnew,callingForm) {
1.556     raeburn  7764:     if (createnew == 1) {
1.570     raeburn  7765:         for (var i=0; i<callingForm.srchby.length; i++) {
                   7766:             if (callingForm.srchby.options[i].value == 'uname') {
                   7767:                 callingForm.srchby.selectedIndex = i;
1.556     raeburn  7768:             }
                   7769:         }
1.570     raeburn  7770:         for (var i=0; i<callingForm.srchin.length; i++) {
                   7771:             if ( callingForm.srchin.options[i].value == 'dom') {
                   7772: 		callingForm.srchin.selectedIndex = i;
1.556     raeburn  7773:             }
                   7774:         }
1.570     raeburn  7775:         for (var i=0; i<callingForm.srchtype.length; i++) {
                   7776:             if (callingForm.srchtype.options[i].value == 'exact') {
                   7777:                 callingForm.srchtype.selectedIndex = i;
1.556     raeburn  7778:             }
                   7779:         }
1.570     raeburn  7780:         for (var i=0; i<callingForm.srchdomain.length; i++) {
                   7781:             if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
                   7782:                 callingForm.srchdomain.selectedIndex = i;
1.556     raeburn  7783:             }
                   7784:         }
                   7785:     }
                   7786: }
                   7787: ENDSCRIPT
1.558     albertel 7788: 
1.556     raeburn  7789:     }
                   7790: 
1.555     raeburn  7791:     my $output = <<"END_BLOCK";
1.556     raeburn  7792: <script type="text/javascript">
1.824     bisitz   7793: // <![CDATA[
1.570     raeburn  7794: function validateEntry(callingForm) {
1.558     albertel 7795: 
1.556     raeburn  7796:     var checkok = 1;
1.558     albertel 7797:     var srchin;
1.570     raeburn  7798:     for (var i=0; i<callingForm.srchin.length; i++) {
                   7799: 	if ( callingForm.srchin[i].checked ) {
                   7800: 	    srchin = callingForm.srchin[i].value;
1.558     albertel 7801: 	}
                   7802:     }
                   7803: 
1.570     raeburn  7804:     var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
                   7805:     var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
                   7806:     var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
                   7807:     var srchterm =  callingForm.srchterm.value;
                   7808:     var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556     raeburn  7809:     var msg = "";
                   7810: 
                   7811:     if (srchterm == "") {
                   7812:         checkok = 0;
1.571     raeburn  7813:         msg += "$lt{'youm'}\\n";
1.556     raeburn  7814:     }
                   7815: 
1.569     raeburn  7816:     if (srchtype== 'begins') {
                   7817:         if (srchterm.length < 2) {
                   7818:             checkok = 0;
1.571     raeburn  7819:             msg += "$lt{'thte'}\\n";
1.569     raeburn  7820:         }
                   7821:     }
                   7822: 
1.556     raeburn  7823:     if (srchtype== 'contains') {
                   7824:         if (srchterm.length < 3) {
                   7825:             checkok = 0;
1.571     raeburn  7826:             msg += "$lt{'thet'}\\n";
1.556     raeburn  7827:         }
                   7828:     }
                   7829:     if (srchin == 'instd') {
                   7830:         if (srchdomain == '') {
                   7831:             checkok = 0;
1.571     raeburn  7832:             msg += "$lt{'yomc'}\\n";
1.556     raeburn  7833:         }
                   7834:     }
                   7835:     if (srchin == 'dom') {
                   7836:         if (srchdomain == '') {
                   7837:             checkok = 0;
1.571     raeburn  7838:             msg += "$lt{'ymcd'}\\n";
1.556     raeburn  7839:         }
                   7840:     }
                   7841:     if (srchby == 'lastfirst') {
                   7842:         if (srchterm.indexOf(",") == -1) {
                   7843:             checkok = 0;
1.571     raeburn  7844:             msg += "$lt{'whus'}\\n";
1.556     raeburn  7845:         }
                   7846:         if (srchterm.indexOf(",") == srchterm.length -1) {
                   7847:             checkok = 0;
1.571     raeburn  7848:             msg += "$lt{'whse'}\\n";
1.556     raeburn  7849:         }
                   7850:     }
                   7851:     if (checkok == 0) {
1.571     raeburn  7852:         alert("$lt{'thfo'}\\n"+msg);
1.556     raeburn  7853:         return;
                   7854:     }
                   7855:     if (checkok == 1) {
1.570     raeburn  7856:         callingForm.submit();
1.556     raeburn  7857:     }
                   7858: }
                   7859: 
                   7860: $newuserscript
                   7861: 
1.824     bisitz   7862: // ]]>
1.556     raeburn  7863: </script>
1.558     albertel 7864: 
                   7865: $new_user_create
                   7866: 
1.555     raeburn  7867: END_BLOCK
1.558     albertel 7868: 
1.876     raeburn  7869:     $output .= &Apache::lonhtmlcommon::start_pick_box().
                   7870:                &Apache::lonhtmlcommon::row_title($lt{'doma'}).
                   7871:                $domform.
                   7872:                &Apache::lonhtmlcommon::row_closure().
                   7873:                &Apache::lonhtmlcommon::row_title($lt{'usr'}).
                   7874:                $srchbysel.
                   7875:                $srchtypesel. 
                   7876:                '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
                   7877:                $srchinsel.
                   7878:                &Apache::lonhtmlcommon::row_closure(1). 
                   7879:                &Apache::lonhtmlcommon::end_pick_box().
                   7880:                '<br />';
1.555     raeburn  7881:     return $output;
                   7882: }
                   7883: 
1.612     raeburn  7884: sub user_rule_check {
1.615     raeburn  7885:     my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612     raeburn  7886:     my $response;
                   7887:     if (ref($usershash) eq 'HASH') {
                   7888:         foreach my $user (keys(%{$usershash})) {
                   7889:             my ($uname,$udom) = split(/:/,$user);
                   7890:             next if ($udom eq '' || $uname eq '');
1.615     raeburn  7891:             my ($id,$newuser);
1.612     raeburn  7892:             if (ref($usershash->{$user}) eq 'HASH') {
1.615     raeburn  7893:                 $newuser = $usershash->{$user}->{'newuser'};
1.612     raeburn  7894:                 $id = $usershash->{$user}->{'id'};
                   7895:             }
                   7896:             my $inst_response;
                   7897:             if (ref($checks) eq 'HASH') {
                   7898:                 if (defined($checks->{'username'})) {
1.615     raeburn  7899:                     ($inst_response,%{$inst_results->{$user}}) = 
1.612     raeburn  7900:                         &Apache::lonnet::get_instuser($udom,$uname);
                   7901:                 } elsif (defined($checks->{'id'})) {
1.615     raeburn  7902:                     ($inst_response,%{$inst_results->{$user}}) =
1.612     raeburn  7903:                         &Apache::lonnet::get_instuser($udom,undef,$id);
                   7904:                 }
1.615     raeburn  7905:             } else {
                   7906:                 ($inst_response,%{$inst_results->{$user}}) =
                   7907:                     &Apache::lonnet::get_instuser($udom,$uname);
                   7908:                 return;
1.612     raeburn  7909:             }
1.615     raeburn  7910:             if (!$got_rules->{$udom}) {
1.612     raeburn  7911:                 my %domconfig = &Apache::lonnet::get_dom('configuration',
                   7912:                                                   ['usercreation'],$udom);
                   7913:                 if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615     raeburn  7914:                     foreach my $item ('username','id') {
1.612     raeburn  7915:                         if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
                   7916:                             $$curr_rules{$udom}{$item} = 
                   7917:                                 $domconfig{'usercreation'}{$item.'_rule'};
1.585     raeburn  7918:                         }
                   7919:                     }
                   7920:                 }
1.615     raeburn  7921:                 $got_rules->{$udom} = 1;  
1.585     raeburn  7922:             }
1.612     raeburn  7923:             foreach my $item (keys(%{$checks})) {
                   7924:                 if (ref($$curr_rules{$udom}) eq 'HASH') {
                   7925:                     if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
                   7926:                         if (@{$$curr_rules{$udom}{$item}} > 0) {
                   7927:                             my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
                   7928:                             foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
                   7929:                                 if ($rule_check{$rule}) {
                   7930:                                     $$rulematch{$user}{$item} = $rule;
                   7931:                                     if ($inst_response eq 'ok') {
1.615     raeburn  7932:                                         if (ref($inst_results) eq 'HASH') {
                   7933:                                             if (ref($inst_results->{$user}) eq 'HASH') {
                   7934:                                                 if (keys(%{$inst_results->{$user}}) == 0) {
                   7935:                                                     $$alerts{$item}{$udom}{$uname} = 1;
                   7936:                                                 }
1.612     raeburn  7937:                                             }
                   7938:                                         }
1.615     raeburn  7939:                                     }
                   7940:                                     last;
1.585     raeburn  7941:                                 }
                   7942:                             }
                   7943:                         }
                   7944:                     }
                   7945:                 }
                   7946:             }
                   7947:         }
                   7948:     }
1.612     raeburn  7949:     return;
                   7950: }
                   7951: 
                   7952: sub user_rule_formats {
                   7953:     my ($domain,$domdesc,$curr_rules,$check) = @_;
                   7954:     my %text = ( 
                   7955:                  'username' => 'Usernames',
                   7956:                  'id'       => 'IDs',
                   7957:                );
                   7958:     my $output;
                   7959:     my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
                   7960:     if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
                   7961:         if (@{$ruleorder} > 0) {
                   7962:             $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>';
                   7963:             foreach my $rule (@{$ruleorder}) {
                   7964:                 if (ref($curr_rules) eq 'ARRAY') {
                   7965:                     if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
                   7966:                         if (ref($rules->{$rule}) eq 'HASH') {
                   7967:                             $output .= '<li>'.$rules->{$rule}{'name'}.': '.
                   7968:                                         $rules->{$rule}{'desc'}.'</li>';
                   7969:                         }
                   7970:                     }
                   7971:                 }
                   7972:             }
                   7973:             $output .= '</ul>';
                   7974:         }
                   7975:     }
                   7976:     return $output;
                   7977: }
                   7978: 
                   7979: sub instrule_disallow_msg {
1.615     raeburn  7980:     my ($checkitem,$domdesc,$count,$mode) = @_;
1.612     raeburn  7981:     my $response;
                   7982:     my %text = (
                   7983:                   item   => 'username',
                   7984:                   items  => 'usernames',
                   7985:                   match  => 'matches',
                   7986:                   do     => 'does',
                   7987:                   action => 'a username',
                   7988:                   one    => 'one',
                   7989:                );
                   7990:     if ($count > 1) {
                   7991:         $text{'item'} = 'usernames';
                   7992:         $text{'match'} ='match';
                   7993:         $text{'do'} = 'do';
                   7994:         $text{'action'} = 'usernames',
                   7995:         $text{'one'} = 'ones';
                   7996:     }
                   7997:     if ($checkitem eq 'id') {
                   7998:         $text{'items'} = 'IDs';
                   7999:         $text{'item'} = 'ID';
                   8000:         $text{'action'} = 'an ID';
1.615     raeburn  8001:         if ($count > 1) {
                   8002:             $text{'item'} = 'IDs';
                   8003:             $text{'action'} = 'IDs';
                   8004:         }
1.612     raeburn  8005:     }
1.674     bisitz   8006:     $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  8007:     if ($mode eq 'upload') {
                   8008:         if ($checkitem eq 'username') {
                   8009:             $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'}.");
                   8010:         } elsif ($checkitem eq 'id') {
1.674     bisitz   8011:             $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  8012:         }
1.669     raeburn  8013:     } elsif ($mode eq 'selfcreate') {
                   8014:         if ($checkitem eq 'id') {
                   8015:             $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.");
                   8016:         }
1.615     raeburn  8017:     } else {
                   8018:         if ($checkitem eq 'username') {
                   8019:             $response .= &mt("You must choose $text{'action'} with a different format --  $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
                   8020:         } elsif ($checkitem eq 'id') {
                   8021:             $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.");
                   8022:         }
1.612     raeburn  8023:     }
                   8024:     return $response;
1.585     raeburn  8025: }
                   8026: 
1.624     raeburn  8027: sub personal_data_fieldtitles {
                   8028:     my %fieldtitles = &Apache::lonlocal::texthash (
                   8029:                         id => 'Student/Employee ID',
                   8030:                         permanentemail => 'E-mail address',
                   8031:                         lastname => 'Last Name',
                   8032:                         firstname => 'First Name',
                   8033:                         middlename => 'Middle Name',
                   8034:                         generation => 'Generation',
                   8035:                         gen => 'Generation',
1.765     raeburn  8036:                         inststatus => 'Affiliation',
1.624     raeburn  8037:                    );
                   8038:     return %fieldtitles;
                   8039: }
                   8040: 
1.642     raeburn  8041: sub sorted_inst_types {
                   8042:     my ($dom) = @_;
                   8043:     my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
                   8044:     my $othertitle = &mt('All users');
                   8045:     if ($env{'request.course.id'}) {
1.668     raeburn  8046:         $othertitle  = &mt('Any users');
1.642     raeburn  8047:     }
                   8048:     my @types;
                   8049:     if (ref($order) eq 'ARRAY') {
                   8050:         @types = @{$order};
                   8051:     }
                   8052:     if (@types == 0) {
                   8053:         if (ref($usertypes) eq 'HASH') {
                   8054:             @types = sort(keys(%{$usertypes}));
                   8055:         }
                   8056:     }
                   8057:     if (keys(%{$usertypes}) > 0) {
                   8058:         $othertitle = &mt('Other users');
                   8059:     }
                   8060:     return ($othertitle,$usertypes,\@types);
                   8061: }
                   8062: 
1.645     raeburn  8063: sub get_institutional_codes {
                   8064:     my ($settings,$allcourses,$LC_code) = @_;
                   8065: # Get complete list of course sections to update
                   8066:     my @currsections = ();
                   8067:     my @currxlists = ();
                   8068:     my $coursecode = $$settings{'internal.coursecode'};
                   8069: 
                   8070:     if ($$settings{'internal.sectionnums'} ne '') {
                   8071:         @currsections = split(/,/,$$settings{'internal.sectionnums'});
                   8072:     }
                   8073: 
                   8074:     if ($$settings{'internal.crosslistings'} ne '') {
                   8075:         @currxlists = split(/,/,$$settings{'internal.crosslistings'});
                   8076:     }
                   8077: 
                   8078:     if (@currxlists > 0) {
                   8079:         foreach (@currxlists) {
                   8080:             if (m/^([^:]+):(\w*)$/) {
                   8081:                 unless (grep/^$1$/,@{$allcourses}) {
                   8082:                     push @{$allcourses},$1;
                   8083:                     $$LC_code{$1} = $2;
                   8084:                 }
                   8085:             }
                   8086:         }
                   8087:     }
                   8088:  
                   8089:     if (@currsections > 0) {
                   8090:         foreach (@currsections) {
                   8091:             if (m/^(\w+):(\w*)$/) {
                   8092:                 my $sec = $coursecode.$1;
                   8093:                 my $lc_sec = $2;
                   8094:                 unless (grep/^$sec$/,@{$allcourses}) {
                   8095:                     push @{$allcourses},$sec;
                   8096:                     $$LC_code{$sec} = $lc_sec;
                   8097:                 }
                   8098:             }
                   8099:         }
                   8100:     }
                   8101:     return;
                   8102: }
                   8103: 
1.112     bowersj2 8104: =pod
                   8105: 
1.780     raeburn  8106: =head1 Slot Helpers
                   8107: 
                   8108: =over 4
                   8109: 
                   8110: =item * sorted_slots()
                   8111: 
                   8112: Sorts an array of slot names in order of slot start time (earliest first). 
                   8113: 
                   8114: Inputs:
                   8115: 
                   8116: =over 4
                   8117: 
                   8118: slotsarr  - Reference to array of unsorted slot names.
                   8119: 
                   8120: slots     - Reference to hash of hash, where outer hash keys are slot names.
                   8121: 
1.549     albertel 8122: =back
                   8123: 
1.780     raeburn  8124: Returns:
                   8125: 
                   8126: =over 4
                   8127: 
                   8128: sorted   - An array of slot names sorted by the start time of the slot.
                   8129: 
                   8130: =back
                   8131: 
                   8132: =back
                   8133: 
                   8134: =cut
                   8135: 
                   8136: 
                   8137: sub sorted_slots {
                   8138:     my ($slotsarr,$slots) = @_;
                   8139:     my @sorted;
                   8140:     if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
                   8141:         @sorted =
                   8142:             sort {
                   8143:                      if (ref($slots->{$a}) && ref($slots->{$b})) {
                   8144:                          return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
                   8145:                      }
                   8146:                      if (ref($slots->{$a})) { return -1;}
                   8147:                      if (ref($slots->{$b})) { return 1;}
                   8148:                      return 0;
                   8149:                  } @{$slotsarr};
                   8150:     }
                   8151:     return @sorted;
                   8152: }
                   8153: 
                   8154: 
                   8155: =pod
                   8156: 
1.549     albertel 8157: =head1 HTTP Helpers
                   8158: 
                   8159: =over 4
                   8160: 
1.648     raeburn  8161: =item * &get_unprocessed_cgi($query,$possible_names)
1.112     bowersj2 8162: 
1.258     albertel 8163: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112     bowersj2 8164: $query.  The parameters listed in $possible_names (an array reference),
1.258     albertel 8165: will be set in $env{'form.name'} if they do not already exist.
1.112     bowersj2 8166: 
                   8167: Typically called with $ENV{'QUERY_STRING'} as the first parameter.  
                   8168: $possible_names is an ref to an array of form element names.  As an example:
                   8169: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258     albertel 8170: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112     bowersj2 8171: 
                   8172: =cut
1.1       albertel 8173: 
1.6       albertel 8174: sub get_unprocessed_cgi {
1.25      albertel 8175:   my ($query,$possible_names)= @_;
1.26      matthew  8176:   # $Apache::lonxml::debug=1;
1.356     albertel 8177:   foreach my $pair (split(/&/,$query)) {
                   8178:     my ($name, $value) = split(/=/,$pair);
1.369     www      8179:     $name = &unescape($name);
1.25      albertel 8180:     if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
                   8181:       $value =~ tr/+/ /;
                   8182:       $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258     albertel 8183:       unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25      albertel 8184:     }
1.16      harris41 8185:   }
1.6       albertel 8186: }
                   8187: 
1.112     bowersj2 8188: =pod
                   8189: 
1.648     raeburn  8190: =item * &cacheheader() 
1.112     bowersj2 8191: 
                   8192: returns cache-controlling header code
                   8193: 
                   8194: =cut
                   8195: 
1.7       albertel 8196: sub cacheheader {
1.258     albertel 8197:     unless ($env{'request.method'} eq 'GET') { return ''; }
1.216     albertel 8198:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
                   8199:     my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7       albertel 8200:                 <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
                   8201:                 <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216     albertel 8202:     return $output;
1.7       albertel 8203: }
                   8204: 
1.112     bowersj2 8205: =pod
                   8206: 
1.648     raeburn  8207: =item * &no_cache($r) 
1.112     bowersj2 8208: 
                   8209: specifies header code to not have cache
                   8210: 
                   8211: =cut
                   8212: 
1.9       albertel 8213: sub no_cache {
1.216     albertel 8214:     my ($r) = @_;
                   8215:     if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258     albertel 8216: 	$env{'request.method'} ne 'GET') { return ''; }
1.216     albertel 8217:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
                   8218:     $r->no_cache(1);
                   8219:     $r->header_out("Expires" => $date);
                   8220:     $r->header_out("Pragma" => "no-cache");
1.123     www      8221: }
                   8222: 
                   8223: sub content_type {
1.181     albertel 8224:     my ($r,$type,$charset) = @_;
1.299     foxr     8225:     if ($r) {
                   8226: 	#  Note that printout.pl calls this with undef for $r.
                   8227: 	&no_cache($r);
                   8228:     }
1.258     albertel 8229:     if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181     albertel 8230:     unless ($charset) {
                   8231: 	$charset=&Apache::lonlocal::current_encoding;
                   8232:     }
                   8233:     if ($charset) { $type.='; charset='.$charset; }
                   8234:     if ($r) {
                   8235: 	$r->content_type($type);
                   8236:     } else {
                   8237: 	print("Content-type: $type\n\n");
                   8238:     }
1.9       albertel 8239: }
1.25      albertel 8240: 
1.112     bowersj2 8241: =pod
                   8242: 
1.648     raeburn  8243: =item * &add_to_env($name,$value) 
1.112     bowersj2 8244: 
1.258     albertel 8245: adds $name to the %env hash with value
1.112     bowersj2 8246: $value, if $name already exists, the entry is converted to an array
                   8247: reference and $value is added to the array.
                   8248: 
                   8249: =cut
                   8250: 
1.25      albertel 8251: sub add_to_env {
                   8252:   my ($name,$value)=@_;
1.258     albertel 8253:   if (defined($env{$name})) {
                   8254:     if (ref($env{$name})) {
1.25      albertel 8255:       #already have multiple values
1.258     albertel 8256:       push(@{ $env{$name} },$value);
1.25      albertel 8257:     } else {
                   8258:       #first time seeing multiple values, convert hash entry to an arrayref
1.258     albertel 8259:       my $first=$env{$name};
                   8260:       undef($env{$name});
                   8261:       push(@{ $env{$name} },$first,$value);
1.25      albertel 8262:     }
                   8263:   } else {
1.258     albertel 8264:     $env{$name}=$value;
1.25      albertel 8265:   }
1.31      albertel 8266: }
1.149     albertel 8267: 
                   8268: =pod
                   8269: 
1.648     raeburn  8270: =item * &get_env_multiple($name) 
1.149     albertel 8271: 
1.258     albertel 8272: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149     albertel 8273: values may be defined and end up as an array ref.
                   8274: 
                   8275: returns an array of values
                   8276: 
                   8277: =cut
                   8278: 
                   8279: sub get_env_multiple {
                   8280:     my ($name) = @_;
                   8281:     my @values;
1.258     albertel 8282:     if (defined($env{$name})) {
1.149     albertel 8283:         # exists is it an array
1.258     albertel 8284:         if (ref($env{$name})) {
                   8285:             @values=@{ $env{$name} };
1.149     albertel 8286:         } else {
1.258     albertel 8287:             $values[0]=$env{$name};
1.149     albertel 8288:         }
                   8289:     }
                   8290:     return(@values);
                   8291: }
                   8292: 
1.660     raeburn  8293: sub ask_for_embedded_content {
                   8294:     my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
                   8295:     my $upload_output = '
                   8296:    <form name="upload_embedded" action="'.$actionurl.'"
                   8297:                   method="post" enctype="multipart/form-data">';
                   8298:     $upload_output .= $state;
1.661     raeburn  8299:     $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
1.660     raeburn  8300: 
                   8301:     my $num = 0;
                   8302:     foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
                   8303:         $upload_output .= &start_data_table_row().
                   8304:             '<td>'.$embed_file.'</td><td>';
                   8305:         if ($args->{'ignore_remote_references'}
                   8306:             && $embed_file =~ m{^\w+://}) {
                   8307:             $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
                   8308:         } elsif ($args->{'error_on_invalid_names'}
                   8309:             && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
                   8310: 
                   8311:             $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
                   8312: 
                   8313:         } else {
                   8314:             $upload_output .='
1.661     raeburn  8315:            <input name="embedded_item_'.$num.'" type="file" value="" />
1.660     raeburn  8316:            <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
                   8317:             my $attrib = join(':',@{$$allfiles{$embed_file}});
                   8318:             $upload_output .=
                   8319:                 "\n\t\t".
                   8320:                 '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
                   8321:                 $attrib.'" />';
                   8322:             if (exists($$codebase{$embed_file})) {
                   8323:                 $upload_output .=
                   8324:                     "\n\t\t".
                   8325:                     '<input name="codebase_'.$num.'" type="hidden" value="'.
                   8326:                     &escape($$codebase{$embed_file}).'" />';
                   8327:             }
                   8328:         }
                   8329:         $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
                   8330:         $num++;
                   8331:     }
                   8332:     $upload_output .= &Apache::loncommon::end_data_table().'<br />
                   8333:    <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
                   8334:    <input type ="submit" value="'.&mt('Upload Listed Files').'" />
                   8335:    '.&mt('(only files for which a location has been provided will be uploaded)').'
                   8336:    </form>';
                   8337:     return $upload_output;
                   8338: }
                   8339: 
1.661     raeburn  8340: sub upload_embedded {
                   8341:     my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
                   8342:         $current_disk_usage) = @_;
                   8343:     my $output;
                   8344:     for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
                   8345:         next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
                   8346:         my $orig_uploaded_filename =
                   8347:             $env{'form.embedded_item_'.$i.'.filename'};
                   8348: 
                   8349:         $env{'form.embedded_orig_'.$i} =
                   8350:             &unescape($env{'form.embedded_orig_'.$i});
                   8351:         my ($path,$fname) =
                   8352:             ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
                   8353:         # no path, whole string is fname
                   8354:         if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
                   8355: 
                   8356:         $path = $env{'form.currentpath'}.$path;
                   8357:         $fname = &Apache::lonnet::clean_filename($fname);
                   8358:         # See if there is anything left
                   8359:         next if ($fname eq '');
                   8360: 
                   8361:         # Check if file already exists as a file or directory.
                   8362:         my ($state,$msg);
                   8363:         if ($context eq 'portfolio') {
                   8364:             my $port_path = $dirpath;
                   8365:             if ($group ne '') {
                   8366:                 $port_path = "groups/$group/$port_path";
                   8367:             }
                   8368:             ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
                   8369:                                               $dir_root,$port_path,$disk_quota,
                   8370:                                               $current_disk_usage,$uname,$udom);
                   8371:             if ($state eq 'will_exceed_quota'
                   8372:                 || $state eq 'file_locked'
                   8373:                 || $state eq 'file_exists' ) {
                   8374:                 $output .= $msg;
                   8375:                 next;
                   8376:             }
                   8377:         } elsif (($context eq 'author') || ($context eq 'testbank')) {
                   8378:             ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
                   8379:             if ($state eq 'exists') {
                   8380:                 $output .= $msg;
                   8381:                 next;
                   8382:             }
                   8383:         }
                   8384:         # Check if extension is valid
                   8385:         if (($fname =~ /\.(\w+)$/) &&
                   8386:             (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
                   8387:             $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
                   8388:             next;
                   8389:         } elsif (($fname =~ /\.(\w+)$/) &&
                   8390:                  (!defined(&Apache::loncommon::fileembstyle($1)))) {
                   8391:             $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
                   8392:             next;
                   8393:         } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
                   8394:             $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
                   8395:             next;
                   8396:         }
                   8397: 
                   8398:         $env{'form.embedded_item_'.$i.'.filename'}=$fname;
                   8399:         if ($context eq 'portfolio') {
                   8400:             my $result=
                   8401:                 &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
                   8402:                                                 $dirpath.$path);
                   8403:             if ($result !~ m|^/uploaded/|) {
                   8404:                 $output .= '<span class="LC_error">'
                   8405:                       .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
                   8406:                            ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
                   8407:                       .'</span><br />';
                   8408:                 next;
                   8409:             } else {
                   8410:                 $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
                   8411:                            $path.$fname.'</span>').'</p>';     
                   8412:             }
                   8413:         } else {
                   8414: # Save the file
                   8415:             my $target = $env{'form.embedded_item_'.$i};
                   8416:             my $fullpath = $dir_root.$dirpath.'/'.$path;
                   8417:             my $dest = $fullpath.$fname;
                   8418:             my $url = $url_root.$dirpath.'/'.$path.$fname;
                   8419:             my @parts=split(/\//,$fullpath);
                   8420:             my $count;
                   8421:             my $filepath = $dir_root;
                   8422:             for ($count=4;$count<=$#parts;$count++) {
                   8423:                 $filepath .= "/$parts[$count]";
                   8424:                 if ((-e $filepath)!=1) {
                   8425:                     mkdir($filepath,0770);
                   8426:                 }
                   8427:             }
                   8428:             my $fh;
                   8429:             if (!open($fh,'>'.$dest)) {
                   8430:                 &Apache::lonnet::logthis('Failed to create '.$dest);
                   8431:                 $output .= '<span class="LC_error">'.
                   8432:                            &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
                   8433:                            '</span><br />';
                   8434:             } else {
                   8435:                 if (!print $fh $env{'form.embedded_item_'.$i}) {
                   8436:                     &Apache::lonnet::logthis('Failed to write to '.$dest);
                   8437:                     $output .= '<span class="LC_error">'.
                   8438:                               &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
                   8439:                               '</span><br />';
                   8440:                 } else {
                   8441:                     if ($context eq 'testbank') {
                   8442:                         $output .= &mt('Embedded file uploaded successfully:').
                   8443:                                    '&nbsp;<a href="'.$url.'">'.
                   8444:                                    $orig_uploaded_filename.'</a><br />';
                   8445:                     } else {
1.705     tempelho 8446:                         $output .= '<span class=\"LC_fontsize_large\">'.
1.661     raeburn  8447:                                    &mt('View embedded file: [_1]','<a href="'.$url.'">'.
1.705     tempelho 8448:                                    $orig_uploaded_filename.'</a>').'</span><br />';
1.661     raeburn  8449:                     }
                   8450:                 }
                   8451:                 close($fh);
                   8452:             }
                   8453:         }
                   8454:     }
                   8455:     return $output;
                   8456: }
                   8457: 
                   8458: sub check_for_existing {
                   8459:     my ($path,$fname,$element) = @_;
                   8460:     my ($state,$msg);
                   8461:     if (-d $path.'/'.$fname) {
                   8462:         $state = 'exists';
                   8463:         $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
                   8464:     } elsif (-e $path.'/'.$fname) {
                   8465:         $state = 'exists';
                   8466:         $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
                   8467:     }
                   8468:     if ($state eq 'exists') {
                   8469:         $msg = '<span class="LC_error">'.$msg.'</span><br />';
                   8470:     }
                   8471:     return ($state,$msg);
                   8472: }
                   8473: 
                   8474: sub check_for_upload {
                   8475:     my ($path,$fname,$group,$element,$portfolio_root,$port_path,
                   8476:         $disk_quota,$current_disk_usage,$uname,$udom) = @_;
                   8477:     my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
                   8478:     my $getpropath = 1;
                   8479:     my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
                   8480:                                             $getpropath);
                   8481:     my $found_file = 0;
                   8482:     my $locked_file = 0;
                   8483:     foreach my $line (@dir_list) {
                   8484:         my ($file_name)=split(/\&/,$line,2);
                   8485:         if ($file_name eq $fname){
                   8486:             $file_name = $path.$file_name;
                   8487:             if ($group ne '') {
                   8488:                 $file_name = $group.$file_name;
                   8489:             }
                   8490:             $found_file = 1;
                   8491:             if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
                   8492:                 $locked_file = 1;
                   8493:             }
                   8494:         }
                   8495:     }
                   8496:     if (($current_disk_usage + $filesize) > $disk_quota){
                   8497:         my $msg = '<span class="LC_error">'.
                   8498:                 &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
                   8499:                   '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
                   8500:         return ('will_exceed_quota',$msg);
                   8501:     } elsif ($found_file) {
                   8502:         if ($locked_file) {
                   8503:             my $msg = '<span class="LC_error">';
                   8504:             $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>');
                   8505:             $msg .= '</span><br />';
                   8506:             $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
                   8507:             return ('file_locked',$msg);
                   8508:         } else {
                   8509:             my $msg = '<span class="LC_error">';
                   8510:             $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'});
                   8511:             $msg .= '</span>';
                   8512:             $msg .= '<br />';
                   8513:             $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
                   8514:             return ('file_exists',$msg);
                   8515:         }
                   8516:     }
                   8517: }
                   8518: 
1.31      albertel 8519: 
1.41      ng       8520: =pod
1.45      matthew  8521: 
1.464     albertel 8522: =back
1.41      ng       8523: 
1.112     bowersj2 8524: =head1 CSV Upload/Handling functions
1.38      albertel 8525: 
1.41      ng       8526: =over 4
                   8527: 
1.648     raeburn  8528: =item * &upfile_store($r)
1.41      ng       8529: 
                   8530: Store uploaded file, $r should be the HTTP Request object,
1.258     albertel 8531: needs $env{'form.upfile'}
1.41      ng       8532: returns $datatoken to be put into hidden field
                   8533: 
                   8534: =cut
1.31      albertel 8535: 
                   8536: sub upfile_store {
                   8537:     my $r=shift;
1.258     albertel 8538:     $env{'form.upfile'}=~s/\r/\n/gs;
                   8539:     $env{'form.upfile'}=~s/\f/\n/gs;
                   8540:     $env{'form.upfile'}=~s/\n+/\n/gs;
                   8541:     $env{'form.upfile'}=~s/\n+$//gs;
1.31      albertel 8542: 
1.258     albertel 8543:     my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
                   8544: 	'_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31      albertel 8545:     {
1.158     raeburn  8546:         my $datafile = $r->dir_config('lonDaemons').
                   8547:                            '/tmp/'.$datatoken.'.tmp';
                   8548:         if ( open(my $fh,">$datafile") ) {
1.258     albertel 8549:             print $fh $env{'form.upfile'};
1.158     raeburn  8550:             close($fh);
                   8551:         }
1.31      albertel 8552:     }
                   8553:     return $datatoken;
                   8554: }
                   8555: 
1.56      matthew  8556: =pod
                   8557: 
1.648     raeburn  8558: =item * &load_tmp_file($r)
1.41      ng       8559: 
                   8560: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258     albertel 8561: needs $env{'form.datatoken'},
                   8562: sets $env{'form.upfile'} to the contents of the file
1.41      ng       8563: 
                   8564: =cut
1.31      albertel 8565: 
                   8566: sub load_tmp_file {
                   8567:     my $r=shift;
                   8568:     my @studentdata=();
                   8569:     {
1.158     raeburn  8570:         my $studentfile = $r->dir_config('lonDaemons').
1.258     albertel 8571:                               '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158     raeburn  8572:         if ( open(my $fh,"<$studentfile") ) {
                   8573:             @studentdata=<$fh>;
                   8574:             close($fh);
                   8575:         }
1.31      albertel 8576:     }
1.258     albertel 8577:     $env{'form.upfile'}=join('',@studentdata);
1.31      albertel 8578: }
                   8579: 
1.56      matthew  8580: =pod
                   8581: 
1.648     raeburn  8582: =item * &upfile_record_sep()
1.41      ng       8583: 
                   8584: Separate uploaded file into records
                   8585: returns array of records,
1.258     albertel 8586: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41      ng       8587: 
                   8588: =cut
1.31      albertel 8589: 
                   8590: sub upfile_record_sep {
1.258     albertel 8591:     if ($env{'form.upfiletype'} eq 'xml') {
1.31      albertel 8592:     } else {
1.248     albertel 8593: 	my @records;
1.258     albertel 8594: 	foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248     albertel 8595: 	    if ($line=~/^\s*$/) { next; }
                   8596: 	    push(@records,$line);
                   8597: 	}
                   8598: 	return @records;
1.31      albertel 8599:     }
                   8600: }
                   8601: 
1.56      matthew  8602: =pod
                   8603: 
1.648     raeburn  8604: =item * &record_sep($record)
1.41      ng       8605: 
1.258     albertel 8606: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41      ng       8607: 
                   8608: =cut
                   8609: 
1.263     www      8610: sub takeleft {
                   8611:     my $index=shift;
                   8612:     return substr('0000'.$index,-4,4);
                   8613: }
                   8614: 
1.31      albertel 8615: sub record_sep {
                   8616:     my $record=shift;
                   8617:     my %components=();
1.258     albertel 8618:     if ($env{'form.upfiletype'} eq 'xml') {
                   8619:     } elsif ($env{'form.upfiletype'} eq 'space') {
1.31      albertel 8620:         my $i=0;
1.356     albertel 8621:         foreach my $field (split(/\s+/,$record)) {
1.31      albertel 8622:             $field=~s/^(\"|\')//;
                   8623:             $field=~s/(\"|\')$//;
1.263     www      8624:             $components{&takeleft($i)}=$field;
1.31      albertel 8625:             $i++;
                   8626:         }
1.258     albertel 8627:     } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31      albertel 8628:         my $i=0;
1.356     albertel 8629:         foreach my $field (split(/\t/,$record)) {
1.31      albertel 8630:             $field=~s/^(\"|\')//;
                   8631:             $field=~s/(\"|\')$//;
1.263     www      8632:             $components{&takeleft($i)}=$field;
1.31      albertel 8633:             $i++;
                   8634:         }
                   8635:     } else {
1.561     www      8636:         my $separator=',';
1.480     banghart 8637:         if ($env{'form.upfiletype'} eq 'semisv') {
1.561     www      8638:             $separator=';';
1.480     banghart 8639:         }
1.31      albertel 8640:         my $i=0;
1.561     www      8641: # the character we are looking for to indicate the end of a quote or a record 
                   8642:         my $looking_for=$separator;
                   8643: # do not add the characters to the fields
                   8644:         my $ignore=0;
                   8645: # we just encountered a separator (or the beginning of the record)
                   8646:         my $just_found_separator=1;
                   8647: # store the field we are working on here
                   8648:         my $field='';
                   8649: # work our way through all characters in record
                   8650:         foreach my $character ($record=~/(.)/g) {
                   8651:             if ($character eq $looking_for) {
                   8652:                if ($character ne $separator) {
                   8653: # Found the end of a quote, again looking for separator
                   8654:                   $looking_for=$separator;
                   8655:                   $ignore=1;
                   8656:                } else {
                   8657: # Found a separator, store away what we got
                   8658:                   $components{&takeleft($i)}=$field;
                   8659: 	          $i++;
                   8660:                   $just_found_separator=1;
                   8661:                   $ignore=0;
                   8662:                   $field='';
                   8663:                }
                   8664:                next;
                   8665:             }
                   8666: # single or double quotation marks after a separator indicate beginning of a quote
                   8667: # we are now looking for the end of the quote and need to ignore separators
                   8668:             if ((($character eq '"') || ($character eq "'")) && ($just_found_separator))  {
                   8669:                $looking_for=$character;
                   8670:                next;
                   8671:             }
                   8672: # ignore would be true after we reached the end of a quote
                   8673:             if ($ignore) { next; }
                   8674:             if (($just_found_separator) && ($character=~/\s/)) { next; }
                   8675:             $field.=$character;
                   8676:             $just_found_separator=0; 
1.31      albertel 8677:         }
1.561     www      8678: # catch the very last entry, since we never encountered the separator
                   8679:         $components{&takeleft($i)}=$field;
1.31      albertel 8680:     }
                   8681:     return %components;
                   8682: }
                   8683: 
1.144     matthew  8684: ######################################################
                   8685: ######################################################
                   8686: 
1.56      matthew  8687: =pod
                   8688: 
1.648     raeburn  8689: =item * &upfile_select_html()
1.41      ng       8690: 
1.144     matthew  8691: Return HTML code to select a file from the users machine and specify 
                   8692: the file type.
1.41      ng       8693: 
                   8694: =cut
                   8695: 
1.144     matthew  8696: ######################################################
                   8697: ######################################################
1.31      albertel 8698: sub upfile_select_html {
1.144     matthew  8699:     my %Types = (
                   8700:                  csv   => &mt('CSV (comma separated values, spreadsheet)'),
1.480     banghart 8701:                  semisv => &mt('Semicolon separated values'),
1.144     matthew  8702:                  space => &mt('Space separated'),
                   8703:                  tab   => &mt('Tabulator separated'),
                   8704: #                 xml   => &mt('HTML/XML'),
                   8705:                  );
                   8706:     my $Str = '<input type="file" name="upfile" size="50" />'.
1.727     riegler  8707:         '<br />'.&mt('Type').': <select name="upfiletype">';
1.144     matthew  8708:     foreach my $type (sort(keys(%Types))) {
                   8709:         $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
                   8710:     }
                   8711:     $Str .= "</select>\n";
                   8712:     return $Str;
1.31      albertel 8713: }
                   8714: 
1.301     albertel 8715: sub get_samples {
                   8716:     my ($records,$toget) = @_;
                   8717:     my @samples=({});
                   8718:     my $got=0;
                   8719:     foreach my $rec (@$records) {
                   8720: 	my %temp = &record_sep($rec);
                   8721: 	if (! grep(/\S/, values(%temp))) { next; }
                   8722: 	if (%temp) {
                   8723: 	    $samples[$got]=\%temp;
                   8724: 	    $got++;
                   8725: 	    if ($got == $toget) { last; }
                   8726: 	}
                   8727:     }
                   8728:     return \@samples;
                   8729: }
                   8730: 
1.144     matthew  8731: ######################################################
                   8732: ######################################################
                   8733: 
1.56      matthew  8734: =pod
                   8735: 
1.648     raeburn  8736: =item * &csv_print_samples($r,$records)
1.41      ng       8737: 
                   8738: Prints a table of sample values from each column uploaded $r is an
                   8739: Apache Request ref, $records is an arrayref from
                   8740: &Apache::loncommon::upfile_record_sep
                   8741: 
                   8742: =cut
                   8743: 
1.144     matthew  8744: ######################################################
                   8745: ######################################################
1.31      albertel 8746: sub csv_print_samples {
                   8747:     my ($r,$records) = @_;
1.662     bisitz   8748:     my $samples = &get_samples($records,5);
1.301     albertel 8749: 
1.594     raeburn  8750:     $r->print(&mt('Samples').'<br />'.&start_data_table().
                   8751:               &start_data_table_header_row());
1.356     albertel 8752:     foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) { 
1.845     bisitz   8753:         $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594     raeburn  8754:     $r->print(&end_data_table_header_row());
1.301     albertel 8755:     foreach my $hash (@$samples) {
1.594     raeburn  8756: 	$r->print(&start_data_table_row());
1.356     albertel 8757: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31      albertel 8758: 	    $r->print('<td>');
1.356     albertel 8759: 	    if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31      albertel 8760: 	    $r->print('</td>');
                   8761: 	}
1.594     raeburn  8762: 	$r->print(&end_data_table_row());
1.31      albertel 8763:     }
1.594     raeburn  8764:     $r->print(&end_data_table().'<br />'."\n");
1.31      albertel 8765: }
                   8766: 
1.144     matthew  8767: ######################################################
                   8768: ######################################################
                   8769: 
1.56      matthew  8770: =pod
                   8771: 
1.648     raeburn  8772: =item * &csv_print_select_table($r,$records,$d)
1.41      ng       8773: 
                   8774: Prints a table to create associations between values and table columns.
1.144     matthew  8775: 
1.41      ng       8776: $r is an Apache Request ref,
                   8777: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174     matthew  8778: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41      ng       8779: 
                   8780: =cut
                   8781: 
1.144     matthew  8782: ######################################################
                   8783: ######################################################
1.31      albertel 8784: sub csv_print_select_table {
                   8785:     my ($r,$records,$d) = @_;
1.301     albertel 8786:     my $i=0;
                   8787:     my $samples = &get_samples($records,1);
1.144     matthew  8788:     $r->print(&mt('Associate columns with student attributes.')."\n".
1.594     raeburn  8789: 	      &start_data_table().&start_data_table_header_row().
1.144     matthew  8790:               '<th>'.&mt('Attribute').'</th>'.
1.594     raeburn  8791:               '<th>'.&mt('Column').'</th>'.
                   8792:               &end_data_table_header_row()."\n");
1.356     albertel 8793:     foreach my $array_ref (@$d) {
                   8794: 	my ($value,$display,$defaultcol)=@{ $array_ref };
1.729     raeburn  8795: 	$r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31      albertel 8796: 
1.875     bisitz   8797: 	$r->print('<td><select name="f'.$i.'"'.
1.32      matthew  8798: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.31      albertel 8799: 	$r->print('<option value="none"></option>');
1.356     albertel 8800: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
                   8801: 	    $r->print('<option value="'.$sample.'"'.
                   8802:                       ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662     bisitz   8803:                       '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31      albertel 8804: 	}
1.594     raeburn  8805: 	$r->print('</select></td>'.&end_data_table_row()."\n");
1.31      albertel 8806: 	$i++;
                   8807:     }
1.594     raeburn  8808:     $r->print(&end_data_table());
1.31      albertel 8809:     $i--;
                   8810:     return $i;
                   8811: }
1.56      matthew  8812: 
1.144     matthew  8813: ######################################################
                   8814: ######################################################
                   8815: 
1.56      matthew  8816: =pod
1.31      albertel 8817: 
1.648     raeburn  8818: =item * &csv_samples_select_table($r,$records,$d)
1.41      ng       8819: 
                   8820: Prints a table of sample values from the upload and can make associate samples to internal names.
                   8821: 
                   8822: $r is an Apache Request ref,
                   8823: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
                   8824: $d is an array of 2 element arrays (internal name, displayed name)
                   8825: 
                   8826: =cut
                   8827: 
1.144     matthew  8828: ######################################################
                   8829: ######################################################
1.31      albertel 8830: sub csv_samples_select_table {
                   8831:     my ($r,$records,$d) = @_;
                   8832:     my $i=0;
1.144     matthew  8833:     #
1.662     bisitz   8834:     my $max_samples = 5;
                   8835:     my $samples = &get_samples($records,$max_samples);
1.594     raeburn  8836:     $r->print(&start_data_table().
                   8837:               &start_data_table_header_row().'<th>'.
                   8838:               &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
                   8839:               &end_data_table_header_row());
1.301     albertel 8840: 
                   8841:     foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594     raeburn  8842: 	$r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32      matthew  8843: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.301     albertel 8844: 	foreach my $option (@$d) {
                   8845: 	    my ($value,$display,$defaultcol)=@{ $option };
1.174     matthew  8846: 	    $r->print('<option value="'.$value.'"'.
1.253     albertel 8847:                       ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174     matthew  8848:                       $display.'</option>');
1.31      albertel 8849: 	}
                   8850: 	$r->print('</select></td><td>');
1.662     bisitz   8851: 	foreach my $line (0..($max_samples-1)) {
1.301     albertel 8852: 	    if (defined($samples->[$line]{$key})) { 
                   8853: 		$r->print($samples->[$line]{$key}."<br />\n"); 
                   8854: 	    }
                   8855: 	}
1.594     raeburn  8856: 	$r->print('</td>'.&end_data_table_row());
1.31      albertel 8857: 	$i++;
                   8858:     }
1.594     raeburn  8859:     $r->print(&end_data_table());
1.31      albertel 8860:     $i--;
                   8861:     return($i);
1.115     matthew  8862: }
                   8863: 
1.144     matthew  8864: ######################################################
                   8865: ######################################################
                   8866: 
1.115     matthew  8867: =pod
                   8868: 
1.648     raeburn  8869: =item * &clean_excel_name($name)
1.115     matthew  8870: 
                   8871: Returns a replacement for $name which does not contain any illegal characters.
                   8872: 
                   8873: =cut
                   8874: 
1.144     matthew  8875: ######################################################
                   8876: ######################################################
1.115     matthew  8877: sub clean_excel_name {
                   8878:     my ($name) = @_;
                   8879:     $name =~ s/[:\*\?\/\\]//g;
                   8880:     if (length($name) > 31) {
                   8881:         $name = substr($name,0,31);
                   8882:     }
                   8883:     return $name;
1.25      albertel 8884: }
1.84      albertel 8885: 
1.85      albertel 8886: =pod
                   8887: 
1.648     raeburn  8888: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85      albertel 8889: 
                   8890: Returns either 1 or undef
                   8891: 
                   8892: 1 if the part is to be hidden, undef if it is to be shown
                   8893: 
                   8894: Arguments are:
                   8895: 
                   8896: $id the id of the part to be checked
                   8897: $symb, optional the symb of the resource to check
                   8898: $udom, optional the domain of the user to check for
                   8899: $uname, optional the username of the user to check for
                   8900: 
                   8901: =cut
1.84      albertel 8902: 
                   8903: sub check_if_partid_hidden {
                   8904:     my ($id,$symb,$udom,$uname) = @_;
1.133     albertel 8905:     my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84      albertel 8906: 					 $symb,$udom,$uname);
1.141     albertel 8907:     my $truth=1;
                   8908:     #if the string starts with !, then the list is the list to show not hide
                   8909:     if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84      albertel 8910:     my @hiddenlist=split(/,/,$hiddenparts);
                   8911:     foreach my $checkid (@hiddenlist) {
1.141     albertel 8912: 	if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84      albertel 8913:     }
1.141     albertel 8914:     return !$truth;
1.84      albertel 8915: }
1.127     matthew  8916: 
1.138     matthew  8917: 
                   8918: ############################################################
                   8919: ############################################################
                   8920: 
                   8921: =pod
                   8922: 
1.157     matthew  8923: =back 
                   8924: 
1.138     matthew  8925: =head1 cgi-bin script and graphing routines
                   8926: 
1.157     matthew  8927: =over 4
                   8928: 
1.648     raeburn  8929: =item * &get_cgi_id()
1.138     matthew  8930: 
                   8931: Inputs: none
                   8932: 
                   8933: Returns an id which can be used to pass environment variables
                   8934: to various cgi-bin scripts.  These environment variables will
                   8935: be removed from the users environment after a given time by
                   8936: the routine &Apache::lonnet::transfer_profile_to_env.
                   8937: 
                   8938: =cut
                   8939: 
                   8940: ############################################################
                   8941: ############################################################
1.152     albertel 8942: my $uniq=0;
1.136     matthew  8943: sub get_cgi_id {
1.154     albertel 8944:     $uniq=($uniq+1)%100000;
1.280     albertel 8945:     return (time.'_'.$$.'_'.$uniq);
1.136     matthew  8946: }
                   8947: 
1.127     matthew  8948: ############################################################
                   8949: ############################################################
                   8950: 
                   8951: =pod
                   8952: 
1.648     raeburn  8953: =item * &DrawBarGraph()
1.127     matthew  8954: 
1.138     matthew  8955: Facilitates the plotting of data in a (stacked) bar graph.
                   8956: Puts plot definition data into the users environment in order for 
                   8957: graph.png to plot it.  Returns an <img> tag for the plot.
                   8958: The bars on the plot are labeled '1','2',...,'n'.
                   8959: 
                   8960: Inputs:
                   8961: 
                   8962: =over 4
                   8963: 
                   8964: =item $Title: string, the title of the plot
                   8965: 
                   8966: =item $xlabel: string, text describing the X-axis of the plot
                   8967: 
                   8968: =item $ylabel: string, text describing the Y-axis of the plot
                   8969: 
                   8970: =item $Max: scalar, the maximum Y value to use in the plot
                   8971: If $Max is < any data point, the graph will not be rendered.
                   8972: 
1.140     matthew  8973: =item $colors: array ref holding the colors to be used for the data sets when
1.138     matthew  8974: they are plotted.  If undefined, default values will be used.
                   8975: 
1.178     matthew  8976: =item $labels: array ref holding the labels to use on the x-axis for the bars.
                   8977: 
1.138     matthew  8978: =item @Values: An array of array references.  Each array reference holds data
                   8979: to be plotted in a stacked bar chart.
                   8980: 
1.239     matthew  8981: =item If the final element of @Values is a hash reference the key/value
                   8982: pairs will be added to the graph definition.
                   8983: 
1.138     matthew  8984: =back
                   8985: 
                   8986: Returns:
                   8987: 
                   8988: An <img> tag which references graph.png and the appropriate identifying
                   8989: information for the plot.
                   8990: 
1.127     matthew  8991: =cut
                   8992: 
                   8993: ############################################################
                   8994: ############################################################
1.134     matthew  8995: sub DrawBarGraph {
1.178     matthew  8996:     my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134     matthew  8997:     #
                   8998:     if (! defined($colors)) {
                   8999:         $colors = ['#33ff00', 
                   9000:                   '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
                   9001:                   '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
                   9002:                   ]; 
                   9003:     }
1.228     matthew  9004:     my $extra_settings = {};
                   9005:     if (ref($Values[-1]) eq 'HASH') {
                   9006:         $extra_settings = pop(@Values);
                   9007:     }
1.127     matthew  9008:     #
1.136     matthew  9009:     my $identifier = &get_cgi_id();
                   9010:     my $id = 'cgi.'.$identifier;        
1.129     matthew  9011:     if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127     matthew  9012:         return '';
                   9013:     }
1.225     matthew  9014:     #
                   9015:     my @Labels;
                   9016:     if (defined($labels)) {
                   9017:         @Labels = @$labels;
                   9018:     } else {
                   9019:         for (my $i=0;$i<@{$Values[0]};$i++) {
                   9020:             push (@Labels,$i+1);
                   9021:         }
                   9022:     }
                   9023:     #
1.129     matthew  9024:     my $NumBars = scalar(@{$Values[0]});
1.225     matthew  9025:     if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129     matthew  9026:     my %ValuesHash;
                   9027:     my $NumSets=1;
                   9028:     foreach my $array (@Values) {
                   9029:         next if (! ref($array));
1.136     matthew  9030:         $ValuesHash{$id.'.data.'.$NumSets++} = 
1.132     matthew  9031:             join(',',@$array);
1.129     matthew  9032:     }
1.127     matthew  9033:     #
1.136     matthew  9034:     my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225     matthew  9035:     if ($NumBars < 3) {
                   9036:         $width = 120+$NumBars*32;
1.220     matthew  9037:         $xskip = 1;
1.225     matthew  9038:         $bar_width = 30;
                   9039:     } elsif ($NumBars < 5) {
                   9040:         $width = 120+$NumBars*20;
                   9041:         $xskip = 1;
                   9042:         $bar_width = 20;
1.220     matthew  9043:     } elsif ($NumBars < 10) {
1.136     matthew  9044:         $width = 120+$NumBars*15;
                   9045:         $xskip = 1;
                   9046:         $bar_width = 15;
                   9047:     } elsif ($NumBars <= 25) {
                   9048:         $width = 120+$NumBars*11;
                   9049:         $xskip = 5;
                   9050:         $bar_width = 8;
                   9051:     } elsif ($NumBars <= 50) {
                   9052:         $width = 120+$NumBars*8;
                   9053:         $xskip = 5;
                   9054:         $bar_width = 4;
                   9055:     } else {
                   9056:         $width = 120+$NumBars*8;
                   9057:         $xskip = 5;
                   9058:         $bar_width = 4;
                   9059:     }
                   9060:     #
1.137     matthew  9061:     $Max = 1 if ($Max < 1);
                   9062:     if ( int($Max) < $Max ) {
                   9063:         $Max++;
                   9064:         $Max = int($Max);
                   9065:     }
1.127     matthew  9066:     $Title  = '' if (! defined($Title));
                   9067:     $xlabel = '' if (! defined($xlabel));
                   9068:     $ylabel = '' if (! defined($ylabel));
1.369     www      9069:     $ValuesHash{$id.'.title'}    = &escape($Title);
                   9070:     $ValuesHash{$id.'.xlabel'}   = &escape($xlabel);
                   9071:     $ValuesHash{$id.'.ylabel'}   = &escape($ylabel);
1.137     matthew  9072:     $ValuesHash{$id.'.y_max_value'} = $Max;
1.136     matthew  9073:     $ValuesHash{$id.'.NumBars'}  = $NumBars;
                   9074:     $ValuesHash{$id.'.NumSets'}  = $NumSets;
                   9075:     $ValuesHash{$id.'.PlotType'} = 'bar';
                   9076:     $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   9077:     $ValuesHash{$id.'.height'}   = $height;
                   9078:     $ValuesHash{$id.'.width'}    = $width;
                   9079:     $ValuesHash{$id.'.xskip'}    = $xskip;
                   9080:     $ValuesHash{$id.'.bar_width'} = $bar_width;
                   9081:     $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127     matthew  9082:     #
1.228     matthew  9083:     # Deal with other parameters
                   9084:     while (my ($key,$value) = each(%$extra_settings)) {
                   9085:         $ValuesHash{$id.'.'.$key} = $value;
                   9086:     }
                   9087:     #
1.646     raeburn  9088:     &Apache::lonnet::appenv(\%ValuesHash);
1.137     matthew  9089:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   9090: }
                   9091: 
                   9092: ############################################################
                   9093: ############################################################
                   9094: 
                   9095: =pod
                   9096: 
1.648     raeburn  9097: =item * &DrawXYGraph()
1.137     matthew  9098: 
1.138     matthew  9099: Facilitates the plotting of data in an XY graph.
                   9100: Puts plot definition data into the users environment in order for 
                   9101: graph.png to plot it.  Returns an <img> tag for the plot.
                   9102: 
                   9103: Inputs:
                   9104: 
                   9105: =over 4
                   9106: 
                   9107: =item $Title: string, the title of the plot
                   9108: 
                   9109: =item $xlabel: string, text describing the X-axis of the plot
                   9110: 
                   9111: =item $ylabel: string, text describing the Y-axis of the plot
                   9112: 
                   9113: =item $Max: scalar, the maximum Y value to use in the plot
                   9114: If $Max is < any data point, the graph will not be rendered.
                   9115: 
                   9116: =item $colors: Array ref containing the hex color codes for the data to be 
                   9117: plotted in.  If undefined, default values will be used.
                   9118: 
                   9119: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   9120: 
                   9121: =item $Ydata: Array ref containing Array refs.  
1.185     www      9122: Each of the contained arrays will be plotted as a separate curve.
1.138     matthew  9123: 
                   9124: =item %Values: hash indicating or overriding any default values which are 
                   9125: passed to graph.png.  
                   9126: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   9127: 
                   9128: =back
                   9129: 
                   9130: Returns:
                   9131: 
                   9132: An <img> tag which references graph.png and the appropriate identifying
                   9133: information for the plot.
                   9134: 
1.137     matthew  9135: =cut
                   9136: 
                   9137: ############################################################
                   9138: ############################################################
                   9139: sub DrawXYGraph {
                   9140:     my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
                   9141:     #
                   9142:     # Create the identifier for the graph
                   9143:     my $identifier = &get_cgi_id();
                   9144:     my $id = 'cgi.'.$identifier;
                   9145:     #
                   9146:     $Title  = '' if (! defined($Title));
                   9147:     $xlabel = '' if (! defined($xlabel));
                   9148:     $ylabel = '' if (! defined($ylabel));
                   9149:     my %ValuesHash = 
                   9150:         (
1.369     www      9151:          $id.'.title'  => &escape($Title),
                   9152:          $id.'.xlabel' => &escape($xlabel),
                   9153:          $id.'.ylabel' => &escape($ylabel),
1.137     matthew  9154:          $id.'.y_max_value'=> $Max,
                   9155:          $id.'.labels'     => join(',',@$Xlabels),
                   9156:          $id.'.PlotType'   => 'XY',
                   9157:          );
                   9158:     #
                   9159:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   9160:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   9161:     }
                   9162:     #
                   9163:     if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
                   9164:         return '';
                   9165:     }
                   9166:     my $NumSets=1;
1.138     matthew  9167:     foreach my $array (@{$Ydata}){
1.137     matthew  9168:         next if (! ref($array));
                   9169:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
                   9170:     }
1.138     matthew  9171:     $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137     matthew  9172:     #
                   9173:     # Deal with other parameters
                   9174:     while (my ($key,$value) = each(%Values)) {
                   9175:         $ValuesHash{$id.'.'.$key} = $value;
1.127     matthew  9176:     }
                   9177:     #
1.646     raeburn  9178:     &Apache::lonnet::appenv(\%ValuesHash);
1.136     matthew  9179:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   9180: }
                   9181: 
                   9182: ############################################################
                   9183: ############################################################
                   9184: 
                   9185: =pod
                   9186: 
1.648     raeburn  9187: =item * &DrawXYYGraph()
1.138     matthew  9188: 
                   9189: Facilitates the plotting of data in an XY graph with two Y axes.
                   9190: Puts plot definition data into the users environment in order for 
                   9191: graph.png to plot it.  Returns an <img> tag for the plot.
                   9192: 
                   9193: Inputs:
                   9194: 
                   9195: =over 4
                   9196: 
                   9197: =item $Title: string, the title of the plot
                   9198: 
                   9199: =item $xlabel: string, text describing the X-axis of the plot
                   9200: 
                   9201: =item $ylabel: string, text describing the Y-axis of the plot
                   9202: 
                   9203: =item $colors: Array ref containing the hex color codes for the data to be 
                   9204: plotted in.  If undefined, default values will be used.
                   9205: 
                   9206: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   9207: 
                   9208: =item $Ydata1: The first data set
                   9209: 
                   9210: =item $Min1: The minimum value of the left Y-axis
                   9211: 
                   9212: =item $Max1: The maximum value of the left Y-axis
                   9213: 
                   9214: =item $Ydata2: The second data set
                   9215: 
                   9216: =item $Min2: The minimum value of the right Y-axis
                   9217: 
                   9218: =item $Max2: The maximum value of the left Y-axis
                   9219: 
                   9220: =item %Values: hash indicating or overriding any default values which are 
                   9221: passed to graph.png.  
                   9222: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   9223: 
                   9224: =back
                   9225: 
                   9226: Returns:
                   9227: 
                   9228: An <img> tag which references graph.png and the appropriate identifying
                   9229: information for the plot.
1.136     matthew  9230: 
                   9231: =cut
                   9232: 
                   9233: ############################################################
                   9234: ############################################################
1.137     matthew  9235: sub DrawXYYGraph {
                   9236:     my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
                   9237:                                         $Ydata2,$Min2,$Max2,%Values)=@_;
1.136     matthew  9238:     #
                   9239:     # Create the identifier for the graph
                   9240:     my $identifier = &get_cgi_id();
                   9241:     my $id = 'cgi.'.$identifier;
                   9242:     #
                   9243:     $Title  = '' if (! defined($Title));
                   9244:     $xlabel = '' if (! defined($xlabel));
                   9245:     $ylabel = '' if (! defined($ylabel));
                   9246:     my %ValuesHash = 
                   9247:         (
1.369     www      9248:          $id.'.title'  => &escape($Title),
                   9249:          $id.'.xlabel' => &escape($xlabel),
                   9250:          $id.'.ylabel' => &escape($ylabel),
1.136     matthew  9251:          $id.'.labels' => join(',',@$Xlabels),
                   9252:          $id.'.PlotType' => 'XY',
                   9253:          $id.'.NumSets' => 2,
1.137     matthew  9254:          $id.'.two_axes' => 1,
                   9255:          $id.'.y1_max_value' => $Max1,
                   9256:          $id.'.y1_min_value' => $Min1,
                   9257:          $id.'.y2_max_value' => $Max2,
                   9258:          $id.'.y2_min_value' => $Min2,
1.136     matthew  9259:          );
                   9260:     #
1.137     matthew  9261:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   9262:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   9263:     }
                   9264:     #
                   9265:     if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
                   9266:         ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136     matthew  9267:         return '';
                   9268:     }
                   9269:     my $NumSets=1;
1.137     matthew  9270:     foreach my $array ($Ydata1,$Ydata2){
1.136     matthew  9271:         next if (! ref($array));
                   9272:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137     matthew  9273:     }
                   9274:     #
                   9275:     # Deal with other parameters
                   9276:     while (my ($key,$value) = each(%Values)) {
                   9277:         $ValuesHash{$id.'.'.$key} = $value;
1.136     matthew  9278:     }
                   9279:     #
1.646     raeburn  9280:     &Apache::lonnet::appenv(\%ValuesHash);
1.130     albertel 9281:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139     matthew  9282: }
                   9283: 
                   9284: ############################################################
                   9285: ############################################################
                   9286: 
                   9287: =pod
                   9288: 
1.157     matthew  9289: =back 
                   9290: 
1.139     matthew  9291: =head1 Statistics helper routines?  
                   9292: 
                   9293: Bad place for them but what the hell.
                   9294: 
1.157     matthew  9295: =over 4
                   9296: 
1.648     raeburn  9297: =item * &chartlink()
1.139     matthew  9298: 
                   9299: Returns a link to the chart for a specific student.  
                   9300: 
                   9301: Inputs:
                   9302: 
                   9303: =over 4
                   9304: 
                   9305: =item $linktext: The text of the link
                   9306: 
                   9307: =item $sname: The students username
                   9308: 
                   9309: =item $sdomain: The students domain
                   9310: 
                   9311: =back
                   9312: 
1.157     matthew  9313: =back
                   9314: 
1.139     matthew  9315: =cut
                   9316: 
                   9317: ############################################################
                   9318: ############################################################
                   9319: sub chartlink {
                   9320:     my ($linktext, $sname, $sdomain) = @_;
                   9321:     my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369     www      9322:         '&amp;SelectedStudent='.&escape($sname.':'.$sdomain).
1.219     albertel 9323:         '&amp;chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139     matthew  9324:        '">'.$linktext.'</a>';
1.153     matthew  9325: }
                   9326: 
                   9327: #######################################################
                   9328: #######################################################
                   9329: 
                   9330: =pod
                   9331: 
                   9332: =head1 Course Environment Routines
1.157     matthew  9333: 
                   9334: =over 4
1.153     matthew  9335: 
1.648     raeburn  9336: =item * &restore_course_settings()
1.153     matthew  9337: 
1.648     raeburn  9338: =item * &store_course_settings()
1.153     matthew  9339: 
                   9340: Restores/Store indicated form parameters from the course environment.
                   9341: Will not overwrite existing values of the form parameters.
                   9342: 
                   9343: Inputs: 
                   9344: a scalar describing the data (e.g. 'chart', 'problem_analysis')
                   9345: 
                   9346: a hash ref describing the data to be stored.  For example:
                   9347:    
                   9348: %Save_Parameters = ('Status' => 'scalar',
                   9349:     'chartoutputmode' => 'scalar',
                   9350:     'chartoutputdata' => 'scalar',
                   9351:     'Section' => 'array',
1.373     raeburn  9352:     'Group' => 'array',
1.153     matthew  9353:     'StudentData' => 'array',
                   9354:     'Maps' => 'array');
                   9355: 
                   9356: Returns: both routines return nothing
                   9357: 
1.631     raeburn  9358: =back
                   9359: 
1.153     matthew  9360: =cut
                   9361: 
                   9362: #######################################################
                   9363: #######################################################
                   9364: sub store_course_settings {
1.496     albertel 9365:     return &store_settings($env{'request.course.id'},@_);
                   9366: }
                   9367: 
                   9368: sub store_settings {
1.153     matthew  9369:     # save to the environment
                   9370:     # appenv the same items, just to be safe
1.300     albertel 9371:     my $udom  = $env{'user.domain'};
                   9372:     my $uname = $env{'user.name'};
1.496     albertel 9373:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  9374:     my %SaveHash;
                   9375:     my %AppHash;
                   9376:     while (my ($setting,$type) = each(%$Settings)) {
1.496     albertel 9377:         my $basename = join('.','internal',$context,$prefix,$setting);
1.300     albertel 9378:         my $envname = 'environment.'.$basename;
1.258     albertel 9379:         if (exists($env{'form.'.$setting})) {
1.153     matthew  9380:             # Save this value away
                   9381:             if ($type eq 'scalar' &&
1.258     albertel 9382:                 (! exists($env{$envname}) || 
                   9383:                  $env{$envname} ne $env{'form.'.$setting})) {
                   9384:                 $SaveHash{$basename} = $env{'form.'.$setting};
                   9385:                 $AppHash{$envname}   = $env{'form.'.$setting};
1.153     matthew  9386:             } elsif ($type eq 'array') {
                   9387:                 my $stored_form;
1.258     albertel 9388:                 if (ref($env{'form.'.$setting})) {
1.153     matthew  9389:                     $stored_form = join(',',
                   9390:                                         map {
1.369     www      9391:                                             &escape($_);
1.258     albertel 9392:                                         } sort(@{$env{'form.'.$setting}}));
1.153     matthew  9393:                 } else {
                   9394:                     $stored_form = 
1.369     www      9395:                         &escape($env{'form.'.$setting});
1.153     matthew  9396:                 }
                   9397:                 # Determine if the array contents are the same.
1.258     albertel 9398:                 if ($stored_form ne $env{$envname}) {
1.153     matthew  9399:                     $SaveHash{$basename} = $stored_form;
                   9400:                     $AppHash{$envname}   = $stored_form;
                   9401:                 }
                   9402:             }
                   9403:         }
                   9404:     }
                   9405:     my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300     albertel 9406:                                           $udom,$uname);
1.153     matthew  9407:     if ($put_result !~ /^(ok|delayed)/) {
                   9408:         &Apache::lonnet::logthis('unable to save form parameters, '.
                   9409:                                  'got error:'.$put_result);
                   9410:     }
                   9411:     # Make sure these settings stick around in this session, too
1.646     raeburn  9412:     &Apache::lonnet::appenv(\%AppHash);
1.153     matthew  9413:     return;
                   9414: }
                   9415: 
                   9416: sub restore_course_settings {
1.499     albertel 9417:     return &restore_settings($env{'request.course.id'},@_);
1.496     albertel 9418: }
                   9419: 
                   9420: sub restore_settings {
                   9421:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  9422:     while (my ($setting,$type) = each(%$Settings)) {
1.258     albertel 9423:         next if (exists($env{'form.'.$setting}));
1.496     albertel 9424:         my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153     matthew  9425:             '.'.$setting;
1.258     albertel 9426:         if (exists($env{$envname})) {
1.153     matthew  9427:             if ($type eq 'scalar') {
1.258     albertel 9428:                 $env{'form.'.$setting} = $env{$envname};
1.153     matthew  9429:             } elsif ($type eq 'array') {
1.258     albertel 9430:                 $env{'form.'.$setting} = [ 
1.153     matthew  9431:                                            map { 
1.369     www      9432:                                                &unescape($_); 
1.258     albertel 9433:                                            } split(',',$env{$envname})
1.153     matthew  9434:                                            ];
                   9435:             }
                   9436:         }
                   9437:     }
1.127     matthew  9438: }
                   9439: 
1.618     raeburn  9440: #######################################################
                   9441: #######################################################
                   9442: 
                   9443: =pod
                   9444: 
                   9445: =head1 Domain E-mail Routines  
                   9446: 
                   9447: =over 4
                   9448: 
1.648     raeburn  9449: =item * &build_recipient_list()
1.618     raeburn  9450: 
1.884     raeburn  9451: Build recipient lists for five types of e-mail:
1.766     raeburn  9452: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.884     raeburn  9453: (d) Help requests, (e) Course requests needing approval,  generated by
                   9454: lonerrorhandler.pm, CHECKRPMS, loncron, lonsupportreq.pm and
                   9455: loncoursequeueadmin.pm respectively.
1.618     raeburn  9456: 
                   9457: Inputs:
1.619     raeburn  9458: defmail (scalar - email address of default recipient), 
1.618     raeburn  9459: mailing type (scalar - errormail, packagesmail, or helpdeskmail), 
1.619     raeburn  9460: defdom (domain for which to retrieve configuration settings),
                   9461: origmail (scalar - email address of recipient from loncapa.conf, 
                   9462: i.e., predates configuration by DC via domainprefs.pm 
1.618     raeburn  9463: 
1.655     raeburn  9464: Returns: comma separated list of addresses to which to send e-mail.
                   9465: 
                   9466: =back
1.618     raeburn  9467: 
                   9468: =cut
                   9469: 
                   9470: ############################################################
                   9471: ############################################################
                   9472: sub build_recipient_list {
1.619     raeburn  9473:     my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618     raeburn  9474:     my @recipients;
                   9475:     my $otheremails;
                   9476:     my %domconfig =
                   9477:          &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
                   9478:     if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766     raeburn  9479:         if (exists($domconfig{'contacts'}{$mailing})) {
                   9480:             if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
                   9481:                 my @contacts = ('adminemail','supportemail');
                   9482:                 foreach my $item (@contacts) {
                   9483:                     if ($domconfig{'contacts'}{$mailing}{$item}) {
                   9484:                         my $addr = $domconfig{'contacts'}{$item}; 
                   9485:                         if (!grep(/^\Q$addr\E$/,@recipients)) {
                   9486:                             push(@recipients,$addr);
                   9487:                         }
1.619     raeburn  9488:                     }
1.766     raeburn  9489:                     $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618     raeburn  9490:                 }
                   9491:             }
1.766     raeburn  9492:         } elsif ($origmail ne '') {
                   9493:             push(@recipients,$origmail);
1.618     raeburn  9494:         }
1.619     raeburn  9495:     } elsif ($origmail ne '') {
                   9496:         push(@recipients,$origmail);
1.618     raeburn  9497:     }
1.688     raeburn  9498:     if (defined($defmail)) {
                   9499:         if ($defmail ne '') {
                   9500:             push(@recipients,$defmail);
                   9501:         }
1.618     raeburn  9502:     }
                   9503:     if ($otheremails) {
1.619     raeburn  9504:         my @others;
                   9505:         if ($otheremails =~ /,/) {
                   9506:             @others = split(/,/,$otheremails);
1.618     raeburn  9507:         } else {
1.619     raeburn  9508:             push(@others,$otheremails);
                   9509:         }
                   9510:         foreach my $addr (@others) {
                   9511:             if (!grep(/^\Q$addr\E$/,@recipients)) {
                   9512:                 push(@recipients,$addr);
                   9513:             }
1.618     raeburn  9514:         }
                   9515:     }
1.619     raeburn  9516:     my $recipientlist = join(',',@recipients); 
1.618     raeburn  9517:     return $recipientlist;
                   9518: }
                   9519: 
1.127     matthew  9520: ############################################################
                   9521: ############################################################
1.154     albertel 9522: 
1.655     raeburn  9523: =pod
                   9524: 
                   9525: =head1 Course Catalog Routines
                   9526: 
                   9527: =over 4
                   9528: 
                   9529: =item * &gather_categories()
                   9530: 
                   9531: Converts category definitions - keys of categories hash stored in  
                   9532: coursecategories in configuration.db on the primary library server in a 
                   9533: domain - to an array.  Also generates javascript and idx hash used to 
                   9534: generate Domain Coordinator interface for editing Course Categories.
                   9535: 
                   9536: Inputs:
1.663     raeburn  9537: 
1.655     raeburn  9538: categories (reference to hash of category definitions).
1.663     raeburn  9539: 
1.655     raeburn  9540: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   9541:       categories and subcategories).
1.663     raeburn  9542: 
1.655     raeburn  9543: idx (reference to hash of counters used in Domain Coordinator interface for 
                   9544:       editing Course Categories).
1.663     raeburn  9545: 
1.655     raeburn  9546: jsarray (reference to array of categories used to create Javascript arrays for
                   9547:          Domain Coordinator interface for editing Course Categories).
                   9548: 
                   9549: Returns: nothing
                   9550: 
                   9551: Side effects: populates cats, idx and jsarray. 
                   9552: 
                   9553: =cut
                   9554: 
                   9555: sub gather_categories {
                   9556:     my ($categories,$cats,$idx,$jsarray) = @_;
                   9557:     my %counters;
                   9558:     my $num = 0;
                   9559:     foreach my $item (keys(%{$categories})) {
                   9560:         my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
                   9561:         if ($container eq '' && $depth == 0) {
                   9562:             $cats->[$depth][$categories->{$item}] = $cat;
                   9563:         } else {
                   9564:             $cats->[$depth]{$container}[$categories->{$item}] = $cat;
                   9565:         }
                   9566:         my ($escitem,$tail) = split(/:/,$item,2);
                   9567:         if ($counters{$tail} eq '') {
                   9568:             $counters{$tail} = $num;
                   9569:             $num ++;
                   9570:         }
                   9571:         if (ref($idx) eq 'HASH') {
                   9572:             $idx->{$item} = $counters{$tail};
                   9573:         }
                   9574:         if (ref($jsarray) eq 'ARRAY') {
                   9575:             push(@{$jsarray->[$counters{$tail}]},$item);
                   9576:         }
                   9577:     }
                   9578:     return;
                   9579: }
                   9580: 
                   9581: =pod
                   9582: 
                   9583: =item * &extract_categories()
                   9584: 
                   9585: Used to generate breadcrumb trails for course categories.
                   9586: 
                   9587: Inputs:
1.663     raeburn  9588: 
1.655     raeburn  9589: categories (reference to hash of category definitions).
1.663     raeburn  9590: 
1.655     raeburn  9591: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   9592:       categories and subcategories).
1.663     raeburn  9593: 
1.655     raeburn  9594: trails (reference to array of breacrumb trails for each category).
1.663     raeburn  9595: 
1.655     raeburn  9596: allitems (reference to hash - key is category key 
                   9597:          (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663     raeburn  9598: 
1.655     raeburn  9599: idx (reference to hash of counters used in Domain Coordinator interface for
                   9600:       editing Course Categories).
1.663     raeburn  9601: 
1.655     raeburn  9602: jsarray (reference to array of categories used to create Javascript arrays for
                   9603:          Domain Coordinator interface for editing Course Categories).
                   9604: 
1.665     raeburn  9605: subcats (reference to hash of arrays containing all subcategories within each 
                   9606:          category, -recursive)
                   9607: 
1.655     raeburn  9608: Returns: nothing
                   9609: 
                   9610: Side effects: populates trails and allitems hash references.
                   9611: 
                   9612: =cut
                   9613: 
                   9614: sub extract_categories {
1.665     raeburn  9615:     my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655     raeburn  9616:     if (ref($categories) eq 'HASH') {
                   9617:         &gather_categories($categories,$cats,$idx,$jsarray);
                   9618:         if (ref($cats->[0]) eq 'ARRAY') {
                   9619:             for (my $i=0; $i<@{$cats->[0]}; $i++) {
                   9620:                 my $name = $cats->[0][$i];
                   9621:                 my $item = &escape($name).'::0';
                   9622:                 my $trailstr;
                   9623:                 if ($name eq 'instcode') {
                   9624:                     $trailstr = &mt('Official courses (with institutional codes)');
1.919     raeburn  9625:                 } elsif ($name eq 'communities') {
                   9626:                     $trailstr = &mt('Communities');
1.655     raeburn  9627:                 } else {
                   9628:                     $trailstr = $name;
                   9629:                 }
                   9630:                 if ($allitems->{$item} eq '') {
                   9631:                     push(@{$trails},$trailstr);
                   9632:                     $allitems->{$item} = scalar(@{$trails})-1;
                   9633:                 }
                   9634:                 my @parents = ($name);
                   9635:                 if (ref($cats->[1]{$name}) eq 'ARRAY') {
                   9636:                     for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
                   9637:                         my $category = $cats->[1]{$name}[$j];
1.665     raeburn  9638:                         if (ref($subcats) eq 'HASH') {
                   9639:                             push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
                   9640:                         }
                   9641:                         &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
                   9642:                     }
                   9643:                 } else {
                   9644:                     if (ref($subcats) eq 'HASH') {
                   9645:                         $subcats->{$item} = [];
1.655     raeburn  9646:                     }
                   9647:                 }
                   9648:             }
                   9649:         }
                   9650:     }
                   9651:     return;
                   9652: }
                   9653: 
                   9654: =pod
                   9655: 
                   9656: =item *&recurse_categories()
                   9657: 
                   9658: Recursively used to generate breadcrumb trails for course categories.
                   9659: 
                   9660: Inputs:
1.663     raeburn  9661: 
1.655     raeburn  9662: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   9663:       categories and subcategories).
1.663     raeburn  9664: 
1.655     raeburn  9665: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663     raeburn  9666: 
                   9667: category (current course category, for which breadcrumb trail is being generated).
                   9668: 
                   9669: trails (reference to array of breadcrumb trails for each category).
                   9670: 
1.655     raeburn  9671: allitems (reference to hash - key is category key
                   9672:          (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663     raeburn  9673: 
1.655     raeburn  9674: parents (array containing containers directories for current category, 
                   9675:          back to top level). 
                   9676: 
                   9677: Returns: nothing
                   9678: 
                   9679: Side effects: populates trails and allitems hash references
                   9680: 
                   9681: =cut
                   9682: 
                   9683: sub recurse_categories {
1.665     raeburn  9684:     my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655     raeburn  9685:     my $shallower = $depth - 1;
                   9686:     if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
                   9687:         for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
                   9688:             my $name = $cats->[$depth]{$category}[$k];
                   9689:             my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
                   9690:             my $trailstr = join(' -&gt; ',(@{$parents},$category));
                   9691:             if ($allitems->{$item} eq '') {
                   9692:                 push(@{$trails},$trailstr);
                   9693:                 $allitems->{$item} = scalar(@{$trails})-1;
                   9694:             }
                   9695:             my $deeper = $depth+1;
                   9696:             push(@{$parents},$category);
1.665     raeburn  9697:             if (ref($subcats) eq 'HASH') {
                   9698:                 my $subcat = &escape($name).':'.$category.':'.$depth;
                   9699:                 for (my $j=@{$parents}; $j>=0; $j--) {
                   9700:                     my $higher;
                   9701:                     if ($j > 0) {
                   9702:                         $higher = &escape($parents->[$j]).':'.
                   9703:                                   &escape($parents->[$j-1]).':'.$j;
                   9704:                     } else {
                   9705:                         $higher = &escape($parents->[$j]).'::'.$j;
                   9706:                     }
                   9707:                     push(@{$subcats->{$higher}},$subcat);
                   9708:                 }
                   9709:             }
                   9710:             &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
                   9711:                                 $subcats);
1.655     raeburn  9712:             pop(@{$parents});
                   9713:         }
                   9714:     } else {
                   9715:         my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
                   9716:         my $trailstr = join(' -&gt; ',(@{$parents},$category));
                   9717:         if ($allitems->{$item} eq '') {
                   9718:             push(@{$trails},$trailstr);
                   9719:             $allitems->{$item} = scalar(@{$trails})-1;
                   9720:         }
                   9721:     }
                   9722:     return;
                   9723: }
                   9724: 
1.663     raeburn  9725: =pod
                   9726: 
                   9727: =item *&assign_categories_table()
                   9728: 
                   9729: Create a datatable for display of hierarchical categories in a domain,
                   9730: with checkboxes to allow a course to be categorized. 
                   9731: 
                   9732: Inputs:
                   9733: 
                   9734: cathash - reference to hash of categories defined for the domain (from
                   9735:           configuration.db)
                   9736: 
                   9737: currcat - scalar with an & separated list of categories assigned to a course. 
                   9738: 
1.919     raeburn  9739: type    - scalar contains course type (Course or Community).
                   9740: 
1.663     raeburn  9741: Returns: $output (markup to be displayed) 
                   9742: 
                   9743: =cut
                   9744: 
                   9745: sub assign_categories_table {
1.919     raeburn  9746:     my ($cathash,$currcat,$type) = @_;
1.663     raeburn  9747:     my $output;
                   9748:     if (ref($cathash) eq 'HASH') {
                   9749:         my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
                   9750:         &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
                   9751:         $maxdepth = scalar(@cats);
                   9752:         if (@cats > 0) {
                   9753:             my $itemcount = 0;
                   9754:             if (ref($cats[0]) eq 'ARRAY') {
                   9755:                 my @currcategories;
                   9756:                 if ($currcat ne '') {
                   9757:                     @currcategories = split('&',$currcat);
                   9758:                 }
1.919     raeburn  9759:                 my $table;
1.663     raeburn  9760:                 for (my $i=0; $i<@{$cats[0]}; $i++) {
                   9761:                     my $parent = $cats[0][$i];
1.919     raeburn  9762:                     next if ($parent eq 'instcode');
                   9763:                     if ($type eq 'Community') {
                   9764:                         next unless ($parent eq 'communities');
                   9765:                     } else {
                   9766:                         next if ($parent eq 'communities');
                   9767:                     }
1.663     raeburn  9768:                     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   9769:                     my $item = &escape($parent).'::0';
                   9770:                     my $checked = '';
                   9771:                     if (@currcategories > 0) {
                   9772:                         if (grep(/^\Q$item\E$/,@currcategories)) {
1.772     bisitz   9773:                             $checked = ' checked="checked"';
1.663     raeburn  9774:                         }
                   9775:                     }
1.919     raeburn  9776:                     my $parent_title = $parent;
                   9777:                     if ($parent eq 'communities') {
                   9778:                         $parent_title = &mt('Communities');
                   9779:                     }
                   9780:                     $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
                   9781:                               '<input type="checkbox" name="usecategory" value="'.
                   9782:                               $item.'"'.$checked.' />'.$parent_title.'</span>'.
                   9783:                               '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663     raeburn  9784:                     my $depth = 1;
                   9785:                     push(@path,$parent);
1.919     raeburn  9786:                     $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663     raeburn  9787:                     pop(@path);
1.919     raeburn  9788:                     $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663     raeburn  9789:                     $itemcount ++;
                   9790:                 }
1.919     raeburn  9791:                 if ($itemcount) {
                   9792:                     $output = &Apache::loncommon::start_data_table().
                   9793:                               $table.
                   9794:                               &Apache::loncommon::end_data_table();
                   9795:                 }
1.663     raeburn  9796:             }
                   9797:         }
                   9798:     }
                   9799:     return $output;
                   9800: }
                   9801: 
                   9802: =pod
                   9803: 
                   9804: =item *&assign_category_rows()
                   9805: 
                   9806: Create a datatable row for display of nested categories in a domain,
                   9807: with checkboxes to allow a course to be categorized,called recursively.
                   9808: 
                   9809: Inputs:
                   9810: 
                   9811: itemcount - track row number for alternating colors
                   9812: 
                   9813: cats - reference to array of arrays/hashes which encapsulates hierarchy of
                   9814:       categories and subcategories.
                   9815: 
                   9816: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
                   9817: 
                   9818: parent - parent of current category item
                   9819: 
                   9820: path - Array containing all categories back up through the hierarchy from the
                   9821:        current category to the top level.
                   9822: 
                   9823: currcategories - reference to array of current categories assigned to the course
                   9824: 
                   9825: Returns: $output (markup to be displayed).
                   9826: 
                   9827: =cut
                   9828: 
                   9829: sub assign_category_rows {
                   9830:     my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
                   9831:     my ($text,$name,$item,$chgstr);
                   9832:     if (ref($cats) eq 'ARRAY') {
                   9833:         my $maxdepth = scalar(@{$cats});
                   9834:         if (ref($cats->[$depth]) eq 'HASH') {
                   9835:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   9836:                 my $numchildren = @{$cats->[$depth]{$parent}};
                   9837:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   9838:                 $text .= '<td><table class="LC_datatable">';
                   9839:                 for (my $j=0; $j<$numchildren; $j++) {
                   9840:                     $name = $cats->[$depth]{$parent}[$j];
                   9841:                     $item = &escape($name).':'.&escape($parent).':'.$depth;
                   9842:                     my $deeper = $depth+1;
                   9843:                     my $checked = '';
                   9844:                     if (ref($currcategories) eq 'ARRAY') {
                   9845:                         if (@{$currcategories} > 0) {
                   9846:                             if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772     bisitz   9847:                                 $checked = ' checked="checked"';
1.663     raeburn  9848:                             }
                   9849:                         }
                   9850:                     }
1.664     raeburn  9851:                     $text .= '<tr><td><span class="LC_nobreak"><label>'.
                   9852:                              '<input type="checkbox" name="usecategory" value="'.
1.675     raeburn  9853:                              $item.'"'.$checked.' />'.$name.'</label></span>'.
                   9854:                              '<input type="hidden" name="catname" value="'.$name.'" />'.
                   9855:                              '</td><td>';
1.663     raeburn  9856:                     if (ref($path) eq 'ARRAY') {
                   9857:                         push(@{$path},$name);
                   9858:                         $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
                   9859:                         pop(@{$path});
                   9860:                     }
                   9861:                     $text .= '</td></tr>';
                   9862:                 }
                   9863:                 $text .= '</table></td>';
                   9864:             }
                   9865:         }
                   9866:     }
                   9867:     return $text;
                   9868: }
                   9869: 
1.655     raeburn  9870: ############################################################
                   9871: ############################################################
                   9872: 
                   9873: 
1.443     albertel 9874: sub commit_customrole {
1.664     raeburn  9875:     my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630     raeburn  9876:     my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443     albertel 9877:                          ($start?', '.&mt('starting').' '.localtime($start):'').
                   9878:                          ($end?', ending '.localtime($end):'').': <b>'.
                   9879:               &Apache::lonnet::assigncustomrole(
1.664     raeburn  9880:                  $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443     albertel 9881:                  '</b><br />';
                   9882:     return $output;
                   9883: }
                   9884: 
                   9885: sub commit_standardrole {
1.541     raeburn  9886:     my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
                   9887:     my ($output,$logmsg,$linefeed);
                   9888:     if ($context eq 'auto') {
                   9889:         $linefeed = "\n";
                   9890:     } else {
                   9891:         $linefeed = "<br />\n";
                   9892:     }  
1.443     albertel 9893:     if ($three eq 'st') {
1.541     raeburn  9894:         my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
                   9895:                                          $one,$two,$sec,$context);
                   9896:         if (($result =~ /^error/) || ($result eq 'not_in_class') || 
1.626     raeburn  9897:             ($result eq 'unknown_course') || ($result eq 'refused')) {
                   9898:             $output = $logmsg.' '.&mt('Error: ').$result."\n"; 
1.443     albertel 9899:         } else {
1.541     raeburn  9900:             $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443     albertel 9901:                ($start?', '.&mt('starting').' '.localtime($start):'').
1.541     raeburn  9902:                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
                   9903:             if ($context eq 'auto') {
                   9904:                 $output .= $result.$linefeed.&mt('Add to classlist').': ok';
                   9905:             } else {
                   9906:                $output .= '<b>'.$result.'</b>'.$linefeed.
                   9907:                &mt('Add to classlist').': <b>ok</b>';
                   9908:             }
                   9909:             $output .= $linefeed;
1.443     albertel 9910:         }
                   9911:     } else {
                   9912:         $output = &mt('Assigning').' '.$three.' in '.$url.
                   9913:                ($start?', '.&mt('starting').' '.localtime($start):'').
1.541     raeburn  9914:                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652     raeburn  9915:         my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541     raeburn  9916:         if ($context eq 'auto') {
                   9917:             $output .= $result.$linefeed;
                   9918:         } else {
                   9919:             $output .= '<b>'.$result.'</b>'.$linefeed;
                   9920:         }
1.443     albertel 9921:     }
                   9922:     return $output;
                   9923: }
                   9924: 
                   9925: sub commit_studentrole {
1.541     raeburn  9926:     my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626     raeburn  9927:     my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541     raeburn  9928:     if ($context eq 'auto') {
                   9929:         $linefeed = "\n";
                   9930:     } else {
                   9931:         $linefeed = '<br />'."\n";
                   9932:     }
1.443     albertel 9933:     if (defined($one) && defined($two)) {
                   9934:         my $cid=$one.'_'.$two;
                   9935:         my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
                   9936:         my $secchange = 0;
                   9937:         my $expire_role_result;
                   9938:         my $modify_section_result;
1.628     raeburn  9939:         if ($oldsec ne '-1') { 
                   9940:             if ($oldsec ne $sec) {
1.443     albertel 9941:                 $secchange = 1;
1.628     raeburn  9942:                 my $now = time;
1.443     albertel 9943:                 my $uurl='/'.$cid;
                   9944:                 $uurl=~s/\_/\//g;
                   9945:                 if ($oldsec) {
                   9946:                     $uurl.='/'.$oldsec;
                   9947:                 }
1.626     raeburn  9948:                 $oldsecurl = $uurl;
1.628     raeburn  9949:                 $expire_role_result = 
1.652     raeburn  9950:                     &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628     raeburn  9951:                 if ($env{'request.course.sec'} ne '') { 
                   9952:                     if ($expire_role_result eq 'refused') {
                   9953:                         my @roles = ('st');
                   9954:                         my @statuses = ('previous');
                   9955:                         my @roledoms = ($one);
                   9956:                         my $withsec = 1;
                   9957:                         my %roleshash = 
                   9958:                             &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
                   9959:                                               \@statuses,\@roles,\@roledoms,$withsec);
                   9960:                         if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
                   9961:                             my ($oldstart,$oldend) = 
                   9962:                                 split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
                   9963:                             if ($oldend > 0 && $oldend <= $now) {
                   9964:                                 $expire_role_result = 'ok';
                   9965:                             }
                   9966:                         }
                   9967:                     }
                   9968:                 }
1.443     albertel 9969:                 $result = $expire_role_result;
                   9970:             }
                   9971:         }
                   9972:         if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652     raeburn  9973:             $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443     albertel 9974:             if ($modify_section_result =~ /^ok/) {
                   9975:                 if ($secchange == 1) {
1.628     raeburn  9976:                     if ($sec eq '') {
                   9977:                         $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
                   9978:                     } else {
                   9979:                         $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
                   9980:                     }
1.443     albertel 9981:                 } elsif ($oldsec eq '-1') {
1.628     raeburn  9982:                     if ($sec eq '') {
                   9983:                         $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
                   9984:                     } else {
                   9985:                         $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                   9986:                     }
1.443     albertel 9987:                 } else {
1.628     raeburn  9988:                     if ($sec eq '') {
                   9989:                         $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
                   9990:                     } else {
                   9991:                         $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                   9992:                     }
1.443     albertel 9993:                 }
                   9994:             } else {
1.628     raeburn  9995:                 if ($secchange) {       
                   9996:                     $$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;
                   9997:                 } else {
                   9998:                     $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
                   9999:                 }
1.443     albertel 10000:             }
                   10001:             $result = $modify_section_result;
                   10002:         } elsif ($secchange == 1) {
1.628     raeburn  10003:             if ($oldsec eq '') {
                   10004:                 $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
                   10005:             } else {
                   10006:                 $$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;
                   10007:             }
1.626     raeburn  10008:             if ($expire_role_result eq 'refused') {
                   10009:                 my $newsecurl = '/'.$cid;
                   10010:                 $newsecurl =~ s/\_/\//g;
                   10011:                 if ($sec ne '') {
                   10012:                     $newsecurl.='/'.$sec;
                   10013:                 }
                   10014:                 if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
                   10015:                     if ($sec eq '') {
                   10016:                         $$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;
                   10017:                     } else {
                   10018:                         $$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;
                   10019:                     }
                   10020:                 }
                   10021:             }
1.443     albertel 10022:         }
                   10023:     } else {
1.626     raeburn  10024:         $$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 10025:         $result = "error: incomplete course id\n";
                   10026:     }
                   10027:     return $result;
                   10028: }
                   10029: 
                   10030: ############################################################
                   10031: ############################################################
                   10032: 
1.566     albertel 10033: sub check_clone {
1.578     raeburn  10034:     my ($args,$linefeed) = @_;
1.566     albertel 10035:     my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
                   10036:     my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
                   10037:     my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
                   10038:     my $clonemsg;
                   10039:     my $can_clone = 0;
1.944     raeburn  10040:     my $lctype = lc($args->{'crstype'});
1.908     raeburn  10041:     if ($lctype ne 'community') {
                   10042:         $lctype = 'course';
                   10043:     }
1.566     albertel 10044:     if ($clonehome eq 'no_host') {
1.944     raeburn  10045:         if ($args->{'crstype'} eq 'Community') {
1.908     raeburn  10046:             $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'});
                   10047:         } else {
                   10048:             $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'});
                   10049:         }     
1.566     albertel 10050:     } else {
                   10051: 	my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944     raeburn  10052:         if ($args->{'crstype'} eq 'Community') {
1.908     raeburn  10053:             if ($clonedesc{'type'} ne 'Community') {
                   10054:                  $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'});
                   10055:                 return ($can_clone, $clonemsg, $cloneid, $clonehome);
                   10056:             }
                   10057:         }
1.882     raeburn  10058: 	if (($env{'request.role.domain'} eq $args->{'clonedomain'}) && 
                   10059:             (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566     albertel 10060: 	    $can_clone = 1;
                   10061: 	} else {
                   10062: 	    my %clonehash = &Apache::lonnet::get('environment',['cloners'],
                   10063: 						 $args->{'clonedomain'},$args->{'clonecourse'});
                   10064: 	    my @cloners = split(/,/,$clonehash{'cloners'});
1.578     raeburn  10065:             if (grep(/^\*$/,@cloners)) {
                   10066:                 $can_clone = 1;
                   10067:             } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
                   10068:                 $can_clone = 1;
                   10069:             } else {
1.908     raeburn  10070:                 my $ccrole = 'cc';
1.944     raeburn  10071:                 if ($args->{'crstype'} eq 'Community') {
1.908     raeburn  10072:                     $ccrole = 'co';
                   10073:                 }
1.578     raeburn  10074: 	        my %roleshash =
                   10075: 		    &Apache::lonnet::get_my_roles($args->{'ccuname'},
                   10076: 					 $args->{'ccdomain'},
1.908     raeburn  10077:                                          'userroles',['active'],[$ccrole],
1.578     raeburn  10078: 					 [$args->{'clonedomain'}]);
1.908     raeburn  10079: 	        if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
1.942     raeburn  10080:                     $can_clone = 1;
                   10081:                 } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},$args->{'ccuname'},$args->{'ccdomain'})) {
                   10082:                     $can_clone = 1;
                   10083:                 } else {
1.944     raeburn  10084:                     if ($args->{'crstype'} eq 'Community') {
1.908     raeburn  10085:                         $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'});
                   10086:                     } else {
                   10087:                         $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'});
                   10088:                     }
1.578     raeburn  10089: 	        }
1.566     albertel 10090: 	    }
1.578     raeburn  10091:         }
1.566     albertel 10092:     }
                   10093:     return ($can_clone, $clonemsg, $cloneid, $clonehome);
                   10094: }
                   10095: 
1.444     albertel 10096: sub construct_course {
1.885     raeburn  10097:     my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category) = @_;
1.444     albertel 10098:     my $outcome;
1.541     raeburn  10099:     my $linefeed =  '<br />'."\n";
                   10100:     if ($context eq 'auto') {
                   10101:         $linefeed = "\n";
                   10102:     }
1.566     albertel 10103: 
                   10104: #
                   10105: # Are we cloning?
                   10106: #
                   10107:     my ($can_clone, $clonemsg, $cloneid, $clonehome);
                   10108:     if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578     raeburn  10109: 	($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566     albertel 10110: 	if ($context ne 'auto') {
1.578     raeburn  10111:             if ($clonemsg ne '') {
                   10112: 	        $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
                   10113:             }
1.566     albertel 10114: 	}
                   10115: 	$outcome .= $clonemsg.$linefeed;
                   10116: 
                   10117:         if (!$can_clone) {
                   10118: 	    return (0,$outcome);
                   10119: 	}
                   10120:     }
                   10121: 
1.444     albertel 10122: #
                   10123: # Open course
                   10124: #
                   10125:     my $crstype = lc($args->{'crstype'});
                   10126:     my %cenv=();
                   10127:     $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
                   10128:                                              $args->{'cdescr'},
                   10129:                                              $args->{'curl'},
                   10130:                                              $args->{'course_home'},
                   10131:                                              $args->{'nonstandard'},
                   10132:                                              $args->{'crscode'},
                   10133:                                              $args->{'ccuname'}.':'.
                   10134:                                              $args->{'ccdomain'},
1.882     raeburn  10135:                                              $args->{'crstype'},
1.885     raeburn  10136:                                              $cnum,$context,$category);
1.444     albertel 10137: 
                   10138:     # Note: The testing routines depend on this being output; see 
                   10139:     # Utils::Course. This needs to at least be output as a comment
                   10140:     # if anyone ever decides to not show this, and Utils::Course::new
                   10141:     # will need to be suitably modified.
1.541     raeburn  10142:     $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943     raeburn  10143:     if ($$courseid =~ /^error:/) {
                   10144:         return (0,$outcome);
                   10145:     }
                   10146: 
1.444     albertel 10147: #
                   10148: # Check if created correctly
                   10149: #
1.479     albertel 10150:     ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444     albertel 10151:     my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943     raeburn  10152:     if ($crsuhome eq 'no_host') {
                   10153:         $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
                   10154:         return (0,$outcome);
                   10155:     }
1.541     raeburn  10156:     $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566     albertel 10157: 
1.444     albertel 10158: #
1.566     albertel 10159: # Do the cloning
                   10160: #   
                   10161:     if ($can_clone && $cloneid) {
                   10162: 	$clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
                   10163: 	if ($context ne 'auto') {
                   10164: 	    $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
                   10165: 	}
                   10166: 	$outcome .= $clonemsg.$linefeed;
                   10167: 	my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444     albertel 10168: # Copy all files
1.637     www      10169: 	&Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444     albertel 10170: # Restore URL
1.566     albertel 10171: 	$cenv{'url'}=$oldcenv{'url'};
1.444     albertel 10172: # Restore title
1.566     albertel 10173: 	$cenv{'description'}=$oldcenv{'description'};
1.955     raeburn  10174: # Restore creation date, creator and creation context.
                   10175:         $cenv{'internal.created'}=$oldcenv{'internal.created'};
                   10176:         $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
                   10177:         $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444     albertel 10178: # Mark as cloned
1.566     albertel 10179: 	$cenv{'clonedfrom'}=$cloneid;
1.638     www      10180: # Need to clone grading mode
                   10181:         my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
                   10182:         $cenv{'grading'}=$newenv{'grading'};
                   10183: # Do not clone these environment entries
                   10184:         &Apache::lonnet::del('environment',
                   10185:                   ['default_enrollment_start_date',
                   10186:                    'default_enrollment_end_date',
                   10187:                    'question.email',
                   10188:                    'policy.email',
                   10189:                    'comment.email',
                   10190:                    'pch.users.denied',
1.725     raeburn  10191:                    'plc.users.denied',
                   10192:                    'hidefromcat',
                   10193:                    'categories'],
1.638     www      10194:                    $$crsudom,$$crsunum);
1.444     albertel 10195:     }
1.566     albertel 10196: 
1.444     albertel 10197: #
                   10198: # Set environment (will override cloned, if existing)
                   10199: #
                   10200:     my @sections = ();
                   10201:     my @xlists = ();
                   10202:     if ($args->{'crstype'}) {
                   10203:         $cenv{'type'}=$args->{'crstype'};
                   10204:     }
                   10205:     if ($args->{'crsid'}) {
                   10206:         $cenv{'courseid'}=$args->{'crsid'};
                   10207:     }
                   10208:     if ($args->{'crscode'}) {
                   10209:         $cenv{'internal.coursecode'}=$args->{'crscode'};
                   10210:     }
                   10211:     if ($args->{'crsquota'} ne '') {
                   10212:         $cenv{'internal.coursequota'}=$args->{'crsquota'};
                   10213:     } else {
                   10214:         $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
                   10215:     }
                   10216:     if ($args->{'ccuname'}) {
                   10217:         $cenv{'internal.courseowner'} = $args->{'ccuname'}.
                   10218:                                         ':'.$args->{'ccdomain'};
                   10219:     } else {
                   10220:         $cenv{'internal.courseowner'} = $args->{'curruser'};
                   10221:     }
                   10222:     my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
                   10223:     if ($args->{'crssections'}) {
                   10224:         $cenv{'internal.sectionnums'} = '';
                   10225:         if ($args->{'crssections'} =~ m/,/) {
                   10226:             @sections = split/,/,$args->{'crssections'};
                   10227:         } else {
                   10228:             $sections[0] = $args->{'crssections'};
                   10229:         }
                   10230:         if (@sections > 0) {
                   10231:             foreach my $item (@sections) {
                   10232:                 my ($sec,$gp) = split/:/,$item;
                   10233:                 my $class = $args->{'crscode'}.$sec;
                   10234:                 my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
                   10235:                 $cenv{'internal.sectionnums'} .= $item.',';
                   10236:                 unless ($addcheck eq 'ok') {
                   10237:                     push @badclasses, $class;
                   10238:                 }
                   10239:             }
                   10240:             $cenv{'internal.sectionnums'} =~ s/,$//;
                   10241:         }
                   10242:     }
                   10243: # do not hide course coordinator from staff listing, 
                   10244: # even if privileged
                   10245:     $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   10246: # add crosslistings
                   10247:     if ($args->{'crsxlist'}) {
                   10248:         $cenv{'internal.crosslistings'}='';
                   10249:         if ($args->{'crsxlist'} =~ m/,/) {
                   10250:             @xlists = split/,/,$args->{'crsxlist'};
                   10251:         } else {
                   10252:             $xlists[0] = $args->{'crsxlist'};
                   10253:         }
                   10254:         if (@xlists > 0) {
                   10255:             foreach my $item (@xlists) {
                   10256:                 my ($xl,$gp) = split/:/,$item;
                   10257:                 my $addcheck =  &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
                   10258:                 $cenv{'internal.crosslistings'} .= $item.',';
                   10259:                 unless ($addcheck eq 'ok') {
                   10260:                     push @badclasses, $xl;
                   10261:                 }
                   10262:             }
                   10263:             $cenv{'internal.crosslistings'} =~ s/,$//;
                   10264:         }
                   10265:     }
                   10266:     if ($args->{'autoadds'}) {
                   10267:         $cenv{'internal.autoadds'}=$args->{'autoadds'};
                   10268:     }
                   10269:     if ($args->{'autodrops'}) {
                   10270:         $cenv{'internal.autodrops'}=$args->{'autodrops'};
                   10271:     }
                   10272: # check for notification of enrollment changes
                   10273:     my @notified = ();
                   10274:     if ($args->{'notify_owner'}) {
                   10275:         if ($args->{'ccuname'} ne '') {
                   10276:             push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
                   10277:         }
                   10278:     }
                   10279:     if ($args->{'notify_dc'}) {
                   10280:         if ($uname ne '') { 
1.630     raeburn  10281:             push(@notified,$uname.':'.$udom);
1.444     albertel 10282:         }
                   10283:     }
                   10284:     if (@notified > 0) {
                   10285:         my $notifylist;
                   10286:         if (@notified > 1) {
                   10287:             $notifylist = join(',',@notified);
                   10288:         } else {
                   10289:             $notifylist = $notified[0];
                   10290:         }
                   10291:         $cenv{'internal.notifylist'} = $notifylist;
                   10292:     }
                   10293:     if (@badclasses > 0) {
                   10294:         my %lt=&Apache::lonlocal::texthash(
                   10295:                 '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',
                   10296:                 'dnhr' => 'does not have rights to access enrollment in these classes',
                   10297:                 'adby' => 'as determined by the policies of your institution on access to official classlists'
                   10298:         );
1.541     raeburn  10299:         my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
                   10300:                            ' ('.$lt{'adby'}.')';
                   10301:         if ($context eq 'auto') {
                   10302:             $outcome .= $badclass_msg.$linefeed;
1.566     albertel 10303:             $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541     raeburn  10304:             foreach my $item (@badclasses) {
                   10305:                 if ($context eq 'auto') {
                   10306:                     $outcome .= " - $item\n";
                   10307:                 } else {
                   10308:                     $outcome .= "<li>$item</li>\n";
                   10309:                 }
                   10310:             }
                   10311:             if ($context eq 'auto') {
                   10312:                 $outcome .= $linefeed;
                   10313:             } else {
1.566     albertel 10314:                 $outcome .= "</ul><br /><br /></div>\n";
1.541     raeburn  10315:             }
                   10316:         } 
1.444     albertel 10317:     }
                   10318:     if ($args->{'no_end_date'}) {
                   10319:         $args->{'endaccess'} = 0;
                   10320:     }
                   10321:     $cenv{'internal.autostart'}=$args->{'enrollstart'};
                   10322:     $cenv{'internal.autoend'}=$args->{'enrollend'};
                   10323:     $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
                   10324:     $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
                   10325:     if ($args->{'showphotos'}) {
                   10326:       $cenv{'internal.showphotos'}=$args->{'showphotos'};
                   10327:     }
                   10328:     $cenv{'internal.authtype'} = $args->{'authtype'};
                   10329:     $cenv{'internal.autharg'} = $args->{'autharg'}; 
                   10330:     if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
                   10331:         if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'}  eq '') {
1.541     raeburn  10332:             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'); 
                   10333:             if ($context eq 'auto') {
                   10334:                 $outcome .= $krb_msg;
                   10335:             } else {
1.566     albertel 10336:                 $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541     raeburn  10337:             }
                   10338:             $outcome .= $linefeed;
1.444     albertel 10339:         }
                   10340:     }
                   10341:     if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
                   10342:        if ($args->{'setpolicy'}) {
                   10343:            $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   10344:        }
                   10345:        if ($args->{'setcontent'}) {
                   10346:            $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   10347:        }
                   10348:     }
                   10349:     if ($args->{'reshome'}) {
                   10350: 	$cenv{'reshome'}=$args->{'reshome'}.'/';
                   10351: 	$cenv{'reshome'}=~s/\/+$/\//;
                   10352:     }
                   10353: #
                   10354: # course has keyed access
                   10355: #
                   10356:     if ($args->{'setkeys'}) {
                   10357:        $cenv{'keyaccess'}='yes';
                   10358:     }
                   10359: # if specified, key authority is not course, but user
                   10360: # only active if keyaccess is yes
                   10361:     if ($args->{'keyauth'}) {
1.487     albertel 10362: 	my ($user,$domain) = split(':',$args->{'keyauth'});
                   10363: 	$user = &LONCAPA::clean_username($user);
                   10364: 	$domain = &LONCAPA::clean_username($domain);
1.488     foxr     10365: 	if ($user ne '' && $domain ne '') {
1.487     albertel 10366: 	    $cenv{'keyauth'}=$user.':'.$domain;
1.444     albertel 10367: 	}
                   10368:     }
                   10369: 
                   10370:     if ($args->{'disresdis'}) {
                   10371:         $cenv{'pch.roles.denied'}='st';
                   10372:     }
                   10373:     if ($args->{'disablechat'}) {
                   10374:         $cenv{'plc.roles.denied'}='st';
                   10375:     }
                   10376: 
                   10377:     # Record we've not yet viewed the Course Initialization Helper for this 
                   10378:     # course
                   10379:     $cenv{'course.helper.not.run'} = 1;
                   10380:     #
                   10381:     # Use new Randomseed
                   10382:     #
                   10383:     $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
                   10384:     $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
                   10385:     #
                   10386:     # The encryption code and receipt prefix for this course
                   10387:     #
                   10388:     $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
                   10389:     $cenv{'internal.encpref'}=100+int(9*rand(99));
                   10390:     #
                   10391:     # By default, use standard grading
                   10392:     if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
                   10393: 
1.541     raeburn  10394:     $outcome .= $linefeed.&mt('Setting environment').': '.                 
                   10395:           &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444     albertel 10396: #
                   10397: # Open all assignments
                   10398: #
                   10399:     if ($args->{'openall'}) {
                   10400:        my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
                   10401:        my %storecontent = ($storeunder         => time,
                   10402:                            $storeunder.'.type' => 'date_start');
                   10403:        
                   10404:        $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541     raeburn  10405:                  ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444     albertel 10406:    }
                   10407: #
                   10408: # Set first page
                   10409: #
                   10410:     unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
                   10411: 	    || ($cloneid)) {
1.445     albertel 10412: 	use LONCAPA::map;
1.444     albertel 10413: 	$outcome .= &mt('Setting first resource').': ';
1.445     albertel 10414: 
                   10415: 	my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
                   10416:         my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
                   10417: 
1.444     albertel 10418:         $outcome .= ($fatal?$errtext:'read ok').' - ';
                   10419:         my $title; my $url;
                   10420:         if ($args->{'firstres'} eq 'syl') {
1.690     bisitz   10421: 	    $title=&mt('Syllabus');
1.444     albertel 10422:             $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
                   10423:         } else {
1.963   ! raeburn  10424:             $title=&mt('Table of Contents');
1.444     albertel 10425:             $url='/adm/navmaps';
                   10426:         }
1.445     albertel 10427: 
                   10428:         $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
                   10429: 	(my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
                   10430: 
                   10431: 	if ($errtext) { $fatal=2; }
1.541     raeburn  10432:         $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444     albertel 10433:     }
1.566     albertel 10434: 
                   10435:     return (1,$outcome);
1.444     albertel 10436: }
                   10437: 
                   10438: ############################################################
                   10439: ############################################################
                   10440: 
1.953     droeschl 10441: #SD
                   10442: # only Community and Course, or anything else?
1.378     raeburn  10443: sub course_type {
                   10444:     my ($cid) = @_;
                   10445:     if (!defined($cid)) {
                   10446:         $cid = $env{'request.course.id'};
                   10447:     }
1.404     albertel 10448:     if (defined($env{'course.'.$cid.'.type'})) {
                   10449:         return $env{'course.'.$cid.'.type'};
1.378     raeburn  10450:     } else {
                   10451:         return 'Course';
1.377     raeburn  10452:     }
                   10453: }
1.156     albertel 10454: 
1.406     raeburn  10455: sub group_term {
                   10456:     my $crstype = &course_type();
                   10457:     my %names = (
                   10458:                   'Course' => 'group',
1.865     raeburn  10459:                   'Community' => 'group',
1.406     raeburn  10460:                 );
                   10461:     return $names{$crstype};
                   10462: }
                   10463: 
1.902     raeburn  10464: sub course_types {
                   10465:     my @types = ('official','unofficial','community');
                   10466:     my %typename = (
                   10467:                          official   => 'Official course',
                   10468:                          unofficial => 'Unofficial course',
                   10469:                          community  => 'Community',
                   10470:                    );
                   10471:     return (\@types,\%typename);
                   10472: }
                   10473: 
1.156     albertel 10474: sub icon {
                   10475:     my ($file)=@_;
1.505     albertel 10476:     my $curfext = lc((split(/\./,$file))[-1]);
1.168     albertel 10477:     my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156     albertel 10478:     my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168     albertel 10479:     if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
                   10480: 	if (-e  $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
                   10481: 	          $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   10482: 	            $curfext.".gif") {
                   10483: 	    $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   10484: 		$curfext.".gif";
                   10485: 	}
                   10486:     }
1.249     albertel 10487:     return &lonhttpdurl($iconname);
1.154     albertel 10488: } 
1.84      albertel 10489: 
1.575     albertel 10490: sub lonhttpdurl {
1.692     www      10491: #
                   10492: # Had been used for "small fry" static images on separate port 8080.
                   10493: # Modify here if lightweight http functionality desired again.
                   10494: # Currently eliminated due to increasing firewall issues.
                   10495: #
1.575     albertel 10496:     my ($url)=@_;
1.692     www      10497:     return $url;
1.215     albertel 10498: }
                   10499: 
1.213     albertel 10500: sub connection_aborted {
                   10501:     my ($r)=@_;
                   10502:     $r->print(" ");$r->rflush();
                   10503:     my $c = $r->connection;
                   10504:     return $c->aborted();
                   10505: }
                   10506: 
1.221     foxr     10507: #    Escapes strings that may have embedded 's that will be put into
1.222     foxr     10508: #    strings as 'strings'.
                   10509: sub escape_single {
1.221     foxr     10510:     my ($input) = @_;
1.223     albertel 10511:     $input =~ s/\\/\\\\/g;	# Escape the \'s..(must be first)>
1.221     foxr     10512:     $input =~ s/\'/\\\'/g;	# Esacpe the 's....
                   10513:     return $input;
                   10514: }
1.223     albertel 10515: 
1.222     foxr     10516: #  Same as escape_single, but escape's "'s  This 
                   10517: #  can be used for  "strings"
                   10518: sub escape_double {
                   10519:     my ($input) = @_;
                   10520:     $input =~ s/\\/\\\\/g;	# Escape the /'s..(must be first)>
                   10521:     $input =~ s/\"/\\\"/g;	# Esacpe the "s....
                   10522:     return $input;
                   10523: }
1.223     albertel 10524:  
1.222     foxr     10525: #   Escapes the last element of a full URL.
                   10526: sub escape_url {
                   10527:     my ($url)   = @_;
1.238     raeburn  10528:     my @urlslices = split(/\//, $url,-1);
1.369     www      10529:     my $lastitem = &escape(pop(@urlslices));
1.223     albertel 10530:     return join('/',@urlslices).'/'.$lastitem;
1.222     foxr     10531: }
1.462     albertel 10532: 
1.820     raeburn  10533: sub compare_arrays {
                   10534:     my ($arrayref1,$arrayref2) = @_;
                   10535:     my (@difference,%count);
                   10536:     @difference = ();
                   10537:     %count = ();
                   10538:     if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
                   10539:         foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
                   10540:         foreach my $element (keys(%count)) {
                   10541:             if ($count{$element} == 1) {
                   10542:                 push(@difference,$element);
                   10543:             }
                   10544:         }
                   10545:     }
                   10546:     return @difference;
                   10547: }
                   10548: 
1.817     bisitz   10549: # -------------------------------------------------------- Initialize user login
1.462     albertel 10550: sub init_user_environment {
1.463     albertel 10551:     my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462     albertel 10552:     my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
                   10553: 
                   10554:     my $public=($username eq 'public' && $domain eq 'public');
                   10555: 
                   10556: # See if old ID present, if so, remove
                   10557: 
                   10558:     my ($filename,$cookie,$userroles);
                   10559:     my $now=time;
                   10560: 
                   10561:     if ($public) {
                   10562: 	my $max_public=100;
                   10563: 	my $oldest;
                   10564: 	my $oldest_time=0;
                   10565: 	for(my $next=1;$next<=$max_public;$next++) {
                   10566: 	    if (-e $lonids."/publicuser_$next.id") {
                   10567: 		my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
                   10568: 		if ($mtime<$oldest_time || !$oldest_time) {
                   10569: 		    $oldest_time=$mtime;
                   10570: 		    $oldest=$next;
                   10571: 		}
                   10572: 	    } else {
                   10573: 		$cookie="publicuser_$next";
                   10574: 		last;
                   10575: 	    }
                   10576: 	}
                   10577: 	if (!$cookie) { $cookie="publicuser_$oldest"; }
                   10578:     } else {
1.463     albertel 10579: 	# if this isn't a robot, kill any existing non-robot sessions
                   10580: 	if (!$args->{'robot'}) {
                   10581: 	    opendir(DIR,$lonids);
                   10582: 	    while ($filename=readdir(DIR)) {
                   10583: 		if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
                   10584: 		    unlink($lonids.'/'.$filename);
                   10585: 		}
1.462     albertel 10586: 	    }
1.463     albertel 10587: 	    closedir(DIR);
1.462     albertel 10588: 	}
                   10589: # Give them a new cookie
1.463     albertel 10590: 	my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684     www      10591: 		                   : $now.$$.int(rand(10000)));
1.463     albertel 10592: 	$cookie="$username\_$id\_$domain\_$authhost";
1.462     albertel 10593:     
                   10594: # Initialize roles
                   10595: 
                   10596: 	$userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
                   10597:     }
                   10598: # ------------------------------------ Check browser type and MathML capability
                   10599: 
                   10600:     my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
                   10601:         $clientunicode,$clientos) = &decode_user_agent($r);
                   10602: 
                   10603: # ------------------------------------------------------------- Get environment
                   10604: 
                   10605:     my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
                   10606:     my ($tmp) = keys(%userenv);
                   10607:     if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   10608:     } else {
                   10609: 	undef(%userenv);
                   10610:     }
                   10611:     if (($userenv{'interface'}) && (!$form->{'interface'})) {
                   10612: 	$form->{'interface'}=$userenv{'interface'};
                   10613:     }
                   10614:     if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
                   10615: 
                   10616: # --------------- Do not trust query string to be put directly into environment
1.817     bisitz   10617:     foreach my $option ('interface','localpath','localres') {
                   10618:         $form->{$option}=~s/[\n\r\=]//gs;
1.462     albertel 10619:     }
                   10620: # --------------------------------------------------------- Write first profile
                   10621: 
                   10622:     {
                   10623: 	my %initial_env = 
                   10624: 	    ("user.name"          => $username,
                   10625: 	     "user.domain"        => $domain,
                   10626: 	     "user.home"          => $authhost,
                   10627: 	     "browser.type"       => $clientbrowser,
                   10628: 	     "browser.version"    => $clientversion,
                   10629: 	     "browser.mathml"     => $clientmathml,
                   10630: 	     "browser.unicode"    => $clientunicode,
                   10631: 	     "browser.os"         => $clientos,
                   10632: 	     "server.domain"      => $Apache::lonnet::perlvar{'lonDefDomain'},
                   10633: 	     "request.course.fn"  => '',
                   10634: 	     "request.course.uri" => '',
                   10635: 	     "request.course.sec" => '',
                   10636: 	     "request.role"       => 'cm',
                   10637: 	     "request.role.adv"   => $env{'user.adv'},
                   10638: 	     "request.host"       => $ENV{'REMOTE_ADDR'},);
                   10639: 
                   10640:         if ($form->{'localpath'}) {
                   10641: 	    $initial_env{"browser.localpath"}  = $form->{'localpath'};
                   10642: 	    $initial_env{"browser.localres"}   = $form->{'localres'};
                   10643:         }
                   10644: 	
                   10645: 	if ($form->{'interface'}) {
                   10646: 	    $form->{'interface'}=~s/\W//gs;
                   10647: 	    $initial_env{"browser.interface"} = $form->{'interface'};
                   10648: 	    $env{'browser.interface'}=$form->{'interface'};
                   10649: 	}
                   10650: 
1.724     raeburn  10651:         foreach my $tool ('aboutme','blog','portfolio') {
                   10652:             $userenv{'availabletools.'.$tool} = 
                   10653:                 &Apache::lonnet::usertools_access($username,$domain,$tool,'reload');
                   10654:         }
                   10655: 
1.864     raeburn  10656:         foreach my $crstype ('official','unofficial','community') {
1.765     raeburn  10657:             $userenv{'canrequest.'.$crstype} =
                   10658:                 &Apache::lonnet::usertools_access($username,$domain,$crstype,
                   10659:                                                   'reload','requestcourses');
                   10660:         }
                   10661: 
1.462     albertel 10662: 	$env{'user.environment'} = "$lonids/$cookie.id";
                   10663: 	
                   10664: 	if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
                   10665: 		 &GDBM_WRCREAT(),0640)) {
                   10666: 	    &_add_to_env(\%disk_env,\%initial_env);
                   10667: 	    &_add_to_env(\%disk_env,\%userenv,'environment.');
                   10668: 	    &_add_to_env(\%disk_env,$userroles);
1.463     albertel 10669: 	    if (ref($args->{'extra_env'})) {
                   10670: 		&_add_to_env(\%disk_env,$args->{'extra_env'});
                   10671: 	    }
1.462     albertel 10672: 	    untie(%disk_env);
                   10673: 	} else {
1.705     tempelho 10674: 	    &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
                   10675: 			   'Could not create environment storage in lonauth: '.$!.'</span>');
1.462     albertel 10676: 	    return 'error: '.$!;
                   10677: 	}
                   10678:     }
                   10679:     $env{'request.role'}='cm';
                   10680:     $env{'request.role.adv'}=$env{'user.adv'};
                   10681:     $env{'browser.type'}=$clientbrowser;
                   10682: 
                   10683:     return $cookie;
                   10684: 
                   10685: }
                   10686: 
                   10687: sub _add_to_env {
                   10688:     my ($idf,$env_data,$prefix) = @_;
1.676     raeburn  10689:     if (ref($env_data) eq 'HASH') {
                   10690:         while (my ($key,$value) = each(%$env_data)) {
                   10691: 	    $idf->{$prefix.$key} = $value;
                   10692: 	    $env{$prefix.$key}   = $value;
                   10693:         }
1.462     albertel 10694:     }
                   10695: }
                   10696: 
1.685     tempelho 10697: # --- Get the symbolic name of a problem and the url
                   10698: sub get_symb {
                   10699:     my ($request,$silent) = @_;
1.726     raeburn  10700:     (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685     tempelho 10701:     my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
                   10702:     if ($symb eq '') {
                   10703:         if (!$silent) {
                   10704:             $request->print("Unable to handle ambiguous references:$url:.");
                   10705:             return ();
                   10706:         }
                   10707:     }
                   10708:     &Apache::lonenc::check_decrypt(\$symb);
                   10709:     return ($symb);
                   10710: }
                   10711: 
                   10712: # --------------------------------------------------------------Get annotation
                   10713: 
                   10714: sub get_annotation {
                   10715:     my ($symb,$enc) = @_;
                   10716: 
                   10717:     my $key = $symb;
                   10718:     if (!$enc) {
                   10719:         $key =
                   10720:             &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
                   10721:     }
                   10722:     my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
                   10723:     return $annotation{$key};
                   10724: }
                   10725: 
                   10726: sub clean_symb {
1.731     raeburn  10727:     my ($symb,$delete_enc) = @_;
1.685     tempelho 10728: 
                   10729:     &Apache::lonenc::check_decrypt(\$symb);
                   10730:     my $enc = $env{'request.enc'};
1.731     raeburn  10731:     if ($delete_enc) {
1.730     raeburn  10732:         delete($env{'request.enc'});
                   10733:     }
1.685     tempelho 10734: 
                   10735:     return ($symb,$enc);
                   10736: }
1.462     albertel 10737: 
1.41      ng       10738: =pod
                   10739: 
                   10740: =back
                   10741: 
1.112     bowersj2 10742: =cut
1.41      ng       10743: 
1.112     bowersj2 10744: 1;
                   10745: __END__;
1.41      ng       10746: 

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