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