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