File:
[LON-CAPA] /
loncom /
interface /
loncommon.pm
Revision
1.762:
download - view:
text,
annotated -
select for diffs
Wed Mar 4 12:43:31 2009 UTC (15 years, 5 months ago) by
bisitz
Branches:
MAIN
CVS tags:
HEAD
Changed standard top level menu headline to <h1> to get a proper page hierachy
and removed corresponding obsolete style.
Needs to be revisited for construction space and other custom titles.
("titlebar" is expected to be redesigned anyway.)
1: # The LearningOnline Network with CAPA
2: # a pile of common routines
3: #
4: # $Id: loncommon.pm,v 1.762 2009/03/04 12:43:31 bisitz 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 Apache::lonnet();
65: use HTML::Entities;
66: use Apache::lonhtmlcommon();
67: use Apache::loncoursedata();
68: use Apache::lontexconvert();
69: use Apache::lonclonecourse();
70: use LONCAPA qw(:DEFAULT :match);
71: use DateTime::TimeZone;
72: use DateTime::Locale::Catalog;
73:
74: # ---------------------------------------------- Designs
75: use vars qw(%defaultdesign);
76:
77: my $readit;
78:
79:
80: ##
81: ## Global Variables
82: ##
83:
84:
85: # ----------------------------------------------- SSI with retries:
86: #
87:
88: =pod
89:
90: =head1 Server Side include with retries:
91:
92: =over 4
93:
94: =item * &ssi_with_retries(resource,retries form)
95:
96: Performs an ssi with some number of retries. Retries continue either
97: until the result is ok or until the retry count supplied by the
98: caller is exhausted.
99:
100: Inputs:
101:
102: =over 4
103:
104: resource - Identifies the resource to insert.
105:
106: retries - Count of the number of retries allowed.
107:
108: form - Hash that identifies the rendering options.
109:
110: =back
111:
112: Returns:
113:
114: =over 4
115:
116: content - The content of the response. If retries were exhausted this is empty.
117:
118: response - The response from the last attempt (which may or may not have been successful.
119:
120: =back
121:
122: =back
123:
124: =cut
125:
126: sub ssi_with_retries {
127: my ($resource, $retries, %form) = @_;
128:
129:
130: my $ok = 0; # True if we got a good response.
131: my $content;
132: my $response;
133:
134: # Try to get the ssi done. within the retries count:
135:
136: do {
137: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
138: $ok = $response->is_success;
139: if (!$ok) {
140: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
141: }
142: $retries--;
143: } while (!$ok && ($retries > 0));
144:
145: if (!$ok) {
146: $content = ''; # On error return an empty content.
147: }
148: return ($content, $response);
149:
150: }
151:
152:
153:
154: # ----------------------------------------------- Filetypes/Languages/Copyright
155: my %language;
156: my %supported_language;
157: my %cprtag;
158: my %scprtag;
159: my %fe; my %fd; my %fm;
160: my %category_extensions;
161:
162: # ---------------------------------------------- Thesaurus variables
163: #
164: # %Keywords:
165: # A hash used by &keyword to determine if a word is considered a keyword.
166: # $thesaurus_db_file
167: # Scalar containing the full path to the thesaurus database.
168:
169: my %Keywords;
170: my $thesaurus_db_file;
171:
172: #
173: # Initialize values from language.tab, copyright.tab, filetypes.tab,
174: # thesaurus.tab, and filecategories.tab.
175: #
176: BEGIN {
177: # Variable initialization
178: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
179: #
180: unless ($readit) {
181: # ------------------------------------------------------------------- languages
182: {
183: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
184: '/language.tab';
185: if ( open(my $fh,"<$langtabfile") ) {
186: while (my $line = <$fh>) {
187: next if ($line=~/^\#/);
188: chomp($line);
189: my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$line));
190: $language{$key}=$val.' - '.$enc;
191: if ($sup) {
192: $supported_language{$key}=$sup;
193: }
194: }
195: close($fh);
196: }
197: }
198: # ------------------------------------------------------------------ copyrights
199: {
200: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
201: '/copyright.tab';
202: if ( open (my $fh,"<$copyrightfile") ) {
203: while (my $line = <$fh>) {
204: next if ($line=~/^\#/);
205: chomp($line);
206: my ($key,$val)=(split(/\s+/,$line,2));
207: $cprtag{$key}=$val;
208: }
209: close($fh);
210: }
211: }
212: # ----------------------------------------------------------- source copyrights
213: {
214: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
215: '/source_copyright.tab';
216: if ( open (my $fh,"<$sourcecopyrightfile") ) {
217: while (my $line = <$fh>) {
218: next if ($line =~ /^\#/);
219: chomp($line);
220: my ($key,$val)=(split(/\s+/,$line,2));
221: $scprtag{$key}=$val;
222: }
223: close($fh);
224: }
225: }
226:
227: # -------------------------------------------------------------- default domain designs
228: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
229: my $designfile = $designdir.'/default.tab';
230: if ( open (my $fh,"<$designfile") ) {
231: while (my $line = <$fh>) {
232: next if ($line =~ /^\#/);
233: chomp($line);
234: my ($key,$val)=(split(/\=/,$line));
235: if ($val) { $defaultdesign{$key}=$val; }
236: }
237: close($fh);
238: }
239:
240: # ------------------------------------------------------------- file categories
241: {
242: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
243: '/filecategories.tab';
244: if ( open (my $fh,"<$categoryfile") ) {
245: while (my $line = <$fh>) {
246: next if ($line =~ /^\#/);
247: chomp($line);
248: my ($extension,$category)=(split(/\s+/,$line,2));
249: push @{$category_extensions{lc($category)}},$extension;
250: }
251: close($fh);
252: }
253:
254: }
255: # ------------------------------------------------------------------ file types
256: {
257: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
258: '/filetypes.tab';
259: if ( open (my $fh,"<$typesfile") ) {
260: while (my $line = <$fh>) {
261: next if ($line =~ /^\#/);
262: chomp($line);
263: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
264: if ($descr ne '') {
265: $fe{$ending}=lc($emb);
266: $fd{$ending}=$descr;
267: if ($mime ne 'unk') { $fm{$ending}=$mime; }
268: }
269: }
270: close($fh);
271: }
272: }
273: &Apache::lonnet::logthis(
274: "<span style='color:yellow;'>INFO: Read file types</span>");
275: $readit=1;
276: } # end of unless($readit)
277:
278: }
279:
280: ###############################################################
281: ## HTML and Javascript Helper Functions ##
282: ###############################################################
283:
284: =pod
285:
286: =head1 HTML and Javascript Functions
287:
288: =over 4
289:
290: =item * &browser_and_searcher_javascript()
291:
292: X<browsing, javascript>X<searching, javascript>Returns a string
293: containing javascript with two functions, C<openbrowser> and
294: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
295: tags.
296:
297: =item * &openbrowser(formname,elementname,only,omit) [javascript]
298:
299: inputs: formname, elementname, only, omit
300:
301: formname and elementname indicate the name of the html form and name of
302: the element that the results of the browsing selection are to be placed in.
303:
304: Specifying 'only' will restrict the browser to displaying only files
305: with the given extension. Can be a comma separated list.
306:
307: Specifying 'omit' will restrict the browser to NOT displaying files
308: with the given extension. Can be a comma separated list.
309:
310: =item * &opensearcher(formname,elementname) [javascript]
311:
312: Inputs: formname, elementname
313:
314: formname and elementname specify the name of the html form and the name
315: of the element the selection from the search results will be placed in.
316:
317: =cut
318:
319: sub browser_and_searcher_javascript {
320: my ($mode)=@_;
321: if (!defined($mode)) { $mode='edit'; }
322: my $resurl=&escape_single(&lastresurl());
323: return <<END;
324: // <!-- BEGIN LON-CAPA Internal
325: var editbrowser = null;
326: function openbrowser(formname,elementname,only,omit,titleelement) {
327: var url = '$resurl/?';
328: if (editbrowser == null) {
329: url += 'launch=1&';
330: }
331: url += 'catalogmode=interactive&';
332: url += 'mode=$mode&';
333: url += 'inhibitmenu=yes&';
334: url += 'form=' + formname + '&';
335: if (only != null) {
336: url += 'only=' + only + '&';
337: } else {
338: url += 'only=&';
339: }
340: if (omit != null) {
341: url += 'omit=' + omit + '&';
342: } else {
343: url += 'omit=&';
344: }
345: if (titleelement != null) {
346: url += 'titleelement=' + titleelement + '&';
347: } else {
348: url += 'titleelement=&';
349: }
350: url += 'element=' + elementname + '';
351: var title = 'Browser';
352: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
353: options += ',width=700,height=600';
354: editbrowser = open(url,title,options,'1');
355: editbrowser.focus();
356: }
357: var editsearcher;
358: function opensearcher(formname,elementname,titleelement) {
359: var url = '/adm/searchcat?';
360: if (editsearcher == null) {
361: url += 'launch=1&';
362: }
363: url += 'catalogmode=interactive&';
364: url += 'mode=$mode&';
365: url += 'form=' + formname + '&';
366: if (titleelement != null) {
367: url += 'titleelement=' + titleelement + '&';
368: } else {
369: url += 'titleelement=&';
370: }
371: url += 'element=' + elementname + '';
372: var title = 'Search';
373: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
374: options += ',width=700,height=600';
375: editsearcher = open(url,title,options,'1');
376: editsearcher.focus();
377: }
378: // END LON-CAPA Internal -->
379: END
380: }
381:
382: sub lastresurl {
383: if ($env{'environment.lastresurl'}) {
384: return $env{'environment.lastresurl'}
385: } else {
386: return '/res';
387: }
388: }
389:
390: sub storeresurl {
391: my $resurl=&Apache::lonnet::clutter(shift);
392: unless ($resurl=~/^\/res/) { return 0; }
393: $resurl=~s/\/$//;
394: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
395: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
396: return 1;
397: }
398:
399: sub studentbrowser_javascript {
400: unless (
401: (($env{'request.course.id'}) &&
402: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
403: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
404: '/'.$env{'request.course.sec'})
405: ))
406: || ($env{'request.role'}=~/^(au|dc|su)/)
407: ) { return ''; }
408: return (<<'ENDSTDBRW');
409: <script type="text/javascript" language="Javascript" >
410: var stdeditbrowser;
411: function openstdbrowser(formname,uname,udom,roleflag,ignorefilter) {
412: var url = '/adm/pickstudent?';
413: var filter;
414: if (!ignorefilter) {
415: eval('filter=document.'+formname+'.'+uname+'.value;');
416: }
417: if (filter != null) {
418: if (filter != '') {
419: url += 'filter='+filter+'&';
420: }
421: }
422: url += 'form=' + formname + '&unameelement='+uname+
423: '&udomelement='+udom;
424: if (roleflag) { url+="&roles=1"; }
425: var title = 'Student_Browser';
426: var options = 'scrollbars=1,resizable=1,menubar=0';
427: options += ',width=700,height=600';
428: stdeditbrowser = open(url,title,options,'1');
429: stdeditbrowser.focus();
430: }
431: </script>
432: ENDSTDBRW
433: }
434:
435: sub selectstudent_link {
436: my ($form,$unameele,$udomele)=@_;
437: if ($env{'request.course.id'}) {
438: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
439: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
440: '/'.$env{'request.course.sec'})) {
441: return '';
442: }
443: return "<a href='".'javascript:openstdbrowser("'.$form.'","'.$unameele.
444: '","'.$udomele.'");'."'>".&mt('Select User')."</a>";
445: }
446: if ($env{'request.role'}=~/^(au|dc|su)/) {
447: return "<a href='".'javascript:openstdbrowser("'.$form.'","'.$unameele.
448: '","'.$udomele.'",1);'."'>".&mt('Select User')."</a>";
449: }
450: return '';
451: }
452:
453: sub authorbrowser_javascript {
454: return <<"ENDAUTHORBRW";
455: <script type="text/javascript">
456: var stdeditbrowser;
457:
458: function openauthorbrowser(formname,udom) {
459: var url = '/adm/pickauthor?';
460: url += 'form='+formname+'&roledom='+udom;
461: var title = 'Author_Browser';
462: var options = 'scrollbars=1,resizable=1,menubar=0';
463: options += ',width=700,height=600';
464: stdeditbrowser = open(url,title,options,'1');
465: stdeditbrowser.focus();
466: }
467:
468: </script>
469: ENDAUTHORBRW
470: }
471:
472: sub coursebrowser_javascript {
473: my ($domainfilter,$sec_element,$formname)=@_;
474: 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');
475: my $output = '
476: <script type="text/javascript">
477: var stdeditbrowser;'."\n";
478: $output .= <<"ENDSTDBRW";
479: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,crstype) {
480: var url = '/adm/pickcourse?';
481: var domainfilter = '';
482: var formid = getFormIdByName(formname);
483: if (formid > -1) {
484: var domid = getIndexByName(formid,udom);
485: if (domid > -1) {
486: if (document.forms[formid].elements[domid].type == 'select-one') {
487: domainfilter=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
488: }
489: if (document.forms[formid].elements[domid].type == 'hidden') {
490: domainfilter=document.forms[formid].elements[domid].value;
491: }
492: }
493: }
494: if (domainfilter != null) {
495: if (domainfilter != '') {
496: url += 'domainfilter='+domainfilter+'&';
497: }
498: }
499: url += 'form=' + formname + '&cnumelement='+uname+
500: '&cdomelement='+udom+
501: '&cnameelement='+desc;
502: if (extra_element !=null && extra_element != '') {
503: if (formname == 'rolechoice' || formname == 'studentform') {
504: url += '&roleelement='+extra_element;
505: if (domainfilter == null || domainfilter == '') {
506: url += '&domainfilter='+extra_element;
507: }
508: }
509: else {
510: if (formname == 'portform') {
511: url += '&setroles='+extra_element;
512: }
513: }
514: }
515: if (multflag !=null && multflag != '') {
516: url += '&multiple='+multflag;
517: }
518: if (crstype == 'Course/Group') {
519: if (formname == 'cu') {
520: crstype = document.cu.crstype.options[document.cu.crstype.selectedIndex].value;
521: if (crstype == "") {
522: alert("$crs_or_grp_alert");
523: return;
524: }
525: }
526: }
527: if (crstype !=null && crstype != '') {
528: url += '&type='+crstype;
529: }
530: var title = 'Course_Browser';
531: var options = 'scrollbars=1,resizable=1,menubar=0';
532: options += ',width=700,height=600';
533: stdeditbrowser = open(url,title,options,'1');
534: stdeditbrowser.focus();
535: }
536:
537: function getFormIdByName(formname) {
538: for (var i=0;i<document.forms.length;i++) {
539: if (document.forms[i].name == formname) {
540: return i;
541: }
542: }
543: return -1;
544: }
545:
546: function getIndexByName(formid,item) {
547: for (var i=0;i<document.forms[formid].elements.length;i++) {
548: if (document.forms[formid].elements[i].name == item) {
549: return i;
550: }
551: }
552: return -1;
553: }
554: ENDSTDBRW
555: if ($sec_element ne '') {
556: $output .= &setsec_javascript($sec_element,$formname);
557: }
558: $output .= '
559: </script>';
560: return $output;
561: }
562:
563: sub setsec_javascript {
564: my ($sec_element,$formname) = @_;
565: my $setsections = qq|
566: function setSect(sectionlist) {
567: var sectionsArray = new Array();
568: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
569: sectionsArray = sectionlist.split(",");
570: }
571: var numSections = sectionsArray.length;
572: document.$formname.$sec_element.length = 0;
573: if (numSections == 0) {
574: document.$formname.$sec_element.multiple=false;
575: document.$formname.$sec_element.size=1;
576: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
577: } else {
578: if (numSections == 1) {
579: document.$formname.$sec_element.multiple=false;
580: document.$formname.$sec_element.size=1;
581: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
582: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
583: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
584: } else {
585: for (var i=0; i<numSections; i++) {
586: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
587: }
588: document.$formname.$sec_element.multiple=true
589: if (numSections < 3) {
590: document.$formname.$sec_element.size=numSections;
591: } else {
592: document.$formname.$sec_element.size=3;
593: }
594: document.$formname.$sec_element.options[0].selected = false
595: }
596: }
597: }
598: |;
599: return $setsections;
600: }
601:
602:
603: sub selectcourse_link {
604: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype)=@_;
605: return "<a href='".'javascript:opencrsbrowser("'.$form.'","'.$unameele.
606: '","'.$udomele.'","'.$desc.'","'.$extra_element.'","'.$multflag.'","'.$selecttype.'");'."'>".&mt('Select Course')."</a>";
607: }
608:
609: sub selectauthor_link {
610: my ($form,$udom)=@_;
611: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
612: &mt('Select Author').'</a>';
613: }
614:
615: sub check_uncheck_jscript {
616: my $jscript = <<"ENDSCRT";
617: function checkAll(field) {
618: if (field.length > 0) {
619: for (i = 0; i < field.length; i++) {
620: field[i].checked = true ;
621: }
622: } else {
623: field.checked = true
624: }
625: }
626:
627: function uncheckAll(field) {
628: if (field.length > 0) {
629: for (i = 0; i < field.length; i++) {
630: field[i].checked = false ;
631: }
632: } else {
633: field.checked = false ;
634: }
635: }
636: ENDSCRT
637: return $jscript;
638: }
639:
640: sub select_timezone {
641: my ($name,$selected,$onchange,$includeempty)=@_;
642: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
643: if ($includeempty) {
644: $output .= '<option value=""';
645: if (($selected eq '') || ($selected eq 'local')) {
646: $output .= ' selected="selected" ';
647: }
648: $output .= '> </option>';
649: }
650: my @timezones = DateTime::TimeZone->all_names;
651: foreach my $tzone (@timezones) {
652: $output.= '<option value="'.$tzone.'"';
653: if ($tzone eq $selected) {
654: $output.=' selected="selected"';
655: }
656: $output.=">$tzone</option>\n";
657: }
658: $output.="</select>";
659: return $output;
660: }
661:
662: sub select_datelocale {
663: my ($name,$selected,$onchange,$includeempty)=@_;
664: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
665: if ($includeempty) {
666: $output .= '<option value=""';
667: if ($selected eq '') {
668: $output .= ' selected="selected" ';
669: }
670: $output .= '> </option>';
671: }
672: my (@possibles,%locale_names);
673: my @locales = DateTime::Locale::Catalog::Locales;
674: foreach my $locale (@locales) {
675: if (ref($locale) eq 'HASH') {
676: my $id = $locale->{'id'};
677: if ($id ne '') {
678: my $en_terr = $locale->{'en_territory'};
679: my $native_terr = $locale->{'native_territory'};
680: my @languages = &Apache::lonlocal::preferred_languages();
681: if (grep(/^en$/,@languages) || !@languages) {
682: if ($en_terr ne '') {
683: $locale_names{$id} = '('.$en_terr.')';
684: } elsif ($native_terr ne '') {
685: $locale_names{$id} = $native_terr;
686: }
687: } else {
688: if ($native_terr ne '') {
689: $locale_names{$id} = $native_terr.' ';
690: } elsif ($en_terr ne '') {
691: $locale_names{$id} = '('.$en_terr.')';
692: }
693: }
694: push (@possibles,$id);
695: }
696: }
697: }
698: foreach my $item (sort(@possibles)) {
699: $output.= '<option value="'.$item.'"';
700: if ($item eq $selected) {
701: $output.=' selected="selected"';
702: }
703: $output.=">$item";
704: if ($locale_names{$item} ne '') {
705: $output.=" $locale_names{$item}</option>\n";
706: }
707: $output.="</option>\n";
708: }
709: $output.="</select>";
710: return $output;
711: }
712:
713: =pod
714:
715: =item * &linked_select_forms(...)
716:
717: linked_select_forms returns a string containing a <script></script> block
718: and html for two <select> menus. The select menus will be linked in that
719: changing the value of the first menu will result in new values being placed
720: in the second menu. The values in the select menu will appear in alphabetical
721: order unless a defined order is provided.
722:
723: linked_select_forms takes the following ordered inputs:
724:
725: =over 4
726:
727: =item * $formname, the name of the <form> tag
728:
729: =item * $middletext, the text which appears between the <select> tags
730:
731: =item * $firstdefault, the default value for the first menu
732:
733: =item * $firstselectname, the name of the first <select> tag
734:
735: =item * $secondselectname, the name of the second <select> tag
736:
737: =item * $hashref, a reference to a hash containing the data for the menus.
738:
739: =item * $menuorder, the order of values in the first menu
740:
741: =back
742:
743: Below is an example of such a hash. Only the 'text', 'default', and
744: 'select2' keys must appear as stated. keys(%menu) are the possible
745: values for the first select menu. The text that coincides with the
746: first menu value is given in $menu{$choice1}->{'text'}. The values
747: and text for the second menu are given in the hash pointed to by
748: $menu{$choice1}->{'select2'}.
749:
750: my %menu = ( A1 => { text =>"Choice A1" ,
751: default => "B3",
752: select2 => {
753: B1 => "Choice B1",
754: B2 => "Choice B2",
755: B3 => "Choice B3",
756: B4 => "Choice B4"
757: },
758: order => ['B4','B3','B1','B2'],
759: },
760: A2 => { text =>"Choice A2" ,
761: default => "C2",
762: select2 => {
763: C1 => "Choice C1",
764: C2 => "Choice C2",
765: C3 => "Choice C3"
766: },
767: order => ['C2','C1','C3'],
768: },
769: A3 => { text =>"Choice A3" ,
770: default => "D6",
771: select2 => {
772: D1 => "Choice D1",
773: D2 => "Choice D2",
774: D3 => "Choice D3",
775: D4 => "Choice D4",
776: D5 => "Choice D5",
777: D6 => "Choice D6",
778: D7 => "Choice D7"
779: },
780: order => ['D4','D3','D2','D1','D7','D6','D5'],
781: }
782: );
783:
784: =cut
785:
786: sub linked_select_forms {
787: my ($formname,
788: $middletext,
789: $firstdefault,
790: $firstselectname,
791: $secondselectname,
792: $hashref,
793: $menuorder,
794: ) = @_;
795: my $second = "document.$formname.$secondselectname";
796: my $first = "document.$formname.$firstselectname";
797: # output the javascript to do the changing
798: my $result = '';
799: $result.="<script type=\"text/javascript\">\n";
800: $result.="var select2data = new Object();\n";
801: $" = '","';
802: my $debug = '';
803: foreach my $s1 (sort(keys(%$hashref))) {
804: $result.="select2data.d_$s1 = new Object();\n";
805: $result.="select2data.d_$s1.def = new String('".
806: $hashref->{$s1}->{'default'}."');\n";
807: $result.="select2data.d_$s1.values = new Array(";
808: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
809: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
810: @s2values = @{$hashref->{$s1}->{'order'}};
811: }
812: $result.="\"@s2values\");\n";
813: $result.="select2data.d_$s1.texts = new Array(";
814: my @s2texts;
815: foreach my $value (@s2values) {
816: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
817: }
818: $result.="\"@s2texts\");\n";
819: }
820: $"=' ';
821: $result.= <<"END";
822:
823: function select1_changed() {
824: // Determine new choice
825: var newvalue = "d_" + $first.value;
826: // update select2
827: var values = select2data[newvalue].values;
828: var texts = select2data[newvalue].texts;
829: var select2def = select2data[newvalue].def;
830: var i;
831: // out with the old
832: for (i = 0; i < $second.options.length; i++) {
833: $second.options[i] = null;
834: }
835: // in with the nuclear
836: for (i=0;i<values.length; i++) {
837: $second.options[i] = new Option(values[i]);
838: $second.options[i].value = values[i];
839: $second.options[i].text = texts[i];
840: if (values[i] == select2def) {
841: $second.options[i].selected = true;
842: }
843: }
844: }
845: </script>
846: END
847: # output the initial values for the selection lists
848: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
849: my @order = sort(keys(%{$hashref}));
850: if (ref($menuorder) eq 'ARRAY') {
851: @order = @{$menuorder};
852: }
853: foreach my $value (@order) {
854: $result.=" <option value=\"$value\" ";
855: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
856: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
857: }
858: $result .= "</select>\n";
859: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
860: $result .= $middletext;
861: $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
862: my $seconddefault = $hashref->{$firstdefault}->{'default'};
863:
864: my @secondorder = sort(keys(%select2));
865: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
866: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
867: }
868: foreach my $value (@secondorder) {
869: $result.=" <option value=\"$value\" ";
870: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
871: $result.=">".&mt($select2{$value})."</option>\n";
872: }
873: $result .= "</select>\n";
874: # return $debug;
875: return $result;
876: } # end of sub linked_select_forms {
877:
878: =pod
879:
880: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height)
881:
882: Returns a string corresponding to an HTML link to the given help
883: $topic, where $topic corresponds to the name of a .tex file in
884: /home/httpd/html/adm/help/tex, with underscores replaced by
885: spaces.
886:
887: $text will optionally be linked to the same topic, allowing you to
888: link text in addition to the graphic. If you do not want to link
889: text, but wish to specify one of the later parameters, pass an
890: empty string.
891:
892: $stayOnPage is a value that will be interpreted as a boolean. If true,
893: the link will not open a new window. If false, the link will open
894: a new window using Javascript. (Default is false.)
895:
896: $width and $height are optional numerical parameters that will
897: override the width and height of the popped up window, which may
898: be useful for certain help topics with big pictures included.
899:
900: =cut
901:
902: sub help_open_topic {
903: my ($topic, $text, $stayOnPage, $width, $height) = @_;
904: $text = "" if (not defined $text);
905: $stayOnPage = 0 if (not defined $stayOnPage);
906: if ($env{'browser.interface'} eq 'textual') {
907: $stayOnPage=1;
908: }
909: $width = 350 if (not defined $width);
910: $height = 400 if (not defined $height);
911: my $filename = $topic;
912: $filename =~ s/ /_/g;
913:
914: my $template = "";
915: my $link;
916:
917: $topic=~s/\W/\_/g;
918:
919: if (!$stayOnPage) {
920: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
921: } else {
922: $link = "/adm/help/${filename}.hlp";
923: }
924:
925: # Add the text
926: if ($text ne "") {
927: $template.="<span class=\"LC_nobreak\"><a class=\"LC_helptextbgcolor\" target=\"_top\" href=\"$link\"><span class=\"LC_helptextfontcolor\">$text</span></a>";
928: }
929:
930: # Add the graphic
931: my $title = &mt('Online Help');
932: my $helpicon=&lonhttpdurl("/adm/help/help.png");
933: $template .= <<"ENDTEMPLATE";
934: <a target="_top" href="$link" title="$title"><img src="$helpicon" border="0" alt="(Help: $topic)" /></a></span>
935: ENDTEMPLATE
936:
937: return $template;
938:
939: }
940:
941: # This is a quicky function for Latex cheatsheet editing, since it
942: # appears in at least four places
943: sub helpLatexCheatsheet {
944: my ($topic,$text,$not_author) = @_;
945: my $out;
946: my $addOther = '';
947: if ($topic) {
948: $addOther = &Apache::loncommon::help_open_topic($topic,$text,
949: undef, undef, 600).
950: '</td><td>';
951: }
952: $out = '<table><tr><td>'.
953: $addOther .
954: &Apache::loncommon::help_open_topic("Greek_Symbols",&mt('Greek Symbols'),
955: undef,undef,600).
956: '</td><td>'.
957: &Apache::loncommon::help_open_topic("Other_Symbols",&mt('Other Symbols'),
958: undef,undef,600).
959: '</td>';
960: unless ($not_author) {
961: $out .= '<td>'.
962: &Apache::loncommon::help_open_topic("Authoring_Output_Tags",&mt('Output Tags'),
963: undef,undef,600).
964: '</td>';
965: }
966: $out .= '</tr></table>';
967: return $out;
968: }
969:
970: sub general_help {
971: my $helptopic='Student_Intro';
972: if ($env{'request.role'}=~/^(ca|au)/) {
973: $helptopic='Authoring_Intro';
974: } elsif ($env{'request.role'}=~/^cc/) {
975: $helptopic='Course_Coordination_Intro';
976: } elsif ($env{'request.role'}=~/^dc/) {
977: $helptopic='Domain_Coordination_Intro';
978: }
979: return $helptopic;
980: }
981:
982: sub update_help_link {
983: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
984: my $origurl = $ENV{'REQUEST_URI'};
985: $origurl=~s|^/~|/priv/|;
986: my $timestamp = time;
987: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
988: $$datum = &escape($$datum);
989: }
990:
991: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
992: my $output .= <<"ENDOUTPUT";
993: <script type="text/javascript">
994: banner_link = '$banner_link';
995: </script>
996: ENDOUTPUT
997: return $output;
998: }
999:
1000: # now just updates the help link and generates a blue icon
1001: sub help_open_menu {
1002: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1003: = @_;
1004: $stayOnPage = 0 if (not defined $stayOnPage);
1005: # only use pop-up help (stayOnPage == 0)
1006: # if environment.remote is on (using remote control UI)
1007: if ($env{'browser.interface'} eq 'textual' ||
1008: $env{'environment.remote'} eq 'off' ) {
1009: $stayOnPage=1;
1010: }
1011: my $output;
1012: if ($component_help) {
1013: if (!$text) {
1014: $output=&help_open_topic($component_help,undef,$stayOnPage,
1015: $width,$height);
1016: } else {
1017: my $help_text;
1018: $help_text=&unescape($topic);
1019: $output='<table><tr><td>'.
1020: &help_open_topic($component_help,$help_text,$stayOnPage,
1021: $width,$height).'</td></tr></table>';
1022: }
1023: }
1024: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1025: return $output.$banner_link;
1026: }
1027:
1028: sub top_nav_help {
1029: my ($text) = @_;
1030: $text = &mt($text);
1031: my $stay_on_page =
1032: ($env{'browser.interface'} eq 'textual' ||
1033: $env{'environment.remote'} eq 'off' );
1034: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1035: : "javascript:helpMenu('open')";
1036: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1037:
1038: my $title = &mt('Get help');
1039:
1040: return <<"END";
1041: $banner_link
1042: <a href="$link" title="$title">$text</a>
1043: END
1044: }
1045:
1046: sub help_menu_js {
1047: my ($text) = @_;
1048:
1049: my $stayOnPage =
1050: ($env{'browser.interface'} eq 'textual' ||
1051: $env{'environment.remote'} eq 'off' );
1052:
1053: my $width = 620;
1054: my $height = 600;
1055: my $helptopic=&general_help();
1056: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1057: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1058: my $start_page =
1059: &Apache::loncommon::start_page('Help Menu', undef,
1060: {'frameset' => 1,
1061: 'js_ready' => 1,
1062: 'add_entries' => {
1063: 'border' => '0',
1064: 'rows' => "110,*",},});
1065: my $end_page =
1066: &Apache::loncommon::end_page({'frameset' => 1,
1067: 'js_ready' => 1,});
1068:
1069: my $template .= <<"ENDTEMPLATE";
1070: <script type="text/javascript">
1071: // <!-- BEGIN LON-CAPA Internal
1072: // <![CDATA[
1073: var banner_link = '';
1074: function helpMenu(target) {
1075: var caller = this;
1076: if (target == 'open') {
1077: var newWindow = null;
1078: try {
1079: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1080: }
1081: catch(error) {
1082: writeHelp(caller);
1083: return;
1084: }
1085: if (newWindow) {
1086: caller = newWindow;
1087: }
1088: }
1089: writeHelp(caller);
1090: return;
1091: }
1092: function writeHelp(caller) {
1093: caller.document.writeln('$start_page<frame name="bannerframe" src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1094: caller.document.close()
1095: caller.focus()
1096: }
1097: // ]]>
1098: // END LON-CAPA Internal -->
1099: </script>
1100: ENDTEMPLATE
1101: return $template;
1102: }
1103:
1104: sub help_open_bug {
1105: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1106: unless ($env{'user.adv'}) { return ''; }
1107: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1108: $text = "" if (not defined $text);
1109: $stayOnPage = 0 if (not defined $stayOnPage);
1110: if ($env{'browser.interface'} eq 'textual' ||
1111: $env{'environment.remote'} eq 'off' ) {
1112: $stayOnPage=1;
1113: }
1114: $width = 600 if (not defined $width);
1115: $height = 600 if (not defined $height);
1116:
1117: $topic=~s/\W+/\+/g;
1118: my $link='';
1119: my $template='';
1120: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1121: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1122: if (!$stayOnPage)
1123: {
1124: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1125: }
1126: else
1127: {
1128: $link = $url;
1129: }
1130: # Add the text
1131: if ($text ne "")
1132: {
1133: $template .=
1134: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1135: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1136: }
1137:
1138: # Add the graphic
1139: my $title = &mt('Report a Bug');
1140: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1141: $template .= <<"ENDTEMPLATE";
1142: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1143: ENDTEMPLATE
1144: if ($text ne '') { $template.='</td></tr></table>' };
1145: return $template;
1146:
1147: }
1148:
1149: sub help_open_faq {
1150: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1151: unless ($env{'user.adv'}) { return ''; }
1152: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1153: $text = "" if (not defined $text);
1154: $stayOnPage = 0 if (not defined $stayOnPage);
1155: if ($env{'browser.interface'} eq 'textual' ||
1156: $env{'environment.remote'} eq 'off' ) {
1157: $stayOnPage=1;
1158: }
1159: $width = 350 if (not defined $width);
1160: $height = 400 if (not defined $height);
1161:
1162: $topic=~s/\W+/\+/g;
1163: my $link='';
1164: my $template='';
1165: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1166: if (!$stayOnPage)
1167: {
1168: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1169: }
1170: else
1171: {
1172: $link = $url;
1173: }
1174:
1175: # Add the text
1176: if ($text ne "")
1177: {
1178: $template .=
1179: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1180: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1181: }
1182:
1183: # Add the graphic
1184: my $title = &mt('View the FAQ');
1185: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1186: $template .= <<"ENDTEMPLATE";
1187: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1188: ENDTEMPLATE
1189: if ($text ne '') { $template.='</td></tr></table>' };
1190: return $template;
1191:
1192: }
1193:
1194: ###############################################################
1195: ###############################################################
1196:
1197: =pod
1198:
1199: =item * &change_content_javascript():
1200:
1201: This and the next function allow you to create small sections of an
1202: otherwise static HTML page that you can update on the fly with
1203: Javascript, even in Netscape 4.
1204:
1205: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1206: must be written to the HTML page once. It will prove the Javascript
1207: function "change(name, content)". Calling the change function with the
1208: name of the section
1209: you want to update, matching the name passed to C<changable_area>, and
1210: the new content you want to put in there, will put the content into
1211: that area.
1212:
1213: B<Note>: Netscape 4 only reserves enough space for the changable area
1214: to contain room for the original contents. You need to "make space"
1215: for whatever changes you wish to make, and be B<sure> to check your
1216: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1217: it's adequate for updating a one-line status display, but little more.
1218: This script will set the space to 100% width, so you only need to
1219: worry about height in Netscape 4.
1220:
1221: Modern browsers are much less limiting, and if you can commit to the
1222: user not using Netscape 4, this feature may be used freely with
1223: pretty much any HTML.
1224:
1225: =cut
1226:
1227: sub change_content_javascript {
1228: # If we're on Netscape 4, we need to use Layer-based code
1229: if ($env{'browser.type'} eq 'netscape' &&
1230: $env{'browser.version'} =~ /^4\./) {
1231: return (<<NETSCAPE4);
1232: function change(name, content) {
1233: doc = document.layers[name+"___escape"].layers[0].document;
1234: doc.open();
1235: doc.write(content);
1236: doc.close();
1237: }
1238: NETSCAPE4
1239: } else {
1240: # Otherwise, we need to use semi-standards-compliant code
1241: # (technically, "innerHTML" isn't standard but the equivalent
1242: # is really scary, and every useful browser supports it
1243: return (<<DOMBASED);
1244: function change(name, content) {
1245: element = document.getElementById(name);
1246: element.innerHTML = content;
1247: }
1248: DOMBASED
1249: }
1250: }
1251:
1252: =pod
1253:
1254: =item * &changable_area($name,$origContent):
1255:
1256: This provides a "changable area" that can be modified on the fly via
1257: the Javascript code provided in C<change_content_javascript>. $name is
1258: the name you will use to reference the area later; do not repeat the
1259: same name on a given HTML page more then once. $origContent is what
1260: the area will originally contain, which can be left blank.
1261:
1262: =cut
1263:
1264: sub changable_area {
1265: my ($name, $origContent) = @_;
1266:
1267: if ($env{'browser.type'} eq 'netscape' &&
1268: $env{'browser.version'} =~ /^4\./) {
1269: # If this is netscape 4, we need to use the Layer tag
1270: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1271: } else {
1272: return "<span id='$name'>$origContent</span>";
1273: }
1274: }
1275:
1276: =pod
1277:
1278: =item * &viewport_geometry_js
1279:
1280: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1281:
1282: =cut
1283:
1284:
1285: sub viewport_geometry_js {
1286: return <<"GEOMETRY";
1287: var Geometry = {};
1288: function init_geometry() {
1289: if (Geometry.init) { return };
1290: Geometry.init=1;
1291: if (window.innerHeight) {
1292: Geometry.getViewportHeight = function() { return window.innerHeight; };
1293: Geometry.getViewportWidth = function() { return window.innerWidth; };
1294: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1295: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1296: }
1297: else if (document.documentElement && document.documentElement.clientHeight) {
1298: Geometry.getViewportHeight =
1299: function() { return document.documentElement.clientHeight; };
1300: Geometry.getViewportWidth =
1301: function() { return document.documentElement.clientWidth; };
1302:
1303: Geometry.getHorizontalScroll =
1304: function() { return document.documentElement.scrollLeft; };
1305: Geometry.getVerticalScroll =
1306: function() { return document.documentElement.scrollTop; };
1307: }
1308: else if (document.body.clientHeight) {
1309: Geometry.getViewportHeight =
1310: function() { return document.body.clientHeight; };
1311: Geometry.getViewportWidth =
1312: function() { return document.body.clientWidth; };
1313: Geometry.getHorizontalScroll =
1314: function() { return document.body.scrollLeft; };
1315: Geometry.getVerticalScroll =
1316: function() { return document.body.scrollTop; };
1317: }
1318: }
1319:
1320: GEOMETRY
1321: }
1322:
1323: =pod
1324:
1325: =item * &viewport_size_js()
1326:
1327: 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.
1328:
1329: =cut
1330:
1331: sub viewport_size_js {
1332: my $geometry = &viewport_geometry_js();
1333: return <<"DIMS";
1334:
1335: $geometry
1336:
1337: function getViewportDims(width,height) {
1338: init_geometry();
1339: width.value = Geometry.getViewportWidth();
1340: height.value = Geometry.getViewportHeight();
1341: return;
1342: }
1343:
1344: DIMS
1345: }
1346:
1347: =pod
1348:
1349: =item * &resize_textarea_js()
1350:
1351: emits the needed javascript to resize a textarea to be as big as possible
1352:
1353: creates a function resize_textrea that takes two IDs first should be
1354: the id of the element to resize, second should be the id of a div that
1355: surrounds everything that comes after the textarea, this routine needs
1356: to be attached to the <body> for the onload and onresize events.
1357:
1358: =back
1359:
1360: =cut
1361:
1362: sub resize_textarea_js {
1363: my $geometry = &viewport_geometry_js();
1364: return <<"RESIZE";
1365: <script type="text/javascript">
1366: $geometry
1367:
1368: function getX(element) {
1369: var x = 0;
1370: while (element) {
1371: x += element.offsetLeft;
1372: element = element.offsetParent;
1373: }
1374: return x;
1375: }
1376: function getY(element) {
1377: var y = 0;
1378: while (element) {
1379: y += element.offsetTop;
1380: element = element.offsetParent;
1381: }
1382: return y;
1383: }
1384:
1385:
1386: function resize_textarea(textarea_id,bottom_id) {
1387: init_geometry();
1388: var textarea = document.getElementById(textarea_id);
1389: //alert(textarea);
1390:
1391: var textarea_top = getY(textarea);
1392: var textarea_height = textarea.offsetHeight;
1393: var bottom = document.getElementById(bottom_id);
1394: var bottom_top = getY(bottom);
1395: var bottom_height = bottom.offsetHeight;
1396: var window_height = Geometry.getViewportHeight();
1397: var fudge = 23;
1398: var new_height = window_height-fudge-textarea_top-bottom_height;
1399: if (new_height < 300) {
1400: new_height = 300;
1401: }
1402: textarea.style.height=new_height+'px';
1403: }
1404: </script>
1405: RESIZE
1406:
1407: }
1408:
1409: =pod
1410:
1411: =head1 Excel and CSV file utility routines
1412:
1413: =over 4
1414:
1415: =cut
1416:
1417: ###############################################################
1418: ###############################################################
1419:
1420: =pod
1421:
1422: =item * &csv_translate($text)
1423:
1424: Translate $text to allow it to be output as a 'comma separated values'
1425: format.
1426:
1427: =cut
1428:
1429: ###############################################################
1430: ###############################################################
1431: sub csv_translate {
1432: my $text = shift;
1433: $text =~ s/\"/\"\"/g;
1434: $text =~ s/\n/ /g;
1435: return $text;
1436: }
1437:
1438: ###############################################################
1439: ###############################################################
1440:
1441: =pod
1442:
1443: =item * &define_excel_formats()
1444:
1445: Define some commonly used Excel cell formats.
1446:
1447: Currently supported formats:
1448:
1449: =over 4
1450:
1451: =item header
1452:
1453: =item bold
1454:
1455: =item h1
1456:
1457: =item h2
1458:
1459: =item h3
1460:
1461: =item h4
1462:
1463: =item i
1464:
1465: =item date
1466:
1467: =back
1468:
1469: Inputs: $workbook
1470:
1471: Returns: $format, a hash reference.
1472:
1473: =cut
1474:
1475: ###############################################################
1476: ###############################################################
1477: sub define_excel_formats {
1478: my ($workbook) = @_;
1479: my $format;
1480: $format->{'header'} = $workbook->add_format(bold => 1,
1481: bottom => 1,
1482: align => 'center');
1483: $format->{'bold'} = $workbook->add_format(bold=>1);
1484: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1485: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1486: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1487: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1488: $format->{'i'} = $workbook->add_format(italic=>1);
1489: $format->{'date'} = $workbook->add_format(num_format=>
1490: 'mm/dd/yyyy hh:mm:ss');
1491: return $format;
1492: }
1493:
1494: ###############################################################
1495: ###############################################################
1496:
1497: =pod
1498:
1499: =item * &create_workbook()
1500:
1501: Create an Excel worksheet. If it fails, output message on the
1502: request object and return undefs.
1503:
1504: Inputs: Apache request object
1505:
1506: Returns (undef) on failure,
1507: Excel worksheet object, scalar with filename, and formats
1508: from &Apache::loncommon::define_excel_formats on success
1509:
1510: =cut
1511:
1512: ###############################################################
1513: ###############################################################
1514: sub create_workbook {
1515: my ($r) = @_;
1516: #
1517: # Create the excel spreadsheet
1518: my $filename = '/prtspool/'.
1519: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1520: time.'_'.rand(1000000000).'.xls';
1521: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1522: if (! defined($workbook)) {
1523: $r->log_error("Error creating excel spreadsheet $filename: $!");
1524: $r->print('<p>'.&mt("Unable to create new Excel file. ".
1525: "This error has been logged. ".
1526: "Please alert your LON-CAPA administrator").
1527: '</p>');
1528: return (undef);
1529: }
1530: #
1531: $workbook->set_tempdir('/home/httpd/perl/tmp');
1532: #
1533: my $format = &Apache::loncommon::define_excel_formats($workbook);
1534: return ($workbook,$filename,$format);
1535: }
1536:
1537: ###############################################################
1538: ###############################################################
1539:
1540: =pod
1541:
1542: =item * &create_text_file()
1543:
1544: Create a file to write to and eventually make available to the user.
1545: If file creation fails, outputs an error message on the request object and
1546: return undefs.
1547:
1548: Inputs: Apache request object, and file suffix
1549:
1550: Returns (undef) on failure,
1551: Filehandle and filename on success.
1552:
1553: =cut
1554:
1555: ###############################################################
1556: ###############################################################
1557: sub create_text_file {
1558: my ($r,$suffix) = @_;
1559: if (! defined($suffix)) { $suffix = 'txt'; };
1560: my $fh;
1561: my $filename = '/prtspool/'.
1562: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1563: time.'_'.rand(1000000000).'.'.$suffix;
1564: $fh = Apache::File->new('>/home/httpd'.$filename);
1565: if (! defined($fh)) {
1566: $r->log_error("Couldn't open $filename for output $!");
1567: $r->print(&mt('Problems occurred in creating the output file. '
1568: .'This error has been logged. '
1569: .'Please alert your LON-CAPA administrator.'));
1570: }
1571: return ($fh,$filename)
1572: }
1573:
1574:
1575: =pod
1576:
1577: =back
1578:
1579: =cut
1580:
1581: ###############################################################
1582: ## Home server <option> list generating code ##
1583: ###############################################################
1584:
1585: # ------------------------------------------
1586:
1587: sub domain_select {
1588: my ($name,$value,$multiple)=@_;
1589: my %domains=map {
1590: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1591: } &Apache::lonnet::all_domains();
1592: if ($multiple) {
1593: $domains{''}=&mt('Any domain');
1594: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1595: return &multiple_select_form($name,$value,4,\%domains);
1596: } else {
1597: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1598: return &select_form($name,$value,%domains);
1599: }
1600: }
1601:
1602: #-------------------------------------------
1603:
1604: =pod
1605:
1606: =head1 Routines for form select boxes
1607:
1608: =over 4
1609:
1610: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1611:
1612: Returns a string containing a <select> element int multiple mode
1613:
1614:
1615: Args:
1616: $name - name of the <select> element
1617: $value - scalar or array ref of values that should already be selected
1618: $size - number of rows long the select element is
1619: $hash - the elements should be 'option' => 'shown text'
1620: (shown text should already have been &mt())
1621: $order - (optional) array ref of the order to show the elements in
1622:
1623: =cut
1624:
1625: #-------------------------------------------
1626: sub multiple_select_form {
1627: my ($name,$value,$size,$hash,$order)=@_;
1628: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1629: my $output='';
1630: if (! defined($size)) {
1631: $size = 4;
1632: if (scalar(keys(%$hash))<4) {
1633: $size = scalar(keys(%$hash));
1634: }
1635: }
1636: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1637: my @order;
1638: if (ref($order) eq 'ARRAY') {
1639: @order = @{$order};
1640: } else {
1641: @order = sort(keys(%$hash));
1642: }
1643: if (exists($$hash{'select_form_order'})) {
1644: @order = @{$$hash{'select_form_order'}};
1645: }
1646:
1647: foreach my $key (@order) {
1648: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1649: $output.='selected="selected" ' if ($selected{$key});
1650: $output.='>'.$hash->{$key}."</option>\n";
1651: }
1652: $output.="</select>\n";
1653: return $output;
1654: }
1655:
1656: #-------------------------------------------
1657:
1658: =pod
1659:
1660: =item * &select_form($defdom,$name,%hash)
1661:
1662: Returns a string containing a <select name='$name' size='1'> form to
1663: allow a user to select options from a hash option_name => displayed text.
1664: See lonrights.pm for an example invocation and use.
1665:
1666: =cut
1667:
1668: #-------------------------------------------
1669: sub select_form {
1670: my ($def,$name,%hash) = @_;
1671: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1672: my @keys;
1673: if (exists($hash{'select_form_order'})) {
1674: @keys=@{$hash{'select_form_order'}};
1675: } else {
1676: @keys=sort(keys(%hash));
1677: }
1678: foreach my $key (@keys) {
1679: $selectform.=
1680: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
1681: ($key eq $def ? 'selected="selected" ' : '').
1682: ">".&mt($hash{$key})."</option>\n";
1683: }
1684: $selectform.="</select>";
1685: return $selectform;
1686: }
1687:
1688: # For display filters
1689:
1690: sub display_filter {
1691: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1692: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1693: return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1694: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
1695: (&mt('all'),10,20,50,100,1000,10000))).
1696: '</label></span> <span class="LC_nobreak">'.
1697: &mt('Filter [_1]',
1698: &select_form($env{'form.displayfilter'},
1699: 'displayfilter',
1700: ('currentfolder' => 'Current folder/page',
1701: 'containing' => 'Containing phrase',
1702: 'none' => 'None'))).
1703: '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1704: }
1705:
1706: sub gradeleveldescription {
1707: my $gradelevel=shift;
1708: my %gradelevels=(0 => 'Not specified',
1709: 1 => 'Grade 1',
1710: 2 => 'Grade 2',
1711: 3 => 'Grade 3',
1712: 4 => 'Grade 4',
1713: 5 => 'Grade 5',
1714: 6 => 'Grade 6',
1715: 7 => 'Grade 7',
1716: 8 => 'Grade 8',
1717: 9 => 'Grade 9',
1718: 10 => 'Grade 10',
1719: 11 => 'Grade 11',
1720: 12 => 'Grade 12',
1721: 13 => 'Grade 13',
1722: 14 => '100 Level',
1723: 15 => '200 Level',
1724: 16 => '300 Level',
1725: 17 => '400 Level',
1726: 18 => 'Graduate Level');
1727: return &mt($gradelevels{$gradelevel});
1728: }
1729:
1730: sub select_level_form {
1731: my ($deflevel,$name)=@_;
1732: unless ($deflevel) { $deflevel=0; }
1733: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1734: for (my $i=0; $i<=18; $i++) {
1735: $selectform.="<option value=\"$i\" ".
1736: ($i==$deflevel ? 'selected="selected" ' : '').
1737: ">".&gradeleveldescription($i)."</option>\n";
1738: }
1739: $selectform.="</select>";
1740: return $selectform;
1741: }
1742:
1743: #-------------------------------------------
1744:
1745: =pod
1746:
1747: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$autosubmit)
1748:
1749: Returns a string containing a <select name='$name' size='1'> form to
1750: allow a user to select the domain to preform an operation in.
1751: See loncreateuser.pm for an example invocation and use.
1752:
1753: If the $includeempty flag is set, it also includes an empty choice ("no domain
1754: selected");
1755:
1756: If the $showdomdesc flag is set, the domain name is followed by the domain description.
1757:
1758: If the $autosubmit flag is set, the form containing the domain selector will be auto-submitted by an onchange action.
1759:
1760: =cut
1761:
1762: #-------------------------------------------
1763: sub select_dom_form {
1764: my ($defdom,$name,$includeempty,$showdomdesc,$autosubmit) = @_;
1765: my $onchange;
1766: if ($autosubmit) {
1767: $onchange = ' onchange="this.form.submit()"';
1768: }
1769: my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1770: if ($includeempty) { @domains=('',@domains); }
1771: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1772: foreach my $dom (@domains) {
1773: $selectdomain.="<option value=\"$dom\" ".
1774: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
1775: if ($showdomdesc) {
1776: if ($dom ne '') {
1777: my $domdesc = &Apache::lonnet::domain($dom,'description');
1778: if ($domdesc ne '') {
1779: $selectdomain .= ' ('.$domdesc.')';
1780: }
1781: }
1782: }
1783: $selectdomain .= "</option>\n";
1784: }
1785: $selectdomain.="</select>";
1786: return $selectdomain;
1787: }
1788:
1789: #-------------------------------------------
1790:
1791: =pod
1792:
1793: =item * &home_server_form_item($domain,$name,$defaultflag)
1794:
1795: input: 4 arguments (two required, two optional) -
1796: $domain - domain of new user
1797: $name - name of form element
1798: $default - Value of 'default' causes a default item to be first
1799: option, and selected by default.
1800: $hide - Value of 'hide' causes hiding of the name of the server,
1801: if 1 server found, or default, if 0 found.
1802: output: returns 2 items:
1803: (a) form element which contains either:
1804: (i) <select name="$name">
1805: <option value="$hostid1">$hostid $servers{$hostid}</option>
1806: <option value="$hostid2">$hostid $servers{$hostid}</option>
1807: </select>
1808: form item if there are multiple library servers in $domain, or
1809: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
1810: if there is only one library server in $domain.
1811:
1812: (b) number of library servers found.
1813:
1814: See loncreateuser.pm for example of use.
1815:
1816: =cut
1817:
1818: #-------------------------------------------
1819: sub home_server_form_item {
1820: my ($domain,$name,$default,$hide) = @_;
1821: my %servers = &Apache::lonnet::get_servers($domain,'library');
1822: my $result;
1823: my $numlib = keys(%servers);
1824: if ($numlib > 1) {
1825: $result .= '<select name="'.$name.'" />'."\n";
1826: if ($default) {
1827: $result .= '<option value="default" selected>'.&mt('default').
1828: '</option>'."\n";
1829: }
1830: foreach my $hostid (sort(keys(%servers))) {
1831: $result.= '<option value="'.$hostid.'">'.
1832: $hostid.' '.$servers{$hostid}."</option>\n";
1833: }
1834: $result .= '</select>'."\n";
1835: } elsif ($numlib == 1) {
1836: my $hostid;
1837: foreach my $item (keys(%servers)) {
1838: $hostid = $item;
1839: }
1840: $result .= '<input type="hidden" name="'.$name.'" value="'.
1841: $hostid.'" />';
1842: if (!$hide) {
1843: $result .= $hostid.' '.$servers{$hostid};
1844: }
1845: $result .= "\n";
1846: } elsif ($default) {
1847: $result .= '<input type="hidden" name="'.$name.
1848: '" value="default" />';
1849: if (!$hide) {
1850: $result .= &mt('default');
1851: }
1852: $result .= "\n";
1853: }
1854: return ($result,$numlib);
1855: }
1856:
1857: =pod
1858:
1859: =back
1860:
1861: =cut
1862:
1863: ###############################################################
1864: ## Decoding User Agent ##
1865: ###############################################################
1866:
1867: =pod
1868:
1869: =head1 Decoding the User Agent
1870:
1871: =over 4
1872:
1873: =item * &decode_user_agent()
1874:
1875: Inputs: $r
1876:
1877: Outputs:
1878:
1879: =over 4
1880:
1881: =item * $httpbrowser
1882:
1883: =item * $clientbrowser
1884:
1885: =item * $clientversion
1886:
1887: =item * $clientmathml
1888:
1889: =item * $clientunicode
1890:
1891: =item * $clientos
1892:
1893: =back
1894:
1895: =back
1896:
1897: =cut
1898:
1899: ###############################################################
1900: ###############################################################
1901: sub decode_user_agent {
1902: my ($r)=@_;
1903: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
1904: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
1905: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1906: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1907: my $clientbrowser='unknown';
1908: my $clientversion='0';
1909: my $clientmathml='';
1910: my $clientunicode='0';
1911: for (my $i=0;$i<=$#browsertype;$i++) {
1912: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
1913: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
1914: $clientbrowser=$bname;
1915: $httpbrowser=~/$vreg/i;
1916: $clientversion=$1;
1917: $clientmathml=($clientversion>=$minv);
1918: $clientunicode=($clientversion>=$univ);
1919: }
1920: }
1921: my $clientos='unknown';
1922: if (($httpbrowser=~/linux/i) ||
1923: ($httpbrowser=~/unix/i) ||
1924: ($httpbrowser=~/ux/i) ||
1925: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
1926: if (($httpbrowser=~/vax/i) ||
1927: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
1928: if ($httpbrowser=~/next/i) { $clientos='next'; }
1929: if (($httpbrowser=~/mac/i) ||
1930: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1931: if ($httpbrowser=~/win/i) { $clientos='win'; }
1932: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1933: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1934: $clientunicode,$clientos,);
1935: }
1936:
1937: ###############################################################
1938: ## Authentication changing form generation subroutines ##
1939: ###############################################################
1940: ##
1941: ## All of the authform_xxxxxxx subroutines take their inputs in a
1942: ## hash, and have reasonable default values.
1943: ##
1944: ## formname = the name given in the <form> tag.
1945: #-------------------------------------------
1946:
1947: =pod
1948:
1949: =head1 Authentication Routines
1950:
1951: =over 4
1952:
1953: =item * &authform_xxxxxx()
1954:
1955: The authform_xxxxxx subroutines provide javascript and html forms which
1956: handle some of the conveniences required for authentication forms.
1957: This is not an optimal method, but it works.
1958:
1959: =over 4
1960:
1961: =item * authform_header
1962:
1963: =item * authform_authorwarning
1964:
1965: =item * authform_nochange
1966:
1967: =item * authform_kerberos
1968:
1969: =item * authform_internal
1970:
1971: =item * authform_filesystem
1972:
1973: =back
1974:
1975: See loncreateuser.pm for invocation and use examples.
1976:
1977: =cut
1978:
1979: #-------------------------------------------
1980: sub authform_header{
1981: my %in = (
1982: formname => 'cu',
1983: kerb_def_dom => '',
1984: @_,
1985: );
1986: $in{'formname'} = 'document.' . $in{'formname'};
1987: my $result='';
1988:
1989: #---------------------------------------------- Code for upper case translation
1990: my $Javascript_toUpperCase;
1991: unless ($in{kerb_def_dom}) {
1992: $Javascript_toUpperCase =<<"END";
1993: switch (choice) {
1994: case 'krb': currentform.elements[choicearg].value =
1995: currentform.elements[choicearg].value.toUpperCase();
1996: break;
1997: default:
1998: }
1999: END
2000: } else {
2001: $Javascript_toUpperCase = "";
2002: }
2003:
2004: my $radioval = "'nochange'";
2005: if (defined($in{'curr_authtype'})) {
2006: if ($in{'curr_authtype'} ne '') {
2007: $radioval = "'".$in{'curr_authtype'}."arg'";
2008: }
2009: }
2010: my $argfield = 'null';
2011: if (defined($in{'mode'})) {
2012: if ($in{'mode'} eq 'modifycourse') {
2013: if (defined($in{'curr_autharg'})) {
2014: if ($in{'curr_autharg'} ne '') {
2015: $argfield = "'$in{'curr_autharg'}'";
2016: }
2017: }
2018: }
2019: }
2020:
2021: $result.=<<"END";
2022: var current = new Object();
2023: current.radiovalue = $radioval;
2024: current.argfield = $argfield;
2025:
2026: function changed_radio(choice,currentform) {
2027: var choicearg = choice + 'arg';
2028: // If a radio button in changed, we need to change the argfield
2029: if (current.radiovalue != choice) {
2030: current.radiovalue = choice;
2031: if (current.argfield != null) {
2032: currentform.elements[current.argfield].value = '';
2033: }
2034: if (choice == 'nochange') {
2035: current.argfield = null;
2036: } else {
2037: current.argfield = choicearg;
2038: switch(choice) {
2039: case 'krb':
2040: currentform.elements[current.argfield].value =
2041: "$in{'kerb_def_dom'}";
2042: break;
2043: default:
2044: break;
2045: }
2046: }
2047: }
2048: return;
2049: }
2050:
2051: function changed_text(choice,currentform) {
2052: var choicearg = choice + 'arg';
2053: if (currentform.elements[choicearg].value !='') {
2054: $Javascript_toUpperCase
2055: // clear old field
2056: if ((current.argfield != choicearg) && (current.argfield != null)) {
2057: currentform.elements[current.argfield].value = '';
2058: }
2059: current.argfield = choicearg;
2060: }
2061: set_auth_radio_buttons(choice,currentform);
2062: return;
2063: }
2064:
2065: function set_auth_radio_buttons(newvalue,currentform) {
2066: var i=0;
2067: while (i < currentform.login.length) {
2068: if (currentform.login[i].value == newvalue) { break; }
2069: i++;
2070: }
2071: if (i == currentform.login.length) {
2072: return;
2073: }
2074: current.radiovalue = newvalue;
2075: currentform.login[i].checked = true;
2076: return;
2077: }
2078: END
2079: return $result;
2080: }
2081:
2082: sub authform_authorwarning{
2083: my $result='';
2084: $result='<i>'.
2085: &mt('As a general rule, only authors or co-authors should be '.
2086: 'filesystem authenticated '.
2087: '(which allows access to the server filesystem).')."</i>\n";
2088: return $result;
2089: }
2090:
2091: sub authform_nochange{
2092: my %in = (
2093: formname => 'document.cu',
2094: kerb_def_dom => 'MSU.EDU',
2095: @_,
2096: );
2097: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2098: my $result;
2099: if (keys(%can_assign) == 0) {
2100: $result = &mt('Under you current role you are not permitted to change login settings for this user');
2101: } else {
2102: $result = '<label>'.&mt('[_1] Do not change login data',
2103: '<input type="radio" name="login" value="nochange" '.
2104: 'checked="checked" onclick="'.
2105: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2106: '</label>';
2107: }
2108: return $result;
2109: }
2110:
2111: sub authform_kerberos {
2112: my %in = (
2113: formname => 'document.cu',
2114: kerb_def_dom => 'MSU.EDU',
2115: kerb_def_auth => 'krb4',
2116: @_,
2117: );
2118: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2119: $autharg,$jscall);
2120: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2121: if ($in{'kerb_def_auth'} eq 'krb5') {
2122: $check5 = ' checked="on"';
2123: } else {
2124: $check4 = ' checked="on"';
2125: }
2126: $krbarg = $in{'kerb_def_dom'};
2127: if (defined($in{'curr_authtype'})) {
2128: if ($in{'curr_authtype'} eq 'krb') {
2129: $krbcheck = ' checked="on"';
2130: if (defined($in{'mode'})) {
2131: if ($in{'mode'} eq 'modifyuser') {
2132: $krbcheck = '';
2133: }
2134: }
2135: if (defined($in{'curr_kerb_ver'})) {
2136: if ($in{'curr_krb_ver'} eq '5') {
2137: $check5 = ' checked="on"';
2138: $check4 = '';
2139: } else {
2140: $check4 = ' checked="on"';
2141: $check5 = '';
2142: }
2143: }
2144: if (defined($in{'curr_autharg'})) {
2145: $krbarg = $in{'curr_autharg'};
2146: }
2147: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2148: if (defined($in{'curr_autharg'})) {
2149: $result =
2150: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2151: $in{'curr_autharg'},$krbver);
2152: } else {
2153: $result =
2154: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2155: }
2156: return $result;
2157: }
2158: }
2159: } else {
2160: if ($authnum == 1) {
2161: $authtype = '<input type="hidden" name="login" value="krb">';
2162: }
2163: }
2164: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2165: return;
2166: } elsif ($authtype eq '') {
2167: if (defined($in{'mode'})) {
2168: if ($in{'mode'} eq 'modifycourse') {
2169: if ($authnum == 1) {
2170: $authtype = '<input type="hidden" name="login" value="krb">';
2171: }
2172: }
2173: }
2174: }
2175: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2176: if ($authtype eq '') {
2177: $authtype = '<input type="radio" name="login" value="krb" '.
2178: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2179: $krbcheck.' />';
2180: }
2181: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
2182: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
2183: $in{'curr_authtype'} eq 'krb5') ||
2184: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
2185: $in{'curr_authtype'} eq 'krb4')) {
2186: $result .= &mt
2187: ('[_1] Kerberos authenticated with domain [_2] '.
2188: '[_3] Version 4 [_4] Version 5 [_5]',
2189: '<label>'.$authtype,
2190: '</label><input type="text" size="10" name="krbarg" '.
2191: 'value="'.$krbarg.'" '.
2192: 'onchange="'.$jscall.'" />',
2193: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2194: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2195: '</label>');
2196: } elsif ($can_assign{'krb4'}) {
2197: $result .= &mt
2198: ('[_1] Kerberos authenticated with domain [_2] '.
2199: '[_3] Version 4 [_4]',
2200: '<label>'.$authtype,
2201: '</label><input type="text" size="10" name="krbarg" '.
2202: 'value="'.$krbarg.'" '.
2203: 'onchange="'.$jscall.'" />',
2204: '<label><input type="hidden" name="krbver" value="4" />',
2205: '</label>');
2206: } elsif ($can_assign{'krb5'}) {
2207: $result .= &mt
2208: ('[_1] Kerberos authenticated with domain [_2] '.
2209: '[_3] Version 5 [_4]',
2210: '<label>'.$authtype,
2211: '</label><input type="text" size="10" name="krbarg" '.
2212: 'value="'.$krbarg.'" '.
2213: 'onchange="'.$jscall.'" />',
2214: '<label><input type="hidden" name="krbver" value="5" />',
2215: '</label>');
2216: }
2217: return $result;
2218: }
2219:
2220: sub authform_internal{
2221: my %in = (
2222: formname => 'document.cu',
2223: kerb_def_dom => 'MSU.EDU',
2224: @_,
2225: );
2226: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
2227: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2228: if (defined($in{'curr_authtype'})) {
2229: if ($in{'curr_authtype'} eq 'int') {
2230: if ($can_assign{'int'}) {
2231: $intcheck = 'checked="on" ';
2232: if (defined($in{'mode'})) {
2233: if ($in{'mode'} eq 'modifyuser') {
2234: $intcheck = '';
2235: }
2236: }
2237: if (defined($in{'curr_autharg'})) {
2238: $intarg = $in{'curr_autharg'};
2239: }
2240: } else {
2241: $result = &mt('Currently internally authenticated.');
2242: return $result;
2243: }
2244: }
2245: } else {
2246: if ($authnum == 1) {
2247: $authtype = '<input type="hidden" name="login" value="int">';
2248: }
2249: }
2250: if (!$can_assign{'int'}) {
2251: return;
2252: } elsif ($authtype eq '') {
2253: if (defined($in{'mode'})) {
2254: if ($in{'mode'} eq 'modifycourse') {
2255: if ($authnum == 1) {
2256: $authtype = '<input type="hidden" name="login" value="int">';
2257: }
2258: }
2259: }
2260: }
2261: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2262: if ($authtype eq '') {
2263: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2264: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2265: }
2266: $autharg = '<input type="password" size="10" name="intarg" value="'.
2267: $intarg.'" onchange="'.$jscall.'" />';
2268: $result = &mt
2269: ('[_1] Internally authenticated (with initial password [_2])',
2270: '<label>'.$authtype,'</label>'.$autharg);
2271: $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>';
2272: return $result;
2273: }
2274:
2275: sub authform_local{
2276: my %in = (
2277: formname => 'document.cu',
2278: kerb_def_dom => 'MSU.EDU',
2279: @_,
2280: );
2281: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
2282: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2283: if (defined($in{'curr_authtype'})) {
2284: if ($in{'curr_authtype'} eq 'loc') {
2285: if ($can_assign{'loc'}) {
2286: $loccheck = 'checked="on" ';
2287: if (defined($in{'mode'})) {
2288: if ($in{'mode'} eq 'modifyuser') {
2289: $loccheck = '';
2290: }
2291: }
2292: if (defined($in{'curr_autharg'})) {
2293: $locarg = $in{'curr_autharg'};
2294: }
2295: } else {
2296: $result = &mt('Currently using local (institutional) authentication.');
2297: return $result;
2298: }
2299: }
2300: } else {
2301: if ($authnum == 1) {
2302: $authtype = '<input type="hidden" name="login" value="loc">';
2303: }
2304: }
2305: if (!$can_assign{'loc'}) {
2306: return;
2307: } elsif ($authtype eq '') {
2308: if (defined($in{'mode'})) {
2309: if ($in{'mode'} eq 'modifycourse') {
2310: if ($authnum == 1) {
2311: $authtype = '<input type="hidden" name="login" value="loc">';
2312: }
2313: }
2314: }
2315: }
2316: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2317: if ($authtype eq '') {
2318: $authtype = '<input type="radio" name="login" value="loc" '.
2319: $loccheck.' onchange="'.$jscall.'" onclick="'.
2320: $jscall.'" />';
2321: }
2322: $autharg = '<input type="text" size="10" name="locarg" value="'.
2323: $locarg.'" onchange="'.$jscall.'" />';
2324: $result = &mt('[_1] Local Authentication with argument [_2]',
2325: '<label>'.$authtype,'</label>'.$autharg);
2326: return $result;
2327: }
2328:
2329: sub authform_filesystem{
2330: my %in = (
2331: formname => 'document.cu',
2332: kerb_def_dom => 'MSU.EDU',
2333: @_,
2334: );
2335: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
2336: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2337: if (defined($in{'curr_authtype'})) {
2338: if ($in{'curr_authtype'} eq 'fsys') {
2339: if ($can_assign{'fsys'}) {
2340: $fsyscheck = 'checked="on" ';
2341: if (defined($in{'mode'})) {
2342: if ($in{'mode'} eq 'modifyuser') {
2343: $fsyscheck = '';
2344: }
2345: }
2346: } else {
2347: $result = &mt('Currently Filesystem Authenticated.');
2348: return $result;
2349: }
2350: }
2351: } else {
2352: if ($authnum == 1) {
2353: $authtype = '<input type="hidden" name="login" value="fsys">';
2354: }
2355: }
2356: if (!$can_assign{'fsys'}) {
2357: return;
2358: } elsif ($authtype eq '') {
2359: if (defined($in{'mode'})) {
2360: if ($in{'mode'} eq 'modifycourse') {
2361: if ($authnum == 1) {
2362: $authtype = '<input type="hidden" name="login" value="fsys">';
2363: }
2364: }
2365: }
2366: }
2367: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2368: if ($authtype eq '') {
2369: $authtype = '<input type="radio" name="login" value="fsys" '.
2370: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2371: $jscall.'" />';
2372: }
2373: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2374: ' onchange="'.$jscall.'" />';
2375: $result = &mt
2376: ('[_1] Filesystem Authenticated (with initial password [_2])',
2377: '<label><input type="radio" name="login" value="fsys" '.
2378: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
2379: '</label><input type="password" size="10" name="fsysarg" value="" '.
2380: 'onchange="'.$jscall.'" />');
2381: return $result;
2382: }
2383:
2384: sub get_assignable_auth {
2385: my ($dom) = @_;
2386: if ($dom eq '') {
2387: $dom = $env{'request.role.domain'};
2388: }
2389: my %can_assign = (
2390: krb4 => 1,
2391: krb5 => 1,
2392: int => 1,
2393: loc => 1,
2394: );
2395: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2396: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2397: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2398: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2399: my $context;
2400: if ($env{'request.role'} =~ /^au/) {
2401: $context = 'author';
2402: } elsif ($env{'request.role'} =~ /^dc/) {
2403: $context = 'domain';
2404: } elsif ($env{'request.course.id'}) {
2405: $context = 'course';
2406: }
2407: if ($context) {
2408: if (ref($authhash->{$context}) eq 'HASH') {
2409: %can_assign = %{$authhash->{$context}};
2410: }
2411: }
2412: }
2413: }
2414: my $authnum = 0;
2415: foreach my $key (keys(%can_assign)) {
2416: if ($can_assign{$key}) {
2417: $authnum ++;
2418: }
2419: }
2420: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2421: $authnum --;
2422: }
2423: return ($authnum,%can_assign);
2424: }
2425:
2426: ###############################################################
2427: ## Get Kerberos Defaults for Domain ##
2428: ###############################################################
2429: ##
2430: ## Returns default kerberos version and an associated argument
2431: ## as listed in file domain.tab. If not listed, provides
2432: ## appropriate default domain and kerberos version.
2433: ##
2434: #-------------------------------------------
2435:
2436: =pod
2437:
2438: =item * &get_kerberos_defaults()
2439:
2440: get_kerberos_defaults($target_domain) returns the default kerberos
2441: version and domain. If not found, it defaults to version 4 and the
2442: domain of the server.
2443:
2444: =over 4
2445:
2446: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2447:
2448: =back
2449:
2450: =back
2451:
2452: =cut
2453:
2454: #-------------------------------------------
2455: sub get_kerberos_defaults {
2456: my $domain=shift;
2457: my ($krbdef,$krbdefdom);
2458: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2459: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2460: $krbdef = $domdefaults{'auth_def'};
2461: $krbdefdom = $domdefaults{'auth_arg_def'};
2462: } else {
2463: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2464: my $krbdefdom=$1;
2465: $krbdefdom=~tr/a-z/A-Z/;
2466: $krbdef = "krb4";
2467: }
2468: return ($krbdef,$krbdefdom);
2469: }
2470:
2471:
2472: ###############################################################
2473: ## Thesaurus Functions ##
2474: ###############################################################
2475:
2476: =pod
2477:
2478: =head1 Thesaurus Functions
2479:
2480: =over 4
2481:
2482: =item * &initialize_keywords()
2483:
2484: Initializes the package variable %Keywords if it is empty. Uses the
2485: package variable $thesaurus_db_file.
2486:
2487: =cut
2488:
2489: ###################################################
2490:
2491: sub initialize_keywords {
2492: return 1 if (scalar keys(%Keywords));
2493: # If we are here, %Keywords is empty, so fill it up
2494: # Make sure the file we need exists...
2495: if (! -e $thesaurus_db_file) {
2496: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2497: " failed because it does not exist");
2498: return 0;
2499: }
2500: # Set up the hash as a database
2501: my %thesaurus_db;
2502: if (! tie(%thesaurus_db,'GDBM_File',
2503: $thesaurus_db_file,&GDBM_READER(),0640)){
2504: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2505: $thesaurus_db_file);
2506: return 0;
2507: }
2508: # Get the average number of appearances of a word.
2509: my $avecount = $thesaurus_db{'average.count'};
2510: # Put keywords (those that appear > average) into %Keywords
2511: while (my ($word,$data)=each (%thesaurus_db)) {
2512: my ($count,undef) = split /:/,$data;
2513: $Keywords{$word}++ if ($count > $avecount);
2514: }
2515: untie %thesaurus_db;
2516: # Remove special values from %Keywords.
2517: foreach my $value ('total.count','average.count') {
2518: delete($Keywords{$value}) if (exists($Keywords{$value}));
2519: }
2520: return 1;
2521: }
2522:
2523: ###################################################
2524:
2525: =pod
2526:
2527: =item * &keyword($word)
2528:
2529: Returns true if $word is a keyword. A keyword is a word that appears more
2530: than the average number of times in the thesaurus database. Calls
2531: &initialize_keywords
2532:
2533: =cut
2534:
2535: ###################################################
2536:
2537: sub keyword {
2538: return if (!&initialize_keywords());
2539: my $word=lc(shift());
2540: $word=~s/\W//g;
2541: return exists($Keywords{$word});
2542: }
2543:
2544: ###############################################################
2545:
2546: =pod
2547:
2548: =item * &get_related_words()
2549:
2550: Look up a word in the thesaurus. Takes a scalar argument and returns
2551: an array of words. If the keyword is not in the thesaurus, an empty array
2552: will be returned. The order of the words returned is determined by the
2553: database which holds them.
2554:
2555: Uses global $thesaurus_db_file.
2556:
2557: =cut
2558:
2559: ###############################################################
2560: sub get_related_words {
2561: my $keyword = shift;
2562: my %thesaurus_db;
2563: if (! -e $thesaurus_db_file) {
2564: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
2565: "failed because the file does not exist");
2566: return ();
2567: }
2568: if (! tie(%thesaurus_db,'GDBM_File',
2569: $thesaurus_db_file,&GDBM_READER(),0640)){
2570: return ();
2571: }
2572: my @Words=();
2573: my $count=0;
2574: if (exists($thesaurus_db{$keyword})) {
2575: # The first element is the number of times
2576: # the word appears. We do not need it now.
2577: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
2578: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
2579: my $threshold=$mostfrequentcount/10;
2580: foreach my $possibleword (@RelatedWords) {
2581: my ($word,$wordcount)=split(/\,/,$possibleword);
2582: if ($wordcount>$threshold) {
2583: push(@Words,$word);
2584: $count++;
2585: if ($count>10) { last; }
2586: }
2587: }
2588: }
2589: untie %thesaurus_db;
2590: return @Words;
2591: }
2592:
2593: =pod
2594:
2595: =back
2596:
2597: =cut
2598:
2599: # -------------------------------------------------------------- Plaintext name
2600: =pod
2601:
2602: =head1 User Name Functions
2603:
2604: =over 4
2605:
2606: =item * &plainname($uname,$udom,$first)
2607:
2608: Takes a users logon name and returns it as a string in
2609: "first middle last generation" form
2610: if $first is set to 'lastname' then it returns it as
2611: 'lastname generation, firstname middlename' if their is a lastname
2612:
2613: =cut
2614:
2615:
2616: ###############################################################
2617: sub plainname {
2618: my ($uname,$udom,$first)=@_;
2619: return if (!defined($uname) || !defined($udom));
2620: my %names=&getnames($uname,$udom);
2621: my $name=&Apache::lonnet::format_name($names{'firstname'},
2622: $names{'middlename'},
2623: $names{'lastname'},
2624: $names{'generation'},$first);
2625: $name=~s/^\s+//;
2626: $name=~s/\s+$//;
2627: $name=~s/\s+/ /g;
2628: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
2629: return $name;
2630: }
2631:
2632: # -------------------------------------------------------------------- Nickname
2633: =pod
2634:
2635: =item * &nickname($uname,$udom)
2636:
2637: Gets a users name and returns it as a string as
2638:
2639: ""nickname""
2640:
2641: if the user has a nickname or
2642:
2643: "first middle last generation"
2644:
2645: if the user does not
2646:
2647: =cut
2648:
2649: sub nickname {
2650: my ($uname,$udom)=@_;
2651: return if (!defined($uname) || !defined($udom));
2652: my %names=&getnames($uname,$udom);
2653: my $name=$names{'nickname'};
2654: if ($name) {
2655: $name='"'.$name.'"';
2656: } else {
2657: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
2658: $names{'lastname'}.' '.$names{'generation'};
2659: $name=~s/\s+$//;
2660: $name=~s/\s+/ /g;
2661: }
2662: return $name;
2663: }
2664:
2665: sub getnames {
2666: my ($uname,$udom)=@_;
2667: return if (!defined($uname) || !defined($udom));
2668: if ($udom eq 'public' && $uname eq 'public') {
2669: return ('lastname' => &mt('Public'));
2670: }
2671: my $id=$uname.':'.$udom;
2672: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
2673: if ($cached) {
2674: return %{$names};
2675: } else {
2676: my %loadnames=&Apache::lonnet::get('environment',
2677: ['firstname','middlename','lastname','generation','nickname'],
2678: $udom,$uname);
2679: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
2680: return %loadnames;
2681: }
2682: }
2683:
2684: # -------------------------------------------------------------------- getemails
2685:
2686: =pod
2687:
2688: =item * &getemails($uname,$udom)
2689:
2690: Gets a user's email information and returns it as a hash with keys:
2691: notification, critnotification, permanentemail
2692:
2693: For notification and critnotification, values are comma-separated lists
2694: of e-mail addresses; for permanentemail, value is a single e-mail address.
2695:
2696:
2697: =cut
2698:
2699:
2700: sub getemails {
2701: my ($uname,$udom)=@_;
2702: if ($udom eq 'public' && $uname eq 'public') {
2703: return;
2704: }
2705: if (!$udom) { $udom=$env{'user.domain'}; }
2706: if (!$uname) { $uname=$env{'user.name'}; }
2707: my $id=$uname.':'.$udom;
2708: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
2709: if ($cached) {
2710: return %{$names};
2711: } else {
2712: my %loadnames=&Apache::lonnet::get('environment',
2713: ['notification','critnotification',
2714: 'permanentemail'],
2715: $udom,$uname);
2716: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
2717: return %loadnames;
2718: }
2719: }
2720:
2721: sub flush_email_cache {
2722: my ($uname,$udom)=@_;
2723: if (!$udom) { $udom =$env{'user.domain'}; }
2724: if (!$uname) { $uname=$env{'user.name'}; }
2725: return if ($udom eq 'public' && $uname eq 'public');
2726: my $id=$uname.':'.$udom;
2727: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
2728: }
2729:
2730: # -------------------------------------------------------------------- getlangs
2731:
2732: =pod
2733:
2734: =item * &getlangs($uname,$udom)
2735:
2736: Gets a user's language preference and returns it as a hash with key:
2737: language.
2738:
2739: =cut
2740:
2741:
2742: sub getlangs {
2743: my ($uname,$udom) = @_;
2744: if (!$udom) { $udom =$env{'user.domain'}; }
2745: if (!$uname) { $uname=$env{'user.name'}; }
2746: my $id=$uname.':'.$udom;
2747: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
2748: if ($cached) {
2749: return %{$langs};
2750: } else {
2751: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
2752: $udom,$uname);
2753: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
2754: return %loadlangs;
2755: }
2756: }
2757:
2758: sub flush_langs_cache {
2759: my ($uname,$udom)=@_;
2760: if (!$udom) { $udom =$env{'user.domain'}; }
2761: if (!$uname) { $uname=$env{'user.name'}; }
2762: return if ($udom eq 'public' && $uname eq 'public');
2763: my $id=$uname.':'.$udom;
2764: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
2765: }
2766:
2767: # ------------------------------------------------------------------ Screenname
2768:
2769: =pod
2770:
2771: =item * &screenname($uname,$udom)
2772:
2773: Gets a users screenname and returns it as a string
2774:
2775: =cut
2776:
2777: sub screenname {
2778: my ($uname,$udom)=@_;
2779: if ($uname eq $env{'user.name'} &&
2780: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
2781: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
2782: return $names{'screenname'};
2783: }
2784:
2785:
2786: # ------------------------------------------------------------- Message Wrapper
2787:
2788: sub messagewrapper {
2789: my ($link,$username,$domain,$subject,$text)=@_;
2790: return
2791: '<a href="/adm/email?compose=individual&'.
2792: 'recname='.$username.'&recdom='.$domain.
2793: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
2794: 'title="'.&mt('Send message').'">'.$link.'</a>';
2795: }
2796: # --------------------------------------------------------------- Notes Wrapper
2797:
2798: sub noteswrapper {
2799: my ($link,$un,$do)=@_;
2800: return
2801: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
2802: }
2803: # ------------------------------------------------------------- Aboutme Wrapper
2804:
2805: sub aboutmewrapper {
2806: my ($link,$username,$domain,$target)=@_;
2807: if (!defined($username) && !defined($domain)) {
2808: return;
2809: }
2810: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
2811: ($target?' target="$target"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
2812: }
2813:
2814: # ------------------------------------------------------------ Syllabus Wrapper
2815:
2816:
2817: sub syllabuswrapper {
2818: my ($linktext,$coursedir,$domain)=@_;
2819: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
2820: }
2821:
2822: sub track_student_link {
2823: my ($linktext,$sname,$sdom,$target,$start) = @_;
2824: my $link ="/adm/trackstudent?";
2825: my $title = 'View recent activity';
2826: if (defined($sname) && $sname !~ /^\s*$/ &&
2827: defined($sdom) && $sdom !~ /^\s*$/) {
2828: $link .= "selected_student=$sname:$sdom";
2829: $title .= ' of this student';
2830: }
2831: if (defined($target) && $target !~ /^\s*$/) {
2832: $target = qq{target="$target"};
2833: } else {
2834: $target = '';
2835: }
2836: if ($start) { $link.='&start='.$start; }
2837: $title = &mt($title);
2838: $linktext = &mt($linktext);
2839: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
2840: &help_open_topic('View_recent_activity');
2841: }
2842:
2843: # ===================================================== Display a student photo
2844:
2845:
2846: sub student_image_tag {
2847: my ($domain,$user)=@_;
2848: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
2849: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
2850: return '<img src="'.$imgsrc.'" align="right" />';
2851: } else {
2852: return '';
2853: }
2854: }
2855:
2856: =pod
2857:
2858: =back
2859:
2860: =head1 Access .tab File Data
2861:
2862: =over 4
2863:
2864: =item * &languageids()
2865:
2866: returns list of all language ids
2867:
2868: =cut
2869:
2870: sub languageids {
2871: return sort(keys(%language));
2872: }
2873:
2874: =pod
2875:
2876: =item * &languagedescription()
2877:
2878: returns description of a specified language id
2879:
2880: =cut
2881:
2882: sub languagedescription {
2883: my $code=shift;
2884: return ($supported_language{$code}?'* ':'').
2885: $language{$code}.
2886: ($supported_language{$code}?' ('.&mt('interface available').')':'');
2887: }
2888:
2889: sub plainlanguagedescription {
2890: my $code=shift;
2891: return $language{$code};
2892: }
2893:
2894: sub supportedlanguagecode {
2895: my $code=shift;
2896: return $supported_language{$code};
2897: }
2898:
2899: =pod
2900:
2901: =item * ©rightids()
2902:
2903: returns list of all copyrights
2904:
2905: =cut
2906:
2907: sub copyrightids {
2908: return sort(keys(%cprtag));
2909: }
2910:
2911: =pod
2912:
2913: =item * ©rightdescription()
2914:
2915: returns description of a specified copyright id
2916:
2917: =cut
2918:
2919: sub copyrightdescription {
2920: return &mt($cprtag{shift(@_)});
2921: }
2922:
2923: =pod
2924:
2925: =item * &source_copyrightids()
2926:
2927: returns list of all source copyrights
2928:
2929: =cut
2930:
2931: sub source_copyrightids {
2932: return sort(keys(%scprtag));
2933: }
2934:
2935: =pod
2936:
2937: =item * &source_copyrightdescription()
2938:
2939: returns description of a specified source copyright id
2940:
2941: =cut
2942:
2943: sub source_copyrightdescription {
2944: return &mt($scprtag{shift(@_)});
2945: }
2946:
2947: =pod
2948:
2949: =item * &filecategories()
2950:
2951: returns list of all file categories
2952:
2953: =cut
2954:
2955: sub filecategories {
2956: return sort(keys(%category_extensions));
2957: }
2958:
2959: =pod
2960:
2961: =item * &filecategorytypes()
2962:
2963: returns list of file types belonging to a given file
2964: category
2965:
2966: =cut
2967:
2968: sub filecategorytypes {
2969: my ($cat) = @_;
2970: return @{$category_extensions{lc($cat)}};
2971: }
2972:
2973: =pod
2974:
2975: =item * &fileembstyle()
2976:
2977: returns embedding style for a specified file type
2978:
2979: =cut
2980:
2981: sub fileembstyle {
2982: return $fe{lc(shift(@_))};
2983: }
2984:
2985: sub filemimetype {
2986: return $fm{lc(shift(@_))};
2987: }
2988:
2989:
2990: sub filecategoryselect {
2991: my ($name,$value)=@_;
2992: return &select_form($value,$name,
2993: '' => &mt('Any category'),
2994: map { $_,$_ } sort(keys(%category_extensions)));
2995: }
2996:
2997: =pod
2998:
2999: =item * &filedescription()
3000:
3001: returns description for a specified file type
3002:
3003: =cut
3004:
3005: sub filedescription {
3006: my $file_description = $fd{lc(shift())};
3007: $file_description =~ s:([\[\]]):~$1:g;
3008: return &mt($file_description);
3009: }
3010:
3011: =pod
3012:
3013: =item * &filedescriptionex()
3014:
3015: returns description for a specified file type with
3016: extra formatting
3017:
3018: =cut
3019:
3020: sub filedescriptionex {
3021: my $ex=shift;
3022: my $file_description = $fd{lc($ex)};
3023: $file_description =~ s:([\[\]]):~$1:g;
3024: return '.'.$ex.' '.&mt($file_description);
3025: }
3026:
3027: # End of .tab access
3028: =pod
3029:
3030: =back
3031:
3032: =cut
3033:
3034: # ------------------------------------------------------------------ File Types
3035: sub fileextensions {
3036: return sort(keys(%fe));
3037: }
3038:
3039: # ----------------------------------------------------------- Display Languages
3040: # returns a hash with all desired display languages
3041: #
3042:
3043: sub display_languages {
3044: my %languages=();
3045: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
3046: $languages{$lang}=1;
3047: }
3048: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
3049: if ($env{'form.displaylanguage'}) {
3050: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3051: $languages{$lang}=1;
3052: }
3053: }
3054: return %languages;
3055: }
3056:
3057: sub languages {
3058: my ($possible_langs) = @_;
3059: my @preferred_langs = &Apache::lonlocal::preferred_languages();
3060: if (!ref($possible_langs)) {
3061: if( wantarray ) {
3062: return @preferred_langs;
3063: } else {
3064: return $preferred_langs[0];
3065: }
3066: }
3067: my %possibilities = map { $_ => 1 } (@$possible_langs);
3068: my @preferred_possibilities;
3069: foreach my $preferred_lang (@preferred_langs) {
3070: if (exists($possibilities{$preferred_lang})) {
3071: push(@preferred_possibilities, $preferred_lang);
3072: }
3073: }
3074: if( wantarray ) {
3075: return @preferred_possibilities;
3076: }
3077: return $preferred_possibilities[0];
3078: }
3079:
3080: sub user_lang {
3081: my ($touname,$toudom,$fromcid) = @_;
3082: my @userlangs;
3083: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3084: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3085: $env{'course.'.$fromcid.'.languages'}));
3086: } else {
3087: my %langhash = &getlangs($touname,$toudom);
3088: if ($langhash{'languages'} ne '') {
3089: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3090: } else {
3091: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3092: if ($domdefs{'lang_def'} ne '') {
3093: @userlangs = ($domdefs{'lang_def'});
3094: }
3095: }
3096: }
3097: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3098: my $user_lh = Apache::localize->get_handle(@languages);
3099: return $user_lh;
3100: }
3101:
3102:
3103: ###############################################################
3104: ## Student Answer Attempts ##
3105: ###############################################################
3106:
3107: =pod
3108:
3109: =head1 Alternate Problem Views
3110:
3111: =over 4
3112:
3113: =item * &get_previous_attempt($symb, $username, $domain, $course,
3114: $getattempt, $regexp, $gradesub)
3115:
3116: Return string with previous attempt on problem. Arguments:
3117:
3118: =over 4
3119:
3120: =item * $symb: Problem, including path
3121:
3122: =item * $username: username of the desired student
3123:
3124: =item * $domain: domain of the desired student
3125:
3126: =item * $course: Course ID
3127:
3128: =item * $getattempt: Leave blank for all attempts, otherwise put
3129: something
3130:
3131: =item * $regexp: if string matches this regexp, the string will be
3132: sent to $gradesub
3133:
3134: =item * $gradesub: routine that processes the string if it matches $regexp
3135:
3136: =back
3137:
3138: The output string is a table containing all desired attempts, if any.
3139:
3140: =cut
3141:
3142: sub get_previous_attempt {
3143: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
3144: my $prevattempts='';
3145: no strict 'refs';
3146: if ($symb) {
3147: my (%returnhash)=
3148: &Apache::lonnet::restore($symb,$course,$domain,$username);
3149: if ($returnhash{'version'}) {
3150: my %lasthash=();
3151: my $version;
3152: for ($version=1;$version<=$returnhash{'version'};$version++) {
3153: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3154: $lasthash{$key}=$returnhash{$version.':'.$key};
3155: }
3156: }
3157: $prevattempts=&start_data_table().&start_data_table_header_row();
3158: $prevattempts.='<th>'.&mt('History').'</th>';
3159: foreach my $key (sort(keys(%lasthash))) {
3160: my ($ign,@parts) = split(/\./,$key);
3161: if ($#parts > 0) {
3162: my $data=$parts[-1];
3163: pop(@parts);
3164: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
3165: } else {
3166: if ($#parts == 0) {
3167: $prevattempts.='<th>'.$parts[0].'</th>';
3168: } else {
3169: $prevattempts.='<th>'.$ign.'</th>';
3170: }
3171: }
3172: }
3173: $prevattempts.=&end_data_table_header_row();
3174: if ($getattempt eq '') {
3175: for ($version=1;$version<=$returnhash{'version'};$version++) {
3176: $prevattempts.=&start_data_table_row().
3177: '<td>'.&mt('Transaction [_1]',$version).'</td>';
3178: foreach my $key (sort(keys(%lasthash))) {
3179: my $value = &format_previous_attempt_value($key,
3180: $returnhash{$version.':'.$key});
3181: $prevattempts.='<td>'.$value.' </td>';
3182: }
3183: $prevattempts.=&end_data_table_row();
3184: }
3185: }
3186: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
3187: foreach my $key (sort(keys(%lasthash))) {
3188: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3189: if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
3190: $prevattempts.='<td>'.$value.' </td>';
3191: }
3192: $prevattempts.= &end_data_table_row().&end_data_table();
3193: } else {
3194: $prevattempts=
3195: &start_data_table().&start_data_table_row().
3196: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3197: &end_data_table_row().&end_data_table();
3198: }
3199: } else {
3200: $prevattempts=
3201: &start_data_table().&start_data_table_row().
3202: '<td>'.&mt('No data.').'</td>'.
3203: &end_data_table_row().&end_data_table();
3204: }
3205: }
3206:
3207: sub format_previous_attempt_value {
3208: my ($key,$value) = @_;
3209: if ($key =~ /timestamp/) {
3210: $value = &Apache::lonlocal::locallocaltime($value);
3211: } elsif (ref($value) eq 'ARRAY') {
3212: $value = '('.join(', ', @{ $value }).')';
3213: } else {
3214: $value = &unescape($value);
3215: }
3216: return $value;
3217: }
3218:
3219:
3220: sub relative_to_absolute {
3221: my ($url,$output)=@_;
3222: my $parser=HTML::TokeParser->new(\$output);
3223: my $token;
3224: my $thisdir=$url;
3225: my @rlinks=();
3226: while ($token=$parser->get_token) {
3227: if ($token->[0] eq 'S') {
3228: if ($token->[1] eq 'a') {
3229: if ($token->[2]->{'href'}) {
3230: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3231: }
3232: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3233: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3234: } elsif ($token->[1] eq 'base') {
3235: $thisdir=$token->[2]->{'href'};
3236: }
3237: }
3238: }
3239: $thisdir=~s-/[^/]*$--;
3240: foreach my $link (@rlinks) {
3241: unless (($link=~/^https?\:\/\//i) ||
3242: ($link=~/^\//) ||
3243: ($link=~/^javascript:/i) ||
3244: ($link=~/^mailto:/i) ||
3245: ($link=~/^\#/)) {
3246: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3247: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
3248: }
3249: }
3250: # -------------------------------------------------- Deal with Applet codebases
3251: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3252: return $output;
3253: }
3254:
3255: =pod
3256:
3257: =item * &get_student_view()
3258:
3259: show a snapshot of what student was looking at
3260:
3261: =cut
3262:
3263: sub get_student_view {
3264: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
3265: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
3266: my (%form);
3267: my @elements=('symb','courseid','domain','username');
3268: foreach my $element (@elements) {
3269: $form{'grade_'.$element}=eval '$'.$element #'
3270: }
3271: if (defined($moreenv)) {
3272: %form=(%form,%{$moreenv});
3273: }
3274: if (defined($target)) { $form{'grade_target'} = $target; }
3275: $feedurl=&Apache::lonnet::clutter($feedurl);
3276: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
3277: $userview=~s/\<body[^\>]*\>//gi;
3278: $userview=~s/\<\/body\>//gi;
3279: $userview=~s/\<html\>//gi;
3280: $userview=~s/\<\/html\>//gi;
3281: $userview=~s/\<head\>//gi;
3282: $userview=~s/\<\/head\>//gi;
3283: $userview=~s/action\s*\=/would_be_action\=/gi;
3284: $userview=&relative_to_absolute($feedurl,$userview);
3285: if (wantarray) {
3286: return ($userview,$response);
3287: } else {
3288: return $userview;
3289: }
3290: }
3291:
3292: sub get_student_view_with_retries {
3293: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3294:
3295: my $ok = 0; # True if we got a good response.
3296: my $content;
3297: my $response;
3298:
3299: # Try to get the student_view done. within the retries count:
3300:
3301: do {
3302: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3303: $ok = $response->is_success;
3304: if (!$ok) {
3305: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3306: }
3307: $retries--;
3308: } while (!$ok && ($retries > 0));
3309:
3310: if (!$ok) {
3311: $content = ''; # On error return an empty content.
3312: }
3313: if (wantarray) {
3314: return ($content, $response);
3315: } else {
3316: return $content;
3317: }
3318: }
3319:
3320: =pod
3321:
3322: =item * &get_student_answers()
3323:
3324: show a snapshot of how student was answering problem
3325:
3326: =cut
3327:
3328: sub get_student_answers {
3329: my ($symb,$username,$domain,$courseid,%form) = @_;
3330: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
3331: my (%moreenv);
3332: my @elements=('symb','courseid','domain','username');
3333: foreach my $element (@elements) {
3334: $moreenv{'grade_'.$element}=eval '$'.$element #'
3335: }
3336: $moreenv{'grade_target'}='answer';
3337: %moreenv=(%form,%moreenv);
3338: $feedurl = &Apache::lonnet::clutter($feedurl);
3339: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
3340: return $userview;
3341: }
3342:
3343: =pod
3344:
3345: =item * &submlink()
3346:
3347: Inputs: $text $uname $udom $symb $target
3348:
3349: Returns: A link to grades.pm such as to see the SUBM view of a student
3350:
3351: =cut
3352:
3353: ###############################################
3354: sub submlink {
3355: my ($text,$uname,$udom,$symb,$target)=@_;
3356: if (!($uname && $udom)) {
3357: (my $cursymb, my $courseid,$udom,$uname)=
3358: &Apache::lonnet::whichuser($symb);
3359: if (!$symb) { $symb=$cursymb; }
3360: }
3361: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
3362: $symb=&escape($symb);
3363: if ($target) { $target="target=\"$target\""; }
3364: return '<a href="/adm/grades?&command=submission&'.
3365: 'symb='.$symb.'&student='.$uname.
3366: '&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
3367: }
3368: ##############################################
3369:
3370: =pod
3371:
3372: =item * &pgrdlink()
3373:
3374: Inputs: $text $uname $udom $symb $target
3375:
3376: Returns: A link to grades.pm such as to see the PGRD view of a student
3377:
3378: =cut
3379:
3380: ###############################################
3381: sub pgrdlink {
3382: my $link=&submlink(@_);
3383: $link=~s/(&command=submission)/$1&showgrading=yes/;
3384: return $link;
3385: }
3386: ##############################################
3387:
3388: =pod
3389:
3390: =item * &pprmlink()
3391:
3392: Inputs: $text $uname $udom $symb $target
3393:
3394: Returns: A link to parmset.pm such as to see the PPRM view of a
3395: student and a specific resource
3396:
3397: =cut
3398:
3399: ###############################################
3400: sub pprmlink {
3401: my ($text,$uname,$udom,$symb,$target)=@_;
3402: if (!($uname && $udom)) {
3403: (my $cursymb, my $courseid,$udom,$uname)=
3404: &Apache::lonnet::whichuser($symb);
3405: if (!$symb) { $symb=$cursymb; }
3406: }
3407: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
3408: $symb=&escape($symb);
3409: if ($target) { $target="target=\"$target\""; }
3410: return '<a href="/adm/parmset?command=set&'.
3411: 'symb='.$symb.'&uname='.$uname.
3412: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
3413: }
3414: ##############################################
3415:
3416: =pod
3417:
3418: =back
3419:
3420: =cut
3421:
3422: ###############################################
3423:
3424:
3425: sub timehash {
3426: my ($thistime) = @_;
3427: my $timezone = &Apache::lonlocal::gettimezone();
3428: my $dt = DateTime->from_epoch(epoch => $thistime)
3429: ->set_time_zone($timezone);
3430: my $wday = $dt->day_of_week();
3431: if ($wday == 7) { $wday = 0; }
3432: return ( 'second' => $dt->second(),
3433: 'minute' => $dt->minute(),
3434: 'hour' => $dt->hour(),
3435: 'day' => $dt->day_of_month(),
3436: 'month' => $dt->month(),
3437: 'year' => $dt->year(),
3438: 'weekday' => $wday,
3439: 'dayyear' => $dt->day_of_year(),
3440: 'dlsav' => $dt->is_dst() );
3441: }
3442:
3443: sub utc_string {
3444: my ($date)=@_;
3445: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
3446: }
3447:
3448: sub maketime {
3449: my %th=@_;
3450: my ($epoch_time,$timezone,$dt);
3451: $timezone = &Apache::lonlocal::gettimezone();
3452: eval {
3453: $dt = DateTime->new( year => $th{'year'},
3454: month => $th{'month'},
3455: day => $th{'day'},
3456: hour => $th{'hour'},
3457: minute => $th{'minute'},
3458: second => $th{'second'},
3459: time_zone => $timezone,
3460: );
3461: };
3462: if (!$@) {
3463: $epoch_time = $dt->epoch;
3464: if ($epoch_time) {
3465: return $epoch_time;
3466: }
3467: }
3468: return POSIX::mktime(
3469: ($th{'seconds'},$th{'minutes'},$th{'hours'},
3470: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
3471: }
3472:
3473: #########################################
3474:
3475: sub findallcourses {
3476: my ($roles,$uname,$udom) = @_;
3477: my %roles;
3478: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
3479: my %courses;
3480: my $now=time;
3481: if (!defined($uname)) {
3482: $uname = $env{'user.name'};
3483: }
3484: if (!defined($udom)) {
3485: $udom = $env{'user.domain'};
3486: }
3487: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
3488: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
3489: if (!%roles) {
3490: %roles = (
3491: cc => 1,
3492: in => 1,
3493: ep => 1,
3494: ta => 1,
3495: cr => 1,
3496: st => 1,
3497: );
3498: }
3499: foreach my $entry (keys(%roleshash)) {
3500: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
3501: if ($trole =~ /^cr/) {
3502: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
3503: } else {
3504: next if (!exists($roles{$trole}));
3505: }
3506: if ($tend) {
3507: next if ($tend < $now);
3508: }
3509: if ($tstart) {
3510: next if ($tstart > $now);
3511: }
3512: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
3513: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
3514: if ($secpart eq '') {
3515: ($cnum,$role) = split(/_/,$cnumpart);
3516: $sec = 'none';
3517: $realsec = '';
3518: } else {
3519: $cnum = $cnumpart;
3520: ($sec,$role) = split(/_/,$secpart);
3521: $realsec = $sec;
3522: }
3523: $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
3524: }
3525: } else {
3526: foreach my $key (keys(%env)) {
3527: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
3528: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
3529: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
3530: next if ($role eq 'ca' || $role eq 'aa');
3531: next if (%roles && !exists($roles{$role}));
3532: my ($starttime,$endtime)=split(/\./,$env{$key});
3533: my $active=1;
3534: if ($starttime) {
3535: if ($now<$starttime) { $active=0; }
3536: }
3537: if ($endtime) {
3538: if ($now>$endtime) { $active=0; }
3539: }
3540: if ($active) {
3541: if ($sec eq '') {
3542: $sec = 'none';
3543: }
3544: $courses{$cdom.'_'.$cnum}{$sec} =
3545: $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
3546: }
3547: }
3548: }
3549: }
3550: return %courses;
3551: }
3552:
3553: ###############################################
3554:
3555: sub blockcheck {
3556: my ($setters,$activity,$uname,$udom) = @_;
3557:
3558: if (!defined($udom)) {
3559: $udom = $env{'user.domain'};
3560: }
3561: if (!defined($uname)) {
3562: $uname = $env{'user.name'};
3563: }
3564:
3565: # If uname and udom are for a course, check for blocks in the course.
3566:
3567: if (&Apache::lonnet::is_course($udom,$uname)) {
3568: my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
3569: my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
3570: return ($startblock,$endblock);
3571: }
3572:
3573: my $startblock = 0;
3574: my $endblock = 0;
3575: my %live_courses = &findallcourses(undef,$uname,$udom);
3576:
3577: # If uname is for a user, and activity is course-specific, i.e.,
3578: # boards, chat or groups, check for blocking in current course only.
3579:
3580: if (($activity eq 'boards' || $activity eq 'chat' ||
3581: $activity eq 'groups') && ($env{'request.course.id'})) {
3582: foreach my $key (keys(%live_courses)) {
3583: if ($key ne $env{'request.course.id'}) {
3584: delete($live_courses{$key});
3585: }
3586: }
3587: }
3588:
3589: my $otheruser = 0;
3590: my %own_courses;
3591: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
3592: # Resource belongs to user other than current user.
3593: $otheruser = 1;
3594: # Gather courses for current user
3595: %own_courses =
3596: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
3597: }
3598:
3599: # Gather active course roles - course coordinator, instructor,
3600: # exam proctor, ta, student, or custom role.
3601:
3602: foreach my $course (keys(%live_courses)) {
3603: my ($cdom,$cnum);
3604: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
3605: $cdom = $env{'course.'.$course.'.domain'};
3606: $cnum = $env{'course.'.$course.'.num'};
3607: } else {
3608: ($cdom,$cnum) = split(/_/,$course);
3609: }
3610: my $no_ownblock = 0;
3611: my $no_userblock = 0;
3612: if ($otheruser && $activity ne 'com') {
3613: # Check if current user has 'evb' priv for this
3614: if (defined($own_courses{$course})) {
3615: foreach my $sec (keys(%{$own_courses{$course}})) {
3616: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
3617: if ($sec ne 'none') {
3618: $checkrole .= '/'.$sec;
3619: }
3620: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3621: $no_ownblock = 1;
3622: last;
3623: }
3624: }
3625: }
3626: # if they have 'evb' priv and are currently not playing student
3627: next if (($no_ownblock) &&
3628: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
3629: }
3630: foreach my $sec (keys(%{$live_courses{$course}})) {
3631: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
3632: if ($sec ne 'none') {
3633: $checkrole .= '/'.$sec;
3634: }
3635: if ($otheruser) {
3636: # Resource belongs to user other than current user.
3637: # Assemble privs for that user, and check for 'evb' priv.
3638: my ($trole,$tdom,$tnum,$tsec);
3639: my $entry = $live_courses{$course}{$sec};
3640: if ($entry =~ /^cr/) {
3641: ($trole,$tdom,$tnum,$tsec) =
3642: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
3643: } else {
3644: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
3645: }
3646: my ($spec,$area,$trest,%allroles,%userroles);
3647: $area = '/'.$tdom.'/'.$tnum;
3648: $trest = $tnum;
3649: if ($tsec ne '') {
3650: $area .= '/'.$tsec;
3651: $trest .= '/'.$tsec;
3652: }
3653: $spec = $trole.'.'.$area;
3654: if ($trole =~ /^cr/) {
3655: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
3656: $tdom,$spec,$trest,$area);
3657: } else {
3658: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
3659: $tdom,$spec,$trest,$area);
3660: }
3661: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
3662: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
3663: if ($1) {
3664: $no_userblock = 1;
3665: last;
3666: }
3667: }
3668: } else {
3669: # Resource belongs to current user
3670: # Check for 'evb' priv via lonnet::allowed().
3671: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3672: $no_ownblock = 1;
3673: last;
3674: }
3675: }
3676: }
3677: # if they have the evb priv and are currently not playing student
3678: next if (($no_ownblock) &&
3679: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
3680: next if ($no_userblock);
3681:
3682: # Retrieve blocking times and identity of blocker for course
3683: # of specified user, unless user has 'evb' privilege.
3684:
3685: my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
3686: if (($start != 0) &&
3687: (($startblock == 0) || ($startblock > $start))) {
3688: $startblock = $start;
3689: }
3690: if (($end != 0) &&
3691: (($endblock == 0) || ($endblock < $end))) {
3692: $endblock = $end;
3693: }
3694: }
3695: return ($startblock,$endblock);
3696: }
3697:
3698: sub get_blocks {
3699: my ($setters,$activity,$cdom,$cnum) = @_;
3700: my $startblock = 0;
3701: my $endblock = 0;
3702: my $course = $cdom.'_'.$cnum;
3703: $setters->{$course} = {};
3704: $setters->{$course}{'staff'} = [];
3705: $setters->{$course}{'times'} = [];
3706: my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
3707: foreach my $record (keys(%records)) {
3708: my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
3709: if ($start <= time && $end >= time) {
3710: my ($staff_name,$staff_dom,$title,$blocks) =
3711: &parse_block_record($records{$record});
3712: if ($blocks->{$activity} eq 'on') {
3713: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
3714: push(@{$$setters{$course}{'times'}}, [$start,$end]);
3715: if ( ($startblock == 0) || ($startblock > $start) ) {
3716: $startblock = $start;
3717: }
3718: if ( ($endblock == 0) || ($endblock < $end) ) {
3719: $endblock = $end;
3720: }
3721: }
3722: }
3723: }
3724: return ($startblock,$endblock);
3725: }
3726:
3727: sub parse_block_record {
3728: my ($record) = @_;
3729: my ($setuname,$setudom,$title,$blocks);
3730: if (ref($record) eq 'HASH') {
3731: ($setuname,$setudom) = split(/:/,$record->{'setter'});
3732: $title = &unescape($record->{'event'});
3733: $blocks = $record->{'blocks'};
3734: } else {
3735: my @data = split(/:/,$record,3);
3736: if (scalar(@data) eq 2) {
3737: $title = $data[1];
3738: ($setuname,$setudom) = split(/@/,$data[0]);
3739: } else {
3740: ($setuname,$setudom,$title) = @data;
3741: }
3742: $blocks = { 'com' => 'on' };
3743: }
3744: return ($setuname,$setudom,$title,$blocks);
3745: }
3746:
3747: sub build_block_table {
3748: my ($startblock,$endblock,$setters) = @_;
3749: my %lt = &Apache::lonlocal::texthash(
3750: 'cacb' => 'Currently active communication blocks',
3751: 'cour' => 'Course',
3752: 'dura' => 'Duration',
3753: 'blse' => 'Block set by'
3754: );
3755: my $output;
3756: $output = '<br />'.$lt{'cacb'}.':<br />';
3757: $output .= &start_data_table();
3758: $output .= '
3759: <tr>
3760: <th>'.$lt{'cour'}.'</th>
3761: <th>'.$lt{'dura'}.'</th>
3762: <th>'.$lt{'blse'}.'</th>
3763: </tr>
3764: ';
3765: foreach my $course (keys(%{$setters})) {
3766: my %courseinfo=&Apache::lonnet::coursedescription($course);
3767: for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) {
3768: my ($uname,$udom) = @{$$setters{$course}{staff}[$i]};
3769: my $fullname = &plainname($uname,$udom);
3770: if (defined($env{'user.name'}) && defined($env{'user.domain'})
3771: && $env{'user.name'} ne 'public'
3772: && $env{'user.domain'} ne 'public') {
3773: $fullname = &aboutmewrapper($fullname,$uname,$udom);
3774: }
3775: my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]};
3776: $openblock = &Apache::lonlocal::locallocaltime($openblock);
3777: $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
3778: $output .= &Apache::loncommon::start_data_table_row().
3779: '<td>'.$courseinfo{'description'}.'</td>'.
3780: '<td>'.$openblock.' to '.$closeblock.'</td>'.
3781: '<td>'.$fullname.'</td>'.
3782: &Apache::loncommon::end_data_table_row();
3783: }
3784: }
3785: $output .= &end_data_table();
3786: }
3787:
3788: sub blocking_status {
3789: my ($activity,$uname,$udom) = @_;
3790: my %setters;
3791: my ($blocked,$output,$ownitem,$is_course);
3792: my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
3793: if ($startblock && $endblock) {
3794: $blocked = 1;
3795: if (wantarray) {
3796: my $category;
3797: if ($activity eq 'boards') {
3798: $category = 'Discussion posts in this course';
3799: } elsif ($activity eq 'blogs') {
3800: $category = 'Blogs';
3801: } elsif ($activity eq 'port') {
3802: if (defined($uname) && defined($udom)) {
3803: if ($uname eq $env{'user.name'} &&
3804: $udom eq $env{'user.domain'}) {
3805: $ownitem = 1;
3806: }
3807: }
3808: $is_course = &Apache::lonnet::is_course($udom,$uname);
3809: if ($ownitem) {
3810: $category = 'Your portfolio files';
3811: } elsif ($is_course) {
3812: my $coursedesc;
3813: foreach my $course (keys(%setters)) {
3814: my %courseinfo =
3815: &Apache::lonnet::coursedescription($course);
3816: $coursedesc = $courseinfo{'description'};
3817: }
3818: $category = "Group files in the course '$coursedesc'";
3819: } else {
3820: $category = 'Portfolio files belonging to ';
3821: if ($env{'user.name'} eq 'public' &&
3822: $env{'user.domain'} eq 'public') {
3823: $category .= &plainname($uname,$udom);
3824: } else {
3825: $category .= &aboutmewrapper(&plainname($uname,$udom),$uname,$udom);
3826: }
3827: }
3828: } elsif ($activity eq 'groups') {
3829: $category = 'Groups in this course';
3830: }
3831: my $showstart = &Apache::lonlocal::locallocaltime($startblock);
3832: my $showend = &Apache::lonlocal::locallocaltime($endblock);
3833: $output = '<br />'.&mt('[_1] will be inaccessible between [_2] and [_3] because communication is being blocked.',$category,$showstart,$showend).'<br />';
3834: if (!($activity eq 'port' && !($ownitem) && !($is_course))) {
3835: $output .= &build_block_table($startblock,$endblock,\%setters);
3836: }
3837: }
3838: }
3839: if (wantarray) {
3840: return ($blocked,$output);
3841: } else {
3842: return $blocked;
3843: }
3844: }
3845:
3846: ###############################################
3847:
3848: sub check_ip_acc {
3849: my ($acc)=@_;
3850: &Apache::lonxml::debug("acc is $acc");
3851: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
3852: return 1;
3853: }
3854: my $allowed=0;
3855: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
3856:
3857: my $name;
3858: foreach my $pattern (split(',',$acc)) {
3859: $pattern =~ s/^\s*//;
3860: $pattern =~ s/\s*$//;
3861: if ($pattern =~ /\*$/) {
3862: #35.8.*
3863: $pattern=~s/\*//;
3864: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
3865: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
3866: #35.8.3.[34-56]
3867: my $low=$2;
3868: my $high=$3;
3869: $pattern=$1;
3870: if ($ip =~ /^\Q$pattern\E/) {
3871: my $last=(split(/\./,$ip))[3];
3872: if ($last <=$high && $last >=$low) { $allowed=1; }
3873: }
3874: } elsif ($pattern =~ /^\*/) {
3875: #*.msu.edu
3876: $pattern=~s/\*//;
3877: if (!defined($name)) {
3878: use Socket;
3879: my $netaddr=inet_aton($ip);
3880: ($name)=gethostbyaddr($netaddr,AF_INET);
3881: }
3882: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
3883: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
3884: #127.0.0.1
3885: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
3886: } else {
3887: #some.name.com
3888: if (!defined($name)) {
3889: use Socket;
3890: my $netaddr=inet_aton($ip);
3891: ($name)=gethostbyaddr($netaddr,AF_INET);
3892: }
3893: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
3894: }
3895: if ($allowed) { last; }
3896: }
3897: return $allowed;
3898: }
3899:
3900: ###############################################
3901:
3902: =pod
3903:
3904: =head1 Domain Template Functions
3905:
3906: =over 4
3907:
3908: =item * &determinedomain()
3909:
3910: Inputs: $domain (usually will be undef)
3911:
3912: Returns: Determines which domain should be used for designs
3913:
3914: =cut
3915:
3916: ###############################################
3917: sub determinedomain {
3918: my $domain=shift;
3919: if (! $domain) {
3920: # Determine domain if we have not been given one
3921: $domain = $Apache::lonnet::perlvar{'lonDefDomain'};
3922: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
3923: if ($env{'request.role.domain'}) {
3924: $domain=$env{'request.role.domain'};
3925: }
3926: }
3927: return $domain;
3928: }
3929: ###############################################
3930:
3931: sub devalidate_domconfig_cache {
3932: my ($udom)=@_;
3933: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
3934: }
3935:
3936: # ---------------------- Get domain configuration for a domain
3937: sub get_domainconf {
3938: my ($udom) = @_;
3939: my $cachetime=1800;
3940: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
3941: if (defined($cached)) { return %{$result}; }
3942:
3943: my %domconfig = &Apache::lonnet::get_dom('configuration',
3944: ['login','rolecolors'],$udom);
3945: my (%designhash,%legacy);
3946: if (keys(%domconfig) > 0) {
3947: if (ref($domconfig{'login'}) eq 'HASH') {
3948: if (keys(%{$domconfig{'login'}})) {
3949: foreach my $key (keys(%{$domconfig{'login'}})) {
3950: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
3951: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
3952: $designhash{$udom.'.login.'.$key.'_'.$img} =
3953: $domconfig{'login'}{$key}{$img};
3954: }
3955: } else {
3956: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
3957: }
3958: }
3959: } else {
3960: $legacy{'login'} = 1;
3961: }
3962: } else {
3963: $legacy{'login'} = 1;
3964: }
3965: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
3966: if (keys(%{$domconfig{'rolecolors'}})) {
3967: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
3968: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
3969: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
3970: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
3971: }
3972: }
3973: }
3974: } else {
3975: $legacy{'rolecolors'} = 1;
3976: }
3977: } else {
3978: $legacy{'rolecolors'} = 1;
3979: }
3980: if (keys(%legacy) > 0) {
3981: my %legacyhash = &get_legacy_domconf($udom);
3982: foreach my $item (keys(%legacyhash)) {
3983: if ($item =~ /^\Q$udom\E\.login/) {
3984: if ($legacy{'login'}) {
3985: $designhash{$item} = $legacyhash{$item};
3986: }
3987: } else {
3988: if ($legacy{'rolecolors'}) {
3989: $designhash{$item} = $legacyhash{$item};
3990: }
3991: }
3992: }
3993: }
3994: } else {
3995: %designhash = &get_legacy_domconf($udom);
3996: }
3997: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
3998: $cachetime);
3999: return %designhash;
4000: }
4001:
4002: sub get_legacy_domconf {
4003: my ($udom) = @_;
4004: my %legacyhash;
4005: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4006: my $designfile = $designdir.'/'.$udom.'.tab';
4007: if (-e $designfile) {
4008: if ( open (my $fh,"<$designfile") ) {
4009: while (my $line = <$fh>) {
4010: next if ($line =~ /^\#/);
4011: chomp($line);
4012: my ($key,$val)=(split(/\=/,$line));
4013: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4014: }
4015: close($fh);
4016: }
4017: }
4018: if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
4019: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4020: }
4021: return %legacyhash;
4022: }
4023:
4024: =pod
4025:
4026: =item * &domainlogo()
4027:
4028: Inputs: $domain (usually will be undef)
4029:
4030: Returns: A link to a domain logo, if the domain logo exists.
4031: If the domain logo does not exist, a description of the domain.
4032:
4033: =cut
4034:
4035: ###############################################
4036: sub domainlogo {
4037: my $domain = &determinedomain(shift);
4038: my %designhash = &get_domainconf($domain);
4039: # See if there is a logo
4040: if ($designhash{$domain.'.login.domlogo'} ne '') {
4041: my $imgsrc = $designhash{$domain.'.login.domlogo'};
4042: if ($imgsrc =~ m{^/(adm|res)/}) {
4043: if ($imgsrc =~ m{^/res/}) {
4044: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4045: &Apache::lonnet::repcopy($local_name);
4046: }
4047: $imgsrc = &lonhttpdurl($imgsrc);
4048: }
4049: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
4050: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4051: return &Apache::lonnet::domain($domain,'description');
4052: } else {
4053: return '';
4054: }
4055: }
4056: ##############################################
4057:
4058: =pod
4059:
4060: =item * &designparm()
4061:
4062: Inputs: $which parameter; $domain (usually will be undef)
4063:
4064: Returns: value of designparamter $which
4065:
4066: =cut
4067:
4068:
4069: ##############################################
4070: sub designparm {
4071: my ($which,$domain)=@_;
4072: if ($env{'browser.blackwhite'} eq 'on') {
4073: if ($which=~/\.(font|alink|vlink|link|textcol)$/) {
4074: return '#000000';
4075: }
4076: if ($which=~/\.(pgbg|sidebg|bgcol)$/) {
4077: return '#FFFFFF';
4078: }
4079: if ($which=~/\.tabbg$/) {
4080: return '#CCCCCC';
4081: }
4082: }
4083: if (exists($env{'environment.color.'.$which})) {
4084: return $env{'environment.color.'.$which};
4085: }
4086: $domain=&determinedomain($domain);
4087: my %domdesign = &get_domainconf($domain);
4088: my $output;
4089: if ($domdesign{$domain.'.'.$which} ne '') {
4090: $output = $domdesign{$domain.'.'.$which};
4091: } else {
4092: $output = $defaultdesign{$which};
4093: }
4094: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
4095: ($which =~ /login\.(img|logo|domlogo|login)/)) {
4096: if ($output =~ m{^/(adm|res)/}) {
4097: if ($output =~ m{^/res/}) {
4098: my $local_name = &Apache::lonnet::filelocation('',$output);
4099: &Apache::lonnet::repcopy($local_name);
4100: }
4101: $output = &lonhttpdurl($output);
4102: }
4103: }
4104: return $output;
4105: }
4106:
4107: ###############################################
4108: ###############################################
4109:
4110: =pod
4111:
4112: =back
4113:
4114: =head1 HTML Helpers
4115:
4116: =over 4
4117:
4118: =item * &bodytag()
4119:
4120: Returns a uniform header for LON-CAPA web pages.
4121:
4122: Inputs:
4123:
4124: =over 4
4125:
4126: =item * $title, A title to be displayed on the page.
4127:
4128: =item * $function, the current role (can be undef).
4129:
4130: =item * $addentries, extra parameters for the <body> tag.
4131:
4132: =item * $bodyonly, if defined, only return the <body> tag.
4133:
4134: =item * $domain, if defined, force a given domain.
4135:
4136: =item * $forcereg, if page should register as content page (relevant for
4137: text interface only)
4138:
4139: =item * $customtitle, alternate text to use instead of $title
4140: in the title box that appears, this text
4141: is not auto translated like the $title is
4142:
4143: =item * $notopbar, if true, keep the 'what is this' info but remove the
4144: navigational links
4145:
4146: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
4147:
4148: =item * $notitle, if true keep the nav controls, but remove the title bar
4149:
4150: =item * $no_inline_link, if true and in remote mode, don't show the
4151: 'Switch To Inline Menu' link
4152:
4153: =item * $args, optional argument valid values are
4154: no_auto_mt_title -> prevents &mt()ing the title arg
4155: inherit_jsmath -> when creating popup window in a page,
4156: should it have jsmath forced on by the
4157: current page
4158:
4159: =back
4160:
4161: Returns: A uniform header for LON-CAPA web pages.
4162: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
4163: If $bodyonly is undef or zero, an html string containing a <body> tag and
4164: other decorations will be returned.
4165:
4166: =cut
4167:
4168: sub bodytag {
4169: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,$customtitle,
4170: $notopbar,$bgcolor,$notitle,$no_inline_link,$args)=@_;
4171:
4172: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
4173:
4174: $function = &get_users_function() if (!$function);
4175: my $img = &designparm($function.'.img',$domain);
4176: my $font = &designparm($function.'.font',$domain);
4177: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
4178:
4179: my %design = ( 'style' => 'margin-top: 0px',
4180: 'bgcolor' => $pgbg,
4181: 'text' => $font,
4182: 'alink' => &designparm($function.'.alink',$domain),
4183: 'vlink' => &designparm($function.'.vlink',$domain),
4184: 'link' => &designparm($function.'.link',$domain),);
4185: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
4186:
4187: # role and realm
4188: my ($role,$realm) = split(/\./,$env{'request.role'},2);
4189: if ($role eq 'ca') {
4190: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
4191: $realm = &plainname($rname,$rdom);
4192: }
4193: # realm
4194: if ($env{'request.course.id'}) {
4195: if ($env{'request.role'} !~ /^cr/) {
4196: $role = &Apache::lonnet::plaintext($role,&course_type());
4197: }
4198: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
4199: } else {
4200: $role = &Apache::lonnet::plaintext($role);
4201: }
4202:
4203: if (!$realm) { $realm=' '; }
4204: # Set messages
4205: my $messages=&domainlogo($domain);
4206:
4207: my $extra_body_attr = &make_attr_string($forcereg,\%design);
4208:
4209: # construct main body tag
4210: my $bodytag = "<body $extra_body_attr>".
4211: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
4212:
4213: if ($bodyonly) {
4214: return $bodytag;
4215: } elsif ($env{'browser.interface'} eq 'textual') {
4216: # Accessibility
4217:
4218: $bodytag.=&Apache::lonmenu::menubuttons($forcereg,$forcereg);
4219: if (!$notitle) {
4220: $bodytag.='<h1>LON-CAPA: '.$title.'</h1>';
4221: }
4222: return $bodytag;
4223: }
4224:
4225: my $name = &plainname($env{'user.name'},$env{'user.domain'});
4226: if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
4227: undef($role);
4228: } else {
4229: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
4230: }
4231:
4232: my $roleinfo=(<<ENDROLE);
4233: <td class="LC_title_bar_who">
4234: <div class="LC_title_bar_name">
4235: $name
4236:
4237: </div>
4238: <div class="LC_title_bar_role">
4239: $role
4240: </div>
4241: <div class="LC_title_bar_realm">
4242: $realm
4243: </div>
4244: </td>
4245: ENDROLE
4246:
4247: my $titleinfo = '<h1>'.$title.'</h1>';
4248: if ($customtitle) {
4249: $titleinfo = $customtitle;
4250: }
4251: #
4252: # Extra info if you are the DC
4253: my $dc_info = '';
4254: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
4255: $env{'course.'.$env{'request.course.id'}.
4256: '.domain'}.'/'})) {
4257: my $cid = $env{'request.course.id'};
4258: $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
4259: $dc_info =~ s/\s+$//;
4260: $dc_info = '('.$dc_info.')';
4261: }
4262:
4263: if (($env{'environment.remote'} eq 'off') || ($args->{'suppress_header_logos'})) {
4264: # No Remote
4265: if ($env{'request.state'} eq 'construct') {
4266: $forcereg=1;
4267: }
4268:
4269: if (!$customtitle && $env{'request.state'} eq 'construct') {
4270: # this is for resources; directories have customtitle, and crumbs
4271: # and select recent are created in lonpubdir.pm
4272: my ($uname,$thisdisfn)=
4273: ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
4274: my $formaction='/priv/'.$uname.'/'.$thisdisfn;
4275: $formaction=~s/\/+/\//g;
4276:
4277: my $parentpath = '';
4278: my $lastitem = '';
4279: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4280: $parentpath = $1;
4281: $lastitem = $2;
4282: } else {
4283: $lastitem = $thisdisfn;
4284: }
4285: $titleinfo =
4286: &Apache::loncommon::help_open_menu('','',3,'Authoring')
4287: .'<b>'.&mt('Construction Space').'</b>: '
4288: .'<form name="dirs" method="post" action="'.$formaction
4289: .'" target="_top"><tt><b>'
4290: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."<span class=\"LC_fontsize_big\">$lastitem</span></b></tt><br />"
4291: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4292: .'</form>'
4293: .&Apache::lonmenu::constspaceform();
4294: }
4295:
4296: my $titletable;
4297: if (!$notitle) {
4298: $titletable =
4299: '<table id="LC_title_bar">'.
4300: "<tr><td> $titleinfo $dc_info</td>".$roleinfo.
4301: '</tr></table>';
4302: }
4303: if ($notopbar) {
4304: $bodytag .= $titletable;
4305: } else {
4306: if ($env{'request.state'} eq 'construct') {
4307: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg,
4308: $titletable);
4309: } else {
4310: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg).
4311: $titletable;
4312: }
4313: }
4314: return $bodytag;
4315: }
4316:
4317: #
4318: # Top frame rendering, Remote is up
4319: #
4320:
4321: my $imgsrc = $img;
4322: if ($img =~ /^\/adm/) {
4323: $imgsrc = &lonhttpdurl($img);
4324: }
4325: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
4326:
4327: # Explicit link to get inline menu
4328: my $menu= ($no_inline_link?''
4329: :'<br /><a href="/adm/remote?action=collapse">'.&mt('Switch to Inline Menu Mode').'</a>');
4330: #
4331: if ($notitle) {
4332: return $bodytag;
4333: }
4334: return(<<ENDBODY);
4335: $bodytag
4336: <table id="LC_title_bar" class="LC_with_remote">
4337: <tr><td class="LC_title_bar_role_logo">$upperleft</td>
4338: <td class="LC_title_bar_domain_logo">$messages </td>
4339: </tr>
4340: <tr><td>$titleinfo $dc_info $menu</td>
4341: $roleinfo
4342: </tr>
4343: </table>
4344: ENDBODY
4345: }
4346:
4347: sub make_attr_string {
4348: my ($register,$attr_ref) = @_;
4349:
4350: if ($attr_ref && !ref($attr_ref)) {
4351: die("addentries Must be a hash ref ".
4352: join(':',caller(1))." ".
4353: join(':',caller(0))." ");
4354: }
4355:
4356: if ($register) {
4357: my ($on_load,$on_unload);
4358: foreach my $key (keys(%{$attr_ref})) {
4359: if (lc($key) eq 'onload') {
4360: $on_load.=$attr_ref->{$key}.';';
4361: delete($attr_ref->{$key});
4362:
4363: } elsif (lc($key) eq 'onunload') {
4364: $on_unload.=$attr_ref->{$key}.';';
4365: delete($attr_ref->{$key});
4366: }
4367: }
4368: $attr_ref->{'onload'} =
4369: &Apache::lonmenu::loadevents(). $on_load;
4370: $attr_ref->{'onunload'}=
4371: &Apache::lonmenu::unloadevents().$on_unload;
4372: }
4373:
4374: # Accessibility font enhance
4375: if ($env{'browser.fontenhance'} eq 'on') {
4376: my $style;
4377: foreach my $key (keys(%{$attr_ref})) {
4378: if (lc($key) eq 'style') {
4379: $style.=$attr_ref->{$key}.';';
4380: delete($attr_ref->{$key});
4381: }
4382: }
4383: $attr_ref->{'style'}=$style.'; font-size: x-large;';
4384: }
4385:
4386: if ($env{'browser.blackwhite'} eq 'on') {
4387: delete($attr_ref->{'font'});
4388: delete($attr_ref->{'link'});
4389: delete($attr_ref->{'alink'});
4390: delete($attr_ref->{'vlink'});
4391: delete($attr_ref->{'bgcolor'});
4392: delete($attr_ref->{'background'});
4393: }
4394:
4395: my $attr_string;
4396: foreach my $attr (keys(%$attr_ref)) {
4397: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
4398: }
4399: return $attr_string;
4400: }
4401:
4402:
4403: ###############################################
4404: ###############################################
4405:
4406: =pod
4407:
4408: =item * &endbodytag()
4409:
4410: Returns a uniform footer for LON-CAPA web pages.
4411:
4412: Inputs: 1 - optional reference to an args hash
4413: If in the hash, key for noredirectlink has a value which evaluates to true,
4414: a 'Continue' link is not displayed if the page contains an
4415: internal redirect in the <head></head> section,
4416: i.e., $env{'internal.head.redirect'} exists
4417:
4418: =cut
4419:
4420: sub endbodytag {
4421: my ($args) = @_;
4422: my $endbodytag='</body>';
4423: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
4424: if ( exists( $env{'internal.head.redirect'} ) ) {
4425: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
4426: $endbodytag=
4427: "<br /><a href=\"$env{'internal.head.redirect'}\">".
4428: &mt('Continue').'</a>'.
4429: $endbodytag;
4430: }
4431: }
4432: return $endbodytag;
4433: }
4434:
4435: =pod
4436:
4437: =item * &standard_css()
4438:
4439: Returns a style sheet
4440:
4441: Inputs: (all optional)
4442: domain -> force to color decorate a page for a specific
4443: domain
4444: function -> force usage of a specific rolish color scheme
4445: bgcolor -> override the default page bgcolor
4446:
4447: =cut
4448:
4449: sub standard_css {
4450: my ($function,$domain,$bgcolor) = @_;
4451: $function = &get_users_function() if (!$function);
4452: my $img = &designparm($function.'.img', $domain);
4453: my $tabbg = &designparm($function.'.tabbg', $domain);
4454: my $font = &designparm($function.'.font', $domain);
4455: my $sidebg = &designparm($function.'.sidebg',$domain);
4456: my $pgbg_or_bgcolor =
4457: $bgcolor ||
4458: &designparm($function.'.pgbg', $domain);
4459: my $pgbg = &designparm($function.'.pgbg', $domain);
4460: my $alink = &designparm($function.'.alink', $domain);
4461: my $vlink = &designparm($function.'.vlink', $domain);
4462: my $link = &designparm($function.'.link', $domain);
4463:
4464: my $loginbg = &designparm('login.sidebg',$domain);
4465: my $bgcol = &designparm('login.bgcol',$domain);
4466: my $textcol = &designparm('login.textcol',$domain);
4467:
4468: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
4469: my $mono = 'monospace';
4470: my $data_table_head = $tabbg;
4471: my $data_table_light = '#EEEEEE';
4472: my $data_table_dark = '#DDDDDD';
4473: my $data_table_darker = '#CCCCCC';
4474: my $data_table_highlight = '#FFFF00';
4475: my $mail_new = '#FFBB77';
4476: my $mail_new_hover = '#DD9955';
4477: my $mail_read = '#BBBB77';
4478: my $mail_read_hover = '#999944';
4479: my $mail_replied = '#AAAA88';
4480: my $mail_replied_hover = '#888855';
4481: my $mail_other = '#99BBBB';
4482: my $mail_other_hover = '#669999';
4483: my $table_header = '#DDDDDD';
4484: my $feedback_link_bg = '#BBBBBB';
4485: my $lg_border_color = '#C8C8C8';
4486:
4487: my $border = ($env{'browser.type'} eq 'explorer' ||
4488: $env{'browser.type'} eq 'safari' ) ? '0px 2px 0px 2px'
4489: : '0px 3px 0px 4px';
4490:
4491:
4492: return <<END;
4493: body{
4494: font-family: $sans;
4495: line-height:130%;
4496: font-size:0.83em;
4497: color:$font;
4498: }
4499: a:link, a:visited { font-size:100%; }
4500:
4501: a:focus { color: red; background: yellow }
4502: table.thinborder,
4503: table.thinborder tr th {
4504: border-style: solid;
4505: border-width: 1px;
4506: border-color: $lg_border_color;
4507: background: $tabbg;
4508: }
4509: table.thinborder tr td {
4510: border-style: solid;
4511: border-width: 1px;
4512: border-color: $lg_border_color;
4513: }
4514:
4515: form, .inline { display: inline; }
4516:
4517: .LC_center { text-align: center; }
4518: .LC_left { text-align:left; }
4519: .LC_right {text-align:right;}
4520: .LC_middle {vertical-align:middle;}
4521: .LC_top {vertical-align:top;}
4522: .LC_bottom {vertical-align:bottom;}
4523:
4524: /* just for tests */
4525: .LC_300Box { width:300px; }
4526: .LC_400Box {width:400px; }
4527: .LC_500Box {width:500px; }
4528: .LC_600Box {width:600px; }
4529: .LC_800Box {width:800px;}
4530: /* end */
4531:
4532: .LC_filename {font-family: $mono; white-space:pre;}
4533: .LC_error {
4534: color: red;
4535: font-size: larger;
4536: }
4537: .LC_warning,
4538: .LC_diff_removed {
4539: color: red;
4540: }
4541:
4542: .LC_info,
4543: .LC_success,
4544: .LC_diff_added {
4545: color: green;
4546: }
4547: .LC_unknown {
4548: color: yellow;
4549: }
4550:
4551: .LC_icon {
4552: border: 0px;
4553: }
4554: .LC_indexer_icon {
4555: border: 0px;
4556: height: 22px;
4557: }
4558: .LC_docs_spacer {
4559: width: 25px;
4560: height: 1px;
4561: border: 0px;
4562: }
4563:
4564: .LC_internal_info {
4565: color: #999999;
4566: }
4567:
4568: table.LC_pastsubmission {
4569: border: 1px solid black;
4570: margin: 2px;
4571: }
4572:
4573: table#LC_top_nav, table#LC_menubuttons,table#LC_nav_location {
4574: width: 100%;
4575: background: $pgbg;
4576: border: 2px;
4577: border-collapse: separate;
4578: padding: 0px;
4579: }
4580:
4581: table#LC_title_bar, table.LC_breadcrumbs,
4582: table#LC_title_bar.LC_with_remote {
4583: width: 100%;
4584: border-color: $pgbg;
4585: border-style: solid;
4586: border-width: $border;
4587:
4588: background: $pgbg;
4589: font-family: $sans;
4590: border-collapse: collapse;
4591: padding: 0px;
4592: }
4593: table.LC_docs_path {
4594: width: 100%;
4595: border: 0;
4596: background: $pgbg;
4597: font-family: $sans;
4598: border-collapse: collapse;
4599: padding: 0px;
4600: }
4601:
4602: table#LC_title_bar td {
4603: background: $tabbg;
4604: }
4605: table#LC_title_bar td.LC_title_bar_who {
4606: background: $tabbg;
4607: color: $font;
4608: font: small $sans;
4609: text-align: right;
4610: }
4611: span.LC_metadata {
4612: font-family: $sans;
4613: }
4614: table#LC_title_bar td.LC_title_bar_domain_logo {
4615: background: $sidebg;
4616: text-align: right;
4617: padding: 0px;
4618: }
4619: table#LC_title_bar td.LC_title_bar_role_logo {
4620: background: $sidebg;
4621: padding: 0px;
4622: }
4623:
4624: table#LC_menubuttons img{
4625: border: 0px;
4626: }
4627: table#LC_top_nav td {
4628: background: $tabbg;
4629: border: 0px;
4630: font-size: small;
4631: vertical-align:top;
4632: padding:2px 5px 2px 5px;
4633: }
4634: table#LC_top_nav td a, div#LC_top_nav a {
4635: color: $font;
4636: font-family: $sans;
4637: }
4638: table#LC_top_nav td.LC_top_nav_logo {
4639: background: $tabbg;
4640: text-align: left;
4641: white-space: nowrap;
4642: width: 31px;
4643: }
4644: table#LC_top_nav td.LC_top_nav_logo img {
4645: border: 0px;
4646: vertical-align: bottom;
4647: }
4648: table#LC_top_nav td.LC_top_nav_exit,
4649: table#LC_top_nav td.LC_top_nav_help {
4650: width: 2.0em;
4651: }
4652: table#LC_top_nav td.LC_top_nav_login {
4653: width: 4.0em;
4654: text-align: center;
4655: }
4656: table.LC_breadcrumbs td, table.LC_docs_path td {
4657: background: $tabbg;
4658: color: $font;
4659: font-family: $sans;
4660: font-size: smaller;
4661: }
4662: table.LC_breadcrumbs td.LC_breadcrumbs_component,
4663: table.LC_docs_path td.LC_docs_path_component {
4664: background: $tabbg;
4665: color: $font;
4666: font-family: $sans;
4667: font-size: larger;
4668: text-align: right;
4669: }
4670: td.LC_table_cell_checkbox {
4671: text-align: center;
4672: }
4673: table#LC_mainmenu td.LC_mainmenu_column {
4674: vertical-align: top;
4675: }
4676:
4677: .LC_fontsize_small
4678: {
4679: font-size: 70%;
4680: }
4681:
4682: .LC_fontsize_medium
4683: {
4684: font-size: 85%;
4685: }
4686:
4687: .LC_fontsize_large
4688: {
4689: font-size: 120%;
4690: }
4691:
4692: .LC_fontcolor_red
4693: {
4694: color: #FF0000;
4695: }
4696:
4697: .LC_menubuttons_inline_text {
4698: color: $font;
4699: font-family: $sans;
4700: font-size: 90%;
4701: padding-left:3px;
4702: }
4703:
4704: .LC_menubuttons_link {
4705: text-decoration: none;
4706: }
4707: /*2008--9-5: new menu style sheet.Changed category*/
4708: .LC_menubuttons_category {
4709: color: $font;
4710: background: $pgbg;
4711: font-family: $sans;
4712: font-size: larger;
4713: font-weight: bold;
4714: }
4715:
4716: td.LC_menubuttons_text {
4717: color: $font;
4718: }
4719:
4720:
4721:
4722: .LC_current_location {
4723: font-family: $sans;
4724: background: $tabbg;
4725: }
4726: .LC_new_mail {
4727: font-family: $sans;
4728: background: $tabbg;
4729: font-weight: bold;
4730: }
4731:
4732:
4733: .LC_dropadd_labeltext {
4734: font-family: $sans;
4735: text-align: right;
4736: }
4737:
4738: .LC_preferences_labeltext {
4739: font-family: $sans;
4740: text-align: right;
4741: }
4742:
4743: .LC_roleslog_note {
4744: font-size: small;
4745: }
4746:
4747: .LC_mail_functions {
4748: font-weight: bold;
4749: }
4750:
4751: table.LC_aboutme_port {
4752: border: 0px;
4753: border-collapse: collapse;
4754: border-spacing: 0px;
4755: }
4756: table.LC_data_table, table.LC_mail_list {
4757: border: 1px solid #000000;
4758: border-collapse: separate;
4759: border-spacing: 1px;
4760: background: $pgbg;
4761: }
4762: .LC_data_table_dense {
4763: font-size: small;
4764: }
4765: table.LC_nested_outer {
4766: border: 1px solid #000000;
4767: border-collapse: collapse;
4768: border-spacing: 0px;
4769: width: 100%;
4770: }
4771: table.LC_nested {
4772: border: 0px;
4773: border-collapse: collapse;
4774: border-spacing: 0px;
4775: width: 100%;
4776: }
4777: table.LC_data_table tr th, table.LC_calendar tr th, table.LC_mail_list tr th,
4778: table.LC_prior_tries tr th {
4779: font-weight: bold;
4780: background-color: $data_table_head;
4781: font-size:90%;
4782: }
4783: table.LC_data_table tr.LC_info_row > td {
4784: background-color: #CCCCCC;
4785: font-weight: bold;
4786: text-align: left;
4787: }
4788: table.LC_data_table tr.LC_odd_row > td,
4789: table.LC_pick_box tr > td.LC_odd_row,
4790: table.LC_aboutme_port tr td {
4791: background-color: $data_table_light;
4792: padding: 2px;
4793: }
4794: table.LC_data_table tr.LC_even_row > td,
4795: table.LC_pick_box tr > td.LC_even_row,
4796: table.LC_aboutme_port tr.LC_even_row td {
4797: background-color: $data_table_dark;
4798: padding: 2px;
4799: }
4800: table.LC_data_table tr.LC_data_table_highlight td {
4801: background-color: $data_table_darker;
4802: }
4803: table.LC_data_table tr td.LC_leftcol_header {
4804: background-color: $data_table_head;
4805: font-weight: bold;
4806: }
4807: table.LC_data_table tr.LC_empty_row td,
4808: table.LC_nested tr.LC_empty_row td {
4809: background-color: #FFFFFF;
4810: font-weight: bold;
4811: font-style: italic;
4812: text-align: center;
4813: padding: 8px;
4814: }
4815: table.LC_nested tr.LC_empty_row td {
4816: padding: 4ex
4817: }
4818: table.LC_nested_outer tr th {
4819: font-weight: bold;
4820: background-color: $data_table_head;
4821: font-size: small;
4822: border-bottom: 1px solid #000000;
4823: }
4824: table.LC_nested_outer tr td.LC_subheader {
4825: background-color: $data_table_head;
4826: font-weight: bold;
4827: font-size: small;
4828: border-bottom: 1px solid #000000;
4829: text-align: right;
4830: }
4831: table.LC_nested tr.LC_info_row td {
4832: background-color: #CCCCCC;
4833: font-weight: bold;
4834: font-size: small;
4835: text-align: center;
4836: }
4837: table.LC_nested tr.LC_info_row td.LC_left_item,
4838: table.LC_nested_outer tr th.LC_left_item {
4839: text-align: left;
4840: }
4841: table.LC_nested td {
4842: background-color: #FFFFFF;
4843: font-size: small;
4844: }
4845: table.LC_nested_outer tr th.LC_right_item,
4846: table.LC_nested tr.LC_info_row td.LC_right_item,
4847: table.LC_nested tr.LC_odd_row td.LC_right_item,
4848: table.LC_nested tr td.LC_right_item {
4849: text-align: right;
4850: }
4851:
4852: table.LC_nested tr.LC_odd_row td {
4853: background-color: #EEEEEE;
4854: }
4855:
4856: table.LC_createuser {
4857: }
4858:
4859: table.LC_createuser tr.LC_section_row td {
4860: font-size: small;
4861: }
4862:
4863: table.LC_createuser tr.LC_info_row td {
4864: background-color: #CCCCCC;
4865: font-weight: bold;
4866: text-align: center;
4867: }
4868:
4869: table.LC_calendar {
4870: border: 1px solid #000000;
4871: border-collapse: collapse;
4872: }
4873: table.LC_calendar_pickdate {
4874: font-size: xx-small;
4875: }
4876: table.LC_calendar tr td {
4877: border: 1px solid #000000;
4878: vertical-align: top;
4879: }
4880: table.LC_calendar tr td.LC_calendar_day_empty {
4881: background-color: $data_table_dark;
4882: }
4883: table.LC_calendar tr td.LC_calendar_day_current {
4884: background-color: $data_table_highlight;
4885: }
4886:
4887: table.LC_mail_list tr.LC_mail_new {
4888: background-color: $mail_new;
4889: }
4890: table.LC_mail_list tr.LC_mail_new:hover {
4891: background-color: $mail_new_hover;
4892: }
4893: table.LC_mail_list tr.LC_mail_read {
4894: background-color: $mail_read;
4895: }
4896: table.LC_mail_list tr.LC_mail_read:hover {
4897: background-color: $mail_read_hover;
4898: }
4899: table.LC_mail_list tr.LC_mail_replied {
4900: background-color: $mail_replied;
4901: }
4902: table.LC_mail_list tr.LC_mail_replied:hover {
4903: background-color: $mail_replied_hover;
4904: }
4905: table.LC_mail_list tr.LC_mail_other {
4906: background-color: $mail_other;
4907: }
4908: table.LC_mail_list tr.LC_mail_other:hover {
4909: background-color: $mail_other_hover;
4910: }
4911: table.LC_mail_list tr.LC_mail_even {
4912: }
4913: table.LC_mail_list tr.LC_mail_odd {
4914: }
4915:
4916: table.LC_data_table tr > td.LC_browser_file,
4917: table.LC_data_table tr > td.LC_browser_file_published {
4918: background: #CCFF88;
4919: }
4920: table.LC_data_table tr > td.LC_browser_file_locked,
4921: table.LC_data_table tr > td.LC_browser_file_unpublished {
4922: background: #FFAA99;
4923: }
4924: table.LC_data_table tr > td.LC_browser_file_obsolete {
4925: background: #AAAAAA;
4926: }
4927: table.LC_data_table tr > td.LC_browser_file_modified,
4928: table.LC_data_table tr > td.LC_browser_file_metamodified {
4929: background: #FFFF77;
4930: }
4931: table.LC_data_table tr.LC_browser_folder > td {
4932: background: #CCCCFF;
4933: }
4934:
4935: table.LC_data_table tr > td.LC_roles_is {
4936: /* background: #77FF77; */
4937: }
4938: table.LC_data_table tr > td.LC_roles_future {
4939: background: #FFFF77;
4940: }
4941: table.LC_data_table tr > td.LC_roles_will {
4942: background: #FFAA77;
4943: }
4944: table.LC_data_table tr > td.LC_roles_expired {
4945: background: #FF7777;
4946: }
4947: table.LC_data_table tr > td.LC_roles_will_not {
4948: background: #AAFF77;
4949: }
4950: table.LC_data_table tr > td.LC_roles_selected {
4951: background: #11CC55;
4952: }
4953:
4954: span.LC_current_location {
4955: font-size:larger;
4956: background: $pgbg;
4957: }
4958:
4959: span.LC_parm_menu_item {
4960: font-size: larger;
4961: font-family: $sans;
4962: }
4963: span.LC_parm_scope_all {
4964: color: red;
4965: }
4966: span.LC_parm_scope_folder {
4967: color: green;
4968: }
4969: span.LC_parm_scope_resource {
4970: color: orange;
4971: }
4972: span.LC_parm_part {
4973: color: blue;
4974: }
4975: span.LC_parm_folder, span.LC_parm_symb {
4976: font-size: x-small;
4977: font-family: $mono;
4978: color: #AAAAAA;
4979: }
4980:
4981: td.LC_parm_overview_level_menu, td.LC_parm_overview_map_menu,
4982: td.LC_parm_overview_parm_selectors, td.LC_parm_overview_parm_restrictions {
4983: border: 1px solid black;
4984: border-collapse: collapse;
4985: }
4986: table.LC_parm_overview_restrictions td {
4987: border-width: 1px 4px 1px 4px;
4988: border-style: solid;
4989: border-color: $pgbg;
4990: text-align: center;
4991: }
4992: table.LC_parm_overview_restrictions th {
4993: background: $tabbg;
4994: border-width: 1px 4px 1px 4px;
4995: border-style: solid;
4996: border-color: $pgbg;
4997: }
4998: table#LC_helpmenu {
4999: border: 0px;
5000: height: 55px;
5001: border-spacing: 0px;
5002: }
5003:
5004: table#LC_helpmenu fieldset legend {
5005: font-size: larger;
5006: font-weight: bold;
5007: }
5008: table#LC_helpmenu_links {
5009: width: 100%;
5010: border: 1px solid black;
5011: background: $pgbg;
5012: padding: 0px;
5013: border-spacing: 1px;
5014: }
5015: table#LC_helpmenu_links tr td {
5016: padding: 1px;
5017: background: $tabbg;
5018: text-align: center;
5019: font-weight: bold;
5020: }
5021:
5022: table#LC_helpmenu_links a:link, table#LC_helpmenu_links a:visited,
5023: table#LC_helpmenu_links a:active {
5024: text-decoration: none;
5025: color: $font;
5026: }
5027: table#LC_helpmenu_links a:hover {
5028: text-decoration: underline;
5029: color: $vlink;
5030: }
5031:
5032: .LC_chrt_popup_exists {
5033: border: 1px solid #339933;
5034: margin: -1px;
5035: }
5036: .LC_chrt_popup_up {
5037: border: 1px solid yellow;
5038: margin: -1px;
5039: }
5040: .LC_chrt_popup {
5041: border: 1px solid #8888FF;
5042: background: #CCCCFF;
5043: }
5044: table.LC_pick_box {
5045: border-collapse: separate;
5046: background: white;
5047: border: 1px solid black;
5048: border-spacing: 1px;
5049: }
5050: table.LC_pick_box td.LC_pick_box_title {
5051: background: $tabbg;
5052: font-weight: bold;
5053: text-align: right;
5054: vertical-align: top;
5055: width: 184px;
5056: padding: 8px;
5057: }
5058: table.LC_pick_box td.LC_selfenroll_pick_box_title {
5059: background: $tabbg;
5060: font-weight: bold;
5061: text-align: right;
5062: width: 350px;
5063: padding: 8px;
5064: }
5065:
5066: table.LC_pick_box td.LC_pick_box_value {
5067: text-align: left;
5068: padding: 8px;
5069: }
5070: table.LC_pick_box td.LC_pick_box_select {
5071: text-align: left;
5072: padding: 8px;
5073: }
5074: table.LC_pick_box td.LC_pick_box_separator {
5075: padding: 0px;
5076: height: 1px;
5077: background: black;
5078: }
5079: table.LC_pick_box td.LC_pick_box_submit {
5080: text-align: right;
5081: }
5082: table.LC_pick_box td.LC_evenrow_value {
5083: text-align: left;
5084: padding: 8px;
5085: background-color: $data_table_light;
5086: }
5087: table.LC_pick_box td.LC_oddrow_value {
5088: text-align: left;
5089: padding: 8px;
5090: background-color: $data_table_light;
5091: }
5092: table.LC_helpform_receipt {
5093: width: 620px;
5094: border-collapse: separate;
5095: background: white;
5096: border: 1px solid black;
5097: border-spacing: 1px;
5098: }
5099: table.LC_helpform_receipt td.LC_pick_box_title {
5100: background: $tabbg;
5101: font-weight: bold;
5102: text-align: right;
5103: width: 184px;
5104: padding: 8px;
5105: }
5106: table.LC_helpform_receipt td.LC_evenrow_value {
5107: text-align: left;
5108: padding: 8px;
5109: background-color: $data_table_light;
5110: }
5111: table.LC_helpform_receipt td.LC_oddrow_value {
5112: text-align: left;
5113: padding: 8px;
5114: background-color: $data_table_light;
5115: }
5116: table.LC_helpform_receipt td.LC_pick_box_separator {
5117: padding: 0px;
5118: height: 1px;
5119: background: black;
5120: }
5121: span.LC_helpform_receipt_cat {
5122: font-weight: bold;
5123: }
5124: table.LC_group_priv_box {
5125: background: white;
5126: border: 1px solid black;
5127: border-spacing: 1px;
5128: }
5129: table.LC_group_priv_box td.LC_pick_box_title {
5130: background: $tabbg;
5131: font-weight: bold;
5132: text-align: right;
5133: width: 184px;
5134: }
5135: table.LC_group_priv_box td.LC_groups_fixed {
5136: background: $data_table_light;
5137: text-align: center;
5138: }
5139: table.LC_group_priv_box td.LC_groups_optional {
5140: background: $data_table_dark;
5141: text-align: center;
5142: }
5143: table.LC_group_priv_box td.LC_groups_functionality {
5144: background: $data_table_darker;
5145: text-align: center;
5146: font-weight: bold;
5147: }
5148: table.LC_group_priv td {
5149: text-align: left;
5150: padding: 0px;
5151: }
5152:
5153: table.LC_notify_front_page {
5154: background: white;
5155: border: 1px solid black;
5156: padding: 8px;
5157: }
5158: table.LC_notify_front_page td {
5159: padding: 8px;
5160: }
5161: .LC_navbuttons {
5162: margin: 2ex 0ex 2ex 0ex;
5163: }
5164: .LC_topic_bar {
5165: font-family: $sans;
5166: font-weight: bold;
5167: width: 100%;
5168: background: $tabbg;
5169: vertical-align: middle;
5170: margin: 2ex 0ex 2ex 0ex;
5171: }
5172: .LC_topic_bar span {
5173: vertical-align: middle;
5174: }
5175: .LC_topic_bar img {
5176: vertical-align: bottom;
5177: }
5178: table.LC_course_group_status {
5179: margin: 20px;
5180: }
5181: table.LC_status_selector td {
5182: vertical-align: top;
5183: text-align: center;
5184: padding: 4px;
5185: }
5186: table.LC_descriptive_input td.LC_description {
5187: vertical-align: top;
5188: text-align: right;
5189: font-weight: bold;
5190: }
5191: div.LC_feedback_link {
5192: clear: both;
5193: background: white;
5194: width: 100%;
5195: }
5196: span.LC_feedback_link {
5197: background: $feedback_link_bg;
5198: font-size: larger;
5199: }
5200: span.LC_message_link {
5201: background: $feedback_link_bg;
5202: font-size: larger;
5203: position: absolute;
5204: right: 1em;
5205: }
5206:
5207: table.LC_prior_tries {
5208: border: 1px solid #000000;
5209: border-collapse: separate;
5210: border-spacing: 1px;
5211: }
5212:
5213: table.LC_prior_tries td {
5214: padding: 2px;
5215: }
5216:
5217: .LC_answer_correct {
5218: background: #AAFFAA;
5219: color: black;
5220: }
5221: .LC_answer_charged_try {
5222: background: #FFAAAA ! important;
5223: color: black;
5224: }
5225: .LC_answer_not_charged_try,
5226: .LC_answer_no_grade,
5227: .LC_answer_late {
5228: background: #FFFFAA;
5229: color: black;
5230: }
5231: .LC_answer_previous {
5232: background: #AAAAFF;
5233: color: black;
5234: }
5235: .LC_answer_no_message {
5236: background: #FFFFFF;
5237: color: black;
5238: }
5239: .LC_answer_unknown {
5240: background: orange;
5241: color: black;
5242: }
5243:
5244:
5245: span.LC_prior_numerical,
5246: span.LC_prior_string,
5247: span.LC_prior_custom,
5248: span.LC_prior_reaction,
5249: span.LC_prior_math {
5250: font-family: monospace;
5251: white-space: pre;
5252: }
5253:
5254: span.LC_prior_string {
5255: font-family: monospace;
5256: white-space: pre;
5257: }
5258:
5259: table.LC_prior_option {
5260: width: 100%;
5261: border-collapse: collapse;
5262: }
5263: table.LC_prior_rank, table.LC_prior_match {
5264: border-collapse: collapse;
5265: }
5266: table.LC_prior_option tr td,
5267: table.LC_prior_rank tr td,
5268: table.LC_prior_match tr td {
5269: border: 1px solid #000000;
5270: }
5271:
5272: span.LC_nobreak {
5273: white-space: nowrap;
5274: }
5275:
5276: span.LC_cusr_emph {
5277: font-style: italic;
5278: }
5279:
5280: span.LC_cusr_subheading {
5281: font-weight: normal;
5282: font-size: 85%;
5283: }
5284:
5285: table.LC_docs_documents {
5286: background: #BBBBBB;
5287: border-width: 0px;
5288: border-collapse: collapse;
5289: }
5290:
5291: table.LC_docs_documents td.LC_docs_document {
5292: border: 2px solid black;
5293: padding: 4px;
5294: }
5295:
5296: .LC_docs_entry_move {
5297: border: 0px;
5298: border-collapse: collapse;
5299: }
5300:
5301: .LC_docs_entry_move td {
5302: border: 2px solid #BBBBBB;
5303: background: #DDDDDD;
5304: }
5305:
5306: .LC_docs_editor td.LC_docs_entry_commands {
5307: background: #DDDDDD;
5308: font-size: x-small;
5309: }
5310: .LC_docs_copy {
5311: color: #000099;
5312: }
5313: .LC_docs_cut {
5314: color: #550044;
5315: }
5316: .LC_docs_rename {
5317: color: #009900;
5318: }
5319: .LC_docs_remove {
5320: color: #990000;
5321: }
5322:
5323: .LC_docs_reinit_warn,
5324: .LC_docs_ext_edit {
5325: font-size: x-small;
5326: }
5327:
5328: .LC_docs_editor td.LC_docs_entry_title,
5329: .LC_docs_editor td.LC_docs_entry_icon {
5330: background: #FFFFBB;
5331: }
5332: .LC_docs_editor td.LC_docs_entry_parameter {
5333: background: #BBBBFF;
5334: font-size: x-small;
5335: white-space: nowrap;
5336: }
5337:
5338: table.LC_docs_adddocs td,
5339: table.LC_docs_adddocs th {
5340: border: 1px solid #BBBBBB;
5341: padding: 4px;
5342: background: #DDDDDD;
5343: }
5344:
5345: table.LC_sty_begin {
5346: background: #BBFFBB;
5347: }
5348: table.LC_sty_end {
5349: background: #FFBBBB;
5350: }
5351:
5352: table.LC_double_column {
5353: border-width: 0px;
5354: border-collapse: collapse;
5355: width: 100%;
5356: padding: 2px;
5357: }
5358:
5359: table.LC_double_column tr td.LC_left_col {
5360: top: 2px;
5361: left: 2px;
5362: width: 47%;
5363: vertical-align: top;
5364: }
5365:
5366: table.LC_double_column tr td.LC_right_col {
5367: top: 2px;
5368: right: 2px;
5369: width: 47%;
5370: vertical-align: top;
5371: }
5372:
5373: span.LC_role_level {
5374: font-weight: bold;
5375: }
5376:
5377: div.LC_left_float {
5378: float: left;
5379: padding-right: 5%;
5380: padding-bottom: 4px;
5381: }
5382:
5383: div.LC_clear_float_header {
5384: padding-bottom: 2px;
5385: }
5386:
5387: div.LC_clear_float_footer {
5388: padding-top: 10px;
5389: clear: both;
5390: }
5391:
5392:
5393: div.LC_grade_show_user {
5394: margin-top: 20px;
5395: border: 1px solid black;
5396: }
5397: div.LC_grade_user_name {
5398: background: #DDDDEE;
5399: border-bottom: 1px solid black;
5400: font-weight: bold;
5401: font-size: large;
5402: }
5403: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
5404: background: #DDEEDD;
5405: }
5406:
5407: div.LC_grade_show_problem,
5408: div.LC_grade_submissions,
5409: div.LC_grade_message_center,
5410: div.LC_grade_info_links,
5411: div.LC_grade_assign {
5412: margin: 5px;
5413: width: 99%;
5414: background: #FFFFFF;
5415: }
5416: div.LC_grade_show_problem_header,
5417: div.LC_grade_submissions_header,
5418: div.LC_grade_message_center_header,
5419: div.LC_grade_assign_header {
5420: font-weight: bold;
5421: font-size: large;
5422: }
5423: div.LC_grade_show_problem_problem,
5424: div.LC_grade_submissions_body,
5425: div.LC_grade_message_center_body,
5426: div.LC_grade_assign_body {
5427: border: 1px solid black;
5428: width: 99%;
5429: background: #FFFFFF;
5430: }
5431: span.LC_grade_check_note {
5432: font-weight: normal;
5433: font-size: medium;
5434: display: inline;
5435: position: absolute;
5436: right: 1em;
5437: }
5438:
5439: table.LC_scantron_action {
5440: width: 100%;
5441: }
5442: table.LC_scantron_action tr th {
5443: font-weight:bold;
5444: font-style:normal;
5445: }
5446: .LC_edit_problem_header,
5447: div.LC_edit_problem_footer {
5448: font-weight: normal;
5449: font-size: medium;
5450: margin: 2px;
5451: }
5452: div.LC_edit_problem_header,
5453: div.LC_edit_problem_header div,
5454: div.LC_edit_problem_footer,
5455: div.LC_edit_problem_footer div,
5456: div.LC_edit_problem_editxml_header,
5457: div.LC_edit_problem_editxml_header div {
5458: margin-top: 5px;
5459: }
5460: div.LC_edit_problem_header_edit_row {
5461: background: $tabbg;
5462: padding: 3px;
5463: margin-bottom: 5px;
5464: }
5465: div.LC_edit_problem_header_title {
5466: font-weight: bold;
5467: font-size: larger;
5468: background: $tabbg;
5469: padding: 3px;
5470: }
5471: table.LC_edit_problem_header_title {
5472: font-size: larger;
5473: font-weight: bold;
5474: width: 100%;
5475: border-color: $pgbg;
5476: border-style: solid;
5477: border-width: $border;
5478:
5479: background: $tabbg;
5480: border-collapse: collapse;
5481: padding: 0px
5482: }
5483:
5484: div.LC_edit_problem_discards {
5485: float: left;
5486: padding-bottom: 5px;
5487: }
5488: div.LC_edit_problem_saves {
5489: float: right;
5490: padding-bottom: 5px;
5491: }
5492: hr.LC_edit_problem_divide {
5493: clear: both;
5494: color: $tabbg;
5495: background-color: $tabbg;
5496: height: 3px;
5497: border: 0px;
5498: }
5499: img.stift{
5500: border-width:0;
5501: vertical-align:middle;
5502: }
5503:
5504: table#LC_mainmenu{
5505: margin-top:10px;
5506: width:80%;
5507:
5508: }
5509:
5510: table#LC_mainmenu td.LC_mainmenu_col_fieldset{
5511: vertical-align: top;
5512: width: 45%;
5513: }
5514: .LC_mainmenu_fieldset_category {
5515: color: $font;
5516: background: $pgbg;
5517: font-family: $sans;
5518: font-size: small;
5519: font-weight: bold;
5520: }
5521:
5522: div.LC_createcourse {
5523: margin: 10px 10px 10px 10px;
5524: }
5525:
5526: /* ---- Remove when done ----
5527: # The following styles is part of the redesign of LON-CAPA and are
5528: # subject to change during this project.
5529: # Don't rely on their current functionality as they might be
5530: # changed or removed.
5531: # --------------------------*/
5532:
5533: a:hover,
5534: ol.LC_smallMenu a:hover,
5535: ol#LC_MenuBreadcrumbs a:hover,
5536: ol#LC_PathBreadcrumbs a:hover,
5537: ul#LC_TabMainMenuContent a:hover,
5538: .LC_FormSectionClearButton input:hover
5539: ul.LC_TabContent li:hover a{
5540: color:#BF2317;
5541: text-decoration:none;
5542: }
5543:
5544: h1 {
5545: padding:5px 10px 5px 20px;
5546: line-height:130%;
5547: }
5548:
5549: h2,h3,h4,h5,h6
5550: {
5551: margin:5px 0px 5px 0px;
5552: padding:0px;
5553: line-height:130%;
5554: }
5555: .LC_hcell{
5556: padding:3px 15px 3px 15px;
5557: margin:0px;
5558: background-color:$tabbg;
5559: border-bottom:solid 1px $lg_border_color;
5560: }
5561: .LC_noBorder {
5562: border:0px;
5563: }
5564:
5565: .LC_bgLightGrey{
5566: background:URL(/adm/lonIcons/lightGreyBG.png) repeat-x left bottom;
5567: }
5568:
5569:
5570: /* Main Header with discription of Person, Course, etc. */
5571: .LC_HeadRight {
5572: text-align: right;
5573: float: right;
5574: margin: 0px;
5575: padding: 0px;
5576: right:0;
5577: position:absolute;
5578: overflow:hidden;
5579: }
5580:
5581: .LC_Right {
5582: float: right;
5583: margin: 0px;
5584: padding: 0px;
5585: }
5586:
5587: p, .LC_ContentBox {
5588: padding: 10px;
5589:
5590: }
5591: .LC_FormSectionClearButton input {
5592: background-color:transparent;
5593: border:0px;
5594: cursor:pointer;
5595: text-decoration:underline;
5596: }
5597: .LC_helptextbgcolor
5598: {
5599: background-color:#5555FF;
5600: }
5601: .LC_helptextfontcolor
5602: {
5603: color:#FFFFFF;
5604: }
5605:
5606: dl,ul,div,fieldset {
5607: margin: 10px 10px 10px 0px;
5608: overflow:hidden;
5609: }
5610: ol.LC_smallMenu, ol#LC_PathBreadcrumbs {
5611: margin: 0px;
5612: }
5613:
5614: ol.LC_smallMenu li {
5615: display: inline;
5616: padding: 5px 5px 0px 10px;
5617: vertical-align: top;
5618: }
5619:
5620: ol.LC_smallMenu li img {
5621: vertical-align: bottom;
5622: }
5623:
5624: ol.LC_smallMenu a {
5625: font-size: 90%;
5626: color: RGB(80, 80, 80);
5627: text-decoration: none;
5628: }
5629: ol#LC_TabMainMenuContent, ul.LC_TabContent ,
5630: ul.LC_TabContentBigger {
5631: display:block;
5632: list-style:none;
5633: margin: 0px;
5634: padding: 0px;
5635: }
5636:
5637: ol#LC_TabMainMenuContent li, ul.LC_TabContent li,
5638: ul.LC_TabContentBigger li{
5639: display: inline;
5640: border-right: solid 1px $lg_border_color;
5641: float:left;
5642: line-height:140%;
5643: white-space:nowrap;
5644: }
5645: ol#LC_TabMainMenuContent li{
5646: vertical-align: bottom;
5647: border-bottom: solid 1px RGB(175, 175, 175);
5648: padding: 5px 10px 5px 10px;
5649: margin-right:5px;
5650: margin-bottom:3px;
5651: font-weight: bold;
5652: background: url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
5653: }
5654:
5655: ol#LC_TabMainMenuContent li a{
5656: color: RGB(47, 47, 47);
5657: text-decoration: none;
5658: }
5659: ul.LC_TabContent {
5660: min-height:1.6em;
5661: }
5662: ul.LC_TabContent li{
5663: vertical-align:middle;
5664: padding:0px 10px 0px 10px;
5665: background-color:$tabbg;
5666: border-bottom:solid 1px $lg_border_color;
5667: }
5668: ul.LC_TabContent li a, ul.LC_TabContent li{
5669: color:rgb(47,47,47);
5670: text-decoration:none;
5671: font-size:95%;
5672: font-weight:bold;
5673: padding-right: 16px;
5674: }
5675: ul.LC_TabContent li:hover, ul.LC_TabContent li.active{
5676: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
5677: border-bottom:solid 1px #FFFFFF;
5678: padding-right: 16px;
5679: }
5680: ul.LC_TabContentBigger li{
5681: vertical-align:bottom;
5682: border-top:solid 1px $lg_border_color;
5683: border-left:solid 1px $lg_border_color;
5684: padding:5px 10px 5px 10px;
5685: margin-left:2px;
5686: background:url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
5687: }
5688: ul.LC_TabContentBigger li:hover, ul.LC_TabContentBigger li.active{
5689: background:url(/adm/lonIcons/lightGreyBG.png) repeat-x right bottom;
5690: }
5691: ul.LC_TabContentBigger li, ul.LC_TabContentBigger li a{
5692: font-size:110%;
5693: font-weight:bold;
5694: }
5695: #LC_CourseDocuments, #LC_SupplementalCourseDocuments
5696: {
5697: margin:0px;
5698: }
5699:
5700: .LC_hideThis
5701: {
5702: display:none;
5703: visibility:hidden;
5704: }
5705:
5706: ol#LC_MenuBreadcrumbs, ol#LC_PathBreadcrumbs {
5707: border-top: solid 1px RGB(255, 255, 255);
5708: height: 20px;
5709: line-height: 20px;
5710: vertical-align: bottom;
5711: margin: 0px 0px 30px 0px;
5712: padding-left: 10px;
5713: list-style-position: inside;
5714: background: url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
5715: }
5716:
5717: ol#LC_MenuBreadcrumbs li, ol#LC_PathBreadcrumbs li {
5718: /*
5719: background: url(/adm/lonIcons/arrow_white.png) no-repeat left center;
5720: */
5721: display: inline;
5722: padding: 0px 0px 0px 10px;
5723: vertical-align: bottom;
5724: overflow:hidden;
5725: }
5726:
5727: ol#LC_MenuBreadcrumbs li a {
5728: text-decoration: none;
5729: font-size:90%;
5730: }
5731: ol#LC_PathBreadcrumbs li a{
5732: text-decoration:none;
5733: font-size:100%;
5734: font-weight:bold;
5735: }
5736: .LC_ContentBoxSpecial
5737: {
5738: border: solid 1px $lg_border_color;
5739: }
5740: .LC_ContentBoxSpecialContactInfo
5741: {
5742: border: solid 1px $lg_border_color;
5743: max-width:25%;
5744: min-width:25%;
5745: }
5746: .LC_AboutMe_Image
5747: {
5748: float:left;
5749: margin-right:10px;
5750: }
5751: .LC_Clear_AboutMe_Image
5752: {
5753: clear:left;
5754: }
5755: dl.LC_ListStyleClean dt {
5756: padding-right: 5px;
5757: display: table-header-group;
5758: }
5759:
5760: dl.LC_ListStyleClean dd {
5761: display: table-row;
5762: }
5763:
5764: .LC_ListStyleClean,
5765: .LC_ListStyleSimple,
5766: .LC_ListStyleNormal,
5767: .LC_ListStyleNormal_Border,
5768: .LC_ListStyleSpecial
5769: {
5770: /*display:block; */
5771: list-style-position: inside;
5772: list-style-type: none;
5773: overflow: hidden;
5774: padding: 0px;
5775: }
5776:
5777: .LC_ListStyleSimple li,
5778: .LC_ListStyleSimple dd,
5779: .LC_ListStyleNormal li,
5780: .LC_ListStyleNormal dd,
5781: .LC_ListStyleSpecial li,
5782: .LC_ListStyleSpecial dd
5783: {
5784: margin: 0px;
5785: padding: 5px 5px 5px 10px;
5786: clear: both;
5787: }
5788:
5789: .LC_ListStyleClean li,
5790: .LC_ListStyleClean dd {
5791: padding-top: 0px;
5792: padding-bottom: 0px;
5793: }
5794:
5795: .LC_ListStyleSimple dd,
5796: .LC_ListStyleSimple li{
5797: border-bottom: solid 1px $lg_border_color;
5798: }
5799:
5800: .LC_ListStyleSpecial li,
5801: .LC_ListStyleSpecial dd {
5802: list-style-type: none;
5803: background-color: RGB(220, 220, 220);
5804: margin-bottom: 4px;
5805: }
5806:
5807: table.LC_SimpleTable {
5808: margin:5px;
5809: border:solid 1px $lg_border_color;
5810: }
5811:
5812: table.LC_SimpleTable tr {
5813: padding:0px;
5814: border:solid 1px $lg_border_color;
5815: }
5816: table.LC_SimpleTable thead{
5817: background:rgb(220,220,220);
5818: }
5819:
5820: div.LC_columnSection {
5821: display: block;
5822: clear: both;
5823: overflow: hidden;
5824: margin:0px;
5825: }
5826:
5827: div.LC_columnSection>* {
5828: float: left;
5829: margin: 10px 20px 10px 0px;
5830: overflow:hidden;
5831: }
5832:
5833: .ContentBoxSpecialTemplate
5834: {
5835: border: solid 1px $lg_border_color;
5836: }
5837: .ContentBoxTemplate {
5838: padding:10px;
5839: }
5840:
5841: div.LC_columnSection > .ContentBoxTemplate,
5842: div.LC_columnSection > .ContentBoxSpecialTemplate
5843: {
5844: width: 600px;
5845: }
5846:
5847: .clear{
5848: clear: both;
5849: line-height: 0px;
5850: font-size: 0px;
5851: height: 0px;
5852: }
5853:
5854: .LC_loginpage_container {
5855: text-align:left;
5856: margin : 0 auto;
5857: width:65%;
5858: padding: 10px;
5859: height: auto;
5860: background-color:#FFFFFF;
5861: border:1px solid #CCCCCC;
5862: }
5863:
5864:
5865: .LC_loginpage_loginContainer {
5866: float:left;
5867: width: 182px;
5868: border:1px solid #CCCCCC;
5869: background-color:$loginbg;
5870: }
5871:
5872: .LC_loginpage_loginContainer h2{
5873: margin-top:0;
5874: display:block;
5875: background:$bgcol;
5876: color:$textcol;
5877: padding-left:5px;
5878: }
5879: .LC_loginpage_loginInfo {
5880: margin-left:20px;
5881: float:left;
5882: width:30%;
5883: border:1px solid #CCCCCC;
5884: padding:10px;
5885: }
5886:
5887: .LC_loginpage_loginDomain {
5888: margin-right:20px;
5889: width:20%;
5890: float:left;
5891: padding:10px;
5892: }
5893:
5894: .LC_loginpage_space {
5895: clear: both;
5896: margin-bottom: 20px;
5897: border-bottom: 1px solid #CCCCCC;
5898: }
5899:
5900: table em{
5901: font-weight: bold;
5902: font-style: normal;
5903: }
5904:
5905: table#LC_tableOfContent{
5906: border-collapse: collapse;
5907: border-spacing: 0;
5908: padding: 3px;
5909: border: 0;
5910: background-color: #FFFFFF;
5911: font-size: 90%;
5912: }
5913: table#LC_tableOfContent a {
5914: text-decoration: none;
5915: }
5916:
5917: table#LC_tableOfContent tr.LC_trOdd{
5918: background-color: #EEEEEE;
5919: }
5920:
5921: table#LC_tableOfContent img{
5922: border: none;
5923: height: 1.3em;
5924: vertical-align: text-bottom;
5925: margin-right: 0.3em;
5926: }
5927:
5928: a#LC_content_toolbar_firsthomework{
5929: background-image:url(/res/adm/pages/open-first-problem.gif);
5930: }
5931:
5932: a#LC_content_toolbar_launchnav{
5933: background-image:url(/res/adm/pages/start-navigation.gif);
5934: }
5935:
5936: a#LC_content_toolbar_closenav{
5937: background-image:url(/res/adm/pages/close-navigation.gif);
5938: }
5939:
5940: a#LC_content_toolbar_everything{
5941: background-image:url(/res/adm/pages/show-all.gif);
5942: }
5943:
5944: a#LC_content_toolbar_uncompleted{
5945: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
5946: }
5947:
5948: #LC_content_toolbar_clearbubbles{
5949: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
5950: }
5951:
5952: a#LC_content_toolbar_changefolder{
5953: background : url(/res/adm/pages/close-all-folders.gif) top center ;
5954: }
5955:
5956: a#LC_content_toolbar_changefolder_toggled{
5957: background-image:url(/res/adm/pages/open-all-folders.gif);
5958: }
5959:
5960: ul#LC_toolbar li a:hover{
5961: background-position: bottom center;
5962: }
5963:
5964: ul#LC_toolbar{
5965: padding:0;
5966: margin: 2px;
5967: list-style:none;
5968: position:relative;
5969: background-color:white;
5970: }
5971:
5972: ul#LC_toolbar li{
5973: border:1px solid white;
5974: padding:0;
5975: margin: 0;
5976: display:inline-block;
5977: vertical-align:middle;
5978: }
5979:
5980: a.LC_toolbarItem{
5981: display:inline-block;
5982: padding:0;
5983: margin:0;
5984: height: 32px;
5985: width: 32px;
5986: color:white;
5987: border:0 none;
5988: background-repeat:no-repeat;
5989: background-color:transparent;
5990: }
5991:
5992:
5993: END
5994: }
5995:
5996: =pod
5997:
5998: =item * &headtag()
5999:
6000: Returns a uniform footer for LON-CAPA web pages.
6001:
6002: Inputs: $title - optional title for the head
6003: $head_extra - optional extra HTML to put inside the <head>
6004: $args - optional arguments
6005: force_register - if is true call registerurl so the remote is
6006: informed
6007: redirect -> array ref of
6008: 1- seconds before redirect occurs
6009: 2- url to redirect to
6010: 3- whether the side effect should occur
6011: (side effect of setting
6012: $env{'internal.head.redirect'} to the url
6013: redirected too)
6014: domain -> force to color decorate a page for a specific
6015: domain
6016: function -> force usage of a specific rolish color scheme
6017: bgcolor -> override the default page bgcolor
6018: no_auto_mt_title
6019: -> prevent &mt()ing the title arg
6020:
6021: =cut
6022:
6023: sub headtag {
6024: my ($title,$head_extra,$args) = @_;
6025:
6026: my $function = $args->{'function'} || &get_users_function();
6027: my $domain = $args->{'domain'} || &determinedomain();
6028: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
6029: my $url = join(':',$env{'user.name'},$env{'user.domain'},
6030: $Apache::lonnet::perlvar{'lonVersion'},
6031: #time(),
6032: $env{'environment.color.timestamp'},
6033: $function,$domain,$bgcolor);
6034:
6035: $url = '/adm/css/'.&escape($url).'.css';
6036:
6037: my $result =
6038: '<head>'.
6039: &font_settings();
6040:
6041: if (!$args->{'frameset'}) {
6042: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
6043: }
6044: if ($args->{'force_register'}) {
6045: $result .= &Apache::lonmenu::registerurl(1);
6046: }
6047: if (!$args->{'no_nav_bar'}
6048: && !$args->{'only_body'}
6049: && !$args->{'frameset'}) {
6050: $result .= &help_menu_js();
6051: }
6052:
6053: if (ref($args->{'redirect'})) {
6054: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
6055: $url = &Apache::lonenc::check_encrypt($url);
6056: if (!$inhibit_continue) {
6057: $env{'internal.head.redirect'} = $url;
6058: }
6059: $result.=<<ADDMETA
6060: <meta http-equiv="pragma" content="no-cache" />
6061: <meta http-equiv="Refresh" content="$time; url=$url" />
6062: ADDMETA
6063: }
6064: if (!defined($title)) {
6065: $title = 'The LearningOnline Network with CAPA';
6066: }
6067: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
6068: $result .= '<title> LON-CAPA '.$title.'</title>'
6069: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
6070: .$head_extra;
6071: return $result;
6072: }
6073:
6074: =pod
6075:
6076: =item * &font_settings()
6077:
6078: Returns neccessary <meta> to set the proper encoding
6079:
6080: Inputs: none
6081:
6082: =cut
6083:
6084: sub font_settings {
6085: my $headerstring='';
6086: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
6087: $headerstring.=
6088: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
6089: }
6090: return $headerstring;
6091: }
6092:
6093: =pod
6094:
6095: =item * &xml_begin()
6096:
6097: Returns the needed doctype and <html>
6098:
6099: Inputs: none
6100:
6101: =cut
6102:
6103: sub xml_begin {
6104: my $output='';
6105:
6106: if ($env{'internal.start_page'}==1) {
6107: &Apache::lonhtmlcommon::init_htmlareafields();
6108: }
6109:
6110: if ($env{'browser.mathml'}) {
6111: $output='<?xml version="1.0"?>'
6112: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
6113: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
6114:
6115: # .'<!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">] >'
6116: .'<!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">'
6117: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
6118: .'xmlns="http://www.w3.org/1999/xhtml">';
6119: } else {
6120: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>';
6121: }
6122: return $output;
6123: }
6124:
6125: =pod
6126:
6127: =item * &endheadtag()
6128:
6129: Returns a uniform </head> for LON-CAPA web pages.
6130:
6131: Inputs: none
6132:
6133: =cut
6134:
6135: sub endheadtag {
6136: return '</head>';
6137: }
6138:
6139: =pod
6140:
6141: =item * &head()
6142:
6143: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
6144:
6145: Inputs:
6146:
6147: =over 4
6148:
6149: $title - optional title for the page
6150:
6151: $head_extra - optional extra HTML to put inside the <head>
6152:
6153: =back
6154:
6155: =cut
6156:
6157: sub head {
6158: my ($title,$head_extra,$args) = @_;
6159: return &headtag($title,$head_extra,$args).&endheadtag();
6160: }
6161:
6162: =pod
6163:
6164: =item * &start_page()
6165:
6166: Returns a complete <html> .. <body> section for LON-CAPA web pages.
6167:
6168: Inputs:
6169:
6170: =over 4
6171:
6172: $title - optional title for the page
6173:
6174: $head_extra - optional extra HTML to incude inside the <head>
6175:
6176: $args - additional optional args supported are:
6177:
6178: =over 8
6179:
6180: only_body -> is true will set &bodytag() onlybodytag
6181: arg on
6182: no_nav_bar -> is true will set &bodytag() notopbar arg on
6183: add_entries -> additional attributes to add to the <body>
6184: domain -> force to color decorate a page for a
6185: specific domain
6186: function -> force usage of a specific rolish color
6187: scheme
6188: redirect -> see &headtag()
6189: bgcolor -> override the default page bg color
6190: js_ready -> return a string ready for being used in
6191: a javascript writeln
6192: html_encode -> return a string ready for being used in
6193: a html attribute
6194: force_register -> if is true will turn on the &bodytag()
6195: $forcereg arg
6196: body_title -> alternate text to use instead of $title
6197: in the title box that appears, this text
6198: is not auto translated like the $title is
6199: frameset -> if true will start with a <frameset>
6200: rather than <body>
6201: no_title -> if true the title bar won't be shown
6202: skip_phases -> hash ref of
6203: head -> skip the <html><head> generation
6204: body -> skip all <body> generation
6205: no_inline_link -> if true and in remote mode, don't show the
6206: 'Switch To Inline Menu' link
6207: no_auto_mt_title -> prevent &mt()ing the title arg
6208: inherit_jsmath -> when creating popup window in a page,
6209: should it have jsmath forced on by the
6210: current page
6211:
6212: =back
6213:
6214: =back
6215:
6216: =cut
6217:
6218: sub start_page {
6219: my ($title,$head_extra,$args) = @_;
6220: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
6221: my %head_args;
6222: foreach my $arg ('redirect','force_register','domain','function',
6223: 'bgcolor','frameset','no_nav_bar','only_body',
6224: 'no_auto_mt_title') {
6225: if (defined($args->{$arg})) {
6226: $head_args{$arg} = $args->{$arg};
6227: }
6228: }
6229:
6230: $env{'internal.start_page'}++;
6231: my $result;
6232: if (! exists($args->{'skip_phases'}{'head'}) ) {
6233: $result.=
6234: &xml_begin().
6235: &headtag($title,$head_extra,\%head_args).&endheadtag();
6236: }
6237:
6238: if (! exists($args->{'skip_phases'}{'body'}) ) {
6239: if ($args->{'frameset'}) {
6240: my $attr_string = &make_attr_string($args->{'force_register'},
6241: $args->{'add_entries'});
6242: $result .= "\n<frameset $attr_string>\n";
6243: } else {
6244: $result .=
6245: &bodytag($title,
6246: $args->{'function'}, $args->{'add_entries'},
6247: $args->{'only_body'}, $args->{'domain'},
6248: $args->{'force_register'}, $args->{'body_title'},
6249: $args->{'no_nav_bar'}, $args->{'bgcolor'},
6250: $args->{'no_title'}, $args->{'no_inline_link'},
6251: $args);
6252: }
6253: }
6254:
6255: if ($args->{'js_ready'}) {
6256: $result = &js_ready($result);
6257: }
6258: if ($args->{'html_encode'}) {
6259: $result = &html_encode($result);
6260: }
6261:
6262: #Breadcrumbs
6263: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
6264: &Apache::lonhtmlcommon::clear_breadcrumbs();
6265: #if any br links exists, add them to the breadcrumbs
6266: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
6267: foreach my $crumb (@{$args->{'bread_crumbs'}}){
6268: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
6269: }
6270: }
6271:
6272: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
6273: if(exists($args->{'bread_crumbs_component'})){
6274: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
6275: }else{
6276: $result .= &Apache::lonhtmlcommon::breadcrumbs();
6277: }
6278: }
6279: return $result;
6280: }
6281:
6282:
6283: =pod
6284:
6285: =item * &head()
6286:
6287: Returns a complete </body></html> section for LON-CAPA web pages.
6288:
6289: Inputs: $args - additional optional args supported are:
6290: js_ready -> return a string ready for being used in
6291: a javascript writeln
6292: html_encode -> return a string ready for being used in
6293: a html attribute
6294: frameset -> if true will start with a <frameset>
6295: rather than <body>
6296: dicsussion -> if true will get discussion from
6297: lonxml::xmlend
6298: (you can pass the target and parser arguments
6299: through optional 'target' and 'parser' args
6300: to this routine)
6301:
6302: =cut
6303:
6304: sub end_page {
6305: my ($args) = @_;
6306: $env{'internal.end_page'}++;
6307: my $result;
6308: if ($args->{'discussion'}) {
6309: my ($target,$parser);
6310: if (ref($args->{'discussion'})) {
6311: ($target,$parser) =($args->{'discussion'}{'target'},
6312: $args->{'discussion'}{'parser'});
6313: }
6314: $result .= &Apache::lonxml::xmlend($target,$parser);
6315: }
6316:
6317: if ($args->{'frameset'}) {
6318: $result .= '</frameset>';
6319: } else {
6320: $result .= &endbodytag($args);
6321: }
6322: $result .= "\n</html>";
6323:
6324: if ($args->{'js_ready'}) {
6325: $result = &js_ready($result);
6326: }
6327:
6328: if ($args->{'html_encode'}) {
6329: $result = &html_encode($result);
6330: }
6331:
6332: return $result;
6333: }
6334:
6335: sub html_encode {
6336: my ($result) = @_;
6337:
6338: $result = &HTML::Entities::encode($result,'<>&"');
6339:
6340: return $result;
6341: }
6342: sub js_ready {
6343: my ($result) = @_;
6344:
6345: $result =~ s/[\n\r]/ /xmsg;
6346: $result =~ s/\\/\\\\/xmsg;
6347: $result =~ s/'/\\'/xmsg;
6348: $result =~ s{</}{<\\/}xmsg;
6349:
6350: return $result;
6351: }
6352:
6353: sub validate_page {
6354: if ( exists($env{'internal.start_page'})
6355: && $env{'internal.start_page'} > 1) {
6356: &Apache::lonnet::logthis('start_page called multiple times '.
6357: $env{'internal.start_page'}.' '.
6358: $ENV{'request.filename'});
6359: }
6360: if ( exists($env{'internal.end_page'})
6361: && $env{'internal.end_page'} > 1) {
6362: &Apache::lonnet::logthis('end_page called multiple times '.
6363: $env{'internal.end_page'}.' '.
6364: $env{'request.filename'});
6365: }
6366: if ( exists($env{'internal.start_page'})
6367: && ! exists($env{'internal.end_page'})) {
6368: &Apache::lonnet::logthis('start_page called without end_page '.
6369: $env{'request.filename'});
6370: }
6371: if ( ! exists($env{'internal.start_page'})
6372: && exists($env{'internal.end_page'})) {
6373: &Apache::lonnet::logthis('end_page called without start_page'.
6374: $env{'request.filename'});
6375: }
6376: }
6377:
6378: sub simple_error_page {
6379: my ($r,$title,$msg) = @_;
6380: my $page =
6381: &Apache::loncommon::start_page($title).
6382: &mt($msg).
6383: &Apache::loncommon::end_page();
6384: if (ref($r)) {
6385: $r->print($page);
6386: return;
6387: }
6388: return $page;
6389: }
6390:
6391: {
6392: my @row_count;
6393: sub start_data_table {
6394: my ($add_class) = @_;
6395: my $css_class = (join(' ','LC_data_table',$add_class));
6396: unshift(@row_count,0);
6397: return '<table class="'.$css_class.'">'."\n";
6398: }
6399:
6400: sub end_data_table {
6401: shift(@row_count);
6402: return '</table>'."\n";;
6403: }
6404:
6405: sub start_data_table_row {
6406: my ($add_class) = @_;
6407: $row_count[0]++;
6408: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
6409: $css_class = (join(' ',$css_class,$add_class));
6410: return '<tr class="'.$css_class.'">'."\n";;
6411: }
6412:
6413: sub continue_data_table_row {
6414: my ($add_class) = @_;
6415: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
6416: $css_class = (join(' ',$css_class,$add_class));
6417: return '<tr class="'.$css_class.'">'."\n";;
6418: }
6419:
6420: sub end_data_table_row {
6421: return '</tr>'."\n";;
6422: }
6423:
6424: sub start_data_table_empty_row {
6425: # $row_count[0]++;
6426: return '<tr class="LC_empty_row" >'."\n";;
6427: }
6428:
6429: sub end_data_table_empty_row {
6430: return '</tr>'."\n";;
6431: }
6432:
6433: sub start_data_table_header_row {
6434: return '<tr class="LC_header_row">'."\n";;
6435: }
6436:
6437: sub end_data_table_header_row {
6438: return '</tr>'."\n";;
6439: }
6440: }
6441:
6442: =pod
6443:
6444: =item * &inhibit_menu_check($arg)
6445:
6446: Checks for a inhibitmenu state and generates output to preserve it
6447:
6448: Inputs: $arg - can be any of
6449: - undef - in which case the return value is a string
6450: to add into arguments list of a uri
6451: - 'input' - in which case the return value is a HTML
6452: <form> <input> field of type hidden to
6453: preserve the value
6454: - a url - in which case the return value is the url with
6455: the neccesary cgi args added to preserve the
6456: inhibitmenu state
6457: - a ref to a url - no return value, but the string is
6458: updated to include the neccessary cgi
6459: args to preserve the inhibitmenu state
6460:
6461: =cut
6462:
6463: sub inhibit_menu_check {
6464: my ($arg) = @_;
6465: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6466: if ($arg eq 'input') {
6467: if ($env{'form.inhibitmenu'}) {
6468: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
6469: } else {
6470: return
6471: }
6472: }
6473: if ($env{'form.inhibitmenu'}) {
6474: if (ref($arg)) {
6475: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6476: } elsif ($arg eq '') {
6477: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
6478: } else {
6479: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6480: }
6481: }
6482: if (!ref($arg)) {
6483: return $arg;
6484: }
6485: }
6486:
6487: ###############################################
6488:
6489: =pod
6490:
6491: =back
6492:
6493: =head1 User Information Routines
6494:
6495: =over 4
6496:
6497: =item * &get_users_function()
6498:
6499: Used by &bodytag to determine the current users primary role.
6500: Returns either 'student','coordinator','admin', or 'author'.
6501:
6502: =cut
6503:
6504: ###############################################
6505: sub get_users_function {
6506: my $function = 'student';
6507: if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
6508: $function='coordinator';
6509: }
6510: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
6511: $function='admin';
6512: }
6513: if (($env{'request.role'}=~/^(au|ca)/) ||
6514: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
6515: $function='author';
6516: }
6517: return $function;
6518: }
6519:
6520: ###############################################
6521:
6522: =pod
6523:
6524: =item * &check_user_status()
6525:
6526: Determines current status of supplied role for a
6527: specific user. Roles can be active, previous or future.
6528:
6529: Inputs:
6530: user's domain, user's username, course's domain,
6531: course's number, optional section ID.
6532:
6533: Outputs:
6534: role status: active, previous or future.
6535:
6536: =cut
6537:
6538: sub check_user_status {
6539: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
6540: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
6541: my @uroles = keys %userinfo;
6542: my $srchstr;
6543: my $active_chk = 'none';
6544: my $now = time;
6545: if (@uroles > 0) {
6546: if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
6547: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
6548: } else {
6549: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
6550: }
6551: if (grep/^\Q$srchstr\E$/,@uroles) {
6552: my $role_end = 0;
6553: my $role_start = 0;
6554: $active_chk = 'active';
6555: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
6556: $role_end = $1;
6557: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
6558: $role_start = $1;
6559: }
6560: }
6561: if ($role_start > 0) {
6562: if ($now < $role_start) {
6563: $active_chk = 'future';
6564: }
6565: }
6566: if ($role_end > 0) {
6567: if ($now > $role_end) {
6568: $active_chk = 'previous';
6569: }
6570: }
6571: }
6572: }
6573: return $active_chk;
6574: }
6575:
6576: ###############################################
6577:
6578: =pod
6579:
6580: =item * &get_sections()
6581:
6582: Determines all the sections for a course including
6583: sections with students and sections containing other roles.
6584: Incoming parameters:
6585:
6586: 1. domain
6587: 2. course number
6588: 3. reference to array containing roles for which sections should
6589: be gathered (optional).
6590: 4. reference to array containing status types for which sections
6591: should be gathered (optional).
6592:
6593: If the third argument is undefined, sections are gathered for any role.
6594: If the fourth argument is undefined, sections are gathered for any status.
6595: Permissible values are 'active' or 'future' or 'previous'.
6596:
6597: Returns section hash (keys are section IDs, values are
6598: number of users in each section), subject to the
6599: optional roles filter, optional status filter
6600:
6601: =cut
6602:
6603: ###############################################
6604: sub get_sections {
6605: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
6606: if (!defined($cdom) || !defined($cnum)) {
6607: my $cid = $env{'request.course.id'};
6608:
6609: return if (!defined($cid));
6610:
6611: $cdom = $env{'course.'.$cid.'.domain'};
6612: $cnum = $env{'course.'.$cid.'.num'};
6613: }
6614:
6615: my %sectioncount;
6616: my $now = time;
6617:
6618: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
6619: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
6620: my $sec_index = &Apache::loncoursedata::CL_SECTION();
6621: my $status_index = &Apache::loncoursedata::CL_STATUS();
6622: my $start_index = &Apache::loncoursedata::CL_START();
6623: my $end_index = &Apache::loncoursedata::CL_END();
6624: my $status;
6625: while (my ($student,$data) = each(%$classlist)) {
6626: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
6627: $data->[$status_index],
6628: $data->[$start_index],
6629: $data->[$end_index]);
6630: if ($stu_status eq 'Active') {
6631: $status = 'active';
6632: } elsif ($end < $now) {
6633: $status = 'previous';
6634: } elsif ($start > $now) {
6635: $status = 'future';
6636: }
6637: if ($section ne '-1' && $section !~ /^\s*$/) {
6638: if ((!defined($possible_status)) || (($status ne '') &&
6639: (grep/^\Q$status\E$/,@{$possible_status}))) {
6640: $sectioncount{$section}++;
6641: }
6642: }
6643: }
6644: }
6645: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6646: foreach my $user (sort(keys(%courseroles))) {
6647: if ($user !~ /^(\w{2})/) { next; }
6648: my ($role) = ($user =~ /^(\w{2})/);
6649: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
6650: my ($section,$status);
6651: if ($role eq 'cr' &&
6652: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
6653: $section=$1;
6654: }
6655: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
6656: if (!defined($section) || $section eq '-1') { next; }
6657: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
6658: if ($end == -1 && $start == -1) {
6659: next; #deleted role
6660: }
6661: if (!defined($possible_status)) {
6662: $sectioncount{$section}++;
6663: } else {
6664: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
6665: $status = 'active';
6666: } elsif ($end < $now) {
6667: $status = 'future';
6668: } elsif ($start > $now) {
6669: $status = 'previous';
6670: }
6671: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
6672: $sectioncount{$section}++;
6673: }
6674: }
6675: }
6676: return %sectioncount;
6677: }
6678:
6679: ###############################################
6680:
6681: =pod
6682:
6683: =item * &get_course_users()
6684:
6685: Retrieves usernames:domains for users in the specified course
6686: with specific role(s), and access status.
6687:
6688: Incoming parameters:
6689: 1. course domain
6690: 2. course number
6691: 3. access status: users must have - either active,
6692: previous, future, or all.
6693: 4. reference to array of permissible roles
6694: 5. reference to array of section restrictions (optional)
6695: 6. reference to results object (hash of hashes).
6696: 7. reference to optional userdata hash
6697: 8. reference to optional statushash
6698: 9. flag if privileged users (except those set to unhide in
6699: course settings) should be excluded
6700: Keys of top level results hash are roles.
6701: Keys of inner hashes are username:domain, with
6702: values set to access type.
6703: Optional userdata hash returns an array with arguments in the
6704: same order as loncoursedata::get_classlist() for student data.
6705:
6706: Optional statushash returns
6707:
6708: Entries for end, start, section and status are blank because
6709: of the possibility of multiple values for non-student roles.
6710:
6711: =cut
6712:
6713: ###############################################
6714:
6715: sub get_course_users {
6716: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
6717: my %idx = ();
6718: my %seclists;
6719:
6720: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
6721: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
6722: $idx{end} = &Apache::loncoursedata::CL_END();
6723: $idx{start} = &Apache::loncoursedata::CL_START();
6724: $idx{id} = &Apache::loncoursedata::CL_ID();
6725: $idx{section} = &Apache::loncoursedata::CL_SECTION();
6726: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
6727: $idx{status} = &Apache::loncoursedata::CL_STATUS();
6728:
6729: if (grep(/^st$/,@{$roles})) {
6730: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
6731: my $now = time;
6732: foreach my $student (keys(%{$classlist})) {
6733: my $match = 0;
6734: my $secmatch = 0;
6735: my $section = $$classlist{$student}[$idx{section}];
6736: my $status = $$classlist{$student}[$idx{status}];
6737: if ($section eq '') {
6738: $section = 'none';
6739: }
6740: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
6741: if (grep(/^all$/,@{$sections})) {
6742: $secmatch = 1;
6743: } elsif ($$classlist{$student}[$idx{section}] eq '') {
6744: if (grep(/^none$/,@{$sections})) {
6745: $secmatch = 1;
6746: }
6747: } else {
6748: if (grep(/^\Q$section\E$/,@{$sections})) {
6749: $secmatch = 1;
6750: }
6751: }
6752: if (!$secmatch) {
6753: next;
6754: }
6755: }
6756: if (defined($$types{'active'})) {
6757: if ($$classlist{$student}[$idx{status}] eq 'Active') {
6758: push(@{$$users{st}{$student}},'active');
6759: $match = 1;
6760: }
6761: }
6762: if (defined($$types{'previous'})) {
6763: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
6764: push(@{$$users{st}{$student}},'previous');
6765: $match = 1;
6766: }
6767: }
6768: if (defined($$types{'future'})) {
6769: if ($$classlist{$student}[$idx{status}] eq 'Future') {
6770: push(@{$$users{st}{$student}},'future');
6771: $match = 1;
6772: }
6773: }
6774: if ($match) {
6775: push(@{$seclists{$student}},$section);
6776: if (ref($userdata) eq 'HASH') {
6777: $$userdata{$student} = $$classlist{$student};
6778: }
6779: if (ref($statushash) eq 'HASH') {
6780: $statushash->{$student}{'st'}{$section} = $status;
6781: }
6782: }
6783: }
6784: }
6785: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
6786: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6787: my $now = time;
6788: my %displaystatus = ( previous => 'Expired',
6789: active => 'Active',
6790: future => 'Future',
6791: );
6792: my %nothide;
6793: if ($hidepriv) {
6794: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
6795: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
6796: if ($user !~ /:/) {
6797: $nothide{join(':',split(/[\@]/,$user))}=1;
6798: } else {
6799: $nothide{$user} = 1;
6800: }
6801: }
6802: }
6803: foreach my $person (sort(keys(%coursepersonnel))) {
6804: my $match = 0;
6805: my $secmatch = 0;
6806: my $status;
6807: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
6808: $user =~ s/:$//;
6809: my ($end,$start) = split(/:/,$coursepersonnel{$person});
6810: if ($end == -1 || $start == -1) {
6811: next;
6812: }
6813: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
6814: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
6815: my ($uname,$udom) = split(/:/,$user);
6816: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
6817: if (grep(/^all$/,@{$sections})) {
6818: $secmatch = 1;
6819: } elsif ($usec eq '') {
6820: if (grep(/^none$/,@{$sections})) {
6821: $secmatch = 1;
6822: }
6823: } else {
6824: if (grep(/^\Q$usec\E$/,@{$sections})) {
6825: $secmatch = 1;
6826: }
6827: }
6828: if (!$secmatch) {
6829: next;
6830: }
6831: }
6832: if ($usec eq '') {
6833: $usec = 'none';
6834: }
6835: if ($uname ne '' && $udom ne '') {
6836: if ($hidepriv) {
6837: if ((&Apache::lonnet::privileged($uname,$udom)) &&
6838: (!$nothide{$uname.':'.$udom})) {
6839: next;
6840: }
6841: }
6842: if ($end > 0 && $end < $now) {
6843: $status = 'previous';
6844: } elsif ($start > $now) {
6845: $status = 'future';
6846: } else {
6847: $status = 'active';
6848: }
6849: foreach my $type (keys(%{$types})) {
6850: if ($status eq $type) {
6851: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
6852: push(@{$$users{$role}{$user}},$type);
6853: }
6854: $match = 1;
6855: }
6856: }
6857: if (($match) && (ref($userdata) eq 'HASH')) {
6858: if (!exists($$userdata{$uname.':'.$udom})) {
6859: &get_user_info($udom,$uname,\%idx,$userdata);
6860: }
6861: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
6862: push(@{$seclists{$uname.':'.$udom}},$usec);
6863: }
6864: if (ref($statushash) eq 'HASH') {
6865: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
6866: }
6867: }
6868: }
6869: }
6870: }
6871: if (grep(/^ow$/,@{$roles})) {
6872: if ((defined($cdom)) && (defined($cnum))) {
6873: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
6874: if ( defined($csettings{'internal.courseowner'}) ) {
6875: my $owner = $csettings{'internal.courseowner'};
6876: next if ($owner eq '');
6877: my ($ownername,$ownerdom);
6878: if ($owner =~ /^([^:]+):([^:]+)$/) {
6879: $ownername = $1;
6880: $ownerdom = $2;
6881: } else {
6882: $ownername = $owner;
6883: $ownerdom = $cdom;
6884: $owner = $ownername.':'.$ownerdom;
6885: }
6886: @{$$users{'ow'}{$owner}} = 'any';
6887: if (defined($userdata) &&
6888: !exists($$userdata{$owner})) {
6889: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
6890: if (!grep(/^none$/,@{$seclists{$owner}})) {
6891: push(@{$seclists{$owner}},'none');
6892: }
6893: if (ref($statushash) eq 'HASH') {
6894: $statushash->{$owner}{'ow'}{'none'} = 'Any';
6895: }
6896: }
6897: }
6898: }
6899: }
6900: foreach my $user (keys(%seclists)) {
6901: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
6902: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
6903: }
6904: }
6905: return;
6906: }
6907:
6908: sub get_user_info {
6909: my ($udom,$uname,$idx,$userdata) = @_;
6910: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
6911: &plainname($uname,$udom,'lastname');
6912: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
6913: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
6914: my %idhash = &Apache::lonnet::idrget($udom,($uname));
6915: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
6916: return;
6917: }
6918:
6919: ###############################################
6920:
6921: =pod
6922:
6923: =item * &get_user_quota()
6924:
6925: Retrieves quota assigned for storage of portfolio files for a user
6926:
6927: Incoming parameters:
6928: 1. user's username
6929: 2. user's domain
6930:
6931: Returns:
6932: 1. Disk quota (in Mb) assigned to student.
6933: 2. (Optional) Type of setting: custom or default
6934: (individually assigned or default for user's
6935: institutional status).
6936: 3. (Optional) - User's institutional status (e.g., faculty, staff
6937: or student - types as defined in localenroll::inst_usertypes
6938: for user's domain, which determines default quota for user.
6939: 4. (Optional) - Default quota which would apply to the user.
6940:
6941: If a value has been stored in the user's environment,
6942: it will return that, otherwise it returns the maximal default
6943: defined for the user's instituional status(es) in the domain.
6944:
6945: =cut
6946:
6947: ###############################################
6948:
6949:
6950: sub get_user_quota {
6951: my ($uname,$udom) = @_;
6952: my ($quota,$quotatype,$settingstatus,$defquota);
6953: if (!defined($udom)) {
6954: $udom = $env{'user.domain'};
6955: }
6956: if (!defined($uname)) {
6957: $uname = $env{'user.name'};
6958: }
6959: if (($udom eq '' || $uname eq '') ||
6960: ($udom eq 'public') && ($uname eq 'public')) {
6961: $quota = 0;
6962: $quotatype = 'default';
6963: $defquota = 0;
6964: } else {
6965: my $inststatus;
6966: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
6967: $quota = $env{'environment.portfolioquota'};
6968: $inststatus = $env{'environment.inststatus'};
6969: } else {
6970: my %userenv =
6971: &Apache::lonnet::get('environment',['portfolioquota',
6972: 'inststatus'],$udom,$uname);
6973: my ($tmp) = keys(%userenv);
6974: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
6975: $quota = $userenv{'portfolioquota'};
6976: $inststatus = $userenv{'inststatus'};
6977: } else {
6978: undef(%userenv);
6979: }
6980: }
6981: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
6982: if ($quota eq '') {
6983: $quota = $defquota;
6984: $quotatype = 'default';
6985: } else {
6986: $quotatype = 'custom';
6987: }
6988: }
6989: if (wantarray) {
6990: return ($quota,$quotatype,$settingstatus,$defquota);
6991: } else {
6992: return $quota;
6993: }
6994: }
6995:
6996: ###############################################
6997:
6998: =pod
6999:
7000: =item * &default_quota()
7001:
7002: Retrieves default quota assigned for storage of user portfolio files,
7003: given an (optional) user's institutional status.
7004:
7005: Incoming parameters:
7006: 1. domain
7007: 2. (Optional) institutional status(es). This is a : separated list of
7008: status types (e.g., faculty, staff, student etc.)
7009: which apply to the user for whom the default is being retrieved.
7010: If the institutional status string in undefined, the domain
7011: default quota will be returned.
7012:
7013: Returns:
7014: 1. Default disk quota (in Mb) for user portfolios in the domain.
7015: 2. (Optional) institutional type which determined the value of the
7016: default quota.
7017:
7018: If a value has been stored in the domain's configuration db,
7019: it will return that, otherwise it returns 20 (for backwards
7020: compatibility with domains which have not set up a configuration
7021: db file; the original statically defined portfolio quota was 20 Mb).
7022:
7023: If the user's status includes multiple types (e.g., staff and student),
7024: the largest default quota which applies to the user determines the
7025: default quota returned.
7026:
7027: =cut
7028:
7029: ###############################################
7030:
7031:
7032: sub default_quota {
7033: my ($udom,$inststatus) = @_;
7034: my ($defquota,$settingstatus);
7035: my %quotahash = &Apache::lonnet::get_dom('configuration',
7036: ['quotas'],$udom);
7037: if (ref($quotahash{'quotas'}) eq 'HASH') {
7038: if ($inststatus ne '') {
7039: my @statuses = split(/:/,$inststatus);
7040: foreach my $item (@statuses) {
7041: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7042: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
7043: if ($defquota eq '') {
7044: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7045: $settingstatus = $item;
7046: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
7047: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7048: $settingstatus = $item;
7049: }
7050: }
7051: } else {
7052: if ($quotahash{'quotas'}{$item} ne '') {
7053: if ($defquota eq '') {
7054: $defquota = $quotahash{'quotas'}{$item};
7055: $settingstatus = $item;
7056: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
7057: $defquota = $quotahash{'quotas'}{$item};
7058: $settingstatus = $item;
7059: }
7060: }
7061: }
7062: }
7063: }
7064: if ($defquota eq '') {
7065: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7066: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
7067: } else {
7068: $defquota = $quotahash{'quotas'}{'default'};
7069: }
7070: $settingstatus = 'default';
7071: }
7072: } else {
7073: $settingstatus = 'default';
7074: $defquota = 20;
7075: }
7076: if (wantarray) {
7077: return ($defquota,$settingstatus);
7078: } else {
7079: return $defquota;
7080: }
7081: }
7082:
7083: sub get_secgrprole_info {
7084: my ($cdom,$cnum,$needroles,$type) = @_;
7085: my %sections_count = &get_sections($cdom,$cnum);
7086: my @sections = (sort {$a <=> $b} keys(%sections_count));
7087: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
7088: my @groups = sort(keys(%curr_groups));
7089: my $allroles = [];
7090: my $rolehash;
7091: my $accesshash = {
7092: active => 'Currently has access',
7093: future => 'Will have future access',
7094: previous => 'Previously had access',
7095: };
7096: if ($needroles) {
7097: $rolehash = {'all' => 'all'};
7098: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7099: if (&Apache::lonnet::error(%user_roles)) {
7100: undef(%user_roles);
7101: }
7102: foreach my $item (keys(%user_roles)) {
7103: my ($role)=split(/\:/,$item,2);
7104: if ($role eq 'cr') { next; }
7105: if ($role =~ /^cr/) {
7106: $$rolehash{$role} = (split('/',$role))[3];
7107: } else {
7108: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
7109: }
7110: }
7111: foreach my $key (sort(keys(%{$rolehash}))) {
7112: push(@{$allroles},$key);
7113: }
7114: push (@{$allroles},'st');
7115: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
7116: }
7117: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
7118: }
7119:
7120: sub user_picker {
7121: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
7122: my $currdom = $dom;
7123: my %curr_selected = (
7124: srchin => 'dom',
7125: srchby => 'lastname',
7126: );
7127: my $srchterm;
7128: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
7129: if ($srch->{'srchby'} ne '') {
7130: $curr_selected{'srchby'} = $srch->{'srchby'};
7131: }
7132: if ($srch->{'srchin'} ne '') {
7133: $curr_selected{'srchin'} = $srch->{'srchin'};
7134: }
7135: if ($srch->{'srchtype'} ne '') {
7136: $curr_selected{'srchtype'} = $srch->{'srchtype'};
7137: }
7138: if ($srch->{'srchdomain'} ne '') {
7139: $currdom = $srch->{'srchdomain'};
7140: }
7141: $srchterm = $srch->{'srchterm'};
7142: }
7143: my %lt=&Apache::lonlocal::texthash(
7144: 'usr' => 'Search criteria',
7145: 'doma' => 'Domain/institution to search',
7146: 'uname' => 'username',
7147: 'lastname' => 'last name',
7148: 'lastfirst' => 'last name, first name',
7149: 'crs' => 'in this course',
7150: 'dom' => 'in selected LON-CAPA domain',
7151: 'alc' => 'all LON-CAPA',
7152: 'instd' => 'in institutional directory for selected domain',
7153: 'exact' => 'is',
7154: 'contains' => 'contains',
7155: 'begins' => 'begins with',
7156: 'youm' => "You must include some text to search for.",
7157: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
7158: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
7159: 'yomc' => "You must choose a domain when using an institutional directory search.",
7160: 'ymcd' => "You must choose a domain when using a domain search.",
7161: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
7162: 'whse' => "When searching by last,first you must include at least one character in the first name.",
7163: 'thfo' => "The following need to be corrected before the search can be run:",
7164: );
7165: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
7166: my $srchinsel = ' <select name="srchin">';
7167:
7168: my @srchins = ('crs','dom','alc','instd');
7169:
7170: foreach my $option (@srchins) {
7171: # FIXME 'alc' option unavailable until
7172: # loncreateuser::print_user_query_page()
7173: # has been completed.
7174: next if ($option eq 'alc');
7175: next if ($option eq 'crs' && !$env{'request.course.id'});
7176: if ($curr_selected{'srchin'} eq $option) {
7177: $srchinsel .= '
7178: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7179: } else {
7180: $srchinsel .= '
7181: <option value="'.$option.'">'.$lt{$option}.'</option>';
7182: }
7183: }
7184: $srchinsel .= "\n </select>\n";
7185:
7186: my $srchbysel = ' <select name="srchby">';
7187: foreach my $option ('lastname','lastfirst','uname') {
7188: if ($curr_selected{'srchby'} eq $option) {
7189: $srchbysel .= '
7190: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7191: } else {
7192: $srchbysel .= '
7193: <option value="'.$option.'">'.$lt{$option}.'</option>';
7194: }
7195: }
7196: $srchbysel .= "\n </select>\n";
7197:
7198: my $srchtypesel = ' <select name="srchtype">';
7199: foreach my $option ('begins','contains','exact') {
7200: if ($curr_selected{'srchtype'} eq $option) {
7201: $srchtypesel .= '
7202: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7203: } else {
7204: $srchtypesel .= '
7205: <option value="'.$option.'">'.$lt{$option}.'</option>';
7206: }
7207: }
7208: $srchtypesel .= "\n </select>\n";
7209:
7210: my ($newuserscript,$new_user_create);
7211:
7212: if ($forcenewuser) {
7213: if (ref($srch) eq 'HASH') {
7214: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
7215: if ($cancreate) {
7216: $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>';
7217: } else {
7218: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
7219: my %usertypetext = (
7220: official => 'institutional',
7221: unofficial => 'non-institutional',
7222: );
7223: $new_user_create = '<br /><span class="LC_warning">'.&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.").' '.&mt('Contact the <a[_1]>helpdesk</a> for assistance.',$helplink).'</span><br /><br />';
7224: }
7225: }
7226: }
7227:
7228: $newuserscript = <<"ENDSCRIPT";
7229:
7230: function setSearch(createnew,callingForm) {
7231: if (createnew == 1) {
7232: for (var i=0; i<callingForm.srchby.length; i++) {
7233: if (callingForm.srchby.options[i].value == 'uname') {
7234: callingForm.srchby.selectedIndex = i;
7235: }
7236: }
7237: for (var i=0; i<callingForm.srchin.length; i++) {
7238: if ( callingForm.srchin.options[i].value == 'dom') {
7239: callingForm.srchin.selectedIndex = i;
7240: }
7241: }
7242: for (var i=0; i<callingForm.srchtype.length; i++) {
7243: if (callingForm.srchtype.options[i].value == 'exact') {
7244: callingForm.srchtype.selectedIndex = i;
7245: }
7246: }
7247: for (var i=0; i<callingForm.srchdomain.length; i++) {
7248: if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
7249: callingForm.srchdomain.selectedIndex = i;
7250: }
7251: }
7252: }
7253: }
7254: ENDSCRIPT
7255:
7256: }
7257:
7258: my $output = <<"END_BLOCK";
7259: <script type="text/javascript">
7260: function validateEntry(callingForm) {
7261:
7262: var checkok = 1;
7263: var srchin;
7264: for (var i=0; i<callingForm.srchin.length; i++) {
7265: if ( callingForm.srchin[i].checked ) {
7266: srchin = callingForm.srchin[i].value;
7267: }
7268: }
7269:
7270: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
7271: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
7272: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
7273: var srchterm = callingForm.srchterm.value;
7274: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
7275: var msg = "";
7276:
7277: if (srchterm == "") {
7278: checkok = 0;
7279: msg += "$lt{'youm'}\\n";
7280: }
7281:
7282: if (srchtype== 'begins') {
7283: if (srchterm.length < 2) {
7284: checkok = 0;
7285: msg += "$lt{'thte'}\\n";
7286: }
7287: }
7288:
7289: if (srchtype== 'contains') {
7290: if (srchterm.length < 3) {
7291: checkok = 0;
7292: msg += "$lt{'thet'}\\n";
7293: }
7294: }
7295: if (srchin == 'instd') {
7296: if (srchdomain == '') {
7297: checkok = 0;
7298: msg += "$lt{'yomc'}\\n";
7299: }
7300: }
7301: if (srchin == 'dom') {
7302: if (srchdomain == '') {
7303: checkok = 0;
7304: msg += "$lt{'ymcd'}\\n";
7305: }
7306: }
7307: if (srchby == 'lastfirst') {
7308: if (srchterm.indexOf(",") == -1) {
7309: checkok = 0;
7310: msg += "$lt{'whus'}\\n";
7311: }
7312: if (srchterm.indexOf(",") == srchterm.length -1) {
7313: checkok = 0;
7314: msg += "$lt{'whse'}\\n";
7315: }
7316: }
7317: if (checkok == 0) {
7318: alert("$lt{'thfo'}\\n"+msg);
7319: return;
7320: }
7321: if (checkok == 1) {
7322: callingForm.submit();
7323: }
7324: }
7325:
7326: $newuserscript
7327:
7328: </script>
7329:
7330: $new_user_create
7331:
7332: <table>
7333: <tr>
7334: <td>$lt{'doma'}:</td>
7335: <td>$domform</td>
7336: </td>
7337: </tr>
7338: <tr>
7339: <td>$lt{'usr'}:</td>
7340: <td>$srchbysel
7341: $srchtypesel
7342: <input type="text" size="15" name="srchterm" value="$srchterm" />
7343: $srchinsel
7344: </td>
7345: </tr>
7346: </table>
7347: <br />
7348: END_BLOCK
7349:
7350: return $output;
7351: }
7352:
7353: sub user_rule_check {
7354: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
7355: my $response;
7356: if (ref($usershash) eq 'HASH') {
7357: foreach my $user (keys(%{$usershash})) {
7358: my ($uname,$udom) = split(/:/,$user);
7359: next if ($udom eq '' || $uname eq '');
7360: my ($id,$newuser);
7361: if (ref($usershash->{$user}) eq 'HASH') {
7362: $newuser = $usershash->{$user}->{'newuser'};
7363: $id = $usershash->{$user}->{'id'};
7364: }
7365: my $inst_response;
7366: if (ref($checks) eq 'HASH') {
7367: if (defined($checks->{'username'})) {
7368: ($inst_response,%{$inst_results->{$user}}) =
7369: &Apache::lonnet::get_instuser($udom,$uname);
7370: } elsif (defined($checks->{'id'})) {
7371: ($inst_response,%{$inst_results->{$user}}) =
7372: &Apache::lonnet::get_instuser($udom,undef,$id);
7373: }
7374: } else {
7375: ($inst_response,%{$inst_results->{$user}}) =
7376: &Apache::lonnet::get_instuser($udom,$uname);
7377: return;
7378: }
7379: if (!$got_rules->{$udom}) {
7380: my %domconfig = &Apache::lonnet::get_dom('configuration',
7381: ['usercreation'],$udom);
7382: if (ref($domconfig{'usercreation'}) eq 'HASH') {
7383: foreach my $item ('username','id') {
7384: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
7385: $$curr_rules{$udom}{$item} =
7386: $domconfig{'usercreation'}{$item.'_rule'};
7387: }
7388: }
7389: }
7390: $got_rules->{$udom} = 1;
7391: }
7392: foreach my $item (keys(%{$checks})) {
7393: if (ref($$curr_rules{$udom}) eq 'HASH') {
7394: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
7395: if (@{$$curr_rules{$udom}{$item}} > 0) {
7396: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
7397: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
7398: if ($rule_check{$rule}) {
7399: $$rulematch{$user}{$item} = $rule;
7400: if ($inst_response eq 'ok') {
7401: if (ref($inst_results) eq 'HASH') {
7402: if (ref($inst_results->{$user}) eq 'HASH') {
7403: if (keys(%{$inst_results->{$user}}) == 0) {
7404: $$alerts{$item}{$udom}{$uname} = 1;
7405: }
7406: }
7407: }
7408: }
7409: last;
7410: }
7411: }
7412: }
7413: }
7414: }
7415: }
7416: }
7417: }
7418: return;
7419: }
7420:
7421: sub user_rule_formats {
7422: my ($domain,$domdesc,$curr_rules,$check) = @_;
7423: my %text = (
7424: 'username' => 'Usernames',
7425: 'id' => 'IDs',
7426: );
7427: my $output;
7428: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
7429: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
7430: if (@{$ruleorder} > 0) {
7431: $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>';
7432: foreach my $rule (@{$ruleorder}) {
7433: if (ref($curr_rules) eq 'ARRAY') {
7434: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
7435: if (ref($rules->{$rule}) eq 'HASH') {
7436: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
7437: $rules->{$rule}{'desc'}.'</li>';
7438: }
7439: }
7440: }
7441: }
7442: $output .= '</ul>';
7443: }
7444: }
7445: return $output;
7446: }
7447:
7448: sub instrule_disallow_msg {
7449: my ($checkitem,$domdesc,$count,$mode) = @_;
7450: my $response;
7451: my %text = (
7452: item => 'username',
7453: items => 'usernames',
7454: match => 'matches',
7455: do => 'does',
7456: action => 'a username',
7457: one => 'one',
7458: );
7459: if ($count > 1) {
7460: $text{'item'} = 'usernames';
7461: $text{'match'} ='match';
7462: $text{'do'} = 'do';
7463: $text{'action'} = 'usernames',
7464: $text{'one'} = 'ones';
7465: }
7466: if ($checkitem eq 'id') {
7467: $text{'items'} = 'IDs';
7468: $text{'item'} = 'ID';
7469: $text{'action'} = 'an ID';
7470: if ($count > 1) {
7471: $text{'item'} = 'IDs';
7472: $text{'action'} = 'IDs';
7473: }
7474: }
7475: $response = &mt("The $text{'item'} you chose $text{'match'} the format of $text{'items'} defined for [_1], but the $text{'item'} $text{'do'} not exist in the institutional directory.",'<span class="LC_cusr_emph">'.$domdesc.'</span>').'<br />';
7476: if ($mode eq 'upload') {
7477: if ($checkitem eq 'username') {
7478: $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'}.");
7479: } elsif ($checkitem eq 'id') {
7480: $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 Student/Employee ID field.");
7481: }
7482: } elsif ($mode eq 'selfcreate') {
7483: if ($checkitem eq 'id') {
7484: $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.");
7485: }
7486: } else {
7487: if ($checkitem eq 'username') {
7488: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
7489: } elsif ($checkitem eq 'id') {
7490: $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.");
7491: }
7492: }
7493: return $response;
7494: }
7495:
7496: sub personal_data_fieldtitles {
7497: my %fieldtitles = &Apache::lonlocal::texthash (
7498: id => 'Student/Employee ID',
7499: permanentemail => 'E-mail address',
7500: lastname => 'Last Name',
7501: firstname => 'First Name',
7502: middlename => 'Middle Name',
7503: generation => 'Generation',
7504: gen => 'Generation',
7505: );
7506: return %fieldtitles;
7507: }
7508:
7509: sub sorted_inst_types {
7510: my ($dom) = @_;
7511: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
7512: my $othertitle = &mt('All users');
7513: if ($env{'request.course.id'}) {
7514: $othertitle = &mt('Any users');
7515: }
7516: my @types;
7517: if (ref($order) eq 'ARRAY') {
7518: @types = @{$order};
7519: }
7520: if (@types == 0) {
7521: if (ref($usertypes) eq 'HASH') {
7522: @types = sort(keys(%{$usertypes}));
7523: }
7524: }
7525: if (keys(%{$usertypes}) > 0) {
7526: $othertitle = &mt('Other users');
7527: }
7528: return ($othertitle,$usertypes,\@types);
7529: }
7530:
7531: sub get_institutional_codes {
7532: my ($settings,$allcourses,$LC_code) = @_;
7533: # Get complete list of course sections to update
7534: my @currsections = ();
7535: my @currxlists = ();
7536: my $coursecode = $$settings{'internal.coursecode'};
7537:
7538: if ($$settings{'internal.sectionnums'} ne '') {
7539: @currsections = split(/,/,$$settings{'internal.sectionnums'});
7540: }
7541:
7542: if ($$settings{'internal.crosslistings'} ne '') {
7543: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
7544: }
7545:
7546: if (@currxlists > 0) {
7547: foreach (@currxlists) {
7548: if (m/^([^:]+):(\w*)$/) {
7549: unless (grep/^$1$/,@{$allcourses}) {
7550: push @{$allcourses},$1;
7551: $$LC_code{$1} = $2;
7552: }
7553: }
7554: }
7555: }
7556:
7557: if (@currsections > 0) {
7558: foreach (@currsections) {
7559: if (m/^(\w+):(\w*)$/) {
7560: my $sec = $coursecode.$1;
7561: my $lc_sec = $2;
7562: unless (grep/^$sec$/,@{$allcourses}) {
7563: push @{$allcourses},$sec;
7564: $$LC_code{$sec} = $lc_sec;
7565: }
7566: }
7567: }
7568: }
7569: return;
7570: }
7571:
7572: =pod
7573:
7574: =back
7575:
7576: =head1 HTTP Helpers
7577:
7578: =over 4
7579:
7580: =item * &get_unprocessed_cgi($query,$possible_names)
7581:
7582: Modify the %env hash to contain unprocessed CGI form parameters held in
7583: $query. The parameters listed in $possible_names (an array reference),
7584: will be set in $env{'form.name'} if they do not already exist.
7585:
7586: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
7587: $possible_names is an ref to an array of form element names. As an example:
7588: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
7589: will result in $env{'form.uname'} and $env{'form.udom'} being set.
7590:
7591: =cut
7592:
7593: sub get_unprocessed_cgi {
7594: my ($query,$possible_names)= @_;
7595: # $Apache::lonxml::debug=1;
7596: foreach my $pair (split(/&/,$query)) {
7597: my ($name, $value) = split(/=/,$pair);
7598: $name = &unescape($name);
7599: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
7600: $value =~ tr/+/ /;
7601: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
7602: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
7603: }
7604: }
7605: }
7606:
7607: =pod
7608:
7609: =item * &cacheheader()
7610:
7611: returns cache-controlling header code
7612:
7613: =cut
7614:
7615: sub cacheheader {
7616: unless ($env{'request.method'} eq 'GET') { return ''; }
7617: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
7618: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
7619: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
7620: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
7621: return $output;
7622: }
7623:
7624: =pod
7625:
7626: =item * &no_cache($r)
7627:
7628: specifies header code to not have cache
7629:
7630: =cut
7631:
7632: sub no_cache {
7633: my ($r) = @_;
7634: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
7635: $env{'request.method'} ne 'GET') { return ''; }
7636: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
7637: $r->no_cache(1);
7638: $r->header_out("Expires" => $date);
7639: $r->header_out("Pragma" => "no-cache");
7640: }
7641:
7642: sub content_type {
7643: my ($r,$type,$charset) = @_;
7644: if ($r) {
7645: # Note that printout.pl calls this with undef for $r.
7646: &no_cache($r);
7647: }
7648: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
7649: unless ($charset) {
7650: $charset=&Apache::lonlocal::current_encoding;
7651: }
7652: if ($charset) { $type.='; charset='.$charset; }
7653: if ($r) {
7654: $r->content_type($type);
7655: } else {
7656: print("Content-type: $type\n\n");
7657: }
7658: }
7659:
7660: =pod
7661:
7662: =item * &add_to_env($name,$value)
7663:
7664: adds $name to the %env hash with value
7665: $value, if $name already exists, the entry is converted to an array
7666: reference and $value is added to the array.
7667:
7668: =cut
7669:
7670: sub add_to_env {
7671: my ($name,$value)=@_;
7672: if (defined($env{$name})) {
7673: if (ref($env{$name})) {
7674: #already have multiple values
7675: push(@{ $env{$name} },$value);
7676: } else {
7677: #first time seeing multiple values, convert hash entry to an arrayref
7678: my $first=$env{$name};
7679: undef($env{$name});
7680: push(@{ $env{$name} },$first,$value);
7681: }
7682: } else {
7683: $env{$name}=$value;
7684: }
7685: }
7686:
7687: =pod
7688:
7689: =item * &get_env_multiple($name)
7690:
7691: gets $name from the %env hash, it seemlessly handles the cases where multiple
7692: values may be defined and end up as an array ref.
7693:
7694: returns an array of values
7695:
7696: =cut
7697:
7698: sub get_env_multiple {
7699: my ($name) = @_;
7700: my @values;
7701: if (defined($env{$name})) {
7702: # exists is it an array
7703: if (ref($env{$name})) {
7704: @values=@{ $env{$name} };
7705: } else {
7706: $values[0]=$env{$name};
7707: }
7708: }
7709: return(@values);
7710: }
7711:
7712: sub ask_for_embedded_content {
7713: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
7714: my $upload_output = '
7715: <form name="upload_embedded" action="'.$actionurl.'"
7716: method="post" enctype="multipart/form-data">';
7717: $upload_output .= $state;
7718: $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
7719:
7720: my $num = 0;
7721: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
7722: $upload_output .= &start_data_table_row().
7723: '<td>'.$embed_file.'</td><td>';
7724: if ($args->{'ignore_remote_references'}
7725: && $embed_file =~ m{^\w+://}) {
7726: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
7727: } elsif ($args->{'error_on_invalid_names'}
7728: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
7729:
7730: $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
7731:
7732: } else {
7733: $upload_output .='
7734: <input name="embedded_item_'.$num.'" type="file" value="" />
7735: <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
7736: my $attrib = join(':',@{$$allfiles{$embed_file}});
7737: $upload_output .=
7738: "\n\t\t".
7739: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
7740: $attrib.'" />';
7741: if (exists($$codebase{$embed_file})) {
7742: $upload_output .=
7743: "\n\t\t".
7744: '<input name="codebase_'.$num.'" type="hidden" value="'.
7745: &escape($$codebase{$embed_file}).'" />';
7746: }
7747: }
7748: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
7749: $num++;
7750: }
7751: $upload_output .= &Apache::loncommon::end_data_table().'<br />
7752: <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
7753: <input type ="submit" value="'.&mt('Upload Listed Files').'" />
7754: '.&mt('(only files for which a location has been provided will be uploaded)').'
7755: </form>';
7756: return $upload_output;
7757: }
7758:
7759: sub upload_embedded {
7760: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
7761: $current_disk_usage) = @_;
7762: my $output;
7763: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
7764: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
7765: my $orig_uploaded_filename =
7766: $env{'form.embedded_item_'.$i.'.filename'};
7767:
7768: $env{'form.embedded_orig_'.$i} =
7769: &unescape($env{'form.embedded_orig_'.$i});
7770: my ($path,$fname) =
7771: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
7772: # no path, whole string is fname
7773: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
7774:
7775: $path = $env{'form.currentpath'}.$path;
7776: $fname = &Apache::lonnet::clean_filename($fname);
7777: # See if there is anything left
7778: next if ($fname eq '');
7779:
7780: # Check if file already exists as a file or directory.
7781: my ($state,$msg);
7782: if ($context eq 'portfolio') {
7783: my $port_path = $dirpath;
7784: if ($group ne '') {
7785: $port_path = "groups/$group/$port_path";
7786: }
7787: ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
7788: $dir_root,$port_path,$disk_quota,
7789: $current_disk_usage,$uname,$udom);
7790: if ($state eq 'will_exceed_quota'
7791: || $state eq 'file_locked'
7792: || $state eq 'file_exists' ) {
7793: $output .= $msg;
7794: next;
7795: }
7796: } elsif (($context eq 'author') || ($context eq 'testbank')) {
7797: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
7798: if ($state eq 'exists') {
7799: $output .= $msg;
7800: next;
7801: }
7802: }
7803: # Check if extension is valid
7804: if (($fname =~ /\.(\w+)$/) &&
7805: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
7806: $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
7807: next;
7808: } elsif (($fname =~ /\.(\w+)$/) &&
7809: (!defined(&Apache::loncommon::fileembstyle($1)))) {
7810: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
7811: next;
7812: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
7813: $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
7814: next;
7815: }
7816:
7817: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
7818: if ($context eq 'portfolio') {
7819: my $result=
7820: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
7821: $dirpath.$path);
7822: if ($result !~ m|^/uploaded/|) {
7823: $output .= '<span class="LC_error">'
7824: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
7825: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
7826: .'</span><br />';
7827: next;
7828: } else {
7829: $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
7830: $path.$fname.'</span>').'</p>';
7831: }
7832: } else {
7833: # Save the file
7834: my $target = $env{'form.embedded_item_'.$i};
7835: my $fullpath = $dir_root.$dirpath.'/'.$path;
7836: my $dest = $fullpath.$fname;
7837: my $url = $url_root.$dirpath.'/'.$path.$fname;
7838: my @parts=split(/\//,$fullpath);
7839: my $count;
7840: my $filepath = $dir_root;
7841: for ($count=4;$count<=$#parts;$count++) {
7842: $filepath .= "/$parts[$count]";
7843: if ((-e $filepath)!=1) {
7844: mkdir($filepath,0770);
7845: }
7846: }
7847: my $fh;
7848: if (!open($fh,'>'.$dest)) {
7849: &Apache::lonnet::logthis('Failed to create '.$dest);
7850: $output .= '<span class="LC_error">'.
7851: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
7852: '</span><br />';
7853: } else {
7854: if (!print $fh $env{'form.embedded_item_'.$i}) {
7855: &Apache::lonnet::logthis('Failed to write to '.$dest);
7856: $output .= '<span class="LC_error">'.
7857: &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
7858: '</span><br />';
7859: } else {
7860: if ($context eq 'testbank') {
7861: $output .= &mt('Embedded file uploaded successfully:').
7862: ' <a href="'.$url.'">'.
7863: $orig_uploaded_filename.'</a><br />';
7864: } else {
7865: $output .= '<span class=\"LC_fontsize_large\">'.
7866: &mt('View embedded file: [_1]','<a href="'.$url.'">'.
7867: $orig_uploaded_filename.'</a>').'</span><br />';
7868: }
7869: }
7870: close($fh);
7871: }
7872: }
7873: }
7874: return $output;
7875: }
7876:
7877: sub check_for_existing {
7878: my ($path,$fname,$element) = @_;
7879: my ($state,$msg);
7880: if (-d $path.'/'.$fname) {
7881: $state = 'exists';
7882: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
7883: } elsif (-e $path.'/'.$fname) {
7884: $state = 'exists';
7885: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
7886: }
7887: if ($state eq 'exists') {
7888: $msg = '<span class="LC_error">'.$msg.'</span><br />';
7889: }
7890: return ($state,$msg);
7891: }
7892:
7893: sub check_for_upload {
7894: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
7895: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
7896: my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
7897: my $getpropath = 1;
7898: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
7899: $getpropath);
7900: my $found_file = 0;
7901: my $locked_file = 0;
7902: foreach my $line (@dir_list) {
7903: my ($file_name)=split(/\&/,$line,2);
7904: if ($file_name eq $fname){
7905: $file_name = $path.$file_name;
7906: if ($group ne '') {
7907: $file_name = $group.$file_name;
7908: }
7909: $found_file = 1;
7910: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
7911: $locked_file = 1;
7912: }
7913: }
7914: }
7915: if (($current_disk_usage + $filesize) > $disk_quota){
7916: my $msg = '<span class="LC_error">'.
7917: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
7918: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
7919: return ('will_exceed_quota',$msg);
7920: } elsif ($found_file) {
7921: if ($locked_file) {
7922: my $msg = '<span class="LC_error">';
7923: $msg .= &mt('Unable to upload [_1]. A locked file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>','<span class="LC_filename">'.$port_path.$env{'form.currentpath'}.'</span>');
7924: $msg .= '</span><br />';
7925: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
7926: return ('file_locked',$msg);
7927: } else {
7928: my $msg = '<span class="LC_error">';
7929: $msg .= &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$port_path.$env{'form.currentpath'});
7930: $msg .= '</span>';
7931: $msg .= '<br />';
7932: $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
7933: return ('file_exists',$msg);
7934: }
7935: }
7936: }
7937:
7938:
7939: =pod
7940:
7941: =back
7942:
7943: =head1 CSV Upload/Handling functions
7944:
7945: =over 4
7946:
7947: =item * &upfile_store($r)
7948:
7949: Store uploaded file, $r should be the HTTP Request object,
7950: needs $env{'form.upfile'}
7951: returns $datatoken to be put into hidden field
7952:
7953: =cut
7954:
7955: sub upfile_store {
7956: my $r=shift;
7957: $env{'form.upfile'}=~s/\r/\n/gs;
7958: $env{'form.upfile'}=~s/\f/\n/gs;
7959: $env{'form.upfile'}=~s/\n+/\n/gs;
7960: $env{'form.upfile'}=~s/\n+$//gs;
7961:
7962: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
7963: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
7964: {
7965: my $datafile = $r->dir_config('lonDaemons').
7966: '/tmp/'.$datatoken.'.tmp';
7967: if ( open(my $fh,">$datafile") ) {
7968: print $fh $env{'form.upfile'};
7969: close($fh);
7970: }
7971: }
7972: return $datatoken;
7973: }
7974:
7975: =pod
7976:
7977: =item * &load_tmp_file($r)
7978:
7979: Load uploaded file from tmp, $r should be the HTTP Request object,
7980: needs $env{'form.datatoken'},
7981: sets $env{'form.upfile'} to the contents of the file
7982:
7983: =cut
7984:
7985: sub load_tmp_file {
7986: my $r=shift;
7987: my @studentdata=();
7988: {
7989: my $studentfile = $r->dir_config('lonDaemons').
7990: '/tmp/'.$env{'form.datatoken'}.'.tmp';
7991: if ( open(my $fh,"<$studentfile") ) {
7992: @studentdata=<$fh>;
7993: close($fh);
7994: }
7995: }
7996: $env{'form.upfile'}=join('',@studentdata);
7997: }
7998:
7999: =pod
8000:
8001: =item * &upfile_record_sep()
8002:
8003: Separate uploaded file into records
8004: returns array of records,
8005: needs $env{'form.upfile'} and $env{'form.upfiletype'}
8006:
8007: =cut
8008:
8009: sub upfile_record_sep {
8010: if ($env{'form.upfiletype'} eq 'xml') {
8011: } else {
8012: my @records;
8013: foreach my $line (split(/\n/,$env{'form.upfile'})) {
8014: if ($line=~/^\s*$/) { next; }
8015: push(@records,$line);
8016: }
8017: return @records;
8018: }
8019: }
8020:
8021: =pod
8022:
8023: =item * &record_sep($record)
8024:
8025: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
8026:
8027: =cut
8028:
8029: sub takeleft {
8030: my $index=shift;
8031: return substr('0000'.$index,-4,4);
8032: }
8033:
8034: sub record_sep {
8035: my $record=shift;
8036: my %components=();
8037: if ($env{'form.upfiletype'} eq 'xml') {
8038: } elsif ($env{'form.upfiletype'} eq 'space') {
8039: my $i=0;
8040: foreach my $field (split(/\s+/,$record)) {
8041: $field=~s/^(\"|\')//;
8042: $field=~s/(\"|\')$//;
8043: $components{&takeleft($i)}=$field;
8044: $i++;
8045: }
8046: } elsif ($env{'form.upfiletype'} eq 'tab') {
8047: my $i=0;
8048: foreach my $field (split(/\t/,$record)) {
8049: $field=~s/^(\"|\')//;
8050: $field=~s/(\"|\')$//;
8051: $components{&takeleft($i)}=$field;
8052: $i++;
8053: }
8054: } else {
8055: my $separator=',';
8056: if ($env{'form.upfiletype'} eq 'semisv') {
8057: $separator=';';
8058: }
8059: my $i=0;
8060: # the character we are looking for to indicate the end of a quote or a record
8061: my $looking_for=$separator;
8062: # do not add the characters to the fields
8063: my $ignore=0;
8064: # we just encountered a separator (or the beginning of the record)
8065: my $just_found_separator=1;
8066: # store the field we are working on here
8067: my $field='';
8068: # work our way through all characters in record
8069: foreach my $character ($record=~/(.)/g) {
8070: if ($character eq $looking_for) {
8071: if ($character ne $separator) {
8072: # Found the end of a quote, again looking for separator
8073: $looking_for=$separator;
8074: $ignore=1;
8075: } else {
8076: # Found a separator, store away what we got
8077: $components{&takeleft($i)}=$field;
8078: $i++;
8079: $just_found_separator=1;
8080: $ignore=0;
8081: $field='';
8082: }
8083: next;
8084: }
8085: # single or double quotation marks after a separator indicate beginning of a quote
8086: # we are now looking for the end of the quote and need to ignore separators
8087: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
8088: $looking_for=$character;
8089: next;
8090: }
8091: # ignore would be true after we reached the end of a quote
8092: if ($ignore) { next; }
8093: if (($just_found_separator) && ($character=~/\s/)) { next; }
8094: $field.=$character;
8095: $just_found_separator=0;
8096: }
8097: # catch the very last entry, since we never encountered the separator
8098: $components{&takeleft($i)}=$field;
8099: }
8100: return %components;
8101: }
8102:
8103: ######################################################
8104: ######################################################
8105:
8106: =pod
8107:
8108: =item * &upfile_select_html()
8109:
8110: Return HTML code to select a file from the users machine and specify
8111: the file type.
8112:
8113: =cut
8114:
8115: ######################################################
8116: ######################################################
8117: sub upfile_select_html {
8118: my %Types = (
8119: csv => &mt('CSV (comma separated values, spreadsheet)'),
8120: semisv => &mt('Semicolon separated values'),
8121: space => &mt('Space separated'),
8122: tab => &mt('Tabulator separated'),
8123: # xml => &mt('HTML/XML'),
8124: );
8125: my $Str = '<input type="file" name="upfile" size="50" />'.
8126: '<br />'.&mt('Type').': <select name="upfiletype">';
8127: foreach my $type (sort(keys(%Types))) {
8128: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
8129: }
8130: $Str .= "</select>\n";
8131: return $Str;
8132: }
8133:
8134: sub get_samples {
8135: my ($records,$toget) = @_;
8136: my @samples=({});
8137: my $got=0;
8138: foreach my $rec (@$records) {
8139: my %temp = &record_sep($rec);
8140: if (! grep(/\S/, values(%temp))) { next; }
8141: if (%temp) {
8142: $samples[$got]=\%temp;
8143: $got++;
8144: if ($got == $toget) { last; }
8145: }
8146: }
8147: return \@samples;
8148: }
8149:
8150: ######################################################
8151: ######################################################
8152:
8153: =pod
8154:
8155: =item * &csv_print_samples($r,$records)
8156:
8157: Prints a table of sample values from each column uploaded $r is an
8158: Apache Request ref, $records is an arrayref from
8159: &Apache::loncommon::upfile_record_sep
8160:
8161: =cut
8162:
8163: ######################################################
8164: ######################################################
8165: sub csv_print_samples {
8166: my ($r,$records) = @_;
8167: my $samples = &get_samples($records,5);
8168:
8169: $r->print(&mt('Samples').'<br />'.&start_data_table().
8170: &start_data_table_header_row());
8171: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8172: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
8173: $r->print(&end_data_table_header_row());
8174: foreach my $hash (@$samples) {
8175: $r->print(&start_data_table_row());
8176: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8177: $r->print('<td>');
8178: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
8179: $r->print('</td>');
8180: }
8181: $r->print(&end_data_table_row());
8182: }
8183: $r->print(&end_data_table().'<br />'."\n");
8184: }
8185:
8186: ######################################################
8187: ######################################################
8188:
8189: =pod
8190:
8191: =item * &csv_print_select_table($r,$records,$d)
8192:
8193: Prints a table to create associations between values and table columns.
8194:
8195: $r is an Apache Request ref,
8196: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
8197: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
8198:
8199: =cut
8200:
8201: ######################################################
8202: ######################################################
8203: sub csv_print_select_table {
8204: my ($r,$records,$d) = @_;
8205: my $i=0;
8206: my $samples = &get_samples($records,1);
8207: $r->print(&mt('Associate columns with student attributes.')."\n".
8208: &start_data_table().&start_data_table_header_row().
8209: '<th>'.&mt('Attribute').'</th>'.
8210: '<th>'.&mt('Column').'</th>'.
8211: &end_data_table_header_row()."\n");
8212: foreach my $array_ref (@$d) {
8213: my ($value,$display,$defaultcol)=@{ $array_ref };
8214: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
8215:
8216: $r->print('<td><select name=f'.$i.
8217: ' onchange="javascript:flip(this.form,'.$i.');">');
8218: $r->print('<option value="none"></option>');
8219: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8220: $r->print('<option value="'.$sample.'"'.
8221: ($sample eq $defaultcol ? ' selected="selected" ' : '').
8222: '>'.&mt('Column [_1]',($sample+1)).'</option>');
8223: }
8224: $r->print('</select></td>'.&end_data_table_row()."\n");
8225: $i++;
8226: }
8227: $r->print(&end_data_table());
8228: $i--;
8229: return $i;
8230: }
8231:
8232: ######################################################
8233: ######################################################
8234:
8235: =pod
8236:
8237: =item * &csv_samples_select_table($r,$records,$d)
8238:
8239: Prints a table of sample values from the upload and can make associate samples to internal names.
8240:
8241: $r is an Apache Request ref,
8242: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
8243: $d is an array of 2 element arrays (internal name, displayed name)
8244:
8245: =cut
8246:
8247: ######################################################
8248: ######################################################
8249: sub csv_samples_select_table {
8250: my ($r,$records,$d) = @_;
8251: my $i=0;
8252: #
8253: my $max_samples = 5;
8254: my $samples = &get_samples($records,$max_samples);
8255: $r->print(&start_data_table().
8256: &start_data_table_header_row().'<th>'.
8257: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
8258: &end_data_table_header_row());
8259:
8260: foreach my $key (sort(keys(%{ $samples->[0] }))) {
8261: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
8262: ' onchange="javascript:flip(this.form,'.$i.');">');
8263: foreach my $option (@$d) {
8264: my ($value,$display,$defaultcol)=@{ $option };
8265: $r->print('<option value="'.$value.'"'.
8266: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
8267: $display.'</option>');
8268: }
8269: $r->print('</select></td><td>');
8270: foreach my $line (0..($max_samples-1)) {
8271: if (defined($samples->[$line]{$key})) {
8272: $r->print($samples->[$line]{$key}."<br />\n");
8273: }
8274: }
8275: $r->print('</td>'.&end_data_table_row());
8276: $i++;
8277: }
8278: $r->print(&end_data_table());
8279: $i--;
8280: return($i);
8281: }
8282:
8283: ######################################################
8284: ######################################################
8285:
8286: =pod
8287:
8288: =item * &clean_excel_name($name)
8289:
8290: Returns a replacement for $name which does not contain any illegal characters.
8291:
8292: =cut
8293:
8294: ######################################################
8295: ######################################################
8296: sub clean_excel_name {
8297: my ($name) = @_;
8298: $name =~ s/[:\*\?\/\\]//g;
8299: if (length($name) > 31) {
8300: $name = substr($name,0,31);
8301: }
8302: return $name;
8303: }
8304:
8305: =pod
8306:
8307: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
8308:
8309: Returns either 1 or undef
8310:
8311: 1 if the part is to be hidden, undef if it is to be shown
8312:
8313: Arguments are:
8314:
8315: $id the id of the part to be checked
8316: $symb, optional the symb of the resource to check
8317: $udom, optional the domain of the user to check for
8318: $uname, optional the username of the user to check for
8319:
8320: =cut
8321:
8322: sub check_if_partid_hidden {
8323: my ($id,$symb,$udom,$uname) = @_;
8324: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
8325: $symb,$udom,$uname);
8326: my $truth=1;
8327: #if the string starts with !, then the list is the list to show not hide
8328: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
8329: my @hiddenlist=split(/,/,$hiddenparts);
8330: foreach my $checkid (@hiddenlist) {
8331: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
8332: }
8333: return !$truth;
8334: }
8335:
8336:
8337: ############################################################
8338: ############################################################
8339:
8340: =pod
8341:
8342: =back
8343:
8344: =head1 cgi-bin script and graphing routines
8345:
8346: =over 4
8347:
8348: =item * &get_cgi_id()
8349:
8350: Inputs: none
8351:
8352: Returns an id which can be used to pass environment variables
8353: to various cgi-bin scripts. These environment variables will
8354: be removed from the users environment after a given time by
8355: the routine &Apache::lonnet::transfer_profile_to_env.
8356:
8357: =cut
8358:
8359: ############################################################
8360: ############################################################
8361: my $uniq=0;
8362: sub get_cgi_id {
8363: $uniq=($uniq+1)%100000;
8364: return (time.'_'.$$.'_'.$uniq);
8365: }
8366:
8367: ############################################################
8368: ############################################################
8369:
8370: =pod
8371:
8372: =item * &DrawBarGraph()
8373:
8374: Facilitates the plotting of data in a (stacked) bar graph.
8375: Puts plot definition data into the users environment in order for
8376: graph.png to plot it. Returns an <img> tag for the plot.
8377: The bars on the plot are labeled '1','2',...,'n'.
8378:
8379: Inputs:
8380:
8381: =over 4
8382:
8383: =item $Title: string, the title of the plot
8384:
8385: =item $xlabel: string, text describing the X-axis of the plot
8386:
8387: =item $ylabel: string, text describing the Y-axis of the plot
8388:
8389: =item $Max: scalar, the maximum Y value to use in the plot
8390: If $Max is < any data point, the graph will not be rendered.
8391:
8392: =item $colors: array ref holding the colors to be used for the data sets when
8393: they are plotted. If undefined, default values will be used.
8394:
8395: =item $labels: array ref holding the labels to use on the x-axis for the bars.
8396:
8397: =item @Values: An array of array references. Each array reference holds data
8398: to be plotted in a stacked bar chart.
8399:
8400: =item If the final element of @Values is a hash reference the key/value
8401: pairs will be added to the graph definition.
8402:
8403: =back
8404:
8405: Returns:
8406:
8407: An <img> tag which references graph.png and the appropriate identifying
8408: information for the plot.
8409:
8410: =cut
8411:
8412: ############################################################
8413: ############################################################
8414: sub DrawBarGraph {
8415: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
8416: #
8417: if (! defined($colors)) {
8418: $colors = ['#33ff00',
8419: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
8420: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
8421: ];
8422: }
8423: my $extra_settings = {};
8424: if (ref($Values[-1]) eq 'HASH') {
8425: $extra_settings = pop(@Values);
8426: }
8427: #
8428: my $identifier = &get_cgi_id();
8429: my $id = 'cgi.'.$identifier;
8430: if (! @Values || ref($Values[0]) ne 'ARRAY') {
8431: return '';
8432: }
8433: #
8434: my @Labels;
8435: if (defined($labels)) {
8436: @Labels = @$labels;
8437: } else {
8438: for (my $i=0;$i<@{$Values[0]};$i++) {
8439: push (@Labels,$i+1);
8440: }
8441: }
8442: #
8443: my $NumBars = scalar(@{$Values[0]});
8444: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
8445: my %ValuesHash;
8446: my $NumSets=1;
8447: foreach my $array (@Values) {
8448: next if (! ref($array));
8449: $ValuesHash{$id.'.data.'.$NumSets++} =
8450: join(',',@$array);
8451: }
8452: #
8453: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
8454: if ($NumBars < 3) {
8455: $width = 120+$NumBars*32;
8456: $xskip = 1;
8457: $bar_width = 30;
8458: } elsif ($NumBars < 5) {
8459: $width = 120+$NumBars*20;
8460: $xskip = 1;
8461: $bar_width = 20;
8462: } elsif ($NumBars < 10) {
8463: $width = 120+$NumBars*15;
8464: $xskip = 1;
8465: $bar_width = 15;
8466: } elsif ($NumBars <= 25) {
8467: $width = 120+$NumBars*11;
8468: $xskip = 5;
8469: $bar_width = 8;
8470: } elsif ($NumBars <= 50) {
8471: $width = 120+$NumBars*8;
8472: $xskip = 5;
8473: $bar_width = 4;
8474: } else {
8475: $width = 120+$NumBars*8;
8476: $xskip = 5;
8477: $bar_width = 4;
8478: }
8479: #
8480: $Max = 1 if ($Max < 1);
8481: if ( int($Max) < $Max ) {
8482: $Max++;
8483: $Max = int($Max);
8484: }
8485: $Title = '' if (! defined($Title));
8486: $xlabel = '' if (! defined($xlabel));
8487: $ylabel = '' if (! defined($ylabel));
8488: $ValuesHash{$id.'.title'} = &escape($Title);
8489: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
8490: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
8491: $ValuesHash{$id.'.y_max_value'} = $Max;
8492: $ValuesHash{$id.'.NumBars'} = $NumBars;
8493: $ValuesHash{$id.'.NumSets'} = $NumSets;
8494: $ValuesHash{$id.'.PlotType'} = 'bar';
8495: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8496: $ValuesHash{$id.'.height'} = $height;
8497: $ValuesHash{$id.'.width'} = $width;
8498: $ValuesHash{$id.'.xskip'} = $xskip;
8499: $ValuesHash{$id.'.bar_width'} = $bar_width;
8500: $ValuesHash{$id.'.labels'} = join(',',@Labels);
8501: #
8502: # Deal with other parameters
8503: while (my ($key,$value) = each(%$extra_settings)) {
8504: $ValuesHash{$id.'.'.$key} = $value;
8505: }
8506: #
8507: &Apache::lonnet::appenv(\%ValuesHash);
8508: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8509: }
8510:
8511: ############################################################
8512: ############################################################
8513:
8514: =pod
8515:
8516: =item * &DrawXYGraph()
8517:
8518: Facilitates the plotting of data in an XY graph.
8519: Puts plot definition data into the users environment in order for
8520: graph.png to plot it. Returns an <img> tag for the plot.
8521:
8522: Inputs:
8523:
8524: =over 4
8525:
8526: =item $Title: string, the title of the plot
8527:
8528: =item $xlabel: string, text describing the X-axis of the plot
8529:
8530: =item $ylabel: string, text describing the Y-axis of the plot
8531:
8532: =item $Max: scalar, the maximum Y value to use in the plot
8533: If $Max is < any data point, the graph will not be rendered.
8534:
8535: =item $colors: Array ref containing the hex color codes for the data to be
8536: plotted in. If undefined, default values will be used.
8537:
8538: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8539:
8540: =item $Ydata: Array ref containing Array refs.
8541: Each of the contained arrays will be plotted as a separate curve.
8542:
8543: =item %Values: hash indicating or overriding any default values which are
8544: passed to graph.png.
8545: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
8546:
8547: =back
8548:
8549: Returns:
8550:
8551: An <img> tag which references graph.png and the appropriate identifying
8552: information for the plot.
8553:
8554: =cut
8555:
8556: ############################################################
8557: ############################################################
8558: sub DrawXYGraph {
8559: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
8560: #
8561: # Create the identifier for the graph
8562: my $identifier = &get_cgi_id();
8563: my $id = 'cgi.'.$identifier;
8564: #
8565: $Title = '' if (! defined($Title));
8566: $xlabel = '' if (! defined($xlabel));
8567: $ylabel = '' if (! defined($ylabel));
8568: my %ValuesHash =
8569: (
8570: $id.'.title' => &escape($Title),
8571: $id.'.xlabel' => &escape($xlabel),
8572: $id.'.ylabel' => &escape($ylabel),
8573: $id.'.y_max_value'=> $Max,
8574: $id.'.labels' => join(',',@$Xlabels),
8575: $id.'.PlotType' => 'XY',
8576: );
8577: #
8578: if (defined($colors) && ref($colors) eq 'ARRAY') {
8579: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8580: }
8581: #
8582: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
8583: return '';
8584: }
8585: my $NumSets=1;
8586: foreach my $array (@{$Ydata}){
8587: next if (! ref($array));
8588: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
8589: }
8590: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
8591: #
8592: # Deal with other parameters
8593: while (my ($key,$value) = each(%Values)) {
8594: $ValuesHash{$id.'.'.$key} = $value;
8595: }
8596: #
8597: &Apache::lonnet::appenv(\%ValuesHash);
8598: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8599: }
8600:
8601: ############################################################
8602: ############################################################
8603:
8604: =pod
8605:
8606: =item * &DrawXYYGraph()
8607:
8608: Facilitates the plotting of data in an XY graph with two Y axes.
8609: Puts plot definition data into the users environment in order for
8610: graph.png to plot it. Returns an <img> tag for the plot.
8611:
8612: Inputs:
8613:
8614: =over 4
8615:
8616: =item $Title: string, the title of the plot
8617:
8618: =item $xlabel: string, text describing the X-axis of the plot
8619:
8620: =item $ylabel: string, text describing the Y-axis of the plot
8621:
8622: =item $colors: Array ref containing the hex color codes for the data to be
8623: plotted in. If undefined, default values will be used.
8624:
8625: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8626:
8627: =item $Ydata1: The first data set
8628:
8629: =item $Min1: The minimum value of the left Y-axis
8630:
8631: =item $Max1: The maximum value of the left Y-axis
8632:
8633: =item $Ydata2: The second data set
8634:
8635: =item $Min2: The minimum value of the right Y-axis
8636:
8637: =item $Max2: The maximum value of the left Y-axis
8638:
8639: =item %Values: hash indicating or overriding any default values which are
8640: passed to graph.png.
8641: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
8642:
8643: =back
8644:
8645: Returns:
8646:
8647: An <img> tag which references graph.png and the appropriate identifying
8648: information for the plot.
8649:
8650: =cut
8651:
8652: ############################################################
8653: ############################################################
8654: sub DrawXYYGraph {
8655: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
8656: $Ydata2,$Min2,$Max2,%Values)=@_;
8657: #
8658: # Create the identifier for the graph
8659: my $identifier = &get_cgi_id();
8660: my $id = 'cgi.'.$identifier;
8661: #
8662: $Title = '' if (! defined($Title));
8663: $xlabel = '' if (! defined($xlabel));
8664: $ylabel = '' if (! defined($ylabel));
8665: my %ValuesHash =
8666: (
8667: $id.'.title' => &escape($Title),
8668: $id.'.xlabel' => &escape($xlabel),
8669: $id.'.ylabel' => &escape($ylabel),
8670: $id.'.labels' => join(',',@$Xlabels),
8671: $id.'.PlotType' => 'XY',
8672: $id.'.NumSets' => 2,
8673: $id.'.two_axes' => 1,
8674: $id.'.y1_max_value' => $Max1,
8675: $id.'.y1_min_value' => $Min1,
8676: $id.'.y2_max_value' => $Max2,
8677: $id.'.y2_min_value' => $Min2,
8678: );
8679: #
8680: if (defined($colors) && ref($colors) eq 'ARRAY') {
8681: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8682: }
8683: #
8684: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
8685: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
8686: return '';
8687: }
8688: my $NumSets=1;
8689: foreach my $array ($Ydata1,$Ydata2){
8690: next if (! ref($array));
8691: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
8692: }
8693: #
8694: # Deal with other parameters
8695: while (my ($key,$value) = each(%Values)) {
8696: $ValuesHash{$id.'.'.$key} = $value;
8697: }
8698: #
8699: &Apache::lonnet::appenv(\%ValuesHash);
8700: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8701: }
8702:
8703: ############################################################
8704: ############################################################
8705:
8706: =pod
8707:
8708: =back
8709:
8710: =head1 Statistics helper routines?
8711:
8712: Bad place for them but what the hell.
8713:
8714: =over 4
8715:
8716: =item * &chartlink()
8717:
8718: Returns a link to the chart for a specific student.
8719:
8720: Inputs:
8721:
8722: =over 4
8723:
8724: =item $linktext: The text of the link
8725:
8726: =item $sname: The students username
8727:
8728: =item $sdomain: The students domain
8729:
8730: =back
8731:
8732: =back
8733:
8734: =cut
8735:
8736: ############################################################
8737: ############################################################
8738: sub chartlink {
8739: my ($linktext, $sname, $sdomain) = @_;
8740: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
8741: '&SelectedStudent='.&escape($sname.':'.$sdomain).
8742: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
8743: '">'.$linktext.'</a>';
8744: }
8745:
8746: #######################################################
8747: #######################################################
8748:
8749: =pod
8750:
8751: =head1 Course Environment Routines
8752:
8753: =over 4
8754:
8755: =item * &restore_course_settings()
8756:
8757: =item * &store_course_settings()
8758:
8759: Restores/Store indicated form parameters from the course environment.
8760: Will not overwrite existing values of the form parameters.
8761:
8762: Inputs:
8763: a scalar describing the data (e.g. 'chart', 'problem_analysis')
8764:
8765: a hash ref describing the data to be stored. For example:
8766:
8767: %Save_Parameters = ('Status' => 'scalar',
8768: 'chartoutputmode' => 'scalar',
8769: 'chartoutputdata' => 'scalar',
8770: 'Section' => 'array',
8771: 'Group' => 'array',
8772: 'StudentData' => 'array',
8773: 'Maps' => 'array');
8774:
8775: Returns: both routines return nothing
8776:
8777: =back
8778:
8779: =cut
8780:
8781: #######################################################
8782: #######################################################
8783: sub store_course_settings {
8784: return &store_settings($env{'request.course.id'},@_);
8785: }
8786:
8787: sub store_settings {
8788: # save to the environment
8789: # appenv the same items, just to be safe
8790: my $udom = $env{'user.domain'};
8791: my $uname = $env{'user.name'};
8792: my ($context,$prefix,$Settings) = @_;
8793: my %SaveHash;
8794: my %AppHash;
8795: while (my ($setting,$type) = each(%$Settings)) {
8796: my $basename = join('.','internal',$context,$prefix,$setting);
8797: my $envname = 'environment.'.$basename;
8798: if (exists($env{'form.'.$setting})) {
8799: # Save this value away
8800: if ($type eq 'scalar' &&
8801: (! exists($env{$envname}) ||
8802: $env{$envname} ne $env{'form.'.$setting})) {
8803: $SaveHash{$basename} = $env{'form.'.$setting};
8804: $AppHash{$envname} = $env{'form.'.$setting};
8805: } elsif ($type eq 'array') {
8806: my $stored_form;
8807: if (ref($env{'form.'.$setting})) {
8808: $stored_form = join(',',
8809: map {
8810: &escape($_);
8811: } sort(@{$env{'form.'.$setting}}));
8812: } else {
8813: $stored_form =
8814: &escape($env{'form.'.$setting});
8815: }
8816: # Determine if the array contents are the same.
8817: if ($stored_form ne $env{$envname}) {
8818: $SaveHash{$basename} = $stored_form;
8819: $AppHash{$envname} = $stored_form;
8820: }
8821: }
8822: }
8823: }
8824: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
8825: $udom,$uname);
8826: if ($put_result !~ /^(ok|delayed)/) {
8827: &Apache::lonnet::logthis('unable to save form parameters, '.
8828: 'got error:'.$put_result);
8829: }
8830: # Make sure these settings stick around in this session, too
8831: &Apache::lonnet::appenv(\%AppHash);
8832: return;
8833: }
8834:
8835: sub restore_course_settings {
8836: return &restore_settings($env{'request.course.id'},@_);
8837: }
8838:
8839: sub restore_settings {
8840: my ($context,$prefix,$Settings) = @_;
8841: while (my ($setting,$type) = each(%$Settings)) {
8842: next if (exists($env{'form.'.$setting}));
8843: my $envname = 'environment.internal.'.$context.'.'.$prefix.
8844: '.'.$setting;
8845: if (exists($env{$envname})) {
8846: if ($type eq 'scalar') {
8847: $env{'form.'.$setting} = $env{$envname};
8848: } elsif ($type eq 'array') {
8849: $env{'form.'.$setting} = [
8850: map {
8851: &unescape($_);
8852: } split(',',$env{$envname})
8853: ];
8854: }
8855: }
8856: }
8857: }
8858:
8859: #######################################################
8860: #######################################################
8861:
8862: =pod
8863:
8864: =head1 Domain E-mail Routines
8865:
8866: =over 4
8867:
8868: =item * &build_recipient_list()
8869:
8870: Build recipient lists for three types of e-mail:
8871: (a) Error Reports, (b) Package Updates, (c) Help requests, generated by
8872: lonerrorhandler.pm, CHECKRPMS and lonsupportreq.pm respectively.
8873:
8874: Inputs:
8875: defmail (scalar - email address of default recipient),
8876: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
8877: defdom (domain for which to retrieve configuration settings),
8878: origmail (scalar - email address of recipient from loncapa.conf,
8879: i.e., predates configuration by DC via domainprefs.pm
8880:
8881: Returns: comma separated list of addresses to which to send e-mail.
8882:
8883: =back
8884:
8885: =cut
8886:
8887: ############################################################
8888: ############################################################
8889: sub build_recipient_list {
8890: my ($defmail,$mailing,$defdom,$origmail) = @_;
8891: my @recipients;
8892: my $otheremails;
8893: my %domconfig =
8894: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
8895: if (ref($domconfig{'contacts'}) eq 'HASH') {
8896: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
8897: my @contacts = ('adminemail','supportemail');
8898: foreach my $item (@contacts) {
8899: if ($domconfig{'contacts'}{$mailing}{$item}) {
8900: my $addr = $domconfig{'contacts'}{$item};
8901: if (!grep(/^\Q$addr\E$/,@recipients)) {
8902: push(@recipients,$addr);
8903: }
8904: }
8905: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
8906: }
8907: }
8908: } elsif ($origmail ne '') {
8909: push(@recipients,$origmail);
8910: }
8911: if (defined($defmail)) {
8912: if ($defmail ne '') {
8913: push(@recipients,$defmail);
8914: }
8915: }
8916: if ($otheremails) {
8917: my @others;
8918: if ($otheremails =~ /,/) {
8919: @others = split(/,/,$otheremails);
8920: } else {
8921: push(@others,$otheremails);
8922: }
8923: foreach my $addr (@others) {
8924: if (!grep(/^\Q$addr\E$/,@recipients)) {
8925: push(@recipients,$addr);
8926: }
8927: }
8928: }
8929: my $recipientlist = join(',',@recipients);
8930: return $recipientlist;
8931: }
8932:
8933: ############################################################
8934: ############################################################
8935:
8936: =pod
8937:
8938: =head1 Course Catalog Routines
8939:
8940: =over 4
8941:
8942: =item * &gather_categories()
8943:
8944: Converts category definitions - keys of categories hash stored in
8945: coursecategories in configuration.db on the primary library server in a
8946: domain - to an array. Also generates javascript and idx hash used to
8947: generate Domain Coordinator interface for editing Course Categories.
8948:
8949: Inputs:
8950:
8951: categories (reference to hash of category definitions).
8952:
8953: cats (reference to array of arrays/hashes which encapsulates hierarchy of
8954: categories and subcategories).
8955:
8956: idx (reference to hash of counters used in Domain Coordinator interface for
8957: editing Course Categories).
8958:
8959: jsarray (reference to array of categories used to create Javascript arrays for
8960: Domain Coordinator interface for editing Course Categories).
8961:
8962: Returns: nothing
8963:
8964: Side effects: populates cats, idx and jsarray.
8965:
8966: =cut
8967:
8968: sub gather_categories {
8969: my ($categories,$cats,$idx,$jsarray) = @_;
8970: my %counters;
8971: my $num = 0;
8972: foreach my $item (keys(%{$categories})) {
8973: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
8974: if ($container eq '' && $depth == 0) {
8975: $cats->[$depth][$categories->{$item}] = $cat;
8976: } else {
8977: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
8978: }
8979: my ($escitem,$tail) = split(/:/,$item,2);
8980: if ($counters{$tail} eq '') {
8981: $counters{$tail} = $num;
8982: $num ++;
8983: }
8984: if (ref($idx) eq 'HASH') {
8985: $idx->{$item} = $counters{$tail};
8986: }
8987: if (ref($jsarray) eq 'ARRAY') {
8988: push(@{$jsarray->[$counters{$tail}]},$item);
8989: }
8990: }
8991: return;
8992: }
8993:
8994: =pod
8995:
8996: =item * &extract_categories()
8997:
8998: Used to generate breadcrumb trails for course categories.
8999:
9000: Inputs:
9001:
9002: categories (reference to hash of category definitions).
9003:
9004: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9005: categories and subcategories).
9006:
9007: trails (reference to array of breacrumb trails for each category).
9008:
9009: allitems (reference to hash - key is category key
9010: (format: escaped(name):escaped(parent category):depth in hierarchy).
9011:
9012: idx (reference to hash of counters used in Domain Coordinator interface for
9013: editing Course Categories).
9014:
9015: jsarray (reference to array of categories used to create Javascript arrays for
9016: Domain Coordinator interface for editing Course Categories).
9017:
9018: subcats (reference to hash of arrays containing all subcategories within each
9019: category, -recursive)
9020:
9021: Returns: nothing
9022:
9023: Side effects: populates trails and allitems hash references.
9024:
9025: =cut
9026:
9027: sub extract_categories {
9028: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
9029: if (ref($categories) eq 'HASH') {
9030: &gather_categories($categories,$cats,$idx,$jsarray);
9031: if (ref($cats->[0]) eq 'ARRAY') {
9032: for (my $i=0; $i<@{$cats->[0]}; $i++) {
9033: my $name = $cats->[0][$i];
9034: my $item = &escape($name).'::0';
9035: my $trailstr;
9036: if ($name eq 'instcode') {
9037: $trailstr = &mt('Official courses (with institutional codes)');
9038: } else {
9039: $trailstr = $name;
9040: }
9041: if ($allitems->{$item} eq '') {
9042: push(@{$trails},$trailstr);
9043: $allitems->{$item} = scalar(@{$trails})-1;
9044: }
9045: my @parents = ($name);
9046: if (ref($cats->[1]{$name}) eq 'ARRAY') {
9047: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
9048: my $category = $cats->[1]{$name}[$j];
9049: if (ref($subcats) eq 'HASH') {
9050: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
9051: }
9052: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
9053: }
9054: } else {
9055: if (ref($subcats) eq 'HASH') {
9056: $subcats->{$item} = [];
9057: }
9058: }
9059: }
9060: }
9061: }
9062: return;
9063: }
9064:
9065: =pod
9066:
9067: =item *&recurse_categories()
9068:
9069: Recursively used to generate breadcrumb trails for course categories.
9070:
9071: Inputs:
9072:
9073: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9074: categories and subcategories).
9075:
9076: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
9077:
9078: category (current course category, for which breadcrumb trail is being generated).
9079:
9080: trails (reference to array of breadcrumb trails for each category).
9081:
9082: allitems (reference to hash - key is category key
9083: (format: escaped(name):escaped(parent category):depth in hierarchy).
9084:
9085: parents (array containing containers directories for current category,
9086: back to top level).
9087:
9088: Returns: nothing
9089:
9090: Side effects: populates trails and allitems hash references
9091:
9092: =cut
9093:
9094: sub recurse_categories {
9095: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
9096: my $shallower = $depth - 1;
9097: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
9098: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
9099: my $name = $cats->[$depth]{$category}[$k];
9100: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9101: my $trailstr = join(' -> ',(@{$parents},$category));
9102: if ($allitems->{$item} eq '') {
9103: push(@{$trails},$trailstr);
9104: $allitems->{$item} = scalar(@{$trails})-1;
9105: }
9106: my $deeper = $depth+1;
9107: push(@{$parents},$category);
9108: if (ref($subcats) eq 'HASH') {
9109: my $subcat = &escape($name).':'.$category.':'.$depth;
9110: for (my $j=@{$parents}; $j>=0; $j--) {
9111: my $higher;
9112: if ($j > 0) {
9113: $higher = &escape($parents->[$j]).':'.
9114: &escape($parents->[$j-1]).':'.$j;
9115: } else {
9116: $higher = &escape($parents->[$j]).'::'.$j;
9117: }
9118: push(@{$subcats->{$higher}},$subcat);
9119: }
9120: }
9121: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
9122: $subcats);
9123: pop(@{$parents});
9124: }
9125: } else {
9126: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9127: my $trailstr = join(' -> ',(@{$parents},$category));
9128: if ($allitems->{$item} eq '') {
9129: push(@{$trails},$trailstr);
9130: $allitems->{$item} = scalar(@{$trails})-1;
9131: }
9132: }
9133: return;
9134: }
9135:
9136: =pod
9137:
9138: =item *&assign_categories_table()
9139:
9140: Create a datatable for display of hierarchical categories in a domain,
9141: with checkboxes to allow a course to be categorized.
9142:
9143: Inputs:
9144:
9145: cathash - reference to hash of categories defined for the domain (from
9146: configuration.db)
9147:
9148: currcat - scalar with an & separated list of categories assigned to a course.
9149:
9150: Returns: $output (markup to be displayed)
9151:
9152: =cut
9153:
9154: sub assign_categories_table {
9155: my ($cathash,$currcat) = @_;
9156: my $output;
9157: if (ref($cathash) eq 'HASH') {
9158: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
9159: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
9160: $maxdepth = scalar(@cats);
9161: if (@cats > 0) {
9162: my $itemcount = 0;
9163: if (ref($cats[0]) eq 'ARRAY') {
9164: $output = &Apache::loncommon::start_data_table();
9165: my @currcategories;
9166: if ($currcat ne '') {
9167: @currcategories = split('&',$currcat);
9168: }
9169: for (my $i=0; $i<@{$cats[0]}; $i++) {
9170: my $parent = $cats[0][$i];
9171: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9172: next if ($parent eq 'instcode');
9173: my $item = &escape($parent).'::0';
9174: my $checked = '';
9175: if (@currcategories > 0) {
9176: if (grep(/^\Q$item\E$/,@currcategories)) {
9177: $checked = ' checked="checked" ';
9178: }
9179: }
9180: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
9181: '<input type="checkbox" name="usecategory" value="'.
9182: $item.'"'.$checked.' />'.$parent.'</span>'.
9183: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
9184: my $depth = 1;
9185: push(@path,$parent);
9186: $output .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
9187: pop(@path);
9188: $output .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
9189: $itemcount ++;
9190: }
9191: $output .= &Apache::loncommon::end_data_table();
9192: }
9193: }
9194: }
9195: return $output;
9196: }
9197:
9198: =pod
9199:
9200: =item *&assign_category_rows()
9201:
9202: Create a datatable row for display of nested categories in a domain,
9203: with checkboxes to allow a course to be categorized,called recursively.
9204:
9205: Inputs:
9206:
9207: itemcount - track row number for alternating colors
9208:
9209: cats - reference to array of arrays/hashes which encapsulates hierarchy of
9210: categories and subcategories.
9211:
9212: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
9213:
9214: parent - parent of current category item
9215:
9216: path - Array containing all categories back up through the hierarchy from the
9217: current category to the top level.
9218:
9219: currcategories - reference to array of current categories assigned to the course
9220:
9221: Returns: $output (markup to be displayed).
9222:
9223: =cut
9224:
9225: sub assign_category_rows {
9226: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
9227: my ($text,$name,$item,$chgstr);
9228: if (ref($cats) eq 'ARRAY') {
9229: my $maxdepth = scalar(@{$cats});
9230: if (ref($cats->[$depth]) eq 'HASH') {
9231: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
9232: my $numchildren = @{$cats->[$depth]{$parent}};
9233: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9234: $text .= '<td><table class="LC_datatable">';
9235: for (my $j=0; $j<$numchildren; $j++) {
9236: $name = $cats->[$depth]{$parent}[$j];
9237: $item = &escape($name).':'.&escape($parent).':'.$depth;
9238: my $deeper = $depth+1;
9239: my $checked = '';
9240: if (ref($currcategories) eq 'ARRAY') {
9241: if (@{$currcategories} > 0) {
9242: if (grep(/^\Q$item\E$/,@{$currcategories})) {
9243: $checked = ' checked="checked" ';
9244: }
9245: }
9246: }
9247: $text .= '<tr><td><span class="LC_nobreak"><label>'.
9248: '<input type="checkbox" name="usecategory" value="'.
9249: $item.'"'.$checked.' />'.$name.'</label></span>'.
9250: '<input type="hidden" name="catname" value="'.$name.'" />'.
9251: '</td><td>';
9252: if (ref($path) eq 'ARRAY') {
9253: push(@{$path},$name);
9254: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
9255: pop(@{$path});
9256: }
9257: $text .= '</td></tr>';
9258: }
9259: $text .= '</table></td>';
9260: }
9261: }
9262: }
9263: return $text;
9264: }
9265:
9266: ############################################################
9267: ############################################################
9268:
9269:
9270: sub commit_customrole {
9271: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
9272: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
9273: ($start?', '.&mt('starting').' '.localtime($start):'').
9274: ($end?', ending '.localtime($end):'').': <b>'.
9275: &Apache::lonnet::assigncustomrole(
9276: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
9277: '</b><br />';
9278: return $output;
9279: }
9280:
9281: sub commit_standardrole {
9282: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
9283: my ($output,$logmsg,$linefeed);
9284: if ($context eq 'auto') {
9285: $linefeed = "\n";
9286: } else {
9287: $linefeed = "<br />\n";
9288: }
9289: if ($three eq 'st') {
9290: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
9291: $one,$two,$sec,$context);
9292: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
9293: ($result eq 'unknown_course') || ($result eq 'refused')) {
9294: $output = $logmsg.' '.&mt('Error: ').$result."\n";
9295: } else {
9296: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
9297: ($start?', '.&mt('starting').' '.localtime($start):'').
9298: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
9299: if ($context eq 'auto') {
9300: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
9301: } else {
9302: $output .= '<b>'.$result.'</b>'.$linefeed.
9303: &mt('Add to classlist').': <b>ok</b>';
9304: }
9305: $output .= $linefeed;
9306: }
9307: } else {
9308: $output = &mt('Assigning').' '.$three.' in '.$url.
9309: ($start?', '.&mt('starting').' '.localtime($start):'').
9310: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
9311: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
9312: if ($context eq 'auto') {
9313: $output .= $result.$linefeed;
9314: } else {
9315: $output .= '<b>'.$result.'</b>'.$linefeed;
9316: }
9317: }
9318: return $output;
9319: }
9320:
9321: sub commit_studentrole {
9322: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
9323: my ($result,$linefeed,$oldsecurl,$newsecurl);
9324: if ($context eq 'auto') {
9325: $linefeed = "\n";
9326: } else {
9327: $linefeed = '<br />'."\n";
9328: }
9329: if (defined($one) && defined($two)) {
9330: my $cid=$one.'_'.$two;
9331: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
9332: my $secchange = 0;
9333: my $expire_role_result;
9334: my $modify_section_result;
9335: if ($oldsec ne '-1') {
9336: if ($oldsec ne $sec) {
9337: $secchange = 1;
9338: my $now = time;
9339: my $uurl='/'.$cid;
9340: $uurl=~s/\_/\//g;
9341: if ($oldsec) {
9342: $uurl.='/'.$oldsec;
9343: }
9344: $oldsecurl = $uurl;
9345: $expire_role_result =
9346: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
9347: if ($env{'request.course.sec'} ne '') {
9348: if ($expire_role_result eq 'refused') {
9349: my @roles = ('st');
9350: my @statuses = ('previous');
9351: my @roledoms = ($one);
9352: my $withsec = 1;
9353: my %roleshash =
9354: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
9355: \@statuses,\@roles,\@roledoms,$withsec);
9356: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
9357: my ($oldstart,$oldend) =
9358: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
9359: if ($oldend > 0 && $oldend <= $now) {
9360: $expire_role_result = 'ok';
9361: }
9362: }
9363: }
9364: }
9365: $result = $expire_role_result;
9366: }
9367: }
9368: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
9369: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
9370: if ($modify_section_result =~ /^ok/) {
9371: if ($secchange == 1) {
9372: if ($sec eq '') {
9373: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
9374: } else {
9375: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
9376: }
9377: } elsif ($oldsec eq '-1') {
9378: if ($sec eq '') {
9379: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
9380: } else {
9381: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9382: }
9383: } else {
9384: if ($sec eq '') {
9385: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
9386: } else {
9387: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9388: }
9389: }
9390: } else {
9391: if ($secchange) {
9392: $$logmsg .= &mt('Error when attempting section change for [_1] from old section "[_2]" to new section: "[_3]" in course [_4] -error:',$uname,$oldsec,$sec,$cid).' '.$modify_section_result.$linefeed;
9393: } else {
9394: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
9395: }
9396: }
9397: $result = $modify_section_result;
9398: } elsif ($secchange == 1) {
9399: if ($oldsec eq '') {
9400: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
9401: } else {
9402: $$logmsg .= &mt('Error when attempting to expire existing role for [_1] in section [_2] in course [_3] -error: ',$uname,$oldsec,$cid).' '.$expire_role_result.$linefeed;
9403: }
9404: if ($expire_role_result eq 'refused') {
9405: my $newsecurl = '/'.$cid;
9406: $newsecurl =~ s/\_/\//g;
9407: if ($sec ne '') {
9408: $newsecurl.='/'.$sec;
9409: }
9410: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
9411: if ($sec eq '') {
9412: $$logmsg .= &mt('Although your current role has privileges to add students to section "[_1]", you do not have privileges to modify existing enrollments unaffiliated with any section.',$sec).$linefeed;
9413: } else {
9414: $$logmsg .= &mt('Although your current role has privileges to add students to section "[_1]", you do not have privileges to modify existing enrollments in other sections.',$sec).$linefeed;
9415: }
9416: }
9417: }
9418: }
9419: } else {
9420: $$logmsg .= &mt('Incomplete course id defined.').$linefeed.&mt('Addition of user [_1] from domain [_2] to course [_3], section [_4] not completed.',$uname,$udom,$one.'_'.$two,$sec).$linefeed;
9421: $result = "error: incomplete course id\n";
9422: }
9423: return $result;
9424: }
9425:
9426: ############################################################
9427: ############################################################
9428:
9429: sub check_clone {
9430: my ($args,$linefeed) = @_;
9431: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
9432: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
9433: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
9434: my $clonemsg;
9435: my $can_clone = 0;
9436:
9437: if ($clonehome eq 'no_host') {
9438: $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'});
9439: } else {
9440: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
9441: if ($env{'request.role.domain'} eq $args->{'clonedomain'}) {
9442: $can_clone = 1;
9443: } else {
9444: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
9445: $args->{'clonedomain'},$args->{'clonecourse'});
9446: my @cloners = split(/,/,$clonehash{'cloners'});
9447: if (grep(/^\*$/,@cloners)) {
9448: $can_clone = 1;
9449: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
9450: $can_clone = 1;
9451: } else {
9452: my %roleshash =
9453: &Apache::lonnet::get_my_roles($args->{'ccuname'},
9454: $args->{'ccdomain'},
9455: 'userroles',['active'],['cc'],
9456: [$args->{'clonedomain'}]);
9457: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
9458: $can_clone = 1;
9459: } else {
9460: $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'});
9461: }
9462: }
9463: }
9464: }
9465: return ($can_clone, $clonemsg, $cloneid, $clonehome);
9466: }
9467:
9468: sub construct_course {
9469: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context) = @_;
9470: my $outcome;
9471: my $linefeed = '<br />'."\n";
9472: if ($context eq 'auto') {
9473: $linefeed = "\n";
9474: }
9475:
9476: #
9477: # Are we cloning?
9478: #
9479: my ($can_clone, $clonemsg, $cloneid, $clonehome);
9480: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
9481: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
9482: if ($context ne 'auto') {
9483: if ($clonemsg ne '') {
9484: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
9485: }
9486: }
9487: $outcome .= $clonemsg.$linefeed;
9488:
9489: if (!$can_clone) {
9490: return (0,$outcome);
9491: }
9492: }
9493:
9494: #
9495: # Open course
9496: #
9497: my $crstype = lc($args->{'crstype'});
9498: my %cenv=();
9499: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
9500: $args->{'cdescr'},
9501: $args->{'curl'},
9502: $args->{'course_home'},
9503: $args->{'nonstandard'},
9504: $args->{'crscode'},
9505: $args->{'ccuname'}.':'.
9506: $args->{'ccdomain'},
9507: $args->{'crstype'});
9508:
9509: # Note: The testing routines depend on this being output; see
9510: # Utils::Course. This needs to at least be output as a comment
9511: # if anyone ever decides to not show this, and Utils::Course::new
9512: # will need to be suitably modified.
9513: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
9514: #
9515: # Check if created correctly
9516: #
9517: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
9518: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
9519: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
9520:
9521: #
9522: # Do the cloning
9523: #
9524: if ($can_clone && $cloneid) {
9525: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
9526: if ($context ne 'auto') {
9527: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
9528: }
9529: $outcome .= $clonemsg.$linefeed;
9530: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
9531: # Copy all files
9532: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
9533: # Restore URL
9534: $cenv{'url'}=$oldcenv{'url'};
9535: # Restore title
9536: $cenv{'description'}=$oldcenv{'description'};
9537: # Mark as cloned
9538: $cenv{'clonedfrom'}=$cloneid;
9539: # Need to clone grading mode
9540: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
9541: $cenv{'grading'}=$newenv{'grading'};
9542: # Do not clone these environment entries
9543: &Apache::lonnet::del('environment',
9544: ['default_enrollment_start_date',
9545: 'default_enrollment_end_date',
9546: 'question.email',
9547: 'policy.email',
9548: 'comment.email',
9549: 'pch.users.denied',
9550: 'plc.users.denied',
9551: 'hidefromcat',
9552: 'categories'],
9553: $$crsudom,$$crsunum);
9554: }
9555:
9556: #
9557: # Set environment (will override cloned, if existing)
9558: #
9559: my @sections = ();
9560: my @xlists = ();
9561: if ($args->{'crstype'}) {
9562: $cenv{'type'}=$args->{'crstype'};
9563: }
9564: if ($args->{'crsid'}) {
9565: $cenv{'courseid'}=$args->{'crsid'};
9566: }
9567: if ($args->{'crscode'}) {
9568: $cenv{'internal.coursecode'}=$args->{'crscode'};
9569: }
9570: if ($args->{'crsquota'} ne '') {
9571: $cenv{'internal.coursequota'}=$args->{'crsquota'};
9572: } else {
9573: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
9574: }
9575: if ($args->{'ccuname'}) {
9576: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
9577: ':'.$args->{'ccdomain'};
9578: } else {
9579: $cenv{'internal.courseowner'} = $args->{'curruser'};
9580: }
9581: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
9582: if ($args->{'crssections'}) {
9583: $cenv{'internal.sectionnums'} = '';
9584: if ($args->{'crssections'} =~ m/,/) {
9585: @sections = split/,/,$args->{'crssections'};
9586: } else {
9587: $sections[0] = $args->{'crssections'};
9588: }
9589: if (@sections > 0) {
9590: foreach my $item (@sections) {
9591: my ($sec,$gp) = split/:/,$item;
9592: my $class = $args->{'crscode'}.$sec;
9593: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
9594: $cenv{'internal.sectionnums'} .= $item.',';
9595: unless ($addcheck eq 'ok') {
9596: push @badclasses, $class;
9597: }
9598: }
9599: $cenv{'internal.sectionnums'} =~ s/,$//;
9600: }
9601: }
9602: # do not hide course coordinator from staff listing,
9603: # even if privileged
9604: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9605: # add crosslistings
9606: if ($args->{'crsxlist'}) {
9607: $cenv{'internal.crosslistings'}='';
9608: if ($args->{'crsxlist'} =~ m/,/) {
9609: @xlists = split/,/,$args->{'crsxlist'};
9610: } else {
9611: $xlists[0] = $args->{'crsxlist'};
9612: }
9613: if (@xlists > 0) {
9614: foreach my $item (@xlists) {
9615: my ($xl,$gp) = split/:/,$item;
9616: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
9617: $cenv{'internal.crosslistings'} .= $item.',';
9618: unless ($addcheck eq 'ok') {
9619: push @badclasses, $xl;
9620: }
9621: }
9622: $cenv{'internal.crosslistings'} =~ s/,$//;
9623: }
9624: }
9625: if ($args->{'autoadds'}) {
9626: $cenv{'internal.autoadds'}=$args->{'autoadds'};
9627: }
9628: if ($args->{'autodrops'}) {
9629: $cenv{'internal.autodrops'}=$args->{'autodrops'};
9630: }
9631: # check for notification of enrollment changes
9632: my @notified = ();
9633: if ($args->{'notify_owner'}) {
9634: if ($args->{'ccuname'} ne '') {
9635: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
9636: }
9637: }
9638: if ($args->{'notify_dc'}) {
9639: if ($uname ne '') {
9640: push(@notified,$uname.':'.$udom);
9641: }
9642: }
9643: if (@notified > 0) {
9644: my $notifylist;
9645: if (@notified > 1) {
9646: $notifylist = join(',',@notified);
9647: } else {
9648: $notifylist = $notified[0];
9649: }
9650: $cenv{'internal.notifylist'} = $notifylist;
9651: }
9652: if (@badclasses > 0) {
9653: my %lt=&Apache::lonlocal::texthash(
9654: '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',
9655: 'dnhr' => 'does not have rights to access enrollment in these classes',
9656: 'adby' => 'as determined by the policies of your institution on access to official classlists'
9657: );
9658: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
9659: ' ('.$lt{'adby'}.')';
9660: if ($context eq 'auto') {
9661: $outcome .= $badclass_msg.$linefeed;
9662: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
9663: foreach my $item (@badclasses) {
9664: if ($context eq 'auto') {
9665: $outcome .= " - $item\n";
9666: } else {
9667: $outcome .= "<li>$item</li>\n";
9668: }
9669: }
9670: if ($context eq 'auto') {
9671: $outcome .= $linefeed;
9672: } else {
9673: $outcome .= "</ul><br /><br /></div>\n";
9674: }
9675: }
9676: }
9677: if ($args->{'no_end_date'}) {
9678: $args->{'endaccess'} = 0;
9679: }
9680: $cenv{'internal.autostart'}=$args->{'enrollstart'};
9681: $cenv{'internal.autoend'}=$args->{'enrollend'};
9682: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
9683: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
9684: if ($args->{'showphotos'}) {
9685: $cenv{'internal.showphotos'}=$args->{'showphotos'};
9686: }
9687: $cenv{'internal.authtype'} = $args->{'authtype'};
9688: $cenv{'internal.autharg'} = $args->{'autharg'};
9689: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
9690: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
9691: 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');
9692: if ($context eq 'auto') {
9693: $outcome .= $krb_msg;
9694: } else {
9695: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
9696: }
9697: $outcome .= $linefeed;
9698: }
9699: }
9700: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
9701: if ($args->{'setpolicy'}) {
9702: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9703: }
9704: if ($args->{'setcontent'}) {
9705: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9706: }
9707: }
9708: if ($args->{'reshome'}) {
9709: $cenv{'reshome'}=$args->{'reshome'}.'/';
9710: $cenv{'reshome'}=~s/\/+$/\//;
9711: }
9712: #
9713: # course has keyed access
9714: #
9715: if ($args->{'setkeys'}) {
9716: $cenv{'keyaccess'}='yes';
9717: }
9718: # if specified, key authority is not course, but user
9719: # only active if keyaccess is yes
9720: if ($args->{'keyauth'}) {
9721: my ($user,$domain) = split(':',$args->{'keyauth'});
9722: $user = &LONCAPA::clean_username($user);
9723: $domain = &LONCAPA::clean_username($domain);
9724: if ($user ne '' && $domain ne '') {
9725: $cenv{'keyauth'}=$user.':'.$domain;
9726: }
9727: }
9728:
9729: if ($args->{'disresdis'}) {
9730: $cenv{'pch.roles.denied'}='st';
9731: }
9732: if ($args->{'disablechat'}) {
9733: $cenv{'plc.roles.denied'}='st';
9734: }
9735:
9736: # Record we've not yet viewed the Course Initialization Helper for this
9737: # course
9738: $cenv{'course.helper.not.run'} = 1;
9739: #
9740: # Use new Randomseed
9741: #
9742: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
9743: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
9744: #
9745: # The encryption code and receipt prefix for this course
9746: #
9747: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
9748: $cenv{'internal.encpref'}=100+int(9*rand(99));
9749: #
9750: # By default, use standard grading
9751: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
9752:
9753: $outcome .= $linefeed.&mt('Setting environment').': '.
9754: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
9755: #
9756: # Open all assignments
9757: #
9758: if ($args->{'openall'}) {
9759: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
9760: my %storecontent = ($storeunder => time,
9761: $storeunder.'.type' => 'date_start');
9762:
9763: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
9764: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
9765: }
9766: #
9767: # Set first page
9768: #
9769: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
9770: || ($cloneid)) {
9771: use LONCAPA::map;
9772: $outcome .= &mt('Setting first resource').': ';
9773:
9774: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
9775: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
9776:
9777: $outcome .= ($fatal?$errtext:'read ok').' - ';
9778: my $title; my $url;
9779: if ($args->{'firstres'} eq 'syl') {
9780: $title=&mt('Syllabus');
9781: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
9782: } else {
9783: $title=&mt('Navigate Contents');
9784: $url='/adm/navmaps';
9785: }
9786:
9787: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
9788: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
9789:
9790: if ($errtext) { $fatal=2; }
9791: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
9792: }
9793:
9794: return (1,$outcome);
9795: }
9796:
9797: ############################################################
9798: ############################################################
9799:
9800: sub course_type {
9801: my ($cid) = @_;
9802: if (!defined($cid)) {
9803: $cid = $env{'request.course.id'};
9804: }
9805: if (defined($env{'course.'.$cid.'.type'})) {
9806: return $env{'course.'.$cid.'.type'};
9807: } else {
9808: return 'Course';
9809: }
9810: }
9811:
9812: sub group_term {
9813: my $crstype = &course_type();
9814: my %names = (
9815: 'Course' => 'group',
9816: 'Group' => 'team',
9817: );
9818: return $names{$crstype};
9819: }
9820:
9821: sub icon {
9822: my ($file)=@_;
9823: my $curfext = lc((split(/\./,$file))[-1]);
9824: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
9825: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
9826: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
9827: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
9828: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
9829: $curfext.".gif") {
9830: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
9831: $curfext.".gif";
9832: }
9833: }
9834: return &lonhttpdurl($iconname);
9835: }
9836:
9837: sub lonhttpdurl {
9838: #
9839: # Had been used for "small fry" static images on separate port 8080.
9840: # Modify here if lightweight http functionality desired again.
9841: # Currently eliminated due to increasing firewall issues.
9842: #
9843: my ($url)=@_;
9844: return $url;
9845: }
9846:
9847: sub connection_aborted {
9848: my ($r)=@_;
9849: $r->print(" ");$r->rflush();
9850: my $c = $r->connection;
9851: return $c->aborted();
9852: }
9853:
9854: # Escapes strings that may have embedded 's that will be put into
9855: # strings as 'strings'.
9856: sub escape_single {
9857: my ($input) = @_;
9858: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
9859: $input =~ s/\'/\\\'/g; # Esacpe the 's....
9860: return $input;
9861: }
9862:
9863: # Same as escape_single, but escape's "'s This
9864: # can be used for "strings"
9865: sub escape_double {
9866: my ($input) = @_;
9867: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
9868: $input =~ s/\"/\\\"/g; # Esacpe the "s....
9869: return $input;
9870: }
9871:
9872: # Escapes the last element of a full URL.
9873: sub escape_url {
9874: my ($url) = @_;
9875: my @urlslices = split(/\//, $url,-1);
9876: my $lastitem = &escape(pop(@urlslices));
9877: return join('/',@urlslices).'/'.$lastitem;
9878: }
9879:
9880: # -------------------------------------------------------- Initliaze user login
9881: sub init_user_environment {
9882: my ($r, $username, $domain, $authhost, $form, $args) = @_;
9883: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
9884:
9885: my $public=($username eq 'public' && $domain eq 'public');
9886:
9887: # See if old ID present, if so, remove
9888:
9889: my ($filename,$cookie,$userroles);
9890: my $now=time;
9891:
9892: if ($public) {
9893: my $max_public=100;
9894: my $oldest;
9895: my $oldest_time=0;
9896: for(my $next=1;$next<=$max_public;$next++) {
9897: if (-e $lonids."/publicuser_$next.id") {
9898: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
9899: if ($mtime<$oldest_time || !$oldest_time) {
9900: $oldest_time=$mtime;
9901: $oldest=$next;
9902: }
9903: } else {
9904: $cookie="publicuser_$next";
9905: last;
9906: }
9907: }
9908: if (!$cookie) { $cookie="publicuser_$oldest"; }
9909: } else {
9910: # if this isn't a robot, kill any existing non-robot sessions
9911: if (!$args->{'robot'}) {
9912: opendir(DIR,$lonids);
9913: while ($filename=readdir(DIR)) {
9914: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
9915: unlink($lonids.'/'.$filename);
9916: }
9917: }
9918: closedir(DIR);
9919: }
9920: # Give them a new cookie
9921: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
9922: : $now.$$.int(rand(10000)));
9923: $cookie="$username\_$id\_$domain\_$authhost";
9924:
9925: # Initialize roles
9926:
9927: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
9928: }
9929: # ------------------------------------ Check browser type and MathML capability
9930:
9931: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
9932: $clientunicode,$clientos) = &decode_user_agent($r);
9933:
9934: # -------------------------------------- Any accessibility options to remember?
9935: if (($form->{'interface'}) && ($form->{'remember'} eq 'true')) {
9936: foreach my $option ('imagesuppress','appletsuppress',
9937: 'embedsuppress','fontenhance','blackwhite') {
9938: if ($form->{$option} eq 'true') {
9939: &Apache::lonnet::put('environment',{$option => 'on'},
9940: $domain,$username);
9941: } else {
9942: &Apache::lonnet::del('environment',[$option],
9943: $domain,$username);
9944: }
9945: }
9946: }
9947: # ------------------------------------------------------------- Get environment
9948:
9949: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
9950: my ($tmp) = keys(%userenv);
9951: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9952: # default remote control to off
9953: if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
9954: } else {
9955: undef(%userenv);
9956: }
9957: if (($userenv{'interface'}) && (!$form->{'interface'})) {
9958: $form->{'interface'}=$userenv{'interface'};
9959: }
9960: $env{'environment.remote'}=$userenv{'remote'};
9961: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
9962:
9963: # --------------- Do not trust query string to be put directly into environment
9964: foreach my $option ('imagesuppress','appletsuppress',
9965: 'embedsuppress','fontenhance','blackwhite',
9966: 'interface','localpath','localres') {
9967: $form->{$option}=~s/[\n\r\=]//gs;
9968: }
9969: # --------------------------------------------------------- Write first profile
9970:
9971: {
9972: my %initial_env =
9973: ("user.name" => $username,
9974: "user.domain" => $domain,
9975: "user.home" => $authhost,
9976: "browser.type" => $clientbrowser,
9977: "browser.version" => $clientversion,
9978: "browser.mathml" => $clientmathml,
9979: "browser.unicode" => $clientunicode,
9980: "browser.os" => $clientos,
9981: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
9982: "request.course.fn" => '',
9983: "request.course.uri" => '',
9984: "request.course.sec" => '',
9985: "request.role" => 'cm',
9986: "request.role.adv" => $env{'user.adv'},
9987: "request.host" => $ENV{'REMOTE_ADDR'},);
9988:
9989: if ($form->{'localpath'}) {
9990: $initial_env{"browser.localpath"} = $form->{'localpath'};
9991: $initial_env{"browser.localres"} = $form->{'localres'};
9992: }
9993:
9994: if ($public) {
9995: $initial_env{"environment.remote"} = "off";
9996: }
9997: if ($form->{'interface'}) {
9998: $form->{'interface'}=~s/\W//gs;
9999: $initial_env{"browser.interface"} = $form->{'interface'};
10000: $env{'browser.interface'}=$form->{'interface'};
10001: foreach my $option ('imagesuppress','appletsuppress',
10002: 'embedsuppress','fontenhance','blackwhite') {
10003: if (($form->{$option} eq 'true') ||
10004: ($userenv{$option} eq 'on')) {
10005: $initial_env{"browser.$option"} = "on";
10006: }
10007: }
10008: }
10009:
10010: foreach my $tool ('aboutme','blog','portfolio') {
10011: $userenv{'availabletools.'.$tool} =
10012: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload');
10013: }
10014:
10015: $env{'user.environment'} = "$lonids/$cookie.id";
10016:
10017: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
10018: &GDBM_WRCREAT(),0640)) {
10019: &_add_to_env(\%disk_env,\%initial_env);
10020: &_add_to_env(\%disk_env,\%userenv,'environment.');
10021: &_add_to_env(\%disk_env,$userroles);
10022: if (ref($args->{'extra_env'})) {
10023: &_add_to_env(\%disk_env,$args->{'extra_env'});
10024: }
10025: untie(%disk_env);
10026: } else {
10027: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
10028: 'Could not create environment storage in lonauth: '.$!.'</span>');
10029: return 'error: '.$!;
10030: }
10031: }
10032: $env{'request.role'}='cm';
10033: $env{'request.role.adv'}=$env{'user.adv'};
10034: $env{'browser.type'}=$clientbrowser;
10035:
10036: return $cookie;
10037:
10038: }
10039:
10040: sub _add_to_env {
10041: my ($idf,$env_data,$prefix) = @_;
10042: if (ref($env_data) eq 'HASH') {
10043: while (my ($key,$value) = each(%$env_data)) {
10044: $idf->{$prefix.$key} = $value;
10045: $env{$prefix.$key} = $value;
10046: }
10047: }
10048: }
10049:
10050: # --- Get the symbolic name of a problem and the url
10051: sub get_symb {
10052: my ($request,$silent) = @_;
10053: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
10054: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
10055: if ($symb eq '') {
10056: if (!$silent) {
10057: $request->print("Unable to handle ambiguous references:$url:.");
10058: return ();
10059: }
10060: }
10061: &Apache::lonenc::check_decrypt(\$symb);
10062: return ($symb);
10063: }
10064:
10065: # --------------------------------------------------------------Get annotation
10066:
10067: sub get_annotation {
10068: my ($symb,$enc) = @_;
10069:
10070: my $key = $symb;
10071: if (!$enc) {
10072: $key =
10073: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
10074: }
10075: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
10076: return $annotation{$key};
10077: }
10078:
10079: sub clean_symb {
10080: my ($symb,$delete_enc) = @_;
10081:
10082: &Apache::lonenc::check_decrypt(\$symb);
10083: my $enc = $env{'request.enc'};
10084: if ($delete_enc) {
10085: delete($env{'request.enc'});
10086: }
10087:
10088: return ($symb,$enc);
10089: }
10090:
10091: =pod
10092:
10093: =back
10094:
10095: =cut
10096:
10097: 1;
10098: __END__;
10099:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>