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

1.10      albertel    1: # The LearningOnline Network with CAPA
1.1       albertel    2: # a pile of common routines
1.10      albertel    3: #
1.66    ! www         4: # $Id: loncommon.pm,v 1.65 2002/09/09 11:50:07 matthew 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.17      harris41   30: # 12/11,12/12,12/17 Scott Harrison
1.18      www        31: # 12/21 Gerd Kortemeyer
1.20      www        32: # 12/21 Scott Harrison
1.22      www        33: # 12/25,12/28 Gerd Kortemeyer
1.23      www        34: # YEAR=2002
                     35: # 1/4 Gerd Kortemeyer
1.43      ng         36: # 6/24,7/2 H. K. Ng
1.1       albertel   37: 
                     38: # Makes a table out of the previous attempts
1.2       albertel   39: # Inputs result_from_symbread, user, domain, course_id
1.16      harris41   40: # Reads in non-network-related .tab files
1.1       albertel   41: 
1.35      matthew    42: # POD header:
                     43: 
1.45      matthew    44: =pod
                     45: 
1.35      matthew    46: =head1 NAME
                     47: 
                     48: Apache::loncommon - pile of common routines
                     49: 
                     50: =head1 SYNOPSIS
                     51: 
                     52: Referenced by other mod_perl Apache modules.
                     53: 
                     54: Invocation:
                     55:  &Apache::loncommon::SUBROUTINENAME(ARGUMENTS);
                     56: 
                     57: =head1 INTRODUCTION
                     58: 
                     59: Common collection of used subroutines.  This collection helps remove
                     60: redundancy from other modules and increase efficiency of memory usage.
                     61: 
                     62: Current things done:
                     63: 
                     64:  Makes a table out of the previous homework attempts
                     65:  Inputs result_from_symbread, user, domain, course_id
                     66:  Reads in non-network-related .tab files
                     67: 
                     68: This is part of the LearningOnline Network with CAPA project
                     69: described at http://www.lon-capa.org.
                     70: 
1.41      ng         71: =head2 General Subroutines
1.35      matthew    72: 
                     73: =over 4
                     74: 
                     75: =cut 
                     76: 
                     77: # End of POD header
1.1       albertel   78: package Apache::loncommon;
                     79: 
                     80: use strict;
1.22      www        81: use Apache::lonnet();
1.46      matthew    82: use GDBM_File;
1.51      www        83: use POSIX qw(strftime mktime);
1.1       albertel   84: use Apache::Constants qw(:common);
                     85: use Apache::lonmsg();
1.22      www        86: my $readit;
                     87: 
1.46      matthew    88: =pod 
                     89: 
                     90: =item Global Variables
                     91: 
                     92: =over 4
                     93: 
                     94: =cut
1.20      www        95: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12      harris41   96: my %language;
                     97: my %cprtag;
                     98: my %fe; my %fd;
1.41      ng         99: my %category_extensions;
1.12      harris41  100: 
1.63      www       101: # ---------------------------------------------- Designs
                    102: 
                    103: my %designhash;
                    104: 
1.46      matthew   105: # ---------------------------------------------- Thesaurus variables
                    106: 
                    107: =pod
                    108: 
                    109: =item %Keywords  
                    110: 
                    111: A hash used by &keyword to determine if a word is considered a keyword.
                    112: 
                    113: =item $thesaurus_db_file
                    114: 
                    115: Scalar containing the full path to the thesaurus database.                 
                    116: 
                    117: =cut
                    118: 
                    119: my %Keywords;
                    120: my $thesaurus_db_file;
                    121: 
                    122: 
                    123: =pod
                    124: 
                    125: =back
                    126: 
                    127: =cut
1.20      www       128: 
1.12      harris41  129: # ----------------------------------------------------------------------- BEGIN
1.41      ng        130: 
                    131: =pod
                    132: 
1.35      matthew   133: =item BEGIN() 
                    134: 
                    135: Initialize values from language.tab, copyright.tab, filetypes.tab,
1.45      matthew   136: thesaurus.tab, and filecategories.tab.
1.35      matthew   137: 
                    138: =cut
1.45      matthew   139: 
1.35      matthew   140: # ----------------------------------------------------------------------- BEGIN
                    141: 
1.18      www       142: BEGIN {
1.46      matthew   143:     # Variable initialization
                    144:     $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
                    145:     #
1.22      www       146:     unless ($readit) {
1.12      harris41  147: # ------------------------------------------------------------------- languages
                    148:     {
                    149: 	my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
                    150: 				 '/language.tab');
1.16      harris41  151: 	if ($fh) {
                    152: 	    while (<$fh>) {
                    153: 		next if /^\#/;
                    154: 		chomp;
                    155: 		my ($key,$val)=(split(/\s+/,$_,2));
                    156: 		$language{$key}=$val;
                    157: 	    }
1.12      harris41  158: 	}
                    159:     }
                    160: # ------------------------------------------------------------------ copyrights
                    161:     {
1.16      harris41  162: 	my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonIncludes'}.
                    163: 				  '/copyright.tab');
                    164: 	if ($fh) {
                    165: 	    while (<$fh>) {
                    166: 		next if /^\#/;
                    167: 		chomp;
                    168: 		my ($key,$val)=(split(/\s+/,$_,2));
                    169: 		$cprtag{$key}=$val;
                    170: 	    }
1.12      harris41  171: 	}
                    172:     }
1.63      www       173: 
                    174: # -------------------------------------------------------------- domain designs
                    175: 
                    176:     my $filename;
                    177:     my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
                    178:     opendir(DIR,$designdir);
                    179:     while ($filename=readdir(DIR)) {
                    180: 	my ($domain)=($filename=~/^(\w+)\./);
                    181:     {
                    182: 	my $fh=Apache::File->new($designdir.'/'.$filename);
                    183: 	if ($fh) {
                    184: 	    while (<$fh>) {
                    185: 		next if /^\#/;
                    186: 		chomp;
                    187: 		my ($key,$val)=(split(/\=/,$_));
                    188: 		if ($val) { $designhash{$domain.'.'.$key}=$val; }
                    189: 	    }
                    190: 	}
                    191:     }
                    192: 
                    193:     }
                    194:     closedir(DIR);
                    195: 
                    196: 
1.15      harris41  197: # ------------------------------------------------------------- file categories
                    198:     {
                    199: 	my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
1.16      harris41  200: 				  '/filecategories.tab');
                    201: 	if ($fh) {
                    202: 	    while (<$fh>) {
                    203: 		next if /^\#/;
                    204: 		chomp;
1.41      ng        205: 		my ($extension,$category)=(split(/\s+/,$_,2));
                    206: 		push @{$category_extensions{lc($category)}},$extension;
1.16      harris41  207: 	    }
1.15      harris41  208: 	}
                    209:     }
1.12      harris41  210: # ------------------------------------------------------------------ file types
                    211:     {
1.16      harris41  212: 	my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
                    213: 	       '/filetypes.tab');
                    214: 	if ($fh) {
                    215:             while (<$fh>) {
                    216: 		next if (/^\#/);
                    217: 		chomp;
                    218: 		my ($ending,$emb,$descr)=split(/\s+/,$_,3);
                    219: 		if ($descr ne '') { 
                    220: 		    $fe{$ending}=lc($emb);
                    221: 		    $fd{$ending}=$descr;
                    222: 		}
1.12      harris41  223: 	    }
                    224: 	}
                    225:     }
1.22      www       226:     &Apache::lonnet::logthis(
1.46      matthew   227:               "<font color=yellow>INFO: Read file types</font>");
1.22      www       228:     $readit=1;
1.46      matthew   229:     }  # end of unless($readit) 
1.32      matthew   230:     
                    231: }
                    232: # ============================================================= END BEGIN BLOCK
1.42      matthew   233: ###############################################################
                    234: ##           HTML and Javascript Helper Functions            ##
                    235: ###############################################################
                    236: 
                    237: =pod 
                    238: 
                    239: =item browser_and_searcher_javascript 
                    240: 
                    241: Returns scalar containing javascript to open a browser window
                    242: or a searcher window.  Also creates 
                    243: 
                    244: =over 4
                    245: 
                    246: =item openbrowser(formname,elementname,only,omit) [javascript]
                    247: 
                    248: inputs: formname, elementname, only, omit
                    249: 
                    250: formname and elementname indicate the name of the html form and name of
                    251: the element that the results of the browsing selection are to be placed in. 
                    252: 
                    253: Specifying 'only' will restrict the browser to displaying only files
                    254: with the given extension.  Can be a comma seperated list.
                    255: 
                    256: Specifying 'omit' will restrict the browser to NOT displaying files
                    257: with the given extension.  Can be a comma seperated list.
                    258: 
                    259: =item opensearcher(formname, elementname) [javascript]
                    260: 
                    261: Inputs: formname, elementname
                    262: 
                    263: formname and elementname specify the name of the html form and the name
                    264: of the element the selection from the search results will be placed in.
                    265: 
                    266: =back
                    267: 
                    268: =cut
                    269: 
                    270: ###############################################################
                    271: sub browser_and_searcher_javascript {
                    272:     return <<END;
1.50      matthew   273:     var editbrowser = null;
1.42      matthew   274:     function openbrowser(formname,elementname,only,omit) {
                    275:         var url = '/res/?';
                    276:         if (editbrowser == null) {
                    277:             url += 'launch=1&';
                    278:         }
                    279:         url += 'catalogmode=interactive&';
                    280:         url += 'mode=edit&';
                    281:         url += 'form=' + formname + '&';
                    282:         if (only != null) {
                    283:             url += 'only=' + only + '&';
                    284:         } 
                    285:         if (omit != null) {
                    286:             url += 'omit=' + omit + '&';
                    287:         }
                    288:         url += 'element=' + elementname + '';
                    289:         var title = 'Browser';
                    290:         var options = 'scrollbars=1,resizable=1,menubar=0';
                    291:         options += ',width=700,height=600';
                    292:         editbrowser = open(url,title,options,'1');
                    293:         editbrowser.focus();
                    294:     }
                    295:     var editsearcher;
                    296:     function opensearcher(formname,elementname) {
                    297:         var url = '/adm/searchcat?';
                    298:         if (editsearcher == null) {
                    299:             url += 'launch=1&';
                    300:         }
                    301:         url += 'catalogmode=interactive&';
                    302:         url += 'mode=edit&';
                    303:         url += 'form=' + formname + '&';
                    304:         url += 'element=' + elementname + '';
                    305:         var title = 'Search';
                    306:         var options = 'scrollbars=1,resizable=1,menubar=0';
                    307:         options += ',width=700,height=600';
                    308:         editsearcher = open(url,title,options,'1');
                    309:         editsearcher.focus();
                    310:     }
                    311: END
                    312: }
                    313: 
                    314: 
                    315: 
                    316: ###############################################################
                    317: 
                    318: =pod
1.36      matthew   319: 
                    320: =item linked_select_forms(...)
                    321: 
                    322: linked_select_forms returns a string containing a <script></script> block
                    323: and html for two <select> menus.  The select menus will be linked in that
                    324: changing the value of the first menu will result in new values being placed
                    325: in the second menu.  The values in the select menu will appear in alphabetical
                    326: order.
                    327: 
                    328: linked_select_forms takes the following ordered inputs:
                    329: 
                    330: =over 4
                    331: 
                    332: =item $formname, the name of the <form> tag
                    333: 
                    334: =item $middletext, the text which appears between the <select> tags
                    335: 
                    336: =item $firstdefault, the default value for the first menu
                    337: 
                    338: =item $firstselectname, the name of the first <select> tag
                    339: 
                    340: =item $secondselectname, the name of the second <select> tag
                    341: 
                    342: =item $hashref, a reference to a hash containing the data for the menus.
                    343: 
1.41      ng        344: =back 
                    345: 
1.36      matthew   346: Below is an example of such a hash.  Only the 'text', 'default', and 
                    347: 'select2' keys must appear as stated.  keys(%menu) are the possible 
                    348: values for the first select menu.  The text that coincides with the 
1.41      ng        349: first menu value is given in $menu{$choice1}->{'text'}.  The values 
1.36      matthew   350: and text for the second menu are given in the hash pointed to by 
                    351: $menu{$choice1}->{'select2'}.  
                    352: 
1.41      ng        353: my %menu = ( A1 => { text =>"Choice A1" ,
1.36      matthew   354:                       default => "B3",
                    355:                       select2 => { 
                    356:                           B1 => "Choice B1",
                    357:                           B2 => "Choice B2",
                    358:                           B3 => "Choice B3",
                    359:                           B4 => "Choice B4"
                    360:                           }
                    361:                   },
                    362:               A2 => { text =>"Choice A2" ,
                    363:                       default => "C2",
                    364:                       select2 => { 
                    365:                           C1 => "Choice C1",
                    366:                           C2 => "Choice C2",
                    367:                           C3 => "Choice C3"
                    368:                           }
                    369:                   },
                    370:               A3 => { text =>"Choice A3" ,
                    371:                       default => "D6",
                    372:                       select2 => { 
                    373:                           D1 => "Choice D1",
                    374:                           D2 => "Choice D2",
                    375:                           D3 => "Choice D3",
                    376:                           D4 => "Choice D4",
                    377:                           D5 => "Choice D5",
                    378:                           D6 => "Choice D6",
                    379:                           D7 => "Choice D7"
                    380:                           }
                    381:                   }
                    382:               );
                    383: 
                    384: =cut
                    385: 
                    386: # ------------------------------------------------
                    387: 
                    388: sub linked_select_forms {
                    389:     my ($formname,
                    390:         $middletext,
                    391:         $firstdefault,
                    392:         $firstselectname,
                    393:         $secondselectname, 
                    394:         $hashref
                    395:         ) = @_;
                    396:     my $second = "document.$formname.$secondselectname";
                    397:     my $first = "document.$formname.$firstselectname";
                    398:     # output the javascript to do the changing
                    399:     my $result = '';
                    400:     $result.="<script>\n";
                    401:     $result.="var select2data = new Object();\n";
                    402:     $" = '","';
                    403:     my $debug = '';
                    404:     foreach my $s1 (sort(keys(%$hashref))) {
                    405:         $result.="select2data.d_$s1 = new Object();\n";        
                    406:         $result.="select2data.d_$s1.def = new String('".
                    407:             $hashref->{$s1}->{'default'}."');\n";
                    408:         $result.="select2data.d_$s1.values = new Array(";        
                    409:         my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
                    410:         $result.="\"@s2values\");\n";
                    411:         $result.="select2data.d_$s1.texts = new Array(";        
                    412:         my @s2texts;
                    413:         foreach my $value (@s2values) {
                    414:             push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
                    415:         }
                    416:         $result.="\"@s2texts\");\n";
                    417:     }
                    418:     $"=' ';
                    419:     $result.= <<"END";
                    420: 
                    421: function select1_changed() {
                    422:     // Determine new choice
                    423:     var newvalue = "d_" + $first.value;
                    424:     // update select2
                    425:     var values     = select2data[newvalue].values;
                    426:     var texts      = select2data[newvalue].texts;
                    427:     var select2def = select2data[newvalue].def;
                    428:     var i;
                    429:     // out with the old
                    430:     for (i = 0; i < $second.options.length; i++) {
                    431:         $second.options[i] = null;
                    432:     }
                    433:     // in with the nuclear
                    434:     for (i=0;i<values.length; i++) {
                    435:         $second.options[i] = new Option(values[i]);
                    436:         $second.options[i].text = texts[i];
                    437:         if (values[i] == select2def) {
                    438:             $second.options[i].selected = true;
                    439:         }
                    440:     }
                    441: }
                    442: </script>
                    443: END
                    444:     # output the initial values for the selection lists
                    445:     $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
                    446:     foreach my $value (sort(keys(%$hashref))) {
                    447:         $result.="    <option value=\"$value\" ";
                    448:         $result.=" selected=\"true\" " if ($value eq $firstdefault);
                    449:         $result.=">$hashref->{$value}->{'text'}</option>\n";
                    450:     }
                    451:     $result .= "</select>\n";
                    452:     my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
                    453:     $result .= $middletext;
                    454:     $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
                    455:     my $seconddefault = $hashref->{$firstdefault}->{'default'};
                    456:     foreach my $value (sort(keys(%select2))) {
                    457:         $result.="    <option value=\"$value\" ";        
                    458:         $result.=" selected=\"true\" " if ($value eq $seconddefault);
                    459:         $result.=">$select2{$value}</option>\n";
                    460:     }
                    461:     $result .= "</select>\n";
                    462:     #    return $debug;
                    463:     return $result;
                    464: }   #  end of sub linked_select_forms {
                    465: 
1.33      matthew   466: ###############################################################
1.44      bowersj2  467: 
1.45      matthew   468: =pod
1.44      bowersj2  469: 
1.48      bowersj2  470: =item help_open_topic($topic, $text, $stayOnPage, $width, $height)
1.44      bowersj2  471: 
                    472: 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.
                    473: 
1.48      bowersj2  474: $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.
                    475: 
1.44      bowersj2  476: $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.)
                    477: 
                    478: $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.
                    479: 
                    480: =cut
                    481: 
                    482: sub help_open_topic {
1.48      bowersj2  483:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
                    484:     $text = "" if (not defined $text);
1.44      bowersj2  485:     $stayOnPage = 0 if (not defined $stayOnPage);
                    486:     $width = 350 if (not defined $width);
                    487:     $height = 400 if (not defined $height);
                    488:     my $filename = $topic;
                    489:     $filename =~ s/ /_/g;
                    490: 
1.48      bowersj2  491:     my $template = "";
                    492:     my $link;
1.44      bowersj2  493: 
                    494:     if (!$stayOnPage)
                    495:     {
1.48      bowersj2  496: 	$link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height'))";
1.44      bowersj2  497:     }
                    498:     else
                    499:     {
1.48      bowersj2  500: 	$link = "/adm/help/${filename}.hlp";
                    501:     }
                    502: 
                    503:     # Add the text
                    504:     if ($text ne "")
                    505:     {
                    506: 	$template .= "<a href=\"$link\">$text</a> ";
                    507:     }
                    508: 
                    509:     # Add the graphic
                    510:     $template .= <<"ENDTEMPLATE";
1.57      albertel  511: <a href="$link"><image src="/adm/help/gif/smallHelp.gif" border="0" alt="(Help: $topic)" /></a>
1.44      bowersj2  512: ENDTEMPLATE
                    513: 
                    514:     return $template;
                    515: 
                    516: }
1.37      matthew   517: 
1.45      matthew   518: =pod
                    519: 
1.37      matthew   520: =item csv_translate($text) 
                    521: 
                    522: Translate $text to allow it to be output as a 'comma seperated values' 
                    523: format.
                    524: 
                    525: =cut
                    526: 
                    527: sub csv_translate {
                    528:     my $text = shift;
                    529:     $text =~ s/\"/\"\"/g;
                    530:     $text =~ s/\n//g;
                    531:     return $text;
                    532: }
                    533: 
                    534: ###############################################################
1.33      matthew   535: ##        Home server <option> list generating code          ##
                    536: ###############################################################
1.35      matthew   537: #-------------------------------------------
                    538: 
1.45      matthew   539: =pod
                    540: 
1.35      matthew   541: =item get_domains()
                    542: 
                    543: Returns an array containing each of the domains listed in the hosts.tab
                    544: file.
                    545: 
                    546: =cut
                    547: 
                    548: #-------------------------------------------
1.34      matthew   549: sub get_domains {
                    550:     # The code below was stolen from "The Perl Cookbook", p 102, 1st ed.
                    551:     my @domains;
                    552:     my %seen;
                    553:     foreach (sort values(%Apache::lonnet::hostdom)) {
                    554:         push (@domains,$_) unless $seen{$_}++;
                    555:     }
                    556:     return @domains;
                    557: }
                    558: 
1.35      matthew   559: #-------------------------------------------
                    560: 
1.45      matthew   561: =pod
                    562: 
1.35      matthew   563: =item select_dom_form($defdom,$name)
                    564: 
                    565: Returns a string containing a <select name='$name' size='1'> form to 
                    566: allow a user to select the domain to preform an operation in.  
                    567: See loncreateuser.pm for an example invocation and use.
                    568: 
                    569: =cut
                    570: 
                    571: #-------------------------------------------
1.34      matthew   572: sub select_dom_form {
                    573:     my ($defdom,$name) = @_;
                    574:     my @domains = get_domains();
                    575:     my $selectdomain = "<select name=\"$name\" size=\"1\">\n";
                    576:     foreach (@domains) {
                    577:         $selectdomain.="<option value=\"$_\" ".
                    578:             ($_ eq $defdom ? 'selected' : '').
                    579:                 ">$_</option>\n";
                    580:     }
                    581:     $selectdomain.="</select>";
                    582:     return $selectdomain;
                    583: }
                    584: 
1.35      matthew   585: #-------------------------------------------
                    586: 
1.45      matthew   587: =pod
                    588: 
1.52      matthew   589: =item get_library_servers($domain)
1.35      matthew   590: 
                    591: Returns a hash which contains keys like '103l3' and values like 
                    592: 'kirk.lite.msu.edu'.  All of the keys will be for machines in the
                    593: given $domain.
                    594: 
                    595: =cut
                    596: 
                    597: #-------------------------------------------
1.52      matthew   598: sub get_library_servers {
1.33      matthew   599:     my $domain = shift;
1.52      matthew   600:     my %library_servers;
1.33      matthew   601:     foreach (keys(%Apache::lonnet::libserv)) {
                    602:         if ($Apache::lonnet::hostdom{$_} eq $domain) {
1.52      matthew   603:             $library_servers{$_} = $Apache::lonnet::hostname{$_};
1.33      matthew   604:         }
                    605:     }
1.52      matthew   606:     return %library_servers;
1.33      matthew   607: }
                    608: 
1.35      matthew   609: #-------------------------------------------
                    610: 
1.45      matthew   611: =pod
                    612: 
1.35      matthew   613: =item home_server_option_list($domain)
                    614: 
                    615: returns a string which contains an <option> list to be used in a 
                    616: <select> form input.  See loncreateuser.pm for an example.
                    617: 
                    618: =cut
                    619: 
                    620: #-------------------------------------------
1.33      matthew   621: sub home_server_option_list {
                    622:     my $domain = shift;
1.52      matthew   623:     my %servers = &get_library_servers($domain);
1.33      matthew   624:     my $result = '';
                    625:     foreach (sort keys(%servers)) {
                    626:         $result.=
                    627:             '<option value="'.$_.'">'.$_.' '.$servers{$_}."</option>\n";
                    628:     }
                    629:     return $result;
                    630: }
                    631: ###############################################################
                    632: ##    End of home server <option> list generating code       ##
                    633: ###############################################################
1.32      matthew   634: 
                    635: ###############################################################
                    636: ##    Authentication changing form generation subroutines    ##
                    637: ###############################################################
                    638: ##
                    639: ## All of the authform_xxxxxxx subroutines take their inputs in a
                    640: ## hash, and have reasonable default values.
                    641: ##
                    642: ##    formname = the name given in the <form> tag.
1.35      matthew   643: #-------------------------------------------
                    644: 
1.45      matthew   645: =pod
                    646: 
1.35      matthew   647: =item authform_xxxxxx
                    648: 
                    649: The authform_xxxxxx subroutines provide javascript and html forms which 
                    650: handle some of the conveniences required for authentication forms.  
                    651: This is not an optimal method, but it works.  
                    652: 
                    653: See loncreateuser.pm for invocation and use examples.
                    654: 
                    655: =over 4
                    656: 
                    657: =item authform_header
                    658: 
                    659: =item authform_authorwarning
                    660: 
                    661: =item authform_nochange
                    662: 
                    663: =item authform_kerberos
                    664: 
                    665: =item authform_internal
                    666: 
                    667: =item authform_filesystem
                    668: 
                    669: =back
                    670: 
                    671: =cut
                    672: 
                    673: #-------------------------------------------
1.32      matthew   674: sub authform_header{  
                    675:     my %in = (
                    676:         formname => 'cu',
                    677:         kerb_def_dom => 'MSU.EDU',
                    678:         @_,
                    679:     );
                    680:     $in{'formname'} = 'document.' . $in{'formname'};
                    681:     my $result='';
                    682:     $result.=<<"END";
                    683: var current = new Object();
                    684: current.radiovalue = 'nochange';
                    685: current.argfield = null;
                    686: 
                    687: function changed_radio(choice,currentform) {
                    688:     var choicearg = choice + 'arg';
                    689:     // If a radio button in changed, we need to change the argfield
                    690:     if (current.radiovalue != choice) {
                    691:         current.radiovalue = choice;
                    692:         if (current.argfield != null) {
                    693:             currentform.elements[current.argfield].value = '';
                    694:         }
                    695:         if (choice == 'nochange') {
                    696:             current.argfield = null;
                    697:         } else {
                    698:             current.argfield = choicearg;
                    699:             switch(choice) {
                    700:                 case 'krb': 
                    701:                     currentform.elements[current.argfield].value = 
                    702:                         "$in{'kerb_def_dom'}";
                    703:                 break;
                    704:               default:
                    705:                 break;
                    706:             }
                    707:         }
                    708:     }
                    709:     return;
                    710: }
1.22      www       711: 
1.32      matthew   712: function changed_text(choice,currentform) {
                    713:     var choicearg = choice + 'arg';
                    714:     if (currentform.elements[choicearg].value !='') {
                    715:         switch (choice) {
                    716:             case 'krb': currentform.elements[choicearg].value =
                    717:                 currentform.elements[choicearg].value.toUpperCase();
                    718:                 break;
                    719:             default:
                    720:         }
                    721:         // clear old field
                    722:         if ((current.argfield != choicearg) && (current.argfield != null)) {
                    723:             currentform.elements[current.argfield].value = '';
                    724:         }
                    725:         current.argfield = choicearg;
                    726:     }
                    727:     set_auth_radio_buttons(choice,currentform);
                    728:     return;
1.20      www       729: }
1.32      matthew   730: 
                    731: function set_auth_radio_buttons(newvalue,currentform) {
                    732:     var i=0;
                    733:     while (i < currentform.login.length) {
                    734:         if (currentform.login[i].value == newvalue) { break; }
                    735:         i++;
                    736:     }
                    737:     if (i == currentform.login.length) {
                    738:         return;
                    739:     }
                    740:     current.radiovalue = newvalue;
                    741:     currentform.login[i].checked = true;
                    742:     return;
                    743: }
                    744: END
                    745:     return $result;
                    746: }
                    747: 
                    748: sub authform_authorwarning{
                    749:     my $result='';
                    750:     $result=<<"END";
                    751: <i>As a general rule, only authors or co-authors should be filesystem
                    752: authenticated (which allows access to the server filesystem).</i>
                    753: END
                    754:     return $result;
                    755: }
                    756: 
                    757: sub authform_nochange{  
                    758:     my %in = (
                    759:               formname => 'document.cu',
                    760:               kerb_def_dom => 'MSU.EDU',
                    761:               @_,
                    762:           );
                    763:     my $result='';
                    764:     $result.=<<"END";
                    765: <input type="radio" name="login" value="nochange" checked="checked"
1.57      albertel  766:        onclick="javascript:changed_radio('nochange',$in{'formname'});" />
1.32      matthew   767: Do not change login data
                    768: END
                    769:     return $result;
                    770: }
                    771: 
                    772: sub authform_kerberos{  
                    773:     my %in = (
                    774:               formname => 'document.cu',
                    775:               kerb_def_dom => 'MSU.EDU',
                    776:               @_,
                    777:               );
                    778:     my $result='';
                    779:     $result.=<<"END";
                    780: <input type="radio" name="login" value="krb" 
                    781:        onclick="javascript:changed_radio('krb',$in{'formname'});"
1.57      albertel  782:        onchange="javascript:changed_radio('krb',$in{'formname'});" />
1.32      matthew   783: Kerberos authenticated with domain
                    784: <input type="text" size="10" name="krbarg" value=""
1.57      albertel  785:        onchange="javascript:changed_text('krb',$in{'formname'});" />
1.58      albertel  786: <input type="radio" name="krbver" value="4" checked="on" />Version 4
                    787: <input type="radio" name="krbver" value="5" />Version 5
1.32      matthew   788: END
                    789:     return $result;
                    790: }
                    791: 
                    792: sub authform_internal{  
                    793:     my %args = (
                    794:                 formname => 'document.cu',
                    795:                 kerb_def_dom => 'MSU.EDU',
                    796:                 @_,
                    797:                 );
                    798:     my $result='';
                    799:     $result.=<<"END";
                    800: <input type="radio" name="login" value="int"
                    801:        onchange="javascript:changed_radio('int',$args{'formname'});"
1.57      albertel  802:        onclick="javascript:changed_radio('int',$args{'formname'});" />
1.32      matthew   803: Internally authenticated (with initial password 
                    804: <input type="text" size="10" name="intarg" value=""
1.57      albertel  805:        onchange="javascript:changed_text('int',$args{'formname'});" />
1.32      matthew   806: END
                    807:     return $result;
                    808: }
                    809: 
                    810: sub authform_local{  
                    811:     my %in = (
                    812:               formname => 'document.cu',
                    813:               kerb_def_dom => 'MSU.EDU',
                    814:               @_,
                    815:               );
                    816:     my $result='';
                    817:     $result.=<<"END";
                    818: <input type="radio" name="login" value="loc"
                    819:        onchange="javascript:changed_radio('loc',$in{'formname'});"
1.57      albertel  820:        onclick="javascript:changed_radio('loc',$in{'formname'});" />
1.32      matthew   821: Local Authentication with argument
                    822: <input type="text" size="10" name="locarg" value=""
1.57      albertel  823:        onchange="javascript:changed_text('loc',$in{'formname'});" />
1.32      matthew   824: END
                    825:     return $result;
                    826: }
                    827: 
                    828: sub authform_filesystem{  
                    829:     my %in = (
                    830:               formname => 'document.cu',
                    831:               kerb_def_dom => 'MSU.EDU',
                    832:               @_,
                    833:               );
                    834:     my $result='';
                    835:     $result.=<<"END";
                    836: <input type="radio" name="login" value="fsys" 
                    837:        onchange="javascript:changed_radio('fsys',$in{'formname'});"
1.57      albertel  838:        onclick="javascript:changed_radio('fsys',$in{'formname'});" />
1.32      matthew   839: Filesystem authenticated (with initial password 
                    840: <input type="text" size="10" name="fsysarg" value=""
                    841:        onchange="javascript:changed_text('fsys',$in{'formname'});">
                    842: END
                    843:     return $result;
                    844: }
                    845: 
                    846: ###############################################################
                    847: ##   End Authentication changing form generation functions   ##
                    848: ###############################################################
                    849: 
1.46      matthew   850: ###############################################################
                    851: ##                Thesaurus Functions                        ##
                    852: ###############################################################
1.20      www       853: 
1.46      matthew   854: =pod
1.20      www       855: 
1.46      matthew   856: =item initialize_keywords
                    857: 
                    858: Initializes the package variable %Keywords if it is empty.  Uses the
                    859: package variable $thesaurus_db_file.
                    860: 
                    861: =cut
                    862: 
                    863: ###################################################
                    864: 
                    865: sub initialize_keywords {
                    866:     return 1 if (scalar keys(%Keywords));
                    867:     # If we are here, %Keywords is empty, so fill it up
                    868:     #   Make sure the file we need exists...
                    869:     if (! -e $thesaurus_db_file) {
                    870:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
                    871:                                  " failed because it does not exist");
                    872:         return 0;
                    873:     }
                    874:     #   Set up the hash as a database
                    875:     my %thesaurus_db;
                    876:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel  877:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew   878:         &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
                    879:                                  $thesaurus_db_file);
                    880:         return 0;
                    881:     } 
                    882:     #  Get the average number of appearances of a word.
                    883:     my $avecount = $thesaurus_db{'average.count'};
                    884:     #  Put keywords (those that appear > average) into %Keywords
                    885:     while (my ($word,$data)=each (%thesaurus_db)) {
                    886:         my ($count,undef) = split /:/,$data;
                    887:         $Keywords{$word}++ if ($count > $avecount);
                    888:     }
                    889:     untie %thesaurus_db;
                    890:     # Remove special values from %Keywords.
                    891:     foreach ('total.count','average.count') {
                    892:         delete($Keywords{$_}) if (exists($Keywords{$_}));
                    893:     }
                    894:     return 1;
                    895: }
                    896: 
                    897: ###################################################
                    898: 
                    899: =pod
                    900: 
                    901: =item keyword($word)
                    902: 
                    903: Returns true if $word is a keyword.  A keyword is a word that appears more 
                    904: than the average number of times in the thesaurus database.  Calls 
                    905: &initialize_keywords
                    906: 
                    907: =cut
                    908: 
                    909: ###################################################
1.20      www       910: 
                    911: sub keyword {
1.46      matthew   912:     return if (!&initialize_keywords());
                    913:     my $word=lc(shift());
                    914:     $word=~s/\W//g;
                    915:     return exists($Keywords{$word});
1.20      www       916: }
1.46      matthew   917: 
                    918: ###############################################################
                    919: 
                    920: =pod 
1.20      www       921: 
1.46      matthew   922: =item get_related_words
                    923: 
                    924: Look up a word in the thesaurus.  Takes a scalar arguement and returns
                    925: an array of words.  If the keyword is not in the thesaurus, an empty array
                    926: will be returned.  The order of the words returned is determined by the
                    927: database which holds them.
                    928: 
                    929: Uses global $thesaurus_db_file.
                    930: 
                    931: =cut
                    932: 
                    933: ###############################################################
                    934: sub get_related_words {
                    935:     my $keyword = shift;
                    936:     my %thesaurus_db;
                    937:     if (! -e $thesaurus_db_file) {
                    938:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
                    939:                                  "failed because the file does not exist");
                    940:         return ();
                    941:     }
                    942:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel  943:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew   944:         return ();
                    945:     } 
                    946:     my @Words=();
                    947:     if (exists($thesaurus_db{$keyword})) {
                    948:         $_ = $thesaurus_db{$keyword};
                    949:         (undef,@Words) = split/:/;  # The first element is the number of times
                    950:                                     # the word appears.  We do not need it now.
                    951:         for (my $i=0;$i<=$#Words;$i++) {
                    952:             ($Words[$i],undef)= split/\,/,$Words[$i];
1.20      www       953:         }
                    954:     }
1.46      matthew   955:     untie %thesaurus_db;
                    956:     return @Words;
1.14      harris41  957: }
1.46      matthew   958: 
                    959: ###############################################################
                    960: ##              End Thesaurus Functions                      ##
                    961: ###############################################################
1.61      www       962: 
                    963: # -------------------------------------------------------------- Plaintext name
                    964: 
                    965: sub plainname {
                    966:     my ($uname,$udom)=@_;
                    967:     my %names=&Apache::lonnet::get('environment',
                    968:                     ['firstname','middlename','lastname','generation'],
                    969: 					 $udom,$uname);
1.62      www       970:     my $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
1.61      www       971: 	$names{'lastname'}.' '.$names{'generation'};
1.62      www       972:     $name=~s/\s+$//;
                    973:     $name=~s/\s+/ /g;
                    974:     return $name;
1.61      www       975: }
1.66    ! www       976: 
        !           977: # -------------------------------------------------------------------- Nickname
        !           978: 
        !           979: 
        !           980: sub nickname {
        !           981:     my ($uname,$udom)=@_;
        !           982:     my %names=&Apache::lonnet::get('environment',
        !           983:   ['nickname','firstname','middlename','lastname','generation'],$udom,$uname);
        !           984:     my $name=$names{'nickname'};
        !           985:     if ($name) {
        !           986:        $name='&quot;'.$name.'&quot;'; 
        !           987:     } else {
        !           988:        $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
        !           989: 	     $names{'lastname'}.' '.$names{'generation'};
        !           990:        $name=~s/\s+$//;
        !           991:        $name=~s/\s+/ /g;
        !           992:     }
        !           993:     return $name;
        !           994: }
        !           995: 
1.61      www       996: 
                    997: # ------------------------------------------------------------------ Screenname
                    998: 
                    999: sub screenname {
                   1000:     my ($uname,$udom)=@_;
                   1001:     my %names=
                   1002:  &Apache::lonnet::get('environment',['screenname'],$udom,$uname);
                   1003:     return $names{'screenname'};
1.62      www      1004: }
                   1005: 
                   1006: # ------------------------------------------------------------- Message Wrapper
                   1007: 
                   1008: sub messagewrapper {
                   1009:     my ($link,$un,$do)=@_;
                   1010:     return 
                   1011: "<a href='/adm/email?compose=individual&recname=$un&recdom=$do'>$link</a>";
                   1012: }
                   1013: # ------------------------------------------------------------- Aboutme Wrapper
                   1014: 
                   1015: sub aboutmewrapper {
                   1016:     my ($link,$un,$do)=@_;
                   1017:     return "<a href='/adm/$do/$un/aboutme'>$link</a>";
                   1018: }
                   1019: 
                   1020: # ------------------------------------------------------------ Syllabus Wrapper
                   1021: 
                   1022: 
                   1023: sub syllabuswrapper {
                   1024:     my ($link,$un,$do)=@_;
                   1025:     return "<a href='/public/$do/$un/syllabus'>$link</a>";
1.61      www      1026: }
1.14      harris41 1027: 
                   1028: # ---------------------------------------------------------------- Language IDs
                   1029: sub languageids {
1.16      harris41 1030:     return sort(keys(%language));
1.14      harris41 1031: }
                   1032: 
                   1033: # -------------------------------------------------------- Language Description
                   1034: sub languagedescription {
1.16      harris41 1035:     return $language{shift(@_)};
1.14      harris41 1036: }
                   1037: 
                   1038: # --------------------------------------------------------------- Copyright IDs
                   1039: sub copyrightids {
1.16      harris41 1040:     return sort(keys(%cprtag));
1.14      harris41 1041: }
                   1042: 
                   1043: # ------------------------------------------------------- Copyright Description
                   1044: sub copyrightdescription {
1.16      harris41 1045:     return $cprtag{shift(@_)};
1.14      harris41 1046: }
                   1047: 
                   1048: # ------------------------------------------------------------- File Categories
                   1049: sub filecategories {
1.41      ng       1050:     return sort(keys(%category_extensions));
1.15      harris41 1051: }
1.14      harris41 1052: 
1.17      harris41 1053: # -------------------------------------- File Types within a specified category
1.15      harris41 1054: sub filecategorytypes {
1.41      ng       1055:     return @{$category_extensions{lc($_[0])}};
1.14      harris41 1056: }
                   1057: 
                   1058: # ------------------------------------------------------------------ File Types
                   1059: sub fileextensions {
1.16      harris41 1060:     return sort(keys(%fe));
1.14      harris41 1061: }
                   1062: 
                   1063: # ------------------------------------------------------------- Embedding Style
                   1064: sub fileembstyle {
1.16      harris41 1065:     return $fe{lc(shift(@_))};
1.14      harris41 1066: }
                   1067: 
                   1068: # ------------------------------------------------------------ Description Text
                   1069: sub filedescription {
1.16      harris41 1070:     return $fd{lc(shift(@_))};
                   1071: }
                   1072: 
                   1073: # ------------------------------------------------------------ Description Text
                   1074: sub filedescriptionex {
                   1075:     my $ex=shift;
                   1076:     return '.'.$ex.' '.$fd{lc($ex)};
1.12      harris41 1077: }
1.1       albertel 1078: 
1.40      ng       1079: # ---- Retrieve attempts by students
                   1080: # input
                   1081: # $symb             - problem including path
                   1082: # $username,$domain - that of the student
                   1083: # $course           - course name
                   1084: # $getattempt       - leave blank if want all attempts, else put something.
1.43      ng       1085: # $regexp           - regular expression. If string matches regexp send to
                   1086: # $gradesub         - routine that process the string if it matches regexp
1.40      ng       1087: # 
                   1088: # output
                   1089: # formatted as a table all the attempts, if any.
                   1090: #
1.1       albertel 1091: sub get_previous_attempt {
1.43      ng       1092:   my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1       albertel 1093:   my $prevattempts='';
1.43      ng       1094:   no strict 'refs';
1.1       albertel 1095:   if ($symb) {
1.3       albertel 1096:     my (%returnhash)=
                   1097:       &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1       albertel 1098:     if ($returnhash{'version'}) {
                   1099:       my %lasthash=();
                   1100:       my $version;
                   1101:       for ($version=1;$version<=$returnhash{'version'};$version++) {
1.19      harris41 1102:         foreach (sort(split(/\:/,$returnhash{$version.':keys'}))) {
1.1       albertel 1103: 	  $lasthash{$_}=$returnhash{$version.':'.$_};
1.19      harris41 1104:         }
1.1       albertel 1105:       }
1.43      ng       1106:       $prevattempts='<table border="0" width="100%"><tr><td bgcolor="#777777">';
1.40      ng       1107:       $prevattempts.='<table border="0" width="100%"><tr bgcolor="#e6ffff"><td>History</td>';
1.16      harris41 1108:       foreach (sort(keys %lasthash)) {
1.31      albertel 1109: 	my ($ign,@parts) = split(/\./,$_);
1.41      ng       1110: 	if ($#parts > 0) {
1.31      albertel 1111: 	  my $data=$parts[-1];
                   1112: 	  pop(@parts);
1.40      ng       1113: 	  $prevattempts.='<td>Part '.join('.',@parts).'<br />'.$data.'&nbsp;</td>';
1.31      albertel 1114: 	} else {
1.41      ng       1115: 	  if ($#parts == 0) {
                   1116: 	    $prevattempts.='<th>'.$parts[0].'</th>';
                   1117: 	  } else {
                   1118: 	    $prevattempts.='<th>'.$ign.'</th>';
                   1119: 	  }
1.31      albertel 1120: 	}
1.16      harris41 1121:       }
1.40      ng       1122:       if ($getattempt eq '') {
                   1123: 	for ($version=1;$version<=$returnhash{'version'};$version++) {
                   1124: 	  $prevattempts.='</tr><tr bgcolor="#ffffe6"><td>Transaction '.$version.'</td>';
                   1125: 	    foreach (sort(keys %lasthash)) {
                   1126: 	       my $value;
                   1127: 	       if ($_ =~ /timestamp/) {
                   1128: 		  $value=scalar(localtime($returnhash{$version.':'.$_}));
                   1129: 	       } else {
                   1130: 		  $value=$returnhash{$version.':'.$_};
                   1131: 	       }
                   1132: 	       $prevattempts.='<td>'.$value.'&nbsp;</td>';   
                   1133: 	    }
                   1134: 	 }
1.1       albertel 1135:       }
1.40      ng       1136:       $prevattempts.='</tr><tr bgcolor="#ffffe6"><td>Current</td>';
1.16      harris41 1137:       foreach (sort(keys %lasthash)) {
1.5       albertel 1138: 	my $value;
                   1139: 	if ($_ =~ /timestamp/) {
                   1140: 	  $value=scalar(localtime($lasthash{$_}));
                   1141: 	} else {
                   1142: 	  $value=$lasthash{$_};
                   1143: 	}
1.49      ng       1144: 	if ($_ =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
1.40      ng       1145: 	$prevattempts.='<td>'.$value.'&nbsp;</td>';
1.16      harris41 1146:       }
1.40      ng       1147:       $prevattempts.='</tr></table></td></tr></table>';
1.1       albertel 1148:     } else {
                   1149:       $prevattempts='Nothing submitted - no attempts.';
                   1150:     }
                   1151:   } else {
                   1152:     $prevattempts='No data.';
                   1153:   }
1.10      albertel 1154: }
                   1155: 
                   1156: sub get_student_view {
1.64      sakharuk 1157:   my ($symb,$username,$domain,$courseid,$target) = @_;
1.10      albertel 1158:   my ($map,$id,$feedurl) = split(/___/,$symb);
                   1159:   my (%old,%moreenv);
                   1160:   my @elements=('symb','courseid','domain','username');
                   1161:   foreach my $element (@elements) {
                   1162:     $old{$element}=$ENV{'form.grade_'.$element};
                   1163:     $moreenv{'form.grade_'.$element}=eval '$'.$element #'
                   1164:   }
1.64      sakharuk 1165:   if ($target eq 'tex') {$moreenv{'form.grade_target'} = 'tex';}
1.11      albertel 1166:   &Apache::lonnet::appenv(%moreenv);
                   1167:   my $userview=&Apache::lonnet::ssi('/res/'.$feedurl);
                   1168:   &Apache::lonnet::delenv('form.grade_');
                   1169:   foreach my $element (@elements) {
                   1170:     $ENV{'form.grade_'.$element}=$old{$element};
                   1171:   }
                   1172:   $userview=~s/\<body[^\>]*\>//gi;
                   1173:   $userview=~s/\<\/body\>//gi;
                   1174:   $userview=~s/\<html\>//gi;
                   1175:   $userview=~s/\<\/html\>//gi;
                   1176:   $userview=~s/\<head\>//gi;
                   1177:   $userview=~s/\<\/head\>//gi;
                   1178:   $userview=~s/action\s*\=/would_be_action\=/gi;
                   1179:   return $userview;
                   1180: }
                   1181: 
                   1182: sub get_student_answers {
                   1183:   my ($symb,$username,$domain,$courseid) = @_;
                   1184:   my ($map,$id,$feedurl) = split(/___/,$symb);
                   1185:   my (%old,%moreenv);
                   1186:   my @elements=('symb','courseid','domain','username');
                   1187:   foreach my $element (@elements) {
                   1188:     $old{$element}=$ENV{'form.grade_'.$element};
                   1189:     $moreenv{'form.grade_'.$element}=eval '$'.$element #'
                   1190:   }
                   1191:   $moreenv{'form.grade_target'}='answer';
1.10      albertel 1192:   &Apache::lonnet::appenv(%moreenv);
                   1193:   my $userview=&Apache::lonnet::ssi('/res/'.$feedurl);
                   1194:   &Apache::lonnet::delenv('form.grade_');
                   1195:   foreach my $element (@elements) {
                   1196:     $ENV{'form.grade_'.$element}=$old{$element};
                   1197:   }
                   1198:   return $userview;
1.1       albertel 1199: }
1.37      matthew  1200: 
                   1201: ###############################################
1.51      www      1202: 
                   1203: 
                   1204: sub timehash {
                   1205:     my @ltime=localtime(shift);
                   1206:     return ( 'seconds' => $ltime[0],
                   1207:              'minutes' => $ltime[1],
                   1208:              'hours'   => $ltime[2],
                   1209:              'day'     => $ltime[3],
                   1210:              'month'   => $ltime[4]+1,
                   1211:              'year'    => $ltime[5]+1900,
                   1212:              'weekday' => $ltime[6],
                   1213:              'dayyear' => $ltime[7]+1,
                   1214:              'dlsav'   => $ltime[8] );
                   1215: }
                   1216: 
                   1217: sub maketime {
                   1218:     my %th=@_;
                   1219:     return POSIX::mktime(
                   1220:         ($th{'seconds'},$th{'minutes'},$th{'hours'},
                   1221:          $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,$th{'dlsav'}));
                   1222: }
                   1223: 
                   1224: 
                   1225: sub findallcourses {
                   1226:     my %courses=();
                   1227:     my $now=time;
                   1228:     foreach (keys %ENV) {
                   1229: 	if ($_=~/^user\.role\.\w+\.\/(\w+)\/(\w+)/) {
                   1230: 	    my ($starttime,$endtime)=$ENV{$_};
                   1231:             my $active=1;
                   1232:             if ($starttime) {
                   1233: 		if ($now<$starttime) { $active=0; }
                   1234:             }
                   1235:             if ($endtime) {
                   1236:                 if ($now>$endtime) { $active=0; }
                   1237:             }
                   1238:             if ($active) { $courses{$1.'_'.$2}=1; }
                   1239:         }
                   1240:     }
                   1241:     return keys %courses;
                   1242: }
1.37      matthew  1243: 
1.54      www      1244: ###############################################
1.60      matthew  1245: ###############################################
                   1246: 
                   1247: =pod
                   1248: 
1.63      www      1249: =item &determinedomain()
1.60      matthew  1250: 
                   1251: Inputs: $domain (usually will be undef)
                   1252: 
1.63      www      1253: Returns: Determines which domain should be used for designs
1.60      matthew  1254: 
                   1255: =cut
1.54      www      1256: 
1.60      matthew  1257: ###############################################
1.63      www      1258: sub determinedomain {
                   1259:     my $domain=shift;
                   1260:    if (! $domain) {
1.60      matthew  1261:         # Determine domain if we have not been given one
                   1262:         $domain = $Apache::lonnet::perlvar{'lonDefDomain'};
                   1263:         if ($ENV{'user.domain'}) { $domain=$ENV{'user.domain'}; }
                   1264:         if ($ENV{'request.role.domain'}) { 
                   1265:             $domain=$ENV{'request.role.domain'}; 
                   1266:         }
                   1267:     }
1.63      www      1268:     return $domain;
                   1269: }
                   1270: ###############################################
                   1271: =pod
                   1272: 
                   1273: =item &domainlogo()
                   1274: 
                   1275: Inputs: $domain (usually will be undef)
                   1276: 
                   1277: Returns: A link to a domain logo, if the domain logo exists.
                   1278: If the domain logo does not exist, a description of the domain.
                   1279: 
                   1280: =cut
                   1281: ###############################################
                   1282: sub domainlogo {
                   1283:     my $domain = &determinedomain(shift);    
                   1284:      # See if there is a logo
1.59      www      1285:     if (-e '/home/httpd/html/adm/lonDomLogos/'.$domain.'.gif') {
1.60      matthew  1286:         return '<img src="/adm/lonDomLogos/'.$domain.'.gif" />';
                   1287:     } elsif(exists($Apache::lonnet::domaindescription{$domain})) {
                   1288:         return $Apache::lonnet::domaindescription{$domain};
1.59      www      1289:     } else {
1.60      matthew  1290:         return '';
1.59      www      1291:     }
                   1292: }
1.63      www      1293: ##############################################
                   1294: 
                   1295: =pod
                   1296: 
                   1297: =item &designparm()
                   1298: 
                   1299: Inputs: $which parameter; $domain (usually will be undef)
                   1300: 
                   1301: Returns: value of designparamter $which
                   1302: 
                   1303: =cut
                   1304: ##############################################
                   1305: sub designparm {
                   1306:     my ($which,$domain)=@_;
                   1307:     $domain=&determinedomain($domain);
                   1308:     if ($designhash{$domain.'.'.$which}) {
                   1309: 	return $designhash{$domain.'.'.$which};
                   1310:     } else {
                   1311:         return $designhash{'default.'.$which};
                   1312:     }
                   1313: }
1.59      www      1314: 
1.60      matthew  1315: ###############################################
                   1316: ###############################################
                   1317: 
                   1318: =pod
                   1319: 
                   1320: =item &bodytag()
                   1321: 
                   1322: Returns a uniform header for LON-CAPA web pages.
                   1323: 
                   1324: Inputs: 
                   1325: 
                   1326:  $title, A title to be displayed on the page.
                   1327:  $function, the current role (can be undef).
                   1328:  $addentries, extra parameters for the <body> tag.
                   1329:  $bodyonly, if defined, only return the <body> tag.
                   1330:  $domain, if defined, force a given domain.
                   1331: 
                   1332: Returns: A uniform header for LON-CAPA web pages.  
                   1333: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
                   1334: If $bodyonly is undef or zero, an html string containing a <body> tag and 
                   1335: other decorations will be returned.
                   1336: 
                   1337: =cut
                   1338: 
                   1339: ###############################################
1.63      www      1340: 
                   1341: 
1.60      matthew  1342: ###############################################
1.54      www      1343: sub bodytag {
1.60      matthew  1344:     my ($title,$function,$addentries,$bodyonly,$domain)=@_;
1.55      www      1345:     unless ($function) {
                   1346: 	$function='student';
                   1347:         if ($ENV{'request.role'}=~/^(cc|in|ta|ep)/) {
                   1348: 	    $function='coordinator';
                   1349:         }
                   1350: 	if ($ENV{'request.role'}=~/^(su|dc|ad|li)/) {
                   1351:             $function='admin';
                   1352:         }
                   1353:         if (($ENV{'request.role'}=~/^(au|ca)/) ||
                   1354:             ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
                   1355:             $function='author';
                   1356:         }
                   1357:     }
1.63      www      1358:     my $img=&designparm($function.'.img',$domain);
                   1359:     my $pgbg=&designparm($function.'.pgbg',$domain);
                   1360:     my $tabbg=&designparm($function.'.tabbg',$domain);
                   1361:     my $font=&designparm($function.'.font',$domain);
                   1362:     my $link=&designparm($function.'.link',$domain);
                   1363:     my $alink=&designparm($function.'.alink',$domain);
                   1364:     my $vlink=&designparm($function.'.vlink',$domain);
                   1365:     my $sidebg=&designparm($function.'.sidebg',$domain);
                   1366: 
                   1367:  # role and realm
1.55      www      1368:     my ($role,$realm)
                   1369:        =&Apache::lonnet::plaintext((split(/\./,$ENV{'request.role'}))[0]);
                   1370: # realm
1.54      www      1371:     if ($ENV{'request.course.id'}) {
1.55      www      1372: 	$realm=
                   1373:          $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
1.54      www      1374:     }
1.55      www      1375:     unless ($realm) { $realm='&nbsp;'; }
                   1376: # Set messages
1.60      matthew  1377:     my $messages=&domainlogo($domain);
1.55      www      1378: # Output
1.60      matthew  1379:     my $bodytag = <<END;
1.54      www      1380: <body bgcolor="$pgbg" text="$font" alink="$alink" vlink="$vlink" link="$link"
                   1381: $addentries>
1.60      matthew  1382: END
                   1383:     if ($bodyonly) {
                   1384:         return $bodytag;
                   1385:     } else {
                   1386:         return(<<ENDBODY);
                   1387: $bodytag
1.55      www      1388: <table width="100%" cellspacing="0" border="0" cellpadding="0">
                   1389: <tr><td bgcolor="$font">
1.63      www      1390: <img src="$img" /></td>
                   1391: <td bgcolor="$font"><font color='$sidebg'>$messages</font></td>
1.55      www      1392: </tr>
1.54      www      1393: <tr>
1.55      www      1394: <td rowspan="3" bgcolor="$tabbg">
                   1395: &nbsp;<font size="5"><b>$title</b></font>
1.54      www      1396: <td bgcolor="$tabbg"  align="right">
                   1397: <font size="2">
                   1398:     $ENV{'environment.firstname'}
                   1399:     $ENV{'environment.middlename'}
                   1400:     $ENV{'environment.lastname'}
                   1401:     $ENV{'environment.generation'}
1.55      www      1402:     </font>&nbsp;
1.54      www      1403: </td>
                   1404: </tr>
                   1405: <tr><td bgcolor="$tabbg" align="right">
1.55      www      1406: <font size="2">$role</font>&nbsp;
1.54      www      1407: </td></tr>
1.55      www      1408: <tr>
                   1409: <td bgcolor="$tabbg" align="right"><font size="2">$realm</font>&nbsp;</td></tr>
1.54      www      1410: </table><br>
                   1411: ENDBODY
1.60      matthew  1412:     }
1.54      www      1413: }
1.37      matthew  1414: ###############################################
1.1       albertel 1415: 
1.6       albertel 1416: sub get_unprocessed_cgi {
1.25      albertel 1417:   my ($query,$possible_names)= @_;
1.26      matthew  1418:   # $Apache::lonxml::debug=1;
1.16      harris41 1419:   foreach (split(/&/,$query)) {
1.6       albertel 1420:     my ($name, $value) = split(/=/,$_);
1.25      albertel 1421:     $name = &Apache::lonnet::unescape($name);
                   1422:     if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
                   1423:       $value =~ tr/+/ /;
                   1424:       $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
                   1425:       &Apache::lonxml::debug("Seting :$name: to :$value:");
1.30      albertel 1426:       unless (defined($ENV{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25      albertel 1427:     }
1.16      harris41 1428:   }
1.6       albertel 1429: }
                   1430: 
1.7       albertel 1431: sub cacheheader {
1.23      www      1432:   unless ($ENV{'request.method'} eq 'GET') { return ''; }
1.8       albertel 1433:   my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
1.7       albertel 1434:   my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
                   1435:                 <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
                   1436:                 <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
                   1437:   return $output;
                   1438: }
                   1439: 
1.9       albertel 1440: sub no_cache {
                   1441:   my ($r) = @_;
1.23      www      1442:   unless ($ENV{'request.method'} eq 'GET') { return ''; }
1.24      albertel 1443:   #my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
1.9       albertel 1444:   $r->no_cache(1);
                   1445:   $r->header_out("Pragma" => "no-cache");
1.24      albertel 1446:   #$r->header_out("Expires" => $date);
1.9       albertel 1447: }
1.25      albertel 1448: 
                   1449: sub add_to_env {
                   1450:   my ($name,$value)=@_;
1.28      albertel 1451:   if (defined($ENV{$name})) {
1.27      albertel 1452:     if (ref($ENV{$name})) {
1.25      albertel 1453:       #already have multiple values
                   1454:       push(@{ $ENV{$name} },$value);
                   1455:     } else {
                   1456:       #first time seeing multiple values, convert hash entry to an arrayref
                   1457:       my $first=$ENV{$name};
                   1458:       undef($ENV{$name});
                   1459:       push(@{ $ENV{$name} },$first,$value);
                   1460:     }
                   1461:   } else {
                   1462:     $ENV{$name}=$value;
                   1463:   }
1.31      albertel 1464: }
                   1465: 
1.41      ng       1466: =pod
1.45      matthew  1467: 
                   1468: =back 
1.41      ng       1469: 
                   1470: =head2 CSV Upload/Handling functions
1.38      albertel 1471: 
1.41      ng       1472: =over 4
                   1473: 
                   1474: =item  upfile_store($r)
                   1475: 
                   1476: Store uploaded file, $r should be the HTTP Request object,
                   1477: needs $ENV{'form.upfile'}
                   1478: returns $datatoken to be put into hidden field
                   1479: 
                   1480: =cut
1.31      albertel 1481: 
                   1482: sub upfile_store {
                   1483:     my $r=shift;
                   1484:     $ENV{'form.upfile'}=~s/\r/\n/gs;
                   1485:     $ENV{'form.upfile'}=~s/\f/\n/gs;
                   1486:     $ENV{'form.upfile'}=~s/\n+/\n/gs;
                   1487:     $ENV{'form.upfile'}=~s/\n+$//gs;
                   1488: 
                   1489:     my $datatoken=$ENV{'user.name'}.'_'.$ENV{'user.domain'}.
                   1490: 	'_enroll_'.$ENV{'request.course.id'}.'_'.time.'_'.$$;
                   1491:     {
                   1492: 	my $fh=Apache::File->new('>'.$r->dir_config('lonDaemons').
                   1493: 				 '/tmp/'.$datatoken.'.tmp');
                   1494: 	print $fh $ENV{'form.upfile'};
                   1495:     }
                   1496:     return $datatoken;
                   1497: }
                   1498: 
1.56      matthew  1499: =pod
                   1500: 
1.41      ng       1501: =item load_tmp_file($r)
                   1502: 
                   1503: Load uploaded file from tmp, $r should be the HTTP Request object,
                   1504: needs $ENV{'form.datatoken'},
                   1505: sets $ENV{'form.upfile'} to the contents of the file
                   1506: 
                   1507: =cut
1.31      albertel 1508: 
                   1509: sub load_tmp_file {
                   1510:     my $r=shift;
                   1511:     my @studentdata=();
                   1512:     {
                   1513: 	my $fh;
                   1514: 	if ($fh=Apache::File->new($r->dir_config('lonDaemons').
                   1515: 				  '/tmp/'.$ENV{'form.datatoken'}.'.tmp')) {
                   1516: 	    @studentdata=<$fh>;
                   1517: 	}
                   1518:     }
                   1519:     $ENV{'form.upfile'}=join('',@studentdata);
                   1520: }
                   1521: 
1.56      matthew  1522: =pod
                   1523: 
1.41      ng       1524: =item upfile_record_sep()
                   1525: 
                   1526: Separate uploaded file into records
                   1527: returns array of records,
                   1528: needs $ENV{'form.upfile'} and $ENV{'form.upfiletype'}
                   1529: 
                   1530: =cut
1.31      albertel 1531: 
                   1532: sub upfile_record_sep {
                   1533:     if ($ENV{'form.upfiletype'} eq 'xml') {
                   1534:     } else {
                   1535: 	return split(/\n/,$ENV{'form.upfile'});
                   1536:     }
                   1537: }
                   1538: 
1.56      matthew  1539: =pod
                   1540: 
1.41      ng       1541: =item record_sep($record)
                   1542: 
                   1543: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $ENV{'form.upfiletype'}
                   1544: 
                   1545: =cut
                   1546: 
1.31      albertel 1547: sub record_sep {
                   1548:     my $record=shift;
                   1549:     my %components=();
                   1550:     if ($ENV{'form.upfiletype'} eq 'xml') {
                   1551:     } elsif ($ENV{'form.upfiletype'} eq 'space') {
                   1552:         my $i=0;
                   1553:         foreach (split(/\s+/,$record)) {
                   1554:             my $field=$_;
                   1555:             $field=~s/^(\"|\')//;
                   1556:             $field=~s/(\"|\')$//;
                   1557:             $components{$i}=$field;
                   1558:             $i++;
                   1559:         }
                   1560:     } elsif ($ENV{'form.upfiletype'} eq 'tab') {
                   1561:         my $i=0;
                   1562:         foreach (split(/\t+/,$record)) {
                   1563:             my $field=$_;
                   1564:             $field=~s/^(\"|\')//;
                   1565:             $field=~s/(\"|\')$//;
                   1566:             $components{$i}=$field;
                   1567:             $i++;
                   1568:         }
                   1569:     } else {
                   1570:         my @allfields=split(/\,/,$record);
                   1571:         my $i=0;
                   1572:         my $j;
                   1573:         for ($j=0;$j<=$#allfields;$j++) {
                   1574:             my $field=$allfields[$j];
                   1575:             if ($field=~/^\s*(\"|\')/) {
                   1576: 		my $delimiter=$1;
                   1577:                 while (($field!~/$delimiter$/) && ($j<$#allfields)) {
                   1578: 		    $j++;
                   1579: 		    $field.=','.$allfields[$j];
                   1580: 		}
                   1581:                 $field=~s/^\s*$delimiter//;
                   1582:                 $field=~s/$delimiter\s*$//;
                   1583:             }
                   1584:             $components{$i}=$field;
                   1585: 	    $i++;
                   1586:         }
                   1587:     }
                   1588:     return %components;
                   1589: }
                   1590: 
1.56      matthew  1591: =pod
                   1592: 
1.41      ng       1593: =item upfile_select_html()
                   1594: 
                   1595: return HTML code to select file and specify its type
                   1596: 
                   1597: =cut
                   1598: 
1.31      albertel 1599: sub upfile_select_html {
                   1600:     return (<<'ENDUPFORM');
1.57      albertel 1601: <input type="file" name="upfile" size="50" />
1.31      albertel 1602: <br />Type: <select name="upfiletype">
                   1603: <option value="csv">CSV (comma separated values, spreadsheet)</option>
                   1604: <option value="space">Space separated</option>
                   1605: <option value="tab">Tabulator separated</option>
                   1606: <option value="xml">HTML/XML</option>
                   1607: </select>
                   1608: ENDUPFORM
                   1609: }
                   1610: 
1.56      matthew  1611: =pod
                   1612: 
1.41      ng       1613: =item csv_print_samples($r,$records)
                   1614: 
                   1615: Prints a table of sample values from each column uploaded $r is an
                   1616: Apache Request ref, $records is an arrayref from
                   1617: &Apache::loncommon::upfile_record_sep
                   1618: 
                   1619: =cut
                   1620: 
1.31      albertel 1621: sub csv_print_samples {
                   1622:     my ($r,$records) = @_;
                   1623:     my (%sone,%stwo,%sthree);
                   1624:     %sone=&record_sep($$records[0]);
                   1625:     if (defined($$records[1])) {%stwo=&record_sep($$records[1]);}
                   1626:     if (defined($$records[2])) {%sthree=&record_sep($$records[2]);}
                   1627: 
                   1628:     $r->print('Samples<br /><table border="2"><tr>');
                   1629:     foreach (sort({$a <=> $b} keys(%sone))) { $r->print('<th>Column&nbsp;'.($_+1).'</th>'); }
                   1630:     $r->print('</tr>');
                   1631:     foreach my $hash (\%sone,\%stwo,\%sthree) {
                   1632: 	$r->print('<tr>');
                   1633: 	foreach (sort({$a <=> $b} keys(%sone))) {
                   1634: 	    $r->print('<td>');
                   1635: 	    if (defined($$hash{$_})) { $r->print($$hash{$_}); }
                   1636: 	    $r->print('</td>');
                   1637: 	}
                   1638: 	$r->print('</tr>');
                   1639:     }
                   1640:     $r->print('</tr></table><br />'."\n");
                   1641: }
                   1642: 
1.56      matthew  1643: =pod
                   1644: 
1.41      ng       1645: =item csv_print_select_table($r,$records,$d)
                   1646: 
                   1647: Prints a table to create associations between values and table columns.
                   1648: $r is an Apache Request ref,
                   1649: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
                   1650: $d is an array of 2 element arrays (internal name, displayed name)
                   1651: 
                   1652: =cut
                   1653: 
1.31      albertel 1654: sub csv_print_select_table {
                   1655:     my ($r,$records,$d) = @_;
                   1656:     my $i=0;my %sone;
                   1657:     %sone=&record_sep($$records[0]);
                   1658:     $r->print('Associate columns with student attributes.'."\n".
                   1659: 	     '<table border="2"><tr><th>Attribute</th><th>Column</th></tr>'."\n");
                   1660:     foreach (@$d) {
                   1661: 	my ($value,$display)=@{ $_ };
                   1662: 	$r->print('<tr><td>'.$display.'</td>');
                   1663: 
                   1664: 	$r->print('<td><select name=f'.$i.
1.32      matthew  1665: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.31      albertel 1666: 	$r->print('<option value="none"></option>');
                   1667: 	foreach (sort({$a <=> $b} keys(%sone))) {
                   1668: 	    $r->print('<option value="'.$_.'">Column '.($_+1).'</option>');
                   1669: 	}
                   1670: 	$r->print('</select></td></tr>'."\n");
                   1671: 	$i++;
                   1672:     }
                   1673:     $i--;
                   1674:     return $i;
                   1675: }
1.56      matthew  1676: 
                   1677: =pod
1.31      albertel 1678: 
1.41      ng       1679: =item csv_samples_select_table($r,$records,$d)
                   1680: 
                   1681: Prints a table of sample values from the upload and can make associate samples to internal names.
                   1682: 
                   1683: $r is an Apache Request ref,
                   1684: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
                   1685: $d is an array of 2 element arrays (internal name, displayed name)
                   1686: 
                   1687: =cut
                   1688: 
1.31      albertel 1689: sub csv_samples_select_table {
                   1690:     my ($r,$records,$d) = @_;
                   1691:     my %sone; my %stwo; my %sthree;
                   1692:     my $i=0;
                   1693: 
                   1694:     $r->print('<table border=2><tr><th>Field</th><th>Samples</th></tr>');
                   1695:     %sone=&record_sep($$records[0]);
                   1696:     if (defined($$records[1])) {%stwo=&record_sep($$records[1]);}
                   1697:     if (defined($$records[2])) {%sthree=&record_sep($$records[2]);}
                   1698: 
                   1699:     foreach (sort keys %sone) {
                   1700: 	$r->print('<tr><td><select name=f'.$i.
1.32      matthew  1701: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.31      albertel 1702: 	foreach (@$d) {
                   1703: 	    my ($value,$display)=@{ $_ };
                   1704: 	    $r->print('<option value='.$value.'>'.$display.'</option>');
                   1705: 	}
                   1706: 	$r->print('</select></td><td>');
                   1707: 	if (defined($sone{$_})) { $r->print($sone{$_}."</br>\n"); }
                   1708: 	if (defined($stwo{$_})) { $r->print($stwo{$_}."</br>\n"); }
                   1709: 	if (defined($sthree{$_})) { $r->print($sthree{$_}."</br>\n"); }
                   1710: 	$r->print('</td></tr>');
                   1711: 	$i++;
                   1712:     }
                   1713:     $i--;
                   1714:     return($i);
1.25      albertel 1715: }
1.1       albertel 1716: 1;
                   1717: __END__;
1.17      harris41 1718: 
1.41      ng       1719: =pod
                   1720: 
                   1721: =back
                   1722: 
                   1723: =head2 Access .tab File Data
                   1724: 
                   1725: =over 4
                   1726: 
1.35      matthew  1727: =item languageids() 
1.17      harris41 1728: 
1.35      matthew  1729: returns list of all language ids
1.17      harris41 1730: 
1.35      matthew  1731: =item languagedescription() 
1.17      harris41 1732: 
1.35      matthew  1733: returns description of a specified language id
1.17      harris41 1734: 
1.35      matthew  1735: =item copyrightids() 
1.17      harris41 1736: 
1.35      matthew  1737: returns list of all copyrights
1.17      harris41 1738: 
1.35      matthew  1739: =item copyrightdescription() 
1.17      harris41 1740: 
1.35      matthew  1741: returns description of a specified copyright id
1.17      harris41 1742: 
1.35      matthew  1743: =item filecategories() 
1.17      harris41 1744: 
1.35      matthew  1745: returns list of all file categories
1.17      harris41 1746: 
1.35      matthew  1747: =item filecategorytypes() 
1.17      harris41 1748: 
1.35      matthew  1749: returns list of file types belonging to a given file
1.17      harris41 1750: category
                   1751: 
1.35      matthew  1752: =item fileembstyle() 
1.17      harris41 1753: 
1.35      matthew  1754: returns embedding style for a specified file type
1.17      harris41 1755: 
1.35      matthew  1756: =item filedescription() 
1.17      harris41 1757: 
1.35      matthew  1758: returns description for a specified file type
1.17      harris41 1759: 
1.35      matthew  1760: =item filedescriptionex() 
1.17      harris41 1761: 
1.35      matthew  1762: returns description for a specified file type with
1.17      harris41 1763: extra formatting
                   1764: 
1.41      ng       1765: =back
                   1766: 
                   1767: =head2 Alternate Problem Views
                   1768: 
                   1769: =over 4
                   1770: 
1.35      matthew  1771: =item get_previous_attempt() 
1.17      harris41 1772: 
1.35      matthew  1773: return string with previous attempt on problem
1.17      harris41 1774: 
1.35      matthew  1775: =item get_student_view() 
1.17      harris41 1776: 
1.35      matthew  1777: show a snapshot of what student was looking at
1.17      harris41 1778: 
1.35      matthew  1779: =item get_student_answers() 
1.17      harris41 1780: 
1.35      matthew  1781: show a snapshot of how student was answering problem
1.17      harris41 1782: 
1.41      ng       1783: =back
                   1784: 
                   1785: =head2 HTTP Helper
                   1786: 
                   1787: =over 4
                   1788: 
                   1789: =item get_unprocessed_cgi($query,$possible_names)
                   1790: 
                   1791: Modify the %ENV hash to contain unprocessed CGI form parameters held in
                   1792: $query.  The parameters listed in $possible_names (an array reference),
                   1793: will be set in $ENV{'form.name'} if they do not already exist.
1.17      harris41 1794: 
1.41      ng       1795: Typically called with $ENV{'QUERY_STRING'} as the first parameter.  
                   1796: $possible_names is an ref to an array of form element names.  As an example:
                   1797: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
                   1798: will result in $ENV{'form.uname'} and $ENV{'form.udom'} being set.
1.17      harris41 1799: 
1.35      matthew  1800: =item cacheheader() 
1.17      harris41 1801: 
1.35      matthew  1802: returns cache-controlling header code
1.17      harris41 1803: 
1.65      matthew  1804: =item no_cache($r) 
1.17      harris41 1805: 
1.35      matthew  1806: specifies header code to not have cache
1.25      albertel 1807: 
1.35      matthew  1808: =item add_to_env($name,$value) 
1.25      albertel 1809: 
1.35      matthew  1810: adds $name to the %ENV hash with value
1.25      albertel 1811: $value, if $name already exists, the entry is converted to an array
                   1812: reference and $value is added to the array.
1.17      harris41 1813: 
                   1814: =back
                   1815: 
                   1816: =cut

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