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

1.10      albertel    1: # The LearningOnline Network with CAPA
1.1       albertel    2: # a pile of common routines
1.10      albertel    3: #
1.106   ! bowersj2    4: # $Id: loncommon.pm,v 1.105 2003/06/18 16:22:53 www 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.12      harris41   28: # YEAR=2001
                     29: # 2/13-12/7 Guy Albertelli
1.18      www        30: # 12/21 Gerd Kortemeyer
1.22      www        31: # 12/25,12/28 Gerd Kortemeyer
1.23      www        32: # YEAR=2002
                     33: # 1/4 Gerd Kortemeyer
1.43      ng         34: # 6/24,7/2 H. K. Ng
1.1       albertel   35: 
                     36: # Makes a table out of the previous attempts
1.2       albertel   37: # Inputs result_from_symbread, user, domain, course_id
1.16      harris41   38: # Reads in non-network-related .tab files
1.1       albertel   39: 
1.35      matthew    40: # POD header:
                     41: 
1.45      matthew    42: =pod
                     43: 
1.35      matthew    44: =head1 NAME
                     45: 
                     46: Apache::loncommon - pile of common routines
                     47: 
                     48: =head1 SYNOPSIS
                     49: 
                     50: Referenced by other mod_perl Apache modules.
                     51: 
                     52: Invocation:
                     53:  &Apache::loncommon::SUBROUTINENAME(ARGUMENTS);
                     54: 
                     55: =head1 INTRODUCTION
                     56: 
                     57: Common collection of used subroutines.  This collection helps remove
                     58: redundancy from other modules and increase efficiency of memory usage.
                     59: 
                     60: Current things done:
                     61: 
                     62:  Makes a table out of the previous homework attempts
                     63:  Inputs result_from_symbread, user, domain, course_id
                     64:  Reads in non-network-related .tab files
                     65: 
                     66: This is part of the LearningOnline Network with CAPA project
                     67: described at http://www.lon-capa.org.
                     68: 
1.41      ng         69: =head2 General Subroutines
1.35      matthew    70: 
                     71: =over 4
                     72: 
                     73: =cut 
                     74: 
                     75: # End of POD header
1.1       albertel   76: package Apache::loncommon;
                     77: 
                     78: use strict;
1.22      www        79: use Apache::lonnet();
1.46      matthew    80: use GDBM_File;
1.51      www        81: use POSIX qw(strftime mktime);
1.99      www        82: use Apache::Constants qw(:common :http :methods);
1.1       albertel   83: use Apache::lonmsg();
1.82      www        84: use Apache::lonmenu();
1.22      www        85: my $readit;
                     86: 
1.46      matthew    87: =pod 
                     88: 
                     89: =item Global Variables
                     90: 
                     91: =over 4
                     92: 
                     93: =cut
1.20      www        94: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12      harris41   95: my %language;
                     96: my %cprtag;
                     97: my %fe; my %fd;
1.41      ng         98: my %category_extensions;
1.12      harris41   99: 
1.63      www       100: # ---------------------------------------------- Designs
                    101: 
                    102: my %designhash;
                    103: 
1.46      matthew   104: # ---------------------------------------------- Thesaurus variables
                    105: 
                    106: =pod
                    107: 
                    108: =item %Keywords  
                    109: 
                    110: A hash used by &keyword to determine if a word is considered a keyword.
                    111: 
                    112: =item $thesaurus_db_file
                    113: 
                    114: Scalar containing the full path to the thesaurus database.                 
                    115: 
                    116: =cut
                    117: 
                    118: my %Keywords;
                    119: my $thesaurus_db_file;
                    120: 
                    121: 
                    122: =pod
                    123: 
                    124: =back
                    125: 
                    126: =cut
1.20      www       127: 
1.12      harris41  128: # ----------------------------------------------------------------------- BEGIN
1.41      ng        129: 
                    130: =pod
                    131: 
1.35      matthew   132: =item BEGIN() 
                    133: 
                    134: Initialize values from language.tab, copyright.tab, filetypes.tab,
1.45      matthew   135: thesaurus.tab, and filecategories.tab.
1.35      matthew   136: 
                    137: =cut
1.45      matthew   138: 
1.35      matthew   139: # ----------------------------------------------------------------------- BEGIN
                    140: 
1.18      www       141: BEGIN {
1.46      matthew   142:     # Variable initialization
                    143:     $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
                    144:     #
1.22      www       145:     unless ($readit) {
1.12      harris41  146: # ------------------------------------------------------------------- languages
                    147:     {
                    148: 	my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
                    149: 				 '/language.tab');
1.16      harris41  150: 	if ($fh) {
                    151: 	    while (<$fh>) {
                    152: 		next if /^\#/;
                    153: 		chomp;
1.98      www       154: 		my ($key,$two,$country,$three,$enc,$val)=(split(/\t/,$_));
                    155: 		$language{$key}=$val.' - '.$enc;
1.16      harris41  156: 	    }
1.12      harris41  157: 	}
                    158:     }
                    159: # ------------------------------------------------------------------ copyrights
                    160:     {
1.16      harris41  161: 	my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonIncludes'}.
                    162: 				  '/copyright.tab');
                    163: 	if ($fh) {
                    164: 	    while (<$fh>) {
                    165: 		next if /^\#/;
                    166: 		chomp;
                    167: 		my ($key,$val)=(split(/\s+/,$_,2));
                    168: 		$cprtag{$key}=$val;
                    169: 	    }
1.12      harris41  170: 	}
                    171:     }
1.63      www       172: 
                    173: # -------------------------------------------------------------- domain designs
                    174: 
                    175:     my $filename;
                    176:     my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
                    177:     opendir(DIR,$designdir);
                    178:     while ($filename=readdir(DIR)) {
                    179: 	my ($domain)=($filename=~/^(\w+)\./);
                    180:     {
                    181: 	my $fh=Apache::File->new($designdir.'/'.$filename);
                    182: 	if ($fh) {
                    183: 	    while (<$fh>) {
                    184: 		next if /^\#/;
                    185: 		chomp;
                    186: 		my ($key,$val)=(split(/\=/,$_));
                    187: 		if ($val) { $designhash{$domain.'.'.$key}=$val; }
                    188: 	    }
                    189: 	}
                    190:     }
                    191: 
                    192:     }
                    193:     closedir(DIR);
                    194: 
                    195: 
1.15      harris41  196: # ------------------------------------------------------------- file categories
                    197:     {
                    198: 	my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
1.16      harris41  199: 				  '/filecategories.tab');
                    200: 	if ($fh) {
                    201: 	    while (<$fh>) {
                    202: 		next if /^\#/;
                    203: 		chomp;
1.41      ng        204: 		my ($extension,$category)=(split(/\s+/,$_,2));
                    205: 		push @{$category_extensions{lc($category)}},$extension;
1.16      harris41  206: 	    }
1.15      harris41  207: 	}
                    208:     }
1.12      harris41  209: # ------------------------------------------------------------------ file types
                    210:     {
1.16      harris41  211: 	my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
                    212: 	       '/filetypes.tab');
                    213: 	if ($fh) {
                    214:             while (<$fh>) {
                    215: 		next if (/^\#/);
                    216: 		chomp;
                    217: 		my ($ending,$emb,$descr)=split(/\s+/,$_,3);
                    218: 		if ($descr ne '') { 
                    219: 		    $fe{$ending}=lc($emb);
                    220: 		    $fd{$ending}=$descr;
                    221: 		}
1.12      harris41  222: 	    }
                    223: 	}
                    224:     }
1.22      www       225:     &Apache::lonnet::logthis(
1.46      matthew   226:               "<font color=yellow>INFO: Read file types</font>");
1.22      www       227:     $readit=1;
1.46      matthew   228:     }  # end of unless($readit) 
1.32      matthew   229:     
                    230: }
                    231: # ============================================================= END BEGIN BLOCK
1.42      matthew   232: ###############################################################
                    233: ##           HTML and Javascript Helper Functions            ##
                    234: ###############################################################
                    235: 
                    236: =pod 
                    237: 
                    238: =item browser_and_searcher_javascript 
                    239: 
                    240: Returns scalar containing javascript to open a browser window
                    241: or a searcher window.  Also creates 
                    242: 
                    243: =over 4
                    244: 
                    245: =item openbrowser(formname,elementname,only,omit) [javascript]
                    246: 
                    247: inputs: formname, elementname, only, omit
                    248: 
                    249: formname and elementname indicate the name of the html form and name of
                    250: the element that the results of the browsing selection are to be placed in. 
                    251: 
                    252: Specifying 'only' will restrict the browser to displaying only files
                    253: with the given extension.  Can be a comma seperated list.
                    254: 
                    255: Specifying 'omit' will restrict the browser to NOT displaying files
                    256: with the given extension.  Can be a comma seperated list.
                    257: 
                    258: =item opensearcher(formname, elementname) [javascript]
                    259: 
                    260: Inputs: formname, elementname
                    261: 
                    262: formname and elementname specify the name of the html form and the name
                    263: of the element the selection from the search results will be placed in.
                    264: 
                    265: =back
                    266: 
                    267: =cut
                    268: 
                    269: ###############################################################
                    270: sub browser_and_searcher_javascript {
                    271:     return <<END;
1.50      matthew   272:     var editbrowser = null;
1.42      matthew   273:     function openbrowser(formname,elementname,only,omit) {
                    274:         var url = '/res/?';
                    275:         if (editbrowser == null) {
                    276:             url += 'launch=1&';
                    277:         }
                    278:         url += 'catalogmode=interactive&';
                    279:         url += 'mode=edit&';
                    280:         url += 'form=' + formname + '&';
                    281:         if (only != null) {
                    282:             url += 'only=' + only + '&';
                    283:         } 
                    284:         if (omit != null) {
                    285:             url += 'omit=' + omit + '&';
                    286:         }
                    287:         url += 'element=' + elementname + '';
                    288:         var title = 'Browser';
                    289:         var options = 'scrollbars=1,resizable=1,menubar=0';
                    290:         options += ',width=700,height=600';
                    291:         editbrowser = open(url,title,options,'1');
                    292:         editbrowser.focus();
                    293:     }
                    294:     var editsearcher;
                    295:     function opensearcher(formname,elementname) {
                    296:         var url = '/adm/searchcat?';
                    297:         if (editsearcher == null) {
                    298:             url += 'launch=1&';
                    299:         }
                    300:         url += 'catalogmode=interactive&';
                    301:         url += 'mode=edit&';
                    302:         url += 'form=' + formname + '&';
                    303:         url += 'element=' + elementname + '';
                    304:         var title = 'Search';
                    305:         var options = 'scrollbars=1,resizable=1,menubar=0';
                    306:         options += ',width=700,height=600';
                    307:         editsearcher = open(url,title,options,'1');
                    308:         editsearcher.focus();
                    309:     }
                    310: END
                    311: }
                    312: 
1.74      www       313: sub studentbrowser_javascript {
                    314:    unless ($ENV{'request.course.id'}) { return ''; }  
                    315:    unless (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) {
                    316:         return '';
                    317:    }
                    318:    return (<<'ENDSTDBRW');
                    319: <script type="text/javascript" language="Javascript" >
                    320:     var stdeditbrowser;
                    321:     function openstdbrowser(formname,uname,udom) {
                    322:         var url = '/adm/pickstudent?';
                    323:         var filter;
                    324:         eval('filter=document.'+formname+'.'+uname+'.value;');
                    325:         if (filter != null) {
                    326:            if (filter != '') {
                    327:                url += 'filter='+filter+'&';
                    328: 	   }
                    329:         }
                    330:         url += 'form=' + formname + '&unameelement='+uname+
                    331:                                     '&udomelement='+udom;
1.102     www       332:         var title = 'Student_Browser';
1.74      www       333:         var options = 'scrollbars=1,resizable=1,menubar=0';
                    334:         options += ',width=700,height=600';
                    335:         stdeditbrowser = open(url,title,options,'1');
                    336:         stdeditbrowser.focus();
                    337:     }
                    338: </script>
                    339: ENDSTDBRW
                    340: }
1.42      matthew   341: 
1.74      www       342: sub selectstudent_link {
                    343:     my ($form,$unameele,$udomele)=@_;
                    344:    unless ($ENV{'request.course.id'}) { return ''; }  
                    345:    unless (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) {
                    346:         return '';
                    347:    }
                    348:     return "<a href='".'javascript:openstdbrowser("'.$form.'","'.$unameele.
1.92      www       349:         '","'.$udomele.'");'."'>Select User</a>";
1.91      www       350: }
                    351: 
                    352: sub coursebrowser_javascript {
                    353:    return (<<'ENDSTDBRW');
                    354: <script type="text/javascript" language="Javascript" >
                    355:     var stdeditbrowser;
                    356:     function opencrsbrowser(formname,uname,udom) {
                    357:         var url = '/adm/pickcourse?';
                    358:         var filter;
                    359:         if (filter != null) {
                    360:            if (filter != '') {
                    361:                url += 'filter='+filter+'&';
                    362: 	   }
                    363:         }
                    364:         url += 'form=' + formname + '&cnumelement='+uname+
                    365:                                     '&cdomelement='+udom;
1.102     www       366:         var title = 'Course_Browser';
1.91      www       367:         var options = 'scrollbars=1,resizable=1,menubar=0';
                    368:         options += ',width=700,height=600';
                    369:         stdeditbrowser = open(url,title,options,'1');
                    370:         stdeditbrowser.focus();
                    371:     }
                    372: </script>
                    373: ENDSTDBRW
                    374: }
                    375: 
                    376: sub selectcourse_link {
                    377:    my ($form,$unameele,$udomele)=@_;
                    378:     return "<a href='".'javascript:opencrsbrowser("'.$form.'","'.$unameele.
                    379:         '","'.$udomele.'");'."'>Select Course</a>";
1.74      www       380: }
1.42      matthew   381: 
                    382: ###############################################################
                    383: 
                    384: =pod
1.36      matthew   385: 
                    386: =item linked_select_forms(...)
                    387: 
                    388: linked_select_forms returns a string containing a <script></script> block
                    389: and html for two <select> menus.  The select menus will be linked in that
                    390: changing the value of the first menu will result in new values being placed
                    391: in the second menu.  The values in the select menu will appear in alphabetical
                    392: order.
                    393: 
                    394: linked_select_forms takes the following ordered inputs:
                    395: 
                    396: =over 4
                    397: 
                    398: =item $formname, the name of the <form> tag
                    399: 
                    400: =item $middletext, the text which appears between the <select> tags
                    401: 
                    402: =item $firstdefault, the default value for the first menu
                    403: 
                    404: =item $firstselectname, the name of the first <select> tag
                    405: 
                    406: =item $secondselectname, the name of the second <select> tag
                    407: 
                    408: =item $hashref, a reference to a hash containing the data for the menus.
                    409: 
1.41      ng        410: =back 
                    411: 
1.36      matthew   412: Below is an example of such a hash.  Only the 'text', 'default', and 
                    413: 'select2' keys must appear as stated.  keys(%menu) are the possible 
                    414: values for the first select menu.  The text that coincides with the 
1.41      ng        415: first menu value is given in $menu{$choice1}->{'text'}.  The values 
1.36      matthew   416: and text for the second menu are given in the hash pointed to by 
                    417: $menu{$choice1}->{'select2'}.  
                    418: 
1.41      ng        419: my %menu = ( A1 => { text =>"Choice A1" ,
1.36      matthew   420:                       default => "B3",
                    421:                       select2 => { 
                    422:                           B1 => "Choice B1",
                    423:                           B2 => "Choice B2",
                    424:                           B3 => "Choice B3",
                    425:                           B4 => "Choice B4"
                    426:                           }
                    427:                   },
                    428:               A2 => { text =>"Choice A2" ,
                    429:                       default => "C2",
                    430:                       select2 => { 
                    431:                           C1 => "Choice C1",
                    432:                           C2 => "Choice C2",
                    433:                           C3 => "Choice C3"
                    434:                           }
                    435:                   },
                    436:               A3 => { text =>"Choice A3" ,
                    437:                       default => "D6",
                    438:                       select2 => { 
                    439:                           D1 => "Choice D1",
                    440:                           D2 => "Choice D2",
                    441:                           D3 => "Choice D3",
                    442:                           D4 => "Choice D4",
                    443:                           D5 => "Choice D5",
                    444:                           D6 => "Choice D6",
                    445:                           D7 => "Choice D7"
                    446:                           }
                    447:                   }
                    448:               );
                    449: 
                    450: =cut
                    451: 
                    452: # ------------------------------------------------
                    453: 
                    454: sub linked_select_forms {
                    455:     my ($formname,
                    456:         $middletext,
                    457:         $firstdefault,
                    458:         $firstselectname,
                    459:         $secondselectname, 
                    460:         $hashref
                    461:         ) = @_;
                    462:     my $second = "document.$formname.$secondselectname";
                    463:     my $first = "document.$formname.$firstselectname";
                    464:     # output the javascript to do the changing
                    465:     my $result = '';
                    466:     $result.="<script>\n";
                    467:     $result.="var select2data = new Object();\n";
                    468:     $" = '","';
                    469:     my $debug = '';
                    470:     foreach my $s1 (sort(keys(%$hashref))) {
                    471:         $result.="select2data.d_$s1 = new Object();\n";        
                    472:         $result.="select2data.d_$s1.def = new String('".
                    473:             $hashref->{$s1}->{'default'}."');\n";
                    474:         $result.="select2data.d_$s1.values = new Array(";        
                    475:         my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
                    476:         $result.="\"@s2values\");\n";
                    477:         $result.="select2data.d_$s1.texts = new Array(";        
                    478:         my @s2texts;
                    479:         foreach my $value (@s2values) {
                    480:             push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
                    481:         }
                    482:         $result.="\"@s2texts\");\n";
                    483:     }
                    484:     $"=' ';
                    485:     $result.= <<"END";
                    486: 
                    487: function select1_changed() {
                    488:     // Determine new choice
                    489:     var newvalue = "d_" + $first.value;
                    490:     // update select2
                    491:     var values     = select2data[newvalue].values;
                    492:     var texts      = select2data[newvalue].texts;
                    493:     var select2def = select2data[newvalue].def;
                    494:     var i;
                    495:     // out with the old
                    496:     for (i = 0; i < $second.options.length; i++) {
                    497:         $second.options[i] = null;
                    498:     }
                    499:     // in with the nuclear
                    500:     for (i=0;i<values.length; i++) {
                    501:         $second.options[i] = new Option(values[i]);
                    502:         $second.options[i].text = texts[i];
                    503:         if (values[i] == select2def) {
                    504:             $second.options[i].selected = true;
                    505:         }
                    506:     }
                    507: }
                    508: </script>
                    509: END
                    510:     # output the initial values for the selection lists
                    511:     $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
                    512:     foreach my $value (sort(keys(%$hashref))) {
                    513:         $result.="    <option value=\"$value\" ";
                    514:         $result.=" selected=\"true\" " if ($value eq $firstdefault);
                    515:         $result.=">$hashref->{$value}->{'text'}</option>\n";
                    516:     }
                    517:     $result .= "</select>\n";
                    518:     my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
                    519:     $result .= $middletext;
                    520:     $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
                    521:     my $seconddefault = $hashref->{$firstdefault}->{'default'};
                    522:     foreach my $value (sort(keys(%select2))) {
                    523:         $result.="    <option value=\"$value\" ";        
                    524:         $result.=" selected=\"true\" " if ($value eq $seconddefault);
                    525:         $result.=">$select2{$value}</option>\n";
                    526:     }
                    527:     $result .= "</select>\n";
                    528:     #    return $debug;
                    529:     return $result;
                    530: }   #  end of sub linked_select_forms {
                    531: 
1.33      matthew   532: ###############################################################
1.44      bowersj2  533: 
1.45      matthew   534: =pod
1.44      bowersj2  535: 
1.48      bowersj2  536: =item help_open_topic($topic, $text, $stayOnPage, $width, $height)
1.44      bowersj2  537: 
                    538: Returns a string corresponding to an HTML link to the given help $topic, where $topic corresponds to the name of a .tex file in /home/httpd/html/adm/help/tex, with underscores replaced by spaces.
                    539: 
1.48      bowersj2  540: $text will optionally be linked to the same topic, allowing you to link text in addition to the graphic. If you do not want to link text, but wish to specify one of the later parameters, pass an empty string.
                    541: 
1.44      bowersj2  542: $stayOnPage is a value that will be interpreted as a boolean. If true, the link will not open a new window. If false, the link will open a new window using Javascript. (Default is false.)
                    543: 
                    544: $width and $height are optional numerical parameters that will override the width and height of the popped up window, which may be useful for certain help topics with big pictures included.
                    545: 
                    546: =cut
                    547: 
                    548: sub help_open_topic {
1.48      bowersj2  549:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
                    550:     $text = "" if (not defined $text);
1.44      bowersj2  551:     $stayOnPage = 0 if (not defined $stayOnPage);
1.79      www       552:     if ($ENV{'browser.interface'} eq 'textual') {
                    553: 	$stayOnPage=1;
                    554:     }
1.44      bowersj2  555:     $width = 350 if (not defined $width);
                    556:     $height = 400 if (not defined $height);
                    557:     my $filename = $topic;
                    558:     $filename =~ s/ /_/g;
                    559: 
1.48      bowersj2  560:     my $template = "";
                    561:     my $link;
1.44      bowersj2  562: 
                    563:     if (!$stayOnPage)
                    564:     {
1.72      bowersj2  565: 	$link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1.44      bowersj2  566:     }
                    567:     else
                    568:     {
1.48      bowersj2  569: 	$link = "/adm/help/${filename}.hlp";
                    570:     }
                    571: 
                    572:     # Add the text
                    573:     if ($text ne "")
                    574:     {
1.77      www       575: 	$template .= 
                    576:   "<table bgcolor='#3333AA' cellspacing='1' cellpadding='1' border='0'><tr>".
1.78      www       577:   "<td bgcolor='#5555FF'><a href=\"$link\"><font color='#FFFFFF' size='2'>$text</font></a>";
1.48      bowersj2  578:     }
                    579: 
                    580:     # Add the graphic
                    581:     $template .= <<"ENDTEMPLATE";
1.77      www       582:  <a href="$link"><image src="/adm/help/gif/smallHelp.gif" border="0" alt="(Help: $topic)" /></a>
1.44      bowersj2  583: ENDTEMPLATE
1.78      www       584:     if ($text ne '') { $template.='</td></tr></table>' };
1.44      bowersj2  585:     return $template;
                    586: 
1.106   ! bowersj2  587: }
        !           588: 
        !           589: # This is a quicky function for Latex cheatsheet editing, since it 
        !           590: # appears in at least four places
        !           591: sub helpLatexCheatsheet {
        !           592:     my $other = shift;
        !           593:     my $addOther = '';
        !           594:     if ($other) {
        !           595: 	$addOther = Apache::loncommon::help_open_topic($other, shift,
        !           596: 						       undef, undef, 600) .
        !           597: 							   '</td><td>';
        !           598:     }
        !           599:     return '<table><tr><td>'.
        !           600: 	$addOther .
        !           601: 	&Apache::loncommon::help_open_topic("Greek_Symbols",'Greek Symbols',
        !           602: 					    undef,undef,600)
        !           603: 	.'</td><td>'.
        !           604: 	&Apache::loncommon::help_open_topic("Other_Symbols",'Other Symbols',
        !           605: 					    undef,undef,600)
        !           606: 	.'</td></tr></table>';
1.44      bowersj2  607: }
1.37      matthew   608: 
1.45      matthew   609: =pod
                    610: 
1.37      matthew   611: =item csv_translate($text) 
                    612: 
                    613: Translate $text to allow it to be output as a 'comma seperated values' 
                    614: format.
                    615: 
                    616: =cut
                    617: 
                    618: sub csv_translate {
                    619:     my $text = shift;
                    620:     $text =~ s/\"/\"\"/g;
                    621:     $text =~ s/\n//g;
                    622:     return $text;
                    623: }
                    624: 
                    625: ###############################################################
1.33      matthew   626: ##        Home server <option> list generating code          ##
                    627: ###############################################################
1.35      matthew   628: #-------------------------------------------
                    629: 
1.45      matthew   630: =pod
                    631: 
1.35      matthew   632: =item get_domains()
                    633: 
                    634: Returns an array containing each of the domains listed in the hosts.tab
                    635: file.
                    636: 
                    637: =cut
                    638: 
                    639: #-------------------------------------------
1.34      matthew   640: sub get_domains {
                    641:     # The code below was stolen from "The Perl Cookbook", p 102, 1st ed.
                    642:     my @domains;
                    643:     my %seen;
                    644:     foreach (sort values(%Apache::lonnet::hostdom)) {
                    645:         push (@domains,$_) unless $seen{$_}++;
                    646:     }
                    647:     return @domains;
                    648: }
1.88      www       649: 
                    650: #-------------------------------------------
                    651: 
                    652: =pod
                    653: 
                    654: =item select_form($defdom,$name,%hash)
                    655: 
                    656: Returns a string containing a <select name='$name' size='1'> form to 
                    657: allow a user to select options from a hash option_name => displayed text.  
                    658: See lonrights.pm for an example invocation and use.
                    659: 
                    660: =cut
                    661: 
                    662: #-------------------------------------------
                    663: sub select_form {
                    664:     my ($def,$name,%hash) = @_;
                    665:     my $selectform = "<select name=\"$name\" size=\"1\">\n";
1.89      www       666:     foreach (sort keys %hash) {
1.88      www       667:         $selectform.="<option value=\"$_\" ".
                    668:             ($_ eq $def ? 'selected' : '').
                    669:                 ">".$hash{$_}."</option>\n";
                    670:     }
                    671:     $selectform.="</select>";
                    672:     return $selectform;
                    673: }
                    674: 
1.34      matthew   675: 
1.35      matthew   676: #-------------------------------------------
                    677: 
1.45      matthew   678: =pod
                    679: 
1.90      www       680: =item select_dom_form($defdom,$name,$includeempty)
1.35      matthew   681: 
                    682: Returns a string containing a <select name='$name' size='1'> form to 
                    683: allow a user to select the domain to preform an operation in.  
                    684: See loncreateuser.pm for an example invocation and use.
                    685: 
1.90      www       686: If the $includeempty flag is set, it also includes an empty choice ("no domain
                    687: selected");
                    688: 
1.35      matthew   689: =cut
                    690: 
                    691: #-------------------------------------------
1.34      matthew   692: sub select_dom_form {
1.90      www       693:     my ($defdom,$name,$includeempty) = @_;
1.34      matthew   694:     my @domains = get_domains();
1.90      www       695:     if ($includeempty) { @domains=('',@domains); }
1.34      matthew   696:     my $selectdomain = "<select name=\"$name\" size=\"1\">\n";
                    697:     foreach (@domains) {
                    698:         $selectdomain.="<option value=\"$_\" ".
                    699:             ($_ eq $defdom ? 'selected' : '').
                    700:                 ">$_</option>\n";
                    701:     }
                    702:     $selectdomain.="</select>";
                    703:     return $selectdomain;
                    704: }
                    705: 
1.35      matthew   706: #-------------------------------------------
                    707: 
1.45      matthew   708: =pod
                    709: 
1.52      matthew   710: =item get_library_servers($domain)
1.35      matthew   711: 
                    712: Returns a hash which contains keys like '103l3' and values like 
                    713: 'kirk.lite.msu.edu'.  All of the keys will be for machines in the
                    714: given $domain.
                    715: 
                    716: =cut
                    717: 
                    718: #-------------------------------------------
1.52      matthew   719: sub get_library_servers {
1.33      matthew   720:     my $domain = shift;
1.52      matthew   721:     my %library_servers;
1.33      matthew   722:     foreach (keys(%Apache::lonnet::libserv)) {
                    723:         if ($Apache::lonnet::hostdom{$_} eq $domain) {
1.52      matthew   724:             $library_servers{$_} = $Apache::lonnet::hostname{$_};
1.33      matthew   725:         }
                    726:     }
1.52      matthew   727:     return %library_servers;
1.33      matthew   728: }
                    729: 
1.35      matthew   730: #-------------------------------------------
                    731: 
1.45      matthew   732: =pod
                    733: 
1.35      matthew   734: =item home_server_option_list($domain)
                    735: 
                    736: returns a string which contains an <option> list to be used in a 
                    737: <select> form input.  See loncreateuser.pm for an example.
                    738: 
                    739: =cut
                    740: 
                    741: #-------------------------------------------
1.33      matthew   742: sub home_server_option_list {
                    743:     my $domain = shift;
1.52      matthew   744:     my %servers = &get_library_servers($domain);
1.33      matthew   745:     my $result = '';
                    746:     foreach (sort keys(%servers)) {
                    747:         $result.=
                    748:             '<option value="'.$_.'">'.$_.' '.$servers{$_}."</option>\n";
                    749:     }
                    750:     return $result;
                    751: }
                    752: ###############################################################
                    753: ##    End of home server <option> list generating code       ##
                    754: ###############################################################
1.87      matthew   755: 
                    756: ###############################################################
                    757: ###############################################################
                    758: 
                    759: =pod
                    760: 
                    761: =item &decode_user_agent()
                    762: 
                    763: Inputs: $r
                    764: 
                    765: Outputs:
                    766: 
                    767: =over 4
                    768: 
                    769: =item $httpbrowser
                    770: 
                    771: =item $clientbrowser
                    772: 
                    773: =item $clientversion
                    774: 
                    775: =item $clientmathml
                    776: 
                    777: =item $clientunicode
                    778: 
                    779: =item $clientos
                    780: 
                    781: =back
                    782: 
                    783: =cut
                    784: 
                    785: ###############################################################
                    786: ###############################################################
                    787: sub decode_user_agent {
                    788:     my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
                    789:     my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
                    790:     my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
                    791:     my $clientbrowser='unknown';
                    792:     my $clientversion='0';
                    793:     my $clientmathml='';
                    794:     my $clientunicode='0';
                    795:     for (my $i=0;$i<=$#browsertype;$i++) {
                    796:         my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
                    797: 	if (($httpbrowser=~/$match/i)  && ($httpbrowser!~/$notmatch/i)) {
                    798: 	    $clientbrowser=$bname;
                    799:             $httpbrowser=~/$vreg/i;
                    800: 	    $clientversion=$1;
                    801:             $clientmathml=($clientversion>=$minv);
                    802:             $clientunicode=($clientversion>=$univ);
                    803: 	}
                    804:     }
                    805:     my $clientos='unknown';
                    806:     if (($httpbrowser=~/linux/i) ||
                    807:         ($httpbrowser=~/unix/i) ||
                    808:         ($httpbrowser=~/ux/i) ||
                    809:         ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
                    810:     if (($httpbrowser=~/vax/i) ||
                    811:         ($httpbrowser=~/vms/i)) { $clientos='vms'; }
                    812:     if ($httpbrowser=~/next/i) { $clientos='next'; }
                    813:     if (($httpbrowser=~/mac/i) ||
                    814:         ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
                    815:     if ($httpbrowser=~/win/i) { $clientos='win'; }
                    816:     if ($httpbrowser=~/embed/i) { $clientos='pda'; }
                    817:     return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
                    818:             $clientunicode,$clientos,);
                    819: }
                    820: 
                    821: ###############################################################
                    822: ###############################################################
                    823: 
1.32      matthew   824: 
                    825: ###############################################################
                    826: ##    Authentication changing form generation subroutines    ##
                    827: ###############################################################
                    828: ##
                    829: ## All of the authform_xxxxxxx subroutines take their inputs in a
                    830: ## hash, and have reasonable default values.
                    831: ##
                    832: ##    formname = the name given in the <form> tag.
1.35      matthew   833: #-------------------------------------------
                    834: 
1.45      matthew   835: =pod
                    836: 
1.35      matthew   837: =item authform_xxxxxx
                    838: 
                    839: The authform_xxxxxx subroutines provide javascript and html forms which 
                    840: handle some of the conveniences required for authentication forms.  
                    841: This is not an optimal method, but it works.  
                    842: 
                    843: See loncreateuser.pm for invocation and use examples.
                    844: 
                    845: =over 4
                    846: 
                    847: =item authform_header
                    848: 
                    849: =item authform_authorwarning
                    850: 
                    851: =item authform_nochange
                    852: 
                    853: =item authform_kerberos
                    854: 
                    855: =item authform_internal
                    856: 
                    857: =item authform_filesystem
                    858: 
                    859: =back
                    860: 
                    861: =cut
                    862: 
                    863: #-------------------------------------------
1.32      matthew   864: sub authform_header{  
                    865:     my %in = (
                    866:         formname => 'cu',
1.80      albertel  867:         kerb_def_dom => '',
1.32      matthew   868:         @_,
                    869:     );
                    870:     $in{'formname'} = 'document.' . $in{'formname'};
                    871:     my $result='';
1.80      albertel  872: 
                    873: #---------------------------------------------- Code for upper case translation
                    874:     my $Javascript_toUpperCase;
                    875:     unless ($in{kerb_def_dom}) {
                    876:         $Javascript_toUpperCase =<<"END";
                    877:         switch (choice) {
                    878:            case 'krb': currentform.elements[choicearg].value =
                    879:                currentform.elements[choicearg].value.toUpperCase();
                    880:                break;
                    881:            default:
                    882:         }
                    883: END
                    884:     } else {
                    885:         $Javascript_toUpperCase = "";
                    886:     }
                    887: 
1.32      matthew   888:     $result.=<<"END";
                    889: var current = new Object();
                    890: current.radiovalue = 'nochange';
                    891: current.argfield = null;
                    892: 
                    893: function changed_radio(choice,currentform) {
                    894:     var choicearg = choice + 'arg';
                    895:     // If a radio button in changed, we need to change the argfield
                    896:     if (current.radiovalue != choice) {
                    897:         current.radiovalue = choice;
                    898:         if (current.argfield != null) {
                    899:             currentform.elements[current.argfield].value = '';
                    900:         }
                    901:         if (choice == 'nochange') {
                    902:             current.argfield = null;
                    903:         } else {
                    904:             current.argfield = choicearg;
                    905:             switch(choice) {
                    906:                 case 'krb': 
                    907:                     currentform.elements[current.argfield].value = 
                    908:                         "$in{'kerb_def_dom'}";
                    909:                 break;
                    910:               default:
                    911:                 break;
                    912:             }
                    913:         }
                    914:     }
                    915:     return;
                    916: }
1.22      www       917: 
1.32      matthew   918: function changed_text(choice,currentform) {
                    919:     var choicearg = choice + 'arg';
                    920:     if (currentform.elements[choicearg].value !='') {
1.80      albertel  921:         $Javascript_toUpperCase
1.32      matthew   922:         // clear old field
                    923:         if ((current.argfield != choicearg) && (current.argfield != null)) {
                    924:             currentform.elements[current.argfield].value = '';
                    925:         }
                    926:         current.argfield = choicearg;
                    927:     }
                    928:     set_auth_radio_buttons(choice,currentform);
                    929:     return;
1.20      www       930: }
1.32      matthew   931: 
                    932: function set_auth_radio_buttons(newvalue,currentform) {
                    933:     var i=0;
                    934:     while (i < currentform.login.length) {
                    935:         if (currentform.login[i].value == newvalue) { break; }
                    936:         i++;
                    937:     }
                    938:     if (i == currentform.login.length) {
                    939:         return;
                    940:     }
                    941:     current.radiovalue = newvalue;
                    942:     currentform.login[i].checked = true;
                    943:     return;
                    944: }
                    945: END
                    946:     return $result;
                    947: }
                    948: 
                    949: sub authform_authorwarning{
                    950:     my $result='';
                    951:     $result=<<"END";
                    952: <i>As a general rule, only authors or co-authors should be filesystem
                    953: authenticated (which allows access to the server filesystem).</i>
                    954: END
                    955:     return $result;
                    956: }
                    957: 
                    958: sub authform_nochange{  
                    959:     my %in = (
                    960:               formname => 'document.cu',
                    961:               kerb_def_dom => 'MSU.EDU',
                    962:               @_,
                    963:           );
                    964:     my $result='';
                    965:     $result.=<<"END";
                    966: <input type="radio" name="login" value="nochange" checked="checked"
1.57      albertel  967:        onclick="javascript:changed_radio('nochange',$in{'formname'});" />
1.32      matthew   968: Do not change login data
                    969: END
                    970:     return $result;
                    971: }
                    972: 
                    973: sub authform_kerberos{  
                    974:     my %in = (
                    975:               formname => 'document.cu',
                    976:               kerb_def_dom => 'MSU.EDU',
1.80      albertel  977:               kerb_def_auth => 'krb4',
1.32      matthew   978:               @_,
                    979:               );
                    980:     my $result='';
1.80      albertel  981:     my $check4;
                    982:     my $check5;
                    983:     if ($in{'kerb_def_auth'} eq 'krb5') {
                    984:        $check5 = " checked=\"on\"";
                    985:     } else {
                    986:        $check4 = " checked=\"on\"";
                    987:     }
1.32      matthew   988:     $result.=<<"END";
                    989: <input type="radio" name="login" value="krb" 
                    990:        onclick="javascript:changed_radio('krb',$in{'formname'});"
1.57      albertel  991:        onchange="javascript:changed_radio('krb',$in{'formname'});" />
1.32      matthew   992: Kerberos authenticated with domain
1.80      albertel  993: <input type="text" size="10" name="krbarg" value="$in{'kerb_def_dom'}"
1.57      albertel  994:        onchange="javascript:changed_text('krb',$in{'formname'});" />
1.80      albertel  995: <input type="radio" name="krbver" value="4" $check4 />Version 4
                    996: <input type="radio" name="krbver" value="5" $check5 />Version 5
1.32      matthew   997: END
                    998:     return $result;
                    999: }
                   1000: 
                   1001: sub authform_internal{  
                   1002:     my %args = (
                   1003:                 formname => 'document.cu',
                   1004:                 kerb_def_dom => 'MSU.EDU',
                   1005:                 @_,
                   1006:                 );
                   1007:     my $result='';
                   1008:     $result.=<<"END";
                   1009: <input type="radio" name="login" value="int"
                   1010:        onchange="javascript:changed_radio('int',$args{'formname'});"
1.57      albertel 1011:        onclick="javascript:changed_radio('int',$args{'formname'});" />
1.32      matthew  1012: Internally authenticated (with initial password 
                   1013: <input type="text" size="10" name="intarg" value=""
1.75      www      1014:        onchange="javascript:changed_text('int',$args{'formname'});" />)
1.32      matthew  1015: END
                   1016:     return $result;
                   1017: }
                   1018: 
                   1019: sub authform_local{  
                   1020:     my %in = (
                   1021:               formname => 'document.cu',
                   1022:               kerb_def_dom => 'MSU.EDU',
                   1023:               @_,
                   1024:               );
                   1025:     my $result='';
                   1026:     $result.=<<"END";
                   1027: <input type="radio" name="login" value="loc"
                   1028:        onchange="javascript:changed_radio('loc',$in{'formname'});"
1.57      albertel 1029:        onclick="javascript:changed_radio('loc',$in{'formname'});" />
1.32      matthew  1030: Local Authentication with argument
                   1031: <input type="text" size="10" name="locarg" value=""
1.57      albertel 1032:        onchange="javascript:changed_text('loc',$in{'formname'});" />
1.32      matthew  1033: END
                   1034:     return $result;
                   1035: }
                   1036: 
                   1037: sub authform_filesystem{  
                   1038:     my %in = (
                   1039:               formname => 'document.cu',
                   1040:               kerb_def_dom => 'MSU.EDU',
                   1041:               @_,
                   1042:               );
                   1043:     my $result='';
                   1044:     $result.=<<"END";
                   1045: <input type="radio" name="login" value="fsys" 
                   1046:        onchange="javascript:changed_radio('fsys',$in{'formname'});"
1.57      albertel 1047:        onclick="javascript:changed_radio('fsys',$in{'formname'});" />
1.32      matthew  1048: Filesystem authenticated (with initial password 
                   1049: <input type="text" size="10" name="fsysarg" value=""
1.75      www      1050:        onchange="javascript:changed_text('fsys',$in{'formname'});">)
1.32      matthew  1051: END
                   1052:     return $result;
                   1053: }
                   1054: 
                   1055: ###############################################################
                   1056: ##   End Authentication changing form generation functions   ##
1.80      albertel 1057: ###############################################################
                   1058: 
                   1059: ###############################################################
                   1060: ##    Get Authentication Defaults for Domain                 ##
                   1061: ###############################################################
                   1062: ##
                   1063: ## Returns default authentication type and an associated argument
                   1064: ## as listed in file domain.tab
                   1065: ##
                   1066: #-------------------------------------------
                   1067: 
                   1068: =pod
                   1069: 
                   1070: =item get_auth_defaults
                   1071: 
                   1072: get_auth_defaults($target_domain) returns the default authentication
                   1073: type and an associated argument (initial password or a kerberos domain).
                   1074: These values are stored in lonTabs/domain.tab
                   1075: 
                   1076: ($def_auth, $def_arg) = &get_auth_defaults($target_domain);
                   1077: 
                   1078: If target_domain is not found in domain.tab, returns nothing ('').
                   1079: 
                   1080: =over 4
                   1081: 
                   1082: =item get_auth_defaults
                   1083: 
                   1084: =back
                   1085: 
                   1086: =cut
                   1087: 
                   1088: #-------------------------------------------
                   1089: sub get_auth_defaults {
                   1090:     my $domain=shift;
                   1091:     return ($Apache::lonnet::domain_auth_def{$domain},$Apache::lonnet::domain_auth_arg_def{$domain});
                   1092: }
                   1093: ###############################################################
                   1094: ##   End Get Authentication Defaults for Domain              ##
                   1095: ###############################################################
                   1096: 
                   1097: ###############################################################
                   1098: ##    Get Kerberos Defaults for Domain                 ##
                   1099: ###############################################################
                   1100: ##
                   1101: ## Returns default kerberos version and an associated argument
                   1102: ## as listed in file domain.tab. If not listed, provides
                   1103: ## appropriate default domain and kerberos version.
                   1104: ##
                   1105: #-------------------------------------------
                   1106: 
                   1107: =pod
                   1108: 
                   1109: =item get_kerberos_defaults
                   1110: 
                   1111: get_kerberos_defaults($target_domain) returns the default kerberos
                   1112: version and domain. If not found in domain.tabs, it defaults to
                   1113: version 4 and the domain of the server.
                   1114: 
                   1115: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
                   1116: 
                   1117: =over 4
                   1118: 
                   1119: =item get_kerberos_defaults
                   1120: 
                   1121: =back
                   1122: 
                   1123: =cut
                   1124: 
                   1125: #-------------------------------------------
                   1126: sub get_kerberos_defaults {
                   1127:     my $domain=shift;
                   1128:     my ($krbdef,$krbdefdom) =
                   1129:         &Apache::loncommon::get_auth_defaults($domain);
                   1130:     unless ($krbdef =~/^krb/ && $krbdefdom) {
                   1131:         $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
                   1132:         my $krbdefdom=$1;
                   1133:         $krbdefdom=~tr/a-z/A-Z/;
                   1134:         $krbdef = "krb4";
                   1135:     }
                   1136:     return ($krbdef,$krbdefdom);
                   1137: }
                   1138: ###############################################################
                   1139: ##   End Get Kerberos Defaults for Domain              ##
1.32      matthew  1140: ###############################################################
                   1141: 
1.46      matthew  1142: ###############################################################
                   1143: ##                Thesaurus Functions                        ##
                   1144: ###############################################################
1.20      www      1145: 
1.46      matthew  1146: =pod
1.20      www      1147: 
1.46      matthew  1148: =item initialize_keywords
                   1149: 
                   1150: Initializes the package variable %Keywords if it is empty.  Uses the
                   1151: package variable $thesaurus_db_file.
                   1152: 
                   1153: =cut
                   1154: 
                   1155: ###################################################
                   1156: 
                   1157: sub initialize_keywords {
                   1158:     return 1 if (scalar keys(%Keywords));
                   1159:     # If we are here, %Keywords is empty, so fill it up
                   1160:     #   Make sure the file we need exists...
                   1161:     if (! -e $thesaurus_db_file) {
                   1162:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
                   1163:                                  " failed because it does not exist");
                   1164:         return 0;
                   1165:     }
                   1166:     #   Set up the hash as a database
                   1167:     my %thesaurus_db;
                   1168:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 1169:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  1170:         &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
                   1171:                                  $thesaurus_db_file);
                   1172:         return 0;
                   1173:     } 
                   1174:     #  Get the average number of appearances of a word.
                   1175:     my $avecount = $thesaurus_db{'average.count'};
                   1176:     #  Put keywords (those that appear > average) into %Keywords
                   1177:     while (my ($word,$data)=each (%thesaurus_db)) {
                   1178:         my ($count,undef) = split /:/,$data;
                   1179:         $Keywords{$word}++ if ($count > $avecount);
                   1180:     }
                   1181:     untie %thesaurus_db;
                   1182:     # Remove special values from %Keywords.
                   1183:     foreach ('total.count','average.count') {
                   1184:         delete($Keywords{$_}) if (exists($Keywords{$_}));
                   1185:     }
                   1186:     return 1;
                   1187: }
                   1188: 
                   1189: ###################################################
                   1190: 
                   1191: =pod
                   1192: 
                   1193: =item keyword($word)
                   1194: 
                   1195: Returns true if $word is a keyword.  A keyword is a word that appears more 
                   1196: than the average number of times in the thesaurus database.  Calls 
                   1197: &initialize_keywords
                   1198: 
                   1199: =cut
                   1200: 
                   1201: ###################################################
1.20      www      1202: 
                   1203: sub keyword {
1.46      matthew  1204:     return if (!&initialize_keywords());
                   1205:     my $word=lc(shift());
                   1206:     $word=~s/\W//g;
                   1207:     return exists($Keywords{$word});
1.20      www      1208: }
1.46      matthew  1209: 
                   1210: ###############################################################
                   1211: 
                   1212: =pod 
1.20      www      1213: 
1.46      matthew  1214: =item get_related_words
                   1215: 
                   1216: Look up a word in the thesaurus.  Takes a scalar arguement and returns
                   1217: an array of words.  If the keyword is not in the thesaurus, an empty array
                   1218: will be returned.  The order of the words returned is determined by the
                   1219: database which holds them.
                   1220: 
                   1221: Uses global $thesaurus_db_file.
                   1222: 
                   1223: =cut
                   1224: 
                   1225: ###############################################################
                   1226: sub get_related_words {
                   1227:     my $keyword = shift;
                   1228:     my %thesaurus_db;
                   1229:     if (! -e $thesaurus_db_file) {
                   1230:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
                   1231:                                  "failed because the file does not exist");
                   1232:         return ();
                   1233:     }
                   1234:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 1235:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  1236:         return ();
                   1237:     } 
                   1238:     my @Words=();
                   1239:     if (exists($thesaurus_db{$keyword})) {
                   1240:         $_ = $thesaurus_db{$keyword};
                   1241:         (undef,@Words) = split/:/;  # The first element is the number of times
                   1242:                                     # the word appears.  We do not need it now.
                   1243:         for (my $i=0;$i<=$#Words;$i++) {
                   1244:             ($Words[$i],undef)= split/\,/,$Words[$i];
1.20      www      1245:         }
                   1246:     }
1.46      matthew  1247:     untie %thesaurus_db;
                   1248:     return @Words;
1.14      harris41 1249: }
1.46      matthew  1250: 
                   1251: ###############################################################
                   1252: ##              End Thesaurus Functions                      ##
                   1253: ###############################################################
1.61      www      1254: 
                   1255: # -------------------------------------------------------------- Plaintext name
1.81      albertel 1256: =pod
                   1257: 
                   1258: =item plainname($uname,$udom)
                   1259: 
                   1260: Gets a users name and returns it as a string in
                   1261: "first middle last generation"
                   1262: form
                   1263: 
                   1264: =cut
1.61      www      1265: 
1.81      albertel 1266: ###############################################################
1.61      www      1267: sub plainname {
                   1268:     my ($uname,$udom)=@_;
                   1269:     my %names=&Apache::lonnet::get('environment',
                   1270:                     ['firstname','middlename','lastname','generation'],
                   1271: 					 $udom,$uname);
1.62      www      1272:     my $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
1.61      www      1273: 	$names{'lastname'}.' '.$names{'generation'};
1.62      www      1274:     $name=~s/\s+$//;
                   1275:     $name=~s/\s+/ /g;
                   1276:     return $name;
1.61      www      1277: }
1.66      www      1278: 
                   1279: # -------------------------------------------------------------------- Nickname
1.81      albertel 1280: =pod
                   1281: 
                   1282: =item nickname($uname,$udom)
                   1283: 
                   1284: Gets a users name and returns it as a string as
                   1285: 
                   1286: "&quot;nickname&quot;"
1.66      www      1287: 
1.81      albertel 1288: if the user has a nickname or
                   1289: 
                   1290: "first middle last generation"
                   1291: 
                   1292: if the user does not
                   1293: 
                   1294: =cut
1.66      www      1295: 
                   1296: sub nickname {
                   1297:     my ($uname,$udom)=@_;
                   1298:     my %names=&Apache::lonnet::get('environment',
                   1299:   ['nickname','firstname','middlename','lastname','generation'],$udom,$uname);
1.68      albertel 1300:     my $name=$names{'nickname'};
1.66      www      1301:     if ($name) {
                   1302:        $name='&quot;'.$name.'&quot;'; 
                   1303:     } else {
                   1304:        $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
                   1305: 	     $names{'lastname'}.' '.$names{'generation'};
                   1306:        $name=~s/\s+$//;
                   1307:        $name=~s/\s+/ /g;
                   1308:     }
                   1309:     return $name;
                   1310: }
                   1311: 
1.61      www      1312: 
                   1313: # ------------------------------------------------------------------ Screenname
1.81      albertel 1314: 
                   1315: =pod
                   1316: 
                   1317: =item screenname($uname,$udom)
                   1318: 
                   1319: Gets a users screenname and returns it as a string
                   1320: 
                   1321: =cut
1.61      www      1322: 
                   1323: sub screenname {
                   1324:     my ($uname,$udom)=@_;
                   1325:     my %names=
                   1326:  &Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68      albertel 1327:     return $names{'screenname'};
1.62      www      1328: }
                   1329: 
                   1330: # ------------------------------------------------------------- Message Wrapper
                   1331: 
                   1332: sub messagewrapper {
                   1333:     my ($link,$un,$do)=@_;
                   1334:     return 
                   1335: "<a href='/adm/email?compose=individual&recname=$un&recdom=$do'>$link</a>";
1.74      www      1336: }
                   1337: # --------------------------------------------------------------- Notes Wrapper
                   1338: 
                   1339: sub noteswrapper {
                   1340:     my ($link,$un,$do)=@_;
                   1341:     return 
                   1342: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62      www      1343: }
                   1344: # ------------------------------------------------------------- Aboutme Wrapper
                   1345: 
                   1346: sub aboutmewrapper {
1.69      matthew  1347:     my ($link,$username,$domain)=@_;
                   1348:     return "<a href='/adm/$domain/$username/aboutme'>$link</a>";
1.62      www      1349: }
                   1350: 
                   1351: # ------------------------------------------------------------ Syllabus Wrapper
                   1352: 
                   1353: 
                   1354: sub syllabuswrapper {
1.73      www      1355:     my ($link,$un,$do,$tf)=@_;
                   1356:     if ($tf) { $link='<font color="'.$tf.'">'.$link.'</font>'; }
1.62      www      1357:     return "<a href='/public/$do/$un/syllabus'>$link</a>";
1.61      www      1358: }
1.14      harris41 1359: 
                   1360: # ---------------------------------------------------------------- Language IDs
                   1361: sub languageids {
1.16      harris41 1362:     return sort(keys(%language));
1.14      harris41 1363: }
                   1364: 
                   1365: # -------------------------------------------------------- Language Description
                   1366: sub languagedescription {
1.16      harris41 1367:     return $language{shift(@_)};
1.97      www      1368: }
                   1369: 
                   1370: # ----------------------------------------------------------- Display Languages
                   1371: # returns a hash with all desired display languages
                   1372: #
                   1373: 
                   1374: sub display_languages {
                   1375:     my %languages=();
                   1376:     if ($ENV{'environment.languages'}) {
                   1377: 	foreach (split(/\s*(\,|\;|\:)\s*/,$ENV{'environment.languages'})) {
1.104     www      1378: 	    $languages{$_}=1;
                   1379:         }
                   1380:     }
                   1381:     if ($ENV{'course.'.$ENV{'request.course.id'}.'.languages'}) {
                   1382: 	foreach (split(/\s*(\,|\;|\:)\s*/,
                   1383: 	$ENV{'course.'.$ENV{'request.course.id'}.'.languages'})) {
1.97      www      1384: 	    $languages{$_}=1;
                   1385:         }
                   1386:     }
                   1387:     &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
                   1388:     if ($ENV{'form.displaylanguage'}) {
                   1389: 	foreach (split(/\s*(\,|\;|\:)\s*/,$ENV{'form.displaylanguage'})) {
                   1390: 	    $languages{$_}=1;
                   1391:         }
                   1392:     }
                   1393:     return %languages;
1.14      harris41 1394: }
                   1395: 
                   1396: # --------------------------------------------------------------- Copyright IDs
                   1397: sub copyrightids {
1.16      harris41 1398:     return sort(keys(%cprtag));
1.14      harris41 1399: }
                   1400: 
                   1401: # ------------------------------------------------------- Copyright Description
                   1402: sub copyrightdescription {
1.16      harris41 1403:     return $cprtag{shift(@_)};
1.14      harris41 1404: }
                   1405: 
                   1406: # ------------------------------------------------------------- File Categories
                   1407: sub filecategories {
1.41      ng       1408:     return sort(keys(%category_extensions));
1.15      harris41 1409: }
1.14      harris41 1410: 
1.17      harris41 1411: # -------------------------------------- File Types within a specified category
1.15      harris41 1412: sub filecategorytypes {
1.41      ng       1413:     return @{$category_extensions{lc($_[0])}};
1.14      harris41 1414: }
                   1415: 
                   1416: # ------------------------------------------------------------------ File Types
                   1417: sub fileextensions {
1.16      harris41 1418:     return sort(keys(%fe));
1.14      harris41 1419: }
                   1420: 
                   1421: # ------------------------------------------------------------- Embedding Style
                   1422: sub fileembstyle {
1.16      harris41 1423:     return $fe{lc(shift(@_))};
1.14      harris41 1424: }
                   1425: 
                   1426: # ------------------------------------------------------------ Description Text
                   1427: sub filedescription {
1.16      harris41 1428:     return $fd{lc(shift(@_))};
                   1429: }
                   1430: 
                   1431: # ------------------------------------------------------------ Description Text
                   1432: sub filedescriptionex {
                   1433:     my $ex=shift;
                   1434:     return '.'.$ex.' '.$fd{lc($ex)};
1.12      harris41 1435: }
1.1       albertel 1436: 
1.40      ng       1437: # ---- Retrieve attempts by students
                   1438: # input
                   1439: # $symb             - problem including path
                   1440: # $username,$domain - that of the student
                   1441: # $course           - course name
                   1442: # $getattempt       - leave blank if want all attempts, else put something.
1.43      ng       1443: # $regexp           - regular expression. If string matches regexp send to
                   1444: # $gradesub         - routine that process the string if it matches regexp
1.40      ng       1445: # 
                   1446: # output
                   1447: # formatted as a table all the attempts, if any.
                   1448: #
1.1       albertel 1449: sub get_previous_attempt {
1.43      ng       1450:   my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1       albertel 1451:   my $prevattempts='';
1.43      ng       1452:   no strict 'refs';
1.1       albertel 1453:   if ($symb) {
1.3       albertel 1454:     my (%returnhash)=
                   1455:       &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1       albertel 1456:     if ($returnhash{'version'}) {
                   1457:       my %lasthash=();
                   1458:       my $version;
                   1459:       for ($version=1;$version<=$returnhash{'version'};$version++) {
1.19      harris41 1460:         foreach (sort(split(/\:/,$returnhash{$version.':keys'}))) {
1.1       albertel 1461: 	  $lasthash{$_}=$returnhash{$version.':'.$_};
1.19      harris41 1462:         }
1.1       albertel 1463:       }
1.43      ng       1464:       $prevattempts='<table border="0" width="100%"><tr><td bgcolor="#777777">';
1.40      ng       1465:       $prevattempts.='<table border="0" width="100%"><tr bgcolor="#e6ffff"><td>History</td>';
1.16      harris41 1466:       foreach (sort(keys %lasthash)) {
1.31      albertel 1467: 	my ($ign,@parts) = split(/\./,$_);
1.41      ng       1468: 	if ($#parts > 0) {
1.31      albertel 1469: 	  my $data=$parts[-1];
                   1470: 	  pop(@parts);
1.40      ng       1471: 	  $prevattempts.='<td>Part '.join('.',@parts).'<br />'.$data.'&nbsp;</td>';
1.31      albertel 1472: 	} else {
1.41      ng       1473: 	  if ($#parts == 0) {
                   1474: 	    $prevattempts.='<th>'.$parts[0].'</th>';
                   1475: 	  } else {
                   1476: 	    $prevattempts.='<th>'.$ign.'</th>';
                   1477: 	  }
1.31      albertel 1478: 	}
1.16      harris41 1479:       }
1.40      ng       1480:       if ($getattempt eq '') {
                   1481: 	for ($version=1;$version<=$returnhash{'version'};$version++) {
                   1482: 	  $prevattempts.='</tr><tr bgcolor="#ffffe6"><td>Transaction '.$version.'</td>';
                   1483: 	    foreach (sort(keys %lasthash)) {
                   1484: 	       my $value;
                   1485: 	       if ($_ =~ /timestamp/) {
                   1486: 		  $value=scalar(localtime($returnhash{$version.':'.$_}));
                   1487: 	       } else {
                   1488: 		  $value=$returnhash{$version.':'.$_};
                   1489: 	       }
                   1490: 	       $prevattempts.='<td>'.$value.'&nbsp;</td>';   
                   1491: 	    }
                   1492: 	 }
1.1       albertel 1493:       }
1.40      ng       1494:       $prevattempts.='</tr><tr bgcolor="#ffffe6"><td>Current</td>';
1.16      harris41 1495:       foreach (sort(keys %lasthash)) {
1.5       albertel 1496: 	my $value;
                   1497: 	if ($_ =~ /timestamp/) {
                   1498: 	  $value=scalar(localtime($lasthash{$_}));
                   1499: 	} else {
                   1500: 	  $value=$lasthash{$_};
                   1501: 	}
1.49      ng       1502: 	if ($_ =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
1.40      ng       1503: 	$prevattempts.='<td>'.$value.'&nbsp;</td>';
1.16      harris41 1504:       }
1.40      ng       1505:       $prevattempts.='</tr></table></td></tr></table>';
1.1       albertel 1506:     } else {
                   1507:       $prevattempts='Nothing submitted - no attempts.';
                   1508:     }
                   1509:   } else {
                   1510:     $prevattempts='No data.';
                   1511:   }
1.10      albertel 1512: }
                   1513: 
                   1514: sub get_student_view {
1.64      sakharuk 1515:   my ($symb,$username,$domain,$courseid,$target) = @_;
1.10      albertel 1516:   my ($map,$id,$feedurl) = split(/___/,$symb);
                   1517:   my (%old,%moreenv);
                   1518:   my @elements=('symb','courseid','domain','username');
                   1519:   foreach my $element (@elements) {
                   1520:     $old{$element}=$ENV{'form.grade_'.$element};
                   1521:     $moreenv{'form.grade_'.$element}=eval '$'.$element #'
                   1522:   }
1.64      sakharuk 1523:   if ($target eq 'tex') {$moreenv{'form.grade_target'} = 'tex';}
1.11      albertel 1524:   &Apache::lonnet::appenv(%moreenv);
1.105     www      1525:   my $userview=&Apache::lonnet::ssi_body(&Apache::lonnet::clutter($feedurl));
1.11      albertel 1526:   &Apache::lonnet::delenv('form.grade_');
                   1527:   foreach my $element (@elements) {
                   1528:     $ENV{'form.grade_'.$element}=$old{$element};
                   1529:   }
                   1530:   $userview=~s/\<body[^\>]*\>//gi;
                   1531:   $userview=~s/\<\/body\>//gi;
                   1532:   $userview=~s/\<html\>//gi;
                   1533:   $userview=~s/\<\/html\>//gi;
                   1534:   $userview=~s/\<head\>//gi;
                   1535:   $userview=~s/\<\/head\>//gi;
                   1536:   $userview=~s/action\s*\=/would_be_action\=/gi;
                   1537:   return $userview;
                   1538: }
                   1539: 
                   1540: sub get_student_answers {
1.100     sakharuk 1541:   my ($symb,$username,$domain,$courseid,%form) = @_;
1.11      albertel 1542:   my ($map,$id,$feedurl) = split(/___/,$symb);
                   1543:   my (%old,%moreenv);
                   1544:   my @elements=('symb','courseid','domain','username');
                   1545:   foreach my $element (@elements) {
                   1546:     $old{$element}=$ENV{'form.grade_'.$element};
                   1547:     $moreenv{'form.grade_'.$element}=eval '$'.$element #'
                   1548:   }
                   1549:   $moreenv{'form.grade_target'}='answer';
1.10      albertel 1550:   &Apache::lonnet::appenv(%moreenv);
1.100     sakharuk 1551:   my $userview=&Apache::lonnet::ssi('/res/'.$feedurl,%form);
1.10      albertel 1552:   &Apache::lonnet::delenv('form.grade_');
                   1553:   foreach my $element (@elements) {
                   1554:     $ENV{'form.grade_'.$element}=$old{$element};
                   1555:   }
                   1556:   return $userview;
1.1       albertel 1557: }
1.37      matthew  1558: 
                   1559: ###############################################
1.51      www      1560: 
                   1561: 
                   1562: sub timehash {
                   1563:     my @ltime=localtime(shift);
                   1564:     return ( 'seconds' => $ltime[0],
                   1565:              'minutes' => $ltime[1],
                   1566:              'hours'   => $ltime[2],
                   1567:              'day'     => $ltime[3],
                   1568:              'month'   => $ltime[4]+1,
                   1569:              'year'    => $ltime[5]+1900,
                   1570:              'weekday' => $ltime[6],
                   1571:              'dayyear' => $ltime[7]+1,
                   1572:              'dlsav'   => $ltime[8] );
                   1573: }
                   1574: 
                   1575: sub maketime {
                   1576:     my %th=@_;
                   1577:     return POSIX::mktime(
                   1578:         ($th{'seconds'},$th{'minutes'},$th{'hours'},
                   1579:          $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,$th{'dlsav'}));
                   1580: }
                   1581: 
1.70      www      1582: 
                   1583: #########################################
                   1584: #
                   1585: # Retro-fixing of un-backward-compatible time format
                   1586: 
                   1587: sub unsqltime {
                   1588:     my $timestamp=shift;
                   1589:     if ($timestamp=~/^(\d+)\-(\d+)\-(\d+)\s+(\d+)\:(\d+)\:(\d+)$/) {
                   1590:        $timestamp=&maketime(
                   1591: 	   'year'=>$1,'month'=>$2,'day'=>$3,
                   1592:            'hours'=>$4,'minutes'=>$5,'seconds'=>$6);
                   1593:     }
                   1594:     return $timestamp;
                   1595: }
                   1596: 
                   1597: #########################################
1.51      www      1598: 
                   1599: sub findallcourses {
                   1600:     my %courses=();
                   1601:     my $now=time;
                   1602:     foreach (keys %ENV) {
                   1603: 	if ($_=~/^user\.role\.\w+\.\/(\w+)\/(\w+)/) {
                   1604: 	    my ($starttime,$endtime)=$ENV{$_};
                   1605:             my $active=1;
                   1606:             if ($starttime) {
                   1607: 		if ($now<$starttime) { $active=0; }
                   1608:             }
                   1609:             if ($endtime) {
                   1610:                 if ($now>$endtime) { $active=0; }
                   1611:             }
                   1612:             if ($active) { $courses{$1.'_'.$2}=1; }
                   1613:         }
                   1614:     }
                   1615:     return keys %courses;
                   1616: }
1.37      matthew  1617: 
1.54      www      1618: ###############################################
1.60      matthew  1619: ###############################################
                   1620: 
                   1621: =pod
                   1622: 
1.63      www      1623: =item &determinedomain()
1.60      matthew  1624: 
                   1625: Inputs: $domain (usually will be undef)
                   1626: 
1.63      www      1627: Returns: Determines which domain should be used for designs
1.60      matthew  1628: 
                   1629: =cut
1.54      www      1630: 
1.60      matthew  1631: ###############################################
1.63      www      1632: sub determinedomain {
                   1633:     my $domain=shift;
                   1634:    if (! $domain) {
1.60      matthew  1635:         # Determine domain if we have not been given one
                   1636:         $domain = $Apache::lonnet::perlvar{'lonDefDomain'};
                   1637:         if ($ENV{'user.domain'}) { $domain=$ENV{'user.domain'}; }
                   1638:         if ($ENV{'request.role.domain'}) { 
                   1639:             $domain=$ENV{'request.role.domain'}; 
                   1640:         }
                   1641:     }
1.63      www      1642:     return $domain;
                   1643: }
                   1644: ###############################################
                   1645: =pod
                   1646: 
                   1647: =item &domainlogo()
                   1648: 
                   1649: Inputs: $domain (usually will be undef)
                   1650: 
                   1651: Returns: A link to a domain logo, if the domain logo exists.
                   1652: If the domain logo does not exist, a description of the domain.
                   1653: 
                   1654: =cut
                   1655: ###############################################
                   1656: sub domainlogo {
                   1657:     my $domain = &determinedomain(shift);    
                   1658:      # See if there is a logo
1.59      www      1659:     if (-e '/home/httpd/html/adm/lonDomLogos/'.$domain.'.gif') {
1.83      albertel 1660: 	my $lonhttpdPort=$Apache::lonnet::perlvar{'lonhttpdPort'};
                   1661: 	if (!defined($lonhttpdPort)) { $lonhttpdPort='8080'; }
                   1662:         return '<img src="http://'.$ENV{'HTTP_HOST'}.':'.$lonhttpdPort.
                   1663: 	    '/adm/lonDomLogos/'.$domain.'.gif" />';
1.60      matthew  1664:     } elsif(exists($Apache::lonnet::domaindescription{$domain})) {
                   1665:         return $Apache::lonnet::domaindescription{$domain};
1.59      www      1666:     } else {
1.60      matthew  1667:         return '';
1.59      www      1668:     }
                   1669: }
1.63      www      1670: ##############################################
                   1671: 
                   1672: =pod
                   1673: 
                   1674: =item &designparm()
                   1675: 
                   1676: Inputs: $which parameter; $domain (usually will be undef)
                   1677: 
                   1678: Returns: value of designparamter $which
                   1679: 
                   1680: =cut
                   1681: ##############################################
                   1682: sub designparm {
                   1683:     my ($which,$domain)=@_;
1.96      www      1684:     if ($ENV{'environment.color.'.$which}) {
                   1685: 	return $ENV{'environment.color.'.$which};
                   1686:     }
1.63      www      1687:     $domain=&determinedomain($domain);
                   1688:     if ($designhash{$domain.'.'.$which}) {
                   1689: 	return $designhash{$domain.'.'.$which};
                   1690:     } else {
                   1691:         return $designhash{'default.'.$which};
                   1692:     }
                   1693: }
1.59      www      1694: 
1.60      matthew  1695: ###############################################
                   1696: ###############################################
                   1697: 
                   1698: =pod
                   1699: 
                   1700: =item &bodytag()
                   1701: 
                   1702: Returns a uniform header for LON-CAPA web pages.
                   1703: 
                   1704: Inputs: 
                   1705: 
                   1706:  $title, A title to be displayed on the page.
                   1707:  $function, the current role (can be undef).
                   1708:  $addentries, extra parameters for the <body> tag.
                   1709:  $bodyonly, if defined, only return the <body> tag.
                   1710:  $domain, if defined, force a given domain.
1.86      www      1711:  $forcereg, if page should register as content page (relevant for 
                   1712:             text interface only)
1.60      matthew  1713: 
                   1714: Returns: A uniform header for LON-CAPA web pages.  
                   1715: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
                   1716: If $bodyonly is undef or zero, an html string containing a <body> tag and 
                   1717: other decorations will be returned.
                   1718: 
                   1719: =cut
                   1720: 
                   1721: ###############################################
1.63      www      1722: 
                   1723: 
1.60      matthew  1724: ###############################################
1.54      www      1725: sub bodytag {
1.86      www      1726:     my ($title,$function,$addentries,$bodyonly,$domain,$forcereg)=@_;
1.55      www      1727:     unless ($function) {
                   1728: 	$function='student';
                   1729:         if ($ENV{'request.role'}=~/^(cc|in|ta|ep)/) {
                   1730: 	    $function='coordinator';
                   1731:         }
                   1732: 	if ($ENV{'request.role'}=~/^(su|dc|ad|li)/) {
                   1733:             $function='admin';
                   1734:         }
                   1735:         if (($ENV{'request.role'}=~/^(au|ca)/) ||
                   1736:             ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
                   1737:             $function='author';
                   1738:         }
                   1739:     }
1.63      www      1740:     my $img=&designparm($function.'.img',$domain);
                   1741:     my $pgbg=&designparm($function.'.pgbg',$domain);
                   1742:     my $tabbg=&designparm($function.'.tabbg',$domain);
                   1743:     my $font=&designparm($function.'.font',$domain);
                   1744:     my $link=&designparm($function.'.link',$domain);
                   1745:     my $alink=&designparm($function.'.alink',$domain);
                   1746:     my $vlink=&designparm($function.'.vlink',$domain);
                   1747:     my $sidebg=&designparm($function.'.sidebg',$domain);
                   1748: 
                   1749:  # role and realm
1.55      www      1750:     my ($role,$realm)
                   1751:        =&Apache::lonnet::plaintext((split(/\./,$ENV{'request.role'}))[0]);
                   1752: # realm
1.54      www      1753:     if ($ENV{'request.course.id'}) {
1.55      www      1754: 	$realm=
                   1755:          $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
1.54      www      1756:     }
1.55      www      1757:     unless ($realm) { $realm='&nbsp;'; }
                   1758: # Set messages
1.60      matthew  1759:     my $messages=&domainlogo($domain);
1.101     www      1760: # Port for miniserver
1.83      albertel 1761:     my $lonhttpdPort=$Apache::lonnet::perlvar{'lonhttpdPort'};
                   1762:     if (!defined($lonhttpdPort)) { $lonhttpdPort='8080'; }
1.101     www      1763: # construct main body tag
1.60      matthew  1764:     my $bodytag = <<END;
1.54      www      1765: <body bgcolor="$pgbg" text="$font" alink="$alink" vlink="$vlink" link="$link"
                   1766: $addentries>
1.60      matthew  1767: END
1.94      www      1768:     my $upperleft='<img src="http://'.$ENV{'HTTP_HOST'}.':'.
                   1769:                    $lonhttpdPort.$img.'" />';
1.60      matthew  1770:     if ($bodyonly) {
                   1771:         return $bodytag;
1.79      www      1772:     } elsif ($ENV{'browser.interface'} eq 'textual') {
1.95      www      1773: # Accessibility
1.93      www      1774:         return $bodytag.&Apache::lonmenu::menubuttons($forcereg,'web',
                   1775:                                                       $forcereg).
                   1776:                '<h1>LON-CAPA: '.$title.'</h1>';
                   1777:     } elsif ($ENV{'environment.remote'} eq 'off') {
1.95      www      1778: # No Remote
                   1779:         return $bodytag.&Apache::lonmenu::menubuttons($forcereg,'web',
                   1780:                                                       $forcereg).
                   1781:                '<table bgcolor="'.$pgbg.'" width="100%" border="0" cellspacing="3" cellpadding="3"><tr><td bgcolor="'.$tabbg.'"><font size="+3" color="'.$font.'"><b>'.$title.
                   1782: '</b></font></td></tr></table>';
1.94      www      1783:     }
1.95      www      1784: 
1.93      www      1785: #
1.95      www      1786: # Top frame rendering, Remote is up
1.93      www      1787: #
1.94      www      1788:     return(<<ENDBODY);
1.60      matthew  1789: $bodytag
1.55      www      1790: <table width="100%" cellspacing="0" border="0" cellpadding="0">
1.95      www      1791: <tr><td bgcolor="$sidebg">
1.94      www      1792: $upperleft</td>
1.95      www      1793: <td bgcolor="$sidebg" align="right">$messages&nbsp;</td>
1.55      www      1794: </tr>
1.54      www      1795: <tr>
1.55      www      1796: <td rowspan="3" bgcolor="$tabbg">
                   1797: &nbsp;<font size="5"><b>$title</b></font>
1.54      www      1798: <td bgcolor="$tabbg"  align="right">
                   1799: <font size="2">
                   1800:     $ENV{'environment.firstname'}
                   1801:     $ENV{'environment.middlename'}
                   1802:     $ENV{'environment.lastname'}
                   1803:     $ENV{'environment.generation'}
1.55      www      1804:     </font>&nbsp;
1.54      www      1805: </td>
                   1806: </tr>
                   1807: <tr><td bgcolor="$tabbg" align="right">
1.55      www      1808: <font size="2">$role</font>&nbsp;
1.54      www      1809: </td></tr>
1.55      www      1810: <tr>
                   1811: <td bgcolor="$tabbg" align="right"><font size="2">$realm</font>&nbsp;</td></tr>
1.54      www      1812: </table><br>
                   1813: ENDBODY
                   1814: }
1.99      www      1815: 
                   1816: ###############################################
                   1817: 
                   1818: sub get_posted_cgi {
                   1819:     my $r=shift;
                   1820: 
                   1821:     my $buffer;
                   1822:     
                   1823:     $r->read($buffer,$r->header_in('Content-length'),0);
                   1824:     unless ($buffer=~/^(\-+\w+)\s+Content\-Disposition\:\s*form\-data/si) {
                   1825: 	my @pairs=split(/&/,$buffer);
                   1826: 	my $pair;
                   1827: 	foreach $pair (@pairs) {
                   1828: 	    my ($name,$value) = split(/=/,$pair);
                   1829: 	    $value =~ tr/+/ /;
                   1830: 	    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
                   1831: 	    $name  =~ tr/+/ /;
                   1832: 	    $name  =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
                   1833: 	    &add_to_env("form.$name",$value);
                   1834: 	}
                   1835:     } else {
                   1836: 	my $contentsep=$1;
                   1837: 	my @lines = split (/\n/,$buffer);
                   1838: 	my $name='';
                   1839: 	my $value='';
                   1840: 	my $fname='';
                   1841: 	my $fmime='';
                   1842: 	my $i;
                   1843: 	for ($i=0;$i<=$#lines;$i++) {
                   1844: 	    if ($lines[$i]=~/^$contentsep/) {
                   1845: 		if ($name) {
                   1846: 		    chomp($value);
                   1847: 		    if ($fname) {
                   1848: 			$ENV{"form.$name.filename"}=$fname;
                   1849: 			$ENV{"form.$name.mimetype"}=$fmime;
                   1850: 		    } else {
                   1851: 			$value=~s/\s+$//s;
                   1852: 		    }
                   1853: 		    &add_to_env("form.$name",$value);
                   1854: 		}
                   1855: 		if ($i<$#lines) {
                   1856: 		    $i++;
                   1857: 		    $lines[$i]=~
                   1858: 		/Content\-Disposition\:\s*form\-data\;\s*name\=\"([^\"]+)\"/i;
                   1859: 		    $name=$1;
                   1860: 		    $value='';
                   1861: 		    if ($lines[$i]=~/filename\=\"([^\"]+)\"/i) {
                   1862: 			$fname=$1;
                   1863: 			if 
                   1864:                             ($lines[$i+1]=~/Content\-Type\:\s*([\w\-\/]+)/i) {
                   1865: 				$fmime=$1;
                   1866: 				$i++;
                   1867: 			    } else {
                   1868: 				$fmime='';
                   1869: 			    }
                   1870: 		    } else {
                   1871: 			$fname='';
                   1872: 			$fmime='';
                   1873: 		    }
                   1874: 		    $i++;
                   1875: 		}
                   1876: 	    } else {
                   1877: 		$value.=$lines[$i]."\n";
                   1878: 	    }
                   1879: 	}
                   1880:     }
                   1881:     $ENV{'request.method'}=$ENV{'REQUEST_METHOD'};
                   1882:     $r->method_number(M_GET);
                   1883:     $r->method('GET');
                   1884:     $r->headers_in->unset('Content-length');
                   1885: }
                   1886: 
1.37      matthew  1887: ###############################################
1.1       albertel 1888: 
1.6       albertel 1889: sub get_unprocessed_cgi {
1.25      albertel 1890:   my ($query,$possible_names)= @_;
1.26      matthew  1891:   # $Apache::lonxml::debug=1;
1.16      harris41 1892:   foreach (split(/&/,$query)) {
1.6       albertel 1893:     my ($name, $value) = split(/=/,$_);
1.25      albertel 1894:     $name = &Apache::lonnet::unescape($name);
                   1895:     if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
                   1896:       $value =~ tr/+/ /;
                   1897:       $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
                   1898:       &Apache::lonxml::debug("Seting :$name: to :$value:");
1.30      albertel 1899:       unless (defined($ENV{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25      albertel 1900:     }
1.16      harris41 1901:   }
1.6       albertel 1902: }
                   1903: 
1.7       albertel 1904: sub cacheheader {
1.23      www      1905:   unless ($ENV{'request.method'} eq 'GET') { return ''; }
1.8       albertel 1906:   my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
1.7       albertel 1907:   my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
                   1908:                 <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
                   1909:                 <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
                   1910:   return $output;
                   1911: }
                   1912: 
1.9       albertel 1913: sub no_cache {
                   1914:   my ($r) = @_;
1.23      www      1915:   unless ($ENV{'request.method'} eq 'GET') { return ''; }
1.24      albertel 1916:   #my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
1.9       albertel 1917:   $r->no_cache(1);
                   1918:   $r->header_out("Pragma" => "no-cache");
1.24      albertel 1919:   #$r->header_out("Expires" => $date);
1.9       albertel 1920: }
1.25      albertel 1921: 
                   1922: sub add_to_env {
                   1923:   my ($name,$value)=@_;
1.28      albertel 1924:   if (defined($ENV{$name})) {
1.27      albertel 1925:     if (ref($ENV{$name})) {
1.25      albertel 1926:       #already have multiple values
                   1927:       push(@{ $ENV{$name} },$value);
                   1928:     } else {
                   1929:       #first time seeing multiple values, convert hash entry to an arrayref
                   1930:       my $first=$ENV{$name};
                   1931:       undef($ENV{$name});
                   1932:       push(@{ $ENV{$name} },$first,$value);
                   1933:     }
                   1934:   } else {
                   1935:     $ENV{$name}=$value;
                   1936:   }
1.31      albertel 1937: }
                   1938: 
1.41      ng       1939: =pod
1.45      matthew  1940: 
                   1941: =back 
1.41      ng       1942: 
                   1943: =head2 CSV Upload/Handling functions
1.38      albertel 1944: 
1.41      ng       1945: =over 4
                   1946: 
                   1947: =item  upfile_store($r)
                   1948: 
                   1949: Store uploaded file, $r should be the HTTP Request object,
                   1950: needs $ENV{'form.upfile'}
                   1951: returns $datatoken to be put into hidden field
                   1952: 
                   1953: =cut
1.31      albertel 1954: 
                   1955: sub upfile_store {
                   1956:     my $r=shift;
                   1957:     $ENV{'form.upfile'}=~s/\r/\n/gs;
                   1958:     $ENV{'form.upfile'}=~s/\f/\n/gs;
                   1959:     $ENV{'form.upfile'}=~s/\n+/\n/gs;
                   1960:     $ENV{'form.upfile'}=~s/\n+$//gs;
                   1961: 
                   1962:     my $datatoken=$ENV{'user.name'}.'_'.$ENV{'user.domain'}.
                   1963: 	'_enroll_'.$ENV{'request.course.id'}.'_'.time.'_'.$$;
                   1964:     {
                   1965: 	my $fh=Apache::File->new('>'.$r->dir_config('lonDaemons').
                   1966: 				 '/tmp/'.$datatoken.'.tmp');
                   1967: 	print $fh $ENV{'form.upfile'};
                   1968:     }
                   1969:     return $datatoken;
                   1970: }
                   1971: 
1.56      matthew  1972: =pod
                   1973: 
1.41      ng       1974: =item load_tmp_file($r)
                   1975: 
                   1976: Load uploaded file from tmp, $r should be the HTTP Request object,
                   1977: needs $ENV{'form.datatoken'},
                   1978: sets $ENV{'form.upfile'} to the contents of the file
                   1979: 
                   1980: =cut
1.31      albertel 1981: 
                   1982: sub load_tmp_file {
                   1983:     my $r=shift;
                   1984:     my @studentdata=();
                   1985:     {
                   1986: 	my $fh;
                   1987: 	if ($fh=Apache::File->new($r->dir_config('lonDaemons').
                   1988: 				  '/tmp/'.$ENV{'form.datatoken'}.'.tmp')) {
                   1989: 	    @studentdata=<$fh>;
                   1990: 	}
                   1991:     }
                   1992:     $ENV{'form.upfile'}=join('',@studentdata);
                   1993: }
                   1994: 
1.56      matthew  1995: =pod
                   1996: 
1.41      ng       1997: =item upfile_record_sep()
                   1998: 
                   1999: Separate uploaded file into records
                   2000: returns array of records,
                   2001: needs $ENV{'form.upfile'} and $ENV{'form.upfiletype'}
                   2002: 
                   2003: =cut
1.31      albertel 2004: 
                   2005: sub upfile_record_sep {
                   2006:     if ($ENV{'form.upfiletype'} eq 'xml') {
                   2007:     } else {
                   2008: 	return split(/\n/,$ENV{'form.upfile'});
                   2009:     }
                   2010: }
                   2011: 
1.56      matthew  2012: =pod
                   2013: 
1.41      ng       2014: =item record_sep($record)
                   2015: 
                   2016: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $ENV{'form.upfiletype'}
                   2017: 
                   2018: =cut
                   2019: 
1.31      albertel 2020: sub record_sep {
                   2021:     my $record=shift;
                   2022:     my %components=();
                   2023:     if ($ENV{'form.upfiletype'} eq 'xml') {
                   2024:     } elsif ($ENV{'form.upfiletype'} eq 'space') {
                   2025:         my $i=0;
                   2026:         foreach (split(/\s+/,$record)) {
                   2027:             my $field=$_;
                   2028:             $field=~s/^(\"|\')//;
                   2029:             $field=~s/(\"|\')$//;
                   2030:             $components{$i}=$field;
                   2031:             $i++;
                   2032:         }
                   2033:     } elsif ($ENV{'form.upfiletype'} eq 'tab') {
                   2034:         my $i=0;
                   2035:         foreach (split(/\t+/,$record)) {
                   2036:             my $field=$_;
                   2037:             $field=~s/^(\"|\')//;
                   2038:             $field=~s/(\"|\')$//;
                   2039:             $components{$i}=$field;
                   2040:             $i++;
                   2041:         }
                   2042:     } else {
                   2043:         my @allfields=split(/\,/,$record);
                   2044:         my $i=0;
                   2045:         my $j;
                   2046:         for ($j=0;$j<=$#allfields;$j++) {
                   2047:             my $field=$allfields[$j];
                   2048:             if ($field=~/^\s*(\"|\')/) {
                   2049: 		my $delimiter=$1;
                   2050:                 while (($field!~/$delimiter$/) && ($j<$#allfields)) {
                   2051: 		    $j++;
                   2052: 		    $field.=','.$allfields[$j];
                   2053: 		}
                   2054:                 $field=~s/^\s*$delimiter//;
                   2055:                 $field=~s/$delimiter\s*$//;
                   2056:             }
                   2057:             $components{$i}=$field;
                   2058: 	    $i++;
                   2059:         }
                   2060:     }
                   2061:     return %components;
                   2062: }
                   2063: 
1.56      matthew  2064: =pod
                   2065: 
1.41      ng       2066: =item upfile_select_html()
                   2067: 
                   2068: return HTML code to select file and specify its type
                   2069: 
                   2070: =cut
                   2071: 
1.31      albertel 2072: sub upfile_select_html {
                   2073:     return (<<'ENDUPFORM');
1.57      albertel 2074: <input type="file" name="upfile" size="50" />
1.31      albertel 2075: <br />Type: <select name="upfiletype">
                   2076: <option value="csv">CSV (comma separated values, spreadsheet)</option>
                   2077: <option value="space">Space separated</option>
                   2078: <option value="tab">Tabulator separated</option>
                   2079: <option value="xml">HTML/XML</option>
                   2080: </select>
                   2081: ENDUPFORM
                   2082: }
                   2083: 
1.56      matthew  2084: =pod
                   2085: 
1.41      ng       2086: =item csv_print_samples($r,$records)
                   2087: 
                   2088: Prints a table of sample values from each column uploaded $r is an
                   2089: Apache Request ref, $records is an arrayref from
                   2090: &Apache::loncommon::upfile_record_sep
                   2091: 
                   2092: =cut
                   2093: 
1.31      albertel 2094: sub csv_print_samples {
                   2095:     my ($r,$records) = @_;
                   2096:     my (%sone,%stwo,%sthree);
                   2097:     %sone=&record_sep($$records[0]);
                   2098:     if (defined($$records[1])) {%stwo=&record_sep($$records[1]);}
                   2099:     if (defined($$records[2])) {%sthree=&record_sep($$records[2]);}
                   2100: 
                   2101:     $r->print('Samples<br /><table border="2"><tr>');
                   2102:     foreach (sort({$a <=> $b} keys(%sone))) { $r->print('<th>Column&nbsp;'.($_+1).'</th>'); }
                   2103:     $r->print('</tr>');
                   2104:     foreach my $hash (\%sone,\%stwo,\%sthree) {
                   2105: 	$r->print('<tr>');
                   2106: 	foreach (sort({$a <=> $b} keys(%sone))) {
                   2107: 	    $r->print('<td>');
                   2108: 	    if (defined($$hash{$_})) { $r->print($$hash{$_}); }
                   2109: 	    $r->print('</td>');
                   2110: 	}
                   2111: 	$r->print('</tr>');
                   2112:     }
                   2113:     $r->print('</tr></table><br />'."\n");
                   2114: }
                   2115: 
1.56      matthew  2116: =pod
                   2117: 
1.41      ng       2118: =item csv_print_select_table($r,$records,$d)
                   2119: 
                   2120: Prints a table to create associations between values and table columns.
                   2121: $r is an Apache Request ref,
                   2122: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
                   2123: $d is an array of 2 element arrays (internal name, displayed name)
                   2124: 
                   2125: =cut
                   2126: 
1.31      albertel 2127: sub csv_print_select_table {
                   2128:     my ($r,$records,$d) = @_;
                   2129:     my $i=0;my %sone;
                   2130:     %sone=&record_sep($$records[0]);
                   2131:     $r->print('Associate columns with student attributes.'."\n".
                   2132: 	     '<table border="2"><tr><th>Attribute</th><th>Column</th></tr>'."\n");
                   2133:     foreach (@$d) {
                   2134: 	my ($value,$display)=@{ $_ };
                   2135: 	$r->print('<tr><td>'.$display.'</td>');
                   2136: 
                   2137: 	$r->print('<td><select name=f'.$i.
1.32      matthew  2138: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.31      albertel 2139: 	$r->print('<option value="none"></option>');
                   2140: 	foreach (sort({$a <=> $b} keys(%sone))) {
                   2141: 	    $r->print('<option value="'.$_.'">Column '.($_+1).'</option>');
                   2142: 	}
                   2143: 	$r->print('</select></td></tr>'."\n");
                   2144: 	$i++;
                   2145:     }
                   2146:     $i--;
                   2147:     return $i;
                   2148: }
1.56      matthew  2149: 
                   2150: =pod
1.31      albertel 2151: 
1.41      ng       2152: =item csv_samples_select_table($r,$records,$d)
                   2153: 
                   2154: Prints a table of sample values from the upload and can make associate samples to internal names.
                   2155: 
                   2156: $r is an Apache Request ref,
                   2157: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
                   2158: $d is an array of 2 element arrays (internal name, displayed name)
                   2159: 
                   2160: =cut
                   2161: 
1.31      albertel 2162: sub csv_samples_select_table {
                   2163:     my ($r,$records,$d) = @_;
                   2164:     my %sone; my %stwo; my %sthree;
                   2165:     my $i=0;
                   2166: 
                   2167:     $r->print('<table border=2><tr><th>Field</th><th>Samples</th></tr>');
                   2168:     %sone=&record_sep($$records[0]);
                   2169:     if (defined($$records[1])) {%stwo=&record_sep($$records[1]);}
                   2170:     if (defined($$records[2])) {%sthree=&record_sep($$records[2]);}
                   2171: 
                   2172:     foreach (sort keys %sone) {
                   2173: 	$r->print('<tr><td><select name=f'.$i.
1.32      matthew  2174: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.31      albertel 2175: 	foreach (@$d) {
                   2176: 	    my ($value,$display)=@{ $_ };
                   2177: 	    $r->print('<option value='.$value.'>'.$display.'</option>');
                   2178: 	}
                   2179: 	$r->print('</select></td><td>');
                   2180: 	if (defined($sone{$_})) { $r->print($sone{$_}."</br>\n"); }
                   2181: 	if (defined($stwo{$_})) { $r->print($stwo{$_}."</br>\n"); }
                   2182: 	if (defined($sthree{$_})) { $r->print($sthree{$_}."</br>\n"); }
                   2183: 	$r->print('</td></tr>');
                   2184: 	$i++;
                   2185:     }
                   2186:     $i--;
                   2187:     return($i);
1.25      albertel 2188: }
1.84      albertel 2189: 
1.85      albertel 2190: =pod
                   2191: 
                   2192: =item check_if_partid_hidden($id,$symb,$udom,$uname)
                   2193: 
                   2194: Returns either 1 or undef
                   2195: 
                   2196: 1 if the part is to be hidden, undef if it is to be shown
                   2197: 
                   2198: Arguments are:
                   2199: 
                   2200: $id the id of the part to be checked
                   2201: $symb, optional the symb of the resource to check
                   2202: $udom, optional the domain of the user to check for
                   2203: $uname, optional the username of the user to check for
                   2204: 
                   2205: =cut
1.84      albertel 2206: 
                   2207: sub check_if_partid_hidden {
                   2208:     my ($id,$symb,$udom,$uname) = @_;
                   2209:     my $hiddenparts=&Apache::lonnet::EXT('resource.0.parameter_hiddenparts',
                   2210: 					 $symb,$udom,$uname);
                   2211:     my @hiddenlist=split(/,/,$hiddenparts);
                   2212:     foreach my $checkid (@hiddenlist) {
                   2213: 	if ($checkid =~ /^\s*\Q$id\E\s*$/) { return 1; }
                   2214:     }
                   2215:     return undef;
                   2216: }
                   2217: 
                   2218: 
                   2219: 
1.1       albertel 2220: 1;
                   2221: __END__;
1.17      harris41 2222: 
1.41      ng       2223: =pod
                   2224: 
                   2225: =back
                   2226: 
                   2227: =head2 Access .tab File Data
                   2228: 
                   2229: =over 4
                   2230: 
1.35      matthew  2231: =item languageids() 
1.17      harris41 2232: 
1.35      matthew  2233: returns list of all language ids
1.17      harris41 2234: 
1.35      matthew  2235: =item languagedescription() 
1.17      harris41 2236: 
1.35      matthew  2237: returns description of a specified language id
1.17      harris41 2238: 
1.35      matthew  2239: =item copyrightids() 
1.17      harris41 2240: 
1.35      matthew  2241: returns list of all copyrights
1.17      harris41 2242: 
1.35      matthew  2243: =item copyrightdescription() 
1.17      harris41 2244: 
1.35      matthew  2245: returns description of a specified copyright id
1.17      harris41 2246: 
1.35      matthew  2247: =item filecategories() 
1.17      harris41 2248: 
1.35      matthew  2249: returns list of all file categories
1.17      harris41 2250: 
1.35      matthew  2251: =item filecategorytypes() 
1.17      harris41 2252: 
1.35      matthew  2253: returns list of file types belonging to a given file
1.17      harris41 2254: category
                   2255: 
1.35      matthew  2256: =item fileembstyle() 
1.17      harris41 2257: 
1.35      matthew  2258: returns embedding style for a specified file type
1.17      harris41 2259: 
1.35      matthew  2260: =item filedescription() 
1.17      harris41 2261: 
1.35      matthew  2262: returns description for a specified file type
1.17      harris41 2263: 
1.35      matthew  2264: =item filedescriptionex() 
1.17      harris41 2265: 
1.35      matthew  2266: returns description for a specified file type with
1.17      harris41 2267: extra formatting
                   2268: 
1.41      ng       2269: =back
                   2270: 
                   2271: =head2 Alternate Problem Views
                   2272: 
                   2273: =over 4
                   2274: 
1.35      matthew  2275: =item get_previous_attempt() 
1.17      harris41 2276: 
1.35      matthew  2277: return string with previous attempt on problem
1.17      harris41 2278: 
1.35      matthew  2279: =item get_student_view() 
1.17      harris41 2280: 
1.35      matthew  2281: show a snapshot of what student was looking at
1.17      harris41 2282: 
1.35      matthew  2283: =item get_student_answers() 
1.17      harris41 2284: 
1.35      matthew  2285: show a snapshot of how student was answering problem
1.17      harris41 2286: 
1.41      ng       2287: =back
                   2288: 
                   2289: =head2 HTTP Helper
                   2290: 
                   2291: =over 4
                   2292: 
                   2293: =item get_unprocessed_cgi($query,$possible_names)
                   2294: 
                   2295: Modify the %ENV hash to contain unprocessed CGI form parameters held in
                   2296: $query.  The parameters listed in $possible_names (an array reference),
                   2297: will be set in $ENV{'form.name'} if they do not already exist.
1.17      harris41 2298: 
1.41      ng       2299: Typically called with $ENV{'QUERY_STRING'} as the first parameter.  
                   2300: $possible_names is an ref to an array of form element names.  As an example:
                   2301: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
                   2302: will result in $ENV{'form.uname'} and $ENV{'form.udom'} being set.
1.17      harris41 2303: 
1.35      matthew  2304: =item cacheheader() 
1.17      harris41 2305: 
1.35      matthew  2306: returns cache-controlling header code
1.17      harris41 2307: 
1.65      matthew  2308: =item no_cache($r) 
1.17      harris41 2309: 
1.35      matthew  2310: specifies header code to not have cache
1.25      albertel 2311: 
1.35      matthew  2312: =item add_to_env($name,$value) 
1.25      albertel 2313: 
1.35      matthew  2314: adds $name to the %ENV hash with value
1.25      albertel 2315: $value, if $name already exists, the entry is converted to an array
                   2316: reference and $value is added to the array.
1.17      harris41 2317: 
                   2318: =back
                   2319: 
                   2320: =cut

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