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