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

1.10      albertel    1: # The LearningOnline Network with CAPA
1.1       albertel    2: # a pile of common routines
1.10      albertel    3: #
1.695   ! raeburn     4: # $Id: loncommon.pm,v 1.694 2008/11/22 19:08:21 tempelho 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.46      matthew   274:               "<font color=yellow>INFO: Read file types</font>");
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');
                    409: <script type="text/javascript" language="Javascript" >
                    410:     var stdeditbrowser;
1.558     albertel  411:     function openstdbrowser(formname,uname,udom,roleflag,ignorefilter) {
1.74      www       412:         var url = '/adm/pickstudent?';
                    413:         var filter;
1.558     albertel  414: 	if (!ignorefilter) {
                    415: 	    eval('filter=document.'+formname+'.'+uname+'.value;');
                    416: 	}
1.74      www       417:         if (filter != null) {
                    418:            if (filter != '') {
                    419:                url += 'filter='+filter+'&';
                    420: 	   }
                    421:         }
                    422:         url += 'form=' + formname + '&unameelement='+uname+
                    423:                                     '&udomelement='+udom;
1.111     www       424: 	if (roleflag) { url+="&roles=1"; }
1.102     www       425:         var title = 'Student_Browser';
1.74      www       426:         var options = 'scrollbars=1,resizable=1,menubar=0';
                    427:         options += ',width=700,height=600';
                    428:         stdeditbrowser = open(url,title,options,'1');
                    429:         stdeditbrowser.focus();
                    430:     }
                    431: </script>
                    432: ENDSTDBRW
                    433: }
1.42      matthew   434: 
1.74      www       435: sub selectstudent_link {
1.111     www       436:    my ($form,$unameele,$udomele)=@_;
1.258     albertel  437:    if ($env{'request.course.id'}) {  
1.302     albertel  438:        if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
                    439: 	   && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
                    440: 					'/'.$env{'request.course.sec'})) {
1.111     www       441: 	   return '';
                    442:        }
                    443:        return "<a href='".'javascript:openstdbrowser("'.$form.'","'.$unameele.
1.607     albertel  444:         '","'.$udomele.'");'."'>".&mt('Select User')."</a>";
1.74      www       445:    }
1.258     albertel  446:    if ($env{'request.role'}=~/^(au|dc|su)/) {
1.111     www       447:        return "<a href='".'javascript:openstdbrowser("'.$form.'","'.$unameele.
1.119     www       448:         '","'.$udomele.'",1);'."'>".&mt('Select User')."</a>";
1.111     www       449:    }
                    450:    return '';
1.91      www       451: }
                    452: 
1.653     raeburn   453: sub authorbrowser_javascript {
                    454:     return <<"ENDAUTHORBRW";
                    455: <script type="text/javascript">
                    456: var stdeditbrowser;
                    457: 
                    458: function openauthorbrowser(formname,udom) {
                    459:     var url = '/adm/pickauthor?';
                    460:     url += 'form='+formname+'&roledom='+udom;
                    461:     var title = 'Author_Browser';
                    462:     var options = 'scrollbars=1,resizable=1,menubar=0';
                    463:     options += ',width=700,height=600';
                    464:     stdeditbrowser = open(url,title,options,'1');
                    465:     stdeditbrowser.focus();
                    466: }
                    467: 
                    468: </script>
                    469: ENDAUTHORBRW
                    470: }
                    471: 
1.91      www       472: sub coursebrowser_javascript {
1.468     raeburn   473:     my ($domainfilter,$sec_element,$formname)=@_;
1.377     raeburn   474:     my $crs_or_grp_alert = &mt('Please select the type of LON-CAPA entity - Course or Group - for which you wish to add/modify a user role');
1.468     raeburn   475:    my $output = '
1.538     albertel  476: <script type="text/javascript">
1.468     raeburn   477:     var stdeditbrowser;'."\n";
                    478:    $output .= <<"ENDSTDBRW";
1.377     raeburn   479:     function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,crstype) {
1.91      www       480:         var url = '/adm/pickcourse?';
1.468     raeburn   481:         var domainfilter = '';
                    482:         var formid = getFormIdByName(formname);
                    483:         if (formid > -1) {
                    484:             var domid = getIndexByName(formid,udom);
                    485:             if (domid > -1) {
                    486:                 if (document.forms[formid].elements[domid].type == 'select-one') {
                    487:                     domainfilter=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
                    488:                 }
                    489:                 if (document.forms[formid].elements[domid].type == 'hidden') {
                    490:                     domainfilter=document.forms[formid].elements[domid].value;
                    491:                 }
                    492:             }
1.91      www       493:         }
1.128     albertel  494:         if (domainfilter != null) {
                    495:            if (domainfilter != '') {
                    496:                url += 'domainfilter='+domainfilter+'&';
                    497: 	   }
                    498:         }
1.91      www       499:         url += 'form=' + formname + '&cnumelement='+uname+
1.187     albertel  500: 	                            '&cdomelement='+udom+
                    501:                                     '&cnameelement='+desc;
1.468     raeburn   502:         if (extra_element !=null && extra_element != '') {
1.594     raeburn   503:             if (formname == 'rolechoice' || formname == 'studentform') {
1.468     raeburn   504:                 url += '&roleelement='+extra_element;
                    505:                 if (domainfilter == null || domainfilter == '') {
                    506:                     url += '&domainfilter='+extra_element;
                    507:                 }
1.234     raeburn   508:             }
1.468     raeburn   509:             else {
                    510:                 if (formname == 'portform') {
                    511:                     url += '&setroles='+extra_element;
                    512:                 }
                    513:             }     
1.230     raeburn   514:         }
1.293     raeburn   515:         if (multflag !=null && multflag != '') {
                    516:             url += '&multiple='+multflag;
                    517:         }
1.377     raeburn   518:         if (crstype == 'Course/Group') {
                    519:             if (formname == 'cu') {
                    520:                 crstype = document.cu.crstype.options[document.cu.crstype.selectedIndex].value; 
                    521:                 if (crstype == "") {
                    522:                     alert("$crs_or_grp_alert");
                    523:                     return;
                    524:                 }
                    525:             }
                    526:         }
                    527:         if (crstype !=null && crstype != '') {
                    528:             url += '&type='+crstype;
                    529:         }
1.102     www       530:         var title = 'Course_Browser';
1.91      www       531:         var options = 'scrollbars=1,resizable=1,menubar=0';
                    532:         options += ',width=700,height=600';
                    533:         stdeditbrowser = open(url,title,options,'1');
                    534:         stdeditbrowser.focus();
                    535:     }
1.468     raeburn   536: 
                    537:     function getFormIdByName(formname) {
                    538:         for (var i=0;i<document.forms.length;i++) {
                    539:             if (document.forms[i].name == formname) {
                    540:                 return i;
                    541:             }
                    542:         }
                    543:         return -1; 
                    544:     }
                    545: 
                    546:     function getIndexByName(formid,item) {
                    547:         for (var i=0;i<document.forms[formid].elements.length;i++) {
                    548:             if (document.forms[formid].elements[i].name == item) {
                    549:                 return i;
                    550:             }
                    551:         }
                    552:         return -1;
                    553:     }
1.91      www       554: ENDSTDBRW
1.468     raeburn   555:     if ($sec_element ne '') {
                    556:         $output .= &setsec_javascript($sec_element,$formname);
                    557:     }
                    558:     $output .= '
                    559: </script>';
                    560:     return $output;
                    561: }
                    562: 
                    563: sub setsec_javascript {
                    564:     my ($sec_element,$formname) = @_;
                    565:     my $setsections = qq|
                    566: function setSect(sectionlist) {
1.629     raeburn   567:     var sectionsArray = new Array();
                    568:     if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
                    569:         sectionsArray = sectionlist.split(",");
                    570:     }
1.468     raeburn   571:     var numSections = sectionsArray.length;
                    572:     document.$formname.$sec_element.length = 0;
                    573:     if (numSections == 0) {
                    574:         document.$formname.$sec_element.multiple=false;
                    575:         document.$formname.$sec_element.size=1;
                    576:         document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
                    577:     } else {
                    578:         if (numSections == 1) {
                    579:             document.$formname.$sec_element.multiple=false;
                    580:             document.$formname.$sec_element.size=1;
                    581:             document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
                    582:             document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
                    583:             document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
                    584:         } else {
                    585:             for (var i=0; i<numSections; i++) {
                    586:                 document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
                    587:             }
                    588:             document.$formname.$sec_element.multiple=true
                    589:             if (numSections < 3) {
                    590:                 document.$formname.$sec_element.size=numSections;
                    591:             } else {
                    592:                 document.$formname.$sec_element.size=3;
                    593:             }
                    594:             document.$formname.$sec_element.options[0].selected = false
                    595:         }
                    596:     }
1.91      www       597: }
1.468     raeburn   598: |;
                    599:     return $setsections;
                    600: }
                    601: 
1.91      www       602: 
                    603: sub selectcourse_link {
1.377     raeburn   604:    my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype)=@_;
1.492     albertel  605:    return "<a href='".'javascript:opencrsbrowser("'.$form.'","'.$unameele.
                    606:         '","'.$udomele.'","'.$desc.'","'.$extra_element.'","'.$multflag.'","'.$selecttype.'");'."'>".&mt('Select Course')."</a>";
1.74      www       607: }
1.42      matthew   608: 
1.653     raeburn   609: sub selectauthor_link {
                    610:    my ($form,$udom)=@_;
                    611:    return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
                    612:           &mt('Select Author').'</a>';
                    613: }
                    614: 
1.273     raeburn   615: sub check_uncheck_jscript {
                    616:     my $jscript = <<"ENDSCRT";
                    617: function checkAll(field) {
                    618:     if (field.length > 0) {
                    619:         for (i = 0; i < field.length; i++) {
                    620:             field[i].checked = true ;
                    621:         }
                    622:     } else {
                    623:         field.checked = true
                    624:     }
                    625: }
                    626:  
                    627: function uncheckAll(field) {
                    628:     if (field.length > 0) {
                    629:         for (i = 0; i < field.length; i++) {
                    630:             field[i].checked = false ;
1.543     albertel  631:         }
                    632:     } else {
1.273     raeburn   633:         field.checked = false ;
                    634:     }
                    635: }
                    636: ENDSCRT
                    637:     return $jscript;
                    638: }
                    639: 
1.656     www       640: sub select_timezone {
1.659     raeburn   641:    my ($name,$selected,$onchange,$includeempty)=@_;
                    642:    my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
                    643:    if ($includeempty) {
                    644:        $output .= '<option value=""';
                    645:        if (($selected eq '') || ($selected eq 'local')) {
                    646:            $output .= ' selected="selected" ';
                    647:        }
                    648:        $output .= '> </option>';
                    649:    }
1.657     raeburn   650:    my @timezones = DateTime::TimeZone->all_names;
                    651:    foreach my $tzone (@timezones) {
                    652:        $output.= '<option value="'.$tzone.'"';
                    653:        if ($tzone eq $selected) {
                    654:            $output.=' selected="selected"';
                    655:        }
                    656:        $output.=">$tzone</option>\n";
1.656     www       657:    }
                    658:    $output.="</select>";
                    659:    return $output;
                    660: }
1.273     raeburn   661: 
1.687     raeburn   662: sub select_datelocale {
                    663:     my ($name,$selected,$onchange,$includeempty)=@_;
                    664:     my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
                    665:     if ($includeempty) {
                    666:         $output .= '<option value=""';
                    667:         if ($selected eq '') {
                    668:             $output .= ' selected="selected" ';
                    669:         }
                    670:         $output .= '> </option>';
                    671:     }
                    672:     my (@possibles,%locale_names);
                    673:     my @locales = DateTime::Locale::Catalog::Locales;
                    674:     foreach my $locale (@locales) {
                    675:         if (ref($locale) eq 'HASH') {
                    676:             my $id = $locale->{'id'};
                    677:             if ($id ne '') {
                    678:                 my $en_terr = $locale->{'en_territory'};
                    679:                 my $native_terr = $locale->{'native_territory'};
1.695   ! raeburn   680:                 my @languages = &Apache::lonlocal::preferred_languages();
1.687     raeburn   681:                 if (grep(/^en$/,@languages) || !@languages) {
                    682:                     if ($en_terr ne '') {
                    683:                         $locale_names{$id} = '('.$en_terr.')';
                    684:                     } elsif ($native_terr ne '') {
                    685:                         $locale_names{$id} = $native_terr;
                    686:                     }
                    687:                 } else {
                    688:                     if ($native_terr ne '') {
                    689:                         $locale_names{$id} = $native_terr.' ';
                    690:                     } elsif ($en_terr ne '') {
                    691:                         $locale_names{$id} = '('.$en_terr.')';
                    692:                     }
                    693:                 }
                    694:                 push (@possibles,$id);
                    695:             }
                    696:         }
                    697:     }
                    698:     foreach my $item (sort(@possibles)) {
                    699:         $output.= '<option value="'.$item.'"';
                    700:         if ($item eq $selected) {
                    701:             $output.=' selected="selected"';
                    702:         }
                    703:         $output.=">$item";
                    704:         if ($locale_names{$item} ne '') {
                    705:             $output.="  $locale_names{$item}</option>\n";
                    706:         }
                    707:         $output.="</option>\n";
                    708:     }
                    709:     $output.="</select>";
                    710:     return $output;
                    711: }
                    712: 
1.42      matthew   713: =pod
1.36      matthew   714: 
1.648     raeburn   715: =item * &linked_select_forms(...)
1.36      matthew   716: 
                    717: linked_select_forms returns a string containing a <script></script> block
                    718: and html for two <select> menus.  The select menus will be linked in that
                    719: changing the value of the first menu will result in new values being placed
                    720: in the second menu.  The values in the select menu will appear in alphabetical
1.609     raeburn   721: order unless a defined order is provided.
1.36      matthew   722: 
                    723: linked_select_forms takes the following ordered inputs:
                    724: 
                    725: =over 4
                    726: 
1.112     bowersj2  727: =item * $formname, the name of the <form> tag
1.36      matthew   728: 
1.112     bowersj2  729: =item * $middletext, the text which appears between the <select> tags
1.36      matthew   730: 
1.112     bowersj2  731: =item * $firstdefault, the default value for the first menu
1.36      matthew   732: 
1.112     bowersj2  733: =item * $firstselectname, the name of the first <select> tag
1.36      matthew   734: 
1.112     bowersj2  735: =item * $secondselectname, the name of the second <select> tag
1.36      matthew   736: 
1.112     bowersj2  737: =item * $hashref, a reference to a hash containing the data for the menus.
1.36      matthew   738: 
1.609     raeburn   739: =item * $menuorder, the order of values in the first menu
                    740: 
1.41      ng        741: =back 
                    742: 
1.36      matthew   743: Below is an example of such a hash.  Only the 'text', 'default', and 
                    744: 'select2' keys must appear as stated.  keys(%menu) are the possible 
                    745: values for the first select menu.  The text that coincides with the 
1.41      ng        746: first menu value is given in $menu{$choice1}->{'text'}.  The values 
1.36      matthew   747: and text for the second menu are given in the hash pointed to by 
                    748: $menu{$choice1}->{'select2'}.  
                    749: 
1.112     bowersj2  750:  my %menu = ( A1 => { text =>"Choice A1" ,
                    751:                        default => "B3",
                    752:                        select2 => { 
                    753:                            B1 => "Choice B1",
                    754:                            B2 => "Choice B2",
                    755:                            B3 => "Choice B3",
                    756:                            B4 => "Choice B4"
1.609     raeburn   757:                            },
                    758:                        order => ['B4','B3','B1','B2'],
1.112     bowersj2  759:                    },
                    760:                A2 => { text =>"Choice A2" ,
                    761:                        default => "C2",
                    762:                        select2 => { 
                    763:                            C1 => "Choice C1",
                    764:                            C2 => "Choice C2",
                    765:                            C3 => "Choice C3"
1.609     raeburn   766:                            },
                    767:                        order => ['C2','C1','C3'],
1.112     bowersj2  768:                    },
                    769:                A3 => { text =>"Choice A3" ,
                    770:                        default => "D6",
                    771:                        select2 => { 
                    772:                            D1 => "Choice D1",
                    773:                            D2 => "Choice D2",
                    774:                            D3 => "Choice D3",
                    775:                            D4 => "Choice D4",
                    776:                            D5 => "Choice D5",
                    777:                            D6 => "Choice D6",
                    778:                            D7 => "Choice D7"
1.609     raeburn   779:                            },
                    780:                        order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112     bowersj2  781:                    }
                    782:                );
1.36      matthew   783: 
                    784: =cut
                    785: 
                    786: sub linked_select_forms {
                    787:     my ($formname,
                    788:         $middletext,
                    789:         $firstdefault,
                    790:         $firstselectname,
                    791:         $secondselectname, 
1.609     raeburn   792:         $hashref,
                    793:         $menuorder,
1.36      matthew   794:         ) = @_;
                    795:     my $second = "document.$formname.$secondselectname";
                    796:     my $first = "document.$formname.$firstselectname";
                    797:     # output the javascript to do the changing
                    798:     my $result = '';
1.219     albertel  799:     $result.="<script type=\"text/javascript\">\n";
1.36      matthew   800:     $result.="var select2data = new Object();\n";
                    801:     $" = '","';
                    802:     my $debug = '';
                    803:     foreach my $s1 (sort(keys(%$hashref))) {
                    804:         $result.="select2data.d_$s1 = new Object();\n";        
                    805:         $result.="select2data.d_$s1.def = new String('".
                    806:             $hashref->{$s1}->{'default'}."');\n";
1.609     raeburn   807:         $result.="select2data.d_$s1.values = new Array(";
1.36      matthew   808:         my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609     raeburn   809:         if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
                    810:             @s2values = @{$hashref->{$s1}->{'order'}};
                    811:         }
1.36      matthew   812:         $result.="\"@s2values\");\n";
                    813:         $result.="select2data.d_$s1.texts = new Array(";        
                    814:         my @s2texts;
                    815:         foreach my $value (@s2values) {
                    816:             push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
                    817:         }
                    818:         $result.="\"@s2texts\");\n";
                    819:     }
                    820:     $"=' ';
                    821:     $result.= <<"END";
                    822: 
                    823: function select1_changed() {
                    824:     // Determine new choice
                    825:     var newvalue = "d_" + $first.value;
                    826:     // update select2
                    827:     var values     = select2data[newvalue].values;
                    828:     var texts      = select2data[newvalue].texts;
                    829:     var select2def = select2data[newvalue].def;
                    830:     var i;
                    831:     // out with the old
                    832:     for (i = 0; i < $second.options.length; i++) {
                    833:         $second.options[i] = null;
                    834:     }
                    835:     // in with the nuclear
                    836:     for (i=0;i<values.length; i++) {
                    837:         $second.options[i] = new Option(values[i]);
1.143     matthew   838:         $second.options[i].value = values[i];
1.36      matthew   839:         $second.options[i].text = texts[i];
                    840:         if (values[i] == select2def) {
                    841:             $second.options[i].selected = true;
                    842:         }
                    843:     }
                    844: }
                    845: </script>
                    846: END
                    847:     # output the initial values for the selection lists
                    848:     $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609     raeburn   849:     my @order = sort(keys(%{$hashref}));
                    850:     if (ref($menuorder) eq 'ARRAY') {
                    851:         @order = @{$menuorder};
                    852:     }
                    853:     foreach my $value (@order) {
1.36      matthew   854:         $result.="    <option value=\"$value\" ";
1.253     albertel  855:         $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119     www       856:         $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36      matthew   857:     }
                    858:     $result .= "</select>\n";
                    859:     my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
                    860:     $result .= $middletext;
                    861:     $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
                    862:     my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609     raeburn   863:     
                    864:     my @secondorder = sort(keys(%select2));
                    865:     if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
                    866:         @secondorder = @{$hashref->{$firstdefault}->{'order'}};
                    867:     }
                    868:     foreach my $value (@secondorder) {
1.36      matthew   869:         $result.="    <option value=\"$value\" ";        
1.253     albertel  870:         $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119     www       871:         $result.=">".&mt($select2{$value})."</option>\n";
1.36      matthew   872:     }
                    873:     $result .= "</select>\n";
                    874:     #    return $debug;
                    875:     return $result;
                    876: }   #  end of sub linked_select_forms {
                    877: 
1.45      matthew   878: =pod
1.44      bowersj2  879: 
1.648     raeburn   880: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height)
1.44      bowersj2  881: 
1.112     bowersj2  882: Returns a string corresponding to an HTML link to the given help
                    883: $topic, where $topic corresponds to the name of a .tex file in
                    884: /home/httpd/html/adm/help/tex, with underscores replaced by
                    885: spaces. 
                    886: 
                    887: $text will optionally be linked to the same topic, allowing you to
                    888: link text in addition to the graphic. If you do not want to link
                    889: text, but wish to specify one of the later parameters, pass an
                    890: empty string. 
                    891: 
                    892: $stayOnPage is a value that will be interpreted as a boolean. If true,
                    893: the link will not open a new window. If false, the link will open
                    894: a new window using Javascript. (Default is false.) 
                    895: 
                    896: $width and $height are optional numerical parameters that will
                    897: override the width and height of the popped up window, which may
                    898: be useful for certain help topics with big pictures included. 
1.44      bowersj2  899: 
                    900: =cut
                    901: 
                    902: sub help_open_topic {
1.48      bowersj2  903:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
                    904:     $text = "" if (not defined $text);
1.44      bowersj2  905:     $stayOnPage = 0 if (not defined $stayOnPage);
1.552     banghart  906:     if ($env{'browser.interface'} eq 'textual') {
1.79      www       907: 	$stayOnPage=1;
                    908:     }
1.44      bowersj2  909:     $width = 350 if (not defined $width);
                    910:     $height = 400 if (not defined $height);
                    911:     my $filename = $topic;
                    912:     $filename =~ s/ /_/g;
                    913: 
1.48      bowersj2  914:     my $template = "";
                    915:     my $link;
1.572     banghart  916:     
1.159     www       917:     $topic=~s/\W/\_/g;
1.44      bowersj2  918: 
1.572     banghart  919:     if (!$stayOnPage) {
1.72      bowersj2  920: 	$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  921:     } else {
1.48      bowersj2  922: 	$link = "/adm/help/${filename}.hlp";
                    923:     }
                    924: 
                    925:     # Add the text
1.572     banghart  926:     if ($text ne "") {
1.77      www       927: 	$template .= 
1.572     banghart  928:             "<table bgcolor='#3333AA' cellspacing='1' cellpadding='1' border='0'><tr>".
1.691     bisitz    929:             "<td bgcolor='#5555FF'><span class=\"LC_nobreak\"><a target=\"_top\" href=\"$link\"><font color='#FFFFFF' size='2'>$text</font></a>";
1.48      bowersj2  930:     }
                    931: 
                    932:     # Add the graphic
1.179     matthew   933:     my $title = &mt('Online Help');
1.667     raeburn   934:     my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.48      bowersj2  935:     $template .= <<"ENDTEMPLATE";
1.436     albertel  936:  <a target="_top" href="$link" title="$title"><img src="$helpicon" border="0" alt="(Help: $topic)" /></a>
1.44      bowersj2  937: ENDTEMPLATE
1.691     bisitz    938:     if ($text ne '') { $template.='</span></td></tr></table>' };
1.44      bowersj2  939:     return $template;
                    940: 
1.106     bowersj2  941: }
                    942: 
                    943: # This is a quicky function for Latex cheatsheet editing, since it 
                    944: # appears in at least four places
                    945: sub helpLatexCheatsheet {
                    946:     my $other = shift;
                    947:     my $addOther = '';
                    948:     if ($other) {
                    949: 	$addOther = Apache::loncommon::help_open_topic($other, shift,
                    950: 						       undef, undef, 600) .
                    951: 							   '</td><td>';
                    952:     }
                    953:     return '<table><tr><td>'.
                    954: 	$addOther .
1.636     raeburn   955: 	&Apache::loncommon::help_open_topic("Greek_Symbols",&mt('Greek Symbols'),
1.106     bowersj2  956: 					    undef,undef,600)
                    957: 	.'</td><td>'.
1.636     raeburn   958: 	&Apache::loncommon::help_open_topic("Other_Symbols",&mt('Other Symbols'),
1.106     bowersj2  959: 					    undef,undef,600)
1.673     felicia   960: 	.'</td><td>'.
                    961: 	&Apache::loncommon::help_open_topic("Authoring_Output_Tags",&mt('Output Tags'),
                    962: 	                                    undef,undef,600)
1.106     bowersj2  963: 	.'</td></tr></table>';
1.172     www       964: }
                    965: 
1.430     albertel  966: sub general_help {
                    967:     my $helptopic='Student_Intro';
                    968:     if ($env{'request.role'}=~/^(ca|au)/) {
                    969: 	$helptopic='Authoring_Intro';
                    970:     } elsif ($env{'request.role'}=~/^cc/) {
                    971: 	$helptopic='Course_Coordination_Intro';
1.672     raeburn   972:     } elsif ($env{'request.role'}=~/^dc/) {
                    973:         $helptopic='Domain_Coordination_Intro';
1.430     albertel  974:     }
                    975:     return $helptopic;
                    976: }
                    977: 
                    978: sub update_help_link {
                    979:     my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
                    980:     my $origurl = $ENV{'REQUEST_URI'};
                    981:     $origurl=~s|^/~|/priv/|;
                    982:     my $timestamp = time;
                    983:     foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
                    984:         $$datum = &escape($$datum);
                    985:     }
                    986: 
                    987:     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";
                    988:     my $output .= <<"ENDOUTPUT";
                    989: <script type="text/javascript">
                    990: banner_link = '$banner_link';
                    991: </script>
                    992: ENDOUTPUT
                    993:     return $output;
                    994: }
                    995: 
                    996: # now just updates the help link and generates a blue icon
1.193     raeburn   997: sub help_open_menu {
1.430     albertel  998:     my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text) 
1.552     banghart  999: 	= @_;    
1.430     albertel 1000:     $stayOnPage = 0 if (not defined $stayOnPage);
1.572     banghart 1001:     # only use pop-up help (stayOnPage == 0)
1.552     banghart 1002:     # if environment.remote is on (using remote control UI)
1.572     banghart 1003:     if ($env{'browser.interface'} eq 'textual' ||
                   1004:     	$env{'environment.remote'} eq 'off' ) {
1.552     banghart 1005:         $stayOnPage=1;
1.430     albertel 1006:     }
                   1007:     my $output;
                   1008:     if ($component_help) {
                   1009: 	if (!$text) {
                   1010: 	    $output=&help_open_topic($component_help,undef,$stayOnPage,
                   1011: 				       $width,$height);
                   1012: 	} else {
                   1013: 	    my $help_text;
                   1014: 	    $help_text=&unescape($topic);
                   1015: 	    $output='<table><tr><td>'.
                   1016: 		&help_open_topic($component_help,$help_text,$stayOnPage,
                   1017: 				 $width,$height).'</td></tr></table>';
                   1018: 	}
                   1019:     }
                   1020:     my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
                   1021:     return $output.$banner_link;
                   1022: }
                   1023: 
                   1024: sub top_nav_help {
                   1025:     my ($text) = @_;
1.436     albertel 1026:     $text = &mt($text);
1.572     banghart 1027:     my $stay_on_page = 
1.436     albertel 1028: 	($env{'browser.interface'}  eq 'textual' ||
                   1029: 	 $env{'environment.remote'} eq 'off' );
1.572     banghart 1030:     my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436     albertel 1031: 	                     : "javascript:helpMenu('open')";
1.572     banghart 1032:     my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436     albertel 1033: 
1.201     raeburn  1034:     my $title = &mt('Get help');
1.436     albertel 1035: 
                   1036:     return <<"END";
                   1037: $banner_link
                   1038:  <a href="$link" title="$title">$text</a>
                   1039: END
                   1040: }
                   1041: 
                   1042: sub help_menu_js {
                   1043:     my ($text) = @_;
                   1044: 
                   1045:     my $stayOnPage = 
                   1046: 	($env{'browser.interface'}  eq 'textual' ||
                   1047: 	 $env{'environment.remote'} eq 'off' );
                   1048: 
                   1049:     my $width = 620;
                   1050:     my $height = 600;
1.430     albertel 1051:     my $helptopic=&general_help();
                   1052:     my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261     albertel 1053:     my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331     albertel 1054:     my $start_page =
                   1055:         &Apache::loncommon::start_page('Help Menu', undef,
                   1056: 				       {'frameset'    => 1,
                   1057: 					'js_ready'    => 1,
                   1058: 					'add_entries' => {
                   1059: 					    'border' => '0',
1.579     raeburn  1060: 					    'rows'   => "110,*",},});
1.331     albertel 1061:     my $end_page =
                   1062:         &Apache::loncommon::end_page({'frameset' => 1,
                   1063: 				      'js_ready' => 1,});
                   1064: 
1.436     albertel 1065:     my $template .= <<"ENDTEMPLATE";
                   1066: <script type="text/javascript">
1.253     albertel 1067: // <!-- BEGIN LON-CAPA Internal
                   1068: // <![CDATA[
1.430     albertel 1069: var banner_link = '';
1.243     raeburn  1070: function helpMenu(target) {
                   1071:     var caller = this;
                   1072:     if (target == 'open') {
                   1073:         var newWindow = null;
                   1074:         try {
1.262     albertel 1075:             newWindow =  window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243     raeburn  1076:         }
                   1077:         catch(error) {
                   1078:             writeHelp(caller);
                   1079:             return;
                   1080:         }
                   1081:         if (newWindow) {
                   1082:             caller = newWindow;
                   1083:         }
1.193     raeburn  1084:     }
1.243     raeburn  1085:     writeHelp(caller);
                   1086:     return;
                   1087: }
                   1088: function writeHelp(caller) {
1.430     albertel 1089:     caller.document.writeln('$start_page<frame name="bannerframe"  src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243     raeburn  1090:     caller.document.close()
                   1091:     caller.focus()
1.193     raeburn  1092: }
1.253     albertel 1093: // ]]>
1.219     albertel 1094: // END LON-CAPA Internal -->
1.436     albertel 1095: </script>
1.193     raeburn  1096: ENDTEMPLATE
                   1097:     return $template;
                   1098: }
                   1099: 
1.172     www      1100: sub help_open_bug {
                   1101:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258     albertel 1102:     unless ($env{'user.adv'}) { return ''; }
1.172     www      1103:     unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
                   1104:     $text = "" if (not defined $text);
                   1105:     $stayOnPage = 0 if (not defined $stayOnPage);
1.258     albertel 1106:     if ($env{'browser.interface'} eq 'textual' ||
                   1107: 	$env{'environment.remote'} eq 'off' ) {
1.172     www      1108: 	$stayOnPage=1;
                   1109:     }
1.184     albertel 1110:     $width = 600 if (not defined $width);
                   1111:     $height = 600 if (not defined $height);
1.172     www      1112: 
                   1113:     $topic=~s/\W+/\+/g;
                   1114:     my $link='';
                   1115:     my $template='';
1.379     albertel 1116:     my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&amp;bug_file_loc='.
                   1117: 	&escape($ENV{'REQUEST_URI'}).'&amp;component='.$topic;
1.172     www      1118:     if (!$stayOnPage)
                   1119:     {
                   1120: 	$link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
                   1121:     }
                   1122:     else
                   1123:     {
                   1124: 	$link = $url;
                   1125:     }
                   1126:     # Add the text
                   1127:     if ($text ne "")
                   1128:     {
                   1129: 	$template .= 
                   1130:   "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.436     albertel 1131:   "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><font color='#FFFFFF' size='2'>$text</font></a>";
1.172     www      1132:     }
                   1133: 
                   1134:     # Add the graphic
1.179     matthew  1135:     my $title = &mt('Report a Bug');
1.215     albertel 1136:     my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172     www      1137:     $template .= <<"ENDTEMPLATE";
1.436     albertel 1138:  <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172     www      1139: ENDTEMPLATE
                   1140:     if ($text ne '') { $template.='</td></tr></table>' };
                   1141:     return $template;
                   1142: 
                   1143: }
                   1144: 
                   1145: sub help_open_faq {
                   1146:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258     albertel 1147:     unless ($env{'user.adv'}) { return ''; }
1.172     www      1148:     unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
                   1149:     $text = "" if (not defined $text);
                   1150:     $stayOnPage = 0 if (not defined $stayOnPage);
1.258     albertel 1151:     if ($env{'browser.interface'} eq 'textual' ||
                   1152: 	$env{'environment.remote'} eq 'off' ) {
1.172     www      1153: 	$stayOnPage=1;
                   1154:     }
                   1155:     $width = 350 if (not defined $width);
                   1156:     $height = 400 if (not defined $height);
                   1157: 
                   1158:     $topic=~s/\W+/\+/g;
                   1159:     my $link='';
                   1160:     my $template='';
                   1161:     my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
                   1162:     if (!$stayOnPage)
                   1163:     {
                   1164: 	$link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
                   1165:     }
                   1166:     else
                   1167:     {
                   1168: 	$link = $url;
                   1169:     }
                   1170: 
                   1171:     # Add the text
                   1172:     if ($text ne "")
                   1173:     {
                   1174: 	$template .= 
1.173     www      1175:   "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.436     albertel 1176:   "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><font color='#FFFFFF' size='2'>$text</font></a>";
1.172     www      1177:     }
                   1178: 
                   1179:     # Add the graphic
1.179     matthew  1180:     my $title = &mt('View the FAQ');
1.215     albertel 1181:     my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172     www      1182:     $template .= <<"ENDTEMPLATE";
1.436     albertel 1183:  <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172     www      1184: ENDTEMPLATE
                   1185:     if ($text ne '') { $template.='</td></tr></table>' };
                   1186:     return $template;
                   1187: 
1.44      bowersj2 1188: }
1.37      matthew  1189: 
1.180     matthew  1190: ###############################################################
                   1191: ###############################################################
                   1192: 
1.45      matthew  1193: =pod
                   1194: 
1.648     raeburn  1195: =item * &change_content_javascript():
1.256     matthew  1196: 
                   1197: This and the next function allow you to create small sections of an
                   1198: otherwise static HTML page that you can update on the fly with
                   1199: Javascript, even in Netscape 4.
                   1200: 
                   1201: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
                   1202: must be written to the HTML page once. It will prove the Javascript
                   1203: function "change(name, content)". Calling the change function with the
                   1204: name of the section 
                   1205: you want to update, matching the name passed to C<changable_area>, and
                   1206: the new content you want to put in there, will put the content into
                   1207: that area.
                   1208: 
                   1209: B<Note>: Netscape 4 only reserves enough space for the changable area
                   1210: to contain room for the original contents. You need to "make space"
                   1211: for whatever changes you wish to make, and be B<sure> to check your
                   1212: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
                   1213: it's adequate for updating a one-line status display, but little more.
                   1214: This script will set the space to 100% width, so you only need to
                   1215: worry about height in Netscape 4.
                   1216: 
                   1217: Modern browsers are much less limiting, and if you can commit to the
                   1218: user not using Netscape 4, this feature may be used freely with
                   1219: pretty much any HTML.
                   1220: 
                   1221: =cut
                   1222: 
                   1223: sub change_content_javascript {
                   1224:     # If we're on Netscape 4, we need to use Layer-based code
1.258     albertel 1225:     if ($env{'browser.type'} eq 'netscape' &&
                   1226: 	$env{'browser.version'} =~ /^4\./) {
1.256     matthew  1227: 	return (<<NETSCAPE4);
                   1228: 	function change(name, content) {
                   1229: 	    doc = document.layers[name+"___escape"].layers[0].document;
                   1230: 	    doc.open();
                   1231: 	    doc.write(content);
                   1232: 	    doc.close();
                   1233: 	}
                   1234: NETSCAPE4
                   1235:     } else {
                   1236: 	# Otherwise, we need to use semi-standards-compliant code
                   1237: 	# (technically, "innerHTML" isn't standard but the equivalent
                   1238: 	# is really scary, and every useful browser supports it
                   1239: 	return (<<DOMBASED);
                   1240: 	function change(name, content) {
                   1241: 	    element = document.getElementById(name);
                   1242: 	    element.innerHTML = content;
                   1243: 	}
                   1244: DOMBASED
                   1245:     }
                   1246: }
                   1247: 
                   1248: =pod
                   1249: 
1.648     raeburn  1250: =item * &changable_area($name,$origContent):
1.256     matthew  1251: 
                   1252: This provides a "changable area" that can be modified on the fly via
                   1253: the Javascript code provided in C<change_content_javascript>. $name is
                   1254: the name you will use to reference the area later; do not repeat the
                   1255: same name on a given HTML page more then once. $origContent is what
                   1256: the area will originally contain, which can be left blank.
                   1257: 
                   1258: =cut
                   1259: 
                   1260: sub changable_area {
                   1261:     my ($name, $origContent) = @_;
                   1262: 
1.258     albertel 1263:     if ($env{'browser.type'} eq 'netscape' &&
                   1264: 	$env{'browser.version'} =~ /^4\./) {
1.256     matthew  1265: 	# If this is netscape 4, we need to use the Layer tag
                   1266: 	return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
                   1267:     } else {
                   1268: 	return "<span id='$name'>$origContent</span>";
                   1269:     }
                   1270: }
                   1271: 
                   1272: =pod
                   1273: 
1.648     raeburn  1274: =item * &viewport_geometry_js 
1.590     raeburn  1275: 
                   1276: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
                   1277: 
                   1278: =cut
                   1279: 
                   1280: 
                   1281: sub viewport_geometry_js { 
                   1282:     return <<"GEOMETRY";
                   1283: var Geometry = {};
                   1284: function init_geometry() {
                   1285:     if (Geometry.init) { return };
                   1286:     Geometry.init=1;
                   1287:     if (window.innerHeight) {
                   1288:         Geometry.getViewportHeight   = function() { return window.innerHeight; };
                   1289:         Geometry.getViewportWidth   = function() { return window.innerWidth; };
                   1290:         Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
                   1291:         Geometry.getVerticalScroll   = function() { return window.pageYOffset; };
                   1292:     }
                   1293:     else if (document.documentElement && document.documentElement.clientHeight) {
                   1294:         Geometry.getViewportHeight =
                   1295:             function() { return document.documentElement.clientHeight; };
                   1296:         Geometry.getViewportWidth =
                   1297:             function() { return document.documentElement.clientWidth; };
                   1298: 
                   1299:         Geometry.getHorizontalScroll =
                   1300:             function() { return document.documentElement.scrollLeft; };
                   1301:         Geometry.getVerticalScroll =
                   1302:             function() { return document.documentElement.scrollTop; };
                   1303:     }
                   1304:     else if (document.body.clientHeight) {
                   1305:         Geometry.getViewportHeight =
                   1306:             function() { return document.body.clientHeight; };
                   1307:         Geometry.getViewportWidth =
                   1308:             function() { return document.body.clientWidth; };
                   1309:         Geometry.getHorizontalScroll =
                   1310:             function() { return document.body.scrollLeft; };
                   1311:         Geometry.getVerticalScroll =
                   1312:             function() { return document.body.scrollTop; };
                   1313:     }
                   1314: }
                   1315: 
                   1316: GEOMETRY
                   1317: }
                   1318: 
                   1319: =pod
                   1320: 
1.648     raeburn  1321: =item * &viewport_size_js()
1.590     raeburn  1322: 
                   1323: 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. 
                   1324: 
                   1325: =cut
                   1326: 
                   1327: sub viewport_size_js {
                   1328:     my $geometry = &viewport_geometry_js();
                   1329:     return <<"DIMS";
                   1330: 
                   1331: $geometry
                   1332: 
                   1333: function getViewportDims(width,height) {
                   1334:     init_geometry();
                   1335:     width.value = Geometry.getViewportWidth();
                   1336:     height.value = Geometry.getViewportHeight();
                   1337:     return;
                   1338: }
                   1339: 
                   1340: DIMS
                   1341: }
                   1342: 
                   1343: =pod
                   1344: 
1.648     raeburn  1345: =item * &resize_textarea_js()
1.565     albertel 1346: 
                   1347: emits the needed javascript to resize a textarea to be as big as possible
                   1348: 
                   1349: creates a function resize_textrea that takes two IDs first should be
                   1350: the id of the element to resize, second should be the id of a div that
                   1351: surrounds everything that comes after the textarea, this routine needs
                   1352: to be attached to the <body> for the onload and onresize events.
                   1353: 
1.648     raeburn  1354: =back
1.565     albertel 1355: 
                   1356: =cut
                   1357: 
                   1358: sub resize_textarea_js {
1.590     raeburn  1359:     my $geometry = &viewport_geometry_js();
1.565     albertel 1360:     return <<"RESIZE";
                   1361:     <script type="text/javascript">
1.590     raeburn  1362: $geometry
1.565     albertel 1363: 
1.588     albertel 1364: function getX(element) {
                   1365:     var x = 0;
                   1366:     while (element) {
                   1367: 	x += element.offsetLeft;
                   1368: 	element = element.offsetParent;
                   1369:     }
                   1370:     return x;
                   1371: }
                   1372: function getY(element) {
                   1373:     var y = 0;
                   1374:     while (element) {
                   1375: 	y += element.offsetTop;
                   1376: 	element = element.offsetParent;
                   1377:     }
                   1378:     return y;
                   1379: }
                   1380: 
                   1381: 
1.565     albertel 1382: function resize_textarea(textarea_id,bottom_id) {
                   1383:     init_geometry();
                   1384:     var textarea        = document.getElementById(textarea_id);
                   1385:     //alert(textarea);
                   1386: 
1.588     albertel 1387:     var textarea_top    = getY(textarea);
1.565     albertel 1388:     var textarea_height = textarea.offsetHeight;
                   1389:     var bottom          = document.getElementById(bottom_id);
1.588     albertel 1390:     var bottom_top      = getY(bottom);
1.565     albertel 1391:     var bottom_height   = bottom.offsetHeight;
                   1392:     var window_height   = Geometry.getViewportHeight();
1.588     albertel 1393:     var fudge           = 23;
1.565     albertel 1394:     var new_height      = window_height-fudge-textarea_top-bottom_height;
                   1395:     if (new_height < 300) {
                   1396: 	new_height = 300;
                   1397:     }
                   1398:     textarea.style.height=new_height+'px';
                   1399: }
                   1400: </script>
                   1401: RESIZE
                   1402: 
                   1403: }
                   1404: 
                   1405: =pod
                   1406: 
1.256     matthew  1407: =head1 Excel and CSV file utility routines
                   1408: 
                   1409: =over 4
                   1410: 
                   1411: =cut
                   1412: 
                   1413: ###############################################################
                   1414: ###############################################################
                   1415: 
                   1416: =pod
                   1417: 
1.648     raeburn  1418: =item * &csv_translate($text) 
1.37      matthew  1419: 
1.185     www      1420: Translate $text to allow it to be output as a 'comma separated values' 
1.37      matthew  1421: format.
                   1422: 
                   1423: =cut
                   1424: 
1.180     matthew  1425: ###############################################################
                   1426: ###############################################################
1.37      matthew  1427: sub csv_translate {
                   1428:     my $text = shift;
                   1429:     $text =~ s/\"/\"\"/g;
1.209     albertel 1430:     $text =~ s/\n/ /g;
1.37      matthew  1431:     return $text;
                   1432: }
1.180     matthew  1433: 
                   1434: ###############################################################
                   1435: ###############################################################
                   1436: 
                   1437: =pod
                   1438: 
1.648     raeburn  1439: =item * &define_excel_formats()
1.180     matthew  1440: 
                   1441: Define some commonly used Excel cell formats.
                   1442: 
                   1443: Currently supported formats:
                   1444: 
                   1445: =over 4
                   1446: 
                   1447: =item header
                   1448: 
                   1449: =item bold
                   1450: 
                   1451: =item h1
                   1452: 
                   1453: =item h2
                   1454: 
                   1455: =item h3
                   1456: 
1.256     matthew  1457: =item h4
                   1458: 
                   1459: =item i
                   1460: 
1.180     matthew  1461: =item date
                   1462: 
                   1463: =back
                   1464: 
                   1465: Inputs: $workbook
                   1466: 
                   1467: Returns: $format, a hash reference.
                   1468: 
                   1469: =cut
                   1470: 
                   1471: ###############################################################
                   1472: ###############################################################
                   1473: sub define_excel_formats {
                   1474:     my ($workbook) = @_;
                   1475:     my $format;
                   1476:     $format->{'header'} = $workbook->add_format(bold      => 1, 
                   1477:                                                 bottom    => 1,
                   1478:                                                 align     => 'center');
                   1479:     $format->{'bold'} = $workbook->add_format(bold=>1);
                   1480:     $format->{'h1'}   = $workbook->add_format(bold=>1, size=>18);
                   1481:     $format->{'h2'}   = $workbook->add_format(bold=>1, size=>16);
                   1482:     $format->{'h3'}   = $workbook->add_format(bold=>1, size=>14);
1.255     matthew  1483:     $format->{'h4'}   = $workbook->add_format(bold=>1, size=>12);
1.246     matthew  1484:     $format->{'i'}    = $workbook->add_format(italic=>1);
1.180     matthew  1485:     $format->{'date'} = $workbook->add_format(num_format=>
1.207     matthew  1486:                                             'mm/dd/yyyy hh:mm:ss');
1.180     matthew  1487:     return $format;
                   1488: }
                   1489: 
                   1490: ###############################################################
                   1491: ###############################################################
1.113     bowersj2 1492: 
                   1493: =pod
                   1494: 
1.648     raeburn  1495: =item * &create_workbook()
1.255     matthew  1496: 
                   1497: Create an Excel worksheet.  If it fails, output message on the
                   1498: request object and return undefs.
                   1499: 
                   1500: Inputs: Apache request object
                   1501: 
                   1502: Returns (undef) on failure, 
                   1503:     Excel worksheet object, scalar with filename, and formats 
                   1504:     from &Apache::loncommon::define_excel_formats on success
                   1505: 
                   1506: =cut
                   1507: 
                   1508: ###############################################################
                   1509: ###############################################################
                   1510: sub create_workbook {
                   1511:     my ($r) = @_;
                   1512:         #
                   1513:     # Create the excel spreadsheet
                   1514:     my $filename = '/prtspool/'.
1.258     albertel 1515:         $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255     matthew  1516:         time.'_'.rand(1000000000).'.xls';
                   1517:     my $workbook  = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
                   1518:     if (! defined($workbook)) {
                   1519:         $r->log_error("Error creating excel spreadsheet $filename: $!");
                   1520:         $r->print('<p>'.&mt("Unable to create new Excel file.  ".
                   1521:                             "This error has been logged.  ".
                   1522:                             "Please alert your LON-CAPA administrator").
                   1523:                   '</p>');
                   1524:         return (undef);
                   1525:     }
                   1526:     #
                   1527:     $workbook->set_tempdir('/home/httpd/perl/tmp');
                   1528:     #
                   1529:     my $format = &Apache::loncommon::define_excel_formats($workbook);
                   1530:     return ($workbook,$filename,$format);
                   1531: }
                   1532: 
                   1533: ###############################################################
                   1534: ###############################################################
                   1535: 
                   1536: =pod
                   1537: 
1.648     raeburn  1538: =item * &create_text_file()
1.113     bowersj2 1539: 
1.542     raeburn  1540: Create a file to write to and eventually make available to the user.
1.256     matthew  1541: If file creation fails, outputs an error message on the request object and 
                   1542: return undefs.
1.113     bowersj2 1543: 
1.256     matthew  1544: Inputs: Apache request object, and file suffix
1.113     bowersj2 1545: 
1.256     matthew  1546: Returns (undef) on failure, 
                   1547:     Filehandle and filename on success.
1.113     bowersj2 1548: 
                   1549: =cut
                   1550: 
1.256     matthew  1551: ###############################################################
                   1552: ###############################################################
                   1553: sub create_text_file {
                   1554:     my ($r,$suffix) = @_;
                   1555:     if (! defined($suffix)) { $suffix = 'txt'; };
                   1556:     my $fh;
                   1557:     my $filename = '/prtspool/'.
1.258     albertel 1558:         $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256     matthew  1559:         time.'_'.rand(1000000000).'.'.$suffix;
                   1560:     $fh = Apache::File->new('>/home/httpd'.$filename);
                   1561:     if (! defined($fh)) {
                   1562:         $r->log_error("Couldn't open $filename for output $!");
1.683     bisitz   1563:         $r->print(&mt('Problems occurred in creating the output file. '
                   1564:                      .'This error has been logged. '
                   1565:                      .'Please alert your LON-CAPA administrator.'));
1.113     bowersj2 1566:     }
1.256     matthew  1567:     return ($fh,$filename)
1.113     bowersj2 1568: }
                   1569: 
                   1570: 
1.256     matthew  1571: =pod 
1.113     bowersj2 1572: 
                   1573: =back
                   1574: 
                   1575: =cut
1.37      matthew  1576: 
                   1577: ###############################################################
1.33      matthew  1578: ##        Home server <option> list generating code          ##
                   1579: ###############################################################
1.35      matthew  1580: 
1.169     www      1581: # ------------------------------------------
                   1582: 
                   1583: sub domain_select {
                   1584:     my ($name,$value,$multiple)=@_;
                   1585:     my %domains=map { 
1.514     albertel 1586: 	$_ => $_.' '. &Apache::lonnet::domain($_,'description') 
1.512     albertel 1587:     } &Apache::lonnet::all_domains();
1.169     www      1588:     if ($multiple) {
                   1589: 	$domains{''}=&mt('Any domain');
1.550     albertel 1590: 	$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287     albertel 1591: 	return &multiple_select_form($name,$value,4,\%domains);
1.169     www      1592:     } else {
1.550     albertel 1593: 	$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.169     www      1594: 	return &select_form($name,$value,%domains);
                   1595:     }
                   1596: }
                   1597: 
1.282     albertel 1598: #-------------------------------------------
                   1599: 
                   1600: =pod
                   1601: 
1.519     raeburn  1602: =head1 Routines for form select boxes
                   1603: 
                   1604: =over 4
                   1605: 
1.648     raeburn  1606: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282     albertel 1607: 
                   1608: Returns a string containing a <select> element int multiple mode
                   1609: 
                   1610: 
                   1611: Args:
                   1612:   $name - name of the <select> element
1.506     raeburn  1613:   $value - scalar or array ref of values that should already be selected
1.282     albertel 1614:   $size - number of rows long the select element is
1.283     albertel 1615:   $hash - the elements should be 'option' => 'shown text'
1.282     albertel 1616:           (shown text should already have been &mt())
1.506     raeburn  1617:   $order - (optional) array ref of the order to show the elements in
1.283     albertel 1618: 
1.282     albertel 1619: =cut
                   1620: 
                   1621: #-------------------------------------------
1.169     www      1622: sub multiple_select_form {
1.284     albertel 1623:     my ($name,$value,$size,$hash,$order)=@_;
1.169     www      1624:     my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
                   1625:     my $output='';
1.191     matthew  1626:     if (! defined($size)) {
                   1627:         $size = 4;
1.283     albertel 1628:         if (scalar(keys(%$hash))<4) {
                   1629:             $size = scalar(keys(%$hash));
1.191     matthew  1630:         }
                   1631:     }
1.169     www      1632:     $output.="\n<select name='$name' size='$size' multiple='1'>";
1.501     banghart 1633:     my @order;
1.506     raeburn  1634:     if (ref($order) eq 'ARRAY')  {
                   1635:         @order = @{$order};
                   1636:     } else {
                   1637:         @order = sort(keys(%$hash));
1.501     banghart 1638:     }
                   1639:     if (exists($$hash{'select_form_order'})) {
                   1640:         @order = @{$$hash{'select_form_order'}};
                   1641:     }
                   1642:         
1.284     albertel 1643:     foreach my $key (@order) {
1.356     albertel 1644:         $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284     albertel 1645:         $output.='selected="selected" ' if ($selected{$key});
                   1646:         $output.='>'.$hash->{$key}."</option>\n";
1.169     www      1647:     }
                   1648:     $output.="</select>\n";
                   1649:     return $output;
                   1650: }
                   1651: 
1.88      www      1652: #-------------------------------------------
                   1653: 
                   1654: =pod
                   1655: 
1.648     raeburn  1656: =item * &select_form($defdom,$name,%hash)
1.88      www      1657: 
                   1658: Returns a string containing a <select name='$name' size='1'> form to 
                   1659: allow a user to select options from a hash option_name => displayed text.  
                   1660: See lonrights.pm for an example invocation and use.
                   1661: 
                   1662: =cut
                   1663: 
                   1664: #-------------------------------------------
                   1665: sub select_form {
                   1666:     my ($def,$name,%hash) = @_;
                   1667:     my $selectform = "<select name=\"$name\" size=\"1\">\n";
1.128     albertel 1668:     my @keys;
                   1669:     if (exists($hash{'select_form_order'})) {
                   1670: 	@keys=@{$hash{'select_form_order'}};
                   1671:     } else {
                   1672: 	@keys=sort(keys(%hash));
                   1673:     }
1.356     albertel 1674:     foreach my $key (@keys) {
                   1675:         $selectform.=
                   1676: 	    '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
                   1677:             ($key eq $def ? 'selected="selected" ' : '').
                   1678:                 ">".&mt($hash{$key})."</option>\n";
1.88      www      1679:     }
                   1680:     $selectform.="</select>";
                   1681:     return $selectform;
                   1682: }
                   1683: 
1.475     www      1684: # For display filters
                   1685: 
                   1686: sub display_filter {
                   1687:     if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477     www      1688:     if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.475     www      1689:     return '<nobr><label>'.&mt('Records [_1]',
                   1690: 			       &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
                   1691: 							   (&mt('all'),10,20,50,100,1000,10000))).
1.478     www      1692: 	   '</label></nobr> <nobr>'.
1.475     www      1693:            &mt('Filter [_1]',
1.477     www      1694: 	   &select_form($env{'form.displayfilter'},
                   1695: 			'displayfilter',
                   1696: 			('currentfolder' => 'Current folder/page',
                   1697: 			 'containing' => 'Containing phrase',
                   1698: 			 'none' => 'None'))).
1.478     www      1699: 			 '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></nobr>';
1.475     www      1700: }
                   1701: 
1.167     www      1702: sub gradeleveldescription {
                   1703:     my $gradelevel=shift;
                   1704:     my %gradelevels=(0 => 'Not specified',
                   1705: 		     1 => 'Grade 1',
                   1706: 		     2 => 'Grade 2',
                   1707: 		     3 => 'Grade 3',
                   1708: 		     4 => 'Grade 4',
                   1709: 		     5 => 'Grade 5',
                   1710: 		     6 => 'Grade 6',
                   1711: 		     7 => 'Grade 7',
                   1712: 		     8 => 'Grade 8',
                   1713: 		     9 => 'Grade 9',
                   1714: 		     10 => 'Grade 10',
                   1715: 		     11 => 'Grade 11',
                   1716: 		     12 => 'Grade 12',
                   1717: 		     13 => 'Grade 13',
                   1718: 		     14 => '100 Level',
                   1719: 		     15 => '200 Level',
                   1720: 		     16 => '300 Level',
                   1721: 		     17 => '400 Level',
                   1722: 		     18 => 'Graduate Level');
                   1723:     return &mt($gradelevels{$gradelevel});
                   1724: }
                   1725: 
1.163     www      1726: sub select_level_form {
                   1727:     my ($deflevel,$name)=@_;
                   1728:     unless ($deflevel) { $deflevel=0; }
1.167     www      1729:     my $selectform = "<select name=\"$name\" size=\"1\">\n";
                   1730:     for (my $i=0; $i<=18; $i++) {
                   1731:         $selectform.="<option value=\"$i\" ".
1.253     albertel 1732:             ($i==$deflevel ? 'selected="selected" ' : '').
1.167     www      1733:                 ">".&gradeleveldescription($i)."</option>\n";
                   1734:     }
                   1735:     $selectform.="</select>";
                   1736:     return $selectform;
1.163     www      1737: }
1.167     www      1738: 
1.35      matthew  1739: #-------------------------------------------
                   1740: 
1.45      matthew  1741: =pod
                   1742: 
1.648     raeburn  1743: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc)
1.35      matthew  1744: 
                   1745: Returns a string containing a <select name='$name' size='1'> form to 
                   1746: allow a user to select the domain to preform an operation in.  
                   1747: See loncreateuser.pm for an example invocation and use.
                   1748: 
1.90      www      1749: If the $includeempty flag is set, it also includes an empty choice ("no domain
                   1750: selected");
                   1751: 
1.563     raeburn  1752: If the $showdomdesc flag is set, the domain name is followed by the domain description. 
                   1753: 
1.35      matthew  1754: =cut
                   1755: 
                   1756: #-------------------------------------------
1.34      matthew  1757: sub select_dom_form {
1.563     raeburn  1758:     my ($defdom,$name,$includeempty,$showdomdesc) = @_;
1.550     albertel 1759:     my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1.90      www      1760:     if ($includeempty) { @domains=('',@domains); }
1.34      matthew  1761:     my $selectdomain = "<select name=\"$name\" size=\"1\">\n";
1.356     albertel 1762:     foreach my $dom (@domains) {
                   1763:         $selectdomain.="<option value=\"$dom\" ".
1.563     raeburn  1764:             ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
                   1765:         if ($showdomdesc) {
                   1766:             if ($dom ne '') {
                   1767:                 my $domdesc = &Apache::lonnet::domain($dom,'description');
                   1768:                 if ($domdesc ne '') {
                   1769:                     $selectdomain .= ' ('.$domdesc.')';
                   1770:                 }
                   1771:             } 
                   1772:         }
                   1773:         $selectdomain .= "</option>\n";
1.34      matthew  1774:     }
                   1775:     $selectdomain.="</select>";
                   1776:     return $selectdomain;
                   1777: }
                   1778: 
1.35      matthew  1779: #-------------------------------------------
                   1780: 
1.45      matthew  1781: =pod
                   1782: 
1.648     raeburn  1783: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35      matthew  1784: 
1.586     raeburn  1785: input: 4 arguments (two required, two optional) - 
                   1786:     $domain - domain of new user
                   1787:     $name - name of form element
                   1788:     $default - Value of 'default' causes a default item to be first 
                   1789:                             option, and selected by default. 
                   1790:     $hide - Value of 'hide' causes hiding of the name of the server, 
                   1791:                             if 1 server found, or default, if 0 found.
1.594     raeburn  1792: output: returns 2 items: 
1.586     raeburn  1793: (a) form element which contains either:
                   1794:    (i) <select name="$name">
                   1795:         <option value="$hostid1">$hostid $servers{$hostid}</option>
                   1796:         <option value="$hostid2">$hostid $servers{$hostid}</option>       
                   1797:        </select>
                   1798:        form item if there are multiple library servers in $domain, or
                   1799:    (ii) an <input type="hidden" name="$name" value="$hostid" /> form item 
                   1800:        if there is only one library server in $domain.
                   1801: 
                   1802: (b) number of library servers found.
                   1803: 
                   1804: See loncreateuser.pm for example of use.
1.35      matthew  1805: 
                   1806: =cut
                   1807: 
                   1808: #-------------------------------------------
1.586     raeburn  1809: sub home_server_form_item {
                   1810:     my ($domain,$name,$default,$hide) = @_;
1.513     albertel 1811:     my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586     raeburn  1812:     my $result;
                   1813:     my $numlib = keys(%servers);
                   1814:     if ($numlib > 1) {
                   1815:         $result .= '<select name="'.$name.'" />'."\n";
                   1816:         if ($default) {
                   1817:             $result .= '<option value="default" selected>'.&mt('default').
                   1818:                        '</option>'."\n";
                   1819:         }
                   1820:         foreach my $hostid (sort(keys(%servers))) {
                   1821:             $result.= '<option value="'.$hostid.'">'.
                   1822: 	              $hostid.' '.$servers{$hostid}."</option>\n";
                   1823:         }
                   1824:         $result .= '</select>'."\n";
                   1825:     } elsif ($numlib == 1) {
                   1826:         my $hostid;
                   1827:         foreach my $item (keys(%servers)) {
                   1828:             $hostid = $item;
                   1829:         }
                   1830:         $result .= '<input type="hidden" name="'.$name.'" value="'.
                   1831:                    $hostid.'" />';
                   1832:                    if (!$hide) {
                   1833:                        $result .= $hostid.' '.$servers{$hostid};
                   1834:                    }
                   1835:                    $result .= "\n";
                   1836:     } elsif ($default) {
                   1837:         $result .= '<input type="hidden" name="'.$name.
                   1838:                    '" value="default" />';
                   1839:                    if (!$hide) {
                   1840:                        $result .= &mt('default');
                   1841:                    }
                   1842:                    $result .= "\n";
1.33      matthew  1843:     }
1.586     raeburn  1844:     return ($result,$numlib);
1.33      matthew  1845: }
1.112     bowersj2 1846: 
                   1847: =pod
                   1848: 
1.534     albertel 1849: =back 
                   1850: 
1.112     bowersj2 1851: =cut
1.87      matthew  1852: 
                   1853: ###############################################################
1.112     bowersj2 1854: ##                  Decoding User Agent                      ##
1.87      matthew  1855: ###############################################################
                   1856: 
                   1857: =pod
                   1858: 
1.112     bowersj2 1859: =head1 Decoding the User Agent
                   1860: 
                   1861: =over 4
                   1862: 
                   1863: =item * &decode_user_agent()
1.87      matthew  1864: 
                   1865: Inputs: $r
                   1866: 
                   1867: Outputs:
                   1868: 
                   1869: =over 4
                   1870: 
1.112     bowersj2 1871: =item * $httpbrowser
1.87      matthew  1872: 
1.112     bowersj2 1873: =item * $clientbrowser
1.87      matthew  1874: 
1.112     bowersj2 1875: =item * $clientversion
1.87      matthew  1876: 
1.112     bowersj2 1877: =item * $clientmathml
1.87      matthew  1878: 
1.112     bowersj2 1879: =item * $clientunicode
1.87      matthew  1880: 
1.112     bowersj2 1881: =item * $clientos
1.87      matthew  1882: 
                   1883: =back
                   1884: 
1.157     matthew  1885: =back 
                   1886: 
1.87      matthew  1887: =cut
                   1888: 
                   1889: ###############################################################
                   1890: ###############################################################
                   1891: sub decode_user_agent {
1.247     albertel 1892:     my ($r)=@_;
1.87      matthew  1893:     my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
                   1894:     my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
                   1895:     my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247     albertel 1896:     if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87      matthew  1897:     my $clientbrowser='unknown';
                   1898:     my $clientversion='0';
                   1899:     my $clientmathml='';
                   1900:     my $clientunicode='0';
                   1901:     for (my $i=0;$i<=$#browsertype;$i++) {
                   1902:         my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
                   1903: 	if (($httpbrowser=~/$match/i)  && ($httpbrowser!~/$notmatch/i)) {
                   1904: 	    $clientbrowser=$bname;
                   1905:             $httpbrowser=~/$vreg/i;
                   1906: 	    $clientversion=$1;
                   1907:             $clientmathml=($clientversion>=$minv);
                   1908:             $clientunicode=($clientversion>=$univ);
                   1909: 	}
                   1910:     }
                   1911:     my $clientos='unknown';
                   1912:     if (($httpbrowser=~/linux/i) ||
                   1913:         ($httpbrowser=~/unix/i) ||
                   1914:         ($httpbrowser=~/ux/i) ||
                   1915:         ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
                   1916:     if (($httpbrowser=~/vax/i) ||
                   1917:         ($httpbrowser=~/vms/i)) { $clientos='vms'; }
                   1918:     if ($httpbrowser=~/next/i) { $clientos='next'; }
                   1919:     if (($httpbrowser=~/mac/i) ||
                   1920:         ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
                   1921:     if ($httpbrowser=~/win/i) { $clientos='win'; }
                   1922:     if ($httpbrowser=~/embed/i) { $clientos='pda'; }
                   1923:     return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
                   1924:             $clientunicode,$clientos,);
                   1925: }
                   1926: 
1.32      matthew  1927: ###############################################################
                   1928: ##    Authentication changing form generation subroutines    ##
                   1929: ###############################################################
                   1930: ##
                   1931: ## All of the authform_xxxxxxx subroutines take their inputs in a
                   1932: ## hash, and have reasonable default values.
                   1933: ##
                   1934: ##    formname = the name given in the <form> tag.
1.35      matthew  1935: #-------------------------------------------
                   1936: 
1.45      matthew  1937: =pod
                   1938: 
1.112     bowersj2 1939: =head1 Authentication Routines
                   1940: 
                   1941: =over 4
                   1942: 
1.648     raeburn  1943: =item * &authform_xxxxxx()
1.35      matthew  1944: 
                   1945: The authform_xxxxxx subroutines provide javascript and html forms which 
                   1946: handle some of the conveniences required for authentication forms.  
                   1947: This is not an optimal method, but it works.  
                   1948: 
                   1949: =over 4
                   1950: 
1.112     bowersj2 1951: =item * authform_header
1.35      matthew  1952: 
1.112     bowersj2 1953: =item * authform_authorwarning
1.35      matthew  1954: 
1.112     bowersj2 1955: =item * authform_nochange
1.35      matthew  1956: 
1.112     bowersj2 1957: =item * authform_kerberos
1.35      matthew  1958: 
1.112     bowersj2 1959: =item * authform_internal
1.35      matthew  1960: 
1.112     bowersj2 1961: =item * authform_filesystem
1.35      matthew  1962: 
                   1963: =back
                   1964: 
1.648     raeburn  1965: See loncreateuser.pm for invocation and use examples.
1.157     matthew  1966: 
1.35      matthew  1967: =cut
                   1968: 
                   1969: #-------------------------------------------
1.32      matthew  1970: sub authform_header{  
                   1971:     my %in = (
                   1972:         formname => 'cu',
1.80      albertel 1973:         kerb_def_dom => '',
1.32      matthew  1974:         @_,
                   1975:     );
                   1976:     $in{'formname'} = 'document.' . $in{'formname'};
                   1977:     my $result='';
1.80      albertel 1978: 
                   1979: #---------------------------------------------- Code for upper case translation
                   1980:     my $Javascript_toUpperCase;
                   1981:     unless ($in{kerb_def_dom}) {
                   1982:         $Javascript_toUpperCase =<<"END";
                   1983:         switch (choice) {
                   1984:            case 'krb': currentform.elements[choicearg].value =
                   1985:                currentform.elements[choicearg].value.toUpperCase();
                   1986:                break;
                   1987:            default:
                   1988:         }
                   1989: END
                   1990:     } else {
                   1991:         $Javascript_toUpperCase = "";
                   1992:     }
                   1993: 
1.165     raeburn  1994:     my $radioval = "'nochange'";
1.591     raeburn  1995:     if (defined($in{'curr_authtype'})) {
                   1996:         if ($in{'curr_authtype'} ne '') {
                   1997:             $radioval = "'".$in{'curr_authtype'}."arg'";
                   1998:         }
1.174     matthew  1999:     }
1.165     raeburn  2000:     my $argfield = 'null';
1.591     raeburn  2001:     if (defined($in{'mode'})) {
1.165     raeburn  2002:         if ($in{'mode'} eq 'modifycourse')  {
1.591     raeburn  2003:             if (defined($in{'curr_autharg'})) {
                   2004:                 if ($in{'curr_autharg'} ne '') {
1.165     raeburn  2005:                     $argfield = "'$in{'curr_autharg'}'";
                   2006:                 }
                   2007:             }
                   2008:         }
                   2009:     }
                   2010: 
1.32      matthew  2011:     $result.=<<"END";
                   2012: var current = new Object();
1.165     raeburn  2013: current.radiovalue = $radioval;
                   2014: current.argfield = $argfield;
1.32      matthew  2015: 
                   2016: function changed_radio(choice,currentform) {
                   2017:     var choicearg = choice + 'arg';
                   2018:     // If a radio button in changed, we need to change the argfield
                   2019:     if (current.radiovalue != choice) {
                   2020:         current.radiovalue = choice;
                   2021:         if (current.argfield != null) {
                   2022:             currentform.elements[current.argfield].value = '';
                   2023:         }
                   2024:         if (choice == 'nochange') {
                   2025:             current.argfield = null;
                   2026:         } else {
                   2027:             current.argfield = choicearg;
                   2028:             switch(choice) {
                   2029:                 case 'krb': 
                   2030:                     currentform.elements[current.argfield].value = 
                   2031:                         "$in{'kerb_def_dom'}";
                   2032:                 break;
                   2033:               default:
                   2034:                 break;
                   2035:             }
                   2036:         }
                   2037:     }
                   2038:     return;
                   2039: }
1.22      www      2040: 
1.32      matthew  2041: function changed_text(choice,currentform) {
                   2042:     var choicearg = choice + 'arg';
                   2043:     if (currentform.elements[choicearg].value !='') {
1.80      albertel 2044:         $Javascript_toUpperCase
1.32      matthew  2045:         // clear old field
                   2046:         if ((current.argfield != choicearg) && (current.argfield != null)) {
                   2047:             currentform.elements[current.argfield].value = '';
                   2048:         }
                   2049:         current.argfield = choicearg;
                   2050:     }
                   2051:     set_auth_radio_buttons(choice,currentform);
                   2052:     return;
1.20      www      2053: }
1.32      matthew  2054: 
                   2055: function set_auth_radio_buttons(newvalue,currentform) {
                   2056:     var i=0;
                   2057:     while (i < currentform.login.length) {
                   2058:         if (currentform.login[i].value == newvalue) { break; }
                   2059:         i++;
                   2060:     }
                   2061:     if (i == currentform.login.length) {
                   2062:         return;
                   2063:     }
                   2064:     current.radiovalue = newvalue;
                   2065:     currentform.login[i].checked = true;
                   2066:     return;
                   2067: }
                   2068: END
                   2069:     return $result;
                   2070: }
                   2071: 
                   2072: sub authform_authorwarning{
                   2073:     my $result='';
1.144     matthew  2074:     $result='<i>'.
                   2075:         &mt('As a general rule, only authors or co-authors should be '.
                   2076:             'filesystem authenticated '.
                   2077:             '(which allows access to the server filesystem).')."</i>\n";
1.32      matthew  2078:     return $result;
                   2079: }
                   2080: 
                   2081: sub authform_nochange{  
                   2082:     my %in = (
                   2083:               formname => 'document.cu',
                   2084:               kerb_def_dom => 'MSU.EDU',
                   2085:               @_,
                   2086:           );
1.586     raeburn  2087:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'}); 
                   2088:     my $result;
                   2089:     if (keys(%can_assign) == 0) {
                   2090:         $result = &mt('Under you current role you are not permitted to change login settings for this user');  
                   2091:     } else {
                   2092:         $result = '<label>'.&mt('[_1] Do not change login data',
                   2093:                   '<input type="radio" name="login" value="nochange" '.
                   2094:                   'checked="checked" onclick="'.
1.281     albertel 2095:             "javascript:changed_radio('nochange',$in{'formname'});".'" />').
                   2096: 	    '</label>';
1.586     raeburn  2097:     }
1.32      matthew  2098:     return $result;
                   2099: }
                   2100: 
1.591     raeburn  2101: sub authform_kerberos {
1.32      matthew  2102:     my %in = (
                   2103:               formname => 'document.cu',
                   2104:               kerb_def_dom => 'MSU.EDU',
1.80      albertel 2105:               kerb_def_auth => 'krb4',
1.32      matthew  2106:               @_,
                   2107:               );
1.586     raeburn  2108:     my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
                   2109:         $autharg,$jscall);
                   2110:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.80      albertel 2111:     if ($in{'kerb_def_auth'} eq 'krb5') {
1.586     raeburn  2112:        $check5 = ' checked="on"';
1.80      albertel 2113:     } else {
1.586     raeburn  2114:        $check4 = ' checked="on"';
1.80      albertel 2115:     }
1.165     raeburn  2116:     $krbarg = $in{'kerb_def_dom'};
1.591     raeburn  2117:     if (defined($in{'curr_authtype'})) {
                   2118:         if ($in{'curr_authtype'} eq 'krb') {
1.586     raeburn  2119:             $krbcheck = ' checked="on"';
1.623     raeburn  2120:             if (defined($in{'mode'})) {
                   2121:                 if ($in{'mode'} eq 'modifyuser') {
                   2122:                     $krbcheck = '';
                   2123:                 }
                   2124:             }
1.591     raeburn  2125:             if (defined($in{'curr_kerb_ver'})) {
                   2126:                 if ($in{'curr_krb_ver'} eq '5') {
                   2127:                     $check5 = ' checked="on"';
                   2128:                     $check4 = '';
                   2129:                 } else {
                   2130:                     $check4 = ' checked="on"';
                   2131:                     $check5 = '';
                   2132:                 }
1.586     raeburn  2133:             }
1.591     raeburn  2134:             if (defined($in{'curr_autharg'})) {
1.165     raeburn  2135:                 $krbarg = $in{'curr_autharg'};
                   2136:             }
1.586     raeburn  2137:             if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591     raeburn  2138:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2139:                     $result = 
                   2140:     &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
                   2141:         $in{'curr_autharg'},$krbver);
                   2142:                 } else {
                   2143:                     $result =
                   2144:     &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
                   2145:                 }
                   2146:                 return $result; 
                   2147:             }
                   2148:         }
                   2149:     } else {
                   2150:         if ($authnum == 1) {
                   2151:             $authtype = '<input type="hidden" name="login" value="krb">';
1.165     raeburn  2152:         }
                   2153:     }
1.586     raeburn  2154:     if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
                   2155:         return;
1.587     raeburn  2156:     } elsif ($authtype eq '') {
1.591     raeburn  2157:         if (defined($in{'mode'})) {
1.587     raeburn  2158:             if ($in{'mode'} eq 'modifycourse') {
                   2159:                 if ($authnum == 1) {
                   2160:                     $authtype = '<input type="hidden" name="login" value="krb">';
                   2161:                 }
                   2162:             }
                   2163:         }
1.586     raeburn  2164:     }
                   2165:     $jscall = "javascript:changed_radio('krb',$in{'formname'});";
                   2166:     if ($authtype eq '') {
                   2167:         $authtype = '<input type="radio" name="login" value="krb" '.
                   2168:                     'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
                   2169:                     $krbcheck.' />';
                   2170:     }
                   2171:     if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
                   2172:         ($can_assign{'krb4'} && !$can_assign{'krb5'} && 
                   2173:          $in{'curr_authtype'} eq 'krb5') ||
                   2174:         (!$can_assign{'krb4'} && $can_assign{'krb5'} && 
                   2175:          $in{'curr_authtype'} eq 'krb4')) {
                   2176:         $result .= &mt
1.144     matthew  2177:         ('[_1] Kerberos authenticated with domain [_2] '.
1.281     albertel 2178:          '[_3] Version 4 [_4] Version 5 [_5]',
1.586     raeburn  2179:          '<label>'.$authtype,
1.281     albertel 2180:          '</label><input type="text" size="10" name="krbarg" '.
1.165     raeburn  2181:              'value="'.$krbarg.'" '.
1.144     matthew  2182:              'onchange="'.$jscall.'" />',
1.281     albertel 2183:          '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
                   2184:          '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
                   2185: 	 '</label>');
1.586     raeburn  2186:     } elsif ($can_assign{'krb4'}) {
                   2187:         $result .= &mt
                   2188:         ('[_1] Kerberos authenticated with domain [_2] '.
                   2189:          '[_3] Version 4 [_4]',
                   2190:          '<label>'.$authtype,
                   2191:          '</label><input type="text" size="10" name="krbarg" '.
                   2192:              'value="'.$krbarg.'" '.
                   2193:              'onchange="'.$jscall.'" />',
                   2194:          '<label><input type="hidden" name="krbver" value="4" />',
                   2195:          '</label>');
                   2196:     } elsif ($can_assign{'krb5'}) {
                   2197:         $result .= &mt
                   2198:         ('[_1] Kerberos authenticated with domain [_2] '.
                   2199:          '[_3] Version 5 [_4]',
                   2200:          '<label>'.$authtype,
                   2201:          '</label><input type="text" size="10" name="krbarg" '.
                   2202:              'value="'.$krbarg.'" '.
                   2203:              'onchange="'.$jscall.'" />',
                   2204:          '<label><input type="hidden" name="krbver" value="5" />',
                   2205:          '</label>');
                   2206:     }
1.32      matthew  2207:     return $result;
                   2208: }
                   2209: 
                   2210: sub authform_internal{  
1.586     raeburn  2211:     my %in = (
1.32      matthew  2212:                 formname => 'document.cu',
                   2213:                 kerb_def_dom => 'MSU.EDU',
                   2214:                 @_,
                   2215:                 );
1.586     raeburn  2216:     my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
                   2217:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2218:     if (defined($in{'curr_authtype'})) {
                   2219:         if ($in{'curr_authtype'} eq 'int') {
1.586     raeburn  2220:             if ($can_assign{'int'}) {
                   2221:                 $intcheck = 'checked="on" ';
1.623     raeburn  2222:                 if (defined($in{'mode'})) {
                   2223:                     if ($in{'mode'} eq 'modifyuser') {
                   2224:                         $intcheck = '';
                   2225:                     }
                   2226:                 }
1.591     raeburn  2227:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2228:                     $intarg = $in{'curr_autharg'};
                   2229:                 }
                   2230:             } else {
                   2231:                 $result = &mt('Currently internally authenticated.');
                   2232:                 return $result;
1.165     raeburn  2233:             }
                   2234:         }
1.586     raeburn  2235:     } else {
                   2236:         if ($authnum == 1) {
                   2237:             $authtype = '<input type="hidden" name="login" value="int">';
                   2238:         }
                   2239:     }
                   2240:     if (!$can_assign{'int'}) {
                   2241:         return;
1.587     raeburn  2242:     } elsif ($authtype eq '') {
1.591     raeburn  2243:         if (defined($in{'mode'})) {
1.587     raeburn  2244:             if ($in{'mode'} eq 'modifycourse') {
                   2245:                 if ($authnum == 1) {
                   2246:                     $authtype = '<input type="hidden" name="login" value="int">';
                   2247:                 }
                   2248:             }
                   2249:         }
1.165     raeburn  2250:     }
1.586     raeburn  2251:     $jscall = "javascript:changed_radio('int',$in{'formname'});";
                   2252:     if ($authtype eq '') {
                   2253:         $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
                   2254:                     ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
                   2255:     }
1.605     bisitz   2256:     $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586     raeburn  2257:                $intarg.'" onchange="'.$jscall.'" />';
                   2258:     $result = &mt
1.144     matthew  2259:         ('[_1] Internally authenticated (with initial password [_2])',
1.586     raeburn  2260:          '<label>'.$authtype,'</label>'.$autharg);
1.620     www      2261:     $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  2262:     return $result;
                   2263: }
                   2264: 
                   2265: sub authform_local{  
                   2266:     my %in = (
                   2267:               formname => 'document.cu',
                   2268:               kerb_def_dom => 'MSU.EDU',
                   2269:               @_,
                   2270:               );
1.586     raeburn  2271:     my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
                   2272:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2273:     if (defined($in{'curr_authtype'})) {
                   2274:         if ($in{'curr_authtype'} eq 'loc') {
1.586     raeburn  2275:             if ($can_assign{'loc'}) {
                   2276:                 $loccheck = 'checked="on" ';
1.623     raeburn  2277:                 if (defined($in{'mode'})) {
                   2278:                     if ($in{'mode'} eq 'modifyuser') {
                   2279:                         $loccheck = '';
                   2280:                     }
                   2281:                 }
1.591     raeburn  2282:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2283:                     $locarg = $in{'curr_autharg'};
                   2284:                 }
                   2285:             } else {
                   2286:                 $result = &mt('Currently using local (institutional) authentication.');
                   2287:                 return $result;
1.165     raeburn  2288:             }
                   2289:         }
1.586     raeburn  2290:     } else {
                   2291:         if ($authnum == 1) {
                   2292:             $authtype = '<input type="hidden" name="login" value="loc">';
                   2293:         }
                   2294:     }
                   2295:     if (!$can_assign{'loc'}) {
                   2296:         return;
1.587     raeburn  2297:     } elsif ($authtype eq '') {
1.591     raeburn  2298:         if (defined($in{'mode'})) {
1.587     raeburn  2299:             if ($in{'mode'} eq 'modifycourse') {
                   2300:                 if ($authnum == 1) {
                   2301:                     $authtype = '<input type="hidden" name="login" value="loc">';
                   2302:                 }
                   2303:             }
                   2304:         }
1.165     raeburn  2305:     }
1.586     raeburn  2306:     $jscall = "javascript:changed_radio('loc',$in{'formname'});";
                   2307:     if ($authtype eq '') {
                   2308:         $authtype = '<input type="radio" name="login" value="loc" '.
                   2309:                     $loccheck.' onchange="'.$jscall.'" onclick="'.
                   2310:                     $jscall.'" />';
                   2311:     }
                   2312:     $autharg = '<input type="text" size="10" name="locarg" value="'.
                   2313:                $locarg.'" onchange="'.$jscall.'" />';
                   2314:     $result = &mt('[_1] Local Authentication with argument [_2]',
                   2315:                   '<label>'.$authtype,'</label>'.$autharg);
1.32      matthew  2316:     return $result;
                   2317: }
                   2318: 
                   2319: sub authform_filesystem{  
                   2320:     my %in = (
                   2321:               formname => 'document.cu',
                   2322:               kerb_def_dom => 'MSU.EDU',
                   2323:               @_,
                   2324:               );
1.586     raeburn  2325:     my ($fsyscheck,$result,$authtype,$autharg,$jscall);
                   2326:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2327:     if (defined($in{'curr_authtype'})) {
                   2328:         if ($in{'curr_authtype'} eq 'fsys') {
1.586     raeburn  2329:             if ($can_assign{'fsys'}) {
                   2330:                 $fsyscheck = 'checked="on" ';
1.623     raeburn  2331:                 if (defined($in{'mode'})) {
                   2332:                     if ($in{'mode'} eq 'modifyuser') {
                   2333:                         $fsyscheck = '';
                   2334:                     }
                   2335:                 }
1.586     raeburn  2336:             } else {
                   2337:                 $result = &mt('Currently Filesystem Authenticated.');
                   2338:                 return $result;
                   2339:             }           
                   2340:         }
                   2341:     } else {
                   2342:         if ($authnum == 1) {
                   2343:             $authtype = '<input type="hidden" name="login" value="fsys">';
                   2344:         }
                   2345:     }
                   2346:     if (!$can_assign{'fsys'}) {
                   2347:         return;
1.587     raeburn  2348:     } elsif ($authtype eq '') {
1.591     raeburn  2349:         if (defined($in{'mode'})) {
1.587     raeburn  2350:             if ($in{'mode'} eq 'modifycourse') {
                   2351:                 if ($authnum == 1) {
                   2352:                     $authtype = '<input type="hidden" name="login" value="fsys">';
                   2353:                 }
                   2354:             }
                   2355:         }
1.586     raeburn  2356:     }
                   2357:     $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
                   2358:     if ($authtype eq '') {
                   2359:         $authtype = '<input type="radio" name="login" value="fsys" '.
                   2360:                     $fsyscheck.' onchange="'.$jscall.'" onclick="'.
                   2361:                     $jscall.'" />';
                   2362:     }
                   2363:     $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
                   2364:                ' onchange="'.$jscall.'" />';
                   2365:     $result = &mt
1.144     matthew  2366:         ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281     albertel 2367:          '<label><input type="radio" name="login" value="fsys" '.
1.586     raeburn  2368:          $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605     bisitz   2369:          '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144     matthew  2370:                   'onchange="'.$jscall.'" />');
1.32      matthew  2371:     return $result;
                   2372: }
                   2373: 
1.586     raeburn  2374: sub get_assignable_auth {
                   2375:     my ($dom) = @_;
                   2376:     if ($dom eq '') {
                   2377:         $dom = $env{'request.role.domain'};
                   2378:     }
                   2379:     my %can_assign = (
                   2380:                           krb4 => 1,
                   2381:                           krb5 => 1,
                   2382:                           int  => 1,
                   2383:                           loc  => 1,
                   2384:                      );
                   2385:     my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
                   2386:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   2387:         if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
                   2388:             my $authhash = $domconfig{'usercreation'}{'authtypes'};
                   2389:             my $context;
                   2390:             if ($env{'request.role'} =~ /^au/) {
                   2391:                 $context = 'author';
                   2392:             } elsif ($env{'request.role'} =~ /^dc/) {
                   2393:                 $context = 'domain';
                   2394:             } elsif ($env{'request.course.id'}) {
                   2395:                 $context = 'course';
                   2396:             }
                   2397:             if ($context) {
                   2398:                 if (ref($authhash->{$context}) eq 'HASH') {
                   2399:                    %can_assign = %{$authhash->{$context}}; 
                   2400:                 }
                   2401:             }
                   2402:         }
                   2403:     }
                   2404:     my $authnum = 0;
                   2405:     foreach my $key (keys(%can_assign)) {
                   2406:         if ($can_assign{$key}) {
                   2407:             $authnum ++;
                   2408:         }
                   2409:     }
                   2410:     if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
                   2411:         $authnum --;
                   2412:     }
                   2413:     return ($authnum,%can_assign);
                   2414: }
                   2415: 
1.80      albertel 2416: ###############################################################
                   2417: ##    Get Kerberos Defaults for Domain                 ##
                   2418: ###############################################################
                   2419: ##
                   2420: ## Returns default kerberos version and an associated argument
                   2421: ## as listed in file domain.tab. If not listed, provides
                   2422: ## appropriate default domain and kerberos version.
                   2423: ##
                   2424: #-------------------------------------------
                   2425: 
                   2426: =pod
                   2427: 
1.648     raeburn  2428: =item * &get_kerberos_defaults()
1.80      albertel 2429: 
                   2430: get_kerberos_defaults($target_domain) returns the default kerberos
1.641     raeburn  2431: version and domain. If not found, it defaults to version 4 and the 
                   2432: domain of the server.
1.80      albertel 2433: 
1.648     raeburn  2434: =over 4
                   2435: 
1.80      albertel 2436: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
                   2437: 
1.648     raeburn  2438: =back
                   2439: 
                   2440: =back
                   2441: 
1.80      albertel 2442: =cut
                   2443: 
                   2444: #-------------------------------------------
                   2445: sub get_kerberos_defaults {
                   2446:     my $domain=shift;
1.641     raeburn  2447:     my ($krbdef,$krbdefdom);
                   2448:     my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
                   2449:     if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
                   2450:         $krbdef = $domdefaults{'auth_def'};
                   2451:         $krbdefdom = $domdefaults{'auth_arg_def'};
                   2452:     } else {
1.80      albertel 2453:         $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
                   2454:         my $krbdefdom=$1;
                   2455:         $krbdefdom=~tr/a-z/A-Z/;
                   2456:         $krbdef = "krb4";
                   2457:     }
                   2458:     return ($krbdef,$krbdefdom);
                   2459: }
1.112     bowersj2 2460: 
1.32      matthew  2461: 
1.46      matthew  2462: ###############################################################
                   2463: ##                Thesaurus Functions                        ##
                   2464: ###############################################################
1.20      www      2465: 
1.46      matthew  2466: =pod
1.20      www      2467: 
1.112     bowersj2 2468: =head1 Thesaurus Functions
                   2469: 
                   2470: =over 4
                   2471: 
1.648     raeburn  2472: =item * &initialize_keywords()
1.46      matthew  2473: 
                   2474: Initializes the package variable %Keywords if it is empty.  Uses the
                   2475: package variable $thesaurus_db_file.
                   2476: 
                   2477: =cut
                   2478: 
                   2479: ###################################################
                   2480: 
                   2481: sub initialize_keywords {
                   2482:     return 1 if (scalar keys(%Keywords));
                   2483:     # If we are here, %Keywords is empty, so fill it up
                   2484:     #   Make sure the file we need exists...
                   2485:     if (! -e $thesaurus_db_file) {
                   2486:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
                   2487:                                  " failed because it does not exist");
                   2488:         return 0;
                   2489:     }
                   2490:     #   Set up the hash as a database
                   2491:     my %thesaurus_db;
                   2492:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 2493:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  2494:         &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
                   2495:                                  $thesaurus_db_file);
                   2496:         return 0;
                   2497:     } 
                   2498:     #  Get the average number of appearances of a word.
                   2499:     my $avecount = $thesaurus_db{'average.count'};
                   2500:     #  Put keywords (those that appear > average) into %Keywords
                   2501:     while (my ($word,$data)=each (%thesaurus_db)) {
                   2502:         my ($count,undef) = split /:/,$data;
                   2503:         $Keywords{$word}++ if ($count > $avecount);
                   2504:     }
                   2505:     untie %thesaurus_db;
                   2506:     # Remove special values from %Keywords.
1.356     albertel 2507:     foreach my $value ('total.count','average.count') {
                   2508:         delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586     raeburn  2509:   }
1.46      matthew  2510:     return 1;
                   2511: }
                   2512: 
                   2513: ###################################################
                   2514: 
                   2515: =pod
                   2516: 
1.648     raeburn  2517: =item * &keyword($word)
1.46      matthew  2518: 
                   2519: Returns true if $word is a keyword.  A keyword is a word that appears more 
                   2520: than the average number of times in the thesaurus database.  Calls 
                   2521: &initialize_keywords
                   2522: 
                   2523: =cut
                   2524: 
                   2525: ###################################################
1.20      www      2526: 
                   2527: sub keyword {
1.46      matthew  2528:     return if (!&initialize_keywords());
                   2529:     my $word=lc(shift());
                   2530:     $word=~s/\W//g;
                   2531:     return exists($Keywords{$word});
1.20      www      2532: }
1.46      matthew  2533: 
                   2534: ###############################################################
                   2535: 
                   2536: =pod 
1.20      www      2537: 
1.648     raeburn  2538: =item * &get_related_words()
1.46      matthew  2539: 
1.160     matthew  2540: Look up a word in the thesaurus.  Takes a scalar argument and returns
1.46      matthew  2541: an array of words.  If the keyword is not in the thesaurus, an empty array
                   2542: will be returned.  The order of the words returned is determined by the
                   2543: database which holds them.
                   2544: 
                   2545: Uses global $thesaurus_db_file.
                   2546: 
                   2547: =cut
                   2548: 
                   2549: ###############################################################
                   2550: sub get_related_words {
                   2551:     my $keyword = shift;
                   2552:     my %thesaurus_db;
                   2553:     if (! -e $thesaurus_db_file) {
                   2554:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
                   2555:                                  "failed because the file does not exist");
                   2556:         return ();
                   2557:     }
                   2558:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 2559:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  2560:         return ();
                   2561:     } 
                   2562:     my @Words=();
1.429     www      2563:     my $count=0;
1.46      matthew  2564:     if (exists($thesaurus_db{$keyword})) {
1.356     albertel 2565: 	# The first element is the number of times
                   2566: 	# the word appears.  We do not need it now.
1.429     www      2567: 	my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
                   2568: 	my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
                   2569: 	my $threshold=$mostfrequentcount/10;
                   2570:         foreach my $possibleword (@RelatedWords) {
                   2571:             my ($word,$wordcount)=split(/\,/,$possibleword);
                   2572:             if ($wordcount>$threshold) {
                   2573: 		push(@Words,$word);
                   2574:                 $count++;
                   2575:                 if ($count>10) { last; }
                   2576: 	    }
1.20      www      2577:         }
                   2578:     }
1.46      matthew  2579:     untie %thesaurus_db;
                   2580:     return @Words;
1.14      harris41 2581: }
1.46      matthew  2582: 
1.112     bowersj2 2583: =pod
                   2584: 
                   2585: =back
                   2586: 
                   2587: =cut
1.61      www      2588: 
                   2589: # -------------------------------------------------------------- Plaintext name
1.81      albertel 2590: =pod
                   2591: 
1.112     bowersj2 2592: =head1 User Name Functions
                   2593: 
                   2594: =over 4
                   2595: 
1.648     raeburn  2596: =item * &plainname($uname,$udom,$first)
1.81      albertel 2597: 
1.112     bowersj2 2598: Takes a users logon name and returns it as a string in
1.226     albertel 2599: "first middle last generation" form 
                   2600: if $first is set to 'lastname' then it returns it as
                   2601: 'lastname generation, firstname middlename' if their is a lastname
1.81      albertel 2602: 
                   2603: =cut
1.61      www      2604: 
1.295     www      2605: 
1.81      albertel 2606: ###############################################################
1.61      www      2607: sub plainname {
1.226     albertel 2608:     my ($uname,$udom,$first)=@_;
1.537     albertel 2609:     return if (!defined($uname) || !defined($udom));
1.295     www      2610:     my %names=&getnames($uname,$udom);
1.226     albertel 2611:     my $name=&Apache::lonnet::format_name($names{'firstname'},
                   2612: 					  $names{'middlename'},
                   2613: 					  $names{'lastname'},
                   2614: 					  $names{'generation'},$first);
                   2615:     $name=~s/^\s+//;
1.62      www      2616:     $name=~s/\s+$//;
                   2617:     $name=~s/\s+/ /g;
1.353     albertel 2618:     if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62      www      2619:     return $name;
1.61      www      2620: }
1.66      www      2621: 
                   2622: # -------------------------------------------------------------------- Nickname
1.81      albertel 2623: =pod
                   2624: 
1.648     raeburn  2625: =item * &nickname($uname,$udom)
1.81      albertel 2626: 
                   2627: Gets a users name and returns it as a string as
                   2628: 
                   2629: "&quot;nickname&quot;"
1.66      www      2630: 
1.81      albertel 2631: if the user has a nickname or
                   2632: 
                   2633: "first middle last generation"
                   2634: 
                   2635: if the user does not
                   2636: 
                   2637: =cut
1.66      www      2638: 
                   2639: sub nickname {
                   2640:     my ($uname,$udom)=@_;
1.537     albertel 2641:     return if (!defined($uname) || !defined($udom));
1.295     www      2642:     my %names=&getnames($uname,$udom);
1.68      albertel 2643:     my $name=$names{'nickname'};
1.66      www      2644:     if ($name) {
                   2645:        $name='&quot;'.$name.'&quot;'; 
                   2646:     } else {
                   2647:        $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
                   2648: 	     $names{'lastname'}.' '.$names{'generation'};
                   2649:        $name=~s/\s+$//;
                   2650:        $name=~s/\s+/ /g;
                   2651:     }
                   2652:     return $name;
                   2653: }
                   2654: 
1.295     www      2655: sub getnames {
                   2656:     my ($uname,$udom)=@_;
1.537     albertel 2657:     return if (!defined($uname) || !defined($udom));
1.433     albertel 2658:     if ($udom eq 'public' && $uname eq 'public') {
                   2659: 	return ('lastname' => &mt('Public'));
                   2660:     }
1.295     www      2661:     my $id=$uname.':'.$udom;
                   2662:     my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
                   2663:     if ($cached) {
                   2664: 	return %{$names};
                   2665:     } else {
                   2666: 	my %loadnames=&Apache::lonnet::get('environment',
                   2667:                     ['firstname','middlename','lastname','generation','nickname'],
                   2668: 					 $udom,$uname);
                   2669: 	&Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
                   2670: 	return %loadnames;
                   2671:     }
                   2672: }
1.61      www      2673: 
1.542     raeburn  2674: # -------------------------------------------------------------------- getemails
1.648     raeburn  2675: 
1.542     raeburn  2676: =pod
                   2677: 
1.648     raeburn  2678: =item * &getemails($uname,$udom)
1.542     raeburn  2679: 
                   2680: Gets a user's email information and returns it as a hash with keys:
                   2681: notification, critnotification, permanentemail
                   2682: 
                   2683: For notification and critnotification, values are comma-separated lists 
1.648     raeburn  2684: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542     raeburn  2685:  
1.648     raeburn  2686: 
1.542     raeburn  2687: =cut
                   2688: 
1.648     raeburn  2689: 
1.466     albertel 2690: sub getemails {
                   2691:     my ($uname,$udom)=@_;
                   2692:     if ($udom eq 'public' && $uname eq 'public') {
                   2693: 	return;
                   2694:     }
1.467     www      2695:     if (!$udom) { $udom=$env{'user.domain'}; }
                   2696:     if (!$uname) { $uname=$env{'user.name'}; }
1.466     albertel 2697:     my $id=$uname.':'.$udom;
                   2698:     my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
                   2699:     if ($cached) {
                   2700: 	return %{$names};
                   2701:     } else {
                   2702: 	my %loadnames=&Apache::lonnet::get('environment',
                   2703:                     			   ['notification','critnotification',
                   2704: 					    'permanentemail'],
                   2705: 					   $udom,$uname);
                   2706: 	&Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
                   2707: 	return %loadnames;
                   2708:     }
                   2709: }
                   2710: 
1.551     albertel 2711: sub flush_email_cache {
                   2712:     my ($uname,$udom)=@_;
                   2713:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2714:     if (!$uname) { $uname=$env{'user.name'};   }
                   2715:     return if ($udom eq 'public' && $uname eq 'public');
                   2716:     my $id=$uname.':'.$udom;
                   2717:     &Apache::lonnet::devalidate_cache_new('emailscache',$id);
                   2718: }
                   2719: 
1.61      www      2720: # ------------------------------------------------------------------ Screenname
1.81      albertel 2721: 
                   2722: =pod
                   2723: 
1.648     raeburn  2724: =item * &screenname($uname,$udom)
1.81      albertel 2725: 
                   2726: Gets a users screenname and returns it as a string
                   2727: 
                   2728: =cut
1.61      www      2729: 
                   2730: sub screenname {
                   2731:     my ($uname,$udom)=@_;
1.258     albertel 2732:     if ($uname eq $env{'user.name'} &&
                   2733: 	$udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212     albertel 2734:     my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68      albertel 2735:     return $names{'screenname'};
1.62      www      2736: }
                   2737: 
1.212     albertel 2738: 
1.62      www      2739: # ------------------------------------------------------------- Message Wrapper
                   2740: 
                   2741: sub messagewrapper {
1.369     www      2742:     my ($link,$username,$domain,$subject,$text)=@_;
1.62      www      2743:     return 
1.441     albertel 2744:         '<a href="/adm/email?compose=individual&amp;'.
                   2745:         'recname='.$username.'&amp;recdom='.$domain.
                   2746: 	'&amp;subject='.&escape($subject).'&amp;text='.&escape($text).'" '.
1.200     matthew  2747:         'title="'.&mt('Send message').'">'.$link.'</a>';
1.74      www      2748: }
                   2749: # --------------------------------------------------------------- Notes Wrapper
                   2750: 
                   2751: sub noteswrapper {
                   2752:     my ($link,$un,$do)=@_;
                   2753:     return 
                   2754: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62      www      2755: }
                   2756: # ------------------------------------------------------------- Aboutme Wrapper
                   2757: 
                   2758: sub aboutmewrapper {
1.166     www      2759:     my ($link,$username,$domain,$target)=@_;
1.447     raeburn  2760:     if (!defined($username)  && !defined($domain)) {
                   2761:         return;
                   2762:     }
1.205     www      2763:     return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.454     banghart 2764: 	($target?' target="$target"':'').' title="'.&mt("View this user's personal page").'">'.$link.'</a>';
1.62      www      2765: }
                   2766: 
                   2767: # ------------------------------------------------------------ Syllabus Wrapper
                   2768: 
                   2769: 
                   2770: sub syllabuswrapper {
1.109     matthew  2771:     my ($linktext,$coursedir,$domain,$fontcolor)=@_;
                   2772:     if ($fontcolor) { 
                   2773:         $linktext='<font color="'.$fontcolor.'">'.$linktext.'</font>'; 
                   2774:     }
1.208     matthew  2775:     return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61      www      2776: }
1.14      harris41 2777: 
1.208     matthew  2778: sub track_student_link {
1.268     albertel 2779:     my ($linktext,$sname,$sdom,$target,$start) = @_;
                   2780:     my $link ="/adm/trackstudent?";
1.208     matthew  2781:     my $title = 'View recent activity';
                   2782:     if (defined($sname) && $sname !~ /^\s*$/ &&
                   2783:         defined($sdom)  && $sdom  !~ /^\s*$/) {
1.268     albertel 2784:         $link .= "selected_student=$sname:$sdom";
1.208     matthew  2785:         $title .= ' of this student';
1.268     albertel 2786:     } 
1.208     matthew  2787:     if (defined($target) && $target !~ /^\s*$/) {
                   2788:         $target = qq{target="$target"};
                   2789:     } else {
                   2790:         $target = '';
                   2791:     }
1.268     albertel 2792:     if ($start) { $link.='&amp;start='.$start; }
1.554     albertel 2793:     $title = &mt($title);
                   2794:     $linktext = &mt($linktext);
1.448     albertel 2795:     return qq{<a href="$link" title="$title" $target>$linktext</a>}.
                   2796: 	&help_open_topic('View_recent_activity');
1.208     matthew  2797: }
                   2798: 
1.508     www      2799: # ===================================================== Display a student photo
                   2800: 
                   2801: 
1.509     albertel 2802: sub student_image_tag {
1.508     www      2803:     my ($domain,$user)=@_;
                   2804:     my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
                   2805:     if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
                   2806: 	return '<img src="'.$imgsrc.'" align="right" />';
                   2807:     } else {
                   2808: 	return '';
                   2809:     }
                   2810: }
                   2811: 
1.112     bowersj2 2812: =pod
                   2813: 
                   2814: =back
                   2815: 
                   2816: =head1 Access .tab File Data
                   2817: 
                   2818: =over 4
                   2819: 
1.648     raeburn  2820: =item * &languageids() 
1.112     bowersj2 2821: 
                   2822: returns list of all language ids
                   2823: 
                   2824: =cut
                   2825: 
1.14      harris41 2826: sub languageids {
1.16      harris41 2827:     return sort(keys(%language));
1.14      harris41 2828: }
                   2829: 
1.112     bowersj2 2830: =pod
                   2831: 
1.648     raeburn  2832: =item * &languagedescription() 
1.112     bowersj2 2833: 
                   2834: returns description of a specified language id
                   2835: 
                   2836: =cut
                   2837: 
1.14      harris41 2838: sub languagedescription {
1.125     www      2839:     my $code=shift;
                   2840:     return  ($supported_language{$code}?'* ':'').
                   2841:             $language{$code}.
1.126     www      2842: 	    ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145     www      2843: }
                   2844: 
                   2845: sub plainlanguagedescription {
                   2846:     my $code=shift;
                   2847:     return $language{$code};
                   2848: }
                   2849: 
                   2850: sub supportedlanguagecode {
                   2851:     my $code=shift;
                   2852:     return $supported_language{$code};
1.97      www      2853: }
                   2854: 
1.112     bowersj2 2855: =pod
                   2856: 
1.648     raeburn  2857: =item * &copyrightids() 
1.112     bowersj2 2858: 
                   2859: returns list of all copyrights
                   2860: 
                   2861: =cut
                   2862: 
                   2863: sub copyrightids {
                   2864:     return sort(keys(%cprtag));
                   2865: }
                   2866: 
                   2867: =pod
                   2868: 
1.648     raeburn  2869: =item * &copyrightdescription() 
1.112     bowersj2 2870: 
                   2871: returns description of a specified copyright id
                   2872: 
                   2873: =cut
                   2874: 
                   2875: sub copyrightdescription {
1.166     www      2876:     return &mt($cprtag{shift(@_)});
1.112     bowersj2 2877: }
1.197     matthew  2878: 
                   2879: =pod
                   2880: 
1.648     raeburn  2881: =item * &source_copyrightids() 
1.192     taceyjo1 2882: 
                   2883: returns list of all source copyrights
                   2884: 
                   2885: =cut
                   2886: 
                   2887: sub source_copyrightids {
                   2888:     return sort(keys(%scprtag));
                   2889: }
                   2890: 
                   2891: =pod
                   2892: 
1.648     raeburn  2893: =item * &source_copyrightdescription() 
1.192     taceyjo1 2894: 
                   2895: returns description of a specified source copyright id
                   2896: 
                   2897: =cut
                   2898: 
                   2899: sub source_copyrightdescription {
                   2900:     return &mt($scprtag{shift(@_)});
                   2901: }
1.112     bowersj2 2902: 
                   2903: =pod
                   2904: 
1.648     raeburn  2905: =item * &filecategories() 
1.112     bowersj2 2906: 
                   2907: returns list of all file categories
                   2908: 
                   2909: =cut
                   2910: 
                   2911: sub filecategories {
                   2912:     return sort(keys(%category_extensions));
                   2913: }
                   2914: 
                   2915: =pod
                   2916: 
1.648     raeburn  2917: =item * &filecategorytypes() 
1.112     bowersj2 2918: 
                   2919: returns list of file types belonging to a given file
                   2920: category
                   2921: 
                   2922: =cut
                   2923: 
                   2924: sub filecategorytypes {
1.356     albertel 2925:     my ($cat) = @_;
                   2926:     return @{$category_extensions{lc($cat)}};
1.112     bowersj2 2927: }
                   2928: 
                   2929: =pod
                   2930: 
1.648     raeburn  2931: =item * &fileembstyle() 
1.112     bowersj2 2932: 
                   2933: returns embedding style for a specified file type
                   2934: 
                   2935: =cut
                   2936: 
                   2937: sub fileembstyle {
                   2938:     return $fe{lc(shift(@_))};
1.169     www      2939: }
                   2940: 
1.351     www      2941: sub filemimetype {
                   2942:     return $fm{lc(shift(@_))};
                   2943: }
                   2944: 
1.169     www      2945: 
                   2946: sub filecategoryselect {
                   2947:     my ($name,$value)=@_;
1.189     matthew  2948:     return &select_form($value,$name,
1.169     www      2949: 			'' => &mt('Any category'),
                   2950: 			map { $_,$_ } sort(keys(%category_extensions)));
1.112     bowersj2 2951: }
                   2952: 
                   2953: =pod
                   2954: 
1.648     raeburn  2955: =item * &filedescription() 
1.112     bowersj2 2956: 
                   2957: returns description for a specified file type
                   2958: 
                   2959: =cut
                   2960: 
                   2961: sub filedescription {
1.188     matthew  2962:     my $file_description = $fd{lc(shift())};
                   2963:     $file_description =~ s:([\[\]]):~$1:g;
                   2964:     return &mt($file_description);
1.112     bowersj2 2965: }
                   2966: 
                   2967: =pod
                   2968: 
1.648     raeburn  2969: =item * &filedescriptionex() 
1.112     bowersj2 2970: 
                   2971: returns description for a specified file type with
                   2972: extra formatting
                   2973: 
                   2974: =cut
                   2975: 
                   2976: sub filedescriptionex {
                   2977:     my $ex=shift;
1.188     matthew  2978:     my $file_description = $fd{lc($ex)};
                   2979:     $file_description =~ s:([\[\]]):~$1:g;
                   2980:     return '.'.$ex.' '.&mt($file_description);
1.112     bowersj2 2981: }
                   2982: 
                   2983: # End of .tab access
                   2984: =pod
                   2985: 
                   2986: =back
                   2987: 
                   2988: =cut
                   2989: 
                   2990: # ------------------------------------------------------------------ File Types
                   2991: sub fileextensions {
                   2992:     return sort(keys(%fe));
                   2993: }
                   2994: 
1.97      www      2995: # ----------------------------------------------------------- Display Languages
                   2996: # returns a hash with all desired display languages
                   2997: #
                   2998: 
                   2999: sub display_languages {
                   3000:     my %languages=();
1.695   ! raeburn  3001:     foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356     albertel 3002: 	$languages{$lang}=1;
1.97      www      3003:     }
                   3004:     &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258     albertel 3005:     if ($env{'form.displaylanguage'}) {
1.356     albertel 3006: 	foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
                   3007: 	    $languages{$lang}=1;
1.97      www      3008:         }
                   3009:     }
                   3010:     return %languages;
1.14      harris41 3011: }
                   3012: 
1.582     albertel 3013: sub languages {
                   3014:     my ($possible_langs) = @_;
1.695   ! raeburn  3015:     my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582     albertel 3016:     if (!ref($possible_langs)) {
                   3017: 	if( wantarray ) {
                   3018: 	    return @preferred_langs;
                   3019: 	} else {
                   3020: 	    return $preferred_langs[0];
                   3021: 	}
                   3022:     }
                   3023:     my %possibilities = map { $_ => 1 } (@$possible_langs);
                   3024:     my @preferred_possibilities;
                   3025:     foreach my $preferred_lang (@preferred_langs) {
                   3026: 	if (exists($possibilities{$preferred_lang})) {
                   3027: 	    push(@preferred_possibilities, $preferred_lang);
                   3028: 	}
                   3029:     }
                   3030:     if( wantarray ) {
                   3031: 	return @preferred_possibilities;
                   3032:     }
                   3033:     return $preferred_possibilities[0];
                   3034: }
                   3035: 
1.112     bowersj2 3036: ###############################################################
                   3037: ##               Student Answer Attempts                     ##
                   3038: ###############################################################
                   3039: 
                   3040: =pod
                   3041: 
                   3042: =head1 Alternate Problem Views
                   3043: 
                   3044: =over 4
                   3045: 
1.648     raeburn  3046: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112     bowersj2 3047:     $getattempt, $regexp, $gradesub)
                   3048: 
                   3049: Return string with previous attempt on problem. Arguments:
                   3050: 
                   3051: =over 4
                   3052: 
                   3053: =item * $symb: Problem, including path
                   3054: 
                   3055: =item * $username: username of the desired student
                   3056: 
                   3057: =item * $domain: domain of the desired student
1.14      harris41 3058: 
1.112     bowersj2 3059: =item * $course: Course ID
1.14      harris41 3060: 
1.112     bowersj2 3061: =item * $getattempt: Leave blank for all attempts, otherwise put
                   3062:     something
1.14      harris41 3063: 
1.112     bowersj2 3064: =item * $regexp: if string matches this regexp, the string will be
                   3065:     sent to $gradesub
1.14      harris41 3066: 
1.112     bowersj2 3067: =item * $gradesub: routine that processes the string if it matches $regexp
1.14      harris41 3068: 
1.112     bowersj2 3069: =back
1.14      harris41 3070: 
1.112     bowersj2 3071: The output string is a table containing all desired attempts, if any.
1.16      harris41 3072: 
1.112     bowersj2 3073: =cut
1.1       albertel 3074: 
                   3075: sub get_previous_attempt {
1.43      ng       3076:   my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1       albertel 3077:   my $prevattempts='';
1.43      ng       3078:   no strict 'refs';
1.1       albertel 3079:   if ($symb) {
1.3       albertel 3080:     my (%returnhash)=
                   3081:       &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1       albertel 3082:     if ($returnhash{'version'}) {
                   3083:       my %lasthash=();
                   3084:       my $version;
                   3085:       for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356     albertel 3086:         foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
                   3087: 	  $lasthash{$key}=$returnhash{$version.':'.$key};
1.19      harris41 3088:         }
1.1       albertel 3089:       }
1.596     albertel 3090:       $prevattempts=&start_data_table().&start_data_table_header_row();
                   3091:       $prevattempts.='<th>'.&mt('History').'</th>';
1.356     albertel 3092:       foreach my $key (sort(keys(%lasthash))) {
                   3093: 	my ($ign,@parts) = split(/\./,$key);
1.41      ng       3094: 	if ($#parts > 0) {
1.31      albertel 3095: 	  my $data=$parts[-1];
                   3096: 	  pop(@parts);
1.596     albertel 3097: 	  $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.'&nbsp;</th>';
1.31      albertel 3098: 	} else {
1.41      ng       3099: 	  if ($#parts == 0) {
                   3100: 	    $prevattempts.='<th>'.$parts[0].'</th>';
                   3101: 	  } else {
                   3102: 	    $prevattempts.='<th>'.$ign.'</th>';
                   3103: 	  }
1.31      albertel 3104: 	}
1.16      harris41 3105:       }
1.596     albertel 3106:       $prevattempts.=&end_data_table_header_row();
1.40      ng       3107:       if ($getattempt eq '') {
                   3108: 	for ($version=1;$version<=$returnhash{'version'};$version++) {
1.596     albertel 3109: 	  $prevattempts.=&start_data_table_row().
                   3110: 	      '<td>'.&mt('Transaction [_1]',$version).'</td>';
1.356     albertel 3111: 	    foreach my $key (sort(keys(%lasthash))) {
1.581     albertel 3112: 		my $value = &format_previous_attempt_value($key,
                   3113: 							   $returnhash{$version.':'.$key});
                   3114: 		$prevattempts.='<td>'.$value.'&nbsp;</td>';   
1.40      ng       3115: 	    }
1.596     albertel 3116: 	  $prevattempts.=&end_data_table_row();
1.40      ng       3117: 	 }
1.1       albertel 3118:       }
1.596     albertel 3119:       $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356     albertel 3120:       foreach my $key (sort(keys(%lasthash))) {
1.581     albertel 3121: 	my $value = &format_previous_attempt_value($key,$lasthash{$key});
1.356     albertel 3122: 	if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
1.40      ng       3123: 	$prevattempts.='<td>'.$value.'&nbsp;</td>';
1.16      harris41 3124:       }
1.596     albertel 3125:       $prevattempts.= &end_data_table_row().&end_data_table();
1.1       albertel 3126:     } else {
1.596     albertel 3127:       $prevattempts=
                   3128: 	  &start_data_table().&start_data_table_row().
                   3129: 	  '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
                   3130: 	  &end_data_table_row().&end_data_table();
1.1       albertel 3131:     }
                   3132:   } else {
1.596     albertel 3133:     $prevattempts=
                   3134: 	  &start_data_table().&start_data_table_row().
                   3135: 	  '<td>'.&mt('No data.').'</td>'.
                   3136: 	  &end_data_table_row().&end_data_table();
1.1       albertel 3137:   }
1.10      albertel 3138: }
                   3139: 
1.581     albertel 3140: sub format_previous_attempt_value {
                   3141:     my ($key,$value) = @_;
                   3142:     if ($key =~ /timestamp/) {
                   3143: 	$value = &Apache::lonlocal::locallocaltime($value);
                   3144:     } elsif (ref($value) eq 'ARRAY') {
                   3145: 	$value = '('.join(', ', @{ $value }).')';
                   3146:     } else {
                   3147: 	$value = &unescape($value);
                   3148:     }
                   3149:     return $value;
                   3150: }
                   3151: 
                   3152: 
1.107     albertel 3153: sub relative_to_absolute {
                   3154:     my ($url,$output)=@_;
                   3155:     my $parser=HTML::TokeParser->new(\$output);
                   3156:     my $token;
                   3157:     my $thisdir=$url;
                   3158:     my @rlinks=();
                   3159:     while ($token=$parser->get_token) {
                   3160: 	if ($token->[0] eq 'S') {
                   3161: 	    if ($token->[1] eq 'a') {
                   3162: 		if ($token->[2]->{'href'}) {
                   3163: 		    $rlinks[$#rlinks+1]=$token->[2]->{'href'};
                   3164: 		}
                   3165: 	    } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
                   3166: 		$rlinks[$#rlinks+1]=$token->[2]->{'src'};
                   3167: 	    } elsif ($token->[1] eq 'base') {
                   3168: 		$thisdir=$token->[2]->{'href'};
                   3169: 	    }
                   3170: 	}
                   3171:     }
                   3172:     $thisdir=~s-/[^/]*$--;
1.356     albertel 3173:     foreach my $link (@rlinks) {
                   3174: 	unless (($link=~/^http:\/\//i) ||
                   3175: 		($link=~/^\//) ||
                   3176: 		($link=~/^javascript:/i) ||
                   3177: 		($link=~/^mailto:/i) ||
                   3178: 		($link=~/^\#/)) {
                   3179: 	    my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
                   3180: 	    $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107     albertel 3181: 	}
                   3182:     }
                   3183: # -------------------------------------------------- Deal with Applet codebases
                   3184:     $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
                   3185:     return $output;
                   3186: }
                   3187: 
1.112     bowersj2 3188: =pod
                   3189: 
1.648     raeburn  3190: =item * &get_student_view()
1.112     bowersj2 3191: 
                   3192: show a snapshot of what student was looking at
                   3193: 
                   3194: =cut
                   3195: 
1.10      albertel 3196: sub get_student_view {
1.186     albertel 3197:   my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114     www      3198:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 3199:   my (%form);
1.10      albertel 3200:   my @elements=('symb','courseid','domain','username');
                   3201:   foreach my $element (@elements) {
1.186     albertel 3202:       $form{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 3203:   }
1.186     albertel 3204:   if (defined($moreenv)) {
                   3205:       %form=(%form,%{$moreenv});
                   3206:   }
1.236     albertel 3207:   if (defined($target)) { $form{'grade_target'} = $target; }
1.107     albertel 3208:   $feedurl=&Apache::lonnet::clutter($feedurl);
1.650     www      3209:   my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11      albertel 3210:   $userview=~s/\<body[^\>]*\>//gi;
                   3211:   $userview=~s/\<\/body\>//gi;
                   3212:   $userview=~s/\<html\>//gi;
                   3213:   $userview=~s/\<\/html\>//gi;
                   3214:   $userview=~s/\<head\>//gi;
                   3215:   $userview=~s/\<\/head\>//gi;
                   3216:   $userview=~s/action\s*\=/would_be_action\=/gi;
1.107     albertel 3217:   $userview=&relative_to_absolute($feedurl,$userview);
1.650     www      3218:   if (wantarray) {
                   3219:      return ($userview,$response);
                   3220:   } else {
                   3221:      return $userview;
                   3222:   }
                   3223: }
                   3224: 
                   3225: sub get_student_view_with_retries {
                   3226:   my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
                   3227: 
                   3228:     my $ok = 0;                 # True if we got a good response.
                   3229:     my $content;
                   3230:     my $response;
                   3231: 
                   3232:     # Try to get the student_view done. within the retries count:
                   3233:     
                   3234:     do {
                   3235:          ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
                   3236:          $ok      = $response->is_success;
                   3237:          if (!$ok) {
                   3238:             &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
                   3239:          }
                   3240:          $retries--;
                   3241:     } while (!$ok && ($retries > 0));
                   3242:     
                   3243:     if (!$ok) {
                   3244:        $content = '';          # On error return an empty content.
                   3245:     }
1.651     www      3246:     if (wantarray) {
                   3247:        return ($content, $response);
                   3248:     } else {
                   3249:        return $content;
                   3250:     }
1.11      albertel 3251: }
                   3252: 
1.112     bowersj2 3253: =pod
                   3254: 
1.648     raeburn  3255: =item * &get_student_answers() 
1.112     bowersj2 3256: 
                   3257: show a snapshot of how student was answering problem
                   3258: 
                   3259: =cut
                   3260: 
1.11      albertel 3261: sub get_student_answers {
1.100     sakharuk 3262:   my ($symb,$username,$domain,$courseid,%form) = @_;
1.114     www      3263:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 3264:   my (%moreenv);
1.11      albertel 3265:   my @elements=('symb','courseid','domain','username');
                   3266:   foreach my $element (@elements) {
1.186     albertel 3267:     $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 3268:   }
1.186     albertel 3269:   $moreenv{'grade_target'}='answer';
                   3270:   %moreenv=(%form,%moreenv);
1.497     raeburn  3271:   $feedurl = &Apache::lonnet::clutter($feedurl);
                   3272:   my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10      albertel 3273:   return $userview;
1.1       albertel 3274: }
1.116     albertel 3275: 
                   3276: =pod
                   3277: 
                   3278: =item * &submlink()
                   3279: 
1.242     albertel 3280: Inputs: $text $uname $udom $symb $target
1.116     albertel 3281: 
                   3282: Returns: A link to grades.pm such as to see the SUBM view of a student
                   3283: 
                   3284: =cut
                   3285: 
                   3286: ###############################################
                   3287: sub submlink {
1.242     albertel 3288:     my ($text,$uname,$udom,$symb,$target)=@_;
1.116     albertel 3289:     if (!($uname && $udom)) {
                   3290: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 3291: 	    &Apache::lonnet::whichuser($symb);
1.116     albertel 3292: 	if (!$symb) { $symb=$cursymb; }
                   3293:     }
1.254     matthew  3294:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      3295:     $symb=&escape($symb);
1.242     albertel 3296:     if ($target) { $target="target=\"$target\""; }
                   3297:     return '<a href="/adm/grades?&command=submission&'.
                   3298: 	'symb='.$symb.'&student='.$uname.
                   3299: 	'&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
                   3300: }
                   3301: ##############################################
                   3302: 
                   3303: =pod
                   3304: 
                   3305: =item * &pgrdlink()
                   3306: 
                   3307: Inputs: $text $uname $udom $symb $target
                   3308: 
                   3309: Returns: A link to grades.pm such as to see the PGRD view of a student
                   3310: 
                   3311: =cut
                   3312: 
                   3313: ###############################################
                   3314: sub pgrdlink {
                   3315:     my $link=&submlink(@_);
                   3316:     $link=~s/(&command=submission)/$1&showgrading=yes/;
                   3317:     return $link;
                   3318: }
                   3319: ##############################################
                   3320: 
                   3321: =pod
                   3322: 
                   3323: =item * &pprmlink()
                   3324: 
                   3325: Inputs: $text $uname $udom $symb $target
                   3326: 
                   3327: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283     albertel 3328: student and a specific resource
1.242     albertel 3329: 
                   3330: =cut
                   3331: 
                   3332: ###############################################
                   3333: sub pprmlink {
                   3334:     my ($text,$uname,$udom,$symb,$target)=@_;
                   3335:     if (!($uname && $udom)) {
                   3336: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 3337: 	    &Apache::lonnet::whichuser($symb);
1.242     albertel 3338: 	if (!$symb) { $symb=$cursymb; }
                   3339:     }
1.254     matthew  3340:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      3341:     $symb=&escape($symb);
1.242     albertel 3342:     if ($target) { $target="target=\"$target\""; }
1.595     albertel 3343:     return '<a href="/adm/parmset?command=set&amp;'.
                   3344: 	'symb='.$symb.'&amp;uname='.$uname.
                   3345: 	'&amp;udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116     albertel 3346: }
                   3347: ##############################################
1.37      matthew  3348: 
1.112     bowersj2 3349: =pod
                   3350: 
                   3351: =back
                   3352: 
                   3353: =cut
                   3354: 
1.37      matthew  3355: ###############################################
1.51      www      3356: 
                   3357: 
                   3358: sub timehash {
1.687     raeburn  3359:     my ($thistime) = @_;
                   3360:     my $timezone = &Apache::lonlocal::gettimezone();
                   3361:     my $dt = DateTime->from_epoch(epoch => $thistime)
                   3362:                      ->set_time_zone($timezone);
                   3363:     my $wday = $dt->day_of_week();
                   3364:     if ($wday == 7) { $wday = 0; }
                   3365:     return ( 'second' => $dt->second(),
                   3366:              'minute' => $dt->minute(),
                   3367:              'hour'   => $dt->hour(),
                   3368:              'day'     => $dt->day_of_month(),
                   3369:              'month'   => $dt->month(),
                   3370:              'year'    => $dt->year(),
                   3371:              'weekday' => $wday,
                   3372:              'dayyear' => $dt->day_of_year(),
                   3373:              'dlsav'   => $dt->is_dst() );
1.51      www      3374: }
                   3375: 
1.370     www      3376: sub utc_string {
                   3377:     my ($date)=@_;
1.371     www      3378:     return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370     www      3379: }
                   3380: 
1.51      www      3381: sub maketime {
                   3382:     my %th=@_;
1.687     raeburn  3383:     my ($epoch_time,$timezone,$dt);
                   3384:     $timezone = &Apache::lonlocal::gettimezone();
                   3385:     eval {
                   3386:         $dt = DateTime->new( year   => $th{'year'},
                   3387:                              month  => $th{'month'},
                   3388:                              day    => $th{'day'},
                   3389:                              hour   => $th{'hour'},
                   3390:                              minute => $th{'minute'},
                   3391:                              second => $th{'second'},
                   3392:                              time_zone => $timezone,
                   3393:                          );
                   3394:     };
                   3395:     if (!$@) {
                   3396:         $epoch_time = $dt->epoch;
                   3397:         if ($epoch_time) {
                   3398:             return $epoch_time;
                   3399:         }
                   3400:     }
1.51      www      3401:     return POSIX::mktime(
                   3402:         ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210     www      3403:          $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70      www      3404: }
                   3405: 
                   3406: #########################################
1.51      www      3407: 
                   3408: sub findallcourses {
1.482     raeburn  3409:     my ($roles,$uname,$udom) = @_;
1.355     albertel 3410:     my %roles;
                   3411:     if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348     albertel 3412:     my %courses;
1.51      www      3413:     my $now=time;
1.482     raeburn  3414:     if (!defined($uname)) {
                   3415:         $uname = $env{'user.name'};
                   3416:     }
                   3417:     if (!defined($udom)) {
                   3418:         $udom = $env{'user.domain'};
                   3419:     }
                   3420:     if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
                   3421:         my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
                   3422:         if (!%roles) {
                   3423:             %roles = (
                   3424:                        cc => 1,
                   3425:                        in => 1,
                   3426:                        ep => 1,
                   3427:                        ta => 1,
                   3428:                        cr => 1,
                   3429:                        st => 1,
                   3430:              );
                   3431:         }
                   3432:         foreach my $entry (keys(%roleshash)) {
                   3433:             my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
                   3434:             if ($trole =~ /^cr/) { 
                   3435:                 next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
                   3436:             } else {
                   3437:                 next if (!exists($roles{$trole}));
                   3438:             }
                   3439:             if ($tend) {
                   3440:                 next if ($tend < $now);
                   3441:             }
                   3442:             if ($tstart) {
                   3443:                 next if ($tstart > $now);
                   3444:             }
                   3445:             my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
                   3446:             (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
                   3447:             if ($secpart eq '') {
                   3448:                 ($cnum,$role) = split(/_/,$cnumpart); 
                   3449:                 $sec = 'none';
                   3450:                 $realsec = '';
                   3451:             } else {
                   3452:                 $cnum = $cnumpart;
                   3453:                 ($sec,$role) = split(/_/,$secpart);
                   3454:                 $realsec = $sec;
1.490     raeburn  3455:             }
1.482     raeburn  3456:             $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
                   3457:         }
                   3458:     } else {
                   3459:         foreach my $key (keys(%env)) {
1.483     albertel 3460: 	    if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
                   3461:                  $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482     raeburn  3462: 	        my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
                   3463: 	        next if ($role eq 'ca' || $role eq 'aa');
                   3464: 	        next if (%roles && !exists($roles{$role}));
                   3465: 	        my ($starttime,$endtime)=split(/\./,$env{$key});
                   3466:                 my $active=1;
                   3467:                 if ($starttime) {
                   3468: 		    if ($now<$starttime) { $active=0; }
                   3469:                 }
                   3470:                 if ($endtime) {
                   3471:                     if ($now>$endtime) { $active=0; }
                   3472:                 }
                   3473:                 if ($active) {
                   3474:                     if ($sec eq '') {
                   3475:                         $sec = 'none';
                   3476:                     }
                   3477:                     $courses{$cdom.'_'.$cnum}{$sec} = 
                   3478:                                      $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474     raeburn  3479:                 }
                   3480:             }
1.51      www      3481:         }
                   3482:     }
1.474     raeburn  3483:     return %courses;
1.51      www      3484: }
1.37      matthew  3485: 
1.54      www      3486: ###############################################
1.474     raeburn  3487: 
                   3488: sub blockcheck {
1.482     raeburn  3489:     my ($setters,$activity,$uname,$udom) = @_;
1.490     raeburn  3490: 
                   3491:     if (!defined($udom)) {
                   3492:         $udom = $env{'user.domain'};
                   3493:     }
                   3494:     if (!defined($uname)) {
                   3495:         $uname = $env{'user.name'};
                   3496:     }
                   3497: 
                   3498:     # If uname and udom are for a course, check for blocks in the course.
                   3499: 
                   3500:     if (&Apache::lonnet::is_course($udom,$uname)) {
                   3501:         my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502     raeburn  3502:         my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490     raeburn  3503:         return ($startblock,$endblock);
                   3504:     }
1.474     raeburn  3505: 
1.502     raeburn  3506:     my $startblock = 0;
                   3507:     my $endblock = 0;
1.482     raeburn  3508:     my %live_courses = &findallcourses(undef,$uname,$udom);
1.474     raeburn  3509: 
1.490     raeburn  3510:     # If uname is for a user, and activity is course-specific, i.e.,
                   3511:     # boards, chat or groups, check for blocking in current course only.
1.474     raeburn  3512: 
1.490     raeburn  3513:     if (($activity eq 'boards' || $activity eq 'chat' ||
                   3514:          $activity eq 'groups') && ($env{'request.course.id'})) {
                   3515:         foreach my $key (keys(%live_courses)) {
                   3516:             if ($key ne $env{'request.course.id'}) {
                   3517:                 delete($live_courses{$key});
                   3518:             }
                   3519:         }
                   3520:     }
                   3521: 
                   3522:     my $otheruser = 0;
                   3523:     my %own_courses;
                   3524:     if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
                   3525:         # Resource belongs to user other than current user.
                   3526:         $otheruser = 1;
                   3527:         # Gather courses for current user
                   3528:         %own_courses = 
                   3529:             &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
                   3530:     }
                   3531: 
                   3532:     # Gather active course roles - course coordinator, instructor, 
                   3533:     # exam proctor, ta, student, or custom role.
1.474     raeburn  3534: 
                   3535:     foreach my $course (keys(%live_courses)) {
1.482     raeburn  3536:         my ($cdom,$cnum);
                   3537:         if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
                   3538:             $cdom = $env{'course.'.$course.'.domain'};
                   3539:             $cnum = $env{'course.'.$course.'.num'};
                   3540:         } else {
1.490     raeburn  3541:             ($cdom,$cnum) = split(/_/,$course); 
1.482     raeburn  3542:         }
                   3543:         my $no_ownblock = 0;
                   3544:         my $no_userblock = 0;
1.533     raeburn  3545:         if ($otheruser && $activity ne 'com') {
1.490     raeburn  3546:             # Check if current user has 'evb' priv for this
                   3547:             if (defined($own_courses{$course})) {
                   3548:                 foreach my $sec (keys(%{$own_courses{$course}})) {
                   3549:                     my $checkrole = 'cm./'.$cdom.'/'.$cnum;
                   3550:                     if ($sec ne 'none') {
                   3551:                         $checkrole .= '/'.$sec;
                   3552:                     }
                   3553:                     if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   3554:                         $no_ownblock = 1;
                   3555:                         last;
                   3556:                     }
                   3557:                 }
                   3558:             }
                   3559:             # if they have 'evb' priv and are currently not playing student
                   3560:             next if (($no_ownblock) &&
                   3561:                  ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
                   3562:         }
1.474     raeburn  3563:         foreach my $sec (keys(%{$live_courses{$course}})) {
1.482     raeburn  3564:             my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474     raeburn  3565:             if ($sec ne 'none') {
1.482     raeburn  3566:                 $checkrole .= '/'.$sec;
1.474     raeburn  3567:             }
1.490     raeburn  3568:             if ($otheruser) {
                   3569:                 # Resource belongs to user other than current user.
                   3570:                 # Assemble privs for that user, and check for 'evb' priv.
1.482     raeburn  3571:                 my ($trole,$tdom,$tnum,$tsec);
                   3572:                 my $entry = $live_courses{$course}{$sec};
                   3573:                 if ($entry =~ /^cr/) {
                   3574:                     ($trole,$tdom,$tnum,$tsec) = 
                   3575:                       ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
                   3576:                 } else {
                   3577:                     ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
                   3578:                 }
                   3579:                 my ($spec,$area,$trest,%allroles,%userroles);
                   3580:                 $area = '/'.$tdom.'/'.$tnum;
                   3581:                 $trest = $tnum;
                   3582:                 if ($tsec ne '') {
                   3583:                     $area .= '/'.$tsec;
                   3584:                     $trest .= '/'.$tsec;
                   3585:                 }
                   3586:                 $spec = $trole.'.'.$area;
                   3587:                 if ($trole =~ /^cr/) {
                   3588:                     &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
                   3589:                                                       $tdom,$spec,$trest,$area);
                   3590:                 } else {
                   3591:                     &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
                   3592:                                                        $tdom,$spec,$trest,$area);
                   3593:                 }
                   3594:                 my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486     raeburn  3595:                 if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
                   3596:                     if ($1) {
                   3597:                         $no_userblock = 1;
                   3598:                         last;
                   3599:                     }
                   3600:                 }
1.490     raeburn  3601:             } else {
                   3602:                 # Resource belongs to current user
                   3603:                 # Check for 'evb' priv via lonnet::allowed().
1.482     raeburn  3604:                 if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   3605:                     $no_ownblock = 1;
                   3606:                     last;
                   3607:                 }
1.474     raeburn  3608:             }
                   3609:         }
                   3610:         # if they have the evb priv and are currently not playing student
1.482     raeburn  3611:         next if (($no_ownblock) &&
1.491     albertel 3612:                  ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482     raeburn  3613:         next if ($no_userblock);
1.474     raeburn  3614: 
1.490     raeburn  3615:         # Retrieve blocking times and identity of blocker for course
                   3616:         # of specified user, unless user has 'evb' privilege.
1.502     raeburn  3617:         
                   3618:         my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
                   3619:         if (($start != 0) && 
                   3620:             (($startblock == 0) || ($startblock > $start))) {
                   3621:             $startblock = $start;
                   3622:         }
                   3623:         if (($end != 0)  &&
                   3624:             (($endblock == 0) || ($endblock < $end))) {
                   3625:             $endblock = $end;
                   3626:         }
1.490     raeburn  3627:     }
                   3628:     return ($startblock,$endblock);
                   3629: }
                   3630: 
                   3631: sub get_blocks {
                   3632:     my ($setters,$activity,$cdom,$cnum) = @_;
                   3633:     my $startblock = 0;
                   3634:     my $endblock = 0;
                   3635:     my $course = $cdom.'_'.$cnum;
                   3636:     $setters->{$course} = {};
                   3637:     $setters->{$course}{'staff'} = [];
                   3638:     $setters->{$course}{'times'} = [];
                   3639:     my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
                   3640:     foreach my $record (keys(%records)) {
                   3641:         my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
                   3642:         if ($start <= time && $end >= time) {
                   3643:             my ($staff_name,$staff_dom,$title,$blocks) =
                   3644:                 &parse_block_record($records{$record});
                   3645:             if ($blocks->{$activity} eq 'on') {
                   3646:                 push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
                   3647:                 push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491     albertel 3648:                 if ( ($startblock == 0) || ($startblock > $start) ) {
                   3649:                     $startblock = $start;
1.490     raeburn  3650:                 }
1.491     albertel 3651:                 if ( ($endblock == 0) || ($endblock < $end) ) {
                   3652:                     $endblock = $end;
1.474     raeburn  3653:                 }
                   3654:             }
                   3655:         }
                   3656:     }
                   3657:     return ($startblock,$endblock);
                   3658: }
                   3659: 
                   3660: sub parse_block_record {
                   3661:     my ($record) = @_;
                   3662:     my ($setuname,$setudom,$title,$blocks);
                   3663:     if (ref($record) eq 'HASH') {
                   3664:         ($setuname,$setudom) = split(/:/,$record->{'setter'});
                   3665:         $title = &unescape($record->{'event'});
                   3666:         $blocks = $record->{'blocks'};
                   3667:     } else {
                   3668:         my @data = split(/:/,$record,3);
                   3669:         if (scalar(@data) eq 2) {
                   3670:             $title = $data[1];
                   3671:             ($setuname,$setudom) = split(/@/,$data[0]);
                   3672:         } else {
                   3673:             ($setuname,$setudom,$title) = @data;
                   3674:         }
                   3675:         $blocks = { 'com' => 'on' };
                   3676:     }
                   3677:     return ($setuname,$setudom,$title,$blocks);
                   3678: }
                   3679: 
                   3680: sub build_block_table {
                   3681:     my ($startblock,$endblock,$setters) = @_;
                   3682:     my %lt = &Apache::lonlocal::texthash(
                   3683:         'cacb' => 'Currently active communication blocks',
                   3684:         'cour' => 'Course',
                   3685:         'dura' => 'Duration',
                   3686:         'blse' => 'Block set by'
                   3687:     );
                   3688:     my $output;
1.476     raeburn  3689:     $output = '<br />'.$lt{'cacb'}.':<br />';
1.474     raeburn  3690:     $output .= &start_data_table();
                   3691:     $output .= '
                   3692: <tr>
                   3693:  <th>'.$lt{'cour'}.'</th>
                   3694:  <th>'.$lt{'dura'}.'</th>
                   3695:  <th>'.$lt{'blse'}.'</th>
                   3696: </tr>
                   3697: ';
                   3698:     foreach my $course (keys(%{$setters})) {
                   3699:         my %courseinfo=&Apache::lonnet::coursedescription($course);
                   3700:         for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) {
                   3701:             my ($uname,$udom) = @{$$setters{$course}{staff}[$i]};
1.490     raeburn  3702:             my $fullname = &plainname($uname,$udom);
                   3703:             if (defined($env{'user.name'}) && defined($env{'user.domain'})
                   3704:                 && $env{'user.name'} ne 'public' 
                   3705:                 && $env{'user.domain'} ne 'public') {
                   3706:                 $fullname = &aboutmewrapper($fullname,$uname,$udom);
                   3707:             }
1.474     raeburn  3708:             my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]};
                   3709:             $openblock = &Apache::lonlocal::locallocaltime($openblock);
                   3710:             $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
                   3711:             $output .= &Apache::loncommon::start_data_table_row().
                   3712:                        '<td>'.$courseinfo{'description'}.'</td>'.
                   3713:                        '<td>'.$openblock.' to '.$closeblock.'</td>'.
1.490     raeburn  3714:                        '<td>'.$fullname.'</td>'.
1.474     raeburn  3715:                         &Apache::loncommon::end_data_table_row();
                   3716:         }
                   3717:     }
                   3718:     $output .= &end_data_table();
                   3719: }
                   3720: 
1.490     raeburn  3721: sub blocking_status {
                   3722:     my ($activity,$uname,$udom) = @_;
                   3723:     my %setters;
                   3724:     my ($blocked,$output,$ownitem,$is_course);
                   3725:     my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
                   3726:     if ($startblock && $endblock) {
                   3727:         $blocked = 1;
                   3728:         if (wantarray) {
                   3729:             my $category;
                   3730:             if ($activity eq 'boards') {
                   3731:                 $category = 'Discussion posts in this course';
                   3732:             } elsif ($activity eq 'blogs') {
                   3733:                 $category = 'Blogs';
                   3734:             } elsif ($activity eq 'port') {
                   3735:                 if (defined($uname) && defined($udom)) {
                   3736:                     if ($uname eq $env{'user.name'} &&
                   3737:                         $udom eq $env{'user.domain'}) {
                   3738:                         $ownitem = 1;
                   3739:                     }
                   3740:                 }
                   3741:                 $is_course = &Apache::lonnet::is_course($udom,$uname);
                   3742:                 if ($ownitem) { 
                   3743:                     $category = 'Your portfolio files';  
                   3744:                 } elsif ($is_course) {
                   3745:                     my $coursedesc;
                   3746:                     foreach my $course (keys(%setters)) {
                   3747:                         my %courseinfo =
                   3748:                              &Apache::lonnet::coursedescription($course);
                   3749:                         $coursedesc = $courseinfo{'description'};
                   3750:                     }
                   3751:                     $category = "Group files in the course '$coursedesc'";
                   3752:                 } else {
                   3753:                     $category = 'Portfolio files belonging to ';
                   3754:                     if ($env{'user.name'} eq 'public' && 
                   3755:                         $env{'user.domain'} eq 'public') {
                   3756:                         $category .= &plainname($uname,$udom);
                   3757:                     } else {
                   3758:                         $category .= &aboutmewrapper(&plainname($uname,$udom),$uname,$udom);  
                   3759:                     }
                   3760:                 }
                   3761:             } elsif ($activity eq 'groups') {
                   3762:                 $category = 'Groups in this course';
                   3763:             }
                   3764:             my $showstart = &Apache::lonlocal::locallocaltime($startblock);
                   3765:             my $showend = &Apache::lonlocal::locallocaltime($endblock);
                   3766:             $output = '<br />'.&mt('[_1] will be inaccessible between [_2] and [_3] because communication is being blocked.',$category,$showstart,$showend).'<br />';
                   3767:             if (!($activity eq 'port' && !($ownitem) && !($is_course))) { 
                   3768:                 $output .= &build_block_table($startblock,$endblock,\%setters);
                   3769:             }
                   3770:         }
                   3771:     }
                   3772:     if (wantarray) {
                   3773:         return ($blocked,$output);
                   3774:     } else {
                   3775:         return $blocked;
                   3776:     }
                   3777: }
                   3778: 
1.60      matthew  3779: ###############################################
                   3780: 
1.682     raeburn  3781: sub check_ip_acc {
                   3782:     my ($acc)=@_;
                   3783:     &Apache::lonxml::debug("acc is $acc");
                   3784:     if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
                   3785:         return 1;
                   3786:     }
                   3787:     my $allowed=0;
                   3788:     my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
                   3789: 
                   3790:     my $name;
                   3791:     foreach my $pattern (split(',',$acc)) {
                   3792:         $pattern =~ s/^\s*//;
                   3793:         $pattern =~ s/\s*$//;
                   3794:         if ($pattern =~ /\*$/) {
                   3795:             #35.8.*
                   3796:             $pattern=~s/\*//;
                   3797:             if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
                   3798:         } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
                   3799:             #35.8.3.[34-56]
                   3800:             my $low=$2;
                   3801:             my $high=$3;
                   3802:             $pattern=$1;
                   3803:             if ($ip =~ /^\Q$pattern\E/) {
                   3804:                 my $last=(split(/\./,$ip))[3];
                   3805:                 if ($last <=$high && $last >=$low) { $allowed=1; }
                   3806:             }
                   3807:         } elsif ($pattern =~ /^\*/) {
                   3808:             #*.msu.edu
                   3809:             $pattern=~s/\*//;
                   3810:             if (!defined($name)) {
                   3811:                 use Socket;
                   3812:                 my $netaddr=inet_aton($ip);
                   3813:                 ($name)=gethostbyaddr($netaddr,AF_INET);
                   3814:             }
                   3815:             if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
                   3816:         } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
                   3817:             #127.0.0.1
                   3818:             if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
                   3819:         } else {
                   3820:             #some.name.com
                   3821:             if (!defined($name)) {
                   3822:                 use Socket;
                   3823:                 my $netaddr=inet_aton($ip);
                   3824:                 ($name)=gethostbyaddr($netaddr,AF_INET);
                   3825:             }
                   3826:             if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
                   3827:         }
                   3828:         if ($allowed) { last; }
                   3829:     }
                   3830:     return $allowed;
                   3831: }
                   3832: 
                   3833: ###############################################
                   3834: 
1.60      matthew  3835: =pod
                   3836: 
1.112     bowersj2 3837: =head1 Domain Template Functions
                   3838: 
                   3839: =over 4
                   3840: 
                   3841: =item * &determinedomain()
1.60      matthew  3842: 
                   3843: Inputs: $domain (usually will be undef)
                   3844: 
1.63      www      3845: Returns: Determines which domain should be used for designs
1.60      matthew  3846: 
                   3847: =cut
1.54      www      3848: 
1.60      matthew  3849: ###############################################
1.63      www      3850: sub determinedomain {
                   3851:     my $domain=shift;
1.531     albertel 3852:     if (! $domain) {
1.60      matthew  3853:         # Determine domain if we have not been given one
                   3854:         $domain = $Apache::lonnet::perlvar{'lonDefDomain'};
1.258     albertel 3855:         if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
                   3856:         if ($env{'request.role.domain'}) { 
                   3857:             $domain=$env{'request.role.domain'}; 
1.60      matthew  3858:         }
                   3859:     }
1.63      www      3860:     return $domain;
                   3861: }
                   3862: ###############################################
1.517     raeburn  3863: 
1.518     albertel 3864: sub devalidate_domconfig_cache {
                   3865:     my ($udom)=@_;
                   3866:     &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
                   3867: }
                   3868: 
                   3869: # ---------------------- Get domain configuration for a domain
                   3870: sub get_domainconf {
                   3871:     my ($udom) = @_;
                   3872:     my $cachetime=1800;
                   3873:     my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
                   3874:     if (defined($cached)) { return %{$result}; }
                   3875: 
                   3876:     my %domconfig = &Apache::lonnet::get_dom('configuration',
                   3877: 					     ['login','rolecolors'],$udom);
1.632     raeburn  3878:     my (%designhash,%legacy);
1.518     albertel 3879:     if (keys(%domconfig) > 0) {
                   3880:         if (ref($domconfig{'login'}) eq 'HASH') {
1.632     raeburn  3881:             if (keys(%{$domconfig{'login'}})) {
                   3882:                 foreach my $key (keys(%{$domconfig{'login'}})) {
                   3883:                     $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
                   3884:                 }
                   3885:             } else {
                   3886:                 $legacy{'login'} = 1;
1.518     albertel 3887:             }
1.632     raeburn  3888:         } else {
                   3889:             $legacy{'login'} = 1;
1.518     albertel 3890:         }
                   3891:         if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632     raeburn  3892:             if (keys(%{$domconfig{'rolecolors'}})) {
                   3893:                 foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
                   3894:                     if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
                   3895:                         foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
                   3896:                             $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
                   3897:                         }
1.518     albertel 3898:                     }
                   3899:                 }
1.632     raeburn  3900:             } else {
                   3901:                 $legacy{'rolecolors'} = 1;
1.518     albertel 3902:             }
1.632     raeburn  3903:         } else {
                   3904:             $legacy{'rolecolors'} = 1;
1.518     albertel 3905:         }
1.632     raeburn  3906:         if (keys(%legacy) > 0) {
                   3907:             my %legacyhash = &get_legacy_domconf($udom);
                   3908:             foreach my $item (keys(%legacyhash)) {
                   3909:                 if ($item =~ /^\Q$udom\E\.login/) {
                   3910:                     if ($legacy{'login'}) { 
                   3911:                         $designhash{$item} = $legacyhash{$item};
                   3912:                     }
                   3913:                 } else {
                   3914:                     if ($legacy{'rolecolors'}) {
                   3915:                         $designhash{$item} = $legacyhash{$item};
                   3916:                     }
1.518     albertel 3917:                 }
                   3918:             }
                   3919:         }
1.632     raeburn  3920:     } else {
                   3921:         %designhash = &get_legacy_domconf($udom); 
1.518     albertel 3922:     }
                   3923:     &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
                   3924: 				  $cachetime);
                   3925:     return %designhash;
                   3926: }
                   3927: 
1.632     raeburn  3928: sub get_legacy_domconf {
                   3929:     my ($udom) = @_;
                   3930:     my %legacyhash;
                   3931:     my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
                   3932:     my $designfile =  $designdir.'/'.$udom.'.tab';
                   3933:     if (-e $designfile) {
                   3934:         if ( open (my $fh,"<$designfile") ) {
                   3935:             while (my $line = <$fh>) {
                   3936:                 next if ($line =~ /^\#/);
                   3937:                 chomp($line);
                   3938:                 my ($key,$val)=(split(/\=/,$line));
                   3939:                 if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
                   3940:             }
                   3941:             close($fh);
                   3942:         }
                   3943:     }
                   3944:     if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
                   3945:         $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
                   3946:     }
                   3947:     return %legacyhash;
                   3948: }
                   3949: 
1.63      www      3950: =pod
                   3951: 
1.112     bowersj2 3952: =item * &domainlogo()
1.63      www      3953: 
                   3954: Inputs: $domain (usually will be undef)
                   3955: 
                   3956: Returns: A link to a domain logo, if the domain logo exists.
                   3957: If the domain logo does not exist, a description of the domain.
                   3958: 
                   3959: =cut
1.112     bowersj2 3960: 
1.63      www      3961: ###############################################
                   3962: sub domainlogo {
1.517     raeburn  3963:     my $domain = &determinedomain(shift);
1.518     albertel 3964:     my %designhash = &get_domainconf($domain);    
1.517     raeburn  3965:     # See if there is a logo
                   3966:     if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519     raeburn  3967:         my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538     albertel 3968:         if ($imgsrc =~ m{^/(adm|res)/}) {
                   3969: 	    if ($imgsrc =~ m{^/res/}) {
                   3970: 		my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
                   3971: 		&Apache::lonnet::repcopy($local_name);
                   3972: 	    }
                   3973: 	   $imgsrc = &lonhttpdurl($imgsrc);
1.519     raeburn  3974:         } 
                   3975:         return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514     albertel 3976:     } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
                   3977:         return &Apache::lonnet::domain($domain,'description');
1.59      www      3978:     } else {
1.60      matthew  3979:         return '';
1.59      www      3980:     }
                   3981: }
1.63      www      3982: ##############################################
                   3983: 
                   3984: =pod
                   3985: 
1.112     bowersj2 3986: =item * &designparm()
1.63      www      3987: 
                   3988: Inputs: $which parameter; $domain (usually will be undef)
                   3989: 
                   3990: Returns: value of designparamter $which
                   3991: 
                   3992: =cut
1.112     bowersj2 3993: 
1.397     albertel 3994: 
1.400     albertel 3995: ##############################################
1.397     albertel 3996: sub designparm {
                   3997:     my ($which,$domain)=@_;
1.258     albertel 3998:     if ($env{'browser.blackwhite'} eq 'on') {
1.635     raeburn  3999: 	if ($which=~/\.(font|alink|vlink|link|textcol)$/) {
1.110     www      4000: 	    return '#000000';
                   4001: 	}
1.635     raeburn  4002: 	if ($which=~/\.(pgbg|sidebg|bgcol)$/) {
1.110     www      4003: 	    return '#FFFFFF';
                   4004: 	}
                   4005: 	if ($which=~/\.tabbg$/) {
                   4006: 	    return '#CCCCCC';
                   4007: 	}
                   4008:     }
1.397     albertel 4009:     if (exists($env{'environment.color.'.$which})) {
1.258     albertel 4010: 	return $env{'environment.color.'.$which};
1.96      www      4011:     }
1.63      www      4012:     $domain=&determinedomain($domain);
1.518     albertel 4013:     my %domdesign = &get_domainconf($domain);
1.520     raeburn  4014:     my $output;
1.517     raeburn  4015:     if ($domdesign{$domain.'.'.$which} ne '') {
1.520     raeburn  4016: 	$output = $domdesign{$domain.'.'.$which};
1.63      www      4017:     } else {
1.520     raeburn  4018:         $output = $defaultdesign{$which};
                   4019:     }
                   4020:     if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635     raeburn  4021:         ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538     albertel 4022:         if ($output =~ m{^/(adm|res)/}) {
                   4023: 	    if ($output =~ m{^/res/}) {
                   4024: 		my $local_name = &Apache::lonnet::filelocation('',$output);
                   4025: 		&Apache::lonnet::repcopy($local_name);
                   4026: 	    }
1.520     raeburn  4027:             $output = &lonhttpdurl($output);
                   4028:         }
1.63      www      4029:     }
1.520     raeburn  4030:     return $output;
1.63      www      4031: }
1.59      www      4032: 
1.60      matthew  4033: ###############################################
                   4034: ###############################################
                   4035: 
                   4036: =pod
                   4037: 
1.112     bowersj2 4038: =back
                   4039: 
1.549     albertel 4040: =head1 HTML Helpers
1.112     bowersj2 4041: 
                   4042: =over 4
                   4043: 
                   4044: =item * &bodytag()
1.60      matthew  4045: 
                   4046: Returns a uniform header for LON-CAPA web pages.
                   4047: 
                   4048: Inputs: 
                   4049: 
1.112     bowersj2 4050: =over 4
                   4051: 
                   4052: =item * $title, A title to be displayed on the page.
                   4053: 
                   4054: =item * $function, the current role (can be undef).
                   4055: 
                   4056: =item * $addentries, extra parameters for the <body> tag.
                   4057: 
                   4058: =item * $bodyonly, if defined, only return the <body> tag.
                   4059: 
                   4060: =item * $domain, if defined, force a given domain.
                   4061: 
                   4062: =item * $forcereg, if page should register as content page (relevant for 
1.86      www      4063:             text interface only)
1.60      matthew  4064: 
1.326     albertel 4065: =item * $customtitle, alternate text to use instead of $title
                   4066:                       in the title box that appears, this text
                   4067:                       is not auto translated like the $title is
1.309     albertel 4068: 
                   4069: =item * $notopbar, if true, keep the 'what is this' info but remove the
                   4070:                    navigational links
1.317     albertel 4071: 
1.338     albertel 4072: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
                   4073: 
                   4074: =item * $notitle, if true keep the nav controls, but remove the title bar
                   4075: 
1.361     albertel 4076: =item * $no_inline_link, if true and in remote mode, don't show the 
                   4077:          'Switch To Inline Menu' link
                   4078: 
1.460     albertel 4079: =item * $args, optional argument valid values are
                   4080:             no_auto_mt_title -> prevents &mt()ing the title arg
1.562     albertel 4081:             inherit_jsmath -> when creating popup window in a page,
                   4082:                               should it have jsmath forced on by the
                   4083:                               current page
1.460     albertel 4084: 
1.112     bowersj2 4085: =back
                   4086: 
1.60      matthew  4087: Returns: A uniform header for LON-CAPA web pages.  
                   4088: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
                   4089: If $bodyonly is undef or zero, an html string containing a <body> tag and 
                   4090: other decorations will be returned.
                   4091: 
                   4092: =cut
                   4093: 
1.54      www      4094: sub bodytag {
1.309     albertel 4095:     my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,$customtitle,
1.460     albertel 4096: 	$notopbar,$bgcolor,$notitle,$no_inline_link,$args)=@_;
1.339     albertel 4097: 
1.460     albertel 4098:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339     albertel 4099: 
1.183     matthew  4100:     $function = &get_users_function() if (!$function);
1.339     albertel 4101:     my $img =    &designparm($function.'.img',$domain);
                   4102:     my $font =   &designparm($function.'.font',$domain);
                   4103:     my $pgbg   = $bgcolor || &designparm($function.'.pgbg',$domain);
                   4104: 
                   4105:     my %design = ( 'style'   => 'margin-top: 0px',
1.535     albertel 4106: 		   'bgcolor' => $pgbg,
1.339     albertel 4107: 		   'text'    => $font,
                   4108:                    'alink'   => &designparm($function.'.alink',$domain),
                   4109: 		   'vlink'   => &designparm($function.'.vlink',$domain),
                   4110: 		   'link'    => &designparm($function.'.link',$domain),);
1.438     albertel 4111:     @design{keys(%$addentries)} = @$addentries{keys(%$addentries)}; 
1.339     albertel 4112: 
1.63      www      4113:  # role and realm
1.378     raeburn  4114:     my ($role,$realm) = split(/\./,$env{'request.role'},2);
                   4115:     if ($role  eq 'ca') {
1.479     albertel 4116:         my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500     albertel 4117:         $realm = &plainname($rname,$rdom);
1.378     raeburn  4118:     } 
1.55      www      4119: # realm
1.258     albertel 4120:     if ($env{'request.course.id'}) {
1.378     raeburn  4121:         if ($env{'request.role'} !~ /^cr/) {
                   4122:             $role = &Apache::lonnet::plaintext($role,&course_type());
                   4123:         }
1.359     albertel 4124: 	$realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378     raeburn  4125:     } else {
                   4126:         $role = &Apache::lonnet::plaintext($role);
1.54      www      4127:     }
1.433     albertel 4128: 
1.359     albertel 4129:     if (!$realm) { $realm='&nbsp;'; }
1.55      www      4130: # Set messages
1.60      matthew  4131:     my $messages=&domainlogo($domain);
1.330     albertel 4132: 
1.438     albertel 4133:     my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329     albertel 4134: 
1.101     www      4135: # construct main body tag
1.359     albertel 4136:     my $bodytag = "<body $extra_body_attr>".
1.562     albertel 4137: 	&Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252     albertel 4138: 
1.530     albertel 4139:     if ($bodyonly) {
1.60      matthew  4140:         return $bodytag;
1.258     albertel 4141:     } elsif ($env{'browser.interface'} eq 'textual') {
1.95      www      4142: # Accessibility
1.224     raeburn  4143:           
1.337     albertel 4144: 	$bodytag.=&Apache::lonmenu::menubuttons($forcereg,$forcereg);
1.338     albertel 4145: 	if (!$notitle) {
1.337     albertel 4146: 	    $bodytag.='<h1>LON-CAPA: '.$title.'</h1>';
                   4147: 	}
                   4148: 	return $bodytag;
1.359     albertel 4149:     }
                   4150: 
1.410     albertel 4151:     my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.433     albertel 4152:     if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
                   4153: 	undef($role);
1.434     albertel 4154:     } else {
                   4155: 	$name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433     albertel 4156:     }
1.359     albertel 4157:     
                   4158:     my $roleinfo=(<<ENDROLE);
                   4159: <td class="LC_title_bar_who">
                   4160: <div class="LC_title_bar_name">
1.410     albertel 4161:     $name
1.361     albertel 4162:     &nbsp;
1.359     albertel 4163: </div>
                   4164: <div class="LC_title_bar_role">
1.361     albertel 4165: $role&nbsp;
1.359     albertel 4166: </div>
                   4167: <div class="LC_title_bar_realm">
1.361     albertel 4168: $realm&nbsp;
1.359     albertel 4169: </div>
1.206     albertel 4170: </td>
                   4171: ENDROLE
1.235     raeburn  4172: 
1.359     albertel 4173:     my $titleinfo = '<span class="LC_title_bar_title">'.$title.'</span>';
                   4174:     if ($customtitle) {
                   4175:         $titleinfo = $customtitle;
                   4176:     }
                   4177:     #
                   4178:     # Extra info if you are the DC
                   4179:     my $dc_info = '';
                   4180:     if ($env{'user.adv'} && exists($env{'user.role.dc./'.
                   4181:                         $env{'course.'.$env{'request.course.id'}.
                   4182:                                  '.domain'}.'/'})) {
                   4183:         my $cid = $env{'request.course.id'};
                   4184:         $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380     www      4185:         $dc_info =~ s/\s+$//;
1.359     albertel 4186:         $dc_info = '('.$dc_info.')';
                   4187:     }
                   4188: 
1.644     www      4189:     if (($env{'environment.remote'} eq 'off') || ($args->{'suppress_header_logos'})) {
1.359     albertel 4190:         # No Remote
1.258     albertel 4191: 	if ($env{'request.state'} eq 'construct') {
1.359     albertel 4192: 	    $forcereg=1;
                   4193: 	}
                   4194: 
                   4195: 	if (!$customtitle && $env{'request.state'} eq 'construct') {
                   4196: 	    # this is for resources; directories have customtitle, and crumbs
                   4197:             # and select recent are created in lonpubdir.pm  
1.229     albertel 4198: 	    my ($uname,$thisdisfn)=
1.258     albertel 4199: 		($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
1.229     albertel 4200: 	    my $formaction='/priv/'.$uname.'/'.$thisdisfn;
                   4201: 	    $formaction=~s/\/+/\//g;
                   4202: 
1.359     albertel 4203: 	    my $parentpath = '';
                   4204: 	    my $lastitem = '';
                   4205: 	    if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
                   4206: 		$parentpath = $1;
                   4207: 		$lastitem = $2;
                   4208: 	    } else {
                   4209: 		$lastitem = $thisdisfn;
                   4210: 	    }
                   4211: 	    $titleinfo = 
1.640     bisitz   4212: 		&Apache::loncommon::help_open_menu('','',3,'Authoring')
                   4213: 		.'<b>'.&mt('Construction Space').'</b>:&nbsp;'
                   4214: 		.'<form name="dirs" method="post" action="'.$formaction
1.359     albertel 4215: 		.'" target="_top"><tt><b>'
                   4216: 		.&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."<font size=\"+1\">$lastitem</font></b></tt><br />"
                   4217: 		.&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
                   4218: 		.'</form>'
                   4219: 		.&Apache::lonmenu::constspaceform();
1.235     raeburn  4220:         }
1.359     albertel 4221: 
1.337     albertel 4222:         my $titletable;
1.338     albertel 4223: 	if (!$notitle) {
1.337     albertel 4224: 	    $titletable =
1.359     albertel 4225: 		'<table id="LC_title_bar">'.
                   4226:                          "<tr><td> $titleinfo $dc_info</td>".$roleinfo.
                   4227: 			 '</tr></table>';
1.337     albertel 4228: 	}
1.359     albertel 4229: 	if ($notopbar) {
                   4230: 	    $bodytag .= $titletable;
                   4231: 	} else {
                   4232: 	    if ($env{'request.state'} eq 'construct') {
1.337     albertel 4233:                 $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg,
                   4234: 							  $titletable);
1.272     raeburn  4235:             } else {
1.336     albertel 4236:                 $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg).
1.359     albertel 4237: 		    $titletable;
1.272     raeburn  4238:             }
1.235     raeburn  4239:         }
                   4240:         return $bodytag;
1.94      www      4241:     }
1.95      www      4242: 
1.93      www      4243: #
1.95      www      4244: # Top frame rendering, Remote is up
1.93      www      4245: #
1.359     albertel 4246: 
1.517     raeburn  4247:     my $imgsrc = $img;
                   4248:     if ($img =~ /^\/adm/) {
1.575     albertel 4249:         $imgsrc = &lonhttpdurl($img);
1.517     raeburn  4250:     }
                   4251:     my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359     albertel 4252: 
1.305     www      4253:     # Explicit link to get inline menu
1.361     albertel 4254:     my $menu= ($no_inline_link?''
                   4255: 	       :'<br /><a href="/adm/remote?action=collapse">'.&mt('Switch to Inline Menu Mode').'</a>');
1.245     matthew  4256:     #
1.338     albertel 4257:     if ($notitle) {
1.337     albertel 4258: 	return $bodytag;
                   4259:     }
1.94      www      4260:     return(<<ENDBODY);
1.60      matthew  4261: $bodytag
1.359     albertel 4262: <table id="LC_title_bar" class="LC_with_remote">
1.368     albertel 4263: <tr><td class="LC_title_bar_role_logo">$upperleft</td>
1.359     albertel 4264:     <td class="LC_title_bar_domain_logo">$messages&nbsp;</td>
1.54      www      4265: </tr>
1.359     albertel 4266: <tr><td>$titleinfo $dc_info $menu</td>
                   4267: $roleinfo
1.368     albertel 4268: </tr>
1.356     albertel 4269: </table>
1.54      www      4270: ENDBODY
1.182     matthew  4271: }
                   4272: 
1.330     albertel 4273: sub make_attr_string {
                   4274:     my ($register,$attr_ref) = @_;
                   4275: 
                   4276:     if ($attr_ref && !ref($attr_ref)) {
                   4277: 	die("addentries Must be a hash ref ".
                   4278: 	    join(':',caller(1))." ".
                   4279: 	    join(':',caller(0))." ");
                   4280:     }
                   4281: 
                   4282:     if ($register) {
1.339     albertel 4283: 	my ($on_load,$on_unload);
                   4284: 	foreach my $key (keys(%{$attr_ref})) {
                   4285: 	    if      (lc($key) eq 'onload') {
                   4286: 		$on_load.=$attr_ref->{$key}.';';
                   4287: 		delete($attr_ref->{$key});
                   4288: 
                   4289: 	    } elsif (lc($key) eq 'onunload') {
                   4290: 		$on_unload.=$attr_ref->{$key}.';';
                   4291: 		delete($attr_ref->{$key});
                   4292: 	    }
                   4293: 	}
                   4294: 	$attr_ref->{'onload'}  =
                   4295: 	    &Apache::lonmenu::loadevents().  $on_load;
                   4296: 	$attr_ref->{'onunload'}=
                   4297: 	    &Apache::lonmenu::unloadevents().$on_unload;
                   4298:     }
                   4299: 
                   4300: # Accessibility font enhance
                   4301:     if ($env{'browser.fontenhance'} eq 'on') {
                   4302: 	my $style;
                   4303: 	foreach my $key (keys(%{$attr_ref})) {
                   4304: 	    if (lc($key) eq 'style') {
                   4305: 		$style.=$attr_ref->{$key}.';';
                   4306: 		delete($attr_ref->{$key});
                   4307: 	    }
                   4308: 	}
                   4309: 	$attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330     albertel 4310:     }
1.339     albertel 4311: 
                   4312:     if ($env{'browser.blackwhite'} eq 'on') {
                   4313: 	delete($attr_ref->{'font'});
                   4314: 	delete($attr_ref->{'link'});
                   4315: 	delete($attr_ref->{'alink'});
                   4316: 	delete($attr_ref->{'vlink'});
                   4317: 	delete($attr_ref->{'bgcolor'});
                   4318: 	delete($attr_ref->{'background'});
                   4319:     }
                   4320: 
1.330     albertel 4321:     my $attr_string;
                   4322:     foreach my $attr (keys(%$attr_ref)) {
                   4323: 	$attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
                   4324:     }
                   4325:     return $attr_string;
                   4326: }
                   4327: 
                   4328: 
1.182     matthew  4329: ###############################################
1.251     albertel 4330: ###############################################
                   4331: 
                   4332: =pod
                   4333: 
                   4334: =item * &endbodytag()
                   4335: 
                   4336: Returns a uniform footer for LON-CAPA web pages.
                   4337: 
1.635     raeburn  4338: Inputs: 1 - optional reference to an args hash
                   4339: If in the hash, key for noredirectlink has a value which evaluates to true,
                   4340: a 'Continue' link is not displayed if the page contains an
                   4341: internal redirect in the <head></head> section,
                   4342: i.e., $env{'internal.head.redirect'} exists   
1.251     albertel 4343: 
                   4344: =cut
                   4345: 
                   4346: sub endbodytag {
1.635     raeburn  4347:     my ($args) = @_;
1.251     albertel 4348:     my $endbodytag='</body>';
1.269     albertel 4349:     $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315     albertel 4350:     if ( exists( $env{'internal.head.redirect'} ) ) {
1.635     raeburn  4351:         if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
                   4352: 	    $endbodytag=
                   4353: 	        "<br /><a href=\"$env{'internal.head.redirect'}\">".
                   4354: 	        &mt('Continue').'</a>'.
                   4355: 	        $endbodytag;
                   4356:         }
1.315     albertel 4357:     }
1.251     albertel 4358:     return $endbodytag;
                   4359: }
                   4360: 
1.352     albertel 4361: =pod
                   4362: 
                   4363: =item * &standard_css()
                   4364: 
                   4365: Returns a style sheet
                   4366: 
                   4367: Inputs: (all optional)
                   4368:             domain         -> force to color decorate a page for a specific
                   4369:                                domain
                   4370:             function       -> force usage of a specific rolish color scheme
                   4371:             bgcolor        -> override the default page bgcolor
                   4372: 
                   4373: =cut
                   4374: 
1.343     albertel 4375: sub standard_css {
1.345     albertel 4376:     my ($function,$domain,$bgcolor) = @_;
1.352     albertel 4377:     $function  = &get_users_function() if (!$function);
                   4378:     my $img    = &designparm($function.'.img',   $domain);
                   4379:     my $tabbg  = &designparm($function.'.tabbg', $domain);
                   4380:     my $font   = &designparm($function.'.font',  $domain);
1.345     albertel 4381:     my $sidebg = &designparm($function.'.sidebg',$domain);
1.382     albertel 4382:     my $pgbg_or_bgcolor =
                   4383: 	         $bgcolor ||
1.352     albertel 4384: 	         &designparm($function.'.pgbg',  $domain);
1.382     albertel 4385:     my $pgbg   = &designparm($function.'.pgbg',  $domain);
1.352     albertel 4386:     my $alink  = &designparm($function.'.alink', $domain);
                   4387:     my $vlink  = &designparm($function.'.vlink', $domain);
                   4388:     my $link   = &designparm($function.'.link',  $domain);
                   4389: 
1.602     albertel 4390:     my $sans                 = 'Verdana,Arial,Helvetica,sans-serif';
1.395     albertel 4391:     my $mono                 = 'monospace';
1.352     albertel 4392:     my $data_table_head      = $tabbg;
                   4393:     my $data_table_light     = '#EEEEEE';
1.470     banghart 4394:     my $data_table_dark      = '#DDDDDD';
                   4395:     my $data_table_darker    = '#CCCCCC';
1.349     albertel 4396:     my $data_table_highlight = '#FFFF00';
1.352     albertel 4397:     my $mail_new             = '#FFBB77';
                   4398:     my $mail_new_hover       = '#DD9955';
                   4399:     my $mail_read            = '#BBBB77';
                   4400:     my $mail_read_hover      = '#999944';
                   4401:     my $mail_replied         = '#AAAA88';
                   4402:     my $mail_replied_hover   = '#888855';
                   4403:     my $mail_other           = '#99BBBB';
                   4404:     my $mail_other_hover     = '#669999';
1.391     albertel 4405:     my $table_header         = '#DDDDDD';
1.489     raeburn  4406:     my $feedback_link_bg     = '#BBBBBB';
1.392     albertel 4407: 
1.608     albertel 4408:     my $border = ($env{'browser.type'} eq 'explorer' ||
                   4409: 		  $env{'browser.type'} eq 'safari'     ) ? '0px 2px 0px 2px'
                   4410: 	                                                 : '0px 3px 0px 4px';
1.448     albertel 4411: 
1.523     albertel 4412: 
1.343     albertel 4413:     return <<END;
1.345     albertel 4414: h1, h2, h3, th { font-family: $sans }
1.343     albertel 4415: a:focus { color: red; background: yellow } 
1.510     albertel 4416: table.thinborder,
1.523     albertel 4417: 
1.510     albertel 4418: table.thinborder tr th {
                   4419:   border-style: solid;
                   4420:   border-width: 1px;
                   4421:   background: $tabbg;
                   4422: }
1.523     albertel 4423: table.thinborder tr td {
1.510     albertel 4424:   border-style: solid;
                   4425:   border-width: 1px
                   4426: }
1.426     albertel 4427: 
1.343     albertel 4428: form, .inline { display: inline; }
                   4429: .center { text-align: center; }
1.593     albertel 4430: .LC_filename {font-family: $mono; white-space:pre;}
1.350     albertel 4431: .LC_error {
                   4432:   color: red;
                   4433:   font-size: larger;
                   4434: }
1.457     albertel 4435: .LC_warning,
                   4436: .LC_diff_removed {
1.394     albertel 4437:   color: red;
                   4438: }
1.532     albertel 4439: 
                   4440: .LC_info,
1.457     albertel 4441: .LC_success,
                   4442: .LC_diff_added {
1.350     albertel 4443:   color: green;
                   4444: }
1.543     albertel 4445: .LC_unknown {
                   4446:   color: yellow;
                   4447: }
                   4448: 
1.440     albertel 4449: .LC_icon {
                   4450:   border: 0px;
                   4451: }
1.539     albertel 4452: .LC_indexer_icon {
                   4453:   border: 0px;
                   4454:   height: 22px;
                   4455: }
1.543     albertel 4456: .LC_docs_spacer {
                   4457:   width: 25px;
                   4458:   height: 1px;
                   4459:   border: 0px;
                   4460: }
1.346     albertel 4461: 
1.532     albertel 4462: .LC_internal_info {
                   4463:   color: #999;
                   4464: }
                   4465: 
1.458     albertel 4466: table.LC_pastsubmission {
                   4467:   border: 1px solid black;
                   4468:   margin: 2px;
                   4469: }
                   4470: 
1.606     albertel 4471: table#LC_top_nav, table#LC_menubuttons,table#LC_nav_location {
1.345     albertel 4472:   width: 100%;
                   4473:   background: $pgbg;
1.392     albertel 4474:   border: 2px;
1.402     albertel 4475:   border-collapse: separate;
1.403     albertel 4476:   padding: 0px;
1.345     albertel 4477: }
1.392     albertel 4478: 
1.606     albertel 4479: table#LC_title_bar, table.LC_breadcrumbs, 
1.393     albertel 4480: table#LC_title_bar.LC_with_remote {
1.359     albertel 4481:   width: 100%;
1.392     albertel 4482:   border-color: $pgbg;
                   4483:   border-style: solid;
                   4484:   border-width: $border;
                   4485: 
1.379     albertel 4486:   background: $pgbg;
                   4487:   font-family: $sans;
1.392     albertel 4488:   border-collapse: collapse;
1.403     albertel 4489:   padding: 0px;
1.359     albertel 4490: }
1.392     albertel 4491: 
1.409     albertel 4492: table.LC_docs_path {
                   4493:   width: 100%;
                   4494:   border: 0;
                   4495:   background: $pgbg;
                   4496:   font-family: $sans;
                   4497:   border-collapse: collapse;
                   4498:   padding: 0px;
                   4499: }
                   4500: 
1.359     albertel 4501: table#LC_title_bar td {
                   4502:   background: $tabbg;
                   4503: }
                   4504: table#LC_title_bar td.LC_title_bar_who {
                   4505:   background: $tabbg;
                   4506:   color: $font;
1.427     albertel 4507:   font: small $sans;
1.359     albertel 4508:   text-align: right;
                   4509: }
1.469     banghart 4510: span.LC_metadata {
                   4511:     font-family: $sans;
                   4512: }
1.359     albertel 4513: span.LC_title_bar_title {
1.416     albertel 4514:   font: bold x-large $sans;
1.359     albertel 4515: }
                   4516: table#LC_title_bar td.LC_title_bar_domain_logo {
                   4517:   background: $sidebg;
                   4518:   text-align: right;
1.368     albertel 4519:   padding: 0px;
                   4520: }
                   4521: table#LC_title_bar td.LC_title_bar_role_logo {
                   4522:   background: $sidebg;
                   4523:   padding: 0px;
1.359     albertel 4524: }
                   4525: 
1.346     albertel 4526: table#LC_menubuttons_mainmenu {
1.526     www      4527:   width: 100%;
1.346     albertel 4528:   border: 0px;
                   4529:   border-spacing: 1px;
1.372     albertel 4530:   padding: 0px 1px;
1.346     albertel 4531:   margin: 0px;
                   4532:   border-collapse: separate;
                   4533: }
                   4534: table#LC_menubuttons img, table#LC_menubuttons_mainmenu img {
                   4535:   border: 0px;
                   4536: }
1.345     albertel 4537: table#LC_top_nav td {
                   4538:   background: $tabbg;
1.392     albertel 4539:   border: 0px;
1.407     albertel 4540:   font-size: small;
1.345     albertel 4541: }
                   4542: table#LC_top_nav td a, div#LC_top_nav a {
                   4543:   color: $font;
                   4544:   font-family: $sans;
                   4545: }
1.364     albertel 4546: table#LC_top_nav td.LC_top_nav_logo {
                   4547:   background: $tabbg;
1.432     albertel 4548:   text-align: left;
1.408     albertel 4549:   white-space: nowrap;
1.432     albertel 4550:   width: 31px;
1.408     albertel 4551: }
                   4552: table#LC_top_nav td.LC_top_nav_logo img {
1.432     albertel 4553:   border: 0px;
1.408     albertel 4554:   vertical-align: bottom;
1.364     albertel 4555: }
1.432     albertel 4556: table#LC_top_nav td.LC_top_nav_exit,
                   4557: table#LC_top_nav td.LC_top_nav_help {
                   4558:   width: 2.0em;
                   4559: }
1.442     albertel 4560: table#LC_top_nav td.LC_top_nav_login {
                   4561:   width: 4.0em;
                   4562:   text-align: center;
                   4563: }
1.409     albertel 4564: table.LC_breadcrumbs td, table.LC_docs_path td  {
1.357     albertel 4565:   background: $tabbg;
                   4566:   color: $font;
                   4567:   font-family: $sans;
1.358     albertel 4568:   font-size: smaller;
1.357     albertel 4569: }
1.411     albertel 4570: table.LC_breadcrumbs td.LC_breadcrumbs_component,
1.409     albertel 4571: table.LC_docs_path td.LC_docs_path_component {
1.357     albertel 4572:   background: $tabbg;
                   4573:   color: $font;
                   4574:   font-family: $sans;
                   4575:   font-size: larger;
                   4576:   text-align: right;
                   4577: }
1.383     albertel 4578: td.LC_table_cell_checkbox {
                   4579:   text-align: center;
                   4580: }
1.522     albertel 4581: table#LC_mainmenu td.LC_mainmenu_column {
                   4582:     vertical-align: top;
                   4583: }
                   4584: 
1.346     albertel 4585: .LC_menubuttons_inline_text {
                   4586:   color: $font;
                   4587:   font-family: $sans;
                   4588:   font-size: smaller;
                   4589: }
                   4590: 
1.526     www      4591: .LC_menubuttons_link {
                   4592:   text-decoration: none;
                   4593: }
1.680     riegler  4594: #2008--9-5: new menu style sheet.Changed category
1.522     albertel 4595: .LC_menubuttons_category {
1.521     www      4596:   color: $font;
1.526     www      4597:   background: $pgbg;
1.521     www      4598:   font-family: $sans;
                   4599:   font-size: larger;
                   4600:   font-weight: bold;
                   4601: }
                   4602: 
1.346     albertel 4603: td.LC_menubuttons_text {
1.526     www      4604:   width: 90%;
1.346     albertel 4605:   color: $font;
                   4606:   font-family: $sans;
                   4607: }
1.526     www      4608: 
1.346     albertel 4609: td.LC_menubuttons_img {
                   4610: }
1.526     www      4611: 
1.346     albertel 4612: .LC_current_location {
                   4613:   font-family: $sans;
                   4614:   background: $tabbg;
                   4615: }
                   4616: .LC_new_mail {
                   4617:   font-family: $sans;
1.634     www      4618:   background: $tabbg;
1.346     albertel 4619:   font-weight: bold;
                   4620: }
1.347     albertel 4621: 
1.526     www      4622: .LC_rolesmenu_is {
                   4623:   font-family: $sans;
                   4624: }
                   4625: 
                   4626: .LC_rolesmenu_selected {
                   4627:   font-family: $sans;
                   4628: }
                   4629: 
                   4630: .LC_rolesmenu_future {
                   4631:   font-family: $sans;
                   4632: }
                   4633: 
                   4634: 
                   4635: .LC_rolesmenu_will {
                   4636:   font-family: $sans;
                   4637: }
                   4638: 
                   4639: .LC_rolesmenu_will_not {
                   4640:   font-family: $sans;
                   4641: }
                   4642: 
                   4643: .LC_rolesmenu_expired {
                   4644:   font-family: $sans;
                   4645: }
                   4646: 
                   4647: .LC_rolesinfo {
                   4648:   font-family: $sans;
                   4649: }
                   4650: 
1.527     www      4651: .LC_dropadd_labeltext {
                   4652:   font-family: $sans;
                   4653:   text-align: right;
                   4654: }
                   4655: 
                   4656: .LC_preferences_labeltext {
                   4657:   font-family: $sans;
                   4658:   text-align: right;
                   4659: }
                   4660: 
1.666     raeburn  4661: .LC_roleslog_note {
                   4662:   font-size: smaller;
                   4663: }
                   4664: 
1.440     albertel 4665: table.LC_aboutme_port {
                   4666:   border: 0px;
                   4667:   border-collapse: collapse;
                   4668:   border-spacing: 0px;
                   4669: }
1.349     albertel 4670: table.LC_data_table, table.LC_mail_list {
1.347     albertel 4671:   border: 1px solid #000000;
1.402     albertel 4672:   border-collapse: separate;
1.426     albertel 4673:   border-spacing: 1px;
1.610     albertel 4674:   background: $pgbg;
1.347     albertel 4675: }
1.422     albertel 4676: .LC_data_table_dense {
                   4677:   font-size: small;
                   4678: }
1.507     raeburn  4679: table.LC_nested_outer {
                   4680:   border: 1px solid #000000;
1.589     raeburn  4681:   border-collapse: collapse;
1.507     raeburn  4682:   border-spacing: 0px;
                   4683:   width: 100%;
                   4684: }
                   4685: table.LC_nested {
                   4686:   border: 0px;
1.589     raeburn  4687:   border-collapse: collapse;
1.507     raeburn  4688:   border-spacing: 0px;
                   4689:   width: 100%;
                   4690: }
1.523     albertel 4691: table.LC_data_table tr th, table.LC_calendar tr th, table.LC_mail_list tr th,
                   4692: table.LC_prior_tries tr th {
1.349     albertel 4693:   font-weight: bold;
                   4694:   background-color: $data_table_head;
1.421     albertel 4695:   font-size: smaller;
1.347     albertel 4696: }
1.610     albertel 4697: table.LC_data_table tr.LC_odd_row > td, 
1.440     albertel 4698: table.LC_aboutme_port tr td {
1.349     albertel 4699:   background-color: $data_table_light;
1.425     albertel 4700:   padding: 2px;
1.347     albertel 4701: }
1.610     albertel 4702: table.LC_data_table tr.LC_even_row > td,
1.440     albertel 4703: table.LC_aboutme_port tr.LC_even_row td {
1.349     albertel 4704:   background-color: $data_table_dark;
1.347     albertel 4705: }
1.425     albertel 4706: table.LC_data_table tr.LC_data_table_highlight td {
                   4707:   background-color: $data_table_darker;
                   4708: }
1.639     raeburn  4709: table.LC_data_table tr td.LC_leftcol_header {
                   4710:   background-color: $data_table_head;
                   4711:   font-weight: bold;
                   4712: }
1.451     albertel 4713: table.LC_data_table tr.LC_empty_row td,
1.507     raeburn  4714: table.LC_nested tr.LC_empty_row td {
1.347     albertel 4715:   background-color: #FFFFFF;
1.421     albertel 4716:   font-weight: bold;
                   4717:   font-style: italic;
                   4718:   text-align: center;
                   4719:   padding: 8px;
1.347     albertel 4720: }
1.507     raeburn  4721: table.LC_nested tr.LC_empty_row td {
1.465     albertel 4722:   padding: 4ex
                   4723: }
1.507     raeburn  4724: table.LC_nested_outer tr th {
                   4725:   font-weight: bold;
                   4726:   background-color: $data_table_head;
                   4727:   font-size: smaller;
                   4728:   border-bottom: 1px solid #000000;
                   4729: }
                   4730: table.LC_nested_outer tr td.LC_subheader {
                   4731:   background-color: $data_table_head;
                   4732:   font-weight: bold;
                   4733:   font-size: small;
                   4734:   border-bottom: 1px solid #000000;
                   4735:   text-align: right;
1.451     albertel 4736: }
1.507     raeburn  4737: table.LC_nested tr.LC_info_row td {
1.451     albertel 4738:   background-color: #CCC;
                   4739:   font-weight: bold;
                   4740:   font-size: small;
1.507     raeburn  4741:   text-align: center;
                   4742: }
1.589     raeburn  4743: table.LC_nested tr.LC_info_row td.LC_left_item,
                   4744: table.LC_nested_outer tr th.LC_left_item {
1.507     raeburn  4745:   text-align: left;
1.451     albertel 4746: }
1.507     raeburn  4747: table.LC_nested td {
1.451     albertel 4748:   background-color: #FFF;
                   4749:   font-size: small;
1.507     raeburn  4750: }
                   4751: table.LC_nested_outer tr th.LC_right_item,
                   4752: table.LC_nested tr.LC_info_row td.LC_right_item,
                   4753: table.LC_nested tr.LC_odd_row td.LC_right_item,
                   4754: table.LC_nested tr td.LC_right_item {
1.451     albertel 4755:   text-align: right;
                   4756: }
                   4757: 
1.507     raeburn  4758: table.LC_nested tr.LC_odd_row td {
1.451     albertel 4759:   background-color: #EEE;
                   4760: }
                   4761: 
1.473     raeburn  4762: table.LC_createuser {
                   4763: }
                   4764: 
                   4765: table.LC_createuser tr.LC_section_row td {
                   4766:   font-size: smaller;
                   4767: }
                   4768: 
                   4769: table.LC_createuser tr.LC_info_row td  {
                   4770:   background-color: #CCC;
                   4771:   font-weight: bold;
                   4772:   text-align: center;
                   4773: }
                   4774: 
1.349     albertel 4775: table.LC_calendar {
                   4776:   border: 1px solid #000000;
                   4777:   border-collapse: collapse;
                   4778: }
                   4779: table.LC_calendar_pickdate {
                   4780:   font-size: xx-small;
                   4781: }
                   4782: table.LC_calendar tr td {
                   4783:   border: 1px solid #000000;
                   4784:   vertical-align: top;
                   4785: }
                   4786: table.LC_calendar tr td.LC_calendar_day_empty {
                   4787:   background-color: $data_table_dark;
                   4788: }
                   4789: table.LC_calendar tr td.LC_calendar_day_current {
                   4790:   background-color: $data_table_highlight;
                   4791: }
                   4792: 
                   4793: table.LC_mail_list tr.LC_mail_new {
                   4794:   background-color: $mail_new;
                   4795: }
                   4796: table.LC_mail_list tr.LC_mail_new:hover {
                   4797:   background-color: $mail_new_hover;
                   4798: }
                   4799: table.LC_mail_list tr.LC_mail_read {
                   4800:   background-color: $mail_read;
                   4801: }
                   4802: table.LC_mail_list tr.LC_mail_read:hover {
                   4803:   background-color: $mail_read_hover;
                   4804: }
                   4805: table.LC_mail_list tr.LC_mail_replied {
                   4806:   background-color: $mail_replied;
                   4807: }
                   4808: table.LC_mail_list tr.LC_mail_replied:hover {
                   4809:   background-color: $mail_replied_hover;
                   4810: }
                   4811: table.LC_mail_list tr.LC_mail_other {
                   4812:   background-color: $mail_other;
                   4813: }
                   4814: table.LC_mail_list tr.LC_mail_other:hover {
                   4815:   background-color: $mail_other_hover;
                   4816: }
1.494     raeburn  4817: table.LC_mail_list tr.LC_mail_even {
                   4818: }
                   4819: table.LC_mail_list tr.LC_mail_odd {
                   4820: }
                   4821: 
1.385     albertel 4822: 
1.386     albertel 4823: table#LC_portfolio_actions {
                   4824:   width: auto;
                   4825:   background: $pgbg;
                   4826:   border: 0px;
                   4827:   border-spacing: 2px 2px;
                   4828:   padding: 0px;
                   4829:   margin: 0px;
                   4830:   border-collapse: separate;
                   4831: }
                   4832: table#LC_portfolio_actions td.LC_label {
                   4833:   background: $tabbg;
                   4834:   text-align: right;
                   4835: }
                   4836: table#LC_portfolio_actions td.LC_value {
                   4837:   background: $tabbg;
                   4838: }
1.385     albertel 4839: 
1.391     albertel 4840: table#LC_cstr_controls {
                   4841:   width: 100%;
                   4842:   border-collapse: collapse;
                   4843: }
                   4844: table#LC_cstr_controls tr td {
                   4845:   border: 4px solid $pgbg;
                   4846:   padding: 4px;
                   4847:   text-align: center;
                   4848:   background: $tabbg;
                   4849: }
                   4850: table#LC_cstr_controls tr th {
                   4851:   border: 4px solid $pgbg;
                   4852:   background: $table_header;
                   4853:   text-align: center;
                   4854:   font-family: $sans;
                   4855:   font-size: smaller;
                   4856: }
                   4857: 
1.389     albertel 4858: table#LC_browser {
                   4859:  
                   4860: }
                   4861: table#LC_browser tr th {
1.391     albertel 4862:   background: $table_header;
1.389     albertel 4863: }
1.390     albertel 4864: table#LC_browser tr td {
                   4865:   padding: 2px;
                   4866: }
1.389     albertel 4867: table#LC_browser tr.LC_browser_file,
                   4868: table#LC_browser tr.LC_browser_file_published {
                   4869:   background: #CCFF88;
                   4870: }
                   4871: table#LC_browser tr.LC_browser_file_locked,
                   4872: table#LC_browser tr.LC_browser_file_unpublished {
                   4873:   background: #FFAA99;
1.387     albertel 4874: }
1.389     albertel 4875: table#LC_browser tr.LC_browser_file_obsolete {
                   4876:   background: #AAAAAA;
1.387     albertel 4877: }
1.455     albertel 4878: table#LC_browser tr.LC_browser_file_modified,
                   4879: table#LC_browser tr.LC_browser_file_metamodified {
1.389     albertel 4880:   background: #FFFF77;
1.387     albertel 4881: }
1.389     albertel 4882: table#LC_browser tr.LC_browser_folder {
                   4883:   background: #CCCCFF;
1.387     albertel 4884: }
1.388     albertel 4885: span.LC_current_location {
                   4886:   font-size: x-large;
                   4887:   background: $pgbg;
                   4888: }
1.387     albertel 4889: 
1.395     albertel 4890: span.LC_parm_menu_item {
                   4891:   font-size: larger;
                   4892:   font-family: $sans;
                   4893: }
                   4894: span.LC_parm_scope_all {
                   4895:   color: red;
                   4896: }
                   4897: span.LC_parm_scope_folder {
                   4898:   color: green;
                   4899: }
                   4900: span.LC_parm_scope_resource {
                   4901:   color: orange;
                   4902: }
                   4903: span.LC_parm_part {
                   4904:   color: blue;
                   4905: }
                   4906: span.LC_parm_folder, span.LC_parm_symb {
                   4907:   font-size: x-small;
                   4908:   font-family: $mono;
                   4909:   color: #AAAAAA;
                   4910: }
                   4911: 
1.396     albertel 4912: td.LC_parm_overview_level_menu, td.LC_parm_overview_map_menu,
                   4913: td.LC_parm_overview_parm_selectors, td.LC_parm_overview_parm_restrictions {
                   4914:   border: 1px solid black;
                   4915:   border-collapse: collapse;
                   4916: }
                   4917: table.LC_parm_overview_restrictions td {
                   4918:   border-width: 1px 4px 1px 4px;
                   4919:   border-style: solid;
                   4920:   border-color: $pgbg;
                   4921:   text-align: center;
                   4922: }
                   4923: table.LC_parm_overview_restrictions th {
                   4924:   background: $tabbg;
                   4925:   border-width: 1px 4px 1px 4px;
                   4926:   border-style: solid;
                   4927:   border-color: $pgbg;
                   4928: }
1.398     albertel 4929: table#LC_helpmenu {
                   4930:   border: 0px;
                   4931:   height: 55px;
                   4932:   border-spacing: 0px;
                   4933: }
                   4934: 
                   4935: table#LC_helpmenu fieldset legend {
                   4936:   font-size: larger;
                   4937:   font-weight: bold;
                   4938: }
1.397     albertel 4939: table#LC_helpmenu_links {
                   4940:   width: 100%;
                   4941:   border: 1px solid black;
                   4942:   background: $pgbg;
                   4943:   padding: 0px;
                   4944:   border-spacing: 1px;
                   4945: }
                   4946: table#LC_helpmenu_links tr td {
                   4947:   padding: 1px;
                   4948:   background: $tabbg;
1.399     albertel 4949:   text-align: center;
                   4950:   font-weight: bold;
1.397     albertel 4951: }
1.396     albertel 4952: 
1.397     albertel 4953: table#LC_helpmenu_links a:link, table#LC_helpmenu_links a:visited,
                   4954: table#LC_helpmenu_links a:active {
                   4955:   text-decoration: none;
                   4956:   color: $font;
                   4957: }
                   4958: table#LC_helpmenu_links a:hover {
                   4959:   text-decoration: underline;
                   4960:   color: $vlink;
                   4961: }
1.396     albertel 4962: 
1.417     albertel 4963: .LC_chrt_popup_exists {
                   4964:   border: 1px solid #339933;
                   4965:   margin: -1px;
                   4966: }
                   4967: .LC_chrt_popup_up {
                   4968:   border: 1px solid yellow;
                   4969:   margin: -1px;
                   4970: }
                   4971: .LC_chrt_popup {
                   4972:   border: 1px solid #8888FF;
                   4973:   background: #CCCCFF;
                   4974: }
1.421     albertel 4975: table.LC_pick_box {
                   4976:   border-collapse: separate;
                   4977:   background: white;
                   4978:   border: 1px solid black;
                   4979:   border-spacing: 1px;
                   4980: }
                   4981: table.LC_pick_box td.LC_pick_box_title {
                   4982:   background: $tabbg;
                   4983:   font-weight: bold;
                   4984:   text-align: right;
                   4985:   width: 184px;
                   4986:   padding: 8px;
                   4987: }
1.645     raeburn  4988: table.LC_pick_box td.LC_selfenroll_pick_box_title {
                   4989:   background: $tabbg;
                   4990:   font-weight: bold;
                   4991:   text-align: right;
                   4992:   width: 350px;
                   4993:   padding: 8px;
                   4994: }
                   4995: 
1.579     raeburn  4996: table.LC_pick_box td.LC_pick_box_value {
                   4997:   text-align: left;
                   4998:   padding: 8px;
                   4999: }
                   5000: table.LC_pick_box td.LC_pick_box_select {
                   5001:   text-align: left;
                   5002:   padding: 8px;
                   5003: }
1.424     albertel 5004: table.LC_pick_box td.LC_pick_box_separator {
1.421     albertel 5005:   padding: 0px;
                   5006:   height: 1px;
                   5007:   background: black;
                   5008: }
                   5009: table.LC_pick_box td.LC_pick_box_submit {
                   5010:   text-align: right;
                   5011: }
1.579     raeburn  5012: table.LC_pick_box td.LC_evenrow_value {
                   5013:   text-align: left;
                   5014:   padding: 8px;
                   5015:   background-color: $data_table_light;
                   5016: }
                   5017: table.LC_pick_box td.LC_oddrow_value {
                   5018:   text-align: left;
                   5019:   padding: 8px;
                   5020:   background-color: $data_table_light;
                   5021: }
                   5022: table.LC_helpform_receipt {
                   5023:   width: 620px;
                   5024:   border-collapse: separate;
                   5025:   background: white;
                   5026:   border: 1px solid black;
                   5027:   border-spacing: 1px;
                   5028: }
                   5029: table.LC_helpform_receipt td.LC_pick_box_title {
                   5030:   background: $tabbg;
                   5031:   font-weight: bold;
                   5032:   text-align: right;
                   5033:   width: 184px;
                   5034:   padding: 8px;
                   5035: }
                   5036: table.LC_helpform_receipt td.LC_evenrow_value {
                   5037:   text-align: left;
                   5038:   padding: 8px;
                   5039:   background-color: $data_table_light;
                   5040: }
                   5041: table.LC_helpform_receipt td.LC_oddrow_value {
                   5042:   text-align: left;
                   5043:   padding: 8px;
                   5044:   background-color: $data_table_light;
                   5045: }
                   5046: table.LC_helpform_receipt td.LC_pick_box_separator {
                   5047:   padding: 0px;
                   5048:   height: 1px;
                   5049:   background: black;
                   5050: }
                   5051: span.LC_helpform_receipt_cat {
                   5052:   font-weight: bold;
                   5053: }
1.424     albertel 5054: table.LC_group_priv_box {
                   5055:   background: white;
                   5056:   border: 1px solid black;
                   5057:   border-spacing: 1px;
                   5058: }
                   5059: table.LC_group_priv_box td.LC_pick_box_title {
                   5060:   background: $tabbg;
                   5061:   font-weight: bold;
                   5062:   text-align: right;
                   5063:   width: 184px;
                   5064: }
                   5065: table.LC_group_priv_box td.LC_groups_fixed {
                   5066:   background: $data_table_light;
                   5067:   text-align: center;
                   5068: }
                   5069: table.LC_group_priv_box td.LC_groups_optional {
                   5070:   background: $data_table_dark;
                   5071:   text-align: center;
                   5072: }
                   5073: table.LC_group_priv_box td.LC_groups_functionality {
                   5074:   background: $data_table_darker;
                   5075:   text-align: center;
                   5076:   font-weight: bold;
                   5077: }
                   5078: table.LC_group_priv td {
                   5079:   text-align: left;
                   5080:   padding: 0px;
                   5081: }
                   5082: 
1.421     albertel 5083: table.LC_notify_front_page {
                   5084:   background: white;
                   5085:   border: 1px solid black;
                   5086:   padding: 8px;
                   5087: }
                   5088: table.LC_notify_front_page td {
                   5089:   padding: 8px;
                   5090: }
1.424     albertel 5091: .LC_navbuttons {
                   5092:   margin: 2ex 0ex 2ex 0ex;
                   5093: }
1.423     albertel 5094: .LC_topic_bar {
                   5095:   font-family: $sans;
                   5096:   font-weight: bold;
                   5097:   width: 100%;
                   5098:   background: $tabbg;
                   5099:   vertical-align: middle;
                   5100:   margin: 2ex 0ex 2ex 0ex;
                   5101: }
                   5102: .LC_topic_bar span {
                   5103:   vertical-align: middle;
                   5104: }
                   5105: .LC_topic_bar img {
                   5106:   vertical-align: bottom;
                   5107: }
                   5108: table.LC_course_group_status {
                   5109:   margin: 20px;
                   5110: }
                   5111: table.LC_status_selector td {
                   5112:   vertical-align: top;
                   5113:   text-align: center;
1.424     albertel 5114:   padding: 4px;
                   5115: }
                   5116: table.LC_descriptive_input td.LC_description {
                   5117:   vertical-align: top;
                   5118:   text-align: right;
                   5119:   font-weight: bold;
1.423     albertel 5120: }
1.599     albertel 5121: div.LC_feedback_link {
1.616     albertel 5122:   clear: both;
1.599     albertel 5123:   background: white;
                   5124:   width: 100%;  
1.489     raeburn  5125: }
                   5126: span.LC_feedback_link {
1.599     albertel 5127:   background: $feedback_link_bg;
                   5128:   font-size: larger;
                   5129: }
                   5130: span.LC_message_link {
                   5131:   background: $feedback_link_bg;
                   5132:   font-size: larger;
                   5133:   position: absolute;
                   5134:   right: 1em;
1.489     raeburn  5135: }
1.421     albertel 5136: 
1.515     albertel 5137: table.LC_prior_tries {
1.524     albertel 5138:   border: 1px solid #000000;
                   5139:   border-collapse: separate;
                   5140:   border-spacing: 1px;
1.515     albertel 5141: }
1.523     albertel 5142: 
1.515     albertel 5143: table.LC_prior_tries td {
1.524     albertel 5144:   padding: 2px;
1.515     albertel 5145: }
1.523     albertel 5146: 
                   5147: .LC_answer_correct {
                   5148:   background: #AAFFAA;
                   5149:   color: black;
                   5150: }
                   5151: .LC_answer_charged_try {
                   5152:   background: #FFAAAA ! important;
                   5153:   color: black;
                   5154: }
                   5155: .LC_answer_not_charged_try, 
                   5156: .LC_answer_no_grade,
                   5157: .LC_answer_late {
                   5158:   background: #FFFFAA;
                   5159:   color: black;
                   5160: }
                   5161: .LC_answer_previous {
                   5162:   background: #AAAAFF;
                   5163:   color: black;
                   5164: }
                   5165: .LC_answer_no_message {
                   5166:   background: #FFFFFF;
                   5167:   color: black;
                   5168: }
                   5169: .LC_answer_unknown {
                   5170:   background: orange;
                   5171:   color: black;
                   5172: }
                   5173: 
                   5174: 
1.529     albertel 5175: span.LC_prior_numerical,
                   5176: span.LC_prior_string,
                   5177: span.LC_prior_custom,
                   5178: span.LC_prior_reaction,
                   5179: span.LC_prior_math {
1.523     albertel 5180:   font-family: monospace;
                   5181:   white-space: pre;
                   5182: }
                   5183: 
1.525     albertel 5184: span.LC_prior_string {
                   5185:   font-family: monospace;
                   5186:   white-space: pre;
                   5187: }
                   5188: 
1.523     albertel 5189: table.LC_prior_option {
                   5190:   width: 100%;
                   5191:   border-collapse: collapse;
                   5192: }
1.528     albertel 5193: table.LC_prior_rank, table.LC_prior_match {
                   5194:   border-collapse: collapse;
                   5195: }
                   5196: table.LC_prior_option tr td,
                   5197: table.LC_prior_rank tr td,
                   5198: table.LC_prior_match tr td {
1.524     albertel 5199:   border: 1px solid #000000;
1.515     albertel 5200: }
                   5201: 
1.519     raeburn  5202: span.LC_nobreak {
1.544     albertel 5203:   white-space: nowrap;
1.519     raeburn  5204: }
                   5205: 
1.576     raeburn  5206: span.LC_cusr_emph {
                   5207:   font-style: italic;
                   5208: }
                   5209: 
1.633     raeburn  5210: span.LC_cusr_subheading {
                   5211:   font-weight: normal;
                   5212:   font-size: 85%;
                   5213: }
                   5214: 
1.545     albertel 5215: table.LC_docs_documents {
                   5216:   background: #BBBBBB;
1.547     albertel 5217:   border-width: 0px;
1.545     albertel 5218:   border-collapse: collapse;
                   5219: }
                   5220: 
                   5221: table.LC_docs_documents td.LC_docs_document {
                   5222:   border: 2px solid black;
                   5223:   padding: 4px;
                   5224: }
                   5225: 
                   5226: .LC_docs_course_commands div {
                   5227:   float: left;
                   5228:   border: 4px solid #AAAAAA;
                   5229:   padding: 4px;
                   5230:   background: #DDDDCC;
                   5231: }
                   5232: 
                   5233: .LC_docs_entry_move {
                   5234:   border: 0px;
                   5235:   border-collapse: collapse;
1.544     albertel 5236: }
                   5237: 
1.545     albertel 5238: .LC_docs_entry_move td {
                   5239:   border: 2px solid #BBBBBB;
                   5240:   background: #DDDDDD;
                   5241: }
                   5242: 
                   5243: .LC_docs_editor td.LC_docs_entry_commands {
                   5244:   background: #DDDDDD;
                   5245:   font-size: x-small;
                   5246: }
1.544     albertel 5247: .LC_docs_copy {
1.545     albertel 5248:   color: #000099;
1.544     albertel 5249: }
                   5250: .LC_docs_cut {
1.545     albertel 5251:   color: #550044;
1.544     albertel 5252: }
                   5253: .LC_docs_rename {
1.545     albertel 5254:   color: #009900;
1.544     albertel 5255: }
                   5256: .LC_docs_remove {
1.545     albertel 5257:   color: #990000;
                   5258: }
                   5259: 
1.547     albertel 5260: .LC_docs_reinit_warn,
                   5261: .LC_docs_ext_edit {
                   5262:   font-size: x-small;
                   5263: }
                   5264: 
1.545     albertel 5265: .LC_docs_editor td.LC_docs_entry_title,
                   5266: .LC_docs_editor td.LC_docs_entry_icon {
                   5267:   background: #FFFFBB;
                   5268: }
                   5269: .LC_docs_editor td.LC_docs_entry_parameter {
                   5270:   background: #BBBBFF;
                   5271:   font-size: x-small;
                   5272:   white-space: nowrap;
                   5273: }
                   5274: 
                   5275: table.LC_docs_adddocs td,
                   5276: table.LC_docs_adddocs th {
                   5277:   border: 1px solid #BBBBBB;
                   5278:   padding: 4px;
                   5279:   background: #DDDDDD;
1.543     albertel 5280: }
                   5281: 
1.584     albertel 5282: table.LC_sty_begin {
                   5283:   background: #BBFFBB;
                   5284: }
                   5285: table.LC_sty_end {
                   5286:   background: #FFBBBB;
                   5287: }
                   5288: 
1.589     raeburn  5289: table.LC_double_column {
                   5290:   border-width: 0px;
                   5291:   border-collapse: collapse;
                   5292:   width: 100%;
                   5293:   padding: 2px;
                   5294: }
                   5295: 
                   5296: table.LC_double_column tr td.LC_left_col {
1.590     raeburn  5297:   top: 2px;
1.589     raeburn  5298:   left: 2px;
                   5299:   width: 47%;
                   5300:   vertical-align: top;
                   5301: }
                   5302: 
                   5303: table.LC_double_column tr td.LC_right_col {
                   5304:   top: 2px;
                   5305:   right: 2px; 
                   5306:   width: 47%;
                   5307:   vertical-align: top;
                   5308: }
                   5309: 
1.594     raeburn  5310: span.LC_role_level {
                   5311:   font-weight: bold;
                   5312: }
                   5313: 
1.591     raeburn  5314: div.LC_left_float {
                   5315:   float: left;
                   5316:   padding-right: 5%;
1.597     albertel 5317:   padding-bottom: 4px;
1.591     raeburn  5318: }
                   5319: 
                   5320: div.LC_clear_float_header {
1.597     albertel 5321:   padding-bottom: 2px;
1.591     raeburn  5322: }
                   5323: 
                   5324: div.LC_clear_float_footer {
1.597     albertel 5325:   padding-top: 10px;
1.591     raeburn  5326:   clear: both;
                   5327: }
                   5328: 
1.597     albertel 5329: 
1.601     albertel 5330: div.LC_grade_select_mode {
1.604     albertel 5331:   font-family: $sans;
1.601     albertel 5332: }
                   5333: div.LC_grade_select_mode div div {
                   5334:   margin: 5px;
                   5335: }
                   5336: div.LC_grade_select_mode_selector {
                   5337:   margin: 5px;
                   5338:   float: left;
                   5339: }
                   5340: div.LC_grade_select_mode_selector_header {
                   5341:   font: bold medium $sans;
                   5342: }
                   5343: div.LC_grade_select_mode_type {
                   5344:   clear: left;
                   5345: }
                   5346: 
1.597     albertel 5347: div.LC_grade_show_user {
                   5348:   margin-top: 20px;
                   5349:   border: 1px solid black;
                   5350: }
                   5351: div.LC_grade_user_name {
                   5352:   background: #DDDDEE;
                   5353:   border-bottom: 1px solid black;
                   5354:   font: bold large $sans;
                   5355: }
                   5356: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
                   5357:   background: #DDEEDD;
                   5358: }
                   5359: 
                   5360: div.LC_grade_show_problem,
                   5361: div.LC_grade_submissions,
                   5362: div.LC_grade_message_center,
                   5363: div.LC_grade_info_links,
                   5364: div.LC_grade_assign {
                   5365:   margin: 5px;
                   5366:   width: 99%;
                   5367:   background: #FFFFFF;
                   5368: }
                   5369: div.LC_grade_show_problem_header,
                   5370: div.LC_grade_submissions_header,
                   5371: div.LC_grade_message_center_header,
                   5372: div.LC_grade_assign_header {
                   5373:   font: bold large $sans;
                   5374: }
                   5375: div.LC_grade_show_problem_problem,
                   5376: div.LC_grade_submissions_body,
                   5377: div.LC_grade_message_center_body,
                   5378: div.LC_grade_assign_body {
                   5379:   border: 1px solid black;
                   5380:   width: 99%;
                   5381:   background: #FFFFFF;
                   5382: }
1.598     albertel 5383: span.LC_grade_check_note {
                   5384:   font: normal medium $sans;
                   5385:   display: inline;
                   5386:   position: absolute;
                   5387:   right: 1em;
                   5388: }
1.597     albertel 5389: 
1.613     albertel 5390: table.LC_scantron_action {
                   5391:   width: 100%;
                   5392: }
                   5393: table.LC_scantron_action tr th {
                   5394:   font: normal bold $sans;
                   5395: }
1.600     albertel 5396: 
1.614     albertel 5397: div.LC_edit_problem_header, 
                   5398: div.LC_edit_problem_footer {
1.600     albertel 5399:   font: normal medium $sans;
1.602     albertel 5400:   margin: 2px;
1.600     albertel 5401: }
                   5402: div.LC_edit_problem_header,
1.602     albertel 5403: div.LC_edit_problem_header div,
1.614     albertel 5404: div.LC_edit_problem_footer,
                   5405: div.LC_edit_problem_footer div,
1.602     albertel 5406: div.LC_edit_problem_editxml_header,
                   5407: div.LC_edit_problem_editxml_header div {
1.600     albertel 5408:   margin-top: 5px;
                   5409: }
1.602     albertel 5410: div.LC_edit_problem_header_edit_row {
                   5411:   background: $tabbg;
                   5412:   padding: 3px;
                   5413:   margin-bottom: 5px;
                   5414: }
1.600     albertel 5415: div.LC_edit_problem_header_title {
1.602     albertel 5416:   font: larger bold $sans;
                   5417:   background: $tabbg;
                   5418:   padding: 3px;
                   5419: }
                   5420: table.LC_edit_problem_header_title {
                   5421:   font: larger bold $sans;
                   5422:   width: 100%;
                   5423:   border-color: $pgbg;
                   5424:   border-style: solid;
                   5425:   border-width: $border;
                   5426: 
1.600     albertel 5427:   background: $tabbg;
1.602     albertel 5428:   border-collapse: collapse;
                   5429:   padding: 0px
                   5430: }
                   5431: 
                   5432: div.LC_edit_problem_discards {
                   5433:   float: left;
                   5434:   padding-bottom: 5px;
                   5435: }
                   5436: div.LC_edit_problem_saves {
                   5437:   float: right;
                   5438:   padding-bottom: 5px;
1.600     albertel 5439: }
                   5440: hr.LC_edit_problem_divide {
1.602     albertel 5441:   clear: both;
1.600     albertel 5442:   color: $tabbg;
                   5443:   background-color: $tabbg;
                   5444:   height: 3px;
                   5445:   border: 0px;
                   5446: }
1.679     riegler  5447: img.stift{
1.678     riegler  5448:   border-width:0;
1.679     riegler  5449:   vertical-align:middle;
1.677     riegler  5450: }
1.680     riegler  5451: 
1.681     riegler  5452: table#LC_mainmenu{
                   5453:  margin-top:10px;
                   5454:  width:80%;
                   5455: 
                   5456: }
                   5457: 
1.680     riegler  5458: table#LC_mainmenu td.LC_mainmenu_col_fieldset{
                   5459:   vertical-align: top;
                   5460:   width: 45%;
                   5461: }
                   5462: .LC_mainmenu_fieldset_category {
                   5463:   color: $font;
                   5464:   background: $pgbg;
                   5465:   font-family: $sans;
                   5466:   font-size: small;
                   5467:   font-weight: bold;
                   5468: }
                   5469: fieldset#LC_mainmenu_fieldset {
1.681     riegler  5470:   margin:0px 10px 10px 0px;
1.680     riegler  5471: 
                   5472: }
1.693     droeschl 5473: /* ---- Remove when done ----
                   5474: # The following styles is part of the redesign of LON-CAPA and are
                   5475: # subject to change during this project.
                   5476: # Don't rely on their current functionality as they might be 
                   5477: # changed or removed.
                   5478: # --------------------------*/
                   5479: 
                   5480: 
                   5481: body {
                   5482: 	font-family: Tahoma, Arial,Helvetica,sans-serif;
                   5483: 	font-size: 0.85em;
                   5484: 	line-height: 130%;
                   5485: 	color: RGB(45, 45, 45);
                   5486: }
                   5487: 
                   5488: a:link,a:visited {
                   5489: 	/*color: RGB(0, 118, 127);*/
                   5490: 	/*text-decoration: underline;*/
                   5491: }
                   5492: 
                   5493: a:hover{
                   5494: 	text-decoration:none;
                   5495: }
                   5496: /*a:hover,
                   5497: UL.smallMenu A:hover,
                   5498: UL.MenuBreadcrumbs A:hover,
                   5499: UL#TabMainMenuContent A:hover{
                   5500: 	color: rgb(200, 10, 50);
                   5501: }*/
                   5502: 
                   5503: h1 { 
                   5504: 	padding:5px 10px 5px 20px;
                   5505: 	line-height:130%;
                   5506: }
                   5507: h2,h4,h6 {
                   5508: 	/*color: RGB(0, 118, 127);*/
                   5509: }
                   5510: h2,h3,h4,h5,h6
                   5511: {
                   5512: margin:5px 0px 5px 0px;
                   5513: line-height:130%;
                   5514: }
                   5515: 
                   5516: .right {
                   5517: 	text-align: right;
                   5518: }
                   5519: 
                   5520: .center {
                   5521: 	text-align: center;
                   5522: }
                   5523: 
                   5524: .left {
                   5525: 	text-align: left;
                   5526: }
                   5527: 
                   5528: 
                   5529: .HeadRight {
                   5530: 	text-align: right;
                   5531: 	float: right;
                   5532: 	margin: 0px;
                   5533: 	padding: 0px;
                   5534: 	 right:0;
                   5535:         position:absolute;
                   5536: }
                   5537: 
                   5538: img {
                   5539: /*	border: 0px; */
                   5540: }
                   5541: 
                   5542: .personalBgColor {
                   5543: 	background: RGB(237, 239, 0) url(images/headHighlight.png) repeat-y left top;
                   5544: }
                   5545: 
                   5546: p {
                   5547: 	padding: 10px;
                   5548: }
                   5549: DL,UL,Div,Fieldset {
                   5550: 	/*margin: 10px;*/
                   5551: 	overflow:hidden;
                   5552: }
                   5553: OL.smallMenu {
                   5554: 	margin: 0px 0px 0px 0px;
                   5555: }
                   5556: 
                   5557: OL.smallMenu li {
                   5558: 	display: inline;
                   5559: 	padding: 5px 5px 0px 10px;
                   5560: 	vertical-align: top;
                   5561: }
                   5562: 
                   5563: OL.smallMenu li img {
                   5564: 	vertical-align: bottom;
                   5565: }
                   5566: 
                   5567: OL.smallMenu A {
                   5568: 	font-size: 90%;
                   5569: 	color: RGB(80, 80, 80);
                   5570: 	text-decoration: none;
                   5571: }
                   5572: 
                   5573: OL#TabMainMenuContent {
                   5574: 	
                   5575: 	margin: 0px 0px 10px 0px;
                   5576: 	padding: 0px;
                   5577: }
                   5578: 
                   5579: OL#TabMainMenuContent LI {
                   5580: 	display: inline;
                   5581: 	vertical-align: bottom;
                   5582: 	border-bottom: solid 1px RGB(175, 175, 175);
                   5583: 	border-right: solid 1px RGB(175, 175, 175);
                   5584: 	padding: 5px 15px 5px 15px;
                   5585: 	margin-right:4px;
                   5586: 	line-height: 140%;
                   5587: 	font-weight: bold;
                   5588: 	overflow:hidden;
                   5589: 	background: RGB(211, 206, 205) URL(images/TabMenuBG.png) repeat-x left top;
                   5590: }
                   5591: 
                   5592: OL#TabMainMenuContent LI A {
                   5593: 	color: RGB(47, 47, 47);
                   5594: 	text-decoration: none;
                   5595: }
                   5596: 
                   5597: OL#TabMainMenuContent DIV.columnSection {
                   5598: 	margin-bottom: 0px;
                   5599: }
                   5600: 
                   5601: OL#MenuBreadcrumbs {
                   5602: 	border-top: solid 1px RGB(255, 255, 255);
                   5603: 	height: 20px;
                   5604: 	line-height: 20px;
                   5605: 	vertical-align: bottom;
                   5606: 	margin: 0px 0px 30px 0px;
                   5607: 	padding-left: 10px;
                   5608: 	list-style-position: inside;
                   5609: 	background: RGB(211, 206, 205) URL(images/TabMenuBG.png) repeat-x left
                   5610: 		top;
                   5611: }
                   5612: 
                   5613: OL#MenuBreadcrumbs li {
                   5614: 	background: url(images/pfeil_white.png) no-repeat left center;
                   5615: 	display: inline;
                   5616: 	padding: 0px 0px 0px 10px;
                   5617: 	vertical-align: bottom;
                   5618: 	overflow:hidden;
                   5619: }
                   5620: 
                   5621: OL#MenuBreadcrumbs LI A {
                   5622: 	text-decoration: none;
                   5623: 	font-size:90%;
                   5624: }
                   5625: 
                   5626: h4.hcell {
                   5627: 	padding: 3px 10px 3px 10px;
                   5628: 	margin: 0px;
                   5629: 	background: RGB(0, 118, 127);
                   5630: 	color: white;
                   5631: 	border: outset 1px;
                   5632: }
                   5633: 
                   5634: DIV.DivContentBoxSpecial
                   5635: {
                   5636: 	border: solid 1px RGB(100, 100, 100);
                   5637: }
                   5638: 
                   5639: FIELDSET
                   5640: {
                   5641: 	/*width:78%;*/
                   5642: }
                   5643: DIV.DivContentBox,
                   5644: DIV.DivContentBoxSpecial {
                   5645: 	width: 80%;
                   5646: 	margin:10px;
                   5647: }
                   5648: 
                   5649: FIELDSET legend,DL DT {
                   5650: 	font-weight: bold;
                   5651: 	font-size: 110%;
                   5652: 	/*padding-left: 0px;*/
                   5653: /*	margin-left: 0px;*/
                   5654: }
                   5655: 
                   5656: DIV.DivImportant {
                   5657: 	background: url(images/important.png) no-repeat center top;
                   5658: 	padding: 100px 10px 10px 10px;
                   5659: 	width: 200px;
                   5660: 	border: double 4px RGB(200, 200, 200);
                   5661: }
                   5662: 
                   5663: 
                   5664: 
                   5665: DL.ListStyleClean DT {
                   5666: 	padding-right: 5px;
                   5667: 	display: table-header-group;
                   5668: }
                   5669: 
                   5670: DL.ListStyleClean DD {
                   5671: 	display: table-row;
                   5672: }
                   5673: 
                   5674: .ListStyleClean,
                   5675: .ListStyleSimple,
                   5676: .ListStyleNormal,
                   5677: .ListStyleNormal_Border,
                   5678: .ListStyleSpecial
                   5679: 	{
                   5680: 	/*display:block;	*/
                   5681: 	width: 400px;
                   5682: 	list-style-position: inside;
                   5683: 	list-style-type: none;
                   5684: 	overflow: hidden;
                   5685: 	padding: 0px;
                   5686: }
                   5687: 
                   5688: .ListStyleClean li,
                   5689: .ListStyleSimple li,
                   5690: .ListStyleSimple DD,
                   5691: .ListStyleNormal li,
                   5692: .ListStyleNormal DD,
                   5693: .ListStyleSpecial li,
                   5694: .ListStyleSpecial DD
                   5695: 	{
                   5696: 	margin: 0px;
                   5697: 	padding: 5px 5px 5px 10px;
                   5698: 	clear: both;
                   5699: 	/*display:block;*/
                   5700: }
                   5701: 
                   5702: .ListStyleClean LI,
                   5703: .ListStyleClean DD {
                   5704: 	padding-top: 0px;
                   5705: 	padding-bottom: 0px;
                   5706: }
                   5707: 
                   5708: .ListStyleSimple DD,
                   5709: .ListStyleSimple LI{
                   5710: 	border-bottom: solid 1px RGB(150, 150, 150);
                   5711: }
                   5712: 
                   5713: .ListStyleSpecial LI,
                   5714: .ListStyleSpecial DD {
                   5715: 	list-style-type: none;
                   5716: 	background-color: RGB(220, 220, 220);
                   5717: 	margin-bottom: 4px;
                   5718: }
                   5719: 
                   5720: table.SimpleTable *{
                   5721: 	padding:10px;
                   5722: 	}
                   5723: 
                   5724: table.SimpleTable td {
                   5725: 	vertical-align:top;
                   5726: 	border:solid 1px RGB(210,210,210);
                   5727: }
                   5728: table.SimpleTable thead{
                   5729: 	 background:rgb(210,210,210);
                   5730: }
                   5731: 
                   5732: DIV.columnSection {
                   5733: 	display: block;
                   5734: 	clear: both;
                   5735: 	overflow: hidden;
                   5736: 	margin:0px;
                   5737: }
                   5738: 
                   5739: DIV.columnSection>* {
                   5740: 	float: left;
                   5741: 	margin: 10px 20px 10px 0px;
                   5742: 	overflow:hidden;	
                   5743: }
                   5744: 
                   5745: DIV.columnSection>FIELDSET,
                   5746: DIV.columnSection>DIV.DivContentBox,
                   5747: DIV.columnSection>DIV.DivContentBoxSpecial
                   5748: 	{
                   5749: 	width: 480px;
                   5750: 	
                   5751: }
                   5752: 
1.694     tempelho 5753: .LC_loginpage_container {
                   5754: 	text-align:left;
                   5755: 	margin : 0 auto;
                   5756: 	width:65%;
                   5757: 	padding: 10px;
                   5758: 	height: auto;
                   5759: 	background-color:#FFFFFF;
                   5760: 	border:1px solid #CCCCCC;
                   5761: }
                   5762: 
                   5763: 
                   5764: .LC_loginpage_loginContainer {
                   5765: 	float:left;
                   5766: 	width:60%;
                   5767: }
                   5768: 
                   5769: .LC_loginpage_loginInfo {
                   5770: 	margin-top:20px;
                   5771: 	margin-left:20px;
                   5772: 	float:left;
                   5773: 	width:30%;
                   5774: 	border:1px solid #CCCCCC;
                   5775: 	padding:10px;
                   5776: }
                   5777: 
                   5778: .LC_loginpage_space {
                   5779: 	clear:both;
                   5780: 	margin-bottom:20px;
                   5781: 	border-bottom: 1px solid #CCCCCC;
                   5782: }
                   5783: 
                   5784: .LC_loginpage_fieldset{
                   5785: 	border: 1px solid #CCCCCC;
                   5786: 	margin: 0 auto;
                   5787: }
                   5788: 
                   5789: .LC_loginpage_legend{
                   5790: 	padding: 2px;
                   5791: 	margin: 0px;
                   5792: 	font-size:14px;
                   5793: 	font-weight:bold;
                   5794: }
                   5795: 
                   5796: 
1.693     droeschl 5797: 
1.343     albertel 5798: END
                   5799: }
                   5800: 
1.306     albertel 5801: =pod
                   5802: 
                   5803: =item * &headtag()
                   5804: 
                   5805: Returns a uniform footer for LON-CAPA web pages.
                   5806: 
1.307     albertel 5807: Inputs: $title - optional title for the head
                   5808:         $head_extra - optional extra HTML to put inside the <head>
1.315     albertel 5809:         $args - optional arguments
1.319     albertel 5810:             force_register - if is true call registerurl so the remote is 
                   5811:                              informed
1.415     albertel 5812:             redirect       -> array ref of
                   5813:                                    1- seconds before redirect occurs
                   5814:                                    2- url to redirect to
                   5815:                                    3- whether the side effect should occur
1.315     albertel 5816:                            (side effect of setting 
                   5817:                                $env{'internal.head.redirect'} to the url 
                   5818:                                redirected too)
1.352     albertel 5819:             domain         -> force to color decorate a page for a specific
                   5820:                                domain
                   5821:             function       -> force usage of a specific rolish color scheme
                   5822:             bgcolor        -> override the default page bgcolor
1.460     albertel 5823:             no_auto_mt_title
                   5824:                            -> prevent &mt()ing the title arg
1.464     albertel 5825: 
1.306     albertel 5826: =cut
                   5827: 
                   5828: sub headtag {
1.313     albertel 5829:     my ($title,$head_extra,$args) = @_;
1.306     albertel 5830:     
1.363     albertel 5831:     my $function = $args->{'function'} || &get_users_function();
                   5832:     my $domain   = $args->{'domain'}   || &determinedomain();
                   5833:     my $bgcolor  = $args->{'bgcolor'}  || &designparm($function.'.pgbg',$domain);
1.418     albertel 5834:     my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458     albertel 5835: 		   $Apache::lonnet::perlvar{'lonVersion'},
1.531     albertel 5836: 		   #time(),
1.418     albertel 5837: 		   $env{'environment.color.timestamp'},
1.363     albertel 5838: 		   $function,$domain,$bgcolor);
                   5839: 
1.369     www      5840:     $url = '/adm/css/'.&escape($url).'.css';
1.363     albertel 5841: 
1.308     albertel 5842:     my $result =
                   5843: 	'<head>'.
1.461     albertel 5844: 	&font_settings();
1.319     albertel 5845: 
1.461     albertel 5846:     if (!$args->{'frameset'}) {
                   5847: 	$result .= &Apache::lonhtmlcommon::htmlareaheaders();
                   5848:     }
1.319     albertel 5849:     if ($args->{'force_register'}) {
                   5850: 	$result .= &Apache::lonmenu::registerurl(1);
                   5851:     }
1.436     albertel 5852:     if (!$args->{'no_nav_bar'} 
                   5853: 	&& !$args->{'only_body'}
                   5854: 	&& !$args->{'frameset'}) {
                   5855: 	$result .= &help_menu_js();
                   5856:     }
1.319     albertel 5857: 
1.314     albertel 5858:     if (ref($args->{'redirect'})) {
1.414     albertel 5859: 	my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315     albertel 5860: 	$url = &Apache::lonenc::check_encrypt($url);
1.414     albertel 5861: 	if (!$inhibit_continue) {
                   5862: 	    $env{'internal.head.redirect'} = $url;
                   5863: 	}
1.313     albertel 5864: 	$result.=<<ADDMETA
                   5865: <meta http-equiv="pragma" content="no-cache" />
1.344     albertel 5866: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313     albertel 5867: ADDMETA
                   5868:     }
1.306     albertel 5869:     if (!defined($title)) {
                   5870: 	$title = 'The LearningOnline Network with CAPA';
                   5871:     }
1.460     albertel 5872:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
                   5873:     $result .= '<title> LON-CAPA '.$title.'</title>'
1.414     albertel 5874: 	.'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
                   5875: 	.$head_extra;
1.306     albertel 5876:     return $result;
                   5877: }
                   5878: 
                   5879: =pod
                   5880: 
1.340     albertel 5881: =item * &font_settings()
                   5882: 
                   5883: Returns neccessary <meta> to set the proper encoding
                   5884: 
                   5885: Inputs: none
                   5886: 
                   5887: =cut
                   5888: 
                   5889: sub font_settings {
                   5890:     my $headerstring='';
1.647     www      5891:     if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340     albertel 5892: 	$headerstring.=
                   5893: 	    '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
                   5894:     }
                   5895:     return $headerstring;
                   5896: }
                   5897: 
1.341     albertel 5898: =pod
                   5899: 
                   5900: =item * &xml_begin()
                   5901: 
                   5902: Returns the needed doctype and <html>
                   5903: 
                   5904: Inputs: none
                   5905: 
                   5906: =cut
                   5907: 
                   5908: sub xml_begin {
                   5909:     my $output='';
                   5910: 
1.592     albertel 5911:     if ($env{'internal.start_page'}==1) {
                   5912: 	&Apache::lonhtmlcommon::init_htmlareafields();
                   5913:     }
1.342     albertel 5914: 
1.341     albertel 5915:     if ($env{'browser.mathml'}) {
                   5916: 	$output='<?xml version="1.0"?>'
                   5917:             #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
                   5918: #            .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
                   5919:             
                   5920: #	    .'<!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">] >'
                   5921: 	    .'<!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">'
                   5922:             .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" ' 
                   5923: 	    .'xmlns="http://www.w3.org/1999/xhtml">';
                   5924:     } else {
                   5925: 	$output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>';
                   5926:     }
                   5927:     return $output;
                   5928: }
1.340     albertel 5929: 
                   5930: =pod
                   5931: 
1.306     albertel 5932: =item * &endheadtag()
                   5933: 
                   5934: Returns a uniform </head> for LON-CAPA web pages.
                   5935: 
                   5936: Inputs: none
                   5937: 
                   5938: =cut
                   5939: 
                   5940: sub endheadtag {
                   5941:     return '</head>';
                   5942: }
                   5943: 
                   5944: =pod
                   5945: 
                   5946: =item * &head()
                   5947: 
                   5948: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
                   5949: 
1.648     raeburn  5950: Inputs:
                   5951: 
                   5952: =over 4
                   5953: 
                   5954: $title - optional title for the page
                   5955: 
                   5956: $head_extra - optional extra HTML to put inside the <head>
                   5957: 
                   5958: =back
1.405     albertel 5959: 
1.306     albertel 5960: =cut
                   5961: 
                   5962: sub head {
1.325     albertel 5963:     my ($title,$head_extra,$args) = @_;
                   5964:     return &headtag($title,$head_extra,$args).&endheadtag();
1.306     albertel 5965: }
                   5966: 
                   5967: =pod
                   5968: 
                   5969: =item * &start_page()
                   5970: 
                   5971: Returns a complete <html> .. <body> section for LON-CAPA web pages.
                   5972: 
1.648     raeburn  5973: Inputs:
                   5974: 
                   5975: =over 4
                   5976: 
                   5977: $title - optional title for the page
                   5978: 
                   5979: $head_extra - optional extra HTML to incude inside the <head>
                   5980: 
                   5981: $args - additional optional args supported are:
                   5982: 
                   5983: =over 8
                   5984: 
                   5985:              only_body      -> is true will set &bodytag() onlybodytag
1.317     albertel 5986:                                     arg on
1.648     raeburn  5987:              no_nav_bar     -> is true will set &bodytag() notopbar arg on
                   5988:              add_entries    -> additional attributes to add to the  <body>
                   5989:              domain         -> force to color decorate a page for a 
1.317     albertel 5990:                                     specific domain
1.648     raeburn  5991:              function       -> force usage of a specific rolish color
1.317     albertel 5992:                                     scheme
1.648     raeburn  5993:              redirect       -> see &headtag()
                   5994:              bgcolor        -> override the default page bg color
                   5995:              js_ready       -> return a string ready for being used in 
1.317     albertel 5996:                                     a javascript writeln
1.648     raeburn  5997:              html_encode    -> return a string ready for being used in 
1.320     albertel 5998:                                     a html attribute
1.648     raeburn  5999:              force_register -> if is true will turn on the &bodytag()
1.317     albertel 6000:                                     $forcereg arg
1.648     raeburn  6001:              body_title     -> alternate text to use instead of $title
1.326     albertel 6002:                                     in the title box that appears, this text
                   6003:                                     is not auto translated like the $title is
1.648     raeburn  6004:              frameset       -> if true will start with a <frameset>
1.330     albertel 6005:                                     rather than <body>
1.648     raeburn  6006:              no_title       -> if true the title bar won't be shown
                   6007:              skip_phases    -> hash ref of 
1.338     albertel 6008:                                     head -> skip the <html><head> generation
                   6009:                                     body -> skip all <body> generation
1.648     raeburn  6010:              no_inline_link -> if true and in remote mode, don't show the 
1.361     albertel 6011:                                     'Switch To Inline Menu' link
1.648     raeburn  6012:              no_auto_mt_title -> prevent &mt()ing the title arg
                   6013:              inherit_jsmath -> when creating popup window in a page,
                   6014:                                     should it have jsmath forced on by the
                   6015:                                     current page
1.361     albertel 6016: 
1.648     raeburn  6017: =back
1.460     albertel 6018: 
1.648     raeburn  6019: =back
1.562     albertel 6020: 
1.306     albertel 6021: =cut
                   6022: 
                   6023: sub start_page {
1.309     albertel 6024:     my ($title,$head_extra,$args) = @_;
1.318     albertel 6025:     #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313     albertel 6026:     my %head_args;
1.352     albertel 6027:     foreach my $arg ('redirect','force_register','domain','function',
1.460     albertel 6028: 		     'bgcolor','frameset','no_nav_bar','only_body',
                   6029: 		     'no_auto_mt_title') {
1.319     albertel 6030: 	if (defined($args->{$arg})) {
1.324     raeburn  6031: 	    $head_args{$arg} = $args->{$arg};
1.319     albertel 6032: 	}
1.313     albertel 6033:     }
1.319     albertel 6034: 
1.315     albertel 6035:     $env{'internal.start_page'}++;
1.338     albertel 6036:     my $result;
                   6037:     if (! exists($args->{'skip_phases'}{'head'}) ) {
                   6038: 	$result.=
1.341     albertel 6039: 	    &xml_begin().
1.338     albertel 6040: 	    &headtag($title,$head_extra,\%head_args).&endheadtag();
                   6041:     }
                   6042:     
                   6043:     if (! exists($args->{'skip_phases'}{'body'}) ) {
                   6044: 	if ($args->{'frameset'}) {
                   6045: 	    my $attr_string = &make_attr_string($args->{'force_register'},
                   6046: 						$args->{'add_entries'});
                   6047: 	    $result .= "\n<frameset $attr_string>\n";
                   6048: 	} else {
                   6049: 	    $result .=
                   6050: 		&bodytag($title, 
                   6051: 			 $args->{'function'},       $args->{'add_entries'},
                   6052: 			 $args->{'only_body'},      $args->{'domain'},
                   6053: 			 $args->{'force_register'}, $args->{'body_title'},
                   6054: 			 $args->{'no_nav_bar'},     $args->{'bgcolor'},
1.460     albertel 6055: 			 $args->{'no_title'},       $args->{'no_inline_link'},
                   6056: 			 $args);
1.338     albertel 6057: 	}
1.330     albertel 6058:     }
1.338     albertel 6059: 
1.315     albertel 6060:     if ($args->{'js_ready'}) {
1.317     albertel 6061: 	$result = &js_ready($result);
1.315     albertel 6062:     }
1.320     albertel 6063:     if ($args->{'html_encode'}) {
                   6064: 	$result = &html_encode($result);
                   6065:     }
1.315     albertel 6066:     return $result;
1.306     albertel 6067: }
                   6068: 
1.330     albertel 6069: 
1.306     albertel 6070: =pod
                   6071: 
                   6072: =item * &head()
                   6073: 
                   6074: Returns a complete </body></html> section for LON-CAPA web pages.
                   6075: 
1.315     albertel 6076: Inputs:         $args - additional optional args supported are:
                   6077:                  js_ready     -> return a string ready for being used in 
                   6078:                                  a javascript writeln
1.320     albertel 6079:                  html_encode  -> return a string ready for being used in 
                   6080:                                  a html attribute
1.330     albertel 6081:                  frameset     -> if true will start with a <frameset>
                   6082:                                  rather than <body>
1.493     albertel 6083:                  dicsussion   -> if true will get discussion from
                   6084:                                   lonxml::xmlend
                   6085:                                  (you can pass the target and parser arguments
                   6086:                                   through optional 'target' and 'parser' args
                   6087:                                   to this routine)
1.306     albertel 6088: 
                   6089: =cut
                   6090: 
                   6091: sub end_page {
1.315     albertel 6092:     my ($args) = @_;
                   6093:     $env{'internal.end_page'}++;
1.330     albertel 6094:     my $result;
1.335     albertel 6095:     if ($args->{'discussion'}) {
                   6096: 	my ($target,$parser);
                   6097: 	if (ref($args->{'discussion'})) {
                   6098: 	    ($target,$parser) =($args->{'discussion'}{'target'},
                   6099: 				$args->{'discussion'}{'parser'});
                   6100: 	}
                   6101: 	$result .= &Apache::lonxml::xmlend($target,$parser);
                   6102:     }
                   6103: 
1.330     albertel 6104:     if ($args->{'frameset'}) {
                   6105: 	$result .= '</frameset>';
                   6106:     } else {
1.635     raeburn  6107: 	$result .= &endbodytag($args);
1.330     albertel 6108:     }
                   6109:     $result .= "\n</html>";
                   6110: 
1.315     albertel 6111:     if ($args->{'js_ready'}) {
1.317     albertel 6112: 	$result = &js_ready($result);
1.315     albertel 6113:     }
1.335     albertel 6114: 
1.320     albertel 6115:     if ($args->{'html_encode'}) {
                   6116: 	$result = &html_encode($result);
                   6117:     }
1.335     albertel 6118: 
1.315     albertel 6119:     return $result;
                   6120: }
                   6121: 
1.320     albertel 6122: sub html_encode {
                   6123:     my ($result) = @_;
                   6124: 
1.322     albertel 6125:     $result = &HTML::Entities::encode($result,'<>&"');
1.320     albertel 6126:     
                   6127:     return $result;
                   6128: }
1.317     albertel 6129: sub js_ready {
                   6130:     my ($result) = @_;
                   6131: 
1.323     albertel 6132:     $result =~ s/[\n\r]/ /xmsg;
                   6133:     $result =~ s/\\/\\\\/xmsg;
                   6134:     $result =~ s/'/\\'/xmsg;
1.372     albertel 6135:     $result =~ s{</}{<\\/}xmsg;
1.317     albertel 6136:     
                   6137:     return $result;
                   6138: }
                   6139: 
1.315     albertel 6140: sub validate_page {
                   6141:     if (  exists($env{'internal.start_page'})
1.316     albertel 6142: 	  &&     $env{'internal.start_page'} > 1) {
                   6143: 	&Apache::lonnet::logthis('start_page called multiple times '.
1.318     albertel 6144: 				 $env{'internal.start_page'}.' '.
1.316     albertel 6145: 				 $ENV{'request.filename'});
1.315     albertel 6146:     }
                   6147:     if (  exists($env{'internal.end_page'})
1.316     albertel 6148: 	  &&     $env{'internal.end_page'} > 1) {
                   6149: 	&Apache::lonnet::logthis('end_page called multiple times '.
1.318     albertel 6150: 				 $env{'internal.end_page'}.' '.
1.316     albertel 6151: 				 $env{'request.filename'});
1.315     albertel 6152:     }
                   6153:     if (     exists($env{'internal.start_page'})
                   6154: 	&& ! exists($env{'internal.end_page'})) {
1.316     albertel 6155: 	&Apache::lonnet::logthis('start_page called without end_page '.
                   6156: 				 $env{'request.filename'});
1.315     albertel 6157:     }
                   6158:     if (   ! exists($env{'internal.start_page'})
                   6159: 	&&   exists($env{'internal.end_page'})) {
1.316     albertel 6160: 	&Apache::lonnet::logthis('end_page called without start_page'.
                   6161: 				 $env{'request.filename'});
1.315     albertel 6162:     }
1.306     albertel 6163: }
1.315     albertel 6164: 
1.318     albertel 6165: sub simple_error_page {
                   6166:     my ($r,$title,$msg) = @_;
                   6167:     my $page =
                   6168: 	&Apache::loncommon::start_page($title).
                   6169: 	&mt($msg).
                   6170: 	&Apache::loncommon::end_page();
                   6171:     if (ref($r)) {
                   6172: 	$r->print($page);
1.327     albertel 6173: 	return;
1.318     albertel 6174:     }
                   6175:     return $page;
                   6176: }
1.347     albertel 6177: 
                   6178: {
1.610     albertel 6179:     my @row_count;
1.347     albertel 6180:     sub start_data_table {
1.422     albertel 6181: 	my ($add_class) = @_;
                   6182: 	my $css_class = (join(' ','LC_data_table',$add_class));
1.610     albertel 6183: 	unshift(@row_count,0);
1.422     albertel 6184: 	return '<table class="'.$css_class.'">'."\n";
1.347     albertel 6185:     }
                   6186: 
                   6187:     sub end_data_table {
1.610     albertel 6188: 	shift(@row_count);
1.389     albertel 6189: 	return '</table>'."\n";;
1.347     albertel 6190:     }
                   6191: 
                   6192:     sub start_data_table_row {
1.422     albertel 6193: 	my ($add_class) = @_;
1.610     albertel 6194: 	$row_count[0]++;
                   6195: 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.428     albertel 6196: 	$css_class = (join(' ',$css_class,$add_class));
1.422     albertel 6197: 	return  '<tr class="'.$css_class.'">'."\n";;
1.347     albertel 6198:     }
1.471     banghart 6199:     
                   6200:     sub continue_data_table_row {
                   6201: 	my ($add_class) = @_;
1.610     albertel 6202: 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.471     banghart 6203: 	$css_class = (join(' ',$css_class,$add_class));
                   6204: 	return  '<tr class="'.$css_class.'">'."\n";;
                   6205:     }
1.347     albertel 6206: 
                   6207:     sub end_data_table_row {
1.389     albertel 6208: 	return '</tr>'."\n";;
1.347     albertel 6209:     }
1.367     www      6210: 
1.421     albertel 6211:     sub start_data_table_empty_row {
1.610     albertel 6212: 	$row_count[0]++;
1.421     albertel 6213: 	return  '<tr class="LC_empty_row" >'."\n";;
                   6214:     }
                   6215: 
                   6216:     sub end_data_table_empty_row {
                   6217: 	return '</tr>'."\n";;
                   6218:     }
                   6219: 
1.367     www      6220:     sub start_data_table_header_row {
1.389     albertel 6221: 	return  '<tr class="LC_header_row">'."\n";;
1.367     www      6222:     }
                   6223: 
                   6224:     sub end_data_table_header_row {
1.389     albertel 6225: 	return '</tr>'."\n";;
1.367     www      6226:     }
1.347     albertel 6227: }
                   6228: 
1.548     albertel 6229: =pod
                   6230: 
                   6231: =item * &inhibit_menu_check($arg)
                   6232: 
                   6233: Checks for a inhibitmenu state and generates output to preserve it
                   6234: 
                   6235: Inputs:         $arg - can be any of
                   6236:                      - undef - in which case the return value is a string 
                   6237:                                to add  into arguments list of a uri
                   6238:                      - 'input' - in which case the return value is a HTML
                   6239:                                  <form> <input> field of type hidden to
                   6240:                                  preserve the value
                   6241:                      - a url - in which case the return value is the url with
                   6242:                                the neccesary cgi args added to preserve the
                   6243:                                inhibitmenu state
                   6244:                      - a ref to a url - no return value, but the string is
                   6245:                                         updated to include the neccessary cgi
                   6246:                                         args to preserve the inhibitmenu state
                   6247: 
                   6248: =cut
                   6249: 
                   6250: sub inhibit_menu_check {
                   6251:     my ($arg) = @_;
                   6252:     &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
                   6253:     if ($arg eq 'input') {
                   6254: 	if ($env{'form.inhibitmenu'}) {
                   6255: 	    return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
                   6256: 	} else {
                   6257: 	    return
                   6258: 	}
                   6259:     }
                   6260:     if ($env{'form.inhibitmenu'}) {
                   6261: 	if (ref($arg)) {
                   6262: 	    $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
                   6263: 	} elsif ($arg eq '') {
                   6264: 	    $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
                   6265: 	} else {
                   6266: 	    $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
                   6267: 	}
                   6268:     }
                   6269:     if (!ref($arg)) {
                   6270: 	return $arg;
                   6271:     }
                   6272: }
                   6273: 
1.251     albertel 6274: ###############################################
1.182     matthew  6275: 
                   6276: =pod
                   6277: 
1.549     albertel 6278: =back
                   6279: 
                   6280: =head1 User Information Routines
                   6281: 
                   6282: =over 4
                   6283: 
1.405     albertel 6284: =item * &get_users_function()
1.182     matthew  6285: 
                   6286: Used by &bodytag to determine the current users primary role.
                   6287: Returns either 'student','coordinator','admin', or 'author'.
                   6288: 
                   6289: =cut
                   6290: 
                   6291: ###############################################
                   6292: sub get_users_function {
                   6293:     my $function = 'student';
1.258     albertel 6294:     if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
1.182     matthew  6295:         $function='coordinator';
                   6296:     }
1.258     albertel 6297:     if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182     matthew  6298:         $function='admin';
                   6299:     }
1.258     albertel 6300:     if (($env{'request.role'}=~/^(au|ca)/) ||
1.182     matthew  6301:         ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
                   6302:         $function='author';
                   6303:     }
                   6304:     return $function;
1.54      www      6305: }
1.99      www      6306: 
                   6307: ###############################################
                   6308: 
1.233     raeburn  6309: =pod
                   6310: 
1.542     raeburn  6311: =item * &check_user_status()
1.274     raeburn  6312: 
                   6313: Determines current status of supplied role for a
                   6314: specific user. Roles can be active, previous or future.
                   6315: 
                   6316: Inputs: 
                   6317: user's domain, user's username, course's domain,
1.375     raeburn  6318: course's number, optional section ID.
1.274     raeburn  6319: 
                   6320: Outputs:
                   6321: role status: active, previous or future. 
                   6322: 
                   6323: =cut
                   6324: 
                   6325: sub check_user_status {
1.412     raeburn  6326:     my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274     raeburn  6327:     my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
                   6328:     my @uroles = keys %userinfo;
                   6329:     my $srchstr;
                   6330:     my $active_chk = 'none';
1.412     raeburn  6331:     my $now = time;
1.274     raeburn  6332:     if (@uroles > 0) {
1.412     raeburn  6333:         if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
1.274     raeburn  6334:             $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
                   6335:         } else {
1.412     raeburn  6336:             $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
                   6337:         }
                   6338:         if (grep/^\Q$srchstr\E$/,@uroles) {
1.274     raeburn  6339:             my $role_end = 0;
                   6340:             my $role_start = 0;
                   6341:             $active_chk = 'active';
1.412     raeburn  6342:             if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
                   6343:                 $role_end = $1;
                   6344:                 if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
                   6345:                     $role_start = $1;
1.274     raeburn  6346:                 }
                   6347:             }
                   6348:             if ($role_start > 0) {
1.412     raeburn  6349:                 if ($now < $role_start) {
1.274     raeburn  6350:                     $active_chk = 'future';
                   6351:                 }
                   6352:             }
                   6353:             if ($role_end > 0) {
1.412     raeburn  6354:                 if ($now > $role_end) {
1.274     raeburn  6355:                     $active_chk = 'previous';
                   6356:                 }
                   6357:             }
                   6358:         }
                   6359:     }
                   6360:     return $active_chk;
                   6361: }
                   6362: 
                   6363: ###############################################
                   6364: 
                   6365: =pod
                   6366: 
1.405     albertel 6367: =item * &get_sections()
1.233     raeburn  6368: 
                   6369: Determines all the sections for a course including
                   6370: sections with students and sections containing other roles.
1.419     raeburn  6371: Incoming parameters: 
                   6372: 
                   6373: 1. domain
                   6374: 2. course number 
                   6375: 3. reference to array containing roles for which sections should 
                   6376: be gathered (optional).
                   6377: 4. reference to array containing status types for which sections 
                   6378: should be gathered (optional).
                   6379: 
                   6380: If the third argument is undefined, sections are gathered for any role. 
                   6381: If the fourth argument is undefined, sections are gathered for any status.
                   6382: Permissible values are 'active' or 'future' or 'previous'.
1.233     raeburn  6383:  
1.374     raeburn  6384: Returns section hash (keys are section IDs, values are
                   6385: number of users in each section), subject to the
1.419     raeburn  6386: optional roles filter, optional status filter 
1.233     raeburn  6387: 
                   6388: =cut
                   6389: 
                   6390: ###############################################
                   6391: sub get_sections {
1.419     raeburn  6392:     my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366     albertel 6393:     if (!defined($cdom) || !defined($cnum)) {
                   6394:         my $cid =  $env{'request.course.id'};
                   6395: 
                   6396: 	return if (!defined($cid));
                   6397: 
                   6398:         $cdom = $env{'course.'.$cid.'.domain'};
                   6399:         $cnum = $env{'course.'.$cid.'.num'};
                   6400:     }
                   6401: 
                   6402:     my %sectioncount;
1.419     raeburn  6403:     my $now = time;
1.240     albertel 6404: 
1.366     albertel 6405:     if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276     albertel 6406: 	my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240     albertel 6407: 	my $sec_index = &Apache::loncoursedata::CL_SECTION();
                   6408: 	my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419     raeburn  6409:         my $start_index = &Apache::loncoursedata::CL_START();
                   6410:         my $end_index = &Apache::loncoursedata::CL_END();
                   6411:         my $status;
1.366     albertel 6412: 	while (my ($student,$data) = each(%$classlist)) {
1.419     raeburn  6413: 	    my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
                   6414: 				                     $data->[$status_index],
                   6415:                                                      $data->[$start_index],
                   6416:                                                      $data->[$end_index]);
                   6417:             if ($stu_status eq 'Active') {
                   6418:                 $status = 'active';
                   6419:             } elsif ($end < $now) {
                   6420:                 $status = 'previous';
                   6421:             } elsif ($start > $now) {
                   6422:                 $status = 'future';
                   6423:             } 
                   6424: 	    if ($section ne '-1' && $section !~ /^\s*$/) {
                   6425:                 if ((!defined($possible_status)) || (($status ne '') && 
                   6426:                     (grep/^\Q$status\E$/,@{$possible_status}))) { 
                   6427: 		    $sectioncount{$section}++;
                   6428:                 }
1.240     albertel 6429: 	    }
                   6430: 	}
                   6431:     }
                   6432:     my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   6433:     foreach my $user (sort(keys(%courseroles))) {
                   6434: 	if ($user !~ /^(\w{2})/) { next; }
                   6435: 	my ($role) = ($user =~ /^(\w{2})/);
                   6436: 	if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419     raeburn  6437: 	my ($section,$status);
1.240     albertel 6438: 	if ($role eq 'cr' &&
                   6439: 	    $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
                   6440: 	    $section=$1;
                   6441: 	}
                   6442: 	if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
                   6443: 	if (!defined($section) || $section eq '-1') { next; }
1.419     raeburn  6444:         my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
                   6445:         if ($end == -1 && $start == -1) {
                   6446:             next; #deleted role
                   6447:         }
                   6448:         if (!defined($possible_status)) { 
                   6449:             $sectioncount{$section}++;
                   6450:         } else {
                   6451:             if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
                   6452:                 $status = 'active';
                   6453:             } elsif ($end < $now) {
                   6454:                 $status = 'future';
                   6455:             } elsif ($start > $now) {
                   6456:                 $status = 'previous';
                   6457:             }
                   6458:             if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
                   6459:                 $sectioncount{$section}++;
                   6460:             }
                   6461:         }
1.233     raeburn  6462:     }
1.366     albertel 6463:     return %sectioncount;
1.233     raeburn  6464: }
                   6465: 
1.274     raeburn  6466: ###############################################
1.294     raeburn  6467: 
                   6468: =pod
1.405     albertel 6469: 
                   6470: =item * &get_course_users()
                   6471: 
1.275     raeburn  6472: Retrieves usernames:domains for users in the specified course
                   6473: with specific role(s), and access status. 
                   6474: 
                   6475: Incoming parameters:
1.277     albertel 6476: 1. course domain
                   6477: 2. course number
                   6478: 3. access status: users must have - either active, 
1.275     raeburn  6479: previous, future, or all.
1.277     albertel 6480: 4. reference to array of permissible roles
1.288     raeburn  6481: 5. reference to array of section restrictions (optional)
                   6482: 6. reference to results object (hash of hashes).
                   6483: 7. reference to optional userdata hash
1.609     raeburn  6484: 8. reference to optional statushash
1.630     raeburn  6485: 9. flag if privileged users (except those set to unhide in
                   6486:    course settings) should be excluded    
1.609     raeburn  6487: Keys of top level results hash are roles.
1.275     raeburn  6488: Keys of inner hashes are username:domain, with 
                   6489: values set to access type.
1.288     raeburn  6490: Optional userdata hash returns an array with arguments in the 
                   6491: same order as loncoursedata::get_classlist() for student data.
                   6492: 
1.609     raeburn  6493: Optional statushash returns
                   6494: 
1.288     raeburn  6495: Entries for end, start, section and status are blank because
                   6496: of the possibility of multiple values for non-student roles.
                   6497: 
1.275     raeburn  6498: =cut
1.405     albertel 6499: 
1.275     raeburn  6500: ###############################################
1.405     albertel 6501: 
1.275     raeburn  6502: sub get_course_users {
1.630     raeburn  6503:     my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288     raeburn  6504:     my %idx = ();
1.419     raeburn  6505:     my %seclists;
1.288     raeburn  6506: 
                   6507:     $idx{udom} = &Apache::loncoursedata::CL_SDOM();
                   6508:     $idx{uname} =  &Apache::loncoursedata::CL_SNAME();
                   6509:     $idx{end} = &Apache::loncoursedata::CL_END();
                   6510:     $idx{start} = &Apache::loncoursedata::CL_START();
                   6511:     $idx{id} = &Apache::loncoursedata::CL_ID();
                   6512:     $idx{section} = &Apache::loncoursedata::CL_SECTION();
                   6513:     $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
                   6514:     $idx{status} = &Apache::loncoursedata::CL_STATUS();
                   6515: 
1.290     albertel 6516:     if (grep(/^st$/,@{$roles})) {
1.276     albertel 6517:         my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278     raeburn  6518:         my $now = time;
1.277     albertel 6519:         foreach my $student (keys(%{$classlist})) {
1.288     raeburn  6520:             my $match = 0;
1.412     raeburn  6521:             my $secmatch = 0;
1.419     raeburn  6522:             my $section = $$classlist{$student}[$idx{section}];
1.609     raeburn  6523:             my $status = $$classlist{$student}[$idx{status}];
1.419     raeburn  6524:             if ($section eq '') {
                   6525:                 $section = 'none';
                   6526:             }
1.291     albertel 6527:             if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 6528:                 if (grep(/^all$/,@{$sections})) {
1.412     raeburn  6529:                     $secmatch = 1;
                   6530:                 } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420     albertel 6531:                     if (grep(/^none$/,@{$sections})) {
1.412     raeburn  6532:                         $secmatch = 1;
                   6533:                     }
                   6534:                 } else {  
1.419     raeburn  6535: 		    if (grep(/^\Q$section\E$/,@{$sections})) {
1.412     raeburn  6536: 		        $secmatch = 1;
                   6537:                     }
1.290     albertel 6538: 		}
1.412     raeburn  6539:                 if (!$secmatch) {
                   6540:                     next;
                   6541:                 }
1.419     raeburn  6542:             }
1.275     raeburn  6543:             if (defined($$types{'active'})) {
1.288     raeburn  6544:                 if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275     raeburn  6545:                     push(@{$$users{st}{$student}},'active');
1.288     raeburn  6546:                     $match = 1;
1.275     raeburn  6547:                 }
                   6548:             }
                   6549:             if (defined($$types{'previous'})) {
1.609     raeburn  6550:                 if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275     raeburn  6551:                     push(@{$$users{st}{$student}},'previous');
1.288     raeburn  6552:                     $match = 1;
1.275     raeburn  6553:                 }
                   6554:             }
                   6555:             if (defined($$types{'future'})) {
1.609     raeburn  6556:                 if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275     raeburn  6557:                     push(@{$$users{st}{$student}},'future');
1.288     raeburn  6558:                     $match = 1;
1.275     raeburn  6559:                 }
                   6560:             }
1.609     raeburn  6561:             if ($match) {
                   6562:                 push(@{$seclists{$student}},$section);
                   6563:                 if (ref($userdata) eq 'HASH') {
                   6564:                     $$userdata{$student} = $$classlist{$student};
                   6565:                 }
                   6566:                 if (ref($statushash) eq 'HASH') {
                   6567:                     $statushash->{$student}{'st'}{$section} = $status;
                   6568:                 }
1.288     raeburn  6569:             }
1.275     raeburn  6570:         }
                   6571:     }
1.412     raeburn  6572:     if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439     raeburn  6573:         my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   6574:         my $now = time;
1.609     raeburn  6575:         my %displaystatus = ( previous => 'Expired',
                   6576:                               active   => 'Active',
                   6577:                               future   => 'Future',
                   6578:                             );
1.630     raeburn  6579:         my %nothide;
                   6580:         if ($hidepriv) {
                   6581:             my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
                   6582:             foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
                   6583:                 if ($user !~ /:/) {
                   6584:                     $nothide{join(':',split(/[\@]/,$user))}=1;
                   6585:                 } else {
                   6586:                     $nothide{$user} = 1;
                   6587:                 }
                   6588:             }
                   6589:         }
1.439     raeburn  6590:         foreach my $person (sort(keys(%coursepersonnel))) {
1.288     raeburn  6591:             my $match = 0;
1.412     raeburn  6592:             my $secmatch = 0;
1.439     raeburn  6593:             my $status;
1.412     raeburn  6594:             my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275     raeburn  6595:             $user =~ s/:$//;
1.439     raeburn  6596:             my ($end,$start) = split(/:/,$coursepersonnel{$person});
                   6597:             if ($end == -1 || $start == -1) {
                   6598:                 next;
                   6599:             }
                   6600:             if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
                   6601:                 (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412     raeburn  6602:                 my ($uname,$udom) = split(/:/,$user);
                   6603:                 if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 6604:                     if (grep(/^all$/,@{$sections})) {
1.412     raeburn  6605:                         $secmatch = 1;
                   6606:                     } elsif ($usec eq '') {
1.420     albertel 6607:                         if (grep(/^none$/,@{$sections})) {
1.412     raeburn  6608:                             $secmatch = 1;
                   6609:                         }
                   6610:                     } else {
                   6611:                         if (grep(/^\Q$usec\E$/,@{$sections})) {
                   6612:                             $secmatch = 1;
                   6613:                         }
                   6614:                     }
                   6615:                     if (!$secmatch) {
                   6616:                         next;
                   6617:                     }
1.288     raeburn  6618:                 }
1.419     raeburn  6619:                 if ($usec eq '') {
                   6620:                     $usec = 'none';
                   6621:                 }
1.275     raeburn  6622:                 if ($uname ne '' && $udom ne '') {
1.630     raeburn  6623:                     if ($hidepriv) {
                   6624:                         if ((&Apache::lonnet::privileged($uname,$udom)) &&
                   6625:                             (!$nothide{$uname.':'.$udom})) {
                   6626:                             next;
                   6627:                         }
                   6628:                     }
1.503     raeburn  6629:                     if ($end > 0 && $end < $now) {
1.439     raeburn  6630:                         $status = 'previous';
                   6631:                     } elsif ($start > $now) {
                   6632:                         $status = 'future';
                   6633:                     } else {
                   6634:                         $status = 'active';
                   6635:                     }
1.277     albertel 6636:                     foreach my $type (keys(%{$types})) { 
1.275     raeburn  6637:                         if ($status eq $type) {
1.420     albertel 6638:                             if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419     raeburn  6639:                                 push(@{$$users{$role}{$user}},$type);
                   6640:                             }
1.288     raeburn  6641:                             $match = 1;
                   6642:                         }
                   6643:                     }
1.419     raeburn  6644:                     if (($match) && (ref($userdata) eq 'HASH')) {
                   6645:                         if (!exists($$userdata{$uname.':'.$udom})) {
                   6646: 			    &get_user_info($udom,$uname,\%idx,$userdata);
                   6647:                         }
1.420     albertel 6648:                         if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419     raeburn  6649:                             push(@{$seclists{$uname.':'.$udom}},$usec);
                   6650:                         }
1.609     raeburn  6651:                         if (ref($statushash) eq 'HASH') {
                   6652:                             $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
                   6653:                         }
1.275     raeburn  6654:                     }
                   6655:                 }
                   6656:             }
                   6657:         }
1.290     albertel 6658:         if (grep(/^ow$/,@{$roles})) {
1.279     raeburn  6659:             if ((defined($cdom)) && (defined($cnum))) {
                   6660:                 my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
                   6661:                 if ( defined($csettings{'internal.courseowner'}) ) {
                   6662:                     my $owner = $csettings{'internal.courseowner'};
1.609     raeburn  6663:                     next if ($owner eq '');
                   6664:                     my ($ownername,$ownerdom);
                   6665:                     if ($owner =~ /^([^:]+):([^:]+)$/) {
                   6666:                         $ownername = $1;
                   6667:                         $ownerdom = $2;
                   6668:                     } else {
                   6669:                         $ownername = $owner;
                   6670:                         $ownerdom = $cdom;
                   6671:                         $owner = $ownername.':'.$ownerdom;
1.439     raeburn  6672:                     }
                   6673:                     @{$$users{'ow'}{$owner}} = 'any';
1.290     albertel 6674:                     if (defined($userdata) && 
1.609     raeburn  6675: 			!exists($$userdata{$owner})) {
                   6676: 			&get_user_info($ownerdom,$ownername,\%idx,$userdata);
                   6677:                         if (!grep(/^none$/,@{$seclists{$owner}})) {
                   6678:                             push(@{$seclists{$owner}},'none');
                   6679:                         }
                   6680:                         if (ref($statushash) eq 'HASH') {
                   6681:                             $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419     raeburn  6682:                         }
1.290     albertel 6683: 		    }
1.279     raeburn  6684:                 }
                   6685:             }
                   6686:         }
1.419     raeburn  6687:         foreach my $user (keys(%seclists)) {
                   6688:             @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
                   6689:             $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
                   6690:         }
1.275     raeburn  6691:     }
                   6692:     return;
                   6693: }
                   6694: 
1.288     raeburn  6695: sub get_user_info {
                   6696:     my ($udom,$uname,$idx,$userdata) = @_;
1.289     albertel 6697:     $$userdata{$uname.':'.$udom}[$$idx{fullname}] = 
                   6698: 	&plainname($uname,$udom,'lastname');
1.291     albertel 6699:     $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297     raeburn  6700:     $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609     raeburn  6701:     my %idhash =  &Apache::lonnet::idrget($udom,($uname));
                   6702:     $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname}; 
1.288     raeburn  6703:     return;
                   6704: }
1.275     raeburn  6705: 
1.472     raeburn  6706: ###############################################
                   6707: 
                   6708: =pod
                   6709: 
                   6710: =item * &get_user_quota()
                   6711: 
                   6712: Retrieves quota assigned for storage of portfolio files for a user  
                   6713: 
                   6714: Incoming parameters:
                   6715: 1. user's username
                   6716: 2. user's domain
                   6717: 
                   6718: Returns:
1.536     raeburn  6719: 1. Disk quota (in Mb) assigned to student.
                   6720: 2. (Optional) Type of setting: custom or default
                   6721:    (individually assigned or default for user's 
                   6722:    institutional status).
                   6723: 3. (Optional) - User's institutional status (e.g., faculty, staff
                   6724:    or student - types as defined in localenroll::inst_usertypes 
                   6725:    for user's domain, which determines default quota for user.
                   6726: 4. (Optional) - Default quota which would apply to the user.
1.472     raeburn  6727: 
                   6728: If a value has been stored in the user's environment, 
1.536     raeburn  6729: it will return that, otherwise it returns the maximal default
                   6730: defined for the user's instituional status(es) in the domain.
1.472     raeburn  6731: 
                   6732: =cut
                   6733: 
                   6734: ###############################################
                   6735: 
                   6736: 
                   6737: sub get_user_quota {
                   6738:     my ($uname,$udom) = @_;
1.536     raeburn  6739:     my ($quota,$quotatype,$settingstatus,$defquota);
1.472     raeburn  6740:     if (!defined($udom)) {
                   6741:         $udom = $env{'user.domain'};
                   6742:     }
                   6743:     if (!defined($uname)) {
                   6744:         $uname = $env{'user.name'};
                   6745:     }
                   6746:     if (($udom eq '' || $uname eq '') ||
                   6747:         ($udom eq 'public') && ($uname eq 'public')) {
                   6748:         $quota = 0;
1.536     raeburn  6749:         $quotatype = 'default';
                   6750:         $defquota = 0; 
1.472     raeburn  6751:     } else {
1.536     raeburn  6752:         my $inststatus;
1.472     raeburn  6753:         if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
                   6754:             $quota = $env{'environment.portfolioquota'};
1.536     raeburn  6755:             $inststatus = $env{'environment.inststatus'};
1.472     raeburn  6756:         } else {
1.536     raeburn  6757:             my %userenv = 
                   6758:                 &Apache::lonnet::get('environment',['portfolioquota',
                   6759:                                      'inststatus'],$udom,$uname);
1.472     raeburn  6760:             my ($tmp) = keys(%userenv);
                   6761:             if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   6762:                 $quota = $userenv{'portfolioquota'};
1.536     raeburn  6763:                 $inststatus = $userenv{'inststatus'};
1.472     raeburn  6764:             } else {
                   6765:                 undef(%userenv);
                   6766:             }
                   6767:         }
1.536     raeburn  6768:         ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472     raeburn  6769:         if ($quota eq '') {
1.536     raeburn  6770:             $quota = $defquota;
                   6771:             $quotatype = 'default';
                   6772:         } else {
                   6773:             $quotatype = 'custom';
1.472     raeburn  6774:         }
                   6775:     }
1.536     raeburn  6776:     if (wantarray) {
                   6777:         return ($quota,$quotatype,$settingstatus,$defquota);
                   6778:     } else {
                   6779:         return $quota;
                   6780:     }
1.472     raeburn  6781: }
                   6782: 
                   6783: ###############################################
                   6784: 
                   6785: =pod
                   6786: 
                   6787: =item * &default_quota()
                   6788: 
1.536     raeburn  6789: Retrieves default quota assigned for storage of user portfolio files,
                   6790: given an (optional) user's institutional status.
1.472     raeburn  6791: 
                   6792: Incoming parameters:
                   6793: 1. domain
1.536     raeburn  6794: 2. (Optional) institutional status(es).  This is a : separated list of 
                   6795:    status types (e.g., faculty, staff, student etc.)
                   6796:    which apply to the user for whom the default is being retrieved.
                   6797:    If the institutional status string in undefined, the domain
                   6798:    default quota will be returned. 
1.472     raeburn  6799: 
                   6800: Returns:
                   6801: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536     raeburn  6802: 2. (Optional) institutional type which determined the value of the
                   6803:    default quota.
1.472     raeburn  6804: 
                   6805: If a value has been stored in the domain's configuration db,
                   6806: it will return that, otherwise it returns 20 (for backwards 
                   6807: compatibility with domains which have not set up a configuration
                   6808: db file; the original statically defined portfolio quota was 20 Mb). 
                   6809: 
1.536     raeburn  6810: If the user's status includes multiple types (e.g., staff and student),
                   6811: the largest default quota which applies to the user determines the
                   6812: default quota returned.
                   6813: 
1.472     raeburn  6814: =cut
                   6815: 
                   6816: ###############################################
                   6817: 
                   6818: 
                   6819: sub default_quota {
1.536     raeburn  6820:     my ($udom,$inststatus) = @_;
                   6821:     my ($defquota,$settingstatus);
                   6822:     my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622     raeburn  6823:                                             ['quotas'],$udom);
                   6824:     if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536     raeburn  6825:         if ($inststatus ne '') {
                   6826:             my @statuses = split(/:/,$inststatus);
                   6827:             foreach my $item (@statuses) {
1.622     raeburn  6828:                 if ($quotahash{'quotas'}{$item} ne '') {
1.536     raeburn  6829:                     if ($defquota eq '') {
1.622     raeburn  6830:                         $defquota = $quotahash{'quotas'}{$item};
1.536     raeburn  6831:                         $settingstatus = $item;
1.622     raeburn  6832:                     } elsif ($quotahash{'quotas'}{$item} > $defquota) {
                   6833:                         $defquota = $quotahash{'quotas'}{$item};
1.536     raeburn  6834:                         $settingstatus = $item;
                   6835:                     }
                   6836:                 }
                   6837:             }
                   6838:         }
                   6839:         if ($defquota eq '') {
1.622     raeburn  6840:             $defquota = $quotahash{'quotas'}{'default'};
1.536     raeburn  6841:             $settingstatus = 'default';
                   6842:         }
                   6843:     } else {
                   6844:         $settingstatus = 'default';
                   6845:         $defquota = 20;
                   6846:     }
                   6847:     if (wantarray) {
                   6848:         return ($defquota,$settingstatus);
1.472     raeburn  6849:     } else {
1.536     raeburn  6850:         return $defquota;
1.472     raeburn  6851:     }
                   6852: }
                   6853: 
1.384     raeburn  6854: sub get_secgrprole_info {
                   6855:     my ($cdom,$cnum,$needroles,$type)  = @_;
                   6856:     my %sections_count = &get_sections($cdom,$cnum);
                   6857:     my @sections =  (sort {$a <=> $b} keys(%sections_count));
                   6858:     my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
                   6859:     my @groups = sort(keys(%curr_groups));
                   6860:     my $allroles = [];
                   6861:     my $rolehash;
                   6862:     my $accesshash = {
                   6863:                      active => 'Currently has access',
                   6864:                      future => 'Will have future access',
                   6865:                      previous => 'Previously had access',
                   6866:                   };
                   6867:     if ($needroles) {
                   6868:         $rolehash = {'all' => 'all'};
1.385     albertel 6869:         my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   6870: 	if (&Apache::lonnet::error(%user_roles)) {
                   6871: 	    undef(%user_roles);
                   6872: 	}
                   6873:         foreach my $item (keys(%user_roles)) {
1.384     raeburn  6874:             my ($role)=split(/\:/,$item,2);
                   6875:             if ($role eq 'cr') { next; }
                   6876:             if ($role =~ /^cr/) {
                   6877:                 $$rolehash{$role} = (split('/',$role))[3];
                   6878:             } else {
                   6879:                 $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
                   6880:             }
                   6881:         }
                   6882:         foreach my $key (sort(keys(%{$rolehash}))) {
                   6883:             push(@{$allroles},$key);
                   6884:         }
                   6885:         push (@{$allroles},'st');
                   6886:         $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
                   6887:     }
                   6888:     return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
                   6889: }
                   6890: 
1.555     raeburn  6891: sub user_picker {
1.627     raeburn  6892:     my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555     raeburn  6893:     my $currdom = $dom;
                   6894:     my %curr_selected = (
                   6895:                         srchin => 'dom',
1.580     raeburn  6896:                         srchby => 'lastname',
1.555     raeburn  6897:                       );
                   6898:     my $srchterm;
1.625     raeburn  6899:     if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555     raeburn  6900:         if ($srch->{'srchby'} ne '') {
                   6901:             $curr_selected{'srchby'} = $srch->{'srchby'};
                   6902:         }
                   6903:         if ($srch->{'srchin'} ne '') {
                   6904:             $curr_selected{'srchin'} = $srch->{'srchin'};
                   6905:         }
                   6906:         if ($srch->{'srchtype'} ne '') {
                   6907:             $curr_selected{'srchtype'} = $srch->{'srchtype'};
                   6908:         }
                   6909:         if ($srch->{'srchdomain'} ne '') {
                   6910:             $currdom = $srch->{'srchdomain'};
                   6911:         }
                   6912:         $srchterm = $srch->{'srchterm'};
                   6913:     }
                   6914:     my %lt=&Apache::lonlocal::texthash(
1.573     raeburn  6915:                     'usr'       => 'Search criteria',
1.563     raeburn  6916:                     'doma'      => 'Domain/institution to search',
1.558     albertel 6917:                     'uname'     => 'username',
                   6918:                     'lastname'  => 'last name',
1.555     raeburn  6919:                     'lastfirst' => 'last name, first name',
1.558     albertel 6920:                     'crs'       => 'in this course',
1.576     raeburn  6921:                     'dom'       => 'in selected LON-CAPA domain', 
1.558     albertel 6922:                     'alc'       => 'all LON-CAPA',
1.573     raeburn  6923:                     'instd'     => 'in institutional directory for selected domain',
1.558     albertel 6924:                     'exact'     => 'is',
                   6925:                     'contains'  => 'contains',
1.569     raeburn  6926:                     'begins'    => 'begins with',
1.571     raeburn  6927:                     'youm'      => "You must include some text to search for.",
                   6928:                     'thte'      => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
                   6929:                     'thet'      => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
                   6930:                     'yomc'      => "You must choose a domain when using an institutional directory search.",
                   6931:                     'ymcd'      => "You must choose a domain when using a domain search.",
                   6932:                     'whus'      => "When using searching by last,first you must include a comma as separator between last name and first name.",
                   6933:                     'whse'      => "When searching by last,first you must include at least one character in the first name.",
                   6934:                      'thfo'     => "The following need to be corrected before the search can be run:",
1.555     raeburn  6935:                                        );
1.563     raeburn  6936:     my $domform = &select_dom_form($currdom,'srchdomain',1,1);
                   6937:     my $srchinsel = ' <select name="srchin">';
1.555     raeburn  6938: 
                   6939:     my @srchins = ('crs','dom','alc','instd');
                   6940: 
                   6941:     foreach my $option (@srchins) {
                   6942:         # FIXME 'alc' option unavailable until 
                   6943:         #       loncreateuser::print_user_query_page()
                   6944:         #       has been completed.
                   6945:         next if ($option eq 'alc');
                   6946:         next if ($option eq 'crs' && !$env{'request.course.id'});
1.563     raeburn  6947:         if ($curr_selected{'srchin'} eq $option) {
                   6948:             $srchinsel .= ' 
                   6949:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   6950:         } else {
                   6951:             $srchinsel .= '
                   6952:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   6953:         }
1.555     raeburn  6954:     }
1.563     raeburn  6955:     $srchinsel .= "\n  </select>\n";
1.555     raeburn  6956: 
                   6957:     my $srchbysel =  ' <select name="srchby">';
1.580     raeburn  6958:     foreach my $option ('lastname','lastfirst','uname') {
1.555     raeburn  6959:         if ($curr_selected{'srchby'} eq $option) {
                   6960:             $srchbysel .= '
                   6961:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   6962:         } else {
                   6963:             $srchbysel .= '
                   6964:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   6965:          }
                   6966:     }
                   6967:     $srchbysel .= "\n  </select>\n";
                   6968: 
                   6969:     my $srchtypesel = ' <select name="srchtype">';
1.580     raeburn  6970:     foreach my $option ('begins','contains','exact') {
1.555     raeburn  6971:         if ($curr_selected{'srchtype'} eq $option) {
                   6972:             $srchtypesel .= '
                   6973:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   6974:         } else {
                   6975:             $srchtypesel .= '
                   6976:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   6977:         }
                   6978:     }
                   6979:     $srchtypesel .= "\n  </select>\n";
                   6980: 
1.558     albertel 6981:     my ($newuserscript,$new_user_create);
1.556     raeburn  6982: 
                   6983:     if ($forcenewuser) {
1.576     raeburn  6984:         if (ref($srch) eq 'HASH') {
                   6985:             if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627     raeburn  6986:                 if ($cancreate) {
                   6987:                     $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>';
                   6988:                 } else {
                   6989:                     my $helplink = ' href="javascript:helpMenu('."'display'".')"';
                   6990:                     my %usertypetext = (
                   6991:                         official   => 'institutional',
                   6992:                         unofficial => 'non-institutional',
                   6993:                     );
                   6994:                     $new_user_create = '<br /><span class="LC_warning">'.&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.").' '.&mt('Contact the <a[_1]>helpdesk</a> for assistance.',$helplink).'</span><br /><br />';
                   6995:                 }
1.576     raeburn  6996:             }
                   6997:         }
                   6998: 
1.556     raeburn  6999:         $newuserscript = <<"ENDSCRIPT";
                   7000: 
1.570     raeburn  7001: function setSearch(createnew,callingForm) {
1.556     raeburn  7002:     if (createnew == 1) {
1.570     raeburn  7003:         for (var i=0; i<callingForm.srchby.length; i++) {
                   7004:             if (callingForm.srchby.options[i].value == 'uname') {
                   7005:                 callingForm.srchby.selectedIndex = i;
1.556     raeburn  7006:             }
                   7007:         }
1.570     raeburn  7008:         for (var i=0; i<callingForm.srchin.length; i++) {
                   7009:             if ( callingForm.srchin.options[i].value == 'dom') {
                   7010: 		callingForm.srchin.selectedIndex = i;
1.556     raeburn  7011:             }
                   7012:         }
1.570     raeburn  7013:         for (var i=0; i<callingForm.srchtype.length; i++) {
                   7014:             if (callingForm.srchtype.options[i].value == 'exact') {
                   7015:                 callingForm.srchtype.selectedIndex = i;
1.556     raeburn  7016:             }
                   7017:         }
1.570     raeburn  7018:         for (var i=0; i<callingForm.srchdomain.length; i++) {
                   7019:             if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
                   7020:                 callingForm.srchdomain.selectedIndex = i;
1.556     raeburn  7021:             }
                   7022:         }
                   7023:     }
                   7024: }
                   7025: ENDSCRIPT
1.558     albertel 7026: 
1.556     raeburn  7027:     }
                   7028: 
1.555     raeburn  7029:     my $output = <<"END_BLOCK";
1.556     raeburn  7030: <script type="text/javascript">
1.570     raeburn  7031: function validateEntry(callingForm) {
1.558     albertel 7032: 
1.556     raeburn  7033:     var checkok = 1;
1.558     albertel 7034:     var srchin;
1.570     raeburn  7035:     for (var i=0; i<callingForm.srchin.length; i++) {
                   7036: 	if ( callingForm.srchin[i].checked ) {
                   7037: 	    srchin = callingForm.srchin[i].value;
1.558     albertel 7038: 	}
                   7039:     }
                   7040: 
1.570     raeburn  7041:     var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
                   7042:     var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
                   7043:     var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
                   7044:     var srchterm =  callingForm.srchterm.value;
                   7045:     var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556     raeburn  7046:     var msg = "";
                   7047: 
                   7048:     if (srchterm == "") {
                   7049:         checkok = 0;
1.571     raeburn  7050:         msg += "$lt{'youm'}\\n";
1.556     raeburn  7051:     }
                   7052: 
1.569     raeburn  7053:     if (srchtype== 'begins') {
                   7054:         if (srchterm.length < 2) {
                   7055:             checkok = 0;
1.571     raeburn  7056:             msg += "$lt{'thte'}\\n";
1.569     raeburn  7057:         }
                   7058:     }
                   7059: 
1.556     raeburn  7060:     if (srchtype== 'contains') {
                   7061:         if (srchterm.length < 3) {
                   7062:             checkok = 0;
1.571     raeburn  7063:             msg += "$lt{'thet'}\\n";
1.556     raeburn  7064:         }
                   7065:     }
                   7066:     if (srchin == 'instd') {
                   7067:         if (srchdomain == '') {
                   7068:             checkok = 0;
1.571     raeburn  7069:             msg += "$lt{'yomc'}\\n";
1.556     raeburn  7070:         }
                   7071:     }
                   7072:     if (srchin == 'dom') {
                   7073:         if (srchdomain == '') {
                   7074:             checkok = 0;
1.571     raeburn  7075:             msg += "$lt{'ymcd'}\\n";
1.556     raeburn  7076:         }
                   7077:     }
                   7078:     if (srchby == 'lastfirst') {
                   7079:         if (srchterm.indexOf(",") == -1) {
                   7080:             checkok = 0;
1.571     raeburn  7081:             msg += "$lt{'whus'}\\n";
1.556     raeburn  7082:         }
                   7083:         if (srchterm.indexOf(",") == srchterm.length -1) {
                   7084:             checkok = 0;
1.571     raeburn  7085:             msg += "$lt{'whse'}\\n";
1.556     raeburn  7086:         }
                   7087:     }
                   7088:     if (checkok == 0) {
1.571     raeburn  7089:         alert("$lt{'thfo'}\\n"+msg);
1.556     raeburn  7090:         return;
                   7091:     }
                   7092:     if (checkok == 1) {
1.570     raeburn  7093:         callingForm.submit();
1.556     raeburn  7094:     }
                   7095: }
                   7096: 
                   7097: $newuserscript
                   7098: 
                   7099: </script>
1.558     albertel 7100: 
                   7101: $new_user_create
                   7102: 
1.555     raeburn  7103: <table>
1.558     albertel 7104:  <tr>
1.573     raeburn  7105:   <td>$lt{'doma'}:</td>
                   7106:   <td>$domform</td>
                   7107:   </td>
                   7108:  </tr>
                   7109:  <tr>
                   7110:   <td>$lt{'usr'}:</td>
1.563     raeburn  7111:   <td>$srchbysel
                   7112:       $srchtypesel 
                   7113:       <input type="text" size="15" name="srchterm" value="$srchterm" />
1.564     albertel 7114:       $srchinsel 
1.563     raeburn  7115:   </td>
                   7116:  </tr>
1.555     raeburn  7117: </table>
                   7118: <br />
                   7119: END_BLOCK
1.558     albertel 7120: 
1.555     raeburn  7121:     return $output;
                   7122: }
                   7123: 
1.612     raeburn  7124: sub user_rule_check {
1.615     raeburn  7125:     my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612     raeburn  7126:     my $response;
                   7127:     if (ref($usershash) eq 'HASH') {
                   7128:         foreach my $user (keys(%{$usershash})) {
                   7129:             my ($uname,$udom) = split(/:/,$user);
                   7130:             next if ($udom eq '' || $uname eq '');
1.615     raeburn  7131:             my ($id,$newuser);
1.612     raeburn  7132:             if (ref($usershash->{$user}) eq 'HASH') {
1.615     raeburn  7133:                 $newuser = $usershash->{$user}->{'newuser'};
1.612     raeburn  7134:                 $id = $usershash->{$user}->{'id'};
                   7135:             }
                   7136:             my $inst_response;
                   7137:             if (ref($checks) eq 'HASH') {
                   7138:                 if (defined($checks->{'username'})) {
1.615     raeburn  7139:                     ($inst_response,%{$inst_results->{$user}}) = 
1.612     raeburn  7140:                         &Apache::lonnet::get_instuser($udom,$uname);
                   7141:                 } elsif (defined($checks->{'id'})) {
1.615     raeburn  7142:                     ($inst_response,%{$inst_results->{$user}}) =
1.612     raeburn  7143:                         &Apache::lonnet::get_instuser($udom,undef,$id);
                   7144:                 }
1.615     raeburn  7145:             } else {
                   7146:                 ($inst_response,%{$inst_results->{$user}}) =
                   7147:                     &Apache::lonnet::get_instuser($udom,$uname);
                   7148:                 return;
1.612     raeburn  7149:             }
1.615     raeburn  7150:             if (!$got_rules->{$udom}) {
1.612     raeburn  7151:                 my %domconfig = &Apache::lonnet::get_dom('configuration',
                   7152:                                                   ['usercreation'],$udom);
                   7153:                 if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615     raeburn  7154:                     foreach my $item ('username','id') {
1.612     raeburn  7155:                         if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
                   7156:                             $$curr_rules{$udom}{$item} = 
                   7157:                                 $domconfig{'usercreation'}{$item.'_rule'};
1.585     raeburn  7158:                         }
                   7159:                     }
                   7160:                 }
1.615     raeburn  7161:                 $got_rules->{$udom} = 1;  
1.585     raeburn  7162:             }
1.612     raeburn  7163:             foreach my $item (keys(%{$checks})) {
                   7164:                 if (ref($$curr_rules{$udom}) eq 'HASH') {
                   7165:                     if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
                   7166:                         if (@{$$curr_rules{$udom}{$item}} > 0) {
                   7167:                             my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
                   7168:                             foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
                   7169:                                 if ($rule_check{$rule}) {
                   7170:                                     $$rulematch{$user}{$item} = $rule;
                   7171:                                     if ($inst_response eq 'ok') {
1.615     raeburn  7172:                                         if (ref($inst_results) eq 'HASH') {
                   7173:                                             if (ref($inst_results->{$user}) eq 'HASH') {
                   7174:                                                 if (keys(%{$inst_results->{$user}}) == 0) {
                   7175:                                                     $$alerts{$item}{$udom}{$uname} = 1;
                   7176:                                                 }
1.612     raeburn  7177:                                             }
                   7178:                                         }
1.615     raeburn  7179:                                     }
                   7180:                                     last;
1.585     raeburn  7181:                                 }
                   7182:                             }
                   7183:                         }
                   7184:                     }
                   7185:                 }
                   7186:             }
                   7187:         }
                   7188:     }
1.612     raeburn  7189:     return;
                   7190: }
                   7191: 
                   7192: sub user_rule_formats {
                   7193:     my ($domain,$domdesc,$curr_rules,$check) = @_;
                   7194:     my %text = ( 
                   7195:                  'username' => 'Usernames',
                   7196:                  'id'       => 'IDs',
                   7197:                );
                   7198:     my $output;
                   7199:     my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
                   7200:     if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
                   7201:         if (@{$ruleorder} > 0) {
                   7202:             $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>';
                   7203:             foreach my $rule (@{$ruleorder}) {
                   7204:                 if (ref($curr_rules) eq 'ARRAY') {
                   7205:                     if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
                   7206:                         if (ref($rules->{$rule}) eq 'HASH') {
                   7207:                             $output .= '<li>'.$rules->{$rule}{'name'}.': '.
                   7208:                                         $rules->{$rule}{'desc'}.'</li>';
                   7209:                         }
                   7210:                     }
                   7211:                 }
                   7212:             }
                   7213:             $output .= '</ul>';
                   7214:         }
                   7215:     }
                   7216:     return $output;
                   7217: }
                   7218: 
                   7219: sub instrule_disallow_msg {
1.615     raeburn  7220:     my ($checkitem,$domdesc,$count,$mode) = @_;
1.612     raeburn  7221:     my $response;
                   7222:     my %text = (
                   7223:                   item   => 'username',
                   7224:                   items  => 'usernames',
                   7225:                   match  => 'matches',
                   7226:                   do     => 'does',
                   7227:                   action => 'a username',
                   7228:                   one    => 'one',
                   7229:                );
                   7230:     if ($count > 1) {
                   7231:         $text{'item'} = 'usernames';
                   7232:         $text{'match'} ='match';
                   7233:         $text{'do'} = 'do';
                   7234:         $text{'action'} = 'usernames',
                   7235:         $text{'one'} = 'ones';
                   7236:     }
                   7237:     if ($checkitem eq 'id') {
                   7238:         $text{'items'} = 'IDs';
                   7239:         $text{'item'} = 'ID';
                   7240:         $text{'action'} = 'an ID';
1.615     raeburn  7241:         if ($count > 1) {
                   7242:             $text{'item'} = 'IDs';
                   7243:             $text{'action'} = 'IDs';
                   7244:         }
1.612     raeburn  7245:     }
1.674     bisitz   7246:     $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  7247:     if ($mode eq 'upload') {
                   7248:         if ($checkitem eq 'username') {
                   7249:             $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'}.");
                   7250:         } elsif ($checkitem eq 'id') {
1.674     bisitz   7251:             $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  7252:         }
1.669     raeburn  7253:     } elsif ($mode eq 'selfcreate') {
                   7254:         if ($checkitem eq 'id') {
                   7255:             $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.");
                   7256:         }
1.615     raeburn  7257:     } else {
                   7258:         if ($checkitem eq 'username') {
                   7259:             $response .= &mt("You must choose $text{'action'} with a different format --  $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
                   7260:         } elsif ($checkitem eq 'id') {
                   7261:             $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.");
                   7262:         }
1.612     raeburn  7263:     }
                   7264:     return $response;
1.585     raeburn  7265: }
                   7266: 
1.624     raeburn  7267: sub personal_data_fieldtitles {
                   7268:     my %fieldtitles = &Apache::lonlocal::texthash (
                   7269:                         id => 'Student/Employee ID',
                   7270:                         permanentemail => 'E-mail address',
                   7271:                         lastname => 'Last Name',
                   7272:                         firstname => 'First Name',
                   7273:                         middlename => 'Middle Name',
                   7274:                         generation => 'Generation',
                   7275:                         gen => 'Generation',
                   7276:                    );
                   7277:     return %fieldtitles;
                   7278: }
                   7279: 
1.642     raeburn  7280: sub sorted_inst_types {
                   7281:     my ($dom) = @_;
                   7282:     my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
                   7283:     my $othertitle = &mt('All users');
                   7284:     if ($env{'request.course.id'}) {
1.668     raeburn  7285:         $othertitle  = &mt('Any users');
1.642     raeburn  7286:     }
                   7287:     my @types;
                   7288:     if (ref($order) eq 'ARRAY') {
                   7289:         @types = @{$order};
                   7290:     }
                   7291:     if (@types == 0) {
                   7292:         if (ref($usertypes) eq 'HASH') {
                   7293:             @types = sort(keys(%{$usertypes}));
                   7294:         }
                   7295:     }
                   7296:     if (keys(%{$usertypes}) > 0) {
                   7297:         $othertitle = &mt('Other users');
                   7298:     }
                   7299:     return ($othertitle,$usertypes,\@types);
                   7300: }
                   7301: 
1.645     raeburn  7302: sub get_institutional_codes {
                   7303:     my ($settings,$allcourses,$LC_code) = @_;
                   7304: # Get complete list of course sections to update
                   7305:     my @currsections = ();
                   7306:     my @currxlists = ();
                   7307:     my $coursecode = $$settings{'internal.coursecode'};
                   7308: 
                   7309:     if ($$settings{'internal.sectionnums'} ne '') {
                   7310:         @currsections = split(/,/,$$settings{'internal.sectionnums'});
                   7311:     }
                   7312: 
                   7313:     if ($$settings{'internal.crosslistings'} ne '') {
                   7314:         @currxlists = split(/,/,$$settings{'internal.crosslistings'});
                   7315:     }
                   7316: 
                   7317:     if (@currxlists > 0) {
                   7318:         foreach (@currxlists) {
                   7319:             if (m/^([^:]+):(\w*)$/) {
                   7320:                 unless (grep/^$1$/,@{$allcourses}) {
                   7321:                     push @{$allcourses},$1;
                   7322:                     $$LC_code{$1} = $2;
                   7323:                 }
                   7324:             }
                   7325:         }
                   7326:     }
                   7327:  
                   7328:     if (@currsections > 0) {
                   7329:         foreach (@currsections) {
                   7330:             if (m/^(\w+):(\w*)$/) {
                   7331:                 my $sec = $coursecode.$1;
                   7332:                 my $lc_sec = $2;
                   7333:                 unless (grep/^$sec$/,@{$allcourses}) {
                   7334:                     push @{$allcourses},$sec;
                   7335:                     $$LC_code{$sec} = $lc_sec;
                   7336:                 }
                   7337:             }
                   7338:         }
                   7339:     }
                   7340:     return;
                   7341: }
                   7342: 
1.112     bowersj2 7343: =pod
                   7344: 
1.549     albertel 7345: =back
                   7346: 
                   7347: =head1 HTTP Helpers
                   7348: 
                   7349: =over 4
                   7350: 
1.648     raeburn  7351: =item * &get_unprocessed_cgi($query,$possible_names)
1.112     bowersj2 7352: 
1.258     albertel 7353: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112     bowersj2 7354: $query.  The parameters listed in $possible_names (an array reference),
1.258     albertel 7355: will be set in $env{'form.name'} if they do not already exist.
1.112     bowersj2 7356: 
                   7357: Typically called with $ENV{'QUERY_STRING'} as the first parameter.  
                   7358: $possible_names is an ref to an array of form element names.  As an example:
                   7359: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258     albertel 7360: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112     bowersj2 7361: 
                   7362: =cut
1.1       albertel 7363: 
1.6       albertel 7364: sub get_unprocessed_cgi {
1.25      albertel 7365:   my ($query,$possible_names)= @_;
1.26      matthew  7366:   # $Apache::lonxml::debug=1;
1.356     albertel 7367:   foreach my $pair (split(/&/,$query)) {
                   7368:     my ($name, $value) = split(/=/,$pair);
1.369     www      7369:     $name = &unescape($name);
1.25      albertel 7370:     if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
                   7371:       $value =~ tr/+/ /;
                   7372:       $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258     albertel 7373:       unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25      albertel 7374:     }
1.16      harris41 7375:   }
1.6       albertel 7376: }
                   7377: 
1.112     bowersj2 7378: =pod
                   7379: 
1.648     raeburn  7380: =item * &cacheheader() 
1.112     bowersj2 7381: 
                   7382: returns cache-controlling header code
                   7383: 
                   7384: =cut
                   7385: 
1.7       albertel 7386: sub cacheheader {
1.258     albertel 7387:     unless ($env{'request.method'} eq 'GET') { return ''; }
1.216     albertel 7388:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
                   7389:     my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7       albertel 7390:                 <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
                   7391:                 <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216     albertel 7392:     return $output;
1.7       albertel 7393: }
                   7394: 
1.112     bowersj2 7395: =pod
                   7396: 
1.648     raeburn  7397: =item * &no_cache($r) 
1.112     bowersj2 7398: 
                   7399: specifies header code to not have cache
                   7400: 
                   7401: =cut
                   7402: 
1.9       albertel 7403: sub no_cache {
1.216     albertel 7404:     my ($r) = @_;
                   7405:     if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258     albertel 7406: 	$env{'request.method'} ne 'GET') { return ''; }
1.216     albertel 7407:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
                   7408:     $r->no_cache(1);
                   7409:     $r->header_out("Expires" => $date);
                   7410:     $r->header_out("Pragma" => "no-cache");
1.123     www      7411: }
                   7412: 
                   7413: sub content_type {
1.181     albertel 7414:     my ($r,$type,$charset) = @_;
1.299     foxr     7415:     if ($r) {
                   7416: 	#  Note that printout.pl calls this with undef for $r.
                   7417: 	&no_cache($r);
                   7418:     }
1.258     albertel 7419:     if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181     albertel 7420:     unless ($charset) {
                   7421: 	$charset=&Apache::lonlocal::current_encoding;
                   7422:     }
                   7423:     if ($charset) { $type.='; charset='.$charset; }
                   7424:     if ($r) {
                   7425: 	$r->content_type($type);
                   7426:     } else {
                   7427: 	print("Content-type: $type\n\n");
                   7428:     }
1.9       albertel 7429: }
1.25      albertel 7430: 
1.112     bowersj2 7431: =pod
                   7432: 
1.648     raeburn  7433: =item * &add_to_env($name,$value) 
1.112     bowersj2 7434: 
1.258     albertel 7435: adds $name to the %env hash with value
1.112     bowersj2 7436: $value, if $name already exists, the entry is converted to an array
                   7437: reference and $value is added to the array.
                   7438: 
                   7439: =cut
                   7440: 
1.25      albertel 7441: sub add_to_env {
                   7442:   my ($name,$value)=@_;
1.258     albertel 7443:   if (defined($env{$name})) {
                   7444:     if (ref($env{$name})) {
1.25      albertel 7445:       #already have multiple values
1.258     albertel 7446:       push(@{ $env{$name} },$value);
1.25      albertel 7447:     } else {
                   7448:       #first time seeing multiple values, convert hash entry to an arrayref
1.258     albertel 7449:       my $first=$env{$name};
                   7450:       undef($env{$name});
                   7451:       push(@{ $env{$name} },$first,$value);
1.25      albertel 7452:     }
                   7453:   } else {
1.258     albertel 7454:     $env{$name}=$value;
1.25      albertel 7455:   }
1.31      albertel 7456: }
1.149     albertel 7457: 
                   7458: =pod
                   7459: 
1.648     raeburn  7460: =item * &get_env_multiple($name) 
1.149     albertel 7461: 
1.258     albertel 7462: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149     albertel 7463: values may be defined and end up as an array ref.
                   7464: 
                   7465: returns an array of values
                   7466: 
                   7467: =cut
                   7468: 
                   7469: sub get_env_multiple {
                   7470:     my ($name) = @_;
                   7471:     my @values;
1.258     albertel 7472:     if (defined($env{$name})) {
1.149     albertel 7473:         # exists is it an array
1.258     albertel 7474:         if (ref($env{$name})) {
                   7475:             @values=@{ $env{$name} };
1.149     albertel 7476:         } else {
1.258     albertel 7477:             $values[0]=$env{$name};
1.149     albertel 7478:         }
                   7479:     }
                   7480:     return(@values);
                   7481: }
                   7482: 
1.660     raeburn  7483: sub ask_for_embedded_content {
                   7484:     my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
                   7485:     my $upload_output = '
                   7486:    <form name="upload_embedded" action="'.$actionurl.'"
                   7487:                   method="post" enctype="multipart/form-data">';
                   7488:     $upload_output .= $state;
1.661     raeburn  7489:     $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
1.660     raeburn  7490: 
                   7491:     my $num = 0;
                   7492:     foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
                   7493:         $upload_output .= &start_data_table_row().
                   7494:             '<td>'.$embed_file.'</td><td>';
                   7495:         if ($args->{'ignore_remote_references'}
                   7496:             && $embed_file =~ m{^\w+://}) {
                   7497:             $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
                   7498:         } elsif ($args->{'error_on_invalid_names'}
                   7499:             && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
                   7500: 
                   7501:             $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
                   7502: 
                   7503:         } else {
                   7504:             $upload_output .='
1.661     raeburn  7505:            <input name="embedded_item_'.$num.'" type="file" value="" />
1.660     raeburn  7506:            <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
                   7507:             my $attrib = join(':',@{$$allfiles{$embed_file}});
                   7508:             $upload_output .=
                   7509:                 "\n\t\t".
                   7510:                 '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
                   7511:                 $attrib.'" />';
                   7512:             if (exists($$codebase{$embed_file})) {
                   7513:                 $upload_output .=
                   7514:                     "\n\t\t".
                   7515:                     '<input name="codebase_'.$num.'" type="hidden" value="'.
                   7516:                     &escape($$codebase{$embed_file}).'" />';
                   7517:             }
                   7518:         }
                   7519:         $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
                   7520:         $num++;
                   7521:     }
                   7522:     $upload_output .= &Apache::loncommon::end_data_table().'<br />
                   7523:    <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
                   7524:    <input type ="submit" value="'.&mt('Upload Listed Files').'" />
                   7525:    '.&mt('(only files for which a location has been provided will be uploaded)').'
                   7526:    </form>';
                   7527:     return $upload_output;
                   7528: }
                   7529: 
1.661     raeburn  7530: sub upload_embedded {
                   7531:     my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
                   7532:         $current_disk_usage) = @_;
                   7533:     my $output;
                   7534:     for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
                   7535:         next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
                   7536:         my $orig_uploaded_filename =
                   7537:             $env{'form.embedded_item_'.$i.'.filename'};
                   7538: 
                   7539:         $env{'form.embedded_orig_'.$i} =
                   7540:             &unescape($env{'form.embedded_orig_'.$i});
                   7541:         my ($path,$fname) =
                   7542:             ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
                   7543:         # no path, whole string is fname
                   7544:         if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
                   7545: 
                   7546:         $path = $env{'form.currentpath'}.$path;
                   7547:         $fname = &Apache::lonnet::clean_filename($fname);
                   7548:         # See if there is anything left
                   7549:         next if ($fname eq '');
                   7550: 
                   7551:         # Check if file already exists as a file or directory.
                   7552:         my ($state,$msg);
                   7553:         if ($context eq 'portfolio') {
                   7554:             my $port_path = $dirpath;
                   7555:             if ($group ne '') {
                   7556:                 $port_path = "groups/$group/$port_path";
                   7557:             }
                   7558:             ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
                   7559:                                               $dir_root,$port_path,$disk_quota,
                   7560:                                               $current_disk_usage,$uname,$udom);
                   7561:             if ($state eq 'will_exceed_quota'
                   7562:                 || $state eq 'file_locked'
                   7563:                 || $state eq 'file_exists' ) {
                   7564:                 $output .= $msg;
                   7565:                 next;
                   7566:             }
                   7567:         } elsif (($context eq 'author') || ($context eq 'testbank')) {
                   7568:             ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
                   7569:             if ($state eq 'exists') {
                   7570:                 $output .= $msg;
                   7571:                 next;
                   7572:             }
                   7573:         }
                   7574:         # Check if extension is valid
                   7575:         if (($fname =~ /\.(\w+)$/) &&
                   7576:             (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
                   7577:             $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
                   7578:             next;
                   7579:         } elsif (($fname =~ /\.(\w+)$/) &&
                   7580:                  (!defined(&Apache::loncommon::fileembstyle($1)))) {
                   7581:             $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
                   7582:             next;
                   7583:         } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
                   7584:             $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
                   7585:             next;
                   7586:         }
                   7587: 
                   7588:         $env{'form.embedded_item_'.$i.'.filename'}=$fname;
                   7589:         if ($context eq 'portfolio') {
                   7590:             my $result=
                   7591:                 &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
                   7592:                                                 $dirpath.$path);
                   7593:             if ($result !~ m|^/uploaded/|) {
                   7594:                 $output .= '<span class="LC_error">'
                   7595:                       .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
                   7596:                            ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
                   7597:                       .'</span><br />';
                   7598:                 next;
                   7599:             } else {
                   7600:                 $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
                   7601:                            $path.$fname.'</span>').'</p>';     
                   7602:             }
                   7603:         } else {
                   7604: # Save the file
                   7605:             my $target = $env{'form.embedded_item_'.$i};
                   7606:             my $fullpath = $dir_root.$dirpath.'/'.$path;
                   7607:             my $dest = $fullpath.$fname;
                   7608:             my $url = $url_root.$dirpath.'/'.$path.$fname;
                   7609:             my @parts=split(/\//,$fullpath);
                   7610:             my $count;
                   7611:             my $filepath = $dir_root;
                   7612:             for ($count=4;$count<=$#parts;$count++) {
                   7613:                 $filepath .= "/$parts[$count]";
                   7614:                 if ((-e $filepath)!=1) {
                   7615:                     mkdir($filepath,0770);
                   7616:                 }
                   7617:             }
                   7618:             my $fh;
                   7619:             if (!open($fh,'>'.$dest)) {
                   7620:                 &Apache::lonnet::logthis('Failed to create '.$dest);
                   7621:                 $output .= '<span class="LC_error">'.
                   7622:                            &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
                   7623:                            '</span><br />';
                   7624:             } else {
                   7625:                 if (!print $fh $env{'form.embedded_item_'.$i}) {
                   7626:                     &Apache::lonnet::logthis('Failed to write to '.$dest);
                   7627:                     $output .= '<span class="LC_error">'.
                   7628:                               &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
                   7629:                               '</span><br />';
                   7630:                 } else {
                   7631:                     if ($context eq 'testbank') {
                   7632:                         $output .= &mt('Embedded file uploaded successfully:').
                   7633:                                    '&nbsp;<a href="'.$url.'">'.
                   7634:                                    $orig_uploaded_filename.'</a><br />';
                   7635:                     } else {
                   7636:                         $output .= '<font size="+2">'.
                   7637:                                    &mt('View embedded file: [_1]','<a href="'.$url.'">'.
                   7638:                                    $orig_uploaded_filename.'</a>').'</font><br />';
                   7639:                     }
                   7640:                 }
                   7641:                 close($fh);
                   7642:             }
                   7643:         }
                   7644:     }
                   7645:     return $output;
                   7646: }
                   7647: 
                   7648: sub check_for_existing {
                   7649:     my ($path,$fname,$element) = @_;
                   7650:     my ($state,$msg);
                   7651:     if (-d $path.'/'.$fname) {
                   7652:         $state = 'exists';
                   7653:         $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
                   7654:     } elsif (-e $path.'/'.$fname) {
                   7655:         $state = 'exists';
                   7656:         $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
                   7657:     }
                   7658:     if ($state eq 'exists') {
                   7659:         $msg = '<span class="LC_error">'.$msg.'</span><br />';
                   7660:     }
                   7661:     return ($state,$msg);
                   7662: }
                   7663: 
                   7664: sub check_for_upload {
                   7665:     my ($path,$fname,$group,$element,$portfolio_root,$port_path,
                   7666:         $disk_quota,$current_disk_usage,$uname,$udom) = @_;
                   7667:     my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
                   7668:     my $getpropath = 1;
                   7669:     my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
                   7670:                                             $getpropath);
                   7671:     my $found_file = 0;
                   7672:     my $locked_file = 0;
                   7673:     foreach my $line (@dir_list) {
                   7674:         my ($file_name)=split(/\&/,$line,2);
                   7675:         if ($file_name eq $fname){
                   7676:             $file_name = $path.$file_name;
                   7677:             if ($group ne '') {
                   7678:                 $file_name = $group.$file_name;
                   7679:             }
                   7680:             $found_file = 1;
                   7681:             if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
                   7682:                 $locked_file = 1;
                   7683:             }
                   7684:         }
                   7685:     }
                   7686:     if (($current_disk_usage + $filesize) > $disk_quota){
                   7687:         my $msg = '<span class="LC_error">'.
                   7688:                 &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
                   7689:                   '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
                   7690:         return ('will_exceed_quota',$msg);
                   7691:     } elsif ($found_file) {
                   7692:         if ($locked_file) {
                   7693:             my $msg = '<span class="LC_error">';
                   7694:             $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>');
                   7695:             $msg .= '</span><br />';
                   7696:             $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
                   7697:             return ('file_locked',$msg);
                   7698:         } else {
                   7699:             my $msg = '<span class="LC_error">';
                   7700:             $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'});
                   7701:             $msg .= '</span>';
                   7702:             $msg .= '<br />';
                   7703:             $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
                   7704:             return ('file_exists',$msg);
                   7705:         }
                   7706:     }
                   7707: }
                   7708: 
1.31      albertel 7709: 
1.41      ng       7710: =pod
1.45      matthew  7711: 
1.464     albertel 7712: =back
1.41      ng       7713: 
1.112     bowersj2 7714: =head1 CSV Upload/Handling functions
1.38      albertel 7715: 
1.41      ng       7716: =over 4
                   7717: 
1.648     raeburn  7718: =item * &upfile_store($r)
1.41      ng       7719: 
                   7720: Store uploaded file, $r should be the HTTP Request object,
1.258     albertel 7721: needs $env{'form.upfile'}
1.41      ng       7722: returns $datatoken to be put into hidden field
                   7723: 
                   7724: =cut
1.31      albertel 7725: 
                   7726: sub upfile_store {
                   7727:     my $r=shift;
1.258     albertel 7728:     $env{'form.upfile'}=~s/\r/\n/gs;
                   7729:     $env{'form.upfile'}=~s/\f/\n/gs;
                   7730:     $env{'form.upfile'}=~s/\n+/\n/gs;
                   7731:     $env{'form.upfile'}=~s/\n+$//gs;
1.31      albertel 7732: 
1.258     albertel 7733:     my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
                   7734: 	'_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31      albertel 7735:     {
1.158     raeburn  7736:         my $datafile = $r->dir_config('lonDaemons').
                   7737:                            '/tmp/'.$datatoken.'.tmp';
                   7738:         if ( open(my $fh,">$datafile") ) {
1.258     albertel 7739:             print $fh $env{'form.upfile'};
1.158     raeburn  7740:             close($fh);
                   7741:         }
1.31      albertel 7742:     }
                   7743:     return $datatoken;
                   7744: }
                   7745: 
1.56      matthew  7746: =pod
                   7747: 
1.648     raeburn  7748: =item * &load_tmp_file($r)
1.41      ng       7749: 
                   7750: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258     albertel 7751: needs $env{'form.datatoken'},
                   7752: sets $env{'form.upfile'} to the contents of the file
1.41      ng       7753: 
                   7754: =cut
1.31      albertel 7755: 
                   7756: sub load_tmp_file {
                   7757:     my $r=shift;
                   7758:     my @studentdata=();
                   7759:     {
1.158     raeburn  7760:         my $studentfile = $r->dir_config('lonDaemons').
1.258     albertel 7761:                               '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158     raeburn  7762:         if ( open(my $fh,"<$studentfile") ) {
                   7763:             @studentdata=<$fh>;
                   7764:             close($fh);
                   7765:         }
1.31      albertel 7766:     }
1.258     albertel 7767:     $env{'form.upfile'}=join('',@studentdata);
1.31      albertel 7768: }
                   7769: 
1.56      matthew  7770: =pod
                   7771: 
1.648     raeburn  7772: =item * &upfile_record_sep()
1.41      ng       7773: 
                   7774: Separate uploaded file into records
                   7775: returns array of records,
1.258     albertel 7776: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41      ng       7777: 
                   7778: =cut
1.31      albertel 7779: 
                   7780: sub upfile_record_sep {
1.258     albertel 7781:     if ($env{'form.upfiletype'} eq 'xml') {
1.31      albertel 7782:     } else {
1.248     albertel 7783: 	my @records;
1.258     albertel 7784: 	foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248     albertel 7785: 	    if ($line=~/^\s*$/) { next; }
                   7786: 	    push(@records,$line);
                   7787: 	}
                   7788: 	return @records;
1.31      albertel 7789:     }
                   7790: }
                   7791: 
1.56      matthew  7792: =pod
                   7793: 
1.648     raeburn  7794: =item * &record_sep($record)
1.41      ng       7795: 
1.258     albertel 7796: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41      ng       7797: 
                   7798: =cut
                   7799: 
1.263     www      7800: sub takeleft {
                   7801:     my $index=shift;
                   7802:     return substr('0000'.$index,-4,4);
                   7803: }
                   7804: 
1.31      albertel 7805: sub record_sep {
                   7806:     my $record=shift;
                   7807:     my %components=();
1.258     albertel 7808:     if ($env{'form.upfiletype'} eq 'xml') {
                   7809:     } elsif ($env{'form.upfiletype'} eq 'space') {
1.31      albertel 7810:         my $i=0;
1.356     albertel 7811:         foreach my $field (split(/\s+/,$record)) {
1.31      albertel 7812:             $field=~s/^(\"|\')//;
                   7813:             $field=~s/(\"|\')$//;
1.263     www      7814:             $components{&takeleft($i)}=$field;
1.31      albertel 7815:             $i++;
                   7816:         }
1.258     albertel 7817:     } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31      albertel 7818:         my $i=0;
1.356     albertel 7819:         foreach my $field (split(/\t/,$record)) {
1.31      albertel 7820:             $field=~s/^(\"|\')//;
                   7821:             $field=~s/(\"|\')$//;
1.263     www      7822:             $components{&takeleft($i)}=$field;
1.31      albertel 7823:             $i++;
                   7824:         }
                   7825:     } else {
1.561     www      7826:         my $separator=',';
1.480     banghart 7827:         if ($env{'form.upfiletype'} eq 'semisv') {
1.561     www      7828:             $separator=';';
1.480     banghart 7829:         }
1.31      albertel 7830:         my $i=0;
1.561     www      7831: # the character we are looking for to indicate the end of a quote or a record 
                   7832:         my $looking_for=$separator;
                   7833: # do not add the characters to the fields
                   7834:         my $ignore=0;
                   7835: # we just encountered a separator (or the beginning of the record)
                   7836:         my $just_found_separator=1;
                   7837: # store the field we are working on here
                   7838:         my $field='';
                   7839: # work our way through all characters in record
                   7840:         foreach my $character ($record=~/(.)/g) {
                   7841:             if ($character eq $looking_for) {
                   7842:                if ($character ne $separator) {
                   7843: # Found the end of a quote, again looking for separator
                   7844:                   $looking_for=$separator;
                   7845:                   $ignore=1;
                   7846:                } else {
                   7847: # Found a separator, store away what we got
                   7848:                   $components{&takeleft($i)}=$field;
                   7849: 	          $i++;
                   7850:                   $just_found_separator=1;
                   7851:                   $ignore=0;
                   7852:                   $field='';
                   7853:                }
                   7854:                next;
                   7855:             }
                   7856: # single or double quotation marks after a separator indicate beginning of a quote
                   7857: # we are now looking for the end of the quote and need to ignore separators
                   7858:             if ((($character eq '"') || ($character eq "'")) && ($just_found_separator))  {
                   7859:                $looking_for=$character;
                   7860:                next;
                   7861:             }
                   7862: # ignore would be true after we reached the end of a quote
                   7863:             if ($ignore) { next; }
                   7864:             if (($just_found_separator) && ($character=~/\s/)) { next; }
                   7865:             $field.=$character;
                   7866:             $just_found_separator=0; 
1.31      albertel 7867:         }
1.561     www      7868: # catch the very last entry, since we never encountered the separator
                   7869:         $components{&takeleft($i)}=$field;
1.31      albertel 7870:     }
                   7871:     return %components;
                   7872: }
                   7873: 
1.144     matthew  7874: ######################################################
                   7875: ######################################################
                   7876: 
1.56      matthew  7877: =pod
                   7878: 
1.648     raeburn  7879: =item * &upfile_select_html()
1.41      ng       7880: 
1.144     matthew  7881: Return HTML code to select a file from the users machine and specify 
                   7882: the file type.
1.41      ng       7883: 
                   7884: =cut
                   7885: 
1.144     matthew  7886: ######################################################
                   7887: ######################################################
1.31      albertel 7888: sub upfile_select_html {
1.144     matthew  7889:     my %Types = (
                   7890:                  csv   => &mt('CSV (comma separated values, spreadsheet)'),
1.480     banghart 7891:                  semisv => &mt('Semicolon separated values'),
1.144     matthew  7892:                  space => &mt('Space separated'),
                   7893:                  tab   => &mt('Tabulator separated'),
                   7894: #                 xml   => &mt('HTML/XML'),
                   7895:                  );
                   7896:     my $Str = '<input type="file" name="upfile" size="50" />'.
                   7897:         '<br />Type: <select name="upfiletype">';
                   7898:     foreach my $type (sort(keys(%Types))) {
                   7899:         $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
                   7900:     }
                   7901:     $Str .= "</select>\n";
                   7902:     return $Str;
1.31      albertel 7903: }
                   7904: 
1.301     albertel 7905: sub get_samples {
                   7906:     my ($records,$toget) = @_;
                   7907:     my @samples=({});
                   7908:     my $got=0;
                   7909:     foreach my $rec (@$records) {
                   7910: 	my %temp = &record_sep($rec);
                   7911: 	if (! grep(/\S/, values(%temp))) { next; }
                   7912: 	if (%temp) {
                   7913: 	    $samples[$got]=\%temp;
                   7914: 	    $got++;
                   7915: 	    if ($got == $toget) { last; }
                   7916: 	}
                   7917:     }
                   7918:     return \@samples;
                   7919: }
                   7920: 
1.144     matthew  7921: ######################################################
                   7922: ######################################################
                   7923: 
1.56      matthew  7924: =pod
                   7925: 
1.648     raeburn  7926: =item * &csv_print_samples($r,$records)
1.41      ng       7927: 
                   7928: Prints a table of sample values from each column uploaded $r is an
                   7929: Apache Request ref, $records is an arrayref from
                   7930: &Apache::loncommon::upfile_record_sep
                   7931: 
                   7932: =cut
                   7933: 
1.144     matthew  7934: ######################################################
                   7935: ######################################################
1.31      albertel 7936: sub csv_print_samples {
                   7937:     my ($r,$records) = @_;
1.662     bisitz   7938:     my $samples = &get_samples($records,5);
1.301     albertel 7939: 
1.594     raeburn  7940:     $r->print(&mt('Samples').'<br />'.&start_data_table().
                   7941:               &start_data_table_header_row());
1.356     albertel 7942:     foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) { 
                   7943:         $r->print('<th>'.&mt('Column&nbsp;[_1]',($sample+1)).'</th>'); }
1.594     raeburn  7944:     $r->print(&end_data_table_header_row());
1.301     albertel 7945:     foreach my $hash (@$samples) {
1.594     raeburn  7946: 	$r->print(&start_data_table_row());
1.356     albertel 7947: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31      albertel 7948: 	    $r->print('<td>');
1.356     albertel 7949: 	    if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31      albertel 7950: 	    $r->print('</td>');
                   7951: 	}
1.594     raeburn  7952: 	$r->print(&end_data_table_row());
1.31      albertel 7953:     }
1.594     raeburn  7954:     $r->print(&end_data_table().'<br />'."\n");
1.31      albertel 7955: }
                   7956: 
1.144     matthew  7957: ######################################################
                   7958: ######################################################
                   7959: 
1.56      matthew  7960: =pod
                   7961: 
1.648     raeburn  7962: =item * &csv_print_select_table($r,$records,$d)
1.41      ng       7963: 
                   7964: Prints a table to create associations between values and table columns.
1.144     matthew  7965: 
1.41      ng       7966: $r is an Apache Request ref,
                   7967: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174     matthew  7968: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41      ng       7969: 
                   7970: =cut
                   7971: 
1.144     matthew  7972: ######################################################
                   7973: ######################################################
1.31      albertel 7974: sub csv_print_select_table {
                   7975:     my ($r,$records,$d) = @_;
1.301     albertel 7976:     my $i=0;
                   7977:     my $samples = &get_samples($records,1);
1.144     matthew  7978:     $r->print(&mt('Associate columns with student attributes.')."\n".
1.594     raeburn  7979: 	      &start_data_table().&start_data_table_header_row().
1.144     matthew  7980:               '<th>'.&mt('Attribute').'</th>'.
1.594     raeburn  7981:               '<th>'.&mt('Column').'</th>'.
                   7982:               &end_data_table_header_row()."\n");
1.356     albertel 7983:     foreach my $array_ref (@$d) {
                   7984: 	my ($value,$display,$defaultcol)=@{ $array_ref };
1.689     bisitz   7985: 	$r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31      albertel 7986: 
                   7987: 	$r->print('<td><select name=f'.$i.
1.32      matthew  7988: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.31      albertel 7989: 	$r->print('<option value="none"></option>');
1.356     albertel 7990: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
                   7991: 	    $r->print('<option value="'.$sample.'"'.
                   7992:                       ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662     bisitz   7993:                       '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31      albertel 7994: 	}
1.594     raeburn  7995: 	$r->print('</select></td>'.&end_data_table_row()."\n");
1.31      albertel 7996: 	$i++;
                   7997:     }
1.594     raeburn  7998:     $r->print(&end_data_table());
1.31      albertel 7999:     $i--;
                   8000:     return $i;
                   8001: }
1.56      matthew  8002: 
1.144     matthew  8003: ######################################################
                   8004: ######################################################
                   8005: 
1.56      matthew  8006: =pod
1.31      albertel 8007: 
1.648     raeburn  8008: =item * &csv_samples_select_table($r,$records,$d)
1.41      ng       8009: 
                   8010: Prints a table of sample values from the upload and can make associate samples to internal names.
                   8011: 
                   8012: $r is an Apache Request ref,
                   8013: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
                   8014: $d is an array of 2 element arrays (internal name, displayed name)
                   8015: 
                   8016: =cut
                   8017: 
1.144     matthew  8018: ######################################################
                   8019: ######################################################
1.31      albertel 8020: sub csv_samples_select_table {
                   8021:     my ($r,$records,$d) = @_;
                   8022:     my $i=0;
1.144     matthew  8023:     #
1.662     bisitz   8024:     my $max_samples = 5;
                   8025:     my $samples = &get_samples($records,$max_samples);
1.594     raeburn  8026:     $r->print(&start_data_table().
                   8027:               &start_data_table_header_row().'<th>'.
                   8028:               &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
                   8029:               &end_data_table_header_row());
1.301     albertel 8030: 
                   8031:     foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594     raeburn  8032: 	$r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32      matthew  8033: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.301     albertel 8034: 	foreach my $option (@$d) {
                   8035: 	    my ($value,$display,$defaultcol)=@{ $option };
1.174     matthew  8036: 	    $r->print('<option value="'.$value.'"'.
1.253     albertel 8037:                       ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174     matthew  8038:                       $display.'</option>');
1.31      albertel 8039: 	}
                   8040: 	$r->print('</select></td><td>');
1.662     bisitz   8041: 	foreach my $line (0..($max_samples-1)) {
1.301     albertel 8042: 	    if (defined($samples->[$line]{$key})) { 
                   8043: 		$r->print($samples->[$line]{$key}."<br />\n"); 
                   8044: 	    }
                   8045: 	}
1.594     raeburn  8046: 	$r->print('</td>'.&end_data_table_row());
1.31      albertel 8047: 	$i++;
                   8048:     }
1.594     raeburn  8049:     $r->print(&end_data_table());
1.31      albertel 8050:     $i--;
                   8051:     return($i);
1.115     matthew  8052: }
                   8053: 
1.144     matthew  8054: ######################################################
                   8055: ######################################################
                   8056: 
1.115     matthew  8057: =pod
                   8058: 
1.648     raeburn  8059: =item * &clean_excel_name($name)
1.115     matthew  8060: 
                   8061: Returns a replacement for $name which does not contain any illegal characters.
                   8062: 
                   8063: =cut
                   8064: 
1.144     matthew  8065: ######################################################
                   8066: ######################################################
1.115     matthew  8067: sub clean_excel_name {
                   8068:     my ($name) = @_;
                   8069:     $name =~ s/[:\*\?\/\\]//g;
                   8070:     if (length($name) > 31) {
                   8071:         $name = substr($name,0,31);
                   8072:     }
                   8073:     return $name;
1.25      albertel 8074: }
1.84      albertel 8075: 
1.85      albertel 8076: =pod
                   8077: 
1.648     raeburn  8078: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85      albertel 8079: 
                   8080: Returns either 1 or undef
                   8081: 
                   8082: 1 if the part is to be hidden, undef if it is to be shown
                   8083: 
                   8084: Arguments are:
                   8085: 
                   8086: $id the id of the part to be checked
                   8087: $symb, optional the symb of the resource to check
                   8088: $udom, optional the domain of the user to check for
                   8089: $uname, optional the username of the user to check for
                   8090: 
                   8091: =cut
1.84      albertel 8092: 
                   8093: sub check_if_partid_hidden {
                   8094:     my ($id,$symb,$udom,$uname) = @_;
1.133     albertel 8095:     my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84      albertel 8096: 					 $symb,$udom,$uname);
1.141     albertel 8097:     my $truth=1;
                   8098:     #if the string starts with !, then the list is the list to show not hide
                   8099:     if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84      albertel 8100:     my @hiddenlist=split(/,/,$hiddenparts);
                   8101:     foreach my $checkid (@hiddenlist) {
1.141     albertel 8102: 	if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84      albertel 8103:     }
1.141     albertel 8104:     return !$truth;
1.84      albertel 8105: }
1.127     matthew  8106: 
1.138     matthew  8107: 
                   8108: ############################################################
                   8109: ############################################################
                   8110: 
                   8111: =pod
                   8112: 
1.157     matthew  8113: =back 
                   8114: 
1.138     matthew  8115: =head1 cgi-bin script and graphing routines
                   8116: 
1.157     matthew  8117: =over 4
                   8118: 
1.648     raeburn  8119: =item * &get_cgi_id()
1.138     matthew  8120: 
                   8121: Inputs: none
                   8122: 
                   8123: Returns an id which can be used to pass environment variables
                   8124: to various cgi-bin scripts.  These environment variables will
                   8125: be removed from the users environment after a given time by
                   8126: the routine &Apache::lonnet::transfer_profile_to_env.
                   8127: 
                   8128: =cut
                   8129: 
                   8130: ############################################################
                   8131: ############################################################
1.152     albertel 8132: my $uniq=0;
1.136     matthew  8133: sub get_cgi_id {
1.154     albertel 8134:     $uniq=($uniq+1)%100000;
1.280     albertel 8135:     return (time.'_'.$$.'_'.$uniq);
1.136     matthew  8136: }
                   8137: 
1.127     matthew  8138: ############################################################
                   8139: ############################################################
                   8140: 
                   8141: =pod
                   8142: 
1.648     raeburn  8143: =item * &DrawBarGraph()
1.127     matthew  8144: 
1.138     matthew  8145: Facilitates the plotting of data in a (stacked) bar graph.
                   8146: Puts plot definition data into the users environment in order for 
                   8147: graph.png to plot it.  Returns an <img> tag for the plot.
                   8148: The bars on the plot are labeled '1','2',...,'n'.
                   8149: 
                   8150: Inputs:
                   8151: 
                   8152: =over 4
                   8153: 
                   8154: =item $Title: string, the title of the plot
                   8155: 
                   8156: =item $xlabel: string, text describing the X-axis of the plot
                   8157: 
                   8158: =item $ylabel: string, text describing the Y-axis of the plot
                   8159: 
                   8160: =item $Max: scalar, the maximum Y value to use in the plot
                   8161: If $Max is < any data point, the graph will not be rendered.
                   8162: 
1.140     matthew  8163: =item $colors: array ref holding the colors to be used for the data sets when
1.138     matthew  8164: they are plotted.  If undefined, default values will be used.
                   8165: 
1.178     matthew  8166: =item $labels: array ref holding the labels to use on the x-axis for the bars.
                   8167: 
1.138     matthew  8168: =item @Values: An array of array references.  Each array reference holds data
                   8169: to be plotted in a stacked bar chart.
                   8170: 
1.239     matthew  8171: =item If the final element of @Values is a hash reference the key/value
                   8172: pairs will be added to the graph definition.
                   8173: 
1.138     matthew  8174: =back
                   8175: 
                   8176: Returns:
                   8177: 
                   8178: An <img> tag which references graph.png and the appropriate identifying
                   8179: information for the plot.
                   8180: 
1.127     matthew  8181: =cut
                   8182: 
                   8183: ############################################################
                   8184: ############################################################
1.134     matthew  8185: sub DrawBarGraph {
1.178     matthew  8186:     my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134     matthew  8187:     #
                   8188:     if (! defined($colors)) {
                   8189:         $colors = ['#33ff00', 
                   8190:                   '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
                   8191:                   '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
                   8192:                   ]; 
                   8193:     }
1.228     matthew  8194:     my $extra_settings = {};
                   8195:     if (ref($Values[-1]) eq 'HASH') {
                   8196:         $extra_settings = pop(@Values);
                   8197:     }
1.127     matthew  8198:     #
1.136     matthew  8199:     my $identifier = &get_cgi_id();
                   8200:     my $id = 'cgi.'.$identifier;        
1.129     matthew  8201:     if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127     matthew  8202:         return '';
                   8203:     }
1.225     matthew  8204:     #
                   8205:     my @Labels;
                   8206:     if (defined($labels)) {
                   8207:         @Labels = @$labels;
                   8208:     } else {
                   8209:         for (my $i=0;$i<@{$Values[0]};$i++) {
                   8210:             push (@Labels,$i+1);
                   8211:         }
                   8212:     }
                   8213:     #
1.129     matthew  8214:     my $NumBars = scalar(@{$Values[0]});
1.225     matthew  8215:     if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129     matthew  8216:     my %ValuesHash;
                   8217:     my $NumSets=1;
                   8218:     foreach my $array (@Values) {
                   8219:         next if (! ref($array));
1.136     matthew  8220:         $ValuesHash{$id.'.data.'.$NumSets++} = 
1.132     matthew  8221:             join(',',@$array);
1.129     matthew  8222:     }
1.127     matthew  8223:     #
1.136     matthew  8224:     my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225     matthew  8225:     if ($NumBars < 3) {
                   8226:         $width = 120+$NumBars*32;
1.220     matthew  8227:         $xskip = 1;
1.225     matthew  8228:         $bar_width = 30;
                   8229:     } elsif ($NumBars < 5) {
                   8230:         $width = 120+$NumBars*20;
                   8231:         $xskip = 1;
                   8232:         $bar_width = 20;
1.220     matthew  8233:     } elsif ($NumBars < 10) {
1.136     matthew  8234:         $width = 120+$NumBars*15;
                   8235:         $xskip = 1;
                   8236:         $bar_width = 15;
                   8237:     } elsif ($NumBars <= 25) {
                   8238:         $width = 120+$NumBars*11;
                   8239:         $xskip = 5;
                   8240:         $bar_width = 8;
                   8241:     } elsif ($NumBars <= 50) {
                   8242:         $width = 120+$NumBars*8;
                   8243:         $xskip = 5;
                   8244:         $bar_width = 4;
                   8245:     } else {
                   8246:         $width = 120+$NumBars*8;
                   8247:         $xskip = 5;
                   8248:         $bar_width = 4;
                   8249:     }
                   8250:     #
1.137     matthew  8251:     $Max = 1 if ($Max < 1);
                   8252:     if ( int($Max) < $Max ) {
                   8253:         $Max++;
                   8254:         $Max = int($Max);
                   8255:     }
1.127     matthew  8256:     $Title  = '' if (! defined($Title));
                   8257:     $xlabel = '' if (! defined($xlabel));
                   8258:     $ylabel = '' if (! defined($ylabel));
1.369     www      8259:     $ValuesHash{$id.'.title'}    = &escape($Title);
                   8260:     $ValuesHash{$id.'.xlabel'}   = &escape($xlabel);
                   8261:     $ValuesHash{$id.'.ylabel'}   = &escape($ylabel);
1.137     matthew  8262:     $ValuesHash{$id.'.y_max_value'} = $Max;
1.136     matthew  8263:     $ValuesHash{$id.'.NumBars'}  = $NumBars;
                   8264:     $ValuesHash{$id.'.NumSets'}  = $NumSets;
                   8265:     $ValuesHash{$id.'.PlotType'} = 'bar';
                   8266:     $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   8267:     $ValuesHash{$id.'.height'}   = $height;
                   8268:     $ValuesHash{$id.'.width'}    = $width;
                   8269:     $ValuesHash{$id.'.xskip'}    = $xskip;
                   8270:     $ValuesHash{$id.'.bar_width'} = $bar_width;
                   8271:     $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127     matthew  8272:     #
1.228     matthew  8273:     # Deal with other parameters
                   8274:     while (my ($key,$value) = each(%$extra_settings)) {
                   8275:         $ValuesHash{$id.'.'.$key} = $value;
                   8276:     }
                   8277:     #
1.646     raeburn  8278:     &Apache::lonnet::appenv(\%ValuesHash);
1.137     matthew  8279:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   8280: }
                   8281: 
                   8282: ############################################################
                   8283: ############################################################
                   8284: 
                   8285: =pod
                   8286: 
1.648     raeburn  8287: =item * &DrawXYGraph()
1.137     matthew  8288: 
1.138     matthew  8289: Facilitates the plotting of data in an XY graph.
                   8290: Puts plot definition data into the users environment in order for 
                   8291: graph.png to plot it.  Returns an <img> tag for the plot.
                   8292: 
                   8293: Inputs:
                   8294: 
                   8295: =over 4
                   8296: 
                   8297: =item $Title: string, the title of the plot
                   8298: 
                   8299: =item $xlabel: string, text describing the X-axis of the plot
                   8300: 
                   8301: =item $ylabel: string, text describing the Y-axis of the plot
                   8302: 
                   8303: =item $Max: scalar, the maximum Y value to use in the plot
                   8304: If $Max is < any data point, the graph will not be rendered.
                   8305: 
                   8306: =item $colors: Array ref containing the hex color codes for the data to be 
                   8307: plotted in.  If undefined, default values will be used.
                   8308: 
                   8309: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   8310: 
                   8311: =item $Ydata: Array ref containing Array refs.  
1.185     www      8312: Each of the contained arrays will be plotted as a separate curve.
1.138     matthew  8313: 
                   8314: =item %Values: hash indicating or overriding any default values which are 
                   8315: passed to graph.png.  
                   8316: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   8317: 
                   8318: =back
                   8319: 
                   8320: Returns:
                   8321: 
                   8322: An <img> tag which references graph.png and the appropriate identifying
                   8323: information for the plot.
                   8324: 
1.137     matthew  8325: =cut
                   8326: 
                   8327: ############################################################
                   8328: ############################################################
                   8329: sub DrawXYGraph {
                   8330:     my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
                   8331:     #
                   8332:     # Create the identifier for the graph
                   8333:     my $identifier = &get_cgi_id();
                   8334:     my $id = 'cgi.'.$identifier;
                   8335:     #
                   8336:     $Title  = '' if (! defined($Title));
                   8337:     $xlabel = '' if (! defined($xlabel));
                   8338:     $ylabel = '' if (! defined($ylabel));
                   8339:     my %ValuesHash = 
                   8340:         (
1.369     www      8341:          $id.'.title'  => &escape($Title),
                   8342:          $id.'.xlabel' => &escape($xlabel),
                   8343:          $id.'.ylabel' => &escape($ylabel),
1.137     matthew  8344:          $id.'.y_max_value'=> $Max,
                   8345:          $id.'.labels'     => join(',',@$Xlabels),
                   8346:          $id.'.PlotType'   => 'XY',
                   8347:          );
                   8348:     #
                   8349:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   8350:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   8351:     }
                   8352:     #
                   8353:     if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
                   8354:         return '';
                   8355:     }
                   8356:     my $NumSets=1;
1.138     matthew  8357:     foreach my $array (@{$Ydata}){
1.137     matthew  8358:         next if (! ref($array));
                   8359:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
                   8360:     }
1.138     matthew  8361:     $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137     matthew  8362:     #
                   8363:     # Deal with other parameters
                   8364:     while (my ($key,$value) = each(%Values)) {
                   8365:         $ValuesHash{$id.'.'.$key} = $value;
1.127     matthew  8366:     }
                   8367:     #
1.646     raeburn  8368:     &Apache::lonnet::appenv(\%ValuesHash);
1.136     matthew  8369:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   8370: }
                   8371: 
                   8372: ############################################################
                   8373: ############################################################
                   8374: 
                   8375: =pod
                   8376: 
1.648     raeburn  8377: =item * &DrawXYYGraph()
1.138     matthew  8378: 
                   8379: Facilitates the plotting of data in an XY graph with two Y axes.
                   8380: Puts plot definition data into the users environment in order for 
                   8381: graph.png to plot it.  Returns an <img> tag for the plot.
                   8382: 
                   8383: Inputs:
                   8384: 
                   8385: =over 4
                   8386: 
                   8387: =item $Title: string, the title of the plot
                   8388: 
                   8389: =item $xlabel: string, text describing the X-axis of the plot
                   8390: 
                   8391: =item $ylabel: string, text describing the Y-axis of the plot
                   8392: 
                   8393: =item $colors: Array ref containing the hex color codes for the data to be 
                   8394: plotted in.  If undefined, default values will be used.
                   8395: 
                   8396: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   8397: 
                   8398: =item $Ydata1: The first data set
                   8399: 
                   8400: =item $Min1: The minimum value of the left Y-axis
                   8401: 
                   8402: =item $Max1: The maximum value of the left Y-axis
                   8403: 
                   8404: =item $Ydata2: The second data set
                   8405: 
                   8406: =item $Min2: The minimum value of the right Y-axis
                   8407: 
                   8408: =item $Max2: The maximum value of the left Y-axis
                   8409: 
                   8410: =item %Values: hash indicating or overriding any default values which are 
                   8411: passed to graph.png.  
                   8412: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   8413: 
                   8414: =back
                   8415: 
                   8416: Returns:
                   8417: 
                   8418: An <img> tag which references graph.png and the appropriate identifying
                   8419: information for the plot.
1.136     matthew  8420: 
                   8421: =cut
                   8422: 
                   8423: ############################################################
                   8424: ############################################################
1.137     matthew  8425: sub DrawXYYGraph {
                   8426:     my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
                   8427:                                         $Ydata2,$Min2,$Max2,%Values)=@_;
1.136     matthew  8428:     #
                   8429:     # Create the identifier for the graph
                   8430:     my $identifier = &get_cgi_id();
                   8431:     my $id = 'cgi.'.$identifier;
                   8432:     #
                   8433:     $Title  = '' if (! defined($Title));
                   8434:     $xlabel = '' if (! defined($xlabel));
                   8435:     $ylabel = '' if (! defined($ylabel));
                   8436:     my %ValuesHash = 
                   8437:         (
1.369     www      8438:          $id.'.title'  => &escape($Title),
                   8439:          $id.'.xlabel' => &escape($xlabel),
                   8440:          $id.'.ylabel' => &escape($ylabel),
1.136     matthew  8441:          $id.'.labels' => join(',',@$Xlabels),
                   8442:          $id.'.PlotType' => 'XY',
                   8443:          $id.'.NumSets' => 2,
1.137     matthew  8444:          $id.'.two_axes' => 1,
                   8445:          $id.'.y1_max_value' => $Max1,
                   8446:          $id.'.y1_min_value' => $Min1,
                   8447:          $id.'.y2_max_value' => $Max2,
                   8448:          $id.'.y2_min_value' => $Min2,
1.136     matthew  8449:          );
                   8450:     #
1.137     matthew  8451:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   8452:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   8453:     }
                   8454:     #
                   8455:     if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
                   8456:         ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136     matthew  8457:         return '';
                   8458:     }
                   8459:     my $NumSets=1;
1.137     matthew  8460:     foreach my $array ($Ydata1,$Ydata2){
1.136     matthew  8461:         next if (! ref($array));
                   8462:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137     matthew  8463:     }
                   8464:     #
                   8465:     # Deal with other parameters
                   8466:     while (my ($key,$value) = each(%Values)) {
                   8467:         $ValuesHash{$id.'.'.$key} = $value;
1.136     matthew  8468:     }
                   8469:     #
1.646     raeburn  8470:     &Apache::lonnet::appenv(\%ValuesHash);
1.130     albertel 8471:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139     matthew  8472: }
                   8473: 
                   8474: ############################################################
                   8475: ############################################################
                   8476: 
                   8477: =pod
                   8478: 
1.157     matthew  8479: =back 
                   8480: 
1.139     matthew  8481: =head1 Statistics helper routines?  
                   8482: 
                   8483: Bad place for them but what the hell.
                   8484: 
1.157     matthew  8485: =over 4
                   8486: 
1.648     raeburn  8487: =item * &chartlink()
1.139     matthew  8488: 
                   8489: Returns a link to the chart for a specific student.  
                   8490: 
                   8491: Inputs:
                   8492: 
                   8493: =over 4
                   8494: 
                   8495: =item $linktext: The text of the link
                   8496: 
                   8497: =item $sname: The students username
                   8498: 
                   8499: =item $sdomain: The students domain
                   8500: 
                   8501: =back
                   8502: 
1.157     matthew  8503: =back
                   8504: 
1.139     matthew  8505: =cut
                   8506: 
                   8507: ############################################################
                   8508: ############################################################
                   8509: sub chartlink {
                   8510:     my ($linktext, $sname, $sdomain) = @_;
                   8511:     my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369     www      8512:         '&amp;SelectedStudent='.&escape($sname.':'.$sdomain).
1.219     albertel 8513:         '&amp;chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139     matthew  8514:        '">'.$linktext.'</a>';
1.153     matthew  8515: }
                   8516: 
                   8517: #######################################################
                   8518: #######################################################
                   8519: 
                   8520: =pod
                   8521: 
                   8522: =head1 Course Environment Routines
1.157     matthew  8523: 
                   8524: =over 4
1.153     matthew  8525: 
1.648     raeburn  8526: =item * &restore_course_settings()
1.153     matthew  8527: 
1.648     raeburn  8528: =item * &store_course_settings()
1.153     matthew  8529: 
                   8530: Restores/Store indicated form parameters from the course environment.
                   8531: Will not overwrite existing values of the form parameters.
                   8532: 
                   8533: Inputs: 
                   8534: a scalar describing the data (e.g. 'chart', 'problem_analysis')
                   8535: 
                   8536: a hash ref describing the data to be stored.  For example:
                   8537:    
                   8538: %Save_Parameters = ('Status' => 'scalar',
                   8539:     'chartoutputmode' => 'scalar',
                   8540:     'chartoutputdata' => 'scalar',
                   8541:     'Section' => 'array',
1.373     raeburn  8542:     'Group' => 'array',
1.153     matthew  8543:     'StudentData' => 'array',
                   8544:     'Maps' => 'array');
                   8545: 
                   8546: Returns: both routines return nothing
                   8547: 
1.631     raeburn  8548: =back
                   8549: 
1.153     matthew  8550: =cut
                   8551: 
                   8552: #######################################################
                   8553: #######################################################
                   8554: sub store_course_settings {
1.496     albertel 8555:     return &store_settings($env{'request.course.id'},@_);
                   8556: }
                   8557: 
                   8558: sub store_settings {
1.153     matthew  8559:     # save to the environment
                   8560:     # appenv the same items, just to be safe
1.300     albertel 8561:     my $udom  = $env{'user.domain'};
                   8562:     my $uname = $env{'user.name'};
1.496     albertel 8563:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  8564:     my %SaveHash;
                   8565:     my %AppHash;
                   8566:     while (my ($setting,$type) = each(%$Settings)) {
1.496     albertel 8567:         my $basename = join('.','internal',$context,$prefix,$setting);
1.300     albertel 8568:         my $envname = 'environment.'.$basename;
1.258     albertel 8569:         if (exists($env{'form.'.$setting})) {
1.153     matthew  8570:             # Save this value away
                   8571:             if ($type eq 'scalar' &&
1.258     albertel 8572:                 (! exists($env{$envname}) || 
                   8573:                  $env{$envname} ne $env{'form.'.$setting})) {
                   8574:                 $SaveHash{$basename} = $env{'form.'.$setting};
                   8575:                 $AppHash{$envname}   = $env{'form.'.$setting};
1.153     matthew  8576:             } elsif ($type eq 'array') {
                   8577:                 my $stored_form;
1.258     albertel 8578:                 if (ref($env{'form.'.$setting})) {
1.153     matthew  8579:                     $stored_form = join(',',
                   8580:                                         map {
1.369     www      8581:                                             &escape($_);
1.258     albertel 8582:                                         } sort(@{$env{'form.'.$setting}}));
1.153     matthew  8583:                 } else {
                   8584:                     $stored_form = 
1.369     www      8585:                         &escape($env{'form.'.$setting});
1.153     matthew  8586:                 }
                   8587:                 # Determine if the array contents are the same.
1.258     albertel 8588:                 if ($stored_form ne $env{$envname}) {
1.153     matthew  8589:                     $SaveHash{$basename} = $stored_form;
                   8590:                     $AppHash{$envname}   = $stored_form;
                   8591:                 }
                   8592:             }
                   8593:         }
                   8594:     }
                   8595:     my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300     albertel 8596:                                           $udom,$uname);
1.153     matthew  8597:     if ($put_result !~ /^(ok|delayed)/) {
                   8598:         &Apache::lonnet::logthis('unable to save form parameters, '.
                   8599:                                  'got error:'.$put_result);
                   8600:     }
                   8601:     # Make sure these settings stick around in this session, too
1.646     raeburn  8602:     &Apache::lonnet::appenv(\%AppHash);
1.153     matthew  8603:     return;
                   8604: }
                   8605: 
                   8606: sub restore_course_settings {
1.499     albertel 8607:     return &restore_settings($env{'request.course.id'},@_);
1.496     albertel 8608: }
                   8609: 
                   8610: sub restore_settings {
                   8611:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  8612:     while (my ($setting,$type) = each(%$Settings)) {
1.258     albertel 8613:         next if (exists($env{'form.'.$setting}));
1.496     albertel 8614:         my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153     matthew  8615:             '.'.$setting;
1.258     albertel 8616:         if (exists($env{$envname})) {
1.153     matthew  8617:             if ($type eq 'scalar') {
1.258     albertel 8618:                 $env{'form.'.$setting} = $env{$envname};
1.153     matthew  8619:             } elsif ($type eq 'array') {
1.258     albertel 8620:                 $env{'form.'.$setting} = [ 
1.153     matthew  8621:                                            map { 
1.369     www      8622:                                                &unescape($_); 
1.258     albertel 8623:                                            } split(',',$env{$envname})
1.153     matthew  8624:                                            ];
                   8625:             }
                   8626:         }
                   8627:     }
1.127     matthew  8628: }
                   8629: 
1.618     raeburn  8630: #######################################################
                   8631: #######################################################
                   8632: 
                   8633: =pod
                   8634: 
                   8635: =head1 Domain E-mail Routines  
                   8636: 
                   8637: =over 4
                   8638: 
1.648     raeburn  8639: =item * &build_recipient_list()
1.618     raeburn  8640: 
                   8641: Build recipient lists for three types of e-mail:
                   8642: (a) Error Reports, (b) Package Updates, (c) Help requests, generated by
1.619     raeburn  8643: lonerrorhandler.pm, CHECKRPMS and lonsupportreq.pm respectively.
1.618     raeburn  8644: 
                   8645: Inputs:
1.619     raeburn  8646: defmail (scalar - email address of default recipient), 
1.618     raeburn  8647: mailing type (scalar - errormail, packagesmail, or helpdeskmail), 
1.619     raeburn  8648: defdom (domain for which to retrieve configuration settings),
                   8649: origmail (scalar - email address of recipient from loncapa.conf, 
                   8650: i.e., predates configuration by DC via domainprefs.pm 
1.618     raeburn  8651: 
1.655     raeburn  8652: Returns: comma separated list of addresses to which to send e-mail.
                   8653: 
                   8654: =back
1.618     raeburn  8655: 
                   8656: =cut
                   8657: 
                   8658: ############################################################
                   8659: ############################################################
                   8660: sub build_recipient_list {
1.619     raeburn  8661:     my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618     raeburn  8662:     my @recipients;
                   8663:     my $otheremails;
                   8664:     my %domconfig =
                   8665:          &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
                   8666:     if (ref($domconfig{'contacts'}) eq 'HASH') {
                   8667:         if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
                   8668:             my @contacts = ('adminemail','supportemail');
                   8669:             foreach my $item (@contacts) {
                   8670:                 if ($domconfig{'contacts'}{$mailing}{$item}) {
1.619     raeburn  8671:                     my $addr = $domconfig{'contacts'}{$item}; 
                   8672:                     if (!grep(/^\Q$addr\E$/,@recipients)) {
                   8673:                         push(@recipients,$addr);
                   8674:                     }
1.618     raeburn  8675:                 }
                   8676:                 $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
                   8677:             }
                   8678:         }
1.619     raeburn  8679:     } elsif ($origmail ne '') {
                   8680:         push(@recipients,$origmail);
1.618     raeburn  8681:     }
1.688     raeburn  8682:     if (defined($defmail)) {
                   8683:         if ($defmail ne '') {
                   8684:             push(@recipients,$defmail);
                   8685:         }
1.618     raeburn  8686:     }
                   8687:     if ($otheremails) {
1.619     raeburn  8688:         my @others;
                   8689:         if ($otheremails =~ /,/) {
                   8690:             @others = split(/,/,$otheremails);
1.618     raeburn  8691:         } else {
1.619     raeburn  8692:             push(@others,$otheremails);
                   8693:         }
                   8694:         foreach my $addr (@others) {
                   8695:             if (!grep(/^\Q$addr\E$/,@recipients)) {
                   8696:                 push(@recipients,$addr);
                   8697:             }
1.618     raeburn  8698:         }
                   8699:     }
1.619     raeburn  8700:     my $recipientlist = join(',',@recipients); 
1.618     raeburn  8701:     return $recipientlist;
                   8702: }
                   8703: 
1.127     matthew  8704: ############################################################
                   8705: ############################################################
1.154     albertel 8706: 
1.655     raeburn  8707: =pod
                   8708: 
                   8709: =head1 Course Catalog Routines
                   8710: 
                   8711: =over 4
                   8712: 
                   8713: =item * &gather_categories()
                   8714: 
                   8715: Converts category definitions - keys of categories hash stored in  
                   8716: coursecategories in configuration.db on the primary library server in a 
                   8717: domain - to an array.  Also generates javascript and idx hash used to 
                   8718: generate Domain Coordinator interface for editing Course Categories.
                   8719: 
                   8720: Inputs:
1.663     raeburn  8721: 
1.655     raeburn  8722: categories (reference to hash of category definitions).
1.663     raeburn  8723: 
1.655     raeburn  8724: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   8725:       categories and subcategories).
1.663     raeburn  8726: 
1.655     raeburn  8727: idx (reference to hash of counters used in Domain Coordinator interface for 
                   8728:       editing Course Categories).
1.663     raeburn  8729: 
1.655     raeburn  8730: jsarray (reference to array of categories used to create Javascript arrays for
                   8731:          Domain Coordinator interface for editing Course Categories).
                   8732: 
                   8733: Returns: nothing
                   8734: 
                   8735: Side effects: populates cats, idx and jsarray. 
                   8736: 
                   8737: =cut
                   8738: 
                   8739: sub gather_categories {
                   8740:     my ($categories,$cats,$idx,$jsarray) = @_;
                   8741:     my %counters;
                   8742:     my $num = 0;
                   8743:     foreach my $item (keys(%{$categories})) {
                   8744:         my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
                   8745:         if ($container eq '' && $depth == 0) {
                   8746:             $cats->[$depth][$categories->{$item}] = $cat;
                   8747:         } else {
                   8748:             $cats->[$depth]{$container}[$categories->{$item}] = $cat;
                   8749:         }
                   8750:         my ($escitem,$tail) = split(/:/,$item,2);
                   8751:         if ($counters{$tail} eq '') {
                   8752:             $counters{$tail} = $num;
                   8753:             $num ++;
                   8754:         }
                   8755:         if (ref($idx) eq 'HASH') {
                   8756:             $idx->{$item} = $counters{$tail};
                   8757:         }
                   8758:         if (ref($jsarray) eq 'ARRAY') {
                   8759:             push(@{$jsarray->[$counters{$tail}]},$item);
                   8760:         }
                   8761:     }
                   8762:     return;
                   8763: }
                   8764: 
                   8765: =pod
                   8766: 
                   8767: =item * &extract_categories()
                   8768: 
                   8769: Used to generate breadcrumb trails for course categories.
                   8770: 
                   8771: Inputs:
1.663     raeburn  8772: 
1.655     raeburn  8773: categories (reference to hash of category definitions).
1.663     raeburn  8774: 
1.655     raeburn  8775: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   8776:       categories and subcategories).
1.663     raeburn  8777: 
1.655     raeburn  8778: trails (reference to array of breacrumb trails for each category).
1.663     raeburn  8779: 
1.655     raeburn  8780: allitems (reference to hash - key is category key 
                   8781:          (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663     raeburn  8782: 
1.655     raeburn  8783: idx (reference to hash of counters used in Domain Coordinator interface for
                   8784:       editing Course Categories).
1.663     raeburn  8785: 
1.655     raeburn  8786: jsarray (reference to array of categories used to create Javascript arrays for
                   8787:          Domain Coordinator interface for editing Course Categories).
                   8788: 
1.665     raeburn  8789: subcats (reference to hash of arrays containing all subcategories within each 
                   8790:          category, -recursive)
                   8791: 
1.655     raeburn  8792: Returns: nothing
                   8793: 
                   8794: Side effects: populates trails and allitems hash references.
                   8795: 
                   8796: =cut
                   8797: 
                   8798: sub extract_categories {
1.665     raeburn  8799:     my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655     raeburn  8800:     if (ref($categories) eq 'HASH') {
                   8801:         &gather_categories($categories,$cats,$idx,$jsarray);
                   8802:         if (ref($cats->[0]) eq 'ARRAY') {
                   8803:             for (my $i=0; $i<@{$cats->[0]}; $i++) {
                   8804:                 my $name = $cats->[0][$i];
                   8805:                 my $item = &escape($name).'::0';
                   8806:                 my $trailstr;
                   8807:                 if ($name eq 'instcode') {
                   8808:                     $trailstr = &mt('Official courses (with institutional codes)');
                   8809:                 } else {
                   8810:                     $trailstr = $name;
                   8811:                 }
                   8812:                 if ($allitems->{$item} eq '') {
                   8813:                     push(@{$trails},$trailstr);
                   8814:                     $allitems->{$item} = scalar(@{$trails})-1;
                   8815:                 }
                   8816:                 my @parents = ($name);
                   8817:                 if (ref($cats->[1]{$name}) eq 'ARRAY') {
                   8818:                     for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
                   8819:                         my $category = $cats->[1]{$name}[$j];
1.665     raeburn  8820:                         if (ref($subcats) eq 'HASH') {
                   8821:                             push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
                   8822:                         }
                   8823:                         &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
                   8824:                     }
                   8825:                 } else {
                   8826:                     if (ref($subcats) eq 'HASH') {
                   8827:                         $subcats->{$item} = [];
1.655     raeburn  8828:                     }
                   8829:                 }
                   8830:             }
                   8831:         }
                   8832:     }
                   8833:     return;
                   8834: }
                   8835: 
                   8836: =pod
                   8837: 
                   8838: =item *&recurse_categories()
                   8839: 
                   8840: Recursively used to generate breadcrumb trails for course categories.
                   8841: 
                   8842: Inputs:
1.663     raeburn  8843: 
1.655     raeburn  8844: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   8845:       categories and subcategories).
1.663     raeburn  8846: 
1.655     raeburn  8847: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663     raeburn  8848: 
                   8849: category (current course category, for which breadcrumb trail is being generated).
                   8850: 
                   8851: trails (reference to array of breadcrumb trails for each category).
                   8852: 
1.655     raeburn  8853: allitems (reference to hash - key is category key
                   8854:          (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663     raeburn  8855: 
1.655     raeburn  8856: parents (array containing containers directories for current category, 
                   8857:          back to top level). 
                   8858: 
                   8859: Returns: nothing
                   8860: 
                   8861: Side effects: populates trails and allitems hash references
                   8862: 
                   8863: =cut
                   8864: 
                   8865: sub recurse_categories {
1.665     raeburn  8866:     my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655     raeburn  8867:     my $shallower = $depth - 1;
                   8868:     if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
                   8869:         for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
                   8870:             my $name = $cats->[$depth]{$category}[$k];
                   8871:             my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
                   8872:             my $trailstr = join(' -&gt; ',(@{$parents},$category));
                   8873:             if ($allitems->{$item} eq '') {
                   8874:                 push(@{$trails},$trailstr);
                   8875:                 $allitems->{$item} = scalar(@{$trails})-1;
                   8876:             }
                   8877:             my $deeper = $depth+1;
                   8878:             push(@{$parents},$category);
1.665     raeburn  8879:             if (ref($subcats) eq 'HASH') {
                   8880:                 my $subcat = &escape($name).':'.$category.':'.$depth;
                   8881:                 for (my $j=@{$parents}; $j>=0; $j--) {
                   8882:                     my $higher;
                   8883:                     if ($j > 0) {
                   8884:                         $higher = &escape($parents->[$j]).':'.
                   8885:                                   &escape($parents->[$j-1]).':'.$j;
                   8886:                     } else {
                   8887:                         $higher = &escape($parents->[$j]).'::'.$j;
                   8888:                     }
                   8889:                     push(@{$subcats->{$higher}},$subcat);
                   8890:                 }
                   8891:             }
                   8892:             &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
                   8893:                                 $subcats);
1.655     raeburn  8894:             pop(@{$parents});
                   8895:         }
                   8896:     } else {
                   8897:         my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
                   8898:         my $trailstr = join(' -&gt; ',(@{$parents},$category));
                   8899:         if ($allitems->{$item} eq '') {
                   8900:             push(@{$trails},$trailstr);
                   8901:             $allitems->{$item} = scalar(@{$trails})-1;
                   8902:         }
                   8903:     }
                   8904:     return;
                   8905: }
                   8906: 
1.663     raeburn  8907: =pod
                   8908: 
                   8909: =item *&assign_categories_table()
                   8910: 
                   8911: Create a datatable for display of hierarchical categories in a domain,
                   8912: with checkboxes to allow a course to be categorized. 
                   8913: 
                   8914: Inputs:
                   8915: 
                   8916: cathash - reference to hash of categories defined for the domain (from
                   8917:           configuration.db)
                   8918: 
                   8919: currcat - scalar with an & separated list of categories assigned to a course. 
                   8920: 
                   8921: Returns: $output (markup to be displayed) 
                   8922: 
                   8923: =cut
                   8924: 
                   8925: sub assign_categories_table {
                   8926:     my ($cathash,$currcat) = @_;
                   8927:     my $output;
                   8928:     if (ref($cathash) eq 'HASH') {
                   8929:         my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
                   8930:         &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
                   8931:         $maxdepth = scalar(@cats);
                   8932:         if (@cats > 0) {
                   8933:             my $itemcount = 0;
                   8934:             if (ref($cats[0]) eq 'ARRAY') {
                   8935:                 $output = &Apache::loncommon::start_data_table();
                   8936:                 my @currcategories;
                   8937:                 if ($currcat ne '') {
                   8938:                     @currcategories = split('&',$currcat);
                   8939:                 }
                   8940:                 for (my $i=0; $i<@{$cats[0]}; $i++) {
                   8941:                     my $parent = $cats[0][$i];
                   8942:                     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   8943:                     next if ($parent eq 'instcode');
                   8944:                     my $item = &escape($parent).'::0';
                   8945:                     my $checked = '';
                   8946:                     if (@currcategories > 0) {
                   8947:                         if (grep(/^\Q$item\E$/,@currcategories)) {
                   8948:                             $checked = ' checked="checked" ';
                   8949:                         }
                   8950:                     }
1.675     raeburn  8951:                     $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
                   8952:                                '<input type="checkbox" name="usecategory" value="'.
                   8953:                                $item.'"'.$checked.' />'.$parent.'</span>'.
                   8954:                                '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663     raeburn  8955:                     my $depth = 1;
                   8956:                     push(@path,$parent);
                   8957:                     $output .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
                   8958:                     pop(@path);
                   8959:                     $output .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
                   8960:                     $itemcount ++;
                   8961:                 }
                   8962:                 $output .= &Apache::loncommon::end_data_table();
                   8963:             }
                   8964:         }
                   8965:     }
                   8966:     return $output;
                   8967: }
                   8968: 
                   8969: =pod
                   8970: 
                   8971: =item *&assign_category_rows()
                   8972: 
                   8973: Create a datatable row for display of nested categories in a domain,
                   8974: with checkboxes to allow a course to be categorized,called recursively.
                   8975: 
                   8976: Inputs:
                   8977: 
                   8978: itemcount - track row number for alternating colors
                   8979: 
                   8980: cats - reference to array of arrays/hashes which encapsulates hierarchy of
                   8981:       categories and subcategories.
                   8982: 
                   8983: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
                   8984: 
                   8985: parent - parent of current category item
                   8986: 
                   8987: path - Array containing all categories back up through the hierarchy from the
                   8988:        current category to the top level.
                   8989: 
                   8990: currcategories - reference to array of current categories assigned to the course
                   8991: 
                   8992: Returns: $output (markup to be displayed).
                   8993: 
                   8994: =cut
                   8995: 
                   8996: sub assign_category_rows {
                   8997:     my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
                   8998:     my ($text,$name,$item,$chgstr);
                   8999:     if (ref($cats) eq 'ARRAY') {
                   9000:         my $maxdepth = scalar(@{$cats});
                   9001:         if (ref($cats->[$depth]) eq 'HASH') {
                   9002:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   9003:                 my $numchildren = @{$cats->[$depth]{$parent}};
                   9004:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   9005:                 $text .= '<td><table class="LC_datatable">';
                   9006:                 for (my $j=0; $j<$numchildren; $j++) {
                   9007:                     $name = $cats->[$depth]{$parent}[$j];
                   9008:                     $item = &escape($name).':'.&escape($parent).':'.$depth;
                   9009:                     my $deeper = $depth+1;
                   9010:                     my $checked = '';
                   9011:                     if (ref($currcategories) eq 'ARRAY') {
                   9012:                         if (@{$currcategories} > 0) {
                   9013:                             if (grep(/^\Q$item\E$/,@{$currcategories})) {
                   9014:                                 $checked = ' checked="checked" ';
                   9015:                             }
                   9016:                         }
                   9017:                     }
1.664     raeburn  9018:                     $text .= '<tr><td><span class="LC_nobreak"><label>'.
                   9019:                              '<input type="checkbox" name="usecategory" value="'.
1.675     raeburn  9020:                              $item.'"'.$checked.' />'.$name.'</label></span>'.
                   9021:                              '<input type="hidden" name="catname" value="'.$name.'" />'.
                   9022:                              '</td><td>';
1.663     raeburn  9023:                     if (ref($path) eq 'ARRAY') {
                   9024:                         push(@{$path},$name);
                   9025:                         $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
                   9026:                         pop(@{$path});
                   9027:                     }
                   9028:                     $text .= '</td></tr>';
                   9029:                 }
                   9030:                 $text .= '</table></td>';
                   9031:             }
                   9032:         }
                   9033:     }
                   9034:     return $text;
                   9035: }
                   9036: 
1.655     raeburn  9037: ############################################################
                   9038: ############################################################
                   9039: 
                   9040: 
1.443     albertel 9041: sub commit_customrole {
1.664     raeburn  9042:     my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630     raeburn  9043:     my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443     albertel 9044:                          ($start?', '.&mt('starting').' '.localtime($start):'').
                   9045:                          ($end?', ending '.localtime($end):'').': <b>'.
                   9046:               &Apache::lonnet::assigncustomrole(
1.664     raeburn  9047:                  $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443     albertel 9048:                  '</b><br />';
                   9049:     return $output;
                   9050: }
                   9051: 
                   9052: sub commit_standardrole {
1.541     raeburn  9053:     my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
                   9054:     my ($output,$logmsg,$linefeed);
                   9055:     if ($context eq 'auto') {
                   9056:         $linefeed = "\n";
                   9057:     } else {
                   9058:         $linefeed = "<br />\n";
                   9059:     }  
1.443     albertel 9060:     if ($three eq 'st') {
1.541     raeburn  9061:         my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
                   9062:                                          $one,$two,$sec,$context);
                   9063:         if (($result =~ /^error/) || ($result eq 'not_in_class') || 
1.626     raeburn  9064:             ($result eq 'unknown_course') || ($result eq 'refused')) {
                   9065:             $output = $logmsg.' '.&mt('Error: ').$result."\n"; 
1.443     albertel 9066:         } else {
1.541     raeburn  9067:             $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443     albertel 9068:                ($start?', '.&mt('starting').' '.localtime($start):'').
1.541     raeburn  9069:                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
                   9070:             if ($context eq 'auto') {
                   9071:                 $output .= $result.$linefeed.&mt('Add to classlist').': ok';
                   9072:             } else {
                   9073:                $output .= '<b>'.$result.'</b>'.$linefeed.
                   9074:                &mt('Add to classlist').': <b>ok</b>';
                   9075:             }
                   9076:             $output .= $linefeed;
1.443     albertel 9077:         }
                   9078:     } else {
                   9079:         $output = &mt('Assigning').' '.$three.' in '.$url.
                   9080:                ($start?', '.&mt('starting').' '.localtime($start):'').
1.541     raeburn  9081:                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652     raeburn  9082:         my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541     raeburn  9083:         if ($context eq 'auto') {
                   9084:             $output .= $result.$linefeed;
                   9085:         } else {
                   9086:             $output .= '<b>'.$result.'</b>'.$linefeed;
                   9087:         }
1.443     albertel 9088:     }
                   9089:     return $output;
                   9090: }
                   9091: 
                   9092: sub commit_studentrole {
1.541     raeburn  9093:     my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626     raeburn  9094:     my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541     raeburn  9095:     if ($context eq 'auto') {
                   9096:         $linefeed = "\n";
                   9097:     } else {
                   9098:         $linefeed = '<br />'."\n";
                   9099:     }
1.443     albertel 9100:     if (defined($one) && defined($two)) {
                   9101:         my $cid=$one.'_'.$two;
                   9102:         my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
                   9103:         my $secchange = 0;
                   9104:         my $expire_role_result;
                   9105:         my $modify_section_result;
1.628     raeburn  9106:         if ($oldsec ne '-1') { 
                   9107:             if ($oldsec ne $sec) {
1.443     albertel 9108:                 $secchange = 1;
1.628     raeburn  9109:                 my $now = time;
1.443     albertel 9110:                 my $uurl='/'.$cid;
                   9111:                 $uurl=~s/\_/\//g;
                   9112:                 if ($oldsec) {
                   9113:                     $uurl.='/'.$oldsec;
                   9114:                 }
1.626     raeburn  9115:                 $oldsecurl = $uurl;
1.628     raeburn  9116:                 $expire_role_result = 
1.652     raeburn  9117:                     &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628     raeburn  9118:                 if ($env{'request.course.sec'} ne '') { 
                   9119:                     if ($expire_role_result eq 'refused') {
                   9120:                         my @roles = ('st');
                   9121:                         my @statuses = ('previous');
                   9122:                         my @roledoms = ($one);
                   9123:                         my $withsec = 1;
                   9124:                         my %roleshash = 
                   9125:                             &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
                   9126:                                               \@statuses,\@roles,\@roledoms,$withsec);
                   9127:                         if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
                   9128:                             my ($oldstart,$oldend) = 
                   9129:                                 split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
                   9130:                             if ($oldend > 0 && $oldend <= $now) {
                   9131:                                 $expire_role_result = 'ok';
                   9132:                             }
                   9133:                         }
                   9134:                     }
                   9135:                 }
1.443     albertel 9136:                 $result = $expire_role_result;
                   9137:             }
                   9138:         }
                   9139:         if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652     raeburn  9140:             $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443     albertel 9141:             if ($modify_section_result =~ /^ok/) {
                   9142:                 if ($secchange == 1) {
1.628     raeburn  9143:                     if ($sec eq '') {
                   9144:                         $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
                   9145:                     } else {
                   9146:                         $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
                   9147:                     }
1.443     albertel 9148:                 } elsif ($oldsec eq '-1') {
1.628     raeburn  9149:                     if ($sec eq '') {
                   9150:                         $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
                   9151:                     } else {
                   9152:                         $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                   9153:                     }
1.443     albertel 9154:                 } else {
1.628     raeburn  9155:                     if ($sec eq '') {
                   9156:                         $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
                   9157:                     } else {
                   9158:                         $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                   9159:                     }
1.443     albertel 9160:                 }
                   9161:             } else {
1.628     raeburn  9162:                 if ($secchange) {       
                   9163:                     $$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;
                   9164:                 } else {
                   9165:                     $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
                   9166:                 }
1.443     albertel 9167:             }
                   9168:             $result = $modify_section_result;
                   9169:         } elsif ($secchange == 1) {
1.628     raeburn  9170:             if ($oldsec eq '') {
                   9171:                 $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
                   9172:             } else {
                   9173:                 $$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;
                   9174:             }
1.626     raeburn  9175:             if ($expire_role_result eq 'refused') {
                   9176:                 my $newsecurl = '/'.$cid;
                   9177:                 $newsecurl =~ s/\_/\//g;
                   9178:                 if ($sec ne '') {
                   9179:                     $newsecurl.='/'.$sec;
                   9180:                 }
                   9181:                 if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
                   9182:                     if ($sec eq '') {
                   9183:                         $$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;
                   9184:                     } else {
                   9185:                         $$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;
                   9186:                     }
                   9187:                 }
                   9188:             }
1.443     albertel 9189:         }
                   9190:     } else {
1.626     raeburn  9191:         $$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 9192:         $result = "error: incomplete course id\n";
                   9193:     }
                   9194:     return $result;
                   9195: }
                   9196: 
                   9197: ############################################################
                   9198: ############################################################
                   9199: 
1.566     albertel 9200: sub check_clone {
1.578     raeburn  9201:     my ($args,$linefeed) = @_;
1.566     albertel 9202:     my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
                   9203:     my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
                   9204:     my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
                   9205:     my $clonemsg;
                   9206:     my $can_clone = 0;
                   9207: 
                   9208:     if ($clonehome eq 'no_host') {
1.578     raeburn  9209:         $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 9210:     } else {
                   9211: 	my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.568     albertel 9212: 	if ($env{'request.role.domain'} eq $args->{'clonedomain'}) {
1.566     albertel 9213: 	    $can_clone = 1;
                   9214: 	} else {
                   9215: 	    my %clonehash = &Apache::lonnet::get('environment',['cloners'],
                   9216: 						 $args->{'clonedomain'},$args->{'clonecourse'});
                   9217: 	    my @cloners = split(/,/,$clonehash{'cloners'});
1.578     raeburn  9218:             if (grep(/^\*$/,@cloners)) {
                   9219:                 $can_clone = 1;
                   9220:             } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
                   9221:                 $can_clone = 1;
                   9222:             } else {
                   9223: 	        my %roleshash =
                   9224: 		    &Apache::lonnet::get_my_roles($args->{'ccuname'},
                   9225: 					 $args->{'ccdomain'},
                   9226:                                          'userroles',['active'],['cc'],
                   9227: 					 [$args->{'clonedomain'}]);
                   9228: 	        if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
                   9229: 		    $can_clone = 1;
                   9230: 	        } else {
                   9231:                     $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'});
                   9232: 	        }
1.566     albertel 9233: 	    }
1.578     raeburn  9234:         }
1.566     albertel 9235:     }
                   9236:     return ($can_clone, $clonemsg, $cloneid, $clonehome);
                   9237: }
                   9238: 
1.444     albertel 9239: sub construct_course {
1.541     raeburn  9240:     my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context) = @_;
1.444     albertel 9241:     my $outcome;
1.541     raeburn  9242:     my $linefeed =  '<br />'."\n";
                   9243:     if ($context eq 'auto') {
                   9244:         $linefeed = "\n";
                   9245:     }
1.566     albertel 9246: 
                   9247: #
                   9248: # Are we cloning?
                   9249: #
                   9250:     my ($can_clone, $clonemsg, $cloneid, $clonehome);
                   9251:     if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578     raeburn  9252: 	($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566     albertel 9253: 	if ($context ne 'auto') {
1.578     raeburn  9254:             if ($clonemsg ne '') {
                   9255: 	        $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
                   9256:             }
1.566     albertel 9257: 	}
                   9258: 	$outcome .= $clonemsg.$linefeed;
                   9259: 
                   9260:         if (!$can_clone) {
                   9261: 	    return (0,$outcome);
                   9262: 	}
                   9263:     }
                   9264: 
1.444     albertel 9265: #
                   9266: # Open course
                   9267: #
                   9268:     my $crstype = lc($args->{'crstype'});
                   9269:     my %cenv=();
                   9270:     $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
                   9271:                                              $args->{'cdescr'},
                   9272:                                              $args->{'curl'},
                   9273:                                              $args->{'course_home'},
                   9274:                                              $args->{'nonstandard'},
                   9275:                                              $args->{'crscode'},
                   9276:                                              $args->{'ccuname'}.':'.
                   9277:                                              $args->{'ccdomain'},
                   9278:                                              $args->{'crstype'});
                   9279: 
                   9280:     # Note: The testing routines depend on this being output; see 
                   9281:     # Utils::Course. This needs to at least be output as a comment
                   9282:     # if anyone ever decides to not show this, and Utils::Course::new
                   9283:     # will need to be suitably modified.
1.541     raeburn  9284:     $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.444     albertel 9285: #
                   9286: # Check if created correctly
                   9287: #
1.479     albertel 9288:     ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444     albertel 9289:     my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.541     raeburn  9290:     $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566     albertel 9291: 
1.444     albertel 9292: #
1.566     albertel 9293: # Do the cloning
                   9294: #   
                   9295:     if ($can_clone && $cloneid) {
                   9296: 	$clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
                   9297: 	if ($context ne 'auto') {
                   9298: 	    $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
                   9299: 	}
                   9300: 	$outcome .= $clonemsg.$linefeed;
                   9301: 	my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444     albertel 9302: # Copy all files
1.637     www      9303: 	&Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444     albertel 9304: # Restore URL
1.566     albertel 9305: 	$cenv{'url'}=$oldcenv{'url'};
1.444     albertel 9306: # Restore title
1.566     albertel 9307: 	$cenv{'description'}=$oldcenv{'description'};
1.444     albertel 9308: # Mark as cloned
1.566     albertel 9309: 	$cenv{'clonedfrom'}=$cloneid;
1.638     www      9310: # Need to clone grading mode
                   9311:         my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
                   9312:         $cenv{'grading'}=$newenv{'grading'};
                   9313: # Do not clone these environment entries
                   9314:         &Apache::lonnet::del('environment',
                   9315:                   ['default_enrollment_start_date',
                   9316:                    'default_enrollment_end_date',
                   9317:                    'question.email',
                   9318:                    'policy.email',
                   9319:                    'comment.email',
                   9320:                    'pch.users.denied',
                   9321:                    'plc.users.denied'],
                   9322:                    $$crsudom,$$crsunum);
1.444     albertel 9323:     }
1.566     albertel 9324: 
1.444     albertel 9325: #
                   9326: # Set environment (will override cloned, if existing)
                   9327: #
                   9328:     my @sections = ();
                   9329:     my @xlists = ();
                   9330:     if ($args->{'crstype'}) {
                   9331:         $cenv{'type'}=$args->{'crstype'};
                   9332:     }
                   9333:     if ($args->{'crsid'}) {
                   9334:         $cenv{'courseid'}=$args->{'crsid'};
                   9335:     }
                   9336:     if ($args->{'crscode'}) {
                   9337:         $cenv{'internal.coursecode'}=$args->{'crscode'};
                   9338:     }
                   9339:     if ($args->{'crsquota'} ne '') {
                   9340:         $cenv{'internal.coursequota'}=$args->{'crsquota'};
                   9341:     } else {
                   9342:         $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
                   9343:     }
                   9344:     if ($args->{'ccuname'}) {
                   9345:         $cenv{'internal.courseowner'} = $args->{'ccuname'}.
                   9346:                                         ':'.$args->{'ccdomain'};
                   9347:     } else {
                   9348:         $cenv{'internal.courseowner'} = $args->{'curruser'};
                   9349:     }
                   9350:     my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
                   9351:     if ($args->{'crssections'}) {
                   9352:         $cenv{'internal.sectionnums'} = '';
                   9353:         if ($args->{'crssections'} =~ m/,/) {
                   9354:             @sections = split/,/,$args->{'crssections'};
                   9355:         } else {
                   9356:             $sections[0] = $args->{'crssections'};
                   9357:         }
                   9358:         if (@sections > 0) {
                   9359:             foreach my $item (@sections) {
                   9360:                 my ($sec,$gp) = split/:/,$item;
                   9361:                 my $class = $args->{'crscode'}.$sec;
                   9362:                 my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
                   9363:                 $cenv{'internal.sectionnums'} .= $item.',';
                   9364:                 unless ($addcheck eq 'ok') {
                   9365:                     push @badclasses, $class;
                   9366:                 }
                   9367:             }
                   9368:             $cenv{'internal.sectionnums'} =~ s/,$//;
                   9369:         }
                   9370:     }
                   9371: # do not hide course coordinator from staff listing, 
                   9372: # even if privileged
                   9373:     $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   9374: # add crosslistings
                   9375:     if ($args->{'crsxlist'}) {
                   9376:         $cenv{'internal.crosslistings'}='';
                   9377:         if ($args->{'crsxlist'} =~ m/,/) {
                   9378:             @xlists = split/,/,$args->{'crsxlist'};
                   9379:         } else {
                   9380:             $xlists[0] = $args->{'crsxlist'};
                   9381:         }
                   9382:         if (@xlists > 0) {
                   9383:             foreach my $item (@xlists) {
                   9384:                 my ($xl,$gp) = split/:/,$item;
                   9385:                 my $addcheck =  &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
                   9386:                 $cenv{'internal.crosslistings'} .= $item.',';
                   9387:                 unless ($addcheck eq 'ok') {
                   9388:                     push @badclasses, $xl;
                   9389:                 }
                   9390:             }
                   9391:             $cenv{'internal.crosslistings'} =~ s/,$//;
                   9392:         }
                   9393:     }
                   9394:     if ($args->{'autoadds'}) {
                   9395:         $cenv{'internal.autoadds'}=$args->{'autoadds'};
                   9396:     }
                   9397:     if ($args->{'autodrops'}) {
                   9398:         $cenv{'internal.autodrops'}=$args->{'autodrops'};
                   9399:     }
                   9400: # check for notification of enrollment changes
                   9401:     my @notified = ();
                   9402:     if ($args->{'notify_owner'}) {
                   9403:         if ($args->{'ccuname'} ne '') {
                   9404:             push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
                   9405:         }
                   9406:     }
                   9407:     if ($args->{'notify_dc'}) {
                   9408:         if ($uname ne '') { 
1.630     raeburn  9409:             push(@notified,$uname.':'.$udom);
1.444     albertel 9410:         }
                   9411:     }
                   9412:     if (@notified > 0) {
                   9413:         my $notifylist;
                   9414:         if (@notified > 1) {
                   9415:             $notifylist = join(',',@notified);
                   9416:         } else {
                   9417:             $notifylist = $notified[0];
                   9418:         }
                   9419:         $cenv{'internal.notifylist'} = $notifylist;
                   9420:     }
                   9421:     if (@badclasses > 0) {
                   9422:         my %lt=&Apache::lonlocal::texthash(
                   9423:                 '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',
                   9424:                 'dnhr' => 'does not have rights to access enrollment in these classes',
                   9425:                 'adby' => 'as determined by the policies of your institution on access to official classlists'
                   9426:         );
1.541     raeburn  9427:         my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
                   9428:                            ' ('.$lt{'adby'}.')';
                   9429:         if ($context eq 'auto') {
                   9430:             $outcome .= $badclass_msg.$linefeed;
1.566     albertel 9431:             $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541     raeburn  9432:             foreach my $item (@badclasses) {
                   9433:                 if ($context eq 'auto') {
                   9434:                     $outcome .= " - $item\n";
                   9435:                 } else {
                   9436:                     $outcome .= "<li>$item</li>\n";
                   9437:                 }
                   9438:             }
                   9439:             if ($context eq 'auto') {
                   9440:                 $outcome .= $linefeed;
                   9441:             } else {
1.566     albertel 9442:                 $outcome .= "</ul><br /><br /></div>\n";
1.541     raeburn  9443:             }
                   9444:         } 
1.444     albertel 9445:     }
                   9446:     if ($args->{'no_end_date'}) {
                   9447:         $args->{'endaccess'} = 0;
                   9448:     }
                   9449:     $cenv{'internal.autostart'}=$args->{'enrollstart'};
                   9450:     $cenv{'internal.autoend'}=$args->{'enrollend'};
                   9451:     $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
                   9452:     $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
                   9453:     if ($args->{'showphotos'}) {
                   9454:       $cenv{'internal.showphotos'}=$args->{'showphotos'};
                   9455:     }
                   9456:     $cenv{'internal.authtype'} = $args->{'authtype'};
                   9457:     $cenv{'internal.autharg'} = $args->{'autharg'}; 
                   9458:     if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
                   9459:         if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'}  eq '') {
1.541     raeburn  9460:             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'); 
                   9461:             if ($context eq 'auto') {
                   9462:                 $outcome .= $krb_msg;
                   9463:             } else {
1.566     albertel 9464:                 $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541     raeburn  9465:             }
                   9466:             $outcome .= $linefeed;
1.444     albertel 9467:         }
                   9468:     }
                   9469:     if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
                   9470:        if ($args->{'setpolicy'}) {
                   9471:            $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   9472:        }
                   9473:        if ($args->{'setcontent'}) {
                   9474:            $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   9475:        }
                   9476:     }
                   9477:     if ($args->{'reshome'}) {
                   9478: 	$cenv{'reshome'}=$args->{'reshome'}.'/';
                   9479: 	$cenv{'reshome'}=~s/\/+$/\//;
                   9480:     }
                   9481: #
                   9482: # course has keyed access
                   9483: #
                   9484:     if ($args->{'setkeys'}) {
                   9485:        $cenv{'keyaccess'}='yes';
                   9486:     }
                   9487: # if specified, key authority is not course, but user
                   9488: # only active if keyaccess is yes
                   9489:     if ($args->{'keyauth'}) {
1.487     albertel 9490: 	my ($user,$domain) = split(':',$args->{'keyauth'});
                   9491: 	$user = &LONCAPA::clean_username($user);
                   9492: 	$domain = &LONCAPA::clean_username($domain);
1.488     foxr     9493: 	if ($user ne '' && $domain ne '') {
1.487     albertel 9494: 	    $cenv{'keyauth'}=$user.':'.$domain;
1.444     albertel 9495: 	}
                   9496:     }
                   9497: 
                   9498:     if ($args->{'disresdis'}) {
                   9499:         $cenv{'pch.roles.denied'}='st';
                   9500:     }
                   9501:     if ($args->{'disablechat'}) {
                   9502:         $cenv{'plc.roles.denied'}='st';
                   9503:     }
                   9504: 
                   9505:     # Record we've not yet viewed the Course Initialization Helper for this 
                   9506:     # course
                   9507:     $cenv{'course.helper.not.run'} = 1;
                   9508:     #
                   9509:     # Use new Randomseed
                   9510:     #
                   9511:     $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
                   9512:     $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
                   9513:     #
                   9514:     # The encryption code and receipt prefix for this course
                   9515:     #
                   9516:     $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
                   9517:     $cenv{'internal.encpref'}=100+int(9*rand(99));
                   9518:     #
                   9519:     # By default, use standard grading
                   9520:     if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
                   9521: 
1.541     raeburn  9522:     $outcome .= $linefeed.&mt('Setting environment').': '.                 
                   9523:           &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444     albertel 9524: #
                   9525: # Open all assignments
                   9526: #
                   9527:     if ($args->{'openall'}) {
                   9528:        my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
                   9529:        my %storecontent = ($storeunder         => time,
                   9530:                            $storeunder.'.type' => 'date_start');
                   9531:        
                   9532:        $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541     raeburn  9533:                  ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444     albertel 9534:    }
                   9535: #
                   9536: # Set first page
                   9537: #
                   9538:     unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
                   9539: 	    || ($cloneid)) {
1.445     albertel 9540: 	use LONCAPA::map;
1.444     albertel 9541: 	$outcome .= &mt('Setting first resource').': ';
1.445     albertel 9542: 
                   9543: 	my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
                   9544:         my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
                   9545: 
1.444     albertel 9546:         $outcome .= ($fatal?$errtext:'read ok').' - ';
                   9547:         my $title; my $url;
                   9548:         if ($args->{'firstres'} eq 'syl') {
1.690     bisitz   9549: 	    $title=&mt('Syllabus');
1.444     albertel 9550:             $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
                   9551:         } else {
1.690     bisitz   9552:             $title=&mt('Navigate Contents');
1.444     albertel 9553:             $url='/adm/navmaps';
                   9554:         }
1.445     albertel 9555: 
                   9556:         $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
                   9557: 	(my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
                   9558: 
                   9559: 	if ($errtext) { $fatal=2; }
1.541     raeburn  9560:         $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444     albertel 9561:     }
1.566     albertel 9562: 
                   9563:     return (1,$outcome);
1.444     albertel 9564: }
                   9565: 
                   9566: ############################################################
                   9567: ############################################################
                   9568: 
1.378     raeburn  9569: sub course_type {
                   9570:     my ($cid) = @_;
                   9571:     if (!defined($cid)) {
                   9572:         $cid = $env{'request.course.id'};
                   9573:     }
1.404     albertel 9574:     if (defined($env{'course.'.$cid.'.type'})) {
                   9575:         return $env{'course.'.$cid.'.type'};
1.378     raeburn  9576:     } else {
                   9577:         return 'Course';
1.377     raeburn  9578:     }
                   9579: }
1.156     albertel 9580: 
1.406     raeburn  9581: sub group_term {
                   9582:     my $crstype = &course_type();
                   9583:     my %names = (
                   9584:                   'Course' => 'group',
                   9585:                   'Group' => 'team',
                   9586:                 );
                   9587:     return $names{$crstype};
                   9588: }
                   9589: 
1.156     albertel 9590: sub icon {
                   9591:     my ($file)=@_;
1.505     albertel 9592:     my $curfext = lc((split(/\./,$file))[-1]);
1.168     albertel 9593:     my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156     albertel 9594:     my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168     albertel 9595:     if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
                   9596: 	if (-e  $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
                   9597: 	          $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   9598: 	            $curfext.".gif") {
                   9599: 	    $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   9600: 		$curfext.".gif";
                   9601: 	}
                   9602:     }
1.249     albertel 9603:     return &lonhttpdurl($iconname);
1.154     albertel 9604: } 
1.84      albertel 9605: 
1.575     albertel 9606: sub lonhttpdurl {
1.692     www      9607: #
                   9608: # Had been used for "small fry" static images on separate port 8080.
                   9609: # Modify here if lightweight http functionality desired again.
                   9610: # Currently eliminated due to increasing firewall issues.
                   9611: #
1.575     albertel 9612:     my ($url)=@_;
1.692     www      9613:     return $url;
1.215     albertel 9614: }
                   9615: 
1.213     albertel 9616: sub connection_aborted {
                   9617:     my ($r)=@_;
                   9618:     $r->print(" ");$r->rflush();
                   9619:     my $c = $r->connection;
                   9620:     return $c->aborted();
                   9621: }
                   9622: 
1.221     foxr     9623: #    Escapes strings that may have embedded 's that will be put into
1.222     foxr     9624: #    strings as 'strings'.
                   9625: sub escape_single {
1.221     foxr     9626:     my ($input) = @_;
1.223     albertel 9627:     $input =~ s/\\/\\\\/g;	# Escape the \'s..(must be first)>
1.221     foxr     9628:     $input =~ s/\'/\\\'/g;	# Esacpe the 's....
                   9629:     return $input;
                   9630: }
1.223     albertel 9631: 
1.222     foxr     9632: #  Same as escape_single, but escape's "'s  This 
                   9633: #  can be used for  "strings"
                   9634: sub escape_double {
                   9635:     my ($input) = @_;
                   9636:     $input =~ s/\\/\\\\/g;	# Escape the /'s..(must be first)>
                   9637:     $input =~ s/\"/\\\"/g;	# Esacpe the "s....
                   9638:     return $input;
                   9639: }
1.223     albertel 9640:  
1.222     foxr     9641: #   Escapes the last element of a full URL.
                   9642: sub escape_url {
                   9643:     my ($url)   = @_;
1.238     raeburn  9644:     my @urlslices = split(/\//, $url,-1);
1.369     www      9645:     my $lastitem = &escape(pop(@urlslices));
1.223     albertel 9646:     return join('/',@urlslices).'/'.$lastitem;
1.222     foxr     9647: }
1.462     albertel 9648: 
                   9649: # -------------------------------------------------------- Initliaze user login
                   9650: sub init_user_environment {
1.463     albertel 9651:     my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462     albertel 9652:     my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
                   9653: 
                   9654:     my $public=($username eq 'public' && $domain eq 'public');
                   9655: 
                   9656: # See if old ID present, if so, remove
                   9657: 
                   9658:     my ($filename,$cookie,$userroles);
                   9659:     my $now=time;
                   9660: 
                   9661:     if ($public) {
                   9662: 	my $max_public=100;
                   9663: 	my $oldest;
                   9664: 	my $oldest_time=0;
                   9665: 	for(my $next=1;$next<=$max_public;$next++) {
                   9666: 	    if (-e $lonids."/publicuser_$next.id") {
                   9667: 		my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
                   9668: 		if ($mtime<$oldest_time || !$oldest_time) {
                   9669: 		    $oldest_time=$mtime;
                   9670: 		    $oldest=$next;
                   9671: 		}
                   9672: 	    } else {
                   9673: 		$cookie="publicuser_$next";
                   9674: 		last;
                   9675: 	    }
                   9676: 	}
                   9677: 	if (!$cookie) { $cookie="publicuser_$oldest"; }
                   9678:     } else {
1.463     albertel 9679: 	# if this isn't a robot, kill any existing non-robot sessions
                   9680: 	if (!$args->{'robot'}) {
                   9681: 	    opendir(DIR,$lonids);
                   9682: 	    while ($filename=readdir(DIR)) {
                   9683: 		if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
                   9684: 		    unlink($lonids.'/'.$filename);
                   9685: 		}
1.462     albertel 9686: 	    }
1.463     albertel 9687: 	    closedir(DIR);
1.462     albertel 9688: 	}
                   9689: # Give them a new cookie
1.463     albertel 9690: 	my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684     www      9691: 		                   : $now.$$.int(rand(10000)));
1.463     albertel 9692: 	$cookie="$username\_$id\_$domain\_$authhost";
1.462     albertel 9693:     
                   9694: # Initialize roles
                   9695: 
                   9696: 	$userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
                   9697:     }
                   9698: # ------------------------------------ Check browser type and MathML capability
                   9699: 
                   9700:     my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
                   9701:         $clientunicode,$clientos) = &decode_user_agent($r);
                   9702: 
                   9703: # -------------------------------------- Any accessibility options to remember?
                   9704:     if (($form->{'interface'}) && ($form->{'remember'} eq 'true')) {
                   9705: 	foreach my $option ('imagesuppress','appletsuppress',
                   9706: 			    'embedsuppress','fontenhance','blackwhite') {
                   9707: 	    if ($form->{$option} eq 'true') {
                   9708: 		&Apache::lonnet::put('environment',{$option => 'on'},
                   9709: 				     $domain,$username);
                   9710: 	    } else {
                   9711: 		&Apache::lonnet::del('environment',[$option],
                   9712: 				     $domain,$username);
                   9713: 	    }
                   9714: 	}
                   9715:     }
                   9716: # ------------------------------------------------------------- Get environment
                   9717: 
                   9718:     my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
                   9719:     my ($tmp) = keys(%userenv);
                   9720:     if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   9721: 	# default remote control to off
                   9722: 	if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
                   9723:     } else {
                   9724: 	undef(%userenv);
                   9725:     }
                   9726:     if (($userenv{'interface'}) && (!$form->{'interface'})) {
                   9727: 	$form->{'interface'}=$userenv{'interface'};
                   9728:     }
                   9729:     $env{'environment.remote'}=$userenv{'remote'};
                   9730:     if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
                   9731: 
                   9732: # --------------- Do not trust query string to be put directly into environment
                   9733:     foreach my $option ('imagesuppress','appletsuppress',
                   9734: 			'embedsuppress','fontenhance','blackwhite',
                   9735: 			'interface','localpath','localres') {
                   9736: 	$form->{$option}=~s/[\n\r\=]//gs;
                   9737:     }
                   9738: # --------------------------------------------------------- Write first profile
                   9739: 
                   9740:     {
                   9741: 	my %initial_env = 
                   9742: 	    ("user.name"          => $username,
                   9743: 	     "user.domain"        => $domain,
                   9744: 	     "user.home"          => $authhost,
                   9745: 	     "browser.type"       => $clientbrowser,
                   9746: 	     "browser.version"    => $clientversion,
                   9747: 	     "browser.mathml"     => $clientmathml,
                   9748: 	     "browser.unicode"    => $clientunicode,
                   9749: 	     "browser.os"         => $clientos,
                   9750: 	     "server.domain"      => $Apache::lonnet::perlvar{'lonDefDomain'},
                   9751: 	     "request.course.fn"  => '',
                   9752: 	     "request.course.uri" => '',
                   9753: 	     "request.course.sec" => '',
                   9754: 	     "request.role"       => 'cm',
                   9755: 	     "request.role.adv"   => $env{'user.adv'},
                   9756: 	     "request.host"       => $ENV{'REMOTE_ADDR'},);
                   9757: 
                   9758:         if ($form->{'localpath'}) {
                   9759: 	    $initial_env{"browser.localpath"}  = $form->{'localpath'};
                   9760: 	    $initial_env{"browser.localres"}   = $form->{'localres'};
                   9761:         }
                   9762: 	
                   9763: 	if ($public) {
                   9764: 	    $initial_env{"environment.remote"} = "off";
                   9765: 	}
                   9766: 	if ($form->{'interface'}) {
                   9767: 	    $form->{'interface'}=~s/\W//gs;
                   9768: 	    $initial_env{"browser.interface"} = $form->{'interface'};
                   9769: 	    $env{'browser.interface'}=$form->{'interface'};
                   9770: 	    foreach my $option ('imagesuppress','appletsuppress',
                   9771: 				'embedsuppress','fontenhance','blackwhite') {
                   9772: 		if (($form->{$option} eq 'true') ||
                   9773: 		    ($userenv{$option} eq 'on')) {
                   9774: 		    $initial_env{"browser.$option"} = "on";
                   9775: 		}
                   9776: 	    }
                   9777: 	}
                   9778: 
                   9779: 	$env{'user.environment'} = "$lonids/$cookie.id";
                   9780: 	
                   9781: 	if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
                   9782: 		 &GDBM_WRCREAT(),0640)) {
                   9783: 	    &_add_to_env(\%disk_env,\%initial_env);
                   9784: 	    &_add_to_env(\%disk_env,\%userenv,'environment.');
                   9785: 	    &_add_to_env(\%disk_env,$userroles);
1.463     albertel 9786: 	    if (ref($args->{'extra_env'})) {
                   9787: 		&_add_to_env(\%disk_env,$args->{'extra_env'});
                   9788: 	    }
1.462     albertel 9789: 	    untie(%disk_env);
                   9790: 	} else {
                   9791: 	    &Apache::lonnet::logthis("<font color=\"blue\">WARNING: ".
                   9792: 			   'Could not create environment storage in lonauth: '.$!.'</font>');
                   9793: 	    return 'error: '.$!;
                   9794: 	}
                   9795:     }
                   9796:     $env{'request.role'}='cm';
                   9797:     $env{'request.role.adv'}=$env{'user.adv'};
                   9798:     $env{'browser.type'}=$clientbrowser;
                   9799: 
                   9800:     return $cookie;
                   9801: 
                   9802: }
                   9803: 
                   9804: sub _add_to_env {
                   9805:     my ($idf,$env_data,$prefix) = @_;
1.676     raeburn  9806:     if (ref($env_data) eq 'HASH') {
                   9807:         while (my ($key,$value) = each(%$env_data)) {
                   9808: 	    $idf->{$prefix.$key} = $value;
                   9809: 	    $env{$prefix.$key}   = $value;
                   9810:         }
1.462     albertel 9811:     }
                   9812: }
                   9813: 
1.685     tempelho 9814: # --- Get the symbolic name of a problem and the url
                   9815: sub get_symb {
                   9816:     my ($request,$silent) = @_;
                   9817:     (my $url=$env{'form.url'}) =~ s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
                   9818:     my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
                   9819:     if ($symb eq '') {
                   9820:         if (!$silent) {
                   9821:             $request->print("Unable to handle ambiguous references:$url:.");
                   9822:             return ();
                   9823:         }
                   9824:     }
                   9825:     &Apache::lonenc::check_decrypt(\$symb);
                   9826:     return ($symb);
                   9827: }
                   9828: 
                   9829: # --------------------------------------------------------------Get annotation
                   9830: 
                   9831: sub get_annotation {
                   9832:     my ($symb,$enc) = @_;
                   9833: 
                   9834:     my $key = $symb;
                   9835:     if (!$enc) {
                   9836:         $key =
                   9837:             &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
                   9838:     }
                   9839:     my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
                   9840:     return $annotation{$key};
                   9841: }
                   9842: 
                   9843: sub clean_symb {
                   9844:     my ($symb) = @_;
                   9845: 
                   9846:     &Apache::lonenc::check_decrypt(\$symb);
                   9847:     my $enc = $env{'request.enc'};
                   9848:     delete($env{'request.enc'});
                   9849: 
                   9850:     return ($symb,$enc);
                   9851: }
1.462     albertel 9852: 
1.41      ng       9853: =pod
                   9854: 
                   9855: =back
                   9856: 
1.112     bowersj2 9857: =cut
1.41      ng       9858: 
1.112     bowersj2 9859: 1;
                   9860: __END__;
1.41      ng       9861: 

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