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