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