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