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

1.10      albertel    1: # The LearningOnline Network with CAPA
1.1       albertel    2: # a pile of common routines
1.10      albertel    3: #
1.856   ! bisitz      4: # $Id: loncommon.pm,v 1.855 2009/07/09 17:17:49 bisitz 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.468     raeburn   485:     my ($domainfilter,$sec_element,$formname)=@_;
1.377     raeburn   486:     my $crs_or_grp_alert = &mt('Please select the type of LON-CAPA entity - Course or Group - for which you wish to add/modify a user role');
1.468     raeburn   487:    my $output = '
1.776     bisitz    488: <script type="text/javascript" language="JavaScript">
1.824     bisitz    489: // <![CDATA[
1.468     raeburn   490:     var stdeditbrowser;'."\n";
                    491:    $output .= <<"ENDSTDBRW";
1.377     raeburn   492:     function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,crstype) {
1.91      www       493:         var url = '/adm/pickcourse?';
1.468     raeburn   494:         var domainfilter = '';
                    495:         var formid = getFormIdByName(formname);
                    496:         if (formid > -1) {
                    497:             var domid = getIndexByName(formid,udom);
                    498:             if (domid > -1) {
                    499:                 if (document.forms[formid].elements[domid].type == 'select-one') {
                    500:                     domainfilter=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
                    501:                 }
                    502:                 if (document.forms[formid].elements[domid].type == 'hidden') {
                    503:                     domainfilter=document.forms[formid].elements[domid].value;
                    504:                 }
                    505:             }
1.91      www       506:         }
1.128     albertel  507:         if (domainfilter != null) {
                    508:            if (domainfilter != '') {
                    509:                url += 'domainfilter='+domainfilter+'&';
                    510: 	   }
                    511:         }
1.91      www       512:         url += 'form=' + formname + '&cnumelement='+uname+
1.187     albertel  513: 	                            '&cdomelement='+udom+
                    514:                                     '&cnameelement='+desc;
1.468     raeburn   515:         if (extra_element !=null && extra_element != '') {
1.594     raeburn   516:             if (formname == 'rolechoice' || formname == 'studentform') {
1.468     raeburn   517:                 url += '&roleelement='+extra_element;
                    518:                 if (domainfilter == null || domainfilter == '') {
                    519:                     url += '&domainfilter='+extra_element;
                    520:                 }
1.234     raeburn   521:             }
1.468     raeburn   522:             else {
                    523:                 if (formname == 'portform') {
                    524:                     url += '&setroles='+extra_element;
1.800     raeburn   525:                 } else {
                    526:                     if (formname == 'rules') {
                    527:                         url += '&fixeddom='+extra_element; 
                    528:                     }
1.468     raeburn   529:                 }
                    530:             }     
1.230     raeburn   531:         }
1.293     raeburn   532:         if (multflag !=null && multflag != '') {
                    533:             url += '&multiple='+multflag;
                    534:         }
1.377     raeburn   535:         if (crstype == 'Course/Group') {
                    536:             if (formname == 'cu') {
                    537:                 crstype = document.cu.crstype.options[document.cu.crstype.selectedIndex].value; 
                    538:                 if (crstype == "") {
                    539:                     alert("$crs_or_grp_alert");
                    540:                     return;
                    541:                 }
                    542:             }
                    543:         }
                    544:         if (crstype !=null && crstype != '') {
                    545:             url += '&type='+crstype;
                    546:         }
1.102     www       547:         var title = 'Course_Browser';
1.91      www       548:         var options = 'scrollbars=1,resizable=1,menubar=0';
                    549:         options += ',width=700,height=600';
                    550:         stdeditbrowser = open(url,title,options,'1');
                    551:         stdeditbrowser.focus();
                    552:     }
1.468     raeburn   553: 
                    554:     function getFormIdByName(formname) {
                    555:         for (var i=0;i<document.forms.length;i++) {
                    556:             if (document.forms[i].name == formname) {
                    557:                 return i;
                    558:             }
                    559:         }
                    560:         return -1; 
                    561:     }
                    562: 
                    563:     function getIndexByName(formid,item) {
                    564:         for (var i=0;i<document.forms[formid].elements.length;i++) {
                    565:             if (document.forms[formid].elements[i].name == item) {
                    566:                 return i;
                    567:             }
                    568:         }
                    569:         return -1;
                    570:     }
1.91      www       571: ENDSTDBRW
1.468     raeburn   572:     if ($sec_element ne '') {
                    573:         $output .= &setsec_javascript($sec_element,$formname);
                    574:     }
                    575:     $output .= '
1.824     bisitz    576: // ]]>
1.468     raeburn   577: </script>';
                    578:     return $output;
                    579: }
                    580: 
                    581: sub setsec_javascript {
                    582:     my ($sec_element,$formname) = @_;
                    583:     my $setsections = qq|
                    584: function setSect(sectionlist) {
1.629     raeburn   585:     var sectionsArray = new Array();
                    586:     if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
                    587:         sectionsArray = sectionlist.split(",");
                    588:     }
1.468     raeburn   589:     var numSections = sectionsArray.length;
                    590:     document.$formname.$sec_element.length = 0;
                    591:     if (numSections == 0) {
                    592:         document.$formname.$sec_element.multiple=false;
                    593:         document.$formname.$sec_element.size=1;
                    594:         document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
                    595:     } else {
                    596:         if (numSections == 1) {
                    597:             document.$formname.$sec_element.multiple=false;
                    598:             document.$formname.$sec_element.size=1;
                    599:             document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
                    600:             document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
                    601:             document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
                    602:         } else {
                    603:             for (var i=0; i<numSections; i++) {
                    604:                 document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
                    605:             }
                    606:             document.$formname.$sec_element.multiple=true
                    607:             if (numSections < 3) {
                    608:                 document.$formname.$sec_element.size=numSections;
                    609:             } else {
                    610:                 document.$formname.$sec_element.size=3;
                    611:             }
                    612:             document.$formname.$sec_element.options[0].selected = false
                    613:         }
                    614:     }
1.91      www       615: }
1.468     raeburn   616: |;
                    617:     return $setsections;
                    618: }
                    619: 
1.91      www       620: 
                    621: sub selectcourse_link {
1.377     raeburn   622:    my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype)=@_;
1.787     bisitz    623:    return '<span class="LC_nobreak">'
                    624:          ."<a href='"
                    625:          .'javascript:opencrsbrowser("'.$form.'","'.$unameele
                    626:          .'","'.$udomele.'","'.$desc.'","'.$extra_element
                    627:          .'","'.$multflag.'","'.$selecttype.'");'
                    628:          ."'>".&mt('Select Course').'</a>'
                    629:          .'</span>';
1.74      www       630: }
1.42      matthew   631: 
1.653     raeburn   632: sub selectauthor_link {
                    633:    my ($form,$udom)=@_;
                    634:    return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
                    635:           &mt('Select Author').'</a>';
                    636: }
                    637: 
1.273     raeburn   638: sub check_uncheck_jscript {
                    639:     my $jscript = <<"ENDSCRT";
                    640: function checkAll(field) {
                    641:     if (field.length > 0) {
                    642:         for (i = 0; i < field.length; i++) {
                    643:             field[i].checked = true ;
                    644:         }
                    645:     } else {
                    646:         field.checked = true
                    647:     }
                    648: }
                    649:  
                    650: function uncheckAll(field) {
                    651:     if (field.length > 0) {
                    652:         for (i = 0; i < field.length; i++) {
                    653:             field[i].checked = false ;
1.543     albertel  654:         }
                    655:     } else {
1.273     raeburn   656:         field.checked = false ;
                    657:     }
                    658: }
                    659: ENDSCRT
                    660:     return $jscript;
                    661: }
                    662: 
1.656     www       663: sub select_timezone {
1.659     raeburn   664:    my ($name,$selected,$onchange,$includeempty)=@_;
                    665:    my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
                    666:    if ($includeempty) {
                    667:        $output .= '<option value=""';
                    668:        if (($selected eq '') || ($selected eq 'local')) {
                    669:            $output .= ' selected="selected" ';
                    670:        }
                    671:        $output .= '> </option>';
                    672:    }
1.657     raeburn   673:    my @timezones = DateTime::TimeZone->all_names;
                    674:    foreach my $tzone (@timezones) {
                    675:        $output.= '<option value="'.$tzone.'"';
                    676:        if ($tzone eq $selected) {
                    677:            $output.=' selected="selected"';
                    678:        }
                    679:        $output.=">$tzone</option>\n";
1.656     www       680:    }
                    681:    $output.="</select>";
                    682:    return $output;
                    683: }
1.273     raeburn   684: 
1.687     raeburn   685: sub select_datelocale {
                    686:     my ($name,$selected,$onchange,$includeempty)=@_;
                    687:     my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
                    688:     if ($includeempty) {
                    689:         $output .= '<option value=""';
                    690:         if ($selected eq '') {
                    691:             $output .= ' selected="selected" ';
                    692:         }
                    693:         $output .= '> </option>';
                    694:     }
                    695:     my (@possibles,%locale_names);
                    696:     my @locales = DateTime::Locale::Catalog::Locales;
                    697:     foreach my $locale (@locales) {
                    698:         if (ref($locale) eq 'HASH') {
                    699:             my $id = $locale->{'id'};
                    700:             if ($id ne '') {
                    701:                 my $en_terr = $locale->{'en_territory'};
                    702:                 my $native_terr = $locale->{'native_territory'};
1.695     raeburn   703:                 my @languages = &Apache::lonlocal::preferred_languages();
1.687     raeburn   704:                 if (grep(/^en$/,@languages) || !@languages) {
                    705:                     if ($en_terr ne '') {
                    706:                         $locale_names{$id} = '('.$en_terr.')';
                    707:                     } elsif ($native_terr ne '') {
                    708:                         $locale_names{$id} = $native_terr;
                    709:                     }
                    710:                 } else {
                    711:                     if ($native_terr ne '') {
                    712:                         $locale_names{$id} = $native_terr.' ';
                    713:                     } elsif ($en_terr ne '') {
                    714:                         $locale_names{$id} = '('.$en_terr.')';
                    715:                     }
                    716:                 }
                    717:                 push (@possibles,$id);
                    718:             }
                    719:         }
                    720:     }
                    721:     foreach my $item (sort(@possibles)) {
                    722:         $output.= '<option value="'.$item.'"';
                    723:         if ($item eq $selected) {
                    724:             $output.=' selected="selected"';
                    725:         }
                    726:         $output.=">$item";
                    727:         if ($locale_names{$item} ne '') {
                    728:             $output.="  $locale_names{$item}</option>\n";
                    729:         }
                    730:         $output.="</option>\n";
                    731:     }
                    732:     $output.="</select>";
                    733:     return $output;
                    734: }
                    735: 
1.792     raeburn   736: sub select_language {
                    737:     my ($name,$selected,$includeempty) = @_;
                    738:     my %langchoices;
                    739:     if ($includeempty) {
                    740:         %langchoices = ('' => 'No language preference');
                    741:     }
                    742:     foreach my $id (&languageids()) {
                    743:         my $code = &supportedlanguagecode($id);
                    744:         if ($code) {
                    745:             $langchoices{$code} = &plainlanguagedescription($id);
                    746:         }
                    747:     }
                    748:     return &select_form($selected,$name,%langchoices);
                    749: }
                    750: 
1.42      matthew   751: =pod
1.36      matthew   752: 
1.648     raeburn   753: =item * &linked_select_forms(...)
1.36      matthew   754: 
                    755: linked_select_forms returns a string containing a <script></script> block
                    756: and html for two <select> menus.  The select menus will be linked in that
                    757: changing the value of the first menu will result in new values being placed
                    758: in the second menu.  The values in the select menu will appear in alphabetical
1.609     raeburn   759: order unless a defined order is provided.
1.36      matthew   760: 
                    761: linked_select_forms takes the following ordered inputs:
                    762: 
                    763: =over 4
                    764: 
1.112     bowersj2  765: =item * $formname, the name of the <form> tag
1.36      matthew   766: 
1.112     bowersj2  767: =item * $middletext, the text which appears between the <select> tags
1.36      matthew   768: 
1.112     bowersj2  769: =item * $firstdefault, the default value for the first menu
1.36      matthew   770: 
1.112     bowersj2  771: =item * $firstselectname, the name of the first <select> tag
1.36      matthew   772: 
1.112     bowersj2  773: =item * $secondselectname, the name of the second <select> tag
1.36      matthew   774: 
1.112     bowersj2  775: =item * $hashref, a reference to a hash containing the data for the menus.
1.36      matthew   776: 
1.609     raeburn   777: =item * $menuorder, the order of values in the first menu
                    778: 
1.41      ng        779: =back 
                    780: 
1.36      matthew   781: Below is an example of such a hash.  Only the 'text', 'default', and 
                    782: 'select2' keys must appear as stated.  keys(%menu) are the possible 
                    783: values for the first select menu.  The text that coincides with the 
1.41      ng        784: first menu value is given in $menu{$choice1}->{'text'}.  The values 
1.36      matthew   785: and text for the second menu are given in the hash pointed to by 
                    786: $menu{$choice1}->{'select2'}.  
                    787: 
1.112     bowersj2  788:  my %menu = ( A1 => { text =>"Choice A1" ,
                    789:                        default => "B3",
                    790:                        select2 => { 
                    791:                            B1 => "Choice B1",
                    792:                            B2 => "Choice B2",
                    793:                            B3 => "Choice B3",
                    794:                            B4 => "Choice B4"
1.609     raeburn   795:                            },
                    796:                        order => ['B4','B3','B1','B2'],
1.112     bowersj2  797:                    },
                    798:                A2 => { text =>"Choice A2" ,
                    799:                        default => "C2",
                    800:                        select2 => { 
                    801:                            C1 => "Choice C1",
                    802:                            C2 => "Choice C2",
                    803:                            C3 => "Choice C3"
1.609     raeburn   804:                            },
                    805:                        order => ['C2','C1','C3'],
1.112     bowersj2  806:                    },
                    807:                A3 => { text =>"Choice A3" ,
                    808:                        default => "D6",
                    809:                        select2 => { 
                    810:                            D1 => "Choice D1",
                    811:                            D2 => "Choice D2",
                    812:                            D3 => "Choice D3",
                    813:                            D4 => "Choice D4",
                    814:                            D5 => "Choice D5",
                    815:                            D6 => "Choice D6",
                    816:                            D7 => "Choice D7"
1.609     raeburn   817:                            },
                    818:                        order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112     bowersj2  819:                    }
                    820:                );
1.36      matthew   821: 
                    822: =cut
                    823: 
                    824: sub linked_select_forms {
                    825:     my ($formname,
                    826:         $middletext,
                    827:         $firstdefault,
                    828:         $firstselectname,
                    829:         $secondselectname, 
1.609     raeburn   830:         $hashref,
                    831:         $menuorder,
1.36      matthew   832:         ) = @_;
                    833:     my $second = "document.$formname.$secondselectname";
                    834:     my $first = "document.$formname.$firstselectname";
                    835:     # output the javascript to do the changing
                    836:     my $result = '';
1.776     bisitz    837:     $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824     bisitz    838:     $result.="// <![CDATA[\n";
1.36      matthew   839:     $result.="var select2data = new Object();\n";
                    840:     $" = '","';
                    841:     my $debug = '';
                    842:     foreach my $s1 (sort(keys(%$hashref))) {
                    843:         $result.="select2data.d_$s1 = new Object();\n";        
                    844:         $result.="select2data.d_$s1.def = new String('".
                    845:             $hashref->{$s1}->{'default'}."');\n";
1.609     raeburn   846:         $result.="select2data.d_$s1.values = new Array(";
1.36      matthew   847:         my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609     raeburn   848:         if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
                    849:             @s2values = @{$hashref->{$s1}->{'order'}};
                    850:         }
1.36      matthew   851:         $result.="\"@s2values\");\n";
                    852:         $result.="select2data.d_$s1.texts = new Array(";        
                    853:         my @s2texts;
                    854:         foreach my $value (@s2values) {
                    855:             push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
                    856:         }
                    857:         $result.="\"@s2texts\");\n";
                    858:     }
                    859:     $"=' ';
                    860:     $result.= <<"END";
                    861: 
                    862: function select1_changed() {
                    863:     // Determine new choice
                    864:     var newvalue = "d_" + $first.value;
                    865:     // update select2
                    866:     var values     = select2data[newvalue].values;
                    867:     var texts      = select2data[newvalue].texts;
                    868:     var select2def = select2data[newvalue].def;
                    869:     var i;
                    870:     // out with the old
                    871:     for (i = 0; i < $second.options.length; i++) {
                    872:         $second.options[i] = null;
                    873:     }
                    874:     // in with the nuclear
                    875:     for (i=0;i<values.length; i++) {
                    876:         $second.options[i] = new Option(values[i]);
1.143     matthew   877:         $second.options[i].value = values[i];
1.36      matthew   878:         $second.options[i].text = texts[i];
                    879:         if (values[i] == select2def) {
                    880:             $second.options[i].selected = true;
                    881:         }
                    882:     }
                    883: }
1.824     bisitz    884: // ]]>
1.36      matthew   885: </script>
                    886: END
                    887:     # output the initial values for the selection lists
                    888:     $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609     raeburn   889:     my @order = sort(keys(%{$hashref}));
                    890:     if (ref($menuorder) eq 'ARRAY') {
                    891:         @order = @{$menuorder};
                    892:     }
                    893:     foreach my $value (@order) {
1.36      matthew   894:         $result.="    <option value=\"$value\" ";
1.253     albertel  895:         $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119     www       896:         $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36      matthew   897:     }
                    898:     $result .= "</select>\n";
                    899:     my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
                    900:     $result .= $middletext;
                    901:     $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
                    902:     my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609     raeburn   903:     
                    904:     my @secondorder = sort(keys(%select2));
                    905:     if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
                    906:         @secondorder = @{$hashref->{$firstdefault}->{'order'}};
                    907:     }
                    908:     foreach my $value (@secondorder) {
1.36      matthew   909:         $result.="    <option value=\"$value\" ";        
1.253     albertel  910:         $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119     www       911:         $result.=">".&mt($select2{$value})."</option>\n";
1.36      matthew   912:     }
                    913:     $result .= "</select>\n";
                    914:     #    return $debug;
                    915:     return $result;
                    916: }   #  end of sub linked_select_forms {
                    917: 
1.45      matthew   918: =pod
1.44      bowersj2  919: 
1.648     raeburn   920: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height)
1.44      bowersj2  921: 
1.112     bowersj2  922: Returns a string corresponding to an HTML link to the given help
                    923: $topic, where $topic corresponds to the name of a .tex file in
                    924: /home/httpd/html/adm/help/tex, with underscores replaced by
                    925: spaces. 
                    926: 
                    927: $text will optionally be linked to the same topic, allowing you to
                    928: link text in addition to the graphic. If you do not want to link
                    929: text, but wish to specify one of the later parameters, pass an
                    930: empty string. 
                    931: 
                    932: $stayOnPage is a value that will be interpreted as a boolean. If true,
                    933: the link will not open a new window. If false, the link will open
                    934: a new window using Javascript. (Default is false.) 
                    935: 
                    936: $width and $height are optional numerical parameters that will
                    937: override the width and height of the popped up window, which may
                    938: be useful for certain help topics with big pictures included. 
1.44      bowersj2  939: 
                    940: =cut
                    941: 
                    942: sub help_open_topic {
1.48      bowersj2  943:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
                    944:     $text = "" if (not defined $text);
1.44      bowersj2  945:     $stayOnPage = 0 if (not defined $stayOnPage);
                    946:     $width = 350 if (not defined $width);
                    947:     $height = 400 if (not defined $height);
                    948:     my $filename = $topic;
                    949:     $filename =~ s/ /_/g;
                    950: 
1.48      bowersj2  951:     my $template = "";
                    952:     my $link;
1.572     banghart  953:     
1.159     www       954:     $topic=~s/\W/\_/g;
1.44      bowersj2  955: 
1.572     banghart  956:     if (!$stayOnPage) {
1.72      bowersj2  957: 	$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  958:     } else {
1.48      bowersj2  959: 	$link = "/adm/help/${filename}.hlp";
                    960:     }
                    961: 
                    962:     # Add the text
1.755     neumanie  963:     if ($text ne "") {	
1.763     bisitz    964: 	$template.='<span class="LC_help_open_topic">'
                    965:                   .'<a target="_top" href="'.$link.'">'
                    966:                   .$text.'</a>';
1.48      bowersj2  967:     }
                    968: 
1.763     bisitz    969:     # (Always) Add the graphic
1.179     matthew   970:     my $title = &mt('Online Help');
1.667     raeburn   971:     my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.763     bisitz    972:     $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
                    973:               .'<img src="'.$helpicon.'" border="0"'
                    974:               .' alt="'.&mt('Help: [_1]',$topic).'"'
1.783     amueller  975:               .' title="'.$title.'"' 
1.763     bisitz    976:               .' /></a>';
                    977:     if ($text ne "") {	
                    978:         $template.='</span>';
                    979:     }
1.44      bowersj2  980:     return $template;
                    981: 
1.106     bowersj2  982: }
                    983: 
                    984: # This is a quicky function for Latex cheatsheet editing, since it 
                    985: # appears in at least four places
                    986: sub helpLatexCheatsheet {
1.732     raeburn   987:     my ($topic,$text,$not_author) = @_;
                    988:     my $out;
1.106     bowersj2  989:     my $addOther = '';
1.732     raeburn   990:     if ($topic) {
1.763     bisitz    991: 	$addOther = '<span>'.&Apache::loncommon::help_open_topic($topic,&mt($text),
                    992: 							       undef, undef, 600).
                    993: 								   '</span> ';
                    994:     }
                    995:     $out = '<span>' # Start cheatsheet
                    996: 	  .$addOther
                    997:           .'<span>'
                    998: 	  .&Apache::loncommon::help_open_topic('Greek_Symbols',&mt('Greek Symbols'),
                    999: 					       undef,undef,600)
                   1000: 	  .'</span> <span>'
                   1001: 	  .&Apache::loncommon::help_open_topic('Other_Symbols',&mt('Other Symbols'),
                   1002: 					       undef,undef,600)
                   1003: 	  .'</span>';
1.732     raeburn  1004:     unless ($not_author) {
1.763     bisitz   1005:         $out .= ' <span>'
                   1006: 	       .&Apache::loncommon::help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),
                   1007: 	                                            undef,undef,600)
                   1008: 	       .'</span>';
1.732     raeburn  1009:     }
1.763     bisitz   1010:     $out .= '</span>'; # End cheatsheet
1.732     raeburn  1011:     return $out;
1.172     www      1012: }
                   1013: 
1.430     albertel 1014: sub general_help {
                   1015:     my $helptopic='Student_Intro';
                   1016:     if ($env{'request.role'}=~/^(ca|au)/) {
                   1017: 	$helptopic='Authoring_Intro';
                   1018:     } elsif ($env{'request.role'}=~/^cc/) {
                   1019: 	$helptopic='Course_Coordination_Intro';
1.672     raeburn  1020:     } elsif ($env{'request.role'}=~/^dc/) {
                   1021:         $helptopic='Domain_Coordination_Intro';
1.430     albertel 1022:     }
                   1023:     return $helptopic;
                   1024: }
                   1025: 
                   1026: sub update_help_link {
                   1027:     my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
                   1028:     my $origurl = $ENV{'REQUEST_URI'};
                   1029:     $origurl=~s|^/~|/priv/|;
                   1030:     my $timestamp = time;
                   1031:     foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
                   1032:         $$datum = &escape($$datum);
                   1033:     }
                   1034: 
                   1035:     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";
                   1036:     my $output .= <<"ENDOUTPUT";
                   1037: <script type="text/javascript">
1.824     bisitz   1038: // <![CDATA[
1.430     albertel 1039: banner_link = '$banner_link';
1.824     bisitz   1040: // ]]>
1.430     albertel 1041: </script>
                   1042: ENDOUTPUT
                   1043:     return $output;
                   1044: }
                   1045: 
                   1046: # now just updates the help link and generates a blue icon
1.193     raeburn  1047: sub help_open_menu {
1.430     albertel 1048:     my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text) 
1.552     banghart 1049: 	= @_;    
1.430     albertel 1050:     $stayOnPage = 0 if (not defined $stayOnPage);
1.572     banghart 1051:     # only use pop-up help (stayOnPage == 0)
1.552     banghart 1052:     # if environment.remote is on (using remote control UI)
1.798     tempelho 1053:     if ($env{'environment.remote'} eq 'off' ) {
1.552     banghart 1054:         $stayOnPage=1;
1.430     albertel 1055:     }
                   1056:     my $output;
                   1057:     if ($component_help) {
                   1058: 	if (!$text) {
                   1059: 	    $output=&help_open_topic($component_help,undef,$stayOnPage,
                   1060: 				       $width,$height);
                   1061: 	} else {
                   1062: 	    my $help_text;
                   1063: 	    $help_text=&unescape($topic);
                   1064: 	    $output='<table><tr><td>'.
                   1065: 		&help_open_topic($component_help,$help_text,$stayOnPage,
                   1066: 				 $width,$height).'</td></tr></table>';
                   1067: 	}
                   1068:     }
                   1069:     my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
                   1070:     return $output.$banner_link;
                   1071: }
                   1072: 
                   1073: sub top_nav_help {
                   1074:     my ($text) = @_;
1.436     albertel 1075:     $text = &mt($text);
1.572     banghart 1076:     my $stay_on_page = 
1.798     tempelho 1077: 	($env{'environment.remote'} eq 'off' );
1.572     banghart 1078:     my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436     albertel 1079: 	                     : "javascript:helpMenu('open')";
1.572     banghart 1080:     my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436     albertel 1081: 
1.201     raeburn  1082:     my $title = &mt('Get help');
1.436     albertel 1083: 
                   1084:     return <<"END";
                   1085: $banner_link
                   1086:  <a href="$link" title="$title">$text</a>
                   1087: END
                   1088: }
                   1089: 
                   1090: sub help_menu_js {
                   1091:     my ($text) = @_;
                   1092: 
                   1093:     my $stayOnPage = 
1.798     tempelho 1094: 	($env{'environment.remote'} eq 'off' );
1.436     albertel 1095: 
                   1096:     my $width = 620;
                   1097:     my $height = 600;
1.430     albertel 1098:     my $helptopic=&general_help();
                   1099:     my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261     albertel 1100:     my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331     albertel 1101:     my $start_page =
                   1102:         &Apache::loncommon::start_page('Help Menu', undef,
                   1103: 				       {'frameset'    => 1,
                   1104: 					'js_ready'    => 1,
                   1105: 					'add_entries' => {
                   1106: 					    'border' => '0',
1.579     raeburn  1107: 					    'rows'   => "110,*",},});
1.331     albertel 1108:     my $end_page =
                   1109:         &Apache::loncommon::end_page({'frameset' => 1,
                   1110: 				      'js_ready' => 1,});
                   1111: 
1.436     albertel 1112:     my $template .= <<"ENDTEMPLATE";
                   1113: <script type="text/javascript">
1.253     albertel 1114: // <!-- BEGIN LON-CAPA Internal
                   1115: // <![CDATA[
1.430     albertel 1116: var banner_link = '';
1.243     raeburn  1117: function helpMenu(target) {
                   1118:     var caller = this;
                   1119:     if (target == 'open') {
                   1120:         var newWindow = null;
                   1121:         try {
1.262     albertel 1122:             newWindow =  window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243     raeburn  1123:         }
                   1124:         catch(error) {
                   1125:             writeHelp(caller);
                   1126:             return;
                   1127:         }
                   1128:         if (newWindow) {
                   1129:             caller = newWindow;
                   1130:         }
1.193     raeburn  1131:     }
1.243     raeburn  1132:     writeHelp(caller);
                   1133:     return;
                   1134: }
                   1135: function writeHelp(caller) {
1.430     albertel 1136:     caller.document.writeln('$start_page<frame name="bannerframe"  src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243     raeburn  1137:     caller.document.close()
                   1138:     caller.focus()
1.193     raeburn  1139: }
1.253     albertel 1140: // ]]>
1.219     albertel 1141: // END LON-CAPA Internal -->
1.436     albertel 1142: </script>
1.193     raeburn  1143: ENDTEMPLATE
                   1144:     return $template;
                   1145: }
                   1146: 
1.172     www      1147: sub help_open_bug {
                   1148:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258     albertel 1149:     unless ($env{'user.adv'}) { return ''; }
1.172     www      1150:     unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
                   1151:     $text = "" if (not defined $text);
                   1152:     $stayOnPage = 0 if (not defined $stayOnPage);
1.798     tempelho 1153:     if ($env{'environment.remote'} eq 'off' ) {
1.172     www      1154: 	$stayOnPage=1;
                   1155:     }
1.184     albertel 1156:     $width = 600 if (not defined $width);
                   1157:     $height = 600 if (not defined $height);
1.172     www      1158: 
                   1159:     $topic=~s/\W+/\+/g;
                   1160:     my $link='';
                   1161:     my $template='';
1.379     albertel 1162:     my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&amp;bug_file_loc='.
                   1163: 	&escape($ENV{'REQUEST_URI'}).'&amp;component='.$topic;
1.172     www      1164:     if (!$stayOnPage)
                   1165:     {
                   1166: 	$link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
                   1167:     }
                   1168:     else
                   1169:     {
                   1170: 	$link = $url;
                   1171:     }
                   1172:     # Add the text
                   1173:     if ($text ne "")
                   1174:     {
                   1175: 	$template .= 
                   1176:   "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705     tempelho 1177:   "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172     www      1178:     }
                   1179: 
                   1180:     # Add the graphic
1.179     matthew  1181:     my $title = &mt('Report a Bug');
1.215     albertel 1182:     my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172     www      1183:     $template .= <<"ENDTEMPLATE";
1.436     albertel 1184:  <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172     www      1185: ENDTEMPLATE
                   1186:     if ($text ne '') { $template.='</td></tr></table>' };
                   1187:     return $template;
                   1188: 
                   1189: }
                   1190: 
                   1191: sub help_open_faq {
                   1192:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258     albertel 1193:     unless ($env{'user.adv'}) { return ''; }
1.172     www      1194:     unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
                   1195:     $text = "" if (not defined $text);
                   1196:     $stayOnPage = 0 if (not defined $stayOnPage);
1.798     tempelho 1197:     if ($env{'environment.remote'} eq 'off' ) {
1.172     www      1198: 	$stayOnPage=1;
                   1199:     }
                   1200:     $width = 350 if (not defined $width);
                   1201:     $height = 400 if (not defined $height);
                   1202: 
                   1203:     $topic=~s/\W+/\+/g;
                   1204:     my $link='';
                   1205:     my $template='';
                   1206:     my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
                   1207:     if (!$stayOnPage)
                   1208:     {
                   1209: 	$link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
                   1210:     }
                   1211:     else
                   1212:     {
                   1213: 	$link = $url;
                   1214:     }
                   1215: 
                   1216:     # Add the text
                   1217:     if ($text ne "")
                   1218:     {
                   1219: 	$template .= 
1.173     www      1220:   "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705     tempelho 1221:   "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172     www      1222:     }
                   1223: 
                   1224:     # Add the graphic
1.179     matthew  1225:     my $title = &mt('View the FAQ');
1.215     albertel 1226:     my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172     www      1227:     $template .= <<"ENDTEMPLATE";
1.436     albertel 1228:  <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172     www      1229: ENDTEMPLATE
                   1230:     if ($text ne '') { $template.='</td></tr></table>' };
                   1231:     return $template;
                   1232: 
1.44      bowersj2 1233: }
1.37      matthew  1234: 
1.180     matthew  1235: ###############################################################
                   1236: ###############################################################
                   1237: 
1.45      matthew  1238: =pod
                   1239: 
1.648     raeburn  1240: =item * &change_content_javascript():
1.256     matthew  1241: 
                   1242: This and the next function allow you to create small sections of an
                   1243: otherwise static HTML page that you can update on the fly with
                   1244: Javascript, even in Netscape 4.
                   1245: 
                   1246: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
                   1247: must be written to the HTML page once. It will prove the Javascript
                   1248: function "change(name, content)". Calling the change function with the
                   1249: name of the section 
                   1250: you want to update, matching the name passed to C<changable_area>, and
                   1251: the new content you want to put in there, will put the content into
                   1252: that area.
                   1253: 
                   1254: B<Note>: Netscape 4 only reserves enough space for the changable area
                   1255: to contain room for the original contents. You need to "make space"
                   1256: for whatever changes you wish to make, and be B<sure> to check your
                   1257: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
                   1258: it's adequate for updating a one-line status display, but little more.
                   1259: This script will set the space to 100% width, so you only need to
                   1260: worry about height in Netscape 4.
                   1261: 
                   1262: Modern browsers are much less limiting, and if you can commit to the
                   1263: user not using Netscape 4, this feature may be used freely with
                   1264: pretty much any HTML.
                   1265: 
                   1266: =cut
                   1267: 
                   1268: sub change_content_javascript {
                   1269:     # If we're on Netscape 4, we need to use Layer-based code
1.258     albertel 1270:     if ($env{'browser.type'} eq 'netscape' &&
                   1271: 	$env{'browser.version'} =~ /^4\./) {
1.256     matthew  1272: 	return (<<NETSCAPE4);
                   1273: 	function change(name, content) {
                   1274: 	    doc = document.layers[name+"___escape"].layers[0].document;
                   1275: 	    doc.open();
                   1276: 	    doc.write(content);
                   1277: 	    doc.close();
                   1278: 	}
                   1279: NETSCAPE4
                   1280:     } else {
                   1281: 	# Otherwise, we need to use semi-standards-compliant code
                   1282: 	# (technically, "innerHTML" isn't standard but the equivalent
                   1283: 	# is really scary, and every useful browser supports it
                   1284: 	return (<<DOMBASED);
                   1285: 	function change(name, content) {
                   1286: 	    element = document.getElementById(name);
                   1287: 	    element.innerHTML = content;
                   1288: 	}
                   1289: DOMBASED
                   1290:     }
                   1291: }
                   1292: 
                   1293: =pod
                   1294: 
1.648     raeburn  1295: =item * &changable_area($name,$origContent):
1.256     matthew  1296: 
                   1297: This provides a "changable area" that can be modified on the fly via
                   1298: the Javascript code provided in C<change_content_javascript>. $name is
                   1299: the name you will use to reference the area later; do not repeat the
                   1300: same name on a given HTML page more then once. $origContent is what
                   1301: the area will originally contain, which can be left blank.
                   1302: 
                   1303: =cut
                   1304: 
                   1305: sub changable_area {
                   1306:     my ($name, $origContent) = @_;
                   1307: 
1.258     albertel 1308:     if ($env{'browser.type'} eq 'netscape' &&
                   1309: 	$env{'browser.version'} =~ /^4\./) {
1.256     matthew  1310: 	# If this is netscape 4, we need to use the Layer tag
                   1311: 	return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
                   1312:     } else {
                   1313: 	return "<span id='$name'>$origContent</span>";
                   1314:     }
                   1315: }
                   1316: 
                   1317: =pod
                   1318: 
1.648     raeburn  1319: =item * &viewport_geometry_js 
1.590     raeburn  1320: 
                   1321: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
                   1322: 
                   1323: =cut
                   1324: 
                   1325: 
                   1326: sub viewport_geometry_js { 
                   1327:     return <<"GEOMETRY";
                   1328: var Geometry = {};
                   1329: function init_geometry() {
                   1330:     if (Geometry.init) { return };
                   1331:     Geometry.init=1;
                   1332:     if (window.innerHeight) {
                   1333:         Geometry.getViewportHeight   = function() { return window.innerHeight; };
                   1334:         Geometry.getViewportWidth   = function() { return window.innerWidth; };
                   1335:         Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
                   1336:         Geometry.getVerticalScroll   = function() { return window.pageYOffset; };
                   1337:     }
                   1338:     else if (document.documentElement && document.documentElement.clientHeight) {
                   1339:         Geometry.getViewportHeight =
                   1340:             function() { return document.documentElement.clientHeight; };
                   1341:         Geometry.getViewportWidth =
                   1342:             function() { return document.documentElement.clientWidth; };
                   1343: 
                   1344:         Geometry.getHorizontalScroll =
                   1345:             function() { return document.documentElement.scrollLeft; };
                   1346:         Geometry.getVerticalScroll =
                   1347:             function() { return document.documentElement.scrollTop; };
                   1348:     }
                   1349:     else if (document.body.clientHeight) {
                   1350:         Geometry.getViewportHeight =
                   1351:             function() { return document.body.clientHeight; };
                   1352:         Geometry.getViewportWidth =
                   1353:             function() { return document.body.clientWidth; };
                   1354:         Geometry.getHorizontalScroll =
                   1355:             function() { return document.body.scrollLeft; };
                   1356:         Geometry.getVerticalScroll =
                   1357:             function() { return document.body.scrollTop; };
                   1358:     }
                   1359: }
                   1360: 
                   1361: GEOMETRY
                   1362: }
                   1363: 
                   1364: =pod
                   1365: 
1.648     raeburn  1366: =item * &viewport_size_js()
1.590     raeburn  1367: 
                   1368: 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. 
                   1369: 
                   1370: =cut
                   1371: 
                   1372: sub viewport_size_js {
                   1373:     my $geometry = &viewport_geometry_js();
                   1374:     return <<"DIMS";
                   1375: 
                   1376: $geometry
                   1377: 
                   1378: function getViewportDims(width,height) {
                   1379:     init_geometry();
                   1380:     width.value = Geometry.getViewportWidth();
                   1381:     height.value = Geometry.getViewportHeight();
                   1382:     return;
                   1383: }
                   1384: 
                   1385: DIMS
                   1386: }
                   1387: 
                   1388: =pod
                   1389: 
1.648     raeburn  1390: =item * &resize_textarea_js()
1.565     albertel 1391: 
                   1392: emits the needed javascript to resize a textarea to be as big as possible
                   1393: 
                   1394: creates a function resize_textrea that takes two IDs first should be
                   1395: the id of the element to resize, second should be the id of a div that
                   1396: surrounds everything that comes after the textarea, this routine needs
                   1397: to be attached to the <body> for the onload and onresize events.
                   1398: 
1.648     raeburn  1399: =back
1.565     albertel 1400: 
                   1401: =cut
                   1402: 
                   1403: sub resize_textarea_js {
1.590     raeburn  1404:     my $geometry = &viewport_geometry_js();
1.565     albertel 1405:     return <<"RESIZE";
                   1406:     <script type="text/javascript">
1.824     bisitz   1407: // <![CDATA[
1.590     raeburn  1408: $geometry
1.565     albertel 1409: 
1.588     albertel 1410: function getX(element) {
                   1411:     var x = 0;
                   1412:     while (element) {
                   1413: 	x += element.offsetLeft;
                   1414: 	element = element.offsetParent;
                   1415:     }
                   1416:     return x;
                   1417: }
                   1418: function getY(element) {
                   1419:     var y = 0;
                   1420:     while (element) {
                   1421: 	y += element.offsetTop;
                   1422: 	element = element.offsetParent;
                   1423:     }
                   1424:     return y;
                   1425: }
                   1426: 
                   1427: 
1.565     albertel 1428: function resize_textarea(textarea_id,bottom_id) {
                   1429:     init_geometry();
                   1430:     var textarea        = document.getElementById(textarea_id);
                   1431:     //alert(textarea);
                   1432: 
1.588     albertel 1433:     var textarea_top    = getY(textarea);
1.565     albertel 1434:     var textarea_height = textarea.offsetHeight;
                   1435:     var bottom          = document.getElementById(bottom_id);
1.588     albertel 1436:     var bottom_top      = getY(bottom);
1.565     albertel 1437:     var bottom_height   = bottom.offsetHeight;
                   1438:     var window_height   = Geometry.getViewportHeight();
1.588     albertel 1439:     var fudge           = 23;
1.565     albertel 1440:     var new_height      = window_height-fudge-textarea_top-bottom_height;
                   1441:     if (new_height < 300) {
                   1442: 	new_height = 300;
                   1443:     }
                   1444:     textarea.style.height=new_height+'px';
                   1445: }
1.824     bisitz   1446: // ]]>
1.565     albertel 1447: </script>
                   1448: RESIZE
                   1449: 
                   1450: }
                   1451: 
                   1452: =pod
                   1453: 
1.256     matthew  1454: =head1 Excel and CSV file utility routines
                   1455: 
                   1456: =over 4
                   1457: 
                   1458: =cut
                   1459: 
                   1460: ###############################################################
                   1461: ###############################################################
                   1462: 
                   1463: =pod
                   1464: 
1.648     raeburn  1465: =item * &csv_translate($text) 
1.37      matthew  1466: 
1.185     www      1467: Translate $text to allow it to be output as a 'comma separated values' 
1.37      matthew  1468: format.
                   1469: 
                   1470: =cut
                   1471: 
1.180     matthew  1472: ###############################################################
                   1473: ###############################################################
1.37      matthew  1474: sub csv_translate {
                   1475:     my $text = shift;
                   1476:     $text =~ s/\"/\"\"/g;
1.209     albertel 1477:     $text =~ s/\n/ /g;
1.37      matthew  1478:     return $text;
                   1479: }
1.180     matthew  1480: 
                   1481: ###############################################################
                   1482: ###############################################################
                   1483: 
                   1484: =pod
                   1485: 
1.648     raeburn  1486: =item * &define_excel_formats()
1.180     matthew  1487: 
                   1488: Define some commonly used Excel cell formats.
                   1489: 
                   1490: Currently supported formats:
                   1491: 
                   1492: =over 4
                   1493: 
                   1494: =item header
                   1495: 
                   1496: =item bold
                   1497: 
                   1498: =item h1
                   1499: 
                   1500: =item h2
                   1501: 
                   1502: =item h3
                   1503: 
1.256     matthew  1504: =item h4
                   1505: 
                   1506: =item i
                   1507: 
1.180     matthew  1508: =item date
                   1509: 
                   1510: =back
                   1511: 
                   1512: Inputs: $workbook
                   1513: 
                   1514: Returns: $format, a hash reference.
                   1515: 
                   1516: =cut
                   1517: 
                   1518: ###############################################################
                   1519: ###############################################################
                   1520: sub define_excel_formats {
                   1521:     my ($workbook) = @_;
                   1522:     my $format;
                   1523:     $format->{'header'} = $workbook->add_format(bold      => 1, 
                   1524:                                                 bottom    => 1,
                   1525:                                                 align     => 'center');
                   1526:     $format->{'bold'} = $workbook->add_format(bold=>1);
                   1527:     $format->{'h1'}   = $workbook->add_format(bold=>1, size=>18);
                   1528:     $format->{'h2'}   = $workbook->add_format(bold=>1, size=>16);
                   1529:     $format->{'h3'}   = $workbook->add_format(bold=>1, size=>14);
1.255     matthew  1530:     $format->{'h4'}   = $workbook->add_format(bold=>1, size=>12);
1.246     matthew  1531:     $format->{'i'}    = $workbook->add_format(italic=>1);
1.180     matthew  1532:     $format->{'date'} = $workbook->add_format(num_format=>
1.207     matthew  1533:                                             'mm/dd/yyyy hh:mm:ss');
1.180     matthew  1534:     return $format;
                   1535: }
                   1536: 
                   1537: ###############################################################
                   1538: ###############################################################
1.113     bowersj2 1539: 
                   1540: =pod
                   1541: 
1.648     raeburn  1542: =item * &create_workbook()
1.255     matthew  1543: 
                   1544: Create an Excel worksheet.  If it fails, output message on the
                   1545: request object and return undefs.
                   1546: 
                   1547: Inputs: Apache request object
                   1548: 
                   1549: Returns (undef) on failure, 
                   1550:     Excel worksheet object, scalar with filename, and formats 
                   1551:     from &Apache::loncommon::define_excel_formats on success
                   1552: 
                   1553: =cut
                   1554: 
                   1555: ###############################################################
                   1556: ###############################################################
                   1557: sub create_workbook {
                   1558:     my ($r) = @_;
                   1559:         #
                   1560:     # Create the excel spreadsheet
                   1561:     my $filename = '/prtspool/'.
1.258     albertel 1562:         $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255     matthew  1563:         time.'_'.rand(1000000000).'.xls';
                   1564:     my $workbook  = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
                   1565:     if (! defined($workbook)) {
                   1566:         $r->log_error("Error creating excel spreadsheet $filename: $!");
                   1567:         $r->print('<p>'.&mt("Unable to create new Excel file.  ".
                   1568:                             "This error has been logged.  ".
                   1569:                             "Please alert your LON-CAPA administrator").
                   1570:                   '</p>');
                   1571:         return (undef);
                   1572:     }
                   1573:     #
                   1574:     $workbook->set_tempdir('/home/httpd/perl/tmp');
                   1575:     #
                   1576:     my $format = &Apache::loncommon::define_excel_formats($workbook);
                   1577:     return ($workbook,$filename,$format);
                   1578: }
                   1579: 
                   1580: ###############################################################
                   1581: ###############################################################
                   1582: 
                   1583: =pod
                   1584: 
1.648     raeburn  1585: =item * &create_text_file()
1.113     bowersj2 1586: 
1.542     raeburn  1587: Create a file to write to and eventually make available to the user.
1.256     matthew  1588: If file creation fails, outputs an error message on the request object and 
                   1589: return undefs.
1.113     bowersj2 1590: 
1.256     matthew  1591: Inputs: Apache request object, and file suffix
1.113     bowersj2 1592: 
1.256     matthew  1593: Returns (undef) on failure, 
                   1594:     Filehandle and filename on success.
1.113     bowersj2 1595: 
                   1596: =cut
                   1597: 
1.256     matthew  1598: ###############################################################
                   1599: ###############################################################
                   1600: sub create_text_file {
                   1601:     my ($r,$suffix) = @_;
                   1602:     if (! defined($suffix)) { $suffix = 'txt'; };
                   1603:     my $fh;
                   1604:     my $filename = '/prtspool/'.
1.258     albertel 1605:         $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256     matthew  1606:         time.'_'.rand(1000000000).'.'.$suffix;
                   1607:     $fh = Apache::File->new('>/home/httpd'.$filename);
                   1608:     if (! defined($fh)) {
                   1609:         $r->log_error("Couldn't open $filename for output $!");
1.683     bisitz   1610:         $r->print(&mt('Problems occurred in creating the output file. '
                   1611:                      .'This error has been logged. '
                   1612:                      .'Please alert your LON-CAPA administrator.'));
1.113     bowersj2 1613:     }
1.256     matthew  1614:     return ($fh,$filename)
1.113     bowersj2 1615: }
                   1616: 
                   1617: 
1.256     matthew  1618: =pod 
1.113     bowersj2 1619: 
                   1620: =back
                   1621: 
                   1622: =cut
1.37      matthew  1623: 
                   1624: ###############################################################
1.33      matthew  1625: ##        Home server <option> list generating code          ##
                   1626: ###############################################################
1.35      matthew  1627: 
1.169     www      1628: # ------------------------------------------
                   1629: 
                   1630: sub domain_select {
                   1631:     my ($name,$value,$multiple)=@_;
                   1632:     my %domains=map { 
1.514     albertel 1633: 	$_ => $_.' '. &Apache::lonnet::domain($_,'description') 
1.512     albertel 1634:     } &Apache::lonnet::all_domains();
1.169     www      1635:     if ($multiple) {
                   1636: 	$domains{''}=&mt('Any domain');
1.550     albertel 1637: 	$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287     albertel 1638: 	return &multiple_select_form($name,$value,4,\%domains);
1.169     www      1639:     } else {
1.550     albertel 1640: 	$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.169     www      1641: 	return &select_form($name,$value,%domains);
                   1642:     }
                   1643: }
                   1644: 
1.282     albertel 1645: #-------------------------------------------
                   1646: 
                   1647: =pod
                   1648: 
1.519     raeburn  1649: =head1 Routines for form select boxes
                   1650: 
                   1651: =over 4
                   1652: 
1.648     raeburn  1653: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282     albertel 1654: 
                   1655: Returns a string containing a <select> element int multiple mode
                   1656: 
                   1657: 
                   1658: Args:
                   1659:   $name - name of the <select> element
1.506     raeburn  1660:   $value - scalar or array ref of values that should already be selected
1.282     albertel 1661:   $size - number of rows long the select element is
1.283     albertel 1662:   $hash - the elements should be 'option' => 'shown text'
1.282     albertel 1663:           (shown text should already have been &mt())
1.506     raeburn  1664:   $order - (optional) array ref of the order to show the elements in
1.283     albertel 1665: 
1.282     albertel 1666: =cut
                   1667: 
                   1668: #-------------------------------------------
1.169     www      1669: sub multiple_select_form {
1.284     albertel 1670:     my ($name,$value,$size,$hash,$order)=@_;
1.169     www      1671:     my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
                   1672:     my $output='';
1.191     matthew  1673:     if (! defined($size)) {
                   1674:         $size = 4;
1.283     albertel 1675:         if (scalar(keys(%$hash))<4) {
                   1676:             $size = scalar(keys(%$hash));
1.191     matthew  1677:         }
                   1678:     }
1.734     bisitz   1679:     $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501     banghart 1680:     my @order;
1.506     raeburn  1681:     if (ref($order) eq 'ARRAY')  {
                   1682:         @order = @{$order};
                   1683:     } else {
                   1684:         @order = sort(keys(%$hash));
1.501     banghart 1685:     }
                   1686:     if (exists($$hash{'select_form_order'})) {
                   1687:         @order = @{$$hash{'select_form_order'}};
                   1688:     }
                   1689:         
1.284     albertel 1690:     foreach my $key (@order) {
1.356     albertel 1691:         $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284     albertel 1692:         $output.='selected="selected" ' if ($selected{$key});
                   1693:         $output.='>'.$hash->{$key}."</option>\n";
1.169     www      1694:     }
                   1695:     $output.="</select>\n";
                   1696:     return $output;
                   1697: }
                   1698: 
1.88      www      1699: #-------------------------------------------
                   1700: 
                   1701: =pod
                   1702: 
1.648     raeburn  1703: =item * &select_form($defdom,$name,%hash)
1.88      www      1704: 
                   1705: Returns a string containing a <select name='$name' size='1'> form to 
                   1706: allow a user to select options from a hash option_name => displayed text.  
                   1707: See lonrights.pm for an example invocation and use.
                   1708: 
                   1709: =cut
                   1710: 
                   1711: #-------------------------------------------
                   1712: sub select_form {
                   1713:     my ($def,$name,%hash) = @_;
                   1714:     my $selectform = "<select name=\"$name\" size=\"1\">\n";
1.128     albertel 1715:     my @keys;
                   1716:     if (exists($hash{'select_form_order'})) {
                   1717: 	@keys=@{$hash{'select_form_order'}};
                   1718:     } else {
                   1719: 	@keys=sort(keys(%hash));
                   1720:     }
1.356     albertel 1721:     foreach my $key (@keys) {
                   1722:         $selectform.=
                   1723: 	    '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
                   1724:             ($key eq $def ? 'selected="selected" ' : '').
                   1725:                 ">".&mt($hash{$key})."</option>\n";
1.88      www      1726:     }
                   1727:     $selectform.="</select>";
                   1728:     return $selectform;
                   1729: }
                   1730: 
1.475     www      1731: # For display filters
                   1732: 
                   1733: sub display_filter {
                   1734:     if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477     www      1735:     if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.714     bisitz   1736:     return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1.475     www      1737: 			       &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
                   1738: 							   (&mt('all'),10,20,50,100,1000,10000))).
1.714     bisitz   1739: 	   '</label></span> <span class="LC_nobreak">'.
1.475     www      1740:            &mt('Filter [_1]',
1.477     www      1741: 	   &select_form($env{'form.displayfilter'},
                   1742: 			'displayfilter',
                   1743: 			('currentfolder' => 'Current folder/page',
                   1744: 			 'containing' => 'Containing phrase',
                   1745: 			 'none' => 'None'))).
1.714     bisitz   1746: 			 '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1.475     www      1747: }
                   1748: 
1.167     www      1749: sub gradeleveldescription {
                   1750:     my $gradelevel=shift;
                   1751:     my %gradelevels=(0 => 'Not specified',
                   1752: 		     1 => 'Grade 1',
                   1753: 		     2 => 'Grade 2',
                   1754: 		     3 => 'Grade 3',
                   1755: 		     4 => 'Grade 4',
                   1756: 		     5 => 'Grade 5',
                   1757: 		     6 => 'Grade 6',
                   1758: 		     7 => 'Grade 7',
                   1759: 		     8 => 'Grade 8',
                   1760: 		     9 => 'Grade 9',
                   1761: 		     10 => 'Grade 10',
                   1762: 		     11 => 'Grade 11',
                   1763: 		     12 => 'Grade 12',
                   1764: 		     13 => 'Grade 13',
                   1765: 		     14 => '100 Level',
                   1766: 		     15 => '200 Level',
                   1767: 		     16 => '300 Level',
                   1768: 		     17 => '400 Level',
                   1769: 		     18 => 'Graduate Level');
                   1770:     return &mt($gradelevels{$gradelevel});
                   1771: }
                   1772: 
1.163     www      1773: sub select_level_form {
                   1774:     my ($deflevel,$name)=@_;
                   1775:     unless ($deflevel) { $deflevel=0; }
1.167     www      1776:     my $selectform = "<select name=\"$name\" size=\"1\">\n";
                   1777:     for (my $i=0; $i<=18; $i++) {
                   1778:         $selectform.="<option value=\"$i\" ".
1.253     albertel 1779:             ($i==$deflevel ? 'selected="selected" ' : '').
1.167     www      1780:                 ">".&gradeleveldescription($i)."</option>\n";
                   1781:     }
                   1782:     $selectform.="</select>";
                   1783:     return $selectform;
1.163     www      1784: }
1.167     www      1785: 
1.35      matthew  1786: #-------------------------------------------
                   1787: 
1.45      matthew  1788: =pod
                   1789: 
1.743     raeburn  1790: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$autosubmit)
1.35      matthew  1791: 
                   1792: Returns a string containing a <select name='$name' size='1'> form to 
                   1793: allow a user to select the domain to preform an operation in.  
                   1794: See loncreateuser.pm for an example invocation and use.
                   1795: 
1.90      www      1796: If the $includeempty flag is set, it also includes an empty choice ("no domain
                   1797: selected");
                   1798: 
1.743     raeburn  1799: If the $showdomdesc flag is set, the domain name is followed by the domain description.
                   1800: 
                   1801: If the $autosubmit flag is set, the form containing the domain selector will be auto-submitted by an onchange action.  
1.563     raeburn  1802: 
1.35      matthew  1803: =cut
                   1804: 
                   1805: #-------------------------------------------
1.34      matthew  1806: sub select_dom_form {
1.743     raeburn  1807:     my ($defdom,$name,$includeempty,$showdomdesc,$autosubmit) = @_;
                   1808:     my $onchange;
                   1809:     if ($autosubmit) {
                   1810:         $onchange = ' onchange="this.form.submit()"';
                   1811:     }
1.550     albertel 1812:     my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1.90      www      1813:     if ($includeempty) { @domains=('',@domains); }
1.743     raeburn  1814:     my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356     albertel 1815:     foreach my $dom (@domains) {
                   1816:         $selectdomain.="<option value=\"$dom\" ".
1.563     raeburn  1817:             ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
                   1818:         if ($showdomdesc) {
                   1819:             if ($dom ne '') {
                   1820:                 my $domdesc = &Apache::lonnet::domain($dom,'description');
                   1821:                 if ($domdesc ne '') {
                   1822:                     $selectdomain .= ' ('.$domdesc.')';
                   1823:                 }
                   1824:             } 
                   1825:         }
                   1826:         $selectdomain .= "</option>\n";
1.34      matthew  1827:     }
                   1828:     $selectdomain.="</select>";
                   1829:     return $selectdomain;
                   1830: }
                   1831: 
1.35      matthew  1832: #-------------------------------------------
                   1833: 
1.45      matthew  1834: =pod
                   1835: 
1.648     raeburn  1836: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35      matthew  1837: 
1.586     raeburn  1838: input: 4 arguments (two required, two optional) - 
                   1839:     $domain - domain of new user
                   1840:     $name - name of form element
                   1841:     $default - Value of 'default' causes a default item to be first 
                   1842:                             option, and selected by default. 
                   1843:     $hide - Value of 'hide' causes hiding of the name of the server, 
                   1844:                             if 1 server found, or default, if 0 found.
1.594     raeburn  1845: output: returns 2 items: 
1.586     raeburn  1846: (a) form element which contains either:
                   1847:    (i) <select name="$name">
                   1848:         <option value="$hostid1">$hostid $servers{$hostid}</option>
                   1849:         <option value="$hostid2">$hostid $servers{$hostid}</option>       
                   1850:        </select>
                   1851:        form item if there are multiple library servers in $domain, or
                   1852:    (ii) an <input type="hidden" name="$name" value="$hostid" /> form item 
                   1853:        if there is only one library server in $domain.
                   1854: 
                   1855: (b) number of library servers found.
                   1856: 
                   1857: See loncreateuser.pm for example of use.
1.35      matthew  1858: 
                   1859: =cut
                   1860: 
                   1861: #-------------------------------------------
1.586     raeburn  1862: sub home_server_form_item {
                   1863:     my ($domain,$name,$default,$hide) = @_;
1.513     albertel 1864:     my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586     raeburn  1865:     my $result;
                   1866:     my $numlib = keys(%servers);
                   1867:     if ($numlib > 1) {
                   1868:         $result .= '<select name="'.$name.'" />'."\n";
                   1869:         if ($default) {
1.804     bisitz   1870:             $result .= '<option value="default" selected="selected">'.&mt('default').
1.586     raeburn  1871:                        '</option>'."\n";
                   1872:         }
                   1873:         foreach my $hostid (sort(keys(%servers))) {
                   1874:             $result.= '<option value="'.$hostid.'">'.
                   1875: 	              $hostid.' '.$servers{$hostid}."</option>\n";
                   1876:         }
                   1877:         $result .= '</select>'."\n";
                   1878:     } elsif ($numlib == 1) {
                   1879:         my $hostid;
                   1880:         foreach my $item (keys(%servers)) {
                   1881:             $hostid = $item;
                   1882:         }
                   1883:         $result .= '<input type="hidden" name="'.$name.'" value="'.
                   1884:                    $hostid.'" />';
                   1885:                    if (!$hide) {
                   1886:                        $result .= $hostid.' '.$servers{$hostid};
                   1887:                    }
                   1888:                    $result .= "\n";
                   1889:     } elsif ($default) {
                   1890:         $result .= '<input type="hidden" name="'.$name.
                   1891:                    '" value="default" />';
                   1892:                    if (!$hide) {
                   1893:                        $result .= &mt('default');
                   1894:                    }
                   1895:                    $result .= "\n";
1.33      matthew  1896:     }
1.586     raeburn  1897:     return ($result,$numlib);
1.33      matthew  1898: }
1.112     bowersj2 1899: 
                   1900: =pod
                   1901: 
1.534     albertel 1902: =back 
                   1903: 
1.112     bowersj2 1904: =cut
1.87      matthew  1905: 
                   1906: ###############################################################
1.112     bowersj2 1907: ##                  Decoding User Agent                      ##
1.87      matthew  1908: ###############################################################
                   1909: 
                   1910: =pod
                   1911: 
1.112     bowersj2 1912: =head1 Decoding the User Agent
                   1913: 
                   1914: =over 4
                   1915: 
                   1916: =item * &decode_user_agent()
1.87      matthew  1917: 
                   1918: Inputs: $r
                   1919: 
                   1920: Outputs:
                   1921: 
                   1922: =over 4
                   1923: 
1.112     bowersj2 1924: =item * $httpbrowser
1.87      matthew  1925: 
1.112     bowersj2 1926: =item * $clientbrowser
1.87      matthew  1927: 
1.112     bowersj2 1928: =item * $clientversion
1.87      matthew  1929: 
1.112     bowersj2 1930: =item * $clientmathml
1.87      matthew  1931: 
1.112     bowersj2 1932: =item * $clientunicode
1.87      matthew  1933: 
1.112     bowersj2 1934: =item * $clientos
1.87      matthew  1935: 
                   1936: =back
                   1937: 
1.157     matthew  1938: =back 
                   1939: 
1.87      matthew  1940: =cut
                   1941: 
                   1942: ###############################################################
                   1943: ###############################################################
                   1944: sub decode_user_agent {
1.247     albertel 1945:     my ($r)=@_;
1.87      matthew  1946:     my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
                   1947:     my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
                   1948:     my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247     albertel 1949:     if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87      matthew  1950:     my $clientbrowser='unknown';
                   1951:     my $clientversion='0';
                   1952:     my $clientmathml='';
                   1953:     my $clientunicode='0';
                   1954:     for (my $i=0;$i<=$#browsertype;$i++) {
                   1955:         my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
                   1956: 	if (($httpbrowser=~/$match/i)  && ($httpbrowser!~/$notmatch/i)) {
                   1957: 	    $clientbrowser=$bname;
                   1958:             $httpbrowser=~/$vreg/i;
                   1959: 	    $clientversion=$1;
                   1960:             $clientmathml=($clientversion>=$minv);
                   1961:             $clientunicode=($clientversion>=$univ);
                   1962: 	}
                   1963:     }
                   1964:     my $clientos='unknown';
                   1965:     if (($httpbrowser=~/linux/i) ||
                   1966:         ($httpbrowser=~/unix/i) ||
                   1967:         ($httpbrowser=~/ux/i) ||
                   1968:         ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
                   1969:     if (($httpbrowser=~/vax/i) ||
                   1970:         ($httpbrowser=~/vms/i)) { $clientos='vms'; }
                   1971:     if ($httpbrowser=~/next/i) { $clientos='next'; }
                   1972:     if (($httpbrowser=~/mac/i) ||
                   1973:         ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
                   1974:     if ($httpbrowser=~/win/i) { $clientos='win'; }
                   1975:     if ($httpbrowser=~/embed/i) { $clientos='pda'; }
                   1976:     return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
                   1977:             $clientunicode,$clientos,);
                   1978: }
                   1979: 
1.32      matthew  1980: ###############################################################
                   1981: ##    Authentication changing form generation subroutines    ##
                   1982: ###############################################################
                   1983: ##
                   1984: ## All of the authform_xxxxxxx subroutines take their inputs in a
                   1985: ## hash, and have reasonable default values.
                   1986: ##
                   1987: ##    formname = the name given in the <form> tag.
1.35      matthew  1988: #-------------------------------------------
                   1989: 
1.45      matthew  1990: =pod
                   1991: 
1.112     bowersj2 1992: =head1 Authentication Routines
                   1993: 
                   1994: =over 4
                   1995: 
1.648     raeburn  1996: =item * &authform_xxxxxx()
1.35      matthew  1997: 
                   1998: The authform_xxxxxx subroutines provide javascript and html forms which 
                   1999: handle some of the conveniences required for authentication forms.  
                   2000: This is not an optimal method, but it works.  
                   2001: 
                   2002: =over 4
                   2003: 
1.112     bowersj2 2004: =item * authform_header
1.35      matthew  2005: 
1.112     bowersj2 2006: =item * authform_authorwarning
1.35      matthew  2007: 
1.112     bowersj2 2008: =item * authform_nochange
1.35      matthew  2009: 
1.112     bowersj2 2010: =item * authform_kerberos
1.35      matthew  2011: 
1.112     bowersj2 2012: =item * authform_internal
1.35      matthew  2013: 
1.112     bowersj2 2014: =item * authform_filesystem
1.35      matthew  2015: 
                   2016: =back
                   2017: 
1.648     raeburn  2018: See loncreateuser.pm for invocation and use examples.
1.157     matthew  2019: 
1.35      matthew  2020: =cut
                   2021: 
                   2022: #-------------------------------------------
1.32      matthew  2023: sub authform_header{  
                   2024:     my %in = (
                   2025:         formname => 'cu',
1.80      albertel 2026:         kerb_def_dom => '',
1.32      matthew  2027:         @_,
                   2028:     );
                   2029:     $in{'formname'} = 'document.' . $in{'formname'};
                   2030:     my $result='';
1.80      albertel 2031: 
                   2032: #---------------------------------------------- Code for upper case translation
                   2033:     my $Javascript_toUpperCase;
                   2034:     unless ($in{kerb_def_dom}) {
                   2035:         $Javascript_toUpperCase =<<"END";
                   2036:         switch (choice) {
                   2037:            case 'krb': currentform.elements[choicearg].value =
                   2038:                currentform.elements[choicearg].value.toUpperCase();
                   2039:                break;
                   2040:            default:
                   2041:         }
                   2042: END
                   2043:     } else {
                   2044:         $Javascript_toUpperCase = "";
                   2045:     }
                   2046: 
1.165     raeburn  2047:     my $radioval = "'nochange'";
1.591     raeburn  2048:     if (defined($in{'curr_authtype'})) {
                   2049:         if ($in{'curr_authtype'} ne '') {
                   2050:             $radioval = "'".$in{'curr_authtype'}."arg'";
                   2051:         }
1.174     matthew  2052:     }
1.165     raeburn  2053:     my $argfield = 'null';
1.591     raeburn  2054:     if (defined($in{'mode'})) {
1.165     raeburn  2055:         if ($in{'mode'} eq 'modifycourse')  {
1.591     raeburn  2056:             if (defined($in{'curr_autharg'})) {
                   2057:                 if ($in{'curr_autharg'} ne '') {
1.165     raeburn  2058:                     $argfield = "'$in{'curr_autharg'}'";
                   2059:                 }
                   2060:             }
                   2061:         }
                   2062:     }
                   2063: 
1.32      matthew  2064:     $result.=<<"END";
                   2065: var current = new Object();
1.165     raeburn  2066: current.radiovalue = $radioval;
                   2067: current.argfield = $argfield;
1.32      matthew  2068: 
                   2069: function changed_radio(choice,currentform) {
                   2070:     var choicearg = choice + 'arg';
                   2071:     // If a radio button in changed, we need to change the argfield
                   2072:     if (current.radiovalue != choice) {
                   2073:         current.radiovalue = choice;
                   2074:         if (current.argfield != null) {
                   2075:             currentform.elements[current.argfield].value = '';
                   2076:         }
                   2077:         if (choice == 'nochange') {
                   2078:             current.argfield = null;
                   2079:         } else {
                   2080:             current.argfield = choicearg;
                   2081:             switch(choice) {
                   2082:                 case 'krb': 
                   2083:                     currentform.elements[current.argfield].value = 
                   2084:                         "$in{'kerb_def_dom'}";
                   2085:                 break;
                   2086:               default:
                   2087:                 break;
                   2088:             }
                   2089:         }
                   2090:     }
                   2091:     return;
                   2092: }
1.22      www      2093: 
1.32      matthew  2094: function changed_text(choice,currentform) {
                   2095:     var choicearg = choice + 'arg';
                   2096:     if (currentform.elements[choicearg].value !='') {
1.80      albertel 2097:         $Javascript_toUpperCase
1.32      matthew  2098:         // clear old field
                   2099:         if ((current.argfield != choicearg) && (current.argfield != null)) {
                   2100:             currentform.elements[current.argfield].value = '';
                   2101:         }
                   2102:         current.argfield = choicearg;
                   2103:     }
                   2104:     set_auth_radio_buttons(choice,currentform);
                   2105:     return;
1.20      www      2106: }
1.32      matthew  2107: 
                   2108: function set_auth_radio_buttons(newvalue,currentform) {
                   2109:     var i=0;
                   2110:     while (i < currentform.login.length) {
                   2111:         if (currentform.login[i].value == newvalue) { break; }
                   2112:         i++;
                   2113:     }
                   2114:     if (i == currentform.login.length) {
                   2115:         return;
                   2116:     }
                   2117:     current.radiovalue = newvalue;
                   2118:     currentform.login[i].checked = true;
                   2119:     return;
                   2120: }
                   2121: END
                   2122:     return $result;
                   2123: }
                   2124: 
                   2125: sub authform_authorwarning{
                   2126:     my $result='';
1.144     matthew  2127:     $result='<i>'.
                   2128:         &mt('As a general rule, only authors or co-authors should be '.
                   2129:             'filesystem authenticated '.
                   2130:             '(which allows access to the server filesystem).')."</i>\n";
1.32      matthew  2131:     return $result;
                   2132: }
                   2133: 
                   2134: sub authform_nochange{  
                   2135:     my %in = (
                   2136:               formname => 'document.cu',
                   2137:               kerb_def_dom => 'MSU.EDU',
                   2138:               @_,
                   2139:           );
1.586     raeburn  2140:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'}); 
                   2141:     my $result;
                   2142:     if (keys(%can_assign) == 0) {
                   2143:         $result = &mt('Under you current role you are not permitted to change login settings for this user');  
                   2144:     } else {
                   2145:         $result = '<label>'.&mt('[_1] Do not change login data',
                   2146:                   '<input type="radio" name="login" value="nochange" '.
                   2147:                   'checked="checked" onclick="'.
1.281     albertel 2148:             "javascript:changed_radio('nochange',$in{'formname'});".'" />').
                   2149: 	    '</label>';
1.586     raeburn  2150:     }
1.32      matthew  2151:     return $result;
                   2152: }
                   2153: 
1.591     raeburn  2154: sub authform_kerberos {
1.32      matthew  2155:     my %in = (
                   2156:               formname => 'document.cu',
                   2157:               kerb_def_dom => 'MSU.EDU',
1.80      albertel 2158:               kerb_def_auth => 'krb4',
1.32      matthew  2159:               @_,
                   2160:               );
1.586     raeburn  2161:     my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
                   2162:         $autharg,$jscall);
                   2163:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.80      albertel 2164:     if ($in{'kerb_def_auth'} eq 'krb5') {
1.772     bisitz   2165:        $check5 = ' checked="checked"';
1.80      albertel 2166:     } else {
1.772     bisitz   2167:        $check4 = ' checked="checked"';
1.80      albertel 2168:     }
1.165     raeburn  2169:     $krbarg = $in{'kerb_def_dom'};
1.591     raeburn  2170:     if (defined($in{'curr_authtype'})) {
                   2171:         if ($in{'curr_authtype'} eq 'krb') {
1.772     bisitz   2172:             $krbcheck = ' checked="checked"';
1.623     raeburn  2173:             if (defined($in{'mode'})) {
                   2174:                 if ($in{'mode'} eq 'modifyuser') {
                   2175:                     $krbcheck = '';
                   2176:                 }
                   2177:             }
1.591     raeburn  2178:             if (defined($in{'curr_kerb_ver'})) {
                   2179:                 if ($in{'curr_krb_ver'} eq '5') {
1.772     bisitz   2180:                     $check5 = ' checked="checked"';
1.591     raeburn  2181:                     $check4 = '';
                   2182:                 } else {
1.772     bisitz   2183:                     $check4 = ' checked="checked"';
1.591     raeburn  2184:                     $check5 = '';
                   2185:                 }
1.586     raeburn  2186:             }
1.591     raeburn  2187:             if (defined($in{'curr_autharg'})) {
1.165     raeburn  2188:                 $krbarg = $in{'curr_autharg'};
                   2189:             }
1.586     raeburn  2190:             if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591     raeburn  2191:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2192:                     $result = 
                   2193:     &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
                   2194:         $in{'curr_autharg'},$krbver);
                   2195:                 } else {
                   2196:                     $result =
                   2197:     &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
                   2198:                 }
                   2199:                 return $result; 
                   2200:             }
                   2201:         }
                   2202:     } else {
                   2203:         if ($authnum == 1) {
1.784     bisitz   2204:             $authtype = '<input type="hidden" name="login" value="krb" />';
1.165     raeburn  2205:         }
                   2206:     }
1.586     raeburn  2207:     if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
                   2208:         return;
1.587     raeburn  2209:     } elsif ($authtype eq '') {
1.591     raeburn  2210:         if (defined($in{'mode'})) {
1.587     raeburn  2211:             if ($in{'mode'} eq 'modifycourse') {
                   2212:                 if ($authnum == 1) {
1.784     bisitz   2213:                     $authtype = '<input type="hidden" name="login" value="krb" />';
1.587     raeburn  2214:                 }
                   2215:             }
                   2216:         }
1.586     raeburn  2217:     }
                   2218:     $jscall = "javascript:changed_radio('krb',$in{'formname'});";
                   2219:     if ($authtype eq '') {
                   2220:         $authtype = '<input type="radio" name="login" value="krb" '.
                   2221:                     'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
                   2222:                     $krbcheck.' />';
                   2223:     }
                   2224:     if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
                   2225:         ($can_assign{'krb4'} && !$can_assign{'krb5'} && 
                   2226:          $in{'curr_authtype'} eq 'krb5') ||
                   2227:         (!$can_assign{'krb4'} && $can_assign{'krb5'} && 
                   2228:          $in{'curr_authtype'} eq 'krb4')) {
                   2229:         $result .= &mt
1.144     matthew  2230:         ('[_1] Kerberos authenticated with domain [_2] '.
1.281     albertel 2231:          '[_3] Version 4 [_4] Version 5 [_5]',
1.586     raeburn  2232:          '<label>'.$authtype,
1.281     albertel 2233:          '</label><input type="text" size="10" name="krbarg" '.
1.165     raeburn  2234:              'value="'.$krbarg.'" '.
1.144     matthew  2235:              'onchange="'.$jscall.'" />',
1.281     albertel 2236:          '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
                   2237:          '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
                   2238: 	 '</label>');
1.586     raeburn  2239:     } elsif ($can_assign{'krb4'}) {
                   2240:         $result .= &mt
                   2241:         ('[_1] Kerberos authenticated with domain [_2] '.
                   2242:          '[_3] Version 4 [_4]',
                   2243:          '<label>'.$authtype,
                   2244:          '</label><input type="text" size="10" name="krbarg" '.
                   2245:              'value="'.$krbarg.'" '.
                   2246:              'onchange="'.$jscall.'" />',
                   2247:          '<label><input type="hidden" name="krbver" value="4" />',
                   2248:          '</label>');
                   2249:     } elsif ($can_assign{'krb5'}) {
                   2250:         $result .= &mt
                   2251:         ('[_1] Kerberos authenticated with domain [_2] '.
                   2252:          '[_3] Version 5 [_4]',
                   2253:          '<label>'.$authtype,
                   2254:          '</label><input type="text" size="10" name="krbarg" '.
                   2255:              'value="'.$krbarg.'" '.
                   2256:              'onchange="'.$jscall.'" />',
                   2257:          '<label><input type="hidden" name="krbver" value="5" />',
                   2258:          '</label>');
                   2259:     }
1.32      matthew  2260:     return $result;
                   2261: }
                   2262: 
                   2263: sub authform_internal{  
1.586     raeburn  2264:     my %in = (
1.32      matthew  2265:                 formname => 'document.cu',
                   2266:                 kerb_def_dom => 'MSU.EDU',
                   2267:                 @_,
                   2268:                 );
1.586     raeburn  2269:     my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
                   2270:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2271:     if (defined($in{'curr_authtype'})) {
                   2272:         if ($in{'curr_authtype'} eq 'int') {
1.586     raeburn  2273:             if ($can_assign{'int'}) {
1.772     bisitz   2274:                 $intcheck = 'checked="checked" ';
1.623     raeburn  2275:                 if (defined($in{'mode'})) {
                   2276:                     if ($in{'mode'} eq 'modifyuser') {
                   2277:                         $intcheck = '';
                   2278:                     }
                   2279:                 }
1.591     raeburn  2280:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2281:                     $intarg = $in{'curr_autharg'};
                   2282:                 }
                   2283:             } else {
                   2284:                 $result = &mt('Currently internally authenticated.');
                   2285:                 return $result;
1.165     raeburn  2286:             }
                   2287:         }
1.586     raeburn  2288:     } else {
                   2289:         if ($authnum == 1) {
1.784     bisitz   2290:             $authtype = '<input type="hidden" name="login" value="int" />';
1.586     raeburn  2291:         }
                   2292:     }
                   2293:     if (!$can_assign{'int'}) {
                   2294:         return;
1.587     raeburn  2295:     } elsif ($authtype eq '') {
1.591     raeburn  2296:         if (defined($in{'mode'})) {
1.587     raeburn  2297:             if ($in{'mode'} eq 'modifycourse') {
                   2298:                 if ($authnum == 1) {
1.784     bisitz   2299:                     $authtype = '<input type="hidden" name="login" value="int" />';
1.587     raeburn  2300:                 }
                   2301:             }
                   2302:         }
1.165     raeburn  2303:     }
1.586     raeburn  2304:     $jscall = "javascript:changed_radio('int',$in{'formname'});";
                   2305:     if ($authtype eq '') {
                   2306:         $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
                   2307:                     ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
                   2308:     }
1.605     bisitz   2309:     $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586     raeburn  2310:                $intarg.'" onchange="'.$jscall.'" />';
                   2311:     $result = &mt
1.144     matthew  2312:         ('[_1] Internally authenticated (with initial password [_2])',
1.586     raeburn  2313:          '<label>'.$authtype,'</label>'.$autharg);
1.824     bisitz   2314:     $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  2315:     return $result;
                   2316: }
                   2317: 
                   2318: sub authform_local{  
                   2319:     my %in = (
                   2320:               formname => 'document.cu',
                   2321:               kerb_def_dom => 'MSU.EDU',
                   2322:               @_,
                   2323:               );
1.586     raeburn  2324:     my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
                   2325:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2326:     if (defined($in{'curr_authtype'})) {
                   2327:         if ($in{'curr_authtype'} eq 'loc') {
1.586     raeburn  2328:             if ($can_assign{'loc'}) {
1.772     bisitz   2329:                 $loccheck = 'checked="checked" ';
1.623     raeburn  2330:                 if (defined($in{'mode'})) {
                   2331:                     if ($in{'mode'} eq 'modifyuser') {
                   2332:                         $loccheck = '';
                   2333:                     }
                   2334:                 }
1.591     raeburn  2335:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2336:                     $locarg = $in{'curr_autharg'};
                   2337:                 }
                   2338:             } else {
                   2339:                 $result = &mt('Currently using local (institutional) authentication.');
                   2340:                 return $result;
1.165     raeburn  2341:             }
                   2342:         }
1.586     raeburn  2343:     } else {
                   2344:         if ($authnum == 1) {
1.784     bisitz   2345:             $authtype = '<input type="hidden" name="login" value="loc" />';
1.586     raeburn  2346:         }
                   2347:     }
                   2348:     if (!$can_assign{'loc'}) {
                   2349:         return;
1.587     raeburn  2350:     } elsif ($authtype eq '') {
1.591     raeburn  2351:         if (defined($in{'mode'})) {
1.587     raeburn  2352:             if ($in{'mode'} eq 'modifycourse') {
                   2353:                 if ($authnum == 1) {
1.784     bisitz   2354:                     $authtype = '<input type="hidden" name="login" value="loc" />';
1.587     raeburn  2355:                 }
                   2356:             }
                   2357:         }
1.165     raeburn  2358:     }
1.586     raeburn  2359:     $jscall = "javascript:changed_radio('loc',$in{'formname'});";
                   2360:     if ($authtype eq '') {
                   2361:         $authtype = '<input type="radio" name="login" value="loc" '.
                   2362:                     $loccheck.' onchange="'.$jscall.'" onclick="'.
                   2363:                     $jscall.'" />';
                   2364:     }
                   2365:     $autharg = '<input type="text" size="10" name="locarg" value="'.
                   2366:                $locarg.'" onchange="'.$jscall.'" />';
                   2367:     $result = &mt('[_1] Local Authentication with argument [_2]',
                   2368:                   '<label>'.$authtype,'</label>'.$autharg);
1.32      matthew  2369:     return $result;
                   2370: }
                   2371: 
                   2372: sub authform_filesystem{  
                   2373:     my %in = (
                   2374:               formname => 'document.cu',
                   2375:               kerb_def_dom => 'MSU.EDU',
                   2376:               @_,
                   2377:               );
1.586     raeburn  2378:     my ($fsyscheck,$result,$authtype,$autharg,$jscall);
                   2379:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2380:     if (defined($in{'curr_authtype'})) {
                   2381:         if ($in{'curr_authtype'} eq 'fsys') {
1.586     raeburn  2382:             if ($can_assign{'fsys'}) {
1.772     bisitz   2383:                 $fsyscheck = 'checked="checked" ';
1.623     raeburn  2384:                 if (defined($in{'mode'})) {
                   2385:                     if ($in{'mode'} eq 'modifyuser') {
                   2386:                         $fsyscheck = '';
                   2387:                     }
                   2388:                 }
1.586     raeburn  2389:             } else {
                   2390:                 $result = &mt('Currently Filesystem Authenticated.');
                   2391:                 return $result;
                   2392:             }           
                   2393:         }
                   2394:     } else {
                   2395:         if ($authnum == 1) {
1.784     bisitz   2396:             $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586     raeburn  2397:         }
                   2398:     }
                   2399:     if (!$can_assign{'fsys'}) {
                   2400:         return;
1.587     raeburn  2401:     } elsif ($authtype eq '') {
1.591     raeburn  2402:         if (defined($in{'mode'})) {
1.587     raeburn  2403:             if ($in{'mode'} eq 'modifycourse') {
                   2404:                 if ($authnum == 1) {
1.784     bisitz   2405:                     $authtype = '<input type="hidden" name="login" value="fsys" />';
1.587     raeburn  2406:                 }
                   2407:             }
                   2408:         }
1.586     raeburn  2409:     }
                   2410:     $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
                   2411:     if ($authtype eq '') {
                   2412:         $authtype = '<input type="radio" name="login" value="fsys" '.
                   2413:                     $fsyscheck.' onchange="'.$jscall.'" onclick="'.
                   2414:                     $jscall.'" />';
                   2415:     }
                   2416:     $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
                   2417:                ' onchange="'.$jscall.'" />';
                   2418:     $result = &mt
1.144     matthew  2419:         ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281     albertel 2420:          '<label><input type="radio" name="login" value="fsys" '.
1.586     raeburn  2421:          $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605     bisitz   2422:          '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144     matthew  2423:                   'onchange="'.$jscall.'" />');
1.32      matthew  2424:     return $result;
                   2425: }
                   2426: 
1.586     raeburn  2427: sub get_assignable_auth {
                   2428:     my ($dom) = @_;
                   2429:     if ($dom eq '') {
                   2430:         $dom = $env{'request.role.domain'};
                   2431:     }
                   2432:     my %can_assign = (
                   2433:                           krb4 => 1,
                   2434:                           krb5 => 1,
                   2435:                           int  => 1,
                   2436:                           loc  => 1,
                   2437:                      );
                   2438:     my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
                   2439:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   2440:         if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
                   2441:             my $authhash = $domconfig{'usercreation'}{'authtypes'};
                   2442:             my $context;
                   2443:             if ($env{'request.role'} =~ /^au/) {
                   2444:                 $context = 'author';
                   2445:             } elsif ($env{'request.role'} =~ /^dc/) {
                   2446:                 $context = 'domain';
                   2447:             } elsif ($env{'request.course.id'}) {
                   2448:                 $context = 'course';
                   2449:             }
                   2450:             if ($context) {
                   2451:                 if (ref($authhash->{$context}) eq 'HASH') {
                   2452:                    %can_assign = %{$authhash->{$context}}; 
                   2453:                 }
                   2454:             }
                   2455:         }
                   2456:     }
                   2457:     my $authnum = 0;
                   2458:     foreach my $key (keys(%can_assign)) {
                   2459:         if ($can_assign{$key}) {
                   2460:             $authnum ++;
                   2461:         }
                   2462:     }
                   2463:     if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
                   2464:         $authnum --;
                   2465:     }
                   2466:     return ($authnum,%can_assign);
                   2467: }
                   2468: 
1.80      albertel 2469: ###############################################################
                   2470: ##    Get Kerberos Defaults for Domain                 ##
                   2471: ###############################################################
                   2472: ##
                   2473: ## Returns default kerberos version and an associated argument
                   2474: ## as listed in file domain.tab. If not listed, provides
                   2475: ## appropriate default domain and kerberos version.
                   2476: ##
                   2477: #-------------------------------------------
                   2478: 
                   2479: =pod
                   2480: 
1.648     raeburn  2481: =item * &get_kerberos_defaults()
1.80      albertel 2482: 
                   2483: get_kerberos_defaults($target_domain) returns the default kerberos
1.641     raeburn  2484: version and domain. If not found, it defaults to version 4 and the 
                   2485: domain of the server.
1.80      albertel 2486: 
1.648     raeburn  2487: =over 4
                   2488: 
1.80      albertel 2489: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
                   2490: 
1.648     raeburn  2491: =back
                   2492: 
                   2493: =back
                   2494: 
1.80      albertel 2495: =cut
                   2496: 
                   2497: #-------------------------------------------
                   2498: sub get_kerberos_defaults {
                   2499:     my $domain=shift;
1.641     raeburn  2500:     my ($krbdef,$krbdefdom);
                   2501:     my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
                   2502:     if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
                   2503:         $krbdef = $domdefaults{'auth_def'};
                   2504:         $krbdefdom = $domdefaults{'auth_arg_def'};
                   2505:     } else {
1.80      albertel 2506:         $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
                   2507:         my $krbdefdom=$1;
                   2508:         $krbdefdom=~tr/a-z/A-Z/;
                   2509:         $krbdef = "krb4";
                   2510:     }
                   2511:     return ($krbdef,$krbdefdom);
                   2512: }
1.112     bowersj2 2513: 
1.32      matthew  2514: 
1.46      matthew  2515: ###############################################################
                   2516: ##                Thesaurus Functions                        ##
                   2517: ###############################################################
1.20      www      2518: 
1.46      matthew  2519: =pod
1.20      www      2520: 
1.112     bowersj2 2521: =head1 Thesaurus Functions
                   2522: 
                   2523: =over 4
                   2524: 
1.648     raeburn  2525: =item * &initialize_keywords()
1.46      matthew  2526: 
                   2527: Initializes the package variable %Keywords if it is empty.  Uses the
                   2528: package variable $thesaurus_db_file.
                   2529: 
                   2530: =cut
                   2531: 
                   2532: ###################################################
                   2533: 
                   2534: sub initialize_keywords {
                   2535:     return 1 if (scalar keys(%Keywords));
                   2536:     # If we are here, %Keywords is empty, so fill it up
                   2537:     #   Make sure the file we need exists...
                   2538:     if (! -e $thesaurus_db_file) {
                   2539:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
                   2540:                                  " failed because it does not exist");
                   2541:         return 0;
                   2542:     }
                   2543:     #   Set up the hash as a database
                   2544:     my %thesaurus_db;
                   2545:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 2546:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  2547:         &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
                   2548:                                  $thesaurus_db_file);
                   2549:         return 0;
                   2550:     } 
                   2551:     #  Get the average number of appearances of a word.
                   2552:     my $avecount = $thesaurus_db{'average.count'};
                   2553:     #  Put keywords (those that appear > average) into %Keywords
                   2554:     while (my ($word,$data)=each (%thesaurus_db)) {
                   2555:         my ($count,undef) = split /:/,$data;
                   2556:         $Keywords{$word}++ if ($count > $avecount);
                   2557:     }
                   2558:     untie %thesaurus_db;
                   2559:     # Remove special values from %Keywords.
1.356     albertel 2560:     foreach my $value ('total.count','average.count') {
                   2561:         delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586     raeburn  2562:   }
1.46      matthew  2563:     return 1;
                   2564: }
                   2565: 
                   2566: ###################################################
                   2567: 
                   2568: =pod
                   2569: 
1.648     raeburn  2570: =item * &keyword($word)
1.46      matthew  2571: 
                   2572: Returns true if $word is a keyword.  A keyword is a word that appears more 
                   2573: than the average number of times in the thesaurus database.  Calls 
                   2574: &initialize_keywords
                   2575: 
                   2576: =cut
                   2577: 
                   2578: ###################################################
1.20      www      2579: 
                   2580: sub keyword {
1.46      matthew  2581:     return if (!&initialize_keywords());
                   2582:     my $word=lc(shift());
                   2583:     $word=~s/\W//g;
                   2584:     return exists($Keywords{$word});
1.20      www      2585: }
1.46      matthew  2586: 
                   2587: ###############################################################
                   2588: 
                   2589: =pod 
1.20      www      2590: 
1.648     raeburn  2591: =item * &get_related_words()
1.46      matthew  2592: 
1.160     matthew  2593: Look up a word in the thesaurus.  Takes a scalar argument and returns
1.46      matthew  2594: an array of words.  If the keyword is not in the thesaurus, an empty array
                   2595: will be returned.  The order of the words returned is determined by the
                   2596: database which holds them.
                   2597: 
                   2598: Uses global $thesaurus_db_file.
                   2599: 
                   2600: =cut
                   2601: 
                   2602: ###############################################################
                   2603: sub get_related_words {
                   2604:     my $keyword = shift;
                   2605:     my %thesaurus_db;
                   2606:     if (! -e $thesaurus_db_file) {
                   2607:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
                   2608:                                  "failed because the file does not exist");
                   2609:         return ();
                   2610:     }
                   2611:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 2612:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  2613:         return ();
                   2614:     } 
                   2615:     my @Words=();
1.429     www      2616:     my $count=0;
1.46      matthew  2617:     if (exists($thesaurus_db{$keyword})) {
1.356     albertel 2618: 	# The first element is the number of times
                   2619: 	# the word appears.  We do not need it now.
1.429     www      2620: 	my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
                   2621: 	my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
                   2622: 	my $threshold=$mostfrequentcount/10;
                   2623:         foreach my $possibleword (@RelatedWords) {
                   2624:             my ($word,$wordcount)=split(/\,/,$possibleword);
                   2625:             if ($wordcount>$threshold) {
                   2626: 		push(@Words,$word);
                   2627:                 $count++;
                   2628:                 if ($count>10) { last; }
                   2629: 	    }
1.20      www      2630:         }
                   2631:     }
1.46      matthew  2632:     untie %thesaurus_db;
                   2633:     return @Words;
1.14      harris41 2634: }
1.46      matthew  2635: 
1.112     bowersj2 2636: =pod
                   2637: 
                   2638: =back
                   2639: 
                   2640: =cut
1.61      www      2641: 
                   2642: # -------------------------------------------------------------- Plaintext name
1.81      albertel 2643: =pod
                   2644: 
1.112     bowersj2 2645: =head1 User Name Functions
                   2646: 
                   2647: =over 4
                   2648: 
1.648     raeburn  2649: =item * &plainname($uname,$udom,$first)
1.81      albertel 2650: 
1.112     bowersj2 2651: Takes a users logon name and returns it as a string in
1.226     albertel 2652: "first middle last generation" form 
                   2653: if $first is set to 'lastname' then it returns it as
                   2654: 'lastname generation, firstname middlename' if their is a lastname
1.81      albertel 2655: 
                   2656: =cut
1.61      www      2657: 
1.295     www      2658: 
1.81      albertel 2659: ###############################################################
1.61      www      2660: sub plainname {
1.226     albertel 2661:     my ($uname,$udom,$first)=@_;
1.537     albertel 2662:     return if (!defined($uname) || !defined($udom));
1.295     www      2663:     my %names=&getnames($uname,$udom);
1.226     albertel 2664:     my $name=&Apache::lonnet::format_name($names{'firstname'},
                   2665: 					  $names{'middlename'},
                   2666: 					  $names{'lastname'},
                   2667: 					  $names{'generation'},$first);
                   2668:     $name=~s/^\s+//;
1.62      www      2669:     $name=~s/\s+$//;
                   2670:     $name=~s/\s+/ /g;
1.353     albertel 2671:     if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62      www      2672:     return $name;
1.61      www      2673: }
1.66      www      2674: 
                   2675: # -------------------------------------------------------------------- Nickname
1.81      albertel 2676: =pod
                   2677: 
1.648     raeburn  2678: =item * &nickname($uname,$udom)
1.81      albertel 2679: 
                   2680: Gets a users name and returns it as a string as
                   2681: 
                   2682: "&quot;nickname&quot;"
1.66      www      2683: 
1.81      albertel 2684: if the user has a nickname or
                   2685: 
                   2686: "first middle last generation"
                   2687: 
                   2688: if the user does not
                   2689: 
                   2690: =cut
1.66      www      2691: 
                   2692: sub nickname {
                   2693:     my ($uname,$udom)=@_;
1.537     albertel 2694:     return if (!defined($uname) || !defined($udom));
1.295     www      2695:     my %names=&getnames($uname,$udom);
1.68      albertel 2696:     my $name=$names{'nickname'};
1.66      www      2697:     if ($name) {
                   2698:        $name='&quot;'.$name.'&quot;'; 
                   2699:     } else {
                   2700:        $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
                   2701: 	     $names{'lastname'}.' '.$names{'generation'};
                   2702:        $name=~s/\s+$//;
                   2703:        $name=~s/\s+/ /g;
                   2704:     }
                   2705:     return $name;
                   2706: }
                   2707: 
1.295     www      2708: sub getnames {
                   2709:     my ($uname,$udom)=@_;
1.537     albertel 2710:     return if (!defined($uname) || !defined($udom));
1.433     albertel 2711:     if ($udom eq 'public' && $uname eq 'public') {
                   2712: 	return ('lastname' => &mt('Public'));
                   2713:     }
1.295     www      2714:     my $id=$uname.':'.$udom;
                   2715:     my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
                   2716:     if ($cached) {
                   2717: 	return %{$names};
                   2718:     } else {
                   2719: 	my %loadnames=&Apache::lonnet::get('environment',
                   2720:                     ['firstname','middlename','lastname','generation','nickname'],
                   2721: 					 $udom,$uname);
                   2722: 	&Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
                   2723: 	return %loadnames;
                   2724:     }
                   2725: }
1.61      www      2726: 
1.542     raeburn  2727: # -------------------------------------------------------------------- getemails
1.648     raeburn  2728: 
1.542     raeburn  2729: =pod
                   2730: 
1.648     raeburn  2731: =item * &getemails($uname,$udom)
1.542     raeburn  2732: 
                   2733: Gets a user's email information and returns it as a hash with keys:
                   2734: notification, critnotification, permanentemail
                   2735: 
                   2736: For notification and critnotification, values are comma-separated lists 
1.648     raeburn  2737: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542     raeburn  2738:  
1.648     raeburn  2739: 
1.542     raeburn  2740: =cut
                   2741: 
1.648     raeburn  2742: 
1.466     albertel 2743: sub getemails {
                   2744:     my ($uname,$udom)=@_;
                   2745:     if ($udom eq 'public' && $uname eq 'public') {
                   2746: 	return;
                   2747:     }
1.467     www      2748:     if (!$udom) { $udom=$env{'user.domain'}; }
                   2749:     if (!$uname) { $uname=$env{'user.name'}; }
1.466     albertel 2750:     my $id=$uname.':'.$udom;
                   2751:     my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
                   2752:     if ($cached) {
                   2753: 	return %{$names};
                   2754:     } else {
                   2755: 	my %loadnames=&Apache::lonnet::get('environment',
                   2756:                     			   ['notification','critnotification',
                   2757: 					    'permanentemail'],
                   2758: 					   $udom,$uname);
                   2759: 	&Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
                   2760: 	return %loadnames;
                   2761:     }
                   2762: }
                   2763: 
1.551     albertel 2764: sub flush_email_cache {
                   2765:     my ($uname,$udom)=@_;
                   2766:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2767:     if (!$uname) { $uname=$env{'user.name'};   }
                   2768:     return if ($udom eq 'public' && $uname eq 'public');
                   2769:     my $id=$uname.':'.$udom;
                   2770:     &Apache::lonnet::devalidate_cache_new('emailscache',$id);
                   2771: }
                   2772: 
1.728     raeburn  2773: # -------------------------------------------------------------------- getlangs
                   2774: 
                   2775: =pod
                   2776: 
                   2777: =item * &getlangs($uname,$udom)
                   2778: 
                   2779: Gets a user's language preference and returns it as a hash with key:
                   2780: language.
                   2781: 
                   2782: =cut
                   2783: 
                   2784: 
                   2785: sub getlangs {
                   2786:     my ($uname,$udom) = @_;
                   2787:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2788:     if (!$uname) { $uname=$env{'user.name'};   }
                   2789:     my $id=$uname.':'.$udom;
                   2790:     my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
                   2791:     if ($cached) {
                   2792:         return %{$langs};
                   2793:     } else {
                   2794:         my %loadlangs=&Apache::lonnet::get('environment',['languages'],
                   2795:                                            $udom,$uname);
                   2796:         &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
                   2797:         return %loadlangs;
                   2798:     }
                   2799: }
                   2800: 
                   2801: sub flush_langs_cache {
                   2802:     my ($uname,$udom)=@_;
                   2803:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2804:     if (!$uname) { $uname=$env{'user.name'};   }
                   2805:     return if ($udom eq 'public' && $uname eq 'public');
                   2806:     my $id=$uname.':'.$udom;
                   2807:     &Apache::lonnet::devalidate_cache_new('userlangs',$id);
                   2808: }
                   2809: 
1.61      www      2810: # ------------------------------------------------------------------ Screenname
1.81      albertel 2811: 
                   2812: =pod
                   2813: 
1.648     raeburn  2814: =item * &screenname($uname,$udom)
1.81      albertel 2815: 
                   2816: Gets a users screenname and returns it as a string
                   2817: 
                   2818: =cut
1.61      www      2819: 
                   2820: sub screenname {
                   2821:     my ($uname,$udom)=@_;
1.258     albertel 2822:     if ($uname eq $env{'user.name'} &&
                   2823: 	$udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212     albertel 2824:     my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68      albertel 2825:     return $names{'screenname'};
1.62      www      2826: }
                   2827: 
1.212     albertel 2828: 
1.802     bisitz   2829: # ------------------------------------------------------------- Confirm Wrapper
                   2830: =pod
                   2831: 
                   2832: =item confirmwrapper
                   2833: 
                   2834: Wrap messages about completion of operation in box
                   2835: 
                   2836: =cut
                   2837: 
                   2838: sub confirmwrapper {
                   2839:     my ($message)=@_;
                   2840:     if ($message) {
                   2841:         return "\n".'<div class="LC_confirm_box">'."\n"
                   2842:                .$message."\n"
                   2843:                .'</div>'."\n";
                   2844:     } else {
                   2845:         return $message;
                   2846:     }
                   2847: }
                   2848: 
1.62      www      2849: # ------------------------------------------------------------- Message Wrapper
                   2850: 
                   2851: sub messagewrapper {
1.369     www      2852:     my ($link,$username,$domain,$subject,$text)=@_;
1.62      www      2853:     return 
1.441     albertel 2854:         '<a href="/adm/email?compose=individual&amp;'.
                   2855:         'recname='.$username.'&amp;recdom='.$domain.
                   2856: 	'&amp;subject='.&escape($subject).'&amp;text='.&escape($text).'" '.
1.200     matthew  2857:         'title="'.&mt('Send message').'">'.$link.'</a>';
1.74      www      2858: }
1.802     bisitz   2859: 
1.74      www      2860: # --------------------------------------------------------------- Notes Wrapper
                   2861: 
                   2862: sub noteswrapper {
                   2863:     my ($link,$un,$do)=@_;
                   2864:     return 
                   2865: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62      www      2866: }
1.802     bisitz   2867: 
1.62      www      2868: # ------------------------------------------------------------- Aboutme Wrapper
                   2869: 
                   2870: sub aboutmewrapper {
1.166     www      2871:     my ($link,$username,$domain,$target)=@_;
1.447     raeburn  2872:     if (!defined($username)  && !defined($domain)) {
                   2873:         return;
                   2874:     }
1.205     www      2875:     return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.756     weissno  2876: 	($target?' target="$target"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62      www      2877: }
                   2878: 
                   2879: # ------------------------------------------------------------ Syllabus Wrapper
                   2880: 
                   2881: sub syllabuswrapper {
1.707     bisitz   2882:     my ($linktext,$coursedir,$domain)=@_;
1.208     matthew  2883:     return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61      www      2884: }
1.14      harris41 2885: 
1.802     bisitz   2886: # -----------------------------------------------------------------------------
                   2887: 
1.208     matthew  2888: sub track_student_link {
1.268     albertel 2889:     my ($linktext,$sname,$sdom,$target,$start) = @_;
                   2890:     my $link ="/adm/trackstudent?";
1.208     matthew  2891:     my $title = 'View recent activity';
                   2892:     if (defined($sname) && $sname !~ /^\s*$/ &&
                   2893:         defined($sdom)  && $sdom  !~ /^\s*$/) {
1.268     albertel 2894:         $link .= "selected_student=$sname:$sdom";
1.208     matthew  2895:         $title .= ' of this student';
1.268     albertel 2896:     } 
1.208     matthew  2897:     if (defined($target) && $target !~ /^\s*$/) {
                   2898:         $target = qq{target="$target"};
                   2899:     } else {
                   2900:         $target = '';
                   2901:     }
1.268     albertel 2902:     if ($start) { $link.='&amp;start='.$start; }
1.554     albertel 2903:     $title = &mt($title);
                   2904:     $linktext = &mt($linktext);
1.448     albertel 2905:     return qq{<a href="$link" title="$title" $target>$linktext</a>}.
                   2906: 	&help_open_topic('View_recent_activity');
1.208     matthew  2907: }
                   2908: 
1.781     raeburn  2909: sub slot_reservations_link {
                   2910:     my ($linktext,$sname,$sdom,$target) = @_;
                   2911:     my $link ="/adm/slotrequest?command=showresv&amp;origin=aboutme";
                   2912:     my $title = 'View slot reservation history';
                   2913:     if (defined($sname) && $sname !~ /^\s*$/ &&
                   2914:         defined($sdom)  && $sdom  !~ /^\s*$/) {
                   2915:         $link .= "&amp;uname=$sname&amp;udom=$sdom";
                   2916:         $title .= ' of this student';
                   2917:     }
                   2918:     if (defined($target) && $target !~ /^\s*$/) {
                   2919:         $target = qq{target="$target"};
                   2920:     } else {
                   2921:         $target = '';
                   2922:     }
                   2923:     $title = &mt($title);
                   2924:     $linktext = &mt($linktext);
                   2925:     return qq{<a href="$link" title="$title" $target>$linktext</a>};
                   2926: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
                   2927: 
                   2928: }
                   2929: 
1.508     www      2930: # ===================================================== Display a student photo
                   2931: 
                   2932: 
1.509     albertel 2933: sub student_image_tag {
1.508     www      2934:     my ($domain,$user)=@_;
                   2935:     my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
                   2936:     if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
                   2937: 	return '<img src="'.$imgsrc.'" align="right" />';
                   2938:     } else {
                   2939: 	return '';
                   2940:     }
                   2941: }
                   2942: 
1.112     bowersj2 2943: =pod
                   2944: 
                   2945: =back
                   2946: 
                   2947: =head1 Access .tab File Data
                   2948: 
                   2949: =over 4
                   2950: 
1.648     raeburn  2951: =item * &languageids() 
1.112     bowersj2 2952: 
                   2953: returns list of all language ids
                   2954: 
                   2955: =cut
                   2956: 
1.14      harris41 2957: sub languageids {
1.16      harris41 2958:     return sort(keys(%language));
1.14      harris41 2959: }
                   2960: 
1.112     bowersj2 2961: =pod
                   2962: 
1.648     raeburn  2963: =item * &languagedescription() 
1.112     bowersj2 2964: 
                   2965: returns description of a specified language id
                   2966: 
                   2967: =cut
                   2968: 
1.14      harris41 2969: sub languagedescription {
1.125     www      2970:     my $code=shift;
                   2971:     return  ($supported_language{$code}?'* ':'').
                   2972:             $language{$code}.
1.126     www      2973: 	    ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145     www      2974: }
                   2975: 
                   2976: sub plainlanguagedescription {
                   2977:     my $code=shift;
                   2978:     return $language{$code};
                   2979: }
                   2980: 
                   2981: sub supportedlanguagecode {
                   2982:     my $code=shift;
                   2983:     return $supported_language{$code};
1.97      www      2984: }
                   2985: 
1.112     bowersj2 2986: =pod
                   2987: 
1.648     raeburn  2988: =item * &copyrightids() 
1.112     bowersj2 2989: 
                   2990: returns list of all copyrights
                   2991: 
                   2992: =cut
                   2993: 
                   2994: sub copyrightids {
                   2995:     return sort(keys(%cprtag));
                   2996: }
                   2997: 
                   2998: =pod
                   2999: 
1.648     raeburn  3000: =item * &copyrightdescription() 
1.112     bowersj2 3001: 
                   3002: returns description of a specified copyright id
                   3003: 
                   3004: =cut
                   3005: 
                   3006: sub copyrightdescription {
1.166     www      3007:     return &mt($cprtag{shift(@_)});
1.112     bowersj2 3008: }
1.197     matthew  3009: 
                   3010: =pod
                   3011: 
1.648     raeburn  3012: =item * &source_copyrightids() 
1.192     taceyjo1 3013: 
                   3014: returns list of all source copyrights
                   3015: 
                   3016: =cut
                   3017: 
                   3018: sub source_copyrightids {
                   3019:     return sort(keys(%scprtag));
                   3020: }
                   3021: 
                   3022: =pod
                   3023: 
1.648     raeburn  3024: =item * &source_copyrightdescription() 
1.192     taceyjo1 3025: 
                   3026: returns description of a specified source copyright id
                   3027: 
                   3028: =cut
                   3029: 
                   3030: sub source_copyrightdescription {
                   3031:     return &mt($scprtag{shift(@_)});
                   3032: }
1.112     bowersj2 3033: 
                   3034: =pod
                   3035: 
1.648     raeburn  3036: =item * &filecategories() 
1.112     bowersj2 3037: 
                   3038: returns list of all file categories
                   3039: 
                   3040: =cut
                   3041: 
                   3042: sub filecategories {
                   3043:     return sort(keys(%category_extensions));
                   3044: }
                   3045: 
                   3046: =pod
                   3047: 
1.648     raeburn  3048: =item * &filecategorytypes() 
1.112     bowersj2 3049: 
                   3050: returns list of file types belonging to a given file
                   3051: category
                   3052: 
                   3053: =cut
                   3054: 
                   3055: sub filecategorytypes {
1.356     albertel 3056:     my ($cat) = @_;
                   3057:     return @{$category_extensions{lc($cat)}};
1.112     bowersj2 3058: }
                   3059: 
                   3060: =pod
                   3061: 
1.648     raeburn  3062: =item * &fileembstyle() 
1.112     bowersj2 3063: 
                   3064: returns embedding style for a specified file type
                   3065: 
                   3066: =cut
                   3067: 
                   3068: sub fileembstyle {
                   3069:     return $fe{lc(shift(@_))};
1.169     www      3070: }
                   3071: 
1.351     www      3072: sub filemimetype {
                   3073:     return $fm{lc(shift(@_))};
                   3074: }
                   3075: 
1.169     www      3076: 
                   3077: sub filecategoryselect {
                   3078:     my ($name,$value)=@_;
1.189     matthew  3079:     return &select_form($value,$name,
1.169     www      3080: 			'' => &mt('Any category'),
                   3081: 			map { $_,$_ } sort(keys(%category_extensions)));
1.112     bowersj2 3082: }
                   3083: 
                   3084: =pod
                   3085: 
1.648     raeburn  3086: =item * &filedescription() 
1.112     bowersj2 3087: 
                   3088: returns description for a specified file type
                   3089: 
                   3090: =cut
                   3091: 
                   3092: sub filedescription {
1.188     matthew  3093:     my $file_description = $fd{lc(shift())};
                   3094:     $file_description =~ s:([\[\]]):~$1:g;
                   3095:     return &mt($file_description);
1.112     bowersj2 3096: }
                   3097: 
                   3098: =pod
                   3099: 
1.648     raeburn  3100: =item * &filedescriptionex() 
1.112     bowersj2 3101: 
                   3102: returns description for a specified file type with
                   3103: extra formatting
                   3104: 
                   3105: =cut
                   3106: 
                   3107: sub filedescriptionex {
                   3108:     my $ex=shift;
1.188     matthew  3109:     my $file_description = $fd{lc($ex)};
                   3110:     $file_description =~ s:([\[\]]):~$1:g;
                   3111:     return '.'.$ex.' '.&mt($file_description);
1.112     bowersj2 3112: }
                   3113: 
                   3114: # End of .tab access
                   3115: =pod
                   3116: 
                   3117: =back
                   3118: 
                   3119: =cut
                   3120: 
                   3121: # ------------------------------------------------------------------ File Types
                   3122: sub fileextensions {
                   3123:     return sort(keys(%fe));
                   3124: }
                   3125: 
1.97      www      3126: # ----------------------------------------------------------- Display Languages
                   3127: # returns a hash with all desired display languages
                   3128: #
                   3129: 
                   3130: sub display_languages {
                   3131:     my %languages=();
1.695     raeburn  3132:     foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356     albertel 3133: 	$languages{$lang}=1;
1.97      www      3134:     }
                   3135:     &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258     albertel 3136:     if ($env{'form.displaylanguage'}) {
1.356     albertel 3137: 	foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
                   3138: 	    $languages{$lang}=1;
1.97      www      3139:         }
                   3140:     }
                   3141:     return %languages;
1.14      harris41 3142: }
                   3143: 
1.582     albertel 3144: sub languages {
                   3145:     my ($possible_langs) = @_;
1.695     raeburn  3146:     my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582     albertel 3147:     if (!ref($possible_langs)) {
                   3148: 	if( wantarray ) {
                   3149: 	    return @preferred_langs;
                   3150: 	} else {
                   3151: 	    return $preferred_langs[0];
                   3152: 	}
                   3153:     }
                   3154:     my %possibilities = map { $_ => 1 } (@$possible_langs);
                   3155:     my @preferred_possibilities;
                   3156:     foreach my $preferred_lang (@preferred_langs) {
                   3157: 	if (exists($possibilities{$preferred_lang})) {
                   3158: 	    push(@preferred_possibilities, $preferred_lang);
                   3159: 	}
                   3160:     }
                   3161:     if( wantarray ) {
                   3162: 	return @preferred_possibilities;
                   3163:     }
                   3164:     return $preferred_possibilities[0];
                   3165: }
                   3166: 
1.742     raeburn  3167: sub user_lang {
                   3168:     my ($touname,$toudom,$fromcid) = @_;
                   3169:     my @userlangs;
                   3170:     if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
                   3171:         @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
                   3172:                     $env{'course.'.$fromcid.'.languages'}));
                   3173:     } else {
                   3174:         my %langhash = &getlangs($touname,$toudom);
                   3175:         if ($langhash{'languages'} ne '') {
                   3176:             @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
                   3177:         } else {
                   3178:             my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
                   3179:             if ($domdefs{'lang_def'} ne '') {
                   3180:                 @userlangs = ($domdefs{'lang_def'});
                   3181:             }
                   3182:         }
                   3183:     }
                   3184:     my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
                   3185:     my $user_lh = Apache::localize->get_handle(@languages);
                   3186:     return $user_lh;
                   3187: }
                   3188: 
                   3189: 
1.112     bowersj2 3190: ###############################################################
                   3191: ##               Student Answer Attempts                     ##
                   3192: ###############################################################
                   3193: 
                   3194: =pod
                   3195: 
                   3196: =head1 Alternate Problem Views
                   3197: 
                   3198: =over 4
                   3199: 
1.648     raeburn  3200: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112     bowersj2 3201:     $getattempt, $regexp, $gradesub)
                   3202: 
                   3203: Return string with previous attempt on problem. Arguments:
                   3204: 
                   3205: =over 4
                   3206: 
                   3207: =item * $symb: Problem, including path
                   3208: 
                   3209: =item * $username: username of the desired student
                   3210: 
                   3211: =item * $domain: domain of the desired student
1.14      harris41 3212: 
1.112     bowersj2 3213: =item * $course: Course ID
1.14      harris41 3214: 
1.112     bowersj2 3215: =item * $getattempt: Leave blank for all attempts, otherwise put
                   3216:     something
1.14      harris41 3217: 
1.112     bowersj2 3218: =item * $regexp: if string matches this regexp, the string will be
                   3219:     sent to $gradesub
1.14      harris41 3220: 
1.112     bowersj2 3221: =item * $gradesub: routine that processes the string if it matches $regexp
1.14      harris41 3222: 
1.112     bowersj2 3223: =back
1.14      harris41 3224: 
1.112     bowersj2 3225: The output string is a table containing all desired attempts, if any.
1.16      harris41 3226: 
1.112     bowersj2 3227: =cut
1.1       albertel 3228: 
                   3229: sub get_previous_attempt {
1.43      ng       3230:   my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1       albertel 3231:   my $prevattempts='';
1.43      ng       3232:   no strict 'refs';
1.1       albertel 3233:   if ($symb) {
1.3       albertel 3234:     my (%returnhash)=
                   3235:       &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1       albertel 3236:     if ($returnhash{'version'}) {
                   3237:       my %lasthash=();
                   3238:       my $version;
                   3239:       for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356     albertel 3240:         foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
                   3241: 	  $lasthash{$key}=$returnhash{$version.':'.$key};
1.19      harris41 3242:         }
1.1       albertel 3243:       }
1.596     albertel 3244:       $prevattempts=&start_data_table().&start_data_table_header_row();
                   3245:       $prevattempts.='<th>'.&mt('History').'</th>';
1.356     albertel 3246:       foreach my $key (sort(keys(%lasthash))) {
                   3247: 	my ($ign,@parts) = split(/\./,$key);
1.41      ng       3248: 	if ($#parts > 0) {
1.31      albertel 3249: 	  my $data=$parts[-1];
                   3250: 	  pop(@parts);
1.596     albertel 3251: 	  $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.'&nbsp;</th>';
1.31      albertel 3252: 	} else {
1.41      ng       3253: 	  if ($#parts == 0) {
                   3254: 	    $prevattempts.='<th>'.$parts[0].'</th>';
                   3255: 	  } else {
                   3256: 	    $prevattempts.='<th>'.$ign.'</th>';
                   3257: 	  }
1.31      albertel 3258: 	}
1.16      harris41 3259:       }
1.596     albertel 3260:       $prevattempts.=&end_data_table_header_row();
1.40      ng       3261:       if ($getattempt eq '') {
                   3262: 	for ($version=1;$version<=$returnhash{'version'};$version++) {
1.596     albertel 3263: 	  $prevattempts.=&start_data_table_row().
                   3264: 	      '<td>'.&mt('Transaction [_1]',$version).'</td>';
1.356     albertel 3265: 	    foreach my $key (sort(keys(%lasthash))) {
1.581     albertel 3266: 		my $value = &format_previous_attempt_value($key,
                   3267: 							   $returnhash{$version.':'.$key});
                   3268: 		$prevattempts.='<td>'.$value.'&nbsp;</td>';   
1.40      ng       3269: 	    }
1.596     albertel 3270: 	  $prevattempts.=&end_data_table_row();
1.40      ng       3271: 	 }
1.1       albertel 3272:       }
1.596     albertel 3273:       $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356     albertel 3274:       foreach my $key (sort(keys(%lasthash))) {
1.581     albertel 3275: 	my $value = &format_previous_attempt_value($key,$lasthash{$key});
1.356     albertel 3276: 	if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
1.40      ng       3277: 	$prevattempts.='<td>'.$value.'&nbsp;</td>';
1.16      harris41 3278:       }
1.596     albertel 3279:       $prevattempts.= &end_data_table_row().&end_data_table();
1.1       albertel 3280:     } else {
1.596     albertel 3281:       $prevattempts=
                   3282: 	  &start_data_table().&start_data_table_row().
                   3283: 	  '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
                   3284: 	  &end_data_table_row().&end_data_table();
1.1       albertel 3285:     }
                   3286:   } else {
1.596     albertel 3287:     $prevattempts=
                   3288: 	  &start_data_table().&start_data_table_row().
                   3289: 	  '<td>'.&mt('No data.').'</td>'.
                   3290: 	  &end_data_table_row().&end_data_table();
1.1       albertel 3291:   }
1.10      albertel 3292: }
                   3293: 
1.581     albertel 3294: sub format_previous_attempt_value {
                   3295:     my ($key,$value) = @_;
                   3296:     if ($key =~ /timestamp/) {
                   3297: 	$value = &Apache::lonlocal::locallocaltime($value);
                   3298:     } elsif (ref($value) eq 'ARRAY') {
                   3299: 	$value = '('.join(', ', @{ $value }).')';
                   3300:     } else {
                   3301: 	$value = &unescape($value);
                   3302:     }
                   3303:     return $value;
                   3304: }
                   3305: 
                   3306: 
1.107     albertel 3307: sub relative_to_absolute {
                   3308:     my ($url,$output)=@_;
                   3309:     my $parser=HTML::TokeParser->new(\$output);
                   3310:     my $token;
                   3311:     my $thisdir=$url;
                   3312:     my @rlinks=();
                   3313:     while ($token=$parser->get_token) {
                   3314: 	if ($token->[0] eq 'S') {
                   3315: 	    if ($token->[1] eq 'a') {
                   3316: 		if ($token->[2]->{'href'}) {
                   3317: 		    $rlinks[$#rlinks+1]=$token->[2]->{'href'};
                   3318: 		}
                   3319: 	    } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
                   3320: 		$rlinks[$#rlinks+1]=$token->[2]->{'src'};
                   3321: 	    } elsif ($token->[1] eq 'base') {
                   3322: 		$thisdir=$token->[2]->{'href'};
                   3323: 	    }
                   3324: 	}
                   3325:     }
                   3326:     $thisdir=~s-/[^/]*$--;
1.356     albertel 3327:     foreach my $link (@rlinks) {
1.726     raeburn  3328: 	unless (($link=~/^https?\:\/\//i) ||
1.356     albertel 3329: 		($link=~/^\//) ||
                   3330: 		($link=~/^javascript:/i) ||
                   3331: 		($link=~/^mailto:/i) ||
                   3332: 		($link=~/^\#/)) {
                   3333: 	    my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
                   3334: 	    $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107     albertel 3335: 	}
                   3336:     }
                   3337: # -------------------------------------------------- Deal with Applet codebases
                   3338:     $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
                   3339:     return $output;
                   3340: }
                   3341: 
1.112     bowersj2 3342: =pod
                   3343: 
1.648     raeburn  3344: =item * &get_student_view()
1.112     bowersj2 3345: 
                   3346: show a snapshot of what student was looking at
                   3347: 
                   3348: =cut
                   3349: 
1.10      albertel 3350: sub get_student_view {
1.186     albertel 3351:   my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114     www      3352:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 3353:   my (%form);
1.10      albertel 3354:   my @elements=('symb','courseid','domain','username');
                   3355:   foreach my $element (@elements) {
1.186     albertel 3356:       $form{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 3357:   }
1.186     albertel 3358:   if (defined($moreenv)) {
                   3359:       %form=(%form,%{$moreenv});
                   3360:   }
1.236     albertel 3361:   if (defined($target)) { $form{'grade_target'} = $target; }
1.107     albertel 3362:   $feedurl=&Apache::lonnet::clutter($feedurl);
1.650     www      3363:   my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11      albertel 3364:   $userview=~s/\<body[^\>]*\>//gi;
                   3365:   $userview=~s/\<\/body\>//gi;
                   3366:   $userview=~s/\<html\>//gi;
                   3367:   $userview=~s/\<\/html\>//gi;
                   3368:   $userview=~s/\<head\>//gi;
                   3369:   $userview=~s/\<\/head\>//gi;
                   3370:   $userview=~s/action\s*\=/would_be_action\=/gi;
1.107     albertel 3371:   $userview=&relative_to_absolute($feedurl,$userview);
1.650     www      3372:   if (wantarray) {
                   3373:      return ($userview,$response);
                   3374:   } else {
                   3375:      return $userview;
                   3376:   }
                   3377: }
                   3378: 
                   3379: sub get_student_view_with_retries {
                   3380:   my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
                   3381: 
                   3382:     my $ok = 0;                 # True if we got a good response.
                   3383:     my $content;
                   3384:     my $response;
                   3385: 
                   3386:     # Try to get the student_view done. within the retries count:
                   3387:     
                   3388:     do {
                   3389:          ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
                   3390:          $ok      = $response->is_success;
                   3391:          if (!$ok) {
                   3392:             &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
                   3393:          }
                   3394:          $retries--;
                   3395:     } while (!$ok && ($retries > 0));
                   3396:     
                   3397:     if (!$ok) {
                   3398:        $content = '';          # On error return an empty content.
                   3399:     }
1.651     www      3400:     if (wantarray) {
                   3401:        return ($content, $response);
                   3402:     } else {
                   3403:        return $content;
                   3404:     }
1.11      albertel 3405: }
                   3406: 
1.112     bowersj2 3407: =pod
                   3408: 
1.648     raeburn  3409: =item * &get_student_answers() 
1.112     bowersj2 3410: 
                   3411: show a snapshot of how student was answering problem
                   3412: 
                   3413: =cut
                   3414: 
1.11      albertel 3415: sub get_student_answers {
1.100     sakharuk 3416:   my ($symb,$username,$domain,$courseid,%form) = @_;
1.114     www      3417:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 3418:   my (%moreenv);
1.11      albertel 3419:   my @elements=('symb','courseid','domain','username');
                   3420:   foreach my $element (@elements) {
1.186     albertel 3421:     $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 3422:   }
1.186     albertel 3423:   $moreenv{'grade_target'}='answer';
                   3424:   %moreenv=(%form,%moreenv);
1.497     raeburn  3425:   $feedurl = &Apache::lonnet::clutter($feedurl);
                   3426:   my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10      albertel 3427:   return $userview;
1.1       albertel 3428: }
1.116     albertel 3429: 
                   3430: =pod
                   3431: 
                   3432: =item * &submlink()
                   3433: 
1.242     albertel 3434: Inputs: $text $uname $udom $symb $target
1.116     albertel 3435: 
                   3436: Returns: A link to grades.pm such as to see the SUBM view of a student
                   3437: 
                   3438: =cut
                   3439: 
                   3440: ###############################################
                   3441: sub submlink {
1.242     albertel 3442:     my ($text,$uname,$udom,$symb,$target)=@_;
1.116     albertel 3443:     if (!($uname && $udom)) {
                   3444: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 3445: 	    &Apache::lonnet::whichuser($symb);
1.116     albertel 3446: 	if (!$symb) { $symb=$cursymb; }
                   3447:     }
1.254     matthew  3448:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      3449:     $symb=&escape($symb);
1.242     albertel 3450:     if ($target) { $target="target=\"$target\""; }
                   3451:     return '<a href="/adm/grades?&command=submission&'.
                   3452: 	'symb='.$symb.'&student='.$uname.
                   3453: 	'&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
                   3454: }
                   3455: ##############################################
                   3456: 
                   3457: =pod
                   3458: 
                   3459: =item * &pgrdlink()
                   3460: 
                   3461: Inputs: $text $uname $udom $symb $target
                   3462: 
                   3463: Returns: A link to grades.pm such as to see the PGRD view of a student
                   3464: 
                   3465: =cut
                   3466: 
                   3467: ###############################################
                   3468: sub pgrdlink {
                   3469:     my $link=&submlink(@_);
                   3470:     $link=~s/(&command=submission)/$1&showgrading=yes/;
                   3471:     return $link;
                   3472: }
                   3473: ##############################################
                   3474: 
                   3475: =pod
                   3476: 
                   3477: =item * &pprmlink()
                   3478: 
                   3479: Inputs: $text $uname $udom $symb $target
                   3480: 
                   3481: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283     albertel 3482: student and a specific resource
1.242     albertel 3483: 
                   3484: =cut
                   3485: 
                   3486: ###############################################
                   3487: sub pprmlink {
                   3488:     my ($text,$uname,$udom,$symb,$target)=@_;
                   3489:     if (!($uname && $udom)) {
                   3490: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 3491: 	    &Apache::lonnet::whichuser($symb);
1.242     albertel 3492: 	if (!$symb) { $symb=$cursymb; }
                   3493:     }
1.254     matthew  3494:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      3495:     $symb=&escape($symb);
1.242     albertel 3496:     if ($target) { $target="target=\"$target\""; }
1.595     albertel 3497:     return '<a href="/adm/parmset?command=set&amp;'.
                   3498: 	'symb='.$symb.'&amp;uname='.$uname.
                   3499: 	'&amp;udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116     albertel 3500: }
                   3501: ##############################################
1.37      matthew  3502: 
1.112     bowersj2 3503: =pod
                   3504: 
                   3505: =back
                   3506: 
                   3507: =cut
                   3508: 
1.37      matthew  3509: ###############################################
1.51      www      3510: 
                   3511: 
                   3512: sub timehash {
1.687     raeburn  3513:     my ($thistime) = @_;
                   3514:     my $timezone = &Apache::lonlocal::gettimezone();
                   3515:     my $dt = DateTime->from_epoch(epoch => $thistime)
                   3516:                      ->set_time_zone($timezone);
                   3517:     my $wday = $dt->day_of_week();
                   3518:     if ($wday == 7) { $wday = 0; }
                   3519:     return ( 'second' => $dt->second(),
                   3520:              'minute' => $dt->minute(),
                   3521:              'hour'   => $dt->hour(),
                   3522:              'day'     => $dt->day_of_month(),
                   3523:              'month'   => $dt->month(),
                   3524:              'year'    => $dt->year(),
                   3525:              'weekday' => $wday,
                   3526:              'dayyear' => $dt->day_of_year(),
                   3527:              'dlsav'   => $dt->is_dst() );
1.51      www      3528: }
                   3529: 
1.370     www      3530: sub utc_string {
                   3531:     my ($date)=@_;
1.371     www      3532:     return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370     www      3533: }
                   3534: 
1.51      www      3535: sub maketime {
                   3536:     my %th=@_;
1.687     raeburn  3537:     my ($epoch_time,$timezone,$dt);
                   3538:     $timezone = &Apache::lonlocal::gettimezone();
                   3539:     eval {
                   3540:         $dt = DateTime->new( year   => $th{'year'},
                   3541:                              month  => $th{'month'},
                   3542:                              day    => $th{'day'},
                   3543:                              hour   => $th{'hour'},
                   3544:                              minute => $th{'minute'},
                   3545:                              second => $th{'second'},
                   3546:                              time_zone => $timezone,
                   3547:                          );
                   3548:     };
                   3549:     if (!$@) {
                   3550:         $epoch_time = $dt->epoch;
                   3551:         if ($epoch_time) {
                   3552:             return $epoch_time;
                   3553:         }
                   3554:     }
1.51      www      3555:     return POSIX::mktime(
                   3556:         ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210     www      3557:          $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70      www      3558: }
                   3559: 
                   3560: #########################################
1.51      www      3561: 
                   3562: sub findallcourses {
1.482     raeburn  3563:     my ($roles,$uname,$udom) = @_;
1.355     albertel 3564:     my %roles;
                   3565:     if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348     albertel 3566:     my %courses;
1.51      www      3567:     my $now=time;
1.482     raeburn  3568:     if (!defined($uname)) {
                   3569:         $uname = $env{'user.name'};
                   3570:     }
                   3571:     if (!defined($udom)) {
                   3572:         $udom = $env{'user.domain'};
                   3573:     }
                   3574:     if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
                   3575:         my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
                   3576:         if (!%roles) {
                   3577:             %roles = (
                   3578:                        cc => 1,
                   3579:                        in => 1,
                   3580:                        ep => 1,
                   3581:                        ta => 1,
                   3582:                        cr => 1,
                   3583:                        st => 1,
                   3584:              );
                   3585:         }
                   3586:         foreach my $entry (keys(%roleshash)) {
                   3587:             my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
                   3588:             if ($trole =~ /^cr/) { 
                   3589:                 next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
                   3590:             } else {
                   3591:                 next if (!exists($roles{$trole}));
                   3592:             }
                   3593:             if ($tend) {
                   3594:                 next if ($tend < $now);
                   3595:             }
                   3596:             if ($tstart) {
                   3597:                 next if ($tstart > $now);
                   3598:             }
                   3599:             my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
                   3600:             (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
                   3601:             if ($secpart eq '') {
                   3602:                 ($cnum,$role) = split(/_/,$cnumpart); 
                   3603:                 $sec = 'none';
                   3604:                 $realsec = '';
                   3605:             } else {
                   3606:                 $cnum = $cnumpart;
                   3607:                 ($sec,$role) = split(/_/,$secpart);
                   3608:                 $realsec = $sec;
1.490     raeburn  3609:             }
1.482     raeburn  3610:             $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
                   3611:         }
                   3612:     } else {
                   3613:         foreach my $key (keys(%env)) {
1.483     albertel 3614: 	    if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
                   3615:                  $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482     raeburn  3616: 	        my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
                   3617: 	        next if ($role eq 'ca' || $role eq 'aa');
                   3618: 	        next if (%roles && !exists($roles{$role}));
                   3619: 	        my ($starttime,$endtime)=split(/\./,$env{$key});
                   3620:                 my $active=1;
                   3621:                 if ($starttime) {
                   3622: 		    if ($now<$starttime) { $active=0; }
                   3623:                 }
                   3624:                 if ($endtime) {
                   3625:                     if ($now>$endtime) { $active=0; }
                   3626:                 }
                   3627:                 if ($active) {
                   3628:                     if ($sec eq '') {
                   3629:                         $sec = 'none';
                   3630:                     }
                   3631:                     $courses{$cdom.'_'.$cnum}{$sec} = 
                   3632:                                      $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474     raeburn  3633:                 }
                   3634:             }
1.51      www      3635:         }
                   3636:     }
1.474     raeburn  3637:     return %courses;
1.51      www      3638: }
1.37      matthew  3639: 
1.54      www      3640: ###############################################
1.474     raeburn  3641: 
                   3642: sub blockcheck {
1.482     raeburn  3643:     my ($setters,$activity,$uname,$udom) = @_;
1.490     raeburn  3644: 
                   3645:     if (!defined($udom)) {
                   3646:         $udom = $env{'user.domain'};
                   3647:     }
                   3648:     if (!defined($uname)) {
                   3649:         $uname = $env{'user.name'};
                   3650:     }
                   3651: 
                   3652:     # If uname and udom are for a course, check for blocks in the course.
                   3653: 
                   3654:     if (&Apache::lonnet::is_course($udom,$uname)) {
                   3655:         my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502     raeburn  3656:         my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490     raeburn  3657:         return ($startblock,$endblock);
                   3658:     }
1.474     raeburn  3659: 
1.502     raeburn  3660:     my $startblock = 0;
                   3661:     my $endblock = 0;
1.482     raeburn  3662:     my %live_courses = &findallcourses(undef,$uname,$udom);
1.474     raeburn  3663: 
1.490     raeburn  3664:     # If uname is for a user, and activity is course-specific, i.e.,
                   3665:     # boards, chat or groups, check for blocking in current course only.
1.474     raeburn  3666: 
1.490     raeburn  3667:     if (($activity eq 'boards' || $activity eq 'chat' ||
                   3668:          $activity eq 'groups') && ($env{'request.course.id'})) {
                   3669:         foreach my $key (keys(%live_courses)) {
                   3670:             if ($key ne $env{'request.course.id'}) {
                   3671:                 delete($live_courses{$key});
                   3672:             }
                   3673:         }
                   3674:     }
                   3675: 
                   3676:     my $otheruser = 0;
                   3677:     my %own_courses;
                   3678:     if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
                   3679:         # Resource belongs to user other than current user.
                   3680:         $otheruser = 1;
                   3681:         # Gather courses for current user
                   3682:         %own_courses = 
                   3683:             &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
                   3684:     }
                   3685: 
                   3686:     # Gather active course roles - course coordinator, instructor, 
                   3687:     # exam proctor, ta, student, or custom role.
1.474     raeburn  3688: 
                   3689:     foreach my $course (keys(%live_courses)) {
1.482     raeburn  3690:         my ($cdom,$cnum);
                   3691:         if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
                   3692:             $cdom = $env{'course.'.$course.'.domain'};
                   3693:             $cnum = $env{'course.'.$course.'.num'};
                   3694:         } else {
1.490     raeburn  3695:             ($cdom,$cnum) = split(/_/,$course); 
1.482     raeburn  3696:         }
                   3697:         my $no_ownblock = 0;
                   3698:         my $no_userblock = 0;
1.533     raeburn  3699:         if ($otheruser && $activity ne 'com') {
1.490     raeburn  3700:             # Check if current user has 'evb' priv for this
                   3701:             if (defined($own_courses{$course})) {
                   3702:                 foreach my $sec (keys(%{$own_courses{$course}})) {
                   3703:                     my $checkrole = 'cm./'.$cdom.'/'.$cnum;
                   3704:                     if ($sec ne 'none') {
                   3705:                         $checkrole .= '/'.$sec;
                   3706:                     }
                   3707:                     if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   3708:                         $no_ownblock = 1;
                   3709:                         last;
                   3710:                     }
                   3711:                 }
                   3712:             }
                   3713:             # if they have 'evb' priv and are currently not playing student
                   3714:             next if (($no_ownblock) &&
                   3715:                  ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
                   3716:         }
1.474     raeburn  3717:         foreach my $sec (keys(%{$live_courses{$course}})) {
1.482     raeburn  3718:             my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474     raeburn  3719:             if ($sec ne 'none') {
1.482     raeburn  3720:                 $checkrole .= '/'.$sec;
1.474     raeburn  3721:             }
1.490     raeburn  3722:             if ($otheruser) {
                   3723:                 # Resource belongs to user other than current user.
                   3724:                 # Assemble privs for that user, and check for 'evb' priv.
1.482     raeburn  3725:                 my ($trole,$tdom,$tnum,$tsec);
                   3726:                 my $entry = $live_courses{$course}{$sec};
                   3727:                 if ($entry =~ /^cr/) {
                   3728:                     ($trole,$tdom,$tnum,$tsec) = 
                   3729:                       ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
                   3730:                 } else {
                   3731:                     ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
                   3732:                 }
                   3733:                 my ($spec,$area,$trest,%allroles,%userroles);
                   3734:                 $area = '/'.$tdom.'/'.$tnum;
                   3735:                 $trest = $tnum;
                   3736:                 if ($tsec ne '') {
                   3737:                     $area .= '/'.$tsec;
                   3738:                     $trest .= '/'.$tsec;
                   3739:                 }
                   3740:                 $spec = $trole.'.'.$area;
                   3741:                 if ($trole =~ /^cr/) {
                   3742:                     &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
                   3743:                                                       $tdom,$spec,$trest,$area);
                   3744:                 } else {
                   3745:                     &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
                   3746:                                                        $tdom,$spec,$trest,$area);
                   3747:                 }
                   3748:                 my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486     raeburn  3749:                 if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
                   3750:                     if ($1) {
                   3751:                         $no_userblock = 1;
                   3752:                         last;
                   3753:                     }
                   3754:                 }
1.490     raeburn  3755:             } else {
                   3756:                 # Resource belongs to current user
                   3757:                 # Check for 'evb' priv via lonnet::allowed().
1.482     raeburn  3758:                 if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   3759:                     $no_ownblock = 1;
                   3760:                     last;
                   3761:                 }
1.474     raeburn  3762:             }
                   3763:         }
                   3764:         # if they have the evb priv and are currently not playing student
1.482     raeburn  3765:         next if (($no_ownblock) &&
1.491     albertel 3766:                  ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482     raeburn  3767:         next if ($no_userblock);
1.474     raeburn  3768: 
1.490     raeburn  3769:         # Retrieve blocking times and identity of blocker for course
                   3770:         # of specified user, unless user has 'evb' privilege.
1.502     raeburn  3771:         
                   3772:         my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
                   3773:         if (($start != 0) && 
                   3774:             (($startblock == 0) || ($startblock > $start))) {
                   3775:             $startblock = $start;
                   3776:         }
                   3777:         if (($end != 0)  &&
                   3778:             (($endblock == 0) || ($endblock < $end))) {
                   3779:             $endblock = $end;
                   3780:         }
1.490     raeburn  3781:     }
                   3782:     return ($startblock,$endblock);
                   3783: }
                   3784: 
                   3785: sub get_blocks {
                   3786:     my ($setters,$activity,$cdom,$cnum) = @_;
                   3787:     my $startblock = 0;
                   3788:     my $endblock = 0;
                   3789:     my $course = $cdom.'_'.$cnum;
                   3790:     $setters->{$course} = {};
                   3791:     $setters->{$course}{'staff'} = [];
                   3792:     $setters->{$course}{'times'} = [];
                   3793:     my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
                   3794:     foreach my $record (keys(%records)) {
                   3795:         my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
                   3796:         if ($start <= time && $end >= time) {
                   3797:             my ($staff_name,$staff_dom,$title,$blocks) =
                   3798:                 &parse_block_record($records{$record});
                   3799:             if ($blocks->{$activity} eq 'on') {
                   3800:                 push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
                   3801:                 push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491     albertel 3802:                 if ( ($startblock == 0) || ($startblock > $start) ) {
                   3803:                     $startblock = $start;
1.490     raeburn  3804:                 }
1.491     albertel 3805:                 if ( ($endblock == 0) || ($endblock < $end) ) {
                   3806:                     $endblock = $end;
1.474     raeburn  3807:                 }
                   3808:             }
                   3809:         }
                   3810:     }
                   3811:     return ($startblock,$endblock);
                   3812: }
                   3813: 
                   3814: sub parse_block_record {
                   3815:     my ($record) = @_;
                   3816:     my ($setuname,$setudom,$title,$blocks);
                   3817:     if (ref($record) eq 'HASH') {
                   3818:         ($setuname,$setudom) = split(/:/,$record->{'setter'});
                   3819:         $title = &unescape($record->{'event'});
                   3820:         $blocks = $record->{'blocks'};
                   3821:     } else {
                   3822:         my @data = split(/:/,$record,3);
                   3823:         if (scalar(@data) eq 2) {
                   3824:             $title = $data[1];
                   3825:             ($setuname,$setudom) = split(/@/,$data[0]);
                   3826:         } else {
                   3827:             ($setuname,$setudom,$title) = @data;
                   3828:         }
                   3829:         $blocks = { 'com' => 'on' };
                   3830:     }
                   3831:     return ($setuname,$setudom,$title,$blocks);
                   3832: }
                   3833: 
                   3834: sub build_block_table {
                   3835:     my ($startblock,$endblock,$setters) = @_;
                   3836:     my %lt = &Apache::lonlocal::texthash(
                   3837:         'cacb' => 'Currently active communication blocks',
                   3838:         'cour' => 'Course',
                   3839:         'dura' => 'Duration',
                   3840:         'blse' => 'Block set by'
                   3841:     );
                   3842:     my $output;
1.476     raeburn  3843:     $output = '<br />'.$lt{'cacb'}.':<br />';
1.474     raeburn  3844:     $output .= &start_data_table();
                   3845:     $output .= '
                   3846: <tr>
                   3847:  <th>'.$lt{'cour'}.'</th>
                   3848:  <th>'.$lt{'dura'}.'</th>
                   3849:  <th>'.$lt{'blse'}.'</th>
                   3850: </tr>
                   3851: ';
                   3852:     foreach my $course (keys(%{$setters})) {
                   3853:         my %courseinfo=&Apache::lonnet::coursedescription($course);
                   3854:         for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) {
                   3855:             my ($uname,$udom) = @{$$setters{$course}{staff}[$i]};
1.490     raeburn  3856:             my $fullname = &plainname($uname,$udom);
                   3857:             if (defined($env{'user.name'}) && defined($env{'user.domain'})
                   3858:                 && $env{'user.name'} ne 'public' 
                   3859:                 && $env{'user.domain'} ne 'public') {
                   3860:                 $fullname = &aboutmewrapper($fullname,$uname,$udom);
                   3861:             }
1.474     raeburn  3862:             my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]};
                   3863:             $openblock = &Apache::lonlocal::locallocaltime($openblock);
                   3864:             $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
                   3865:             $output .= &Apache::loncommon::start_data_table_row().
                   3866:                        '<td>'.$courseinfo{'description'}.'</td>'.
                   3867:                        '<td>'.$openblock.' to '.$closeblock.'</td>'.
1.490     raeburn  3868:                        '<td>'.$fullname.'</td>'.
1.474     raeburn  3869:                         &Apache::loncommon::end_data_table_row();
                   3870:         }
                   3871:     }
                   3872:     $output .= &end_data_table();
                   3873: }
1.854     kalberla 3874: sub blocking_status {
                   3875:   my $blocked = blocking_status_print(@_);
                   3876:   my ($activity,$uname,$udom) = @_;
                   3877:   if(!wantarray) {
                   3878:     return $blocked;
                   3879:   }
                   3880:   my $output;
                   3881:   my $querystring;
                   3882:   $querystring = "?activity=$activity";
                   3883:   if(defined($uname)) { 
                   3884:     $querystring .= "&uname=$uname";
                   3885:   }if(defined($udom)) {
                   3886:     $querystring .= "&udom=$udom";
                   3887:   }
                   3888: 
                   3889:       $output .= <<"END_MYBLOCK";
                   3890: <script type="text/javascript">
                   3891: // <![CDATA[
                   3892:     function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
                   3893:         var options = "width=" + w + ",height=" + h + ",";
                   3894:         options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
                   3895:         options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
                   3896:         var newWin = window.open(url, wdwName, options);
                   3897:         newWin.focus();
                   3898:     }
                   3899: 
                   3900: // ]]>
                   3901: </script>
                   3902: END_MYBLOCK
                   3903:   my $popupUrl = "/adm/blockingstatus/$querystring";
                   3904:   $output.="\n<img src='/res/adm/pages/emblem-readonly.png' /><a onclick='openWindow(\"$popupUrl\",\"Blocking Table\",600,300,\"no\",\"no\");return false;' href='/adm/blockingstatus/$querystring'>Blocking Table</a>";
1.474     raeburn  3905: 
1.854     kalberla 3906:   return ($blocked, $output);
                   3907: }
                   3908: sub blocking_status_print {
1.490     raeburn  3909:     my ($activity,$uname,$udom) = @_;
                   3910:     my %setters;
                   3911:     my ($blocked,$output,$ownitem,$is_course);
                   3912:     my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
                   3913:     if ($startblock && $endblock) {
                   3914:         $blocked = 1;
                   3915:         if (wantarray) {
                   3916:             my $category;
                   3917:             if ($activity eq 'boards') {
                   3918:                 $category = 'Discussion posts in this course';
                   3919:             } elsif ($activity eq 'blogs') {
                   3920:                 $category = 'Blogs';
                   3921:             } elsif ($activity eq 'port') {
                   3922:                 if (defined($uname) && defined($udom)) {
                   3923:                     if ($uname eq $env{'user.name'} &&
                   3924:                         $udom eq $env{'user.domain'}) {
                   3925:                         $ownitem = 1;
                   3926:                     }
                   3927:                 }
                   3928:                 $is_course = &Apache::lonnet::is_course($udom,$uname);
                   3929:                 if ($ownitem) { 
                   3930:                     $category = 'Your portfolio files';  
                   3931:                 } elsif ($is_course) {
                   3932:                     my $coursedesc;
                   3933:                     foreach my $course (keys(%setters)) {
                   3934:                         my %courseinfo =
                   3935:                              &Apache::lonnet::coursedescription($course);
                   3936:                         $coursedesc = $courseinfo{'description'};
                   3937:                     }
1.764     weissno  3938:                     $category = "Group portfolio in the course '$coursedesc'";
1.490     raeburn  3939:                 } else {
                   3940:                     $category = 'Portfolio files belonging to ';
                   3941:                     if ($env{'user.name'} eq 'public' && 
                   3942:                         $env{'user.domain'} eq 'public') {
                   3943:                         $category .= &plainname($uname,$udom);
                   3944:                     } else {
                   3945:                         $category .= &aboutmewrapper(&plainname($uname,$udom),$uname,$udom);  
                   3946:                     }
                   3947:                 }
                   3948:             } elsif ($activity eq 'groups') {
                   3949:                 $category = 'Groups in this course';
                   3950:             }
                   3951:             my $showstart = &Apache::lonlocal::locallocaltime($startblock);
                   3952:             my $showend = &Apache::lonlocal::locallocaltime($endblock);
                   3953:             $output = '<br />'.&mt('[_1] will be inaccessible between [_2] and [_3] because communication is being blocked.',$category,$showstart,$showend).'<br />';
                   3954:             if (!($activity eq 'port' && !($ownitem) && !($is_course))) { 
                   3955:                 $output .= &build_block_table($startblock,$endblock,\%setters);
                   3956:             }
                   3957:         }
                   3958:     }
                   3959:     if (wantarray) {
                   3960:         return ($blocked,$output);
                   3961:     } else {
                   3962:         return $blocked;
                   3963:     }
                   3964: }
                   3965: 
1.60      matthew  3966: ###############################################
                   3967: 
1.682     raeburn  3968: sub check_ip_acc {
                   3969:     my ($acc)=@_;
                   3970:     &Apache::lonxml::debug("acc is $acc");
                   3971:     if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
                   3972:         return 1;
                   3973:     }
                   3974:     my $allowed=0;
                   3975:     my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
                   3976: 
                   3977:     my $name;
                   3978:     foreach my $pattern (split(',',$acc)) {
                   3979:         $pattern =~ s/^\s*//;
                   3980:         $pattern =~ s/\s*$//;
                   3981:         if ($pattern =~ /\*$/) {
                   3982:             #35.8.*
                   3983:             $pattern=~s/\*//;
                   3984:             if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
                   3985:         } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
                   3986:             #35.8.3.[34-56]
                   3987:             my $low=$2;
                   3988:             my $high=$3;
                   3989:             $pattern=$1;
                   3990:             if ($ip =~ /^\Q$pattern\E/) {
                   3991:                 my $last=(split(/\./,$ip))[3];
                   3992:                 if ($last <=$high && $last >=$low) { $allowed=1; }
                   3993:             }
                   3994:         } elsif ($pattern =~ /^\*/) {
                   3995:             #*.msu.edu
                   3996:             $pattern=~s/\*//;
                   3997:             if (!defined($name)) {
                   3998:                 use Socket;
                   3999:                 my $netaddr=inet_aton($ip);
                   4000:                 ($name)=gethostbyaddr($netaddr,AF_INET);
                   4001:             }
                   4002:             if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
                   4003:         } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
                   4004:             #127.0.0.1
                   4005:             if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
                   4006:         } else {
                   4007:             #some.name.com
                   4008:             if (!defined($name)) {
                   4009:                 use Socket;
                   4010:                 my $netaddr=inet_aton($ip);
                   4011:                 ($name)=gethostbyaddr($netaddr,AF_INET);
                   4012:             }
                   4013:             if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
                   4014:         }
                   4015:         if ($allowed) { last; }
                   4016:     }
                   4017:     return $allowed;
                   4018: }
                   4019: 
                   4020: ###############################################
                   4021: 
1.60      matthew  4022: =pod
                   4023: 
1.112     bowersj2 4024: =head1 Domain Template Functions
                   4025: 
                   4026: =over 4
                   4027: 
                   4028: =item * &determinedomain()
1.60      matthew  4029: 
                   4030: Inputs: $domain (usually will be undef)
                   4031: 
1.63      www      4032: Returns: Determines which domain should be used for designs
1.60      matthew  4033: 
                   4034: =cut
1.54      www      4035: 
1.60      matthew  4036: ###############################################
1.63      www      4037: sub determinedomain {
                   4038:     my $domain=shift;
1.531     albertel 4039:     if (! $domain) {
1.60      matthew  4040:         # Determine domain if we have not been given one
                   4041:         $domain = $Apache::lonnet::perlvar{'lonDefDomain'};
1.258     albertel 4042:         if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
                   4043:         if ($env{'request.role.domain'}) { 
                   4044:             $domain=$env{'request.role.domain'}; 
1.60      matthew  4045:         }
                   4046:     }
1.63      www      4047:     return $domain;
                   4048: }
                   4049: ###############################################
1.517     raeburn  4050: 
1.518     albertel 4051: sub devalidate_domconfig_cache {
                   4052:     my ($udom)=@_;
                   4053:     &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
                   4054: }
                   4055: 
                   4056: # ---------------------- Get domain configuration for a domain
                   4057: sub get_domainconf {
                   4058:     my ($udom) = @_;
                   4059:     my $cachetime=1800;
                   4060:     my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
                   4061:     if (defined($cached)) { return %{$result}; }
                   4062: 
                   4063:     my %domconfig = &Apache::lonnet::get_dom('configuration',
                   4064: 					     ['login','rolecolors'],$udom);
1.632     raeburn  4065:     my (%designhash,%legacy);
1.518     albertel 4066:     if (keys(%domconfig) > 0) {
                   4067:         if (ref($domconfig{'login'}) eq 'HASH') {
1.632     raeburn  4068:             if (keys(%{$domconfig{'login'}})) {
                   4069:                 foreach my $key (keys(%{$domconfig{'login'}})) {
1.699     raeburn  4070:                     if (ref($domconfig{'login'}{$key}) eq 'HASH') {
                   4071:                         foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
                   4072:                             $designhash{$udom.'.login.'.$key.'_'.$img} = 
                   4073:                                 $domconfig{'login'}{$key}{$img};
                   4074:                         }
                   4075:                     } else {
                   4076:                         $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
                   4077:                     }
1.632     raeburn  4078:                 }
                   4079:             } else {
                   4080:                 $legacy{'login'} = 1;
1.518     albertel 4081:             }
1.632     raeburn  4082:         } else {
                   4083:             $legacy{'login'} = 1;
1.518     albertel 4084:         }
                   4085:         if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632     raeburn  4086:             if (keys(%{$domconfig{'rolecolors'}})) {
                   4087:                 foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
                   4088:                     if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
                   4089:                         foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
                   4090:                             $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
                   4091:                         }
1.518     albertel 4092:                     }
                   4093:                 }
1.632     raeburn  4094:             } else {
                   4095:                 $legacy{'rolecolors'} = 1;
1.518     albertel 4096:             }
1.632     raeburn  4097:         } else {
                   4098:             $legacy{'rolecolors'} = 1;
1.518     albertel 4099:         }
1.632     raeburn  4100:         if (keys(%legacy) > 0) {
                   4101:             my %legacyhash = &get_legacy_domconf($udom);
                   4102:             foreach my $item (keys(%legacyhash)) {
                   4103:                 if ($item =~ /^\Q$udom\E\.login/) {
                   4104:                     if ($legacy{'login'}) { 
                   4105:                         $designhash{$item} = $legacyhash{$item};
                   4106:                     }
                   4107:                 } else {
                   4108:                     if ($legacy{'rolecolors'}) {
                   4109:                         $designhash{$item} = $legacyhash{$item};
                   4110:                     }
1.518     albertel 4111:                 }
                   4112:             }
                   4113:         }
1.632     raeburn  4114:     } else {
                   4115:         %designhash = &get_legacy_domconf($udom); 
1.518     albertel 4116:     }
                   4117:     &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
                   4118: 				  $cachetime);
                   4119:     return %designhash;
                   4120: }
                   4121: 
1.632     raeburn  4122: sub get_legacy_domconf {
                   4123:     my ($udom) = @_;
                   4124:     my %legacyhash;
                   4125:     my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
                   4126:     my $designfile =  $designdir.'/'.$udom.'.tab';
                   4127:     if (-e $designfile) {
                   4128:         if ( open (my $fh,"<$designfile") ) {
                   4129:             while (my $line = <$fh>) {
                   4130:                 next if ($line =~ /^\#/);
                   4131:                 chomp($line);
                   4132:                 my ($key,$val)=(split(/\=/,$line));
                   4133:                 if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
                   4134:             }
                   4135:             close($fh);
                   4136:         }
                   4137:     }
                   4138:     if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
                   4139:         $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
                   4140:     }
                   4141:     return %legacyhash;
                   4142: }
                   4143: 
1.63      www      4144: =pod
                   4145: 
1.112     bowersj2 4146: =item * &domainlogo()
1.63      www      4147: 
                   4148: Inputs: $domain (usually will be undef)
                   4149: 
                   4150: Returns: A link to a domain logo, if the domain logo exists.
                   4151: If the domain logo does not exist, a description of the domain.
                   4152: 
                   4153: =cut
1.112     bowersj2 4154: 
1.63      www      4155: ###############################################
                   4156: sub domainlogo {
1.517     raeburn  4157:     my $domain = &determinedomain(shift);
1.518     albertel 4158:     my %designhash = &get_domainconf($domain);    
1.517     raeburn  4159:     # See if there is a logo
                   4160:     if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519     raeburn  4161:         my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538     albertel 4162:         if ($imgsrc =~ m{^/(adm|res)/}) {
                   4163: 	    if ($imgsrc =~ m{^/res/}) {
                   4164: 		my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
                   4165: 		&Apache::lonnet::repcopy($local_name);
                   4166: 	    }
                   4167: 	   $imgsrc = &lonhttpdurl($imgsrc);
1.519     raeburn  4168:         } 
                   4169:         return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514     albertel 4170:     } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
                   4171:         return &Apache::lonnet::domain($domain,'description');
1.59      www      4172:     } else {
1.60      matthew  4173:         return '';
1.59      www      4174:     }
                   4175: }
1.63      www      4176: ##############################################
                   4177: 
                   4178: =pod
                   4179: 
1.112     bowersj2 4180: =item * &designparm()
1.63      www      4181: 
                   4182: Inputs: $which parameter; $domain (usually will be undef)
                   4183: 
                   4184: Returns: value of designparamter $which
                   4185: 
                   4186: =cut
1.112     bowersj2 4187: 
1.397     albertel 4188: 
1.400     albertel 4189: ##############################################
1.397     albertel 4190: sub designparm {
                   4191:     my ($which,$domain)=@_;
                   4192:     if (exists($env{'environment.color.'.$which})) {
1.817     bisitz   4193:         return $env{'environment.color.'.$which};
1.96      www      4194:     }
1.63      www      4195:     $domain=&determinedomain($domain);
1.518     albertel 4196:     my %domdesign = &get_domainconf($domain);
1.520     raeburn  4197:     my $output;
1.517     raeburn  4198:     if ($domdesign{$domain.'.'.$which} ne '') {
1.817     bisitz   4199:         $output = $domdesign{$domain.'.'.$which};
1.63      www      4200:     } else {
1.520     raeburn  4201:         $output = $defaultdesign{$which};
                   4202:     }
                   4203:     if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635     raeburn  4204:         ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538     albertel 4205:         if ($output =~ m{^/(adm|res)/}) {
1.817     bisitz   4206:             if ($output =~ m{^/res/}) {
                   4207:                 my $local_name = &Apache::lonnet::filelocation('',$output);
                   4208:                 &Apache::lonnet::repcopy($local_name);
                   4209:             }
1.520     raeburn  4210:             $output = &lonhttpdurl($output);
                   4211:         }
1.63      www      4212:     }
1.520     raeburn  4213:     return $output;
1.63      www      4214: }
1.59      www      4215: 
1.822     bisitz   4216: ##############################################
                   4217: =pod
                   4218: 
1.832     bisitz   4219: =item * &authorspace()
                   4220: 
                   4221: Inputs: ./.
                   4222: 
                   4223: Returns: Path to the Construction Space of the current user's
                   4224:          accessed author space
                   4225:          The author space will be that of the current user
                   4226:          when accessing the own author space
                   4227:          and that of the co-author/assistent co-author
                   4228:          when accessing the co-author's/assistent co-author's
                   4229:          space
                   4230: 
                   4231: =cut
                   4232: 
                   4233: sub authorspace {
                   4234:     my $caname = '';
                   4235:     if ($env{'request.role'} =~ /^ca|^aa/) {
                   4236:         (undef,$caname) =
                   4237:             ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
                   4238:     } else {
                   4239:         $caname = $env{'user.name'};
                   4240:     }
                   4241:     return '/priv/'.$caname.'/';
                   4242: }
                   4243: 
                   4244: ##############################################
                   4245: =pod
                   4246: 
1.822     bisitz   4247: =item * &head_subbox()
                   4248: 
                   4249: Inputs: $content (contains HTML code with page functions, etc.)
                   4250: 
                   4251: Returns: HTML div with $content
                   4252:          To be included in page header
                   4253: 
                   4254: =cut
                   4255: 
                   4256: sub head_subbox {
                   4257:     my ($content)=@_;
                   4258:     my $output =
1.844     bisitz   4259:         '<div id="LC_head_subbox">'
1.822     bisitz   4260:        .$content
                   4261:        .'</div>'
                   4262: }
                   4263: 
                   4264: ##############################################
                   4265: =pod
                   4266: 
                   4267: =item * &CSTR_pageheader()
                   4268: 
                   4269: Inputs: ./.
                   4270: 
                   4271: Returns: HTML div with CSTR path and recent box
                   4272:          To be included on Construction Space pages
                   4273: 
                   4274: =cut
                   4275: 
                   4276: sub CSTR_pageheader {
                   4277:     # this is for resources; directories have customtitle, and crumbs
                   4278:             # and select recent are created in lonpubdir.pm  
                   4279:     my ($uname,$thisdisfn)=
                   4280:         ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
                   4281:     my $formaction='/priv/'.$uname.'/'.$thisdisfn;
                   4282:     $formaction=~s/\/+/\//g;
                   4283: 
                   4284:     my $parentpath = '';
                   4285:     my $lastitem = '';
                   4286:     if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
                   4287:         $parentpath = $1;
                   4288:         $lastitem = $2;
                   4289:     } else {
                   4290:         $lastitem = $thisdisfn;
                   4291:     }
                   4292:     return
                   4293:          '<div>'
                   4294:         .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
                   4295:         .'<b>'.&mt('Construction Space:').'</b> '
                   4296:         .'<form name="dirs" method="post" action="'.$formaction
                   4297:         .'" target="_top"><tt><b>' #FIXME lonpubdir: target="_parent"
                   4298:         .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."$lastitem</b></tt><br />"
                   4299:         #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
                   4300:         .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
                   4301:         .'</form>'
                   4302:         .&Apache::lonmenu::constspaceform()
                   4303:         .'</div>';
                   4304: }
                   4305: 
1.60      matthew  4306: ###############################################
                   4307: ###############################################
                   4308: 
                   4309: =pod
                   4310: 
1.112     bowersj2 4311: =back
                   4312: 
1.549     albertel 4313: =head1 HTML Helpers
1.112     bowersj2 4314: 
                   4315: =over 4
                   4316: 
                   4317: =item * &bodytag()
1.60      matthew  4318: 
                   4319: Returns a uniform header for LON-CAPA web pages.
                   4320: 
                   4321: Inputs: 
                   4322: 
1.112     bowersj2 4323: =over 4
                   4324: 
                   4325: =item * $title, A title to be displayed on the page.
                   4326: 
                   4327: =item * $function, the current role (can be undef).
                   4328: 
                   4329: =item * $addentries, extra parameters for the <body> tag.
                   4330: 
                   4331: =item * $bodyonly, if defined, only return the <body> tag.
                   4332: 
                   4333: =item * $domain, if defined, force a given domain.
                   4334: 
                   4335: =item * $forcereg, if page should register as content page (relevant for 
1.86      www      4336:             text interface only)
1.60      matthew  4337: 
1.814     bisitz   4338: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
                   4339:                      navigational links
1.317     albertel 4340: 
1.338     albertel 4341: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
                   4342: 
1.361     albertel 4343: =item * $no_inline_link, if true and in remote mode, don't show the 
                   4344:          'Switch To Inline Menu' link
                   4345: 
1.460     albertel 4346: =item * $args, optional argument valid values are
                   4347:             no_auto_mt_title -> prevents &mt()ing the title arg
1.562     albertel 4348:             inherit_jsmath -> when creating popup window in a page,
                   4349:                               should it have jsmath forced on by the
                   4350:                               current page
1.460     albertel 4351: 
1.112     bowersj2 4352: =back
                   4353: 
1.60      matthew  4354: Returns: A uniform header for LON-CAPA web pages.  
                   4355: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
                   4356: If $bodyonly is undef or zero, an html string containing a <body> tag and 
                   4357: other decorations will be returned.
                   4358: 
                   4359: =cut
                   4360: 
1.54      www      4361: sub bodytag {
1.831     bisitz   4362:     my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.816     bisitz   4363:         $no_nav_bar,$bgcolor,$no_inline_link,$args)=@_;
1.339     albertel 4364: 
1.460     albertel 4365:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339     albertel 4366: 
1.183     matthew  4367:     $function = &get_users_function() if (!$function);
1.339     albertel 4368:     my $img =    &designparm($function.'.img',$domain);
                   4369:     my $font =   &designparm($function.'.font',$domain);
                   4370:     my $pgbg   = $bgcolor || &designparm($function.'.pgbg',$domain);
                   4371: 
1.803     bisitz   4372:     my %design = ( 'style'   => 'margin-top: 0',
1.535     albertel 4373: 		   'bgcolor' => $pgbg,
1.339     albertel 4374: 		   'text'    => $font,
                   4375:                    'alink'   => &designparm($function.'.alink',$domain),
                   4376: 		   'vlink'   => &designparm($function.'.vlink',$domain),
                   4377: 		   'link'    => &designparm($function.'.link',$domain),);
1.438     albertel 4378:     @design{keys(%$addentries)} = @$addentries{keys(%$addentries)}; 
1.339     albertel 4379: 
1.63      www      4380:  # role and realm
1.378     raeburn  4381:     my ($role,$realm) = split(/\./,$env{'request.role'},2);
                   4382:     if ($role  eq 'ca') {
1.479     albertel 4383:         my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500     albertel 4384:         $realm = &plainname($rname,$rdom);
1.378     raeburn  4385:     } 
1.55      www      4386: # realm
1.258     albertel 4387:     if ($env{'request.course.id'}) {
1.378     raeburn  4388:         if ($env{'request.role'} !~ /^cr/) {
                   4389:             $role = &Apache::lonnet::plaintext($role,&course_type());
                   4390:         }
1.359     albertel 4391: 	$realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378     raeburn  4392:     } else {
                   4393:         $role = &Apache::lonnet::plaintext($role);
1.54      www      4394:     }
1.433     albertel 4395: 
1.359     albertel 4396:     if (!$realm) { $realm='&nbsp;'; }
1.55      www      4397: # Set messages
1.60      matthew  4398:     my $messages=&domainlogo($domain);
1.330     albertel 4399: 
1.438     albertel 4400:     my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329     albertel 4401: 
1.101     www      4402: # construct main body tag
1.359     albertel 4403:     my $bodytag = "<body $extra_body_attr>".
1.562     albertel 4404: 	&Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252     albertel 4405: 
1.530     albertel 4406:     if ($bodyonly) {
1.60      matthew  4407:         return $bodytag;
1.798     tempelho 4408:     } 
1.359     albertel 4409: 
1.410     albertel 4410:     my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.433     albertel 4411:     if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
                   4412: 	undef($role);
1.434     albertel 4413:     } else {
                   4414: 	$name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433     albertel 4415:     }
1.359     albertel 4416:     
1.762     bisitz   4417:     my $titleinfo = '<h1>'.$title.'</h1>';
1.359     albertel 4418:     #
                   4419:     # Extra info if you are the DC
                   4420:     my $dc_info = '';
                   4421:     if ($env{'user.adv'} && exists($env{'user.role.dc./'.
                   4422:                         $env{'course.'.$env{'request.course.id'}.
                   4423:                                  '.domain'}.'/'})) {
                   4424:         my $cid = $env{'request.course.id'};
                   4425:         $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380     www      4426:         $dc_info =~ s/\s+$//;
1.359     albertel 4427:         $dc_info = '('.$dc_info.')';
                   4428:     }
                   4429: 
1.853     droeschl 4430:     $role = "($role)" if $role;
                   4431:     &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
                   4432: 
1.837     bisitz   4433:     if ($env{'environment.remote'} eq 'off') {
1.359     albertel 4434:         # No Remote
1.258     albertel 4435: 	if ($env{'request.state'} eq 'construct') {
1.359     albertel 4436: 	    $forcereg=1;
                   4437: 	}
                   4438: 
1.836     bisitz   4439: #    if ($env{'request.state'} eq 'construct') {
                   4440: #        $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
                   4441: #    }
1.359     albertel 4442: 
1.816     bisitz   4443:         my $titletable = '<table id="LC_title_bar">'
1.836     bisitz   4444:                         ."<tr><td> $titleinfo $dc_info</td>"
1.816     bisitz   4445:                         .'</tr></table>';
                   4446: 
1.814     bisitz   4447: 	if ($no_nav_bar) {
1.359     albertel 4448: 	    $bodytag .= $titletable;
                   4449: 	} else {
1.852     droeschl 4450:         $bodytag .= qq|<div id="LC_nav_bar">$name $role<br />
                   4451:             <em>$realm</em> $dc_info</div>| unless $env{'form.inhibitmenu'};
                   4452: 
1.359     albertel 4453: 	    if ($env{'request.state'} eq 'construct') {
1.337     albertel 4454:                 $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg,
                   4455: 							  $titletable);
1.272     raeburn  4456:             } else {
1.336     albertel 4457:                 $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg).
1.359     albertel 4458: 		    $titletable;
1.272     raeburn  4459:             }
1.235     raeburn  4460:         }
                   4461:         return $bodytag;
1.94      www      4462:     }
1.95      www      4463: 
1.93      www      4464: #
1.95      www      4465: # Top frame rendering, Remote is up
1.93      www      4466: #
1.359     albertel 4467: 
1.517     raeburn  4468:     my $imgsrc = $img;
                   4469:     if ($img =~ /^\/adm/) {
1.575     albertel 4470:         $imgsrc = &lonhttpdurl($img);
1.517     raeburn  4471:     }
                   4472:     my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359     albertel 4473: 
1.305     www      4474:     # Explicit link to get inline menu
1.361     albertel 4475:     my $menu= ($no_inline_link?''
1.853     droeschl 4476: 	       :'<a href="/adm/remote?action=collapse">'.&mt('Switch to Inline Menu Mode').'</a>');
                   4477:     $bodytag .= qq|<div id="LC_nav_bar">$name $role
                   4478:             <em>$realm</em> $dc_info </div>
                   4479:             <ol class="LC_smallMenu LC_right">
                   4480:                 <li>$menu</li>
                   4481:             </ol>| unless $env{'form.inhibitmenu'};
1.245     matthew  4482:     #
1.94      www      4483:     return(<<ENDBODY);
1.60      matthew  4484: $bodytag
1.359     albertel 4485: <table id="LC_title_bar" class="LC_with_remote">
1.791     tempelho 4486: <tr><td>$upperleft</td>
                   4487:     <td>$messages&nbsp;</td>
1.54      www      4488: </tr>
1.359     albertel 4489: <tr><td>$titleinfo $dc_info $menu</td>
1.368     albertel 4490: </tr>
1.356     albertel 4491: </table>
1.54      www      4492: ENDBODY
1.182     matthew  4493: }
                   4494: 
1.330     albertel 4495: sub make_attr_string {
                   4496:     my ($register,$attr_ref) = @_;
                   4497: 
                   4498:     if ($attr_ref && !ref($attr_ref)) {
                   4499: 	die("addentries Must be a hash ref ".
                   4500: 	    join(':',caller(1))." ".
                   4501: 	    join(':',caller(0))." ");
                   4502:     }
                   4503: 
                   4504:     if ($register) {
1.339     albertel 4505: 	my ($on_load,$on_unload);
                   4506: 	foreach my $key (keys(%{$attr_ref})) {
                   4507: 	    if      (lc($key) eq 'onload') {
                   4508: 		$on_load.=$attr_ref->{$key}.';';
                   4509: 		delete($attr_ref->{$key});
                   4510: 
                   4511: 	    } elsif (lc($key) eq 'onunload') {
                   4512: 		$on_unload.=$attr_ref->{$key}.';';
                   4513: 		delete($attr_ref->{$key});
                   4514: 	    }
                   4515: 	}
                   4516: 	$attr_ref->{'onload'}  =
                   4517: 	    &Apache::lonmenu::loadevents().  $on_load;
                   4518: 	$attr_ref->{'onunload'}=
                   4519: 	    &Apache::lonmenu::unloadevents().$on_unload;
                   4520:     }
                   4521: 
                   4522: # Accessibility font enhance
                   4523:     if ($env{'browser.fontenhance'} eq 'on') {
                   4524: 	my $style;
                   4525: 	foreach my $key (keys(%{$attr_ref})) {
                   4526: 	    if (lc($key) eq 'style') {
                   4527: 		$style.=$attr_ref->{$key}.';';
                   4528: 		delete($attr_ref->{$key});
                   4529: 	    }
                   4530: 	}
                   4531: 	$attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330     albertel 4532:     }
1.339     albertel 4533: 
1.330     albertel 4534:     my $attr_string;
                   4535:     foreach my $attr (keys(%$attr_ref)) {
                   4536: 	$attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
                   4537:     }
                   4538:     return $attr_string;
                   4539: }
                   4540: 
                   4541: 
1.182     matthew  4542: ###############################################
1.251     albertel 4543: ###############################################
                   4544: 
                   4545: =pod
                   4546: 
                   4547: =item * &endbodytag()
                   4548: 
                   4549: Returns a uniform footer for LON-CAPA web pages.
                   4550: 
1.635     raeburn  4551: Inputs: 1 - optional reference to an args hash
                   4552: If in the hash, key for noredirectlink has a value which evaluates to true,
                   4553: a 'Continue' link is not displayed if the page contains an
                   4554: internal redirect in the <head></head> section,
                   4555: i.e., $env{'internal.head.redirect'} exists   
1.251     albertel 4556: 
                   4557: =cut
                   4558: 
                   4559: sub endbodytag {
1.635     raeburn  4560:     my ($args) = @_;
1.251     albertel 4561:     my $endbodytag='</body>';
1.269     albertel 4562:     $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315     albertel 4563:     if ( exists( $env{'internal.head.redirect'} ) ) {
1.635     raeburn  4564:         if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
                   4565: 	    $endbodytag=
                   4566: 	        "<br /><a href=\"$env{'internal.head.redirect'}\">".
                   4567: 	        &mt('Continue').'</a>'.
                   4568: 	        $endbodytag;
                   4569:         }
1.315     albertel 4570:     }
1.251     albertel 4571:     return $endbodytag;
                   4572: }
                   4573: 
1.352     albertel 4574: =pod
                   4575: 
                   4576: =item * &standard_css()
                   4577: 
                   4578: Returns a style sheet
                   4579: 
                   4580: Inputs: (all optional)
                   4581:             domain         -> force to color decorate a page for a specific
                   4582:                                domain
                   4583:             function       -> force usage of a specific rolish color scheme
                   4584:             bgcolor        -> override the default page bgcolor
                   4585: 
                   4586: =cut
                   4587: 
1.343     albertel 4588: sub standard_css {
1.345     albertel 4589:     my ($function,$domain,$bgcolor) = @_;
1.352     albertel 4590:     $function  = &get_users_function() if (!$function);
                   4591:     my $img    = &designparm($function.'.img',   $domain);
                   4592:     my $tabbg  = &designparm($function.'.tabbg', $domain);
                   4593:     my $font   = &designparm($function.'.font',  $domain);
1.801     tempelho 4594:     my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791     tempelho 4595: #second colour for later usage
1.345     albertel 4596:     my $sidebg = &designparm($function.'.sidebg',$domain);
1.382     albertel 4597:     my $pgbg_or_bgcolor =
                   4598: 	         $bgcolor ||
1.352     albertel 4599: 	         &designparm($function.'.pgbg',  $domain);
1.382     albertel 4600:     my $pgbg   = &designparm($function.'.pgbg',  $domain);
1.352     albertel 4601:     my $alink  = &designparm($function.'.alink', $domain);
                   4602:     my $vlink  = &designparm($function.'.vlink', $domain);
                   4603:     my $link   = &designparm($function.'.link',  $domain);
                   4604: 
1.704     muellerd 4605:     my $loginbg = &designparm('login.sidebg',$domain);
1.712     muellerd 4606:     my $bgcol = &designparm('login.bgcol',$domain);
                   4607:     my $textcol = &designparm('login.textcol',$domain);
1.704     muellerd 4608: 
1.602     albertel 4609:     my $sans                 = 'Verdana,Arial,Helvetica,sans-serif';
1.395     albertel 4610:     my $mono                 = 'monospace';
1.850     bisitz   4611:     my $data_table_head      = $sidebg;
                   4612:     my $data_table_light     = '#FAFAFA';
                   4613:     my $data_table_dark      = '#F0F0F0';
1.470     banghart 4614:     my $data_table_darker    = '#CCCCCC';
1.349     albertel 4615:     my $data_table_highlight = '#FFFF00';
1.352     albertel 4616:     my $mail_new             = '#FFBB77';
                   4617:     my $mail_new_hover       = '#DD9955';
                   4618:     my $mail_read            = '#BBBB77';
                   4619:     my $mail_read_hover      = '#999944';
                   4620:     my $mail_replied         = '#AAAA88';
                   4621:     my $mail_replied_hover   = '#888855';
                   4622:     my $mail_other           = '#99BBBB';
                   4623:     my $mail_other_hover     = '#669999';
1.391     albertel 4624:     my $table_header         = '#DDDDDD';
1.489     raeburn  4625:     my $feedback_link_bg     = '#BBBBBB';
1.701     harmsja  4626:     my $lg_border_color	     = '#C8C8C8';
1.392     albertel 4627: 
1.608     albertel 4628:     my $border = ($env{'browser.type'} eq 'explorer' ||
1.803     bisitz   4629: 		  $env{'browser.type'} eq 'safari'     ) ? '0 2px 0 2px'
                   4630: 	                                                 : '0 3px 0 4px';
1.448     albertel 4631: 
1.523     albertel 4632: 
1.343     albertel 4633:     return <<END;
1.795     www      4634: body {
                   4635:    font-family: $sans;
                   4636:    line-height:130%;
                   4637:    font-size:0.83em;
                   4638:    color:$font;
                   4639: }
                   4640: 
                   4641: a:link, a:visited { 
                   4642:   font-size:100%; 
                   4643: }
                   4644: 
                   4645: a:focus { 
                   4646:   color: red;
                   4647:   background: yellow 
                   4648: }
1.698     harmsja  4649: 
1.846     bisitz   4650: hr {
                   4651:   clear: both;
                   4652:   color: $tabbg;
                   4653:   background-color: $tabbg;
                   4654:   height: 3px;
                   4655:   border: none;
                   4656: }
                   4657: 
1.795     www      4658: form, .inline { 
                   4659:    display: inline; 
                   4660: }
1.721     harmsja  4661: 
1.795     www      4662: .LC_right {
                   4663:    text-align:right;
                   4664: }
                   4665: 
                   4666: .LC_middle {
                   4667:    vertical-align:middle;
                   4668: }
1.721     harmsja  4669: 
                   4670: /* just for tests */
1.754     droeschl 4671: .LC_400Box {width:400px; }
1.721     harmsja  4672: /* end */
                   4673: 
1.778     bisitz   4674: .LC_filename {
                   4675:   font-family: $mono;
                   4676:   white-space:pre;
                   4677: }
                   4678: 
                   4679: .LC_fileicon {
                   4680:   border: none;
                   4681:   height: 1.3em;
                   4682:   vertical-align: text-bottom;
                   4683:   margin-right: 0.3em;
                   4684:   text-decoration:none;
                   4685: }
                   4686: 
1.350     albertel 4687: .LC_error {
                   4688:   color: red;
                   4689:   font-size: larger;
                   4690: }
1.795     www      4691: 
1.457     albertel 4692: .LC_warning,
                   4693: .LC_diff_removed {
1.733     bisitz   4694:   color: red;
1.394     albertel 4695: }
1.532     albertel 4696: 
                   4697: .LC_info,
1.457     albertel 4698: .LC_success,
                   4699: .LC_diff_added {
1.350     albertel 4700:   color: green;
                   4701: }
1.795     www      4702: 
1.802     bisitz   4703: div.LC_confirm_box {
                   4704:   background-color: #FAFAFA;
                   4705:   border: 1px solid $lg_border_color;
                   4706:   margin-right: 0;
                   4707:   padding: 5px;
                   4708: }
                   4709: 
                   4710: div.LC_confirm_box .LC_error img,
                   4711: div.LC_confirm_box .LC_success img {
                   4712:   vertical-align: middle;
                   4713: }
                   4714: 
1.440     albertel 4715: .LC_icon {
1.771     droeschl 4716:   border: none;
1.790     droeschl 4717:   vertical-align: middle;
1.771     droeschl 4718: }
                   4719: 
1.543     albertel 4720: .LC_docs_spacer {
                   4721:   width: 25px;
                   4722:   height: 1px;
1.771     droeschl 4723:   border: none;
1.543     albertel 4724: }
1.346     albertel 4725: 
1.532     albertel 4726: .LC_internal_info {
1.735     bisitz   4727:   color: #999999;
1.532     albertel 4728: }
                   4729: 
1.794     www      4730: .LC_discussion {
                   4731:    background: $tabbg;
                   4732:    border: 1px solid black;
                   4733:    margin: 2px;
                   4734: }
                   4735: 
                   4736: .LC_disc_action_links_bar {
                   4737:    background: $tabbg;
1.803     bisitz   4738:    border: none;
1.795     www      4739:    margin: 4px;
1.794     www      4740: }
                   4741: 
                   4742: .LC_disc_action_left {
                   4743:    text-align: left;
                   4744: }
                   4745: 
                   4746: .LC_disc_action_right {
                   4747:    text-align: right;
                   4748: }
                   4749: 
                   4750: .LC_disc_new_item {
                   4751:    background: white;
                   4752:    border: 2px solid red;
                   4753:    margin: 2px;
                   4754: }
                   4755: 
                   4756: .LC_disc_old_item {
                   4757:    background: white;
                   4758:    border: 1px solid black;
                   4759:    margin: 2px;
                   4760: }
                   4761: 
1.458     albertel 4762: table.LC_pastsubmission {
                   4763:   border: 1px solid black;
                   4764:   margin: 2px;
                   4765: }
                   4766: 
1.795     www      4767: table#LC_top_nav,
                   4768: table#LC_menubuttons,
                   4769: table#LC_nav_location {
1.345     albertel 4770:   width: 100%;
                   4771:   background: $pgbg;
1.392     albertel 4772:   border: 2px;
1.402     albertel 4773:   border-collapse: separate;
1.803     bisitz   4774:   padding: 0;
1.345     albertel 4775: }
1.392     albertel 4776: 
1.801     tempelho 4777: table#LC_title_bar a {
                   4778:   color: $fontmenu;
                   4779: }
1.836     bisitz   4780: 
1.807     droeschl 4781: table#LC_title_bar {
1.819     tempelho 4782:   clear: both;
1.836     bisitz   4783:   display: none;
1.807     droeschl 4784: }
                   4785: 
1.795     www      4786: table#LC_title_bar,
                   4787: table.LC_breadcrumbs,
1.393     albertel 4788: table#LC_title_bar.LC_with_remote {
1.359     albertel 4789:   width: 100%;
1.392     albertel 4790:   border-color: $pgbg;
                   4791:   border-style: solid;
                   4792:   border-width: $border;
1.379     albertel 4793:   background: $pgbg;
1.801     tempelho 4794:   color: $fontmenu;
1.392     albertel 4795:   border-collapse: collapse;
1.803     bisitz   4796:   padding: 0;
1.819     tempelho 4797:   margin: 0;
1.359     albertel 4798: }
1.795     www      4799: 
1.359     albertel 4800: table#LC_title_bar td {
                   4801:   background: $tabbg;
                   4802: }
1.795     www      4803: 
1.706     harmsja  4804: table#LC_menubuttons img{
1.803     bisitz   4805:   border: none;
1.346     albertel 4806: }
1.795     www      4807: 
1.345     albertel 4808: table#LC_top_nav td {
                   4809:   background: $tabbg;
1.803     bisitz   4810:   border: none;
1.407     albertel 4811:   font-size: small;
1.706     harmsja  4812:   vertical-align:top;
                   4813:   padding:2px 5px 2px 5px;
1.345     albertel 4814: }
1.795     www      4815: 
                   4816: table#LC_top_nav td a,
                   4817: div#LC_top_nav a {
1.345     albertel 4818:   color: $font;
                   4819: }
1.795     www      4820: 
1.364     albertel 4821: table#LC_top_nav td.LC_top_nav_logo {
                   4822:   background: $tabbg;
1.432     albertel 4823:   text-align: left;
1.408     albertel 4824:   white-space: nowrap;
1.432     albertel 4825:   width: 31px;
1.408     albertel 4826: }
1.795     www      4827: 
1.408     albertel 4828: table#LC_top_nav td.LC_top_nav_logo img {
1.803     bisitz   4829:   border: none;
1.408     albertel 4830:   vertical-align: bottom;
1.364     albertel 4831: }
1.795     www      4832: 
1.777     tempelho 4833: table#LC_top_nav td.LC_top_nav_exit,
1.779     bisitz   4834: table#LC_top_nav td.LC_top_nav_help {
1.777     tempelho 4835:   width: 2.0em;
                   4836: }
1.795     www      4837: 
1.442     albertel 4838: table#LC_top_nav td.LC_top_nav_login {
                   4839:   width: 4.0em;
                   4840:   text-align: center;
                   4841: }
1.795     www      4842: 
1.842     droeschl 4843: .LC_breadcrumbs_component {
                   4844:     float: right;
                   4845:     margin: 0 1em;
1.357     albertel 4846: }
1.842     droeschl 4847: .LC_breadcrumbs_component img {
                   4848:     vertical-align: middle;
1.777     tempelho 4849: }
1.795     www      4850: 
1.383     albertel 4851: td.LC_table_cell_checkbox {
                   4852:   text-align: center;
                   4853: }
1.795     www      4854: 
1.779     bisitz   4855: table#LC_mainmenu td.LC_mainmenu_column {
                   4856:     vertical-align: top;
1.777     tempelho 4857: }
1.522     albertel 4858: 
1.795     www      4859: .LC_fontsize_small {
1.705     tempelho 4860:  font-size: 70%;
                   4861: }
                   4862: 
1.844     bisitz   4863: #LC_breadcrumbs {
1.819     tempelho 4864:  clear:both;
                   4865:  background: $sidebg;
1.822     bisitz   4866:  border-bottom: 1px solid $lg_border_color;
1.819     tempelho 4867:  line-height: 32px; 
1.822     bisitz   4868:  margin: 0;
1.819     tempelho 4869:  padding: 0;
                   4870: }
1.839     droeschl 4871: /* Preliminary fix to hide breadcrumbs inside remote control window */
1.844     bisitz   4872: #LC_remote #LC_breadcrumbs {
1.839     droeschl 4873:     display:none;
                   4874: }
1.819     tempelho 4875: 
1.844     bisitz   4876: #LC_head_subbox {
1.822     bisitz   4877:  clear:both;
                   4878:  background: #F8F8F8; /* $sidebg; */
                   4879:  border-bottom: 1px solid $lg_border_color;
                   4880:  margin: 0 0 10px 0;
                   4881:  padding: 5px;
                   4882: }
                   4883: 
1.795     www      4884: .LC_fontsize_medium {
1.705     tempelho 4885:  font-size: 85%;
                   4886: }
                   4887: 
1.795     www      4888: .LC_fontsize_large {
1.705     tempelho 4889:  font-size: 120%;
                   4890: }
                   4891: 
1.346     albertel 4892: .LC_menubuttons_inline_text {
                   4893:   color: $font;
1.698     harmsja  4894:   font-size: 90%;
1.701     harmsja  4895:   padding-left:3px;
1.346     albertel 4896: }
                   4897: 
1.526     www      4898: .LC_menubuttons_link {
                   4899:   text-decoration: none;
                   4900: }
1.795     www      4901: 
1.522     albertel 4902: .LC_menubuttons_category {
1.521     www      4903:   color: $font;
1.526     www      4904:   background: $pgbg;
1.521     www      4905:   font-size: larger;
                   4906:   font-weight: bold;
                   4907: }
                   4908: 
1.346     albertel 4909: td.LC_menubuttons_text {
1.779     bisitz   4910:  	color: $font;
1.346     albertel 4911: }
1.706     harmsja  4912: 
1.346     albertel 4913: .LC_current_location {
                   4914:   background: $tabbg;
                   4915: }
1.795     www      4916: 
1.346     albertel 4917: .LC_new_mail {
1.634     www      4918:   background: $tabbg;
1.346     albertel 4919:   font-weight: bold;
                   4920: }
1.347     albertel 4921: 
1.666     raeburn  4922: .LC_roleslog_note {
1.701     harmsja  4923:   font-size: small;
1.666     raeburn  4924: }
                   4925: 
1.795     www      4926: table.LC_data_table,
                   4927: table.LC_mail_list {
1.347     albertel 4928:   border: 1px solid #000000;
1.402     albertel 4929:   border-collapse: separate;
1.426     albertel 4930:   border-spacing: 1px;
1.610     albertel 4931:   background: $pgbg;
1.347     albertel 4932: }
1.795     www      4933: 
1.422     albertel 4934: .LC_data_table_dense {
                   4935:   font-size: small;
                   4936: }
1.795     www      4937: 
1.507     raeburn  4938: table.LC_nested_outer {
                   4939:   border: 1px solid #000000;
1.589     raeburn  4940:   border-collapse: collapse;
1.803     bisitz   4941:   border-spacing: 0;
1.507     raeburn  4942:   width: 100%;
                   4943: }
1.795     www      4944: 
1.507     raeburn  4945: table.LC_nested {
1.803     bisitz   4946:   border: none;
1.589     raeburn  4947:   border-collapse: collapse;
1.803     bisitz   4948:   border-spacing: 0;
1.507     raeburn  4949:   width: 100%;
                   4950: }
1.795     www      4951: 
                   4952: table.LC_data_table tr th, 
                   4953: table.LC_calendar tr th, 
                   4954: table.LC_mail_list tr th,
1.523     albertel 4955: table.LC_prior_tries tr th {
1.349     albertel 4956:   font-weight: bold;
                   4957:   background-color: $data_table_head;
1.801     tempelho 4958:   color:$fontmenu;
1.701     harmsja  4959:   font-size:90%;
1.347     albertel 4960: }
1.795     www      4961: 
1.711     raeburn  4962: table.LC_data_table tr.LC_info_row > td {
1.735     bisitz   4963:   background-color: #CCCCCC;
1.711     raeburn  4964:   font-weight: bold;
                   4965:   text-align: left;
                   4966: }
1.795     www      4967: 
1.779     bisitz   4968: table.LC_data_table tr.LC_odd_row > td,
1.809     bisitz   4969: table.LC_pick_box tr > td.LC_odd_row {
1.349     albertel 4970:   background-color: $data_table_light;
1.425     albertel 4971:   padding: 2px;
1.347     albertel 4972: }
1.795     www      4973: 
1.610     albertel 4974: table.LC_data_table tr.LC_even_row > td,
1.809     bisitz   4975: table.LC_pick_box tr > td.LC_even_row {
1.349     albertel 4976:   background-color: $data_table_dark;
1.709     bisitz   4977:   padding: 2px;
1.347     albertel 4978: }
1.795     www      4979: 
1.425     albertel 4980: table.LC_data_table tr.LC_data_table_highlight td {
                   4981:   background-color: $data_table_darker;
                   4982: }
1.795     www      4983: 
1.639     raeburn  4984: table.LC_data_table tr td.LC_leftcol_header {
                   4985:   background-color: $data_table_head;
                   4986:   font-weight: bold;
                   4987: }
1.795     www      4988: 
1.451     albertel 4989: table.LC_data_table tr.LC_empty_row td,
1.507     raeburn  4990: table.LC_nested tr.LC_empty_row td {
1.347     albertel 4991:   background-color: #FFFFFF;
1.421     albertel 4992:   font-weight: bold;
                   4993:   font-style: italic;
                   4994:   text-align: center;
                   4995:   padding: 8px;
1.347     albertel 4996: }
1.795     www      4997: 
1.507     raeburn  4998: table.LC_nested tr.LC_empty_row td {
1.465     albertel 4999:   padding: 4ex
                   5000: }
1.795     www      5001: 
1.507     raeburn  5002: table.LC_nested_outer tr th {
                   5003:   font-weight: bold;
1.801     tempelho 5004:   color:$fontmenu;
1.507     raeburn  5005:   background-color: $data_table_head;
1.701     harmsja  5006:   font-size: small;
1.507     raeburn  5007:   border-bottom: 1px solid #000000;
                   5008: }
1.795     www      5009: 
1.507     raeburn  5010: table.LC_nested_outer tr td.LC_subheader {
                   5011:   background-color: $data_table_head;
                   5012:   font-weight: bold;
                   5013:   font-size: small;
                   5014:   border-bottom: 1px solid #000000;
                   5015:   text-align: right;
1.451     albertel 5016: }
1.795     www      5017: 
1.507     raeburn  5018: table.LC_nested tr.LC_info_row td {
1.735     bisitz   5019:   background-color: #CCCCCC;
1.451     albertel 5020:   font-weight: bold;
                   5021:   font-size: small;
1.507     raeburn  5022:   text-align: center;
                   5023: }
1.795     www      5024: 
1.589     raeburn  5025: table.LC_nested tr.LC_info_row td.LC_left_item,
                   5026: table.LC_nested_outer tr th.LC_left_item {
1.507     raeburn  5027:   text-align: left;
1.451     albertel 5028: }
1.795     www      5029: 
1.507     raeburn  5030: table.LC_nested td {
1.735     bisitz   5031:   background-color: #FFFFFF;
1.451     albertel 5032:   font-size: small;
1.507     raeburn  5033: }
1.795     www      5034: 
1.507     raeburn  5035: table.LC_nested_outer tr th.LC_right_item,
                   5036: table.LC_nested tr.LC_info_row td.LC_right_item,
                   5037: table.LC_nested tr.LC_odd_row td.LC_right_item,
                   5038: table.LC_nested tr td.LC_right_item {
1.451     albertel 5039:   text-align: right;
                   5040: }
                   5041: 
1.507     raeburn  5042: table.LC_nested tr.LC_odd_row td {
1.735     bisitz   5043:   background-color: #EEEEEE;
1.451     albertel 5044: }
                   5045: 
1.473     raeburn  5046: table.LC_createuser {
                   5047: }
                   5048: 
                   5049: table.LC_createuser tr.LC_section_row td {
1.701     harmsja  5050:   font-size: small;
1.473     raeburn  5051: }
                   5052: 
                   5053: table.LC_createuser tr.LC_info_row td  {
1.735     bisitz   5054:   background-color: #CCCCCC;
1.473     raeburn  5055:   font-weight: bold;
                   5056:   text-align: center;
                   5057: }
                   5058: 
1.349     albertel 5059: table.LC_calendar {
                   5060:   border: 1px solid #000000;
                   5061:   border-collapse: collapse;
                   5062: }
1.795     www      5063: 
1.349     albertel 5064: table.LC_calendar_pickdate {
                   5065:   font-size: xx-small;
                   5066: }
1.795     www      5067: 
1.349     albertel 5068: table.LC_calendar tr td {
                   5069:   border: 1px solid #000000;
                   5070:   vertical-align: top;
                   5071: }
1.795     www      5072: 
1.349     albertel 5073: table.LC_calendar tr td.LC_calendar_day_empty {
                   5074:   background-color: $data_table_dark;
                   5075: }
1.795     www      5076: 
1.779     bisitz   5077: table.LC_calendar tr td.LC_calendar_day_current {
                   5078:   background-color: $data_table_highlight;
1.777     tempelho 5079: }
1.795     www      5080: 
1.349     albertel 5081: table.LC_mail_list tr.LC_mail_new {
                   5082:   background-color: $mail_new;
                   5083: }
1.795     www      5084: 
1.349     albertel 5085: table.LC_mail_list tr.LC_mail_new:hover {
                   5086:   background-color: $mail_new_hover;
                   5087: }
1.795     www      5088: 
                   5089: table.LC_mail_list tr.LC_mail_even {
1.777     tempelho 5090: }
1.795     www      5091: 
                   5092: table.LC_mail_list tr.LC_mail_odd {
1.777     tempelho 5093: }
1.795     www      5094: 
1.349     albertel 5095: table.LC_mail_list tr.LC_mail_read {
                   5096:   background-color: $mail_read;
                   5097: }
1.795     www      5098: 
1.349     albertel 5099: table.LC_mail_list tr.LC_mail_read:hover {
                   5100:   background-color: $mail_read_hover;
                   5101: }
1.795     www      5102: 
1.349     albertel 5103: table.LC_mail_list tr.LC_mail_replied {
                   5104:   background-color: $mail_replied;
                   5105: }
1.795     www      5106: 
1.349     albertel 5107: table.LC_mail_list tr.LC_mail_replied:hover {
                   5108:   background-color: $mail_replied_hover;
                   5109: }
1.795     www      5110: 
1.349     albertel 5111: table.LC_mail_list tr.LC_mail_other {
                   5112:   background-color: $mail_other;
                   5113: }
1.795     www      5114: 
1.349     albertel 5115: table.LC_mail_list tr.LC_mail_other:hover {
                   5116:   background-color: $mail_other_hover;
                   5117: }
1.494     raeburn  5118: 
1.777     tempelho 5119: table.LC_data_table tr > td.LC_browser_file,
                   5120: table.LC_data_table tr > td.LC_browser_file_published {
1.389     albertel 5121:   background: #CCFF88;
                   5122: }
1.795     www      5123: 
1.777     tempelho 5124: table.LC_data_table tr > td.LC_browser_file_locked,
                   5125: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389     albertel 5126:   background: #FFAA99;
1.387     albertel 5127: }
1.795     www      5128: 
1.777     tempelho 5129: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.779     bisitz   5130:   background: #AAAAAA;
                   5131: }
1.795     www      5132: 
1.777     tempelho 5133: table.LC_data_table tr > td.LC_browser_file_modified,
1.779     bisitz   5134: table.LC_data_table tr > td.LC_browser_file_metamodified {
                   5135:   background: #FFFF77;
1.777     tempelho 5136: }
1.795     www      5137: 
1.696     bisitz   5138: table.LC_data_table tr.LC_browser_folder > td {
1.389     albertel 5139:   background: #CCCCFF;
1.387     albertel 5140: }
1.696     bisitz   5141: 
1.707     bisitz   5142: table.LC_data_table tr > td.LC_roles_is {
                   5143: /*  background: #77FF77; */
                   5144: }
1.795     www      5145: 
1.707     bisitz   5146: table.LC_data_table tr > td.LC_roles_future {
                   5147:   background: #FFFF77;
                   5148: }
1.795     www      5149: 
1.707     bisitz   5150: table.LC_data_table tr > td.LC_roles_will {
                   5151:   background: #FFAA77;
                   5152: }
1.795     www      5153: 
1.707     bisitz   5154: table.LC_data_table tr > td.LC_roles_expired {
                   5155:   background: #FF7777;
                   5156: }
1.795     www      5157: 
1.707     bisitz   5158: table.LC_data_table tr > td.LC_roles_will_not {
                   5159:   background: #AAFF77;
                   5160: }
1.795     www      5161: 
1.707     bisitz   5162: table.LC_data_table tr > td.LC_roles_selected {
                   5163:   background: #11CC55;
                   5164: }
                   5165: 
1.388     albertel 5166: span.LC_current_location {
1.701     harmsja  5167:   font-size:larger;
1.388     albertel 5168:   background: $pgbg;
                   5169: }
1.387     albertel 5170: 
1.395     albertel 5171: span.LC_parm_menu_item {
                   5172:   font-size: larger;
                   5173: }
1.795     www      5174: 
1.395     albertel 5175: span.LC_parm_scope_all {
                   5176:   color: red;
                   5177: }
1.795     www      5178: 
1.395     albertel 5179: span.LC_parm_scope_folder {
                   5180:   color: green;
                   5181: }
1.795     www      5182: 
1.395     albertel 5183: span.LC_parm_scope_resource {
                   5184:   color: orange;
                   5185: }
1.795     www      5186: 
1.395     albertel 5187: span.LC_parm_part {
                   5188:   color: blue;
                   5189: }
1.795     www      5190: 
1.395     albertel 5191: span.LC_parm_folder, span.LC_parm_symb {
                   5192:   font-size: x-small;
                   5193:   font-family: $mono;
                   5194:   color: #AAAAAA;
                   5195: }
                   5196: 
1.795     www      5197: td.LC_parm_overview_level_menu,
                   5198: td.LC_parm_overview_map_menu,
                   5199: td.LC_parm_overview_parm_selectors,
                   5200: td.LC_parm_overview_restrictions  {
1.396     albertel 5201:   border: 1px solid black;
                   5202:   border-collapse: collapse;
                   5203: }
1.795     www      5204: 
1.396     albertel 5205: table.LC_parm_overview_restrictions td {
                   5206:   border-width: 1px 4px 1px 4px;
                   5207:   border-style: solid;
                   5208:   border-color: $pgbg;
                   5209:   text-align: center;
                   5210: }
1.795     www      5211: 
1.396     albertel 5212: table.LC_parm_overview_restrictions th {
                   5213:   background: $tabbg;
                   5214:   border-width: 1px 4px 1px 4px;
                   5215:   border-style: solid;
                   5216:   border-color: $pgbg;
                   5217: }
1.795     www      5218: 
1.398     albertel 5219: table#LC_helpmenu {
1.803     bisitz   5220:   border: none;
1.398     albertel 5221:   height: 55px;
1.803     bisitz   5222:   border-spacing: 0;
1.398     albertel 5223: }
                   5224: 
                   5225: table#LC_helpmenu fieldset legend {
                   5226:   font-size: larger;
                   5227: }
1.795     www      5228: 
1.397     albertel 5229: table#LC_helpmenu_links {
                   5230:   width: 100%;
                   5231:   border: 1px solid black;
                   5232:   background: $pgbg;
1.803     bisitz   5233:   padding: 0;
1.397     albertel 5234:   border-spacing: 1px;
                   5235: }
1.795     www      5236: 
1.397     albertel 5237: table#LC_helpmenu_links tr td {
                   5238:   padding: 1px;
                   5239:   background: $tabbg;
1.399     albertel 5240:   text-align: center;
                   5241:   font-weight: bold;
1.397     albertel 5242: }
1.396     albertel 5243: 
1.795     www      5244: table#LC_helpmenu_links a:link,
                   5245: table#LC_helpmenu_links a:visited,
1.397     albertel 5246: table#LC_helpmenu_links a:active {
                   5247:   text-decoration: none;
                   5248:   color: $font;
                   5249: }
1.795     www      5250: 
1.397     albertel 5251: table#LC_helpmenu_links a:hover {
                   5252:   text-decoration: underline;
                   5253:   color: $vlink;
                   5254: }
1.396     albertel 5255: 
1.417     albertel 5256: .LC_chrt_popup_exists {
                   5257:   border: 1px solid #339933;
                   5258:   margin: -1px;
                   5259: }
1.795     www      5260: 
1.417     albertel 5261: .LC_chrt_popup_up {
                   5262:   border: 1px solid yellow;
                   5263:   margin: -1px;
                   5264: }
1.795     www      5265: 
1.417     albertel 5266: .LC_chrt_popup {
                   5267:   border: 1px solid #8888FF;
                   5268:   background: #CCCCFF;
                   5269: }
1.795     www      5270: 
1.421     albertel 5271: table.LC_pick_box {
                   5272:   border-collapse: separate;
                   5273:   background: white;
                   5274:   border: 1px solid black;
                   5275:   border-spacing: 1px;
                   5276: }
1.795     www      5277: 
1.421     albertel 5278: table.LC_pick_box td.LC_pick_box_title {
1.850     bisitz   5279:   background: $sidebg;
1.421     albertel 5280:   font-weight: bold;
                   5281:   text-align: right;
1.740     bisitz   5282:   vertical-align: top;
1.421     albertel 5283:   width: 184px;
                   5284:   padding: 8px;
                   5285: }
1.795     www      5286: 
1.645     raeburn  5287: table.LC_pick_box td.LC_selfenroll_pick_box_title {
                   5288:   background: $tabbg;
                   5289:   font-weight: bold;
                   5290:   text-align: right;
                   5291:   width: 350px;
                   5292:   padding: 8px;
                   5293: }
                   5294: 
1.579     raeburn  5295: table.LC_pick_box td.LC_pick_box_value {
                   5296:   text-align: left;
                   5297:   padding: 8px;
                   5298: }
1.795     www      5299: 
1.579     raeburn  5300: table.LC_pick_box td.LC_pick_box_select {
                   5301:   text-align: left;
                   5302:   padding: 8px;
                   5303: }
1.795     www      5304: 
1.424     albertel 5305: table.LC_pick_box td.LC_pick_box_separator {
1.803     bisitz   5306:   padding: 0;
1.421     albertel 5307:   height: 1px;
                   5308:   background: black;
                   5309: }
1.795     www      5310: 
1.421     albertel 5311: table.LC_pick_box td.LC_pick_box_submit {
                   5312:   text-align: right;
                   5313: }
1.795     www      5314: 
1.579     raeburn  5315: table.LC_pick_box td.LC_evenrow_value {
                   5316:   text-align: left;
                   5317:   padding: 8px;
                   5318:   background-color: $data_table_light;
                   5319: }
1.795     www      5320: 
1.579     raeburn  5321: table.LC_pick_box td.LC_oddrow_value {
                   5322:   text-align: left;
                   5323:   padding: 8px;
                   5324:   background-color: $data_table_light;
                   5325: }
1.795     www      5326: 
1.579     raeburn  5327: table.LC_helpform_receipt {
                   5328:   width: 620px;
                   5329:   border-collapse: separate;
                   5330:   background: white;
                   5331:   border: 1px solid black;
                   5332:   border-spacing: 1px;
                   5333: }
1.795     www      5334: 
1.579     raeburn  5335: table.LC_helpform_receipt td.LC_pick_box_title {
                   5336:   background: $tabbg;
                   5337:   font-weight: bold;
                   5338:   text-align: right;
                   5339:   width: 184px;
                   5340:   padding: 8px;
                   5341: }
1.795     www      5342: 
1.579     raeburn  5343: table.LC_helpform_receipt td.LC_evenrow_value {
                   5344:   text-align: left;
                   5345:   padding: 8px;
                   5346:   background-color: $data_table_light;
                   5347: }
1.795     www      5348: 
1.579     raeburn  5349: table.LC_helpform_receipt td.LC_oddrow_value {
                   5350:   text-align: left;
                   5351:   padding: 8px;
                   5352:   background-color: $data_table_light;
                   5353: }
1.795     www      5354: 
1.579     raeburn  5355: table.LC_helpform_receipt td.LC_pick_box_separator {
1.803     bisitz   5356:   padding: 0;
1.579     raeburn  5357:   height: 1px;
                   5358:   background: black;
                   5359: }
1.795     www      5360: 
1.579     raeburn  5361: span.LC_helpform_receipt_cat {
                   5362:   font-weight: bold;
                   5363: }
1.795     www      5364: 
1.424     albertel 5365: table.LC_group_priv_box {
                   5366:   background: white;
                   5367:   border: 1px solid black;
                   5368:   border-spacing: 1px;
                   5369: }
1.795     www      5370: 
1.424     albertel 5371: table.LC_group_priv_box td.LC_pick_box_title {
                   5372:   background: $tabbg;
                   5373:   font-weight: bold;
                   5374:   text-align: right;
                   5375:   width: 184px;
                   5376: }
1.795     www      5377: 
1.424     albertel 5378: table.LC_group_priv_box td.LC_groups_fixed {
                   5379:   background: $data_table_light;
                   5380:   text-align: center;
                   5381: }
1.795     www      5382: 
1.424     albertel 5383: table.LC_group_priv_box td.LC_groups_optional {
                   5384:   background: $data_table_dark;
                   5385:   text-align: center;
                   5386: }
1.795     www      5387: 
1.424     albertel 5388: table.LC_group_priv_box td.LC_groups_functionality {
                   5389:   background: $data_table_darker;
                   5390:   text-align: center;
                   5391:   font-weight: bold;
                   5392: }
1.795     www      5393: 
1.424     albertel 5394: table.LC_group_priv td {
                   5395:   text-align: left;
1.803     bisitz   5396:   padding: 0;
1.424     albertel 5397: }
                   5398: 
1.421     albertel 5399: table.LC_notify_front_page {
                   5400:   background: white;
                   5401:   border: 1px solid black;
                   5402:   padding: 8px;
                   5403: }
1.795     www      5404: 
1.421     albertel 5405: table.LC_notify_front_page td {
                   5406:   padding: 8px;
                   5407: }
1.795     www      5408: 
1.424     albertel 5409: .LC_navbuttons {
                   5410:   margin: 2ex 0ex 2ex 0ex;
                   5411: }
1.795     www      5412: 
1.423     albertel 5413: .LC_topic_bar {
                   5414:   font-weight: bold;
                   5415:   width: 100%;
                   5416:   background: $tabbg;
                   5417:   vertical-align: middle;
                   5418:   margin: 2ex 0ex 2ex 0ex;
1.805     bisitz   5419:   padding: 3px;
1.423     albertel 5420: }
1.795     www      5421: 
1.423     albertel 5422: .LC_topic_bar span {
                   5423:   vertical-align: middle;
                   5424: }
1.795     www      5425: 
1.423     albertel 5426: .LC_topic_bar img {
                   5427:   vertical-align: bottom;
                   5428: }
1.795     www      5429: 
1.423     albertel 5430: table.LC_course_group_status {
                   5431:   margin: 20px;
                   5432: }
1.795     www      5433: 
1.423     albertel 5434: table.LC_status_selector td {
                   5435:   vertical-align: top;
                   5436:   text-align: center;
1.424     albertel 5437:   padding: 4px;
                   5438: }
1.795     www      5439: 
1.599     albertel 5440: div.LC_feedback_link {
1.616     albertel 5441:   clear: both;
1.829     kalberla 5442:   background: $sidebg;
1.779     bisitz   5443:   width: 100%;
1.829     kalberla 5444:   padding-bottom: 10px;
                   5445:   border: 1px $tabbg solid;
1.833     kalberla 5446:   height: 22px;
                   5447:   line-height: 22px;
                   5448:   padding-top: 5px;
                   5449: }
                   5450: 
                   5451: div.LC_feedback_link img {
                   5452:   height: 22px;
1.829     kalberla 5453: }
                   5454: 
                   5455: div.LC_feedback_link a{
                   5456:   text-decoration: none;
1.489     raeburn  5457: }
1.795     www      5458: 
1.489     raeburn  5459: span.LC_feedback_link {
1.829     kalberla 5460:   //background: $feedback_link_bg;
1.599     albertel 5461:   font-size: larger;
                   5462: }
1.795     www      5463: 
1.599     albertel 5464: span.LC_message_link {
1.829     kalberla 5465:   //background: $feedback_link_bg;
1.599     albertel 5466:   font-size: larger;
                   5467:   position: absolute;
                   5468:   right: 1em;
1.489     raeburn  5469: }
1.421     albertel 5470: 
1.515     albertel 5471: table.LC_prior_tries {
1.524     albertel 5472:   border: 1px solid #000000;
                   5473:   border-collapse: separate;
                   5474:   border-spacing: 1px;
1.515     albertel 5475: }
1.523     albertel 5476: 
1.515     albertel 5477: table.LC_prior_tries td {
1.524     albertel 5478:   padding: 2px;
1.515     albertel 5479: }
1.523     albertel 5480: 
                   5481: .LC_answer_correct {
1.795     www      5482:   background: lightgreen;
                   5483:   color: darkgreen;
                   5484:   padding: 6px;
1.523     albertel 5485: }
1.795     www      5486: 
1.523     albertel 5487: .LC_answer_charged_try {
1.797     www      5488:   background: #FFAAAA;
1.795     www      5489:   color: darkred;
                   5490:   padding: 6px;
1.523     albertel 5491: }
1.795     www      5492: 
1.779     bisitz   5493: .LC_answer_not_charged_try,
1.523     albertel 5494: .LC_answer_no_grade,
                   5495: .LC_answer_late {
1.795     www      5496:   background: lightyellow;
1.523     albertel 5497:   color: black;
1.795     www      5498:   padding: 6px;
1.523     albertel 5499: }
1.795     www      5500: 
1.523     albertel 5501: .LC_answer_previous {
1.795     www      5502:   background: lightblue;
                   5503:   color: darkblue;
                   5504:   padding: 6px;
1.523     albertel 5505: }
1.795     www      5506: 
1.779     bisitz   5507: .LC_answer_no_message {
1.777     tempelho 5508:   background: #FFFFFF;
                   5509:   color: black;
1.795     www      5510:   padding: 6px;
1.779     bisitz   5511: }
1.795     www      5512: 
1.779     bisitz   5513: .LC_answer_unknown {
                   5514:   background: orange;
                   5515:   color: black;
1.795     www      5516:   padding: 6px;
1.777     tempelho 5517: }
1.795     www      5518: 
1.529     albertel 5519: span.LC_prior_numerical,
                   5520: span.LC_prior_string,
                   5521: span.LC_prior_custom,
                   5522: span.LC_prior_reaction,
                   5523: span.LC_prior_math {
1.523     albertel 5524:   font-family: monospace;
                   5525:   white-space: pre;
                   5526: }
                   5527: 
1.525     albertel 5528: span.LC_prior_string {
                   5529:   font-family: monospace;
                   5530:   white-space: pre;
                   5531: }
                   5532: 
1.523     albertel 5533: table.LC_prior_option {
                   5534:   width: 100%;
                   5535:   border-collapse: collapse;
                   5536: }
1.795     www      5537: 
                   5538: table.LC_prior_rank, 
                   5539: table.LC_prior_match {
1.528     albertel 5540:   border-collapse: collapse;
                   5541: }
1.795     www      5542: 
1.528     albertel 5543: table.LC_prior_option tr td,
                   5544: table.LC_prior_rank tr td,
                   5545: table.LC_prior_match tr td {
1.524     albertel 5546:   border: 1px solid #000000;
1.515     albertel 5547: }
                   5548: 
1.855     bisitz   5549: .LC_nobreak {
1.544     albertel 5550:   white-space: nowrap;
1.519     raeburn  5551: }
                   5552: 
1.576     raeburn  5553: span.LC_cusr_emph {
                   5554:   font-style: italic;
                   5555: }
                   5556: 
1.633     raeburn  5557: span.LC_cusr_subheading {
                   5558:   font-weight: normal;
                   5559:   font-size: 85%;
                   5560: }
                   5561: 
1.545     albertel 5562: table.LC_docs_documents {
                   5563:   background: #BBBBBB;
1.803     bisitz   5564:   border-width: 0;
1.545     albertel 5565:   border-collapse: collapse;
                   5566: }
1.795     www      5567: 
1.777     tempelho 5568: table.LC_docs_documents td.LC_docs_document {
1.779     bisitz   5569:   border: 2px solid black;
                   5570:   padding: 4px;
1.777     tempelho 5571: }
1.795     www      5572: 
1.545     albertel 5573: .LC_docs_entry_move {
1.803     bisitz   5574:   border: none;
1.545     albertel 5575:   border-collapse: collapse;
1.544     albertel 5576: }
                   5577: 
1.545     albertel 5578: .LC_docs_entry_move td {
                   5579:   border: 2px solid #BBBBBB;
                   5580:   background: #DDDDDD;
                   5581: }
                   5582: 
                   5583: .LC_docs_editor td.LC_docs_entry_commands {
                   5584:   background: #DDDDDD;
                   5585:   font-size: x-small;
                   5586: }
1.795     www      5587: 
1.544     albertel 5588: .LC_docs_copy {
1.545     albertel 5589:   color: #000099;
1.544     albertel 5590: }
1.795     www      5591: 
1.544     albertel 5592: .LC_docs_cut {
1.545     albertel 5593:   color: #550044;
1.544     albertel 5594: }
1.795     www      5595: 
1.544     albertel 5596: .LC_docs_rename {
1.545     albertel 5597:   color: #009900;
1.544     albertel 5598: }
1.795     www      5599: 
1.544     albertel 5600: .LC_docs_remove {
1.545     albertel 5601:   color: #990000;
                   5602: }
                   5603: 
1.547     albertel 5604: .LC_docs_reinit_warn,
                   5605: .LC_docs_ext_edit {
                   5606:   font-size: x-small;
                   5607: }
                   5608: 
1.545     albertel 5609: .LC_docs_editor td.LC_docs_entry_title,
                   5610: .LC_docs_editor td.LC_docs_entry_icon {
                   5611:   background: #FFFFBB;
                   5612: }
1.795     www      5613: 
1.545     albertel 5614: .LC_docs_editor td.LC_docs_entry_parameter {
                   5615:   background: #BBBBFF;
                   5616:   font-size: x-small;
                   5617:   white-space: nowrap;
                   5618: }
                   5619: 
                   5620: table.LC_docs_adddocs td,
                   5621: table.LC_docs_adddocs th {
                   5622:   border: 1px solid #BBBBBB;
                   5623:   padding: 4px;
                   5624:   background: #DDDDDD;
1.543     albertel 5625: }
                   5626: 
1.584     albertel 5627: table.LC_sty_begin {
                   5628:   background: #BBFFBB;
                   5629: }
1.795     www      5630: 
1.584     albertel 5631: table.LC_sty_end {
                   5632:   background: #FFBBBB;
                   5633: }
                   5634: 
1.589     raeburn  5635: table.LC_double_column {
1.803     bisitz   5636:   border-width: 0;
1.589     raeburn  5637:   border-collapse: collapse;
                   5638:   width: 100%;
                   5639:   padding: 2px;
                   5640: }
                   5641: 
                   5642: table.LC_double_column tr td.LC_left_col {
1.590     raeburn  5643:   top: 2px;
1.589     raeburn  5644:   left: 2px;
                   5645:   width: 47%;
                   5646:   vertical-align: top;
                   5647: }
                   5648: 
                   5649: table.LC_double_column tr td.LC_right_col {
                   5650:   top: 2px;
1.779     bisitz   5651:   right: 2px;
1.589     raeburn  5652:   width: 47%;
                   5653:   vertical-align: top;
                   5654: }
                   5655: 
1.594     raeburn  5656: span.LC_role_level {
                   5657:   font-weight: bold;
                   5658: }
                   5659: 
1.591     raeburn  5660: div.LC_left_float {
                   5661:   float: left;
                   5662:   padding-right: 5%;
1.597     albertel 5663:   padding-bottom: 4px;
1.591     raeburn  5664: }
                   5665: 
                   5666: div.LC_clear_float_header {
1.597     albertel 5667:   padding-bottom: 2px;
1.591     raeburn  5668: }
                   5669: 
                   5670: div.LC_clear_float_footer {
1.597     albertel 5671:   padding-top: 10px;
1.591     raeburn  5672:   clear: both;
                   5673: }
                   5674: 
1.597     albertel 5675: div.LC_grade_show_user {
                   5676:   margin-top: 20px;
                   5677:   border: 1px solid black;
                   5678: }
1.795     www      5679: 
1.597     albertel 5680: div.LC_grade_user_name {
                   5681:   background: #DDDDEE;
                   5682:   border-bottom: 1px solid black;
1.705     tempelho 5683:   font-weight: bold;
                   5684:   font-size: large;
1.597     albertel 5685: }
1.795     www      5686: 
1.597     albertel 5687: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
                   5688:   background: #DDEEDD;
                   5689: }
                   5690: 
                   5691: div.LC_grade_show_problem,
                   5692: div.LC_grade_submissions,
                   5693: div.LC_grade_message_center,
                   5694: div.LC_grade_info_links,
                   5695: div.LC_grade_assign {
                   5696:   margin: 5px;
                   5697:   width: 99%;
                   5698:   background: #FFFFFF;
                   5699: }
1.795     www      5700: 
1.597     albertel 5701: div.LC_grade_show_problem_header,
                   5702: div.LC_grade_submissions_header,
                   5703: div.LC_grade_message_center_header,
                   5704: div.LC_grade_assign_header {
1.705     tempelho 5705:   font-weight: bold;
                   5706:   font-size: large;
1.597     albertel 5707: }
1.795     www      5708: 
1.597     albertel 5709: div.LC_grade_show_problem_problem,
                   5710: div.LC_grade_submissions_body,
                   5711: div.LC_grade_message_center_body,
                   5712: div.LC_grade_assign_body {
                   5713:   border: 1px solid black;
                   5714:   width: 99%;
                   5715:   background: #FFFFFF;
                   5716: }
1.795     www      5717: 
1.598     albertel 5718: span.LC_grade_check_note {
1.705     tempelho 5719:   font-weight: normal;
                   5720:   font-size: medium;
1.598     albertel 5721:   display: inline;
                   5722:   position: absolute;
                   5723:   right: 1em;
                   5724: }
1.597     albertel 5725: 
1.613     albertel 5726: table.LC_scantron_action {
                   5727:   width: 100%;
                   5728: }
1.795     www      5729: 
1.613     albertel 5730: table.LC_scantron_action tr th {
1.698     harmsja  5731:   font-weight:bold;
                   5732:   font-style:normal;
1.613     albertel 5733: }
1.795     www      5734: 
1.779     bisitz   5735: .LC_edit_problem_header,
1.614     albertel 5736: div.LC_edit_problem_footer {
1.705     tempelho 5737:   font-weight: normal;
                   5738:   font-size:  medium;
1.602     albertel 5739:   margin: 2px;
1.600     albertel 5740: }
1.795     www      5741: 
1.600     albertel 5742: div.LC_edit_problem_header,
1.602     albertel 5743: div.LC_edit_problem_header div,
1.614     albertel 5744: div.LC_edit_problem_footer,
                   5745: div.LC_edit_problem_footer div,
1.602     albertel 5746: div.LC_edit_problem_editxml_header,
                   5747: div.LC_edit_problem_editxml_header div {
1.600     albertel 5748:   margin-top: 5px;
                   5749: }
1.795     www      5750: 
1.600     albertel 5751: div.LC_edit_problem_header_title {
1.705     tempelho 5752:   font-weight: bold;
                   5753:   font-size: larger;
1.602     albertel 5754:   background: $tabbg;
                   5755:   padding: 3px;
                   5756: }
1.795     www      5757: 
1.602     albertel 5758: table.LC_edit_problem_header_title {
1.705     tempelho 5759:   font-size: larger;
                   5760:   font-weight:  bold;
1.602     albertel 5761:   width: 100%;
                   5762:   border-color: $pgbg;
                   5763:   border-style: solid;
                   5764:   border-width: $border;
1.600     albertel 5765:   background: $tabbg;
1.602     albertel 5766:   border-collapse: collapse;
1.803     bisitz   5767:   padding: 0;
1.602     albertel 5768: }
                   5769: 
                   5770: div.LC_edit_problem_discards {
                   5771:   float: left;
                   5772:   padding-bottom: 5px;
                   5773: }
1.795     www      5774: 
1.602     albertel 5775: div.LC_edit_problem_saves {
                   5776:   float: right;
                   5777:   padding-bottom: 5px;
1.600     albertel 5778: }
1.795     www      5779: 
1.679     riegler  5780: img.stift{
1.803     bisitz   5781:   border-width: 0;
                   5782:   vertical-align: middle;
1.677     riegler  5783: }
1.680     riegler  5784: 
1.681     riegler  5785: table#LC_mainmenu{
                   5786:  margin-top:10px;
                   5787:  width:80%;
                   5788: }
                   5789: 
1.680     riegler  5790: table#LC_mainmenu td.LC_mainmenu_col_fieldset{
                   5791:   vertical-align: top;
                   5792:   width: 45%;
                   5793: }
1.795     www      5794: 
1.779     bisitz   5795: .LC_mainmenu_fieldset_category {
                   5796:   color: $font;
                   5797:   background: $pgbg;
                   5798:   font-size: small;
                   5799:   font-weight: bold;
1.777     tempelho 5800: }
1.795     www      5801: 
1.716     raeburn  5802: div.LC_createcourse {
                   5803:     margin: 10px 10px 10px 10px;
                   5804: }
                   5805: 
1.693     droeschl 5806: /* ---- Remove when done ----
                   5807: # The following styles is part of the redesign of LON-CAPA and are
                   5808: # subject to change during this project.
                   5809: # Don't rely on their current functionality as they might be 
                   5810: # changed or removed.
                   5811: # --------------------------*/
                   5812: 
1.698     harmsja  5813: a:hover,
1.721     harmsja  5814: ol.LC_smallMenu a:hover,
                   5815: ol#LC_MenuBreadcrumbs a:hover,
                   5816: ol#LC_PathBreadcrumbs a:hover,
                   5817: ul#LC_TabMainMenuContent a:hover,
                   5818: .LC_FormSectionClearButton input:hover
1.795     www      5819: ul.LC_TabContent   li:hover a {
1.698     harmsja  5820: 	color:#BF2317;
                   5821:         text-decoration:none;
1.693     droeschl 5822: }
                   5823: 
1.779     bisitz   5824: h1 {
1.813     bisitz   5825: 	padding: 0;
1.693     droeschl 5826: 	line-height:130%;
                   5827: }
1.698     harmsja  5828: 
1.795     www      5829: h2,h3,h4,h5,h6 {
1.803     bisitz   5830: 	margin: 5px 0 5px 0;
                   5831: 	padding: 0;
1.721     harmsja  5832: 	line-height:130%;
1.693     droeschl 5833: }
1.795     www      5834: 
                   5835: .LC_hcell {
1.698     harmsja  5836:         padding:3px 15px 3px 15px;
1.803     bisitz   5837:         margin: 0;
1.703     harmsja  5838: 	background-color:$tabbg;
1.801     tempelho 5839: 	color:$fontmenu;
1.779     bisitz   5840: 	border-bottom:solid 1px $lg_border_color;
1.693     droeschl 5841: }
1.795     www      5842: 
1.840     bisitz   5843: .LC_Box > .LC_hcell {
1.847     tempelho 5844:     margin: 0 -10px 10px -10px;
1.835     bisitz   5845: }
                   5846: 
1.721     harmsja  5847: .LC_noBorder {
1.803     bisitz   5848:         border: 0;
1.698     harmsja  5849: }
1.693     droeschl 5850: 
1.761     tempelho 5851: .LC_Right {
                   5852:         float: right;
1.803     bisitz   5853:         margin: 0;
                   5854:         padding: 0;
1.761     tempelho 5855: }
                   5856: 
1.721     harmsja  5857: .LC_FormSectionClearButton input {
1.779     bisitz   5858:         background-color:transparent;
1.803     bisitz   5859:         border: none;
1.698     harmsja  5860:         cursor:pointer;
                   5861:         text-decoration:underline;
1.693     droeschl 5862: }
1.763     bisitz   5863: 
                   5864: .LC_help_open_topic {
                   5865:         color: #FFFFFF;
                   5866:         background-color: #EEEEFF;
                   5867:         margin: 1px;
                   5868:         padding: 4px;
                   5869:         border: 1px solid #000033;
                   5870:         white-space: nowrap;
1.783     amueller 5871: /*		vertical-align: middle; */
1.759     neumanie 5872: }
1.693     droeschl 5873: 
1.698     harmsja  5874: dl,ul,div,fieldset {
1.803     bisitz   5875: 	margin: 10px 10px 10px 0;
1.806     bisitz   5876: /*	overflow: hidden; */
1.693     droeschl 5877: }
1.795     www      5878: 
1.838     bisitz   5879: fieldset > legend {
                   5880:     font-weight: bold;
                   5881:     padding: 0 5px 0 5px;
                   5882: }
                   5883: 
1.813     bisitz   5884: #LC_nav_bar {
1.807     droeschl 5885:     float: left;
1.852     droeschl 5886:     margin: 0.2em 0 0 0;
1.807     droeschl 5887: }
                   5888: 
1.813     bisitz   5889: #LC_nav_bar em{
1.807     droeschl 5890:     font-weight: bold;
                   5891:     font-style: normal;
                   5892: }
                   5893: 
                   5894: ol.LC_smallMenu {
                   5895:     float: right;
1.852     droeschl 5896:     margin: 0.2em 0 0 0;
1.807     droeschl 5897: }
                   5898: 
1.852     droeschl 5899: ol#LC_PathBreadcrumbs {
1.803     bisitz   5900: 	margin: 0;
1.693     droeschl 5901: }
                   5902: 
1.721     harmsja  5903: ol.LC_smallMenu li {
1.693     droeschl 5904: 	display: inline;
1.803     bisitz   5905: 	padding: 5px 5px 0 10px;
1.693     droeschl 5906: 	vertical-align: top;
                   5907: }
                   5908: 
1.721     harmsja  5909: ol.LC_smallMenu li img {
1.693     droeschl 5910: 	vertical-align: bottom;
                   5911: }
                   5912: 
1.721     harmsja  5913: ol.LC_smallMenu a {
1.693     droeschl 5914: 	font-size: 90%;
                   5915: 	color: RGB(80, 80, 80);
                   5916: 	text-decoration: none;
                   5917: }
1.795     www      5918: 
1.808     droeschl 5919: ul#LC_TabMainMenuContent {
1.807     droeschl 5920:     clear: both;
1.808     droeschl 5921:     color: $fontmenu;
                   5922:     background: $tabbg;
                   5923:     list-style: none;
                   5924:     padding: 0;
                   5925:     margin: 0;
                   5926:     width: 100%;
                   5927: }
                   5928: 
                   5929: ul#LC_TabMainMenuContent li {
                   5930:     font-weight: bold;
                   5931:     line-height: 1.8em;
                   5932:     padding: 0 0.8em; 
                   5933:     border-right: 1px solid black;
                   5934:     display: inline;
                   5935:     vertical-align: middle;
1.807     droeschl 5936: }
                   5937: 
1.847     tempelho 5938: ul.LC_TabContent {
1.721     harmsja  5939: 	display:block;
1.847     tempelho 5940: 	background: $sidebg;
                   5941: 	border-bottom: solid 1px $lg_border_color
1.721     harmsja  5942: 	list-style:none;
1.847     tempelho 5943: 	margin: -10px -10px 0 -10px;
1.803     bisitz   5944: 	padding: 0;
1.693     droeschl 5945: }
                   5946: 
1.847     tempelho 5947: ul.LC_TabContentBigger {
                   5948:         display:block;
                   5949:         list-style:none;
                   5950:         padding: 0;
                   5951: }
                   5952: 
                   5953: 
1.795     www      5954: ul.LC_TabContent li,
                   5955: ul.LC_TabContentBigger li {
1.693     droeschl 5956: 	display: inline;
1.741     harmsja  5957: 	border-right: solid 1px $lg_border_color;
                   5958: 	float:left;
                   5959: 	line-height:140%;
                   5960: 	white-space:nowrap;
                   5961: }
1.795     www      5962: 
1.808     droeschl 5963: ul#LC_TabMainMenuContent li a {
                   5964:     color: $fontmenu;
1.693     droeschl 5965: 	text-decoration: none;
                   5966: }
1.795     www      5967: 
1.721     harmsja  5968: ul.LC_TabContent {
1.847     tempelho 5969: 	min-height:1.5em;
1.721     harmsja  5970: }
1.795     www      5971: 
                   5972: ul.LC_TabContent li {
1.741     harmsja  5973: 	vertical-align:middle;
1.803     bisitz   5974: 	padding: 0 10px 0 10px;
1.745     ehlerst  5975: 	background-color:$tabbg;
                   5976: 	border-bottom:solid 1px $lg_border_color;
1.721     harmsja  5977: }
1.795     www      5978: 
1.847     tempelho 5979: ul.LC_TabContent .right {
                   5980: 	float:right;
                   5981: }
                   5982: 
1.795     www      5983: ul.LC_TabContent li a, ul.LC_TabContent li {
1.721     harmsja  5984: 	color:rgb(47,47,47);
                   5985: 	text-decoration:none;
                   5986: 	font-size:95%;
                   5987: 	font-weight:bold;
1.761     tempelho 5988: 	padding-right: 16px;
1.721     harmsja  5989: }
1.795     www      5990: 
                   5991: ul.LC_TabContent li:hover, ul.LC_TabContent li.active {
1.761     tempelho 5992:         background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.841     tempelho 5993: 	border-bottom:solid 2px #FFFFFF;
1.761     tempelho 5994: 	padding-right: 16px;
1.744     ehlerst  5995: }
1.795     www      5996: 
                   5997: ul.LC_TabContentBigger li {
1.741     harmsja  5998: 	vertical-align:bottom;
                   5999: 	border-top:solid 1px $lg_border_color;
                   6000: 	border-left:solid 1px $lg_border_color;
                   6001: 	padding:5px 10px 5px 10px;
                   6002: 	margin-left:2px;
1.841     tempelho 6003: 	background: #d9d9d9;
                   6004: }
                   6005: 
                   6006: #maincoursedoc {
                   6007: 	clear:both;
1.741     harmsja  6008: }
1.795     www      6009: 
                   6010: ul.LC_TabContentBigger li:hover, 
                   6011: ul.LC_TabContentBigger li.active {
1.847     tempelho 6012: 	background: #ffffff;
1.744     ehlerst  6013: }
1.795     www      6014: 
                   6015: ul.LC_TabContentBigger li, 
                   6016: ul.LC_TabContentBigger li a {
1.741     harmsja  6017: 	font-size:110%;
                   6018: 	font-weight:bold;
                   6019: }
1.693     droeschl 6020: 
1.795     www      6021: ol#LC_MenuBreadcrumbs, 
                   6022: ol#LC_PathBreadcrumbs, 
1.823     bisitz   6023: ul#LC_CourseBreadcrumbs {
1.693     droeschl 6024: 	padding-left: 10px;
1.819     tempelho 6025: 	margin: 0;
1.693     droeschl 6026: 	list-style-position: inside;
                   6027: }
                   6028: 
1.795     www      6029: ol#LC_MenuBreadcrumbs li, 
                   6030: ol#LC_PathBreadcrumbs li, 
1.823     bisitz   6031: ul#LC_CourseBreadcrumbs li {
1.842     droeschl 6032:     display: inline;
                   6033:     white-space: nowrap;
1.693     droeschl 6034: }
                   6035: 
1.823     bisitz   6036: ol#LC_MenuBreadcrumbs li a,
                   6037: ul#LC_CourseBreadcrumbs li a {
1.693     droeschl 6038: 	text-decoration: none;
                   6039: 	font-size:90%;
                   6040: }
1.795     www      6041: 
                   6042: ol#LC_PathBreadcrumbs li a {
1.698     harmsja  6043: 	text-decoration:none;
                   6044: 	font-size:100%;
                   6045: 	font-weight:bold;
1.693     droeschl 6046: }
1.795     www      6047: 
1.840     bisitz   6048: .LC_Box {
1.835     bisitz   6049:     border: solid 1px $lg_border_color;
                   6050:     padding: 0 10px 10px 10px;
1.746     neumanie 6051: }
1.795     www      6052: 
                   6053: .LC_AboutMe_Image {
1.747     neumanie 6054: 	float:left;
                   6055: 	margin-right:10px;
                   6056: }
1.795     www      6057: 
                   6058: .LC_Clear_AboutMe_Image {
1.747     neumanie 6059: 	clear:left;
                   6060: }
1.795     www      6061: 
1.721     harmsja  6062: dl.LC_ListStyleClean dt {
1.693     droeschl 6063: 	padding-right: 5px;
                   6064: 	display: table-header-group;
                   6065: }
                   6066: 
1.721     harmsja  6067: dl.LC_ListStyleClean dd {
1.693     droeschl 6068: 	display: table-row;
                   6069: }
                   6070: 
1.721     harmsja  6071: .LC_ListStyleClean,
                   6072: .LC_ListStyleSimple,
                   6073: .LC_ListStyleNormal,
1.777     tempelho 6074: .LC_ListStyle_Border,
1.795     www      6075: .LC_ListStyleSpecial {
1.693     droeschl 6076: 	/*display:block;	*/
                   6077: 	list-style-position: inside;
                   6078: 	list-style-type: none;
                   6079: 	overflow: hidden;
1.803     bisitz   6080: 	padding: 0;
1.693     droeschl 6081: }
                   6082: 
1.721     harmsja  6083: .LC_ListStyleSimple li,
                   6084: .LC_ListStyleSimple dd,
                   6085: .LC_ListStyleNormal li,
                   6086: .LC_ListStyleNormal dd,
                   6087: .LC_ListStyleSpecial li,
1.795     www      6088: .LC_ListStyleSpecial dd {
1.803     bisitz   6089: 	margin: 0;
1.693     droeschl 6090: 	padding: 5px 5px 5px 10px;
                   6091: 	clear: both;
                   6092: }
                   6093: 
1.721     harmsja  6094: .LC_ListStyleClean li,
                   6095: .LC_ListStyleClean dd {
1.803     bisitz   6096: 	padding-top: 0;
                   6097: 	padding-bottom: 0;
1.693     droeschl 6098: }
                   6099: 
1.721     harmsja  6100: .LC_ListStyleSimple dd,
1.795     www      6101: .LC_ListStyleSimple li {
1.698     harmsja  6102: 	border-bottom: solid 1px $lg_border_color;
1.693     droeschl 6103: }
                   6104: 
1.721     harmsja  6105: .LC_ListStyleSpecial li,
                   6106: .LC_ListStyleSpecial dd {
1.693     droeschl 6107: 	list-style-type: none;
                   6108: 	background-color: RGB(220, 220, 220);
                   6109: 	margin-bottom: 4px;
                   6110: }
                   6111: 
1.721     harmsja  6112: table.LC_SimpleTable {
1.698     harmsja  6113: 	margin:5px;
                   6114: 	border:solid 1px $lg_border_color;
1.795     www      6115: }
1.693     droeschl 6116: 
1.721     harmsja  6117: table.LC_SimpleTable tr {
1.803     bisitz   6118: 	padding: 0;
1.698     harmsja  6119: 	border:solid 1px $lg_border_color;
1.693     droeschl 6120: }
1.795     www      6121: 
                   6122: table.LC_SimpleTable thead {
1.698     harmsja  6123: 	 background:rgb(220,220,220);
1.693     droeschl 6124: }
                   6125: 
1.721     harmsja  6126: div.LC_columnSection {
1.693     droeschl 6127: 	display: block;
                   6128: 	clear: both;
                   6129: 	overflow: hidden;
1.803     bisitz   6130: 	margin: 0;
1.693     droeschl 6131: }
                   6132: 
1.721     harmsja  6133: div.LC_columnSection>* {
1.693     droeschl 6134: 	float: left;
1.803     bisitz   6135: 	margin: 10px 20px 10px 0;
1.747     neumanie 6136: 	overflow:hidden;
1.693     droeschl 6137: }
1.721     harmsja  6138: 
1.694     tempelho 6139: .LC_loginpage_container {
                   6140: 	text-align:left;
                   6141: 	margin : 0 auto;
1.785     tempelho 6142: 	width:90%;
1.694     tempelho 6143: 	padding: 10px;
                   6144: 	height: auto;
1.712     muellerd 6145: 	background-color:#FFFFFF;
1.694     tempelho 6146: 	border:1px solid #CCCCCC;
                   6147: }
                   6148: 
                   6149: 
                   6150: .LC_loginpage_loginContainer {
                   6151: 	float:left;
1.712     muellerd 6152: 	width: 182px;
1.785     tempelho 6153: 	padding: 2px;
1.712     muellerd 6154: 	border:1px solid #CCCCCC;
                   6155: 	background-color:$loginbg;
1.694     tempelho 6156: }
                   6157: 
1.795     www      6158: .LC_loginpage_loginContainer h2 {
1.803     bisitz   6159: 	margin-top: 0;
1.712     muellerd 6160: 	display:block;
                   6161: 	background:$bgcol;
                   6162: 	color:$textcol;
                   6163: 	padding-left:5px;
                   6164: }
1.785     tempelho 6165: 
1.694     tempelho 6166: .LC_loginpage_loginInfo {
                   6167: 	float:left;
1.785     tempelho 6168: 	width:182px;
1.694     tempelho 6169: 	border:1px solid #CCCCCC;
1.785     tempelho 6170: 	padding:2px;
1.712     muellerd 6171: }
                   6172: 
1.694     tempelho 6173: .LC_loginpage_space {
1.754     droeschl 6174: 	clear: both;
                   6175: 	margin-bottom: 20px;
1.694     tempelho 6176: 	border-bottom: 1px solid #CCCCCC;
                   6177: }
                   6178: 
1.785     tempelho 6179: .LC_loginpage_floatLeft {
                   6180: 	float: left;
                   6181: 	width: 200px;
                   6182: 	margin: 0;
                   6183: }
                   6184: 
1.795     www      6185: table em {
1.754     droeschl 6186: 	font-weight: bold;
                   6187: 	font-style: normal;
1.748     schulted 6188: }
1.795     www      6189: 
1.779     bisitz   6190: table.LC_tableBrowseRes,
1.795     www      6191: table.LC_tableOfContent {
1.769     schulted 6192:         border:none;
                   6193: 	border-spacing: 1;
1.754     droeschl 6194: 	padding: 3px;
                   6195: 	background-color: #FFFFFF;
                   6196: 	font-size: 90%;
1.753     droeschl 6197: }
1.789     droeschl 6198: 
                   6199: table.LC_tableOfContent{
                   6200:     border-collapse: collapse;
                   6201: }
                   6202: 
1.771     droeschl 6203: table.LC_tableBrowseRes a,
1.768     schulted 6204: table.LC_tableOfContent a {
1.771     droeschl 6205:         background-color: transparent;
1.753     droeschl 6206: 	text-decoration: none;
                   6207: }
                   6208: 
1.771     droeschl 6209: table.LC_tableBrowseRes tr.LC_trOdd,
1.768     schulted 6210: table.LC_tableOfContent tr.LC_trOdd{
1.754     droeschl 6211: 	background-color: #EEEEEE;
1.753     droeschl 6212: }
                   6213: 
1.795     www      6214: table.LC_tableOfContent img {
1.753     droeschl 6215: 	border: none;
                   6216: 	height: 1.3em;
                   6217: 	vertical-align: text-bottom;
                   6218: 	margin-right: 0.3em;
                   6219: }
1.757     schulted 6220: 
1.795     www      6221: a#LC_content_toolbar_firsthomework {
1.774     ehlerst  6222: 	background-image:url(/res/adm/pages/open-first-problem.gif);
                   6223: }
                   6224: 
1.795     www      6225: a#LC_content_toolbar_launchnav {
1.774     ehlerst  6226: 	background-image:url(/res/adm/pages/start-navigation.gif);
                   6227: }
                   6228: 
1.795     www      6229: a#LC_content_toolbar_closenav {
1.774     ehlerst  6230: 	background-image:url(/res/adm/pages/close-navigation.gif);
                   6231: }
                   6232: 
1.795     www      6233: a#LC_content_toolbar_everything {
1.774     ehlerst  6234: 	background-image:url(/res/adm/pages/show-all.gif);
                   6235: }
                   6236: 
1.795     www      6237: a#LC_content_toolbar_uncompleted {
1.774     ehlerst  6238: 	background-image:url(/res/adm/pages/show-incomplete-problems.gif);
                   6239: }
                   6240: 
1.795     www      6241: #LC_content_toolbar_clearbubbles {
1.774     ehlerst  6242: 	background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
                   6243: }
                   6244: 
1.795     www      6245: a#LC_content_toolbar_changefolder {
1.757     schulted 6246: 	background : url(/res/adm/pages/close-all-folders.gif) top center ;
                   6247: }
                   6248: 
1.795     www      6249: a#LC_content_toolbar_changefolder_toggled {
1.757     schulted 6250: 	background-image:url(/res/adm/pages/open-all-folders.gif);
                   6251: }
                   6252: 
1.795     www      6253: ul#LC_toolbar li a:hover {
1.757     schulted 6254: 	background-position: bottom center;
                   6255: }
                   6256: 
1.795     www      6257: ul#LC_toolbar {
1.803     bisitz   6258: 	padding: 0;
1.757     schulted 6259: 	margin: 2px;
                   6260: 	list-style:none;
                   6261: 	position:relative;
                   6262: 	background-color:white;
                   6263: }
                   6264: 
1.795     www      6265: ul#LC_toolbar li {
1.757     schulted 6266: 	border:1px solid white;
1.803     bisitz   6267: 	padding: 0;
1.757     schulted 6268: 	margin: 0;
1.795     www      6269:         float: left;
1.767     droeschl 6270: 	display:inline;
1.757     schulted 6271: 	vertical-align:middle;
1.795     www      6272: } 
1.757     schulted 6273: 
1.783     amueller 6274: 
1.795     www      6275: a.LC_toolbarItem {
1.767     droeschl 6276: 	display:block;
1.803     bisitz   6277: 	padding: 0;
                   6278: 	margin: 0;
1.757     schulted 6279: 	height: 32px;
                   6280: 	width: 32px;
1.779     bisitz   6281: 	color:white;
1.803     bisitz   6282: 	border: none;
1.757     schulted 6283: 	background-repeat:no-repeat;
                   6284: 	background-color:transparent;
                   6285: }
                   6286: 
1.843     bisitz   6287: ul.LC_funclist li {
1.782     bisitz   6288:   float: left;
                   6289:   white-space: nowrap;
                   6290:   height: 35px; /* at least as high as heighest list item */
1.803     bisitz   6291:   margin: 0 15px 15px 10px;
1.782     bisitz   6292: }
                   6293: 
1.757     schulted 6294: 
1.343     albertel 6295: END
                   6296: }
                   6297: 
1.306     albertel 6298: =pod
                   6299: 
                   6300: =item * &headtag()
                   6301: 
                   6302: Returns a uniform footer for LON-CAPA web pages.
                   6303: 
1.307     albertel 6304: Inputs: $title - optional title for the head
                   6305:         $head_extra - optional extra HTML to put inside the <head>
1.315     albertel 6306:         $args - optional arguments
1.319     albertel 6307:             force_register - if is true call registerurl so the remote is 
                   6308:                              informed
1.415     albertel 6309:             redirect       -> array ref of
                   6310:                                    1- seconds before redirect occurs
                   6311:                                    2- url to redirect to
                   6312:                                    3- whether the side effect should occur
1.315     albertel 6313:                            (side effect of setting 
                   6314:                                $env{'internal.head.redirect'} to the url 
                   6315:                                redirected too)
1.352     albertel 6316:             domain         -> force to color decorate a page for a specific
                   6317:                                domain
                   6318:             function       -> force usage of a specific rolish color scheme
                   6319:             bgcolor        -> override the default page bgcolor
1.460     albertel 6320:             no_auto_mt_title
                   6321:                            -> prevent &mt()ing the title arg
1.464     albertel 6322: 
1.306     albertel 6323: =cut
                   6324: 
                   6325: sub headtag {
1.313     albertel 6326:     my ($title,$head_extra,$args) = @_;
1.306     albertel 6327:     
1.363     albertel 6328:     my $function = $args->{'function'} || &get_users_function();
                   6329:     my $domain   = $args->{'domain'}   || &determinedomain();
                   6330:     my $bgcolor  = $args->{'bgcolor'}  || &designparm($function.'.pgbg',$domain);
1.418     albertel 6331:     my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458     albertel 6332: 		   $Apache::lonnet::perlvar{'lonVersion'},
1.531     albertel 6333: 		   #time(),
1.418     albertel 6334: 		   $env{'environment.color.timestamp'},
1.363     albertel 6335: 		   $function,$domain,$bgcolor);
                   6336: 
1.369     www      6337:     $url = '/adm/css/'.&escape($url).'.css';
1.363     albertel 6338: 
1.308     albertel 6339:     my $result =
                   6340: 	'<head>'.
1.461     albertel 6341: 	&font_settings();
1.319     albertel 6342: 
1.461     albertel 6343:     if (!$args->{'frameset'}) {
                   6344: 	$result .= &Apache::lonhtmlcommon::htmlareaheaders();
                   6345:     }
1.319     albertel 6346:     if ($args->{'force_register'}) {
                   6347: 	$result .= &Apache::lonmenu::registerurl(1);
                   6348:     }
1.436     albertel 6349:     if (!$args->{'no_nav_bar'} 
                   6350: 	&& !$args->{'only_body'}
                   6351: 	&& !$args->{'frameset'}) {
                   6352: 	$result .= &help_menu_js();
                   6353:     }
1.319     albertel 6354: 
1.314     albertel 6355:     if (ref($args->{'redirect'})) {
1.414     albertel 6356: 	my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315     albertel 6357: 	$url = &Apache::lonenc::check_encrypt($url);
1.414     albertel 6358: 	if (!$inhibit_continue) {
                   6359: 	    $env{'internal.head.redirect'} = $url;
                   6360: 	}
1.313     albertel 6361: 	$result.=<<ADDMETA
                   6362: <meta http-equiv="pragma" content="no-cache" />
1.344     albertel 6363: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313     albertel 6364: ADDMETA
                   6365:     }
1.306     albertel 6366:     if (!defined($title)) {
                   6367: 	$title = 'The LearningOnline Network with CAPA';
                   6368:     }
1.460     albertel 6369:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
                   6370:     $result .= '<title> LON-CAPA '.$title.'</title>'
1.414     albertel 6371: 	.'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
                   6372: 	.$head_extra;
1.306     albertel 6373:     return $result;
                   6374: }
                   6375: 
                   6376: =pod
                   6377: 
1.340     albertel 6378: =item * &font_settings()
                   6379: 
                   6380: Returns neccessary <meta> to set the proper encoding
                   6381: 
                   6382: Inputs: none
                   6383: 
                   6384: =cut
                   6385: 
                   6386: sub font_settings {
                   6387:     my $headerstring='';
1.647     www      6388:     if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340     albertel 6389: 	$headerstring.=
                   6390: 	    '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
                   6391:     }
                   6392:     return $headerstring;
                   6393: }
                   6394: 
1.341     albertel 6395: =pod
                   6396: 
                   6397: =item * &xml_begin()
                   6398: 
                   6399: Returns the needed doctype and <html>
                   6400: 
                   6401: Inputs: none
                   6402: 
                   6403: =cut
                   6404: 
                   6405: sub xml_begin {
                   6406:     my $output='';
                   6407: 
1.592     albertel 6408:     if ($env{'internal.start_page'}==1) {
                   6409: 	&Apache::lonhtmlcommon::init_htmlareafields();
                   6410:     }
1.342     albertel 6411: 
1.341     albertel 6412:     if ($env{'browser.mathml'}) {
                   6413: 	$output='<?xml version="1.0"?>'
                   6414:             #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
                   6415: #            .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
                   6416:             
                   6417: #	    .'<!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">] >'
                   6418: 	    .'<!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">'
                   6419:             .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" ' 
                   6420: 	    .'xmlns="http://www.w3.org/1999/xhtml">';
                   6421:     } else {
1.849     bisitz   6422: 	$output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
                   6423:            .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1.341     albertel 6424:     }
                   6425:     return $output;
                   6426: }
1.340     albertel 6427: 
                   6428: =pod
                   6429: 
1.306     albertel 6430: =item * &endheadtag()
                   6431: 
                   6432: Returns a uniform </head> for LON-CAPA web pages.
                   6433: 
                   6434: Inputs: none
                   6435: 
                   6436: =cut
                   6437: 
                   6438: sub endheadtag {
                   6439:     return '</head>';
                   6440: }
                   6441: 
                   6442: =pod
                   6443: 
                   6444: =item * &head()
                   6445: 
                   6446: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
                   6447: 
1.648     raeburn  6448: Inputs:
                   6449: 
                   6450: =over 4
                   6451: 
                   6452: $title - optional title for the page
                   6453: 
                   6454: $head_extra - optional extra HTML to put inside the <head>
                   6455: 
                   6456: =back
1.405     albertel 6457: 
1.306     albertel 6458: =cut
                   6459: 
                   6460: sub head {
1.325     albertel 6461:     my ($title,$head_extra,$args) = @_;
                   6462:     return &headtag($title,$head_extra,$args).&endheadtag();
1.306     albertel 6463: }
                   6464: 
                   6465: =pod
                   6466: 
                   6467: =item * &start_page()
                   6468: 
                   6469: Returns a complete <html> .. <body> section for LON-CAPA web pages.
                   6470: 
1.648     raeburn  6471: Inputs:
                   6472: 
                   6473: =over 4
                   6474: 
                   6475: $title - optional title for the page
                   6476: 
                   6477: $head_extra - optional extra HTML to incude inside the <head>
                   6478: 
                   6479: $args - additional optional args supported are:
                   6480: 
                   6481: =over 8
                   6482: 
                   6483:              only_body      -> is true will set &bodytag() onlybodytag
1.317     albertel 6484:                                     arg on
1.814     bisitz   6485:              no_nav_bar     -> is true will set &bodytag() no_nav_bar arg on
1.648     raeburn  6486:              add_entries    -> additional attributes to add to the  <body>
                   6487:              domain         -> force to color decorate a page for a 
1.317     albertel 6488:                                     specific domain
1.648     raeburn  6489:              function       -> force usage of a specific rolish color
1.317     albertel 6490:                                     scheme
1.648     raeburn  6491:              redirect       -> see &headtag()
                   6492:              bgcolor        -> override the default page bg color
                   6493:              js_ready       -> return a string ready for being used in 
1.317     albertel 6494:                                     a javascript writeln
1.648     raeburn  6495:              html_encode    -> return a string ready for being used in 
1.320     albertel 6496:                                     a html attribute
1.648     raeburn  6497:              force_register -> if is true will turn on the &bodytag()
1.317     albertel 6498:                                     $forcereg arg
1.648     raeburn  6499:              frameset       -> if true will start with a <frameset>
1.330     albertel 6500:                                     rather than <body>
1.648     raeburn  6501:              skip_phases    -> hash ref of 
1.338     albertel 6502:                                     head -> skip the <html><head> generation
                   6503:                                     body -> skip all <body> generation
1.648     raeburn  6504:              no_inline_link -> if true and in remote mode, don't show the 
1.361     albertel 6505:                                     'Switch To Inline Menu' link
1.648     raeburn  6506:              no_auto_mt_title -> prevent &mt()ing the title arg
                   6507:              inherit_jsmath -> when creating popup window in a page,
                   6508:                                     should it have jsmath forced on by the
                   6509:                                     current page
1.361     albertel 6510: 
1.648     raeburn  6511: =back
1.460     albertel 6512: 
1.648     raeburn  6513: =back
1.562     albertel 6514: 
1.306     albertel 6515: =cut
                   6516: 
                   6517: sub start_page {
1.309     albertel 6518:     my ($title,$head_extra,$args) = @_;
1.318     albertel 6519:     #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313     albertel 6520:     my %head_args;
1.352     albertel 6521:     foreach my $arg ('redirect','force_register','domain','function',
1.460     albertel 6522: 		     'bgcolor','frameset','no_nav_bar','only_body',
                   6523: 		     'no_auto_mt_title') {
1.319     albertel 6524: 	if (defined($args->{$arg})) {
1.324     raeburn  6525: 	    $head_args{$arg} = $args->{$arg};
1.319     albertel 6526: 	}
1.313     albertel 6527:     }
1.319     albertel 6528: 
1.315     albertel 6529:     $env{'internal.start_page'}++;
1.338     albertel 6530:     my $result;
                   6531:     if (! exists($args->{'skip_phases'}{'head'}) ) {
                   6532: 	$result.=
1.341     albertel 6533: 	    &xml_begin().
1.338     albertel 6534: 	    &headtag($title,$head_extra,\%head_args).&endheadtag();
                   6535:     }
                   6536:     
                   6537:     if (! exists($args->{'skip_phases'}{'body'}) ) {
                   6538: 	if ($args->{'frameset'}) {
                   6539: 	    my $attr_string = &make_attr_string($args->{'force_register'},
                   6540: 						$args->{'add_entries'});
                   6541: 	    $result .= "\n<frameset $attr_string>\n";
1.831     bisitz   6542:         } else {
                   6543:             $result .=
                   6544:                 &bodytag($title, 
                   6545:                          $args->{'function'},       $args->{'add_entries'},
                   6546:                          $args->{'only_body'},      $args->{'domain'},
                   6547:                          $args->{'force_register'}, $args->{'no_nav_bar'},
                   6548:                          $args->{'bgcolor'},        $args->{'no_inline_link'},
                   6549:                          $args);
                   6550:         }
1.330     albertel 6551:     }
1.338     albertel 6552: 
1.315     albertel 6553:     if ($args->{'js_ready'}) {
1.713     kaisler  6554: 		$result = &js_ready($result);
1.315     albertel 6555:     }
1.320     albertel 6556:     if ($args->{'html_encode'}) {
1.713     kaisler  6557: 		$result = &html_encode($result);
                   6558:     }
                   6559: 
1.813     bisitz   6560:     # Preparation for new and consistent functionlist at top of screen
                   6561:     # if ($args->{'functionlist'}) {
                   6562:     #            $result .= &build_functionlist();
                   6563:     #}
                   6564: 
                   6565:     # Don't add anything more if only_body wanted
                   6566:     return $result if $args->{'only_body'};
                   6567: 
                   6568:     #Breadcrumbs
1.758     kaisler  6569:     if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
                   6570: 		&Apache::lonhtmlcommon::clear_breadcrumbs();
                   6571: 		#if any br links exists, add them to the breadcrumbs
                   6572: 		if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {         
                   6573: 			foreach my $crumb (@{$args->{'bread_crumbs'}}){
                   6574: 				&Apache::lonhtmlcommon::add_breadcrumb($crumb);
                   6575: 			}
                   6576: 		}
                   6577: 
                   6578: 		#if bread_crumbs_component exists show it as headline else show only the breadcrumbs
                   6579: 		if(exists($args->{'bread_crumbs_component'})){
                   6580: 			$result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
                   6581: 		}else{
                   6582: 			$result .= &Apache::lonhtmlcommon::breadcrumbs();
                   6583: 		}
1.320     albertel 6584:     }
1.315     albertel 6585:     return $result;
1.306     albertel 6586: }
                   6587: 
1.330     albertel 6588: 
1.306     albertel 6589: =pod
                   6590: 
                   6591: =item * &head()
                   6592: 
                   6593: Returns a complete </body></html> section for LON-CAPA web pages.
                   6594: 
1.315     albertel 6595: Inputs:         $args - additional optional args supported are:
                   6596:                  js_ready     -> return a string ready for being used in 
                   6597:                                  a javascript writeln
1.320     albertel 6598:                  html_encode  -> return a string ready for being used in 
                   6599:                                  a html attribute
1.330     albertel 6600:                  frameset     -> if true will start with a <frameset>
                   6601:                                  rather than <body>
1.493     albertel 6602:                  dicsussion   -> if true will get discussion from
                   6603:                                   lonxml::xmlend
                   6604:                                  (you can pass the target and parser arguments
                   6605:                                   through optional 'target' and 'parser' args
                   6606:                                   to this routine)
1.306     albertel 6607: 
                   6608: =cut
                   6609: 
                   6610: sub end_page {
1.315     albertel 6611:     my ($args) = @_;
                   6612:     $env{'internal.end_page'}++;
1.330     albertel 6613:     my $result;
1.335     albertel 6614:     if ($args->{'discussion'}) {
                   6615: 	my ($target,$parser);
                   6616: 	if (ref($args->{'discussion'})) {
                   6617: 	    ($target,$parser) =($args->{'discussion'}{'target'},
                   6618: 				$args->{'discussion'}{'parser'});
                   6619: 	}
                   6620: 	$result .= &Apache::lonxml::xmlend($target,$parser);
                   6621:     }
                   6622: 
1.330     albertel 6623:     if ($args->{'frameset'}) {
                   6624: 	$result .= '</frameset>';
                   6625:     } else {
1.635     raeburn  6626: 	$result .= &endbodytag($args);
1.330     albertel 6627:     }
                   6628:     $result .= "\n</html>";
                   6629: 
1.315     albertel 6630:     if ($args->{'js_ready'}) {
1.317     albertel 6631: 	$result = &js_ready($result);
1.315     albertel 6632:     }
1.335     albertel 6633: 
1.320     albertel 6634:     if ($args->{'html_encode'}) {
                   6635: 	$result = &html_encode($result);
                   6636:     }
1.335     albertel 6637: 
1.315     albertel 6638:     return $result;
                   6639: }
                   6640: 
1.320     albertel 6641: sub html_encode {
                   6642:     my ($result) = @_;
                   6643: 
1.322     albertel 6644:     $result = &HTML::Entities::encode($result,'<>&"');
1.320     albertel 6645:     
                   6646:     return $result;
                   6647: }
1.317     albertel 6648: sub js_ready {
                   6649:     my ($result) = @_;
                   6650: 
1.323     albertel 6651:     $result =~ s/[\n\r]/ /xmsg;
                   6652:     $result =~ s/\\/\\\\/xmsg;
                   6653:     $result =~ s/'/\\'/xmsg;
1.372     albertel 6654:     $result =~ s{</}{<\\/}xmsg;
1.317     albertel 6655:     
                   6656:     return $result;
                   6657: }
                   6658: 
1.315     albertel 6659: sub validate_page {
                   6660:     if (  exists($env{'internal.start_page'})
1.316     albertel 6661: 	  &&     $env{'internal.start_page'} > 1) {
                   6662: 	&Apache::lonnet::logthis('start_page called multiple times '.
1.318     albertel 6663: 				 $env{'internal.start_page'}.' '.
1.316     albertel 6664: 				 $ENV{'request.filename'});
1.315     albertel 6665:     }
                   6666:     if (  exists($env{'internal.end_page'})
1.316     albertel 6667: 	  &&     $env{'internal.end_page'} > 1) {
                   6668: 	&Apache::lonnet::logthis('end_page called multiple times '.
1.318     albertel 6669: 				 $env{'internal.end_page'}.' '.
1.316     albertel 6670: 				 $env{'request.filename'});
1.315     albertel 6671:     }
                   6672:     if (     exists($env{'internal.start_page'})
                   6673: 	&& ! exists($env{'internal.end_page'})) {
1.316     albertel 6674: 	&Apache::lonnet::logthis('start_page called without end_page '.
                   6675: 				 $env{'request.filename'});
1.315     albertel 6676:     }
                   6677:     if (   ! exists($env{'internal.start_page'})
                   6678: 	&&   exists($env{'internal.end_page'})) {
1.316     albertel 6679: 	&Apache::lonnet::logthis('end_page called without start_page'.
                   6680: 				 $env{'request.filename'});
1.315     albertel 6681:     }
1.306     albertel 6682: }
1.315     albertel 6683: 
1.318     albertel 6684: sub simple_error_page {
                   6685:     my ($r,$title,$msg) = @_;
                   6686:     my $page =
                   6687: 	&Apache::loncommon::start_page($title).
                   6688: 	&mt($msg).
                   6689: 	&Apache::loncommon::end_page();
                   6690:     if (ref($r)) {
                   6691: 	$r->print($page);
1.327     albertel 6692: 	return;
1.318     albertel 6693:     }
                   6694:     return $page;
                   6695: }
1.347     albertel 6696: 
                   6697: {
1.610     albertel 6698:     my @row_count;
1.347     albertel 6699:     sub start_data_table {
1.422     albertel 6700: 	my ($add_class) = @_;
                   6701: 	my $css_class = (join(' ','LC_data_table',$add_class));
1.610     albertel 6702: 	unshift(@row_count,0);
1.422     albertel 6703: 	return '<table class="'.$css_class.'">'."\n";
1.347     albertel 6704:     }
                   6705: 
                   6706:     sub end_data_table {
1.610     albertel 6707: 	shift(@row_count);
1.389     albertel 6708: 	return '</table>'."\n";;
1.347     albertel 6709:     }
                   6710: 
                   6711:     sub start_data_table_row {
1.422     albertel 6712: 	my ($add_class) = @_;
1.610     albertel 6713: 	$row_count[0]++;
                   6714: 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.428     albertel 6715: 	$css_class = (join(' ',$css_class,$add_class));
1.422     albertel 6716: 	return  '<tr class="'.$css_class.'">'."\n";;
1.347     albertel 6717:     }
1.471     banghart 6718:     
                   6719:     sub continue_data_table_row {
                   6720: 	my ($add_class) = @_;
1.610     albertel 6721: 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.471     banghart 6722: 	$css_class = (join(' ',$css_class,$add_class));
                   6723: 	return  '<tr class="'.$css_class.'">'."\n";;
                   6724:     }
1.347     albertel 6725: 
                   6726:     sub end_data_table_row {
1.389     albertel 6727: 	return '</tr>'."\n";;
1.347     albertel 6728:     }
1.367     www      6729: 
1.421     albertel 6730:     sub start_data_table_empty_row {
1.707     bisitz   6731: #	$row_count[0]++;
1.421     albertel 6732: 	return  '<tr class="LC_empty_row" >'."\n";;
                   6733:     }
                   6734: 
                   6735:     sub end_data_table_empty_row {
                   6736: 	return '</tr>'."\n";;
                   6737:     }
                   6738: 
1.367     www      6739:     sub start_data_table_header_row {
1.389     albertel 6740: 	return  '<tr class="LC_header_row">'."\n";;
1.367     www      6741:     }
                   6742: 
                   6743:     sub end_data_table_header_row {
1.389     albertel 6744: 	return '</tr>'."\n";;
1.367     www      6745:     }
1.347     albertel 6746: }
                   6747: 
1.548     albertel 6748: =pod
                   6749: 
                   6750: =item * &inhibit_menu_check($arg)
                   6751: 
                   6752: Checks for a inhibitmenu state and generates output to preserve it
                   6753: 
                   6754: Inputs:         $arg - can be any of
                   6755:                      - undef - in which case the return value is a string 
                   6756:                                to add  into arguments list of a uri
                   6757:                      - 'input' - in which case the return value is a HTML
                   6758:                                  <form> <input> field of type hidden to
                   6759:                                  preserve the value
                   6760:                      - a url - in which case the return value is the url with
                   6761:                                the neccesary cgi args added to preserve the
                   6762:                                inhibitmenu state
                   6763:                      - a ref to a url - no return value, but the string is
                   6764:                                         updated to include the neccessary cgi
                   6765:                                         args to preserve the inhibitmenu state
                   6766: 
                   6767: =cut
                   6768: 
                   6769: sub inhibit_menu_check {
                   6770:     my ($arg) = @_;
                   6771:     &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
                   6772:     if ($arg eq 'input') {
                   6773: 	if ($env{'form.inhibitmenu'}) {
                   6774: 	    return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
                   6775: 	} else {
                   6776: 	    return
                   6777: 	}
                   6778:     }
                   6779:     if ($env{'form.inhibitmenu'}) {
                   6780: 	if (ref($arg)) {
                   6781: 	    $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
                   6782: 	} elsif ($arg eq '') {
                   6783: 	    $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
                   6784: 	} else {
                   6785: 	    $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
                   6786: 	}
                   6787:     }
                   6788:     if (!ref($arg)) {
                   6789: 	return $arg;
                   6790:     }
                   6791: }
                   6792: 
1.251     albertel 6793: ###############################################
1.182     matthew  6794: 
                   6795: =pod
                   6796: 
1.549     albertel 6797: =back
                   6798: 
                   6799: =head1 User Information Routines
                   6800: 
                   6801: =over 4
                   6802: 
1.405     albertel 6803: =item * &get_users_function()
1.182     matthew  6804: 
                   6805: Used by &bodytag to determine the current users primary role.
                   6806: Returns either 'student','coordinator','admin', or 'author'.
                   6807: 
                   6808: =cut
                   6809: 
                   6810: ###############################################
                   6811: sub get_users_function {
1.815     tempelho 6812:     my $function = 'norole';
1.818     tempelho 6813:     if ($env{'request.role'}=~/^(st)/) {
                   6814:         $function='student';
                   6815:     }
1.258     albertel 6816:     if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
1.182     matthew  6817:         $function='coordinator';
                   6818:     }
1.258     albertel 6819:     if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182     matthew  6820:         $function='admin';
                   6821:     }
1.826     bisitz   6822:     if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.182     matthew  6823:         ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
                   6824:         $function='author';
                   6825:     }
                   6826:     return $function;
1.54      www      6827: }
1.99      www      6828: 
                   6829: ###############################################
                   6830: 
1.233     raeburn  6831: =pod
                   6832: 
1.821     raeburn  6833: =item * &show_course()
                   6834: 
                   6835: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
                   6836: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
                   6837: 
                   6838: Inputs:
                   6839: None
                   6840: 
                   6841: Outputs:
                   6842: Scalar: 1 if 'Course' to be used, 0 otherwise.
                   6843: 
                   6844: =cut
                   6845: 
                   6846: ###############################################
                   6847: sub show_course {
                   6848:     my $course = !$env{'user.adv'};
                   6849:     if (!$env{'user.adv'}) {
                   6850:         foreach my $env (keys(%env)) {
                   6851:             next if ($env !~ m/^user\.priv\./);
                   6852:             if ($env !~ m/^user\.priv\.(?:st|cm)/) {
                   6853:                 $course = 0;
                   6854:                 last;
                   6855:             }
                   6856:         }
                   6857:     }
                   6858:     return $course;
                   6859: }
                   6860: 
                   6861: ###############################################
                   6862: 
                   6863: =pod
                   6864: 
1.542     raeburn  6865: =item * &check_user_status()
1.274     raeburn  6866: 
                   6867: Determines current status of supplied role for a
                   6868: specific user. Roles can be active, previous or future.
                   6869: 
                   6870: Inputs: 
                   6871: user's domain, user's username, course's domain,
1.375     raeburn  6872: course's number, optional section ID.
1.274     raeburn  6873: 
                   6874: Outputs:
                   6875: role status: active, previous or future. 
                   6876: 
                   6877: =cut
                   6878: 
                   6879: sub check_user_status {
1.412     raeburn  6880:     my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274     raeburn  6881:     my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
                   6882:     my @uroles = keys %userinfo;
                   6883:     my $srchstr;
                   6884:     my $active_chk = 'none';
1.412     raeburn  6885:     my $now = time;
1.274     raeburn  6886:     if (@uroles > 0) {
1.412     raeburn  6887:         if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
1.274     raeburn  6888:             $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
                   6889:         } else {
1.412     raeburn  6890:             $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
                   6891:         }
                   6892:         if (grep/^\Q$srchstr\E$/,@uroles) {
1.274     raeburn  6893:             my $role_end = 0;
                   6894:             my $role_start = 0;
                   6895:             $active_chk = 'active';
1.412     raeburn  6896:             if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
                   6897:                 $role_end = $1;
                   6898:                 if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
                   6899:                     $role_start = $1;
1.274     raeburn  6900:                 }
                   6901:             }
                   6902:             if ($role_start > 0) {
1.412     raeburn  6903:                 if ($now < $role_start) {
1.274     raeburn  6904:                     $active_chk = 'future';
                   6905:                 }
                   6906:             }
                   6907:             if ($role_end > 0) {
1.412     raeburn  6908:                 if ($now > $role_end) {
1.274     raeburn  6909:                     $active_chk = 'previous';
                   6910:                 }
                   6911:             }
                   6912:         }
                   6913:     }
                   6914:     return $active_chk;
                   6915: }
                   6916: 
                   6917: ###############################################
                   6918: 
                   6919: =pod
                   6920: 
1.405     albertel 6921: =item * &get_sections()
1.233     raeburn  6922: 
                   6923: Determines all the sections for a course including
                   6924: sections with students and sections containing other roles.
1.419     raeburn  6925: Incoming parameters: 
                   6926: 
                   6927: 1. domain
                   6928: 2. course number 
                   6929: 3. reference to array containing roles for which sections should 
                   6930: be gathered (optional).
                   6931: 4. reference to array containing status types for which sections 
                   6932: should be gathered (optional).
                   6933: 
                   6934: If the third argument is undefined, sections are gathered for any role. 
                   6935: If the fourth argument is undefined, sections are gathered for any status.
                   6936: Permissible values are 'active' or 'future' or 'previous'.
1.233     raeburn  6937:  
1.374     raeburn  6938: Returns section hash (keys are section IDs, values are
                   6939: number of users in each section), subject to the
1.419     raeburn  6940: optional roles filter, optional status filter 
1.233     raeburn  6941: 
                   6942: =cut
                   6943: 
                   6944: ###############################################
                   6945: sub get_sections {
1.419     raeburn  6946:     my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366     albertel 6947:     if (!defined($cdom) || !defined($cnum)) {
                   6948:         my $cid =  $env{'request.course.id'};
                   6949: 
                   6950: 	return if (!defined($cid));
                   6951: 
                   6952:         $cdom = $env{'course.'.$cid.'.domain'};
                   6953:         $cnum = $env{'course.'.$cid.'.num'};
                   6954:     }
                   6955: 
                   6956:     my %sectioncount;
1.419     raeburn  6957:     my $now = time;
1.240     albertel 6958: 
1.366     albertel 6959:     if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276     albertel 6960: 	my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240     albertel 6961: 	my $sec_index = &Apache::loncoursedata::CL_SECTION();
                   6962: 	my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419     raeburn  6963:         my $start_index = &Apache::loncoursedata::CL_START();
                   6964:         my $end_index = &Apache::loncoursedata::CL_END();
                   6965:         my $status;
1.366     albertel 6966: 	while (my ($student,$data) = each(%$classlist)) {
1.419     raeburn  6967: 	    my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
                   6968: 				                     $data->[$status_index],
                   6969:                                                      $data->[$start_index],
                   6970:                                                      $data->[$end_index]);
                   6971:             if ($stu_status eq 'Active') {
                   6972:                 $status = 'active';
                   6973:             } elsif ($end < $now) {
                   6974:                 $status = 'previous';
                   6975:             } elsif ($start > $now) {
                   6976:                 $status = 'future';
                   6977:             } 
                   6978: 	    if ($section ne '-1' && $section !~ /^\s*$/) {
                   6979:                 if ((!defined($possible_status)) || (($status ne '') && 
                   6980:                     (grep/^\Q$status\E$/,@{$possible_status}))) { 
                   6981: 		    $sectioncount{$section}++;
                   6982:                 }
1.240     albertel 6983: 	    }
                   6984: 	}
                   6985:     }
                   6986:     my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   6987:     foreach my $user (sort(keys(%courseroles))) {
                   6988: 	if ($user !~ /^(\w{2})/) { next; }
                   6989: 	my ($role) = ($user =~ /^(\w{2})/);
                   6990: 	if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419     raeburn  6991: 	my ($section,$status);
1.240     albertel 6992: 	if ($role eq 'cr' &&
                   6993: 	    $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
                   6994: 	    $section=$1;
                   6995: 	}
                   6996: 	if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
                   6997: 	if (!defined($section) || $section eq '-1') { next; }
1.419     raeburn  6998:         my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
                   6999:         if ($end == -1 && $start == -1) {
                   7000:             next; #deleted role
                   7001:         }
                   7002:         if (!defined($possible_status)) { 
                   7003:             $sectioncount{$section}++;
                   7004:         } else {
                   7005:             if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
                   7006:                 $status = 'active';
                   7007:             } elsif ($end < $now) {
                   7008:                 $status = 'future';
                   7009:             } elsif ($start > $now) {
                   7010:                 $status = 'previous';
                   7011:             }
                   7012:             if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
                   7013:                 $sectioncount{$section}++;
                   7014:             }
                   7015:         }
1.233     raeburn  7016:     }
1.366     albertel 7017:     return %sectioncount;
1.233     raeburn  7018: }
                   7019: 
1.274     raeburn  7020: ###############################################
1.294     raeburn  7021: 
                   7022: =pod
1.405     albertel 7023: 
                   7024: =item * &get_course_users()
                   7025: 
1.275     raeburn  7026: Retrieves usernames:domains for users in the specified course
                   7027: with specific role(s), and access status. 
                   7028: 
                   7029: Incoming parameters:
1.277     albertel 7030: 1. course domain
                   7031: 2. course number
                   7032: 3. access status: users must have - either active, 
1.275     raeburn  7033: previous, future, or all.
1.277     albertel 7034: 4. reference to array of permissible roles
1.288     raeburn  7035: 5. reference to array of section restrictions (optional)
                   7036: 6. reference to results object (hash of hashes).
                   7037: 7. reference to optional userdata hash
1.609     raeburn  7038: 8. reference to optional statushash
1.630     raeburn  7039: 9. flag if privileged users (except those set to unhide in
                   7040:    course settings) should be excluded    
1.609     raeburn  7041: Keys of top level results hash are roles.
1.275     raeburn  7042: Keys of inner hashes are username:domain, with 
                   7043: values set to access type.
1.288     raeburn  7044: Optional userdata hash returns an array with arguments in the 
                   7045: same order as loncoursedata::get_classlist() for student data.
                   7046: 
1.609     raeburn  7047: Optional statushash returns
                   7048: 
1.288     raeburn  7049: Entries for end, start, section and status are blank because
                   7050: of the possibility of multiple values for non-student roles.
                   7051: 
1.275     raeburn  7052: =cut
1.405     albertel 7053: 
1.275     raeburn  7054: ###############################################
1.405     albertel 7055: 
1.275     raeburn  7056: sub get_course_users {
1.630     raeburn  7057:     my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288     raeburn  7058:     my %idx = ();
1.419     raeburn  7059:     my %seclists;
1.288     raeburn  7060: 
                   7061:     $idx{udom} = &Apache::loncoursedata::CL_SDOM();
                   7062:     $idx{uname} =  &Apache::loncoursedata::CL_SNAME();
                   7063:     $idx{end} = &Apache::loncoursedata::CL_END();
                   7064:     $idx{start} = &Apache::loncoursedata::CL_START();
                   7065:     $idx{id} = &Apache::loncoursedata::CL_ID();
                   7066:     $idx{section} = &Apache::loncoursedata::CL_SECTION();
                   7067:     $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
                   7068:     $idx{status} = &Apache::loncoursedata::CL_STATUS();
                   7069: 
1.290     albertel 7070:     if (grep(/^st$/,@{$roles})) {
1.276     albertel 7071:         my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278     raeburn  7072:         my $now = time;
1.277     albertel 7073:         foreach my $student (keys(%{$classlist})) {
1.288     raeburn  7074:             my $match = 0;
1.412     raeburn  7075:             my $secmatch = 0;
1.419     raeburn  7076:             my $section = $$classlist{$student}[$idx{section}];
1.609     raeburn  7077:             my $status = $$classlist{$student}[$idx{status}];
1.419     raeburn  7078:             if ($section eq '') {
                   7079:                 $section = 'none';
                   7080:             }
1.291     albertel 7081:             if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 7082:                 if (grep(/^all$/,@{$sections})) {
1.412     raeburn  7083:                     $secmatch = 1;
                   7084:                 } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420     albertel 7085:                     if (grep(/^none$/,@{$sections})) {
1.412     raeburn  7086:                         $secmatch = 1;
                   7087:                     }
                   7088:                 } else {  
1.419     raeburn  7089: 		    if (grep(/^\Q$section\E$/,@{$sections})) {
1.412     raeburn  7090: 		        $secmatch = 1;
                   7091:                     }
1.290     albertel 7092: 		}
1.412     raeburn  7093:                 if (!$secmatch) {
                   7094:                     next;
                   7095:                 }
1.419     raeburn  7096:             }
1.275     raeburn  7097:             if (defined($$types{'active'})) {
1.288     raeburn  7098:                 if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275     raeburn  7099:                     push(@{$$users{st}{$student}},'active');
1.288     raeburn  7100:                     $match = 1;
1.275     raeburn  7101:                 }
                   7102:             }
                   7103:             if (defined($$types{'previous'})) {
1.609     raeburn  7104:                 if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275     raeburn  7105:                     push(@{$$users{st}{$student}},'previous');
1.288     raeburn  7106:                     $match = 1;
1.275     raeburn  7107:                 }
                   7108:             }
                   7109:             if (defined($$types{'future'})) {
1.609     raeburn  7110:                 if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275     raeburn  7111:                     push(@{$$users{st}{$student}},'future');
1.288     raeburn  7112:                     $match = 1;
1.275     raeburn  7113:                 }
                   7114:             }
1.609     raeburn  7115:             if ($match) {
                   7116:                 push(@{$seclists{$student}},$section);
                   7117:                 if (ref($userdata) eq 'HASH') {
                   7118:                     $$userdata{$student} = $$classlist{$student};
                   7119:                 }
                   7120:                 if (ref($statushash) eq 'HASH') {
                   7121:                     $statushash->{$student}{'st'}{$section} = $status;
                   7122:                 }
1.288     raeburn  7123:             }
1.275     raeburn  7124:         }
                   7125:     }
1.412     raeburn  7126:     if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439     raeburn  7127:         my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   7128:         my $now = time;
1.609     raeburn  7129:         my %displaystatus = ( previous => 'Expired',
                   7130:                               active   => 'Active',
                   7131:                               future   => 'Future',
                   7132:                             );
1.630     raeburn  7133:         my %nothide;
                   7134:         if ($hidepriv) {
                   7135:             my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
                   7136:             foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
                   7137:                 if ($user !~ /:/) {
                   7138:                     $nothide{join(':',split(/[\@]/,$user))}=1;
                   7139:                 } else {
                   7140:                     $nothide{$user} = 1;
                   7141:                 }
                   7142:             }
                   7143:         }
1.439     raeburn  7144:         foreach my $person (sort(keys(%coursepersonnel))) {
1.288     raeburn  7145:             my $match = 0;
1.412     raeburn  7146:             my $secmatch = 0;
1.439     raeburn  7147:             my $status;
1.412     raeburn  7148:             my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275     raeburn  7149:             $user =~ s/:$//;
1.439     raeburn  7150:             my ($end,$start) = split(/:/,$coursepersonnel{$person});
                   7151:             if ($end == -1 || $start == -1) {
                   7152:                 next;
                   7153:             }
                   7154:             if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
                   7155:                 (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412     raeburn  7156:                 my ($uname,$udom) = split(/:/,$user);
                   7157:                 if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 7158:                     if (grep(/^all$/,@{$sections})) {
1.412     raeburn  7159:                         $secmatch = 1;
                   7160:                     } elsif ($usec eq '') {
1.420     albertel 7161:                         if (grep(/^none$/,@{$sections})) {
1.412     raeburn  7162:                             $secmatch = 1;
                   7163:                         }
                   7164:                     } else {
                   7165:                         if (grep(/^\Q$usec\E$/,@{$sections})) {
                   7166:                             $secmatch = 1;
                   7167:                         }
                   7168:                     }
                   7169:                     if (!$secmatch) {
                   7170:                         next;
                   7171:                     }
1.288     raeburn  7172:                 }
1.419     raeburn  7173:                 if ($usec eq '') {
                   7174:                     $usec = 'none';
                   7175:                 }
1.275     raeburn  7176:                 if ($uname ne '' && $udom ne '') {
1.630     raeburn  7177:                     if ($hidepriv) {
                   7178:                         if ((&Apache::lonnet::privileged($uname,$udom)) &&
                   7179:                             (!$nothide{$uname.':'.$udom})) {
                   7180:                             next;
                   7181:                         }
                   7182:                     }
1.503     raeburn  7183:                     if ($end > 0 && $end < $now) {
1.439     raeburn  7184:                         $status = 'previous';
                   7185:                     } elsif ($start > $now) {
                   7186:                         $status = 'future';
                   7187:                     } else {
                   7188:                         $status = 'active';
                   7189:                     }
1.277     albertel 7190:                     foreach my $type (keys(%{$types})) { 
1.275     raeburn  7191:                         if ($status eq $type) {
1.420     albertel 7192:                             if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419     raeburn  7193:                                 push(@{$$users{$role}{$user}},$type);
                   7194:                             }
1.288     raeburn  7195:                             $match = 1;
                   7196:                         }
                   7197:                     }
1.419     raeburn  7198:                     if (($match) && (ref($userdata) eq 'HASH')) {
                   7199:                         if (!exists($$userdata{$uname.':'.$udom})) {
                   7200: 			    &get_user_info($udom,$uname,\%idx,$userdata);
                   7201:                         }
1.420     albertel 7202:                         if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419     raeburn  7203:                             push(@{$seclists{$uname.':'.$udom}},$usec);
                   7204:                         }
1.609     raeburn  7205:                         if (ref($statushash) eq 'HASH') {
                   7206:                             $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
                   7207:                         }
1.275     raeburn  7208:                     }
                   7209:                 }
                   7210:             }
                   7211:         }
1.290     albertel 7212:         if (grep(/^ow$/,@{$roles})) {
1.279     raeburn  7213:             if ((defined($cdom)) && (defined($cnum))) {
                   7214:                 my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
                   7215:                 if ( defined($csettings{'internal.courseowner'}) ) {
                   7216:                     my $owner = $csettings{'internal.courseowner'};
1.609     raeburn  7217:                     next if ($owner eq '');
                   7218:                     my ($ownername,$ownerdom);
                   7219:                     if ($owner =~ /^([^:]+):([^:]+)$/) {
                   7220:                         $ownername = $1;
                   7221:                         $ownerdom = $2;
                   7222:                     } else {
                   7223:                         $ownername = $owner;
                   7224:                         $ownerdom = $cdom;
                   7225:                         $owner = $ownername.':'.$ownerdom;
1.439     raeburn  7226:                     }
                   7227:                     @{$$users{'ow'}{$owner}} = 'any';
1.290     albertel 7228:                     if (defined($userdata) && 
1.609     raeburn  7229: 			!exists($$userdata{$owner})) {
                   7230: 			&get_user_info($ownerdom,$ownername,\%idx,$userdata);
                   7231:                         if (!grep(/^none$/,@{$seclists{$owner}})) {
                   7232:                             push(@{$seclists{$owner}},'none');
                   7233:                         }
                   7234:                         if (ref($statushash) eq 'HASH') {
                   7235:                             $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419     raeburn  7236:                         }
1.290     albertel 7237: 		    }
1.279     raeburn  7238:                 }
                   7239:             }
                   7240:         }
1.419     raeburn  7241:         foreach my $user (keys(%seclists)) {
                   7242:             @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
                   7243:             $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
                   7244:         }
1.275     raeburn  7245:     }
                   7246:     return;
                   7247: }
                   7248: 
1.288     raeburn  7249: sub get_user_info {
                   7250:     my ($udom,$uname,$idx,$userdata) = @_;
1.289     albertel 7251:     $$userdata{$uname.':'.$udom}[$$idx{fullname}] = 
                   7252: 	&plainname($uname,$udom,'lastname');
1.291     albertel 7253:     $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297     raeburn  7254:     $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609     raeburn  7255:     my %idhash =  &Apache::lonnet::idrget($udom,($uname));
                   7256:     $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname}; 
1.288     raeburn  7257:     return;
                   7258: }
1.275     raeburn  7259: 
1.472     raeburn  7260: ###############################################
                   7261: 
                   7262: =pod
                   7263: 
                   7264: =item * &get_user_quota()
                   7265: 
                   7266: Retrieves quota assigned for storage of portfolio files for a user  
                   7267: 
                   7268: Incoming parameters:
                   7269: 1. user's username
                   7270: 2. user's domain
                   7271: 
                   7272: Returns:
1.536     raeburn  7273: 1. Disk quota (in Mb) assigned to student.
                   7274: 2. (Optional) Type of setting: custom or default
                   7275:    (individually assigned or default for user's 
                   7276:    institutional status).
                   7277: 3. (Optional) - User's institutional status (e.g., faculty, staff
                   7278:    or student - types as defined in localenroll::inst_usertypes 
                   7279:    for user's domain, which determines default quota for user.
                   7280: 4. (Optional) - Default quota which would apply to the user.
1.472     raeburn  7281: 
                   7282: If a value has been stored in the user's environment, 
1.536     raeburn  7283: it will return that, otherwise it returns the maximal default
                   7284: defined for the user's instituional status(es) in the domain.
1.472     raeburn  7285: 
                   7286: =cut
                   7287: 
                   7288: ###############################################
                   7289: 
                   7290: 
                   7291: sub get_user_quota {
                   7292:     my ($uname,$udom) = @_;
1.536     raeburn  7293:     my ($quota,$quotatype,$settingstatus,$defquota);
1.472     raeburn  7294:     if (!defined($udom)) {
                   7295:         $udom = $env{'user.domain'};
                   7296:     }
                   7297:     if (!defined($uname)) {
                   7298:         $uname = $env{'user.name'};
                   7299:     }
                   7300:     if (($udom eq '' || $uname eq '') ||
                   7301:         ($udom eq 'public') && ($uname eq 'public')) {
                   7302:         $quota = 0;
1.536     raeburn  7303:         $quotatype = 'default';
                   7304:         $defquota = 0; 
1.472     raeburn  7305:     } else {
1.536     raeburn  7306:         my $inststatus;
1.472     raeburn  7307:         if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
                   7308:             $quota = $env{'environment.portfolioquota'};
1.536     raeburn  7309:             $inststatus = $env{'environment.inststatus'};
1.472     raeburn  7310:         } else {
1.536     raeburn  7311:             my %userenv = 
                   7312:                 &Apache::lonnet::get('environment',['portfolioquota',
                   7313:                                      'inststatus'],$udom,$uname);
1.472     raeburn  7314:             my ($tmp) = keys(%userenv);
                   7315:             if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   7316:                 $quota = $userenv{'portfolioquota'};
1.536     raeburn  7317:                 $inststatus = $userenv{'inststatus'};
1.472     raeburn  7318:             } else {
                   7319:                 undef(%userenv);
                   7320:             }
                   7321:         }
1.536     raeburn  7322:         ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472     raeburn  7323:         if ($quota eq '') {
1.536     raeburn  7324:             $quota = $defquota;
                   7325:             $quotatype = 'default';
                   7326:         } else {
                   7327:             $quotatype = 'custom';
1.472     raeburn  7328:         }
                   7329:     }
1.536     raeburn  7330:     if (wantarray) {
                   7331:         return ($quota,$quotatype,$settingstatus,$defquota);
                   7332:     } else {
                   7333:         return $quota;
                   7334:     }
1.472     raeburn  7335: }
                   7336: 
                   7337: ###############################################
                   7338: 
                   7339: =pod
                   7340: 
                   7341: =item * &default_quota()
                   7342: 
1.536     raeburn  7343: Retrieves default quota assigned for storage of user portfolio files,
                   7344: given an (optional) user's institutional status.
1.472     raeburn  7345: 
                   7346: Incoming parameters:
                   7347: 1. domain
1.536     raeburn  7348: 2. (Optional) institutional status(es).  This is a : separated list of 
                   7349:    status types (e.g., faculty, staff, student etc.)
                   7350:    which apply to the user for whom the default is being retrieved.
                   7351:    If the institutional status string in undefined, the domain
                   7352:    default quota will be returned. 
1.472     raeburn  7353: 
                   7354: Returns:
                   7355: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536     raeburn  7356: 2. (Optional) institutional type which determined the value of the
                   7357:    default quota.
1.472     raeburn  7358: 
                   7359: If a value has been stored in the domain's configuration db,
                   7360: it will return that, otherwise it returns 20 (for backwards 
                   7361: compatibility with domains which have not set up a configuration
                   7362: db file; the original statically defined portfolio quota was 20 Mb). 
                   7363: 
1.536     raeburn  7364: If the user's status includes multiple types (e.g., staff and student),
                   7365: the largest default quota which applies to the user determines the
                   7366: default quota returned.
                   7367: 
1.780     raeburn  7368: =back
                   7369: 
1.472     raeburn  7370: =cut
                   7371: 
                   7372: ###############################################
                   7373: 
                   7374: 
                   7375: sub default_quota {
1.536     raeburn  7376:     my ($udom,$inststatus) = @_;
                   7377:     my ($defquota,$settingstatus);
                   7378:     my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622     raeburn  7379:                                             ['quotas'],$udom);
                   7380:     if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536     raeburn  7381:         if ($inststatus ne '') {
1.765     raeburn  7382:             my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536     raeburn  7383:             foreach my $item (@statuses) {
1.711     raeburn  7384:                 if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
                   7385:                     if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
                   7386:                         if ($defquota eq '') {
                   7387:                             $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
                   7388:                             $settingstatus = $item;
                   7389:                         } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
                   7390:                             $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
                   7391:                             $settingstatus = $item;
                   7392:                         }
                   7393:                     }
                   7394:                 } else {
                   7395:                     if ($quotahash{'quotas'}{$item} ne '') {
                   7396:                         if ($defquota eq '') {
                   7397:                             $defquota = $quotahash{'quotas'}{$item};
                   7398:                             $settingstatus = $item;
                   7399:                         } elsif ($quotahash{'quotas'}{$item} > $defquota) {
                   7400:                             $defquota = $quotahash{'quotas'}{$item};
                   7401:                             $settingstatus = $item;
                   7402:                         }
1.536     raeburn  7403:                     }
                   7404:                 }
                   7405:             }
                   7406:         }
                   7407:         if ($defquota eq '') {
1.711     raeburn  7408:             if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
                   7409:                 $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
                   7410:             } else {
                   7411:                 $defquota = $quotahash{'quotas'}{'default'};
                   7412:             }
1.536     raeburn  7413:             $settingstatus = 'default';
                   7414:         }
                   7415:     } else {
                   7416:         $settingstatus = 'default';
                   7417:         $defquota = 20;
                   7418:     }
                   7419:     if (wantarray) {
                   7420:         return ($defquota,$settingstatus);
1.472     raeburn  7421:     } else {
1.536     raeburn  7422:         return $defquota;
1.472     raeburn  7423:     }
                   7424: }
                   7425: 
1.384     raeburn  7426: sub get_secgrprole_info {
                   7427:     my ($cdom,$cnum,$needroles,$type)  = @_;
                   7428:     my %sections_count = &get_sections($cdom,$cnum);
                   7429:     my @sections =  (sort {$a <=> $b} keys(%sections_count));
                   7430:     my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
                   7431:     my @groups = sort(keys(%curr_groups));
                   7432:     my $allroles = [];
                   7433:     my $rolehash;
                   7434:     my $accesshash = {
                   7435:                      active => 'Currently has access',
                   7436:                      future => 'Will have future access',
                   7437:                      previous => 'Previously had access',
                   7438:                   };
                   7439:     if ($needroles) {
                   7440:         $rolehash = {'all' => 'all'};
1.385     albertel 7441:         my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   7442: 	if (&Apache::lonnet::error(%user_roles)) {
                   7443: 	    undef(%user_roles);
                   7444: 	}
                   7445:         foreach my $item (keys(%user_roles)) {
1.384     raeburn  7446:             my ($role)=split(/\:/,$item,2);
                   7447:             if ($role eq 'cr') { next; }
                   7448:             if ($role =~ /^cr/) {
                   7449:                 $$rolehash{$role} = (split('/',$role))[3];
                   7450:             } else {
                   7451:                 $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
                   7452:             }
                   7453:         }
                   7454:         foreach my $key (sort(keys(%{$rolehash}))) {
                   7455:             push(@{$allroles},$key);
                   7456:         }
                   7457:         push (@{$allroles},'st');
                   7458:         $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
                   7459:     }
                   7460:     return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
                   7461: }
                   7462: 
1.555     raeburn  7463: sub user_picker {
1.627     raeburn  7464:     my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555     raeburn  7465:     my $currdom = $dom;
                   7466:     my %curr_selected = (
                   7467:                         srchin => 'dom',
1.580     raeburn  7468:                         srchby => 'lastname',
1.555     raeburn  7469:                       );
                   7470:     my $srchterm;
1.625     raeburn  7471:     if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555     raeburn  7472:         if ($srch->{'srchby'} ne '') {
                   7473:             $curr_selected{'srchby'} = $srch->{'srchby'};
                   7474:         }
                   7475:         if ($srch->{'srchin'} ne '') {
                   7476:             $curr_selected{'srchin'} = $srch->{'srchin'};
                   7477:         }
                   7478:         if ($srch->{'srchtype'} ne '') {
                   7479:             $curr_selected{'srchtype'} = $srch->{'srchtype'};
                   7480:         }
                   7481:         if ($srch->{'srchdomain'} ne '') {
                   7482:             $currdom = $srch->{'srchdomain'};
                   7483:         }
                   7484:         $srchterm = $srch->{'srchterm'};
                   7485:     }
                   7486:     my %lt=&Apache::lonlocal::texthash(
1.573     raeburn  7487:                     'usr'       => 'Search criteria',
1.563     raeburn  7488:                     'doma'      => 'Domain/institution to search',
1.558     albertel 7489:                     'uname'     => 'username',
                   7490:                     'lastname'  => 'last name',
1.555     raeburn  7491:                     'lastfirst' => 'last name, first name',
1.558     albertel 7492:                     'crs'       => 'in this course',
1.576     raeburn  7493:                     'dom'       => 'in selected LON-CAPA domain', 
1.558     albertel 7494:                     'alc'       => 'all LON-CAPA',
1.573     raeburn  7495:                     'instd'     => 'in institutional directory for selected domain',
1.558     albertel 7496:                     'exact'     => 'is',
                   7497:                     'contains'  => 'contains',
1.569     raeburn  7498:                     'begins'    => 'begins with',
1.571     raeburn  7499:                     'youm'      => "You must include some text to search for.",
                   7500:                     'thte'      => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
                   7501:                     'thet'      => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
                   7502:                     'yomc'      => "You must choose a domain when using an institutional directory search.",
                   7503:                     'ymcd'      => "You must choose a domain when using a domain search.",
                   7504:                     'whus'      => "When using searching by last,first you must include a comma as separator between last name and first name.",
                   7505:                     'whse'      => "When searching by last,first you must include at least one character in the first name.",
                   7506:                      'thfo'     => "The following need to be corrected before the search can be run:",
1.555     raeburn  7507:                                        );
1.563     raeburn  7508:     my $domform = &select_dom_form($currdom,'srchdomain',1,1);
                   7509:     my $srchinsel = ' <select name="srchin">';
1.555     raeburn  7510: 
                   7511:     my @srchins = ('crs','dom','alc','instd');
                   7512: 
                   7513:     foreach my $option (@srchins) {
                   7514:         # FIXME 'alc' option unavailable until 
                   7515:         #       loncreateuser::print_user_query_page()
                   7516:         #       has been completed.
                   7517:         next if ($option eq 'alc');
                   7518:         next if ($option eq 'crs' && !$env{'request.course.id'});
1.563     raeburn  7519:         if ($curr_selected{'srchin'} eq $option) {
                   7520:             $srchinsel .= ' 
                   7521:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7522:         } else {
                   7523:             $srchinsel .= '
                   7524:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7525:         }
1.555     raeburn  7526:     }
1.563     raeburn  7527:     $srchinsel .= "\n  </select>\n";
1.555     raeburn  7528: 
                   7529:     my $srchbysel =  ' <select name="srchby">';
1.580     raeburn  7530:     foreach my $option ('lastname','lastfirst','uname') {
1.555     raeburn  7531:         if ($curr_selected{'srchby'} eq $option) {
                   7532:             $srchbysel .= '
                   7533:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7534:         } else {
                   7535:             $srchbysel .= '
                   7536:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7537:          }
                   7538:     }
                   7539:     $srchbysel .= "\n  </select>\n";
                   7540: 
                   7541:     my $srchtypesel = ' <select name="srchtype">';
1.580     raeburn  7542:     foreach my $option ('begins','contains','exact') {
1.555     raeburn  7543:         if ($curr_selected{'srchtype'} eq $option) {
                   7544:             $srchtypesel .= '
                   7545:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7546:         } else {
                   7547:             $srchtypesel .= '
                   7548:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7549:         }
                   7550:     }
                   7551:     $srchtypesel .= "\n  </select>\n";
                   7552: 
1.558     albertel 7553:     my ($newuserscript,$new_user_create);
1.556     raeburn  7554: 
                   7555:     if ($forcenewuser) {
1.576     raeburn  7556:         if (ref($srch) eq 'HASH') {
                   7557:             if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627     raeburn  7558:                 if ($cancreate) {
                   7559:                     $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>';
                   7560:                 } else {
1.799     bisitz   7561:                     my $helplink = 'javascript:helpMenu('."'display'".')';
1.627     raeburn  7562:                     my %usertypetext = (
                   7563:                         official   => 'institutional',
                   7564:                         unofficial => 'non-institutional',
                   7565:                     );
1.799     bisitz   7566:                     $new_user_create = '<p class="LC_warning">'
                   7567:                                       .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
                   7568:                                       .' '
                   7569:                                       .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
                   7570:                                           ,'<a href="'.$helplink.'">','</a>')
                   7571:                                       .'</p><br />';
1.627     raeburn  7572:                 }
1.576     raeburn  7573:             }
                   7574:         }
                   7575: 
1.556     raeburn  7576:         $newuserscript = <<"ENDSCRIPT";
                   7577: 
1.570     raeburn  7578: function setSearch(createnew,callingForm) {
1.556     raeburn  7579:     if (createnew == 1) {
1.570     raeburn  7580:         for (var i=0; i<callingForm.srchby.length; i++) {
                   7581:             if (callingForm.srchby.options[i].value == 'uname') {
                   7582:                 callingForm.srchby.selectedIndex = i;
1.556     raeburn  7583:             }
                   7584:         }
1.570     raeburn  7585:         for (var i=0; i<callingForm.srchin.length; i++) {
                   7586:             if ( callingForm.srchin.options[i].value == 'dom') {
                   7587: 		callingForm.srchin.selectedIndex = i;
1.556     raeburn  7588:             }
                   7589:         }
1.570     raeburn  7590:         for (var i=0; i<callingForm.srchtype.length; i++) {
                   7591:             if (callingForm.srchtype.options[i].value == 'exact') {
                   7592:                 callingForm.srchtype.selectedIndex = i;
1.556     raeburn  7593:             }
                   7594:         }
1.570     raeburn  7595:         for (var i=0; i<callingForm.srchdomain.length; i++) {
                   7596:             if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
                   7597:                 callingForm.srchdomain.selectedIndex = i;
1.556     raeburn  7598:             }
                   7599:         }
                   7600:     }
                   7601: }
                   7602: ENDSCRIPT
1.558     albertel 7603: 
1.556     raeburn  7604:     }
                   7605: 
1.555     raeburn  7606:     my $output = <<"END_BLOCK";
1.556     raeburn  7607: <script type="text/javascript">
1.824     bisitz   7608: // <![CDATA[
1.570     raeburn  7609: function validateEntry(callingForm) {
1.558     albertel 7610: 
1.556     raeburn  7611:     var checkok = 1;
1.558     albertel 7612:     var srchin;
1.570     raeburn  7613:     for (var i=0; i<callingForm.srchin.length; i++) {
                   7614: 	if ( callingForm.srchin[i].checked ) {
                   7615: 	    srchin = callingForm.srchin[i].value;
1.558     albertel 7616: 	}
                   7617:     }
                   7618: 
1.570     raeburn  7619:     var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
                   7620:     var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
                   7621:     var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
                   7622:     var srchterm =  callingForm.srchterm.value;
                   7623:     var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556     raeburn  7624:     var msg = "";
                   7625: 
                   7626:     if (srchterm == "") {
                   7627:         checkok = 0;
1.571     raeburn  7628:         msg += "$lt{'youm'}\\n";
1.556     raeburn  7629:     }
                   7630: 
1.569     raeburn  7631:     if (srchtype== 'begins') {
                   7632:         if (srchterm.length < 2) {
                   7633:             checkok = 0;
1.571     raeburn  7634:             msg += "$lt{'thte'}\\n";
1.569     raeburn  7635:         }
                   7636:     }
                   7637: 
1.556     raeburn  7638:     if (srchtype== 'contains') {
                   7639:         if (srchterm.length < 3) {
                   7640:             checkok = 0;
1.571     raeburn  7641:             msg += "$lt{'thet'}\\n";
1.556     raeburn  7642:         }
                   7643:     }
                   7644:     if (srchin == 'instd') {
                   7645:         if (srchdomain == '') {
                   7646:             checkok = 0;
1.571     raeburn  7647:             msg += "$lt{'yomc'}\\n";
1.556     raeburn  7648:         }
                   7649:     }
                   7650:     if (srchin == 'dom') {
                   7651:         if (srchdomain == '') {
                   7652:             checkok = 0;
1.571     raeburn  7653:             msg += "$lt{'ymcd'}\\n";
1.556     raeburn  7654:         }
                   7655:     }
                   7656:     if (srchby == 'lastfirst') {
                   7657:         if (srchterm.indexOf(",") == -1) {
                   7658:             checkok = 0;
1.571     raeburn  7659:             msg += "$lt{'whus'}\\n";
1.556     raeburn  7660:         }
                   7661:         if (srchterm.indexOf(",") == srchterm.length -1) {
                   7662:             checkok = 0;
1.571     raeburn  7663:             msg += "$lt{'whse'}\\n";
1.556     raeburn  7664:         }
                   7665:     }
                   7666:     if (checkok == 0) {
1.571     raeburn  7667:         alert("$lt{'thfo'}\\n"+msg);
1.556     raeburn  7668:         return;
                   7669:     }
                   7670:     if (checkok == 1) {
1.570     raeburn  7671:         callingForm.submit();
1.556     raeburn  7672:     }
                   7673: }
                   7674: 
                   7675: $newuserscript
                   7676: 
1.824     bisitz   7677: // ]]>
1.556     raeburn  7678: </script>
1.558     albertel 7679: 
                   7680: $new_user_create
                   7681: 
1.555     raeburn  7682: <table>
1.558     albertel 7683:  <tr>
1.573     raeburn  7684:   <td>$lt{'doma'}:</td>
                   7685:   <td>$domform</td>
                   7686:   </td>
                   7687:  </tr>
                   7688:  <tr>
                   7689:   <td>$lt{'usr'}:</td>
1.563     raeburn  7690:   <td>$srchbysel
                   7691:       $srchtypesel 
                   7692:       <input type="text" size="15" name="srchterm" value="$srchterm" />
1.564     albertel 7693:       $srchinsel 
1.563     raeburn  7694:   </td>
                   7695:  </tr>
1.555     raeburn  7696: </table>
                   7697: <br />
                   7698: END_BLOCK
1.558     albertel 7699: 
1.555     raeburn  7700:     return $output;
                   7701: }
                   7702: 
1.612     raeburn  7703: sub user_rule_check {
1.615     raeburn  7704:     my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612     raeburn  7705:     my $response;
                   7706:     if (ref($usershash) eq 'HASH') {
                   7707:         foreach my $user (keys(%{$usershash})) {
                   7708:             my ($uname,$udom) = split(/:/,$user);
                   7709:             next if ($udom eq '' || $uname eq '');
1.615     raeburn  7710:             my ($id,$newuser);
1.612     raeburn  7711:             if (ref($usershash->{$user}) eq 'HASH') {
1.615     raeburn  7712:                 $newuser = $usershash->{$user}->{'newuser'};
1.612     raeburn  7713:                 $id = $usershash->{$user}->{'id'};
                   7714:             }
                   7715:             my $inst_response;
                   7716:             if (ref($checks) eq 'HASH') {
                   7717:                 if (defined($checks->{'username'})) {
1.615     raeburn  7718:                     ($inst_response,%{$inst_results->{$user}}) = 
1.612     raeburn  7719:                         &Apache::lonnet::get_instuser($udom,$uname);
                   7720:                 } elsif (defined($checks->{'id'})) {
1.615     raeburn  7721:                     ($inst_response,%{$inst_results->{$user}}) =
1.612     raeburn  7722:                         &Apache::lonnet::get_instuser($udom,undef,$id);
                   7723:                 }
1.615     raeburn  7724:             } else {
                   7725:                 ($inst_response,%{$inst_results->{$user}}) =
                   7726:                     &Apache::lonnet::get_instuser($udom,$uname);
                   7727:                 return;
1.612     raeburn  7728:             }
1.615     raeburn  7729:             if (!$got_rules->{$udom}) {
1.612     raeburn  7730:                 my %domconfig = &Apache::lonnet::get_dom('configuration',
                   7731:                                                   ['usercreation'],$udom);
                   7732:                 if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615     raeburn  7733:                     foreach my $item ('username','id') {
1.612     raeburn  7734:                         if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
                   7735:                             $$curr_rules{$udom}{$item} = 
                   7736:                                 $domconfig{'usercreation'}{$item.'_rule'};
1.585     raeburn  7737:                         }
                   7738:                     }
                   7739:                 }
1.615     raeburn  7740:                 $got_rules->{$udom} = 1;  
1.585     raeburn  7741:             }
1.612     raeburn  7742:             foreach my $item (keys(%{$checks})) {
                   7743:                 if (ref($$curr_rules{$udom}) eq 'HASH') {
                   7744:                     if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
                   7745:                         if (@{$$curr_rules{$udom}{$item}} > 0) {
                   7746:                             my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
                   7747:                             foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
                   7748:                                 if ($rule_check{$rule}) {
                   7749:                                     $$rulematch{$user}{$item} = $rule;
                   7750:                                     if ($inst_response eq 'ok') {
1.615     raeburn  7751:                                         if (ref($inst_results) eq 'HASH') {
                   7752:                                             if (ref($inst_results->{$user}) eq 'HASH') {
                   7753:                                                 if (keys(%{$inst_results->{$user}}) == 0) {
                   7754:                                                     $$alerts{$item}{$udom}{$uname} = 1;
                   7755:                                                 }
1.612     raeburn  7756:                                             }
                   7757:                                         }
1.615     raeburn  7758:                                     }
                   7759:                                     last;
1.585     raeburn  7760:                                 }
                   7761:                             }
                   7762:                         }
                   7763:                     }
                   7764:                 }
                   7765:             }
                   7766:         }
                   7767:     }
1.612     raeburn  7768:     return;
                   7769: }
                   7770: 
                   7771: sub user_rule_formats {
                   7772:     my ($domain,$domdesc,$curr_rules,$check) = @_;
                   7773:     my %text = ( 
                   7774:                  'username' => 'Usernames',
                   7775:                  'id'       => 'IDs',
                   7776:                );
                   7777:     my $output;
                   7778:     my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
                   7779:     if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
                   7780:         if (@{$ruleorder} > 0) {
                   7781:             $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>';
                   7782:             foreach my $rule (@{$ruleorder}) {
                   7783:                 if (ref($curr_rules) eq 'ARRAY') {
                   7784:                     if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
                   7785:                         if (ref($rules->{$rule}) eq 'HASH') {
                   7786:                             $output .= '<li>'.$rules->{$rule}{'name'}.': '.
                   7787:                                         $rules->{$rule}{'desc'}.'</li>';
                   7788:                         }
                   7789:                     }
                   7790:                 }
                   7791:             }
                   7792:             $output .= '</ul>';
                   7793:         }
                   7794:     }
                   7795:     return $output;
                   7796: }
                   7797: 
                   7798: sub instrule_disallow_msg {
1.615     raeburn  7799:     my ($checkitem,$domdesc,$count,$mode) = @_;
1.612     raeburn  7800:     my $response;
                   7801:     my %text = (
                   7802:                   item   => 'username',
                   7803:                   items  => 'usernames',
                   7804:                   match  => 'matches',
                   7805:                   do     => 'does',
                   7806:                   action => 'a username',
                   7807:                   one    => 'one',
                   7808:                );
                   7809:     if ($count > 1) {
                   7810:         $text{'item'} = 'usernames';
                   7811:         $text{'match'} ='match';
                   7812:         $text{'do'} = 'do';
                   7813:         $text{'action'} = 'usernames',
                   7814:         $text{'one'} = 'ones';
                   7815:     }
                   7816:     if ($checkitem eq 'id') {
                   7817:         $text{'items'} = 'IDs';
                   7818:         $text{'item'} = 'ID';
                   7819:         $text{'action'} = 'an ID';
1.615     raeburn  7820:         if ($count > 1) {
                   7821:             $text{'item'} = 'IDs';
                   7822:             $text{'action'} = 'IDs';
                   7823:         }
1.612     raeburn  7824:     }
1.674     bisitz   7825:     $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  7826:     if ($mode eq 'upload') {
                   7827:         if ($checkitem eq 'username') {
                   7828:             $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'}.");
                   7829:         } elsif ($checkitem eq 'id') {
1.674     bisitz   7830:             $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  7831:         }
1.669     raeburn  7832:     } elsif ($mode eq 'selfcreate') {
                   7833:         if ($checkitem eq 'id') {
                   7834:             $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.");
                   7835:         }
1.615     raeburn  7836:     } else {
                   7837:         if ($checkitem eq 'username') {
                   7838:             $response .= &mt("You must choose $text{'action'} with a different format --  $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
                   7839:         } elsif ($checkitem eq 'id') {
                   7840:             $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.");
                   7841:         }
1.612     raeburn  7842:     }
                   7843:     return $response;
1.585     raeburn  7844: }
                   7845: 
1.624     raeburn  7846: sub personal_data_fieldtitles {
                   7847:     my %fieldtitles = &Apache::lonlocal::texthash (
                   7848:                         id => 'Student/Employee ID',
                   7849:                         permanentemail => 'E-mail address',
                   7850:                         lastname => 'Last Name',
                   7851:                         firstname => 'First Name',
                   7852:                         middlename => 'Middle Name',
                   7853:                         generation => 'Generation',
                   7854:                         gen => 'Generation',
1.765     raeburn  7855:                         inststatus => 'Affiliation',
1.624     raeburn  7856:                    );
                   7857:     return %fieldtitles;
                   7858: }
                   7859: 
1.642     raeburn  7860: sub sorted_inst_types {
                   7861:     my ($dom) = @_;
                   7862:     my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
                   7863:     my $othertitle = &mt('All users');
                   7864:     if ($env{'request.course.id'}) {
1.668     raeburn  7865:         $othertitle  = &mt('Any users');
1.642     raeburn  7866:     }
                   7867:     my @types;
                   7868:     if (ref($order) eq 'ARRAY') {
                   7869:         @types = @{$order};
                   7870:     }
                   7871:     if (@types == 0) {
                   7872:         if (ref($usertypes) eq 'HASH') {
                   7873:             @types = sort(keys(%{$usertypes}));
                   7874:         }
                   7875:     }
                   7876:     if (keys(%{$usertypes}) > 0) {
                   7877:         $othertitle = &mt('Other users');
                   7878:     }
                   7879:     return ($othertitle,$usertypes,\@types);
                   7880: }
                   7881: 
1.645     raeburn  7882: sub get_institutional_codes {
                   7883:     my ($settings,$allcourses,$LC_code) = @_;
                   7884: # Get complete list of course sections to update
                   7885:     my @currsections = ();
                   7886:     my @currxlists = ();
                   7887:     my $coursecode = $$settings{'internal.coursecode'};
                   7888: 
                   7889:     if ($$settings{'internal.sectionnums'} ne '') {
                   7890:         @currsections = split(/,/,$$settings{'internal.sectionnums'});
                   7891:     }
                   7892: 
                   7893:     if ($$settings{'internal.crosslistings'} ne '') {
                   7894:         @currxlists = split(/,/,$$settings{'internal.crosslistings'});
                   7895:     }
                   7896: 
                   7897:     if (@currxlists > 0) {
                   7898:         foreach (@currxlists) {
                   7899:             if (m/^([^:]+):(\w*)$/) {
                   7900:                 unless (grep/^$1$/,@{$allcourses}) {
                   7901:                     push @{$allcourses},$1;
                   7902:                     $$LC_code{$1} = $2;
                   7903:                 }
                   7904:             }
                   7905:         }
                   7906:     }
                   7907:  
                   7908:     if (@currsections > 0) {
                   7909:         foreach (@currsections) {
                   7910:             if (m/^(\w+):(\w*)$/) {
                   7911:                 my $sec = $coursecode.$1;
                   7912:                 my $lc_sec = $2;
                   7913:                 unless (grep/^$sec$/,@{$allcourses}) {
                   7914:                     push @{$allcourses},$sec;
                   7915:                     $$LC_code{$sec} = $lc_sec;
                   7916:                 }
                   7917:             }
                   7918:         }
                   7919:     }
                   7920:     return;
                   7921: }
                   7922: 
1.112     bowersj2 7923: =pod
                   7924: 
1.780     raeburn  7925: =head1 Slot Helpers
                   7926: 
                   7927: =over 4
                   7928: 
                   7929: =item * sorted_slots()
                   7930: 
                   7931: Sorts an array of slot names in order of slot start time (earliest first). 
                   7932: 
                   7933: Inputs:
                   7934: 
                   7935: =over 4
                   7936: 
                   7937: slotsarr  - Reference to array of unsorted slot names.
                   7938: 
                   7939: slots     - Reference to hash of hash, where outer hash keys are slot names.
                   7940: 
1.549     albertel 7941: =back
                   7942: 
1.780     raeburn  7943: Returns:
                   7944: 
                   7945: =over 4
                   7946: 
                   7947: sorted   - An array of slot names sorted by the start time of the slot.
                   7948: 
                   7949: =back
                   7950: 
                   7951: =back
                   7952: 
                   7953: =cut
                   7954: 
                   7955: 
                   7956: sub sorted_slots {
                   7957:     my ($slotsarr,$slots) = @_;
                   7958:     my @sorted;
                   7959:     if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
                   7960:         @sorted =
                   7961:             sort {
                   7962:                      if (ref($slots->{$a}) && ref($slots->{$b})) {
                   7963:                          return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
                   7964:                      }
                   7965:                      if (ref($slots->{$a})) { return -1;}
                   7966:                      if (ref($slots->{$b})) { return 1;}
                   7967:                      return 0;
                   7968:                  } @{$slotsarr};
                   7969:     }
                   7970:     return @sorted;
                   7971: }
                   7972: 
                   7973: 
                   7974: =pod
                   7975: 
1.549     albertel 7976: =head1 HTTP Helpers
                   7977: 
                   7978: =over 4
                   7979: 
1.648     raeburn  7980: =item * &get_unprocessed_cgi($query,$possible_names)
1.112     bowersj2 7981: 
1.258     albertel 7982: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112     bowersj2 7983: $query.  The parameters listed in $possible_names (an array reference),
1.258     albertel 7984: will be set in $env{'form.name'} if they do not already exist.
1.112     bowersj2 7985: 
                   7986: Typically called with $ENV{'QUERY_STRING'} as the first parameter.  
                   7987: $possible_names is an ref to an array of form element names.  As an example:
                   7988: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258     albertel 7989: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112     bowersj2 7990: 
                   7991: =cut
1.1       albertel 7992: 
1.6       albertel 7993: sub get_unprocessed_cgi {
1.25      albertel 7994:   my ($query,$possible_names)= @_;
1.26      matthew  7995:   # $Apache::lonxml::debug=1;
1.356     albertel 7996:   foreach my $pair (split(/&/,$query)) {
                   7997:     my ($name, $value) = split(/=/,$pair);
1.369     www      7998:     $name = &unescape($name);
1.25      albertel 7999:     if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
                   8000:       $value =~ tr/+/ /;
                   8001:       $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258     albertel 8002:       unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25      albertel 8003:     }
1.16      harris41 8004:   }
1.6       albertel 8005: }
                   8006: 
1.112     bowersj2 8007: =pod
                   8008: 
1.648     raeburn  8009: =item * &cacheheader() 
1.112     bowersj2 8010: 
                   8011: returns cache-controlling header code
                   8012: 
                   8013: =cut
                   8014: 
1.7       albertel 8015: sub cacheheader {
1.258     albertel 8016:     unless ($env{'request.method'} eq 'GET') { return ''; }
1.216     albertel 8017:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
                   8018:     my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7       albertel 8019:                 <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
                   8020:                 <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216     albertel 8021:     return $output;
1.7       albertel 8022: }
                   8023: 
1.112     bowersj2 8024: =pod
                   8025: 
1.648     raeburn  8026: =item * &no_cache($r) 
1.112     bowersj2 8027: 
                   8028: specifies header code to not have cache
                   8029: 
                   8030: =cut
                   8031: 
1.9       albertel 8032: sub no_cache {
1.216     albertel 8033:     my ($r) = @_;
                   8034:     if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258     albertel 8035: 	$env{'request.method'} ne 'GET') { return ''; }
1.216     albertel 8036:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
                   8037:     $r->no_cache(1);
                   8038:     $r->header_out("Expires" => $date);
                   8039:     $r->header_out("Pragma" => "no-cache");
1.123     www      8040: }
                   8041: 
                   8042: sub content_type {
1.181     albertel 8043:     my ($r,$type,$charset) = @_;
1.299     foxr     8044:     if ($r) {
                   8045: 	#  Note that printout.pl calls this with undef for $r.
                   8046: 	&no_cache($r);
                   8047:     }
1.258     albertel 8048:     if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181     albertel 8049:     unless ($charset) {
                   8050: 	$charset=&Apache::lonlocal::current_encoding;
                   8051:     }
                   8052:     if ($charset) { $type.='; charset='.$charset; }
                   8053:     if ($r) {
                   8054: 	$r->content_type($type);
                   8055:     } else {
                   8056: 	print("Content-type: $type\n\n");
                   8057:     }
1.9       albertel 8058: }
1.25      albertel 8059: 
1.112     bowersj2 8060: =pod
                   8061: 
1.648     raeburn  8062: =item * &add_to_env($name,$value) 
1.112     bowersj2 8063: 
1.258     albertel 8064: adds $name to the %env hash with value
1.112     bowersj2 8065: $value, if $name already exists, the entry is converted to an array
                   8066: reference and $value is added to the array.
                   8067: 
                   8068: =cut
                   8069: 
1.25      albertel 8070: sub add_to_env {
                   8071:   my ($name,$value)=@_;
1.258     albertel 8072:   if (defined($env{$name})) {
                   8073:     if (ref($env{$name})) {
1.25      albertel 8074:       #already have multiple values
1.258     albertel 8075:       push(@{ $env{$name} },$value);
1.25      albertel 8076:     } else {
                   8077:       #first time seeing multiple values, convert hash entry to an arrayref
1.258     albertel 8078:       my $first=$env{$name};
                   8079:       undef($env{$name});
                   8080:       push(@{ $env{$name} },$first,$value);
1.25      albertel 8081:     }
                   8082:   } else {
1.258     albertel 8083:     $env{$name}=$value;
1.25      albertel 8084:   }
1.31      albertel 8085: }
1.149     albertel 8086: 
                   8087: =pod
                   8088: 
1.648     raeburn  8089: =item * &get_env_multiple($name) 
1.149     albertel 8090: 
1.258     albertel 8091: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149     albertel 8092: values may be defined and end up as an array ref.
                   8093: 
                   8094: returns an array of values
                   8095: 
                   8096: =cut
                   8097: 
                   8098: sub get_env_multiple {
                   8099:     my ($name) = @_;
                   8100:     my @values;
1.258     albertel 8101:     if (defined($env{$name})) {
1.149     albertel 8102:         # exists is it an array
1.258     albertel 8103:         if (ref($env{$name})) {
                   8104:             @values=@{ $env{$name} };
1.149     albertel 8105:         } else {
1.258     albertel 8106:             $values[0]=$env{$name};
1.149     albertel 8107:         }
                   8108:     }
                   8109:     return(@values);
                   8110: }
                   8111: 
1.660     raeburn  8112: sub ask_for_embedded_content {
                   8113:     my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
                   8114:     my $upload_output = '
                   8115:    <form name="upload_embedded" action="'.$actionurl.'"
                   8116:                   method="post" enctype="multipart/form-data">';
                   8117:     $upload_output .= $state;
1.661     raeburn  8118:     $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
1.660     raeburn  8119: 
                   8120:     my $num = 0;
                   8121:     foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
                   8122:         $upload_output .= &start_data_table_row().
                   8123:             '<td>'.$embed_file.'</td><td>';
                   8124:         if ($args->{'ignore_remote_references'}
                   8125:             && $embed_file =~ m{^\w+://}) {
                   8126:             $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
                   8127:         } elsif ($args->{'error_on_invalid_names'}
                   8128:             && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
                   8129: 
                   8130:             $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
                   8131: 
                   8132:         } else {
                   8133:             $upload_output .='
1.661     raeburn  8134:            <input name="embedded_item_'.$num.'" type="file" value="" />
1.660     raeburn  8135:            <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
                   8136:             my $attrib = join(':',@{$$allfiles{$embed_file}});
                   8137:             $upload_output .=
                   8138:                 "\n\t\t".
                   8139:                 '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
                   8140:                 $attrib.'" />';
                   8141:             if (exists($$codebase{$embed_file})) {
                   8142:                 $upload_output .=
                   8143:                     "\n\t\t".
                   8144:                     '<input name="codebase_'.$num.'" type="hidden" value="'.
                   8145:                     &escape($$codebase{$embed_file}).'" />';
                   8146:             }
                   8147:         }
                   8148:         $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
                   8149:         $num++;
                   8150:     }
                   8151:     $upload_output .= &Apache::loncommon::end_data_table().'<br />
                   8152:    <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
                   8153:    <input type ="submit" value="'.&mt('Upload Listed Files').'" />
                   8154:    '.&mt('(only files for which a location has been provided will be uploaded)').'
                   8155:    </form>';
                   8156:     return $upload_output;
                   8157: }
                   8158: 
1.661     raeburn  8159: sub upload_embedded {
                   8160:     my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
                   8161:         $current_disk_usage) = @_;
                   8162:     my $output;
                   8163:     for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
                   8164:         next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
                   8165:         my $orig_uploaded_filename =
                   8166:             $env{'form.embedded_item_'.$i.'.filename'};
                   8167: 
                   8168:         $env{'form.embedded_orig_'.$i} =
                   8169:             &unescape($env{'form.embedded_orig_'.$i});
                   8170:         my ($path,$fname) =
                   8171:             ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
                   8172:         # no path, whole string is fname
                   8173:         if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
                   8174: 
                   8175:         $path = $env{'form.currentpath'}.$path;
                   8176:         $fname = &Apache::lonnet::clean_filename($fname);
                   8177:         # See if there is anything left
                   8178:         next if ($fname eq '');
                   8179: 
                   8180:         # Check if file already exists as a file or directory.
                   8181:         my ($state,$msg);
                   8182:         if ($context eq 'portfolio') {
                   8183:             my $port_path = $dirpath;
                   8184:             if ($group ne '') {
                   8185:                 $port_path = "groups/$group/$port_path";
                   8186:             }
                   8187:             ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
                   8188:                                               $dir_root,$port_path,$disk_quota,
                   8189:                                               $current_disk_usage,$uname,$udom);
                   8190:             if ($state eq 'will_exceed_quota'
                   8191:                 || $state eq 'file_locked'
                   8192:                 || $state eq 'file_exists' ) {
                   8193:                 $output .= $msg;
                   8194:                 next;
                   8195:             }
                   8196:         } elsif (($context eq 'author') || ($context eq 'testbank')) {
                   8197:             ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
                   8198:             if ($state eq 'exists') {
                   8199:                 $output .= $msg;
                   8200:                 next;
                   8201:             }
                   8202:         }
                   8203:         # Check if extension is valid
                   8204:         if (($fname =~ /\.(\w+)$/) &&
                   8205:             (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
                   8206:             $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
                   8207:             next;
                   8208:         } elsif (($fname =~ /\.(\w+)$/) &&
                   8209:                  (!defined(&Apache::loncommon::fileembstyle($1)))) {
                   8210:             $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
                   8211:             next;
                   8212:         } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
                   8213:             $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
                   8214:             next;
                   8215:         }
                   8216: 
                   8217:         $env{'form.embedded_item_'.$i.'.filename'}=$fname;
                   8218:         if ($context eq 'portfolio') {
                   8219:             my $result=
                   8220:                 &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
                   8221:                                                 $dirpath.$path);
                   8222:             if ($result !~ m|^/uploaded/|) {
                   8223:                 $output .= '<span class="LC_error">'
                   8224:                       .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
                   8225:                            ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
                   8226:                       .'</span><br />';
                   8227:                 next;
                   8228:             } else {
                   8229:                 $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
                   8230:                            $path.$fname.'</span>').'</p>';     
                   8231:             }
                   8232:         } else {
                   8233: # Save the file
                   8234:             my $target = $env{'form.embedded_item_'.$i};
                   8235:             my $fullpath = $dir_root.$dirpath.'/'.$path;
                   8236:             my $dest = $fullpath.$fname;
                   8237:             my $url = $url_root.$dirpath.'/'.$path.$fname;
                   8238:             my @parts=split(/\//,$fullpath);
                   8239:             my $count;
                   8240:             my $filepath = $dir_root;
                   8241:             for ($count=4;$count<=$#parts;$count++) {
                   8242:                 $filepath .= "/$parts[$count]";
                   8243:                 if ((-e $filepath)!=1) {
                   8244:                     mkdir($filepath,0770);
                   8245:                 }
                   8246:             }
                   8247:             my $fh;
                   8248:             if (!open($fh,'>'.$dest)) {
                   8249:                 &Apache::lonnet::logthis('Failed to create '.$dest);
                   8250:                 $output .= '<span class="LC_error">'.
                   8251:                            &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
                   8252:                            '</span><br />';
                   8253:             } else {
                   8254:                 if (!print $fh $env{'form.embedded_item_'.$i}) {
                   8255:                     &Apache::lonnet::logthis('Failed to write to '.$dest);
                   8256:                     $output .= '<span class="LC_error">'.
                   8257:                               &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
                   8258:                               '</span><br />';
                   8259:                 } else {
                   8260:                     if ($context eq 'testbank') {
                   8261:                         $output .= &mt('Embedded file uploaded successfully:').
                   8262:                                    '&nbsp;<a href="'.$url.'">'.
                   8263:                                    $orig_uploaded_filename.'</a><br />';
                   8264:                     } else {
1.705     tempelho 8265:                         $output .= '<span class=\"LC_fontsize_large\">'.
1.661     raeburn  8266:                                    &mt('View embedded file: [_1]','<a href="'.$url.'">'.
1.705     tempelho 8267:                                    $orig_uploaded_filename.'</a>').'</span><br />';
1.661     raeburn  8268:                     }
                   8269:                 }
                   8270:                 close($fh);
                   8271:             }
                   8272:         }
                   8273:     }
                   8274:     return $output;
                   8275: }
                   8276: 
                   8277: sub check_for_existing {
                   8278:     my ($path,$fname,$element) = @_;
                   8279:     my ($state,$msg);
                   8280:     if (-d $path.'/'.$fname) {
                   8281:         $state = 'exists';
                   8282:         $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
                   8283:     } elsif (-e $path.'/'.$fname) {
                   8284:         $state = 'exists';
                   8285:         $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
                   8286:     }
                   8287:     if ($state eq 'exists') {
                   8288:         $msg = '<span class="LC_error">'.$msg.'</span><br />';
                   8289:     }
                   8290:     return ($state,$msg);
                   8291: }
                   8292: 
                   8293: sub check_for_upload {
                   8294:     my ($path,$fname,$group,$element,$portfolio_root,$port_path,
                   8295:         $disk_quota,$current_disk_usage,$uname,$udom) = @_;
                   8296:     my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
                   8297:     my $getpropath = 1;
                   8298:     my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
                   8299:                                             $getpropath);
                   8300:     my $found_file = 0;
                   8301:     my $locked_file = 0;
                   8302:     foreach my $line (@dir_list) {
                   8303:         my ($file_name)=split(/\&/,$line,2);
                   8304:         if ($file_name eq $fname){
                   8305:             $file_name = $path.$file_name;
                   8306:             if ($group ne '') {
                   8307:                 $file_name = $group.$file_name;
                   8308:             }
                   8309:             $found_file = 1;
                   8310:             if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
                   8311:                 $locked_file = 1;
                   8312:             }
                   8313:         }
                   8314:     }
                   8315:     if (($current_disk_usage + $filesize) > $disk_quota){
                   8316:         my $msg = '<span class="LC_error">'.
                   8317:                 &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
                   8318:                   '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
                   8319:         return ('will_exceed_quota',$msg);
                   8320:     } elsif ($found_file) {
                   8321:         if ($locked_file) {
                   8322:             my $msg = '<span class="LC_error">';
                   8323:             $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>');
                   8324:             $msg .= '</span><br />';
                   8325:             $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
                   8326:             return ('file_locked',$msg);
                   8327:         } else {
                   8328:             my $msg = '<span class="LC_error">';
                   8329:             $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'});
                   8330:             $msg .= '</span>';
                   8331:             $msg .= '<br />';
                   8332:             $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
                   8333:             return ('file_exists',$msg);
                   8334:         }
                   8335:     }
                   8336: }
                   8337: 
1.31      albertel 8338: 
1.41      ng       8339: =pod
1.45      matthew  8340: 
1.464     albertel 8341: =back
1.41      ng       8342: 
1.112     bowersj2 8343: =head1 CSV Upload/Handling functions
1.38      albertel 8344: 
1.41      ng       8345: =over 4
                   8346: 
1.648     raeburn  8347: =item * &upfile_store($r)
1.41      ng       8348: 
                   8349: Store uploaded file, $r should be the HTTP Request object,
1.258     albertel 8350: needs $env{'form.upfile'}
1.41      ng       8351: returns $datatoken to be put into hidden field
                   8352: 
                   8353: =cut
1.31      albertel 8354: 
                   8355: sub upfile_store {
                   8356:     my $r=shift;
1.258     albertel 8357:     $env{'form.upfile'}=~s/\r/\n/gs;
                   8358:     $env{'form.upfile'}=~s/\f/\n/gs;
                   8359:     $env{'form.upfile'}=~s/\n+/\n/gs;
                   8360:     $env{'form.upfile'}=~s/\n+$//gs;
1.31      albertel 8361: 
1.258     albertel 8362:     my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
                   8363: 	'_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31      albertel 8364:     {
1.158     raeburn  8365:         my $datafile = $r->dir_config('lonDaemons').
                   8366:                            '/tmp/'.$datatoken.'.tmp';
                   8367:         if ( open(my $fh,">$datafile") ) {
1.258     albertel 8368:             print $fh $env{'form.upfile'};
1.158     raeburn  8369:             close($fh);
                   8370:         }
1.31      albertel 8371:     }
                   8372:     return $datatoken;
                   8373: }
                   8374: 
1.56      matthew  8375: =pod
                   8376: 
1.648     raeburn  8377: =item * &load_tmp_file($r)
1.41      ng       8378: 
                   8379: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258     albertel 8380: needs $env{'form.datatoken'},
                   8381: sets $env{'form.upfile'} to the contents of the file
1.41      ng       8382: 
                   8383: =cut
1.31      albertel 8384: 
                   8385: sub load_tmp_file {
                   8386:     my $r=shift;
                   8387:     my @studentdata=();
                   8388:     {
1.158     raeburn  8389:         my $studentfile = $r->dir_config('lonDaemons').
1.258     albertel 8390:                               '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158     raeburn  8391:         if ( open(my $fh,"<$studentfile") ) {
                   8392:             @studentdata=<$fh>;
                   8393:             close($fh);
                   8394:         }
1.31      albertel 8395:     }
1.258     albertel 8396:     $env{'form.upfile'}=join('',@studentdata);
1.31      albertel 8397: }
                   8398: 
1.56      matthew  8399: =pod
                   8400: 
1.648     raeburn  8401: =item * &upfile_record_sep()
1.41      ng       8402: 
                   8403: Separate uploaded file into records
                   8404: returns array of records,
1.258     albertel 8405: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41      ng       8406: 
                   8407: =cut
1.31      albertel 8408: 
                   8409: sub upfile_record_sep {
1.258     albertel 8410:     if ($env{'form.upfiletype'} eq 'xml') {
1.31      albertel 8411:     } else {
1.248     albertel 8412: 	my @records;
1.258     albertel 8413: 	foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248     albertel 8414: 	    if ($line=~/^\s*$/) { next; }
                   8415: 	    push(@records,$line);
                   8416: 	}
                   8417: 	return @records;
1.31      albertel 8418:     }
                   8419: }
                   8420: 
1.56      matthew  8421: =pod
                   8422: 
1.648     raeburn  8423: =item * &record_sep($record)
1.41      ng       8424: 
1.258     albertel 8425: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41      ng       8426: 
                   8427: =cut
                   8428: 
1.263     www      8429: sub takeleft {
                   8430:     my $index=shift;
                   8431:     return substr('0000'.$index,-4,4);
                   8432: }
                   8433: 
1.31      albertel 8434: sub record_sep {
                   8435:     my $record=shift;
                   8436:     my %components=();
1.258     albertel 8437:     if ($env{'form.upfiletype'} eq 'xml') {
                   8438:     } elsif ($env{'form.upfiletype'} eq 'space') {
1.31      albertel 8439:         my $i=0;
1.356     albertel 8440:         foreach my $field (split(/\s+/,$record)) {
1.31      albertel 8441:             $field=~s/^(\"|\')//;
                   8442:             $field=~s/(\"|\')$//;
1.263     www      8443:             $components{&takeleft($i)}=$field;
1.31      albertel 8444:             $i++;
                   8445:         }
1.258     albertel 8446:     } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31      albertel 8447:         my $i=0;
1.356     albertel 8448:         foreach my $field (split(/\t/,$record)) {
1.31      albertel 8449:             $field=~s/^(\"|\')//;
                   8450:             $field=~s/(\"|\')$//;
1.263     www      8451:             $components{&takeleft($i)}=$field;
1.31      albertel 8452:             $i++;
                   8453:         }
                   8454:     } else {
1.561     www      8455:         my $separator=',';
1.480     banghart 8456:         if ($env{'form.upfiletype'} eq 'semisv') {
1.561     www      8457:             $separator=';';
1.480     banghart 8458:         }
1.31      albertel 8459:         my $i=0;
1.561     www      8460: # the character we are looking for to indicate the end of a quote or a record 
                   8461:         my $looking_for=$separator;
                   8462: # do not add the characters to the fields
                   8463:         my $ignore=0;
                   8464: # we just encountered a separator (or the beginning of the record)
                   8465:         my $just_found_separator=1;
                   8466: # store the field we are working on here
                   8467:         my $field='';
                   8468: # work our way through all characters in record
                   8469:         foreach my $character ($record=~/(.)/g) {
                   8470:             if ($character eq $looking_for) {
                   8471:                if ($character ne $separator) {
                   8472: # Found the end of a quote, again looking for separator
                   8473:                   $looking_for=$separator;
                   8474:                   $ignore=1;
                   8475:                } else {
                   8476: # Found a separator, store away what we got
                   8477:                   $components{&takeleft($i)}=$field;
                   8478: 	          $i++;
                   8479:                   $just_found_separator=1;
                   8480:                   $ignore=0;
                   8481:                   $field='';
                   8482:                }
                   8483:                next;
                   8484:             }
                   8485: # single or double quotation marks after a separator indicate beginning of a quote
                   8486: # we are now looking for the end of the quote and need to ignore separators
                   8487:             if ((($character eq '"') || ($character eq "'")) && ($just_found_separator))  {
                   8488:                $looking_for=$character;
                   8489:                next;
                   8490:             }
                   8491: # ignore would be true after we reached the end of a quote
                   8492:             if ($ignore) { next; }
                   8493:             if (($just_found_separator) && ($character=~/\s/)) { next; }
                   8494:             $field.=$character;
                   8495:             $just_found_separator=0; 
1.31      albertel 8496:         }
1.561     www      8497: # catch the very last entry, since we never encountered the separator
                   8498:         $components{&takeleft($i)}=$field;
1.31      albertel 8499:     }
                   8500:     return %components;
                   8501: }
                   8502: 
1.144     matthew  8503: ######################################################
                   8504: ######################################################
                   8505: 
1.56      matthew  8506: =pod
                   8507: 
1.648     raeburn  8508: =item * &upfile_select_html()
1.41      ng       8509: 
1.144     matthew  8510: Return HTML code to select a file from the users machine and specify 
                   8511: the file type.
1.41      ng       8512: 
                   8513: =cut
                   8514: 
1.144     matthew  8515: ######################################################
                   8516: ######################################################
1.31      albertel 8517: sub upfile_select_html {
1.144     matthew  8518:     my %Types = (
                   8519:                  csv   => &mt('CSV (comma separated values, spreadsheet)'),
1.480     banghart 8520:                  semisv => &mt('Semicolon separated values'),
1.144     matthew  8521:                  space => &mt('Space separated'),
                   8522:                  tab   => &mt('Tabulator separated'),
                   8523: #                 xml   => &mt('HTML/XML'),
                   8524:                  );
                   8525:     my $Str = '<input type="file" name="upfile" size="50" />'.
1.727     riegler  8526:         '<br />'.&mt('Type').': <select name="upfiletype">';
1.144     matthew  8527:     foreach my $type (sort(keys(%Types))) {
                   8528:         $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
                   8529:     }
                   8530:     $Str .= "</select>\n";
                   8531:     return $Str;
1.31      albertel 8532: }
                   8533: 
1.301     albertel 8534: sub get_samples {
                   8535:     my ($records,$toget) = @_;
                   8536:     my @samples=({});
                   8537:     my $got=0;
                   8538:     foreach my $rec (@$records) {
                   8539: 	my %temp = &record_sep($rec);
                   8540: 	if (! grep(/\S/, values(%temp))) { next; }
                   8541: 	if (%temp) {
                   8542: 	    $samples[$got]=\%temp;
                   8543: 	    $got++;
                   8544: 	    if ($got == $toget) { last; }
                   8545: 	}
                   8546:     }
                   8547:     return \@samples;
                   8548: }
                   8549: 
1.144     matthew  8550: ######################################################
                   8551: ######################################################
                   8552: 
1.56      matthew  8553: =pod
                   8554: 
1.648     raeburn  8555: =item * &csv_print_samples($r,$records)
1.41      ng       8556: 
                   8557: Prints a table of sample values from each column uploaded $r is an
                   8558: Apache Request ref, $records is an arrayref from
                   8559: &Apache::loncommon::upfile_record_sep
                   8560: 
                   8561: =cut
                   8562: 
1.144     matthew  8563: ######################################################
                   8564: ######################################################
1.31      albertel 8565: sub csv_print_samples {
                   8566:     my ($r,$records) = @_;
1.662     bisitz   8567:     my $samples = &get_samples($records,5);
1.301     albertel 8568: 
1.594     raeburn  8569:     $r->print(&mt('Samples').'<br />'.&start_data_table().
                   8570:               &start_data_table_header_row());
1.356     albertel 8571:     foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) { 
1.845     bisitz   8572:         $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594     raeburn  8573:     $r->print(&end_data_table_header_row());
1.301     albertel 8574:     foreach my $hash (@$samples) {
1.594     raeburn  8575: 	$r->print(&start_data_table_row());
1.356     albertel 8576: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31      albertel 8577: 	    $r->print('<td>');
1.356     albertel 8578: 	    if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31      albertel 8579: 	    $r->print('</td>');
                   8580: 	}
1.594     raeburn  8581: 	$r->print(&end_data_table_row());
1.31      albertel 8582:     }
1.594     raeburn  8583:     $r->print(&end_data_table().'<br />'."\n");
1.31      albertel 8584: }
                   8585: 
1.144     matthew  8586: ######################################################
                   8587: ######################################################
                   8588: 
1.56      matthew  8589: =pod
                   8590: 
1.648     raeburn  8591: =item * &csv_print_select_table($r,$records,$d)
1.41      ng       8592: 
                   8593: Prints a table to create associations between values and table columns.
1.144     matthew  8594: 
1.41      ng       8595: $r is an Apache Request ref,
                   8596: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174     matthew  8597: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41      ng       8598: 
                   8599: =cut
                   8600: 
1.144     matthew  8601: ######################################################
                   8602: ######################################################
1.31      albertel 8603: sub csv_print_select_table {
                   8604:     my ($r,$records,$d) = @_;
1.301     albertel 8605:     my $i=0;
                   8606:     my $samples = &get_samples($records,1);
1.144     matthew  8607:     $r->print(&mt('Associate columns with student attributes.')."\n".
1.594     raeburn  8608: 	      &start_data_table().&start_data_table_header_row().
1.144     matthew  8609:               '<th>'.&mt('Attribute').'</th>'.
1.594     raeburn  8610:               '<th>'.&mt('Column').'</th>'.
                   8611:               &end_data_table_header_row()."\n");
1.356     albertel 8612:     foreach my $array_ref (@$d) {
                   8613: 	my ($value,$display,$defaultcol)=@{ $array_ref };
1.729     raeburn  8614: 	$r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31      albertel 8615: 
                   8616: 	$r->print('<td><select name=f'.$i.
1.32      matthew  8617: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.31      albertel 8618: 	$r->print('<option value="none"></option>');
1.356     albertel 8619: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
                   8620: 	    $r->print('<option value="'.$sample.'"'.
                   8621:                       ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662     bisitz   8622:                       '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31      albertel 8623: 	}
1.594     raeburn  8624: 	$r->print('</select></td>'.&end_data_table_row()."\n");
1.31      albertel 8625: 	$i++;
                   8626:     }
1.594     raeburn  8627:     $r->print(&end_data_table());
1.31      albertel 8628:     $i--;
                   8629:     return $i;
                   8630: }
1.56      matthew  8631: 
1.144     matthew  8632: ######################################################
                   8633: ######################################################
                   8634: 
1.56      matthew  8635: =pod
1.31      albertel 8636: 
1.648     raeburn  8637: =item * &csv_samples_select_table($r,$records,$d)
1.41      ng       8638: 
                   8639: Prints a table of sample values from the upload and can make associate samples to internal names.
                   8640: 
                   8641: $r is an Apache Request ref,
                   8642: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
                   8643: $d is an array of 2 element arrays (internal name, displayed name)
                   8644: 
                   8645: =cut
                   8646: 
1.144     matthew  8647: ######################################################
                   8648: ######################################################
1.31      albertel 8649: sub csv_samples_select_table {
                   8650:     my ($r,$records,$d) = @_;
                   8651:     my $i=0;
1.144     matthew  8652:     #
1.662     bisitz   8653:     my $max_samples = 5;
                   8654:     my $samples = &get_samples($records,$max_samples);
1.594     raeburn  8655:     $r->print(&start_data_table().
                   8656:               &start_data_table_header_row().'<th>'.
                   8657:               &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
                   8658:               &end_data_table_header_row());
1.301     albertel 8659: 
                   8660:     foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594     raeburn  8661: 	$r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32      matthew  8662: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.301     albertel 8663: 	foreach my $option (@$d) {
                   8664: 	    my ($value,$display,$defaultcol)=@{ $option };
1.174     matthew  8665: 	    $r->print('<option value="'.$value.'"'.
1.253     albertel 8666:                       ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174     matthew  8667:                       $display.'</option>');
1.31      albertel 8668: 	}
                   8669: 	$r->print('</select></td><td>');
1.662     bisitz   8670: 	foreach my $line (0..($max_samples-1)) {
1.301     albertel 8671: 	    if (defined($samples->[$line]{$key})) { 
                   8672: 		$r->print($samples->[$line]{$key}."<br />\n"); 
                   8673: 	    }
                   8674: 	}
1.594     raeburn  8675: 	$r->print('</td>'.&end_data_table_row());
1.31      albertel 8676: 	$i++;
                   8677:     }
1.594     raeburn  8678:     $r->print(&end_data_table());
1.31      albertel 8679:     $i--;
                   8680:     return($i);
1.115     matthew  8681: }
                   8682: 
1.144     matthew  8683: ######################################################
                   8684: ######################################################
                   8685: 
1.115     matthew  8686: =pod
                   8687: 
1.648     raeburn  8688: =item * &clean_excel_name($name)
1.115     matthew  8689: 
                   8690: Returns a replacement for $name which does not contain any illegal characters.
                   8691: 
                   8692: =cut
                   8693: 
1.144     matthew  8694: ######################################################
                   8695: ######################################################
1.115     matthew  8696: sub clean_excel_name {
                   8697:     my ($name) = @_;
                   8698:     $name =~ s/[:\*\?\/\\]//g;
                   8699:     if (length($name) > 31) {
                   8700:         $name = substr($name,0,31);
                   8701:     }
                   8702:     return $name;
1.25      albertel 8703: }
1.84      albertel 8704: 
1.85      albertel 8705: =pod
                   8706: 
1.648     raeburn  8707: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85      albertel 8708: 
                   8709: Returns either 1 or undef
                   8710: 
                   8711: 1 if the part is to be hidden, undef if it is to be shown
                   8712: 
                   8713: Arguments are:
                   8714: 
                   8715: $id the id of the part to be checked
                   8716: $symb, optional the symb of the resource to check
                   8717: $udom, optional the domain of the user to check for
                   8718: $uname, optional the username of the user to check for
                   8719: 
                   8720: =cut
1.84      albertel 8721: 
                   8722: sub check_if_partid_hidden {
                   8723:     my ($id,$symb,$udom,$uname) = @_;
1.133     albertel 8724:     my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84      albertel 8725: 					 $symb,$udom,$uname);
1.141     albertel 8726:     my $truth=1;
                   8727:     #if the string starts with !, then the list is the list to show not hide
                   8728:     if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84      albertel 8729:     my @hiddenlist=split(/,/,$hiddenparts);
                   8730:     foreach my $checkid (@hiddenlist) {
1.141     albertel 8731: 	if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84      albertel 8732:     }
1.141     albertel 8733:     return !$truth;
1.84      albertel 8734: }
1.127     matthew  8735: 
1.138     matthew  8736: 
                   8737: ############################################################
                   8738: ############################################################
                   8739: 
                   8740: =pod
                   8741: 
1.157     matthew  8742: =back 
                   8743: 
1.138     matthew  8744: =head1 cgi-bin script and graphing routines
                   8745: 
1.157     matthew  8746: =over 4
                   8747: 
1.648     raeburn  8748: =item * &get_cgi_id()
1.138     matthew  8749: 
                   8750: Inputs: none
                   8751: 
                   8752: Returns an id which can be used to pass environment variables
                   8753: to various cgi-bin scripts.  These environment variables will
                   8754: be removed from the users environment after a given time by
                   8755: the routine &Apache::lonnet::transfer_profile_to_env.
                   8756: 
                   8757: =cut
                   8758: 
                   8759: ############################################################
                   8760: ############################################################
1.152     albertel 8761: my $uniq=0;
1.136     matthew  8762: sub get_cgi_id {
1.154     albertel 8763:     $uniq=($uniq+1)%100000;
1.280     albertel 8764:     return (time.'_'.$$.'_'.$uniq);
1.136     matthew  8765: }
                   8766: 
1.127     matthew  8767: ############################################################
                   8768: ############################################################
                   8769: 
                   8770: =pod
                   8771: 
1.648     raeburn  8772: =item * &DrawBarGraph()
1.127     matthew  8773: 
1.138     matthew  8774: Facilitates the plotting of data in a (stacked) bar graph.
                   8775: Puts plot definition data into the users environment in order for 
                   8776: graph.png to plot it.  Returns an <img> tag for the plot.
                   8777: The bars on the plot are labeled '1','2',...,'n'.
                   8778: 
                   8779: Inputs:
                   8780: 
                   8781: =over 4
                   8782: 
                   8783: =item $Title: string, the title of the plot
                   8784: 
                   8785: =item $xlabel: string, text describing the X-axis of the plot
                   8786: 
                   8787: =item $ylabel: string, text describing the Y-axis of the plot
                   8788: 
                   8789: =item $Max: scalar, the maximum Y value to use in the plot
                   8790: If $Max is < any data point, the graph will not be rendered.
                   8791: 
1.140     matthew  8792: =item $colors: array ref holding the colors to be used for the data sets when
1.138     matthew  8793: they are plotted.  If undefined, default values will be used.
                   8794: 
1.178     matthew  8795: =item $labels: array ref holding the labels to use on the x-axis for the bars.
                   8796: 
1.138     matthew  8797: =item @Values: An array of array references.  Each array reference holds data
                   8798: to be plotted in a stacked bar chart.
                   8799: 
1.239     matthew  8800: =item If the final element of @Values is a hash reference the key/value
                   8801: pairs will be added to the graph definition.
                   8802: 
1.138     matthew  8803: =back
                   8804: 
                   8805: Returns:
                   8806: 
                   8807: An <img> tag which references graph.png and the appropriate identifying
                   8808: information for the plot.
                   8809: 
1.127     matthew  8810: =cut
                   8811: 
                   8812: ############################################################
                   8813: ############################################################
1.134     matthew  8814: sub DrawBarGraph {
1.178     matthew  8815:     my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134     matthew  8816:     #
                   8817:     if (! defined($colors)) {
                   8818:         $colors = ['#33ff00', 
                   8819:                   '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
                   8820:                   '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
                   8821:                   ]; 
                   8822:     }
1.228     matthew  8823:     my $extra_settings = {};
                   8824:     if (ref($Values[-1]) eq 'HASH') {
                   8825:         $extra_settings = pop(@Values);
                   8826:     }
1.127     matthew  8827:     #
1.136     matthew  8828:     my $identifier = &get_cgi_id();
                   8829:     my $id = 'cgi.'.$identifier;        
1.129     matthew  8830:     if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127     matthew  8831:         return '';
                   8832:     }
1.225     matthew  8833:     #
                   8834:     my @Labels;
                   8835:     if (defined($labels)) {
                   8836:         @Labels = @$labels;
                   8837:     } else {
                   8838:         for (my $i=0;$i<@{$Values[0]};$i++) {
                   8839:             push (@Labels,$i+1);
                   8840:         }
                   8841:     }
                   8842:     #
1.129     matthew  8843:     my $NumBars = scalar(@{$Values[0]});
1.225     matthew  8844:     if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129     matthew  8845:     my %ValuesHash;
                   8846:     my $NumSets=1;
                   8847:     foreach my $array (@Values) {
                   8848:         next if (! ref($array));
1.136     matthew  8849:         $ValuesHash{$id.'.data.'.$NumSets++} = 
1.132     matthew  8850:             join(',',@$array);
1.129     matthew  8851:     }
1.127     matthew  8852:     #
1.136     matthew  8853:     my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225     matthew  8854:     if ($NumBars < 3) {
                   8855:         $width = 120+$NumBars*32;
1.220     matthew  8856:         $xskip = 1;
1.225     matthew  8857:         $bar_width = 30;
                   8858:     } elsif ($NumBars < 5) {
                   8859:         $width = 120+$NumBars*20;
                   8860:         $xskip = 1;
                   8861:         $bar_width = 20;
1.220     matthew  8862:     } elsif ($NumBars < 10) {
1.136     matthew  8863:         $width = 120+$NumBars*15;
                   8864:         $xskip = 1;
                   8865:         $bar_width = 15;
                   8866:     } elsif ($NumBars <= 25) {
                   8867:         $width = 120+$NumBars*11;
                   8868:         $xskip = 5;
                   8869:         $bar_width = 8;
                   8870:     } elsif ($NumBars <= 50) {
                   8871:         $width = 120+$NumBars*8;
                   8872:         $xskip = 5;
                   8873:         $bar_width = 4;
                   8874:     } else {
                   8875:         $width = 120+$NumBars*8;
                   8876:         $xskip = 5;
                   8877:         $bar_width = 4;
                   8878:     }
                   8879:     #
1.137     matthew  8880:     $Max = 1 if ($Max < 1);
                   8881:     if ( int($Max) < $Max ) {
                   8882:         $Max++;
                   8883:         $Max = int($Max);
                   8884:     }
1.127     matthew  8885:     $Title  = '' if (! defined($Title));
                   8886:     $xlabel = '' if (! defined($xlabel));
                   8887:     $ylabel = '' if (! defined($ylabel));
1.369     www      8888:     $ValuesHash{$id.'.title'}    = &escape($Title);
                   8889:     $ValuesHash{$id.'.xlabel'}   = &escape($xlabel);
                   8890:     $ValuesHash{$id.'.ylabel'}   = &escape($ylabel);
1.137     matthew  8891:     $ValuesHash{$id.'.y_max_value'} = $Max;
1.136     matthew  8892:     $ValuesHash{$id.'.NumBars'}  = $NumBars;
                   8893:     $ValuesHash{$id.'.NumSets'}  = $NumSets;
                   8894:     $ValuesHash{$id.'.PlotType'} = 'bar';
                   8895:     $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   8896:     $ValuesHash{$id.'.height'}   = $height;
                   8897:     $ValuesHash{$id.'.width'}    = $width;
                   8898:     $ValuesHash{$id.'.xskip'}    = $xskip;
                   8899:     $ValuesHash{$id.'.bar_width'} = $bar_width;
                   8900:     $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127     matthew  8901:     #
1.228     matthew  8902:     # Deal with other parameters
                   8903:     while (my ($key,$value) = each(%$extra_settings)) {
                   8904:         $ValuesHash{$id.'.'.$key} = $value;
                   8905:     }
                   8906:     #
1.646     raeburn  8907:     &Apache::lonnet::appenv(\%ValuesHash);
1.137     matthew  8908:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   8909: }
                   8910: 
                   8911: ############################################################
                   8912: ############################################################
                   8913: 
                   8914: =pod
                   8915: 
1.648     raeburn  8916: =item * &DrawXYGraph()
1.137     matthew  8917: 
1.138     matthew  8918: Facilitates the plotting of data in an XY graph.
                   8919: Puts plot definition data into the users environment in order for 
                   8920: graph.png to plot it.  Returns an <img> tag for the plot.
                   8921: 
                   8922: Inputs:
                   8923: 
                   8924: =over 4
                   8925: 
                   8926: =item $Title: string, the title of the plot
                   8927: 
                   8928: =item $xlabel: string, text describing the X-axis of the plot
                   8929: 
                   8930: =item $ylabel: string, text describing the Y-axis of the plot
                   8931: 
                   8932: =item $Max: scalar, the maximum Y value to use in the plot
                   8933: If $Max is < any data point, the graph will not be rendered.
                   8934: 
                   8935: =item $colors: Array ref containing the hex color codes for the data to be 
                   8936: plotted in.  If undefined, default values will be used.
                   8937: 
                   8938: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   8939: 
                   8940: =item $Ydata: Array ref containing Array refs.  
1.185     www      8941: Each of the contained arrays will be plotted as a separate curve.
1.138     matthew  8942: 
                   8943: =item %Values: hash indicating or overriding any default values which are 
                   8944: passed to graph.png.  
                   8945: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   8946: 
                   8947: =back
                   8948: 
                   8949: Returns:
                   8950: 
                   8951: An <img> tag which references graph.png and the appropriate identifying
                   8952: information for the plot.
                   8953: 
1.137     matthew  8954: =cut
                   8955: 
                   8956: ############################################################
                   8957: ############################################################
                   8958: sub DrawXYGraph {
                   8959:     my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
                   8960:     #
                   8961:     # Create the identifier for the graph
                   8962:     my $identifier = &get_cgi_id();
                   8963:     my $id = 'cgi.'.$identifier;
                   8964:     #
                   8965:     $Title  = '' if (! defined($Title));
                   8966:     $xlabel = '' if (! defined($xlabel));
                   8967:     $ylabel = '' if (! defined($ylabel));
                   8968:     my %ValuesHash = 
                   8969:         (
1.369     www      8970:          $id.'.title'  => &escape($Title),
                   8971:          $id.'.xlabel' => &escape($xlabel),
                   8972:          $id.'.ylabel' => &escape($ylabel),
1.137     matthew  8973:          $id.'.y_max_value'=> $Max,
                   8974:          $id.'.labels'     => join(',',@$Xlabels),
                   8975:          $id.'.PlotType'   => 'XY',
                   8976:          );
                   8977:     #
                   8978:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   8979:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   8980:     }
                   8981:     #
                   8982:     if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
                   8983:         return '';
                   8984:     }
                   8985:     my $NumSets=1;
1.138     matthew  8986:     foreach my $array (@{$Ydata}){
1.137     matthew  8987:         next if (! ref($array));
                   8988:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
                   8989:     }
1.138     matthew  8990:     $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137     matthew  8991:     #
                   8992:     # Deal with other parameters
                   8993:     while (my ($key,$value) = each(%Values)) {
                   8994:         $ValuesHash{$id.'.'.$key} = $value;
1.127     matthew  8995:     }
                   8996:     #
1.646     raeburn  8997:     &Apache::lonnet::appenv(\%ValuesHash);
1.136     matthew  8998:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   8999: }
                   9000: 
                   9001: ############################################################
                   9002: ############################################################
                   9003: 
                   9004: =pod
                   9005: 
1.648     raeburn  9006: =item * &DrawXYYGraph()
1.138     matthew  9007: 
                   9008: Facilitates the plotting of data in an XY graph with two Y axes.
                   9009: Puts plot definition data into the users environment in order for 
                   9010: graph.png to plot it.  Returns an <img> tag for the plot.
                   9011: 
                   9012: Inputs:
                   9013: 
                   9014: =over 4
                   9015: 
                   9016: =item $Title: string, the title of the plot
                   9017: 
                   9018: =item $xlabel: string, text describing the X-axis of the plot
                   9019: 
                   9020: =item $ylabel: string, text describing the Y-axis of the plot
                   9021: 
                   9022: =item $colors: Array ref containing the hex color codes for the data to be 
                   9023: plotted in.  If undefined, default values will be used.
                   9024: 
                   9025: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   9026: 
                   9027: =item $Ydata1: The first data set
                   9028: 
                   9029: =item $Min1: The minimum value of the left Y-axis
                   9030: 
                   9031: =item $Max1: The maximum value of the left Y-axis
                   9032: 
                   9033: =item $Ydata2: The second data set
                   9034: 
                   9035: =item $Min2: The minimum value of the right Y-axis
                   9036: 
                   9037: =item $Max2: The maximum value of the left Y-axis
                   9038: 
                   9039: =item %Values: hash indicating or overriding any default values which are 
                   9040: passed to graph.png.  
                   9041: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   9042: 
                   9043: =back
                   9044: 
                   9045: Returns:
                   9046: 
                   9047: An <img> tag which references graph.png and the appropriate identifying
                   9048: information for the plot.
1.136     matthew  9049: 
                   9050: =cut
                   9051: 
                   9052: ############################################################
                   9053: ############################################################
1.137     matthew  9054: sub DrawXYYGraph {
                   9055:     my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
                   9056:                                         $Ydata2,$Min2,$Max2,%Values)=@_;
1.136     matthew  9057:     #
                   9058:     # Create the identifier for the graph
                   9059:     my $identifier = &get_cgi_id();
                   9060:     my $id = 'cgi.'.$identifier;
                   9061:     #
                   9062:     $Title  = '' if (! defined($Title));
                   9063:     $xlabel = '' if (! defined($xlabel));
                   9064:     $ylabel = '' if (! defined($ylabel));
                   9065:     my %ValuesHash = 
                   9066:         (
1.369     www      9067:          $id.'.title'  => &escape($Title),
                   9068:          $id.'.xlabel' => &escape($xlabel),
                   9069:          $id.'.ylabel' => &escape($ylabel),
1.136     matthew  9070:          $id.'.labels' => join(',',@$Xlabels),
                   9071:          $id.'.PlotType' => 'XY',
                   9072:          $id.'.NumSets' => 2,
1.137     matthew  9073:          $id.'.two_axes' => 1,
                   9074:          $id.'.y1_max_value' => $Max1,
                   9075:          $id.'.y1_min_value' => $Min1,
                   9076:          $id.'.y2_max_value' => $Max2,
                   9077:          $id.'.y2_min_value' => $Min2,
1.136     matthew  9078:          );
                   9079:     #
1.137     matthew  9080:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   9081:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   9082:     }
                   9083:     #
                   9084:     if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
                   9085:         ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136     matthew  9086:         return '';
                   9087:     }
                   9088:     my $NumSets=1;
1.137     matthew  9089:     foreach my $array ($Ydata1,$Ydata2){
1.136     matthew  9090:         next if (! ref($array));
                   9091:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137     matthew  9092:     }
                   9093:     #
                   9094:     # Deal with other parameters
                   9095:     while (my ($key,$value) = each(%Values)) {
                   9096:         $ValuesHash{$id.'.'.$key} = $value;
1.136     matthew  9097:     }
                   9098:     #
1.646     raeburn  9099:     &Apache::lonnet::appenv(\%ValuesHash);
1.130     albertel 9100:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139     matthew  9101: }
                   9102: 
                   9103: ############################################################
                   9104: ############################################################
                   9105: 
                   9106: =pod
                   9107: 
1.157     matthew  9108: =back 
                   9109: 
1.139     matthew  9110: =head1 Statistics helper routines?  
                   9111: 
                   9112: Bad place for them but what the hell.
                   9113: 
1.157     matthew  9114: =over 4
                   9115: 
1.648     raeburn  9116: =item * &chartlink()
1.139     matthew  9117: 
                   9118: Returns a link to the chart for a specific student.  
                   9119: 
                   9120: Inputs:
                   9121: 
                   9122: =over 4
                   9123: 
                   9124: =item $linktext: The text of the link
                   9125: 
                   9126: =item $sname: The students username
                   9127: 
                   9128: =item $sdomain: The students domain
                   9129: 
                   9130: =back
                   9131: 
1.157     matthew  9132: =back
                   9133: 
1.139     matthew  9134: =cut
                   9135: 
                   9136: ############################################################
                   9137: ############################################################
                   9138: sub chartlink {
                   9139:     my ($linktext, $sname, $sdomain) = @_;
                   9140:     my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369     www      9141:         '&amp;SelectedStudent='.&escape($sname.':'.$sdomain).
1.219     albertel 9142:         '&amp;chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139     matthew  9143:        '">'.$linktext.'</a>';
1.153     matthew  9144: }
                   9145: 
                   9146: #######################################################
                   9147: #######################################################
                   9148: 
                   9149: =pod
                   9150: 
                   9151: =head1 Course Environment Routines
1.157     matthew  9152: 
                   9153: =over 4
1.153     matthew  9154: 
1.648     raeburn  9155: =item * &restore_course_settings()
1.153     matthew  9156: 
1.648     raeburn  9157: =item * &store_course_settings()
1.153     matthew  9158: 
                   9159: Restores/Store indicated form parameters from the course environment.
                   9160: Will not overwrite existing values of the form parameters.
                   9161: 
                   9162: Inputs: 
                   9163: a scalar describing the data (e.g. 'chart', 'problem_analysis')
                   9164: 
                   9165: a hash ref describing the data to be stored.  For example:
                   9166:    
                   9167: %Save_Parameters = ('Status' => 'scalar',
                   9168:     'chartoutputmode' => 'scalar',
                   9169:     'chartoutputdata' => 'scalar',
                   9170:     'Section' => 'array',
1.373     raeburn  9171:     'Group' => 'array',
1.153     matthew  9172:     'StudentData' => 'array',
                   9173:     'Maps' => 'array');
                   9174: 
                   9175: Returns: both routines return nothing
                   9176: 
1.631     raeburn  9177: =back
                   9178: 
1.153     matthew  9179: =cut
                   9180: 
                   9181: #######################################################
                   9182: #######################################################
                   9183: sub store_course_settings {
1.496     albertel 9184:     return &store_settings($env{'request.course.id'},@_);
                   9185: }
                   9186: 
                   9187: sub store_settings {
1.153     matthew  9188:     # save to the environment
                   9189:     # appenv the same items, just to be safe
1.300     albertel 9190:     my $udom  = $env{'user.domain'};
                   9191:     my $uname = $env{'user.name'};
1.496     albertel 9192:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  9193:     my %SaveHash;
                   9194:     my %AppHash;
                   9195:     while (my ($setting,$type) = each(%$Settings)) {
1.496     albertel 9196:         my $basename = join('.','internal',$context,$prefix,$setting);
1.300     albertel 9197:         my $envname = 'environment.'.$basename;
1.258     albertel 9198:         if (exists($env{'form.'.$setting})) {
1.153     matthew  9199:             # Save this value away
                   9200:             if ($type eq 'scalar' &&
1.258     albertel 9201:                 (! exists($env{$envname}) || 
                   9202:                  $env{$envname} ne $env{'form.'.$setting})) {
                   9203:                 $SaveHash{$basename} = $env{'form.'.$setting};
                   9204:                 $AppHash{$envname}   = $env{'form.'.$setting};
1.153     matthew  9205:             } elsif ($type eq 'array') {
                   9206:                 my $stored_form;
1.258     albertel 9207:                 if (ref($env{'form.'.$setting})) {
1.153     matthew  9208:                     $stored_form = join(',',
                   9209:                                         map {
1.369     www      9210:                                             &escape($_);
1.258     albertel 9211:                                         } sort(@{$env{'form.'.$setting}}));
1.153     matthew  9212:                 } else {
                   9213:                     $stored_form = 
1.369     www      9214:                         &escape($env{'form.'.$setting});
1.153     matthew  9215:                 }
                   9216:                 # Determine if the array contents are the same.
1.258     albertel 9217:                 if ($stored_form ne $env{$envname}) {
1.153     matthew  9218:                     $SaveHash{$basename} = $stored_form;
                   9219:                     $AppHash{$envname}   = $stored_form;
                   9220:                 }
                   9221:             }
                   9222:         }
                   9223:     }
                   9224:     my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300     albertel 9225:                                           $udom,$uname);
1.153     matthew  9226:     if ($put_result !~ /^(ok|delayed)/) {
                   9227:         &Apache::lonnet::logthis('unable to save form parameters, '.
                   9228:                                  'got error:'.$put_result);
                   9229:     }
                   9230:     # Make sure these settings stick around in this session, too
1.646     raeburn  9231:     &Apache::lonnet::appenv(\%AppHash);
1.153     matthew  9232:     return;
                   9233: }
                   9234: 
                   9235: sub restore_course_settings {
1.499     albertel 9236:     return &restore_settings($env{'request.course.id'},@_);
1.496     albertel 9237: }
                   9238: 
                   9239: sub restore_settings {
                   9240:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  9241:     while (my ($setting,$type) = each(%$Settings)) {
1.258     albertel 9242:         next if (exists($env{'form.'.$setting}));
1.496     albertel 9243:         my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153     matthew  9244:             '.'.$setting;
1.258     albertel 9245:         if (exists($env{$envname})) {
1.153     matthew  9246:             if ($type eq 'scalar') {
1.258     albertel 9247:                 $env{'form.'.$setting} = $env{$envname};
1.153     matthew  9248:             } elsif ($type eq 'array') {
1.258     albertel 9249:                 $env{'form.'.$setting} = [ 
1.153     matthew  9250:                                            map { 
1.369     www      9251:                                                &unescape($_); 
1.258     albertel 9252:                                            } split(',',$env{$envname})
1.153     matthew  9253:                                            ];
                   9254:             }
                   9255:         }
                   9256:     }
1.127     matthew  9257: }
                   9258: 
1.618     raeburn  9259: #######################################################
                   9260: #######################################################
                   9261: 
                   9262: =pod
                   9263: 
                   9264: =head1 Domain E-mail Routines  
                   9265: 
                   9266: =over 4
                   9267: 
1.648     raeburn  9268: =item * &build_recipient_list()
1.618     raeburn  9269: 
1.766     raeburn  9270: Build recipient lists for four types of e-mail:
                   9271: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
                   9272: (d) Help requests, generated by
                   9273: lonerrorhandler.pm, CHECKRPMS, loncron, and lonsupportreq.pm respectively.
1.618     raeburn  9274: 
                   9275: Inputs:
1.619     raeburn  9276: defmail (scalar - email address of default recipient), 
1.618     raeburn  9277: mailing type (scalar - errormail, packagesmail, or helpdeskmail), 
1.619     raeburn  9278: defdom (domain for which to retrieve configuration settings),
                   9279: origmail (scalar - email address of recipient from loncapa.conf, 
                   9280: i.e., predates configuration by DC via domainprefs.pm 
1.618     raeburn  9281: 
1.655     raeburn  9282: Returns: comma separated list of addresses to which to send e-mail.
                   9283: 
                   9284: =back
1.618     raeburn  9285: 
                   9286: =cut
                   9287: 
                   9288: ############################################################
                   9289: ############################################################
                   9290: sub build_recipient_list {
1.619     raeburn  9291:     my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618     raeburn  9292:     my @recipients;
                   9293:     my $otheremails;
                   9294:     my %domconfig =
                   9295:          &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
                   9296:     if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766     raeburn  9297:         if (exists($domconfig{'contacts'}{$mailing})) {
                   9298:             if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
                   9299:                 my @contacts = ('adminemail','supportemail');
                   9300:                 foreach my $item (@contacts) {
                   9301:                     if ($domconfig{'contacts'}{$mailing}{$item}) {
                   9302:                         my $addr = $domconfig{'contacts'}{$item}; 
                   9303:                         if (!grep(/^\Q$addr\E$/,@recipients)) {
                   9304:                             push(@recipients,$addr);
                   9305:                         }
1.619     raeburn  9306:                     }
1.766     raeburn  9307:                     $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618     raeburn  9308:                 }
                   9309:             }
1.766     raeburn  9310:         } elsif ($origmail ne '') {
                   9311:             push(@recipients,$origmail);
1.618     raeburn  9312:         }
1.619     raeburn  9313:     } elsif ($origmail ne '') {
                   9314:         push(@recipients,$origmail);
1.618     raeburn  9315:     }
1.688     raeburn  9316:     if (defined($defmail)) {
                   9317:         if ($defmail ne '') {
                   9318:             push(@recipients,$defmail);
                   9319:         }
1.618     raeburn  9320:     }
                   9321:     if ($otheremails) {
1.619     raeburn  9322:         my @others;
                   9323:         if ($otheremails =~ /,/) {
                   9324:             @others = split(/,/,$otheremails);
1.618     raeburn  9325:         } else {
1.619     raeburn  9326:             push(@others,$otheremails);
                   9327:         }
                   9328:         foreach my $addr (@others) {
                   9329:             if (!grep(/^\Q$addr\E$/,@recipients)) {
                   9330:                 push(@recipients,$addr);
                   9331:             }
1.618     raeburn  9332:         }
                   9333:     }
1.619     raeburn  9334:     my $recipientlist = join(',',@recipients); 
1.618     raeburn  9335:     return $recipientlist;
                   9336: }
                   9337: 
1.127     matthew  9338: ############################################################
                   9339: ############################################################
1.154     albertel 9340: 
1.655     raeburn  9341: =pod
                   9342: 
                   9343: =head1 Course Catalog Routines
                   9344: 
                   9345: =over 4
                   9346: 
                   9347: =item * &gather_categories()
                   9348: 
                   9349: Converts category definitions - keys of categories hash stored in  
                   9350: coursecategories in configuration.db on the primary library server in a 
                   9351: domain - to an array.  Also generates javascript and idx hash used to 
                   9352: generate Domain Coordinator interface for editing Course Categories.
                   9353: 
                   9354: Inputs:
1.663     raeburn  9355: 
1.655     raeburn  9356: categories (reference to hash of category definitions).
1.663     raeburn  9357: 
1.655     raeburn  9358: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   9359:       categories and subcategories).
1.663     raeburn  9360: 
1.655     raeburn  9361: idx (reference to hash of counters used in Domain Coordinator interface for 
                   9362:       editing Course Categories).
1.663     raeburn  9363: 
1.655     raeburn  9364: jsarray (reference to array of categories used to create Javascript arrays for
                   9365:          Domain Coordinator interface for editing Course Categories).
                   9366: 
                   9367: Returns: nothing
                   9368: 
                   9369: Side effects: populates cats, idx and jsarray. 
                   9370: 
                   9371: =cut
                   9372: 
                   9373: sub gather_categories {
                   9374:     my ($categories,$cats,$idx,$jsarray) = @_;
                   9375:     my %counters;
                   9376:     my $num = 0;
                   9377:     foreach my $item (keys(%{$categories})) {
                   9378:         my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
                   9379:         if ($container eq '' && $depth == 0) {
                   9380:             $cats->[$depth][$categories->{$item}] = $cat;
                   9381:         } else {
                   9382:             $cats->[$depth]{$container}[$categories->{$item}] = $cat;
                   9383:         }
                   9384:         my ($escitem,$tail) = split(/:/,$item,2);
                   9385:         if ($counters{$tail} eq '') {
                   9386:             $counters{$tail} = $num;
                   9387:             $num ++;
                   9388:         }
                   9389:         if (ref($idx) eq 'HASH') {
                   9390:             $idx->{$item} = $counters{$tail};
                   9391:         }
                   9392:         if (ref($jsarray) eq 'ARRAY') {
                   9393:             push(@{$jsarray->[$counters{$tail}]},$item);
                   9394:         }
                   9395:     }
                   9396:     return;
                   9397: }
                   9398: 
                   9399: =pod
                   9400: 
                   9401: =item * &extract_categories()
                   9402: 
                   9403: Used to generate breadcrumb trails for course categories.
                   9404: 
                   9405: Inputs:
1.663     raeburn  9406: 
1.655     raeburn  9407: categories (reference to hash of category definitions).
1.663     raeburn  9408: 
1.655     raeburn  9409: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   9410:       categories and subcategories).
1.663     raeburn  9411: 
1.655     raeburn  9412: trails (reference to array of breacrumb trails for each category).
1.663     raeburn  9413: 
1.655     raeburn  9414: allitems (reference to hash - key is category key 
                   9415:          (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663     raeburn  9416: 
1.655     raeburn  9417: idx (reference to hash of counters used in Domain Coordinator interface for
                   9418:       editing Course Categories).
1.663     raeburn  9419: 
1.655     raeburn  9420: jsarray (reference to array of categories used to create Javascript arrays for
                   9421:          Domain Coordinator interface for editing Course Categories).
                   9422: 
1.665     raeburn  9423: subcats (reference to hash of arrays containing all subcategories within each 
                   9424:          category, -recursive)
                   9425: 
1.655     raeburn  9426: Returns: nothing
                   9427: 
                   9428: Side effects: populates trails and allitems hash references.
                   9429: 
                   9430: =cut
                   9431: 
                   9432: sub extract_categories {
1.665     raeburn  9433:     my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655     raeburn  9434:     if (ref($categories) eq 'HASH') {
                   9435:         &gather_categories($categories,$cats,$idx,$jsarray);
                   9436:         if (ref($cats->[0]) eq 'ARRAY') {
                   9437:             for (my $i=0; $i<@{$cats->[0]}; $i++) {
                   9438:                 my $name = $cats->[0][$i];
                   9439:                 my $item = &escape($name).'::0';
                   9440:                 my $trailstr;
                   9441:                 if ($name eq 'instcode') {
                   9442:                     $trailstr = &mt('Official courses (with institutional codes)');
                   9443:                 } else {
                   9444:                     $trailstr = $name;
                   9445:                 }
                   9446:                 if ($allitems->{$item} eq '') {
                   9447:                     push(@{$trails},$trailstr);
                   9448:                     $allitems->{$item} = scalar(@{$trails})-1;
                   9449:                 }
                   9450:                 my @parents = ($name);
                   9451:                 if (ref($cats->[1]{$name}) eq 'ARRAY') {
                   9452:                     for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
                   9453:                         my $category = $cats->[1]{$name}[$j];
1.665     raeburn  9454:                         if (ref($subcats) eq 'HASH') {
                   9455:                             push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
                   9456:                         }
                   9457:                         &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
                   9458:                     }
                   9459:                 } else {
                   9460:                     if (ref($subcats) eq 'HASH') {
                   9461:                         $subcats->{$item} = [];
1.655     raeburn  9462:                     }
                   9463:                 }
                   9464:             }
                   9465:         }
                   9466:     }
                   9467:     return;
                   9468: }
                   9469: 
                   9470: =pod
                   9471: 
                   9472: =item *&recurse_categories()
                   9473: 
                   9474: Recursively used to generate breadcrumb trails for course categories.
                   9475: 
                   9476: Inputs:
1.663     raeburn  9477: 
1.655     raeburn  9478: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   9479:       categories and subcategories).
1.663     raeburn  9480: 
1.655     raeburn  9481: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663     raeburn  9482: 
                   9483: category (current course category, for which breadcrumb trail is being generated).
                   9484: 
                   9485: trails (reference to array of breadcrumb trails for each category).
                   9486: 
1.655     raeburn  9487: allitems (reference to hash - key is category key
                   9488:          (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663     raeburn  9489: 
1.655     raeburn  9490: parents (array containing containers directories for current category, 
                   9491:          back to top level). 
                   9492: 
                   9493: Returns: nothing
                   9494: 
                   9495: Side effects: populates trails and allitems hash references
                   9496: 
                   9497: =cut
                   9498: 
                   9499: sub recurse_categories {
1.665     raeburn  9500:     my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655     raeburn  9501:     my $shallower = $depth - 1;
                   9502:     if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
                   9503:         for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
                   9504:             my $name = $cats->[$depth]{$category}[$k];
                   9505:             my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
                   9506:             my $trailstr = join(' -&gt; ',(@{$parents},$category));
                   9507:             if ($allitems->{$item} eq '') {
                   9508:                 push(@{$trails},$trailstr);
                   9509:                 $allitems->{$item} = scalar(@{$trails})-1;
                   9510:             }
                   9511:             my $deeper = $depth+1;
                   9512:             push(@{$parents},$category);
1.665     raeburn  9513:             if (ref($subcats) eq 'HASH') {
                   9514:                 my $subcat = &escape($name).':'.$category.':'.$depth;
                   9515:                 for (my $j=@{$parents}; $j>=0; $j--) {
                   9516:                     my $higher;
                   9517:                     if ($j > 0) {
                   9518:                         $higher = &escape($parents->[$j]).':'.
                   9519:                                   &escape($parents->[$j-1]).':'.$j;
                   9520:                     } else {
                   9521:                         $higher = &escape($parents->[$j]).'::'.$j;
                   9522:                     }
                   9523:                     push(@{$subcats->{$higher}},$subcat);
                   9524:                 }
                   9525:             }
                   9526:             &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
                   9527:                                 $subcats);
1.655     raeburn  9528:             pop(@{$parents});
                   9529:         }
                   9530:     } else {
                   9531:         my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
                   9532:         my $trailstr = join(' -&gt; ',(@{$parents},$category));
                   9533:         if ($allitems->{$item} eq '') {
                   9534:             push(@{$trails},$trailstr);
                   9535:             $allitems->{$item} = scalar(@{$trails})-1;
                   9536:         }
                   9537:     }
                   9538:     return;
                   9539: }
                   9540: 
1.663     raeburn  9541: =pod
                   9542: 
                   9543: =item *&assign_categories_table()
                   9544: 
                   9545: Create a datatable for display of hierarchical categories in a domain,
                   9546: with checkboxes to allow a course to be categorized. 
                   9547: 
                   9548: Inputs:
                   9549: 
                   9550: cathash - reference to hash of categories defined for the domain (from
                   9551:           configuration.db)
                   9552: 
                   9553: currcat - scalar with an & separated list of categories assigned to a course. 
                   9554: 
                   9555: Returns: $output (markup to be displayed) 
                   9556: 
                   9557: =cut
                   9558: 
                   9559: sub assign_categories_table {
                   9560:     my ($cathash,$currcat) = @_;
                   9561:     my $output;
                   9562:     if (ref($cathash) eq 'HASH') {
                   9563:         my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
                   9564:         &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
                   9565:         $maxdepth = scalar(@cats);
                   9566:         if (@cats > 0) {
                   9567:             my $itemcount = 0;
                   9568:             if (ref($cats[0]) eq 'ARRAY') {
                   9569:                 $output = &Apache::loncommon::start_data_table();
                   9570:                 my @currcategories;
                   9571:                 if ($currcat ne '') {
                   9572:                     @currcategories = split('&',$currcat);
                   9573:                 }
                   9574:                 for (my $i=0; $i<@{$cats[0]}; $i++) {
                   9575:                     my $parent = $cats[0][$i];
                   9576:                     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   9577:                     next if ($parent eq 'instcode');
                   9578:                     my $item = &escape($parent).'::0';
                   9579:                     my $checked = '';
                   9580:                     if (@currcategories > 0) {
                   9581:                         if (grep(/^\Q$item\E$/,@currcategories)) {
1.772     bisitz   9582:                             $checked = ' checked="checked"';
1.663     raeburn  9583:                         }
                   9584:                     }
1.675     raeburn  9585:                     $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
                   9586:                                '<input type="checkbox" name="usecategory" value="'.
                   9587:                                $item.'"'.$checked.' />'.$parent.'</span>'.
                   9588:                                '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663     raeburn  9589:                     my $depth = 1;
                   9590:                     push(@path,$parent);
                   9591:                     $output .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
                   9592:                     pop(@path);
                   9593:                     $output .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
                   9594:                     $itemcount ++;
                   9595:                 }
                   9596:                 $output .= &Apache::loncommon::end_data_table();
                   9597:             }
                   9598:         }
                   9599:     }
                   9600:     return $output;
                   9601: }
                   9602: 
                   9603: =pod
                   9604: 
                   9605: =item *&assign_category_rows()
                   9606: 
                   9607: Create a datatable row for display of nested categories in a domain,
                   9608: with checkboxes to allow a course to be categorized,called recursively.
                   9609: 
                   9610: Inputs:
                   9611: 
                   9612: itemcount - track row number for alternating colors
                   9613: 
                   9614: cats - reference to array of arrays/hashes which encapsulates hierarchy of
                   9615:       categories and subcategories.
                   9616: 
                   9617: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
                   9618: 
                   9619: parent - parent of current category item
                   9620: 
                   9621: path - Array containing all categories back up through the hierarchy from the
                   9622:        current category to the top level.
                   9623: 
                   9624: currcategories - reference to array of current categories assigned to the course
                   9625: 
                   9626: Returns: $output (markup to be displayed).
                   9627: 
                   9628: =cut
                   9629: 
                   9630: sub assign_category_rows {
                   9631:     my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
                   9632:     my ($text,$name,$item,$chgstr);
                   9633:     if (ref($cats) eq 'ARRAY') {
                   9634:         my $maxdepth = scalar(@{$cats});
                   9635:         if (ref($cats->[$depth]) eq 'HASH') {
                   9636:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   9637:                 my $numchildren = @{$cats->[$depth]{$parent}};
                   9638:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   9639:                 $text .= '<td><table class="LC_datatable">';
                   9640:                 for (my $j=0; $j<$numchildren; $j++) {
                   9641:                     $name = $cats->[$depth]{$parent}[$j];
                   9642:                     $item = &escape($name).':'.&escape($parent).':'.$depth;
                   9643:                     my $deeper = $depth+1;
                   9644:                     my $checked = '';
                   9645:                     if (ref($currcategories) eq 'ARRAY') {
                   9646:                         if (@{$currcategories} > 0) {
                   9647:                             if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772     bisitz   9648:                                 $checked = ' checked="checked"';
1.663     raeburn  9649:                             }
                   9650:                         }
                   9651:                     }
1.664     raeburn  9652:                     $text .= '<tr><td><span class="LC_nobreak"><label>'.
                   9653:                              '<input type="checkbox" name="usecategory" value="'.
1.675     raeburn  9654:                              $item.'"'.$checked.' />'.$name.'</label></span>'.
                   9655:                              '<input type="hidden" name="catname" value="'.$name.'" />'.
                   9656:                              '</td><td>';
1.663     raeburn  9657:                     if (ref($path) eq 'ARRAY') {
                   9658:                         push(@{$path},$name);
                   9659:                         $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
                   9660:                         pop(@{$path});
                   9661:                     }
                   9662:                     $text .= '</td></tr>';
                   9663:                 }
                   9664:                 $text .= '</table></td>';
                   9665:             }
                   9666:         }
                   9667:     }
                   9668:     return $text;
                   9669: }
                   9670: 
1.655     raeburn  9671: ############################################################
                   9672: ############################################################
                   9673: 
                   9674: 
1.443     albertel 9675: sub commit_customrole {
1.664     raeburn  9676:     my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630     raeburn  9677:     my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443     albertel 9678:                          ($start?', '.&mt('starting').' '.localtime($start):'').
                   9679:                          ($end?', ending '.localtime($end):'').': <b>'.
                   9680:               &Apache::lonnet::assigncustomrole(
1.664     raeburn  9681:                  $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443     albertel 9682:                  '</b><br />';
                   9683:     return $output;
                   9684: }
                   9685: 
                   9686: sub commit_standardrole {
1.541     raeburn  9687:     my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
                   9688:     my ($output,$logmsg,$linefeed);
                   9689:     if ($context eq 'auto') {
                   9690:         $linefeed = "\n";
                   9691:     } else {
                   9692:         $linefeed = "<br />\n";
                   9693:     }  
1.443     albertel 9694:     if ($three eq 'st') {
1.541     raeburn  9695:         my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
                   9696:                                          $one,$two,$sec,$context);
                   9697:         if (($result =~ /^error/) || ($result eq 'not_in_class') || 
1.626     raeburn  9698:             ($result eq 'unknown_course') || ($result eq 'refused')) {
                   9699:             $output = $logmsg.' '.&mt('Error: ').$result."\n"; 
1.443     albertel 9700:         } else {
1.541     raeburn  9701:             $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443     albertel 9702:                ($start?', '.&mt('starting').' '.localtime($start):'').
1.541     raeburn  9703:                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
                   9704:             if ($context eq 'auto') {
                   9705:                 $output .= $result.$linefeed.&mt('Add to classlist').': ok';
                   9706:             } else {
                   9707:                $output .= '<b>'.$result.'</b>'.$linefeed.
                   9708:                &mt('Add to classlist').': <b>ok</b>';
                   9709:             }
                   9710:             $output .= $linefeed;
1.443     albertel 9711:         }
                   9712:     } else {
                   9713:         $output = &mt('Assigning').' '.$three.' in '.$url.
                   9714:                ($start?', '.&mt('starting').' '.localtime($start):'').
1.541     raeburn  9715:                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652     raeburn  9716:         my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541     raeburn  9717:         if ($context eq 'auto') {
                   9718:             $output .= $result.$linefeed;
                   9719:         } else {
                   9720:             $output .= '<b>'.$result.'</b>'.$linefeed;
                   9721:         }
1.443     albertel 9722:     }
                   9723:     return $output;
                   9724: }
                   9725: 
                   9726: sub commit_studentrole {
1.541     raeburn  9727:     my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626     raeburn  9728:     my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541     raeburn  9729:     if ($context eq 'auto') {
                   9730:         $linefeed = "\n";
                   9731:     } else {
                   9732:         $linefeed = '<br />'."\n";
                   9733:     }
1.443     albertel 9734:     if (defined($one) && defined($two)) {
                   9735:         my $cid=$one.'_'.$two;
                   9736:         my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
                   9737:         my $secchange = 0;
                   9738:         my $expire_role_result;
                   9739:         my $modify_section_result;
1.628     raeburn  9740:         if ($oldsec ne '-1') { 
                   9741:             if ($oldsec ne $sec) {
1.443     albertel 9742:                 $secchange = 1;
1.628     raeburn  9743:                 my $now = time;
1.443     albertel 9744:                 my $uurl='/'.$cid;
                   9745:                 $uurl=~s/\_/\//g;
                   9746:                 if ($oldsec) {
                   9747:                     $uurl.='/'.$oldsec;
                   9748:                 }
1.626     raeburn  9749:                 $oldsecurl = $uurl;
1.628     raeburn  9750:                 $expire_role_result = 
1.652     raeburn  9751:                     &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628     raeburn  9752:                 if ($env{'request.course.sec'} ne '') { 
                   9753:                     if ($expire_role_result eq 'refused') {
                   9754:                         my @roles = ('st');
                   9755:                         my @statuses = ('previous');
                   9756:                         my @roledoms = ($one);
                   9757:                         my $withsec = 1;
                   9758:                         my %roleshash = 
                   9759:                             &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
                   9760:                                               \@statuses,\@roles,\@roledoms,$withsec);
                   9761:                         if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
                   9762:                             my ($oldstart,$oldend) = 
                   9763:                                 split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
                   9764:                             if ($oldend > 0 && $oldend <= $now) {
                   9765:                                 $expire_role_result = 'ok';
                   9766:                             }
                   9767:                         }
                   9768:                     }
                   9769:                 }
1.443     albertel 9770:                 $result = $expire_role_result;
                   9771:             }
                   9772:         }
                   9773:         if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652     raeburn  9774:             $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443     albertel 9775:             if ($modify_section_result =~ /^ok/) {
                   9776:                 if ($secchange == 1) {
1.628     raeburn  9777:                     if ($sec eq '') {
                   9778:                         $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
                   9779:                     } else {
                   9780:                         $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
                   9781:                     }
1.443     albertel 9782:                 } elsif ($oldsec eq '-1') {
1.628     raeburn  9783:                     if ($sec eq '') {
                   9784:                         $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
                   9785:                     } else {
                   9786:                         $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                   9787:                     }
1.443     albertel 9788:                 } else {
1.628     raeburn  9789:                     if ($sec eq '') {
                   9790:                         $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
                   9791:                     } else {
                   9792:                         $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                   9793:                     }
1.443     albertel 9794:                 }
                   9795:             } else {
1.628     raeburn  9796:                 if ($secchange) {       
                   9797:                     $$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;
                   9798:                 } else {
                   9799:                     $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
                   9800:                 }
1.443     albertel 9801:             }
                   9802:             $result = $modify_section_result;
                   9803:         } elsif ($secchange == 1) {
1.628     raeburn  9804:             if ($oldsec eq '') {
                   9805:                 $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
                   9806:             } else {
                   9807:                 $$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;
                   9808:             }
1.626     raeburn  9809:             if ($expire_role_result eq 'refused') {
                   9810:                 my $newsecurl = '/'.$cid;
                   9811:                 $newsecurl =~ s/\_/\//g;
                   9812:                 if ($sec ne '') {
                   9813:                     $newsecurl.='/'.$sec;
                   9814:                 }
                   9815:                 if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
                   9816:                     if ($sec eq '') {
                   9817:                         $$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;
                   9818:                     } else {
                   9819:                         $$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;
                   9820:                     }
                   9821:                 }
                   9822:             }
1.443     albertel 9823:         }
                   9824:     } else {
1.626     raeburn  9825:         $$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 9826:         $result = "error: incomplete course id\n";
                   9827:     }
                   9828:     return $result;
                   9829: }
                   9830: 
                   9831: ############################################################
                   9832: ############################################################
                   9833: 
1.566     albertel 9834: sub check_clone {
1.578     raeburn  9835:     my ($args,$linefeed) = @_;
1.566     albertel 9836:     my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
                   9837:     my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
                   9838:     my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
                   9839:     my $clonemsg;
                   9840:     my $can_clone = 0;
                   9841: 
                   9842:     if ($clonehome eq 'no_host') {
1.578     raeburn  9843:         $clonemsg = &mt('No new course created.').$linefeed.&mt('A new course could not be cloned from the specified original - [_1] - because it is a non-existent course.',$args->{'clonecourse'}.':'.$args->{'clonedomain'});     
1.566     albertel 9844:     } else {
                   9845: 	my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.568     albertel 9846: 	if ($env{'request.role.domain'} eq $args->{'clonedomain'}) {
1.566     albertel 9847: 	    $can_clone = 1;
                   9848: 	} else {
                   9849: 	    my %clonehash = &Apache::lonnet::get('environment',['cloners'],
                   9850: 						 $args->{'clonedomain'},$args->{'clonecourse'});
                   9851: 	    my @cloners = split(/,/,$clonehash{'cloners'});
1.578     raeburn  9852:             if (grep(/^\*$/,@cloners)) {
                   9853:                 $can_clone = 1;
                   9854:             } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
                   9855:                 $can_clone = 1;
                   9856:             } else {
                   9857: 	        my %roleshash =
                   9858: 		    &Apache::lonnet::get_my_roles($args->{'ccuname'},
                   9859: 					 $args->{'ccdomain'},
                   9860:                                          'userroles',['active'],['cc'],
                   9861: 					 [$args->{'clonedomain'}]);
                   9862: 	        if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
                   9863: 		    $can_clone = 1;
                   9864: 	        } else {
                   9865:                     $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'});
                   9866: 	        }
1.566     albertel 9867: 	    }
1.578     raeburn  9868:         }
1.566     albertel 9869:     }
                   9870:     return ($can_clone, $clonemsg, $cloneid, $clonehome);
                   9871: }
                   9872: 
1.444     albertel 9873: sub construct_course {
1.541     raeburn  9874:     my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context) = @_;
1.444     albertel 9875:     my $outcome;
1.541     raeburn  9876:     my $linefeed =  '<br />'."\n";
                   9877:     if ($context eq 'auto') {
                   9878:         $linefeed = "\n";
                   9879:     }
1.566     albertel 9880: 
                   9881: #
                   9882: # Are we cloning?
                   9883: #
                   9884:     my ($can_clone, $clonemsg, $cloneid, $clonehome);
                   9885:     if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578     raeburn  9886: 	($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566     albertel 9887: 	if ($context ne 'auto') {
1.578     raeburn  9888:             if ($clonemsg ne '') {
                   9889: 	        $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
                   9890:             }
1.566     albertel 9891: 	}
                   9892: 	$outcome .= $clonemsg.$linefeed;
                   9893: 
                   9894:         if (!$can_clone) {
                   9895: 	    return (0,$outcome);
                   9896: 	}
                   9897:     }
                   9898: 
1.444     albertel 9899: #
                   9900: # Open course
                   9901: #
                   9902:     my $crstype = lc($args->{'crstype'});
                   9903:     my %cenv=();
                   9904:     $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
                   9905:                                              $args->{'cdescr'},
                   9906:                                              $args->{'curl'},
                   9907:                                              $args->{'course_home'},
                   9908:                                              $args->{'nonstandard'},
                   9909:                                              $args->{'crscode'},
                   9910:                                              $args->{'ccuname'}.':'.
                   9911:                                              $args->{'ccdomain'},
                   9912:                                              $args->{'crstype'});
                   9913: 
                   9914:     # Note: The testing routines depend on this being output; see 
                   9915:     # Utils::Course. This needs to at least be output as a comment
                   9916:     # if anyone ever decides to not show this, and Utils::Course::new
                   9917:     # will need to be suitably modified.
1.541     raeburn  9918:     $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.444     albertel 9919: #
                   9920: # Check if created correctly
                   9921: #
1.479     albertel 9922:     ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444     albertel 9923:     my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.541     raeburn  9924:     $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566     albertel 9925: 
1.444     albertel 9926: #
1.566     albertel 9927: # Do the cloning
                   9928: #   
                   9929:     if ($can_clone && $cloneid) {
                   9930: 	$clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
                   9931: 	if ($context ne 'auto') {
                   9932: 	    $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
                   9933: 	}
                   9934: 	$outcome .= $clonemsg.$linefeed;
                   9935: 	my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444     albertel 9936: # Copy all files
1.637     www      9937: 	&Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444     albertel 9938: # Restore URL
1.566     albertel 9939: 	$cenv{'url'}=$oldcenv{'url'};
1.444     albertel 9940: # Restore title
1.566     albertel 9941: 	$cenv{'description'}=$oldcenv{'description'};
1.444     albertel 9942: # Mark as cloned
1.566     albertel 9943: 	$cenv{'clonedfrom'}=$cloneid;
1.638     www      9944: # Need to clone grading mode
                   9945:         my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
                   9946:         $cenv{'grading'}=$newenv{'grading'};
                   9947: # Do not clone these environment entries
                   9948:         &Apache::lonnet::del('environment',
                   9949:                   ['default_enrollment_start_date',
                   9950:                    'default_enrollment_end_date',
                   9951:                    'question.email',
                   9952:                    'policy.email',
                   9953:                    'comment.email',
                   9954:                    'pch.users.denied',
1.725     raeburn  9955:                    'plc.users.denied',
                   9956:                    'hidefromcat',
                   9957:                    'categories'],
1.638     www      9958:                    $$crsudom,$$crsunum);
1.444     albertel 9959:     }
1.566     albertel 9960: 
1.444     albertel 9961: #
                   9962: # Set environment (will override cloned, if existing)
                   9963: #
                   9964:     my @sections = ();
                   9965:     my @xlists = ();
                   9966:     if ($args->{'crstype'}) {
                   9967:         $cenv{'type'}=$args->{'crstype'};
                   9968:     }
                   9969:     if ($args->{'crsid'}) {
                   9970:         $cenv{'courseid'}=$args->{'crsid'};
                   9971:     }
                   9972:     if ($args->{'crscode'}) {
                   9973:         $cenv{'internal.coursecode'}=$args->{'crscode'};
                   9974:     }
                   9975:     if ($args->{'crsquota'} ne '') {
                   9976:         $cenv{'internal.coursequota'}=$args->{'crsquota'};
                   9977:     } else {
                   9978:         $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
                   9979:     }
                   9980:     if ($args->{'ccuname'}) {
                   9981:         $cenv{'internal.courseowner'} = $args->{'ccuname'}.
                   9982:                                         ':'.$args->{'ccdomain'};
                   9983:     } else {
                   9984:         $cenv{'internal.courseowner'} = $args->{'curruser'};
                   9985:     }
                   9986:     my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
                   9987:     if ($args->{'crssections'}) {
                   9988:         $cenv{'internal.sectionnums'} = '';
                   9989:         if ($args->{'crssections'} =~ m/,/) {
                   9990:             @sections = split/,/,$args->{'crssections'};
                   9991:         } else {
                   9992:             $sections[0] = $args->{'crssections'};
                   9993:         }
                   9994:         if (@sections > 0) {
                   9995:             foreach my $item (@sections) {
                   9996:                 my ($sec,$gp) = split/:/,$item;
                   9997:                 my $class = $args->{'crscode'}.$sec;
                   9998:                 my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
                   9999:                 $cenv{'internal.sectionnums'} .= $item.',';
                   10000:                 unless ($addcheck eq 'ok') {
                   10001:                     push @badclasses, $class;
                   10002:                 }
                   10003:             }
                   10004:             $cenv{'internal.sectionnums'} =~ s/,$//;
                   10005:         }
                   10006:     }
                   10007: # do not hide course coordinator from staff listing, 
                   10008: # even if privileged
                   10009:     $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   10010: # add crosslistings
                   10011:     if ($args->{'crsxlist'}) {
                   10012:         $cenv{'internal.crosslistings'}='';
                   10013:         if ($args->{'crsxlist'} =~ m/,/) {
                   10014:             @xlists = split/,/,$args->{'crsxlist'};
                   10015:         } else {
                   10016:             $xlists[0] = $args->{'crsxlist'};
                   10017:         }
                   10018:         if (@xlists > 0) {
                   10019:             foreach my $item (@xlists) {
                   10020:                 my ($xl,$gp) = split/:/,$item;
                   10021:                 my $addcheck =  &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
                   10022:                 $cenv{'internal.crosslistings'} .= $item.',';
                   10023:                 unless ($addcheck eq 'ok') {
                   10024:                     push @badclasses, $xl;
                   10025:                 }
                   10026:             }
                   10027:             $cenv{'internal.crosslistings'} =~ s/,$//;
                   10028:         }
                   10029:     }
                   10030:     if ($args->{'autoadds'}) {
                   10031:         $cenv{'internal.autoadds'}=$args->{'autoadds'};
                   10032:     }
                   10033:     if ($args->{'autodrops'}) {
                   10034:         $cenv{'internal.autodrops'}=$args->{'autodrops'};
                   10035:     }
                   10036: # check for notification of enrollment changes
                   10037:     my @notified = ();
                   10038:     if ($args->{'notify_owner'}) {
                   10039:         if ($args->{'ccuname'} ne '') {
                   10040:             push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
                   10041:         }
                   10042:     }
                   10043:     if ($args->{'notify_dc'}) {
                   10044:         if ($uname ne '') { 
1.630     raeburn  10045:             push(@notified,$uname.':'.$udom);
1.444     albertel 10046:         }
                   10047:     }
                   10048:     if (@notified > 0) {
                   10049:         my $notifylist;
                   10050:         if (@notified > 1) {
                   10051:             $notifylist = join(',',@notified);
                   10052:         } else {
                   10053:             $notifylist = $notified[0];
                   10054:         }
                   10055:         $cenv{'internal.notifylist'} = $notifylist;
                   10056:     }
                   10057:     if (@badclasses > 0) {
                   10058:         my %lt=&Apache::lonlocal::texthash(
                   10059:                 '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',
                   10060:                 'dnhr' => 'does not have rights to access enrollment in these classes',
                   10061:                 'adby' => 'as determined by the policies of your institution on access to official classlists'
                   10062:         );
1.541     raeburn  10063:         my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
                   10064:                            ' ('.$lt{'adby'}.')';
                   10065:         if ($context eq 'auto') {
                   10066:             $outcome .= $badclass_msg.$linefeed;
1.566     albertel 10067:             $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541     raeburn  10068:             foreach my $item (@badclasses) {
                   10069:                 if ($context eq 'auto') {
                   10070:                     $outcome .= " - $item\n";
                   10071:                 } else {
                   10072:                     $outcome .= "<li>$item</li>\n";
                   10073:                 }
                   10074:             }
                   10075:             if ($context eq 'auto') {
                   10076:                 $outcome .= $linefeed;
                   10077:             } else {
1.566     albertel 10078:                 $outcome .= "</ul><br /><br /></div>\n";
1.541     raeburn  10079:             }
                   10080:         } 
1.444     albertel 10081:     }
                   10082:     if ($args->{'no_end_date'}) {
                   10083:         $args->{'endaccess'} = 0;
                   10084:     }
                   10085:     $cenv{'internal.autostart'}=$args->{'enrollstart'};
                   10086:     $cenv{'internal.autoend'}=$args->{'enrollend'};
                   10087:     $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
                   10088:     $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
                   10089:     if ($args->{'showphotos'}) {
                   10090:       $cenv{'internal.showphotos'}=$args->{'showphotos'};
                   10091:     }
                   10092:     $cenv{'internal.authtype'} = $args->{'authtype'};
                   10093:     $cenv{'internal.autharg'} = $args->{'autharg'}; 
                   10094:     if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
                   10095:         if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'}  eq '') {
1.541     raeburn  10096:             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'); 
                   10097:             if ($context eq 'auto') {
                   10098:                 $outcome .= $krb_msg;
                   10099:             } else {
1.566     albertel 10100:                 $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541     raeburn  10101:             }
                   10102:             $outcome .= $linefeed;
1.444     albertel 10103:         }
                   10104:     }
                   10105:     if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
                   10106:        if ($args->{'setpolicy'}) {
                   10107:            $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   10108:        }
                   10109:        if ($args->{'setcontent'}) {
                   10110:            $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   10111:        }
                   10112:     }
                   10113:     if ($args->{'reshome'}) {
                   10114: 	$cenv{'reshome'}=$args->{'reshome'}.'/';
                   10115: 	$cenv{'reshome'}=~s/\/+$/\//;
                   10116:     }
                   10117: #
                   10118: # course has keyed access
                   10119: #
                   10120:     if ($args->{'setkeys'}) {
                   10121:        $cenv{'keyaccess'}='yes';
                   10122:     }
                   10123: # if specified, key authority is not course, but user
                   10124: # only active if keyaccess is yes
                   10125:     if ($args->{'keyauth'}) {
1.487     albertel 10126: 	my ($user,$domain) = split(':',$args->{'keyauth'});
                   10127: 	$user = &LONCAPA::clean_username($user);
                   10128: 	$domain = &LONCAPA::clean_username($domain);
1.488     foxr     10129: 	if ($user ne '' && $domain ne '') {
1.487     albertel 10130: 	    $cenv{'keyauth'}=$user.':'.$domain;
1.444     albertel 10131: 	}
                   10132:     }
                   10133: 
                   10134:     if ($args->{'disresdis'}) {
                   10135:         $cenv{'pch.roles.denied'}='st';
                   10136:     }
                   10137:     if ($args->{'disablechat'}) {
                   10138:         $cenv{'plc.roles.denied'}='st';
                   10139:     }
                   10140: 
                   10141:     # Record we've not yet viewed the Course Initialization Helper for this 
                   10142:     # course
                   10143:     $cenv{'course.helper.not.run'} = 1;
                   10144:     #
                   10145:     # Use new Randomseed
                   10146:     #
                   10147:     $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
                   10148:     $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
                   10149:     #
                   10150:     # The encryption code and receipt prefix for this course
                   10151:     #
                   10152:     $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
                   10153:     $cenv{'internal.encpref'}=100+int(9*rand(99));
                   10154:     #
                   10155:     # By default, use standard grading
                   10156:     if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
                   10157: 
1.541     raeburn  10158:     $outcome .= $linefeed.&mt('Setting environment').': '.                 
                   10159:           &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444     albertel 10160: #
                   10161: # Open all assignments
                   10162: #
                   10163:     if ($args->{'openall'}) {
                   10164:        my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
                   10165:        my %storecontent = ($storeunder         => time,
                   10166:                            $storeunder.'.type' => 'date_start');
                   10167:        
                   10168:        $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541     raeburn  10169:                  ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444     albertel 10170:    }
                   10171: #
                   10172: # Set first page
                   10173: #
                   10174:     unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
                   10175: 	    || ($cloneid)) {
1.445     albertel 10176: 	use LONCAPA::map;
1.444     albertel 10177: 	$outcome .= &mt('Setting first resource').': ';
1.445     albertel 10178: 
                   10179: 	my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
                   10180:         my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
                   10181: 
1.444     albertel 10182:         $outcome .= ($fatal?$errtext:'read ok').' - ';
                   10183:         my $title; my $url;
                   10184:         if ($args->{'firstres'} eq 'syl') {
1.690     bisitz   10185: 	    $title=&mt('Syllabus');
1.444     albertel 10186:             $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
                   10187:         } else {
1.690     bisitz   10188:             $title=&mt('Navigate Contents');
1.444     albertel 10189:             $url='/adm/navmaps';
                   10190:         }
1.445     albertel 10191: 
                   10192:         $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
                   10193: 	(my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
                   10194: 
                   10195: 	if ($errtext) { $fatal=2; }
1.541     raeburn  10196:         $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444     albertel 10197:     }
1.566     albertel 10198: 
                   10199:     return (1,$outcome);
1.444     albertel 10200: }
                   10201: 
                   10202: ############################################################
                   10203: ############################################################
                   10204: 
1.378     raeburn  10205: sub course_type {
                   10206:     my ($cid) = @_;
                   10207:     if (!defined($cid)) {
                   10208:         $cid = $env{'request.course.id'};
                   10209:     }
1.404     albertel 10210:     if (defined($env{'course.'.$cid.'.type'})) {
                   10211:         return $env{'course.'.$cid.'.type'};
1.378     raeburn  10212:     } else {
                   10213:         return 'Course';
1.377     raeburn  10214:     }
                   10215: }
1.156     albertel 10216: 
1.406     raeburn  10217: sub group_term {
                   10218:     my $crstype = &course_type();
                   10219:     my %names = (
                   10220:                   'Course' => 'group',
                   10221:                   'Group' => 'team',
                   10222:                 );
                   10223:     return $names{$crstype};
                   10224: }
                   10225: 
1.156     albertel 10226: sub icon {
                   10227:     my ($file)=@_;
1.505     albertel 10228:     my $curfext = lc((split(/\./,$file))[-1]);
1.168     albertel 10229:     my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156     albertel 10230:     my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168     albertel 10231:     if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
                   10232: 	if (-e  $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
                   10233: 	          $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   10234: 	            $curfext.".gif") {
                   10235: 	    $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   10236: 		$curfext.".gif";
                   10237: 	}
                   10238:     }
1.249     albertel 10239:     return &lonhttpdurl($iconname);
1.154     albertel 10240: } 
1.84      albertel 10241: 
1.575     albertel 10242: sub lonhttpdurl {
1.692     www      10243: #
                   10244: # Had been used for "small fry" static images on separate port 8080.
                   10245: # Modify here if lightweight http functionality desired again.
                   10246: # Currently eliminated due to increasing firewall issues.
                   10247: #
1.575     albertel 10248:     my ($url)=@_;
1.692     www      10249:     return $url;
1.215     albertel 10250: }
                   10251: 
1.213     albertel 10252: sub connection_aborted {
                   10253:     my ($r)=@_;
                   10254:     $r->print(" ");$r->rflush();
                   10255:     my $c = $r->connection;
                   10256:     return $c->aborted();
                   10257: }
                   10258: 
1.221     foxr     10259: #    Escapes strings that may have embedded 's that will be put into
1.222     foxr     10260: #    strings as 'strings'.
                   10261: sub escape_single {
1.221     foxr     10262:     my ($input) = @_;
1.223     albertel 10263:     $input =~ s/\\/\\\\/g;	# Escape the \'s..(must be first)>
1.221     foxr     10264:     $input =~ s/\'/\\\'/g;	# Esacpe the 's....
                   10265:     return $input;
                   10266: }
1.223     albertel 10267: 
1.222     foxr     10268: #  Same as escape_single, but escape's "'s  This 
                   10269: #  can be used for  "strings"
                   10270: sub escape_double {
                   10271:     my ($input) = @_;
                   10272:     $input =~ s/\\/\\\\/g;	# Escape the /'s..(must be first)>
                   10273:     $input =~ s/\"/\\\"/g;	# Esacpe the "s....
                   10274:     return $input;
                   10275: }
1.223     albertel 10276:  
1.222     foxr     10277: #   Escapes the last element of a full URL.
                   10278: sub escape_url {
                   10279:     my ($url)   = @_;
1.238     raeburn  10280:     my @urlslices = split(/\//, $url,-1);
1.369     www      10281:     my $lastitem = &escape(pop(@urlslices));
1.223     albertel 10282:     return join('/',@urlslices).'/'.$lastitem;
1.222     foxr     10283: }
1.462     albertel 10284: 
1.820     raeburn  10285: sub compare_arrays {
                   10286:     my ($arrayref1,$arrayref2) = @_;
                   10287:     my (@difference,%count);
                   10288:     @difference = ();
                   10289:     %count = ();
                   10290:     if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
                   10291:         foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
                   10292:         foreach my $element (keys(%count)) {
                   10293:             if ($count{$element} == 1) {
                   10294:                 push(@difference,$element);
                   10295:             }
                   10296:         }
                   10297:     }
                   10298:     return @difference;
                   10299: }
                   10300: 
1.817     bisitz   10301: # -------------------------------------------------------- Initialize user login
1.462     albertel 10302: sub init_user_environment {
1.463     albertel 10303:     my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462     albertel 10304:     my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
                   10305: 
                   10306:     my $public=($username eq 'public' && $domain eq 'public');
                   10307: 
                   10308: # See if old ID present, if so, remove
                   10309: 
                   10310:     my ($filename,$cookie,$userroles);
                   10311:     my $now=time;
                   10312: 
                   10313:     if ($public) {
                   10314: 	my $max_public=100;
                   10315: 	my $oldest;
                   10316: 	my $oldest_time=0;
                   10317: 	for(my $next=1;$next<=$max_public;$next++) {
                   10318: 	    if (-e $lonids."/publicuser_$next.id") {
                   10319: 		my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
                   10320: 		if ($mtime<$oldest_time || !$oldest_time) {
                   10321: 		    $oldest_time=$mtime;
                   10322: 		    $oldest=$next;
                   10323: 		}
                   10324: 	    } else {
                   10325: 		$cookie="publicuser_$next";
                   10326: 		last;
                   10327: 	    }
                   10328: 	}
                   10329: 	if (!$cookie) { $cookie="publicuser_$oldest"; }
                   10330:     } else {
1.463     albertel 10331: 	# if this isn't a robot, kill any existing non-robot sessions
                   10332: 	if (!$args->{'robot'}) {
                   10333: 	    opendir(DIR,$lonids);
                   10334: 	    while ($filename=readdir(DIR)) {
                   10335: 		if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
                   10336: 		    unlink($lonids.'/'.$filename);
                   10337: 		}
1.462     albertel 10338: 	    }
1.463     albertel 10339: 	    closedir(DIR);
1.462     albertel 10340: 	}
                   10341: # Give them a new cookie
1.463     albertel 10342: 	my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684     www      10343: 		                   : $now.$$.int(rand(10000)));
1.463     albertel 10344: 	$cookie="$username\_$id\_$domain\_$authhost";
1.462     albertel 10345:     
                   10346: # Initialize roles
                   10347: 
                   10348: 	$userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
                   10349:     }
                   10350: # ------------------------------------ Check browser type and MathML capability
                   10351: 
                   10352:     my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
                   10353:         $clientunicode,$clientos) = &decode_user_agent($r);
                   10354: 
                   10355: # ------------------------------------------------------------- Get environment
                   10356: 
                   10357:     my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
                   10358:     my ($tmp) = keys(%userenv);
                   10359:     if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   10360: 	# default remote control to off
                   10361: 	if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
                   10362:     } else {
                   10363: 	undef(%userenv);
                   10364:     }
                   10365:     if (($userenv{'interface'}) && (!$form->{'interface'})) {
                   10366: 	$form->{'interface'}=$userenv{'interface'};
                   10367:     }
                   10368:     $env{'environment.remote'}=$userenv{'remote'};
                   10369:     if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
                   10370: 
                   10371: # --------------- Do not trust query string to be put directly into environment
1.817     bisitz   10372:     foreach my $option ('interface','localpath','localres') {
                   10373:         $form->{$option}=~s/[\n\r\=]//gs;
1.462     albertel 10374:     }
                   10375: # --------------------------------------------------------- Write first profile
                   10376: 
                   10377:     {
                   10378: 	my %initial_env = 
                   10379: 	    ("user.name"          => $username,
                   10380: 	     "user.domain"        => $domain,
                   10381: 	     "user.home"          => $authhost,
                   10382: 	     "browser.type"       => $clientbrowser,
                   10383: 	     "browser.version"    => $clientversion,
                   10384: 	     "browser.mathml"     => $clientmathml,
                   10385: 	     "browser.unicode"    => $clientunicode,
                   10386: 	     "browser.os"         => $clientos,
                   10387: 	     "server.domain"      => $Apache::lonnet::perlvar{'lonDefDomain'},
                   10388: 	     "request.course.fn"  => '',
                   10389: 	     "request.course.uri" => '',
                   10390: 	     "request.course.sec" => '',
                   10391: 	     "request.role"       => 'cm',
                   10392: 	     "request.role.adv"   => $env{'user.adv'},
                   10393: 	     "request.host"       => $ENV{'REMOTE_ADDR'},);
                   10394: 
                   10395:         if ($form->{'localpath'}) {
                   10396: 	    $initial_env{"browser.localpath"}  = $form->{'localpath'};
                   10397: 	    $initial_env{"browser.localres"}   = $form->{'localres'};
                   10398:         }
                   10399: 	
                   10400: 	if ($public) {
                   10401: 	    $initial_env{"environment.remote"} = "off";
                   10402: 	}
                   10403: 	if ($form->{'interface'}) {
                   10404: 	    $form->{'interface'}=~s/\W//gs;
                   10405: 	    $initial_env{"browser.interface"} = $form->{'interface'};
                   10406: 	    $env{'browser.interface'}=$form->{'interface'};
                   10407: 	}
                   10408: 
1.724     raeburn  10409:         foreach my $tool ('aboutme','blog','portfolio') {
                   10410:             $userenv{'availabletools.'.$tool} = 
                   10411:                 &Apache::lonnet::usertools_access($username,$domain,$tool,'reload');
                   10412:         }
                   10413: 
1.765     raeburn  10414:         foreach my $crstype ('official','unofficial') {
                   10415:             $userenv{'canrequest.'.$crstype} =
                   10416:                 &Apache::lonnet::usertools_access($username,$domain,$crstype,
                   10417:                                                   'reload','requestcourses');
                   10418:         }
                   10419: 
1.462     albertel 10420: 	$env{'user.environment'} = "$lonids/$cookie.id";
                   10421: 	
                   10422: 	if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
                   10423: 		 &GDBM_WRCREAT(),0640)) {
                   10424: 	    &_add_to_env(\%disk_env,\%initial_env);
                   10425: 	    &_add_to_env(\%disk_env,\%userenv,'environment.');
                   10426: 	    &_add_to_env(\%disk_env,$userroles);
1.463     albertel 10427: 	    if (ref($args->{'extra_env'})) {
                   10428: 		&_add_to_env(\%disk_env,$args->{'extra_env'});
                   10429: 	    }
1.462     albertel 10430: 	    untie(%disk_env);
                   10431: 	} else {
1.705     tempelho 10432: 	    &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
                   10433: 			   'Could not create environment storage in lonauth: '.$!.'</span>');
1.462     albertel 10434: 	    return 'error: '.$!;
                   10435: 	}
                   10436:     }
                   10437:     $env{'request.role'}='cm';
                   10438:     $env{'request.role.adv'}=$env{'user.adv'};
                   10439:     $env{'browser.type'}=$clientbrowser;
                   10440: 
                   10441:     return $cookie;
                   10442: 
                   10443: }
                   10444: 
                   10445: sub _add_to_env {
                   10446:     my ($idf,$env_data,$prefix) = @_;
1.676     raeburn  10447:     if (ref($env_data) eq 'HASH') {
                   10448:         while (my ($key,$value) = each(%$env_data)) {
                   10449: 	    $idf->{$prefix.$key} = $value;
                   10450: 	    $env{$prefix.$key}   = $value;
                   10451:         }
1.462     albertel 10452:     }
                   10453: }
                   10454: 
1.685     tempelho 10455: # --- Get the symbolic name of a problem and the url
                   10456: sub get_symb {
                   10457:     my ($request,$silent) = @_;
1.726     raeburn  10458:     (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685     tempelho 10459:     my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
                   10460:     if ($symb eq '') {
                   10461:         if (!$silent) {
                   10462:             $request->print("Unable to handle ambiguous references:$url:.");
                   10463:             return ();
                   10464:         }
                   10465:     }
                   10466:     &Apache::lonenc::check_decrypt(\$symb);
                   10467:     return ($symb);
                   10468: }
                   10469: 
                   10470: # --------------------------------------------------------------Get annotation
                   10471: 
                   10472: sub get_annotation {
                   10473:     my ($symb,$enc) = @_;
                   10474: 
                   10475:     my $key = $symb;
                   10476:     if (!$enc) {
                   10477:         $key =
                   10478:             &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
                   10479:     }
                   10480:     my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
                   10481:     return $annotation{$key};
                   10482: }
                   10483: 
                   10484: sub clean_symb {
1.731     raeburn  10485:     my ($symb,$delete_enc) = @_;
1.685     tempelho 10486: 
                   10487:     &Apache::lonenc::check_decrypt(\$symb);
                   10488:     my $enc = $env{'request.enc'};
1.731     raeburn  10489:     if ($delete_enc) {
1.730     raeburn  10490:         delete($env{'request.enc'});
                   10491:     }
1.685     tempelho 10492: 
                   10493:     return ($symb,$enc);
                   10494: }
1.462     albertel 10495: 
1.41      ng       10496: =pod
                   10497: 
                   10498: =back
                   10499: 
1.112     bowersj2 10500: =cut
1.41      ng       10501: 
1.112     bowersj2 10502: 1;
                   10503: __END__;
1.41      ng       10504: 

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