Annotation of loncom/interface/loncommon.pm, revision 1.228
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.228 ! matthew 4: # $Id: loncommon.pm,v 1.227 2004/11/08 22:50:37 albertel Exp $
1.10 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
29: # Makes a table out of the previous attempts
1.2 albertel 30: # Inputs result_from_symbread, user, domain, course_id
1.16 harris41 31: # Reads in non-network-related .tab files
1.1 albertel 32:
1.35 matthew 33: # POD header:
34:
1.45 matthew 35: =pod
36:
1.35 matthew 37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
1.112 bowersj2 43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
1.35 matthew 45:
1.112 bowersj2 46: =head1 OVERVIEW
1.35 matthew 47:
1.112 bowersj2 48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
1.35 matthew 50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
1.1 albertel 55: package Apache::loncommon;
56:
57: use strict;
1.22 www 58: use Apache::lonnet();
1.46 matthew 59: use GDBM_File;
1.51 www 60: use POSIX qw(strftime mktime);
1.99 www 61: use Apache::Constants qw(:common :http :methods);
1.82 www 62: use Apache::lonmenu();
1.117 www 63: use Apache::lonlocal;
1.139 matthew 64: use HTML::Entities;
1.117 www 65:
1.22 www 66: my $readit;
67:
1.157 matthew 68: ##
69: ## Global Variables
70: ##
1.46 matthew 71:
1.20 www 72: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 73: my %language;
1.124 www 74: my %supported_language;
1.12 harris41 75: my %cprtag;
1.192 taceyjo1 76: my %scprtag;
1.12 harris41 77: my %fe; my %fd;
1.41 ng 78: my %category_extensions;
1.12 harris41 79:
1.63 www 80: # ---------------------------------------------- Designs
81:
82: my %designhash;
83:
1.46 matthew 84: # ---------------------------------------------- Thesaurus variables
1.144 matthew 85: #
86: # %Keywords:
87: # A hash used by &keyword to determine if a word is considered a keyword.
88: # $thesaurus_db_file
89: # Scalar containing the full path to the thesaurus database.
1.46 matthew 90:
91: my %Keywords;
92: my $thesaurus_db_file;
93:
1.144 matthew 94: #
95: # Initialize values from language.tab, copyright.tab, filetypes.tab,
96: # thesaurus.tab, and filecategories.tab.
97: #
1.18 www 98: BEGIN {
1.46 matthew 99: # Variable initialization
100: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
101: #
1.22 www 102: unless ($readit) {
1.12 harris41 103: # ------------------------------------------------------------------- languages
104: {
1.158 raeburn 105: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
106: '/language.tab';
107: if ( open(my $fh,"<$langtabfile") ) {
108: while (<$fh>) {
109: next if /^\#/;
110: chomp;
111: my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$_));
112: $language{$key}=$val.' - '.$enc;
113: if ($sup) {
114: $supported_language{$key}=$sup;
115: }
116: }
117: close($fh);
118: }
1.12 harris41 119: }
120: # ------------------------------------------------------------------ copyrights
121: {
1.158 raeburn 122: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
123: '/copyright.tab';
124: if ( open (my $fh,"<$copyrightfile") ) {
125: while (<$fh>) {
126: next if /^\#/;
127: chomp;
128: my ($key,$val)=(split(/\s+/,$_,2));
129: $cprtag{$key}=$val;
130: }
131: close($fh);
132: }
1.12 harris41 133: }
1.192 taceyjo1 134: # ------------------------------------------------------------------ source copyrights
135: {
136: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
137: '/source_copyright.tab';
138: if ( open (my $fh,"<$sourcecopyrightfile") ) {
139: while (<$fh>) {
140: next if /^\#/;
141: chomp;
142: my ($key,$val)=(split(/\s+/,$_,2));
143: $scprtag{$key}=$val;
144: }
145: close($fh);
146: }
147: }
1.63 www 148:
149: # -------------------------------------------------------------- domain designs
150:
151: my $filename;
152: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
153: opendir(DIR,$designdir);
154: while ($filename=readdir(DIR)) {
155: my ($domain)=($filename=~/^(\w+)\./);
156: {
1.158 raeburn 157: my $designfile = $designdir.'/'.$filename;
158: if ( open (my $fh,"<$designfile") ) {
159: while (<$fh>) {
160: next if /^\#/;
161: chomp;
162: my ($key,$val)=(split(/\=/,$_));
163: if ($val) { $designhash{$domain.'.'.$key}=$val; }
164: }
165: close($fh);
166: }
1.63 www 167: }
168:
169: }
170: closedir(DIR);
171:
172:
1.15 harris41 173: # ------------------------------------------------------------- file categories
174: {
1.158 raeburn 175: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
176: '/filecategories.tab';
177: if ( open (my $fh,"<$categoryfile") ) {
178: while (<$fh>) {
179: next if /^\#/;
180: chomp;
181: my ($extension,$category)=(split(/\s+/,$_,2));
182: push @{$category_extensions{lc($category)}},$extension;
183: }
184: close($fh);
185: }
186:
1.15 harris41 187: }
1.12 harris41 188: # ------------------------------------------------------------------ file types
189: {
1.158 raeburn 190: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
191: '/filetypes.tab';
192: if ( open (my $fh,"<$typesfile") ) {
1.16 harris41 193: while (<$fh>) {
1.158 raeburn 194: next if (/^\#/);
195: chomp;
196: my ($ending,$emb,$descr)=split(/\s+/,$_,3);
197: if ($descr ne '') {
198: $fe{$ending}=lc($emb);
199: $fd{$ending}=$descr;
200: }
201: }
202: close($fh);
203: }
1.12 harris41 204: }
1.22 www 205: &Apache::lonnet::logthis(
1.46 matthew 206: "<font color=yellow>INFO: Read file types</font>");
1.22 www 207: $readit=1;
1.46 matthew 208: } # end of unless($readit)
1.32 matthew 209:
210: }
1.112 bowersj2 211:
1.42 matthew 212: ###############################################################
213: ## HTML and Javascript Helper Functions ##
214: ###############################################################
215:
216: =pod
217:
1.112 bowersj2 218: =head1 HTML and Javascript Functions
1.42 matthew 219:
1.112 bowersj2 220: =over 4
221:
222: =item * browser_and_searcher_javascript ()
223:
224: X<browsing, javascript>X<searching, javascript>Returns a string
225: containing javascript with two functions, C<openbrowser> and
226: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
227: tags.
1.42 matthew 228:
1.112 bowersj2 229: =item * openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 230:
231: inputs: formname, elementname, only, omit
232:
233: formname and elementname indicate the name of the html form and name of
234: the element that the results of the browsing selection are to be placed in.
235:
236: Specifying 'only' will restrict the browser to displaying only files
1.185 www 237: with the given extension. Can be a comma separated list.
1.42 matthew 238:
239: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 240: with the given extension. Can be a comma separated list.
1.42 matthew 241:
1.112 bowersj2 242: =item * opensearcher(formname, elementname) [javascript]
1.42 matthew 243:
244: Inputs: formname, elementname
245:
246: formname and elementname specify the name of the html form and the name
247: of the element the selection from the search results will be placed in.
248:
249: =cut
250:
251: sub browser_and_searcher_javascript {
1.199 albertel 252: my ($mode)=@_;
253: if (!defined($mode)) { $mode='edit'; }
1.170 www 254: my $resurl=&lastresurl();
1.42 matthew 255: return <<END;
1.219 albertel 256: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 257: var editbrowser = null;
1.135 albertel 258: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 259: var url = '$resurl/?';
1.42 matthew 260: if (editbrowser == null) {
261: url += 'launch=1&';
262: }
263: url += 'catalogmode=interactive&';
1.199 albertel 264: url += 'mode=$mode&';
1.42 matthew 265: url += 'form=' + formname + '&';
266: if (only != null) {
267: url += 'only=' + only + '&';
1.217 albertel 268: } else {
269: url += 'only=&';
270: }
1.42 matthew 271: if (omit != null) {
272: url += 'omit=' + omit + '&';
1.217 albertel 273: } else {
274: url += 'omit=&';
275: }
1.135 albertel 276: if (titleelement != null) {
277: url += 'titleelement=' + titleelement + '&';
1.217 albertel 278: } else {
279: url += 'titleelement=&';
280: }
1.42 matthew 281: url += 'element=' + elementname + '';
282: var title = 'Browser';
1.217 albertel 283: var options = 'scrollbars=1,resizable=1,menubar=1,location=1';
1.42 matthew 284: options += ',width=700,height=600';
285: editbrowser = open(url,title,options,'1');
286: editbrowser.focus();
287: }
288: var editsearcher;
1.135 albertel 289: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 290: var url = '/adm/searchcat?';
291: if (editsearcher == null) {
292: url += 'launch=1&';
293: }
294: url += 'catalogmode=interactive&';
1.199 albertel 295: url += 'mode=$mode&';
1.42 matthew 296: url += 'form=' + formname + '&';
1.135 albertel 297: if (titleelement != null) {
298: url += 'titleelement=' + titleelement + '&';
1.217 albertel 299: } else {
300: url += 'titleelement=&';
301: }
1.42 matthew 302: url += 'element=' + elementname + '';
303: var title = 'Search';
304: var options = 'scrollbars=1,resizable=1,menubar=0';
305: options += ',width=700,height=600';
306: editsearcher = open(url,title,options,'1');
307: editsearcher.focus();
308: }
1.219 albertel 309: // END LON-CAPA Internal -->
1.42 matthew 310: END
1.170 www 311: }
312:
313: sub lastresurl {
314: if ($ENV{'environment.lastresurl'}) {
315: return $ENV{'environment.lastresurl'}
316: } else {
317: return '/res';
318: }
319: }
320:
321: sub storeresurl {
322: my $resurl=&Apache::lonnet::clutter(shift);
323: unless ($resurl=~/^\/res/) { return 0; }
324: $resurl=~s/\/$//;
325: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
326: &Apache::lonnet::appenv('environment.lastresurl' => $resurl);
327: return 1;
1.42 matthew 328: }
329:
1.74 www 330: sub studentbrowser_javascript {
1.111 www 331: unless (
332: (($ENV{'request.course.id'}) &&
333: (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})))
334: || ($ENV{'request.role'}=~/^(au|dc|su)/)
335: ) { return ''; }
1.74 www 336: return (<<'ENDSTDBRW');
337: <script type="text/javascript" language="Javascript" >
338: var stdeditbrowser;
1.111 www 339: function openstdbrowser(formname,uname,udom,roleflag) {
1.74 www 340: var url = '/adm/pickstudent?';
341: var filter;
342: eval('filter=document.'+formname+'.'+uname+'.value;');
343: if (filter != null) {
344: if (filter != '') {
345: url += 'filter='+filter+'&';
346: }
347: }
348: url += 'form=' + formname + '&unameelement='+uname+
349: '&udomelement='+udom;
1.111 www 350: if (roleflag) { url+="&roles=1"; }
1.102 www 351: var title = 'Student_Browser';
1.74 www 352: var options = 'scrollbars=1,resizable=1,menubar=0';
353: options += ',width=700,height=600';
354: stdeditbrowser = open(url,title,options,'1');
355: stdeditbrowser.focus();
356: }
357: </script>
358: ENDSTDBRW
359: }
1.42 matthew 360:
1.74 www 361: sub selectstudent_link {
1.111 www 362: my ($form,$unameele,$udomele)=@_;
363: if ($ENV{'request.course.id'}) {
364: unless (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) {
365: return '';
366: }
367: return "<a href='".'javascript:openstdbrowser("'.$form.'","'.$unameele.
1.119 www 368: '","'.$udomele.'");'."'>".&mt('Select User')."</a>";
1.74 www 369: }
1.111 www 370: if ($ENV{'request.role'}=~/^(au|dc|su)/) {
371: return "<a href='".'javascript:openstdbrowser("'.$form.'","'.$unameele.
1.119 www 372: '","'.$udomele.'",1);'."'>".&mt('Select User')."</a>";
1.111 www 373: }
374: return '';
1.91 www 375: }
376:
377: sub coursebrowser_javascript {
1.128 albertel 378: my ($domainfilter)=@_;
379: return (<<ENDSTDBRW);
1.91 www 380: <script type="text/javascript" language="Javascript" >
381: var stdeditbrowser;
1.187 albertel 382: function opencrsbrowser(formname,uname,udom,desc) {
1.91 www 383: var url = '/adm/pickcourse?';
384: var filter;
385: if (filter != null) {
386: if (filter != '') {
387: url += 'filter='+filter+'&';
388: }
389: }
1.128 albertel 390: var domainfilter='$domainfilter';
391: if (domainfilter != null) {
392: if (domainfilter != '') {
393: url += 'domainfilter='+domainfilter+'&';
394: }
395: }
1.91 www 396: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 397: '&cdomelement='+udom+
398: '&cnameelement='+desc;
1.102 www 399: var title = 'Course_Browser';
1.91 www 400: var options = 'scrollbars=1,resizable=1,menubar=0';
401: options += ',width=700,height=600';
402: stdeditbrowser = open(url,title,options,'1');
403: stdeditbrowser.focus();
404: }
405: </script>
406: ENDSTDBRW
407: }
408:
409: sub selectcourse_link {
1.187 albertel 410: my ($form,$unameele,$udomele,$desc)=@_;
1.91 www 411: return "<a href='".'javascript:opencrsbrowser("'.$form.'","'.$unameele.
1.187 albertel 412: '","'.$udomele.'","'.$desc.'");'."'>".&mt('Select Course')."</a>";
1.74 www 413: }
1.42 matthew 414:
415: =pod
1.36 matthew 416:
1.112 bowersj2 417: =item * linked_select_forms(...)
1.36 matthew 418:
419: linked_select_forms returns a string containing a <script></script> block
420: and html for two <select> menus. The select menus will be linked in that
421: changing the value of the first menu will result in new values being placed
422: in the second menu. The values in the select menu will appear in alphabetical
423: order.
424:
425: linked_select_forms takes the following ordered inputs:
426:
427: =over 4
428:
1.112 bowersj2 429: =item * $formname, the name of the <form> tag
1.36 matthew 430:
1.112 bowersj2 431: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 432:
1.112 bowersj2 433: =item * $firstdefault, the default value for the first menu
1.36 matthew 434:
1.112 bowersj2 435: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 436:
1.112 bowersj2 437: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 438:
1.112 bowersj2 439: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 440:
1.41 ng 441: =back
442:
1.36 matthew 443: Below is an example of such a hash. Only the 'text', 'default', and
444: 'select2' keys must appear as stated. keys(%menu) are the possible
445: values for the first select menu. The text that coincides with the
1.41 ng 446: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 447: and text for the second menu are given in the hash pointed to by
448: $menu{$choice1}->{'select2'}.
449:
1.112 bowersj2 450: my %menu = ( A1 => { text =>"Choice A1" ,
451: default => "B3",
452: select2 => {
453: B1 => "Choice B1",
454: B2 => "Choice B2",
455: B3 => "Choice B3",
456: B4 => "Choice B4"
457: }
458: },
459: A2 => { text =>"Choice A2" ,
460: default => "C2",
461: select2 => {
462: C1 => "Choice C1",
463: C2 => "Choice C2",
464: C3 => "Choice C3"
465: }
466: },
467: A3 => { text =>"Choice A3" ,
468: default => "D6",
469: select2 => {
470: D1 => "Choice D1",
471: D2 => "Choice D2",
472: D3 => "Choice D3",
473: D4 => "Choice D4",
474: D5 => "Choice D5",
475: D6 => "Choice D6",
476: D7 => "Choice D7"
477: }
478: }
479: );
1.36 matthew 480:
481: =cut
482:
483: sub linked_select_forms {
484: my ($formname,
485: $middletext,
486: $firstdefault,
487: $firstselectname,
488: $secondselectname,
489: $hashref
490: ) = @_;
491: my $second = "document.$formname.$secondselectname";
492: my $first = "document.$formname.$firstselectname";
493: # output the javascript to do the changing
494: my $result = '';
1.219 albertel 495: $result.="<script type=\"text/javascript\">\n";
1.36 matthew 496: $result.="var select2data = new Object();\n";
497: $" = '","';
498: my $debug = '';
499: foreach my $s1 (sort(keys(%$hashref))) {
500: $result.="select2data.d_$s1 = new Object();\n";
501: $result.="select2data.d_$s1.def = new String('".
502: $hashref->{$s1}->{'default'}."');\n";
503: $result.="select2data.d_$s1.values = new Array(";
504: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
505: $result.="\"@s2values\");\n";
506: $result.="select2data.d_$s1.texts = new Array(";
507: my @s2texts;
508: foreach my $value (@s2values) {
509: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
510: }
511: $result.="\"@s2texts\");\n";
512: }
513: $"=' ';
514: $result.= <<"END";
515:
516: function select1_changed() {
517: // Determine new choice
518: var newvalue = "d_" + $first.value;
519: // update select2
520: var values = select2data[newvalue].values;
521: var texts = select2data[newvalue].texts;
522: var select2def = select2data[newvalue].def;
523: var i;
524: // out with the old
525: for (i = 0; i < $second.options.length; i++) {
526: $second.options[i] = null;
527: }
528: // in with the nuclear
529: for (i=0;i<values.length; i++) {
530: $second.options[i] = new Option(values[i]);
1.143 matthew 531: $second.options[i].value = values[i];
1.36 matthew 532: $second.options[i].text = texts[i];
533: if (values[i] == select2def) {
534: $second.options[i].selected = true;
535: }
536: }
537: }
538: </script>
539: END
540: # output the initial values for the selection lists
541: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
542: foreach my $value (sort(keys(%$hashref))) {
543: $result.=" <option value=\"$value\" ";
544: $result.=" selected=\"true\" " if ($value eq $firstdefault);
1.119 www 545: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 546: }
547: $result .= "</select>\n";
548: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
549: $result .= $middletext;
550: $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
551: my $seconddefault = $hashref->{$firstdefault}->{'default'};
552: foreach my $value (sort(keys(%select2))) {
553: $result.=" <option value=\"$value\" ";
554: $result.=" selected=\"true\" " if ($value eq $seconddefault);
1.119 www 555: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 556: }
557: $result .= "</select>\n";
558: # return $debug;
559: return $result;
560: } # end of sub linked_select_forms {
561:
1.45 matthew 562: =pod
1.44 bowersj2 563:
1.112 bowersj2 564: =item * help_open_topic($topic, $text, $stayOnPage, $width, $height)
1.44 bowersj2 565:
1.112 bowersj2 566: Returns a string corresponding to an HTML link to the given help
567: $topic, where $topic corresponds to the name of a .tex file in
568: /home/httpd/html/adm/help/tex, with underscores replaced by
569: spaces.
570:
571: $text will optionally be linked to the same topic, allowing you to
572: link text in addition to the graphic. If you do not want to link
573: text, but wish to specify one of the later parameters, pass an
574: empty string.
575:
576: $stayOnPage is a value that will be interpreted as a boolean. If true,
577: the link will not open a new window. If false, the link will open
578: a new window using Javascript. (Default is false.)
579:
580: $width and $height are optional numerical parameters that will
581: override the width and height of the popped up window, which may
582: be useful for certain help topics with big pictures included.
1.44 bowersj2 583:
584: =cut
585:
586: sub help_open_topic {
1.48 bowersj2 587: my ($topic, $text, $stayOnPage, $width, $height) = @_;
588: $text = "" if (not defined $text);
1.44 bowersj2 589: $stayOnPage = 0 if (not defined $stayOnPage);
1.108 bowersj2 590: if ($ENV{'browser.interface'} eq 'textual' ||
591: $ENV{'environment.remote'} eq 'off' ) {
1.79 www 592: $stayOnPage=1;
593: }
1.44 bowersj2 594: $width = 350 if (not defined $width);
595: $height = 400 if (not defined $height);
596: my $filename = $topic;
597: $filename =~ s/ /_/g;
598:
1.48 bowersj2 599: my $template = "";
600: my $link;
1.159 www 601:
602: $topic=~s/\W/\_/g;
1.44 bowersj2 603:
604: if (!$stayOnPage)
605: {
1.72 bowersj2 606: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1.44 bowersj2 607: }
608: else
609: {
1.48 bowersj2 610: $link = "/adm/help/${filename}.hlp";
611: }
612:
613: # Add the text
614: if ($text ne "")
615: {
1.77 www 616: $template .=
617: "<table bgcolor='#3333AA' cellspacing='1' cellpadding='1' border='0'><tr>".
1.78 www 618: "<td bgcolor='#5555FF'><a href=\"$link\"><font color='#FFFFFF' size='2'>$text</font></a>";
1.48 bowersj2 619: }
620:
621: # Add the graphic
1.179 matthew 622: my $title = &mt('Online Help');
1.215 albertel 623: my $helpicon=&lonhttpdurl("/adm/help/gif/smallHelp.gif");
1.48 bowersj2 624: $template .= <<"ENDTEMPLATE";
1.218 albertel 625: <a href="$link" title="$title"><img src="$helpicon" border="0" alt="(Help: $topic)" /></a>
1.44 bowersj2 626: ENDTEMPLATE
1.78 www 627: if ($text ne '') { $template.='</td></tr></table>' };
1.44 bowersj2 628: return $template;
629:
1.106 bowersj2 630: }
631:
632: # This is a quicky function for Latex cheatsheet editing, since it
633: # appears in at least four places
634: sub helpLatexCheatsheet {
635: my $other = shift;
636: my $addOther = '';
637: if ($other) {
638: $addOther = Apache::loncommon::help_open_topic($other, shift,
639: undef, undef, 600) .
640: '</td><td>';
641: }
642: return '<table><tr><td>'.
643: $addOther .
644: &Apache::loncommon::help_open_topic("Greek_Symbols",'Greek Symbols',
645: undef,undef,600)
646: .'</td><td>'.
647: &Apache::loncommon::help_open_topic("Other_Symbols",'Other Symbols',
648: undef,undef,600)
649: .'</td></tr></table>';
1.172 www 650: }
651:
1.193 raeburn 652: sub help_open_menu {
653: my ($color,$topic,$component_help,$function,$faq,$bug,$stayOnPage,$width,$height,$text) = @_;
654: $text = "" if (not defined $text);
655: $stayOnPage = 0 if (not defined $stayOnPage);
656: if ($ENV{'browser.interface'} eq 'textual' ||
657: $ENV{'environment.remote'} eq 'off' ) {
658: $stayOnPage=1;
659: }
660: $width = 620 if (not defined $width);
661: $height = 600 if (not defined $height);
662: my $link='';
1.201 raeburn 663: my $title = &mt('Get help');
1.193 raeburn 664: my $origurl = $ENV{'REQUEST_URI'};
1.227 albertel 665: $origurl=~s|^/~|/priv/|;
1.193 raeburn 666: my $timestamp = time;
667: foreach (\$color,\$function,\$topic,\$component_help,\$faq,\$bug,\$origurl) {
668: $$_ = &Apache::lonnet::escape($$_);
669: }
670:
1.195 albertel 671: if (!$stayOnPage) {
1.193 raeburn 672: $link = "javascript:helpMenu('open')";
1.195 albertel 673: } else {
1.193 raeburn 674: $link = "javascript:helpMenu('display')";
675: }
1.198 raeburn 676: my $banner_link = "/adm/helpmenu?page=banner&color=$color&function=$function&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1.193 raeburn 677: my $details_link = "/adm/helpmenu?page=body&color=$color&function=$function&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp";
1.196 albertel 678: my $template;
679: if ($text ne "") {
680: $template .=
1.211 www 681: "<table bgcolor='#773311' cellspacing='1' cellpadding='1' border='0'><tr>".
682: "<td bgcolor='#886622'><a href=\"$link\"><font color='#FFFFFF' size='2'>$text</font></a>";
1.196 albertel 683: }
1.215 albertel 684: my $helpicon=&lonhttpdurl("/adm/lonIcons/helpgateway.gif");
1.196 albertel 685: $template .= <<"ENDTEMPLATE";
1.219 albertel 686: <script type="text/javascript">
687: //<!-- BEGIN LON-CAPA Internal
1.193 raeburn 688: function helpMenu(caller) {
689: if (caller == 'open') {
690: newWindow = window.open("","helpmenu","HEIGHT=$height,WIDTH=$width,resize=yes,scrollbars=yes" )
691: caller = newWindow.document
692: } else {
693: caller = this.document
694: }
695: caller.write("<html><head><title>LON-CAPA Help Menu</title><meta http-equiv='pragma' content='no-cache'></head>")
696: caller.write("<frameset rows='105,*' border='0'><frame name='bannerframe' src='$banner_link'><frame name='bodyframe' src='$details_link'></frameset>")
697: caller.write("</html>")
698: caller.close()
699: if (caller == newWindow.document) {
700: caller.focus()
701: }
702: }
1.219 albertel 703: // END LON-CAPA Internal -->
1.193 raeburn 704: </script>
1.218 albertel 705: <a href="$link" title="$title"><img src="$helpicon" border="0" alt="(Help Menu)" /></a>
1.193 raeburn 706: ENDTEMPLATE
1.203 albertel 707: if ($component_help) {
708: if (!$text) {
709: $template=&help_open_topic($component_help,undef,$stayOnPage,
710: $width,$height).' '.$template;
711: } else {
712: my $help_text;
713: $help_text=&Apache::lonnet::unescape($topic);
714: $template='<table><tr><td>'.
715: &help_open_topic($component_help,$help_text,$stayOnPage,
716: $width,$height).'</td><td>'.$template.
717: '</td></tr></table>';
718: }
719: }
1.196 albertel 720: if ($text ne '') { $template.='</td></tr></table>' };
1.193 raeburn 721: return $template;
722: }
723:
1.172 www 724: sub help_open_bug {
725: my ($topic, $text, $stayOnPage, $width, $height) = @_;
726: unless ($ENV{'user.adv'}) { return ''; }
727: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
728: $text = "" if (not defined $text);
729: $stayOnPage = 0 if (not defined $stayOnPage);
730: if ($ENV{'browser.interface'} eq 'textual' ||
731: $ENV{'environment.remote'} eq 'off' ) {
732: $stayOnPage=1;
733: }
1.184 albertel 734: $width = 600 if (not defined $width);
735: $height = 600 if (not defined $height);
1.172 www 736:
737: $topic=~s/\W+/\+/g;
738: my $link='';
739: my $template='';
740: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
741: &Apache::lonnet::escape($ENV{'REQUEST_URI'}).'&component='.$topic;
742: if (!$stayOnPage)
743: {
744: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
745: }
746: else
747: {
748: $link = $url;
749: }
750: # Add the text
751: if ($text ne "")
752: {
753: $template .=
754: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
755: "<td bgcolor='#FF5555'><a href=\"$link\"><font color='#FFFFFF' size='2'>$text</font></a>";
756: }
757:
758: # Add the graphic
1.179 matthew 759: my $title = &mt('Report a Bug');
1.215 albertel 760: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 761: $template .= <<"ENDTEMPLATE";
1.218 albertel 762: <a href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 763: ENDTEMPLATE
764: if ($text ne '') { $template.='</td></tr></table>' };
765: return $template;
766:
767: }
768:
769: sub help_open_faq {
770: my ($topic, $text, $stayOnPage, $width, $height) = @_;
771: unless ($ENV{'user.adv'}) { return ''; }
772: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
773: $text = "" if (not defined $text);
774: $stayOnPage = 0 if (not defined $stayOnPage);
775: if ($ENV{'browser.interface'} eq 'textual' ||
776: $ENV{'environment.remote'} eq 'off' ) {
777: $stayOnPage=1;
778: }
779: $width = 350 if (not defined $width);
780: $height = 400 if (not defined $height);
781:
782: $topic=~s/\W+/\+/g;
783: my $link='';
784: my $template='';
785: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
786: if (!$stayOnPage)
787: {
788: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
789: }
790: else
791: {
792: $link = $url;
793: }
794:
795: # Add the text
796: if ($text ne "")
797: {
798: $template .=
1.173 www 799: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
800: "<td bgcolor='#448844'><a href=\"$link\"><font color='#FFFFFF' size='2'>$text</font></a>";
1.172 www 801: }
802:
803: # Add the graphic
1.179 matthew 804: my $title = &mt('View the FAQ');
1.215 albertel 805: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 806: $template .= <<"ENDTEMPLATE";
1.218 albertel 807: <a href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 808: ENDTEMPLATE
809: if ($text ne '') { $template.='</td></tr></table>' };
810: return $template;
811:
1.44 bowersj2 812: }
1.37 matthew 813:
1.180 matthew 814: ###############################################################
815: ###############################################################
816:
1.45 matthew 817: =pod
818:
1.112 bowersj2 819: =item * csv_translate($text)
1.37 matthew 820:
1.185 www 821: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 822: format.
823:
824: =cut
825:
1.180 matthew 826: ###############################################################
827: ###############################################################
1.37 matthew 828: sub csv_translate {
829: my $text = shift;
830: $text =~ s/\"/\"\"/g;
1.209 albertel 831: $text =~ s/\n/ /g;
1.37 matthew 832: return $text;
833: }
1.180 matthew 834:
835:
836: ###############################################################
837: ###############################################################
838:
839: =pod
840:
841: =item * define_excel_formats
842:
843: Define some commonly used Excel cell formats.
844:
845: Currently supported formats:
846:
847: =over 4
848:
849: =item header
850:
851: =item bold
852:
853: =item h1
854:
855: =item h2
856:
857: =item h3
858:
859: =item date
860:
861: =back
862:
863: Inputs: $workbook
864:
865: Returns: $format, a hash reference.
866:
867: =cut
868:
869: ###############################################################
870: ###############################################################
871: sub define_excel_formats {
872: my ($workbook) = @_;
873: my $format;
874: $format->{'header'} = $workbook->add_format(bold => 1,
875: bottom => 1,
876: align => 'center');
877: $format->{'bold'} = $workbook->add_format(bold=>1);
878: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
879: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
880: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
881: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 882: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 883: return $format;
884: }
885:
886: ###############################################################
887: ###############################################################
1.113 bowersj2 888:
889: =pod
890:
891: =item * change_content_javascript():
892:
893: This and the next function allow you to create small sections of an
894: otherwise static HTML page that you can update on the fly with
895: Javascript, even in Netscape 4.
896:
897: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
898: must be written to the HTML page once. It will prove the Javascript
899: function "change(name, content)". Calling the change function with the
900: name of the section
901: you want to update, matching the name passed to C<changable_area>, and
902: the new content you want to put in there, will put the content into
903: that area.
904:
905: B<Note>: Netscape 4 only reserves enough space for the changable area
906: to contain room for the original contents. You need to "make space"
907: for whatever changes you wish to make, and be B<sure> to check your
908: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
909: it's adequate for updating a one-line status display, but little more.
910: This script will set the space to 100% width, so you only need to
911: worry about height in Netscape 4.
912:
913: Modern browsers are much less limiting, and if you can commit to the
914: user not using Netscape 4, this feature may be used freely with
915: pretty much any HTML.
916:
917: =cut
918:
919: sub change_content_javascript {
920: # If we're on Netscape 4, we need to use Layer-based code
921: if ($ENV{'browser.type'} eq 'netscape' &&
922: $ENV{'browser.version'} =~ /^4\./) {
923: return (<<NETSCAPE4);
924: function change(name, content) {
925: doc = document.layers[name+"___escape"].layers[0].document;
926: doc.open();
927: doc.write(content);
928: doc.close();
929: }
930: NETSCAPE4
931: } else {
932: # Otherwise, we need to use semi-standards-compliant code
933: # (technically, "innerHTML" isn't standard but the equivalent
934: # is really scary, and every useful browser supports it
935: return (<<DOMBASED);
936: function change(name, content) {
937: element = document.getElementById(name);
938: element.innerHTML = content;
939: }
940: DOMBASED
941: }
942: }
943:
944: =pod
945:
946: =item * changable_area($name, $origContent):
947:
948: This provides a "changable area" that can be modified on the fly via
949: the Javascript code provided in C<change_content_javascript>. $name is
950: the name you will use to reference the area later; do not repeat the
951: same name on a given HTML page more then once. $origContent is what
952: the area will originally contain, which can be left blank.
953:
954: =cut
955:
956: sub changable_area {
957: my ($name, $origContent) = @_;
958:
959: if ($ENV{'browser.type'} eq 'netscape' &&
960: $ENV{'browser.version'} =~ /^4\./) {
961: # If this is netscape 4, we need to use the Layer tag
962: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
963: } else {
964: return "<span id='$name'>$origContent</span>";
965: }
966: }
967:
968: =pod
969:
970: =back
971:
972: =cut
1.37 matthew 973:
974: ###############################################################
1.33 matthew 975: ## Home server <option> list generating code ##
976: ###############################################################
1.35 matthew 977:
1.45 matthew 978: =pod
979:
1.112 bowersj2 980: =head1 Home Server option list generating code
981:
982: =over 4
983:
984: =item * get_domains()
1.35 matthew 985:
986: Returns an array containing each of the domains listed in the hosts.tab
987: file.
988:
989: =cut
990:
991: #-------------------------------------------
1.34 matthew 992: sub get_domains {
993: # The code below was stolen from "The Perl Cookbook", p 102, 1st ed.
994: my @domains;
995: my %seen;
996: foreach (sort values(%Apache::lonnet::hostdom)) {
1.169 www 997: push (@domains,$_) unless $seen{$_}++;
1.34 matthew 998: }
999: return @domains;
1000: }
1.88 www 1001:
1.169 www 1002: # ------------------------------------------
1003:
1004: sub domain_select {
1005: my ($name,$value,$multiple)=@_;
1006: my %domains=map {
1007: $_ => $_.' '.$Apache::lonnet::domaindescription{$_}
1008: } &get_domains;
1009: if ($multiple) {
1010: $domains{''}=&mt('Any domain');
1.191 matthew 1011: return &multiple_select_form($name,$value,4,%domains);
1.169 www 1012: } else {
1013: return &select_form($name,$value,%domains);
1014: }
1015: }
1016:
1017: sub multiple_select_form {
1.191 matthew 1018: my ($name,$value,$size,%hash)=@_;
1.169 www 1019: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1020: my $output='';
1.191 matthew 1021: if (! defined($size)) {
1022: $size = 4;
1023: if (scalar(keys(%hash))<4) {
1024: $size = scalar(keys(%hash));
1025: }
1026: }
1.169 www 1027: $output.="\n<select name='$name' size='$size' multiple='1'>";
1.191 matthew 1028: foreach (sort(keys(%hash))) {
1029: $output.='<option value="'.$_.'" ';
1030: $output.='selected ' if ($selected{$_});
1031: $output.='>'.$hash{$_}."</option>\n";
1.169 www 1032: }
1033: $output.="</select>\n";
1034: return $output;
1035: }
1036:
1.88 www 1037: #-------------------------------------------
1038:
1039: =pod
1040:
1.112 bowersj2 1041: =item * select_form($defdom,$name,%hash)
1.88 www 1042:
1043: Returns a string containing a <select name='$name' size='1'> form to
1044: allow a user to select options from a hash option_name => displayed text.
1045: See lonrights.pm for an example invocation and use.
1046:
1047: =cut
1048:
1049: #-------------------------------------------
1050: sub select_form {
1051: my ($def,$name,%hash) = @_;
1052: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1.128 albertel 1053: my @keys;
1054: if (exists($hash{'select_form_order'})) {
1055: @keys=@{$hash{'select_form_order'}};
1056: } else {
1057: @keys=sort(keys(%hash));
1058: }
1059: foreach (@keys) {
1.88 www 1060: $selectform.="<option value=\"$_\" ".
1061: ($_ eq $def ? 'selected' : '').
1.119 www 1062: ">".&mt($hash{$_})."</option>\n";
1.88 www 1063: }
1064: $selectform.="</select>";
1065: return $selectform;
1066: }
1067:
1.167 www 1068: sub gradeleveldescription {
1069: my $gradelevel=shift;
1070: my %gradelevels=(0 => 'Not specified',
1071: 1 => 'Grade 1',
1072: 2 => 'Grade 2',
1073: 3 => 'Grade 3',
1074: 4 => 'Grade 4',
1075: 5 => 'Grade 5',
1076: 6 => 'Grade 6',
1077: 7 => 'Grade 7',
1078: 8 => 'Grade 8',
1079: 9 => 'Grade 9',
1080: 10 => 'Grade 10',
1081: 11 => 'Grade 11',
1082: 12 => 'Grade 12',
1083: 13 => 'Grade 13',
1084: 14 => '100 Level',
1085: 15 => '200 Level',
1086: 16 => '300 Level',
1087: 17 => '400 Level',
1088: 18 => 'Graduate Level');
1089: return &mt($gradelevels{$gradelevel});
1090: }
1091:
1.163 www 1092: sub select_level_form {
1093: my ($deflevel,$name)=@_;
1094: unless ($deflevel) { $deflevel=0; }
1.167 www 1095: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1096: for (my $i=0; $i<=18; $i++) {
1097: $selectform.="<option value=\"$i\" ".
1098: ($i==$deflevel ? 'selected' : '').
1099: ">".&gradeleveldescription($i)."</option>\n";
1100: }
1101: $selectform.="</select>";
1102: return $selectform;
1.163 www 1103: }
1.167 www 1104:
1.35 matthew 1105: #-------------------------------------------
1106:
1.45 matthew 1107: =pod
1108:
1.112 bowersj2 1109: =item * select_dom_form($defdom,$name,$includeempty)
1.35 matthew 1110:
1111: Returns a string containing a <select name='$name' size='1'> form to
1112: allow a user to select the domain to preform an operation in.
1113: See loncreateuser.pm for an example invocation and use.
1114:
1.90 www 1115: If the $includeempty flag is set, it also includes an empty choice ("no domain
1116: selected");
1117:
1.35 matthew 1118: =cut
1119:
1120: #-------------------------------------------
1.34 matthew 1121: sub select_dom_form {
1.90 www 1122: my ($defdom,$name,$includeempty) = @_;
1.34 matthew 1123: my @domains = get_domains();
1.90 www 1124: if ($includeempty) { @domains=('',@domains); }
1.34 matthew 1125: my $selectdomain = "<select name=\"$name\" size=\"1\">\n";
1126: foreach (@domains) {
1127: $selectdomain.="<option value=\"$_\" ".
1128: ($_ eq $defdom ? 'selected' : '').
1129: ">$_</option>\n";
1130: }
1131: $selectdomain.="</select>";
1132: return $selectdomain;
1133: }
1134:
1.35 matthew 1135: #-------------------------------------------
1136:
1.45 matthew 1137: =pod
1138:
1.112 bowersj2 1139: =item * get_library_servers($domain)
1.35 matthew 1140:
1141: Returns a hash which contains keys like '103l3' and values like
1142: 'kirk.lite.msu.edu'. All of the keys will be for machines in the
1143: given $domain.
1144:
1145: =cut
1146:
1147: #-------------------------------------------
1.52 matthew 1148: sub get_library_servers {
1.33 matthew 1149: my $domain = shift;
1.52 matthew 1150: my %library_servers;
1.33 matthew 1151: foreach (keys(%Apache::lonnet::libserv)) {
1152: if ($Apache::lonnet::hostdom{$_} eq $domain) {
1.52 matthew 1153: $library_servers{$_} = $Apache::lonnet::hostname{$_};
1.33 matthew 1154: }
1155: }
1.52 matthew 1156: return %library_servers;
1.33 matthew 1157: }
1158:
1.35 matthew 1159: #-------------------------------------------
1160:
1.45 matthew 1161: =pod
1162:
1.112 bowersj2 1163: =item * home_server_option_list($domain)
1.35 matthew 1164:
1165: returns a string which contains an <option> list to be used in a
1166: <select> form input. See loncreateuser.pm for an example.
1167:
1168: =cut
1169:
1170: #-------------------------------------------
1.33 matthew 1171: sub home_server_option_list {
1172: my $domain = shift;
1.52 matthew 1173: my %servers = &get_library_servers($domain);
1.33 matthew 1174: my $result = '';
1175: foreach (sort keys(%servers)) {
1176: $result.=
1177: '<option value="'.$_.'">'.$_.' '.$servers{$_}."</option>\n";
1178: }
1179: return $result;
1180: }
1.112 bowersj2 1181:
1182: =pod
1183:
1184: =back
1185:
1186: =cut
1.87 matthew 1187:
1188: ###############################################################
1.112 bowersj2 1189: ## Decoding User Agent ##
1.87 matthew 1190: ###############################################################
1191:
1192: =pod
1193:
1.112 bowersj2 1194: =head1 Decoding the User Agent
1195:
1196: =over 4
1197:
1198: =item * &decode_user_agent()
1.87 matthew 1199:
1200: Inputs: $r
1201:
1202: Outputs:
1203:
1204: =over 4
1205:
1.112 bowersj2 1206: =item * $httpbrowser
1.87 matthew 1207:
1.112 bowersj2 1208: =item * $clientbrowser
1.87 matthew 1209:
1.112 bowersj2 1210: =item * $clientversion
1.87 matthew 1211:
1.112 bowersj2 1212: =item * $clientmathml
1.87 matthew 1213:
1.112 bowersj2 1214: =item * $clientunicode
1.87 matthew 1215:
1.112 bowersj2 1216: =item * $clientos
1.87 matthew 1217:
1218: =back
1219:
1.157 matthew 1220: =back
1221:
1.87 matthew 1222: =cut
1223:
1224: ###############################################################
1225: ###############################################################
1226: sub decode_user_agent {
1227: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
1228: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
1229: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1230: my $clientbrowser='unknown';
1231: my $clientversion='0';
1232: my $clientmathml='';
1233: my $clientunicode='0';
1234: for (my $i=0;$i<=$#browsertype;$i++) {
1235: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
1236: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
1237: $clientbrowser=$bname;
1238: $httpbrowser=~/$vreg/i;
1239: $clientversion=$1;
1240: $clientmathml=($clientversion>=$minv);
1241: $clientunicode=($clientversion>=$univ);
1242: }
1243: }
1244: my $clientos='unknown';
1245: if (($httpbrowser=~/linux/i) ||
1246: ($httpbrowser=~/unix/i) ||
1247: ($httpbrowser=~/ux/i) ||
1248: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
1249: if (($httpbrowser=~/vax/i) ||
1250: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
1251: if ($httpbrowser=~/next/i) { $clientos='next'; }
1252: if (($httpbrowser=~/mac/i) ||
1253: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1254: if ($httpbrowser=~/win/i) { $clientos='win'; }
1255: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1256: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1257: $clientunicode,$clientos,);
1258: }
1259:
1.32 matthew 1260: ###############################################################
1261: ## Authentication changing form generation subroutines ##
1262: ###############################################################
1263: ##
1264: ## All of the authform_xxxxxxx subroutines take their inputs in a
1265: ## hash, and have reasonable default values.
1266: ##
1267: ## formname = the name given in the <form> tag.
1.35 matthew 1268: #-------------------------------------------
1269:
1.45 matthew 1270: =pod
1271:
1.112 bowersj2 1272: =head1 Authentication Routines
1273:
1274: =over 4
1275:
1276: =item * authform_xxxxxx
1.35 matthew 1277:
1278: The authform_xxxxxx subroutines provide javascript and html forms which
1279: handle some of the conveniences required for authentication forms.
1280: This is not an optimal method, but it works.
1281:
1282: See loncreateuser.pm for invocation and use examples.
1283:
1284: =over 4
1285:
1.112 bowersj2 1286: =item * authform_header
1.35 matthew 1287:
1.112 bowersj2 1288: =item * authform_authorwarning
1.35 matthew 1289:
1.112 bowersj2 1290: =item * authform_nochange
1.35 matthew 1291:
1.112 bowersj2 1292: =item * authform_kerberos
1.35 matthew 1293:
1.112 bowersj2 1294: =item * authform_internal
1.35 matthew 1295:
1.112 bowersj2 1296: =item * authform_filesystem
1.35 matthew 1297:
1298: =back
1299:
1.157 matthew 1300: =back
1301:
1.35 matthew 1302: =cut
1303:
1304: #-------------------------------------------
1.32 matthew 1305: sub authform_header{
1306: my %in = (
1307: formname => 'cu',
1.80 albertel 1308: kerb_def_dom => '',
1.32 matthew 1309: @_,
1310: );
1311: $in{'formname'} = 'document.' . $in{'formname'};
1312: my $result='';
1.80 albertel 1313:
1314: #---------------------------------------------- Code for upper case translation
1315: my $Javascript_toUpperCase;
1316: unless ($in{kerb_def_dom}) {
1317: $Javascript_toUpperCase =<<"END";
1318: switch (choice) {
1319: case 'krb': currentform.elements[choicearg].value =
1320: currentform.elements[choicearg].value.toUpperCase();
1321: break;
1322: default:
1323: }
1324: END
1325: } else {
1326: $Javascript_toUpperCase = "";
1327: }
1328:
1.165 raeburn 1329: my $radioval = "'nochange'";
1.174 matthew 1330: if (exists($in{'curr_authtype'}) &&
1331: defined($in{'curr_authtype'}) &&
1332: $in{'curr_authtype'} ne '') {
1333: $radioval = "'$in{'curr_authtype'}arg'";
1334: }
1.165 raeburn 1335: my $argfield = 'null';
1336: if ( grep/^mode$/,(keys %in) ) {
1337: if ($in{'mode'} eq 'modifycourse') {
1338: if ( grep/^curr_authtype$/,(keys %in) ) {
1339: $radioval = "'$in{'curr_authtype'}'";
1340: }
1341: if ( grep/^curr_autharg$/,(keys %in) ) {
1342: unless ($in{'curr_autharg'} eq '') {
1343: $argfield = "'$in{'curr_autharg'}'";
1344: }
1345: }
1346: }
1347: }
1348:
1.32 matthew 1349: $result.=<<"END";
1350: var current = new Object();
1.165 raeburn 1351: current.radiovalue = $radioval;
1352: current.argfield = $argfield;
1.32 matthew 1353:
1354: function changed_radio(choice,currentform) {
1355: var choicearg = choice + 'arg';
1356: // If a radio button in changed, we need to change the argfield
1357: if (current.radiovalue != choice) {
1358: current.radiovalue = choice;
1359: if (current.argfield != null) {
1360: currentform.elements[current.argfield].value = '';
1361: }
1362: if (choice == 'nochange') {
1363: current.argfield = null;
1364: } else {
1365: current.argfield = choicearg;
1366: switch(choice) {
1367: case 'krb':
1368: currentform.elements[current.argfield].value =
1369: "$in{'kerb_def_dom'}";
1370: break;
1371: default:
1372: break;
1373: }
1374: }
1375: }
1376: return;
1377: }
1.22 www 1378:
1.32 matthew 1379: function changed_text(choice,currentform) {
1380: var choicearg = choice + 'arg';
1381: if (currentform.elements[choicearg].value !='') {
1.80 albertel 1382: $Javascript_toUpperCase
1.32 matthew 1383: // clear old field
1384: if ((current.argfield != choicearg) && (current.argfield != null)) {
1385: currentform.elements[current.argfield].value = '';
1386: }
1387: current.argfield = choicearg;
1388: }
1389: set_auth_radio_buttons(choice,currentform);
1390: return;
1.20 www 1391: }
1.32 matthew 1392:
1393: function set_auth_radio_buttons(newvalue,currentform) {
1394: var i=0;
1395: while (i < currentform.login.length) {
1396: if (currentform.login[i].value == newvalue) { break; }
1397: i++;
1398: }
1399: if (i == currentform.login.length) {
1400: return;
1401: }
1402: current.radiovalue = newvalue;
1403: currentform.login[i].checked = true;
1404: return;
1405: }
1406: END
1407: return $result;
1408: }
1409:
1410: sub authform_authorwarning{
1411: my $result='';
1.144 matthew 1412: $result='<i>'.
1413: &mt('As a general rule, only authors or co-authors should be '.
1414: 'filesystem authenticated '.
1415: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 1416: return $result;
1417: }
1418:
1419: sub authform_nochange{
1420: my %in = (
1421: formname => 'document.cu',
1422: kerb_def_dom => 'MSU.EDU',
1423: @_,
1424: );
1.144 matthew 1425: my $result = &mt('[_1] Do not change login data',
1426: '<input type="radio" name="login" value="nochange" '.
1427: 'checked="checked" onclick="'.
1428: "javascript:changed_radio('nochange',$in{'formname'});".'" />');
1.32 matthew 1429: return $result;
1430: }
1431:
1432: sub authform_kerberos{
1433: my %in = (
1434: formname => 'document.cu',
1435: kerb_def_dom => 'MSU.EDU',
1.80 albertel 1436: kerb_def_auth => 'krb4',
1.32 matthew 1437: @_,
1438: );
1.165 raeburn 1439: my ($check4,$check5,$krbarg);
1.80 albertel 1440: if ($in{'kerb_def_auth'} eq 'krb5') {
1441: $check5 = " checked=\"on\"";
1442: } else {
1443: $check4 = " checked=\"on\"";
1444: }
1.165 raeburn 1445: $krbarg = $in{'kerb_def_dom'};
1446:
1447: my $krbcheck = "";
1448: if ( grep/^curr_authtype$/,(keys %in) ) {
1449: if ($in{'curr_authtype'} =~ m/^krb/) {
1450: $krbcheck = " checked=\"on\"";
1451: if ( grep/^curr_autharg$/,(keys %in) ) {
1452: $krbarg = $in{'curr_autharg'};
1453: }
1454: }
1455: }
1456:
1.144 matthew 1457: my $jscall = "javascript:changed_radio('krb',$in{'formname'});";
1458: my $result .= &mt
1459: ('[_1] Kerberos authenticated with domain [_2] '.
1460: '[_3] Version 4 [_4] Version 5',
1461: '<input type="radio" name="login" value="krb" '.
1.165 raeburn 1462: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.$krbcheck.' />',
1.144 matthew 1463: '<input type="text" size="10" name="krbarg" '.
1.165 raeburn 1464: 'value="'.$krbarg.'" '.
1.144 matthew 1465: 'onchange="'.$jscall.'" />',
1466: '<input type="radio" name="krbver" value="4" '.$check4.' />',
1467: '<input type="radio" name="krbver" value="5" '.$check5.' />');
1.32 matthew 1468: return $result;
1469: }
1470:
1471: sub authform_internal{
1472: my %args = (
1473: formname => 'document.cu',
1474: kerb_def_dom => 'MSU.EDU',
1475: @_,
1476: );
1.165 raeburn 1477:
1478: my $intcheck = "";
1479: my $intarg = 'value=""';
1480: if ( grep/^curr_authtype$/,(keys %args) ) {
1481: if ($args{'curr_authtype'} eq 'int') {
1482: $intcheck = " checked=\"on\"";
1483: if ( grep/^curr_autharg$/,(keys %args) ) {
1484: $intarg = "value=\"$args{'curr_autharg'}\"";
1485: }
1486: }
1487: }
1488:
1.144 matthew 1489: my $jscall = "javascript:changed_radio('int',$args{'formname'});";
1490: my $result.=&mt
1491: ('[_1] Internally authenticated (with initial password [_2])',
1.165 raeburn 1492: '<input type="radio" name="login" value="int" '.$intcheck.
1493: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1494: '<input type="text" size="10" name="intarg" '.$intarg.
1495: ' onchange="'.$jscall.'" />');
1.32 matthew 1496: return $result;
1497: }
1498:
1499: sub authform_local{
1500: my %in = (
1501: formname => 'document.cu',
1502: kerb_def_dom => 'MSU.EDU',
1503: @_,
1504: );
1.165 raeburn 1505:
1506: my $loccheck = "";
1507: my $locarg = 'value=""';
1508: if ( grep/^curr_authtype$/,(keys %in) ) {
1509: if ($in{'curr_authtype'} eq 'loc') {
1510: $loccheck = " checked=\"on\"";
1511: if ( grep/^curr_autharg$/,(keys %in) ) {
1512: $locarg = "value=\"$in{'curr_autharg'}\"";
1513: }
1514: }
1515: }
1516:
1.144 matthew 1517: my $jscall = "javascript:changed_radio('loc',$in{'formname'});";
1.160 matthew 1518: my $result.=&mt('[_1] Local Authentication with argument [_2]',
1.165 raeburn 1519: '<input type="radio" name="login" value="loc" '.$loccheck.
1520: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1521: '<input type="text" size="10" name="locarg" '.$locarg.
1522: ' onchange="'.$jscall.'" />');
1.32 matthew 1523: return $result;
1524: }
1525:
1526: sub authform_filesystem{
1527: my %in = (
1528: formname => 'document.cu',
1529: kerb_def_dom => 'MSU.EDU',
1530: @_,
1531: );
1.144 matthew 1532: my $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
1533: my $result.= &mt
1534: ('[_1] Filesystem Authenticated (with initial password [_2])',
1535: '<input type="radio" name="login" value="fsys" '.
1536: 'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1537: '<input type="text" size="10" name="fsysarg" value="" '.
1538: 'onchange="'.$jscall.'" />');
1.32 matthew 1539: return $result;
1540: }
1541:
1.80 albertel 1542: ###############################################################
1543: ## Get Authentication Defaults for Domain ##
1544: ###############################################################
1545:
1546: =pod
1547:
1.112 bowersj2 1548: =head1 Domains and Authentication
1549:
1550: Returns default authentication type and an associated argument as
1551: listed in file 'domain.tab'.
1552:
1553: =over 4
1554:
1555: =item * get_auth_defaults
1.80 albertel 1556:
1557: get_auth_defaults($target_domain) returns the default authentication
1558: type and an associated argument (initial password or a kerberos domain).
1559: These values are stored in lonTabs/domain.tab
1560:
1561: ($def_auth, $def_arg) = &get_auth_defaults($target_domain);
1562:
1563: If target_domain is not found in domain.tab, returns nothing ('').
1564:
1565: =cut
1566:
1567: #-------------------------------------------
1568: sub get_auth_defaults {
1569: my $domain=shift;
1570: return ($Apache::lonnet::domain_auth_def{$domain},$Apache::lonnet::domain_auth_arg_def{$domain});
1571: }
1572: ###############################################################
1573: ## End Get Authentication Defaults for Domain ##
1574: ###############################################################
1575:
1576: ###############################################################
1577: ## Get Kerberos Defaults for Domain ##
1578: ###############################################################
1579: ##
1580: ## Returns default kerberos version and an associated argument
1581: ## as listed in file domain.tab. If not listed, provides
1582: ## appropriate default domain and kerberos version.
1583: ##
1584: #-------------------------------------------
1585:
1586: =pod
1587:
1.112 bowersj2 1588: =item * get_kerberos_defaults
1.80 albertel 1589:
1590: get_kerberos_defaults($target_domain) returns the default kerberos
1591: version and domain. If not found in domain.tabs, it defaults to
1592: version 4 and the domain of the server.
1593:
1594: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
1595:
1596: =cut
1597:
1598: #-------------------------------------------
1599: sub get_kerberos_defaults {
1600: my $domain=shift;
1601: my ($krbdef,$krbdefdom) =
1602: &Apache::loncommon::get_auth_defaults($domain);
1603: unless ($krbdef =~/^krb/ && $krbdefdom) {
1604: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
1605: my $krbdefdom=$1;
1606: $krbdefdom=~tr/a-z/A-Z/;
1607: $krbdef = "krb4";
1608: }
1609: return ($krbdef,$krbdefdom);
1610: }
1.112 bowersj2 1611:
1612: =pod
1613:
1614: =back
1615:
1616: =cut
1.32 matthew 1617:
1.46 matthew 1618: ###############################################################
1619: ## Thesaurus Functions ##
1620: ###############################################################
1.20 www 1621:
1.46 matthew 1622: =pod
1.20 www 1623:
1.112 bowersj2 1624: =head1 Thesaurus Functions
1625:
1626: =over 4
1627:
1628: =item * initialize_keywords
1.46 matthew 1629:
1630: Initializes the package variable %Keywords if it is empty. Uses the
1631: package variable $thesaurus_db_file.
1632:
1633: =cut
1634:
1635: ###################################################
1636:
1637: sub initialize_keywords {
1638: return 1 if (scalar keys(%Keywords));
1639: # If we are here, %Keywords is empty, so fill it up
1640: # Make sure the file we need exists...
1641: if (! -e $thesaurus_db_file) {
1642: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
1643: " failed because it does not exist");
1644: return 0;
1645: }
1646: # Set up the hash as a database
1647: my %thesaurus_db;
1648: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 1649: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 1650: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
1651: $thesaurus_db_file);
1652: return 0;
1653: }
1654: # Get the average number of appearances of a word.
1655: my $avecount = $thesaurus_db{'average.count'};
1656: # Put keywords (those that appear > average) into %Keywords
1657: while (my ($word,$data)=each (%thesaurus_db)) {
1658: my ($count,undef) = split /:/,$data;
1659: $Keywords{$word}++ if ($count > $avecount);
1660: }
1661: untie %thesaurus_db;
1662: # Remove special values from %Keywords.
1663: foreach ('total.count','average.count') {
1664: delete($Keywords{$_}) if (exists($Keywords{$_}));
1665: }
1666: return 1;
1667: }
1668:
1669: ###################################################
1670:
1671: =pod
1672:
1.112 bowersj2 1673: =item * keyword($word)
1.46 matthew 1674:
1675: Returns true if $word is a keyword. A keyword is a word that appears more
1676: than the average number of times in the thesaurus database. Calls
1677: &initialize_keywords
1678:
1679: =cut
1680:
1681: ###################################################
1.20 www 1682:
1683: sub keyword {
1.46 matthew 1684: return if (!&initialize_keywords());
1685: my $word=lc(shift());
1686: $word=~s/\W//g;
1687: return exists($Keywords{$word});
1.20 www 1688: }
1.46 matthew 1689:
1690: ###############################################################
1691:
1692: =pod
1.20 www 1693:
1.112 bowersj2 1694: =item * get_related_words
1.46 matthew 1695:
1.160 matthew 1696: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 1697: an array of words. If the keyword is not in the thesaurus, an empty array
1698: will be returned. The order of the words returned is determined by the
1699: database which holds them.
1700:
1701: Uses global $thesaurus_db_file.
1702:
1703: =cut
1704:
1705: ###############################################################
1706: sub get_related_words {
1707: my $keyword = shift;
1708: my %thesaurus_db;
1709: if (! -e $thesaurus_db_file) {
1710: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
1711: "failed because the file does not exist");
1712: return ();
1713: }
1714: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 1715: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 1716: return ();
1717: }
1718: my @Words=();
1719: if (exists($thesaurus_db{$keyword})) {
1720: $_ = $thesaurus_db{$keyword};
1721: (undef,@Words) = split/:/; # The first element is the number of times
1722: # the word appears. We do not need it now.
1723: for (my $i=0;$i<=$#Words;$i++) {
1724: ($Words[$i],undef)= split/\,/,$Words[$i];
1.20 www 1725: }
1726: }
1.46 matthew 1727: untie %thesaurus_db;
1728: return @Words;
1.14 harris41 1729: }
1.46 matthew 1730:
1.112 bowersj2 1731: =pod
1732:
1733: =back
1734:
1735: =cut
1.61 www 1736:
1737: # -------------------------------------------------------------- Plaintext name
1.81 albertel 1738: =pod
1739:
1.112 bowersj2 1740: =head1 User Name Functions
1741:
1742: =over 4
1743:
1.226 albertel 1744: =item * plainname($uname,$udom,$first)
1.81 albertel 1745:
1.112 bowersj2 1746: Takes a users logon name and returns it as a string in
1.226 albertel 1747: "first middle last generation" form
1748: if $first is set to 'lastname' then it returns it as
1749: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 1750:
1751: =cut
1.61 www 1752:
1.81 albertel 1753: ###############################################################
1.61 www 1754: sub plainname {
1.226 albertel 1755: my ($uname,$udom,$first)=@_;
1.61 www 1756: my %names=&Apache::lonnet::get('environment',
1757: ['firstname','middlename','lastname','generation'],
1758: $udom,$uname);
1.226 albertel 1759: my $name=&Apache::lonnet::format_name($names{'firstname'},
1760: $names{'middlename'},
1761: $names{'lastname'},
1762: $names{'generation'},$first);
1763: $name=~s/^\s+//;
1.62 www 1764: $name=~s/\s+$//;
1765: $name=~s/\s+/ /g;
1.190 albertel 1766: if ($name !~ /\S/) { $name=$uname.'@'.$udom; }
1.62 www 1767: return $name;
1.61 www 1768: }
1.66 www 1769:
1770: # -------------------------------------------------------------------- Nickname
1.81 albertel 1771: =pod
1772:
1.112 bowersj2 1773: =item * nickname($uname,$udom)
1.81 albertel 1774:
1775: Gets a users name and returns it as a string as
1776:
1777: ""nickname""
1.66 www 1778:
1.81 albertel 1779: if the user has a nickname or
1780:
1781: "first middle last generation"
1782:
1783: if the user does not
1784:
1785: =cut
1.66 www 1786:
1787: sub nickname {
1788: my ($uname,$udom)=@_;
1.212 albertel 1789: my %names;
1790: if ($uname eq $ENV{'user.name'} &&
1791: $udom eq $ENV{'user.domain'}) {
1792: %names=('nickname' => $ENV{'environment.nickname'} ,
1793: 'firstname' => $ENV{'environment.firstname'} ,
1794: 'middlename' => $ENV{'environment.middlename'},
1795: 'lastname' => $ENV{'environment.lastname'} ,
1796: 'generation' => $ENV{'environment.generation'});
1797: } else {
1798: %names=&Apache::lonnet::get('environment',
1799: ['nickname','firstname','middlename',
1800: 'lastname','generation'],$udom,$uname);
1801: }
1.68 albertel 1802: my $name=$names{'nickname'};
1.66 www 1803: if ($name) {
1804: $name='"'.$name.'"';
1805: } else {
1806: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
1807: $names{'lastname'}.' '.$names{'generation'};
1808: $name=~s/\s+$//;
1809: $name=~s/\s+/ /g;
1810: }
1811: return $name;
1812: }
1813:
1.61 www 1814:
1815: # ------------------------------------------------------------------ Screenname
1.81 albertel 1816:
1817: =pod
1818:
1.112 bowersj2 1819: =item * screenname($uname,$udom)
1.81 albertel 1820:
1821: Gets a users screenname and returns it as a string
1822:
1823: =cut
1.61 www 1824:
1825: sub screenname {
1826: my ($uname,$udom)=@_;
1.212 albertel 1827: if ($uname eq $ENV{'user.name'} &&
1828: $udom eq $ENV{'user.domain'}) {return $ENV{'environment.screenname'};}
1829: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 1830: return $names{'screenname'};
1.62 www 1831: }
1832:
1.212 albertel 1833:
1.62 www 1834: # ------------------------------------------------------------- Message Wrapper
1835:
1836: sub messagewrapper {
1.200 matthew 1837: my ($link,$username,$domain)=@_;
1.62 www 1838: return
1.200 matthew 1839: '<a href="/adm/email?compose=individual&'.
1840: 'recname='.$username.'&recdom='.$domain.'" '.
1841: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 1842: }
1843: # --------------------------------------------------------------- Notes Wrapper
1844:
1845: sub noteswrapper {
1846: my ($link,$un,$do)=@_;
1847: return
1848: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 1849: }
1850: # ------------------------------------------------------------- Aboutme Wrapper
1851:
1852: sub aboutmewrapper {
1.166 www 1853: my ($link,$username,$domain,$target)=@_;
1.205 www 1854: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.200 matthew 1855: ($target?' target="$target"':'').' title="'.&mt('View this users personal page').'">'.$link.'</a>';
1.62 www 1856: }
1857:
1858: # ------------------------------------------------------------ Syllabus Wrapper
1859:
1860:
1861: sub syllabuswrapper {
1.109 matthew 1862: my ($linktext,$coursedir,$domain,$fontcolor)=@_;
1863: if ($fontcolor) {
1864: $linktext='<font color="'.$fontcolor.'">'.$linktext.'</font>';
1865: }
1.208 matthew 1866: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 1867: }
1.14 harris41 1868:
1.208 matthew 1869: sub track_student_link {
1870: my ($linktext,$sname,$sdom,$target) = @_;
1871: my $link ="/adm/trackstudent";
1872: my $title = 'View recent activity';
1873: if (defined($sname) && $sname !~ /^\s*$/ &&
1874: defined($sdom) && $sdom !~ /^\s*$/) {
1875: $link .= "?selected_student=$sname:$sdom";
1876: $title .= ' of this student';
1877: }
1878: if (defined($target) && $target !~ /^\s*$/) {
1879: $target = qq{target="$target"};
1880: } else {
1881: $target = '';
1882: }
1883: return qq{<a href="$link" title="$title" $target>$linktext</a>};
1884: }
1885:
1886:
1887:
1.112 bowersj2 1888: =pod
1889:
1890: =back
1891:
1892: =head1 Access .tab File Data
1893:
1894: =over 4
1895:
1896: =item * languageids()
1897:
1898: returns list of all language ids
1899:
1900: =cut
1901:
1.14 harris41 1902: sub languageids {
1.16 harris41 1903: return sort(keys(%language));
1.14 harris41 1904: }
1905:
1.112 bowersj2 1906: =pod
1907:
1908: =item * languagedescription()
1909:
1910: returns description of a specified language id
1911:
1912: =cut
1913:
1.14 harris41 1914: sub languagedescription {
1.125 www 1915: my $code=shift;
1916: return ($supported_language{$code}?'* ':'').
1917: $language{$code}.
1.126 www 1918: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 1919: }
1920:
1921: sub plainlanguagedescription {
1922: my $code=shift;
1923: return $language{$code};
1924: }
1925:
1926: sub supportedlanguagecode {
1927: my $code=shift;
1928: return $supported_language{$code};
1.97 www 1929: }
1930:
1.112 bowersj2 1931: =pod
1932:
1933: =item * copyrightids()
1934:
1935: returns list of all copyrights
1936:
1937: =cut
1938:
1939: sub copyrightids {
1940: return sort(keys(%cprtag));
1941: }
1942:
1943: =pod
1944:
1945: =item * copyrightdescription()
1946:
1947: returns description of a specified copyright id
1948:
1949: =cut
1950:
1951: sub copyrightdescription {
1.166 www 1952: return &mt($cprtag{shift(@_)});
1.112 bowersj2 1953: }
1.197 matthew 1954:
1955: =pod
1956:
1.192 taceyjo1 1957: =item * source_copyrightids()
1958:
1959: returns list of all source copyrights
1960:
1961: =cut
1962:
1963: sub source_copyrightids {
1964: return sort(keys(%scprtag));
1965: }
1966:
1967: =pod
1968:
1969: =item * source_copyrightdescription()
1970:
1971: returns description of a specified source copyright id
1972:
1973: =cut
1974:
1975: sub source_copyrightdescription {
1976: return &mt($scprtag{shift(@_)});
1977: }
1.112 bowersj2 1978:
1979: =pod
1980:
1981: =item * filecategories()
1982:
1983: returns list of all file categories
1984:
1985: =cut
1986:
1987: sub filecategories {
1988: return sort(keys(%category_extensions));
1989: }
1990:
1991: =pod
1992:
1993: =item * filecategorytypes()
1994:
1995: returns list of file types belonging to a given file
1996: category
1997:
1998: =cut
1999:
2000: sub filecategorytypes {
2001: return @{$category_extensions{lc($_[0])}};
2002: }
2003:
2004: =pod
2005:
2006: =item * fileembstyle()
2007:
2008: returns embedding style for a specified file type
2009:
2010: =cut
2011:
2012: sub fileembstyle {
2013: return $fe{lc(shift(@_))};
1.169 www 2014: }
2015:
2016:
2017: sub filecategoryselect {
2018: my ($name,$value)=@_;
1.189 matthew 2019: return &select_form($value,$name,
1.169 www 2020: '' => &mt('Any category'),
2021: map { $_,$_ } sort(keys(%category_extensions)));
1.112 bowersj2 2022: }
2023:
2024: =pod
2025:
2026: =item * filedescription()
2027:
2028: returns description for a specified file type
2029:
2030: =cut
2031:
2032: sub filedescription {
1.188 matthew 2033: my $file_description = $fd{lc(shift())};
2034: $file_description =~ s:([\[\]]):~$1:g;
2035: return &mt($file_description);
1.112 bowersj2 2036: }
2037:
2038: =pod
2039:
2040: =item * filedescriptionex()
2041:
2042: returns description for a specified file type with
2043: extra formatting
2044:
2045: =cut
2046:
2047: sub filedescriptionex {
2048: my $ex=shift;
1.188 matthew 2049: my $file_description = $fd{lc($ex)};
2050: $file_description =~ s:([\[\]]):~$1:g;
2051: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 2052: }
2053:
2054: # End of .tab access
2055: =pod
2056:
2057: =back
2058:
2059: =cut
2060:
2061: # ------------------------------------------------------------------ File Types
2062: sub fileextensions {
2063: return sort(keys(%fe));
2064: }
2065:
1.97 www 2066: # ----------------------------------------------------------- Display Languages
2067: # returns a hash with all desired display languages
2068: #
2069:
2070: sub display_languages {
2071: my %languages=();
1.118 www 2072: foreach (&preferred_languages()) {
2073: $languages{$_}=1;
1.97 www 2074: }
2075: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
2076: if ($ENV{'form.displaylanguage'}) {
2077: foreach (split(/\s*(\,|\;|\:)\s*/,$ENV{'form.displaylanguage'})) {
2078: $languages{$_}=1;
2079: }
2080: }
2081: return %languages;
1.14 harris41 2082: }
2083:
1.117 www 2084: sub preferred_languages {
2085: my @languages=();
2086: if ($ENV{'course.'.$ENV{'request.course.id'}.'.languages'}) {
2087: @languages=(@languages,split(/\s*(\,|\;|\:)\s*/,
2088: $ENV{'course.'.$ENV{'request.course.id'}.'.languages'}));
1.177 www 2089: }
2090: if ($ENV{'environment.languages'}) {
2091: @languages=split(/\s*(\,|\;|\:)\s*/,$ENV{'environment.languages'});
1.118 www 2092: }
1.162 www 2093: my $browser=(split(/\;/,$ENV{'HTTP_ACCEPT_LANGUAGE'}))[0];
2094: if ($browser) {
2095: @languages=(@languages,split(/\s*(\,|\;|\:)\s*/,$browser));
2096: }
1.118 www 2097: if ($Apache::lonnet::domain_lang_def{$ENV{'user.domain'}}) {
2098: @languages=(@languages,
2099: $Apache::lonnet::domain_lang_def{$ENV{'user.domain'}});
2100: }
2101: if ($Apache::lonnet::domain_lang_def{$ENV{'request.role.domain'}}) {
2102: @languages=(@languages,
2103: $Apache::lonnet::domain_lang_def{$ENV{'request.role.domain'}});
2104: }
2105: if ($Apache::lonnet::domain_lang_def{
2106: $Apache::lonnet::perlvar{'lonDefDomain'}}) {
2107: @languages=(@languages,
2108: $Apache::lonnet::domain_lang_def{
2109: $Apache::lonnet::perlvar{'lonDefDomain'}});
2110: }
2111: # turn "en-ca" into "en-ca,en"
2112: my @genlanguages;
2113: foreach (@languages) {
2114: unless ($_=~/\w/) { next; }
2115: push (@genlanguages,$_);
2116: if ($_=~/(\-|\_)/) {
2117: push (@genlanguages,(split(/(\-|\_)/,$_))[0]);
2118: }
2119: }
2120: return @genlanguages;
1.117 www 2121: }
2122:
1.112 bowersj2 2123: ###############################################################
2124: ## Student Answer Attempts ##
2125: ###############################################################
2126:
2127: =pod
2128:
2129: =head1 Alternate Problem Views
2130:
2131: =over 4
2132:
2133: =item * get_previous_attempt($symb, $username, $domain, $course,
2134: $getattempt, $regexp, $gradesub)
2135:
2136: Return string with previous attempt on problem. Arguments:
2137:
2138: =over 4
2139:
2140: =item * $symb: Problem, including path
2141:
2142: =item * $username: username of the desired student
2143:
2144: =item * $domain: domain of the desired student
1.14 harris41 2145:
1.112 bowersj2 2146: =item * $course: Course ID
1.14 harris41 2147:
1.112 bowersj2 2148: =item * $getattempt: Leave blank for all attempts, otherwise put
2149: something
1.14 harris41 2150:
1.112 bowersj2 2151: =item * $regexp: if string matches this regexp, the string will be
2152: sent to $gradesub
1.14 harris41 2153:
1.112 bowersj2 2154: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 2155:
1.112 bowersj2 2156: =back
1.14 harris41 2157:
1.112 bowersj2 2158: The output string is a table containing all desired attempts, if any.
1.16 harris41 2159:
1.112 bowersj2 2160: =cut
1.1 albertel 2161:
2162: sub get_previous_attempt {
1.43 ng 2163: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 2164: my $prevattempts='';
1.43 ng 2165: no strict 'refs';
1.1 albertel 2166: if ($symb) {
1.3 albertel 2167: my (%returnhash)=
2168: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 2169: if ($returnhash{'version'}) {
2170: my %lasthash=();
2171: my $version;
2172: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.19 harris41 2173: foreach (sort(split(/\:/,$returnhash{$version.':keys'}))) {
1.1 albertel 2174: $lasthash{$_}=$returnhash{$version.':'.$_};
1.19 harris41 2175: }
1.1 albertel 2176: }
1.43 ng 2177: $prevattempts='<table border="0" width="100%"><tr><td bgcolor="#777777">';
1.40 ng 2178: $prevattempts.='<table border="0" width="100%"><tr bgcolor="#e6ffff"><td>History</td>';
1.16 harris41 2179: foreach (sort(keys %lasthash)) {
1.31 albertel 2180: my ($ign,@parts) = split(/\./,$_);
1.41 ng 2181: if ($#parts > 0) {
1.31 albertel 2182: my $data=$parts[-1];
2183: pop(@parts);
1.40 ng 2184: $prevattempts.='<td>Part '.join('.',@parts).'<br />'.$data.' </td>';
1.31 albertel 2185: } else {
1.41 ng 2186: if ($#parts == 0) {
2187: $prevattempts.='<th>'.$parts[0].'</th>';
2188: } else {
2189: $prevattempts.='<th>'.$ign.'</th>';
2190: }
1.31 albertel 2191: }
1.16 harris41 2192: }
1.40 ng 2193: if ($getattempt eq '') {
2194: for ($version=1;$version<=$returnhash{'version'};$version++) {
2195: $prevattempts.='</tr><tr bgcolor="#ffffe6"><td>Transaction '.$version.'</td>';
2196: foreach (sort(keys %lasthash)) {
2197: my $value;
2198: if ($_ =~ /timestamp/) {
2199: $value=scalar(localtime($returnhash{$version.':'.$_}));
2200: } else {
2201: $value=$returnhash{$version.':'.$_};
2202: }
1.142 albertel 2203: $prevattempts.='<td>'.&Apache::lonnet::unescape($value).' </td>';
1.40 ng 2204: }
2205: }
1.1 albertel 2206: }
1.40 ng 2207: $prevattempts.='</tr><tr bgcolor="#ffffe6"><td>Current</td>';
1.16 harris41 2208: foreach (sort(keys %lasthash)) {
1.5 albertel 2209: my $value;
2210: if ($_ =~ /timestamp/) {
2211: $value=scalar(localtime($lasthash{$_}));
2212: } else {
2213: $value=$lasthash{$_};
2214: }
1.142 albertel 2215: $value=&Apache::lonnet::unescape($value);
1.49 ng 2216: if ($_ =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
1.40 ng 2217: $prevattempts.='<td>'.$value.' </td>';
1.16 harris41 2218: }
1.40 ng 2219: $prevattempts.='</tr></table></td></tr></table>';
1.1 albertel 2220: } else {
2221: $prevattempts='Nothing submitted - no attempts.';
2222: }
2223: } else {
2224: $prevattempts='No data.';
2225: }
1.10 albertel 2226: }
2227:
1.107 albertel 2228: sub relative_to_absolute {
2229: my ($url,$output)=@_;
2230: my $parser=HTML::TokeParser->new(\$output);
2231: my $token;
2232: my $thisdir=$url;
2233: my @rlinks=();
2234: while ($token=$parser->get_token) {
2235: if ($token->[0] eq 'S') {
2236: if ($token->[1] eq 'a') {
2237: if ($token->[2]->{'href'}) {
2238: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
2239: }
2240: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
2241: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
2242: } elsif ($token->[1] eq 'base') {
2243: $thisdir=$token->[2]->{'href'};
2244: }
2245: }
2246: }
2247: $thisdir=~s-/[^/]*$--;
2248: foreach (@rlinks) {
2249: unless (($_=~/^http:\/\//i) ||
2250: ($_=~/^\//) ||
2251: ($_=~/^javascript:/i) ||
2252: ($_=~/^mailto:/i) ||
2253: ($_=~/^\#/)) {
2254: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$_);
2255: $output=~s/(\"|\'|\=\s*)$_(\"|\'|\s|\>)/$1$newlocation$2/;
2256: }
2257: }
2258: # -------------------------------------------------- Deal with Applet codebases
2259: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
2260: return $output;
2261: }
2262:
1.112 bowersj2 2263: =pod
2264:
2265: =item * get_student_view
2266:
2267: show a snapshot of what student was looking at
2268:
2269: =cut
2270:
1.10 albertel 2271: sub get_student_view {
1.186 albertel 2272: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 2273: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 2274: my (%form);
1.10 albertel 2275: my @elements=('symb','courseid','domain','username');
2276: foreach my $element (@elements) {
1.186 albertel 2277: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 2278: }
1.186 albertel 2279: if (defined($moreenv)) {
2280: %form=(%form,%{$moreenv});
2281: }
2282: if ($target eq 'tex') {$form{'grade_target'} = 'tex';}
1.107 albertel 2283: $feedurl=&Apache::lonnet::clutter($feedurl);
1.186 albertel 2284: my $userview=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 2285: $userview=~s/\<body[^\>]*\>//gi;
2286: $userview=~s/\<\/body\>//gi;
2287: $userview=~s/\<html\>//gi;
2288: $userview=~s/\<\/html\>//gi;
2289: $userview=~s/\<head\>//gi;
2290: $userview=~s/\<\/head\>//gi;
2291: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 2292: $userview=&relative_to_absolute($feedurl,$userview);
1.11 albertel 2293: return $userview;
2294: }
2295:
1.112 bowersj2 2296: =pod
2297:
2298: =item * get_student_answers()
2299:
2300: show a snapshot of how student was answering problem
2301:
2302: =cut
2303:
1.11 albertel 2304: sub get_student_answers {
1.100 sakharuk 2305: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 2306: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 2307: my (%moreenv);
1.11 albertel 2308: my @elements=('symb','courseid','domain','username');
2309: foreach my $element (@elements) {
1.186 albertel 2310: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 2311: }
1.186 albertel 2312: $moreenv{'grade_target'}='answer';
2313: %moreenv=(%form,%moreenv);
2314: my $userview=&Apache::lonnet::ssi('/res/'.$feedurl,%moreenv);
1.10 albertel 2315: return $userview;
1.1 albertel 2316: }
1.116 albertel 2317:
2318: =pod
2319:
2320: =item * &submlink()
2321:
2322: Inputs: $text $uname $udom $symb
2323:
2324: Returns: A link to grades.pm such as to see the SUBM view of a student
2325:
2326: =cut
2327:
2328: ###############################################
2329: sub submlink {
2330: my ($text,$uname,$udom,$symb)=@_;
2331: if (!($uname && $udom)) {
2332: (my $cursymb, my $courseid,$udom,$uname)=
2333: &Apache::lonxml::whichuser($symb);
2334: if (!$symb) { $symb=$cursymb; }
2335: }
2336: if (!$symb) { $symb=&symbread(); }
2337: return '<a href="/adm/grades?symb='.$symb.'&student='.$uname.
2338: '&userdom='.$udom.'&command=submission">'.$text.'</a>';
2339: }
2340: ##############################################
1.37 matthew 2341:
1.112 bowersj2 2342: =pod
2343:
2344: =back
2345:
2346: =cut
2347:
1.37 matthew 2348: ###############################################
1.51 www 2349:
2350:
2351: sub timehash {
2352: my @ltime=localtime(shift);
2353: return ( 'seconds' => $ltime[0],
2354: 'minutes' => $ltime[1],
2355: 'hours' => $ltime[2],
2356: 'day' => $ltime[3],
2357: 'month' => $ltime[4]+1,
2358: 'year' => $ltime[5]+1900,
2359: 'weekday' => $ltime[6],
2360: 'dayyear' => $ltime[7]+1,
2361: 'dlsav' => $ltime[8] );
2362: }
2363:
2364: sub maketime {
2365: my %th=@_;
2366: return POSIX::mktime(
2367: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 2368: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 2369: }
2370:
2371: #########################################
1.51 www 2372:
2373: sub findallcourses {
2374: my %courses=();
2375: my $now=time;
2376: foreach (keys %ENV) {
2377: if ($_=~/^user\.role\.\w+\.\/(\w+)\/(\w+)/) {
2378: my ($starttime,$endtime)=$ENV{$_};
2379: my $active=1;
2380: if ($starttime) {
2381: if ($now<$starttime) { $active=0; }
2382: }
2383: if ($endtime) {
2384: if ($now>$endtime) { $active=0; }
2385: }
2386: if ($active) { $courses{$1.'_'.$2}=1; }
2387: }
2388: }
2389: return keys %courses;
2390: }
1.37 matthew 2391:
1.54 www 2392: ###############################################
1.60 matthew 2393: ###############################################
2394:
2395: =pod
2396:
1.112 bowersj2 2397: =head1 Domain Template Functions
2398:
2399: =over 4
2400:
2401: =item * &determinedomain()
1.60 matthew 2402:
2403: Inputs: $domain (usually will be undef)
2404:
1.63 www 2405: Returns: Determines which domain should be used for designs
1.60 matthew 2406:
2407: =cut
1.54 www 2408:
1.60 matthew 2409: ###############################################
1.63 www 2410: sub determinedomain {
2411: my $domain=shift;
2412: if (! $domain) {
1.60 matthew 2413: # Determine domain if we have not been given one
2414: $domain = $Apache::lonnet::perlvar{'lonDefDomain'};
2415: if ($ENV{'user.domain'}) { $domain=$ENV{'user.domain'}; }
2416: if ($ENV{'request.role.domain'}) {
2417: $domain=$ENV{'request.role.domain'};
2418: }
2419: }
1.63 www 2420: return $domain;
2421: }
2422: ###############################################
2423: =pod
2424:
1.112 bowersj2 2425: =item * &domainlogo()
1.63 www 2426:
2427: Inputs: $domain (usually will be undef)
2428:
2429: Returns: A link to a domain logo, if the domain logo exists.
2430: If the domain logo does not exist, a description of the domain.
2431:
2432: =cut
1.112 bowersj2 2433:
1.63 www 2434: ###############################################
2435: sub domainlogo {
2436: my $domain = &determinedomain(shift);
2437: # See if there is a logo
1.59 www 2438: if (-e '/home/httpd/html/adm/lonDomLogos/'.$domain.'.gif') {
1.215 albertel 2439: my $logo=&lonhttpdurl("/adm/lonDomLogos/$domain.gif");
2440: return '<img src="'.$logo.'" alt="'.$domain.'" />';
1.60 matthew 2441: } elsif(exists($Apache::lonnet::domaindescription{$domain})) {
2442: return $Apache::lonnet::domaindescription{$domain};
1.59 www 2443: } else {
1.60 matthew 2444: return '';
1.59 www 2445: }
2446: }
1.63 www 2447: ##############################################
2448:
2449: =pod
2450:
1.112 bowersj2 2451: =item * &designparm()
1.63 www 2452:
2453: Inputs: $which parameter; $domain (usually will be undef)
2454:
2455: Returns: value of designparamter $which
2456:
2457: =cut
1.112 bowersj2 2458:
1.63 www 2459: ##############################################
2460: sub designparm {
2461: my ($which,$domain)=@_;
1.110 www 2462: if ($ENV{'browser.blackwhite'} eq 'on') {
2463: if ($which=~/\.(font|alink|vlink|link)$/) {
2464: return '#000000';
2465: }
2466: if ($which=~/\.(pgbg|sidebg)$/) {
2467: return '#FFFFFF';
2468: }
2469: if ($which=~/\.tabbg$/) {
2470: return '#CCCCCC';
2471: }
2472: }
1.96 www 2473: if ($ENV{'environment.color.'.$which}) {
2474: return $ENV{'environment.color.'.$which};
2475: }
1.63 www 2476: $domain=&determinedomain($domain);
2477: if ($designhash{$domain.'.'.$which}) {
2478: return $designhash{$domain.'.'.$which};
2479: } else {
2480: return $designhash{'default.'.$which};
2481: }
2482: }
1.59 www 2483:
1.60 matthew 2484: ###############################################
2485: ###############################################
2486:
2487: =pod
2488:
1.112 bowersj2 2489: =back
2490:
2491: =head1 HTTP Helpers
2492:
2493: =over 4
2494:
2495: =item * &bodytag()
1.60 matthew 2496:
2497: Returns a uniform header for LON-CAPA web pages.
2498:
2499: Inputs:
2500:
1.112 bowersj2 2501: =over 4
2502:
2503: =item * $title, A title to be displayed on the page.
2504:
2505: =item * $function, the current role (can be undef).
2506:
2507: =item * $addentries, extra parameters for the <body> tag.
2508:
2509: =item * $bodyonly, if defined, only return the <body> tag.
2510:
2511: =item * $domain, if defined, force a given domain.
2512:
2513: =item * $forcereg, if page should register as content page (relevant for
1.86 www 2514: text interface only)
1.60 matthew 2515:
1.112 bowersj2 2516: =back
2517:
1.60 matthew 2518: Returns: A uniform header for LON-CAPA web pages.
2519: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
2520: If $bodyonly is undef or zero, an html string containing a <body> tag and
2521: other decorations will be returned.
2522:
2523: =cut
2524:
1.54 www 2525: sub bodytag {
1.224 raeburn 2526: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,$customtitle)=@_;
1.117 www 2527: $title=&mt($title);
1.183 matthew 2528: $function = &get_users_function() if (!$function);
1.63 www 2529: my $img=&designparm($function.'.img',$domain);
2530: my $pgbg=&designparm($function.'.pgbg',$domain);
2531: my $tabbg=&designparm($function.'.tabbg',$domain);
2532: my $font=&designparm($function.'.font',$domain);
2533: my $link=&designparm($function.'.link',$domain);
2534: my $alink=&designparm($function.'.alink',$domain);
2535: my $vlink=&designparm($function.'.vlink',$domain);
2536: my $sidebg=&designparm($function.'.sidebg',$domain);
1.110 www 2537: # Accessibility font enhance
2538: unless ($addentries) { $addentries=''; }
1.146 www 2539: my $addstyle='';
1.110 www 2540: if ($ENV{'browser.fontenhance'} eq 'on') {
1.146 www 2541: $addstyle=' font-size: x-large;';
1.110 www 2542: }
1.63 www 2543: # role and realm
1.55 www 2544: my ($role,$realm)
2545: =&Apache::lonnet::plaintext((split(/\./,$ENV{'request.role'}))[0]);
2546: # realm
1.54 www 2547: if ($ENV{'request.course.id'}) {
1.55 www 2548: $realm=
2549: $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
1.54 www 2550: }
1.55 www 2551: unless ($realm) { $realm=' '; }
2552: # Set messages
1.60 matthew 2553: my $messages=&domainlogo($domain);
1.101 www 2554: # Port for miniserver
1.83 albertel 2555: my $lonhttpdPort=$Apache::lonnet::perlvar{'lonhttpdPort'};
2556: if (!defined($lonhttpdPort)) { $lonhttpdPort='8080'; }
1.101 www 2557: # construct main body tag
1.60 matthew 2558: my $bodytag = <<END;
1.146 www 2559: <style>
1.147 www 2560: h1, h2, h3, th { font-family: Arial, Helvetica, sans-serif }
1.146 www 2561: a:focus { color: red; background: yellow }
2562: </style>
1.54 www 2563: <body bgcolor="$pgbg" text="$font" alink="$alink" vlink="$vlink" link="$link"
1.151 www 2564: style="margin-top: 0px;$addstyle" $addentries>
1.60 matthew 2565: END
1.94 www 2566: my $upperleft='<img src="http://'.$ENV{'HTTP_HOST'}.':'.
1.150 matthew 2567: $lonhttpdPort.$img.'" alt="'.$function.'" />';
1.60 matthew 2568: if ($bodyonly) {
2569: return $bodytag;
1.79 www 2570: } elsif ($ENV{'browser.interface'} eq 'textual') {
1.95 www 2571: # Accessibility
1.224 raeburn 2572:
1.93 www 2573: return $bodytag.&Apache::lonmenu::menubuttons($forcereg,'web',
2574: $forcereg).
2575: '<h1>LON-CAPA: '.$title.'</h1>';
2576: } elsif ($ENV{'environment.remote'} eq 'off') {
1.95 www 2577: # No Remote
1.206 albertel 2578: my $roleinfo=(<<ENDROLE);
2579: <td bgcolor="$tabbg" align="right">
2580: <p>
2581: <font size="2" face="Arial, Helvetica, sans-serif">
2582: $ENV{'environment.firstname'}
2583: $ENV{'environment.middlename'}
2584: $ENV{'environment.lastname'}
2585: $ENV{'environment.generation'}
2586: </font>
2587: <br />
2588: <font size="2" face="Arial, Helvetica, sans-serif">$role</font>
2589: <br />
2590: <font size="2" face="Arial, Helvetica, sans-serif">$realm</font>
2591: </p>
2592: </td>
2593: ENDROLE
1.224 raeburn 2594: my $titleinfo = '<font face="Arial, Helvetica, sans-serif" size="+3" color="'.
2595: $font.'"><b>'.$title.'</b></font>';
2596: if ($customtitle) {
2597: $titleinfo = $customtitle;
2598: }
1.95 www 2599: return $bodytag.&Apache::lonmenu::menubuttons($forcereg,'web',
2600: $forcereg).
1.224 raeburn 2601: '<table bgcolor="'.$pgbg.'" width="100%" border="0" cellspacing="3" cellpadding="3"><tr><td rowspan="3" bgcolor="'.$tabbg.'">'.$titleinfo.'</td>'.$roleinfo.'</tr></table>';
1.94 www 2602: }
1.95 www 2603:
1.93 www 2604: #
1.95 www 2605: # Top frame rendering, Remote is up
1.93 www 2606: #
1.224 raeburn 2607: my $titleinfo = ' <font size="5" face="Arial, Helvetica, sans-serif"><b>'.$title.'</b></font>';
2608: if ($customtitle) {
2609: $titleinfo = $customtitle;
2610: }
1.94 www 2611: return(<<ENDBODY);
1.60 matthew 2612: $bodytag
1.55 www 2613: <table width="100%" cellspacing="0" border="0" cellpadding="0">
1.95 www 2614: <tr><td bgcolor="$sidebg">
1.94 www 2615: $upperleft</td>
1.95 www 2616: <td bgcolor="$sidebg" align="right">$messages </td>
1.55 www 2617: </tr>
1.54 www 2618: <tr>
1.55 www 2619: <td rowspan="3" bgcolor="$tabbg">
1.224 raeburn 2620: $titleinfo
1.146 www 2621: <td bgcolor="$tabbg" align="right">
2622: <font size="2" face="Arial, Helvetica, sans-serif">
1.54 www 2623: $ENV{'environment.firstname'}
2624: $ENV{'environment.middlename'}
2625: $ENV{'environment.lastname'}
2626: $ENV{'environment.generation'}
1.55 www 2627: </font>
1.54 www 2628: </td>
2629: </tr>
2630: <tr><td bgcolor="$tabbg" align="right">
1.146 www 2631: <font size="2" face="Arial, Helvetica, sans-serif">$role</font>
1.54 www 2632: </td></tr>
1.55 www 2633: <tr>
1.148 www 2634: <td bgcolor="$tabbg" align="right"><font size="2" face="Arial, Helvetica, sans-serif">$realm</font> </td></tr>
1.202 albertel 2635: </table><br />
1.54 www 2636: ENDBODY
1.182 matthew 2637: }
2638:
2639: ###############################################
2640:
2641: =pod
2642:
2643: =item get_users_function
2644:
2645: Used by &bodytag to determine the current users primary role.
2646: Returns either 'student','coordinator','admin', or 'author'.
2647:
2648: =cut
2649:
2650: ###############################################
2651: sub get_users_function {
2652: my $function = 'student';
2653: if ($ENV{'request.role'}=~/^(cc|in|ta|ep)/) {
2654: $function='coordinator';
2655: }
2656: if ($ENV{'request.role'}=~/^(su|dc|ad|li)/) {
2657: $function='admin';
2658: }
2659: if (($ENV{'request.role'}=~/^(au|ca)/) ||
2660: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
2661: $function='author';
2662: }
2663: return $function;
1.54 www 2664: }
1.99 www 2665:
2666: ###############################################
2667:
2668: sub get_posted_cgi {
2669: my $r=shift;
2670:
2671: my $buffer;
2672:
2673: $r->read($buffer,$r->header_in('Content-length'),0);
2674: unless ($buffer=~/^(\-+\w+)\s+Content\-Disposition\:\s*form\-data/si) {
2675: my @pairs=split(/&/,$buffer);
2676: my $pair;
2677: foreach $pair (@pairs) {
2678: my ($name,$value) = split(/=/,$pair);
2679: $value =~ tr/+/ /;
2680: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
2681: $name =~ tr/+/ /;
2682: $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
2683: &add_to_env("form.$name",$value);
2684: }
2685: } else {
2686: my $contentsep=$1;
2687: my @lines = split (/\n/,$buffer);
2688: my $name='';
2689: my $value='';
2690: my $fname='';
2691: my $fmime='';
2692: my $i;
2693: for ($i=0;$i<=$#lines;$i++) {
2694: if ($lines[$i]=~/^$contentsep/) {
2695: if ($name) {
2696: chomp($value);
2697: if ($fname) {
2698: $ENV{"form.$name.filename"}=$fname;
2699: $ENV{"form.$name.mimetype"}=$fmime;
2700: } else {
2701: $value=~s/\s+$//s;
2702: }
2703: &add_to_env("form.$name",$value);
2704: }
2705: if ($i<$#lines) {
2706: $i++;
2707: $lines[$i]=~
2708: /Content\-Disposition\:\s*form\-data\;\s*name\=\"([^\"]+)\"/i;
2709: $name=$1;
2710: $value='';
2711: if ($lines[$i]=~/filename\=\"([^\"]+)\"/i) {
2712: $fname=$1;
2713: if
2714: ($lines[$i+1]=~/Content\-Type\:\s*([\w\-\/]+)/i) {
2715: $fmime=$1;
2716: $i++;
2717: } else {
2718: $fmime='';
2719: }
2720: } else {
2721: $fname='';
2722: $fmime='';
2723: }
2724: $i++;
2725: }
2726: } else {
2727: $value.=$lines[$i]."\n";
2728: }
2729: }
2730: }
2731: $ENV{'request.method'}=$ENV{'REQUEST_METHOD'};
2732: $r->method_number(M_GET);
2733: $r->method('GET');
2734: $r->headers_in->unset('Content-length');
2735: }
2736:
1.112 bowersj2 2737: =pod
2738:
2739: =item * get_unprocessed_cgi($query,$possible_names)
2740:
2741: Modify the %ENV hash to contain unprocessed CGI form parameters held in
2742: $query. The parameters listed in $possible_names (an array reference),
2743: will be set in $ENV{'form.name'} if they do not already exist.
2744:
2745: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
2746: $possible_names is an ref to an array of form element names. As an example:
2747: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
2748: will result in $ENV{'form.uname'} and $ENV{'form.udom'} being set.
2749:
2750: =cut
1.1 albertel 2751:
1.6 albertel 2752: sub get_unprocessed_cgi {
1.25 albertel 2753: my ($query,$possible_names)= @_;
1.26 matthew 2754: # $Apache::lonxml::debug=1;
1.16 harris41 2755: foreach (split(/&/,$query)) {
1.6 albertel 2756: my ($name, $value) = split(/=/,$_);
1.25 albertel 2757: $name = &Apache::lonnet::unescape($name);
2758: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
2759: $value =~ tr/+/ /;
2760: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
2761: &Apache::lonxml::debug("Seting :$name: to :$value:");
1.30 albertel 2762: unless (defined($ENV{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 2763: }
1.16 harris41 2764: }
1.6 albertel 2765: }
2766:
1.112 bowersj2 2767: =pod
2768:
2769: =item * cacheheader()
2770:
2771: returns cache-controlling header code
2772:
2773: =cut
2774:
1.7 albertel 2775: sub cacheheader {
1.216 albertel 2776: unless ($ENV{'request.method'} eq 'GET') { return ''; }
2777: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
2778: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 2779: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
2780: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 2781: return $output;
1.7 albertel 2782: }
2783:
1.112 bowersj2 2784: =pod
2785:
2786: =item * no_cache($r)
2787:
2788: specifies header code to not have cache
2789:
2790: =cut
2791:
1.9 albertel 2792: sub no_cache {
1.216 albertel 2793: my ($r) = @_;
2794: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
2795: $ENV{'request.method'} ne 'GET') { return ''; }
2796: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
2797: $r->no_cache(1);
2798: $r->header_out("Expires" => $date);
2799: $r->header_out("Pragma" => "no-cache");
1.123 www 2800: }
2801:
2802: sub content_type {
1.181 albertel 2803: my ($r,$type,$charset) = @_;
2804: unless ($charset) {
2805: $charset=&Apache::lonlocal::current_encoding;
2806: }
2807: if ($charset) { $type.='; charset='.$charset; }
2808: if ($r) {
2809: $r->content_type($type);
2810: } else {
2811: print("Content-type: $type\n\n");
2812: }
1.9 albertel 2813: }
1.25 albertel 2814:
1.112 bowersj2 2815: =pod
2816:
2817: =item * add_to_env($name,$value)
2818:
2819: adds $name to the %ENV hash with value
2820: $value, if $name already exists, the entry is converted to an array
2821: reference and $value is added to the array.
2822:
2823: =cut
2824:
1.25 albertel 2825: sub add_to_env {
2826: my ($name,$value)=@_;
1.28 albertel 2827: if (defined($ENV{$name})) {
1.27 albertel 2828: if (ref($ENV{$name})) {
1.25 albertel 2829: #already have multiple values
2830: push(@{ $ENV{$name} },$value);
2831: } else {
2832: #first time seeing multiple values, convert hash entry to an arrayref
2833: my $first=$ENV{$name};
2834: undef($ENV{$name});
2835: push(@{ $ENV{$name} },$first,$value);
2836: }
2837: } else {
2838: $ENV{$name}=$value;
2839: }
1.31 albertel 2840: }
1.149 albertel 2841:
2842: =pod
2843:
2844: =item * get_env_multiple($name)
2845:
2846: gets $name from the %ENV hash, it seemlessly handles the cases where multiple
2847: values may be defined and end up as an array ref.
2848:
2849: returns an array of values
2850:
2851: =cut
2852:
2853: sub get_env_multiple {
2854: my ($name) = @_;
2855: my @values;
2856: if (defined($ENV{$name})) {
2857: # exists is it an array
2858: if (ref($ENV{$name})) {
2859: @values=@{ $ENV{$name} };
2860: } else {
2861: $values[0]=$ENV{$name};
2862: }
2863: }
2864: return(@values);
2865: }
2866:
1.31 albertel 2867:
1.41 ng 2868: =pod
1.45 matthew 2869:
2870: =back
1.41 ng 2871:
1.112 bowersj2 2872: =head1 CSV Upload/Handling functions
1.38 albertel 2873:
1.41 ng 2874: =over 4
2875:
1.112 bowersj2 2876: =item * upfile_store($r)
1.41 ng 2877:
2878: Store uploaded file, $r should be the HTTP Request object,
2879: needs $ENV{'form.upfile'}
2880: returns $datatoken to be put into hidden field
2881:
2882: =cut
1.31 albertel 2883:
2884: sub upfile_store {
2885: my $r=shift;
2886: $ENV{'form.upfile'}=~s/\r/\n/gs;
2887: $ENV{'form.upfile'}=~s/\f/\n/gs;
2888: $ENV{'form.upfile'}=~s/\n+/\n/gs;
2889: $ENV{'form.upfile'}=~s/\n+$//gs;
2890:
2891: my $datatoken=$ENV{'user.name'}.'_'.$ENV{'user.domain'}.
2892: '_enroll_'.$ENV{'request.course.id'}.'_'.time.'_'.$$;
2893: {
1.158 raeburn 2894: my $datafile = $r->dir_config('lonDaemons').
2895: '/tmp/'.$datatoken.'.tmp';
2896: if ( open(my $fh,">$datafile") ) {
2897: print $fh $ENV{'form.upfile'};
2898: close($fh);
2899: }
1.31 albertel 2900: }
2901: return $datatoken;
2902: }
2903:
1.56 matthew 2904: =pod
2905:
1.112 bowersj2 2906: =item * load_tmp_file($r)
1.41 ng 2907:
2908: Load uploaded file from tmp, $r should be the HTTP Request object,
2909: needs $ENV{'form.datatoken'},
2910: sets $ENV{'form.upfile'} to the contents of the file
2911:
2912: =cut
1.31 albertel 2913:
2914: sub load_tmp_file {
2915: my $r=shift;
2916: my @studentdata=();
2917: {
1.158 raeburn 2918: my $studentfile = $r->dir_config('lonDaemons').
2919: '/tmp/'.$ENV{'form.datatoken'}.'.tmp';
2920: if ( open(my $fh,"<$studentfile") ) {
2921: @studentdata=<$fh>;
2922: close($fh);
2923: }
1.31 albertel 2924: }
2925: $ENV{'form.upfile'}=join('',@studentdata);
2926: }
2927:
1.56 matthew 2928: =pod
2929:
1.112 bowersj2 2930: =item * upfile_record_sep()
1.41 ng 2931:
2932: Separate uploaded file into records
2933: returns array of records,
2934: needs $ENV{'form.upfile'} and $ENV{'form.upfiletype'}
2935:
2936: =cut
1.31 albertel 2937:
2938: sub upfile_record_sep {
2939: if ($ENV{'form.upfiletype'} eq 'xml') {
2940: } else {
2941: return split(/\n/,$ENV{'form.upfile'});
2942: }
2943: }
2944:
1.56 matthew 2945: =pod
2946:
1.112 bowersj2 2947: =item * record_sep($record)
1.41 ng 2948:
2949: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $ENV{'form.upfiletype'}
2950:
2951: =cut
2952:
1.31 albertel 2953: sub record_sep {
2954: my $record=shift;
2955: my %components=();
2956: if ($ENV{'form.upfiletype'} eq 'xml') {
2957: } elsif ($ENV{'form.upfiletype'} eq 'space') {
2958: my $i=0;
2959: foreach (split(/\s+/,$record)) {
2960: my $field=$_;
2961: $field=~s/^(\"|\')//;
2962: $field=~s/(\"|\')$//;
2963: $components{$i}=$field;
2964: $i++;
2965: }
2966: } elsif ($ENV{'form.upfiletype'} eq 'tab') {
2967: my $i=0;
1.171 matthew 2968: foreach (split(/\t/,$record)) {
1.31 albertel 2969: my $field=$_;
2970: $field=~s/^(\"|\')//;
2971: $field=~s/(\"|\')$//;
2972: $components{$i}=$field;
2973: $i++;
2974: }
2975: } else {
2976: my @allfields=split(/\,/,$record);
2977: my $i=0;
2978: my $j;
2979: for ($j=0;$j<=$#allfields;$j++) {
2980: my $field=$allfields[$j];
2981: if ($field=~/^\s*(\"|\')/) {
2982: my $delimiter=$1;
2983: while (($field!~/$delimiter$/) && ($j<$#allfields)) {
2984: $j++;
2985: $field.=','.$allfields[$j];
2986: }
2987: $field=~s/^\s*$delimiter//;
2988: $field=~s/$delimiter\s*$//;
2989: }
2990: $components{$i}=$field;
2991: $i++;
2992: }
2993: }
2994: return %components;
2995: }
2996:
1.144 matthew 2997: ######################################################
2998: ######################################################
2999:
1.56 matthew 3000: =pod
3001:
1.112 bowersj2 3002: =item * upfile_select_html()
1.41 ng 3003:
1.144 matthew 3004: Return HTML code to select a file from the users machine and specify
3005: the file type.
1.41 ng 3006:
3007: =cut
3008:
1.144 matthew 3009: ######################################################
3010: ######################################################
1.31 albertel 3011: sub upfile_select_html {
1.144 matthew 3012: my %Types = (
3013: csv => &mt('CSV (comma separated values, spreadsheet)'),
3014: space => &mt('Space separated'),
3015: tab => &mt('Tabulator separated'),
3016: # xml => &mt('HTML/XML'),
3017: );
3018: my $Str = '<input type="file" name="upfile" size="50" />'.
3019: '<br />Type: <select name="upfiletype">';
3020: foreach my $type (sort(keys(%Types))) {
3021: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
3022: }
3023: $Str .= "</select>\n";
3024: return $Str;
1.31 albertel 3025: }
3026:
1.144 matthew 3027: ######################################################
3028: ######################################################
3029:
1.56 matthew 3030: =pod
3031:
1.112 bowersj2 3032: =item * csv_print_samples($r,$records)
1.41 ng 3033:
3034: Prints a table of sample values from each column uploaded $r is an
3035: Apache Request ref, $records is an arrayref from
3036: &Apache::loncommon::upfile_record_sep
3037:
3038: =cut
3039:
1.144 matthew 3040: ######################################################
3041: ######################################################
1.31 albertel 3042: sub csv_print_samples {
3043: my ($r,$records) = @_;
3044: my (%sone,%stwo,%sthree);
3045: %sone=&record_sep($$records[0]);
3046: if (defined($$records[1])) {%stwo=&record_sep($$records[1]);}
3047: if (defined($$records[2])) {%sthree=&record_sep($$records[2]);}
1.144 matthew 3048: #
3049: $r->print(&mt('Samples').'<br /><table border="2"><tr>');
3050: foreach (sort({$a <=> $b} keys(%sone))) {
3051: $r->print('<th>'.&mt('Column [_1]',($_+1)).'</th>'); }
1.31 albertel 3052: $r->print('</tr>');
3053: foreach my $hash (\%sone,\%stwo,\%sthree) {
3054: $r->print('<tr>');
3055: foreach (sort({$a <=> $b} keys(%sone))) {
3056: $r->print('<td>');
3057: if (defined($$hash{$_})) { $r->print($$hash{$_}); }
3058: $r->print('</td>');
3059: }
3060: $r->print('</tr>');
3061: }
3062: $r->print('</tr></table><br />'."\n");
3063: }
3064:
1.144 matthew 3065: ######################################################
3066: ######################################################
3067:
1.56 matthew 3068: =pod
3069:
1.112 bowersj2 3070: =item * csv_print_select_table($r,$records,$d)
1.41 ng 3071:
3072: Prints a table to create associations between values and table columns.
1.144 matthew 3073:
1.41 ng 3074: $r is an Apache Request ref,
3075: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 3076: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 3077:
3078: =cut
3079:
1.144 matthew 3080: ######################################################
3081: ######################################################
1.31 albertel 3082: sub csv_print_select_table {
3083: my ($r,$records,$d) = @_;
3084: my $i=0;my %sone;
3085: %sone=&record_sep($$records[0]);
1.144 matthew 3086: $r->print(&mt('Associate columns with student attributes.')."\n".
3087: '<table border="2"><tr>'.
3088: '<th>'.&mt('Attribute').'</th>'.
3089: '<th>'.&mt('Column').'</th></tr>'."\n");
1.31 albertel 3090: foreach (@$d) {
1.174 matthew 3091: my ($value,$display,$defaultcol)=@{ $_ };
1.31 albertel 3092: $r->print('<tr><td>'.$display.'</td>');
3093:
3094: $r->print('<td><select name=f'.$i.
1.32 matthew 3095: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 3096: $r->print('<option value="none"></option>');
3097: foreach (sort({$a <=> $b} keys(%sone))) {
1.174 matthew 3098: $r->print('<option value="'.$_.'"'.
3099: ($_ eq $defaultcol ? ' selected ' : '').
3100: '>Column '.($_+1).'</option>');
1.31 albertel 3101: }
3102: $r->print('</select></td></tr>'."\n");
3103: $i++;
3104: }
3105: $i--;
3106: return $i;
3107: }
1.56 matthew 3108:
1.144 matthew 3109: ######################################################
3110: ######################################################
3111:
1.56 matthew 3112: =pod
1.31 albertel 3113:
1.112 bowersj2 3114: =item * csv_samples_select_table($r,$records,$d)
1.41 ng 3115:
3116: Prints a table of sample values from the upload and can make associate samples to internal names.
3117:
3118: $r is an Apache Request ref,
3119: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
3120: $d is an array of 2 element arrays (internal name, displayed name)
3121:
3122: =cut
3123:
1.144 matthew 3124: ######################################################
3125: ######################################################
1.31 albertel 3126: sub csv_samples_select_table {
3127: my ($r,$records,$d) = @_;
3128: my %sone; my %stwo; my %sthree;
3129: my $i=0;
1.144 matthew 3130: #
3131: $r->print('<table border=2><tr><th>'.
3132: &mt('Field').'</th><th>'.&mt('Samples').'</th></tr>');
1.31 albertel 3133: %sone=&record_sep($$records[0]);
3134: if (defined($$records[1])) {%stwo=&record_sep($$records[1]);}
3135: if (defined($$records[2])) {%sthree=&record_sep($$records[2]);}
1.144 matthew 3136: #
1.31 albertel 3137: foreach (sort keys %sone) {
1.144 matthew 3138: $r->print('<tr><td><select name="f'.$i.'"'.
1.32 matthew 3139: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 3140: foreach (@$d) {
1.174 matthew 3141: my ($value,$display,$defaultcol)=@{ $_ };
3142: $r->print('<option value="'.$value.'"'.
3143: ($i eq $defaultcol ? ' selected ':'').'>'.
3144: $display.'</option>');
1.31 albertel 3145: }
3146: $r->print('</select></td><td>');
3147: if (defined($sone{$_})) { $r->print($sone{$_}."</br>\n"); }
3148: if (defined($stwo{$_})) { $r->print($stwo{$_}."</br>\n"); }
3149: if (defined($sthree{$_})) { $r->print($sthree{$_}."</br>\n"); }
3150: $r->print('</td></tr>');
3151: $i++;
3152: }
3153: $i--;
3154: return($i);
1.115 matthew 3155: }
3156:
1.144 matthew 3157: ######################################################
3158: ######################################################
3159:
1.115 matthew 3160: =pod
3161:
3162: =item clean_excel_name($name)
3163:
3164: Returns a replacement for $name which does not contain any illegal characters.
3165:
3166: =cut
3167:
1.144 matthew 3168: ######################################################
3169: ######################################################
1.115 matthew 3170: sub clean_excel_name {
3171: my ($name) = @_;
3172: $name =~ s/[:\*\?\/\\]//g;
3173: if (length($name) > 31) {
3174: $name = substr($name,0,31);
3175: }
3176: return $name;
1.25 albertel 3177: }
1.84 albertel 3178:
1.85 albertel 3179: =pod
3180:
1.112 bowersj2 3181: =item * check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 3182:
3183: Returns either 1 or undef
3184:
3185: 1 if the part is to be hidden, undef if it is to be shown
3186:
3187: Arguments are:
3188:
3189: $id the id of the part to be checked
3190: $symb, optional the symb of the resource to check
3191: $udom, optional the domain of the user to check for
3192: $uname, optional the username of the user to check for
3193:
3194: =cut
1.84 albertel 3195:
3196: sub check_if_partid_hidden {
3197: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 3198: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 3199: $symb,$udom,$uname);
1.141 albertel 3200: my $truth=1;
3201: #if the string starts with !, then the list is the list to show not hide
3202: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 3203: my @hiddenlist=split(/,/,$hiddenparts);
3204: foreach my $checkid (@hiddenlist) {
1.141 albertel 3205: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 3206: }
1.141 albertel 3207: return !$truth;
1.84 albertel 3208: }
1.127 matthew 3209:
1.138 matthew 3210:
3211: ############################################################
3212: ############################################################
3213:
3214: =pod
3215:
1.157 matthew 3216: =back
3217:
1.138 matthew 3218: =head1 cgi-bin script and graphing routines
3219:
1.157 matthew 3220: =over 4
3221:
1.138 matthew 3222: =item get_cgi_id
3223:
3224: Inputs: none
3225:
3226: Returns an id which can be used to pass environment variables
3227: to various cgi-bin scripts. These environment variables will
3228: be removed from the users environment after a given time by
3229: the routine &Apache::lonnet::transfer_profile_to_env.
3230:
3231: =cut
3232:
3233: ############################################################
3234: ############################################################
1.152 albertel 3235: my $uniq=0;
1.136 matthew 3236: sub get_cgi_id {
1.154 albertel 3237: $uniq=($uniq+1)%100000;
1.152 albertel 3238: return (time.'_'.$uniq);
1.136 matthew 3239: }
3240:
1.127 matthew 3241: ############################################################
3242: ############################################################
3243:
3244: =pod
3245:
1.134 matthew 3246: =item DrawBarGraph
1.127 matthew 3247:
1.138 matthew 3248: Facilitates the plotting of data in a (stacked) bar graph.
3249: Puts plot definition data into the users environment in order for
3250: graph.png to plot it. Returns an <img> tag for the plot.
3251: The bars on the plot are labeled '1','2',...,'n'.
3252:
3253: Inputs:
3254:
3255: =over 4
3256:
3257: =item $Title: string, the title of the plot
3258:
3259: =item $xlabel: string, text describing the X-axis of the plot
3260:
3261: =item $ylabel: string, text describing the Y-axis of the plot
3262:
3263: =item $Max: scalar, the maximum Y value to use in the plot
3264: If $Max is < any data point, the graph will not be rendered.
3265:
1.140 matthew 3266: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 3267: they are plotted. If undefined, default values will be used.
3268:
1.178 matthew 3269: =item $labels: array ref holding the labels to use on the x-axis for the bars.
3270:
1.138 matthew 3271: =item @Values: An array of array references. Each array reference holds data
3272: to be plotted in a stacked bar chart.
3273:
3274: =back
3275:
3276: Returns:
3277:
3278: An <img> tag which references graph.png and the appropriate identifying
3279: information for the plot.
3280:
1.127 matthew 3281: =cut
3282:
3283: ############################################################
3284: ############################################################
1.134 matthew 3285: sub DrawBarGraph {
1.178 matthew 3286: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 3287: #
3288: if (! defined($colors)) {
3289: $colors = ['#33ff00',
3290: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
3291: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
3292: ];
3293: }
1.228 ! matthew 3294: my $extra_settings = {};
! 3295: if (ref($Values[-1]) eq 'HASH') {
! 3296: $extra_settings = pop(@Values);
! 3297: }
1.127 matthew 3298: #
1.136 matthew 3299: my $identifier = &get_cgi_id();
3300: my $id = 'cgi.'.$identifier;
1.129 matthew 3301: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 3302: return '';
3303: }
1.225 matthew 3304: #
3305: my @Labels;
3306: if (defined($labels)) {
3307: @Labels = @$labels;
3308: } else {
3309: for (my $i=0;$i<@{$Values[0]};$i++) {
3310: push (@Labels,$i+1);
3311: }
3312: }
3313: #
1.129 matthew 3314: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 3315: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 3316: my %ValuesHash;
3317: my $NumSets=1;
3318: foreach my $array (@Values) {
3319: next if (! ref($array));
1.136 matthew 3320: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 3321: join(',',@$array);
1.129 matthew 3322: }
1.127 matthew 3323: #
1.136 matthew 3324: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 3325: if ($NumBars < 3) {
3326: $width = 120+$NumBars*32;
1.220 matthew 3327: $xskip = 1;
1.225 matthew 3328: $bar_width = 30;
3329: } elsif ($NumBars < 5) {
3330: $width = 120+$NumBars*20;
3331: $xskip = 1;
3332: $bar_width = 20;
1.220 matthew 3333: } elsif ($NumBars < 10) {
1.136 matthew 3334: $width = 120+$NumBars*15;
3335: $xskip = 1;
3336: $bar_width = 15;
3337: } elsif ($NumBars <= 25) {
3338: $width = 120+$NumBars*11;
3339: $xskip = 5;
3340: $bar_width = 8;
3341: } elsif ($NumBars <= 50) {
3342: $width = 120+$NumBars*8;
3343: $xskip = 5;
3344: $bar_width = 4;
3345: } else {
3346: $width = 120+$NumBars*8;
3347: $xskip = 5;
3348: $bar_width = 4;
3349: }
3350: #
1.137 matthew 3351: $Max = 1 if ($Max < 1);
3352: if ( int($Max) < $Max ) {
3353: $Max++;
3354: $Max = int($Max);
3355: }
1.127 matthew 3356: $Title = '' if (! defined($Title));
3357: $xlabel = '' if (! defined($xlabel));
3358: $ylabel = '' if (! defined($ylabel));
1.136 matthew 3359: $ValuesHash{$id.'.title'} = &Apache::lonnet::escape($Title);
3360: $ValuesHash{$id.'.xlabel'} = &Apache::lonnet::escape($xlabel);
3361: $ValuesHash{$id.'.ylabel'} = &Apache::lonnet::escape($ylabel);
1.137 matthew 3362: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 3363: $ValuesHash{$id.'.NumBars'} = $NumBars;
3364: $ValuesHash{$id.'.NumSets'} = $NumSets;
3365: $ValuesHash{$id.'.PlotType'} = 'bar';
3366: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
3367: $ValuesHash{$id.'.height'} = $height;
3368: $ValuesHash{$id.'.width'} = $width;
3369: $ValuesHash{$id.'.xskip'} = $xskip;
3370: $ValuesHash{$id.'.bar_width'} = $bar_width;
3371: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 3372: #
1.228 ! matthew 3373: # Deal with other parameters
! 3374: while (my ($key,$value) = each(%$extra_settings)) {
! 3375: $ValuesHash{$id.'.'.$key} = $value;
! 3376: }
! 3377: #
1.137 matthew 3378: &Apache::lonnet::appenv(%ValuesHash);
3379: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
3380: }
3381:
3382: ############################################################
3383: ############################################################
3384:
3385: =pod
3386:
3387: =item DrawXYGraph
3388:
1.138 matthew 3389: Facilitates the plotting of data in an XY graph.
3390: Puts plot definition data into the users environment in order for
3391: graph.png to plot it. Returns an <img> tag for the plot.
3392:
3393: Inputs:
3394:
3395: =over 4
3396:
3397: =item $Title: string, the title of the plot
3398:
3399: =item $xlabel: string, text describing the X-axis of the plot
3400:
3401: =item $ylabel: string, text describing the Y-axis of the plot
3402:
3403: =item $Max: scalar, the maximum Y value to use in the plot
3404: If $Max is < any data point, the graph will not be rendered.
3405:
3406: =item $colors: Array ref containing the hex color codes for the data to be
3407: plotted in. If undefined, default values will be used.
3408:
3409: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
3410:
3411: =item $Ydata: Array ref containing Array refs.
1.185 www 3412: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 3413:
3414: =item %Values: hash indicating or overriding any default values which are
3415: passed to graph.png.
3416: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
3417:
3418: =back
3419:
3420: Returns:
3421:
3422: An <img> tag which references graph.png and the appropriate identifying
3423: information for the plot.
3424:
1.137 matthew 3425: =cut
3426:
3427: ############################################################
3428: ############################################################
3429: sub DrawXYGraph {
3430: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
3431: #
3432: # Create the identifier for the graph
3433: my $identifier = &get_cgi_id();
3434: my $id = 'cgi.'.$identifier;
3435: #
3436: $Title = '' if (! defined($Title));
3437: $xlabel = '' if (! defined($xlabel));
3438: $ylabel = '' if (! defined($ylabel));
3439: my %ValuesHash =
3440: (
3441: $id.'.title' => &Apache::lonnet::escape($Title),
3442: $id.'.xlabel' => &Apache::lonnet::escape($xlabel),
3443: $id.'.ylabel' => &Apache::lonnet::escape($ylabel),
3444: $id.'.y_max_value'=> $Max,
3445: $id.'.labels' => join(',',@$Xlabels),
3446: $id.'.PlotType' => 'XY',
3447: );
3448: #
3449: if (defined($colors) && ref($colors) eq 'ARRAY') {
3450: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
3451: }
3452: #
3453: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
3454: return '';
3455: }
3456: my $NumSets=1;
1.138 matthew 3457: foreach my $array (@{$Ydata}){
1.137 matthew 3458: next if (! ref($array));
3459: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
3460: }
1.138 matthew 3461: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 3462: #
3463: # Deal with other parameters
3464: while (my ($key,$value) = each(%Values)) {
3465: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 3466: }
3467: #
1.136 matthew 3468: &Apache::lonnet::appenv(%ValuesHash);
3469: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
3470: }
3471:
3472: ############################################################
3473: ############################################################
3474:
3475: =pod
3476:
1.138 matthew 3477: =item DrawXYYGraph
3478:
3479: Facilitates the plotting of data in an XY graph with two Y axes.
3480: Puts plot definition data into the users environment in order for
3481: graph.png to plot it. Returns an <img> tag for the plot.
3482:
3483: Inputs:
3484:
3485: =over 4
3486:
3487: =item $Title: string, the title of the plot
3488:
3489: =item $xlabel: string, text describing the X-axis of the plot
3490:
3491: =item $ylabel: string, text describing the Y-axis of the plot
3492:
3493: =item $colors: Array ref containing the hex color codes for the data to be
3494: plotted in. If undefined, default values will be used.
3495:
3496: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
3497:
3498: =item $Ydata1: The first data set
3499:
3500: =item $Min1: The minimum value of the left Y-axis
3501:
3502: =item $Max1: The maximum value of the left Y-axis
3503:
3504: =item $Ydata2: The second data set
3505:
3506: =item $Min2: The minimum value of the right Y-axis
3507:
3508: =item $Max2: The maximum value of the left Y-axis
3509:
3510: =item %Values: hash indicating or overriding any default values which are
3511: passed to graph.png.
3512: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
3513:
3514: =back
3515:
3516: Returns:
3517:
3518: An <img> tag which references graph.png and the appropriate identifying
3519: information for the plot.
1.136 matthew 3520:
3521: =cut
3522:
3523: ############################################################
3524: ############################################################
1.137 matthew 3525: sub DrawXYYGraph {
3526: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
3527: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 3528: #
3529: # Create the identifier for the graph
3530: my $identifier = &get_cgi_id();
3531: my $id = 'cgi.'.$identifier;
3532: #
3533: $Title = '' if (! defined($Title));
3534: $xlabel = '' if (! defined($xlabel));
3535: $ylabel = '' if (! defined($ylabel));
3536: my %ValuesHash =
3537: (
3538: $id.'.title' => &Apache::lonnet::escape($Title),
3539: $id.'.xlabel' => &Apache::lonnet::escape($xlabel),
3540: $id.'.ylabel' => &Apache::lonnet::escape($ylabel),
3541: $id.'.labels' => join(',',@$Xlabels),
3542: $id.'.PlotType' => 'XY',
3543: $id.'.NumSets' => 2,
1.137 matthew 3544: $id.'.two_axes' => 1,
3545: $id.'.y1_max_value' => $Max1,
3546: $id.'.y1_min_value' => $Min1,
3547: $id.'.y2_max_value' => $Max2,
3548: $id.'.y2_min_value' => $Min2,
1.136 matthew 3549: );
3550: #
1.137 matthew 3551: if (defined($colors) && ref($colors) eq 'ARRAY') {
3552: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
3553: }
3554: #
3555: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
3556: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 3557: return '';
3558: }
3559: my $NumSets=1;
1.137 matthew 3560: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 3561: next if (! ref($array));
3562: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 3563: }
3564: #
3565: # Deal with other parameters
3566: while (my ($key,$value) = each(%Values)) {
3567: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 3568: }
3569: #
3570: &Apache::lonnet::appenv(%ValuesHash);
1.130 albertel 3571: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 3572: }
3573:
3574: ############################################################
3575: ############################################################
3576:
3577: =pod
3578:
1.157 matthew 3579: =back
3580:
1.139 matthew 3581: =head1 Statistics helper routines?
3582:
3583: Bad place for them but what the hell.
3584:
1.157 matthew 3585: =over 4
3586:
1.139 matthew 3587: =item &chartlink
3588:
3589: Returns a link to the chart for a specific student.
3590:
3591: Inputs:
3592:
3593: =over 4
3594:
3595: =item $linktext: The text of the link
3596:
3597: =item $sname: The students username
3598:
3599: =item $sdomain: The students domain
3600:
3601: =back
3602:
1.157 matthew 3603: =back
3604:
1.139 matthew 3605: =cut
3606:
3607: ############################################################
3608: ############################################################
3609: sub chartlink {
3610: my ($linktext, $sname, $sdomain) = @_;
3611: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.219 albertel 3612: '&SelectedStudent='.&Apache::lonnet::escape($sname.':'.$sdomain).
3613: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 3614: '">'.$linktext.'</a>';
1.153 matthew 3615: }
3616:
3617: #######################################################
3618: #######################################################
3619:
3620: =pod
3621:
3622: =head1 Course Environment Routines
1.157 matthew 3623:
3624: =over 4
1.153 matthew 3625:
3626: =item &restore_course_settings
3627:
3628: =item &store_course_settings
3629:
3630: Restores/Store indicated form parameters from the course environment.
3631: Will not overwrite existing values of the form parameters.
3632:
3633: Inputs:
3634: a scalar describing the data (e.g. 'chart', 'problem_analysis')
3635:
3636: a hash ref describing the data to be stored. For example:
3637:
3638: %Save_Parameters = ('Status' => 'scalar',
3639: 'chartoutputmode' => 'scalar',
3640: 'chartoutputdata' => 'scalar',
3641: 'Section' => 'array',
3642: 'StudentData' => 'array',
3643: 'Maps' => 'array');
3644:
3645: Returns: both routines return nothing
3646:
3647: =cut
3648:
3649: #######################################################
3650: #######################################################
3651: sub store_course_settings {
3652: # save to the environment
3653: # appenv the same items, just to be safe
3654: my $courseid = $ENV{'request.course.id'};
3655: my $coursedom = $ENV{'course.'.$courseid.'.domain'};
3656: my ($prefix,$Settings) = @_;
3657: my %SaveHash;
3658: my %AppHash;
3659: while (my ($setting,$type) = each(%$Settings)) {
1.176 albertel 3660: my $basename = 'internal.'.$prefix.'.'.$setting;
1.153 matthew 3661: my $envname = 'course.'.$courseid.'.'.$basename;
3662: if (exists($ENV{'form.'.$setting})) {
3663: # Save this value away
3664: if ($type eq 'scalar' &&
3665: (! exists($ENV{$envname}) ||
3666: $ENV{$envname} ne $ENV{'form.'.$setting})) {
3667: $SaveHash{$basename} = $ENV{'form.'.$setting};
3668: $AppHash{$envname} = $ENV{'form.'.$setting};
3669: } elsif ($type eq 'array') {
3670: my $stored_form;
3671: if (ref($ENV{'form.'.$setting})) {
3672: $stored_form = join(',',
3673: map {
3674: &Apache::lonnet::escape($_);
3675: } sort(@{$ENV{'form.'.$setting}}));
3676: } else {
3677: $stored_form =
3678: &Apache::lonnet::escape($ENV{'form.'.$setting});
3679: }
3680: # Determine if the array contents are the same.
3681: if ($stored_form ne $ENV{$envname}) {
3682: $SaveHash{$basename} = $stored_form;
3683: $AppHash{$envname} = $stored_form;
3684: }
3685: }
3686: }
3687: }
3688: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
3689: $coursedom,
3690: $ENV{'course.'.$courseid.'.num'});
3691: if ($put_result !~ /^(ok|delayed)/) {
3692: &Apache::lonnet::logthis('unable to save form parameters, '.
3693: 'got error:'.$put_result);
3694: }
3695: # Make sure these settings stick around in this session, too
3696: &Apache::lonnet::appenv(%AppHash);
3697: return;
3698: }
3699:
3700: sub restore_course_settings {
3701: my $courseid = $ENV{'request.course.id'};
3702: my ($prefix,$Settings) = @_;
3703: while (my ($setting,$type) = each(%$Settings)) {
3704: next if (exists($ENV{'form.'.$setting}));
1.176 albertel 3705: my $envname = 'course.'.$courseid.'.internal.'.$prefix.
1.153 matthew 3706: '.'.$setting;
3707: if (exists($ENV{$envname})) {
3708: if ($type eq 'scalar') {
3709: $ENV{'form.'.$setting} = $ENV{$envname};
3710: } elsif ($type eq 'array') {
3711: $ENV{'form.'.$setting} = [
3712: map {
3713: &Apache::lonnet::unescape($_);
3714: } split(',',$ENV{$envname})
3715: ];
3716: }
3717: }
3718: }
1.127 matthew 3719: }
3720:
3721: ############################################################
3722: ############################################################
1.154 albertel 3723:
3724: sub propath {
3725: my ($udom,$uname)=@_;
3726: $udom=~s/\W//g;
3727: $uname=~s/\W//g;
3728: my $subdir=$uname.'__';
3729: $subdir =~ s/(.)(.)(.).*/$1\/$2\/$3/;
3730: my $proname="$Apache::lonnet::perlvar{'lonUsersDir'}/$udom/$subdir/$uname";
3731: return $proname;
1.156 albertel 3732: }
3733:
3734: sub icon {
3735: my ($file)=@_;
1.168 albertel 3736: my $curfext = (split(/\./,$file))[-1];
3737: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 3738: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 3739: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
3740: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
3741: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
3742: $curfext.".gif") {
3743: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
3744: $curfext.".gif";
3745: }
3746: }
3747: return $iconname;
1.154 albertel 3748: }
1.84 albertel 3749:
1.215 albertel 3750: sub lonhttpdurl {
3751: my ($url)=@_;
3752: my $lonhttpd_port=$Apache::lonnet::perlvar{'lonhttpdPort'};
3753: if (!defined($lonhttpd_port)) { $lonhttpd_port='8080'; }
3754: return 'http://'.$ENV{'SERVER_NAME'}.':'.$lonhttpd_port.$url;
3755: }
3756:
1.213 albertel 3757: sub connection_aborted {
3758: my ($r)=@_;
3759: $r->print(" ");$r->rflush();
3760: my $c = $r->connection;
3761: return $c->aborted();
3762: }
3763:
1.221 foxr 3764: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 3765: # strings as 'strings'.
3766: sub escape_single {
1.221 foxr 3767: my ($input) = @_;
1.223 albertel 3768: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 3769: $input =~ s/\'/\\\'/g; # Esacpe the 's....
3770: return $input;
3771: }
1.223 albertel 3772:
1.222 foxr 3773: # Same as escape_single, but escape's "'s This
3774: # can be used for "strings"
3775: sub escape_double {
3776: my ($input) = @_;
3777: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
3778: $input =~ s/\"/\\\"/g; # Esacpe the "s....
3779: return $input;
3780: }
1.223 albertel 3781:
1.222 foxr 3782: # Escapes the last element of a full URL.
3783: sub escape_url {
3784: my ($url) = @_;
3785: my @urlslices = split(/\//, $url);
1.223 albertel 3786: my $lastitem = &Apache::lonnet::escape(pop(@urlslices));
3787: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 3788: }
1.41 ng 3789: =pod
3790:
3791: =back
3792:
1.112 bowersj2 3793: =cut
1.41 ng 3794:
1.112 bowersj2 3795: 1;
3796: __END__;
1.41 ng 3797:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>