Annotation of loncom/interface/loncommon.pm, revision 1.499
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.499 ! albertel 4: # $Id: loncommon.pm,v 1.498 2006/12/28 02:50:20 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.258 albertel 58: use Apache::lonnet;
1.46 matthew 59: use GDBM_File;
1.51 www 60: use POSIX qw(strftime mktime);
1.82 www 61: use Apache::lonmenu();
1.498 albertel 62: use Apache::lonenc();
1.117 www 63: use Apache::lonlocal;
1.139 matthew 64: use HTML::Entities;
1.334 albertel 65: use Apache::lonhtmlcommon();
66: use Apache::loncoursedata();
1.344 albertel 67: use Apache::lontexconvert();
1.444 albertel 68: use Apache::lonclonecourse();
1.479 albertel 69: use LONCAPA qw(:DEFAULT :match);
1.117 www 70:
1.22 www 71: my $readit;
72:
1.157 matthew 73: ##
74: ## Global Variables
75: ##
1.46 matthew 76:
1.20 www 77: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 78: my %language;
1.124 www 79: my %supported_language;
1.12 harris41 80: my %cprtag;
1.192 taceyjo1 81: my %scprtag;
1.351 www 82: my %fe; my %fd; my %fm;
1.41 ng 83: my %category_extensions;
1.12 harris41 84:
1.63 www 85: # ---------------------------------------------- Designs
86:
87: my %designhash;
88:
1.46 matthew 89: # ---------------------------------------------- Thesaurus variables
1.144 matthew 90: #
91: # %Keywords:
92: # A hash used by &keyword to determine if a word is considered a keyword.
93: # $thesaurus_db_file
94: # Scalar containing the full path to the thesaurus database.
1.46 matthew 95:
96: my %Keywords;
97: my $thesaurus_db_file;
98:
1.144 matthew 99: #
100: # Initialize values from language.tab, copyright.tab, filetypes.tab,
101: # thesaurus.tab, and filecategories.tab.
102: #
1.18 www 103: BEGIN {
1.46 matthew 104: # Variable initialization
105: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
106: #
1.22 www 107: unless ($readit) {
1.12 harris41 108: # ------------------------------------------------------------------- languages
109: {
1.158 raeburn 110: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
111: '/language.tab';
112: if ( open(my $fh,"<$langtabfile") ) {
1.356 albertel 113: while (my $line = <$fh>) {
114: next if ($line=~/^\#/);
115: chomp($line);
116: my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$line));
1.158 raeburn 117: $language{$key}=$val.' - '.$enc;
118: if ($sup) {
119: $supported_language{$key}=$sup;
120: }
121: }
122: close($fh);
123: }
1.12 harris41 124: }
125: # ------------------------------------------------------------------ copyrights
126: {
1.158 raeburn 127: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
128: '/copyright.tab';
129: if ( open (my $fh,"<$copyrightfile") ) {
1.356 albertel 130: while (my $line = <$fh>) {
131: next if ($line=~/^\#/);
132: chomp($line);
133: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 134: $cprtag{$key}=$val;
135: }
136: close($fh);
137: }
1.12 harris41 138: }
1.351 www 139: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 140: {
141: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
142: '/source_copyright.tab';
143: if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356 albertel 144: while (my $line = <$fh>) {
145: next if ($line =~ /^\#/);
146: chomp($line);
147: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 148: $scprtag{$key}=$val;
149: }
150: close($fh);
151: }
152: }
1.63 www 153:
154: # -------------------------------------------------------------- domain designs
155:
156: my $filename;
157: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
158: opendir(DIR,$designdir);
159: while ($filename=readdir(DIR)) {
1.271 albertel 160: if ($filename!~/\.tab$/) { next; }
1.479 albertel 161: my ($domain)=($filename=~/^($match_domain)\./);
1.271 albertel 162: {
163: my $designfile = $designdir.'/'.$filename;
164: if ( open (my $fh,"<$designfile") ) {
1.356 albertel 165: while (my $line = <$fh>) {
166: next if ($line =~ /^\#/);
167: chomp($line);
168: my ($key,$val)=(split(/\=/,$line));
1.271 albertel 169: if ($val) { $designhash{$domain.'.'.$key}=$val; }
170: }
171: close($fh);
172: }
173: }
1.63 www 174:
175: }
176: closedir(DIR);
177:
178:
1.15 harris41 179: # ------------------------------------------------------------- file categories
180: {
1.158 raeburn 181: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
182: '/filecategories.tab';
183: if ( open (my $fh,"<$categoryfile") ) {
1.356 albertel 184: while (my $line = <$fh>) {
185: next if ($line =~ /^\#/);
186: chomp($line);
187: my ($extension,$category)=(split(/\s+/,$line,2));
1.158 raeburn 188: push @{$category_extensions{lc($category)}},$extension;
189: }
190: close($fh);
191: }
192:
1.15 harris41 193: }
1.12 harris41 194: # ------------------------------------------------------------------ file types
195: {
1.158 raeburn 196: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
197: '/filetypes.tab';
198: if ( open (my $fh,"<$typesfile") ) {
1.356 albertel 199: while (my $line = <$fh>) {
200: next if ($line =~ /^\#/);
201: chomp($line);
202: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 203: if ($descr ne '') {
204: $fe{$ending}=lc($emb);
205: $fd{$ending}=$descr;
1.351 www 206: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 207: }
208: }
209: close($fh);
210: }
1.12 harris41 211: }
1.22 www 212: &Apache::lonnet::logthis(
1.46 matthew 213: "<font color=yellow>INFO: Read file types</font>");
1.22 www 214: $readit=1;
1.46 matthew 215: } # end of unless($readit)
1.32 matthew 216:
217: }
1.112 bowersj2 218:
1.42 matthew 219: ###############################################################
220: ## HTML and Javascript Helper Functions ##
221: ###############################################################
222:
223: =pod
224:
1.112 bowersj2 225: =head1 HTML and Javascript Functions
1.42 matthew 226:
1.112 bowersj2 227: =over 4
228:
229: =item * browser_and_searcher_javascript ()
230:
231: X<browsing, javascript>X<searching, javascript>Returns a string
232: containing javascript with two functions, C<openbrowser> and
233: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
234: tags.
1.42 matthew 235:
1.112 bowersj2 236: =item * openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 237:
238: inputs: formname, elementname, only, omit
239:
240: formname and elementname indicate the name of the html form and name of
241: the element that the results of the browsing selection are to be placed in.
242:
243: Specifying 'only' will restrict the browser to displaying only files
1.185 www 244: with the given extension. Can be a comma separated list.
1.42 matthew 245:
246: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 247: with the given extension. Can be a comma separated list.
1.42 matthew 248:
1.112 bowersj2 249: =item * opensearcher(formname, elementname) [javascript]
1.42 matthew 250:
251: Inputs: formname, elementname
252:
253: formname and elementname specify the name of the html form and the name
254: of the element the selection from the search results will be placed in.
255:
256: =cut
257:
258: sub browser_and_searcher_javascript {
1.199 albertel 259: my ($mode)=@_;
260: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 261: my $resurl=&escape_single(&lastresurl());
1.42 matthew 262: return <<END;
1.219 albertel 263: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 264: var editbrowser = null;
1.135 albertel 265: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 266: var url = '$resurl/?';
1.42 matthew 267: if (editbrowser == null) {
268: url += 'launch=1&';
269: }
270: url += 'catalogmode=interactive&';
1.199 albertel 271: url += 'mode=$mode&';
1.42 matthew 272: url += 'form=' + formname + '&';
273: if (only != null) {
274: url += 'only=' + only + '&';
1.217 albertel 275: } else {
276: url += 'only=&';
277: }
1.42 matthew 278: if (omit != null) {
279: url += 'omit=' + omit + '&';
1.217 albertel 280: } else {
281: url += 'omit=&';
282: }
1.135 albertel 283: if (titleelement != null) {
284: url += 'titleelement=' + titleelement + '&';
1.217 albertel 285: } else {
286: url += 'titleelement=&';
287: }
1.42 matthew 288: url += 'element=' + elementname + '';
289: var title = 'Browser';
1.435 albertel 290: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 291: options += ',width=700,height=600';
292: editbrowser = open(url,title,options,'1');
293: editbrowser.focus();
294: }
295: var editsearcher;
1.135 albertel 296: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 297: var url = '/adm/searchcat?';
298: if (editsearcher == null) {
299: url += 'launch=1&';
300: }
301: url += 'catalogmode=interactive&';
1.199 albertel 302: url += 'mode=$mode&';
1.42 matthew 303: url += 'form=' + formname + '&';
1.135 albertel 304: if (titleelement != null) {
305: url += 'titleelement=' + titleelement + '&';
1.217 albertel 306: } else {
307: url += 'titleelement=&';
308: }
1.42 matthew 309: url += 'element=' + elementname + '';
310: var title = 'Search';
1.435 albertel 311: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 312: options += ',width=700,height=600';
313: editsearcher = open(url,title,options,'1');
314: editsearcher.focus();
315: }
1.219 albertel 316: // END LON-CAPA Internal -->
1.42 matthew 317: END
1.170 www 318: }
319:
320: sub lastresurl {
1.258 albertel 321: if ($env{'environment.lastresurl'}) {
322: return $env{'environment.lastresurl'}
1.170 www 323: } else {
324: return '/res';
325: }
326: }
327:
328: sub storeresurl {
329: my $resurl=&Apache::lonnet::clutter(shift);
330: unless ($resurl=~/^\/res/) { return 0; }
331: $resurl=~s/\/$//;
332: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
333: &Apache::lonnet::appenv('environment.lastresurl' => $resurl);
334: return 1;
1.42 matthew 335: }
336:
1.74 www 337: sub studentbrowser_javascript {
1.111 www 338: unless (
1.258 albertel 339: (($env{'request.course.id'}) &&
1.302 albertel 340: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
341: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
342: '/'.$env{'request.course.sec'})
343: ))
1.258 albertel 344: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 345: ) { return ''; }
1.74 www 346: return (<<'ENDSTDBRW');
347: <script type="text/javascript" language="Javascript" >
348: var stdeditbrowser;
1.111 www 349: function openstdbrowser(formname,uname,udom,roleflag) {
1.74 www 350: var url = '/adm/pickstudent?';
351: var filter;
352: eval('filter=document.'+formname+'.'+uname+'.value;');
353: if (filter != null) {
354: if (filter != '') {
355: url += 'filter='+filter+'&';
356: }
357: }
358: url += 'form=' + formname + '&unameelement='+uname+
359: '&udomelement='+udom;
1.111 www 360: if (roleflag) { url+="&roles=1"; }
1.102 www 361: var title = 'Student_Browser';
1.74 www 362: var options = 'scrollbars=1,resizable=1,menubar=0';
363: options += ',width=700,height=600';
364: stdeditbrowser = open(url,title,options,'1');
365: stdeditbrowser.focus();
366: }
367: </script>
368: ENDSTDBRW
369: }
1.42 matthew 370:
1.74 www 371: sub selectstudent_link {
1.111 www 372: my ($form,$unameele,$udomele)=@_;
1.258 albertel 373: if ($env{'request.course.id'}) {
1.302 albertel 374: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
375: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
376: '/'.$env{'request.course.sec'})) {
1.111 www 377: return '';
378: }
379: return "<a href='".'javascript:openstdbrowser("'.$form.'","'.$unameele.
1.119 www 380: '","'.$udomele.'");'."'>".&mt('Select User')."</a>";
1.74 www 381: }
1.258 albertel 382: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.111 www 383: return "<a href='".'javascript:openstdbrowser("'.$form.'","'.$unameele.
1.119 www 384: '","'.$udomele.'",1);'."'>".&mt('Select User')."</a>";
1.111 www 385: }
386: return '';
1.91 www 387: }
388:
389: sub coursebrowser_javascript {
1.468 raeburn 390: my ($domainfilter,$sec_element,$formname)=@_;
1.377 raeburn 391: my $crs_or_grp_alert = &mt('Please select the type of LON-CAPA entity - Course or Group - for which you wish to add/modify a user role');
1.468 raeburn 392: my $output = '
1.91 www 393: <script type="text/javascript" language="Javascript" >
1.468 raeburn 394: var stdeditbrowser;'."\n";
395: $output .= <<"ENDSTDBRW";
1.377 raeburn 396: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,crstype) {
1.91 www 397: var url = '/adm/pickcourse?';
1.468 raeburn 398: var domainfilter = '';
399: var formid = getFormIdByName(formname);
400: if (formid > -1) {
401: var domid = getIndexByName(formid,udom);
402: if (domid > -1) {
403: if (document.forms[formid].elements[domid].type == 'select-one') {
404: domainfilter=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
405: }
406: if (document.forms[formid].elements[domid].type == 'hidden') {
407: domainfilter=document.forms[formid].elements[domid].value;
408: }
409: }
1.91 www 410: }
1.128 albertel 411: if (domainfilter != null) {
412: if (domainfilter != '') {
413: url += 'domainfilter='+domainfilter+'&';
414: }
415: }
1.91 www 416: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 417: '&cdomelement='+udom+
418: '&cnameelement='+desc;
1.468 raeburn 419: if (extra_element !=null && extra_element != '') {
420: if (formname == 'rolechoice') {
421: url += '&roleelement='+extra_element;
422: if (domainfilter == null || domainfilter == '') {
423: url += '&domainfilter='+extra_element;
424: }
1.234 raeburn 425: }
1.468 raeburn 426: else {
427: if (formname == 'portform') {
428: url += '&setroles='+extra_element;
429: }
430: }
1.230 raeburn 431: }
1.293 raeburn 432: if (multflag !=null && multflag != '') {
433: url += '&multiple='+multflag;
434: }
1.377 raeburn 435: if (crstype == 'Course/Group') {
436: if (formname == 'cu') {
437: crstype = document.cu.crstype.options[document.cu.crstype.selectedIndex].value;
438: if (crstype == "") {
439: alert("$crs_or_grp_alert");
440: return;
441: }
442: }
443: }
444: if (crstype !=null && crstype != '') {
445: url += '&type='+crstype;
446: }
1.102 www 447: var title = 'Course_Browser';
1.91 www 448: var options = 'scrollbars=1,resizable=1,menubar=0';
449: options += ',width=700,height=600';
450: stdeditbrowser = open(url,title,options,'1');
451: stdeditbrowser.focus();
452: }
1.468 raeburn 453:
454: function getFormIdByName(formname) {
455: for (var i=0;i<document.forms.length;i++) {
456: if (document.forms[i].name == formname) {
457: return i;
458: }
459: }
460: return -1;
461: }
462:
463: function getIndexByName(formid,item) {
464: for (var i=0;i<document.forms[formid].elements.length;i++) {
465: if (document.forms[formid].elements[i].name == item) {
466: return i;
467: }
468: }
469: return -1;
470: }
1.91 www 471: ENDSTDBRW
1.468 raeburn 472: if ($sec_element ne '') {
473: $output .= &setsec_javascript($sec_element,$formname);
474: }
475: $output .= '
476: </script>';
477: return $output;
478: }
479:
480: sub setsec_javascript {
481: my ($sec_element,$formname) = @_;
482: my $setsections = qq|
483: function setSect(sectionlist) {
484: var sectionsArray = sectionlist.split(",");
485: var numSections = sectionsArray.length;
486: document.$formname.$sec_element.length = 0;
487: if (numSections == 0) {
488: document.$formname.$sec_element.multiple=false;
489: document.$formname.$sec_element.size=1;
490: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
491: } else {
492: if (numSections == 1) {
493: document.$formname.$sec_element.multiple=false;
494: document.$formname.$sec_element.size=1;
495: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
496: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
497: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
498: } else {
499: for (var i=0; i<numSections; i++) {
500: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
501: }
502: document.$formname.$sec_element.multiple=true
503: if (numSections < 3) {
504: document.$formname.$sec_element.size=numSections;
505: } else {
506: document.$formname.$sec_element.size=3;
507: }
508: document.$formname.$sec_element.options[0].selected = false
509: }
510: }
1.91 www 511: }
1.468 raeburn 512: |;
513: return $setsections;
514: }
515:
1.91 www 516:
517: sub selectcourse_link {
1.377 raeburn 518: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype)=@_;
1.492 albertel 519: return "<a href='".'javascript:opencrsbrowser("'.$form.'","'.$unameele.
520: '","'.$udomele.'","'.$desc.'","'.$extra_element.'","'.$multflag.'","'.$selecttype.'");'."'>".&mt('Select Course')."</a>";
1.74 www 521: }
1.42 matthew 522:
1.273 raeburn 523: sub check_uncheck_jscript {
524: my $jscript = <<"ENDSCRT";
525: function checkAll(field) {
526: if (field.length > 0) {
527: for (i = 0; i < field.length; i++) {
528: field[i].checked = true ;
529: }
530: } else {
531: field.checked = true
532: }
533: }
534:
535: function uncheckAll(field) {
536: if (field.length > 0) {
537: for (i = 0; i < field.length; i++) {
538: field[i].checked = false ;
539: } } else {
540: field.checked = false ;
541: }
542: }
543: ENDSCRT
544: return $jscript;
545: }
546:
547:
1.42 matthew 548: =pod
1.36 matthew 549:
1.112 bowersj2 550: =item * linked_select_forms(...)
1.36 matthew 551:
552: linked_select_forms returns a string containing a <script></script> block
553: and html for two <select> menus. The select menus will be linked in that
554: changing the value of the first menu will result in new values being placed
555: in the second menu. The values in the select menu will appear in alphabetical
556: order.
557:
558: linked_select_forms takes the following ordered inputs:
559:
560: =over 4
561:
1.112 bowersj2 562: =item * $formname, the name of the <form> tag
1.36 matthew 563:
1.112 bowersj2 564: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 565:
1.112 bowersj2 566: =item * $firstdefault, the default value for the first menu
1.36 matthew 567:
1.112 bowersj2 568: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 569:
1.112 bowersj2 570: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 571:
1.112 bowersj2 572: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 573:
1.41 ng 574: =back
575:
1.36 matthew 576: Below is an example of such a hash. Only the 'text', 'default', and
577: 'select2' keys must appear as stated. keys(%menu) are the possible
578: values for the first select menu. The text that coincides with the
1.41 ng 579: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 580: and text for the second menu are given in the hash pointed to by
581: $menu{$choice1}->{'select2'}.
582:
1.112 bowersj2 583: my %menu = ( A1 => { text =>"Choice A1" ,
584: default => "B3",
585: select2 => {
586: B1 => "Choice B1",
587: B2 => "Choice B2",
588: B3 => "Choice B3",
589: B4 => "Choice B4"
590: }
591: },
592: A2 => { text =>"Choice A2" ,
593: default => "C2",
594: select2 => {
595: C1 => "Choice C1",
596: C2 => "Choice C2",
597: C3 => "Choice C3"
598: }
599: },
600: A3 => { text =>"Choice A3" ,
601: default => "D6",
602: select2 => {
603: D1 => "Choice D1",
604: D2 => "Choice D2",
605: D3 => "Choice D3",
606: D4 => "Choice D4",
607: D5 => "Choice D5",
608: D6 => "Choice D6",
609: D7 => "Choice D7"
610: }
611: }
612: );
1.36 matthew 613:
614: =cut
615:
616: sub linked_select_forms {
617: my ($formname,
618: $middletext,
619: $firstdefault,
620: $firstselectname,
621: $secondselectname,
622: $hashref
623: ) = @_;
624: my $second = "document.$formname.$secondselectname";
625: my $first = "document.$formname.$firstselectname";
626: # output the javascript to do the changing
627: my $result = '';
1.219 albertel 628: $result.="<script type=\"text/javascript\">\n";
1.36 matthew 629: $result.="var select2data = new Object();\n";
630: $" = '","';
631: my $debug = '';
632: foreach my $s1 (sort(keys(%$hashref))) {
633: $result.="select2data.d_$s1 = new Object();\n";
634: $result.="select2data.d_$s1.def = new String('".
635: $hashref->{$s1}->{'default'}."');\n";
636: $result.="select2data.d_$s1.values = new Array(";
637: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
638: $result.="\"@s2values\");\n";
639: $result.="select2data.d_$s1.texts = new Array(";
640: my @s2texts;
641: foreach my $value (@s2values) {
642: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
643: }
644: $result.="\"@s2texts\");\n";
645: }
646: $"=' ';
647: $result.= <<"END";
648:
649: function select1_changed() {
650: // Determine new choice
651: var newvalue = "d_" + $first.value;
652: // update select2
653: var values = select2data[newvalue].values;
654: var texts = select2data[newvalue].texts;
655: var select2def = select2data[newvalue].def;
656: var i;
657: // out with the old
658: for (i = 0; i < $second.options.length; i++) {
659: $second.options[i] = null;
660: }
661: // in with the nuclear
662: for (i=0;i<values.length; i++) {
663: $second.options[i] = new Option(values[i]);
1.143 matthew 664: $second.options[i].value = values[i];
1.36 matthew 665: $second.options[i].text = texts[i];
666: if (values[i] == select2def) {
667: $second.options[i].selected = true;
668: }
669: }
670: }
671: </script>
672: END
673: # output the initial values for the selection lists
674: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
675: foreach my $value (sort(keys(%$hashref))) {
676: $result.=" <option value=\"$value\" ";
1.253 albertel 677: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 678: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 679: }
680: $result .= "</select>\n";
681: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
682: $result .= $middletext;
683: $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
684: my $seconddefault = $hashref->{$firstdefault}->{'default'};
685: foreach my $value (sort(keys(%select2))) {
686: $result.=" <option value=\"$value\" ";
1.253 albertel 687: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 688: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 689: }
690: $result .= "</select>\n";
691: # return $debug;
692: return $result;
693: } # end of sub linked_select_forms {
694:
1.45 matthew 695: =pod
1.44 bowersj2 696:
1.112 bowersj2 697: =item * help_open_topic($topic, $text, $stayOnPage, $width, $height)
1.44 bowersj2 698:
1.112 bowersj2 699: Returns a string corresponding to an HTML link to the given help
700: $topic, where $topic corresponds to the name of a .tex file in
701: /home/httpd/html/adm/help/tex, with underscores replaced by
702: spaces.
703:
704: $text will optionally be linked to the same topic, allowing you to
705: link text in addition to the graphic. If you do not want to link
706: text, but wish to specify one of the later parameters, pass an
707: empty string.
708:
709: $stayOnPage is a value that will be interpreted as a boolean. If true,
710: the link will not open a new window. If false, the link will open
711: a new window using Javascript. (Default is false.)
712:
713: $width and $height are optional numerical parameters that will
714: override the width and height of the popped up window, which may
715: be useful for certain help topics with big pictures included.
1.44 bowersj2 716:
717: =cut
718:
719: sub help_open_topic {
1.48 bowersj2 720: my ($topic, $text, $stayOnPage, $width, $height) = @_;
721: $text = "" if (not defined $text);
1.44 bowersj2 722: $stayOnPage = 0 if (not defined $stayOnPage);
1.258 albertel 723: if ($env{'browser.interface'} eq 'textual' ||
724: $env{'environment.remote'} eq 'off' ) {
1.79 www 725: $stayOnPage=1;
726: }
1.44 bowersj2 727: $width = 350 if (not defined $width);
728: $height = 400 if (not defined $height);
729: my $filename = $topic;
730: $filename =~ s/ /_/g;
731:
1.48 bowersj2 732: my $template = "";
733: my $link;
1.159 www 734:
735: $topic=~s/\W/\_/g;
1.44 bowersj2 736:
737: if (!$stayOnPage)
738: {
1.72 bowersj2 739: $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 740: }
741: else
742: {
1.48 bowersj2 743: $link = "/adm/help/${filename}.hlp";
744: }
745:
746: # Add the text
747: if ($text ne "")
748: {
1.77 www 749: $template .=
750: "<table bgcolor='#3333AA' cellspacing='1' cellpadding='1' border='0'><tr>".
1.436 albertel 751: "<td bgcolor='#5555FF'><a target=\"_top\" href=\"$link\"><font color='#FFFFFF' size='2'>$text</font></a>";
1.48 bowersj2 752: }
753:
754: # Add the graphic
1.179 matthew 755: my $title = &mt('Online Help');
1.215 albertel 756: my $helpicon=&lonhttpdurl("/adm/help/gif/smallHelp.gif");
1.48 bowersj2 757: $template .= <<"ENDTEMPLATE";
1.436 albertel 758: <a target="_top" href="$link" title="$title"><img src="$helpicon" border="0" alt="(Help: $topic)" /></a>
1.44 bowersj2 759: ENDTEMPLATE
1.78 www 760: if ($text ne '') { $template.='</td></tr></table>' };
1.44 bowersj2 761: return $template;
762:
1.106 bowersj2 763: }
764:
765: # This is a quicky function for Latex cheatsheet editing, since it
766: # appears in at least four places
767: sub helpLatexCheatsheet {
768: my $other = shift;
769: my $addOther = '';
770: if ($other) {
771: $addOther = Apache::loncommon::help_open_topic($other, shift,
772: undef, undef, 600) .
773: '</td><td>';
774: }
775: return '<table><tr><td>'.
776: $addOther .
777: &Apache::loncommon::help_open_topic("Greek_Symbols",'Greek Symbols',
778: undef,undef,600)
779: .'</td><td>'.
780: &Apache::loncommon::help_open_topic("Other_Symbols",'Other Symbols',
781: undef,undef,600)
782: .'</td></tr></table>';
1.172 www 783: }
784:
1.430 albertel 785: sub general_help {
786: my $helptopic='Student_Intro';
787: if ($env{'request.role'}=~/^(ca|au)/) {
788: $helptopic='Authoring_Intro';
789: } elsif ($env{'request.role'}=~/^cc/) {
790: $helptopic='Course_Coordination_Intro';
791: }
792: return $helptopic;
793: }
794:
795: sub update_help_link {
796: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
797: my $origurl = $ENV{'REQUEST_URI'};
798: $origurl=~s|^/~|/priv/|;
799: my $timestamp = time;
800: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
801: $$datum = &escape($$datum);
802: }
803:
804: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
805: my $output .= <<"ENDOUTPUT";
806: <script type="text/javascript">
807: banner_link = '$banner_link';
808: </script>
809: ENDOUTPUT
810: return $output;
811: }
812:
813: # now just updates the help link and generates a blue icon
1.193 raeburn 814: sub help_open_menu {
1.430 albertel 815: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
816: = @_;
817:
818: $stayOnPage = 0 if (not defined $stayOnPage);
819: if ($env{'browser.interface'} eq 'textual' ||
820: $env{'environment.remote'} eq 'off' ) {
821: $stayOnPage=1;
822: }
823: my $output;
824: if ($component_help) {
825: if (!$text) {
826: $output=&help_open_topic($component_help,undef,$stayOnPage,
827: $width,$height);
828: } else {
829: my $help_text;
830: $help_text=&unescape($topic);
831: $output='<table><tr><td>'.
832: &help_open_topic($component_help,$help_text,$stayOnPage,
833: $width,$height).'</td></tr></table>';
834: }
835: }
836: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
837: return $output.$banner_link;
838: }
839:
840: sub top_nav_help {
841: my ($text) = @_;
842:
1.436 albertel 843: $text = &mt($text);
844:
845: my $stayOnPage =
846: ($env{'browser.interface'} eq 'textual' ||
847: $env{'environment.remote'} eq 'off' );
848: my $link= ($stayOnPage) ? "javascript:helpMenu('display')"
849: : "javascript:helpMenu('open')";
850: my $banner_link = &update_help_link(undef,undef,undef,undef,$stayOnPage);
851:
1.201 raeburn 852: my $title = &mt('Get help');
1.436 albertel 853:
854: return <<"END";
855: $banner_link
856: <a href="$link" title="$title">$text</a>
857: END
858: }
859:
860: sub help_menu_js {
861: my ($text) = @_;
862:
863: my $stayOnPage =
864: ($env{'browser.interface'} eq 'textual' ||
865: $env{'environment.remote'} eq 'off' );
866:
867: my $width = 620;
868: my $height = 600;
1.430 albertel 869: my $helptopic=&general_help();
870: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261 albertel 871: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 872: my $start_page =
873: &Apache::loncommon::start_page('Help Menu', undef,
874: {'frameset' => 1,
875: 'js_ready' => 1,
876: 'add_entries' => {
877: 'border' => '0',
878: 'rows' => "105,*",},});
879: my $end_page =
880: &Apache::loncommon::end_page({'frameset' => 1,
881: 'js_ready' => 1,});
882:
1.436 albertel 883: my $template .= <<"ENDTEMPLATE";
884: <script type="text/javascript">
1.253 albertel 885: // <!-- BEGIN LON-CAPA Internal
886: // <![CDATA[
1.430 albertel 887: var banner_link = '';
1.243 raeburn 888: function helpMenu(target) {
889: var caller = this;
890: if (target == 'open') {
891: var newWindow = null;
892: try {
1.262 albertel 893: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 894: }
895: catch(error) {
896: writeHelp(caller);
897: return;
898: }
899: if (newWindow) {
900: caller = newWindow;
901: }
1.193 raeburn 902: }
1.243 raeburn 903: writeHelp(caller);
904: return;
905: }
906: function writeHelp(caller) {
1.430 albertel 907: caller.document.writeln('$start_page<frame name="bannerframe" src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243 raeburn 908: caller.document.close()
909: caller.focus()
1.193 raeburn 910: }
1.253 albertel 911: // ]]>
1.219 albertel 912: // END LON-CAPA Internal -->
1.436 albertel 913: </script>
1.193 raeburn 914: ENDTEMPLATE
915: return $template;
916: }
917:
1.172 www 918: sub help_open_bug {
919: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 920: unless ($env{'user.adv'}) { return ''; }
1.172 www 921: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
922: $text = "" if (not defined $text);
923: $stayOnPage = 0 if (not defined $stayOnPage);
1.258 albertel 924: if ($env{'browser.interface'} eq 'textual' ||
925: $env{'environment.remote'} eq 'off' ) {
1.172 www 926: $stayOnPage=1;
927: }
1.184 albertel 928: $width = 600 if (not defined $width);
929: $height = 600 if (not defined $height);
1.172 www 930:
931: $topic=~s/\W+/\+/g;
932: my $link='';
933: my $template='';
1.379 albertel 934: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
935: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 936: if (!$stayOnPage)
937: {
938: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
939: }
940: else
941: {
942: $link = $url;
943: }
944: # Add the text
945: if ($text ne "")
946: {
947: $template .=
948: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.436 albertel 949: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><font color='#FFFFFF' size='2'>$text</font></a>";
1.172 www 950: }
951:
952: # Add the graphic
1.179 matthew 953: my $title = &mt('Report a Bug');
1.215 albertel 954: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 955: $template .= <<"ENDTEMPLATE";
1.436 albertel 956: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 957: ENDTEMPLATE
958: if ($text ne '') { $template.='</td></tr></table>' };
959: return $template;
960:
961: }
962:
963: sub help_open_faq {
964: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 965: unless ($env{'user.adv'}) { return ''; }
1.172 www 966: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
967: $text = "" if (not defined $text);
968: $stayOnPage = 0 if (not defined $stayOnPage);
1.258 albertel 969: if ($env{'browser.interface'} eq 'textual' ||
970: $env{'environment.remote'} eq 'off' ) {
1.172 www 971: $stayOnPage=1;
972: }
973: $width = 350 if (not defined $width);
974: $height = 400 if (not defined $height);
975:
976: $topic=~s/\W+/\+/g;
977: my $link='';
978: my $template='';
979: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
980: if (!$stayOnPage)
981: {
982: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
983: }
984: else
985: {
986: $link = $url;
987: }
988:
989: # Add the text
990: if ($text ne "")
991: {
992: $template .=
1.173 www 993: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.436 albertel 994: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><font color='#FFFFFF' size='2'>$text</font></a>";
1.172 www 995: }
996:
997: # Add the graphic
1.179 matthew 998: my $title = &mt('View the FAQ');
1.215 albertel 999: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1000: $template .= <<"ENDTEMPLATE";
1.436 albertel 1001: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1002: ENDTEMPLATE
1003: if ($text ne '') { $template.='</td></tr></table>' };
1004: return $template;
1005:
1.44 bowersj2 1006: }
1.37 matthew 1007:
1.180 matthew 1008: ###############################################################
1009: ###############################################################
1010:
1.45 matthew 1011: =pod
1012:
1.256 matthew 1013: =item * change_content_javascript():
1014:
1015: This and the next function allow you to create small sections of an
1016: otherwise static HTML page that you can update on the fly with
1017: Javascript, even in Netscape 4.
1018:
1019: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1020: must be written to the HTML page once. It will prove the Javascript
1021: function "change(name, content)". Calling the change function with the
1022: name of the section
1023: you want to update, matching the name passed to C<changable_area>, and
1024: the new content you want to put in there, will put the content into
1025: that area.
1026:
1027: B<Note>: Netscape 4 only reserves enough space for the changable area
1028: to contain room for the original contents. You need to "make space"
1029: for whatever changes you wish to make, and be B<sure> to check your
1030: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1031: it's adequate for updating a one-line status display, but little more.
1032: This script will set the space to 100% width, so you only need to
1033: worry about height in Netscape 4.
1034:
1035: Modern browsers are much less limiting, and if you can commit to the
1036: user not using Netscape 4, this feature may be used freely with
1037: pretty much any HTML.
1038:
1039: =cut
1040:
1041: sub change_content_javascript {
1042: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1043: if ($env{'browser.type'} eq 'netscape' &&
1044: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1045: return (<<NETSCAPE4);
1046: function change(name, content) {
1047: doc = document.layers[name+"___escape"].layers[0].document;
1048: doc.open();
1049: doc.write(content);
1050: doc.close();
1051: }
1052: NETSCAPE4
1053: } else {
1054: # Otherwise, we need to use semi-standards-compliant code
1055: # (technically, "innerHTML" isn't standard but the equivalent
1056: # is really scary, and every useful browser supports it
1057: return (<<DOMBASED);
1058: function change(name, content) {
1059: element = document.getElementById(name);
1060: element.innerHTML = content;
1061: }
1062: DOMBASED
1063: }
1064: }
1065:
1066: =pod
1067:
1068: =item * changable_area($name, $origContent):
1069:
1070: This provides a "changable area" that can be modified on the fly via
1071: the Javascript code provided in C<change_content_javascript>. $name is
1072: the name you will use to reference the area later; do not repeat the
1073: same name on a given HTML page more then once. $origContent is what
1074: the area will originally contain, which can be left blank.
1075:
1076: =cut
1077:
1078: sub changable_area {
1079: my ($name, $origContent) = @_;
1080:
1.258 albertel 1081: if ($env{'browser.type'} eq 'netscape' &&
1082: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1083: # If this is netscape 4, we need to use the Layer tag
1084: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1085: } else {
1086: return "<span id='$name'>$origContent</span>";
1087: }
1088: }
1089:
1090: =pod
1091:
1092: =back
1093:
1094: =head1 Excel and CSV file utility routines
1095:
1096: =over 4
1097:
1098: =cut
1099:
1100: ###############################################################
1101: ###############################################################
1102:
1103: =pod
1104:
1.112 bowersj2 1105: =item * csv_translate($text)
1.37 matthew 1106:
1.185 www 1107: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1108: format.
1109:
1110: =cut
1111:
1.180 matthew 1112: ###############################################################
1113: ###############################################################
1.37 matthew 1114: sub csv_translate {
1115: my $text = shift;
1116: $text =~ s/\"/\"\"/g;
1.209 albertel 1117: $text =~ s/\n/ /g;
1.37 matthew 1118: return $text;
1119: }
1.180 matthew 1120:
1121: ###############################################################
1122: ###############################################################
1123:
1124: =pod
1125:
1126: =item * define_excel_formats
1127:
1128: Define some commonly used Excel cell formats.
1129:
1130: Currently supported formats:
1131:
1132: =over 4
1133:
1134: =item header
1135:
1136: =item bold
1137:
1138: =item h1
1139:
1140: =item h2
1141:
1142: =item h3
1143:
1.256 matthew 1144: =item h4
1145:
1146: =item i
1147:
1.180 matthew 1148: =item date
1149:
1150: =back
1151:
1152: Inputs: $workbook
1153:
1154: Returns: $format, a hash reference.
1155:
1156: =cut
1157:
1158: ###############################################################
1159: ###############################################################
1160: sub define_excel_formats {
1161: my ($workbook) = @_;
1162: my $format;
1163: $format->{'header'} = $workbook->add_format(bold => 1,
1164: bottom => 1,
1165: align => 'center');
1166: $format->{'bold'} = $workbook->add_format(bold=>1);
1167: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1168: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1169: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1170: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1171: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1172: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1173: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1174: return $format;
1175: }
1176:
1177: ###############################################################
1178: ###############################################################
1.113 bowersj2 1179:
1180: =pod
1181:
1.256 matthew 1182: =item * create_workbook
1.255 matthew 1183:
1184: Create an Excel worksheet. If it fails, output message on the
1185: request object and return undefs.
1186:
1187: Inputs: Apache request object
1188:
1189: Returns (undef) on failure,
1190: Excel worksheet object, scalar with filename, and formats
1191: from &Apache::loncommon::define_excel_formats on success
1192:
1193: =cut
1194:
1195: ###############################################################
1196: ###############################################################
1197: sub create_workbook {
1198: my ($r) = @_;
1199: #
1200: # Create the excel spreadsheet
1201: my $filename = '/prtspool/'.
1.258 albertel 1202: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1203: time.'_'.rand(1000000000).'.xls';
1204: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1205: if (! defined($workbook)) {
1206: $r->log_error("Error creating excel spreadsheet $filename: $!");
1207: $r->print('<p>'.&mt("Unable to create new Excel file. ".
1208: "This error has been logged. ".
1209: "Please alert your LON-CAPA administrator").
1210: '</p>');
1211: return (undef);
1212: }
1213: #
1214: $workbook->set_tempdir('/home/httpd/perl/tmp');
1215: #
1216: my $format = &Apache::loncommon::define_excel_formats($workbook);
1217: return ($workbook,$filename,$format);
1218: }
1219:
1220: ###############################################################
1221: ###############################################################
1222:
1223: =pod
1224:
1.256 matthew 1225: =item * create_text_file
1.113 bowersj2 1226:
1.256 matthew 1227: Create a file to write to and eventually make available to the usre.
1228: If file creation fails, outputs an error message on the request object and
1229: return undefs.
1.113 bowersj2 1230:
1.256 matthew 1231: Inputs: Apache request object, and file suffix
1.113 bowersj2 1232:
1.256 matthew 1233: Returns (undef) on failure,
1234: Filehandle and filename on success.
1.113 bowersj2 1235:
1236: =cut
1237:
1.256 matthew 1238: ###############################################################
1239: ###############################################################
1240: sub create_text_file {
1241: my ($r,$suffix) = @_;
1242: if (! defined($suffix)) { $suffix = 'txt'; };
1243: my $fh;
1244: my $filename = '/prtspool/'.
1.258 albertel 1245: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1246: time.'_'.rand(1000000000).'.'.$suffix;
1247: $fh = Apache::File->new('>/home/httpd'.$filename);
1248: if (! defined($fh)) {
1249: $r->log_error("Couldn't open $filename for output $!");
1250: $r->print("Problems occured in creating the output file. ".
1251: "This error has been logged. ".
1252: "Please alert your LON-CAPA administrator.");
1.113 bowersj2 1253: }
1.256 matthew 1254: return ($fh,$filename)
1.113 bowersj2 1255: }
1256:
1257:
1.256 matthew 1258: =pod
1.113 bowersj2 1259:
1260: =back
1261:
1262: =cut
1.37 matthew 1263:
1264: ###############################################################
1.33 matthew 1265: ## Home server <option> list generating code ##
1266: ###############################################################
1.35 matthew 1267:
1.45 matthew 1268: =pod
1269:
1.112 bowersj2 1270: =head1 Home Server option list generating code
1271:
1272: =over 4
1273:
1274: =item * get_domains()
1.35 matthew 1275:
1276: Returns an array containing each of the domains listed in the hosts.tab
1277: file.
1278:
1279: =cut
1280:
1281: #-------------------------------------------
1.34 matthew 1282: sub get_domains {
1283: # The code below was stolen from "The Perl Cookbook", p 102, 1st ed.
1284: my @domains;
1285: my %seen;
1.356 albertel 1286: foreach my $dom (sort(values(%Apache::lonnet::hostdom))) {
1287: push(@domains,$dom) unless $seen{$dom}++;
1.34 matthew 1288: }
1289: return @domains;
1290: }
1.88 www 1291:
1.169 www 1292: # ------------------------------------------
1293:
1294: sub domain_select {
1295: my ($name,$value,$multiple)=@_;
1296: my %domains=map {
1297: $_ => $_.' '.$Apache::lonnet::domaindescription{$_}
1298: } &get_domains;
1299: if ($multiple) {
1300: $domains{''}=&mt('Any domain');
1.287 albertel 1301: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1302: } else {
1303: return &select_form($name,$value,%domains);
1304: }
1305: }
1306:
1.282 albertel 1307: #-------------------------------------------
1308:
1309: =pod
1310:
1.287 albertel 1311: =item * multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1312:
1313: Returns a string containing a <select> element int multiple mode
1314:
1315:
1316: Args:
1317: $name - name of the <select> element
1318: $value - sclara or array ref of values that should already be selected
1319: $size - number of rows long the select element is
1.283 albertel 1320: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1321: (shown text should already have been &mt())
1.284 albertel 1322: $order - (optional) array ref of the order to show the elments in
1.283 albertel 1323:
1.282 albertel 1324: =cut
1325:
1326: #-------------------------------------------
1.169 www 1327: sub multiple_select_form {
1.284 albertel 1328: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1329: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1330: my $output='';
1.191 matthew 1331: if (! defined($size)) {
1332: $size = 4;
1.283 albertel 1333: if (scalar(keys(%$hash))<4) {
1334: $size = scalar(keys(%$hash));
1.191 matthew 1335: }
1336: }
1.169 www 1337: $output.="\n<select name='$name' size='$size' multiple='1'>";
1.286 banghart 1338: my @order = ref($order) ? @$order
1.284 albertel 1339: : sort(keys(%$hash));
1340: foreach my $key (@order) {
1.356 albertel 1341: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1342: $output.='selected="selected" ' if ($selected{$key});
1343: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1344: }
1345: $output.="</select>\n";
1346: return $output;
1347: }
1348:
1.88 www 1349: #-------------------------------------------
1350:
1351: =pod
1352:
1.112 bowersj2 1353: =item * select_form($defdom,$name,%hash)
1.88 www 1354:
1355: Returns a string containing a <select name='$name' size='1'> form to
1356: allow a user to select options from a hash option_name => displayed text.
1357: See lonrights.pm for an example invocation and use.
1358:
1359: =cut
1360:
1361: #-------------------------------------------
1362: sub select_form {
1363: my ($def,$name,%hash) = @_;
1364: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1.128 albertel 1365: my @keys;
1366: if (exists($hash{'select_form_order'})) {
1367: @keys=@{$hash{'select_form_order'}};
1368: } else {
1369: @keys=sort(keys(%hash));
1370: }
1.356 albertel 1371: foreach my $key (@keys) {
1372: $selectform.=
1373: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
1374: ($key eq $def ? 'selected="selected" ' : '').
1375: ">".&mt($hash{$key})."</option>\n";
1.88 www 1376: }
1377: $selectform.="</select>";
1378: return $selectform;
1379: }
1380:
1.475 www 1381: # For display filters
1382:
1383: sub display_filter {
1384: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 1385: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.475 www 1386: return '<nobr><label>'.&mt('Records [_1]',
1387: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
1388: (&mt('all'),10,20,50,100,1000,10000))).
1.478 www 1389: '</label></nobr> <nobr>'.
1.475 www 1390: &mt('Filter [_1]',
1.477 www 1391: &select_form($env{'form.displayfilter'},
1392: 'displayfilter',
1393: ('currentfolder' => 'Current folder/page',
1394: 'containing' => 'Containing phrase',
1395: 'none' => 'None'))).
1.478 www 1396: '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></nobr>';
1.475 www 1397: }
1398:
1.167 www 1399: sub gradeleveldescription {
1400: my $gradelevel=shift;
1401: my %gradelevels=(0 => 'Not specified',
1402: 1 => 'Grade 1',
1403: 2 => 'Grade 2',
1404: 3 => 'Grade 3',
1405: 4 => 'Grade 4',
1406: 5 => 'Grade 5',
1407: 6 => 'Grade 6',
1408: 7 => 'Grade 7',
1409: 8 => 'Grade 8',
1410: 9 => 'Grade 9',
1411: 10 => 'Grade 10',
1412: 11 => 'Grade 11',
1413: 12 => 'Grade 12',
1414: 13 => 'Grade 13',
1415: 14 => '100 Level',
1416: 15 => '200 Level',
1417: 16 => '300 Level',
1418: 17 => '400 Level',
1419: 18 => 'Graduate Level');
1420: return &mt($gradelevels{$gradelevel});
1421: }
1422:
1.163 www 1423: sub select_level_form {
1424: my ($deflevel,$name)=@_;
1425: unless ($deflevel) { $deflevel=0; }
1.167 www 1426: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1427: for (my $i=0; $i<=18; $i++) {
1428: $selectform.="<option value=\"$i\" ".
1.253 albertel 1429: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 1430: ">".&gradeleveldescription($i)."</option>\n";
1431: }
1432: $selectform.="</select>";
1433: return $selectform;
1.163 www 1434: }
1.167 www 1435:
1.35 matthew 1436: #-------------------------------------------
1437:
1.45 matthew 1438: =pod
1439:
1.112 bowersj2 1440: =item * select_dom_form($defdom,$name,$includeempty)
1.35 matthew 1441:
1442: Returns a string containing a <select name='$name' size='1'> form to
1443: allow a user to select the domain to preform an operation in.
1444: See loncreateuser.pm for an example invocation and use.
1445:
1.90 www 1446: If the $includeempty flag is set, it also includes an empty choice ("no domain
1447: selected");
1448:
1.35 matthew 1449: =cut
1450:
1451: #-------------------------------------------
1.34 matthew 1452: sub select_dom_form {
1.90 www 1453: my ($defdom,$name,$includeempty) = @_;
1.34 matthew 1454: my @domains = get_domains();
1.90 www 1455: if ($includeempty) { @domains=('',@domains); }
1.34 matthew 1456: my $selectdomain = "<select name=\"$name\" size=\"1\">\n";
1.356 albertel 1457: foreach my $dom (@domains) {
1458: $selectdomain.="<option value=\"$dom\" ".
1459: ($dom eq $defdom ? 'selected="selected" ' : '').
1460: ">$dom</option>\n";
1.34 matthew 1461: }
1462: $selectdomain.="</select>";
1463: return $selectdomain;
1464: }
1465:
1.35 matthew 1466: #-------------------------------------------
1467:
1.45 matthew 1468: =pod
1469:
1.112 bowersj2 1470: =item * get_library_servers($domain)
1.35 matthew 1471:
1472: Returns a hash which contains keys like '103l3' and values like
1473: 'kirk.lite.msu.edu'. All of the keys will be for machines in the
1474: given $domain.
1475:
1476: =cut
1477:
1478: #-------------------------------------------
1.52 matthew 1479: sub get_library_servers {
1.33 matthew 1480: my $domain = shift;
1.52 matthew 1481: my %library_servers;
1.356 albertel 1482: foreach my $hostid (keys(%Apache::lonnet::libserv)) {
1483: if ($Apache::lonnet::hostdom{$hostid} eq $domain) {
1484: $library_servers{$hostid} = $Apache::lonnet::hostname{$hostid};
1.33 matthew 1485: }
1486: }
1.52 matthew 1487: return %library_servers;
1.33 matthew 1488: }
1489:
1.35 matthew 1490: #-------------------------------------------
1491:
1.45 matthew 1492: =pod
1493:
1.112 bowersj2 1494: =item * home_server_option_list($domain)
1.35 matthew 1495:
1496: returns a string which contains an <option> list to be used in a
1497: <select> form input. See loncreateuser.pm for an example.
1498:
1499: =cut
1500:
1501: #-------------------------------------------
1.33 matthew 1502: sub home_server_option_list {
1503: my $domain = shift;
1.52 matthew 1504: my %servers = &get_library_servers($domain);
1.33 matthew 1505: my $result = '';
1.356 albertel 1506: foreach my $hostid (sort(keys(%servers))) {
1.33 matthew 1507: $result.=
1.356 albertel 1508: '<option value="'.$hostid.'">'.
1509: $hostid.' '.$servers{$hostid}."</option>\n";
1.33 matthew 1510: }
1511: return $result;
1512: }
1.112 bowersj2 1513:
1514: =pod
1515:
1516: =back
1517:
1518: =cut
1.87 matthew 1519:
1520: ###############################################################
1.112 bowersj2 1521: ## Decoding User Agent ##
1.87 matthew 1522: ###############################################################
1523:
1524: =pod
1525:
1.112 bowersj2 1526: =head1 Decoding the User Agent
1527:
1528: =over 4
1529:
1530: =item * &decode_user_agent()
1.87 matthew 1531:
1532: Inputs: $r
1533:
1534: Outputs:
1535:
1536: =over 4
1537:
1.112 bowersj2 1538: =item * $httpbrowser
1.87 matthew 1539:
1.112 bowersj2 1540: =item * $clientbrowser
1.87 matthew 1541:
1.112 bowersj2 1542: =item * $clientversion
1.87 matthew 1543:
1.112 bowersj2 1544: =item * $clientmathml
1.87 matthew 1545:
1.112 bowersj2 1546: =item * $clientunicode
1.87 matthew 1547:
1.112 bowersj2 1548: =item * $clientos
1.87 matthew 1549:
1550: =back
1551:
1.157 matthew 1552: =back
1553:
1.87 matthew 1554: =cut
1555:
1556: ###############################################################
1557: ###############################################################
1558: sub decode_user_agent {
1.247 albertel 1559: my ($r)=@_;
1.87 matthew 1560: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
1561: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
1562: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 1563: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 1564: my $clientbrowser='unknown';
1565: my $clientversion='0';
1566: my $clientmathml='';
1567: my $clientunicode='0';
1568: for (my $i=0;$i<=$#browsertype;$i++) {
1569: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
1570: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
1571: $clientbrowser=$bname;
1572: $httpbrowser=~/$vreg/i;
1573: $clientversion=$1;
1574: $clientmathml=($clientversion>=$minv);
1575: $clientunicode=($clientversion>=$univ);
1576: }
1577: }
1578: my $clientos='unknown';
1579: if (($httpbrowser=~/linux/i) ||
1580: ($httpbrowser=~/unix/i) ||
1581: ($httpbrowser=~/ux/i) ||
1582: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
1583: if (($httpbrowser=~/vax/i) ||
1584: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
1585: if ($httpbrowser=~/next/i) { $clientos='next'; }
1586: if (($httpbrowser=~/mac/i) ||
1587: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1588: if ($httpbrowser=~/win/i) { $clientos='win'; }
1589: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1590: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1591: $clientunicode,$clientos,);
1592: }
1593:
1.32 matthew 1594: ###############################################################
1595: ## Authentication changing form generation subroutines ##
1596: ###############################################################
1597: ##
1598: ## All of the authform_xxxxxxx subroutines take their inputs in a
1599: ## hash, and have reasonable default values.
1600: ##
1601: ## formname = the name given in the <form> tag.
1.35 matthew 1602: #-------------------------------------------
1603:
1.45 matthew 1604: =pod
1605:
1.112 bowersj2 1606: =head1 Authentication Routines
1607:
1608: =over 4
1609:
1610: =item * authform_xxxxxx
1.35 matthew 1611:
1612: The authform_xxxxxx subroutines provide javascript and html forms which
1613: handle some of the conveniences required for authentication forms.
1614: This is not an optimal method, but it works.
1615:
1616: See loncreateuser.pm for invocation and use examples.
1617:
1618: =over 4
1619:
1.112 bowersj2 1620: =item * authform_header
1.35 matthew 1621:
1.112 bowersj2 1622: =item * authform_authorwarning
1.35 matthew 1623:
1.112 bowersj2 1624: =item * authform_nochange
1.35 matthew 1625:
1.112 bowersj2 1626: =item * authform_kerberos
1.35 matthew 1627:
1.112 bowersj2 1628: =item * authform_internal
1.35 matthew 1629:
1.112 bowersj2 1630: =item * authform_filesystem
1.35 matthew 1631:
1632: =back
1633:
1.157 matthew 1634: =back
1635:
1.35 matthew 1636: =cut
1637:
1638: #-------------------------------------------
1.32 matthew 1639: sub authform_header{
1640: my %in = (
1641: formname => 'cu',
1.80 albertel 1642: kerb_def_dom => '',
1.32 matthew 1643: @_,
1644: );
1645: $in{'formname'} = 'document.' . $in{'formname'};
1646: my $result='';
1.80 albertel 1647:
1648: #---------------------------------------------- Code for upper case translation
1649: my $Javascript_toUpperCase;
1650: unless ($in{kerb_def_dom}) {
1651: $Javascript_toUpperCase =<<"END";
1652: switch (choice) {
1653: case 'krb': currentform.elements[choicearg].value =
1654: currentform.elements[choicearg].value.toUpperCase();
1655: break;
1656: default:
1657: }
1658: END
1659: } else {
1660: $Javascript_toUpperCase = "";
1661: }
1662:
1.165 raeburn 1663: my $radioval = "'nochange'";
1.174 matthew 1664: if (exists($in{'curr_authtype'}) &&
1665: defined($in{'curr_authtype'}) &&
1666: $in{'curr_authtype'} ne '') {
1667: $radioval = "'$in{'curr_authtype'}arg'";
1668: }
1.165 raeburn 1669: my $argfield = 'null';
1670: if ( grep/^mode$/,(keys %in) ) {
1671: if ($in{'mode'} eq 'modifycourse') {
1672: if ( grep/^curr_authtype$/,(keys %in) ) {
1673: $radioval = "'$in{'curr_authtype'}'";
1674: }
1675: if ( grep/^curr_autharg$/,(keys %in) ) {
1676: unless ($in{'curr_autharg'} eq '') {
1677: $argfield = "'$in{'curr_autharg'}'";
1678: }
1679: }
1680: }
1681: }
1682:
1.32 matthew 1683: $result.=<<"END";
1684: var current = new Object();
1.165 raeburn 1685: current.radiovalue = $radioval;
1686: current.argfield = $argfield;
1.32 matthew 1687:
1688: function changed_radio(choice,currentform) {
1689: var choicearg = choice + 'arg';
1690: // If a radio button in changed, we need to change the argfield
1691: if (current.radiovalue != choice) {
1692: current.radiovalue = choice;
1693: if (current.argfield != null) {
1694: currentform.elements[current.argfield].value = '';
1695: }
1696: if (choice == 'nochange') {
1697: current.argfield = null;
1698: } else {
1699: current.argfield = choicearg;
1700: switch(choice) {
1701: case 'krb':
1702: currentform.elements[current.argfield].value =
1703: "$in{'kerb_def_dom'}";
1704: break;
1705: default:
1706: break;
1707: }
1708: }
1709: }
1710: return;
1711: }
1.22 www 1712:
1.32 matthew 1713: function changed_text(choice,currentform) {
1714: var choicearg = choice + 'arg';
1715: if (currentform.elements[choicearg].value !='') {
1.80 albertel 1716: $Javascript_toUpperCase
1.32 matthew 1717: // clear old field
1718: if ((current.argfield != choicearg) && (current.argfield != null)) {
1719: currentform.elements[current.argfield].value = '';
1720: }
1721: current.argfield = choicearg;
1722: }
1723: set_auth_radio_buttons(choice,currentform);
1724: return;
1.20 www 1725: }
1.32 matthew 1726:
1727: function set_auth_radio_buttons(newvalue,currentform) {
1728: var i=0;
1729: while (i < currentform.login.length) {
1730: if (currentform.login[i].value == newvalue) { break; }
1731: i++;
1732: }
1733: if (i == currentform.login.length) {
1734: return;
1735: }
1736: current.radiovalue = newvalue;
1737: currentform.login[i].checked = true;
1738: return;
1739: }
1740: END
1741: return $result;
1742: }
1743:
1744: sub authform_authorwarning{
1745: my $result='';
1.144 matthew 1746: $result='<i>'.
1747: &mt('As a general rule, only authors or co-authors should be '.
1748: 'filesystem authenticated '.
1749: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 1750: return $result;
1751: }
1752:
1753: sub authform_nochange{
1754: my %in = (
1755: formname => 'document.cu',
1756: kerb_def_dom => 'MSU.EDU',
1757: @_,
1758: );
1.281 albertel 1759: my $result = '<label>'.&mt('[_1] Do not change login data',
1.144 matthew 1760: '<input type="radio" name="login" value="nochange" '.
1761: 'checked="checked" onclick="'.
1.281 albertel 1762: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
1763: '</label>';
1.32 matthew 1764: return $result;
1765: }
1766:
1767: sub authform_kerberos{
1768: my %in = (
1769: formname => 'document.cu',
1770: kerb_def_dom => 'MSU.EDU',
1.80 albertel 1771: kerb_def_auth => 'krb4',
1.32 matthew 1772: @_,
1773: );
1.165 raeburn 1774: my ($check4,$check5,$krbarg);
1.80 albertel 1775: if ($in{'kerb_def_auth'} eq 'krb5') {
1776: $check5 = " checked=\"on\"";
1777: } else {
1778: $check4 = " checked=\"on\"";
1779: }
1.165 raeburn 1780: $krbarg = $in{'kerb_def_dom'};
1781:
1782: my $krbcheck = "";
1783: if ( grep/^curr_authtype$/,(keys %in) ) {
1784: if ($in{'curr_authtype'} =~ m/^krb/) {
1785: $krbcheck = " checked=\"on\"";
1786: if ( grep/^curr_autharg$/,(keys %in) ) {
1787: $krbarg = $in{'curr_autharg'};
1788: }
1789: }
1790: }
1791:
1.144 matthew 1792: my $jscall = "javascript:changed_radio('krb',$in{'formname'});";
1793: my $result .= &mt
1794: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 1795: '[_3] Version 4 [_4] Version 5 [_5]',
1796: '<label><input type="radio" name="login" value="krb" '.
1.165 raeburn 1797: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.$krbcheck.' />',
1.281 albertel 1798: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 1799: 'value="'.$krbarg.'" '.
1.144 matthew 1800: 'onchange="'.$jscall.'" />',
1.281 albertel 1801: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
1802: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
1803: '</label>');
1.32 matthew 1804: return $result;
1805: }
1806:
1807: sub authform_internal{
1808: my %args = (
1809: formname => 'document.cu',
1810: kerb_def_dom => 'MSU.EDU',
1811: @_,
1812: );
1.165 raeburn 1813:
1814: my $intcheck = "";
1815: my $intarg = 'value=""';
1816: if ( grep/^curr_authtype$/,(keys %args) ) {
1817: if ($args{'curr_authtype'} eq 'int') {
1818: $intcheck = " checked=\"on\"";
1819: if ( grep/^curr_autharg$/,(keys %args) ) {
1820: $intarg = "value=\"$args{'curr_autharg'}\"";
1821: }
1822: }
1823: }
1824:
1.144 matthew 1825: my $jscall = "javascript:changed_radio('int',$args{'formname'});";
1826: my $result.=&mt
1827: ('[_1] Internally authenticated (with initial password [_2])',
1.281 albertel 1828: '<label><input type="radio" name="login" value="int" '.$intcheck.
1.165 raeburn 1829: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.281 albertel 1830: '</label><input type="text" size="10" name="intarg" '.$intarg.
1.165 raeburn 1831: ' onchange="'.$jscall.'" />');
1.32 matthew 1832: return $result;
1833: }
1834:
1835: sub authform_local{
1836: my %in = (
1837: formname => 'document.cu',
1838: kerb_def_dom => 'MSU.EDU',
1839: @_,
1840: );
1.165 raeburn 1841:
1842: my $loccheck = "";
1843: my $locarg = 'value=""';
1844: if ( grep/^curr_authtype$/,(keys %in) ) {
1845: if ($in{'curr_authtype'} eq 'loc') {
1846: $loccheck = " checked=\"on\"";
1847: if ( grep/^curr_autharg$/,(keys %in) ) {
1848: $locarg = "value=\"$in{'curr_autharg'}\"";
1849: }
1850: }
1851: }
1852:
1.144 matthew 1853: my $jscall = "javascript:changed_radio('loc',$in{'formname'});";
1.160 matthew 1854: my $result.=&mt('[_1] Local Authentication with argument [_2]',
1.281 albertel 1855: '<label><input type="radio" name="login" value="loc" '.$loccheck.
1.165 raeburn 1856: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.281 albertel 1857: '</label><input type="text" size="10" name="locarg" '.$locarg.
1.165 raeburn 1858: ' onchange="'.$jscall.'" />');
1.32 matthew 1859: return $result;
1860: }
1861:
1862: sub authform_filesystem{
1863: my %in = (
1864: formname => 'document.cu',
1865: kerb_def_dom => 'MSU.EDU',
1866: @_,
1867: );
1.144 matthew 1868: my $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
1869: my $result.= &mt
1870: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 1871: '<label><input type="radio" name="login" value="fsys" '.
1.144 matthew 1872: 'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.281 albertel 1873: '</label><input type="text" size="10" name="fsysarg" value="" '.
1.144 matthew 1874: 'onchange="'.$jscall.'" />');
1.32 matthew 1875: return $result;
1876: }
1877:
1.80 albertel 1878: ###############################################################
1879: ## Get Authentication Defaults for Domain ##
1880: ###############################################################
1881:
1882: =pod
1883:
1.112 bowersj2 1884: =head1 Domains and Authentication
1885:
1886: Returns default authentication type and an associated argument as
1887: listed in file 'domain.tab'.
1888:
1889: =over 4
1890:
1891: =item * get_auth_defaults
1.80 albertel 1892:
1893: get_auth_defaults($target_domain) returns the default authentication
1894: type and an associated argument (initial password or a kerberos domain).
1895: These values are stored in lonTabs/domain.tab
1896:
1897: ($def_auth, $def_arg) = &get_auth_defaults($target_domain);
1898:
1899: If target_domain is not found in domain.tab, returns nothing ('').
1900:
1901: =cut
1902:
1903: #-------------------------------------------
1904: sub get_auth_defaults {
1905: my $domain=shift;
1906: return ($Apache::lonnet::domain_auth_def{$domain},$Apache::lonnet::domain_auth_arg_def{$domain});
1907: }
1908: ###############################################################
1909: ## End Get Authentication Defaults for Domain ##
1910: ###############################################################
1911:
1912: ###############################################################
1913: ## Get Kerberos Defaults for Domain ##
1914: ###############################################################
1915: ##
1916: ## Returns default kerberos version and an associated argument
1917: ## as listed in file domain.tab. If not listed, provides
1918: ## appropriate default domain and kerberos version.
1919: ##
1920: #-------------------------------------------
1921:
1922: =pod
1923:
1.112 bowersj2 1924: =item * get_kerberos_defaults
1.80 albertel 1925:
1926: get_kerberos_defaults($target_domain) returns the default kerberos
1927: version and domain. If not found in domain.tabs, it defaults to
1928: version 4 and the domain of the server.
1929:
1930: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
1931:
1932: =cut
1933:
1934: #-------------------------------------------
1935: sub get_kerberos_defaults {
1936: my $domain=shift;
1937: my ($krbdef,$krbdefdom) =
1938: &Apache::loncommon::get_auth_defaults($domain);
1939: unless ($krbdef =~/^krb/ && $krbdefdom) {
1940: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
1941: my $krbdefdom=$1;
1942: $krbdefdom=~tr/a-z/A-Z/;
1943: $krbdef = "krb4";
1944: }
1945: return ($krbdef,$krbdefdom);
1946: }
1.112 bowersj2 1947:
1948: =pod
1949:
1950: =back
1951:
1952: =cut
1.32 matthew 1953:
1.46 matthew 1954: ###############################################################
1955: ## Thesaurus Functions ##
1956: ###############################################################
1.20 www 1957:
1.46 matthew 1958: =pod
1.20 www 1959:
1.112 bowersj2 1960: =head1 Thesaurus Functions
1961:
1962: =over 4
1963:
1964: =item * initialize_keywords
1.46 matthew 1965:
1966: Initializes the package variable %Keywords if it is empty. Uses the
1967: package variable $thesaurus_db_file.
1968:
1969: =cut
1970:
1971: ###################################################
1972:
1973: sub initialize_keywords {
1974: return 1 if (scalar keys(%Keywords));
1975: # If we are here, %Keywords is empty, so fill it up
1976: # Make sure the file we need exists...
1977: if (! -e $thesaurus_db_file) {
1978: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
1979: " failed because it does not exist");
1980: return 0;
1981: }
1982: # Set up the hash as a database
1983: my %thesaurus_db;
1984: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 1985: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 1986: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
1987: $thesaurus_db_file);
1988: return 0;
1989: }
1990: # Get the average number of appearances of a word.
1991: my $avecount = $thesaurus_db{'average.count'};
1992: # Put keywords (those that appear > average) into %Keywords
1993: while (my ($word,$data)=each (%thesaurus_db)) {
1994: my ($count,undef) = split /:/,$data;
1995: $Keywords{$word}++ if ($count > $avecount);
1996: }
1997: untie %thesaurus_db;
1998: # Remove special values from %Keywords.
1.356 albertel 1999: foreach my $value ('total.count','average.count') {
2000: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.46 matthew 2001: }
2002: return 1;
2003: }
2004:
2005: ###################################################
2006:
2007: =pod
2008:
1.112 bowersj2 2009: =item * keyword($word)
1.46 matthew 2010:
2011: Returns true if $word is a keyword. A keyword is a word that appears more
2012: than the average number of times in the thesaurus database. Calls
2013: &initialize_keywords
2014:
2015: =cut
2016:
2017: ###################################################
1.20 www 2018:
2019: sub keyword {
1.46 matthew 2020: return if (!&initialize_keywords());
2021: my $word=lc(shift());
2022: $word=~s/\W//g;
2023: return exists($Keywords{$word});
1.20 www 2024: }
1.46 matthew 2025:
2026: ###############################################################
2027:
2028: =pod
1.20 www 2029:
1.112 bowersj2 2030: =item * get_related_words
1.46 matthew 2031:
1.160 matthew 2032: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 2033: an array of words. If the keyword is not in the thesaurus, an empty array
2034: will be returned. The order of the words returned is determined by the
2035: database which holds them.
2036:
2037: Uses global $thesaurus_db_file.
2038:
2039: =cut
2040:
2041: ###############################################################
2042: sub get_related_words {
2043: my $keyword = shift;
2044: my %thesaurus_db;
2045: if (! -e $thesaurus_db_file) {
2046: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
2047: "failed because the file does not exist");
2048: return ();
2049: }
2050: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2051: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2052: return ();
2053: }
2054: my @Words=();
1.429 www 2055: my $count=0;
1.46 matthew 2056: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 2057: # The first element is the number of times
2058: # the word appears. We do not need it now.
1.429 www 2059: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
2060: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
2061: my $threshold=$mostfrequentcount/10;
2062: foreach my $possibleword (@RelatedWords) {
2063: my ($word,$wordcount)=split(/\,/,$possibleword);
2064: if ($wordcount>$threshold) {
2065: push(@Words,$word);
2066: $count++;
2067: if ($count>10) { last; }
2068: }
1.20 www 2069: }
2070: }
1.46 matthew 2071: untie %thesaurus_db;
2072: return @Words;
1.14 harris41 2073: }
1.46 matthew 2074:
1.112 bowersj2 2075: =pod
2076:
2077: =back
2078:
2079: =cut
1.61 www 2080:
2081: # -------------------------------------------------------------- Plaintext name
1.81 albertel 2082: =pod
2083:
1.112 bowersj2 2084: =head1 User Name Functions
2085:
2086: =over 4
2087:
1.226 albertel 2088: =item * plainname($uname,$udom,$first)
1.81 albertel 2089:
1.112 bowersj2 2090: Takes a users logon name and returns it as a string in
1.226 albertel 2091: "first middle last generation" form
2092: if $first is set to 'lastname' then it returns it as
2093: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 2094:
2095: =cut
1.61 www 2096:
1.295 www 2097:
1.81 albertel 2098: ###############################################################
1.61 www 2099: sub plainname {
1.226 albertel 2100: my ($uname,$udom,$first)=@_;
1.295 www 2101: my %names=&getnames($uname,$udom);
1.226 albertel 2102: my $name=&Apache::lonnet::format_name($names{'firstname'},
2103: $names{'middlename'},
2104: $names{'lastname'},
2105: $names{'generation'},$first);
2106: $name=~s/^\s+//;
1.62 www 2107: $name=~s/\s+$//;
2108: $name=~s/\s+/ /g;
1.353 albertel 2109: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 2110: return $name;
1.61 www 2111: }
1.66 www 2112:
2113: # -------------------------------------------------------------------- Nickname
1.81 albertel 2114: =pod
2115:
1.112 bowersj2 2116: =item * nickname($uname,$udom)
1.81 albertel 2117:
2118: Gets a users name and returns it as a string as
2119:
2120: ""nickname""
1.66 www 2121:
1.81 albertel 2122: if the user has a nickname or
2123:
2124: "first middle last generation"
2125:
2126: if the user does not
2127:
2128: =cut
1.66 www 2129:
2130: sub nickname {
2131: my ($uname,$udom)=@_;
1.295 www 2132: my %names=&getnames($uname,$udom);
1.68 albertel 2133: my $name=$names{'nickname'};
1.66 www 2134: if ($name) {
2135: $name='"'.$name.'"';
2136: } else {
2137: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
2138: $names{'lastname'}.' '.$names{'generation'};
2139: $name=~s/\s+$//;
2140: $name=~s/\s+/ /g;
2141: }
2142: return $name;
2143: }
2144:
1.295 www 2145: sub getnames {
2146: my ($uname,$udom)=@_;
1.433 albertel 2147: if ($udom eq 'public' && $uname eq 'public') {
2148: return ('lastname' => &mt('Public'));
2149: }
1.295 www 2150: my $id=$uname.':'.$udom;
2151: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
2152: if ($cached) {
2153: return %{$names};
2154: } else {
2155: my %loadnames=&Apache::lonnet::get('environment',
2156: ['firstname','middlename','lastname','generation','nickname'],
2157: $udom,$uname);
2158: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
2159: return %loadnames;
2160: }
2161: }
1.61 www 2162:
1.466 albertel 2163: sub getemails {
2164: my ($uname,$udom)=@_;
2165: if ($udom eq 'public' && $uname eq 'public') {
2166: return;
2167: }
1.467 www 2168: if (!$udom) { $udom=$env{'user.domain'}; }
2169: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 2170: my $id=$uname.':'.$udom;
2171: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
2172: if ($cached) {
2173: return %{$names};
2174: } else {
2175: my %loadnames=&Apache::lonnet::get('environment',
2176: ['notification','critnotification',
2177: 'permanentemail'],
2178: $udom,$uname);
2179: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
2180: return %loadnames;
2181: }
2182: }
2183:
1.61 www 2184: # ------------------------------------------------------------------ Screenname
1.81 albertel 2185:
2186: =pod
2187:
1.112 bowersj2 2188: =item * screenname($uname,$udom)
1.81 albertel 2189:
2190: Gets a users screenname and returns it as a string
2191:
2192: =cut
1.61 www 2193:
2194: sub screenname {
2195: my ($uname,$udom)=@_;
1.258 albertel 2196: if ($uname eq $env{'user.name'} &&
2197: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 2198: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 2199: return $names{'screenname'};
1.62 www 2200: }
2201:
1.212 albertel 2202:
1.62 www 2203: # ------------------------------------------------------------- Message Wrapper
2204:
2205: sub messagewrapper {
1.369 www 2206: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 2207: return
1.441 albertel 2208: '<a href="/adm/email?compose=individual&'.
2209: 'recname='.$username.'&recdom='.$domain.
2210: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 2211: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 2212: }
2213: # --------------------------------------------------------------- Notes Wrapper
2214:
2215: sub noteswrapper {
2216: my ($link,$un,$do)=@_;
2217: return
2218: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 2219: }
2220: # ------------------------------------------------------------- Aboutme Wrapper
2221:
2222: sub aboutmewrapper {
1.166 www 2223: my ($link,$username,$domain,$target)=@_;
1.447 raeburn 2224: if (!defined($username) && !defined($domain)) {
2225: return;
2226: }
1.205 www 2227: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.454 banghart 2228: ($target?' target="$target"':'').' title="'.&mt("View this user's personal page").'">'.$link.'</a>';
1.62 www 2229: }
2230:
2231: # ------------------------------------------------------------ Syllabus Wrapper
2232:
2233:
2234: sub syllabuswrapper {
1.109 matthew 2235: my ($linktext,$coursedir,$domain,$fontcolor)=@_;
2236: if ($fontcolor) {
2237: $linktext='<font color="'.$fontcolor.'">'.$linktext.'</font>';
2238: }
1.208 matthew 2239: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 2240: }
1.14 harris41 2241:
1.208 matthew 2242: sub track_student_link {
1.268 albertel 2243: my ($linktext,$sname,$sdom,$target,$start) = @_;
2244: my $link ="/adm/trackstudent?";
1.208 matthew 2245: my $title = 'View recent activity';
2246: if (defined($sname) && $sname !~ /^\s*$/ &&
2247: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 2248: $link .= "selected_student=$sname:$sdom";
1.208 matthew 2249: $title .= ' of this student';
1.268 albertel 2250: }
1.208 matthew 2251: if (defined($target) && $target !~ /^\s*$/) {
2252: $target = qq{target="$target"};
2253: } else {
2254: $target = '';
2255: }
1.268 albertel 2256: if ($start) { $link.='&start='.$start; }
1.448 albertel 2257:
2258: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
2259: &help_open_topic('View_recent_activity');
1.208 matthew 2260: }
2261:
1.112 bowersj2 2262: =pod
2263:
2264: =back
2265:
2266: =head1 Access .tab File Data
2267:
2268: =over 4
2269:
2270: =item * languageids()
2271:
2272: returns list of all language ids
2273:
2274: =cut
2275:
1.14 harris41 2276: sub languageids {
1.16 harris41 2277: return sort(keys(%language));
1.14 harris41 2278: }
2279:
1.112 bowersj2 2280: =pod
2281:
2282: =item * languagedescription()
2283:
2284: returns description of a specified language id
2285:
2286: =cut
2287:
1.14 harris41 2288: sub languagedescription {
1.125 www 2289: my $code=shift;
2290: return ($supported_language{$code}?'* ':'').
2291: $language{$code}.
1.126 www 2292: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 2293: }
2294:
2295: sub plainlanguagedescription {
2296: my $code=shift;
2297: return $language{$code};
2298: }
2299:
2300: sub supportedlanguagecode {
2301: my $code=shift;
2302: return $supported_language{$code};
1.97 www 2303: }
2304:
1.112 bowersj2 2305: =pod
2306:
2307: =item * copyrightids()
2308:
2309: returns list of all copyrights
2310:
2311: =cut
2312:
2313: sub copyrightids {
2314: return sort(keys(%cprtag));
2315: }
2316:
2317: =pod
2318:
2319: =item * copyrightdescription()
2320:
2321: returns description of a specified copyright id
2322:
2323: =cut
2324:
2325: sub copyrightdescription {
1.166 www 2326: return &mt($cprtag{shift(@_)});
1.112 bowersj2 2327: }
1.197 matthew 2328:
2329: =pod
2330:
1.192 taceyjo1 2331: =item * source_copyrightids()
2332:
2333: returns list of all source copyrights
2334:
2335: =cut
2336:
2337: sub source_copyrightids {
2338: return sort(keys(%scprtag));
2339: }
2340:
2341: =pod
2342:
2343: =item * source_copyrightdescription()
2344:
2345: returns description of a specified source copyright id
2346:
2347: =cut
2348:
2349: sub source_copyrightdescription {
2350: return &mt($scprtag{shift(@_)});
2351: }
1.112 bowersj2 2352:
2353: =pod
2354:
2355: =item * filecategories()
2356:
2357: returns list of all file categories
2358:
2359: =cut
2360:
2361: sub filecategories {
2362: return sort(keys(%category_extensions));
2363: }
2364:
2365: =pod
2366:
2367: =item * filecategorytypes()
2368:
2369: returns list of file types belonging to a given file
2370: category
2371:
2372: =cut
2373:
2374: sub filecategorytypes {
1.356 albertel 2375: my ($cat) = @_;
2376: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 2377: }
2378:
2379: =pod
2380:
2381: =item * fileembstyle()
2382:
2383: returns embedding style for a specified file type
2384:
2385: =cut
2386:
2387: sub fileembstyle {
2388: return $fe{lc(shift(@_))};
1.169 www 2389: }
2390:
1.351 www 2391: sub filemimetype {
2392: return $fm{lc(shift(@_))};
2393: }
2394:
1.169 www 2395:
2396: sub filecategoryselect {
2397: my ($name,$value)=@_;
1.189 matthew 2398: return &select_form($value,$name,
1.169 www 2399: '' => &mt('Any category'),
2400: map { $_,$_ } sort(keys(%category_extensions)));
1.112 bowersj2 2401: }
2402:
2403: =pod
2404:
2405: =item * filedescription()
2406:
2407: returns description for a specified file type
2408:
2409: =cut
2410:
2411: sub filedescription {
1.188 matthew 2412: my $file_description = $fd{lc(shift())};
2413: $file_description =~ s:([\[\]]):~$1:g;
2414: return &mt($file_description);
1.112 bowersj2 2415: }
2416:
2417: =pod
2418:
2419: =item * filedescriptionex()
2420:
2421: returns description for a specified file type with
2422: extra formatting
2423:
2424: =cut
2425:
2426: sub filedescriptionex {
2427: my $ex=shift;
1.188 matthew 2428: my $file_description = $fd{lc($ex)};
2429: $file_description =~ s:([\[\]]):~$1:g;
2430: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 2431: }
2432:
2433: # End of .tab access
2434: =pod
2435:
2436: =back
2437:
2438: =cut
2439:
2440: # ------------------------------------------------------------------ File Types
2441: sub fileextensions {
2442: return sort(keys(%fe));
2443: }
2444:
1.97 www 2445: # ----------------------------------------------------------- Display Languages
2446: # returns a hash with all desired display languages
2447: #
2448:
2449: sub display_languages {
2450: my %languages=();
1.356 albertel 2451: foreach my $lang (&preferred_languages()) {
2452: $languages{$lang}=1;
1.97 www 2453: }
2454: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 2455: if ($env{'form.displaylanguage'}) {
1.356 albertel 2456: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
2457: $languages{$lang}=1;
1.97 www 2458: }
2459: }
2460: return %languages;
1.14 harris41 2461: }
2462:
1.117 www 2463: sub preferred_languages {
2464: my @languages=();
1.258 albertel 2465: if ($env{'course.'.$env{'request.course.id'}.'.languages'}) {
1.117 www 2466: @languages=(@languages,split(/\s*(\,|\;|\:)\s*/,
1.258 albertel 2467: $env{'course.'.$env{'request.course.id'}.'.languages'}));
1.177 www 2468: }
1.258 albertel 2469: if ($env{'environment.languages'}) {
1.459 albertel 2470: @languages=(@languages,
2471: split(/\s*(\,|\;|\:)\s*/,$env{'environment.languages'}));
1.118 www 2472: }
1.162 www 2473: my $browser=(split(/\;/,$ENV{'HTTP_ACCEPT_LANGUAGE'}))[0];
2474: if ($browser) {
2475: @languages=(@languages,split(/\s*(\,|\;|\:)\s*/,$browser));
2476: }
1.258 albertel 2477: if ($Apache::lonnet::domain_lang_def{$env{'user.domain'}}) {
1.118 www 2478: @languages=(@languages,
1.258 albertel 2479: $Apache::lonnet::domain_lang_def{$env{'user.domain'}});
1.118 www 2480: }
1.258 albertel 2481: if ($Apache::lonnet::domain_lang_def{$env{'request.role.domain'}}) {
1.118 www 2482: @languages=(@languages,
1.258 albertel 2483: $Apache::lonnet::domain_lang_def{$env{'request.role.domain'}});
1.118 www 2484: }
2485: if ($Apache::lonnet::domain_lang_def{
2486: $Apache::lonnet::perlvar{'lonDefDomain'}}) {
2487: @languages=(@languages,
2488: $Apache::lonnet::domain_lang_def{
2489: $Apache::lonnet::perlvar{'lonDefDomain'}});
2490: }
2491: # turn "en-ca" into "en-ca,en"
2492: my @genlanguages;
1.356 albertel 2493: foreach my $lang (@languages) {
2494: unless ($lang=~/\w/) { next; }
2495: push (@genlanguages,$lang);
2496: if ($lang=~/(\-|\_)/) {
2497: push(@genlanguages,(split(/(\-|\_)/,$lang))[0]);
1.118 www 2498: }
2499: }
2500: return @genlanguages;
1.117 www 2501: }
2502:
1.112 bowersj2 2503: ###############################################################
2504: ## Student Answer Attempts ##
2505: ###############################################################
2506:
2507: =pod
2508:
2509: =head1 Alternate Problem Views
2510:
2511: =over 4
2512:
2513: =item * get_previous_attempt($symb, $username, $domain, $course,
2514: $getattempt, $regexp, $gradesub)
2515:
2516: Return string with previous attempt on problem. Arguments:
2517:
2518: =over 4
2519:
2520: =item * $symb: Problem, including path
2521:
2522: =item * $username: username of the desired student
2523:
2524: =item * $domain: domain of the desired student
1.14 harris41 2525:
1.112 bowersj2 2526: =item * $course: Course ID
1.14 harris41 2527:
1.112 bowersj2 2528: =item * $getattempt: Leave blank for all attempts, otherwise put
2529: something
1.14 harris41 2530:
1.112 bowersj2 2531: =item * $regexp: if string matches this regexp, the string will be
2532: sent to $gradesub
1.14 harris41 2533:
1.112 bowersj2 2534: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 2535:
1.112 bowersj2 2536: =back
1.14 harris41 2537:
1.112 bowersj2 2538: The output string is a table containing all desired attempts, if any.
1.16 harris41 2539:
1.112 bowersj2 2540: =cut
1.1 albertel 2541:
2542: sub get_previous_attempt {
1.43 ng 2543: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 2544: my $prevattempts='';
1.43 ng 2545: no strict 'refs';
1.1 albertel 2546: if ($symb) {
1.3 albertel 2547: my (%returnhash)=
2548: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 2549: if ($returnhash{'version'}) {
2550: my %lasthash=();
2551: my $version;
2552: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 2553: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
2554: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 2555: }
1.1 albertel 2556: }
1.43 ng 2557: $prevattempts='<table border="0" width="100%"><tr><td bgcolor="#777777">';
1.40 ng 2558: $prevattempts.='<table border="0" width="100%"><tr bgcolor="#e6ffff"><td>History</td>';
1.356 albertel 2559: foreach my $key (sort(keys(%lasthash))) {
2560: my ($ign,@parts) = split(/\./,$key);
1.41 ng 2561: if ($#parts > 0) {
1.31 albertel 2562: my $data=$parts[-1];
2563: pop(@parts);
1.40 ng 2564: $prevattempts.='<td>Part '.join('.',@parts).'<br />'.$data.' </td>';
1.31 albertel 2565: } else {
1.41 ng 2566: if ($#parts == 0) {
2567: $prevattempts.='<th>'.$parts[0].'</th>';
2568: } else {
2569: $prevattempts.='<th>'.$ign.'</th>';
2570: }
1.31 albertel 2571: }
1.16 harris41 2572: }
1.40 ng 2573: if ($getattempt eq '') {
2574: for ($version=1;$version<=$returnhash{'version'};$version++) {
2575: $prevattempts.='</tr><tr bgcolor="#ffffe6"><td>Transaction '.$version.'</td>';
1.356 albertel 2576: foreach my $key (sort(keys(%lasthash))) {
1.40 ng 2577: my $value;
1.356 albertel 2578: if ($key =~ /timestamp/) {
2579: $value=scalar(localtime($returnhash{$version.':'.$key}));
1.40 ng 2580: } else {
1.356 albertel 2581: $value=$returnhash{$version.':'.$key};
1.40 ng 2582: }
1.369 www 2583: $prevattempts.='<td>'.&unescape($value).' </td>';
1.40 ng 2584: }
2585: }
1.1 albertel 2586: }
1.40 ng 2587: $prevattempts.='</tr><tr bgcolor="#ffffe6"><td>Current</td>';
1.356 albertel 2588: foreach my $key (sort(keys(%lasthash))) {
1.5 albertel 2589: my $value;
1.356 albertel 2590: if ($key =~ /timestamp/) {
2591: $value=scalar(localtime($lasthash{$key}));
1.5 albertel 2592: } else {
1.356 albertel 2593: $value=$lasthash{$key};
1.5 albertel 2594: }
1.369 www 2595: $value=&unescape($value);
1.356 albertel 2596: if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
1.40 ng 2597: $prevattempts.='<td>'.$value.' </td>';
1.16 harris41 2598: }
1.40 ng 2599: $prevattempts.='</tr></table></td></tr></table>';
1.1 albertel 2600: } else {
2601: $prevattempts='Nothing submitted - no attempts.';
2602: }
2603: } else {
2604: $prevattempts='No data.';
2605: }
1.10 albertel 2606: }
2607:
1.107 albertel 2608: sub relative_to_absolute {
2609: my ($url,$output)=@_;
2610: my $parser=HTML::TokeParser->new(\$output);
2611: my $token;
2612: my $thisdir=$url;
2613: my @rlinks=();
2614: while ($token=$parser->get_token) {
2615: if ($token->[0] eq 'S') {
2616: if ($token->[1] eq 'a') {
2617: if ($token->[2]->{'href'}) {
2618: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
2619: }
2620: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
2621: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
2622: } elsif ($token->[1] eq 'base') {
2623: $thisdir=$token->[2]->{'href'};
2624: }
2625: }
2626: }
2627: $thisdir=~s-/[^/]*$--;
1.356 albertel 2628: foreach my $link (@rlinks) {
2629: unless (($link=~/^http:\/\//i) ||
2630: ($link=~/^\//) ||
2631: ($link=~/^javascript:/i) ||
2632: ($link=~/^mailto:/i) ||
2633: ($link=~/^\#/)) {
2634: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
2635: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 2636: }
2637: }
2638: # -------------------------------------------------- Deal with Applet codebases
2639: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
2640: return $output;
2641: }
2642:
1.112 bowersj2 2643: =pod
2644:
2645: =item * get_student_view
2646:
2647: show a snapshot of what student was looking at
2648:
2649: =cut
2650:
1.10 albertel 2651: sub get_student_view {
1.186 albertel 2652: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 2653: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 2654: my (%form);
1.10 albertel 2655: my @elements=('symb','courseid','domain','username');
2656: foreach my $element (@elements) {
1.186 albertel 2657: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 2658: }
1.186 albertel 2659: if (defined($moreenv)) {
2660: %form=(%form,%{$moreenv});
2661: }
1.236 albertel 2662: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 2663: $feedurl=&Apache::lonnet::clutter($feedurl);
1.186 albertel 2664: my $userview=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 2665: $userview=~s/\<body[^\>]*\>//gi;
2666: $userview=~s/\<\/body\>//gi;
2667: $userview=~s/\<html\>//gi;
2668: $userview=~s/\<\/html\>//gi;
2669: $userview=~s/\<head\>//gi;
2670: $userview=~s/\<\/head\>//gi;
2671: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 2672: $userview=&relative_to_absolute($feedurl,$userview);
1.11 albertel 2673: return $userview;
2674: }
2675:
1.112 bowersj2 2676: =pod
2677:
2678: =item * get_student_answers()
2679:
2680: show a snapshot of how student was answering problem
2681:
2682: =cut
2683:
1.11 albertel 2684: sub get_student_answers {
1.100 sakharuk 2685: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 2686: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 2687: my (%moreenv);
1.11 albertel 2688: my @elements=('symb','courseid','domain','username');
2689: foreach my $element (@elements) {
1.186 albertel 2690: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 2691: }
1.186 albertel 2692: $moreenv{'grade_target'}='answer';
2693: %moreenv=(%form,%moreenv);
1.497 raeburn 2694: $feedurl = &Apache::lonnet::clutter($feedurl);
2695: &Apache::lonenc::check_encrypt(\$feedurl);
2696: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 2697: return $userview;
1.1 albertel 2698: }
1.116 albertel 2699:
2700: =pod
2701:
2702: =item * &submlink()
2703:
1.242 albertel 2704: Inputs: $text $uname $udom $symb $target
1.116 albertel 2705:
2706: Returns: A link to grades.pm such as to see the SUBM view of a student
2707:
2708: =cut
2709:
2710: ###############################################
2711: sub submlink {
1.242 albertel 2712: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 2713: if (!($uname && $udom)) {
2714: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 2715: &Apache::lonnet::whichuser($symb);
1.116 albertel 2716: if (!$symb) { $symb=$cursymb; }
2717: }
1.254 matthew 2718: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 2719: $symb=&escape($symb);
1.242 albertel 2720: if ($target) { $target="target=\"$target\""; }
2721: return '<a href="/adm/grades?&command=submission&'.
2722: 'symb='.$symb.'&student='.$uname.
2723: '&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
2724: }
2725: ##############################################
2726:
2727: =pod
2728:
2729: =item * &pgrdlink()
2730:
2731: Inputs: $text $uname $udom $symb $target
2732:
2733: Returns: A link to grades.pm such as to see the PGRD view of a student
2734:
2735: =cut
2736:
2737: ###############################################
2738: sub pgrdlink {
2739: my $link=&submlink(@_);
2740: $link=~s/(&command=submission)/$1&showgrading=yes/;
2741: return $link;
2742: }
2743: ##############################################
2744:
2745: =pod
2746:
2747: =item * &pprmlink()
2748:
2749: Inputs: $text $uname $udom $symb $target
2750:
2751: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 2752: student and a specific resource
1.242 albertel 2753:
2754: =cut
2755:
2756: ###############################################
2757: sub pprmlink {
2758: my ($text,$uname,$udom,$symb,$target)=@_;
2759: if (!($uname && $udom)) {
2760: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 2761: &Apache::lonnet::whichuser($symb);
1.242 albertel 2762: if (!$symb) { $symb=$cursymb; }
2763: }
1.254 matthew 2764: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 2765: $symb=&escape($symb);
1.242 albertel 2766: if ($target) { $target="target=\"$target\""; }
2767: return '<a href="/adm/parmset?&command=set&'.
2768: 'symb='.$symb.'&uname='.$uname.
2769: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 2770: }
2771: ##############################################
1.37 matthew 2772:
1.112 bowersj2 2773: =pod
2774:
2775: =back
2776:
2777: =cut
2778:
1.37 matthew 2779: ###############################################
1.51 www 2780:
2781:
2782: sub timehash {
2783: my @ltime=localtime(shift);
2784: return ( 'seconds' => $ltime[0],
2785: 'minutes' => $ltime[1],
2786: 'hours' => $ltime[2],
2787: 'day' => $ltime[3],
2788: 'month' => $ltime[4]+1,
2789: 'year' => $ltime[5]+1900,
2790: 'weekday' => $ltime[6],
2791: 'dayyear' => $ltime[7]+1,
2792: 'dlsav' => $ltime[8] );
2793: }
2794:
1.370 www 2795: sub utc_string {
2796: my ($date)=@_;
1.371 www 2797: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 2798: }
2799:
1.51 www 2800: sub maketime {
2801: my %th=@_;
2802: return POSIX::mktime(
2803: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 2804: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 2805: }
2806:
2807: #########################################
1.51 www 2808:
2809: sub findallcourses {
1.482 raeburn 2810: my ($roles,$uname,$udom) = @_;
1.355 albertel 2811: my %roles;
2812: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 2813: my %courses;
1.51 www 2814: my $now=time;
1.482 raeburn 2815: if (!defined($uname)) {
2816: $uname = $env{'user.name'};
2817: }
2818: if (!defined($udom)) {
2819: $udom = $env{'user.domain'};
2820: }
2821: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
2822: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
2823: if (!%roles) {
2824: %roles = (
2825: cc => 1,
2826: in => 1,
2827: ep => 1,
2828: ta => 1,
2829: cr => 1,
2830: st => 1,
2831: );
2832: }
2833: foreach my $entry (keys(%roleshash)) {
2834: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
2835: if ($trole =~ /^cr/) {
2836: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
2837: } else {
2838: next if (!exists($roles{$trole}));
2839: }
2840: if ($tend) {
2841: next if ($tend < $now);
2842: }
2843: if ($tstart) {
2844: next if ($tstart > $now);
2845: }
2846: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
2847: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
2848: if ($secpart eq '') {
2849: ($cnum,$role) = split(/_/,$cnumpart);
2850: $sec = 'none';
2851: $realsec = '';
2852: } else {
2853: $cnum = $cnumpart;
2854: ($sec,$role) = split(/_/,$secpart);
2855: $realsec = $sec;
1.490 raeburn 2856: }
1.482 raeburn 2857: $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
2858: }
2859: } else {
2860: foreach my $key (keys(%env)) {
1.483 albertel 2861: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
2862: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 2863: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
2864: next if ($role eq 'ca' || $role eq 'aa');
2865: next if (%roles && !exists($roles{$role}));
2866: my ($starttime,$endtime)=split(/\./,$env{$key});
2867: my $active=1;
2868: if ($starttime) {
2869: if ($now<$starttime) { $active=0; }
2870: }
2871: if ($endtime) {
2872: if ($now>$endtime) { $active=0; }
2873: }
2874: if ($active) {
2875: if ($sec eq '') {
2876: $sec = 'none';
2877: }
2878: $courses{$cdom.'_'.$cnum}{$sec} =
2879: $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474 raeburn 2880: }
2881: }
1.51 www 2882: }
2883: }
1.474 raeburn 2884: return %courses;
1.51 www 2885: }
1.37 matthew 2886:
1.54 www 2887: ###############################################
1.474 raeburn 2888:
2889: sub blockcheck {
1.482 raeburn 2890: my ($setters,$activity,$uname,$udom) = @_;
1.490 raeburn 2891:
2892: if (!defined($udom)) {
2893: $udom = $env{'user.domain'};
2894: }
2895: if (!defined($uname)) {
2896: $uname = $env{'user.name'};
2897: }
2898:
2899: my ($startblock,$endblock);
2900:
2901: # If uname and udom are for a course, check for blocks in the course.
2902:
2903: if (&Apache::lonnet::is_course($udom,$uname)) {
2904: my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
2905: ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
2906: return ($startblock,$endblock);
2907: }
1.474 raeburn 2908:
1.482 raeburn 2909: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 2910:
1.490 raeburn 2911: # If uname is for a user, and activity is course-specific, i.e.,
2912: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 2913:
1.490 raeburn 2914: if (($activity eq 'boards' || $activity eq 'chat' ||
2915: $activity eq 'groups') && ($env{'request.course.id'})) {
2916: foreach my $key (keys(%live_courses)) {
2917: if ($key ne $env{'request.course.id'}) {
2918: delete($live_courses{$key});
2919: }
2920: }
2921: }
2922:
2923: my $otheruser = 0;
2924: my %own_courses;
2925: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
2926: # Resource belongs to user other than current user.
2927: $otheruser = 1;
2928: # Gather courses for current user
2929: %own_courses =
2930: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
2931: }
2932:
2933: # Gather active course roles - course coordinator, instructor,
2934: # exam proctor, ta, student, or custom role.
1.474 raeburn 2935:
2936: foreach my $course (keys(%live_courses)) {
1.482 raeburn 2937: my ($cdom,$cnum);
2938: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
2939: $cdom = $env{'course.'.$course.'.domain'};
2940: $cnum = $env{'course.'.$course.'.num'};
2941: } else {
1.490 raeburn 2942: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 2943: }
2944: my $no_ownblock = 0;
2945: my $no_userblock = 0;
1.490 raeburn 2946: if ($otheruser) {
2947: # Check if current user has 'evb' priv for this
2948: if (defined($own_courses{$course})) {
2949: foreach my $sec (keys(%{$own_courses{$course}})) {
2950: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
2951: if ($sec ne 'none') {
2952: $checkrole .= '/'.$sec;
2953: }
2954: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
2955: $no_ownblock = 1;
2956: last;
2957: }
2958: }
2959: }
2960: # if they have 'evb' priv and are currently not playing student
2961: next if (($no_ownblock) &&
2962: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
2963: }
1.474 raeburn 2964: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 2965: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 2966: if ($sec ne 'none') {
1.482 raeburn 2967: $checkrole .= '/'.$sec;
1.474 raeburn 2968: }
1.490 raeburn 2969: # Resource belongs to user other than current user.
2970: # Assemble privs for that user, and check for 'evb' priv.
2971: if ($otheruser) {
2972: # Resource belongs to user other than current user.
2973: # Assemble privs for that user, and check for 'evb' priv.
1.482 raeburn 2974: my ($trole,$tdom,$tnum,$tsec);
2975: my $entry = $live_courses{$course}{$sec};
2976: if ($entry =~ /^cr/) {
2977: ($trole,$tdom,$tnum,$tsec) =
2978: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
2979: } else {
2980: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
2981: }
2982: my ($spec,$area,$trest,%allroles,%userroles);
2983: $area = '/'.$tdom.'/'.$tnum;
2984: $trest = $tnum;
2985: if ($tsec ne '') {
2986: $area .= '/'.$tsec;
2987: $trest .= '/'.$tsec;
2988: }
2989: $spec = $trole.'.'.$area;
2990: if ($trole =~ /^cr/) {
2991: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
2992: $tdom,$spec,$trest,$area);
2993: } else {
2994: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
2995: $tdom,$spec,$trest,$area);
2996: }
2997: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486 raeburn 2998: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
2999: if ($1) {
3000: $no_userblock = 1;
3001: last;
3002: }
3003: }
1.490 raeburn 3004: } else {
3005: # Resource belongs to current user
3006: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 3007: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3008: $no_ownblock = 1;
3009: last;
3010: }
1.474 raeburn 3011: }
3012: }
3013: # if they have the evb priv and are currently not playing student
1.482 raeburn 3014: next if (($no_ownblock) &&
1.491 albertel 3015: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 3016: next if ($no_userblock);
1.474 raeburn 3017:
1.490 raeburn 3018: # Retrieve blocking times and identity of blocker for course
3019: # of specified user, unless user has 'evb' privilege.
3020:
3021: ($startblock,$endblock)=&get_blocks($setters,$activity,$cdom,$cnum);
3022: }
3023: return ($startblock,$endblock);
3024: }
3025:
3026: sub get_blocks {
3027: my ($setters,$activity,$cdom,$cnum) = @_;
3028: my $startblock = 0;
3029: my $endblock = 0;
3030: my $course = $cdom.'_'.$cnum;
3031: $setters->{$course} = {};
3032: $setters->{$course}{'staff'} = [];
3033: $setters->{$course}{'times'} = [];
3034: my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
3035: foreach my $record (keys(%records)) {
3036: my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
3037: if ($start <= time && $end >= time) {
3038: my ($staff_name,$staff_dom,$title,$blocks) =
3039: &parse_block_record($records{$record});
3040: if ($blocks->{$activity} eq 'on') {
3041: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
3042: push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491 albertel 3043: if ( ($startblock == 0) || ($startblock > $start) ) {
3044: $startblock = $start;
1.490 raeburn 3045: }
1.491 albertel 3046: if ( ($endblock == 0) || ($endblock < $end) ) {
3047: $endblock = $end;
1.474 raeburn 3048: }
3049: }
3050: }
3051: }
3052: return ($startblock,$endblock);
3053: }
3054:
3055: sub parse_block_record {
3056: my ($record) = @_;
3057: my ($setuname,$setudom,$title,$blocks);
3058: if (ref($record) eq 'HASH') {
3059: ($setuname,$setudom) = split(/:/,$record->{'setter'});
3060: $title = &unescape($record->{'event'});
3061: $blocks = $record->{'blocks'};
3062: } else {
3063: my @data = split(/:/,$record,3);
3064: if (scalar(@data) eq 2) {
3065: $title = $data[1];
3066: ($setuname,$setudom) = split(/@/,$data[0]);
3067: } else {
3068: ($setuname,$setudom,$title) = @data;
3069: }
3070: $blocks = { 'com' => 'on' };
3071: }
3072: return ($setuname,$setudom,$title,$blocks);
3073: }
3074:
3075: sub build_block_table {
3076: my ($startblock,$endblock,$setters) = @_;
3077: my %lt = &Apache::lonlocal::texthash(
3078: 'cacb' => 'Currently active communication blocks',
3079: 'cour' => 'Course',
3080: 'dura' => 'Duration',
3081: 'blse' => 'Block set by'
3082: );
3083: my $output;
1.476 raeburn 3084: $output = '<br />'.$lt{'cacb'}.':<br />';
1.474 raeburn 3085: $output .= &start_data_table();
3086: $output .= '
3087: <tr>
3088: <th>'.$lt{'cour'}.'</th>
3089: <th>'.$lt{'dura'}.'</th>
3090: <th>'.$lt{'blse'}.'</th>
3091: </tr>
3092: ';
3093: foreach my $course (keys(%{$setters})) {
3094: my %courseinfo=&Apache::lonnet::coursedescription($course);
3095: for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) {
3096: my ($uname,$udom) = @{$$setters{$course}{staff}[$i]};
1.490 raeburn 3097: my $fullname = &plainname($uname,$udom);
3098: if (defined($env{'user.name'}) && defined($env{'user.domain'})
3099: && $env{'user.name'} ne 'public'
3100: && $env{'user.domain'} ne 'public') {
3101: $fullname = &aboutmewrapper($fullname,$uname,$udom);
3102: }
1.474 raeburn 3103: my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]};
3104: $openblock = &Apache::lonlocal::locallocaltime($openblock);
3105: $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
3106: $output .= &Apache::loncommon::start_data_table_row().
3107: '<td>'.$courseinfo{'description'}.'</td>'.
3108: '<td>'.$openblock.' to '.$closeblock.'</td>'.
1.490 raeburn 3109: '<td>'.$fullname.'</td>'.
1.474 raeburn 3110: &Apache::loncommon::end_data_table_row();
3111: }
3112: }
3113: $output .= &end_data_table();
3114: }
3115:
1.490 raeburn 3116: sub blocking_status {
3117: my ($activity,$uname,$udom) = @_;
3118: my %setters;
3119: my ($blocked,$output,$ownitem,$is_course);
3120: my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
3121: if ($startblock && $endblock) {
3122: $blocked = 1;
3123: if (wantarray) {
3124: my $category;
3125: if ($activity eq 'boards') {
3126: $category = 'Discussion posts in this course';
3127: } elsif ($activity eq 'blogs') {
3128: $category = 'Blogs';
3129: } elsif ($activity eq 'port') {
3130: if (defined($uname) && defined($udom)) {
3131: if ($uname eq $env{'user.name'} &&
3132: $udom eq $env{'user.domain'}) {
3133: $ownitem = 1;
3134: }
3135: }
3136: $is_course = &Apache::lonnet::is_course($udom,$uname);
3137: if ($ownitem) {
3138: $category = 'Your portfolio files';
3139: } elsif ($is_course) {
3140: my $coursedesc;
3141: foreach my $course (keys(%setters)) {
3142: my %courseinfo =
3143: &Apache::lonnet::coursedescription($course);
3144: $coursedesc = $courseinfo{'description'};
3145: }
3146: $category = "Group files in the course '$coursedesc'";
3147: } else {
3148: $category = 'Portfolio files belonging to ';
3149: if ($env{'user.name'} eq 'public' &&
3150: $env{'user.domain'} eq 'public') {
3151: $category .= &plainname($uname,$udom);
3152: } else {
3153: $category .= &aboutmewrapper(&plainname($uname,$udom),$uname,$udom);
3154: }
3155: }
3156: } elsif ($activity eq 'groups') {
3157: $category = 'Groups in this course';
3158: }
3159: my $showstart = &Apache::lonlocal::locallocaltime($startblock);
3160: my $showend = &Apache::lonlocal::locallocaltime($endblock);
3161: $output = '<br />'.&mt('[_1] will be inaccessible between [_2] and [_3] because communication is being blocked.',$category,$showstart,$showend).'<br />';
3162: if (!($activity eq 'port' && !($ownitem) && !($is_course))) {
3163: $output .= &build_block_table($startblock,$endblock,\%setters);
3164: }
3165: }
3166: }
3167: if (wantarray) {
3168: return ($blocked,$output);
3169: } else {
3170: return $blocked;
3171: }
3172: }
3173:
1.60 matthew 3174: ###############################################
3175:
3176: =pod
3177:
1.112 bowersj2 3178: =head1 Domain Template Functions
3179:
3180: =over 4
3181:
3182: =item * &determinedomain()
1.60 matthew 3183:
3184: Inputs: $domain (usually will be undef)
3185:
1.63 www 3186: Returns: Determines which domain should be used for designs
1.60 matthew 3187:
3188: =cut
1.54 www 3189:
1.60 matthew 3190: ###############################################
1.63 www 3191: sub determinedomain {
3192: my $domain=shift;
3193: if (! $domain) {
1.60 matthew 3194: # Determine domain if we have not been given one
3195: $domain = $Apache::lonnet::perlvar{'lonDefDomain'};
1.258 albertel 3196: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
3197: if ($env{'request.role.domain'}) {
3198: $domain=$env{'request.role.domain'};
1.60 matthew 3199: }
3200: }
1.63 www 3201: return $domain;
3202: }
3203: ###############################################
3204: =pod
3205:
1.112 bowersj2 3206: =item * &domainlogo()
1.63 www 3207:
3208: Inputs: $domain (usually will be undef)
3209:
3210: Returns: A link to a domain logo, if the domain logo exists.
3211: If the domain logo does not exist, a description of the domain.
3212:
3213: =cut
1.112 bowersj2 3214:
1.63 www 3215: ###############################################
3216: sub domainlogo {
3217: my $domain = &determinedomain(shift);
3218: # See if there is a logo
1.59 www 3219: if (-e '/home/httpd/html/adm/lonDomLogos/'.$domain.'.gif') {
1.215 albertel 3220: my $logo=&lonhttpdurl("/adm/lonDomLogos/$domain.gif");
3221: return '<img src="'.$logo.'" alt="'.$domain.'" />';
1.60 matthew 3222: } elsif(exists($Apache::lonnet::domaindescription{$domain})) {
3223: return $Apache::lonnet::domaindescription{$domain};
1.59 www 3224: } else {
1.60 matthew 3225: return '';
1.59 www 3226: }
3227: }
1.63 www 3228: ##############################################
3229:
3230: =pod
3231:
1.112 bowersj2 3232: =item * &designparm()
1.63 www 3233:
3234: Inputs: $which parameter; $domain (usually will be undef)
3235:
3236: Returns: value of designparamter $which
3237:
3238: =cut
1.112 bowersj2 3239:
1.397 albertel 3240:
1.400 albertel 3241: ##############################################
1.397 albertel 3242: sub designparm {
3243: my ($which,$domain)=@_;
1.258 albertel 3244: if ($env{'browser.blackwhite'} eq 'on') {
1.110 www 3245: if ($which=~/\.(font|alink|vlink|link)$/) {
3246: return '#000000';
3247: }
3248: if ($which=~/\.(pgbg|sidebg)$/) {
3249: return '#FFFFFF';
3250: }
3251: if ($which=~/\.tabbg$/) {
3252: return '#CCCCCC';
3253: }
3254: }
1.397 albertel 3255: if (exists($env{'environment.color.'.$which})) {
1.258 albertel 3256: return $env{'environment.color.'.$which};
1.96 www 3257: }
1.63 www 3258: $domain=&determinedomain($domain);
1.397 albertel 3259: if (exists($designhash{$domain.'.'.$which})) {
1.63 www 3260: return $designhash{$domain.'.'.$which};
3261: } else {
3262: return $designhash{'default.'.$which};
3263: }
3264: }
1.59 www 3265:
1.60 matthew 3266: ###############################################
3267: ###############################################
3268:
3269: =pod
3270:
1.112 bowersj2 3271: =back
3272:
3273: =head1 HTTP Helpers
3274:
3275: =over 4
3276:
3277: =item * &bodytag()
1.60 matthew 3278:
3279: Returns a uniform header for LON-CAPA web pages.
3280:
3281: Inputs:
3282:
1.112 bowersj2 3283: =over 4
3284:
3285: =item * $title, A title to be displayed on the page.
3286:
3287: =item * $function, the current role (can be undef).
3288:
3289: =item * $addentries, extra parameters for the <body> tag.
3290:
3291: =item * $bodyonly, if defined, only return the <body> tag.
3292:
3293: =item * $domain, if defined, force a given domain.
3294:
3295: =item * $forcereg, if page should register as content page (relevant for
1.86 www 3296: text interface only)
1.60 matthew 3297:
1.326 albertel 3298: =item * $customtitle, alternate text to use instead of $title
3299: in the title box that appears, this text
3300: is not auto translated like the $title is
1.309 albertel 3301:
3302: =item * $notopbar, if true, keep the 'what is this' info but remove the
3303: navigational links
1.317 albertel 3304:
1.338 albertel 3305: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
3306:
3307: =item * $notitle, if true keep the nav controls, but remove the title bar
3308:
1.361 albertel 3309: =item * $no_inline_link, if true and in remote mode, don't show the
3310: 'Switch To Inline Menu' link
3311:
1.460 albertel 3312: =item * $args, optional argument valid values are
3313: no_auto_mt_title -> prevents &mt()ing the title arg
3314:
1.112 bowersj2 3315: =back
3316:
1.60 matthew 3317: Returns: A uniform header for LON-CAPA web pages.
3318: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
3319: If $bodyonly is undef or zero, an html string containing a <body> tag and
3320: other decorations will be returned.
3321:
3322: =cut
3323:
1.54 www 3324: sub bodytag {
1.309 albertel 3325: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,$customtitle,
1.460 albertel 3326: $notopbar,$bgcolor,$notitle,$no_inline_link,$args)=@_;
1.339 albertel 3327:
1.460 albertel 3328: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 3329:
1.183 matthew 3330: $function = &get_users_function() if (!$function);
1.339 albertel 3331: my $img = &designparm($function.'.img',$domain);
3332: my $font = &designparm($function.'.font',$domain);
3333: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
3334:
3335: my %design = ( 'style' => 'margin-top: 0px',
3336: 'bgcolor' => $pgbg,
3337: 'text' => $font,
3338: 'alink' => &designparm($function.'.alink',$domain),
3339: 'vlink' => &designparm($function.'.vlink',$domain),
3340: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 3341: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 3342:
1.63 www 3343: # role and realm
1.378 raeburn 3344: my ($role,$realm) = split(/\./,$env{'request.role'},2);
3345: if ($role eq 'ca') {
1.479 albertel 3346: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.378 raeburn 3347: $realm = &plainname($rname,$rdom).':'.$rdom;
3348: }
1.55 www 3349: # realm
1.258 albertel 3350: if ($env{'request.course.id'}) {
1.378 raeburn 3351: if ($env{'request.role'} !~ /^cr/) {
3352: $role = &Apache::lonnet::plaintext($role,&course_type());
3353: }
1.359 albertel 3354: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 3355: } else {
3356: $role = &Apache::lonnet::plaintext($role);
1.54 www 3357: }
1.433 albertel 3358:
1.359 albertel 3359: if (!$realm) { $realm=' '; }
1.55 www 3360: # Set messages
1.60 matthew 3361: my $messages=&domainlogo($domain);
1.101 www 3362: # Port for miniserver
1.83 albertel 3363: my $lonhttpdPort=$Apache::lonnet::perlvar{'lonhttpdPort'};
3364: if (!defined($lonhttpdPort)) { $lonhttpdPort='8080'; }
1.330 albertel 3365:
1.438 albertel 3366: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 3367:
1.101 www 3368: # construct main body tag
1.359 albertel 3369: my $bodytag = "<body $extra_body_attr>".
3370: &Apache::lontexconvert::init_math_support();
1.252 albertel 3371:
1.332 albertel 3372: if ($bodyonly
3373: || ($env{'request.state'} eq 'construct'
3374: && $env{'environment.remote'} ne 'off' )) {
1.60 matthew 3375: return $bodytag;
1.258 albertel 3376: } elsif ($env{'browser.interface'} eq 'textual') {
1.95 www 3377: # Accessibility
1.224 raeburn 3378:
1.337 albertel 3379: $bodytag.=&Apache::lonmenu::menubuttons($forcereg,$forcereg);
1.338 albertel 3380: if (!$notitle) {
1.337 albertel 3381: $bodytag.='<h1>LON-CAPA: '.$title.'</h1>';
3382: }
3383: return $bodytag;
1.359 albertel 3384: }
3385:
1.410 albertel 3386: my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.433 albertel 3387: if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
3388: undef($role);
1.434 albertel 3389: } else {
3390: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433 albertel 3391: }
1.359 albertel 3392:
3393: my $roleinfo=(<<ENDROLE);
3394: <td class="LC_title_bar_who">
3395: <div class="LC_title_bar_name">
1.410 albertel 3396: $name
1.361 albertel 3397:
1.359 albertel 3398: </div>
3399: <div class="LC_title_bar_role">
1.361 albertel 3400: $role
1.359 albertel 3401: </div>
3402: <div class="LC_title_bar_realm">
1.361 albertel 3403: $realm
1.359 albertel 3404: </div>
1.206 albertel 3405: </td>
3406: ENDROLE
1.235 raeburn 3407:
1.359 albertel 3408: my $titleinfo = '<span class="LC_title_bar_title">'.$title.'</span>';
3409: if ($customtitle) {
3410: $titleinfo = $customtitle;
3411: }
3412: #
3413: # Extra info if you are the DC
3414: my $dc_info = '';
3415: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
3416: $env{'course.'.$env{'request.course.id'}.
3417: '.domain'}.'/'})) {
3418: my $cid = $env{'request.course.id'};
3419: $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 3420: $dc_info =~ s/\s+$//;
1.359 albertel 3421: $dc_info = '('.$dc_info.')';
3422: }
3423:
3424: if ($env{'environment.remote'} eq 'off') {
3425: # No Remote
1.258 albertel 3426: if ($env{'request.state'} eq 'construct') {
1.359 albertel 3427: $forcereg=1;
3428: }
3429:
3430: if (!$customtitle && $env{'request.state'} eq 'construct') {
3431: # this is for resources; directories have customtitle, and crumbs
3432: # and select recent are created in lonpubdir.pm
1.229 albertel 3433: my ($uname,$thisdisfn)=
1.258 albertel 3434: ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
1.229 albertel 3435: my $formaction='/priv/'.$uname.'/'.$thisdisfn;
3436: $formaction=~s/\/+/\//g;
3437:
1.359 albertel 3438: my $parentpath = '';
3439: my $lastitem = '';
3440: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
3441: $parentpath = $1;
3442: $lastitem = $2;
3443: } else {
3444: $lastitem = $thisdisfn;
3445: }
3446: $titleinfo =
1.401 albertel 3447: &Apache::loncommon::help_open_menu('','',3,'Authoring').
1.359 albertel 3448: '<b>Construction Space</b>: '.
3449: '<form name="dirs" method="post" action="'.$formaction
3450: .'" target="_top"><tt><b>'
3451: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."<font size=\"+1\">$lastitem</font></b></tt><br />"
3452: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
3453: .'</form>'
3454: .&Apache::lonmenu::constspaceform();
1.235 raeburn 3455: }
1.359 albertel 3456:
1.337 albertel 3457: my $titletable;
1.338 albertel 3458: if (!$notitle) {
1.337 albertel 3459: $titletable =
1.359 albertel 3460: '<table id="LC_title_bar">'.
3461: "<tr><td> $titleinfo $dc_info</td>".$roleinfo.
3462: '</tr></table>';
1.337 albertel 3463: }
1.359 albertel 3464: if ($notopbar) {
3465: $bodytag .= $titletable;
3466: } else {
3467: if ($env{'request.state'} eq 'construct') {
1.337 albertel 3468: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg,
3469: $titletable);
1.272 raeburn 3470: } else {
1.336 albertel 3471: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg).
1.359 albertel 3472: $titletable;
1.272 raeburn 3473: }
1.235 raeburn 3474: }
3475: return $bodytag;
1.94 www 3476: }
1.95 www 3477:
1.93 www 3478: #
1.95 www 3479: # Top frame rendering, Remote is up
1.93 www 3480: #
1.359 albertel 3481:
3482: my $upperleft='<img src="http://'.$ENV{'HTTP_HOST'}.':'.
3483: $lonhttpdPort.$img.'" alt="'.$function.'" />';
3484:
1.305 www 3485: # Explicit link to get inline menu
1.361 albertel 3486: my $menu= ($no_inline_link?''
3487: :'<br /><a href="/adm/remote?action=collapse">'.&mt('Switch to Inline Menu Mode').'</a>');
1.245 matthew 3488: #
1.338 albertel 3489: if ($notitle) {
1.337 albertel 3490: return $bodytag;
3491: }
1.94 www 3492: return(<<ENDBODY);
1.60 matthew 3493: $bodytag
1.359 albertel 3494: <table id="LC_title_bar" class="LC_with_remote">
1.368 albertel 3495: <tr><td class="LC_title_bar_role_logo">$upperleft</td>
1.359 albertel 3496: <td class="LC_title_bar_domain_logo">$messages </td>
1.54 www 3497: </tr>
1.359 albertel 3498: <tr><td>$titleinfo $dc_info $menu</td>
3499: $roleinfo
1.368 albertel 3500: </tr>
1.356 albertel 3501: </table>
1.54 www 3502: ENDBODY
1.182 matthew 3503: }
3504:
1.330 albertel 3505: sub make_attr_string {
3506: my ($register,$attr_ref) = @_;
3507:
3508: if ($attr_ref && !ref($attr_ref)) {
3509: die("addentries Must be a hash ref ".
3510: join(':',caller(1))." ".
3511: join(':',caller(0))." ");
3512: }
3513:
3514: if ($register) {
1.339 albertel 3515: my ($on_load,$on_unload);
3516: foreach my $key (keys(%{$attr_ref})) {
3517: if (lc($key) eq 'onload') {
3518: $on_load.=$attr_ref->{$key}.';';
3519: delete($attr_ref->{$key});
3520:
3521: } elsif (lc($key) eq 'onunload') {
3522: $on_unload.=$attr_ref->{$key}.';';
3523: delete($attr_ref->{$key});
3524: }
3525: }
3526: $attr_ref->{'onload'} =
3527: &Apache::lonmenu::loadevents(). $on_load;
3528: $attr_ref->{'onunload'}=
3529: &Apache::lonmenu::unloadevents().$on_unload;
3530: }
3531:
3532: # Accessibility font enhance
3533: if ($env{'browser.fontenhance'} eq 'on') {
3534: my $style;
3535: foreach my $key (keys(%{$attr_ref})) {
3536: if (lc($key) eq 'style') {
3537: $style.=$attr_ref->{$key}.';';
3538: delete($attr_ref->{$key});
3539: }
3540: }
3541: $attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330 albertel 3542: }
1.339 albertel 3543:
3544: if ($env{'browser.blackwhite'} eq 'on') {
3545: delete($attr_ref->{'font'});
3546: delete($attr_ref->{'link'});
3547: delete($attr_ref->{'alink'});
3548: delete($attr_ref->{'vlink'});
3549: delete($attr_ref->{'bgcolor'});
3550: delete($attr_ref->{'background'});
3551: }
3552:
1.330 albertel 3553: my $attr_string;
3554: foreach my $attr (keys(%$attr_ref)) {
3555: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
3556: }
3557: return $attr_string;
3558: }
3559:
3560:
1.182 matthew 3561: ###############################################
1.251 albertel 3562: ###############################################
3563:
3564: =pod
3565:
3566: =back
3567:
1.306 albertel 3568: =head1 HTML Helpers
1.251 albertel 3569:
3570: =over 4
3571:
3572: =item * &endbodytag()
3573:
3574: Returns a uniform footer for LON-CAPA web pages.
3575:
1.306 albertel 3576: Inputs: none
1.251 albertel 3577:
3578: =back
3579:
3580: =cut
3581:
3582: sub endbodytag {
3583: my $endbodytag='</body>';
1.269 albertel 3584: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 3585: if ( exists( $env{'internal.head.redirect'} ) ) {
3586: $endbodytag=
3587: "<br /><a href=\"$env{'internal.head.redirect'}\">".
3588: &mt('Continue').'</a>'.
3589: $endbodytag;
3590: }
1.251 albertel 3591: return $endbodytag;
3592: }
3593:
1.352 albertel 3594: =pod
3595:
3596: =over 4
3597:
3598: =item * &standard_css()
3599:
3600: Returns a style sheet
3601:
3602: Inputs: (all optional)
3603: domain -> force to color decorate a page for a specific
3604: domain
3605: function -> force usage of a specific rolish color scheme
3606: bgcolor -> override the default page bgcolor
3607:
3608: =back
3609:
3610: =cut
3611:
1.343 albertel 3612: sub standard_css {
1.345 albertel 3613: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 3614: $function = &get_users_function() if (!$function);
3615: my $img = &designparm($function.'.img', $domain);
3616: my $tabbg = &designparm($function.'.tabbg', $domain);
3617: my $font = &designparm($function.'.font', $domain);
1.345 albertel 3618: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 3619: my $pgbg_or_bgcolor =
3620: $bgcolor ||
1.352 albertel 3621: &designparm($function.'.pgbg', $domain);
1.382 albertel 3622: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 3623: my $alink = &designparm($function.'.alink', $domain);
3624: my $vlink = &designparm($function.'.vlink', $domain);
3625: my $link = &designparm($function.'.link', $domain);
3626:
3627: my $sans = 'Arial,Helvetica,sans-serif';
1.395 albertel 3628: my $mono = 'monospace';
1.352 albertel 3629: my $data_table_head = $tabbg;
3630: my $data_table_light = '#EEEEEE';
1.470 banghart 3631: my $data_table_dark = '#DDDDDD';
3632: my $data_table_darker = '#CCCCCC';
1.349 albertel 3633: my $data_table_highlight = '#FFFF00';
1.352 albertel 3634: my $mail_new = '#FFBB77';
3635: my $mail_new_hover = '#DD9955';
3636: my $mail_read = '#BBBB77';
3637: my $mail_read_hover = '#999944';
3638: my $mail_replied = '#AAAA88';
3639: my $mail_replied_hover = '#888855';
3640: my $mail_other = '#99BBBB';
3641: my $mail_other_hover = '#669999';
1.391 albertel 3642: my $table_header = '#DDDDDD';
1.489 raeburn 3643: my $feedback_link_bg = '#BBBBBB';
1.392 albertel 3644:
3645: my $border = ($env{'browser.type'} eq 'explorer') ? '0px 2px 0px 2px'
3646: : '0px 3px 0px 4px';
1.448 albertel 3647:
1.343 albertel 3648: return <<END;
1.345 albertel 3649: h1, h2, h3, th { font-family: $sans }
1.343 albertel 3650: a:focus { color: red; background: yellow }
3651: table.thinborder { border-collapse: collapse; }
1.426 albertel 3652: table.thinborder tr th { border-style: solid; border-width: 1px; background: $tabbg;}
3653: table.thinborder tr td { border-style: solid; border-width: 1px}
3654:
1.343 albertel 3655: form, .inline { display: inline; }
3656: .center { text-align: center; }
1.395 albertel 3657: .LC_filename {font-family: $mono;}
1.350 albertel 3658: .LC_error {
3659: color: red;
3660: font-size: larger;
3661: }
1.457 albertel 3662: .LC_warning,
3663: .LC_diff_removed {
1.394 albertel 3664: color: red;
3665: }
1.457 albertel 3666: .LC_success,
3667: .LC_diff_added {
1.350 albertel 3668: color: green;
3669: }
1.440 albertel 3670: .LC_icon {
3671: border: 0px;
3672: }
1.346 albertel 3673:
1.458 albertel 3674: table.LC_pastsubmission {
3675: border: 1px solid black;
3676: margin: 2px;
3677: }
3678:
1.392 albertel 3679: table#LC_top_nav, table#LC_menubuttons {
1.345 albertel 3680: width: 100%;
3681: background: $pgbg;
1.392 albertel 3682: border: 2px;
1.402 albertel 3683: border-collapse: separate;
1.403 albertel 3684: padding: 0px;
1.345 albertel 3685: }
1.392 albertel 3686:
1.409 albertel 3687: table#LC_title_bar, table.LC_breadcrumbs, table#LC_nav_location,
1.393 albertel 3688: table#LC_title_bar.LC_with_remote {
1.359 albertel 3689: width: 100%;
1.392 albertel 3690: border-color: $pgbg;
3691: border-style: solid;
3692: border-width: $border;
3693:
1.379 albertel 3694: background: $pgbg;
3695: font-family: $sans;
1.392 albertel 3696: border-collapse: collapse;
1.403 albertel 3697: padding: 0px;
1.359 albertel 3698: }
1.392 albertel 3699:
1.409 albertel 3700: table.LC_docs_path {
3701: width: 100%;
3702: border: 0;
3703: background: $pgbg;
3704: font-family: $sans;
3705: border-collapse: collapse;
3706: padding: 0px;
3707: }
3708:
1.359 albertel 3709: table#LC_title_bar td {
3710: background: $tabbg;
3711: }
3712: table#LC_title_bar td.LC_title_bar_who {
3713: background: $tabbg;
3714: color: $font;
1.427 albertel 3715: font: small $sans;
1.359 albertel 3716: text-align: right;
3717: }
1.469 banghart 3718: span.LC_metadata {
3719: font-family: $sans;
3720: }
1.359 albertel 3721: span.LC_title_bar_title {
1.416 albertel 3722: font: bold x-large $sans;
1.359 albertel 3723: }
3724: table#LC_title_bar td.LC_title_bar_domain_logo {
3725: background: $sidebg;
3726: text-align: right;
1.368 albertel 3727: padding: 0px;
3728: }
3729: table#LC_title_bar td.LC_title_bar_role_logo {
3730: background: $sidebg;
3731: padding: 0px;
1.359 albertel 3732: }
3733:
1.346 albertel 3734: table#LC_menubuttons_mainmenu {
3735: background: $pgbg;
3736: border: 0px;
3737: border-spacing: 1px;
1.372 albertel 3738: padding: 0px 1px;
1.346 albertel 3739: margin: 0px;
3740: border-collapse: separate;
3741: }
3742: table#LC_menubuttons img, table#LC_menubuttons_mainmenu img {
3743: border: 0px;
3744: }
1.345 albertel 3745: table#LC_top_nav td {
3746: background: $tabbg;
1.392 albertel 3747: border: 0px;
1.407 albertel 3748: font-size: small;
1.345 albertel 3749: }
3750: table#LC_top_nav td a, div#LC_top_nav a {
3751: color: $font;
3752: font-family: $sans;
3753: }
1.364 albertel 3754: table#LC_top_nav td.LC_top_nav_logo {
3755: background: $tabbg;
1.432 albertel 3756: text-align: left;
1.408 albertel 3757: white-space: nowrap;
1.432 albertel 3758: width: 31px;
1.408 albertel 3759: }
3760: table#LC_top_nav td.LC_top_nav_logo img {
1.432 albertel 3761: border: 0px;
1.408 albertel 3762: vertical-align: bottom;
1.364 albertel 3763: }
1.432 albertel 3764: table#LC_top_nav td.LC_top_nav_exit,
3765: table#LC_top_nav td.LC_top_nav_help {
3766: width: 2.0em;
3767: }
1.442 albertel 3768: table#LC_top_nav td.LC_top_nav_login {
3769: width: 4.0em;
3770: text-align: center;
3771: }
1.409 albertel 3772: table.LC_breadcrumbs td, table.LC_docs_path td {
1.357 albertel 3773: background: $tabbg;
3774: color: $font;
3775: font-family: $sans;
1.358 albertel 3776: font-size: smaller;
1.357 albertel 3777: }
1.411 albertel 3778: table.LC_breadcrumbs td.LC_breadcrumbs_component,
1.409 albertel 3779: table.LC_docs_path td.LC_docs_path_component {
1.357 albertel 3780: background: $tabbg;
3781: color: $font;
3782: font-family: $sans;
3783: font-size: larger;
3784: text-align: right;
3785: }
1.383 albertel 3786: td.LC_table_cell_checkbox {
3787: text-align: center;
3788: }
3789:
1.346 albertel 3790: .LC_menubuttons_inline_text {
3791: color: $font;
3792: font-family: $sans;
3793: font-size: smaller;
3794: }
3795:
3796: td.LC_menubuttons_text {
3797: color: $font;
3798: font-family: $sans;
3799: }
3800: td.LC_menubuttons_img {
3801: background: $tabbg;
3802: }
3803: .LC_current_location {
3804: font-family: $sans;
3805: background: $tabbg;
3806: }
3807: .LC_new_mail {
3808: font-family: $sans;
3809: font-weight: bold;
3810: }
1.347 albertel 3811:
1.440 albertel 3812: table.LC_aboutme_port {
3813: border: 0px;
3814: border-collapse: collapse;
3815: border-spacing: 0px;
3816: }
1.349 albertel 3817: table.LC_data_table, table.LC_mail_list {
1.347 albertel 3818: border: 1px solid #000000;
1.402 albertel 3819: border-collapse: separate;
1.426 albertel 3820: border-spacing: 1px;
1.347 albertel 3821: }
1.422 albertel 3822: .LC_data_table_dense {
3823: font-size: small;
3824: }
1.349 albertel 3825: table.LC_data_table tr th, table.LC_calendar tr th, table.LC_mail_list tr th {
3826: font-weight: bold;
3827: background-color: $data_table_head;
1.421 albertel 3828: font-size: smaller;
1.347 albertel 3829: }
1.440 albertel 3830: table.LC_data_table tr td,
3831: table.LC_aboutme_port tr td {
1.349 albertel 3832: background-color: $data_table_light;
1.425 albertel 3833: padding: 2px;
1.347 albertel 3834: }
1.440 albertel 3835: table.LC_data_table tr.LC_even_row td,
3836: table.LC_aboutme_port tr.LC_even_row td {
1.349 albertel 3837: background-color: $data_table_dark;
1.347 albertel 3838: }
1.425 albertel 3839: table.LC_data_table tr.LC_data_table_highlight td {
3840: background-color: $data_table_darker;
3841: }
1.451 albertel 3842: table.LC_data_table tr.LC_empty_row td,
1.452 albertel 3843: table.LC_whatsnew tr.LC_empty_row td {
1.347 albertel 3844: background-color: #FFFFFF;
1.421 albertel 3845: font-weight: bold;
3846: font-style: italic;
3847: text-align: center;
3848: padding: 8px;
1.347 albertel 3849: }
1.465 albertel 3850: table.LC_whatsnew tr.LC_empty_row td {
3851: padding: 4ex
3852: }
1.451 albertel 3853: table.LC_whatsnew {
3854: }
3855:
3856: table.LC_whatsnew tr th,
3857: table.LC_whatsnew tr.LC_info_row td {
3858: background-color: #CCC;
3859: font-weight: bold;
3860: font-size: small;
3861: text-align: right;
3862: }
3863: table.LC_whatsnew tr td {
3864: background-color: #FFF;
3865: font-size: small;
3866: text-align: right;
3867: }
3868: table.LC_whatsnew tr td.LC_first_item {
3869: text-align: left;
3870: }
3871:
3872: table.LC_whatsnew tr.LC_odd_row td {
3873: background-color: #EEE;
3874: }
3875:
1.473 raeburn 3876: table.LC_createuser {
3877: }
3878:
3879: table.LC_createuser tr.LC_section_row td {
3880: font-size: smaller;
3881: }
3882:
3883: table.LC_createuser tr.LC_info_row td {
3884: background-color: #CCC;
3885: font-weight: bold;
3886: text-align: center;
3887: }
3888:
1.349 albertel 3889: table.LC_calendar {
3890: border: 1px solid #000000;
3891: border-collapse: collapse;
3892: }
3893: table.LC_calendar_pickdate {
3894: font-size: xx-small;
3895: }
3896: table.LC_calendar tr td {
3897: border: 1px solid #000000;
3898: vertical-align: top;
3899: }
3900: table.LC_calendar tr td.LC_calendar_day_empty {
3901: background-color: $data_table_dark;
3902: }
3903: table.LC_calendar tr td.LC_calendar_day_current {
3904: background-color: $data_table_highlight;
3905: }
3906:
3907: table.LC_mail_list tr.LC_mail_new {
3908: background-color: $mail_new;
3909: }
3910: table.LC_mail_list tr.LC_mail_new:hover {
3911: background-color: $mail_new_hover;
3912: }
3913: table.LC_mail_list tr.LC_mail_read {
3914: background-color: $mail_read;
3915: }
3916: table.LC_mail_list tr.LC_mail_read:hover {
3917: background-color: $mail_read_hover;
3918: }
3919: table.LC_mail_list tr.LC_mail_replied {
3920: background-color: $mail_replied;
3921: }
3922: table.LC_mail_list tr.LC_mail_replied:hover {
3923: background-color: $mail_replied_hover;
3924: }
3925: table.LC_mail_list tr.LC_mail_other {
3926: background-color: $mail_other;
3927: }
3928: table.LC_mail_list tr.LC_mail_other:hover {
3929: background-color: $mail_other_hover;
3930: }
1.494 raeburn 3931: table.LC_mail_list tr.LC_mail_even {
3932: }
3933: table.LC_mail_list tr.LC_mail_odd {
3934: }
3935:
1.385 albertel 3936:
1.386 albertel 3937: table#LC_portfolio_actions {
3938: width: auto;
3939: background: $pgbg;
3940: border: 0px;
3941: border-spacing: 2px 2px;
3942: padding: 0px;
3943: margin: 0px;
3944: border-collapse: separate;
3945: }
3946: table#LC_portfolio_actions td.LC_label {
3947: background: $tabbg;
3948: text-align: right;
3949: }
3950: table#LC_portfolio_actions td.LC_value {
3951: background: $tabbg;
3952: }
1.385 albertel 3953:
1.391 albertel 3954: table#LC_cstr_controls {
3955: width: 100%;
3956: border-collapse: collapse;
3957: }
3958: table#LC_cstr_controls tr td {
3959: border: 4px solid $pgbg;
3960: padding: 4px;
3961: text-align: center;
3962: background: $tabbg;
3963: }
3964: table#LC_cstr_controls tr th {
3965: border: 4px solid $pgbg;
3966: background: $table_header;
3967: text-align: center;
3968: font-family: $sans;
3969: font-size: smaller;
3970: }
3971:
1.389 albertel 3972: table#LC_browser {
3973:
3974: }
3975: table#LC_browser tr th {
1.391 albertel 3976: background: $table_header;
1.389 albertel 3977: }
1.390 albertel 3978: table#LC_browser tr td {
3979: padding: 2px;
3980: }
1.389 albertel 3981: table#LC_browser tr.LC_browser_file,
3982: table#LC_browser tr.LC_browser_file_published {
3983: background: #CCFF88;
3984: }
3985: table#LC_browser tr.LC_browser_file_locked,
3986: table#LC_browser tr.LC_browser_file_unpublished {
3987: background: #FFAA99;
1.387 albertel 3988: }
1.389 albertel 3989: table#LC_browser tr.LC_browser_file_obsolete {
3990: background: #AAAAAA;
1.387 albertel 3991: }
1.455 albertel 3992: table#LC_browser tr.LC_browser_file_modified,
3993: table#LC_browser tr.LC_browser_file_metamodified {
1.389 albertel 3994: background: #FFFF77;
1.387 albertel 3995: }
1.389 albertel 3996: table#LC_browser tr.LC_browser_folder {
3997: background: #CCCCFF;
1.387 albertel 3998: }
1.388 albertel 3999: span.LC_current_location {
4000: font-size: x-large;
4001: background: $pgbg;
4002: }
1.387 albertel 4003:
1.395 albertel 4004: span.LC_parm_menu_item {
4005: font-size: larger;
4006: font-family: $sans;
4007: }
4008: span.LC_parm_scope_all {
4009: color: red;
4010: }
4011: span.LC_parm_scope_folder {
4012: color: green;
4013: }
4014: span.LC_parm_scope_resource {
4015: color: orange;
4016: }
4017: span.LC_parm_part {
4018: color: blue;
4019: }
4020: span.LC_parm_folder, span.LC_parm_symb {
4021: font-size: x-small;
4022: font-family: $mono;
4023: color: #AAAAAA;
4024: }
4025:
1.396 albertel 4026: td.LC_parm_overview_level_menu, td.LC_parm_overview_map_menu,
4027: td.LC_parm_overview_parm_selectors, td.LC_parm_overview_parm_restrictions {
4028: border: 1px solid black;
4029: border-collapse: collapse;
4030: }
4031: table.LC_parm_overview_restrictions td {
4032: border-width: 1px 4px 1px 4px;
4033: border-style: solid;
4034: border-color: $pgbg;
4035: text-align: center;
4036: }
4037: table.LC_parm_overview_restrictions th {
4038: background: $tabbg;
4039: border-width: 1px 4px 1px 4px;
4040: border-style: solid;
4041: border-color: $pgbg;
4042: }
1.398 albertel 4043: table#LC_helpmenu {
4044: border: 0px;
4045: height: 55px;
4046: border-spacing: 0px;
4047: }
4048:
4049: table#LC_helpmenu fieldset legend {
4050: font-size: larger;
4051: font-weight: bold;
4052: }
1.397 albertel 4053: table#LC_helpmenu_links {
4054: width: 100%;
4055: border: 1px solid black;
4056: background: $pgbg;
4057: padding: 0px;
4058: border-spacing: 1px;
4059: }
4060: table#LC_helpmenu_links tr td {
4061: padding: 1px;
4062: background: $tabbg;
1.399 albertel 4063: text-align: center;
4064: font-weight: bold;
1.397 albertel 4065: }
1.396 albertel 4066:
1.397 albertel 4067: table#LC_helpmenu_links a:link, table#LC_helpmenu_links a:visited,
4068: table#LC_helpmenu_links a:active {
4069: text-decoration: none;
4070: color: $font;
4071: }
4072: table#LC_helpmenu_links a:hover {
4073: text-decoration: underline;
4074: color: $vlink;
4075: }
1.396 albertel 4076:
1.417 albertel 4077: .LC_chrt_popup_exists {
4078: border: 1px solid #339933;
4079: margin: -1px;
4080: }
4081: .LC_chrt_popup_up {
4082: border: 1px solid yellow;
4083: margin: -1px;
4084: }
4085: .LC_chrt_popup {
4086: border: 1px solid #8888FF;
4087: background: #CCCCFF;
4088: }
4089:
1.421 albertel 4090: table.LC_pick_box {
4091: width: 100%;
4092: border-collapse: separate;
4093: background: white;
4094: border: 1px solid black;
4095: border-spacing: 1px;
4096: }
4097: table.LC_pick_box td.LC_pick_box_title {
4098: background: $tabbg;
4099: font-weight: bold;
4100: text-align: right;
4101: width: 184px;
4102: padding: 8px;
4103: }
1.424 albertel 4104: table.LC_pick_box td.LC_pick_box_separator {
1.421 albertel 4105: padding: 0px;
4106: height: 1px;
4107: background: black;
4108: }
4109: table.LC_pick_box td.LC_pick_box_submit {
4110: text-align: right;
4111: }
4112:
1.424 albertel 4113: table.LC_group_priv_box {
4114: background: white;
4115: border: 1px solid black;
4116: border-spacing: 1px;
4117: }
4118: table.LC_group_priv_box td.LC_pick_box_title {
4119: background: $tabbg;
4120: font-weight: bold;
4121: text-align: right;
4122: width: 184px;
4123: }
4124: table.LC_group_priv_box td.LC_groups_fixed {
4125: background: $data_table_light;
4126: text-align: center;
4127: }
4128: table.LC_group_priv_box td.LC_groups_optional {
4129: background: $data_table_dark;
4130: text-align: center;
4131: }
4132: table.LC_group_priv_box td.LC_groups_functionality {
4133: background: $data_table_darker;
4134: text-align: center;
4135: font-weight: bold;
4136: }
4137: table.LC_group_priv td {
4138: text-align: left;
4139: padding: 0px;
4140: }
4141:
1.421 albertel 4142: table.LC_notify_front_page {
4143: background: white;
4144: border: 1px solid black;
4145: padding: 8px;
4146: }
4147: table.LC_notify_front_page td {
4148: padding: 8px;
4149: }
1.424 albertel 4150: .LC_navbuttons {
4151: margin: 2ex 0ex 2ex 0ex;
4152: }
1.423 albertel 4153: .LC_topic_bar {
4154: font-family: $sans;
4155: font-weight: bold;
4156: width: 100%;
4157: background: $tabbg;
4158: vertical-align: middle;
4159: margin: 2ex 0ex 2ex 0ex;
4160: }
4161: .LC_topic_bar span {
4162: vertical-align: middle;
4163: }
4164: .LC_topic_bar img {
4165: vertical-align: bottom;
4166: }
4167: table.LC_course_group_status {
4168: margin: 20px;
4169: }
4170: table.LC_status_selector td {
4171: vertical-align: top;
4172: text-align: center;
1.424 albertel 4173: padding: 4px;
4174: }
4175: table.LC_descriptive_input td.LC_description {
4176: vertical-align: top;
4177: text-align: right;
4178: font-weight: bold;
1.423 albertel 4179: }
1.489 raeburn 4180: table.LC_feedback_link {
4181: background: $feedback_link_bg;
4182: }
4183: span.LC_feedback_link {
4184: background: $feedback_link_bg;
4185: font-size: larger;
4186: }
1.421 albertel 4187:
1.343 albertel 4188: END
4189: }
4190:
1.306 albertel 4191: =pod
4192:
4193: =over 4
4194:
4195: =item * &headtag()
4196:
4197: Returns a uniform footer for LON-CAPA web pages.
4198:
1.307 albertel 4199: Inputs: $title - optional title for the head
4200: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 4201: $args - optional arguments
1.319 albertel 4202: force_register - if is true call registerurl so the remote is
4203: informed
1.415 albertel 4204: redirect -> array ref of
4205: 1- seconds before redirect occurs
4206: 2- url to redirect to
4207: 3- whether the side effect should occur
1.315 albertel 4208: (side effect of setting
4209: $env{'internal.head.redirect'} to the url
4210: redirected too)
1.352 albertel 4211: domain -> force to color decorate a page for a specific
4212: domain
4213: function -> force usage of a specific rolish color scheme
4214: bgcolor -> override the default page bgcolor
1.460 albertel 4215: no_auto_mt_title
4216: -> prevent &mt()ing the title arg
1.464 albertel 4217:
1.306 albertel 4218: =back
4219:
4220: =cut
4221:
4222: sub headtag {
1.313 albertel 4223: my ($title,$head_extra,$args) = @_;
1.306 albertel 4224:
1.363 albertel 4225: my $function = $args->{'function'} || &get_users_function();
4226: my $domain = $args->{'domain'} || &determinedomain();
4227: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 4228: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 4229: $Apache::lonnet::perlvar{'lonVersion'},
1.418 albertel 4230: #time(),
4231: $env{'environment.color.timestamp'},
1.363 albertel 4232: $function,$domain,$bgcolor);
4233:
1.369 www 4234: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 4235:
1.308 albertel 4236: my $result =
4237: '<head>'.
1.461 albertel 4238: &font_settings();
1.319 albertel 4239:
1.461 albertel 4240: if (!$args->{'frameset'}) {
4241: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
4242: }
1.319 albertel 4243: if ($args->{'force_register'}) {
4244: $result .= &Apache::lonmenu::registerurl(1);
4245: }
1.436 albertel 4246: if (!$args->{'no_nav_bar'}
4247: && !$args->{'only_body'}
4248: && !$args->{'frameset'}) {
4249: $result .= &help_menu_js();
4250: }
1.319 albertel 4251:
1.314 albertel 4252: if (ref($args->{'redirect'})) {
1.414 albertel 4253: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 4254: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 4255: if (!$inhibit_continue) {
4256: $env{'internal.head.redirect'} = $url;
4257: }
1.313 albertel 4258: $result.=<<ADDMETA
4259: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 4260: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 4261: ADDMETA
4262: }
1.306 albertel 4263: if (!defined($title)) {
4264: $title = 'The LearningOnline Network with CAPA';
4265: }
1.460 albertel 4266: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
4267: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 4268: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
4269: .$head_extra;
1.306 albertel 4270: return $result;
4271: }
4272:
4273: =pod
4274:
4275: =over 4
4276:
1.340 albertel 4277: =item * &font_settings()
4278:
4279: Returns neccessary <meta> to set the proper encoding
4280:
4281: Inputs: none
4282:
4283: =back
4284:
4285: =cut
4286:
4287: sub font_settings {
4288: my $headerstring='';
4289: if (($env{'browser.os'} eq 'mac') && (!$env{'browser.mathml'})) {
4290: $headerstring.=
4291: '<meta Content-Type="text/html; charset=x-mac-roman" />';
4292: } elsif (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
4293: $headerstring.=
4294: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
4295: }
4296: return $headerstring;
4297: }
4298:
1.341 albertel 4299: =pod
4300:
4301: =over 4
4302:
4303: =item * &xml_begin()
4304:
4305: Returns the needed doctype and <html>
4306:
4307: Inputs: none
4308:
4309: =back
4310:
4311: =cut
4312:
4313: sub xml_begin {
4314: my $output='';
4315:
1.342 albertel 4316: &Apache::lonhtmlcommon::init_htmlareafields();
4317:
1.341 albertel 4318: if ($env{'browser.mathml'}) {
4319: $output='<?xml version="1.0"?>'
4320: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
4321: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
4322:
4323: # .'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" [<!ENTITY mathns "http://www.w3.org/1998/Math/MathML">] >'
4324: .'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">'
4325: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
4326: .'xmlns="http://www.w3.org/1999/xhtml">';
4327: } else {
4328: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>';
4329: }
4330: return $output;
4331: }
1.340 albertel 4332:
4333: =pod
4334:
4335: =over 4
4336:
1.306 albertel 4337: =item * &endheadtag()
4338:
4339: Returns a uniform </head> for LON-CAPA web pages.
4340:
4341: Inputs: none
4342:
4343: =back
4344:
4345: =cut
4346:
4347: sub endheadtag {
4348: return '</head>';
4349: }
4350:
4351: =pod
4352:
4353: =over 4
4354:
4355: =item * &head()
4356:
4357: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
4358:
4359: Inputs: $title - optional title for the page
1.307 albertel 4360: $head_extra - optional extra HTML to put inside the <head>
1.405 albertel 4361:
1.306 albertel 4362: =back
4363:
4364: =cut
4365:
4366: sub head {
1.325 albertel 4367: my ($title,$head_extra,$args) = @_;
4368: return &headtag($title,$head_extra,$args).&endheadtag();
1.306 albertel 4369: }
4370:
4371: =pod
4372:
4373: =over 4
4374:
4375: =item * &start_page()
4376:
4377: Returns a complete <html> .. <body> section for LON-CAPA web pages.
4378:
4379: Inputs: $title - optional title for the page
4380: $head_extra - optional extra HTML to incude inside the <head>
1.315 albertel 4381: $args - additional optional args supported are:
1.317 albertel 4382: only_body -> is true will set &bodytag() onlybodytag
4383: arg on
4384: no_nav_bar -> is true will set &bodytag() notopbar arg on
4385: add_entries -> additional attributes to add to the <body>
4386: domain -> force to color decorate a page for a
4387: specific domain
4388: function -> force usage of a specific rolish color
4389: scheme
4390: redirect -> see &headtag()
4391: bgcolor -> override the default page bg color
4392: js_ready -> return a string ready for being used in
4393: a javascript writeln
1.320 albertel 4394: html_encode -> return a string ready for being used in
4395: a html attribute
1.317 albertel 4396: force_register -> if is true will turn on the &bodytag()
4397: $forcereg arg
1.326 albertel 4398: body_title -> alternate text to use instead of $title
4399: in the title box that appears, this text
4400: is not auto translated like the $title is
1.330 albertel 4401: frameset -> if true will start with a <frameset>
4402: rather than <body>
1.338 albertel 4403: no_title -> if true the title bar won't be shown
4404: skip_phases -> hash ref of
4405: head -> skip the <html><head> generation
4406: body -> skip all <body> generation
1.337 albertel 4407:
1.361 albertel 4408: no_inline_link -> if true and in remote mode, don't show the
4409: 'Switch To Inline Menu' link
4410:
1.460 albertel 4411: no_auto_mt_title -> prevent &mt()ing the title arg
4412:
1.306 albertel 4413: =back
4414:
4415: =cut
4416:
4417: sub start_page {
1.309 albertel 4418: my ($title,$head_extra,$args) = @_;
1.318 albertel 4419: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313 albertel 4420: my %head_args;
1.352 albertel 4421: foreach my $arg ('redirect','force_register','domain','function',
1.460 albertel 4422: 'bgcolor','frameset','no_nav_bar','only_body',
4423: 'no_auto_mt_title') {
1.319 albertel 4424: if (defined($args->{$arg})) {
1.324 raeburn 4425: $head_args{$arg} = $args->{$arg};
1.319 albertel 4426: }
1.313 albertel 4427: }
1.319 albertel 4428:
1.315 albertel 4429: $env{'internal.start_page'}++;
1.338 albertel 4430: my $result;
4431: if (! exists($args->{'skip_phases'}{'head'}) ) {
4432: $result.=
1.341 albertel 4433: &xml_begin().
1.338 albertel 4434: &headtag($title,$head_extra,\%head_args).&endheadtag();
4435: }
4436:
4437: if (! exists($args->{'skip_phases'}{'body'}) ) {
4438: if ($args->{'frameset'}) {
4439: my $attr_string = &make_attr_string($args->{'force_register'},
4440: $args->{'add_entries'});
4441: $result .= "\n<frameset $attr_string>\n";
4442: } else {
4443: $result .=
4444: &bodytag($title,
4445: $args->{'function'}, $args->{'add_entries'},
4446: $args->{'only_body'}, $args->{'domain'},
4447: $args->{'force_register'}, $args->{'body_title'},
4448: $args->{'no_nav_bar'}, $args->{'bgcolor'},
1.460 albertel 4449: $args->{'no_title'}, $args->{'no_inline_link'},
4450: $args);
1.338 albertel 4451: }
1.330 albertel 4452: }
1.338 albertel 4453:
1.315 albertel 4454: if ($args->{'js_ready'}) {
1.317 albertel 4455: $result = &js_ready($result);
1.315 albertel 4456: }
1.320 albertel 4457: if ($args->{'html_encode'}) {
4458: $result = &html_encode($result);
4459: }
1.315 albertel 4460: return $result;
1.306 albertel 4461: }
4462:
1.330 albertel 4463:
1.306 albertel 4464: =pod
4465:
4466: =over 4
4467:
4468: =item * &head()
4469:
4470: Returns a complete </body></html> section for LON-CAPA web pages.
4471:
1.315 albertel 4472: Inputs: $args - additional optional args supported are:
4473: js_ready -> return a string ready for being used in
4474: a javascript writeln
1.320 albertel 4475: html_encode -> return a string ready for being used in
4476: a html attribute
1.330 albertel 4477: frameset -> if true will start with a <frameset>
4478: rather than <body>
1.493 albertel 4479: dicsussion -> if true will get discussion from
4480: lonxml::xmlend
4481: (you can pass the target and parser arguments
4482: through optional 'target' and 'parser' args
4483: to this routine)
1.306 albertel 4484:
4485: =cut
4486:
4487: sub end_page {
1.315 albertel 4488: my ($args) = @_;
4489: $env{'internal.end_page'}++;
1.330 albertel 4490: my $result;
1.335 albertel 4491: if ($args->{'discussion'}) {
4492: my ($target,$parser);
4493: if (ref($args->{'discussion'})) {
4494: ($target,$parser) =($args->{'discussion'}{'target'},
4495: $args->{'discussion'}{'parser'});
4496: }
4497: $result .= &Apache::lonxml::xmlend($target,$parser);
4498: }
4499:
1.330 albertel 4500: if ($args->{'frameset'}) {
4501: $result .= '</frameset>';
4502: } else {
4503: $result .= &endbodytag();
4504: }
4505: $result .= "\n</html>";
4506:
1.315 albertel 4507: if ($args->{'js_ready'}) {
1.317 albertel 4508: $result = &js_ready($result);
1.315 albertel 4509: }
1.335 albertel 4510:
1.320 albertel 4511: if ($args->{'html_encode'}) {
4512: $result = &html_encode($result);
4513: }
1.335 albertel 4514:
1.315 albertel 4515: return $result;
4516: }
4517:
1.320 albertel 4518: sub html_encode {
4519: my ($result) = @_;
4520:
1.322 albertel 4521: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 4522:
4523: return $result;
4524: }
1.317 albertel 4525: sub js_ready {
4526: my ($result) = @_;
4527:
1.323 albertel 4528: $result =~ s/[\n\r]/ /xmsg;
4529: $result =~ s/\\/\\\\/xmsg;
4530: $result =~ s/'/\\'/xmsg;
1.372 albertel 4531: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 4532:
4533: return $result;
4534: }
4535:
1.315 albertel 4536: sub validate_page {
4537: if ( exists($env{'internal.start_page'})
1.316 albertel 4538: && $env{'internal.start_page'} > 1) {
4539: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 4540: $env{'internal.start_page'}.' '.
1.316 albertel 4541: $ENV{'request.filename'});
1.315 albertel 4542: }
4543: if ( exists($env{'internal.end_page'})
1.316 albertel 4544: && $env{'internal.end_page'} > 1) {
4545: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 4546: $env{'internal.end_page'}.' '.
1.316 albertel 4547: $env{'request.filename'});
1.315 albertel 4548: }
4549: if ( exists($env{'internal.start_page'})
4550: && ! exists($env{'internal.end_page'})) {
1.316 albertel 4551: &Apache::lonnet::logthis('start_page called without end_page '.
4552: $env{'request.filename'});
1.315 albertel 4553: }
4554: if ( ! exists($env{'internal.start_page'})
4555: && exists($env{'internal.end_page'})) {
1.316 albertel 4556: &Apache::lonnet::logthis('end_page called without start_page'.
4557: $env{'request.filename'});
1.315 albertel 4558: }
1.306 albertel 4559: }
1.315 albertel 4560:
1.318 albertel 4561: sub simple_error_page {
4562: my ($r,$title,$msg) = @_;
4563: my $page =
4564: &Apache::loncommon::start_page($title).
4565: &mt($msg).
4566: &Apache::loncommon::end_page();
4567: if (ref($r)) {
4568: $r->print($page);
1.327 albertel 4569: return;
1.318 albertel 4570: }
4571: return $page;
4572: }
1.347 albertel 4573:
4574: {
4575: my $row_count;
4576: sub start_data_table {
1.422 albertel 4577: my ($add_class) = @_;
4578: my $css_class = (join(' ','LC_data_table',$add_class));
1.347 albertel 4579: undef($row_count);
1.422 albertel 4580: return '<table class="'.$css_class.'">'."\n";
1.347 albertel 4581: }
4582:
4583: sub end_data_table {
4584: undef($row_count);
1.389 albertel 4585: return '</table>'."\n";;
1.347 albertel 4586: }
4587:
4588: sub start_data_table_row {
1.422 albertel 4589: my ($add_class) = @_;
1.347 albertel 4590: $row_count++;
1.422 albertel 4591: my $css_class = ($row_count % 2)?'':'LC_even_row';
1.428 albertel 4592: $css_class = (join(' ',$css_class,$add_class));
1.422 albertel 4593: return '<tr class="'.$css_class.'">'."\n";;
1.347 albertel 4594: }
1.471 banghart 4595:
4596: sub continue_data_table_row {
4597: my ($add_class) = @_;
4598: my $css_class = ($row_count % 2)?'':'LC_even_row';
4599: $css_class = (join(' ',$css_class,$add_class));
4600: return '<tr class="'.$css_class.'">'."\n";;
4601: }
1.347 albertel 4602:
4603: sub end_data_table_row {
1.389 albertel 4604: return '</tr>'."\n";;
1.347 albertel 4605: }
1.367 www 4606:
1.421 albertel 4607: sub start_data_table_empty_row {
4608: $row_count++;
4609: return '<tr class="LC_empty_row" >'."\n";;
4610: }
4611:
4612: sub end_data_table_empty_row {
4613: return '</tr>'."\n";;
4614: }
4615:
1.367 www 4616: sub start_data_table_header_row {
1.389 albertel 4617: return '<tr class="LC_header_row">'."\n";;
1.367 www 4618: }
4619:
4620: sub end_data_table_header_row {
1.389 albertel 4621: return '</tr>'."\n";;
1.367 www 4622: }
1.347 albertel 4623: }
4624:
1.251 albertel 4625: ###############################################
1.182 matthew 4626:
4627: =pod
4628:
1.405 albertel 4629: =item * &get_users_function()
1.182 matthew 4630:
4631: Used by &bodytag to determine the current users primary role.
4632: Returns either 'student','coordinator','admin', or 'author'.
4633:
4634: =cut
4635:
4636: ###############################################
4637: sub get_users_function {
4638: my $function = 'student';
1.258 albertel 4639: if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
1.182 matthew 4640: $function='coordinator';
4641: }
1.258 albertel 4642: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 4643: $function='admin';
4644: }
1.258 albertel 4645: if (($env{'request.role'}=~/^(au|ca)/) ||
1.182 matthew 4646: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
4647: $function='author';
4648: }
4649: return $function;
1.54 www 4650: }
1.99 www 4651:
4652: ###############################################
4653:
1.233 raeburn 4654: =pod
4655:
1.405 albertel 4656: =item * &check_user_status
1.274 raeburn 4657:
4658: Determines current status of supplied role for a
4659: specific user. Roles can be active, previous or future.
4660:
4661: Inputs:
4662: user's domain, user's username, course's domain,
1.375 raeburn 4663: course's number, optional section ID.
1.274 raeburn 4664:
4665: Outputs:
4666: role status: active, previous or future.
4667:
4668: =cut
4669:
4670: sub check_user_status {
1.412 raeburn 4671: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274 raeburn 4672: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
4673: my @uroles = keys %userinfo;
4674: my $srchstr;
4675: my $active_chk = 'none';
1.412 raeburn 4676: my $now = time;
1.274 raeburn 4677: if (@uroles > 0) {
1.412 raeburn 4678: if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 4679: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
4680: } else {
1.412 raeburn 4681: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
4682: }
4683: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 4684: my $role_end = 0;
4685: my $role_start = 0;
4686: $active_chk = 'active';
1.412 raeburn 4687: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
4688: $role_end = $1;
4689: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
4690: $role_start = $1;
1.274 raeburn 4691: }
4692: }
4693: if ($role_start > 0) {
1.412 raeburn 4694: if ($now < $role_start) {
1.274 raeburn 4695: $active_chk = 'future';
4696: }
4697: }
4698: if ($role_end > 0) {
1.412 raeburn 4699: if ($now > $role_end) {
1.274 raeburn 4700: $active_chk = 'previous';
4701: }
4702: }
4703: }
4704: }
4705: return $active_chk;
4706: }
4707:
4708: ###############################################
4709:
4710: =pod
4711:
1.405 albertel 4712: =item * &get_sections()
1.233 raeburn 4713:
4714: Determines all the sections for a course including
4715: sections with students and sections containing other roles.
1.419 raeburn 4716: Incoming parameters:
4717:
4718: 1. domain
4719: 2. course number
4720: 3. reference to array containing roles for which sections should
4721: be gathered (optional).
4722: 4. reference to array containing status types for which sections
4723: should be gathered (optional).
4724:
4725: If the third argument is undefined, sections are gathered for any role.
4726: If the fourth argument is undefined, sections are gathered for any status.
4727: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 4728:
1.374 raeburn 4729: Returns section hash (keys are section IDs, values are
4730: number of users in each section), subject to the
1.419 raeburn 4731: optional roles filter, optional status filter
1.233 raeburn 4732:
4733: =cut
4734:
4735: ###############################################
4736: sub get_sections {
1.419 raeburn 4737: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 4738: if (!defined($cdom) || !defined($cnum)) {
4739: my $cid = $env{'request.course.id'};
4740:
4741: return if (!defined($cid));
4742:
4743: $cdom = $env{'course.'.$cid.'.domain'};
4744: $cnum = $env{'course.'.$cid.'.num'};
4745: }
4746:
4747: my %sectioncount;
1.419 raeburn 4748: my $now = time;
1.240 albertel 4749:
1.366 albertel 4750: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276 albertel 4751: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 4752: my $sec_index = &Apache::loncoursedata::CL_SECTION();
4753: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 4754: my $start_index = &Apache::loncoursedata::CL_START();
4755: my $end_index = &Apache::loncoursedata::CL_END();
4756: my $status;
1.366 albertel 4757: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 4758: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
4759: $data->[$status_index],
4760: $data->[$start_index],
4761: $data->[$end_index]);
4762: if ($stu_status eq 'Active') {
4763: $status = 'active';
4764: } elsif ($end < $now) {
4765: $status = 'previous';
4766: } elsif ($start > $now) {
4767: $status = 'future';
4768: }
4769: if ($section ne '-1' && $section !~ /^\s*$/) {
4770: if ((!defined($possible_status)) || (($status ne '') &&
4771: (grep/^\Q$status\E$/,@{$possible_status}))) {
4772: $sectioncount{$section}++;
4773: }
1.240 albertel 4774: }
4775: }
4776: }
4777: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
4778: foreach my $user (sort(keys(%courseroles))) {
4779: if ($user !~ /^(\w{2})/) { next; }
4780: my ($role) = ($user =~ /^(\w{2})/);
4781: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 4782: my ($section,$status);
1.240 albertel 4783: if ($role eq 'cr' &&
4784: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
4785: $section=$1;
4786: }
4787: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
4788: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 4789: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
4790: if ($end == -1 && $start == -1) {
4791: next; #deleted role
4792: }
4793: if (!defined($possible_status)) {
4794: $sectioncount{$section}++;
4795: } else {
4796: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
4797: $status = 'active';
4798: } elsif ($end < $now) {
4799: $status = 'future';
4800: } elsif ($start > $now) {
4801: $status = 'previous';
4802: }
4803: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
4804: $sectioncount{$section}++;
4805: }
4806: }
1.233 raeburn 4807: }
1.366 albertel 4808: return %sectioncount;
1.233 raeburn 4809: }
4810:
1.274 raeburn 4811: ###############################################
1.294 raeburn 4812:
4813: =pod
1.405 albertel 4814:
4815: =item * &get_course_users()
4816:
1.275 raeburn 4817: Retrieves usernames:domains for users in the specified course
4818: with specific role(s), and access status.
4819:
4820: Incoming parameters:
1.277 albertel 4821: 1. course domain
4822: 2. course number
4823: 3. access status: users must have - either active,
1.275 raeburn 4824: previous, future, or all.
1.277 albertel 4825: 4. reference to array of permissible roles
1.288 raeburn 4826: 5. reference to array of section restrictions (optional)
4827: 6. reference to results object (hash of hashes).
4828: 7. reference to optional userdata hash
1.275 raeburn 4829: Keys of top level hash are roles.
4830: Keys of inner hashes are username:domain, with
4831: values set to access type.
1.288 raeburn 4832: Optional userdata hash returns an array with arguments in the
4833: same order as loncoursedata::get_classlist() for student data.
4834:
4835: Entries for end, start, section and status are blank because
4836: of the possibility of multiple values for non-student roles.
4837:
1.275 raeburn 4838: =cut
1.405 albertel 4839:
1.275 raeburn 4840: ###############################################
1.405 albertel 4841:
1.275 raeburn 4842: sub get_course_users {
1.288 raeburn 4843: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata) = @_;
4844: my %idx = ();
1.419 raeburn 4845: my %seclists;
1.288 raeburn 4846:
4847: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
4848: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
4849: $idx{end} = &Apache::loncoursedata::CL_END();
4850: $idx{start} = &Apache::loncoursedata::CL_START();
4851: $idx{id} = &Apache::loncoursedata::CL_ID();
4852: $idx{section} = &Apache::loncoursedata::CL_SECTION();
4853: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
4854: $idx{status} = &Apache::loncoursedata::CL_STATUS();
4855:
1.290 albertel 4856: if (grep(/^st$/,@{$roles})) {
1.276 albertel 4857: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 4858: my $now = time;
1.277 albertel 4859: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 4860: my $match = 0;
1.412 raeburn 4861: my $secmatch = 0;
1.419 raeburn 4862: my $section = $$classlist{$student}[$idx{section}];
4863: if ($section eq '') {
4864: $section = 'none';
4865: }
1.291 albertel 4866: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 4867: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 4868: $secmatch = 1;
4869: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 4870: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 4871: $secmatch = 1;
4872: }
4873: } else {
1.419 raeburn 4874: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 4875: $secmatch = 1;
4876: }
1.290 albertel 4877: }
1.412 raeburn 4878: if (!$secmatch) {
4879: next;
4880: }
1.419 raeburn 4881: }
1.420 albertel 4882: push(@{$seclists{$student}},$section);
1.275 raeburn 4883: if (defined($$types{'active'})) {
1.288 raeburn 4884: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 4885: push(@{$$users{st}{$student}},'active');
1.288 raeburn 4886: $match = 1;
1.275 raeburn 4887: }
4888: }
4889: if (defined($$types{'previous'})) {
1.288 raeburn 4890: if ($$classlist{$student}[$idx{end}] <= $now) {
1.275 raeburn 4891: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 4892: $match = 1;
1.275 raeburn 4893: }
4894: }
4895: if (defined($$types{'future'})) {
1.288 raeburn 4896: if (($$classlist{$student}[$idx{start}] > $now) && ($$classlist{$student}[$idx{end}] > $now) || ($$classlist{$student}[$idx{end}] == 0) || ($$classlist{$student}[$idx{end}] eq '')) {
1.275 raeburn 4897: push(@{$$users{st}{$student}},'future');
1.288 raeburn 4898: $match = 1;
1.275 raeburn 4899: }
4900: }
1.412 raeburn 4901: if ($match && ref($userdata) eq 'HASH') {
1.288 raeburn 4902: $$userdata{$student} = $$classlist{$student};
4903: }
1.275 raeburn 4904: }
4905: }
1.412 raeburn 4906: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 4907: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
4908: my $now = time;
4909: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 4910: my $match = 0;
1.412 raeburn 4911: my $secmatch = 0;
1.439 raeburn 4912: my $status;
1.412 raeburn 4913: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 4914: $user =~ s/:$//;
1.439 raeburn 4915: my ($end,$start) = split(/:/,$coursepersonnel{$person});
4916: if ($end == -1 || $start == -1) {
4917: next;
4918: }
4919: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
4920: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 4921: my ($uname,$udom) = split(/:/,$user);
4922: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 4923: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 4924: $secmatch = 1;
4925: } elsif ($usec eq '') {
1.420 albertel 4926: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 4927: $secmatch = 1;
4928: }
4929: } else {
4930: if (grep(/^\Q$usec\E$/,@{$sections})) {
4931: $secmatch = 1;
4932: }
4933: }
4934: if (!$secmatch) {
4935: next;
4936: }
1.288 raeburn 4937: }
1.419 raeburn 4938: if ($usec eq '') {
4939: $usec = 'none';
4940: }
1.275 raeburn 4941: if ($uname ne '' && $udom ne '') {
1.439 raeburn 4942: if ($end < $now) {
4943: $status = 'previous';
4944: } elsif ($start > $now) {
4945: $status = 'future';
4946: } else {
4947: $status = 'active';
4948: }
1.277 albertel 4949: foreach my $type (keys(%{$types})) {
1.275 raeburn 4950: if ($status eq $type) {
1.420 albertel 4951: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 4952: push(@{$$users{$role}{$user}},$type);
4953: }
1.288 raeburn 4954: $match = 1;
4955: }
4956: }
1.419 raeburn 4957: if (($match) && (ref($userdata) eq 'HASH')) {
4958: if (!exists($$userdata{$uname.':'.$udom})) {
4959: &get_user_info($udom,$uname,\%idx,$userdata);
4960: }
1.420 albertel 4961: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 4962: push(@{$seclists{$uname.':'.$udom}},$usec);
4963: }
1.275 raeburn 4964: }
4965: }
4966: }
4967: }
1.290 albertel 4968: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 4969: if ((defined($cdom)) && (defined($cnum))) {
4970: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
4971: if ( defined($csettings{'internal.courseowner'}) ) {
4972: my $owner = $csettings{'internal.courseowner'};
1.439 raeburn 4973: if ($owner !~ /^[^:]+:[^:]+$/) {
4974: $owner = $owner.':'.$cdom;
4975: }
4976: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 4977: if (defined($userdata) &&
4978: !exists($$userdata{$owner.':'.$cdom})) {
4979: &get_user_info($cdom,$owner,\%idx,$userdata);
1.420 albertel 4980: if (!grep(/^none$/,@{$seclists{$owner.':'.$cdom}})) {
1.419 raeburn 4981: push(@{$seclists{$owner.':'.$cdom}},'none');
4982: }
1.290 albertel 4983: }
1.279 raeburn 4984: }
4985: }
4986: }
1.419 raeburn 4987: foreach my $user (keys(%seclists)) {
4988: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
4989: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
4990: }
1.275 raeburn 4991: }
4992: return;
4993: }
4994:
1.288 raeburn 4995: sub get_user_info {
4996: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 4997: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
4998: &plainname($uname,$udom,'lastname');
1.291 albertel 4999: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 5000: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.288 raeburn 5001: return;
5002: }
1.275 raeburn 5003:
1.472 raeburn 5004: ###############################################
5005:
5006: =pod
5007:
5008: =item * &get_user_quota()
5009:
5010: Retrieves quota assigned for storage of portfolio files for a user
5011:
5012: Incoming parameters:
5013: 1. user's username
5014: 2. user's domain
5015:
5016: Returns:
5017: 1. Disk quota (in Mb) assigned to student.
5018:
5019: If a value has been stored in the user's environment,
5020: it will return that, otherwise it returns the default
5021: for users in the domain.
5022:
5023: =cut
5024:
5025: ###############################################
5026:
5027:
5028: sub get_user_quota {
5029: my ($uname,$udom) = @_;
5030: my $quota;
5031: if (!defined($udom)) {
5032: $udom = $env{'user.domain'};
5033: }
5034: if (!defined($uname)) {
5035: $uname = $env{'user.name'};
5036: }
5037: if (($udom eq '' || $uname eq '') ||
5038: ($udom eq 'public') && ($uname eq 'public')) {
5039: $quota = 0;
5040: } else {
5041: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
5042: $quota = $env{'environment.portfolioquota'};
5043: } else {
5044: my %userenv = &Apache::lonnet::dump('environment',$udom,$uname);
5045: my ($tmp) = keys(%userenv);
5046: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
5047: $quota = $userenv{'portfolioquota'};
5048: } else {
5049: undef(%userenv);
5050: }
5051: }
5052: if ($quota eq '') {
5053: $quota = &default_quota($udom);
5054: }
5055: }
5056: return $quota;
5057: }
5058:
5059: ###############################################
5060:
5061: =pod
5062:
5063: =item * &default_quota()
5064:
5065: Retrieves default quota assigned for storage of user portfolio files
5066:
5067: Incoming parameters:
5068: 1. domain
5069:
5070: Returns:
5071: 1. Default disk quota (in Mb) for user portfolios in the domain.
5072:
5073: If a value has been stored in the domain's configuration db,
5074: it will return that, otherwise it returns 20 (for backwards
5075: compatibility with domains which have not set up a configuration
5076: db file; the original statically defined portfolio quota was 20 Mb).
5077:
5078: =cut
5079:
5080: ###############################################
5081:
5082:
5083: sub default_quota {
5084: my ($udom) = @_;
5085: my %defaults = &Apache::lonnet::get_dom('configuration',
5086: ['portfolioquota'],$udom);
5087: if ($defaults{'portfolioquota'} ne '') {
5088: return $defaults{'portfolioquota'};
5089: } else {
5090: return '20';
5091: }
5092: }
5093:
1.384 raeburn 5094: sub get_secgrprole_info {
5095: my ($cdom,$cnum,$needroles,$type) = @_;
5096: my %sections_count = &get_sections($cdom,$cnum);
5097: my @sections = (sort {$a <=> $b} keys(%sections_count));
5098: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
5099: my @groups = sort(keys(%curr_groups));
5100: my $allroles = [];
5101: my $rolehash;
5102: my $accesshash = {
5103: active => 'Currently has access',
5104: future => 'Will have future access',
5105: previous => 'Previously had access',
5106: };
5107: if ($needroles) {
5108: $rolehash = {'all' => 'all'};
1.385 albertel 5109: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
5110: if (&Apache::lonnet::error(%user_roles)) {
5111: undef(%user_roles);
5112: }
5113: foreach my $item (keys(%user_roles)) {
1.384 raeburn 5114: my ($role)=split(/\:/,$item,2);
5115: if ($role eq 'cr') { next; }
5116: if ($role =~ /^cr/) {
5117: $$rolehash{$role} = (split('/',$role))[3];
5118: } else {
5119: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
5120: }
5121: }
5122: foreach my $key (sort(keys(%{$rolehash}))) {
5123: push(@{$allroles},$key);
5124: }
5125: push (@{$allroles},'st');
5126: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
5127: }
5128: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
5129: }
5130:
1.112 bowersj2 5131: =pod
5132:
5133: =item * get_unprocessed_cgi($query,$possible_names)
5134:
1.258 albertel 5135: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 5136: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 5137: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 5138:
5139: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
5140: $possible_names is an ref to an array of form element names. As an example:
5141: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 5142: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 5143:
5144: =cut
1.1 albertel 5145:
1.6 albertel 5146: sub get_unprocessed_cgi {
1.25 albertel 5147: my ($query,$possible_names)= @_;
1.26 matthew 5148: # $Apache::lonxml::debug=1;
1.356 albertel 5149: foreach my $pair (split(/&/,$query)) {
5150: my ($name, $value) = split(/=/,$pair);
1.369 www 5151: $name = &unescape($name);
1.25 albertel 5152: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
5153: $value =~ tr/+/ /;
5154: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 5155: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 5156: }
1.16 harris41 5157: }
1.6 albertel 5158: }
5159:
1.112 bowersj2 5160: =pod
5161:
5162: =item * cacheheader()
5163:
5164: returns cache-controlling header code
5165:
5166: =cut
5167:
1.7 albertel 5168: sub cacheheader {
1.258 albertel 5169: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 5170: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
5171: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 5172: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
5173: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 5174: return $output;
1.7 albertel 5175: }
5176:
1.112 bowersj2 5177: =pod
5178:
5179: =item * no_cache($r)
5180:
5181: specifies header code to not have cache
5182:
5183: =cut
5184:
1.9 albertel 5185: sub no_cache {
1.216 albertel 5186: my ($r) = @_;
5187: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 5188: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 5189: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
5190: $r->no_cache(1);
5191: $r->header_out("Expires" => $date);
5192: $r->header_out("Pragma" => "no-cache");
1.123 www 5193: }
5194:
5195: sub content_type {
1.181 albertel 5196: my ($r,$type,$charset) = @_;
1.299 foxr 5197: if ($r) {
5198: # Note that printout.pl calls this with undef for $r.
5199: &no_cache($r);
5200: }
1.258 albertel 5201: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 5202: unless ($charset) {
5203: $charset=&Apache::lonlocal::current_encoding;
5204: }
5205: if ($charset) { $type.='; charset='.$charset; }
5206: if ($r) {
5207: $r->content_type($type);
5208: } else {
5209: print("Content-type: $type\n\n");
5210: }
1.9 albertel 5211: }
1.25 albertel 5212:
1.112 bowersj2 5213: =pod
5214:
5215: =item * add_to_env($name,$value)
5216:
1.258 albertel 5217: adds $name to the %env hash with value
1.112 bowersj2 5218: $value, if $name already exists, the entry is converted to an array
5219: reference and $value is added to the array.
5220:
5221: =cut
5222:
1.25 albertel 5223: sub add_to_env {
5224: my ($name,$value)=@_;
1.258 albertel 5225: if (defined($env{$name})) {
5226: if (ref($env{$name})) {
1.25 albertel 5227: #already have multiple values
1.258 albertel 5228: push(@{ $env{$name} },$value);
1.25 albertel 5229: } else {
5230: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 5231: my $first=$env{$name};
5232: undef($env{$name});
5233: push(@{ $env{$name} },$first,$value);
1.25 albertel 5234: }
5235: } else {
1.258 albertel 5236: $env{$name}=$value;
1.25 albertel 5237: }
1.31 albertel 5238: }
1.149 albertel 5239:
5240: =pod
5241:
5242: =item * get_env_multiple($name)
5243:
1.258 albertel 5244: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 5245: values may be defined and end up as an array ref.
5246:
5247: returns an array of values
5248:
5249: =cut
5250:
5251: sub get_env_multiple {
5252: my ($name) = @_;
5253: my @values;
1.258 albertel 5254: if (defined($env{$name})) {
1.149 albertel 5255: # exists is it an array
1.258 albertel 5256: if (ref($env{$name})) {
5257: @values=@{ $env{$name} };
1.149 albertel 5258: } else {
1.258 albertel 5259: $values[0]=$env{$name};
1.149 albertel 5260: }
5261: }
5262: return(@values);
5263: }
5264:
1.31 albertel 5265:
1.41 ng 5266: =pod
1.45 matthew 5267:
1.464 albertel 5268: =back
1.41 ng 5269:
1.112 bowersj2 5270: =head1 CSV Upload/Handling functions
1.38 albertel 5271:
1.41 ng 5272: =over 4
5273:
1.112 bowersj2 5274: =item * upfile_store($r)
1.41 ng 5275:
5276: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 5277: needs $env{'form.upfile'}
1.41 ng 5278: returns $datatoken to be put into hidden field
5279:
5280: =cut
1.31 albertel 5281:
5282: sub upfile_store {
5283: my $r=shift;
1.258 albertel 5284: $env{'form.upfile'}=~s/\r/\n/gs;
5285: $env{'form.upfile'}=~s/\f/\n/gs;
5286: $env{'form.upfile'}=~s/\n+/\n/gs;
5287: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 5288:
1.258 albertel 5289: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
5290: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 5291: {
1.158 raeburn 5292: my $datafile = $r->dir_config('lonDaemons').
5293: '/tmp/'.$datatoken.'.tmp';
5294: if ( open(my $fh,">$datafile") ) {
1.258 albertel 5295: print $fh $env{'form.upfile'};
1.158 raeburn 5296: close($fh);
5297: }
1.31 albertel 5298: }
5299: return $datatoken;
5300: }
5301:
1.56 matthew 5302: =pod
5303:
1.112 bowersj2 5304: =item * load_tmp_file($r)
1.41 ng 5305:
5306: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 5307: needs $env{'form.datatoken'},
5308: sets $env{'form.upfile'} to the contents of the file
1.41 ng 5309:
5310: =cut
1.31 albertel 5311:
5312: sub load_tmp_file {
5313: my $r=shift;
5314: my @studentdata=();
5315: {
1.158 raeburn 5316: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 5317: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 5318: if ( open(my $fh,"<$studentfile") ) {
5319: @studentdata=<$fh>;
5320: close($fh);
5321: }
1.31 albertel 5322: }
1.258 albertel 5323: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 5324: }
5325:
1.56 matthew 5326: =pod
5327:
1.112 bowersj2 5328: =item * upfile_record_sep()
1.41 ng 5329:
5330: Separate uploaded file into records
5331: returns array of records,
1.258 albertel 5332: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 5333:
5334: =cut
1.31 albertel 5335:
5336: sub upfile_record_sep {
1.258 albertel 5337: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 5338: } else {
1.248 albertel 5339: my @records;
1.258 albertel 5340: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 5341: if ($line=~/^\s*$/) { next; }
5342: push(@records,$line);
5343: }
5344: return @records;
1.31 albertel 5345: }
5346: }
5347:
1.56 matthew 5348: =pod
5349:
1.112 bowersj2 5350: =item * record_sep($record)
1.41 ng 5351:
1.258 albertel 5352: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 5353:
5354: =cut
5355:
1.263 www 5356: sub takeleft {
5357: my $index=shift;
5358: return substr('0000'.$index,-4,4);
5359: }
5360:
1.31 albertel 5361: sub record_sep {
5362: my $record=shift;
5363: my %components=();
1.258 albertel 5364: if ($env{'form.upfiletype'} eq 'xml') {
5365: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 5366: my $i=0;
1.356 albertel 5367: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 5368: $field=~s/^(\"|\')//;
5369: $field=~s/(\"|\')$//;
1.263 www 5370: $components{&takeleft($i)}=$field;
1.31 albertel 5371: $i++;
5372: }
1.258 albertel 5373: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 5374: my $i=0;
1.356 albertel 5375: foreach my $field (split(/\t/,$record)) {
1.31 albertel 5376: $field=~s/^(\"|\')//;
5377: $field=~s/(\"|\')$//;
1.263 www 5378: $components{&takeleft($i)}=$field;
1.31 albertel 5379: $i++;
5380: }
5381: } else {
1.480 banghart 5382: my @allfields;
5383: if ($env{'form.upfiletype'} eq 'semisv') {
5384: @allfields=split(/;/,$record);
5385: } else {
5386: @allfields=split(/\,/,$record);
5387: }
1.31 albertel 5388: my $i=0;
5389: my $j;
5390: for ($j=0;$j<=$#allfields;$j++) {
5391: my $field=$allfields[$j];
5392: if ($field=~/^\s*(\"|\')/) {
5393: my $delimiter=$1;
5394: while (($field!~/$delimiter$/) && ($j<$#allfields)) {
5395: $j++;
5396: $field.=','.$allfields[$j];
5397: }
5398: $field=~s/^\s*$delimiter//;
5399: $field=~s/$delimiter\s*$//;
5400: }
1.263 www 5401: $components{&takeleft($i)}=$field;
1.31 albertel 5402: $i++;
5403: }
5404: }
5405: return %components;
5406: }
5407:
1.144 matthew 5408: ######################################################
5409: ######################################################
5410:
1.56 matthew 5411: =pod
5412:
1.112 bowersj2 5413: =item * upfile_select_html()
1.41 ng 5414:
1.144 matthew 5415: Return HTML code to select a file from the users machine and specify
5416: the file type.
1.41 ng 5417:
5418: =cut
5419:
1.144 matthew 5420: ######################################################
5421: ######################################################
1.31 albertel 5422: sub upfile_select_html {
1.144 matthew 5423: my %Types = (
5424: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 5425: semisv => &mt('Semicolon separated values'),
1.144 matthew 5426: space => &mt('Space separated'),
5427: tab => &mt('Tabulator separated'),
5428: # xml => &mt('HTML/XML'),
5429: );
5430: my $Str = '<input type="file" name="upfile" size="50" />'.
5431: '<br />Type: <select name="upfiletype">';
5432: foreach my $type (sort(keys(%Types))) {
5433: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
5434: }
5435: $Str .= "</select>\n";
5436: return $Str;
1.31 albertel 5437: }
5438:
1.301 albertel 5439: sub get_samples {
5440: my ($records,$toget) = @_;
5441: my @samples=({});
5442: my $got=0;
5443: foreach my $rec (@$records) {
5444: my %temp = &record_sep($rec);
5445: if (! grep(/\S/, values(%temp))) { next; }
5446: if (%temp) {
5447: $samples[$got]=\%temp;
5448: $got++;
5449: if ($got == $toget) { last; }
5450: }
5451: }
5452: return \@samples;
5453: }
5454:
1.144 matthew 5455: ######################################################
5456: ######################################################
5457:
1.56 matthew 5458: =pod
5459:
1.112 bowersj2 5460: =item * csv_print_samples($r,$records)
1.41 ng 5461:
5462: Prints a table of sample values from each column uploaded $r is an
5463: Apache Request ref, $records is an arrayref from
5464: &Apache::loncommon::upfile_record_sep
5465:
5466: =cut
5467:
1.144 matthew 5468: ######################################################
5469: ######################################################
1.31 albertel 5470: sub csv_print_samples {
5471: my ($r,$records) = @_;
1.301 albertel 5472: my $samples = &get_samples($records,3);
5473:
1.144 matthew 5474: $r->print(&mt('Samples').'<br /><table border="2"><tr>');
1.356 albertel 5475: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
5476: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.31 albertel 5477: $r->print('</tr>');
1.301 albertel 5478: foreach my $hash (@$samples) {
1.31 albertel 5479: $r->print('<tr>');
1.356 albertel 5480: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 5481: $r->print('<td>');
1.356 albertel 5482: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 5483: $r->print('</td>');
5484: }
5485: $r->print('</tr>');
5486: }
5487: $r->print('</tr></table><br />'."\n");
5488: }
5489:
1.144 matthew 5490: ######################################################
5491: ######################################################
5492:
1.56 matthew 5493: =pod
5494:
1.112 bowersj2 5495: =item * csv_print_select_table($r,$records,$d)
1.41 ng 5496:
5497: Prints a table to create associations between values and table columns.
1.144 matthew 5498:
1.41 ng 5499: $r is an Apache Request ref,
5500: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 5501: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 5502:
5503: =cut
5504:
1.144 matthew 5505: ######################################################
5506: ######################################################
1.31 albertel 5507: sub csv_print_select_table {
5508: my ($r,$records,$d) = @_;
1.301 albertel 5509: my $i=0;
5510: my $samples = &get_samples($records,1);
1.144 matthew 5511: $r->print(&mt('Associate columns with student attributes.')."\n".
5512: '<table border="2"><tr>'.
5513: '<th>'.&mt('Attribute').'</th>'.
5514: '<th>'.&mt('Column').'</th></tr>'."\n");
1.356 albertel 5515: foreach my $array_ref (@$d) {
5516: my ($value,$display,$defaultcol)=@{ $array_ref };
1.31 albertel 5517: $r->print('<tr><td>'.$display.'</td>');
5518:
5519: $r->print('<td><select name=f'.$i.
1.32 matthew 5520: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 5521: $r->print('<option value="none"></option>');
1.356 albertel 5522: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
5523: $r->print('<option value="'.$sample.'"'.
5524: ($sample eq $defaultcol ? ' selected="selected" ' : '').
5525: '>Column '.($sample+1).'</option>');
1.31 albertel 5526: }
5527: $r->print('</select></td></tr>'."\n");
5528: $i++;
5529: }
5530: $i--;
5531: return $i;
5532: }
1.56 matthew 5533:
1.144 matthew 5534: ######################################################
5535: ######################################################
5536:
1.56 matthew 5537: =pod
1.31 albertel 5538:
1.112 bowersj2 5539: =item * csv_samples_select_table($r,$records,$d)
1.41 ng 5540:
5541: Prints a table of sample values from the upload and can make associate samples to internal names.
5542:
5543: $r is an Apache Request ref,
5544: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
5545: $d is an array of 2 element arrays (internal name, displayed name)
5546:
5547: =cut
5548:
1.144 matthew 5549: ######################################################
5550: ######################################################
1.31 albertel 5551: sub csv_samples_select_table {
5552: my ($r,$records,$d) = @_;
5553: my $i=0;
1.144 matthew 5554: #
1.301 albertel 5555: my $samples = &get_samples($records,3);
1.144 matthew 5556: $r->print('<table border=2><tr><th>'.
5557: &mt('Field').'</th><th>'.&mt('Samples').'</th></tr>');
1.301 albertel 5558:
5559: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.144 matthew 5560: $r->print('<tr><td><select name="f'.$i.'"'.
1.32 matthew 5561: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 5562: foreach my $option (@$d) {
5563: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 5564: $r->print('<option value="'.$value.'"'.
1.253 albertel 5565: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 5566: $display.'</option>');
1.31 albertel 5567: }
5568: $r->print('</select></td><td>');
1.301 albertel 5569: foreach my $line (0..2) {
5570: if (defined($samples->[$line]{$key})) {
5571: $r->print($samples->[$line]{$key}."<br />\n");
5572: }
5573: }
1.31 albertel 5574: $r->print('</td></tr>');
5575: $i++;
5576: }
5577: $i--;
5578: return($i);
1.115 matthew 5579: }
5580:
1.144 matthew 5581: ######################################################
5582: ######################################################
5583:
1.115 matthew 5584: =pod
5585:
5586: =item clean_excel_name($name)
5587:
5588: Returns a replacement for $name which does not contain any illegal characters.
5589:
5590: =cut
5591:
1.144 matthew 5592: ######################################################
5593: ######################################################
1.115 matthew 5594: sub clean_excel_name {
5595: my ($name) = @_;
5596: $name =~ s/[:\*\?\/\\]//g;
5597: if (length($name) > 31) {
5598: $name = substr($name,0,31);
5599: }
5600: return $name;
1.25 albertel 5601: }
1.84 albertel 5602:
1.85 albertel 5603: =pod
5604:
1.112 bowersj2 5605: =item * check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 5606:
5607: Returns either 1 or undef
5608:
5609: 1 if the part is to be hidden, undef if it is to be shown
5610:
5611: Arguments are:
5612:
5613: $id the id of the part to be checked
5614: $symb, optional the symb of the resource to check
5615: $udom, optional the domain of the user to check for
5616: $uname, optional the username of the user to check for
5617:
5618: =cut
1.84 albertel 5619:
5620: sub check_if_partid_hidden {
5621: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 5622: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 5623: $symb,$udom,$uname);
1.141 albertel 5624: my $truth=1;
5625: #if the string starts with !, then the list is the list to show not hide
5626: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 5627: my @hiddenlist=split(/,/,$hiddenparts);
5628: foreach my $checkid (@hiddenlist) {
1.141 albertel 5629: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 5630: }
1.141 albertel 5631: return !$truth;
1.84 albertel 5632: }
1.127 matthew 5633:
1.138 matthew 5634:
5635: ############################################################
5636: ############################################################
5637:
5638: =pod
5639:
1.157 matthew 5640: =back
5641:
1.138 matthew 5642: =head1 cgi-bin script and graphing routines
5643:
1.157 matthew 5644: =over 4
5645:
1.138 matthew 5646: =item get_cgi_id
5647:
5648: Inputs: none
5649:
5650: Returns an id which can be used to pass environment variables
5651: to various cgi-bin scripts. These environment variables will
5652: be removed from the users environment after a given time by
5653: the routine &Apache::lonnet::transfer_profile_to_env.
5654:
5655: =cut
5656:
5657: ############################################################
5658: ############################################################
1.152 albertel 5659: my $uniq=0;
1.136 matthew 5660: sub get_cgi_id {
1.154 albertel 5661: $uniq=($uniq+1)%100000;
1.280 albertel 5662: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 5663: }
5664:
1.127 matthew 5665: ############################################################
5666: ############################################################
5667:
5668: =pod
5669:
1.134 matthew 5670: =item DrawBarGraph
1.127 matthew 5671:
1.138 matthew 5672: Facilitates the plotting of data in a (stacked) bar graph.
5673: Puts plot definition data into the users environment in order for
5674: graph.png to plot it. Returns an <img> tag for the plot.
5675: The bars on the plot are labeled '1','2',...,'n'.
5676:
5677: Inputs:
5678:
5679: =over 4
5680:
5681: =item $Title: string, the title of the plot
5682:
5683: =item $xlabel: string, text describing the X-axis of the plot
5684:
5685: =item $ylabel: string, text describing the Y-axis of the plot
5686:
5687: =item $Max: scalar, the maximum Y value to use in the plot
5688: If $Max is < any data point, the graph will not be rendered.
5689:
1.140 matthew 5690: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 5691: they are plotted. If undefined, default values will be used.
5692:
1.178 matthew 5693: =item $labels: array ref holding the labels to use on the x-axis for the bars.
5694:
1.138 matthew 5695: =item @Values: An array of array references. Each array reference holds data
5696: to be plotted in a stacked bar chart.
5697:
1.239 matthew 5698: =item If the final element of @Values is a hash reference the key/value
5699: pairs will be added to the graph definition.
5700:
1.138 matthew 5701: =back
5702:
5703: Returns:
5704:
5705: An <img> tag which references graph.png and the appropriate identifying
5706: information for the plot.
5707:
1.127 matthew 5708: =cut
5709:
5710: ############################################################
5711: ############################################################
1.134 matthew 5712: sub DrawBarGraph {
1.178 matthew 5713: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 5714: #
5715: if (! defined($colors)) {
5716: $colors = ['#33ff00',
5717: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
5718: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
5719: ];
5720: }
1.228 matthew 5721: my $extra_settings = {};
5722: if (ref($Values[-1]) eq 'HASH') {
5723: $extra_settings = pop(@Values);
5724: }
1.127 matthew 5725: #
1.136 matthew 5726: my $identifier = &get_cgi_id();
5727: my $id = 'cgi.'.$identifier;
1.129 matthew 5728: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 5729: return '';
5730: }
1.225 matthew 5731: #
5732: my @Labels;
5733: if (defined($labels)) {
5734: @Labels = @$labels;
5735: } else {
5736: for (my $i=0;$i<@{$Values[0]};$i++) {
5737: push (@Labels,$i+1);
5738: }
5739: }
5740: #
1.129 matthew 5741: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 5742: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 5743: my %ValuesHash;
5744: my $NumSets=1;
5745: foreach my $array (@Values) {
5746: next if (! ref($array));
1.136 matthew 5747: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 5748: join(',',@$array);
1.129 matthew 5749: }
1.127 matthew 5750: #
1.136 matthew 5751: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 5752: if ($NumBars < 3) {
5753: $width = 120+$NumBars*32;
1.220 matthew 5754: $xskip = 1;
1.225 matthew 5755: $bar_width = 30;
5756: } elsif ($NumBars < 5) {
5757: $width = 120+$NumBars*20;
5758: $xskip = 1;
5759: $bar_width = 20;
1.220 matthew 5760: } elsif ($NumBars < 10) {
1.136 matthew 5761: $width = 120+$NumBars*15;
5762: $xskip = 1;
5763: $bar_width = 15;
5764: } elsif ($NumBars <= 25) {
5765: $width = 120+$NumBars*11;
5766: $xskip = 5;
5767: $bar_width = 8;
5768: } elsif ($NumBars <= 50) {
5769: $width = 120+$NumBars*8;
5770: $xskip = 5;
5771: $bar_width = 4;
5772: } else {
5773: $width = 120+$NumBars*8;
5774: $xskip = 5;
5775: $bar_width = 4;
5776: }
5777: #
1.137 matthew 5778: $Max = 1 if ($Max < 1);
5779: if ( int($Max) < $Max ) {
5780: $Max++;
5781: $Max = int($Max);
5782: }
1.127 matthew 5783: $Title = '' if (! defined($Title));
5784: $xlabel = '' if (! defined($xlabel));
5785: $ylabel = '' if (! defined($ylabel));
1.369 www 5786: $ValuesHash{$id.'.title'} = &escape($Title);
5787: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
5788: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 5789: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 5790: $ValuesHash{$id.'.NumBars'} = $NumBars;
5791: $ValuesHash{$id.'.NumSets'} = $NumSets;
5792: $ValuesHash{$id.'.PlotType'} = 'bar';
5793: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
5794: $ValuesHash{$id.'.height'} = $height;
5795: $ValuesHash{$id.'.width'} = $width;
5796: $ValuesHash{$id.'.xskip'} = $xskip;
5797: $ValuesHash{$id.'.bar_width'} = $bar_width;
5798: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 5799: #
1.228 matthew 5800: # Deal with other parameters
5801: while (my ($key,$value) = each(%$extra_settings)) {
5802: $ValuesHash{$id.'.'.$key} = $value;
5803: }
5804: #
1.137 matthew 5805: &Apache::lonnet::appenv(%ValuesHash);
5806: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
5807: }
5808:
5809: ############################################################
5810: ############################################################
5811:
5812: =pod
5813:
5814: =item DrawXYGraph
5815:
1.138 matthew 5816: Facilitates the plotting of data in an XY graph.
5817: Puts plot definition data into the users environment in order for
5818: graph.png to plot it. Returns an <img> tag for the plot.
5819:
5820: Inputs:
5821:
5822: =over 4
5823:
5824: =item $Title: string, the title of the plot
5825:
5826: =item $xlabel: string, text describing the X-axis of the plot
5827:
5828: =item $ylabel: string, text describing the Y-axis of the plot
5829:
5830: =item $Max: scalar, the maximum Y value to use in the plot
5831: If $Max is < any data point, the graph will not be rendered.
5832:
5833: =item $colors: Array ref containing the hex color codes for the data to be
5834: plotted in. If undefined, default values will be used.
5835:
5836: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
5837:
5838: =item $Ydata: Array ref containing Array refs.
1.185 www 5839: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 5840:
5841: =item %Values: hash indicating or overriding any default values which are
5842: passed to graph.png.
5843: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
5844:
5845: =back
5846:
5847: Returns:
5848:
5849: An <img> tag which references graph.png and the appropriate identifying
5850: information for the plot.
5851:
1.137 matthew 5852: =cut
5853:
5854: ############################################################
5855: ############################################################
5856: sub DrawXYGraph {
5857: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
5858: #
5859: # Create the identifier for the graph
5860: my $identifier = &get_cgi_id();
5861: my $id = 'cgi.'.$identifier;
5862: #
5863: $Title = '' if (! defined($Title));
5864: $xlabel = '' if (! defined($xlabel));
5865: $ylabel = '' if (! defined($ylabel));
5866: my %ValuesHash =
5867: (
1.369 www 5868: $id.'.title' => &escape($Title),
5869: $id.'.xlabel' => &escape($xlabel),
5870: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 5871: $id.'.y_max_value'=> $Max,
5872: $id.'.labels' => join(',',@$Xlabels),
5873: $id.'.PlotType' => 'XY',
5874: );
5875: #
5876: if (defined($colors) && ref($colors) eq 'ARRAY') {
5877: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
5878: }
5879: #
5880: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
5881: return '';
5882: }
5883: my $NumSets=1;
1.138 matthew 5884: foreach my $array (@{$Ydata}){
1.137 matthew 5885: next if (! ref($array));
5886: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
5887: }
1.138 matthew 5888: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 5889: #
5890: # Deal with other parameters
5891: while (my ($key,$value) = each(%Values)) {
5892: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 5893: }
5894: #
1.136 matthew 5895: &Apache::lonnet::appenv(%ValuesHash);
5896: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
5897: }
5898:
5899: ############################################################
5900: ############################################################
5901:
5902: =pod
5903:
1.138 matthew 5904: =item DrawXYYGraph
5905:
5906: Facilitates the plotting of data in an XY graph with two Y axes.
5907: Puts plot definition data into the users environment in order for
5908: graph.png to plot it. Returns an <img> tag for the plot.
5909:
5910: Inputs:
5911:
5912: =over 4
5913:
5914: =item $Title: string, the title of the plot
5915:
5916: =item $xlabel: string, text describing the X-axis of the plot
5917:
5918: =item $ylabel: string, text describing the Y-axis of the plot
5919:
5920: =item $colors: Array ref containing the hex color codes for the data to be
5921: plotted in. If undefined, default values will be used.
5922:
5923: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
5924:
5925: =item $Ydata1: The first data set
5926:
5927: =item $Min1: The minimum value of the left Y-axis
5928:
5929: =item $Max1: The maximum value of the left Y-axis
5930:
5931: =item $Ydata2: The second data set
5932:
5933: =item $Min2: The minimum value of the right Y-axis
5934:
5935: =item $Max2: The maximum value of the left Y-axis
5936:
5937: =item %Values: hash indicating or overriding any default values which are
5938: passed to graph.png.
5939: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
5940:
5941: =back
5942:
5943: Returns:
5944:
5945: An <img> tag which references graph.png and the appropriate identifying
5946: information for the plot.
1.136 matthew 5947:
5948: =cut
5949:
5950: ############################################################
5951: ############################################################
1.137 matthew 5952: sub DrawXYYGraph {
5953: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
5954: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 5955: #
5956: # Create the identifier for the graph
5957: my $identifier = &get_cgi_id();
5958: my $id = 'cgi.'.$identifier;
5959: #
5960: $Title = '' if (! defined($Title));
5961: $xlabel = '' if (! defined($xlabel));
5962: $ylabel = '' if (! defined($ylabel));
5963: my %ValuesHash =
5964: (
1.369 www 5965: $id.'.title' => &escape($Title),
5966: $id.'.xlabel' => &escape($xlabel),
5967: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 5968: $id.'.labels' => join(',',@$Xlabels),
5969: $id.'.PlotType' => 'XY',
5970: $id.'.NumSets' => 2,
1.137 matthew 5971: $id.'.two_axes' => 1,
5972: $id.'.y1_max_value' => $Max1,
5973: $id.'.y1_min_value' => $Min1,
5974: $id.'.y2_max_value' => $Max2,
5975: $id.'.y2_min_value' => $Min2,
1.136 matthew 5976: );
5977: #
1.137 matthew 5978: if (defined($colors) && ref($colors) eq 'ARRAY') {
5979: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
5980: }
5981: #
5982: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
5983: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 5984: return '';
5985: }
5986: my $NumSets=1;
1.137 matthew 5987: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 5988: next if (! ref($array));
5989: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 5990: }
5991: #
5992: # Deal with other parameters
5993: while (my ($key,$value) = each(%Values)) {
5994: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 5995: }
5996: #
5997: &Apache::lonnet::appenv(%ValuesHash);
1.130 albertel 5998: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 5999: }
6000:
6001: ############################################################
6002: ############################################################
6003:
6004: =pod
6005:
1.157 matthew 6006: =back
6007:
1.139 matthew 6008: =head1 Statistics helper routines?
6009:
6010: Bad place for them but what the hell.
6011:
1.157 matthew 6012: =over 4
6013:
1.139 matthew 6014: =item &chartlink
6015:
6016: Returns a link to the chart for a specific student.
6017:
6018: Inputs:
6019:
6020: =over 4
6021:
6022: =item $linktext: The text of the link
6023:
6024: =item $sname: The students username
6025:
6026: =item $sdomain: The students domain
6027:
6028: =back
6029:
1.157 matthew 6030: =back
6031:
1.139 matthew 6032: =cut
6033:
6034: ############################################################
6035: ############################################################
6036: sub chartlink {
6037: my ($linktext, $sname, $sdomain) = @_;
6038: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 6039: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 6040: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 6041: '">'.$linktext.'</a>';
1.153 matthew 6042: }
6043:
6044: #######################################################
6045: #######################################################
6046:
6047: =pod
6048:
6049: =head1 Course Environment Routines
1.157 matthew 6050:
6051: =over 4
1.153 matthew 6052:
6053: =item &restore_course_settings
6054:
6055: =item &store_course_settings
6056:
6057: Restores/Store indicated form parameters from the course environment.
6058: Will not overwrite existing values of the form parameters.
6059:
6060: Inputs:
6061: a scalar describing the data (e.g. 'chart', 'problem_analysis')
6062:
6063: a hash ref describing the data to be stored. For example:
6064:
6065: %Save_Parameters = ('Status' => 'scalar',
6066: 'chartoutputmode' => 'scalar',
6067: 'chartoutputdata' => 'scalar',
6068: 'Section' => 'array',
1.373 raeburn 6069: 'Group' => 'array',
1.153 matthew 6070: 'StudentData' => 'array',
6071: 'Maps' => 'array');
6072:
6073: Returns: both routines return nothing
6074:
6075: =cut
6076:
6077: #######################################################
6078: #######################################################
6079: sub store_course_settings {
1.496 albertel 6080: return &store_settings($env{'request.course.id'},@_);
6081: }
6082:
6083: sub store_settings {
1.153 matthew 6084: # save to the environment
6085: # appenv the same items, just to be safe
1.300 albertel 6086: my $udom = $env{'user.domain'};
6087: my $uname = $env{'user.name'};
1.496 albertel 6088: my ($context,$prefix,$Settings) = @_;
1.153 matthew 6089: my %SaveHash;
6090: my %AppHash;
6091: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 6092: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 6093: my $envname = 'environment.'.$basename;
1.258 albertel 6094: if (exists($env{'form.'.$setting})) {
1.153 matthew 6095: # Save this value away
6096: if ($type eq 'scalar' &&
1.258 albertel 6097: (! exists($env{$envname}) ||
6098: $env{$envname} ne $env{'form.'.$setting})) {
6099: $SaveHash{$basename} = $env{'form.'.$setting};
6100: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 6101: } elsif ($type eq 'array') {
6102: my $stored_form;
1.258 albertel 6103: if (ref($env{'form.'.$setting})) {
1.153 matthew 6104: $stored_form = join(',',
6105: map {
1.369 www 6106: &escape($_);
1.258 albertel 6107: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 6108: } else {
6109: $stored_form =
1.369 www 6110: &escape($env{'form.'.$setting});
1.153 matthew 6111: }
6112: # Determine if the array contents are the same.
1.258 albertel 6113: if ($stored_form ne $env{$envname}) {
1.153 matthew 6114: $SaveHash{$basename} = $stored_form;
6115: $AppHash{$envname} = $stored_form;
6116: }
6117: }
6118: }
6119: }
6120: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 6121: $udom,$uname);
1.153 matthew 6122: if ($put_result !~ /^(ok|delayed)/) {
6123: &Apache::lonnet::logthis('unable to save form parameters, '.
6124: 'got error:'.$put_result);
6125: }
6126: # Make sure these settings stick around in this session, too
6127: &Apache::lonnet::appenv(%AppHash);
6128: return;
6129: }
6130:
6131: sub restore_course_settings {
1.499 ! albertel 6132: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 6133: }
6134:
6135: sub restore_settings {
6136: my ($context,$prefix,$Settings) = @_;
1.153 matthew 6137: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 6138: next if (exists($env{'form.'.$setting}));
1.496 albertel 6139: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 6140: '.'.$setting;
1.258 albertel 6141: if (exists($env{$envname})) {
1.153 matthew 6142: if ($type eq 'scalar') {
1.258 albertel 6143: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 6144: } elsif ($type eq 'array') {
1.258 albertel 6145: $env{'form.'.$setting} = [
1.153 matthew 6146: map {
1.369 www 6147: &unescape($_);
1.258 albertel 6148: } split(',',$env{$envname})
1.153 matthew 6149: ];
6150: }
6151: }
6152: }
1.127 matthew 6153: }
6154:
6155: ############################################################
6156: ############################################################
1.154 albertel 6157:
1.443 albertel 6158: sub commit_customrole {
6159: my ($udom,$uname,$url,$three,$four,$five,$start,$end) = @_;
6160: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.'@'.$three.' in '.$url.
6161: ($start?', '.&mt('starting').' '.localtime($start):'').
6162: ($end?', ending '.localtime($end):'').': <b>'.
6163: &Apache::lonnet::assigncustomrole(
6164: $udom,$uname,$url,$three,$four,$five,$end,$start).
6165: '</b><br />';
6166: return $output;
6167: }
6168:
6169: sub commit_standardrole {
6170: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec) = @_;
6171: my $output;
6172: my $logmsg;
6173: if ($three eq 'st') {
6174: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec);
6175: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course')) {
6176: $output = "Error: $result\n";
6177: } else {
6178: $output = &mt('Assigning').' '.$three.' in '.$url.
6179: ($start?', '.&mt('starting').' '.localtime($start):'').
6180: ($end?', '.&mt('ending').' '.localtime($end):'').
6181: ': <b>'.$result.'</b><br />'.
6182: &mt('Add to classlist').': <b>ok</b><br />';
6183: }
6184: } else {
6185: $output = &mt('Assigning').' '.$three.' in '.$url.
6186: ($start?', '.&mt('starting').' '.localtime($start):'').
6187: ($end?', '.&mt('ending').' '.localtime($end):'').': <b>'.
6188: &Apache::lonnet::assignrole(
6189: $udom,$uname,$url,$three,$end,$start).
6190: '</b><br />';
6191: }
6192: return $output;
6193: }
6194:
6195: sub commit_studentrole {
6196: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec) = @_;
6197: my $linefeed = '<br />'."\n";
6198: my $result;
6199: if (defined($one) && defined($two)) {
6200: my $cid=$one.'_'.$two;
6201: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
6202: my $secchange = 0;
6203: my $expire_role_result;
6204: my $modify_section_result;
6205: unless ($oldsec eq '-1') {
6206: unless ($sec eq $oldsec) {
6207: $secchange = 1;
6208: my $uurl='/'.$cid;
6209: $uurl=~s/\_/\//g;
6210: if ($oldsec) {
6211: $uurl.='/'.$oldsec;
6212: }
6213: $expire_role_result = &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',time);
6214: $result = $expire_role_result;
6215: }
6216: }
6217: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
6218: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid);
6219: if ($modify_section_result =~ /^ok/) {
6220: if ($secchange == 1) {
6221: $$logmsg .= "Section for $uname switched from old section: $oldsec to new section: $sec".$linefeed;
6222: } elsif ($oldsec eq '-1') {
6223: $$logmsg .= "New student role for $uname in section $sec in course $cid".$linefeed;
6224: } else {
6225: $$logmsg .= "Student $uname assigned to unchanged section $sec in course $cid".$linefeed;
6226: }
6227: } else {
6228: $$logmsg .= "Error when attempting section change for $uname from old section $oldsec to new section: $sec in course $cid -error: $modify_section_result".$linefeed;
6229: }
6230: $result = $modify_section_result;
6231: } elsif ($secchange == 1) {
6232: $$logmsg .= "Error when attempting to expire role for $uname in old section $oldsec in course $cid -error: $expire_role_result".$linefeed;
6233: }
6234: } else {
6235: $$logmsg .= "Incomplete course id defined. Addition of user $uname from domain $udom to course $one\_$two, section $sec not completed.$linefeed";
6236: $result = "error: incomplete course id\n";
6237: }
6238: return $result;
6239: }
6240:
6241: ############################################################
6242: ############################################################
6243:
1.444 albertel 6244: sub construct_course {
6245: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname) = @_;
6246: my $outcome;
6247:
6248: #
6249: # Open course
6250: #
6251: my $crstype = lc($args->{'crstype'});
6252: my %cenv=();
6253: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
6254: $args->{'cdescr'},
6255: $args->{'curl'},
6256: $args->{'course_home'},
6257: $args->{'nonstandard'},
6258: $args->{'crscode'},
6259: $args->{'ccuname'}.':'.
6260: $args->{'ccdomain'},
6261: $args->{'crstype'});
6262:
6263: # Note: The testing routines depend on this being output; see
6264: # Utils::Course. This needs to at least be output as a comment
6265: # if anyone ever decides to not show this, and Utils::Course::new
6266: # will need to be suitably modified.
6267: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]<br />',$crstype,$$courseid);
6268: #
6269: # Check if created correctly
6270: #
1.479 albertel 6271: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 6272: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
6273: $outcome .= &mt('Created on').': '.$crsuhome.'<br>';
6274: #
6275: # Are we cloning?
6276: #
6277: my $cloneid='';
6278: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
6279: $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
1.479 albertel 6280: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
1.444 albertel 6281: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
6282: if ($clonehome eq 'no_host') {
6283: $outcome .=
6284: '<br /><font color="red">'.&mt('Attempting to clone non-existing [_1]',$crstype).' '.$cloneid.'</font>';
6285: } else {
6286: $outcome .=
6287: '<br /><font color="green">'.&mt('Cloning [_1] from [_2]',$crstype,$clonehome).'</font>';
6288: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
6289: # Copy all files
6290: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid);
6291: # Restore URL
6292: $cenv{'url'}=$oldcenv{'url'};
6293: # Restore title
6294: $cenv{'description'}=$oldcenv{'description'};
6295: # restore grading mode
6296: if (defined($oldcenv{'grading'})) {
6297: $cenv{'grading'}=$oldcenv{'grading'};
6298: }
6299: # Mark as cloned
6300: $cenv{'clonedfrom'}=$cloneid;
6301: delete($cenv{'default_enrollment_start_date'});
6302: delete($cenv{'default_enrollment_end_date'});
6303: }
6304: }
6305: #
6306: # Set environment (will override cloned, if existing)
6307: #
6308: my @sections = ();
6309: my @xlists = ();
6310: if ($args->{'crstype'}) {
6311: $cenv{'type'}=$args->{'crstype'};
6312: }
6313: if ($args->{'crsid'}) {
6314: $cenv{'courseid'}=$args->{'crsid'};
6315: }
6316: if ($args->{'crscode'}) {
6317: $cenv{'internal.coursecode'}=$args->{'crscode'};
6318: }
6319: if ($args->{'crsquota'} ne '') {
6320: $cenv{'internal.coursequota'}=$args->{'crsquota'};
6321: } else {
6322: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
6323: }
6324: if ($args->{'ccuname'}) {
6325: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
6326: ':'.$args->{'ccdomain'};
6327: } else {
6328: $cenv{'internal.courseowner'} = $args->{'curruser'};
6329: }
6330:
6331: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
6332: if ($args->{'crssections'}) {
6333: $cenv{'internal.sectionnums'} = '';
6334: if ($args->{'crssections'} =~ m/,/) {
6335: @sections = split/,/,$args->{'crssections'};
6336: } else {
6337: $sections[0] = $args->{'crssections'};
6338: }
6339: if (@sections > 0) {
6340: foreach my $item (@sections) {
6341: my ($sec,$gp) = split/:/,$item;
6342: my $class = $args->{'crscode'}.$sec;
6343: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
6344: $cenv{'internal.sectionnums'} .= $item.',';
6345: unless ($addcheck eq 'ok') {
6346: push @badclasses, $class;
6347: }
6348: }
6349: $cenv{'internal.sectionnums'} =~ s/,$//;
6350: }
6351: }
6352: # do not hide course coordinator from staff listing,
6353: # even if privileged
6354: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
6355: # add crosslistings
6356: if ($args->{'crsxlist'}) {
6357: $cenv{'internal.crosslistings'}='';
6358: if ($args->{'crsxlist'} =~ m/,/) {
6359: @xlists = split/,/,$args->{'crsxlist'};
6360: } else {
6361: $xlists[0] = $args->{'crsxlist'};
6362: }
6363: if (@xlists > 0) {
6364: foreach my $item (@xlists) {
6365: my ($xl,$gp) = split/:/,$item;
6366: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
6367: $cenv{'internal.crosslistings'} .= $item.',';
6368: unless ($addcheck eq 'ok') {
6369: push @badclasses, $xl;
6370: }
6371: }
6372: $cenv{'internal.crosslistings'} =~ s/,$//;
6373: }
6374: }
6375: if ($args->{'autoadds'}) {
6376: $cenv{'internal.autoadds'}=$args->{'autoadds'};
6377: }
6378: if ($args->{'autodrops'}) {
6379: $cenv{'internal.autodrops'}=$args->{'autodrops'};
6380: }
6381: # check for notification of enrollment changes
6382: my @notified = ();
6383: if ($args->{'notify_owner'}) {
6384: if ($args->{'ccuname'} ne '') {
6385: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
6386: }
6387: }
6388: if ($args->{'notify_dc'}) {
6389: if ($uname ne '') {
6390: push(@notified,$uname.'@'.$udom);
6391: }
6392: }
6393: if (@notified > 0) {
6394: my $notifylist;
6395: if (@notified > 1) {
6396: $notifylist = join(',',@notified);
6397: } else {
6398: $notifylist = $notified[0];
6399: }
6400: $cenv{'internal.notifylist'} = $notifylist;
6401: }
6402: if (@badclasses > 0) {
6403: my %lt=&Apache::lonlocal::texthash(
6404: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course. However, if automated course roster updates are enabled for this class, these particular sections/crosslistings will not contribute towards enrollment, because the user identified as the course owner for this LON-CAPA course',
6405: 'dnhr' => 'does not have rights to access enrollment in these classes',
6406: 'adby' => 'as determined by the policies of your institution on access to official classlists'
6407: );
6408: $outcome .= '<font color="red">'.$lt{'tclb'}.' ('.$cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.' ('.$lt{'adby'}.').<br /><ul>'."\n";
6409: foreach (@badclasses) {
6410: $outcome .= "<li>$_</li>\n";
6411: }
6412: $outcome .= "</ul><br /><br /></font>\n";
6413: }
6414: if ($args->{'no_end_date'}) {
6415: $args->{'endaccess'} = 0;
6416: }
6417: $cenv{'internal.autostart'}=$args->{'enrollstart'};
6418: $cenv{'internal.autoend'}=$args->{'enrollend'};
6419: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
6420: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
6421: if ($args->{'showphotos'}) {
6422: $cenv{'internal.showphotos'}=$args->{'showphotos'};
6423: }
6424: $cenv{'internal.authtype'} = $args->{'authtype'};
6425: $cenv{'internal.autharg'} = $args->{'autharg'};
6426: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
6427: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
6428: $outcome .= '<font color="red" size="+1">'.
6429: &mt('As you did not include the default Kerberos domain to be used for authentication in this class, the institutional data used by the automated enrollment process must include the Kerberos domain for each new student').'</font></p>';
6430: }
6431: }
6432: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
6433: if ($args->{'setpolicy'}) {
6434: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
6435: }
6436: if ($args->{'setcontent'}) {
6437: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
6438: }
6439: }
6440: if ($args->{'reshome'}) {
6441: $cenv{'reshome'}=$args->{'reshome'}.'/';
6442: $cenv{'reshome'}=~s/\/+$/\//;
6443: }
6444: #
6445: # course has keyed access
6446: #
6447: if ($args->{'setkeys'}) {
6448: $cenv{'keyaccess'}='yes';
6449: }
6450: # if specified, key authority is not course, but user
6451: # only active if keyaccess is yes
6452: if ($args->{'keyauth'}) {
1.487 albertel 6453: my ($user,$domain) = split(':',$args->{'keyauth'});
6454: $user = &LONCAPA::clean_username($user);
6455: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 6456: if ($user ne '' && $domain ne '') {
1.487 albertel 6457: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 6458: }
6459: }
6460:
6461: if ($args->{'disresdis'}) {
6462: $cenv{'pch.roles.denied'}='st';
6463: }
6464: if ($args->{'disablechat'}) {
6465: $cenv{'plc.roles.denied'}='st';
6466: }
6467:
6468: # Record we've not yet viewed the Course Initialization Helper for this
6469: # course
6470: $cenv{'course.helper.not.run'} = 1;
6471: #
6472: # Use new Randomseed
6473: #
6474: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
6475: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
6476: #
6477: # The encryption code and receipt prefix for this course
6478: #
6479: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
6480: $cenv{'internal.encpref'}=100+int(9*rand(99));
6481: #
6482: # By default, use standard grading
6483: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
6484:
6485: $outcome .= ('<br />'.&mt('Setting environment').': '.
6486: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).'<br>');
6487: #
6488: # Open all assignments
6489: #
6490: if ($args->{'openall'}) {
6491: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
6492: my %storecontent = ($storeunder => time,
6493: $storeunder.'.type' => 'date_start');
6494:
6495: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
6496: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).'<br>';
6497: }
6498: #
6499: # Set first page
6500: #
6501: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
6502: || ($cloneid)) {
1.445 albertel 6503: use LONCAPA::map;
1.444 albertel 6504: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 6505:
6506: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
6507: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
6508:
1.444 albertel 6509: $outcome .= ($fatal?$errtext:'read ok').' - ';
6510: my $title; my $url;
6511: if ($args->{'firstres'} eq 'syl') {
6512: $title='Syllabus';
6513: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
6514: } else {
6515: $title='Navigate Contents';
6516: $url='/adm/navmaps';
6517: }
1.445 albertel 6518:
6519: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
6520: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
6521:
6522: if ($errtext) { $fatal=2; }
6523: $outcome .= ($fatal?$errtext:'write ok').'<br />';
1.444 albertel 6524: }
6525: return $outcome;
6526: }
6527:
6528: ############################################################
6529: ############################################################
6530:
1.378 raeburn 6531: sub course_type {
6532: my ($cid) = @_;
6533: if (!defined($cid)) {
6534: $cid = $env{'request.course.id'};
6535: }
1.404 albertel 6536: if (defined($env{'course.'.$cid.'.type'})) {
6537: return $env{'course.'.$cid.'.type'};
1.378 raeburn 6538: } else {
6539: return 'Course';
1.377 raeburn 6540: }
6541: }
1.156 albertel 6542:
1.406 raeburn 6543: sub group_term {
6544: my $crstype = &course_type();
6545: my %names = (
6546: 'Course' => 'group',
6547: 'Group' => 'team',
6548: );
6549: return $names{$crstype};
6550: }
6551:
1.156 albertel 6552: sub icon {
6553: my ($file)=@_;
1.168 albertel 6554: my $curfext = (split(/\./,$file))[-1];
6555: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 6556: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 6557: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
6558: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
6559: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
6560: $curfext.".gif") {
6561: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
6562: $curfext.".gif";
6563: }
6564: }
1.249 albertel 6565: return &lonhttpdurl($iconname);
1.154 albertel 6566: }
1.84 albertel 6567:
1.215 albertel 6568: sub lonhttpdurl {
6569: my ($url)=@_;
6570: my $lonhttpd_port=$Apache::lonnet::perlvar{'lonhttpdPort'};
6571: if (!defined($lonhttpd_port)) { $lonhttpd_port='8080'; }
6572: return 'http://'.$ENV{'SERVER_NAME'}.':'.$lonhttpd_port.$url;
6573: }
6574:
1.213 albertel 6575: sub connection_aborted {
6576: my ($r)=@_;
6577: $r->print(" ");$r->rflush();
6578: my $c = $r->connection;
6579: return $c->aborted();
6580: }
6581:
1.221 foxr 6582: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 6583: # strings as 'strings'.
6584: sub escape_single {
1.221 foxr 6585: my ($input) = @_;
1.223 albertel 6586: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 6587: $input =~ s/\'/\\\'/g; # Esacpe the 's....
6588: return $input;
6589: }
1.223 albertel 6590:
1.222 foxr 6591: # Same as escape_single, but escape's "'s This
6592: # can be used for "strings"
6593: sub escape_double {
6594: my ($input) = @_;
6595: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
6596: $input =~ s/\"/\\\"/g; # Esacpe the "s....
6597: return $input;
6598: }
1.223 albertel 6599:
1.222 foxr 6600: # Escapes the last element of a full URL.
6601: sub escape_url {
6602: my ($url) = @_;
1.238 raeburn 6603: my @urlslices = split(/\//, $url,-1);
1.369 www 6604: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 6605: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 6606: }
1.462 albertel 6607:
6608: # -------------------------------------------------------- Initliaze user login
6609: sub init_user_environment {
1.463 albertel 6610: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 6611: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
6612:
6613: my $public=($username eq 'public' && $domain eq 'public');
6614:
6615: # See if old ID present, if so, remove
6616:
6617: my ($filename,$cookie,$userroles);
6618: my $now=time;
6619:
6620: if ($public) {
6621: my $max_public=100;
6622: my $oldest;
6623: my $oldest_time=0;
6624: for(my $next=1;$next<=$max_public;$next++) {
6625: if (-e $lonids."/publicuser_$next.id") {
6626: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
6627: if ($mtime<$oldest_time || !$oldest_time) {
6628: $oldest_time=$mtime;
6629: $oldest=$next;
6630: }
6631: } else {
6632: $cookie="publicuser_$next";
6633: last;
6634: }
6635: }
6636: if (!$cookie) { $cookie="publicuser_$oldest"; }
6637: } else {
1.463 albertel 6638: # if this isn't a robot, kill any existing non-robot sessions
6639: if (!$args->{'robot'}) {
6640: opendir(DIR,$lonids);
6641: while ($filename=readdir(DIR)) {
6642: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
6643: unlink($lonids.'/'.$filename);
6644: }
1.462 albertel 6645: }
1.463 albertel 6646: closedir(DIR);
1.462 albertel 6647: }
6648: # Give them a new cookie
1.463 albertel 6649: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
6650: : $now);
6651: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 6652:
6653: # Initialize roles
6654:
6655: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
6656: }
6657: # ------------------------------------ Check browser type and MathML capability
6658:
6659: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
6660: $clientunicode,$clientos) = &decode_user_agent($r);
6661:
6662: # -------------------------------------- Any accessibility options to remember?
6663: if (($form->{'interface'}) && ($form->{'remember'} eq 'true')) {
6664: foreach my $option ('imagesuppress','appletsuppress',
6665: 'embedsuppress','fontenhance','blackwhite') {
6666: if ($form->{$option} eq 'true') {
6667: &Apache::lonnet::put('environment',{$option => 'on'},
6668: $domain,$username);
6669: } else {
6670: &Apache::lonnet::del('environment',[$option],
6671: $domain,$username);
6672: }
6673: }
6674: }
6675: # ------------------------------------------------------------- Get environment
6676:
6677: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
6678: my ($tmp) = keys(%userenv);
6679: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
6680: # default remote control to off
6681: if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
6682: } else {
6683: undef(%userenv);
6684: }
6685: if (($userenv{'interface'}) && (!$form->{'interface'})) {
6686: $form->{'interface'}=$userenv{'interface'};
6687: }
6688: $env{'environment.remote'}=$userenv{'remote'};
6689: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
6690:
6691: # --------------- Do not trust query string to be put directly into environment
6692: foreach my $option ('imagesuppress','appletsuppress',
6693: 'embedsuppress','fontenhance','blackwhite',
6694: 'interface','localpath','localres') {
6695: $form->{$option}=~s/[\n\r\=]//gs;
6696: }
6697: # --------------------------------------------------------- Write first profile
6698:
6699: {
6700: my %initial_env =
6701: ("user.name" => $username,
6702: "user.domain" => $domain,
6703: "user.home" => $authhost,
6704: "browser.type" => $clientbrowser,
6705: "browser.version" => $clientversion,
6706: "browser.mathml" => $clientmathml,
6707: "browser.unicode" => $clientunicode,
6708: "browser.os" => $clientos,
6709: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
6710: "request.course.fn" => '',
6711: "request.course.uri" => '',
6712: "request.course.sec" => '',
6713: "request.role" => 'cm',
6714: "request.role.adv" => $env{'user.adv'},
6715: "request.host" => $ENV{'REMOTE_ADDR'},);
6716:
6717: if ($form->{'localpath'}) {
6718: $initial_env{"browser.localpath"} = $form->{'localpath'};
6719: $initial_env{"browser.localres"} = $form->{'localres'};
6720: }
6721:
6722: if ($public) {
6723: $initial_env{"environment.remote"} = "off";
6724: }
6725: if ($form->{'interface'}) {
6726: $form->{'interface'}=~s/\W//gs;
6727: $initial_env{"browser.interface"} = $form->{'interface'};
6728: $env{'browser.interface'}=$form->{'interface'};
6729: foreach my $option ('imagesuppress','appletsuppress',
6730: 'embedsuppress','fontenhance','blackwhite') {
6731: if (($form->{$option} eq 'true') ||
6732: ($userenv{$option} eq 'on')) {
6733: $initial_env{"browser.$option"} = "on";
6734: }
6735: }
6736: }
6737:
6738: $env{'user.environment'} = "$lonids/$cookie.id";
6739:
6740: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
6741: &GDBM_WRCREAT(),0640)) {
6742: &_add_to_env(\%disk_env,\%initial_env);
6743: &_add_to_env(\%disk_env,\%userenv,'environment.');
6744: &_add_to_env(\%disk_env,$userroles);
1.463 albertel 6745: if (ref($args->{'extra_env'})) {
6746: &_add_to_env(\%disk_env,$args->{'extra_env'});
6747: }
1.462 albertel 6748: untie(%disk_env);
6749: } else {
6750: &Apache::lonnet::logthis("<font color=\"blue\">WARNING: ".
6751: 'Could not create environment storage in lonauth: '.$!.'</font>');
6752: return 'error: '.$!;
6753: }
6754: }
6755: $env{'request.role'}='cm';
6756: $env{'request.role.adv'}=$env{'user.adv'};
6757: $env{'browser.type'}=$clientbrowser;
6758:
6759: return $cookie;
6760:
6761: }
6762:
6763: sub _add_to_env {
6764: my ($idf,$env_data,$prefix) = @_;
6765: while (my ($key,$value) = each(%$env_data)) {
6766: $idf->{$prefix.$key} = $value;
6767: $env{$prefix.$key} = $value;
6768: }
6769: }
6770:
6771:
1.41 ng 6772: =pod
6773:
6774: =back
6775:
1.112 bowersj2 6776: =cut
1.41 ng 6777:
1.112 bowersj2 6778: 1;
6779: __END__;
1.41 ng 6780:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>