File:
[LON-CAPA] /
loncom /
interface /
loncommon.pm
Revision
1.742:
download - view:
text,
annotated -
select for diffs
Thu Feb 5 00:45:29 2009 UTC (15 years, 8 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
- Move &user_lang() from lonmsg.pm to loncommon.pm so it is more generally available.
- This routine is used to get a language handle object from Locale::Maketext for a user different to the current session user.
1: # The LearningOnline Network with CAPA
2: # a pile of common routines
3: #
4: # $Id: loncommon.pm,v 1.742 2009/02/05 00:45:29 raeburn Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: # Makes a table out of the previous attempts
30: # Inputs result_from_symbread, user, domain, course_id
31: # Reads in non-network-related .tab files
32:
33: # POD header:
34:
35: =pod
36:
37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
45:
46: =head1 OVERVIEW
47:
48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
55: package Apache::loncommon;
56:
57: use strict;
58: use Apache::lonnet;
59: use GDBM_File;
60: use POSIX qw(strftime mktime);
61: use Apache::lonmenu();
62: use Apache::lonenc();
63: use Apache::lonlocal;
64: use 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 .=
928: "<table bgcolor='#3333AA' cellspacing='1' cellpadding='1' border='0'><tr>".
929: "<td bgcolor='#5555FF'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
930: }
931:
932: # Add the graphic
933: my $title = &mt('Online Help');
934: my $helpicon=&lonhttpdurl("/adm/help/help.png");
935: $template .= <<"ENDTEMPLATE";
936: <a target="_top" href="$link" title="$title"><img src="$helpicon" border="0" alt="(Help: $topic)" /></a>
937: ENDTEMPLATE
938: if ($text ne '') { $template.='</td></tr></table>' };
939: return $template;
940:
941: }
942:
943: # This is a quicky function for Latex cheatsheet editing, since it
944: # appears in at least four places
945: sub helpLatexCheatsheet {
946: my ($topic,$text,$not_author) = @_;
947: my $out;
948: my $addOther = '';
949: if ($topic) {
950: $addOther = &Apache::loncommon::help_open_topic($topic,$text,
951: undef, undef, 600).
952: '</td><td>';
953: }
954: $out = '<table><tr><td>'.
955: $addOther .
956: &Apache::loncommon::help_open_topic("Greek_Symbols",&mt('Greek Symbols'),
957: undef,undef,600).
958: '</td><td>'.
959: &Apache::loncommon::help_open_topic("Other_Symbols",&mt('Other Symbols'),
960: undef,undef,600).
961: '</td>';
962: unless ($not_author) {
963: $out .= '<td>'.
964: &Apache::loncommon::help_open_topic("Authoring_Output_Tags",&mt('Output Tags'),
965: undef,undef,600).
966: '</td>';
967: }
968: $out .= '</tr></table>';
969: return $out;
970: }
971:
972: sub general_help {
973: my $helptopic='Student_Intro';
974: if ($env{'request.role'}=~/^(ca|au)/) {
975: $helptopic='Authoring_Intro';
976: } elsif ($env{'request.role'}=~/^cc/) {
977: $helptopic='Course_Coordination_Intro';
978: } elsif ($env{'request.role'}=~/^dc/) {
979: $helptopic='Domain_Coordination_Intro';
980: }
981: return $helptopic;
982: }
983:
984: sub update_help_link {
985: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
986: my $origurl = $ENV{'REQUEST_URI'};
987: $origurl=~s|^/~|/priv/|;
988: my $timestamp = time;
989: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
990: $$datum = &escape($$datum);
991: }
992:
993: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
994: my $output .= <<"ENDOUTPUT";
995: <script type="text/javascript">
996: banner_link = '$banner_link';
997: </script>
998: ENDOUTPUT
999: return $output;
1000: }
1001:
1002: # now just updates the help link and generates a blue icon
1003: sub help_open_menu {
1004: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1005: = @_;
1006: $stayOnPage = 0 if (not defined $stayOnPage);
1007: # only use pop-up help (stayOnPage == 0)
1008: # if environment.remote is on (using remote control UI)
1009: if ($env{'browser.interface'} eq 'textual' ||
1010: $env{'environment.remote'} eq 'off' ) {
1011: $stayOnPage=1;
1012: }
1013: my $output;
1014: if ($component_help) {
1015: if (!$text) {
1016: $output=&help_open_topic($component_help,undef,$stayOnPage,
1017: $width,$height);
1018: } else {
1019: my $help_text;
1020: $help_text=&unescape($topic);
1021: $output='<table><tr><td>'.
1022: &help_open_topic($component_help,$help_text,$stayOnPage,
1023: $width,$height).'</td></tr></table>';
1024: }
1025: }
1026: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1027: return $output.$banner_link;
1028: }
1029:
1030: sub top_nav_help {
1031: my ($text) = @_;
1032: $text = &mt($text);
1033: my $stay_on_page =
1034: ($env{'browser.interface'} eq 'textual' ||
1035: $env{'environment.remote'} eq 'off' );
1036: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1037: : "javascript:helpMenu('open')";
1038: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1039:
1040: my $title = &mt('Get help');
1041:
1042: return <<"END";
1043: $banner_link
1044: <a href="$link" title="$title">$text</a>
1045: END
1046: }
1047:
1048: sub help_menu_js {
1049: my ($text) = @_;
1050:
1051: my $stayOnPage =
1052: ($env{'browser.interface'} eq 'textual' ||
1053: $env{'environment.remote'} eq 'off' );
1054:
1055: my $width = 620;
1056: my $height = 600;
1057: my $helptopic=&general_help();
1058: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1059: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1060: my $start_page =
1061: &Apache::loncommon::start_page('Help Menu', undef,
1062: {'frameset' => 1,
1063: 'js_ready' => 1,
1064: 'add_entries' => {
1065: 'border' => '0',
1066: 'rows' => "110,*",},});
1067: my $end_page =
1068: &Apache::loncommon::end_page({'frameset' => 1,
1069: 'js_ready' => 1,});
1070:
1071: my $template .= <<"ENDTEMPLATE";
1072: <script type="text/javascript">
1073: // <!-- BEGIN LON-CAPA Internal
1074: // <![CDATA[
1075: var banner_link = '';
1076: function helpMenu(target) {
1077: var caller = this;
1078: if (target == 'open') {
1079: var newWindow = null;
1080: try {
1081: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1082: }
1083: catch(error) {
1084: writeHelp(caller);
1085: return;
1086: }
1087: if (newWindow) {
1088: caller = newWindow;
1089: }
1090: }
1091: writeHelp(caller);
1092: return;
1093: }
1094: function writeHelp(caller) {
1095: caller.document.writeln('$start_page<frame name="bannerframe" src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1096: caller.document.close()
1097: caller.focus()
1098: }
1099: // ]]>
1100: // END LON-CAPA Internal -->
1101: </script>
1102: ENDTEMPLATE
1103: return $template;
1104: }
1105:
1106: sub help_open_bug {
1107: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1108: unless ($env{'user.adv'}) { return ''; }
1109: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1110: $text = "" if (not defined $text);
1111: $stayOnPage = 0 if (not defined $stayOnPage);
1112: if ($env{'browser.interface'} eq 'textual' ||
1113: $env{'environment.remote'} eq 'off' ) {
1114: $stayOnPage=1;
1115: }
1116: $width = 600 if (not defined $width);
1117: $height = 600 if (not defined $height);
1118:
1119: $topic=~s/\W+/\+/g;
1120: my $link='';
1121: my $template='';
1122: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1123: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1124: if (!$stayOnPage)
1125: {
1126: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1127: }
1128: else
1129: {
1130: $link = $url;
1131: }
1132: # Add the text
1133: if ($text ne "")
1134: {
1135: $template .=
1136: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1137: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1138: }
1139:
1140: # Add the graphic
1141: my $title = &mt('Report a Bug');
1142: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1143: $template .= <<"ENDTEMPLATE";
1144: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1145: ENDTEMPLATE
1146: if ($text ne '') { $template.='</td></tr></table>' };
1147: return $template;
1148:
1149: }
1150:
1151: sub help_open_faq {
1152: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1153: unless ($env{'user.adv'}) { return ''; }
1154: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1155: $text = "" if (not defined $text);
1156: $stayOnPage = 0 if (not defined $stayOnPage);
1157: if ($env{'browser.interface'} eq 'textual' ||
1158: $env{'environment.remote'} eq 'off' ) {
1159: $stayOnPage=1;
1160: }
1161: $width = 350 if (not defined $width);
1162: $height = 400 if (not defined $height);
1163:
1164: $topic=~s/\W+/\+/g;
1165: my $link='';
1166: my $template='';
1167: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1168: if (!$stayOnPage)
1169: {
1170: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1171: }
1172: else
1173: {
1174: $link = $url;
1175: }
1176:
1177: # Add the text
1178: if ($text ne "")
1179: {
1180: $template .=
1181: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1182: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1183: }
1184:
1185: # Add the graphic
1186: my $title = &mt('View the FAQ');
1187: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1188: $template .= <<"ENDTEMPLATE";
1189: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1190: ENDTEMPLATE
1191: if ($text ne '') { $template.='</td></tr></table>' };
1192: return $template;
1193:
1194: }
1195:
1196: ###############################################################
1197: ###############################################################
1198:
1199: =pod
1200:
1201: =item * &change_content_javascript():
1202:
1203: This and the next function allow you to create small sections of an
1204: otherwise static HTML page that you can update on the fly with
1205: Javascript, even in Netscape 4.
1206:
1207: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1208: must be written to the HTML page once. It will prove the Javascript
1209: function "change(name, content)". Calling the change function with the
1210: name of the section
1211: you want to update, matching the name passed to C<changable_area>, and
1212: the new content you want to put in there, will put the content into
1213: that area.
1214:
1215: B<Note>: Netscape 4 only reserves enough space for the changable area
1216: to contain room for the original contents. You need to "make space"
1217: for whatever changes you wish to make, and be B<sure> to check your
1218: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1219: it's adequate for updating a one-line status display, but little more.
1220: This script will set the space to 100% width, so you only need to
1221: worry about height in Netscape 4.
1222:
1223: Modern browsers are much less limiting, and if you can commit to the
1224: user not using Netscape 4, this feature may be used freely with
1225: pretty much any HTML.
1226:
1227: =cut
1228:
1229: sub change_content_javascript {
1230: # If we're on Netscape 4, we need to use Layer-based code
1231: if ($env{'browser.type'} eq 'netscape' &&
1232: $env{'browser.version'} =~ /^4\./) {
1233: return (<<NETSCAPE4);
1234: function change(name, content) {
1235: doc = document.layers[name+"___escape"].layers[0].document;
1236: doc.open();
1237: doc.write(content);
1238: doc.close();
1239: }
1240: NETSCAPE4
1241: } else {
1242: # Otherwise, we need to use semi-standards-compliant code
1243: # (technically, "innerHTML" isn't standard but the equivalent
1244: # is really scary, and every useful browser supports it
1245: return (<<DOMBASED);
1246: function change(name, content) {
1247: element = document.getElementById(name);
1248: element.innerHTML = content;
1249: }
1250: DOMBASED
1251: }
1252: }
1253:
1254: =pod
1255:
1256: =item * &changable_area($name,$origContent):
1257:
1258: This provides a "changable area" that can be modified on the fly via
1259: the Javascript code provided in C<change_content_javascript>. $name is
1260: the name you will use to reference the area later; do not repeat the
1261: same name on a given HTML page more then once. $origContent is what
1262: the area will originally contain, which can be left blank.
1263:
1264: =cut
1265:
1266: sub changable_area {
1267: my ($name, $origContent) = @_;
1268:
1269: if ($env{'browser.type'} eq 'netscape' &&
1270: $env{'browser.version'} =~ /^4\./) {
1271: # If this is netscape 4, we need to use the Layer tag
1272: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1273: } else {
1274: return "<span id='$name'>$origContent</span>";
1275: }
1276: }
1277:
1278: =pod
1279:
1280: =item * &viewport_geometry_js
1281:
1282: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1283:
1284: =cut
1285:
1286:
1287: sub viewport_geometry_js {
1288: return <<"GEOMETRY";
1289: var Geometry = {};
1290: function init_geometry() {
1291: if (Geometry.init) { return };
1292: Geometry.init=1;
1293: if (window.innerHeight) {
1294: Geometry.getViewportHeight = function() { return window.innerHeight; };
1295: Geometry.getViewportWidth = function() { return window.innerWidth; };
1296: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1297: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1298: }
1299: else if (document.documentElement && document.documentElement.clientHeight) {
1300: Geometry.getViewportHeight =
1301: function() { return document.documentElement.clientHeight; };
1302: Geometry.getViewportWidth =
1303: function() { return document.documentElement.clientWidth; };
1304:
1305: Geometry.getHorizontalScroll =
1306: function() { return document.documentElement.scrollLeft; };
1307: Geometry.getVerticalScroll =
1308: function() { return document.documentElement.scrollTop; };
1309: }
1310: else if (document.body.clientHeight) {
1311: Geometry.getViewportHeight =
1312: function() { return document.body.clientHeight; };
1313: Geometry.getViewportWidth =
1314: function() { return document.body.clientWidth; };
1315: Geometry.getHorizontalScroll =
1316: function() { return document.body.scrollLeft; };
1317: Geometry.getVerticalScroll =
1318: function() { return document.body.scrollTop; };
1319: }
1320: }
1321:
1322: GEOMETRY
1323: }
1324:
1325: =pod
1326:
1327: =item * &viewport_size_js()
1328:
1329: 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.
1330:
1331: =cut
1332:
1333: sub viewport_size_js {
1334: my $geometry = &viewport_geometry_js();
1335: return <<"DIMS";
1336:
1337: $geometry
1338:
1339: function getViewportDims(width,height) {
1340: init_geometry();
1341: width.value = Geometry.getViewportWidth();
1342: height.value = Geometry.getViewportHeight();
1343: return;
1344: }
1345:
1346: DIMS
1347: }
1348:
1349: =pod
1350:
1351: =item * &resize_textarea_js()
1352:
1353: emits the needed javascript to resize a textarea to be as big as possible
1354:
1355: creates a function resize_textrea that takes two IDs first should be
1356: the id of the element to resize, second should be the id of a div that
1357: surrounds everything that comes after the textarea, this routine needs
1358: to be attached to the <body> for the onload and onresize events.
1359:
1360: =back
1361:
1362: =cut
1363:
1364: sub resize_textarea_js {
1365: my $geometry = &viewport_geometry_js();
1366: return <<"RESIZE";
1367: <script type="text/javascript">
1368: $geometry
1369:
1370: function getX(element) {
1371: var x = 0;
1372: while (element) {
1373: x += element.offsetLeft;
1374: element = element.offsetParent;
1375: }
1376: return x;
1377: }
1378: function getY(element) {
1379: var y = 0;
1380: while (element) {
1381: y += element.offsetTop;
1382: element = element.offsetParent;
1383: }
1384: return y;
1385: }
1386:
1387:
1388: function resize_textarea(textarea_id,bottom_id) {
1389: init_geometry();
1390: var textarea = document.getElementById(textarea_id);
1391: //alert(textarea);
1392:
1393: var textarea_top = getY(textarea);
1394: var textarea_height = textarea.offsetHeight;
1395: var bottom = document.getElementById(bottom_id);
1396: var bottom_top = getY(bottom);
1397: var bottom_height = bottom.offsetHeight;
1398: var window_height = Geometry.getViewportHeight();
1399: var fudge = 23;
1400: var new_height = window_height-fudge-textarea_top-bottom_height;
1401: if (new_height < 300) {
1402: new_height = 300;
1403: }
1404: textarea.style.height=new_height+'px';
1405: }
1406: </script>
1407: RESIZE
1408:
1409: }
1410:
1411: =pod
1412:
1413: =head1 Excel and CSV file utility routines
1414:
1415: =over 4
1416:
1417: =cut
1418:
1419: ###############################################################
1420: ###############################################################
1421:
1422: =pod
1423:
1424: =item * &csv_translate($text)
1425:
1426: Translate $text to allow it to be output as a 'comma separated values'
1427: format.
1428:
1429: =cut
1430:
1431: ###############################################################
1432: ###############################################################
1433: sub csv_translate {
1434: my $text = shift;
1435: $text =~ s/\"/\"\"/g;
1436: $text =~ s/\n/ /g;
1437: return $text;
1438: }
1439:
1440: ###############################################################
1441: ###############################################################
1442:
1443: =pod
1444:
1445: =item * &define_excel_formats()
1446:
1447: Define some commonly used Excel cell formats.
1448:
1449: Currently supported formats:
1450:
1451: =over 4
1452:
1453: =item header
1454:
1455: =item bold
1456:
1457: =item h1
1458:
1459: =item h2
1460:
1461: =item h3
1462:
1463: =item h4
1464:
1465: =item i
1466:
1467: =item date
1468:
1469: =back
1470:
1471: Inputs: $workbook
1472:
1473: Returns: $format, a hash reference.
1474:
1475: =cut
1476:
1477: ###############################################################
1478: ###############################################################
1479: sub define_excel_formats {
1480: my ($workbook) = @_;
1481: my $format;
1482: $format->{'header'} = $workbook->add_format(bold => 1,
1483: bottom => 1,
1484: align => 'center');
1485: $format->{'bold'} = $workbook->add_format(bold=>1);
1486: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1487: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1488: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1489: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1490: $format->{'i'} = $workbook->add_format(italic=>1);
1491: $format->{'date'} = $workbook->add_format(num_format=>
1492: 'mm/dd/yyyy hh:mm:ss');
1493: return $format;
1494: }
1495:
1496: ###############################################################
1497: ###############################################################
1498:
1499: =pod
1500:
1501: =item * &create_workbook()
1502:
1503: Create an Excel worksheet. If it fails, output message on the
1504: request object and return undefs.
1505:
1506: Inputs: Apache request object
1507:
1508: Returns (undef) on failure,
1509: Excel worksheet object, scalar with filename, and formats
1510: from &Apache::loncommon::define_excel_formats on success
1511:
1512: =cut
1513:
1514: ###############################################################
1515: ###############################################################
1516: sub create_workbook {
1517: my ($r) = @_;
1518: #
1519: # Create the excel spreadsheet
1520: my $filename = '/prtspool/'.
1521: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1522: time.'_'.rand(1000000000).'.xls';
1523: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1524: if (! defined($workbook)) {
1525: $r->log_error("Error creating excel spreadsheet $filename: $!");
1526: $r->print('<p>'.&mt("Unable to create new Excel file. ".
1527: "This error has been logged. ".
1528: "Please alert your LON-CAPA administrator").
1529: '</p>');
1530: return (undef);
1531: }
1532: #
1533: $workbook->set_tempdir('/home/httpd/perl/tmp');
1534: #
1535: my $format = &Apache::loncommon::define_excel_formats($workbook);
1536: return ($workbook,$filename,$format);
1537: }
1538:
1539: ###############################################################
1540: ###############################################################
1541:
1542: =pod
1543:
1544: =item * &create_text_file()
1545:
1546: Create a file to write to and eventually make available to the user.
1547: If file creation fails, outputs an error message on the request object and
1548: return undefs.
1549:
1550: Inputs: Apache request object, and file suffix
1551:
1552: Returns (undef) on failure,
1553: Filehandle and filename on success.
1554:
1555: =cut
1556:
1557: ###############################################################
1558: ###############################################################
1559: sub create_text_file {
1560: my ($r,$suffix) = @_;
1561: if (! defined($suffix)) { $suffix = 'txt'; };
1562: my $fh;
1563: my $filename = '/prtspool/'.
1564: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1565: time.'_'.rand(1000000000).'.'.$suffix;
1566: $fh = Apache::File->new('>/home/httpd'.$filename);
1567: if (! defined($fh)) {
1568: $r->log_error("Couldn't open $filename for output $!");
1569: $r->print(&mt('Problems occurred in creating the output file. '
1570: .'This error has been logged. '
1571: .'Please alert your LON-CAPA administrator.'));
1572: }
1573: return ($fh,$filename)
1574: }
1575:
1576:
1577: =pod
1578:
1579: =back
1580:
1581: =cut
1582:
1583: ###############################################################
1584: ## Home server <option> list generating code ##
1585: ###############################################################
1586:
1587: # ------------------------------------------
1588:
1589: sub domain_select {
1590: my ($name,$value,$multiple)=@_;
1591: my %domains=map {
1592: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1593: } &Apache::lonnet::all_domains();
1594: if ($multiple) {
1595: $domains{''}=&mt('Any domain');
1596: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1597: return &multiple_select_form($name,$value,4,\%domains);
1598: } else {
1599: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1600: return &select_form($name,$value,%domains);
1601: }
1602: }
1603:
1604: #-------------------------------------------
1605:
1606: =pod
1607:
1608: =head1 Routines for form select boxes
1609:
1610: =over 4
1611:
1612: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1613:
1614: Returns a string containing a <select> element int multiple mode
1615:
1616:
1617: Args:
1618: $name - name of the <select> element
1619: $value - scalar or array ref of values that should already be selected
1620: $size - number of rows long the select element is
1621: $hash - the elements should be 'option' => 'shown text'
1622: (shown text should already have been &mt())
1623: $order - (optional) array ref of the order to show the elements in
1624:
1625: =cut
1626:
1627: #-------------------------------------------
1628: sub multiple_select_form {
1629: my ($name,$value,$size,$hash,$order)=@_;
1630: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1631: my $output='';
1632: if (! defined($size)) {
1633: $size = 4;
1634: if (scalar(keys(%$hash))<4) {
1635: $size = scalar(keys(%$hash));
1636: }
1637: }
1638: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1639: my @order;
1640: if (ref($order) eq 'ARRAY') {
1641: @order = @{$order};
1642: } else {
1643: @order = sort(keys(%$hash));
1644: }
1645: if (exists($$hash{'select_form_order'})) {
1646: @order = @{$$hash{'select_form_order'}};
1647: }
1648:
1649: foreach my $key (@order) {
1650: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1651: $output.='selected="selected" ' if ($selected{$key});
1652: $output.='>'.$hash->{$key}."</option>\n";
1653: }
1654: $output.="</select>\n";
1655: return $output;
1656: }
1657:
1658: #-------------------------------------------
1659:
1660: =pod
1661:
1662: =item * &select_form($defdom,$name,%hash)
1663:
1664: Returns a string containing a <select name='$name' size='1'> form to
1665: allow a user to select options from a hash option_name => displayed text.
1666: See lonrights.pm for an example invocation and use.
1667:
1668: =cut
1669:
1670: #-------------------------------------------
1671: sub select_form {
1672: my ($def,$name,%hash) = @_;
1673: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1674: my @keys;
1675: if (exists($hash{'select_form_order'})) {
1676: @keys=@{$hash{'select_form_order'}};
1677: } else {
1678: @keys=sort(keys(%hash));
1679: }
1680: foreach my $key (@keys) {
1681: $selectform.=
1682: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
1683: ($key eq $def ? 'selected="selected" ' : '').
1684: ">".&mt($hash{$key})."</option>\n";
1685: }
1686: $selectform.="</select>";
1687: return $selectform;
1688: }
1689:
1690: # For display filters
1691:
1692: sub display_filter {
1693: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1694: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1695: return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1696: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
1697: (&mt('all'),10,20,50,100,1000,10000))).
1698: '</label></span> <span class="LC_nobreak">'.
1699: &mt('Filter [_1]',
1700: &select_form($env{'form.displayfilter'},
1701: 'displayfilter',
1702: ('currentfolder' => 'Current folder/page',
1703: 'containing' => 'Containing phrase',
1704: 'none' => 'None'))).
1705: '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1706: }
1707:
1708: sub gradeleveldescription {
1709: my $gradelevel=shift;
1710: my %gradelevels=(0 => 'Not specified',
1711: 1 => 'Grade 1',
1712: 2 => 'Grade 2',
1713: 3 => 'Grade 3',
1714: 4 => 'Grade 4',
1715: 5 => 'Grade 5',
1716: 6 => 'Grade 6',
1717: 7 => 'Grade 7',
1718: 8 => 'Grade 8',
1719: 9 => 'Grade 9',
1720: 10 => 'Grade 10',
1721: 11 => 'Grade 11',
1722: 12 => 'Grade 12',
1723: 13 => 'Grade 13',
1724: 14 => '100 Level',
1725: 15 => '200 Level',
1726: 16 => '300 Level',
1727: 17 => '400 Level',
1728: 18 => 'Graduate Level');
1729: return &mt($gradelevels{$gradelevel});
1730: }
1731:
1732: sub select_level_form {
1733: my ($deflevel,$name)=@_;
1734: unless ($deflevel) { $deflevel=0; }
1735: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1736: for (my $i=0; $i<=18; $i++) {
1737: $selectform.="<option value=\"$i\" ".
1738: ($i==$deflevel ? 'selected="selected" ' : '').
1739: ">".&gradeleveldescription($i)."</option>\n";
1740: }
1741: $selectform.="</select>";
1742: return $selectform;
1743: }
1744:
1745: #-------------------------------------------
1746:
1747: =pod
1748:
1749: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc)
1750:
1751: Returns a string containing a <select name='$name' size='1'> form to
1752: allow a user to select the domain to preform an operation in.
1753: See loncreateuser.pm for an example invocation and use.
1754:
1755: If the $includeempty flag is set, it also includes an empty choice ("no domain
1756: selected");
1757:
1758: If the $showdomdesc flag is set, the domain name is followed by the domain description.
1759:
1760: =cut
1761:
1762: #-------------------------------------------
1763: sub select_dom_form {
1764: my ($defdom,$name,$includeempty,$showdomdesc) = @_;
1765: my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1766: if ($includeempty) { @domains=('',@domains); }
1767: my $selectdomain = "<select name=\"$name\" size=\"1\">\n";
1768: foreach my $dom (@domains) {
1769: $selectdomain.="<option value=\"$dom\" ".
1770: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
1771: if ($showdomdesc) {
1772: if ($dom ne '') {
1773: my $domdesc = &Apache::lonnet::domain($dom,'description');
1774: if ($domdesc ne '') {
1775: $selectdomain .= ' ('.$domdesc.')';
1776: }
1777: }
1778: }
1779: $selectdomain .= "</option>\n";
1780: }
1781: $selectdomain.="</select>";
1782: return $selectdomain;
1783: }
1784:
1785: #-------------------------------------------
1786:
1787: =pod
1788:
1789: =item * &home_server_form_item($domain,$name,$defaultflag)
1790:
1791: input: 4 arguments (two required, two optional) -
1792: $domain - domain of new user
1793: $name - name of form element
1794: $default - Value of 'default' causes a default item to be first
1795: option, and selected by default.
1796: $hide - Value of 'hide' causes hiding of the name of the server,
1797: if 1 server found, or default, if 0 found.
1798: output: returns 2 items:
1799: (a) form element which contains either:
1800: (i) <select name="$name">
1801: <option value="$hostid1">$hostid $servers{$hostid}</option>
1802: <option value="$hostid2">$hostid $servers{$hostid}</option>
1803: </select>
1804: form item if there are multiple library servers in $domain, or
1805: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
1806: if there is only one library server in $domain.
1807:
1808: (b) number of library servers found.
1809:
1810: See loncreateuser.pm for example of use.
1811:
1812: =cut
1813:
1814: #-------------------------------------------
1815: sub home_server_form_item {
1816: my ($domain,$name,$default,$hide) = @_;
1817: my %servers = &Apache::lonnet::get_servers($domain,'library');
1818: my $result;
1819: my $numlib = keys(%servers);
1820: if ($numlib > 1) {
1821: $result .= '<select name="'.$name.'" />'."\n";
1822: if ($default) {
1823: $result .= '<option value="default" selected>'.&mt('default').
1824: '</option>'."\n";
1825: }
1826: foreach my $hostid (sort(keys(%servers))) {
1827: $result.= '<option value="'.$hostid.'">'.
1828: $hostid.' '.$servers{$hostid}."</option>\n";
1829: }
1830: $result .= '</select>'."\n";
1831: } elsif ($numlib == 1) {
1832: my $hostid;
1833: foreach my $item (keys(%servers)) {
1834: $hostid = $item;
1835: }
1836: $result .= '<input type="hidden" name="'.$name.'" value="'.
1837: $hostid.'" />';
1838: if (!$hide) {
1839: $result .= $hostid.' '.$servers{$hostid};
1840: }
1841: $result .= "\n";
1842: } elsif ($default) {
1843: $result .= '<input type="hidden" name="'.$name.
1844: '" value="default" />';
1845: if (!$hide) {
1846: $result .= &mt('default');
1847: }
1848: $result .= "\n";
1849: }
1850: return ($result,$numlib);
1851: }
1852:
1853: =pod
1854:
1855: =back
1856:
1857: =cut
1858:
1859: ###############################################################
1860: ## Decoding User Agent ##
1861: ###############################################################
1862:
1863: =pod
1864:
1865: =head1 Decoding the User Agent
1866:
1867: =over 4
1868:
1869: =item * &decode_user_agent()
1870:
1871: Inputs: $r
1872:
1873: Outputs:
1874:
1875: =over 4
1876:
1877: =item * $httpbrowser
1878:
1879: =item * $clientbrowser
1880:
1881: =item * $clientversion
1882:
1883: =item * $clientmathml
1884:
1885: =item * $clientunicode
1886:
1887: =item * $clientos
1888:
1889: =back
1890:
1891: =back
1892:
1893: =cut
1894:
1895: ###############################################################
1896: ###############################################################
1897: sub decode_user_agent {
1898: my ($r)=@_;
1899: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
1900: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
1901: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1902: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1903: my $clientbrowser='unknown';
1904: my $clientversion='0';
1905: my $clientmathml='';
1906: my $clientunicode='0';
1907: for (my $i=0;$i<=$#browsertype;$i++) {
1908: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
1909: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
1910: $clientbrowser=$bname;
1911: $httpbrowser=~/$vreg/i;
1912: $clientversion=$1;
1913: $clientmathml=($clientversion>=$minv);
1914: $clientunicode=($clientversion>=$univ);
1915: }
1916: }
1917: my $clientos='unknown';
1918: if (($httpbrowser=~/linux/i) ||
1919: ($httpbrowser=~/unix/i) ||
1920: ($httpbrowser=~/ux/i) ||
1921: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
1922: if (($httpbrowser=~/vax/i) ||
1923: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
1924: if ($httpbrowser=~/next/i) { $clientos='next'; }
1925: if (($httpbrowser=~/mac/i) ||
1926: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1927: if ($httpbrowser=~/win/i) { $clientos='win'; }
1928: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1929: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1930: $clientunicode,$clientos,);
1931: }
1932:
1933: ###############################################################
1934: ## Authentication changing form generation subroutines ##
1935: ###############################################################
1936: ##
1937: ## All of the authform_xxxxxxx subroutines take their inputs in a
1938: ## hash, and have reasonable default values.
1939: ##
1940: ## formname = the name given in the <form> tag.
1941: #-------------------------------------------
1942:
1943: =pod
1944:
1945: =head1 Authentication Routines
1946:
1947: =over 4
1948:
1949: =item * &authform_xxxxxx()
1950:
1951: The authform_xxxxxx subroutines provide javascript and html forms which
1952: handle some of the conveniences required for authentication forms.
1953: This is not an optimal method, but it works.
1954:
1955: =over 4
1956:
1957: =item * authform_header
1958:
1959: =item * authform_authorwarning
1960:
1961: =item * authform_nochange
1962:
1963: =item * authform_kerberos
1964:
1965: =item * authform_internal
1966:
1967: =item * authform_filesystem
1968:
1969: =back
1970:
1971: See loncreateuser.pm for invocation and use examples.
1972:
1973: =cut
1974:
1975: #-------------------------------------------
1976: sub authform_header{
1977: my %in = (
1978: formname => 'cu',
1979: kerb_def_dom => '',
1980: @_,
1981: );
1982: $in{'formname'} = 'document.' . $in{'formname'};
1983: my $result='';
1984:
1985: #---------------------------------------------- Code for upper case translation
1986: my $Javascript_toUpperCase;
1987: unless ($in{kerb_def_dom}) {
1988: $Javascript_toUpperCase =<<"END";
1989: switch (choice) {
1990: case 'krb': currentform.elements[choicearg].value =
1991: currentform.elements[choicearg].value.toUpperCase();
1992: break;
1993: default:
1994: }
1995: END
1996: } else {
1997: $Javascript_toUpperCase = "";
1998: }
1999:
2000: my $radioval = "'nochange'";
2001: if (defined($in{'curr_authtype'})) {
2002: if ($in{'curr_authtype'} ne '') {
2003: $radioval = "'".$in{'curr_authtype'}."arg'";
2004: }
2005: }
2006: my $argfield = 'null';
2007: if (defined($in{'mode'})) {
2008: if ($in{'mode'} eq 'modifycourse') {
2009: if (defined($in{'curr_autharg'})) {
2010: if ($in{'curr_autharg'} ne '') {
2011: $argfield = "'$in{'curr_autharg'}'";
2012: }
2013: }
2014: }
2015: }
2016:
2017: $result.=<<"END";
2018: var current = new Object();
2019: current.radiovalue = $radioval;
2020: current.argfield = $argfield;
2021:
2022: function changed_radio(choice,currentform) {
2023: var choicearg = choice + 'arg';
2024: // If a radio button in changed, we need to change the argfield
2025: if (current.radiovalue != choice) {
2026: current.radiovalue = choice;
2027: if (current.argfield != null) {
2028: currentform.elements[current.argfield].value = '';
2029: }
2030: if (choice == 'nochange') {
2031: current.argfield = null;
2032: } else {
2033: current.argfield = choicearg;
2034: switch(choice) {
2035: case 'krb':
2036: currentform.elements[current.argfield].value =
2037: "$in{'kerb_def_dom'}";
2038: break;
2039: default:
2040: break;
2041: }
2042: }
2043: }
2044: return;
2045: }
2046:
2047: function changed_text(choice,currentform) {
2048: var choicearg = choice + 'arg';
2049: if (currentform.elements[choicearg].value !='') {
2050: $Javascript_toUpperCase
2051: // clear old field
2052: if ((current.argfield != choicearg) && (current.argfield != null)) {
2053: currentform.elements[current.argfield].value = '';
2054: }
2055: current.argfield = choicearg;
2056: }
2057: set_auth_radio_buttons(choice,currentform);
2058: return;
2059: }
2060:
2061: function set_auth_radio_buttons(newvalue,currentform) {
2062: var i=0;
2063: while (i < currentform.login.length) {
2064: if (currentform.login[i].value == newvalue) { break; }
2065: i++;
2066: }
2067: if (i == currentform.login.length) {
2068: return;
2069: }
2070: current.radiovalue = newvalue;
2071: currentform.login[i].checked = true;
2072: return;
2073: }
2074: END
2075: return $result;
2076: }
2077:
2078: sub authform_authorwarning{
2079: my $result='';
2080: $result='<i>'.
2081: &mt('As a general rule, only authors or co-authors should be '.
2082: 'filesystem authenticated '.
2083: '(which allows access to the server filesystem).')."</i>\n";
2084: return $result;
2085: }
2086:
2087: sub authform_nochange{
2088: my %in = (
2089: formname => 'document.cu',
2090: kerb_def_dom => 'MSU.EDU',
2091: @_,
2092: );
2093: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2094: my $result;
2095: if (keys(%can_assign) == 0) {
2096: $result = &mt('Under you current role you are not permitted to change login settings for this user');
2097: } else {
2098: $result = '<label>'.&mt('[_1] Do not change login data',
2099: '<input type="radio" name="login" value="nochange" '.
2100: 'checked="checked" onclick="'.
2101: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2102: '</label>';
2103: }
2104: return $result;
2105: }
2106:
2107: sub authform_kerberos {
2108: my %in = (
2109: formname => 'document.cu',
2110: kerb_def_dom => 'MSU.EDU',
2111: kerb_def_auth => 'krb4',
2112: @_,
2113: );
2114: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2115: $autharg,$jscall);
2116: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2117: if ($in{'kerb_def_auth'} eq 'krb5') {
2118: $check5 = ' checked="on"';
2119: } else {
2120: $check4 = ' checked="on"';
2121: }
2122: $krbarg = $in{'kerb_def_dom'};
2123: if (defined($in{'curr_authtype'})) {
2124: if ($in{'curr_authtype'} eq 'krb') {
2125: $krbcheck = ' checked="on"';
2126: if (defined($in{'mode'})) {
2127: if ($in{'mode'} eq 'modifyuser') {
2128: $krbcheck = '';
2129: }
2130: }
2131: if (defined($in{'curr_kerb_ver'})) {
2132: if ($in{'curr_krb_ver'} eq '5') {
2133: $check5 = ' checked="on"';
2134: $check4 = '';
2135: } else {
2136: $check4 = ' checked="on"';
2137: $check5 = '';
2138: }
2139: }
2140: if (defined($in{'curr_autharg'})) {
2141: $krbarg = $in{'curr_autharg'};
2142: }
2143: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2144: if (defined($in{'curr_autharg'})) {
2145: $result =
2146: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2147: $in{'curr_autharg'},$krbver);
2148: } else {
2149: $result =
2150: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2151: }
2152: return $result;
2153: }
2154: }
2155: } else {
2156: if ($authnum == 1) {
2157: $authtype = '<input type="hidden" name="login" value="krb">';
2158: }
2159: }
2160: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2161: return;
2162: } elsif ($authtype eq '') {
2163: if (defined($in{'mode'})) {
2164: if ($in{'mode'} eq 'modifycourse') {
2165: if ($authnum == 1) {
2166: $authtype = '<input type="hidden" name="login" value="krb">';
2167: }
2168: }
2169: }
2170: }
2171: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2172: if ($authtype eq '') {
2173: $authtype = '<input type="radio" name="login" value="krb" '.
2174: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2175: $krbcheck.' />';
2176: }
2177: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
2178: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
2179: $in{'curr_authtype'} eq 'krb5') ||
2180: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
2181: $in{'curr_authtype'} eq 'krb4')) {
2182: $result .= &mt
2183: ('[_1] Kerberos authenticated with domain [_2] '.
2184: '[_3] Version 4 [_4] Version 5 [_5]',
2185: '<label>'.$authtype,
2186: '</label><input type="text" size="10" name="krbarg" '.
2187: 'value="'.$krbarg.'" '.
2188: 'onchange="'.$jscall.'" />',
2189: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2190: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2191: '</label>');
2192: } elsif ($can_assign{'krb4'}) {
2193: $result .= &mt
2194: ('[_1] Kerberos authenticated with domain [_2] '.
2195: '[_3] Version 4 [_4]',
2196: '<label>'.$authtype,
2197: '</label><input type="text" size="10" name="krbarg" '.
2198: 'value="'.$krbarg.'" '.
2199: 'onchange="'.$jscall.'" />',
2200: '<label><input type="hidden" name="krbver" value="4" />',
2201: '</label>');
2202: } elsif ($can_assign{'krb5'}) {
2203: $result .= &mt
2204: ('[_1] Kerberos authenticated with domain [_2] '.
2205: '[_3] Version 5 [_4]',
2206: '<label>'.$authtype,
2207: '</label><input type="text" size="10" name="krbarg" '.
2208: 'value="'.$krbarg.'" '.
2209: 'onchange="'.$jscall.'" />',
2210: '<label><input type="hidden" name="krbver" value="5" />',
2211: '</label>');
2212: }
2213: return $result;
2214: }
2215:
2216: sub authform_internal{
2217: my %in = (
2218: formname => 'document.cu',
2219: kerb_def_dom => 'MSU.EDU',
2220: @_,
2221: );
2222: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
2223: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2224: if (defined($in{'curr_authtype'})) {
2225: if ($in{'curr_authtype'} eq 'int') {
2226: if ($can_assign{'int'}) {
2227: $intcheck = 'checked="on" ';
2228: if (defined($in{'mode'})) {
2229: if ($in{'mode'} eq 'modifyuser') {
2230: $intcheck = '';
2231: }
2232: }
2233: if (defined($in{'curr_autharg'})) {
2234: $intarg = $in{'curr_autharg'};
2235: }
2236: } else {
2237: $result = &mt('Currently internally authenticated.');
2238: return $result;
2239: }
2240: }
2241: } else {
2242: if ($authnum == 1) {
2243: $authtype = '<input type="hidden" name="login" value="int">';
2244: }
2245: }
2246: if (!$can_assign{'int'}) {
2247: return;
2248: } elsif ($authtype eq '') {
2249: if (defined($in{'mode'})) {
2250: if ($in{'mode'} eq 'modifycourse') {
2251: if ($authnum == 1) {
2252: $authtype = '<input type="hidden" name="login" value="int">';
2253: }
2254: }
2255: }
2256: }
2257: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2258: if ($authtype eq '') {
2259: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2260: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2261: }
2262: $autharg = '<input type="password" size="10" name="intarg" value="'.
2263: $intarg.'" onchange="'.$jscall.'" />';
2264: $result = &mt
2265: ('[_1] Internally authenticated (with initial password [_2])',
2266: '<label>'.$authtype,'</label>'.$autharg);
2267: $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>';
2268: return $result;
2269: }
2270:
2271: sub authform_local{
2272: my %in = (
2273: formname => 'document.cu',
2274: kerb_def_dom => 'MSU.EDU',
2275: @_,
2276: );
2277: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
2278: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2279: if (defined($in{'curr_authtype'})) {
2280: if ($in{'curr_authtype'} eq 'loc') {
2281: if ($can_assign{'loc'}) {
2282: $loccheck = 'checked="on" ';
2283: if (defined($in{'mode'})) {
2284: if ($in{'mode'} eq 'modifyuser') {
2285: $loccheck = '';
2286: }
2287: }
2288: if (defined($in{'curr_autharg'})) {
2289: $locarg = $in{'curr_autharg'};
2290: }
2291: } else {
2292: $result = &mt('Currently using local (institutional) authentication.');
2293: return $result;
2294: }
2295: }
2296: } else {
2297: if ($authnum == 1) {
2298: $authtype = '<input type="hidden" name="login" value="loc">';
2299: }
2300: }
2301: if (!$can_assign{'loc'}) {
2302: return;
2303: } elsif ($authtype eq '') {
2304: if (defined($in{'mode'})) {
2305: if ($in{'mode'} eq 'modifycourse') {
2306: if ($authnum == 1) {
2307: $authtype = '<input type="hidden" name="login" value="loc">';
2308: }
2309: }
2310: }
2311: }
2312: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2313: if ($authtype eq '') {
2314: $authtype = '<input type="radio" name="login" value="loc" '.
2315: $loccheck.' onchange="'.$jscall.'" onclick="'.
2316: $jscall.'" />';
2317: }
2318: $autharg = '<input type="text" size="10" name="locarg" value="'.
2319: $locarg.'" onchange="'.$jscall.'" />';
2320: $result = &mt('[_1] Local Authentication with argument [_2]',
2321: '<label>'.$authtype,'</label>'.$autharg);
2322: return $result;
2323: }
2324:
2325: sub authform_filesystem{
2326: my %in = (
2327: formname => 'document.cu',
2328: kerb_def_dom => 'MSU.EDU',
2329: @_,
2330: );
2331: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
2332: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2333: if (defined($in{'curr_authtype'})) {
2334: if ($in{'curr_authtype'} eq 'fsys') {
2335: if ($can_assign{'fsys'}) {
2336: $fsyscheck = 'checked="on" ';
2337: if (defined($in{'mode'})) {
2338: if ($in{'mode'} eq 'modifyuser') {
2339: $fsyscheck = '';
2340: }
2341: }
2342: } else {
2343: $result = &mt('Currently Filesystem Authenticated.');
2344: return $result;
2345: }
2346: }
2347: } else {
2348: if ($authnum == 1) {
2349: $authtype = '<input type="hidden" name="login" value="fsys">';
2350: }
2351: }
2352: if (!$can_assign{'fsys'}) {
2353: return;
2354: } elsif ($authtype eq '') {
2355: if (defined($in{'mode'})) {
2356: if ($in{'mode'} eq 'modifycourse') {
2357: if ($authnum == 1) {
2358: $authtype = '<input type="hidden" name="login" value="fsys">';
2359: }
2360: }
2361: }
2362: }
2363: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2364: if ($authtype eq '') {
2365: $authtype = '<input type="radio" name="login" value="fsys" '.
2366: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2367: $jscall.'" />';
2368: }
2369: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2370: ' onchange="'.$jscall.'" />';
2371: $result = &mt
2372: ('[_1] Filesystem Authenticated (with initial password [_2])',
2373: '<label><input type="radio" name="login" value="fsys" '.
2374: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
2375: '</label><input type="password" size="10" name="fsysarg" value="" '.
2376: 'onchange="'.$jscall.'" />');
2377: return $result;
2378: }
2379:
2380: sub get_assignable_auth {
2381: my ($dom) = @_;
2382: if ($dom eq '') {
2383: $dom = $env{'request.role.domain'};
2384: }
2385: my %can_assign = (
2386: krb4 => 1,
2387: krb5 => 1,
2388: int => 1,
2389: loc => 1,
2390: );
2391: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2392: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2393: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2394: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2395: my $context;
2396: if ($env{'request.role'} =~ /^au/) {
2397: $context = 'author';
2398: } elsif ($env{'request.role'} =~ /^dc/) {
2399: $context = 'domain';
2400: } elsif ($env{'request.course.id'}) {
2401: $context = 'course';
2402: }
2403: if ($context) {
2404: if (ref($authhash->{$context}) eq 'HASH') {
2405: %can_assign = %{$authhash->{$context}};
2406: }
2407: }
2408: }
2409: }
2410: my $authnum = 0;
2411: foreach my $key (keys(%can_assign)) {
2412: if ($can_assign{$key}) {
2413: $authnum ++;
2414: }
2415: }
2416: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2417: $authnum --;
2418: }
2419: return ($authnum,%can_assign);
2420: }
2421:
2422: ###############################################################
2423: ## Get Kerberos Defaults for Domain ##
2424: ###############################################################
2425: ##
2426: ## Returns default kerberos version and an associated argument
2427: ## as listed in file domain.tab. If not listed, provides
2428: ## appropriate default domain and kerberos version.
2429: ##
2430: #-------------------------------------------
2431:
2432: =pod
2433:
2434: =item * &get_kerberos_defaults()
2435:
2436: get_kerberos_defaults($target_domain) returns the default kerberos
2437: version and domain. If not found, it defaults to version 4 and the
2438: domain of the server.
2439:
2440: =over 4
2441:
2442: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2443:
2444: =back
2445:
2446: =back
2447:
2448: =cut
2449:
2450: #-------------------------------------------
2451: sub get_kerberos_defaults {
2452: my $domain=shift;
2453: my ($krbdef,$krbdefdom);
2454: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2455: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2456: $krbdef = $domdefaults{'auth_def'};
2457: $krbdefdom = $domdefaults{'auth_arg_def'};
2458: } else {
2459: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2460: my $krbdefdom=$1;
2461: $krbdefdom=~tr/a-z/A-Z/;
2462: $krbdef = "krb4";
2463: }
2464: return ($krbdef,$krbdefdom);
2465: }
2466:
2467:
2468: ###############################################################
2469: ## Thesaurus Functions ##
2470: ###############################################################
2471:
2472: =pod
2473:
2474: =head1 Thesaurus Functions
2475:
2476: =over 4
2477:
2478: =item * &initialize_keywords()
2479:
2480: Initializes the package variable %Keywords if it is empty. Uses the
2481: package variable $thesaurus_db_file.
2482:
2483: =cut
2484:
2485: ###################################################
2486:
2487: sub initialize_keywords {
2488: return 1 if (scalar keys(%Keywords));
2489: # If we are here, %Keywords is empty, so fill it up
2490: # Make sure the file we need exists...
2491: if (! -e $thesaurus_db_file) {
2492: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2493: " failed because it does not exist");
2494: return 0;
2495: }
2496: # Set up the hash as a database
2497: my %thesaurus_db;
2498: if (! tie(%thesaurus_db,'GDBM_File',
2499: $thesaurus_db_file,&GDBM_READER(),0640)){
2500: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2501: $thesaurus_db_file);
2502: return 0;
2503: }
2504: # Get the average number of appearances of a word.
2505: my $avecount = $thesaurus_db{'average.count'};
2506: # Put keywords (those that appear > average) into %Keywords
2507: while (my ($word,$data)=each (%thesaurus_db)) {
2508: my ($count,undef) = split /:/,$data;
2509: $Keywords{$word}++ if ($count > $avecount);
2510: }
2511: untie %thesaurus_db;
2512: # Remove special values from %Keywords.
2513: foreach my $value ('total.count','average.count') {
2514: delete($Keywords{$value}) if (exists($Keywords{$value}));
2515: }
2516: return 1;
2517: }
2518:
2519: ###################################################
2520:
2521: =pod
2522:
2523: =item * &keyword($word)
2524:
2525: Returns true if $word is a keyword. A keyword is a word that appears more
2526: than the average number of times in the thesaurus database. Calls
2527: &initialize_keywords
2528:
2529: =cut
2530:
2531: ###################################################
2532:
2533: sub keyword {
2534: return if (!&initialize_keywords());
2535: my $word=lc(shift());
2536: $word=~s/\W//g;
2537: return exists($Keywords{$word});
2538: }
2539:
2540: ###############################################################
2541:
2542: =pod
2543:
2544: =item * &get_related_words()
2545:
2546: Look up a word in the thesaurus. Takes a scalar argument and returns
2547: an array of words. If the keyword is not in the thesaurus, an empty array
2548: will be returned. The order of the words returned is determined by the
2549: database which holds them.
2550:
2551: Uses global $thesaurus_db_file.
2552:
2553: =cut
2554:
2555: ###############################################################
2556: sub get_related_words {
2557: my $keyword = shift;
2558: my %thesaurus_db;
2559: if (! -e $thesaurus_db_file) {
2560: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
2561: "failed because the file does not exist");
2562: return ();
2563: }
2564: if (! tie(%thesaurus_db,'GDBM_File',
2565: $thesaurus_db_file,&GDBM_READER(),0640)){
2566: return ();
2567: }
2568: my @Words=();
2569: my $count=0;
2570: if (exists($thesaurus_db{$keyword})) {
2571: # The first element is the number of times
2572: # the word appears. We do not need it now.
2573: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
2574: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
2575: my $threshold=$mostfrequentcount/10;
2576: foreach my $possibleword (@RelatedWords) {
2577: my ($word,$wordcount)=split(/\,/,$possibleword);
2578: if ($wordcount>$threshold) {
2579: push(@Words,$word);
2580: $count++;
2581: if ($count>10) { last; }
2582: }
2583: }
2584: }
2585: untie %thesaurus_db;
2586: return @Words;
2587: }
2588:
2589: =pod
2590:
2591: =back
2592:
2593: =cut
2594:
2595: # -------------------------------------------------------------- Plaintext name
2596: =pod
2597:
2598: =head1 User Name Functions
2599:
2600: =over 4
2601:
2602: =item * &plainname($uname,$udom,$first)
2603:
2604: Takes a users logon name and returns it as a string in
2605: "first middle last generation" form
2606: if $first is set to 'lastname' then it returns it as
2607: 'lastname generation, firstname middlename' if their is a lastname
2608:
2609: =cut
2610:
2611:
2612: ###############################################################
2613: sub plainname {
2614: my ($uname,$udom,$first)=@_;
2615: return if (!defined($uname) || !defined($udom));
2616: my %names=&getnames($uname,$udom);
2617: my $name=&Apache::lonnet::format_name($names{'firstname'},
2618: $names{'middlename'},
2619: $names{'lastname'},
2620: $names{'generation'},$first);
2621: $name=~s/^\s+//;
2622: $name=~s/\s+$//;
2623: $name=~s/\s+/ /g;
2624: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
2625: return $name;
2626: }
2627:
2628: # -------------------------------------------------------------------- Nickname
2629: =pod
2630:
2631: =item * &nickname($uname,$udom)
2632:
2633: Gets a users name and returns it as a string as
2634:
2635: ""nickname""
2636:
2637: if the user has a nickname or
2638:
2639: "first middle last generation"
2640:
2641: if the user does not
2642:
2643: =cut
2644:
2645: sub nickname {
2646: my ($uname,$udom)=@_;
2647: return if (!defined($uname) || !defined($udom));
2648: my %names=&getnames($uname,$udom);
2649: my $name=$names{'nickname'};
2650: if ($name) {
2651: $name='"'.$name.'"';
2652: } else {
2653: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
2654: $names{'lastname'}.' '.$names{'generation'};
2655: $name=~s/\s+$//;
2656: $name=~s/\s+/ /g;
2657: }
2658: return $name;
2659: }
2660:
2661: sub getnames {
2662: my ($uname,$udom)=@_;
2663: return if (!defined($uname) || !defined($udom));
2664: if ($udom eq 'public' && $uname eq 'public') {
2665: return ('lastname' => &mt('Public'));
2666: }
2667: my $id=$uname.':'.$udom;
2668: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
2669: if ($cached) {
2670: return %{$names};
2671: } else {
2672: my %loadnames=&Apache::lonnet::get('environment',
2673: ['firstname','middlename','lastname','generation','nickname'],
2674: $udom,$uname);
2675: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
2676: return %loadnames;
2677: }
2678: }
2679:
2680: # -------------------------------------------------------------------- getemails
2681:
2682: =pod
2683:
2684: =item * &getemails($uname,$udom)
2685:
2686: Gets a user's email information and returns it as a hash with keys:
2687: notification, critnotification, permanentemail
2688:
2689: For notification and critnotification, values are comma-separated lists
2690: of e-mail addresses; for permanentemail, value is a single e-mail address.
2691:
2692:
2693: =cut
2694:
2695:
2696: sub getemails {
2697: my ($uname,$udom)=@_;
2698: if ($udom eq 'public' && $uname eq 'public') {
2699: return;
2700: }
2701: if (!$udom) { $udom=$env{'user.domain'}; }
2702: if (!$uname) { $uname=$env{'user.name'}; }
2703: my $id=$uname.':'.$udom;
2704: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
2705: if ($cached) {
2706: return %{$names};
2707: } else {
2708: my %loadnames=&Apache::lonnet::get('environment',
2709: ['notification','critnotification',
2710: 'permanentemail'],
2711: $udom,$uname);
2712: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
2713: return %loadnames;
2714: }
2715: }
2716:
2717: sub flush_email_cache {
2718: my ($uname,$udom)=@_;
2719: if (!$udom) { $udom =$env{'user.domain'}; }
2720: if (!$uname) { $uname=$env{'user.name'}; }
2721: return if ($udom eq 'public' && $uname eq 'public');
2722: my $id=$uname.':'.$udom;
2723: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
2724: }
2725:
2726: # -------------------------------------------------------------------- getlangs
2727:
2728: =pod
2729:
2730: =item * &getlangs($uname,$udom)
2731:
2732: Gets a user's language preference and returns it as a hash with key:
2733: language.
2734:
2735: =cut
2736:
2737:
2738: sub getlangs {
2739: my ($uname,$udom) = @_;
2740: if (!$udom) { $udom =$env{'user.domain'}; }
2741: if (!$uname) { $uname=$env{'user.name'}; }
2742: my $id=$uname.':'.$udom;
2743: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
2744: if ($cached) {
2745: return %{$langs};
2746: } else {
2747: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
2748: $udom,$uname);
2749: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
2750: return %loadlangs;
2751: }
2752: }
2753:
2754: sub flush_langs_cache {
2755: my ($uname,$udom)=@_;
2756: if (!$udom) { $udom =$env{'user.domain'}; }
2757: if (!$uname) { $uname=$env{'user.name'}; }
2758: return if ($udom eq 'public' && $uname eq 'public');
2759: my $id=$uname.':'.$udom;
2760: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
2761: }
2762:
2763: # ------------------------------------------------------------------ Screenname
2764:
2765: =pod
2766:
2767: =item * &screenname($uname,$udom)
2768:
2769: Gets a users screenname and returns it as a string
2770:
2771: =cut
2772:
2773: sub screenname {
2774: my ($uname,$udom)=@_;
2775: if ($uname eq $env{'user.name'} &&
2776: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
2777: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
2778: return $names{'screenname'};
2779: }
2780:
2781:
2782: # ------------------------------------------------------------- Message Wrapper
2783:
2784: sub messagewrapper {
2785: my ($link,$username,$domain,$subject,$text)=@_;
2786: return
2787: '<a href="/adm/email?compose=individual&'.
2788: 'recname='.$username.'&recdom='.$domain.
2789: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
2790: 'title="'.&mt('Send message').'">'.$link.'</a>';
2791: }
2792: # --------------------------------------------------------------- Notes Wrapper
2793:
2794: sub noteswrapper {
2795: my ($link,$un,$do)=@_;
2796: return
2797: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
2798: }
2799: # ------------------------------------------------------------- Aboutme Wrapper
2800:
2801: sub aboutmewrapper {
2802: my ($link,$username,$domain,$target)=@_;
2803: if (!defined($username) && !defined($domain)) {
2804: return;
2805: }
2806: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
2807: ($target?' target="$target"':'').' title="'.&mt("View this user's personal page").'">'.$link.'</a>';
2808: }
2809:
2810: # ------------------------------------------------------------ Syllabus Wrapper
2811:
2812:
2813: sub syllabuswrapper {
2814: my ($linktext,$coursedir,$domain)=@_;
2815: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
2816: }
2817:
2818: sub track_student_link {
2819: my ($linktext,$sname,$sdom,$target,$start) = @_;
2820: my $link ="/adm/trackstudent?";
2821: my $title = 'View recent activity';
2822: if (defined($sname) && $sname !~ /^\s*$/ &&
2823: defined($sdom) && $sdom !~ /^\s*$/) {
2824: $link .= "selected_student=$sname:$sdom";
2825: $title .= ' of this student';
2826: }
2827: if (defined($target) && $target !~ /^\s*$/) {
2828: $target = qq{target="$target"};
2829: } else {
2830: $target = '';
2831: }
2832: if ($start) { $link.='&start='.$start; }
2833: $title = &mt($title);
2834: $linktext = &mt($linktext);
2835: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
2836: &help_open_topic('View_recent_activity');
2837: }
2838:
2839: # ===================================================== Display a student photo
2840:
2841:
2842: sub student_image_tag {
2843: my ($domain,$user)=@_;
2844: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
2845: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
2846: return '<img src="'.$imgsrc.'" align="right" />';
2847: } else {
2848: return '';
2849: }
2850: }
2851:
2852: =pod
2853:
2854: =back
2855:
2856: =head1 Access .tab File Data
2857:
2858: =over 4
2859:
2860: =item * &languageids()
2861:
2862: returns list of all language ids
2863:
2864: =cut
2865:
2866: sub languageids {
2867: return sort(keys(%language));
2868: }
2869:
2870: =pod
2871:
2872: =item * &languagedescription()
2873:
2874: returns description of a specified language id
2875:
2876: =cut
2877:
2878: sub languagedescription {
2879: my $code=shift;
2880: return ($supported_language{$code}?'* ':'').
2881: $language{$code}.
2882: ($supported_language{$code}?' ('.&mt('interface available').')':'');
2883: }
2884:
2885: sub plainlanguagedescription {
2886: my $code=shift;
2887: return $language{$code};
2888: }
2889:
2890: sub supportedlanguagecode {
2891: my $code=shift;
2892: return $supported_language{$code};
2893: }
2894:
2895: =pod
2896:
2897: =item * ©rightids()
2898:
2899: returns list of all copyrights
2900:
2901: =cut
2902:
2903: sub copyrightids {
2904: return sort(keys(%cprtag));
2905: }
2906:
2907: =pod
2908:
2909: =item * ©rightdescription()
2910:
2911: returns description of a specified copyright id
2912:
2913: =cut
2914:
2915: sub copyrightdescription {
2916: return &mt($cprtag{shift(@_)});
2917: }
2918:
2919: =pod
2920:
2921: =item * &source_copyrightids()
2922:
2923: returns list of all source copyrights
2924:
2925: =cut
2926:
2927: sub source_copyrightids {
2928: return sort(keys(%scprtag));
2929: }
2930:
2931: =pod
2932:
2933: =item * &source_copyrightdescription()
2934:
2935: returns description of a specified source copyright id
2936:
2937: =cut
2938:
2939: sub source_copyrightdescription {
2940: return &mt($scprtag{shift(@_)});
2941: }
2942:
2943: =pod
2944:
2945: =item * &filecategories()
2946:
2947: returns list of all file categories
2948:
2949: =cut
2950:
2951: sub filecategories {
2952: return sort(keys(%category_extensions));
2953: }
2954:
2955: =pod
2956:
2957: =item * &filecategorytypes()
2958:
2959: returns list of file types belonging to a given file
2960: category
2961:
2962: =cut
2963:
2964: sub filecategorytypes {
2965: my ($cat) = @_;
2966: return @{$category_extensions{lc($cat)}};
2967: }
2968:
2969: =pod
2970:
2971: =item * &fileembstyle()
2972:
2973: returns embedding style for a specified file type
2974:
2975: =cut
2976:
2977: sub fileembstyle {
2978: return $fe{lc(shift(@_))};
2979: }
2980:
2981: sub filemimetype {
2982: return $fm{lc(shift(@_))};
2983: }
2984:
2985:
2986: sub filecategoryselect {
2987: my ($name,$value)=@_;
2988: return &select_form($value,$name,
2989: '' => &mt('Any category'),
2990: map { $_,$_ } sort(keys(%category_extensions)));
2991: }
2992:
2993: =pod
2994:
2995: =item * &filedescription()
2996:
2997: returns description for a specified file type
2998:
2999: =cut
3000:
3001: sub filedescription {
3002: my $file_description = $fd{lc(shift())};
3003: $file_description =~ s:([\[\]]):~$1:g;
3004: return &mt($file_description);
3005: }
3006:
3007: =pod
3008:
3009: =item * &filedescriptionex()
3010:
3011: returns description for a specified file type with
3012: extra formatting
3013:
3014: =cut
3015:
3016: sub filedescriptionex {
3017: my $ex=shift;
3018: my $file_description = $fd{lc($ex)};
3019: $file_description =~ s:([\[\]]):~$1:g;
3020: return '.'.$ex.' '.&mt($file_description);
3021: }
3022:
3023: # End of .tab access
3024: =pod
3025:
3026: =back
3027:
3028: =cut
3029:
3030: # ------------------------------------------------------------------ File Types
3031: sub fileextensions {
3032: return sort(keys(%fe));
3033: }
3034:
3035: # ----------------------------------------------------------- Display Languages
3036: # returns a hash with all desired display languages
3037: #
3038:
3039: sub display_languages {
3040: my %languages=();
3041: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
3042: $languages{$lang}=1;
3043: }
3044: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
3045: if ($env{'form.displaylanguage'}) {
3046: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3047: $languages{$lang}=1;
3048: }
3049: }
3050: return %languages;
3051: }
3052:
3053: sub languages {
3054: my ($possible_langs) = @_;
3055: my @preferred_langs = &Apache::lonlocal::preferred_languages();
3056: if (!ref($possible_langs)) {
3057: if( wantarray ) {
3058: return @preferred_langs;
3059: } else {
3060: return $preferred_langs[0];
3061: }
3062: }
3063: my %possibilities = map { $_ => 1 } (@$possible_langs);
3064: my @preferred_possibilities;
3065: foreach my $preferred_lang (@preferred_langs) {
3066: if (exists($possibilities{$preferred_lang})) {
3067: push(@preferred_possibilities, $preferred_lang);
3068: }
3069: }
3070: if( wantarray ) {
3071: return @preferred_possibilities;
3072: }
3073: return $preferred_possibilities[0];
3074: }
3075:
3076: sub user_lang {
3077: my ($touname,$toudom,$fromcid) = @_;
3078: my @userlangs;
3079: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3080: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3081: $env{'course.'.$fromcid.'.languages'}));
3082: } else {
3083: my %langhash = &getlangs($touname,$toudom);
3084: if ($langhash{'languages'} ne '') {
3085: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3086: } else {
3087: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3088: if ($domdefs{'lang_def'} ne '') {
3089: @userlangs = ($domdefs{'lang_def'});
3090: }
3091: }
3092: }
3093: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3094: my $user_lh = Apache::localize->get_handle(@languages);
3095: return $user_lh;
3096: }
3097:
3098:
3099: ###############################################################
3100: ## Student Answer Attempts ##
3101: ###############################################################
3102:
3103: =pod
3104:
3105: =head1 Alternate Problem Views
3106:
3107: =over 4
3108:
3109: =item * &get_previous_attempt($symb, $username, $domain, $course,
3110: $getattempt, $regexp, $gradesub)
3111:
3112: Return string with previous attempt on problem. Arguments:
3113:
3114: =over 4
3115:
3116: =item * $symb: Problem, including path
3117:
3118: =item * $username: username of the desired student
3119:
3120: =item * $domain: domain of the desired student
3121:
3122: =item * $course: Course ID
3123:
3124: =item * $getattempt: Leave blank for all attempts, otherwise put
3125: something
3126:
3127: =item * $regexp: if string matches this regexp, the string will be
3128: sent to $gradesub
3129:
3130: =item * $gradesub: routine that processes the string if it matches $regexp
3131:
3132: =back
3133:
3134: The output string is a table containing all desired attempts, if any.
3135:
3136: =cut
3137:
3138: sub get_previous_attempt {
3139: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
3140: my $prevattempts='';
3141: no strict 'refs';
3142: if ($symb) {
3143: my (%returnhash)=
3144: &Apache::lonnet::restore($symb,$course,$domain,$username);
3145: if ($returnhash{'version'}) {
3146: my %lasthash=();
3147: my $version;
3148: for ($version=1;$version<=$returnhash{'version'};$version++) {
3149: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3150: $lasthash{$key}=$returnhash{$version.':'.$key};
3151: }
3152: }
3153: $prevattempts=&start_data_table().&start_data_table_header_row();
3154: $prevattempts.='<th>'.&mt('History').'</th>';
3155: foreach my $key (sort(keys(%lasthash))) {
3156: my ($ign,@parts) = split(/\./,$key);
3157: if ($#parts > 0) {
3158: my $data=$parts[-1];
3159: pop(@parts);
3160: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
3161: } else {
3162: if ($#parts == 0) {
3163: $prevattempts.='<th>'.$parts[0].'</th>';
3164: } else {
3165: $prevattempts.='<th>'.$ign.'</th>';
3166: }
3167: }
3168: }
3169: $prevattempts.=&end_data_table_header_row();
3170: if ($getattempt eq '') {
3171: for ($version=1;$version<=$returnhash{'version'};$version++) {
3172: $prevattempts.=&start_data_table_row().
3173: '<td>'.&mt('Transaction [_1]',$version).'</td>';
3174: foreach my $key (sort(keys(%lasthash))) {
3175: my $value = &format_previous_attempt_value($key,
3176: $returnhash{$version.':'.$key});
3177: $prevattempts.='<td>'.$value.' </td>';
3178: }
3179: $prevattempts.=&end_data_table_row();
3180: }
3181: }
3182: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
3183: foreach my $key (sort(keys(%lasthash))) {
3184: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3185: if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
3186: $prevattempts.='<td>'.$value.' </td>';
3187: }
3188: $prevattempts.= &end_data_table_row().&end_data_table();
3189: } else {
3190: $prevattempts=
3191: &start_data_table().&start_data_table_row().
3192: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3193: &end_data_table_row().&end_data_table();
3194: }
3195: } else {
3196: $prevattempts=
3197: &start_data_table().&start_data_table_row().
3198: '<td>'.&mt('No data.').'</td>'.
3199: &end_data_table_row().&end_data_table();
3200: }
3201: }
3202:
3203: sub format_previous_attempt_value {
3204: my ($key,$value) = @_;
3205: if ($key =~ /timestamp/) {
3206: $value = &Apache::lonlocal::locallocaltime($value);
3207: } elsif (ref($value) eq 'ARRAY') {
3208: $value = '('.join(', ', @{ $value }).')';
3209: } else {
3210: $value = &unescape($value);
3211: }
3212: return $value;
3213: }
3214:
3215:
3216: sub relative_to_absolute {
3217: my ($url,$output)=@_;
3218: my $parser=HTML::TokeParser->new(\$output);
3219: my $token;
3220: my $thisdir=$url;
3221: my @rlinks=();
3222: while ($token=$parser->get_token) {
3223: if ($token->[0] eq 'S') {
3224: if ($token->[1] eq 'a') {
3225: if ($token->[2]->{'href'}) {
3226: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3227: }
3228: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3229: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3230: } elsif ($token->[1] eq 'base') {
3231: $thisdir=$token->[2]->{'href'};
3232: }
3233: }
3234: }
3235: $thisdir=~s-/[^/]*$--;
3236: foreach my $link (@rlinks) {
3237: unless (($link=~/^https?\:\/\//i) ||
3238: ($link=~/^\//) ||
3239: ($link=~/^javascript:/i) ||
3240: ($link=~/^mailto:/i) ||
3241: ($link=~/^\#/)) {
3242: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3243: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
3244: }
3245: }
3246: # -------------------------------------------------- Deal with Applet codebases
3247: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3248: return $output;
3249: }
3250:
3251: =pod
3252:
3253: =item * &get_student_view()
3254:
3255: show a snapshot of what student was looking at
3256:
3257: =cut
3258:
3259: sub get_student_view {
3260: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
3261: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
3262: my (%form);
3263: my @elements=('symb','courseid','domain','username');
3264: foreach my $element (@elements) {
3265: $form{'grade_'.$element}=eval '$'.$element #'
3266: }
3267: if (defined($moreenv)) {
3268: %form=(%form,%{$moreenv});
3269: }
3270: if (defined($target)) { $form{'grade_target'} = $target; }
3271: $feedurl=&Apache::lonnet::clutter($feedurl);
3272: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
3273: $userview=~s/\<body[^\>]*\>//gi;
3274: $userview=~s/\<\/body\>//gi;
3275: $userview=~s/\<html\>//gi;
3276: $userview=~s/\<\/html\>//gi;
3277: $userview=~s/\<head\>//gi;
3278: $userview=~s/\<\/head\>//gi;
3279: $userview=~s/action\s*\=/would_be_action\=/gi;
3280: $userview=&relative_to_absolute($feedurl,$userview);
3281: if (wantarray) {
3282: return ($userview,$response);
3283: } else {
3284: return $userview;
3285: }
3286: }
3287:
3288: sub get_student_view_with_retries {
3289: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3290:
3291: my $ok = 0; # True if we got a good response.
3292: my $content;
3293: my $response;
3294:
3295: # Try to get the student_view done. within the retries count:
3296:
3297: do {
3298: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3299: $ok = $response->is_success;
3300: if (!$ok) {
3301: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3302: }
3303: $retries--;
3304: } while (!$ok && ($retries > 0));
3305:
3306: if (!$ok) {
3307: $content = ''; # On error return an empty content.
3308: }
3309: if (wantarray) {
3310: return ($content, $response);
3311: } else {
3312: return $content;
3313: }
3314: }
3315:
3316: =pod
3317:
3318: =item * &get_student_answers()
3319:
3320: show a snapshot of how student was answering problem
3321:
3322: =cut
3323:
3324: sub get_student_answers {
3325: my ($symb,$username,$domain,$courseid,%form) = @_;
3326: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
3327: my (%moreenv);
3328: my @elements=('symb','courseid','domain','username');
3329: foreach my $element (@elements) {
3330: $moreenv{'grade_'.$element}=eval '$'.$element #'
3331: }
3332: $moreenv{'grade_target'}='answer';
3333: %moreenv=(%form,%moreenv);
3334: $feedurl = &Apache::lonnet::clutter($feedurl);
3335: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
3336: return $userview;
3337: }
3338:
3339: =pod
3340:
3341: =item * &submlink()
3342:
3343: Inputs: $text $uname $udom $symb $target
3344:
3345: Returns: A link to grades.pm such as to see the SUBM view of a student
3346:
3347: =cut
3348:
3349: ###############################################
3350: sub submlink {
3351: my ($text,$uname,$udom,$symb,$target)=@_;
3352: if (!($uname && $udom)) {
3353: (my $cursymb, my $courseid,$udom,$uname)=
3354: &Apache::lonnet::whichuser($symb);
3355: if (!$symb) { $symb=$cursymb; }
3356: }
3357: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
3358: $symb=&escape($symb);
3359: if ($target) { $target="target=\"$target\""; }
3360: return '<a href="/adm/grades?&command=submission&'.
3361: 'symb='.$symb.'&student='.$uname.
3362: '&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
3363: }
3364: ##############################################
3365:
3366: =pod
3367:
3368: =item * &pgrdlink()
3369:
3370: Inputs: $text $uname $udom $symb $target
3371:
3372: Returns: A link to grades.pm such as to see the PGRD view of a student
3373:
3374: =cut
3375:
3376: ###############################################
3377: sub pgrdlink {
3378: my $link=&submlink(@_);
3379: $link=~s/(&command=submission)/$1&showgrading=yes/;
3380: return $link;
3381: }
3382: ##############################################
3383:
3384: =pod
3385:
3386: =item * &pprmlink()
3387:
3388: Inputs: $text $uname $udom $symb $target
3389:
3390: Returns: A link to parmset.pm such as to see the PPRM view of a
3391: student and a specific resource
3392:
3393: =cut
3394:
3395: ###############################################
3396: sub pprmlink {
3397: my ($text,$uname,$udom,$symb,$target)=@_;
3398: if (!($uname && $udom)) {
3399: (my $cursymb, my $courseid,$udom,$uname)=
3400: &Apache::lonnet::whichuser($symb);
3401: if (!$symb) { $symb=$cursymb; }
3402: }
3403: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
3404: $symb=&escape($symb);
3405: if ($target) { $target="target=\"$target\""; }
3406: return '<a href="/adm/parmset?command=set&'.
3407: 'symb='.$symb.'&uname='.$uname.
3408: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
3409: }
3410: ##############################################
3411:
3412: =pod
3413:
3414: =back
3415:
3416: =cut
3417:
3418: ###############################################
3419:
3420:
3421: sub timehash {
3422: my ($thistime) = @_;
3423: my $timezone = &Apache::lonlocal::gettimezone();
3424: my $dt = DateTime->from_epoch(epoch => $thistime)
3425: ->set_time_zone($timezone);
3426: my $wday = $dt->day_of_week();
3427: if ($wday == 7) { $wday = 0; }
3428: return ( 'second' => $dt->second(),
3429: 'minute' => $dt->minute(),
3430: 'hour' => $dt->hour(),
3431: 'day' => $dt->day_of_month(),
3432: 'month' => $dt->month(),
3433: 'year' => $dt->year(),
3434: 'weekday' => $wday,
3435: 'dayyear' => $dt->day_of_year(),
3436: 'dlsav' => $dt->is_dst() );
3437: }
3438:
3439: sub utc_string {
3440: my ($date)=@_;
3441: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
3442: }
3443:
3444: sub maketime {
3445: my %th=@_;
3446: my ($epoch_time,$timezone,$dt);
3447: $timezone = &Apache::lonlocal::gettimezone();
3448: eval {
3449: $dt = DateTime->new( year => $th{'year'},
3450: month => $th{'month'},
3451: day => $th{'day'},
3452: hour => $th{'hour'},
3453: minute => $th{'minute'},
3454: second => $th{'second'},
3455: time_zone => $timezone,
3456: );
3457: };
3458: if (!$@) {
3459: $epoch_time = $dt->epoch;
3460: if ($epoch_time) {
3461: return $epoch_time;
3462: }
3463: }
3464: return POSIX::mktime(
3465: ($th{'seconds'},$th{'minutes'},$th{'hours'},
3466: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
3467: }
3468:
3469: #########################################
3470:
3471: sub findallcourses {
3472: my ($roles,$uname,$udom) = @_;
3473: my %roles;
3474: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
3475: my %courses;
3476: my $now=time;
3477: if (!defined($uname)) {
3478: $uname = $env{'user.name'};
3479: }
3480: if (!defined($udom)) {
3481: $udom = $env{'user.domain'};
3482: }
3483: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
3484: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
3485: if (!%roles) {
3486: %roles = (
3487: cc => 1,
3488: in => 1,
3489: ep => 1,
3490: ta => 1,
3491: cr => 1,
3492: st => 1,
3493: );
3494: }
3495: foreach my $entry (keys(%roleshash)) {
3496: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
3497: if ($trole =~ /^cr/) {
3498: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
3499: } else {
3500: next if (!exists($roles{$trole}));
3501: }
3502: if ($tend) {
3503: next if ($tend < $now);
3504: }
3505: if ($tstart) {
3506: next if ($tstart > $now);
3507: }
3508: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
3509: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
3510: if ($secpart eq '') {
3511: ($cnum,$role) = split(/_/,$cnumpart);
3512: $sec = 'none';
3513: $realsec = '';
3514: } else {
3515: $cnum = $cnumpart;
3516: ($sec,$role) = split(/_/,$secpart);
3517: $realsec = $sec;
3518: }
3519: $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
3520: }
3521: } else {
3522: foreach my $key (keys(%env)) {
3523: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
3524: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
3525: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
3526: next if ($role eq 'ca' || $role eq 'aa');
3527: next if (%roles && !exists($roles{$role}));
3528: my ($starttime,$endtime)=split(/\./,$env{$key});
3529: my $active=1;
3530: if ($starttime) {
3531: if ($now<$starttime) { $active=0; }
3532: }
3533: if ($endtime) {
3534: if ($now>$endtime) { $active=0; }
3535: }
3536: if ($active) {
3537: if ($sec eq '') {
3538: $sec = 'none';
3539: }
3540: $courses{$cdom.'_'.$cnum}{$sec} =
3541: $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
3542: }
3543: }
3544: }
3545: }
3546: return %courses;
3547: }
3548:
3549: ###############################################
3550:
3551: sub blockcheck {
3552: my ($setters,$activity,$uname,$udom) = @_;
3553:
3554: if (!defined($udom)) {
3555: $udom = $env{'user.domain'};
3556: }
3557: if (!defined($uname)) {
3558: $uname = $env{'user.name'};
3559: }
3560:
3561: # If uname and udom are for a course, check for blocks in the course.
3562:
3563: if (&Apache::lonnet::is_course($udom,$uname)) {
3564: my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
3565: my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
3566: return ($startblock,$endblock);
3567: }
3568:
3569: my $startblock = 0;
3570: my $endblock = 0;
3571: my %live_courses = &findallcourses(undef,$uname,$udom);
3572:
3573: # If uname is for a user, and activity is course-specific, i.e.,
3574: # boards, chat or groups, check for blocking in current course only.
3575:
3576: if (($activity eq 'boards' || $activity eq 'chat' ||
3577: $activity eq 'groups') && ($env{'request.course.id'})) {
3578: foreach my $key (keys(%live_courses)) {
3579: if ($key ne $env{'request.course.id'}) {
3580: delete($live_courses{$key});
3581: }
3582: }
3583: }
3584:
3585: my $otheruser = 0;
3586: my %own_courses;
3587: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
3588: # Resource belongs to user other than current user.
3589: $otheruser = 1;
3590: # Gather courses for current user
3591: %own_courses =
3592: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
3593: }
3594:
3595: # Gather active course roles - course coordinator, instructor,
3596: # exam proctor, ta, student, or custom role.
3597:
3598: foreach my $course (keys(%live_courses)) {
3599: my ($cdom,$cnum);
3600: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
3601: $cdom = $env{'course.'.$course.'.domain'};
3602: $cnum = $env{'course.'.$course.'.num'};
3603: } else {
3604: ($cdom,$cnum) = split(/_/,$course);
3605: }
3606: my $no_ownblock = 0;
3607: my $no_userblock = 0;
3608: if ($otheruser && $activity ne 'com') {
3609: # Check if current user has 'evb' priv for this
3610: if (defined($own_courses{$course})) {
3611: foreach my $sec (keys(%{$own_courses{$course}})) {
3612: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
3613: if ($sec ne 'none') {
3614: $checkrole .= '/'.$sec;
3615: }
3616: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3617: $no_ownblock = 1;
3618: last;
3619: }
3620: }
3621: }
3622: # if they have 'evb' priv and are currently not playing student
3623: next if (($no_ownblock) &&
3624: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
3625: }
3626: foreach my $sec (keys(%{$live_courses{$course}})) {
3627: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
3628: if ($sec ne 'none') {
3629: $checkrole .= '/'.$sec;
3630: }
3631: if ($otheruser) {
3632: # Resource belongs to user other than current user.
3633: # Assemble privs for that user, and check for 'evb' priv.
3634: my ($trole,$tdom,$tnum,$tsec);
3635: my $entry = $live_courses{$course}{$sec};
3636: if ($entry =~ /^cr/) {
3637: ($trole,$tdom,$tnum,$tsec) =
3638: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
3639: } else {
3640: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
3641: }
3642: my ($spec,$area,$trest,%allroles,%userroles);
3643: $area = '/'.$tdom.'/'.$tnum;
3644: $trest = $tnum;
3645: if ($tsec ne '') {
3646: $area .= '/'.$tsec;
3647: $trest .= '/'.$tsec;
3648: }
3649: $spec = $trole.'.'.$area;
3650: if ($trole =~ /^cr/) {
3651: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
3652: $tdom,$spec,$trest,$area);
3653: } else {
3654: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
3655: $tdom,$spec,$trest,$area);
3656: }
3657: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
3658: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
3659: if ($1) {
3660: $no_userblock = 1;
3661: last;
3662: }
3663: }
3664: } else {
3665: # Resource belongs to current user
3666: # Check for 'evb' priv via lonnet::allowed().
3667: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3668: $no_ownblock = 1;
3669: last;
3670: }
3671: }
3672: }
3673: # if they have the evb priv and are currently not playing student
3674: next if (($no_ownblock) &&
3675: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
3676: next if ($no_userblock);
3677:
3678: # Retrieve blocking times and identity of blocker for course
3679: # of specified user, unless user has 'evb' privilege.
3680:
3681: my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
3682: if (($start != 0) &&
3683: (($startblock == 0) || ($startblock > $start))) {
3684: $startblock = $start;
3685: }
3686: if (($end != 0) &&
3687: (($endblock == 0) || ($endblock < $end))) {
3688: $endblock = $end;
3689: }
3690: }
3691: return ($startblock,$endblock);
3692: }
3693:
3694: sub get_blocks {
3695: my ($setters,$activity,$cdom,$cnum) = @_;
3696: my $startblock = 0;
3697: my $endblock = 0;
3698: my $course = $cdom.'_'.$cnum;
3699: $setters->{$course} = {};
3700: $setters->{$course}{'staff'} = [];
3701: $setters->{$course}{'times'} = [];
3702: my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
3703: foreach my $record (keys(%records)) {
3704: my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
3705: if ($start <= time && $end >= time) {
3706: my ($staff_name,$staff_dom,$title,$blocks) =
3707: &parse_block_record($records{$record});
3708: if ($blocks->{$activity} eq 'on') {
3709: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
3710: push(@{$$setters{$course}{'times'}}, [$start,$end]);
3711: if ( ($startblock == 0) || ($startblock > $start) ) {
3712: $startblock = $start;
3713: }
3714: if ( ($endblock == 0) || ($endblock < $end) ) {
3715: $endblock = $end;
3716: }
3717: }
3718: }
3719: }
3720: return ($startblock,$endblock);
3721: }
3722:
3723: sub parse_block_record {
3724: my ($record) = @_;
3725: my ($setuname,$setudom,$title,$blocks);
3726: if (ref($record) eq 'HASH') {
3727: ($setuname,$setudom) = split(/:/,$record->{'setter'});
3728: $title = &unescape($record->{'event'});
3729: $blocks = $record->{'blocks'};
3730: } else {
3731: my @data = split(/:/,$record,3);
3732: if (scalar(@data) eq 2) {
3733: $title = $data[1];
3734: ($setuname,$setudom) = split(/@/,$data[0]);
3735: } else {
3736: ($setuname,$setudom,$title) = @data;
3737: }
3738: $blocks = { 'com' => 'on' };
3739: }
3740: return ($setuname,$setudom,$title,$blocks);
3741: }
3742:
3743: sub build_block_table {
3744: my ($startblock,$endblock,$setters) = @_;
3745: my %lt = &Apache::lonlocal::texthash(
3746: 'cacb' => 'Currently active communication blocks',
3747: 'cour' => 'Course',
3748: 'dura' => 'Duration',
3749: 'blse' => 'Block set by'
3750: );
3751: my $output;
3752: $output = '<br />'.$lt{'cacb'}.':<br />';
3753: $output .= &start_data_table();
3754: $output .= '
3755: <tr>
3756: <th>'.$lt{'cour'}.'</th>
3757: <th>'.$lt{'dura'}.'</th>
3758: <th>'.$lt{'blse'}.'</th>
3759: </tr>
3760: ';
3761: foreach my $course (keys(%{$setters})) {
3762: my %courseinfo=&Apache::lonnet::coursedescription($course);
3763: for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) {
3764: my ($uname,$udom) = @{$$setters{$course}{staff}[$i]};
3765: my $fullname = &plainname($uname,$udom);
3766: if (defined($env{'user.name'}) && defined($env{'user.domain'})
3767: && $env{'user.name'} ne 'public'
3768: && $env{'user.domain'} ne 'public') {
3769: $fullname = &aboutmewrapper($fullname,$uname,$udom);
3770: }
3771: my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]};
3772: $openblock = &Apache::lonlocal::locallocaltime($openblock);
3773: $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
3774: $output .= &Apache::loncommon::start_data_table_row().
3775: '<td>'.$courseinfo{'description'}.'</td>'.
3776: '<td>'.$openblock.' to '.$closeblock.'</td>'.
3777: '<td>'.$fullname.'</td>'.
3778: &Apache::loncommon::end_data_table_row();
3779: }
3780: }
3781: $output .= &end_data_table();
3782: }
3783:
3784: sub blocking_status {
3785: my ($activity,$uname,$udom) = @_;
3786: my %setters;
3787: my ($blocked,$output,$ownitem,$is_course);
3788: my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
3789: if ($startblock && $endblock) {
3790: $blocked = 1;
3791: if (wantarray) {
3792: my $category;
3793: if ($activity eq 'boards') {
3794: $category = 'Discussion posts in this course';
3795: } elsif ($activity eq 'blogs') {
3796: $category = 'Blogs';
3797: } elsif ($activity eq 'port') {
3798: if (defined($uname) && defined($udom)) {
3799: if ($uname eq $env{'user.name'} &&
3800: $udom eq $env{'user.domain'}) {
3801: $ownitem = 1;
3802: }
3803: }
3804: $is_course = &Apache::lonnet::is_course($udom,$uname);
3805: if ($ownitem) {
3806: $category = 'Your portfolio files';
3807: } elsif ($is_course) {
3808: my $coursedesc;
3809: foreach my $course (keys(%setters)) {
3810: my %courseinfo =
3811: &Apache::lonnet::coursedescription($course);
3812: $coursedesc = $courseinfo{'description'};
3813: }
3814: $category = "Group files in the course '$coursedesc'";
3815: } else {
3816: $category = 'Portfolio files belonging to ';
3817: if ($env{'user.name'} eq 'public' &&
3818: $env{'user.domain'} eq 'public') {
3819: $category .= &plainname($uname,$udom);
3820: } else {
3821: $category .= &aboutmewrapper(&plainname($uname,$udom),$uname,$udom);
3822: }
3823: }
3824: } elsif ($activity eq 'groups') {
3825: $category = 'Groups in this course';
3826: }
3827: my $showstart = &Apache::lonlocal::locallocaltime($startblock);
3828: my $showend = &Apache::lonlocal::locallocaltime($endblock);
3829: $output = '<br />'.&mt('[_1] will be inaccessible between [_2] and [_3] because communication is being blocked.',$category,$showstart,$showend).'<br />';
3830: if (!($activity eq 'port' && !($ownitem) && !($is_course))) {
3831: $output .= &build_block_table($startblock,$endblock,\%setters);
3832: }
3833: }
3834: }
3835: if (wantarray) {
3836: return ($blocked,$output);
3837: } else {
3838: return $blocked;
3839: }
3840: }
3841:
3842: ###############################################
3843:
3844: sub check_ip_acc {
3845: my ($acc)=@_;
3846: &Apache::lonxml::debug("acc is $acc");
3847: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
3848: return 1;
3849: }
3850: my $allowed=0;
3851: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
3852:
3853: my $name;
3854: foreach my $pattern (split(',',$acc)) {
3855: $pattern =~ s/^\s*//;
3856: $pattern =~ s/\s*$//;
3857: if ($pattern =~ /\*$/) {
3858: #35.8.*
3859: $pattern=~s/\*//;
3860: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
3861: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
3862: #35.8.3.[34-56]
3863: my $low=$2;
3864: my $high=$3;
3865: $pattern=$1;
3866: if ($ip =~ /^\Q$pattern\E/) {
3867: my $last=(split(/\./,$ip))[3];
3868: if ($last <=$high && $last >=$low) { $allowed=1; }
3869: }
3870: } elsif ($pattern =~ /^\*/) {
3871: #*.msu.edu
3872: $pattern=~s/\*//;
3873: if (!defined($name)) {
3874: use Socket;
3875: my $netaddr=inet_aton($ip);
3876: ($name)=gethostbyaddr($netaddr,AF_INET);
3877: }
3878: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
3879: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
3880: #127.0.0.1
3881: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
3882: } else {
3883: #some.name.com
3884: if (!defined($name)) {
3885: use Socket;
3886: my $netaddr=inet_aton($ip);
3887: ($name)=gethostbyaddr($netaddr,AF_INET);
3888: }
3889: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
3890: }
3891: if ($allowed) { last; }
3892: }
3893: return $allowed;
3894: }
3895:
3896: ###############################################
3897:
3898: =pod
3899:
3900: =head1 Domain Template Functions
3901:
3902: =over 4
3903:
3904: =item * &determinedomain()
3905:
3906: Inputs: $domain (usually will be undef)
3907:
3908: Returns: Determines which domain should be used for designs
3909:
3910: =cut
3911:
3912: ###############################################
3913: sub determinedomain {
3914: my $domain=shift;
3915: if (! $domain) {
3916: # Determine domain if we have not been given one
3917: $domain = $Apache::lonnet::perlvar{'lonDefDomain'};
3918: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
3919: if ($env{'request.role.domain'}) {
3920: $domain=$env{'request.role.domain'};
3921: }
3922: }
3923: return $domain;
3924: }
3925: ###############################################
3926:
3927: sub devalidate_domconfig_cache {
3928: my ($udom)=@_;
3929: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
3930: }
3931:
3932: # ---------------------- Get domain configuration for a domain
3933: sub get_domainconf {
3934: my ($udom) = @_;
3935: my $cachetime=1800;
3936: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
3937: if (defined($cached)) { return %{$result}; }
3938:
3939: my %domconfig = &Apache::lonnet::get_dom('configuration',
3940: ['login','rolecolors'],$udom);
3941: my (%designhash,%legacy);
3942: if (keys(%domconfig) > 0) {
3943: if (ref($domconfig{'login'}) eq 'HASH') {
3944: if (keys(%{$domconfig{'login'}})) {
3945: foreach my $key (keys(%{$domconfig{'login'}})) {
3946: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
3947: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
3948: $designhash{$udom.'.login.'.$key.'_'.$img} =
3949: $domconfig{'login'}{$key}{$img};
3950: }
3951: } else {
3952: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
3953: }
3954: }
3955: } else {
3956: $legacy{'login'} = 1;
3957: }
3958: } else {
3959: $legacy{'login'} = 1;
3960: }
3961: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
3962: if (keys(%{$domconfig{'rolecolors'}})) {
3963: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
3964: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
3965: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
3966: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
3967: }
3968: }
3969: }
3970: } else {
3971: $legacy{'rolecolors'} = 1;
3972: }
3973: } else {
3974: $legacy{'rolecolors'} = 1;
3975: }
3976: if (keys(%legacy) > 0) {
3977: my %legacyhash = &get_legacy_domconf($udom);
3978: foreach my $item (keys(%legacyhash)) {
3979: if ($item =~ /^\Q$udom\E\.login/) {
3980: if ($legacy{'login'}) {
3981: $designhash{$item} = $legacyhash{$item};
3982: }
3983: } else {
3984: if ($legacy{'rolecolors'}) {
3985: $designhash{$item} = $legacyhash{$item};
3986: }
3987: }
3988: }
3989: }
3990: } else {
3991: %designhash = &get_legacy_domconf($udom);
3992: }
3993: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
3994: $cachetime);
3995: return %designhash;
3996: }
3997:
3998: sub get_legacy_domconf {
3999: my ($udom) = @_;
4000: my %legacyhash;
4001: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4002: my $designfile = $designdir.'/'.$udom.'.tab';
4003: if (-e $designfile) {
4004: if ( open (my $fh,"<$designfile") ) {
4005: while (my $line = <$fh>) {
4006: next if ($line =~ /^\#/);
4007: chomp($line);
4008: my ($key,$val)=(split(/\=/,$line));
4009: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4010: }
4011: close($fh);
4012: }
4013: }
4014: if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
4015: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4016: }
4017: return %legacyhash;
4018: }
4019:
4020: =pod
4021:
4022: =item * &domainlogo()
4023:
4024: Inputs: $domain (usually will be undef)
4025:
4026: Returns: A link to a domain logo, if the domain logo exists.
4027: If the domain logo does not exist, a description of the domain.
4028:
4029: =cut
4030:
4031: ###############################################
4032: sub domainlogo {
4033: my $domain = &determinedomain(shift);
4034: my %designhash = &get_domainconf($domain);
4035: # See if there is a logo
4036: if ($designhash{$domain.'.login.domlogo'} ne '') {
4037: my $imgsrc = $designhash{$domain.'.login.domlogo'};
4038: if ($imgsrc =~ m{^/(adm|res)/}) {
4039: if ($imgsrc =~ m{^/res/}) {
4040: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4041: &Apache::lonnet::repcopy($local_name);
4042: }
4043: $imgsrc = &lonhttpdurl($imgsrc);
4044: }
4045: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
4046: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4047: return &Apache::lonnet::domain($domain,'description');
4048: } else {
4049: return '';
4050: }
4051: }
4052: ##############################################
4053:
4054: =pod
4055:
4056: =item * &designparm()
4057:
4058: Inputs: $which parameter; $domain (usually will be undef)
4059:
4060: Returns: value of designparamter $which
4061:
4062: =cut
4063:
4064:
4065: ##############################################
4066: sub designparm {
4067: my ($which,$domain)=@_;
4068: if ($env{'browser.blackwhite'} eq 'on') {
4069: if ($which=~/\.(font|alink|vlink|link|textcol)$/) {
4070: return '#000000';
4071: }
4072: if ($which=~/\.(pgbg|sidebg|bgcol)$/) {
4073: return '#FFFFFF';
4074: }
4075: if ($which=~/\.tabbg$/) {
4076: return '#CCCCCC';
4077: }
4078: }
4079: if (exists($env{'environment.color.'.$which})) {
4080: return $env{'environment.color.'.$which};
4081: }
4082: $domain=&determinedomain($domain);
4083: my %domdesign = &get_domainconf($domain);
4084: my $output;
4085: if ($domdesign{$domain.'.'.$which} ne '') {
4086: $output = $domdesign{$domain.'.'.$which};
4087: } else {
4088: $output = $defaultdesign{$which};
4089: }
4090: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
4091: ($which =~ /login\.(img|logo|domlogo|login)/)) {
4092: if ($output =~ m{^/(adm|res)/}) {
4093: if ($output =~ m{^/res/}) {
4094: my $local_name = &Apache::lonnet::filelocation('',$output);
4095: &Apache::lonnet::repcopy($local_name);
4096: }
4097: $output = &lonhttpdurl($output);
4098: }
4099: }
4100: return $output;
4101: }
4102:
4103: ###############################################
4104: ###############################################
4105:
4106: =pod
4107:
4108: =back
4109:
4110: =head1 HTML Helpers
4111:
4112: =over 4
4113:
4114: =item * &bodytag()
4115:
4116: Returns a uniform header for LON-CAPA web pages.
4117:
4118: Inputs:
4119:
4120: =over 4
4121:
4122: =item * $title, A title to be displayed on the page.
4123:
4124: =item * $function, the current role (can be undef).
4125:
4126: =item * $addentries, extra parameters for the <body> tag.
4127:
4128: =item * $bodyonly, if defined, only return the <body> tag.
4129:
4130: =item * $domain, if defined, force a given domain.
4131:
4132: =item * $forcereg, if page should register as content page (relevant for
4133: text interface only)
4134:
4135: =item * $customtitle, alternate text to use instead of $title
4136: in the title box that appears, this text
4137: is not auto translated like the $title is
4138:
4139: =item * $notopbar, if true, keep the 'what is this' info but remove the
4140: navigational links
4141:
4142: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
4143:
4144: =item * $notitle, if true keep the nav controls, but remove the title bar
4145:
4146: =item * $no_inline_link, if true and in remote mode, don't show the
4147: 'Switch To Inline Menu' link
4148:
4149: =item * $args, optional argument valid values are
4150: no_auto_mt_title -> prevents &mt()ing the title arg
4151: inherit_jsmath -> when creating popup window in a page,
4152: should it have jsmath forced on by the
4153: current page
4154:
4155: =back
4156:
4157: Returns: A uniform header for LON-CAPA web pages.
4158: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
4159: If $bodyonly is undef or zero, an html string containing a <body> tag and
4160: other decorations will be returned.
4161:
4162: =cut
4163:
4164: sub bodytag {
4165: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,$customtitle,
4166: $notopbar,$bgcolor,$notitle,$no_inline_link,$args)=@_;
4167:
4168: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
4169:
4170: $function = &get_users_function() if (!$function);
4171: my $img = &designparm($function.'.img',$domain);
4172: my $font = &designparm($function.'.font',$domain);
4173: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
4174:
4175: my %design = ( 'style' => 'margin-top: 0px',
4176: 'bgcolor' => $pgbg,
4177: 'text' => $font,
4178: 'alink' => &designparm($function.'.alink',$domain),
4179: 'vlink' => &designparm($function.'.vlink',$domain),
4180: 'link' => &designparm($function.'.link',$domain),);
4181: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
4182:
4183: # role and realm
4184: my ($role,$realm) = split(/\./,$env{'request.role'},2);
4185: if ($role eq 'ca') {
4186: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
4187: $realm = &plainname($rname,$rdom);
4188: }
4189: # realm
4190: if ($env{'request.course.id'}) {
4191: if ($env{'request.role'} !~ /^cr/) {
4192: $role = &Apache::lonnet::plaintext($role,&course_type());
4193: }
4194: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
4195: } else {
4196: $role = &Apache::lonnet::plaintext($role);
4197: }
4198:
4199: if (!$realm) { $realm=' '; }
4200: # Set messages
4201: my $messages=&domainlogo($domain);
4202:
4203: my $extra_body_attr = &make_attr_string($forcereg,\%design);
4204:
4205: # construct main body tag
4206: my $bodytag = "<body $extra_body_attr>".
4207: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
4208:
4209: if ($bodyonly) {
4210: return $bodytag;
4211: } elsif ($env{'browser.interface'} eq 'textual') {
4212: # Accessibility
4213:
4214: $bodytag.=&Apache::lonmenu::menubuttons($forcereg,$forcereg);
4215: if (!$notitle) {
4216: $bodytag.='<h1>LON-CAPA: '.$title.'</h1>';
4217: }
4218: return $bodytag;
4219: }
4220:
4221: my $name = &plainname($env{'user.name'},$env{'user.domain'});
4222: if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
4223: undef($role);
4224: } else {
4225: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
4226: }
4227:
4228: my $roleinfo=(<<ENDROLE);
4229: <td class="LC_title_bar_who">
4230: <div class="LC_title_bar_name">
4231: $name
4232:
4233: </div>
4234: <div class="LC_title_bar_role">
4235: $role
4236: </div>
4237: <div class="LC_title_bar_realm">
4238: $realm
4239: </div>
4240: </td>
4241: ENDROLE
4242:
4243: my $titleinfo = '<span class="LC_title_bar_title">'.$title.'</span>';
4244: if ($customtitle) {
4245: $titleinfo = $customtitle;
4246: }
4247: #
4248: # Extra info if you are the DC
4249: my $dc_info = '';
4250: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
4251: $env{'course.'.$env{'request.course.id'}.
4252: '.domain'}.'/'})) {
4253: my $cid = $env{'request.course.id'};
4254: $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
4255: $dc_info =~ s/\s+$//;
4256: $dc_info = '('.$dc_info.')';
4257: }
4258:
4259: if (($env{'environment.remote'} eq 'off') || ($args->{'suppress_header_logos'})) {
4260: # No Remote
4261: if ($env{'request.state'} eq 'construct') {
4262: $forcereg=1;
4263: }
4264:
4265: if (!$customtitle && $env{'request.state'} eq 'construct') {
4266: # this is for resources; directories have customtitle, and crumbs
4267: # and select recent are created in lonpubdir.pm
4268: my ($uname,$thisdisfn)=
4269: ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
4270: my $formaction='/priv/'.$uname.'/'.$thisdisfn;
4271: $formaction=~s/\/+/\//g;
4272:
4273: my $parentpath = '';
4274: my $lastitem = '';
4275: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4276: $parentpath = $1;
4277: $lastitem = $2;
4278: } else {
4279: $lastitem = $thisdisfn;
4280: }
4281: $titleinfo =
4282: &Apache::loncommon::help_open_menu('','',3,'Authoring')
4283: .'<b>'.&mt('Construction Space').'</b>: '
4284: .'<form name="dirs" method="post" action="'.$formaction
4285: .'" target="_top"><tt><b>'
4286: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."<span class=\"LC_fontsize_big\">$lastitem</span></b></tt><br />"
4287: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4288: .'</form>'
4289: .&Apache::lonmenu::constspaceform();
4290: }
4291:
4292: my $titletable;
4293: if (!$notitle) {
4294: $titletable =
4295: '<table id="LC_title_bar">'.
4296: "<tr><td> $titleinfo $dc_info</td>".$roleinfo.
4297: '</tr></table>';
4298: }
4299: if ($notopbar) {
4300: $bodytag .= $titletable;
4301: } else {
4302: if ($env{'request.state'} eq 'construct') {
4303: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg,
4304: $titletable);
4305: } else {
4306: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg).
4307: $titletable;
4308: }
4309: }
4310: return $bodytag;
4311: }
4312:
4313: #
4314: # Top frame rendering, Remote is up
4315: #
4316:
4317: my $imgsrc = $img;
4318: if ($img =~ /^\/adm/) {
4319: $imgsrc = &lonhttpdurl($img);
4320: }
4321: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
4322:
4323: # Explicit link to get inline menu
4324: my $menu= ($no_inline_link?''
4325: :'<br /><a href="/adm/remote?action=collapse">'.&mt('Switch to Inline Menu Mode').'</a>');
4326: #
4327: if ($notitle) {
4328: return $bodytag;
4329: }
4330: return(<<ENDBODY);
4331: $bodytag
4332: <table id="LC_title_bar" class="LC_with_remote">
4333: <tr><td class="LC_title_bar_role_logo">$upperleft</td>
4334: <td class="LC_title_bar_domain_logo">$messages </td>
4335: </tr>
4336: <tr><td>$titleinfo $dc_info $menu</td>
4337: $roleinfo
4338: </tr>
4339: </table>
4340: ENDBODY
4341: }
4342:
4343: sub make_attr_string {
4344: my ($register,$attr_ref) = @_;
4345:
4346: if ($attr_ref && !ref($attr_ref)) {
4347: die("addentries Must be a hash ref ".
4348: join(':',caller(1))." ".
4349: join(':',caller(0))." ");
4350: }
4351:
4352: if ($register) {
4353: my ($on_load,$on_unload);
4354: foreach my $key (keys(%{$attr_ref})) {
4355: if (lc($key) eq 'onload') {
4356: $on_load.=$attr_ref->{$key}.';';
4357: delete($attr_ref->{$key});
4358:
4359: } elsif (lc($key) eq 'onunload') {
4360: $on_unload.=$attr_ref->{$key}.';';
4361: delete($attr_ref->{$key});
4362: }
4363: }
4364: $attr_ref->{'onload'} =
4365: &Apache::lonmenu::loadevents(). $on_load;
4366: $attr_ref->{'onunload'}=
4367: &Apache::lonmenu::unloadevents().$on_unload;
4368: }
4369:
4370: # Accessibility font enhance
4371: if ($env{'browser.fontenhance'} eq 'on') {
4372: my $style;
4373: foreach my $key (keys(%{$attr_ref})) {
4374: if (lc($key) eq 'style') {
4375: $style.=$attr_ref->{$key}.';';
4376: delete($attr_ref->{$key});
4377: }
4378: }
4379: $attr_ref->{'style'}=$style.'; font-size: x-large;';
4380: }
4381:
4382: if ($env{'browser.blackwhite'} eq 'on') {
4383: delete($attr_ref->{'font'});
4384: delete($attr_ref->{'link'});
4385: delete($attr_ref->{'alink'});
4386: delete($attr_ref->{'vlink'});
4387: delete($attr_ref->{'bgcolor'});
4388: delete($attr_ref->{'background'});
4389: }
4390:
4391: my $attr_string;
4392: foreach my $attr (keys(%$attr_ref)) {
4393: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
4394: }
4395: return $attr_string;
4396: }
4397:
4398:
4399: ###############################################
4400: ###############################################
4401:
4402: =pod
4403:
4404: =item * &endbodytag()
4405:
4406: Returns a uniform footer for LON-CAPA web pages.
4407:
4408: Inputs: 1 - optional reference to an args hash
4409: If in the hash, key for noredirectlink has a value which evaluates to true,
4410: a 'Continue' link is not displayed if the page contains an
4411: internal redirect in the <head></head> section,
4412: i.e., $env{'internal.head.redirect'} exists
4413:
4414: =cut
4415:
4416: sub endbodytag {
4417: my ($args) = @_;
4418: my $endbodytag='</body>';
4419: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
4420: if ( exists( $env{'internal.head.redirect'} ) ) {
4421: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
4422: $endbodytag=
4423: "<br /><a href=\"$env{'internal.head.redirect'}\">".
4424: &mt('Continue').'</a>'.
4425: $endbodytag;
4426: }
4427: }
4428: return $endbodytag;
4429: }
4430:
4431: =pod
4432:
4433: =item * &standard_css()
4434:
4435: Returns a style sheet
4436:
4437: Inputs: (all optional)
4438: domain -> force to color decorate a page for a specific
4439: domain
4440: function -> force usage of a specific rolish color scheme
4441: bgcolor -> override the default page bgcolor
4442:
4443: =cut
4444:
4445: sub standard_css {
4446: my ($function,$domain,$bgcolor) = @_;
4447: $function = &get_users_function() if (!$function);
4448: my $img = &designparm($function.'.img', $domain);
4449: my $tabbg = &designparm($function.'.tabbg', $domain);
4450: my $font = &designparm($function.'.font', $domain);
4451: my $sidebg = &designparm($function.'.sidebg',$domain);
4452: my $pgbg_or_bgcolor =
4453: $bgcolor ||
4454: &designparm($function.'.pgbg', $domain);
4455: my $pgbg = &designparm($function.'.pgbg', $domain);
4456: my $alink = &designparm($function.'.alink', $domain);
4457: my $vlink = &designparm($function.'.vlink', $domain);
4458: my $link = &designparm($function.'.link', $domain);
4459:
4460: my $loginbg = &designparm('login.sidebg',$domain);
4461: my $bgcol = &designparm('login.bgcol',$domain);
4462: my $textcol = &designparm('login.textcol',$domain);
4463:
4464: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
4465: my $mono = 'monospace';
4466: my $data_table_head = $tabbg;
4467: my $data_table_light = '#EEEEEE';
4468: my $data_table_dark = '#DDDDDD';
4469: my $data_table_darker = '#CCCCCC';
4470: my $data_table_highlight = '#FFFF00';
4471: my $mail_new = '#FFBB77';
4472: my $mail_new_hover = '#DD9955';
4473: my $mail_read = '#BBBB77';
4474: my $mail_read_hover = '#999944';
4475: my $mail_replied = '#AAAA88';
4476: my $mail_replied_hover = '#888855';
4477: my $mail_other = '#99BBBB';
4478: my $mail_other_hover = '#669999';
4479: my $table_header = '#DDDDDD';
4480: my $feedback_link_bg = '#BBBBBB';
4481: my $lg_border_color = '#C8C8C8';
4482:
4483: my $border = ($env{'browser.type'} eq 'explorer' ||
4484: $env{'browser.type'} eq 'safari' ) ? '0px 2px 0px 2px'
4485: : '0px 3px 0px 4px';
4486:
4487:
4488: return <<END;
4489: body{
4490: font-family: $sans;
4491: line-height:130%;
4492: font-size:0.83em;
4493: color:$font;
4494: }
4495: a:link, a:visited { font-size:100%; }
4496:
4497: a:focus { color: red; background: yellow }
4498: table.thinborder,
4499: table.thinborder tr th {
4500: border-style: solid;
4501: border-width: 1px;
4502: border-color: $lg_border_color;
4503: background: $tabbg;
4504: }
4505: table.thinborder tr td {
4506: border-style: solid;
4507: border-width: 1px;
4508: border-color: $lg_border_color;
4509: }
4510:
4511: form, .inline { display: inline; }
4512:
4513: .LC_center { text-align: center; }
4514: .LC_left { text-align:left; }
4515: .LC_right {text-align:right;}
4516: .LC_middle {vertical-align:middle;}
4517: .LC_top {vertical-align:top;}
4518: .LC_bottom {vertical-align:bottom;}
4519:
4520: /* just for tests */
4521: .LC_300Box { width:300px; }
4522: .LC_200Box {width:200px; }
4523: .LC_500Box {width:500px; }
4524: .LC_600Box {width:600px; }
4525: .LC_800Box {width:800px;}
4526: /* end */
4527:
4528: .LC_filename {font-family: $mono; white-space:pre;}
4529: .LC_error {
4530: color: red;
4531: font-size: larger;
4532: }
4533: .LC_warning,
4534: .LC_diff_removed {
4535: color: red;
4536: }
4537:
4538: .LC_info,
4539: .LC_success,
4540: .LC_diff_added {
4541: color: green;
4542: }
4543: .LC_unknown {
4544: color: yellow;
4545: }
4546:
4547: .LC_icon {
4548: border: 0px;
4549: }
4550: .LC_indexer_icon {
4551: border: 0px;
4552: height: 22px;
4553: }
4554: .LC_docs_spacer {
4555: width: 25px;
4556: height: 1px;
4557: border: 0px;
4558: }
4559:
4560: .LC_internal_info {
4561: color: #999999;
4562: }
4563:
4564: table.LC_pastsubmission {
4565: border: 1px solid black;
4566: margin: 2px;
4567: }
4568:
4569: table#LC_top_nav, table#LC_menubuttons,table#LC_nav_location {
4570: width: 100%;
4571: background: $pgbg;
4572: border: 2px;
4573: border-collapse: separate;
4574: padding: 0px;
4575: }
4576:
4577: table#LC_title_bar, table.LC_breadcrumbs,
4578: table#LC_title_bar.LC_with_remote {
4579: width: 100%;
4580: border-color: $pgbg;
4581: border-style: solid;
4582: border-width: $border;
4583:
4584: background: $pgbg;
4585: font-family: $sans;
4586: border-collapse: collapse;
4587: padding: 0px;
4588: }
4589: table.LC_docs_path {
4590: width: 100%;
4591: border: 0;
4592: background: $pgbg;
4593: font-family: $sans;
4594: border-collapse: collapse;
4595: padding: 0px;
4596: }
4597:
4598: table#LC_title_bar td {
4599: background: $tabbg;
4600: }
4601: table#LC_title_bar td.LC_title_bar_who {
4602: background: $tabbg;
4603: color: $font;
4604: font: small $sans;
4605: text-align: right;
4606: }
4607: span.LC_metadata {
4608: font-family: $sans;
4609: }
4610: span.LC_title_bar_title {
4611: font: bold x-large $sans;
4612: }
4613: table#LC_title_bar td.LC_title_bar_domain_logo {
4614: background: $sidebg;
4615: text-align: right;
4616: padding: 0px;
4617: }
4618: table#LC_title_bar td.LC_title_bar_role_logo {
4619: background: $sidebg;
4620: padding: 0px;
4621: }
4622:
4623: table#LC_menubuttons img{
4624: border: 0px;
4625: }
4626: table#LC_top_nav td {
4627: background: $tabbg;
4628: border: 0px;
4629: font-size: small;
4630: vertical-align:top;
4631: padding:2px 5px 2px 5px;
4632: }
4633: table#LC_top_nav td a, div#LC_top_nav a {
4634: color: $font;
4635: font-family: $sans;
4636: }
4637: table#LC_top_nav td.LC_top_nav_logo {
4638: background: $tabbg;
4639: text-align: left;
4640: white-space: nowrap;
4641: width: 31px;
4642: }
4643: table#LC_top_nav td.LC_top_nav_logo img {
4644: border: 0px;
4645: vertical-align: bottom;
4646: }
4647: table#LC_top_nav td.LC_top_nav_exit,
4648: table#LC_top_nav td.LC_top_nav_help {
4649: width: 2.0em;
4650: }
4651: table#LC_top_nav td.LC_top_nav_login {
4652: width: 4.0em;
4653: text-align: center;
4654: }
4655: table.LC_breadcrumbs td, table.LC_docs_path td {
4656: background: $tabbg;
4657: color: $font;
4658: font-family: $sans;
4659: font-size: smaller;
4660: }
4661: table.LC_breadcrumbs td.LC_breadcrumbs_component,
4662: table.LC_docs_path td.LC_docs_path_component {
4663: background: $tabbg;
4664: color: $font;
4665: font-family: $sans;
4666: font-size: larger;
4667: text-align: right;
4668: }
4669: td.LC_table_cell_checkbox {
4670: text-align: center;
4671: }
4672: table#LC_mainmenu td.LC_mainmenu_column {
4673: vertical-align: top;
4674: }
4675:
4676: .LC_fontsize_small
4677: {
4678: font-size: 70%;
4679: }
4680:
4681: .LC_fontsize_medium
4682: {
4683: font-size: 85%;
4684: }
4685:
4686: .LC_fontsize_large
4687: {
4688: font-size: 120%;
4689: }
4690:
4691: .LC_fontcolor_red
4692: {
4693: color: #FF0000;
4694: }
4695:
4696: .LC_menubuttons_inline_text {
4697: color: $font;
4698: font-family: $sans;
4699: font-size: 90%;
4700: padding-left:3px;
4701: }
4702:
4703: .LC_menubuttons_link {
4704: text-decoration: none;
4705: }
4706: /*2008--9-5: new menu style sheet.Changed category*/
4707: .LC_menubuttons_category {
4708: color: $font;
4709: background: $pgbg;
4710: font-family: $sans;
4711: font-size: larger;
4712: font-weight: bold;
4713: }
4714:
4715: td.LC_menubuttons_text {
4716: color: $font;
4717: }
4718:
4719:
4720:
4721: .LC_current_location {
4722: font-family: $sans;
4723: background: $tabbg;
4724: }
4725: .LC_new_mail {
4726: font-family: $sans;
4727: background: $tabbg;
4728: font-weight: bold;
4729: }
4730:
4731:
4732: .LC_dropadd_labeltext {
4733: font-family: $sans;
4734: text-align: right;
4735: }
4736:
4737: .LC_preferences_labeltext {
4738: font-family: $sans;
4739: text-align: right;
4740: }
4741:
4742: .LC_roleslog_note {
4743: font-size: small;
4744: }
4745:
4746: .LC_mail_functions {
4747: font-weight: bold;
4748: }
4749:
4750: table.LC_aboutme_port {
4751: border: 0px;
4752: border-collapse: collapse;
4753: border-spacing: 0px;
4754: }
4755: table.LC_data_table, table.LC_mail_list {
4756: border: 1px solid #000000;
4757: border-collapse: separate;
4758: border-spacing: 1px;
4759: background: $pgbg;
4760: }
4761: .LC_data_table_dense {
4762: font-size: small;
4763: }
4764: table.LC_nested_outer {
4765: border: 1px solid #000000;
4766: border-collapse: collapse;
4767: border-spacing: 0px;
4768: width: 100%;
4769: }
4770: table.LC_nested {
4771: border: 0px;
4772: border-collapse: collapse;
4773: border-spacing: 0px;
4774: width: 100%;
4775: }
4776: table.LC_data_table tr th, table.LC_calendar tr th, table.LC_mail_list tr th,
4777: table.LC_prior_tries tr th {
4778: font-weight: bold;
4779: background-color: $data_table_head;
4780: font-size:90%;
4781: }
4782: table.LC_data_table tr.LC_info_row > td {
4783: background-color: #CCCCCC;
4784: font-weight: bold;
4785: text-align: left;
4786: }
4787: table.LC_data_table tr.LC_odd_row > td,
4788: table.LC_pick_box tr > td.LC_odd_row,
4789: table.LC_aboutme_port tr td {
4790: background-color: $data_table_light;
4791: padding: 2px;
4792: }
4793: table.LC_data_table tr.LC_even_row > td,
4794: table.LC_pick_box tr > td.LC_even_row,
4795: table.LC_aboutme_port tr.LC_even_row td {
4796: background-color: $data_table_dark;
4797: padding: 2px;
4798: }
4799: table.LC_data_table tr.LC_data_table_highlight td {
4800: background-color: $data_table_darker;
4801: }
4802: table.LC_data_table tr td.LC_leftcol_header {
4803: background-color: $data_table_head;
4804: font-weight: bold;
4805: }
4806: table.LC_data_table tr.LC_empty_row td,
4807: table.LC_nested tr.LC_empty_row td {
4808: background-color: #FFFFFF;
4809: font-weight: bold;
4810: font-style: italic;
4811: text-align: center;
4812: padding: 8px;
4813: }
4814: table.LC_nested tr.LC_empty_row td {
4815: padding: 4ex
4816: }
4817: table.LC_nested_outer tr th {
4818: font-weight: bold;
4819: background-color: $data_table_head;
4820: font-size: small;
4821: border-bottom: 1px solid #000000;
4822: }
4823: table.LC_nested_outer tr td.LC_subheader {
4824: background-color: $data_table_head;
4825: font-weight: bold;
4826: font-size: small;
4827: border-bottom: 1px solid #000000;
4828: text-align: right;
4829: }
4830: table.LC_nested tr.LC_info_row td {
4831: background-color: #CCCCCC;
4832: font-weight: bold;
4833: font-size: small;
4834: text-align: center;
4835: }
4836: table.LC_nested tr.LC_info_row td.LC_left_item,
4837: table.LC_nested_outer tr th.LC_left_item {
4838: text-align: left;
4839: }
4840: table.LC_nested td {
4841: background-color: #FFFFFF;
4842: font-size: small;
4843: }
4844: table.LC_nested_outer tr th.LC_right_item,
4845: table.LC_nested tr.LC_info_row td.LC_right_item,
4846: table.LC_nested tr.LC_odd_row td.LC_right_item,
4847: table.LC_nested tr td.LC_right_item {
4848: text-align: right;
4849: }
4850:
4851: table.LC_nested tr.LC_odd_row td {
4852: background-color: #EEEEEE;
4853: }
4854:
4855: table.LC_createuser {
4856: }
4857:
4858: table.LC_createuser tr.LC_section_row td {
4859: font-size: small;
4860: }
4861:
4862: table.LC_createuser tr.LC_info_row td {
4863: background-color: #CCCCCC;
4864: font-weight: bold;
4865: text-align: center;
4866: }
4867:
4868: table.LC_calendar {
4869: border: 1px solid #000000;
4870: border-collapse: collapse;
4871: }
4872: table.LC_calendar_pickdate {
4873: font-size: xx-small;
4874: }
4875: table.LC_calendar tr td {
4876: border: 1px solid #000000;
4877: vertical-align: top;
4878: }
4879: table.LC_calendar tr td.LC_calendar_day_empty {
4880: background-color: $data_table_dark;
4881: }
4882: table.LC_calendar tr td.LC_calendar_day_current {
4883: background-color: $data_table_highlight;
4884: }
4885:
4886: table.LC_mail_list tr.LC_mail_new {
4887: background-color: $mail_new;
4888: }
4889: table.LC_mail_list tr.LC_mail_new:hover {
4890: background-color: $mail_new_hover;
4891: }
4892: table.LC_mail_list tr.LC_mail_read {
4893: background-color: $mail_read;
4894: }
4895: table.LC_mail_list tr.LC_mail_read:hover {
4896: background-color: $mail_read_hover;
4897: }
4898: table.LC_mail_list tr.LC_mail_replied {
4899: background-color: $mail_replied;
4900: }
4901: table.LC_mail_list tr.LC_mail_replied:hover {
4902: background-color: $mail_replied_hover;
4903: }
4904: table.LC_mail_list tr.LC_mail_other {
4905: background-color: $mail_other;
4906: }
4907: table.LC_mail_list tr.LC_mail_other:hover {
4908: background-color: $mail_other_hover;
4909: }
4910: table.LC_mail_list tr.LC_mail_even {
4911: }
4912: table.LC_mail_list tr.LC_mail_odd {
4913: }
4914:
4915: table.LC_data_table tr > td.LC_browser_file,
4916: table.LC_data_table tr > td.LC_browser_file_published {
4917: background: #CCFF88;
4918: }
4919: table.LC_data_table tr > td.LC_browser_file_locked,
4920: table.LC_data_table tr > td.LC_browser_file_unpublished {
4921: background: #FFAA99;
4922: }
4923: table.LC_data_table tr > td.LC_browser_file_obsolete {
4924: background: #AAAAAA;
4925: }
4926: table.LC_data_table tr > td.LC_browser_file_modified,
4927: table.LC_data_table tr > td.LC_browser_file_metamodified {
4928: background: #FFFF77;
4929: }
4930: table.LC_data_table tr.LC_browser_folder > td {
4931: background: #CCCCFF;
4932: }
4933:
4934: table.LC_data_table tr > td.LC_roles_is {
4935: /* background: #77FF77; */
4936: }
4937: table.LC_data_table tr > td.LC_roles_future {
4938: background: #FFFF77;
4939: }
4940: table.LC_data_table tr > td.LC_roles_will {
4941: background: #FFAA77;
4942: }
4943: table.LC_data_table tr > td.LC_roles_expired {
4944: background: #FF7777;
4945: }
4946: table.LC_data_table tr > td.LC_roles_will_not {
4947: background: #AAFF77;
4948: }
4949: table.LC_data_table tr > td.LC_roles_selected {
4950: background: #11CC55;
4951: }
4952:
4953: span.LC_current_location {
4954: font-size:larger;
4955: background: $pgbg;
4956: }
4957:
4958: span.LC_parm_menu_item {
4959: font-size: larger;
4960: font-family: $sans;
4961: }
4962: span.LC_parm_scope_all {
4963: color: red;
4964: }
4965: span.LC_parm_scope_folder {
4966: color: green;
4967: }
4968: span.LC_parm_scope_resource {
4969: color: orange;
4970: }
4971: span.LC_parm_part {
4972: color: blue;
4973: }
4974: span.LC_parm_folder, span.LC_parm_symb {
4975: font-size: x-small;
4976: font-family: $mono;
4977: color: #AAAAAA;
4978: }
4979:
4980: td.LC_parm_overview_level_menu, td.LC_parm_overview_map_menu,
4981: td.LC_parm_overview_parm_selectors, td.LC_parm_overview_parm_restrictions {
4982: border: 1px solid black;
4983: border-collapse: collapse;
4984: }
4985: table.LC_parm_overview_restrictions td {
4986: border-width: 1px 4px 1px 4px;
4987: border-style: solid;
4988: border-color: $pgbg;
4989: text-align: center;
4990: }
4991: table.LC_parm_overview_restrictions th {
4992: background: $tabbg;
4993: border-width: 1px 4px 1px 4px;
4994: border-style: solid;
4995: border-color: $pgbg;
4996: }
4997: table#LC_helpmenu {
4998: border: 0px;
4999: height: 55px;
5000: border-spacing: 0px;
5001: }
5002:
5003: table#LC_helpmenu fieldset legend {
5004: font-size: larger;
5005: font-weight: bold;
5006: }
5007: table#LC_helpmenu_links {
5008: width: 100%;
5009: border: 1px solid black;
5010: background: $pgbg;
5011: padding: 0px;
5012: border-spacing: 1px;
5013: }
5014: table#LC_helpmenu_links tr td {
5015: padding: 1px;
5016: background: $tabbg;
5017: text-align: center;
5018: font-weight: bold;
5019: }
5020:
5021: table#LC_helpmenu_links a:link, table#LC_helpmenu_links a:visited,
5022: table#LC_helpmenu_links a:active {
5023: text-decoration: none;
5024: color: $font;
5025: }
5026: table#LC_helpmenu_links a:hover {
5027: text-decoration: underline;
5028: color: $vlink;
5029: }
5030:
5031: .LC_chrt_popup_exists {
5032: border: 1px solid #339933;
5033: margin: -1px;
5034: }
5035: .LC_chrt_popup_up {
5036: border: 1px solid yellow;
5037: margin: -1px;
5038: }
5039: .LC_chrt_popup {
5040: border: 1px solid #8888FF;
5041: background: #CCCCFF;
5042: }
5043: table.LC_pick_box {
5044: border-collapse: separate;
5045: background: white;
5046: border: 1px solid black;
5047: border-spacing: 1px;
5048: }
5049: table.LC_pick_box td.LC_pick_box_title {
5050: background: $tabbg;
5051: font-weight: bold;
5052: text-align: right;
5053: vertical-align: top;
5054: width: 184px;
5055: padding: 8px;
5056: }
5057: table.LC_pick_box td.LC_selfenroll_pick_box_title {
5058: background: $tabbg;
5059: font-weight: bold;
5060: text-align: right;
5061: width: 350px;
5062: padding: 8px;
5063: }
5064:
5065: table.LC_pick_box td.LC_pick_box_value {
5066: text-align: left;
5067: padding: 8px;
5068: }
5069: table.LC_pick_box td.LC_pick_box_select {
5070: text-align: left;
5071: padding: 8px;
5072: }
5073: table.LC_pick_box td.LC_pick_box_separator {
5074: padding: 0px;
5075: height: 1px;
5076: background: black;
5077: }
5078: table.LC_pick_box td.LC_pick_box_submit {
5079: text-align: right;
5080: }
5081: table.LC_pick_box td.LC_evenrow_value {
5082: text-align: left;
5083: padding: 8px;
5084: background-color: $data_table_light;
5085: }
5086: table.LC_pick_box td.LC_oddrow_value {
5087: text-align: left;
5088: padding: 8px;
5089: background-color: $data_table_light;
5090: }
5091: table.LC_helpform_receipt {
5092: width: 620px;
5093: border-collapse: separate;
5094: background: white;
5095: border: 1px solid black;
5096: border-spacing: 1px;
5097: }
5098: table.LC_helpform_receipt td.LC_pick_box_title {
5099: background: $tabbg;
5100: font-weight: bold;
5101: text-align: right;
5102: width: 184px;
5103: padding: 8px;
5104: }
5105: table.LC_helpform_receipt td.LC_evenrow_value {
5106: text-align: left;
5107: padding: 8px;
5108: background-color: $data_table_light;
5109: }
5110: table.LC_helpform_receipt td.LC_oddrow_value {
5111: text-align: left;
5112: padding: 8px;
5113: background-color: $data_table_light;
5114: }
5115: table.LC_helpform_receipt td.LC_pick_box_separator {
5116: padding: 0px;
5117: height: 1px;
5118: background: black;
5119: }
5120: span.LC_helpform_receipt_cat {
5121: font-weight: bold;
5122: }
5123: table.LC_group_priv_box {
5124: background: white;
5125: border: 1px solid black;
5126: border-spacing: 1px;
5127: }
5128: table.LC_group_priv_box td.LC_pick_box_title {
5129: background: $tabbg;
5130: font-weight: bold;
5131: text-align: right;
5132: width: 184px;
5133: }
5134: table.LC_group_priv_box td.LC_groups_fixed {
5135: background: $data_table_light;
5136: text-align: center;
5137: }
5138: table.LC_group_priv_box td.LC_groups_optional {
5139: background: $data_table_dark;
5140: text-align: center;
5141: }
5142: table.LC_group_priv_box td.LC_groups_functionality {
5143: background: $data_table_darker;
5144: text-align: center;
5145: font-weight: bold;
5146: }
5147: table.LC_group_priv td {
5148: text-align: left;
5149: padding: 0px;
5150: }
5151:
5152: table.LC_notify_front_page {
5153: background: white;
5154: border: 1px solid black;
5155: padding: 8px;
5156: }
5157: table.LC_notify_front_page td {
5158: padding: 8px;
5159: }
5160: .LC_navbuttons {
5161: margin: 2ex 0ex 2ex 0ex;
5162: }
5163: .LC_topic_bar {
5164: font-family: $sans;
5165: font-weight: bold;
5166: width: 100%;
5167: background: $tabbg;
5168: vertical-align: middle;
5169: margin: 2ex 0ex 2ex 0ex;
5170: }
5171: .LC_topic_bar span {
5172: vertical-align: middle;
5173: }
5174: .LC_topic_bar img {
5175: vertical-align: bottom;
5176: }
5177: table.LC_course_group_status {
5178: margin: 20px;
5179: }
5180: table.LC_status_selector td {
5181: vertical-align: top;
5182: text-align: center;
5183: padding: 4px;
5184: }
5185: table.LC_descriptive_input td.LC_description {
5186: vertical-align: top;
5187: text-align: right;
5188: font-weight: bold;
5189: }
5190: div.LC_feedback_link {
5191: clear: both;
5192: background: white;
5193: width: 100%;
5194: }
5195: span.LC_feedback_link {
5196: background: $feedback_link_bg;
5197: font-size: larger;
5198: }
5199: span.LC_message_link {
5200: background: $feedback_link_bg;
5201: font-size: larger;
5202: position: absolute;
5203: right: 1em;
5204: }
5205:
5206: table.LC_prior_tries {
5207: border: 1px solid #000000;
5208: border-collapse: separate;
5209: border-spacing: 1px;
5210: }
5211:
5212: table.LC_prior_tries td {
5213: padding: 2px;
5214: }
5215:
5216: .LC_answer_correct {
5217: background: #AAFFAA;
5218: color: black;
5219: }
5220: .LC_answer_charged_try {
5221: background: #FFAAAA ! important;
5222: color: black;
5223: }
5224: .LC_answer_not_charged_try,
5225: .LC_answer_no_grade,
5226: .LC_answer_late {
5227: background: #FFFFAA;
5228: color: black;
5229: }
5230: .LC_answer_previous {
5231: background: #AAAAFF;
5232: color: black;
5233: }
5234: .LC_answer_no_message {
5235: background: #FFFFFF;
5236: color: black;
5237: }
5238: .LC_answer_unknown {
5239: background: orange;
5240: color: black;
5241: }
5242:
5243:
5244: span.LC_prior_numerical,
5245: span.LC_prior_string,
5246: span.LC_prior_custom,
5247: span.LC_prior_reaction,
5248: span.LC_prior_math {
5249: font-family: monospace;
5250: white-space: pre;
5251: }
5252:
5253: span.LC_prior_string {
5254: font-family: monospace;
5255: white-space: pre;
5256: }
5257:
5258: table.LC_prior_option {
5259: width: 100%;
5260: border-collapse: collapse;
5261: }
5262: table.LC_prior_rank, table.LC_prior_match {
5263: border-collapse: collapse;
5264: }
5265: table.LC_prior_option tr td,
5266: table.LC_prior_rank tr td,
5267: table.LC_prior_match tr td {
5268: border: 1px solid #000000;
5269: }
5270:
5271: span.LC_nobreak {
5272: white-space: nowrap;
5273: }
5274:
5275: span.LC_cusr_emph {
5276: font-style: italic;
5277: }
5278:
5279: span.LC_cusr_subheading {
5280: font-weight: normal;
5281: font-size: 85%;
5282: }
5283:
5284: table.LC_docs_documents {
5285: background: #BBBBBB;
5286: border-width: 0px;
5287: border-collapse: collapse;
5288: }
5289:
5290: table.LC_docs_documents td.LC_docs_document {
5291: border: 2px solid black;
5292: padding: 4px;
5293: }
5294:
5295: .LC_docs_entry_move {
5296: border: 0px;
5297: border-collapse: collapse;
5298: }
5299:
5300: .LC_docs_entry_move td {
5301: border: 2px solid #BBBBBB;
5302: background: #DDDDDD;
5303: }
5304:
5305: .LC_docs_editor td.LC_docs_entry_commands {
5306: background: #DDDDDD;
5307: font-size: x-small;
5308: }
5309: .LC_docs_copy {
5310: color: #000099;
5311: }
5312: .LC_docs_cut {
5313: color: #550044;
5314: }
5315: .LC_docs_rename {
5316: color: #009900;
5317: }
5318: .LC_docs_remove {
5319: color: #990000;
5320: }
5321:
5322: .LC_docs_reinit_warn,
5323: .LC_docs_ext_edit {
5324: font-size: x-small;
5325: }
5326:
5327: .LC_docs_editor td.LC_docs_entry_title,
5328: .LC_docs_editor td.LC_docs_entry_icon {
5329: background: #FFFFBB;
5330: }
5331: .LC_docs_editor td.LC_docs_entry_parameter {
5332: background: #BBBBFF;
5333: font-size: x-small;
5334: white-space: nowrap;
5335: }
5336:
5337: table.LC_docs_adddocs td,
5338: table.LC_docs_adddocs th {
5339: border: 1px solid #BBBBBB;
5340: padding: 4px;
5341: background: #DDDDDD;
5342: }
5343:
5344: table.LC_sty_begin {
5345: background: #BBFFBB;
5346: }
5347: table.LC_sty_end {
5348: background: #FFBBBB;
5349: }
5350:
5351: table.LC_double_column {
5352: border-width: 0px;
5353: border-collapse: collapse;
5354: width: 100%;
5355: padding: 2px;
5356: }
5357:
5358: table.LC_double_column tr td.LC_left_col {
5359: top: 2px;
5360: left: 2px;
5361: width: 47%;
5362: vertical-align: top;
5363: }
5364:
5365: table.LC_double_column tr td.LC_right_col {
5366: top: 2px;
5367: right: 2px;
5368: width: 47%;
5369: vertical-align: top;
5370: }
5371:
5372: span.LC_role_level {
5373: font-weight: bold;
5374: }
5375:
5376: div.LC_left_float {
5377: float: left;
5378: padding-right: 5%;
5379: padding-bottom: 4px;
5380: }
5381:
5382: div.LC_clear_float_header {
5383: padding-bottom: 2px;
5384: }
5385:
5386: div.LC_clear_float_footer {
5387: padding-top: 10px;
5388: clear: both;
5389: }
5390:
5391:
5392: div.LC_grade_show_user {
5393: margin-top: 20px;
5394: border: 1px solid black;
5395: }
5396: div.LC_grade_user_name {
5397: background: #DDDDEE;
5398: border-bottom: 1px solid black;
5399: font-weight: bold;
5400: font-size: large;
5401: }
5402: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
5403: background: #DDEEDD;
5404: }
5405:
5406: div.LC_grade_show_problem,
5407: div.LC_grade_submissions,
5408: div.LC_grade_message_center,
5409: div.LC_grade_info_links,
5410: div.LC_grade_assign {
5411: margin: 5px;
5412: width: 99%;
5413: background: #FFFFFF;
5414: }
5415: div.LC_grade_show_problem_header,
5416: div.LC_grade_submissions_header,
5417: div.LC_grade_message_center_header,
5418: div.LC_grade_assign_header {
5419: font-weight: bold;
5420: font-size: large;
5421: }
5422: div.LC_grade_show_problem_problem,
5423: div.LC_grade_submissions_body,
5424: div.LC_grade_message_center_body,
5425: div.LC_grade_assign_body {
5426: border: 1px solid black;
5427: width: 99%;
5428: background: #FFFFFF;
5429: }
5430: span.LC_grade_check_note {
5431: font-weight: normal;
5432: font-size: medium;
5433: display: inline;
5434: position: absolute;
5435: right: 1em;
5436: }
5437:
5438: table.LC_scantron_action {
5439: width: 100%;
5440: }
5441: table.LC_scantron_action tr th {
5442: font-weight:bold;
5443: font-style:normal;
5444: }
5445: .LC_edit_problem_header,
5446: div.LC_edit_problem_footer {
5447: font-weight: normal;
5448: font-size: medium;
5449: margin: 2px;
5450: }
5451: div.LC_edit_problem_header,
5452: div.LC_edit_problem_header div,
5453: div.LC_edit_problem_footer,
5454: div.LC_edit_problem_footer div,
5455: div.LC_edit_problem_editxml_header,
5456: div.LC_edit_problem_editxml_header div {
5457: margin-top: 5px;
5458: }
5459: div.LC_edit_problem_header_edit_row {
5460: background: $tabbg;
5461: padding: 3px;
5462: margin-bottom: 5px;
5463: }
5464: div.LC_edit_problem_header_title {
5465: font-weight: bold;
5466: font-size: larger;
5467: background: $tabbg;
5468: padding: 3px;
5469: }
5470: table.LC_edit_problem_header_title {
5471: font-size: larger;
5472: font-weight: bold;
5473: width: 100%;
5474: border-color: $pgbg;
5475: border-style: solid;
5476: border-width: $border;
5477:
5478: background: $tabbg;
5479: border-collapse: collapse;
5480: padding: 0px
5481: }
5482:
5483: div.LC_edit_problem_discards {
5484: float: left;
5485: padding-bottom: 5px;
5486: }
5487: div.LC_edit_problem_saves {
5488: float: right;
5489: padding-bottom: 5px;
5490: }
5491: hr.LC_edit_problem_divide {
5492: clear: both;
5493: color: $tabbg;
5494: background-color: $tabbg;
5495: height: 3px;
5496: border: 0px;
5497: }
5498: img.stift{
5499: border-width:0;
5500: vertical-align:middle;
5501: }
5502:
5503: table#LC_mainmenu{
5504: margin-top:10px;
5505: width:80%;
5506:
5507: }
5508:
5509: table#LC_mainmenu td.LC_mainmenu_col_fieldset{
5510: vertical-align: top;
5511: width: 45%;
5512: }
5513: .LC_mainmenu_fieldset_category {
5514: color: $font;
5515: background: $pgbg;
5516: font-family: $sans;
5517: font-size: small;
5518: font-weight: bold;
5519: }
5520:
5521: div.LC_createcourse {
5522: margin: 10px 10px 10px 10px;
5523: }
5524:
5525: /* ---- Remove when done ----
5526: # The following styles is part of the redesign of LON-CAPA and are
5527: # subject to change during this project.
5528: # Don't rely on their current functionality as they might be
5529: # changed or removed.
5530: # --------------------------*/
5531:
5532: a:hover,
5533: ol.LC_smallMenu a:hover,
5534: ol#LC_MenuBreadcrumbs a:hover,
5535: ol#LC_PathBreadcrumbs a:hover,
5536: ul#LC_TabMainMenuContent a:hover,
5537: .LC_FormSectionClearButton input:hover
5538: ul.LC_TabContent li:hover a{
5539: color:#BF2317;
5540: text-decoration:none;
5541: }
5542:
5543: h1 {
5544: padding:5px 10px 5px 20px;
5545: line-height:130%;
5546: }
5547:
5548: h2,h3,h4,h5,h6
5549: {
5550: margin:5px 0px 5px 0px;
5551: padding:0px;
5552: line-height:130%;
5553: }
5554: .LC_hcell{
5555: padding:3px 15px 3px 15px;
5556: margin:0px;
5557: background-color:$tabbg;
5558: border-bottom:solid 1px $lg_border_color;
5559: }
5560: .LC_noBorder {
5561: border:0px;
5562: }
5563:
5564: .LC_bgLightGrey{
5565: background:URL(/adm/lonIcons/lightGreyBG.png) repeat-x left bottom;
5566: }
5567:
5568:
5569: /* Main Header with discription of Person, Course, etc. */
5570: .LC_HeadRight {
5571: text-align: right;
5572: float: right;
5573: margin: 0px;
5574: padding: 0px;
5575: right:0;
5576: position:absolute;
5577: overflow:hidden;
5578: }
5579:
5580: p, .LC_ContentBox {
5581: padding: 10px;
5582:
5583: }
5584: .LC_FormSectionClearButton input {
5585: background-color:transparent;
5586: border:0px;
5587: cursor:pointer;
5588: text-decoration:underline;
5589: }
5590:
5591:
5592: dl,ul,div,fieldset {
5593: margin: 10px 10px 10px 0px;
5594: overflow:hidden;
5595: }
5596: ol.LC_smallMenu, ol#LC_PathBreadcrumbs {
5597: margin: 0px;
5598: }
5599:
5600: ol.LC_smallMenu li {
5601: display: inline;
5602: padding: 5px 5px 0px 10px;
5603: vertical-align: top;
5604: }
5605:
5606: ol.LC_smallMenu li img {
5607: vertical-align: bottom;
5608: }
5609:
5610: ol.LC_smallMenu a {
5611: font-size: 90%;
5612: color: RGB(80, 80, 80);
5613: text-decoration: none;
5614: }
5615: ol#LC_TabMainMenueContent, ul.LC_TabContent,
5616: ul.LC_TabContentBigger {
5617: display:block;
5618: list-style:none;
5619: margin: 0px;
5620: padding: 0px;
5621: }
5622:
5623: ol#LC_TabMainMenuContent li, ul.LC_TabContent,
5624: ul.LC_TabContentBigger li{
5625: display: inline;
5626: border-right: solid 1px $lg_border_color;
5627: float:left;
5628: line-height:140%;
5629: white-space:nowrap;
5630: }
5631: ol#LC_TabMainMenuContent li{
5632: vertical-align: bottom;
5633: border-bottom: solid 1px RGB(175, 175, 175);
5634: padding: 5px 10px 5px 10px;
5635: margin-right:5px;
5636: margin-bottom:3px;
5637: font-weight: bold;
5638: background: url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
5639: }
5640:
5641: ol#LC_TabMainMenuContent li a{
5642: color: RGB(47, 47, 47);
5643: text-decoration: none;
5644: }
5645: ul.LC_TabContent {
5646: min-height:1.6em;
5647: border-bottom:solid 1px $lg_border_color;
5648: }
5649: ul.LC_TabContent li{
5650: vertical-align:middle;
5651: padding:0px 10px 0px 10px;
5652: }
5653: ul.LC_TabContent li a, ul.LC_TabContent li{
5654: color:rgb(47,47,47);
5655: text-decoration:none;
5656: font-size:95%;
5657: font-weight:bold;
5658: }
5659: ul.LC_TabContentBigger li{
5660: vertical-align:bottom;
5661: border-top:solid 1px $lg_border_color;
5662: border-left:solid 1px $lg_border_color;
5663: padding:5px 10px 5px 10px;
5664: margin-left:2px;
5665: background:url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
5666: }
5667: ul.LC_TabContentBigger li, ul.LC_TabContentBigger li a{
5668: font-size:110%;
5669: font-weight:bold;
5670: }
5671: #LC_CourseDocuments, #LC_SupplementalCourseDocuments
5672: {
5673: margin:0px;
5674: }
5675:
5676: .LC_hideThis
5677: {
5678: display:none;
5679: visibility:hidden;
5680: }
5681:
5682: ol#LC_MenuBreadcrumbs, ol#LC_PathBreadcrumbs {
5683: border-top: solid 1px RGB(255, 255, 255);
5684: height: 20px;
5685: line-height: 20px;
5686: vertical-align: bottom;
5687: margin: 0px 0px 30px 0px;
5688: padding-left: 10px;
5689: list-style-position: inside;
5690: background: url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
5691: }
5692:
5693: ol#LC_MenuBreadcrumbs li, ol#LC_PathBreadcrumbs li {
5694: /*
5695: background: url(/adm/lonIcons/arrow_white.png) no-repeat left center;
5696: */
5697: display: inline;
5698: padding: 0px 0px 0px 10px;
5699: vertical-align: bottom;
5700: overflow:hidden;
5701: }
5702:
5703: ol#LC_MenuBreadcrumbs li a {
5704: text-decoration: none;
5705: font-size:90%;
5706: }
5707: ol#LC_PathBreadcrumbs li a{
5708: text-decoration:none;
5709: font-size:100%;
5710: font-weight:bold;
5711: }
5712: .LC_ContentBoxSpecial
5713: {
5714: border: solid 1px $lg_border_color;
5715: }
5716:
5717: dl.LC_ListStyleClean dt {
5718: padding-right: 5px;
5719: display: table-header-group;
5720: }
5721:
5722: dl.LC_ListStyleClean dd {
5723: display: table-row;
5724: }
5725:
5726: .LC_ListStyleClean,
5727: .LC_ListStyleSimple,
5728: .LC_ListStyleNormal,
5729: .LC_ListStyleNormal_Border,
5730: .LC_ListStyleSpecial
5731: {
5732: /*display:block; */
5733: list-style-position: inside;
5734: list-style-type: none;
5735: overflow: hidden;
5736: padding: 0px;
5737: }
5738:
5739: .LC_ListStyleSimple li,
5740: .LC_ListStyleSimple dd,
5741: .LC_ListStyleNormal li,
5742: .LC_ListStyleNormal dd,
5743: .LC_ListStyleSpecial li,
5744: .LC_ListStyleSpecial dd
5745: {
5746: margin: 0px;
5747: padding: 5px 5px 5px 10px;
5748: clear: both;
5749: }
5750:
5751: .LC_ListStyleClean li,
5752: .LC_ListStyleClean dd {
5753: padding-top: 0px;
5754: padding-bottom: 0px;
5755: }
5756:
5757: .LC_ListStyleSimple dd,
5758: .LC_ListStyleSimple li{
5759: border-bottom: solid 1px $lg_border_color;
5760: }
5761:
5762: .LC_ListStyleSpecial li,
5763: .LC_ListStyleSpecial dd {
5764: list-style-type: none;
5765: background-color: RGB(220, 220, 220);
5766: margin-bottom: 4px;
5767: }
5768:
5769: table.LC_SimpleTable {
5770: margin:5px;
5771: border:solid 1px $lg_border_color;
5772: }
5773:
5774: table.LC_SimpleTable tr {
5775: padding:0px;
5776: border:solid 1px $lg_border_color;
5777: }
5778: table.LC_SimpleTable thead{
5779: background:rgb(220,220,220);
5780: }
5781:
5782: div.LC_columnSection {
5783: display: block;
5784: clear: both;
5785: overflow: hidden;
5786: margin:0px;
5787: }
5788:
5789: div.LC_columnSection>* {
5790: float: left;
5791: margin: 10px 20px 10px 0px;
5792: overflow:hidden;
5793: }
5794: div.LC_columnSection > .LC_ContentBox,
5795: div.LC_columnSection > .LC_ContentBoxSpecial
5796: {
5797: width: 400px;
5798: }
5799:
5800: .ContentBoxSpecialTemplate
5801: {
5802: border: solid 1px $lg_border_color;
5803: }
5804: .ContentBoxTemplate {
5805: padding:10px;
5806: }
5807:
5808: div.LC_columnSection > .ContentBoxTemplate,
5809: div.LC_columnSection > .ContentBoxSpecialTemplate
5810: {
5811: width: 600px;
5812:
5813: }
5814:
5815: .clear{
5816: clear: both;
5817: line-height: 0px;
5818: font-size: 0px;
5819: height: 0px;
5820: }
5821:
5822: .LC_loginpage_container {
5823: text-align:left;
5824: margin : 0 auto;
5825: width:65%;
5826: padding: 10px;
5827: height: auto;
5828: background-color:#FFFFFF;
5829: border:1px solid #CCCCCC;
5830: }
5831:
5832:
5833: .LC_loginpage_loginContainer {
5834: float:left;
5835: width: 182px;
5836: border:1px solid #CCCCCC;
5837: background-color:$loginbg;
5838: }
5839:
5840: .LC_loginpage_loginContainer h2{
5841: margin-top:0;
5842: display:block;
5843: background:$bgcol;
5844: color:$textcol;
5845: padding-left:5px;
5846: }
5847: .LC_loginpage_loginInfo {
5848: margin-left:20px;
5849: float:left;
5850: width:30%;
5851: border:1px solid #CCCCCC;
5852: padding:10px;
5853: }
5854:
5855: .LC_loginpage_loginDomain {
5856: margin-right:20px;
5857: width:20%;
5858: float:left;
5859: padding:10px;
5860: }
5861:
5862: .LC_loginpage_space {
5863: clear:both;
5864: margin-bottom:20px;
5865: border-bottom: 1px solid #CCCCCC;
5866: }
5867:
5868: END
5869: }
5870:
5871: =pod
5872:
5873: =item * &headtag()
5874:
5875: Returns a uniform footer for LON-CAPA web pages.
5876:
5877: Inputs: $title - optional title for the head
5878: $head_extra - optional extra HTML to put inside the <head>
5879: $args - optional arguments
5880: force_register - if is true call registerurl so the remote is
5881: informed
5882: redirect -> array ref of
5883: 1- seconds before redirect occurs
5884: 2- url to redirect to
5885: 3- whether the side effect should occur
5886: (side effect of setting
5887: $env{'internal.head.redirect'} to the url
5888: redirected too)
5889: domain -> force to color decorate a page for a specific
5890: domain
5891: function -> force usage of a specific rolish color scheme
5892: bgcolor -> override the default page bgcolor
5893: no_auto_mt_title
5894: -> prevent &mt()ing the title arg
5895:
5896: =cut
5897:
5898: sub headtag {
5899: my ($title,$head_extra,$args) = @_;
5900:
5901: my $function = $args->{'function'} || &get_users_function();
5902: my $domain = $args->{'domain'} || &determinedomain();
5903: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
5904: my $url = join(':',$env{'user.name'},$env{'user.domain'},
5905: $Apache::lonnet::perlvar{'lonVersion'},
5906: #time(),
5907: $env{'environment.color.timestamp'},
5908: $function,$domain,$bgcolor);
5909:
5910: $url = '/adm/css/'.&escape($url).'.css';
5911:
5912: my $result =
5913: '<head>'.
5914: &font_settings();
5915:
5916: if (!$args->{'frameset'}) {
5917: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
5918: }
5919: if ($args->{'force_register'}) {
5920: $result .= &Apache::lonmenu::registerurl(1);
5921: }
5922: if (!$args->{'no_nav_bar'}
5923: && !$args->{'only_body'}
5924: && !$args->{'frameset'}) {
5925: $result .= &help_menu_js();
5926: }
5927:
5928: if (ref($args->{'redirect'})) {
5929: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
5930: $url = &Apache::lonenc::check_encrypt($url);
5931: if (!$inhibit_continue) {
5932: $env{'internal.head.redirect'} = $url;
5933: }
5934: $result.=<<ADDMETA
5935: <meta http-equiv="pragma" content="no-cache" />
5936: <meta http-equiv="Refresh" content="$time; url=$url" />
5937: ADDMETA
5938: }
5939: if (!defined($title)) {
5940: $title = 'The LearningOnline Network with CAPA';
5941: }
5942: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
5943: $result .= '<title> LON-CAPA '.$title.'</title>'
5944: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
5945: .$head_extra;
5946: return $result;
5947: }
5948:
5949: =pod
5950:
5951: =item * &font_settings()
5952:
5953: Returns neccessary <meta> to set the proper encoding
5954:
5955: Inputs: none
5956:
5957: =cut
5958:
5959: sub font_settings {
5960: my $headerstring='';
5961: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
5962: $headerstring.=
5963: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
5964: }
5965: return $headerstring;
5966: }
5967:
5968: =pod
5969:
5970: =item * &xml_begin()
5971:
5972: Returns the needed doctype and <html>
5973:
5974: Inputs: none
5975:
5976: =cut
5977:
5978: sub xml_begin {
5979: my $output='';
5980:
5981: if ($env{'internal.start_page'}==1) {
5982: &Apache::lonhtmlcommon::init_htmlareafields();
5983: }
5984:
5985: if ($env{'browser.mathml'}) {
5986: $output='<?xml version="1.0"?>'
5987: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
5988: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
5989:
5990: # .'<!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">] >'
5991: .'<!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">'
5992: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
5993: .'xmlns="http://www.w3.org/1999/xhtml">';
5994: } else {
5995: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>';
5996: }
5997: return $output;
5998: }
5999:
6000: =pod
6001:
6002: =item * &endheadtag()
6003:
6004: Returns a uniform </head> for LON-CAPA web pages.
6005:
6006: Inputs: none
6007:
6008: =cut
6009:
6010: sub endheadtag {
6011: return '</head>';
6012: }
6013:
6014: =pod
6015:
6016: =item * &head()
6017:
6018: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
6019:
6020: Inputs:
6021:
6022: =over 4
6023:
6024: $title - optional title for the page
6025:
6026: $head_extra - optional extra HTML to put inside the <head>
6027:
6028: =back
6029:
6030: =cut
6031:
6032: sub head {
6033: my ($title,$head_extra,$args) = @_;
6034: return &headtag($title,$head_extra,$args).&endheadtag();
6035: }
6036:
6037: =pod
6038:
6039: =item * &start_page()
6040:
6041: Returns a complete <html> .. <body> section for LON-CAPA web pages.
6042:
6043: Inputs:
6044:
6045: =over 4
6046:
6047: $title - optional title for the page
6048:
6049: $head_extra - optional extra HTML to incude inside the <head>
6050:
6051: $args - additional optional args supported are:
6052:
6053: =over 8
6054:
6055: only_body -> is true will set &bodytag() onlybodytag
6056: arg on
6057: no_nav_bar -> is true will set &bodytag() notopbar arg on
6058: add_entries -> additional attributes to add to the <body>
6059: domain -> force to color decorate a page for a
6060: specific domain
6061: function -> force usage of a specific rolish color
6062: scheme
6063: redirect -> see &headtag()
6064: bgcolor -> override the default page bg color
6065: js_ready -> return a string ready for being used in
6066: a javascript writeln
6067: html_encode -> return a string ready for being used in
6068: a html attribute
6069: force_register -> if is true will turn on the &bodytag()
6070: $forcereg arg
6071: body_title -> alternate text to use instead of $title
6072: in the title box that appears, this text
6073: is not auto translated like the $title is
6074: frameset -> if true will start with a <frameset>
6075: rather than <body>
6076: no_title -> if true the title bar won't be shown
6077: skip_phases -> hash ref of
6078: head -> skip the <html><head> generation
6079: body -> skip all <body> generation
6080: no_inline_link -> if true and in remote mode, don't show the
6081: 'Switch To Inline Menu' link
6082: no_auto_mt_title -> prevent &mt()ing the title arg
6083: inherit_jsmath -> when creating popup window in a page,
6084: should it have jsmath forced on by the
6085: current page
6086:
6087: =back
6088:
6089: =back
6090:
6091: =cut
6092:
6093: sub start_page {
6094: my ($title,$head_extra,$args) = @_;
6095: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
6096: my %head_args;
6097: foreach my $arg ('redirect','force_register','domain','function',
6098: 'bgcolor','frameset','no_nav_bar','only_body',
6099: 'no_auto_mt_title') {
6100: if (defined($args->{$arg})) {
6101: $head_args{$arg} = $args->{$arg};
6102: }
6103: }
6104:
6105: $env{'internal.start_page'}++;
6106: my $result;
6107: if (! exists($args->{'skip_phases'}{'head'}) ) {
6108: $result.=
6109: &xml_begin().
6110: &headtag($title,$head_extra,\%head_args).&endheadtag();
6111: }
6112:
6113: if (! exists($args->{'skip_phases'}{'body'}) ) {
6114: if ($args->{'frameset'}) {
6115: my $attr_string = &make_attr_string($args->{'force_register'},
6116: $args->{'add_entries'});
6117: $result .= "\n<frameset $attr_string>\n";
6118: } else {
6119: $result .=
6120: &bodytag($title,
6121: $args->{'function'}, $args->{'add_entries'},
6122: $args->{'only_body'}, $args->{'domain'},
6123: $args->{'force_register'}, $args->{'body_title'},
6124: $args->{'no_nav_bar'}, $args->{'bgcolor'},
6125: $args->{'no_title'}, $args->{'no_inline_link'},
6126: $args);
6127: }
6128: }
6129:
6130: if ($args->{'js_ready'}) {
6131: $result = &js_ready($result);
6132: }
6133: if ($args->{'html_encode'}) {
6134: $result = &html_encode($result);
6135: }
6136:
6137: if (exists($args->{'bread_crumbs'})) {
6138: &Apache::lonhtmlcommon::clear_breadcrumbs();
6139: if (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
6140: foreach my $crumb (@{$args->{'bread_crumbs'}}){
6141: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
6142: }
6143: }
6144: $result .= &Apache::lonhtmlcommon::breadcrumbs();
6145: }
6146:
6147: return $result;
6148: }
6149:
6150:
6151: =pod
6152:
6153: =item * &head()
6154:
6155: Returns a complete </body></html> section for LON-CAPA web pages.
6156:
6157: Inputs: $args - additional optional args supported are:
6158: js_ready -> return a string ready for being used in
6159: a javascript writeln
6160: html_encode -> return a string ready for being used in
6161: a html attribute
6162: frameset -> if true will start with a <frameset>
6163: rather than <body>
6164: dicsussion -> if true will get discussion from
6165: lonxml::xmlend
6166: (you can pass the target and parser arguments
6167: through optional 'target' and 'parser' args
6168: to this routine)
6169:
6170: =cut
6171:
6172: sub end_page {
6173: my ($args) = @_;
6174: $env{'internal.end_page'}++;
6175: my $result;
6176: if ($args->{'discussion'}) {
6177: my ($target,$parser);
6178: if (ref($args->{'discussion'})) {
6179: ($target,$parser) =($args->{'discussion'}{'target'},
6180: $args->{'discussion'}{'parser'});
6181: }
6182: $result .= &Apache::lonxml::xmlend($target,$parser);
6183: }
6184:
6185: if ($args->{'frameset'}) {
6186: $result .= '</frameset>';
6187: } else {
6188: $result .= &endbodytag($args);
6189: }
6190: $result .= "\n</html>";
6191:
6192: if ($args->{'js_ready'}) {
6193: $result = &js_ready($result);
6194: }
6195:
6196: if ($args->{'html_encode'}) {
6197: $result = &html_encode($result);
6198: }
6199:
6200: return $result;
6201: }
6202:
6203: sub html_encode {
6204: my ($result) = @_;
6205:
6206: $result = &HTML::Entities::encode($result,'<>&"');
6207:
6208: return $result;
6209: }
6210: sub js_ready {
6211: my ($result) = @_;
6212:
6213: $result =~ s/[\n\r]/ /xmsg;
6214: $result =~ s/\\/\\\\/xmsg;
6215: $result =~ s/'/\\'/xmsg;
6216: $result =~ s{</}{<\\/}xmsg;
6217:
6218: return $result;
6219: }
6220:
6221: sub validate_page {
6222: if ( exists($env{'internal.start_page'})
6223: && $env{'internal.start_page'} > 1) {
6224: &Apache::lonnet::logthis('start_page called multiple times '.
6225: $env{'internal.start_page'}.' '.
6226: $ENV{'request.filename'});
6227: }
6228: if ( exists($env{'internal.end_page'})
6229: && $env{'internal.end_page'} > 1) {
6230: &Apache::lonnet::logthis('end_page called multiple times '.
6231: $env{'internal.end_page'}.' '.
6232: $env{'request.filename'});
6233: }
6234: if ( exists($env{'internal.start_page'})
6235: && ! exists($env{'internal.end_page'})) {
6236: &Apache::lonnet::logthis('start_page called without end_page '.
6237: $env{'request.filename'});
6238: }
6239: if ( ! exists($env{'internal.start_page'})
6240: && exists($env{'internal.end_page'})) {
6241: &Apache::lonnet::logthis('end_page called without start_page'.
6242: $env{'request.filename'});
6243: }
6244: }
6245:
6246: sub simple_error_page {
6247: my ($r,$title,$msg) = @_;
6248: my $page =
6249: &Apache::loncommon::start_page($title).
6250: &mt($msg).
6251: &Apache::loncommon::end_page();
6252: if (ref($r)) {
6253: $r->print($page);
6254: return;
6255: }
6256: return $page;
6257: }
6258:
6259: {
6260: my @row_count;
6261: sub start_data_table {
6262: my ($add_class) = @_;
6263: my $css_class = (join(' ','LC_data_table',$add_class));
6264: unshift(@row_count,0);
6265: return '<table class="'.$css_class.'">'."\n";
6266: }
6267:
6268: sub end_data_table {
6269: shift(@row_count);
6270: return '</table>'."\n";;
6271: }
6272:
6273: sub start_data_table_row {
6274: my ($add_class) = @_;
6275: $row_count[0]++;
6276: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
6277: $css_class = (join(' ',$css_class,$add_class));
6278: return '<tr class="'.$css_class.'">'."\n";;
6279: }
6280:
6281: sub continue_data_table_row {
6282: my ($add_class) = @_;
6283: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
6284: $css_class = (join(' ',$css_class,$add_class));
6285: return '<tr class="'.$css_class.'">'."\n";;
6286: }
6287:
6288: sub end_data_table_row {
6289: return '</tr>'."\n";;
6290: }
6291:
6292: sub start_data_table_empty_row {
6293: # $row_count[0]++;
6294: return '<tr class="LC_empty_row" >'."\n";;
6295: }
6296:
6297: sub end_data_table_empty_row {
6298: return '</tr>'."\n";;
6299: }
6300:
6301: sub start_data_table_header_row {
6302: return '<tr class="LC_header_row">'."\n";;
6303: }
6304:
6305: sub end_data_table_header_row {
6306: return '</tr>'."\n";;
6307: }
6308: }
6309:
6310: =pod
6311:
6312: =item * &inhibit_menu_check($arg)
6313:
6314: Checks for a inhibitmenu state and generates output to preserve it
6315:
6316: Inputs: $arg - can be any of
6317: - undef - in which case the return value is a string
6318: to add into arguments list of a uri
6319: - 'input' - in which case the return value is a HTML
6320: <form> <input> field of type hidden to
6321: preserve the value
6322: - a url - in which case the return value is the url with
6323: the neccesary cgi args added to preserve the
6324: inhibitmenu state
6325: - a ref to a url - no return value, but the string is
6326: updated to include the neccessary cgi
6327: args to preserve the inhibitmenu state
6328:
6329: =cut
6330:
6331: sub inhibit_menu_check {
6332: my ($arg) = @_;
6333: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6334: if ($arg eq 'input') {
6335: if ($env{'form.inhibitmenu'}) {
6336: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
6337: } else {
6338: return
6339: }
6340: }
6341: if ($env{'form.inhibitmenu'}) {
6342: if (ref($arg)) {
6343: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6344: } elsif ($arg eq '') {
6345: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
6346: } else {
6347: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6348: }
6349: }
6350: if (!ref($arg)) {
6351: return $arg;
6352: }
6353: }
6354:
6355: ###############################################
6356:
6357: =pod
6358:
6359: =back
6360:
6361: =head1 User Information Routines
6362:
6363: =over 4
6364:
6365: =item * &get_users_function()
6366:
6367: Used by &bodytag to determine the current users primary role.
6368: Returns either 'student','coordinator','admin', or 'author'.
6369:
6370: =cut
6371:
6372: ###############################################
6373: sub get_users_function {
6374: my $function = 'student';
6375: if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
6376: $function='coordinator';
6377: }
6378: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
6379: $function='admin';
6380: }
6381: if (($env{'request.role'}=~/^(au|ca)/) ||
6382: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
6383: $function='author';
6384: }
6385: return $function;
6386: }
6387:
6388: ###############################################
6389:
6390: =pod
6391:
6392: =item * &check_user_status()
6393:
6394: Determines current status of supplied role for a
6395: specific user. Roles can be active, previous or future.
6396:
6397: Inputs:
6398: user's domain, user's username, course's domain,
6399: course's number, optional section ID.
6400:
6401: Outputs:
6402: role status: active, previous or future.
6403:
6404: =cut
6405:
6406: sub check_user_status {
6407: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
6408: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
6409: my @uroles = keys %userinfo;
6410: my $srchstr;
6411: my $active_chk = 'none';
6412: my $now = time;
6413: if (@uroles > 0) {
6414: if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
6415: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
6416: } else {
6417: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
6418: }
6419: if (grep/^\Q$srchstr\E$/,@uroles) {
6420: my $role_end = 0;
6421: my $role_start = 0;
6422: $active_chk = 'active';
6423: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
6424: $role_end = $1;
6425: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
6426: $role_start = $1;
6427: }
6428: }
6429: if ($role_start > 0) {
6430: if ($now < $role_start) {
6431: $active_chk = 'future';
6432: }
6433: }
6434: if ($role_end > 0) {
6435: if ($now > $role_end) {
6436: $active_chk = 'previous';
6437: }
6438: }
6439: }
6440: }
6441: return $active_chk;
6442: }
6443:
6444: ###############################################
6445:
6446: =pod
6447:
6448: =item * &get_sections()
6449:
6450: Determines all the sections for a course including
6451: sections with students and sections containing other roles.
6452: Incoming parameters:
6453:
6454: 1. domain
6455: 2. course number
6456: 3. reference to array containing roles for which sections should
6457: be gathered (optional).
6458: 4. reference to array containing status types for which sections
6459: should be gathered (optional).
6460:
6461: If the third argument is undefined, sections are gathered for any role.
6462: If the fourth argument is undefined, sections are gathered for any status.
6463: Permissible values are 'active' or 'future' or 'previous'.
6464:
6465: Returns section hash (keys are section IDs, values are
6466: number of users in each section), subject to the
6467: optional roles filter, optional status filter
6468:
6469: =cut
6470:
6471: ###############################################
6472: sub get_sections {
6473: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
6474: if (!defined($cdom) || !defined($cnum)) {
6475: my $cid = $env{'request.course.id'};
6476:
6477: return if (!defined($cid));
6478:
6479: $cdom = $env{'course.'.$cid.'.domain'};
6480: $cnum = $env{'course.'.$cid.'.num'};
6481: }
6482:
6483: my %sectioncount;
6484: my $now = time;
6485:
6486: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
6487: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
6488: my $sec_index = &Apache::loncoursedata::CL_SECTION();
6489: my $status_index = &Apache::loncoursedata::CL_STATUS();
6490: my $start_index = &Apache::loncoursedata::CL_START();
6491: my $end_index = &Apache::loncoursedata::CL_END();
6492: my $status;
6493: while (my ($student,$data) = each(%$classlist)) {
6494: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
6495: $data->[$status_index],
6496: $data->[$start_index],
6497: $data->[$end_index]);
6498: if ($stu_status eq 'Active') {
6499: $status = 'active';
6500: } elsif ($end < $now) {
6501: $status = 'previous';
6502: } elsif ($start > $now) {
6503: $status = 'future';
6504: }
6505: if ($section ne '-1' && $section !~ /^\s*$/) {
6506: if ((!defined($possible_status)) || (($status ne '') &&
6507: (grep/^\Q$status\E$/,@{$possible_status}))) {
6508: $sectioncount{$section}++;
6509: }
6510: }
6511: }
6512: }
6513: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6514: foreach my $user (sort(keys(%courseroles))) {
6515: if ($user !~ /^(\w{2})/) { next; }
6516: my ($role) = ($user =~ /^(\w{2})/);
6517: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
6518: my ($section,$status);
6519: if ($role eq 'cr' &&
6520: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
6521: $section=$1;
6522: }
6523: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
6524: if (!defined($section) || $section eq '-1') { next; }
6525: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
6526: if ($end == -1 && $start == -1) {
6527: next; #deleted role
6528: }
6529: if (!defined($possible_status)) {
6530: $sectioncount{$section}++;
6531: } else {
6532: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
6533: $status = 'active';
6534: } elsif ($end < $now) {
6535: $status = 'future';
6536: } elsif ($start > $now) {
6537: $status = 'previous';
6538: }
6539: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
6540: $sectioncount{$section}++;
6541: }
6542: }
6543: }
6544: return %sectioncount;
6545: }
6546:
6547: ###############################################
6548:
6549: =pod
6550:
6551: =item * &get_course_users()
6552:
6553: Retrieves usernames:domains for users in the specified course
6554: with specific role(s), and access status.
6555:
6556: Incoming parameters:
6557: 1. course domain
6558: 2. course number
6559: 3. access status: users must have - either active,
6560: previous, future, or all.
6561: 4. reference to array of permissible roles
6562: 5. reference to array of section restrictions (optional)
6563: 6. reference to results object (hash of hashes).
6564: 7. reference to optional userdata hash
6565: 8. reference to optional statushash
6566: 9. flag if privileged users (except those set to unhide in
6567: course settings) should be excluded
6568: Keys of top level results hash are roles.
6569: Keys of inner hashes are username:domain, with
6570: values set to access type.
6571: Optional userdata hash returns an array with arguments in the
6572: same order as loncoursedata::get_classlist() for student data.
6573:
6574: Optional statushash returns
6575:
6576: Entries for end, start, section and status are blank because
6577: of the possibility of multiple values for non-student roles.
6578:
6579: =cut
6580:
6581: ###############################################
6582:
6583: sub get_course_users {
6584: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
6585: my %idx = ();
6586: my %seclists;
6587:
6588: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
6589: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
6590: $idx{end} = &Apache::loncoursedata::CL_END();
6591: $idx{start} = &Apache::loncoursedata::CL_START();
6592: $idx{id} = &Apache::loncoursedata::CL_ID();
6593: $idx{section} = &Apache::loncoursedata::CL_SECTION();
6594: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
6595: $idx{status} = &Apache::loncoursedata::CL_STATUS();
6596:
6597: if (grep(/^st$/,@{$roles})) {
6598: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
6599: my $now = time;
6600: foreach my $student (keys(%{$classlist})) {
6601: my $match = 0;
6602: my $secmatch = 0;
6603: my $section = $$classlist{$student}[$idx{section}];
6604: my $status = $$classlist{$student}[$idx{status}];
6605: if ($section eq '') {
6606: $section = 'none';
6607: }
6608: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
6609: if (grep(/^all$/,@{$sections})) {
6610: $secmatch = 1;
6611: } elsif ($$classlist{$student}[$idx{section}] eq '') {
6612: if (grep(/^none$/,@{$sections})) {
6613: $secmatch = 1;
6614: }
6615: } else {
6616: if (grep(/^\Q$section\E$/,@{$sections})) {
6617: $secmatch = 1;
6618: }
6619: }
6620: if (!$secmatch) {
6621: next;
6622: }
6623: }
6624: if (defined($$types{'active'})) {
6625: if ($$classlist{$student}[$idx{status}] eq 'Active') {
6626: push(@{$$users{st}{$student}},'active');
6627: $match = 1;
6628: }
6629: }
6630: if (defined($$types{'previous'})) {
6631: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
6632: push(@{$$users{st}{$student}},'previous');
6633: $match = 1;
6634: }
6635: }
6636: if (defined($$types{'future'})) {
6637: if ($$classlist{$student}[$idx{status}] eq 'Future') {
6638: push(@{$$users{st}{$student}},'future');
6639: $match = 1;
6640: }
6641: }
6642: if ($match) {
6643: push(@{$seclists{$student}},$section);
6644: if (ref($userdata) eq 'HASH') {
6645: $$userdata{$student} = $$classlist{$student};
6646: }
6647: if (ref($statushash) eq 'HASH') {
6648: $statushash->{$student}{'st'}{$section} = $status;
6649: }
6650: }
6651: }
6652: }
6653: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
6654: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6655: my $now = time;
6656: my %displaystatus = ( previous => 'Expired',
6657: active => 'Active',
6658: future => 'Future',
6659: );
6660: my %nothide;
6661: if ($hidepriv) {
6662: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
6663: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
6664: if ($user !~ /:/) {
6665: $nothide{join(':',split(/[\@]/,$user))}=1;
6666: } else {
6667: $nothide{$user} = 1;
6668: }
6669: }
6670: }
6671: foreach my $person (sort(keys(%coursepersonnel))) {
6672: my $match = 0;
6673: my $secmatch = 0;
6674: my $status;
6675: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
6676: $user =~ s/:$//;
6677: my ($end,$start) = split(/:/,$coursepersonnel{$person});
6678: if ($end == -1 || $start == -1) {
6679: next;
6680: }
6681: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
6682: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
6683: my ($uname,$udom) = split(/:/,$user);
6684: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
6685: if (grep(/^all$/,@{$sections})) {
6686: $secmatch = 1;
6687: } elsif ($usec eq '') {
6688: if (grep(/^none$/,@{$sections})) {
6689: $secmatch = 1;
6690: }
6691: } else {
6692: if (grep(/^\Q$usec\E$/,@{$sections})) {
6693: $secmatch = 1;
6694: }
6695: }
6696: if (!$secmatch) {
6697: next;
6698: }
6699: }
6700: if ($usec eq '') {
6701: $usec = 'none';
6702: }
6703: if ($uname ne '' && $udom ne '') {
6704: if ($hidepriv) {
6705: if ((&Apache::lonnet::privileged($uname,$udom)) &&
6706: (!$nothide{$uname.':'.$udom})) {
6707: next;
6708: }
6709: }
6710: if ($end > 0 && $end < $now) {
6711: $status = 'previous';
6712: } elsif ($start > $now) {
6713: $status = 'future';
6714: } else {
6715: $status = 'active';
6716: }
6717: foreach my $type (keys(%{$types})) {
6718: if ($status eq $type) {
6719: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
6720: push(@{$$users{$role}{$user}},$type);
6721: }
6722: $match = 1;
6723: }
6724: }
6725: if (($match) && (ref($userdata) eq 'HASH')) {
6726: if (!exists($$userdata{$uname.':'.$udom})) {
6727: &get_user_info($udom,$uname,\%idx,$userdata);
6728: }
6729: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
6730: push(@{$seclists{$uname.':'.$udom}},$usec);
6731: }
6732: if (ref($statushash) eq 'HASH') {
6733: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
6734: }
6735: }
6736: }
6737: }
6738: }
6739: if (grep(/^ow$/,@{$roles})) {
6740: if ((defined($cdom)) && (defined($cnum))) {
6741: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
6742: if ( defined($csettings{'internal.courseowner'}) ) {
6743: my $owner = $csettings{'internal.courseowner'};
6744: next if ($owner eq '');
6745: my ($ownername,$ownerdom);
6746: if ($owner =~ /^([^:]+):([^:]+)$/) {
6747: $ownername = $1;
6748: $ownerdom = $2;
6749: } else {
6750: $ownername = $owner;
6751: $ownerdom = $cdom;
6752: $owner = $ownername.':'.$ownerdom;
6753: }
6754: @{$$users{'ow'}{$owner}} = 'any';
6755: if (defined($userdata) &&
6756: !exists($$userdata{$owner})) {
6757: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
6758: if (!grep(/^none$/,@{$seclists{$owner}})) {
6759: push(@{$seclists{$owner}},'none');
6760: }
6761: if (ref($statushash) eq 'HASH') {
6762: $statushash->{$owner}{'ow'}{'none'} = 'Any';
6763: }
6764: }
6765: }
6766: }
6767: }
6768: foreach my $user (keys(%seclists)) {
6769: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
6770: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
6771: }
6772: }
6773: return;
6774: }
6775:
6776: sub get_user_info {
6777: my ($udom,$uname,$idx,$userdata) = @_;
6778: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
6779: &plainname($uname,$udom,'lastname');
6780: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
6781: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
6782: my %idhash = &Apache::lonnet::idrget($udom,($uname));
6783: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
6784: return;
6785: }
6786:
6787: ###############################################
6788:
6789: =pod
6790:
6791: =item * &get_user_quota()
6792:
6793: Retrieves quota assigned for storage of portfolio files for a user
6794:
6795: Incoming parameters:
6796: 1. user's username
6797: 2. user's domain
6798:
6799: Returns:
6800: 1. Disk quota (in Mb) assigned to student.
6801: 2. (Optional) Type of setting: custom or default
6802: (individually assigned or default for user's
6803: institutional status).
6804: 3. (Optional) - User's institutional status (e.g., faculty, staff
6805: or student - types as defined in localenroll::inst_usertypes
6806: for user's domain, which determines default quota for user.
6807: 4. (Optional) - Default quota which would apply to the user.
6808:
6809: If a value has been stored in the user's environment,
6810: it will return that, otherwise it returns the maximal default
6811: defined for the user's instituional status(es) in the domain.
6812:
6813: =cut
6814:
6815: ###############################################
6816:
6817:
6818: sub get_user_quota {
6819: my ($uname,$udom) = @_;
6820: my ($quota,$quotatype,$settingstatus,$defquota);
6821: if (!defined($udom)) {
6822: $udom = $env{'user.domain'};
6823: }
6824: if (!defined($uname)) {
6825: $uname = $env{'user.name'};
6826: }
6827: if (($udom eq '' || $uname eq '') ||
6828: ($udom eq 'public') && ($uname eq 'public')) {
6829: $quota = 0;
6830: $quotatype = 'default';
6831: $defquota = 0;
6832: } else {
6833: my $inststatus;
6834: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
6835: $quota = $env{'environment.portfolioquota'};
6836: $inststatus = $env{'environment.inststatus'};
6837: } else {
6838: my %userenv =
6839: &Apache::lonnet::get('environment',['portfolioquota',
6840: 'inststatus'],$udom,$uname);
6841: my ($tmp) = keys(%userenv);
6842: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
6843: $quota = $userenv{'portfolioquota'};
6844: $inststatus = $userenv{'inststatus'};
6845: } else {
6846: undef(%userenv);
6847: }
6848: }
6849: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
6850: if ($quota eq '') {
6851: $quota = $defquota;
6852: $quotatype = 'default';
6853: } else {
6854: $quotatype = 'custom';
6855: }
6856: }
6857: if (wantarray) {
6858: return ($quota,$quotatype,$settingstatus,$defquota);
6859: } else {
6860: return $quota;
6861: }
6862: }
6863:
6864: ###############################################
6865:
6866: =pod
6867:
6868: =item * &default_quota()
6869:
6870: Retrieves default quota assigned for storage of user portfolio files,
6871: given an (optional) user's institutional status.
6872:
6873: Incoming parameters:
6874: 1. domain
6875: 2. (Optional) institutional status(es). This is a : separated list of
6876: status types (e.g., faculty, staff, student etc.)
6877: which apply to the user for whom the default is being retrieved.
6878: If the institutional status string in undefined, the domain
6879: default quota will be returned.
6880:
6881: Returns:
6882: 1. Default disk quota (in Mb) for user portfolios in the domain.
6883: 2. (Optional) institutional type which determined the value of the
6884: default quota.
6885:
6886: If a value has been stored in the domain's configuration db,
6887: it will return that, otherwise it returns 20 (for backwards
6888: compatibility with domains which have not set up a configuration
6889: db file; the original statically defined portfolio quota was 20 Mb).
6890:
6891: If the user's status includes multiple types (e.g., staff and student),
6892: the largest default quota which applies to the user determines the
6893: default quota returned.
6894:
6895: =cut
6896:
6897: ###############################################
6898:
6899:
6900: sub default_quota {
6901: my ($udom,$inststatus) = @_;
6902: my ($defquota,$settingstatus);
6903: my %quotahash = &Apache::lonnet::get_dom('configuration',
6904: ['quotas'],$udom);
6905: if (ref($quotahash{'quotas'}) eq 'HASH') {
6906: if ($inststatus ne '') {
6907: my @statuses = split(/:/,$inststatus);
6908: foreach my $item (@statuses) {
6909: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
6910: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
6911: if ($defquota eq '') {
6912: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
6913: $settingstatus = $item;
6914: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
6915: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
6916: $settingstatus = $item;
6917: }
6918: }
6919: } else {
6920: if ($quotahash{'quotas'}{$item} ne '') {
6921: if ($defquota eq '') {
6922: $defquota = $quotahash{'quotas'}{$item};
6923: $settingstatus = $item;
6924: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
6925: $defquota = $quotahash{'quotas'}{$item};
6926: $settingstatus = $item;
6927: }
6928: }
6929: }
6930: }
6931: }
6932: if ($defquota eq '') {
6933: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
6934: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
6935: } else {
6936: $defquota = $quotahash{'quotas'}{'default'};
6937: }
6938: $settingstatus = 'default';
6939: }
6940: } else {
6941: $settingstatus = 'default';
6942: $defquota = 20;
6943: }
6944: if (wantarray) {
6945: return ($defquota,$settingstatus);
6946: } else {
6947: return $defquota;
6948: }
6949: }
6950:
6951: sub get_secgrprole_info {
6952: my ($cdom,$cnum,$needroles,$type) = @_;
6953: my %sections_count = &get_sections($cdom,$cnum);
6954: my @sections = (sort {$a <=> $b} keys(%sections_count));
6955: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
6956: my @groups = sort(keys(%curr_groups));
6957: my $allroles = [];
6958: my $rolehash;
6959: my $accesshash = {
6960: active => 'Currently has access',
6961: future => 'Will have future access',
6962: previous => 'Previously had access',
6963: };
6964: if ($needroles) {
6965: $rolehash = {'all' => 'all'};
6966: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6967: if (&Apache::lonnet::error(%user_roles)) {
6968: undef(%user_roles);
6969: }
6970: foreach my $item (keys(%user_roles)) {
6971: my ($role)=split(/\:/,$item,2);
6972: if ($role eq 'cr') { next; }
6973: if ($role =~ /^cr/) {
6974: $$rolehash{$role} = (split('/',$role))[3];
6975: } else {
6976: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
6977: }
6978: }
6979: foreach my $key (sort(keys(%{$rolehash}))) {
6980: push(@{$allroles},$key);
6981: }
6982: push (@{$allroles},'st');
6983: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
6984: }
6985: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
6986: }
6987:
6988: sub user_picker {
6989: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
6990: my $currdom = $dom;
6991: my %curr_selected = (
6992: srchin => 'dom',
6993: srchby => 'lastname',
6994: );
6995: my $srchterm;
6996: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
6997: if ($srch->{'srchby'} ne '') {
6998: $curr_selected{'srchby'} = $srch->{'srchby'};
6999: }
7000: if ($srch->{'srchin'} ne '') {
7001: $curr_selected{'srchin'} = $srch->{'srchin'};
7002: }
7003: if ($srch->{'srchtype'} ne '') {
7004: $curr_selected{'srchtype'} = $srch->{'srchtype'};
7005: }
7006: if ($srch->{'srchdomain'} ne '') {
7007: $currdom = $srch->{'srchdomain'};
7008: }
7009: $srchterm = $srch->{'srchterm'};
7010: }
7011: my %lt=&Apache::lonlocal::texthash(
7012: 'usr' => 'Search criteria',
7013: 'doma' => 'Domain/institution to search',
7014: 'uname' => 'username',
7015: 'lastname' => 'last name',
7016: 'lastfirst' => 'last name, first name',
7017: 'crs' => 'in this course',
7018: 'dom' => 'in selected LON-CAPA domain',
7019: 'alc' => 'all LON-CAPA',
7020: 'instd' => 'in institutional directory for selected domain',
7021: 'exact' => 'is',
7022: 'contains' => 'contains',
7023: 'begins' => 'begins with',
7024: 'youm' => "You must include some text to search for.",
7025: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
7026: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
7027: 'yomc' => "You must choose a domain when using an institutional directory search.",
7028: 'ymcd' => "You must choose a domain when using a domain search.",
7029: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
7030: 'whse' => "When searching by last,first you must include at least one character in the first name.",
7031: 'thfo' => "The following need to be corrected before the search can be run:",
7032: );
7033: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
7034: my $srchinsel = ' <select name="srchin">';
7035:
7036: my @srchins = ('crs','dom','alc','instd');
7037:
7038: foreach my $option (@srchins) {
7039: # FIXME 'alc' option unavailable until
7040: # loncreateuser::print_user_query_page()
7041: # has been completed.
7042: next if ($option eq 'alc');
7043: next if ($option eq 'crs' && !$env{'request.course.id'});
7044: if ($curr_selected{'srchin'} eq $option) {
7045: $srchinsel .= '
7046: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7047: } else {
7048: $srchinsel .= '
7049: <option value="'.$option.'">'.$lt{$option}.'</option>';
7050: }
7051: }
7052: $srchinsel .= "\n </select>\n";
7053:
7054: my $srchbysel = ' <select name="srchby">';
7055: foreach my $option ('lastname','lastfirst','uname') {
7056: if ($curr_selected{'srchby'} eq $option) {
7057: $srchbysel .= '
7058: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7059: } else {
7060: $srchbysel .= '
7061: <option value="'.$option.'">'.$lt{$option}.'</option>';
7062: }
7063: }
7064: $srchbysel .= "\n </select>\n";
7065:
7066: my $srchtypesel = ' <select name="srchtype">';
7067: foreach my $option ('begins','contains','exact') {
7068: if ($curr_selected{'srchtype'} eq $option) {
7069: $srchtypesel .= '
7070: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7071: } else {
7072: $srchtypesel .= '
7073: <option value="'.$option.'">'.$lt{$option}.'</option>';
7074: }
7075: }
7076: $srchtypesel .= "\n </select>\n";
7077:
7078: my ($newuserscript,$new_user_create);
7079:
7080: if ($forcenewuser) {
7081: if (ref($srch) eq 'HASH') {
7082: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
7083: if ($cancreate) {
7084: $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>';
7085: } else {
7086: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
7087: my %usertypetext = (
7088: official => 'institutional',
7089: unofficial => 'non-institutional',
7090: );
7091: $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 />';
7092: }
7093: }
7094: }
7095:
7096: $newuserscript = <<"ENDSCRIPT";
7097:
7098: function setSearch(createnew,callingForm) {
7099: if (createnew == 1) {
7100: for (var i=0; i<callingForm.srchby.length; i++) {
7101: if (callingForm.srchby.options[i].value == 'uname') {
7102: callingForm.srchby.selectedIndex = i;
7103: }
7104: }
7105: for (var i=0; i<callingForm.srchin.length; i++) {
7106: if ( callingForm.srchin.options[i].value == 'dom') {
7107: callingForm.srchin.selectedIndex = i;
7108: }
7109: }
7110: for (var i=0; i<callingForm.srchtype.length; i++) {
7111: if (callingForm.srchtype.options[i].value == 'exact') {
7112: callingForm.srchtype.selectedIndex = i;
7113: }
7114: }
7115: for (var i=0; i<callingForm.srchdomain.length; i++) {
7116: if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
7117: callingForm.srchdomain.selectedIndex = i;
7118: }
7119: }
7120: }
7121: }
7122: ENDSCRIPT
7123:
7124: }
7125:
7126: my $output = <<"END_BLOCK";
7127: <script type="text/javascript">
7128: function validateEntry(callingForm) {
7129:
7130: var checkok = 1;
7131: var srchin;
7132: for (var i=0; i<callingForm.srchin.length; i++) {
7133: if ( callingForm.srchin[i].checked ) {
7134: srchin = callingForm.srchin[i].value;
7135: }
7136: }
7137:
7138: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
7139: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
7140: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
7141: var srchterm = callingForm.srchterm.value;
7142: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
7143: var msg = "";
7144:
7145: if (srchterm == "") {
7146: checkok = 0;
7147: msg += "$lt{'youm'}\\n";
7148: }
7149:
7150: if (srchtype== 'begins') {
7151: if (srchterm.length < 2) {
7152: checkok = 0;
7153: msg += "$lt{'thte'}\\n";
7154: }
7155: }
7156:
7157: if (srchtype== 'contains') {
7158: if (srchterm.length < 3) {
7159: checkok = 0;
7160: msg += "$lt{'thet'}\\n";
7161: }
7162: }
7163: if (srchin == 'instd') {
7164: if (srchdomain == '') {
7165: checkok = 0;
7166: msg += "$lt{'yomc'}\\n";
7167: }
7168: }
7169: if (srchin == 'dom') {
7170: if (srchdomain == '') {
7171: checkok = 0;
7172: msg += "$lt{'ymcd'}\\n";
7173: }
7174: }
7175: if (srchby == 'lastfirst') {
7176: if (srchterm.indexOf(",") == -1) {
7177: checkok = 0;
7178: msg += "$lt{'whus'}\\n";
7179: }
7180: if (srchterm.indexOf(",") == srchterm.length -1) {
7181: checkok = 0;
7182: msg += "$lt{'whse'}\\n";
7183: }
7184: }
7185: if (checkok == 0) {
7186: alert("$lt{'thfo'}\\n"+msg);
7187: return;
7188: }
7189: if (checkok == 1) {
7190: callingForm.submit();
7191: }
7192: }
7193:
7194: $newuserscript
7195:
7196: </script>
7197:
7198: $new_user_create
7199:
7200: <table>
7201: <tr>
7202: <td>$lt{'doma'}:</td>
7203: <td>$domform</td>
7204: </td>
7205: </tr>
7206: <tr>
7207: <td>$lt{'usr'}:</td>
7208: <td>$srchbysel
7209: $srchtypesel
7210: <input type="text" size="15" name="srchterm" value="$srchterm" />
7211: $srchinsel
7212: </td>
7213: </tr>
7214: </table>
7215: <br />
7216: END_BLOCK
7217:
7218: return $output;
7219: }
7220:
7221: sub user_rule_check {
7222: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
7223: my $response;
7224: if (ref($usershash) eq 'HASH') {
7225: foreach my $user (keys(%{$usershash})) {
7226: my ($uname,$udom) = split(/:/,$user);
7227: next if ($udom eq '' || $uname eq '');
7228: my ($id,$newuser);
7229: if (ref($usershash->{$user}) eq 'HASH') {
7230: $newuser = $usershash->{$user}->{'newuser'};
7231: $id = $usershash->{$user}->{'id'};
7232: }
7233: my $inst_response;
7234: if (ref($checks) eq 'HASH') {
7235: if (defined($checks->{'username'})) {
7236: ($inst_response,%{$inst_results->{$user}}) =
7237: &Apache::lonnet::get_instuser($udom,$uname);
7238: } elsif (defined($checks->{'id'})) {
7239: ($inst_response,%{$inst_results->{$user}}) =
7240: &Apache::lonnet::get_instuser($udom,undef,$id);
7241: }
7242: } else {
7243: ($inst_response,%{$inst_results->{$user}}) =
7244: &Apache::lonnet::get_instuser($udom,$uname);
7245: return;
7246: }
7247: if (!$got_rules->{$udom}) {
7248: my %domconfig = &Apache::lonnet::get_dom('configuration',
7249: ['usercreation'],$udom);
7250: if (ref($domconfig{'usercreation'}) eq 'HASH') {
7251: foreach my $item ('username','id') {
7252: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
7253: $$curr_rules{$udom}{$item} =
7254: $domconfig{'usercreation'}{$item.'_rule'};
7255: }
7256: }
7257: }
7258: $got_rules->{$udom} = 1;
7259: }
7260: foreach my $item (keys(%{$checks})) {
7261: if (ref($$curr_rules{$udom}) eq 'HASH') {
7262: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
7263: if (@{$$curr_rules{$udom}{$item}} > 0) {
7264: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
7265: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
7266: if ($rule_check{$rule}) {
7267: $$rulematch{$user}{$item} = $rule;
7268: if ($inst_response eq 'ok') {
7269: if (ref($inst_results) eq 'HASH') {
7270: if (ref($inst_results->{$user}) eq 'HASH') {
7271: if (keys(%{$inst_results->{$user}}) == 0) {
7272: $$alerts{$item}{$udom}{$uname} = 1;
7273: }
7274: }
7275: }
7276: }
7277: last;
7278: }
7279: }
7280: }
7281: }
7282: }
7283: }
7284: }
7285: }
7286: return;
7287: }
7288:
7289: sub user_rule_formats {
7290: my ($domain,$domdesc,$curr_rules,$check) = @_;
7291: my %text = (
7292: 'username' => 'Usernames',
7293: 'id' => 'IDs',
7294: );
7295: my $output;
7296: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
7297: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
7298: if (@{$ruleorder} > 0) {
7299: $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>';
7300: foreach my $rule (@{$ruleorder}) {
7301: if (ref($curr_rules) eq 'ARRAY') {
7302: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
7303: if (ref($rules->{$rule}) eq 'HASH') {
7304: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
7305: $rules->{$rule}{'desc'}.'</li>';
7306: }
7307: }
7308: }
7309: }
7310: $output .= '</ul>';
7311: }
7312: }
7313: return $output;
7314: }
7315:
7316: sub instrule_disallow_msg {
7317: my ($checkitem,$domdesc,$count,$mode) = @_;
7318: my $response;
7319: my %text = (
7320: item => 'username',
7321: items => 'usernames',
7322: match => 'matches',
7323: do => 'does',
7324: action => 'a username',
7325: one => 'one',
7326: );
7327: if ($count > 1) {
7328: $text{'item'} = 'usernames';
7329: $text{'match'} ='match';
7330: $text{'do'} = 'do';
7331: $text{'action'} = 'usernames',
7332: $text{'one'} = 'ones';
7333: }
7334: if ($checkitem eq 'id') {
7335: $text{'items'} = 'IDs';
7336: $text{'item'} = 'ID';
7337: $text{'action'} = 'an ID';
7338: if ($count > 1) {
7339: $text{'item'} = 'IDs';
7340: $text{'action'} = 'IDs';
7341: }
7342: }
7343: $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 />';
7344: if ($mode eq 'upload') {
7345: if ($checkitem eq 'username') {
7346: $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'}.");
7347: } elsif ($checkitem eq 'id') {
7348: $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.");
7349: }
7350: } elsif ($mode eq 'selfcreate') {
7351: if ($checkitem eq 'id') {
7352: $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.");
7353: }
7354: } else {
7355: if ($checkitem eq 'username') {
7356: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
7357: } elsif ($checkitem eq 'id') {
7358: $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.");
7359: }
7360: }
7361: return $response;
7362: }
7363:
7364: sub personal_data_fieldtitles {
7365: my %fieldtitles = &Apache::lonlocal::texthash (
7366: id => 'Student/Employee ID',
7367: permanentemail => 'E-mail address',
7368: lastname => 'Last Name',
7369: firstname => 'First Name',
7370: middlename => 'Middle Name',
7371: generation => 'Generation',
7372: gen => 'Generation',
7373: );
7374: return %fieldtitles;
7375: }
7376:
7377: sub sorted_inst_types {
7378: my ($dom) = @_;
7379: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
7380: my $othertitle = &mt('All users');
7381: if ($env{'request.course.id'}) {
7382: $othertitle = &mt('Any users');
7383: }
7384: my @types;
7385: if (ref($order) eq 'ARRAY') {
7386: @types = @{$order};
7387: }
7388: if (@types == 0) {
7389: if (ref($usertypes) eq 'HASH') {
7390: @types = sort(keys(%{$usertypes}));
7391: }
7392: }
7393: if (keys(%{$usertypes}) > 0) {
7394: $othertitle = &mt('Other users');
7395: }
7396: return ($othertitle,$usertypes,\@types);
7397: }
7398:
7399: sub get_institutional_codes {
7400: my ($settings,$allcourses,$LC_code) = @_;
7401: # Get complete list of course sections to update
7402: my @currsections = ();
7403: my @currxlists = ();
7404: my $coursecode = $$settings{'internal.coursecode'};
7405:
7406: if ($$settings{'internal.sectionnums'} ne '') {
7407: @currsections = split(/,/,$$settings{'internal.sectionnums'});
7408: }
7409:
7410: if ($$settings{'internal.crosslistings'} ne '') {
7411: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
7412: }
7413:
7414: if (@currxlists > 0) {
7415: foreach (@currxlists) {
7416: if (m/^([^:]+):(\w*)$/) {
7417: unless (grep/^$1$/,@{$allcourses}) {
7418: push @{$allcourses},$1;
7419: $$LC_code{$1} = $2;
7420: }
7421: }
7422: }
7423: }
7424:
7425: if (@currsections > 0) {
7426: foreach (@currsections) {
7427: if (m/^(\w+):(\w*)$/) {
7428: my $sec = $coursecode.$1;
7429: my $lc_sec = $2;
7430: unless (grep/^$sec$/,@{$allcourses}) {
7431: push @{$allcourses},$sec;
7432: $$LC_code{$sec} = $lc_sec;
7433: }
7434: }
7435: }
7436: }
7437: return;
7438: }
7439:
7440: =pod
7441:
7442: =back
7443:
7444: =head1 HTTP Helpers
7445:
7446: =over 4
7447:
7448: =item * &get_unprocessed_cgi($query,$possible_names)
7449:
7450: Modify the %env hash to contain unprocessed CGI form parameters held in
7451: $query. The parameters listed in $possible_names (an array reference),
7452: will be set in $env{'form.name'} if they do not already exist.
7453:
7454: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
7455: $possible_names is an ref to an array of form element names. As an example:
7456: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
7457: will result in $env{'form.uname'} and $env{'form.udom'} being set.
7458:
7459: =cut
7460:
7461: sub get_unprocessed_cgi {
7462: my ($query,$possible_names)= @_;
7463: # $Apache::lonxml::debug=1;
7464: foreach my $pair (split(/&/,$query)) {
7465: my ($name, $value) = split(/=/,$pair);
7466: $name = &unescape($name);
7467: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
7468: $value =~ tr/+/ /;
7469: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
7470: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
7471: }
7472: }
7473: }
7474:
7475: =pod
7476:
7477: =item * &cacheheader()
7478:
7479: returns cache-controlling header code
7480:
7481: =cut
7482:
7483: sub cacheheader {
7484: unless ($env{'request.method'} eq 'GET') { return ''; }
7485: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
7486: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
7487: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
7488: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
7489: return $output;
7490: }
7491:
7492: =pod
7493:
7494: =item * &no_cache($r)
7495:
7496: specifies header code to not have cache
7497:
7498: =cut
7499:
7500: sub no_cache {
7501: my ($r) = @_;
7502: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
7503: $env{'request.method'} ne 'GET') { return ''; }
7504: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
7505: $r->no_cache(1);
7506: $r->header_out("Expires" => $date);
7507: $r->header_out("Pragma" => "no-cache");
7508: }
7509:
7510: sub content_type {
7511: my ($r,$type,$charset) = @_;
7512: if ($r) {
7513: # Note that printout.pl calls this with undef for $r.
7514: &no_cache($r);
7515: }
7516: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
7517: unless ($charset) {
7518: $charset=&Apache::lonlocal::current_encoding;
7519: }
7520: if ($charset) { $type.='; charset='.$charset; }
7521: if ($r) {
7522: $r->content_type($type);
7523: } else {
7524: print("Content-type: $type\n\n");
7525: }
7526: }
7527:
7528: =pod
7529:
7530: =item * &add_to_env($name,$value)
7531:
7532: adds $name to the %env hash with value
7533: $value, if $name already exists, the entry is converted to an array
7534: reference and $value is added to the array.
7535:
7536: =cut
7537:
7538: sub add_to_env {
7539: my ($name,$value)=@_;
7540: if (defined($env{$name})) {
7541: if (ref($env{$name})) {
7542: #already have multiple values
7543: push(@{ $env{$name} },$value);
7544: } else {
7545: #first time seeing multiple values, convert hash entry to an arrayref
7546: my $first=$env{$name};
7547: undef($env{$name});
7548: push(@{ $env{$name} },$first,$value);
7549: }
7550: } else {
7551: $env{$name}=$value;
7552: }
7553: }
7554:
7555: =pod
7556:
7557: =item * &get_env_multiple($name)
7558:
7559: gets $name from the %env hash, it seemlessly handles the cases where multiple
7560: values may be defined and end up as an array ref.
7561:
7562: returns an array of values
7563:
7564: =cut
7565:
7566: sub get_env_multiple {
7567: my ($name) = @_;
7568: my @values;
7569: if (defined($env{$name})) {
7570: # exists is it an array
7571: if (ref($env{$name})) {
7572: @values=@{ $env{$name} };
7573: } else {
7574: $values[0]=$env{$name};
7575: }
7576: }
7577: return(@values);
7578: }
7579:
7580: sub ask_for_embedded_content {
7581: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
7582: my $upload_output = '
7583: <form name="upload_embedded" action="'.$actionurl.'"
7584: method="post" enctype="multipart/form-data">';
7585: $upload_output .= $state;
7586: $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
7587:
7588: my $num = 0;
7589: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
7590: $upload_output .= &start_data_table_row().
7591: '<td>'.$embed_file.'</td><td>';
7592: if ($args->{'ignore_remote_references'}
7593: && $embed_file =~ m{^\w+://}) {
7594: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
7595: } elsif ($args->{'error_on_invalid_names'}
7596: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
7597:
7598: $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
7599:
7600: } else {
7601: $upload_output .='
7602: <input name="embedded_item_'.$num.'" type="file" value="" />
7603: <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
7604: my $attrib = join(':',@{$$allfiles{$embed_file}});
7605: $upload_output .=
7606: "\n\t\t".
7607: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
7608: $attrib.'" />';
7609: if (exists($$codebase{$embed_file})) {
7610: $upload_output .=
7611: "\n\t\t".
7612: '<input name="codebase_'.$num.'" type="hidden" value="'.
7613: &escape($$codebase{$embed_file}).'" />';
7614: }
7615: }
7616: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
7617: $num++;
7618: }
7619: $upload_output .= &Apache::loncommon::end_data_table().'<br />
7620: <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
7621: <input type ="submit" value="'.&mt('Upload Listed Files').'" />
7622: '.&mt('(only files for which a location has been provided will be uploaded)').'
7623: </form>';
7624: return $upload_output;
7625: }
7626:
7627: sub upload_embedded {
7628: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
7629: $current_disk_usage) = @_;
7630: my $output;
7631: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
7632: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
7633: my $orig_uploaded_filename =
7634: $env{'form.embedded_item_'.$i.'.filename'};
7635:
7636: $env{'form.embedded_orig_'.$i} =
7637: &unescape($env{'form.embedded_orig_'.$i});
7638: my ($path,$fname) =
7639: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
7640: # no path, whole string is fname
7641: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
7642:
7643: $path = $env{'form.currentpath'}.$path;
7644: $fname = &Apache::lonnet::clean_filename($fname);
7645: # See if there is anything left
7646: next if ($fname eq '');
7647:
7648: # Check if file already exists as a file or directory.
7649: my ($state,$msg);
7650: if ($context eq 'portfolio') {
7651: my $port_path = $dirpath;
7652: if ($group ne '') {
7653: $port_path = "groups/$group/$port_path";
7654: }
7655: ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
7656: $dir_root,$port_path,$disk_quota,
7657: $current_disk_usage,$uname,$udom);
7658: if ($state eq 'will_exceed_quota'
7659: || $state eq 'file_locked'
7660: || $state eq 'file_exists' ) {
7661: $output .= $msg;
7662: next;
7663: }
7664: } elsif (($context eq 'author') || ($context eq 'testbank')) {
7665: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
7666: if ($state eq 'exists') {
7667: $output .= $msg;
7668: next;
7669: }
7670: }
7671: # Check if extension is valid
7672: if (($fname =~ /\.(\w+)$/) &&
7673: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
7674: $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
7675: next;
7676: } elsif (($fname =~ /\.(\w+)$/) &&
7677: (!defined(&Apache::loncommon::fileembstyle($1)))) {
7678: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
7679: next;
7680: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
7681: $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
7682: next;
7683: }
7684:
7685: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
7686: if ($context eq 'portfolio') {
7687: my $result=
7688: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
7689: $dirpath.$path);
7690: if ($result !~ m|^/uploaded/|) {
7691: $output .= '<span class="LC_error">'
7692: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
7693: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
7694: .'</span><br />';
7695: next;
7696: } else {
7697: $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
7698: $path.$fname.'</span>').'</p>';
7699: }
7700: } else {
7701: # Save the file
7702: my $target = $env{'form.embedded_item_'.$i};
7703: my $fullpath = $dir_root.$dirpath.'/'.$path;
7704: my $dest = $fullpath.$fname;
7705: my $url = $url_root.$dirpath.'/'.$path.$fname;
7706: my @parts=split(/\//,$fullpath);
7707: my $count;
7708: my $filepath = $dir_root;
7709: for ($count=4;$count<=$#parts;$count++) {
7710: $filepath .= "/$parts[$count]";
7711: if ((-e $filepath)!=1) {
7712: mkdir($filepath,0770);
7713: }
7714: }
7715: my $fh;
7716: if (!open($fh,'>'.$dest)) {
7717: &Apache::lonnet::logthis('Failed to create '.$dest);
7718: $output .= '<span class="LC_error">'.
7719: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
7720: '</span><br />';
7721: } else {
7722: if (!print $fh $env{'form.embedded_item_'.$i}) {
7723: &Apache::lonnet::logthis('Failed to write to '.$dest);
7724: $output .= '<span class="LC_error">'.
7725: &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
7726: '</span><br />';
7727: } else {
7728: if ($context eq 'testbank') {
7729: $output .= &mt('Embedded file uploaded successfully:').
7730: ' <a href="'.$url.'">'.
7731: $orig_uploaded_filename.'</a><br />';
7732: } else {
7733: $output .= '<span class=\"LC_fontsize_large\">'.
7734: &mt('View embedded file: [_1]','<a href="'.$url.'">'.
7735: $orig_uploaded_filename.'</a>').'</span><br />';
7736: }
7737: }
7738: close($fh);
7739: }
7740: }
7741: }
7742: return $output;
7743: }
7744:
7745: sub check_for_existing {
7746: my ($path,$fname,$element) = @_;
7747: my ($state,$msg);
7748: if (-d $path.'/'.$fname) {
7749: $state = 'exists';
7750: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
7751: } elsif (-e $path.'/'.$fname) {
7752: $state = 'exists';
7753: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
7754: }
7755: if ($state eq 'exists') {
7756: $msg = '<span class="LC_error">'.$msg.'</span><br />';
7757: }
7758: return ($state,$msg);
7759: }
7760:
7761: sub check_for_upload {
7762: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
7763: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
7764: my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
7765: my $getpropath = 1;
7766: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
7767: $getpropath);
7768: my $found_file = 0;
7769: my $locked_file = 0;
7770: foreach my $line (@dir_list) {
7771: my ($file_name)=split(/\&/,$line,2);
7772: if ($file_name eq $fname){
7773: $file_name = $path.$file_name;
7774: if ($group ne '') {
7775: $file_name = $group.$file_name;
7776: }
7777: $found_file = 1;
7778: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
7779: $locked_file = 1;
7780: }
7781: }
7782: }
7783: if (($current_disk_usage + $filesize) > $disk_quota){
7784: my $msg = '<span class="LC_error">'.
7785: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
7786: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
7787: return ('will_exceed_quota',$msg);
7788: } elsif ($found_file) {
7789: if ($locked_file) {
7790: my $msg = '<span class="LC_error">';
7791: $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>');
7792: $msg .= '</span><br />';
7793: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
7794: return ('file_locked',$msg);
7795: } else {
7796: my $msg = '<span class="LC_error">';
7797: $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'});
7798: $msg .= '</span>';
7799: $msg .= '<br />';
7800: $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
7801: return ('file_exists',$msg);
7802: }
7803: }
7804: }
7805:
7806:
7807: =pod
7808:
7809: =back
7810:
7811: =head1 CSV Upload/Handling functions
7812:
7813: =over 4
7814:
7815: =item * &upfile_store($r)
7816:
7817: Store uploaded file, $r should be the HTTP Request object,
7818: needs $env{'form.upfile'}
7819: returns $datatoken to be put into hidden field
7820:
7821: =cut
7822:
7823: sub upfile_store {
7824: my $r=shift;
7825: $env{'form.upfile'}=~s/\r/\n/gs;
7826: $env{'form.upfile'}=~s/\f/\n/gs;
7827: $env{'form.upfile'}=~s/\n+/\n/gs;
7828: $env{'form.upfile'}=~s/\n+$//gs;
7829:
7830: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
7831: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
7832: {
7833: my $datafile = $r->dir_config('lonDaemons').
7834: '/tmp/'.$datatoken.'.tmp';
7835: if ( open(my $fh,">$datafile") ) {
7836: print $fh $env{'form.upfile'};
7837: close($fh);
7838: }
7839: }
7840: return $datatoken;
7841: }
7842:
7843: =pod
7844:
7845: =item * &load_tmp_file($r)
7846:
7847: Load uploaded file from tmp, $r should be the HTTP Request object,
7848: needs $env{'form.datatoken'},
7849: sets $env{'form.upfile'} to the contents of the file
7850:
7851: =cut
7852:
7853: sub load_tmp_file {
7854: my $r=shift;
7855: my @studentdata=();
7856: {
7857: my $studentfile = $r->dir_config('lonDaemons').
7858: '/tmp/'.$env{'form.datatoken'}.'.tmp';
7859: if ( open(my $fh,"<$studentfile") ) {
7860: @studentdata=<$fh>;
7861: close($fh);
7862: }
7863: }
7864: $env{'form.upfile'}=join('',@studentdata);
7865: }
7866:
7867: =pod
7868:
7869: =item * &upfile_record_sep()
7870:
7871: Separate uploaded file into records
7872: returns array of records,
7873: needs $env{'form.upfile'} and $env{'form.upfiletype'}
7874:
7875: =cut
7876:
7877: sub upfile_record_sep {
7878: if ($env{'form.upfiletype'} eq 'xml') {
7879: } else {
7880: my @records;
7881: foreach my $line (split(/\n/,$env{'form.upfile'})) {
7882: if ($line=~/^\s*$/) { next; }
7883: push(@records,$line);
7884: }
7885: return @records;
7886: }
7887: }
7888:
7889: =pod
7890:
7891: =item * &record_sep($record)
7892:
7893: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
7894:
7895: =cut
7896:
7897: sub takeleft {
7898: my $index=shift;
7899: return substr('0000'.$index,-4,4);
7900: }
7901:
7902: sub record_sep {
7903: my $record=shift;
7904: my %components=();
7905: if ($env{'form.upfiletype'} eq 'xml') {
7906: } elsif ($env{'form.upfiletype'} eq 'space') {
7907: my $i=0;
7908: foreach my $field (split(/\s+/,$record)) {
7909: $field=~s/^(\"|\')//;
7910: $field=~s/(\"|\')$//;
7911: $components{&takeleft($i)}=$field;
7912: $i++;
7913: }
7914: } elsif ($env{'form.upfiletype'} eq 'tab') {
7915: my $i=0;
7916: foreach my $field (split(/\t/,$record)) {
7917: $field=~s/^(\"|\')//;
7918: $field=~s/(\"|\')$//;
7919: $components{&takeleft($i)}=$field;
7920: $i++;
7921: }
7922: } else {
7923: my $separator=',';
7924: if ($env{'form.upfiletype'} eq 'semisv') {
7925: $separator=';';
7926: }
7927: my $i=0;
7928: # the character we are looking for to indicate the end of a quote or a record
7929: my $looking_for=$separator;
7930: # do not add the characters to the fields
7931: my $ignore=0;
7932: # we just encountered a separator (or the beginning of the record)
7933: my $just_found_separator=1;
7934: # store the field we are working on here
7935: my $field='';
7936: # work our way through all characters in record
7937: foreach my $character ($record=~/(.)/g) {
7938: if ($character eq $looking_for) {
7939: if ($character ne $separator) {
7940: # Found the end of a quote, again looking for separator
7941: $looking_for=$separator;
7942: $ignore=1;
7943: } else {
7944: # Found a separator, store away what we got
7945: $components{&takeleft($i)}=$field;
7946: $i++;
7947: $just_found_separator=1;
7948: $ignore=0;
7949: $field='';
7950: }
7951: next;
7952: }
7953: # single or double quotation marks after a separator indicate beginning of a quote
7954: # we are now looking for the end of the quote and need to ignore separators
7955: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
7956: $looking_for=$character;
7957: next;
7958: }
7959: # ignore would be true after we reached the end of a quote
7960: if ($ignore) { next; }
7961: if (($just_found_separator) && ($character=~/\s/)) { next; }
7962: $field.=$character;
7963: $just_found_separator=0;
7964: }
7965: # catch the very last entry, since we never encountered the separator
7966: $components{&takeleft($i)}=$field;
7967: }
7968: return %components;
7969: }
7970:
7971: ######################################################
7972: ######################################################
7973:
7974: =pod
7975:
7976: =item * &upfile_select_html()
7977:
7978: Return HTML code to select a file from the users machine and specify
7979: the file type.
7980:
7981: =cut
7982:
7983: ######################################################
7984: ######################################################
7985: sub upfile_select_html {
7986: my %Types = (
7987: csv => &mt('CSV (comma separated values, spreadsheet)'),
7988: semisv => &mt('Semicolon separated values'),
7989: space => &mt('Space separated'),
7990: tab => &mt('Tabulator separated'),
7991: # xml => &mt('HTML/XML'),
7992: );
7993: my $Str = '<input type="file" name="upfile" size="50" />'.
7994: '<br />'.&mt('Type').': <select name="upfiletype">';
7995: foreach my $type (sort(keys(%Types))) {
7996: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
7997: }
7998: $Str .= "</select>\n";
7999: return $Str;
8000: }
8001:
8002: sub get_samples {
8003: my ($records,$toget) = @_;
8004: my @samples=({});
8005: my $got=0;
8006: foreach my $rec (@$records) {
8007: my %temp = &record_sep($rec);
8008: if (! grep(/\S/, values(%temp))) { next; }
8009: if (%temp) {
8010: $samples[$got]=\%temp;
8011: $got++;
8012: if ($got == $toget) { last; }
8013: }
8014: }
8015: return \@samples;
8016: }
8017:
8018: ######################################################
8019: ######################################################
8020:
8021: =pod
8022:
8023: =item * &csv_print_samples($r,$records)
8024:
8025: Prints a table of sample values from each column uploaded $r is an
8026: Apache Request ref, $records is an arrayref from
8027: &Apache::loncommon::upfile_record_sep
8028:
8029: =cut
8030:
8031: ######################################################
8032: ######################################################
8033: sub csv_print_samples {
8034: my ($r,$records) = @_;
8035: my $samples = &get_samples($records,5);
8036:
8037: $r->print(&mt('Samples').'<br />'.&start_data_table().
8038: &start_data_table_header_row());
8039: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8040: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
8041: $r->print(&end_data_table_header_row());
8042: foreach my $hash (@$samples) {
8043: $r->print(&start_data_table_row());
8044: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8045: $r->print('<td>');
8046: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
8047: $r->print('</td>');
8048: }
8049: $r->print(&end_data_table_row());
8050: }
8051: $r->print(&end_data_table().'<br />'."\n");
8052: }
8053:
8054: ######################################################
8055: ######################################################
8056:
8057: =pod
8058:
8059: =item * &csv_print_select_table($r,$records,$d)
8060:
8061: Prints a table to create associations between values and table columns.
8062:
8063: $r is an Apache Request ref,
8064: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
8065: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
8066:
8067: =cut
8068:
8069: ######################################################
8070: ######################################################
8071: sub csv_print_select_table {
8072: my ($r,$records,$d) = @_;
8073: my $i=0;
8074: my $samples = &get_samples($records,1);
8075: $r->print(&mt('Associate columns with student attributes.')."\n".
8076: &start_data_table().&start_data_table_header_row().
8077: '<th>'.&mt('Attribute').'</th>'.
8078: '<th>'.&mt('Column').'</th>'.
8079: &end_data_table_header_row()."\n");
8080: foreach my $array_ref (@$d) {
8081: my ($value,$display,$defaultcol)=@{ $array_ref };
8082: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
8083:
8084: $r->print('<td><select name=f'.$i.
8085: ' onchange="javascript:flip(this.form,'.$i.');">');
8086: $r->print('<option value="none"></option>');
8087: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8088: $r->print('<option value="'.$sample.'"'.
8089: ($sample eq $defaultcol ? ' selected="selected" ' : '').
8090: '>'.&mt('Column [_1]',($sample+1)).'</option>');
8091: }
8092: $r->print('</select></td>'.&end_data_table_row()."\n");
8093: $i++;
8094: }
8095: $r->print(&end_data_table());
8096: $i--;
8097: return $i;
8098: }
8099:
8100: ######################################################
8101: ######################################################
8102:
8103: =pod
8104:
8105: =item * &csv_samples_select_table($r,$records,$d)
8106:
8107: Prints a table of sample values from the upload and can make associate samples to internal names.
8108:
8109: $r is an Apache Request ref,
8110: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
8111: $d is an array of 2 element arrays (internal name, displayed name)
8112:
8113: =cut
8114:
8115: ######################################################
8116: ######################################################
8117: sub csv_samples_select_table {
8118: my ($r,$records,$d) = @_;
8119: my $i=0;
8120: #
8121: my $max_samples = 5;
8122: my $samples = &get_samples($records,$max_samples);
8123: $r->print(&start_data_table().
8124: &start_data_table_header_row().'<th>'.
8125: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
8126: &end_data_table_header_row());
8127:
8128: foreach my $key (sort(keys(%{ $samples->[0] }))) {
8129: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
8130: ' onchange="javascript:flip(this.form,'.$i.');">');
8131: foreach my $option (@$d) {
8132: my ($value,$display,$defaultcol)=@{ $option };
8133: $r->print('<option value="'.$value.'"'.
8134: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
8135: $display.'</option>');
8136: }
8137: $r->print('</select></td><td>');
8138: foreach my $line (0..($max_samples-1)) {
8139: if (defined($samples->[$line]{$key})) {
8140: $r->print($samples->[$line]{$key}."<br />\n");
8141: }
8142: }
8143: $r->print('</td>'.&end_data_table_row());
8144: $i++;
8145: }
8146: $r->print(&end_data_table());
8147: $i--;
8148: return($i);
8149: }
8150:
8151: ######################################################
8152: ######################################################
8153:
8154: =pod
8155:
8156: =item * &clean_excel_name($name)
8157:
8158: Returns a replacement for $name which does not contain any illegal characters.
8159:
8160: =cut
8161:
8162: ######################################################
8163: ######################################################
8164: sub clean_excel_name {
8165: my ($name) = @_;
8166: $name =~ s/[:\*\?\/\\]//g;
8167: if (length($name) > 31) {
8168: $name = substr($name,0,31);
8169: }
8170: return $name;
8171: }
8172:
8173: =pod
8174:
8175: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
8176:
8177: Returns either 1 or undef
8178:
8179: 1 if the part is to be hidden, undef if it is to be shown
8180:
8181: Arguments are:
8182:
8183: $id the id of the part to be checked
8184: $symb, optional the symb of the resource to check
8185: $udom, optional the domain of the user to check for
8186: $uname, optional the username of the user to check for
8187:
8188: =cut
8189:
8190: sub check_if_partid_hidden {
8191: my ($id,$symb,$udom,$uname) = @_;
8192: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
8193: $symb,$udom,$uname);
8194: my $truth=1;
8195: #if the string starts with !, then the list is the list to show not hide
8196: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
8197: my @hiddenlist=split(/,/,$hiddenparts);
8198: foreach my $checkid (@hiddenlist) {
8199: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
8200: }
8201: return !$truth;
8202: }
8203:
8204:
8205: ############################################################
8206: ############################################################
8207:
8208: =pod
8209:
8210: =back
8211:
8212: =head1 cgi-bin script and graphing routines
8213:
8214: =over 4
8215:
8216: =item * &get_cgi_id()
8217:
8218: Inputs: none
8219:
8220: Returns an id which can be used to pass environment variables
8221: to various cgi-bin scripts. These environment variables will
8222: be removed from the users environment after a given time by
8223: the routine &Apache::lonnet::transfer_profile_to_env.
8224:
8225: =cut
8226:
8227: ############################################################
8228: ############################################################
8229: my $uniq=0;
8230: sub get_cgi_id {
8231: $uniq=($uniq+1)%100000;
8232: return (time.'_'.$$.'_'.$uniq);
8233: }
8234:
8235: ############################################################
8236: ############################################################
8237:
8238: =pod
8239:
8240: =item * &DrawBarGraph()
8241:
8242: Facilitates the plotting of data in a (stacked) bar graph.
8243: Puts plot definition data into the users environment in order for
8244: graph.png to plot it. Returns an <img> tag for the plot.
8245: The bars on the plot are labeled '1','2',...,'n'.
8246:
8247: Inputs:
8248:
8249: =over 4
8250:
8251: =item $Title: string, the title of the plot
8252:
8253: =item $xlabel: string, text describing the X-axis of the plot
8254:
8255: =item $ylabel: string, text describing the Y-axis of the plot
8256:
8257: =item $Max: scalar, the maximum Y value to use in the plot
8258: If $Max is < any data point, the graph will not be rendered.
8259:
8260: =item $colors: array ref holding the colors to be used for the data sets when
8261: they are plotted. If undefined, default values will be used.
8262:
8263: =item $labels: array ref holding the labels to use on the x-axis for the bars.
8264:
8265: =item @Values: An array of array references. Each array reference holds data
8266: to be plotted in a stacked bar chart.
8267:
8268: =item If the final element of @Values is a hash reference the key/value
8269: pairs will be added to the graph definition.
8270:
8271: =back
8272:
8273: Returns:
8274:
8275: An <img> tag which references graph.png and the appropriate identifying
8276: information for the plot.
8277:
8278: =cut
8279:
8280: ############################################################
8281: ############################################################
8282: sub DrawBarGraph {
8283: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
8284: #
8285: if (! defined($colors)) {
8286: $colors = ['#33ff00',
8287: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
8288: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
8289: ];
8290: }
8291: my $extra_settings = {};
8292: if (ref($Values[-1]) eq 'HASH') {
8293: $extra_settings = pop(@Values);
8294: }
8295: #
8296: my $identifier = &get_cgi_id();
8297: my $id = 'cgi.'.$identifier;
8298: if (! @Values || ref($Values[0]) ne 'ARRAY') {
8299: return '';
8300: }
8301: #
8302: my @Labels;
8303: if (defined($labels)) {
8304: @Labels = @$labels;
8305: } else {
8306: for (my $i=0;$i<@{$Values[0]};$i++) {
8307: push (@Labels,$i+1);
8308: }
8309: }
8310: #
8311: my $NumBars = scalar(@{$Values[0]});
8312: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
8313: my %ValuesHash;
8314: my $NumSets=1;
8315: foreach my $array (@Values) {
8316: next if (! ref($array));
8317: $ValuesHash{$id.'.data.'.$NumSets++} =
8318: join(',',@$array);
8319: }
8320: #
8321: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
8322: if ($NumBars < 3) {
8323: $width = 120+$NumBars*32;
8324: $xskip = 1;
8325: $bar_width = 30;
8326: } elsif ($NumBars < 5) {
8327: $width = 120+$NumBars*20;
8328: $xskip = 1;
8329: $bar_width = 20;
8330: } elsif ($NumBars < 10) {
8331: $width = 120+$NumBars*15;
8332: $xskip = 1;
8333: $bar_width = 15;
8334: } elsif ($NumBars <= 25) {
8335: $width = 120+$NumBars*11;
8336: $xskip = 5;
8337: $bar_width = 8;
8338: } elsif ($NumBars <= 50) {
8339: $width = 120+$NumBars*8;
8340: $xskip = 5;
8341: $bar_width = 4;
8342: } else {
8343: $width = 120+$NumBars*8;
8344: $xskip = 5;
8345: $bar_width = 4;
8346: }
8347: #
8348: $Max = 1 if ($Max < 1);
8349: if ( int($Max) < $Max ) {
8350: $Max++;
8351: $Max = int($Max);
8352: }
8353: $Title = '' if (! defined($Title));
8354: $xlabel = '' if (! defined($xlabel));
8355: $ylabel = '' if (! defined($ylabel));
8356: $ValuesHash{$id.'.title'} = &escape($Title);
8357: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
8358: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
8359: $ValuesHash{$id.'.y_max_value'} = $Max;
8360: $ValuesHash{$id.'.NumBars'} = $NumBars;
8361: $ValuesHash{$id.'.NumSets'} = $NumSets;
8362: $ValuesHash{$id.'.PlotType'} = 'bar';
8363: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8364: $ValuesHash{$id.'.height'} = $height;
8365: $ValuesHash{$id.'.width'} = $width;
8366: $ValuesHash{$id.'.xskip'} = $xskip;
8367: $ValuesHash{$id.'.bar_width'} = $bar_width;
8368: $ValuesHash{$id.'.labels'} = join(',',@Labels);
8369: #
8370: # Deal with other parameters
8371: while (my ($key,$value) = each(%$extra_settings)) {
8372: $ValuesHash{$id.'.'.$key} = $value;
8373: }
8374: #
8375: &Apache::lonnet::appenv(\%ValuesHash);
8376: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8377: }
8378:
8379: ############################################################
8380: ############################################################
8381:
8382: =pod
8383:
8384: =item * &DrawXYGraph()
8385:
8386: Facilitates the plotting of data in an XY graph.
8387: Puts plot definition data into the users environment in order for
8388: graph.png to plot it. Returns an <img> tag for the plot.
8389:
8390: Inputs:
8391:
8392: =over 4
8393:
8394: =item $Title: string, the title of the plot
8395:
8396: =item $xlabel: string, text describing the X-axis of the plot
8397:
8398: =item $ylabel: string, text describing the Y-axis of the plot
8399:
8400: =item $Max: scalar, the maximum Y value to use in the plot
8401: If $Max is < any data point, the graph will not be rendered.
8402:
8403: =item $colors: Array ref containing the hex color codes for the data to be
8404: plotted in. If undefined, default values will be used.
8405:
8406: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8407:
8408: =item $Ydata: Array ref containing Array refs.
8409: Each of the contained arrays will be plotted as a separate curve.
8410:
8411: =item %Values: hash indicating or overriding any default values which are
8412: passed to graph.png.
8413: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
8414:
8415: =back
8416:
8417: Returns:
8418:
8419: An <img> tag which references graph.png and the appropriate identifying
8420: information for the plot.
8421:
8422: =cut
8423:
8424: ############################################################
8425: ############################################################
8426: sub DrawXYGraph {
8427: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
8428: #
8429: # Create the identifier for the graph
8430: my $identifier = &get_cgi_id();
8431: my $id = 'cgi.'.$identifier;
8432: #
8433: $Title = '' if (! defined($Title));
8434: $xlabel = '' if (! defined($xlabel));
8435: $ylabel = '' if (! defined($ylabel));
8436: my %ValuesHash =
8437: (
8438: $id.'.title' => &escape($Title),
8439: $id.'.xlabel' => &escape($xlabel),
8440: $id.'.ylabel' => &escape($ylabel),
8441: $id.'.y_max_value'=> $Max,
8442: $id.'.labels' => join(',',@$Xlabels),
8443: $id.'.PlotType' => 'XY',
8444: );
8445: #
8446: if (defined($colors) && ref($colors) eq 'ARRAY') {
8447: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8448: }
8449: #
8450: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
8451: return '';
8452: }
8453: my $NumSets=1;
8454: foreach my $array (@{$Ydata}){
8455: next if (! ref($array));
8456: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
8457: }
8458: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
8459: #
8460: # Deal with other parameters
8461: while (my ($key,$value) = each(%Values)) {
8462: $ValuesHash{$id.'.'.$key} = $value;
8463: }
8464: #
8465: &Apache::lonnet::appenv(\%ValuesHash);
8466: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8467: }
8468:
8469: ############################################################
8470: ############################################################
8471:
8472: =pod
8473:
8474: =item * &DrawXYYGraph()
8475:
8476: Facilitates the plotting of data in an XY graph with two Y axes.
8477: Puts plot definition data into the users environment in order for
8478: graph.png to plot it. Returns an <img> tag for the plot.
8479:
8480: Inputs:
8481:
8482: =over 4
8483:
8484: =item $Title: string, the title of the plot
8485:
8486: =item $xlabel: string, text describing the X-axis of the plot
8487:
8488: =item $ylabel: string, text describing the Y-axis of the plot
8489:
8490: =item $colors: Array ref containing the hex color codes for the data to be
8491: plotted in. If undefined, default values will be used.
8492:
8493: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8494:
8495: =item $Ydata1: The first data set
8496:
8497: =item $Min1: The minimum value of the left Y-axis
8498:
8499: =item $Max1: The maximum value of the left Y-axis
8500:
8501: =item $Ydata2: The second data set
8502:
8503: =item $Min2: The minimum value of the right Y-axis
8504:
8505: =item $Max2: The maximum value of the left Y-axis
8506:
8507: =item %Values: hash indicating or overriding any default values which are
8508: passed to graph.png.
8509: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
8510:
8511: =back
8512:
8513: Returns:
8514:
8515: An <img> tag which references graph.png and the appropriate identifying
8516: information for the plot.
8517:
8518: =cut
8519:
8520: ############################################################
8521: ############################################################
8522: sub DrawXYYGraph {
8523: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
8524: $Ydata2,$Min2,$Max2,%Values)=@_;
8525: #
8526: # Create the identifier for the graph
8527: my $identifier = &get_cgi_id();
8528: my $id = 'cgi.'.$identifier;
8529: #
8530: $Title = '' if (! defined($Title));
8531: $xlabel = '' if (! defined($xlabel));
8532: $ylabel = '' if (! defined($ylabel));
8533: my %ValuesHash =
8534: (
8535: $id.'.title' => &escape($Title),
8536: $id.'.xlabel' => &escape($xlabel),
8537: $id.'.ylabel' => &escape($ylabel),
8538: $id.'.labels' => join(',',@$Xlabels),
8539: $id.'.PlotType' => 'XY',
8540: $id.'.NumSets' => 2,
8541: $id.'.two_axes' => 1,
8542: $id.'.y1_max_value' => $Max1,
8543: $id.'.y1_min_value' => $Min1,
8544: $id.'.y2_max_value' => $Max2,
8545: $id.'.y2_min_value' => $Min2,
8546: );
8547: #
8548: if (defined($colors) && ref($colors) eq 'ARRAY') {
8549: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8550: }
8551: #
8552: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
8553: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
8554: return '';
8555: }
8556: my $NumSets=1;
8557: foreach my $array ($Ydata1,$Ydata2){
8558: next if (! ref($array));
8559: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
8560: }
8561: #
8562: # Deal with other parameters
8563: while (my ($key,$value) = each(%Values)) {
8564: $ValuesHash{$id.'.'.$key} = $value;
8565: }
8566: #
8567: &Apache::lonnet::appenv(\%ValuesHash);
8568: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8569: }
8570:
8571: ############################################################
8572: ############################################################
8573:
8574: =pod
8575:
8576: =back
8577:
8578: =head1 Statistics helper routines?
8579:
8580: Bad place for them but what the hell.
8581:
8582: =over 4
8583:
8584: =item * &chartlink()
8585:
8586: Returns a link to the chart for a specific student.
8587:
8588: Inputs:
8589:
8590: =over 4
8591:
8592: =item $linktext: The text of the link
8593:
8594: =item $sname: The students username
8595:
8596: =item $sdomain: The students domain
8597:
8598: =back
8599:
8600: =back
8601:
8602: =cut
8603:
8604: ############################################################
8605: ############################################################
8606: sub chartlink {
8607: my ($linktext, $sname, $sdomain) = @_;
8608: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
8609: '&SelectedStudent='.&escape($sname.':'.$sdomain).
8610: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
8611: '">'.$linktext.'</a>';
8612: }
8613:
8614: #######################################################
8615: #######################################################
8616:
8617: =pod
8618:
8619: =head1 Course Environment Routines
8620:
8621: =over 4
8622:
8623: =item * &restore_course_settings()
8624:
8625: =item * &store_course_settings()
8626:
8627: Restores/Store indicated form parameters from the course environment.
8628: Will not overwrite existing values of the form parameters.
8629:
8630: Inputs:
8631: a scalar describing the data (e.g. 'chart', 'problem_analysis')
8632:
8633: a hash ref describing the data to be stored. For example:
8634:
8635: %Save_Parameters = ('Status' => 'scalar',
8636: 'chartoutputmode' => 'scalar',
8637: 'chartoutputdata' => 'scalar',
8638: 'Section' => 'array',
8639: 'Group' => 'array',
8640: 'StudentData' => 'array',
8641: 'Maps' => 'array');
8642:
8643: Returns: both routines return nothing
8644:
8645: =back
8646:
8647: =cut
8648:
8649: #######################################################
8650: #######################################################
8651: sub store_course_settings {
8652: return &store_settings($env{'request.course.id'},@_);
8653: }
8654:
8655: sub store_settings {
8656: # save to the environment
8657: # appenv the same items, just to be safe
8658: my $udom = $env{'user.domain'};
8659: my $uname = $env{'user.name'};
8660: my ($context,$prefix,$Settings) = @_;
8661: my %SaveHash;
8662: my %AppHash;
8663: while (my ($setting,$type) = each(%$Settings)) {
8664: my $basename = join('.','internal',$context,$prefix,$setting);
8665: my $envname = 'environment.'.$basename;
8666: if (exists($env{'form.'.$setting})) {
8667: # Save this value away
8668: if ($type eq 'scalar' &&
8669: (! exists($env{$envname}) ||
8670: $env{$envname} ne $env{'form.'.$setting})) {
8671: $SaveHash{$basename} = $env{'form.'.$setting};
8672: $AppHash{$envname} = $env{'form.'.$setting};
8673: } elsif ($type eq 'array') {
8674: my $stored_form;
8675: if (ref($env{'form.'.$setting})) {
8676: $stored_form = join(',',
8677: map {
8678: &escape($_);
8679: } sort(@{$env{'form.'.$setting}}));
8680: } else {
8681: $stored_form =
8682: &escape($env{'form.'.$setting});
8683: }
8684: # Determine if the array contents are the same.
8685: if ($stored_form ne $env{$envname}) {
8686: $SaveHash{$basename} = $stored_form;
8687: $AppHash{$envname} = $stored_form;
8688: }
8689: }
8690: }
8691: }
8692: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
8693: $udom,$uname);
8694: if ($put_result !~ /^(ok|delayed)/) {
8695: &Apache::lonnet::logthis('unable to save form parameters, '.
8696: 'got error:'.$put_result);
8697: }
8698: # Make sure these settings stick around in this session, too
8699: &Apache::lonnet::appenv(\%AppHash);
8700: return;
8701: }
8702:
8703: sub restore_course_settings {
8704: return &restore_settings($env{'request.course.id'},@_);
8705: }
8706:
8707: sub restore_settings {
8708: my ($context,$prefix,$Settings) = @_;
8709: while (my ($setting,$type) = each(%$Settings)) {
8710: next if (exists($env{'form.'.$setting}));
8711: my $envname = 'environment.internal.'.$context.'.'.$prefix.
8712: '.'.$setting;
8713: if (exists($env{$envname})) {
8714: if ($type eq 'scalar') {
8715: $env{'form.'.$setting} = $env{$envname};
8716: } elsif ($type eq 'array') {
8717: $env{'form.'.$setting} = [
8718: map {
8719: &unescape($_);
8720: } split(',',$env{$envname})
8721: ];
8722: }
8723: }
8724: }
8725: }
8726:
8727: #######################################################
8728: #######################################################
8729:
8730: =pod
8731:
8732: =head1 Domain E-mail Routines
8733:
8734: =over 4
8735:
8736: =item * &build_recipient_list()
8737:
8738: Build recipient lists for three types of e-mail:
8739: (a) Error Reports, (b) Package Updates, (c) Help requests, generated by
8740: lonerrorhandler.pm, CHECKRPMS and lonsupportreq.pm respectively.
8741:
8742: Inputs:
8743: defmail (scalar - email address of default recipient),
8744: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
8745: defdom (domain for which to retrieve configuration settings),
8746: origmail (scalar - email address of recipient from loncapa.conf,
8747: i.e., predates configuration by DC via domainprefs.pm
8748:
8749: Returns: comma separated list of addresses to which to send e-mail.
8750:
8751: =back
8752:
8753: =cut
8754:
8755: ############################################################
8756: ############################################################
8757: sub build_recipient_list {
8758: my ($defmail,$mailing,$defdom,$origmail) = @_;
8759: my @recipients;
8760: my $otheremails;
8761: my %domconfig =
8762: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
8763: if (ref($domconfig{'contacts'}) eq 'HASH') {
8764: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
8765: my @contacts = ('adminemail','supportemail');
8766: foreach my $item (@contacts) {
8767: if ($domconfig{'contacts'}{$mailing}{$item}) {
8768: my $addr = $domconfig{'contacts'}{$item};
8769: if (!grep(/^\Q$addr\E$/,@recipients)) {
8770: push(@recipients,$addr);
8771: }
8772: }
8773: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
8774: }
8775: }
8776: } elsif ($origmail ne '') {
8777: push(@recipients,$origmail);
8778: }
8779: if (defined($defmail)) {
8780: if ($defmail ne '') {
8781: push(@recipients,$defmail);
8782: }
8783: }
8784: if ($otheremails) {
8785: my @others;
8786: if ($otheremails =~ /,/) {
8787: @others = split(/,/,$otheremails);
8788: } else {
8789: push(@others,$otheremails);
8790: }
8791: foreach my $addr (@others) {
8792: if (!grep(/^\Q$addr\E$/,@recipients)) {
8793: push(@recipients,$addr);
8794: }
8795: }
8796: }
8797: my $recipientlist = join(',',@recipients);
8798: return $recipientlist;
8799: }
8800:
8801: ############################################################
8802: ############################################################
8803:
8804: =pod
8805:
8806: =head1 Course Catalog Routines
8807:
8808: =over 4
8809:
8810: =item * &gather_categories()
8811:
8812: Converts category definitions - keys of categories hash stored in
8813: coursecategories in configuration.db on the primary library server in a
8814: domain - to an array. Also generates javascript and idx hash used to
8815: generate Domain Coordinator interface for editing Course Categories.
8816:
8817: Inputs:
8818:
8819: categories (reference to hash of category definitions).
8820:
8821: cats (reference to array of arrays/hashes which encapsulates hierarchy of
8822: categories and subcategories).
8823:
8824: idx (reference to hash of counters used in Domain Coordinator interface for
8825: editing Course Categories).
8826:
8827: jsarray (reference to array of categories used to create Javascript arrays for
8828: Domain Coordinator interface for editing Course Categories).
8829:
8830: Returns: nothing
8831:
8832: Side effects: populates cats, idx and jsarray.
8833:
8834: =cut
8835:
8836: sub gather_categories {
8837: my ($categories,$cats,$idx,$jsarray) = @_;
8838: my %counters;
8839: my $num = 0;
8840: foreach my $item (keys(%{$categories})) {
8841: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
8842: if ($container eq '' && $depth == 0) {
8843: $cats->[$depth][$categories->{$item}] = $cat;
8844: } else {
8845: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
8846: }
8847: my ($escitem,$tail) = split(/:/,$item,2);
8848: if ($counters{$tail} eq '') {
8849: $counters{$tail} = $num;
8850: $num ++;
8851: }
8852: if (ref($idx) eq 'HASH') {
8853: $idx->{$item} = $counters{$tail};
8854: }
8855: if (ref($jsarray) eq 'ARRAY') {
8856: push(@{$jsarray->[$counters{$tail}]},$item);
8857: }
8858: }
8859: return;
8860: }
8861:
8862: =pod
8863:
8864: =item * &extract_categories()
8865:
8866: Used to generate breadcrumb trails for course categories.
8867:
8868: Inputs:
8869:
8870: categories (reference to hash of category definitions).
8871:
8872: cats (reference to array of arrays/hashes which encapsulates hierarchy of
8873: categories and subcategories).
8874:
8875: trails (reference to array of breacrumb trails for each category).
8876:
8877: allitems (reference to hash - key is category key
8878: (format: escaped(name):escaped(parent category):depth in hierarchy).
8879:
8880: idx (reference to hash of counters used in Domain Coordinator interface for
8881: editing Course Categories).
8882:
8883: jsarray (reference to array of categories used to create Javascript arrays for
8884: Domain Coordinator interface for editing Course Categories).
8885:
8886: subcats (reference to hash of arrays containing all subcategories within each
8887: category, -recursive)
8888:
8889: Returns: nothing
8890:
8891: Side effects: populates trails and allitems hash references.
8892:
8893: =cut
8894:
8895: sub extract_categories {
8896: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
8897: if (ref($categories) eq 'HASH') {
8898: &gather_categories($categories,$cats,$idx,$jsarray);
8899: if (ref($cats->[0]) eq 'ARRAY') {
8900: for (my $i=0; $i<@{$cats->[0]}; $i++) {
8901: my $name = $cats->[0][$i];
8902: my $item = &escape($name).'::0';
8903: my $trailstr;
8904: if ($name eq 'instcode') {
8905: $trailstr = &mt('Official courses (with institutional codes)');
8906: } else {
8907: $trailstr = $name;
8908: }
8909: if ($allitems->{$item} eq '') {
8910: push(@{$trails},$trailstr);
8911: $allitems->{$item} = scalar(@{$trails})-1;
8912: }
8913: my @parents = ($name);
8914: if (ref($cats->[1]{$name}) eq 'ARRAY') {
8915: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
8916: my $category = $cats->[1]{$name}[$j];
8917: if (ref($subcats) eq 'HASH') {
8918: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
8919: }
8920: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
8921: }
8922: } else {
8923: if (ref($subcats) eq 'HASH') {
8924: $subcats->{$item} = [];
8925: }
8926: }
8927: }
8928: }
8929: }
8930: return;
8931: }
8932:
8933: =pod
8934:
8935: =item *&recurse_categories()
8936:
8937: Recursively used to generate breadcrumb trails for course categories.
8938:
8939: Inputs:
8940:
8941: cats (reference to array of arrays/hashes which encapsulates hierarchy of
8942: categories and subcategories).
8943:
8944: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
8945:
8946: category (current course category, for which breadcrumb trail is being generated).
8947:
8948: trails (reference to array of breadcrumb trails for each category).
8949:
8950: allitems (reference to hash - key is category key
8951: (format: escaped(name):escaped(parent category):depth in hierarchy).
8952:
8953: parents (array containing containers directories for current category,
8954: back to top level).
8955:
8956: Returns: nothing
8957:
8958: Side effects: populates trails and allitems hash references
8959:
8960: =cut
8961:
8962: sub recurse_categories {
8963: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
8964: my $shallower = $depth - 1;
8965: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
8966: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
8967: my $name = $cats->[$depth]{$category}[$k];
8968: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
8969: my $trailstr = join(' -> ',(@{$parents},$category));
8970: if ($allitems->{$item} eq '') {
8971: push(@{$trails},$trailstr);
8972: $allitems->{$item} = scalar(@{$trails})-1;
8973: }
8974: my $deeper = $depth+1;
8975: push(@{$parents},$category);
8976: if (ref($subcats) eq 'HASH') {
8977: my $subcat = &escape($name).':'.$category.':'.$depth;
8978: for (my $j=@{$parents}; $j>=0; $j--) {
8979: my $higher;
8980: if ($j > 0) {
8981: $higher = &escape($parents->[$j]).':'.
8982: &escape($parents->[$j-1]).':'.$j;
8983: } else {
8984: $higher = &escape($parents->[$j]).'::'.$j;
8985: }
8986: push(@{$subcats->{$higher}},$subcat);
8987: }
8988: }
8989: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
8990: $subcats);
8991: pop(@{$parents});
8992: }
8993: } else {
8994: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
8995: my $trailstr = join(' -> ',(@{$parents},$category));
8996: if ($allitems->{$item} eq '') {
8997: push(@{$trails},$trailstr);
8998: $allitems->{$item} = scalar(@{$trails})-1;
8999: }
9000: }
9001: return;
9002: }
9003:
9004: =pod
9005:
9006: =item *&assign_categories_table()
9007:
9008: Create a datatable for display of hierarchical categories in a domain,
9009: with checkboxes to allow a course to be categorized.
9010:
9011: Inputs:
9012:
9013: cathash - reference to hash of categories defined for the domain (from
9014: configuration.db)
9015:
9016: currcat - scalar with an & separated list of categories assigned to a course.
9017:
9018: Returns: $output (markup to be displayed)
9019:
9020: =cut
9021:
9022: sub assign_categories_table {
9023: my ($cathash,$currcat) = @_;
9024: my $output;
9025: if (ref($cathash) eq 'HASH') {
9026: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
9027: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
9028: $maxdepth = scalar(@cats);
9029: if (@cats > 0) {
9030: my $itemcount = 0;
9031: if (ref($cats[0]) eq 'ARRAY') {
9032: $output = &Apache::loncommon::start_data_table();
9033: my @currcategories;
9034: if ($currcat ne '') {
9035: @currcategories = split('&',$currcat);
9036: }
9037: for (my $i=0; $i<@{$cats[0]}; $i++) {
9038: my $parent = $cats[0][$i];
9039: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9040: next if ($parent eq 'instcode');
9041: my $item = &escape($parent).'::0';
9042: my $checked = '';
9043: if (@currcategories > 0) {
9044: if (grep(/^\Q$item\E$/,@currcategories)) {
9045: $checked = ' checked="checked" ';
9046: }
9047: }
9048: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
9049: '<input type="checkbox" name="usecategory" value="'.
9050: $item.'"'.$checked.' />'.$parent.'</span>'.
9051: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
9052: my $depth = 1;
9053: push(@path,$parent);
9054: $output .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
9055: pop(@path);
9056: $output .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
9057: $itemcount ++;
9058: }
9059: $output .= &Apache::loncommon::end_data_table();
9060: }
9061: }
9062: }
9063: return $output;
9064: }
9065:
9066: =pod
9067:
9068: =item *&assign_category_rows()
9069:
9070: Create a datatable row for display of nested categories in a domain,
9071: with checkboxes to allow a course to be categorized,called recursively.
9072:
9073: Inputs:
9074:
9075: itemcount - track row number for alternating colors
9076:
9077: cats - reference to array of arrays/hashes which encapsulates hierarchy of
9078: categories and subcategories.
9079:
9080: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
9081:
9082: parent - parent of current category item
9083:
9084: path - Array containing all categories back up through the hierarchy from the
9085: current category to the top level.
9086:
9087: currcategories - reference to array of current categories assigned to the course
9088:
9089: Returns: $output (markup to be displayed).
9090:
9091: =cut
9092:
9093: sub assign_category_rows {
9094: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
9095: my ($text,$name,$item,$chgstr);
9096: if (ref($cats) eq 'ARRAY') {
9097: my $maxdepth = scalar(@{$cats});
9098: if (ref($cats->[$depth]) eq 'HASH') {
9099: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
9100: my $numchildren = @{$cats->[$depth]{$parent}};
9101: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9102: $text .= '<td><table class="LC_datatable">';
9103: for (my $j=0; $j<$numchildren; $j++) {
9104: $name = $cats->[$depth]{$parent}[$j];
9105: $item = &escape($name).':'.&escape($parent).':'.$depth;
9106: my $deeper = $depth+1;
9107: my $checked = '';
9108: if (ref($currcategories) eq 'ARRAY') {
9109: if (@{$currcategories} > 0) {
9110: if (grep(/^\Q$item\E$/,@{$currcategories})) {
9111: $checked = ' checked="checked" ';
9112: }
9113: }
9114: }
9115: $text .= '<tr><td><span class="LC_nobreak"><label>'.
9116: '<input type="checkbox" name="usecategory" value="'.
9117: $item.'"'.$checked.' />'.$name.'</label></span>'.
9118: '<input type="hidden" name="catname" value="'.$name.'" />'.
9119: '</td><td>';
9120: if (ref($path) eq 'ARRAY') {
9121: push(@{$path},$name);
9122: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
9123: pop(@{$path});
9124: }
9125: $text .= '</td></tr>';
9126: }
9127: $text .= '</table></td>';
9128: }
9129: }
9130: }
9131: return $text;
9132: }
9133:
9134: ############################################################
9135: ############################################################
9136:
9137:
9138: sub commit_customrole {
9139: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
9140: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
9141: ($start?', '.&mt('starting').' '.localtime($start):'').
9142: ($end?', ending '.localtime($end):'').': <b>'.
9143: &Apache::lonnet::assigncustomrole(
9144: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
9145: '</b><br />';
9146: return $output;
9147: }
9148:
9149: sub commit_standardrole {
9150: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
9151: my ($output,$logmsg,$linefeed);
9152: if ($context eq 'auto') {
9153: $linefeed = "\n";
9154: } else {
9155: $linefeed = "<br />\n";
9156: }
9157: if ($three eq 'st') {
9158: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
9159: $one,$two,$sec,$context);
9160: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
9161: ($result eq 'unknown_course') || ($result eq 'refused')) {
9162: $output = $logmsg.' '.&mt('Error: ').$result."\n";
9163: } else {
9164: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
9165: ($start?', '.&mt('starting').' '.localtime($start):'').
9166: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
9167: if ($context eq 'auto') {
9168: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
9169: } else {
9170: $output .= '<b>'.$result.'</b>'.$linefeed.
9171: &mt('Add to classlist').': <b>ok</b>';
9172: }
9173: $output .= $linefeed;
9174: }
9175: } else {
9176: $output = &mt('Assigning').' '.$three.' in '.$url.
9177: ($start?', '.&mt('starting').' '.localtime($start):'').
9178: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
9179: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
9180: if ($context eq 'auto') {
9181: $output .= $result.$linefeed;
9182: } else {
9183: $output .= '<b>'.$result.'</b>'.$linefeed;
9184: }
9185: }
9186: return $output;
9187: }
9188:
9189: sub commit_studentrole {
9190: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
9191: my ($result,$linefeed,$oldsecurl,$newsecurl);
9192: if ($context eq 'auto') {
9193: $linefeed = "\n";
9194: } else {
9195: $linefeed = '<br />'."\n";
9196: }
9197: if (defined($one) && defined($two)) {
9198: my $cid=$one.'_'.$two;
9199: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
9200: my $secchange = 0;
9201: my $expire_role_result;
9202: my $modify_section_result;
9203: if ($oldsec ne '-1') {
9204: if ($oldsec ne $sec) {
9205: $secchange = 1;
9206: my $now = time;
9207: my $uurl='/'.$cid;
9208: $uurl=~s/\_/\//g;
9209: if ($oldsec) {
9210: $uurl.='/'.$oldsec;
9211: }
9212: $oldsecurl = $uurl;
9213: $expire_role_result =
9214: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
9215: if ($env{'request.course.sec'} ne '') {
9216: if ($expire_role_result eq 'refused') {
9217: my @roles = ('st');
9218: my @statuses = ('previous');
9219: my @roledoms = ($one);
9220: my $withsec = 1;
9221: my %roleshash =
9222: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
9223: \@statuses,\@roles,\@roledoms,$withsec);
9224: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
9225: my ($oldstart,$oldend) =
9226: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
9227: if ($oldend > 0 && $oldend <= $now) {
9228: $expire_role_result = 'ok';
9229: }
9230: }
9231: }
9232: }
9233: $result = $expire_role_result;
9234: }
9235: }
9236: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
9237: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
9238: if ($modify_section_result =~ /^ok/) {
9239: if ($secchange == 1) {
9240: if ($sec eq '') {
9241: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
9242: } else {
9243: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
9244: }
9245: } elsif ($oldsec eq '-1') {
9246: if ($sec eq '') {
9247: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
9248: } else {
9249: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9250: }
9251: } else {
9252: if ($sec eq '') {
9253: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
9254: } else {
9255: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9256: }
9257: }
9258: } else {
9259: if ($secchange) {
9260: $$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;
9261: } else {
9262: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
9263: }
9264: }
9265: $result = $modify_section_result;
9266: } elsif ($secchange == 1) {
9267: if ($oldsec eq '') {
9268: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
9269: } else {
9270: $$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;
9271: }
9272: if ($expire_role_result eq 'refused') {
9273: my $newsecurl = '/'.$cid;
9274: $newsecurl =~ s/\_/\//g;
9275: if ($sec ne '') {
9276: $newsecurl.='/'.$sec;
9277: }
9278: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
9279: if ($sec eq '') {
9280: $$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;
9281: } else {
9282: $$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;
9283: }
9284: }
9285: }
9286: }
9287: } else {
9288: $$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;
9289: $result = "error: incomplete course id\n";
9290: }
9291: return $result;
9292: }
9293:
9294: ############################################################
9295: ############################################################
9296:
9297: sub check_clone {
9298: my ($args,$linefeed) = @_;
9299: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
9300: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
9301: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
9302: my $clonemsg;
9303: my $can_clone = 0;
9304:
9305: if ($clonehome eq 'no_host') {
9306: $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'});
9307: } else {
9308: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
9309: if ($env{'request.role.domain'} eq $args->{'clonedomain'}) {
9310: $can_clone = 1;
9311: } else {
9312: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
9313: $args->{'clonedomain'},$args->{'clonecourse'});
9314: my @cloners = split(/,/,$clonehash{'cloners'});
9315: if (grep(/^\*$/,@cloners)) {
9316: $can_clone = 1;
9317: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
9318: $can_clone = 1;
9319: } else {
9320: my %roleshash =
9321: &Apache::lonnet::get_my_roles($args->{'ccuname'},
9322: $args->{'ccdomain'},
9323: 'userroles',['active'],['cc'],
9324: [$args->{'clonedomain'}]);
9325: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
9326: $can_clone = 1;
9327: } else {
9328: $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'});
9329: }
9330: }
9331: }
9332: }
9333: return ($can_clone, $clonemsg, $cloneid, $clonehome);
9334: }
9335:
9336: sub construct_course {
9337: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context) = @_;
9338: my $outcome;
9339: my $linefeed = '<br />'."\n";
9340: if ($context eq 'auto') {
9341: $linefeed = "\n";
9342: }
9343:
9344: #
9345: # Are we cloning?
9346: #
9347: my ($can_clone, $clonemsg, $cloneid, $clonehome);
9348: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
9349: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
9350: if ($context ne 'auto') {
9351: if ($clonemsg ne '') {
9352: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
9353: }
9354: }
9355: $outcome .= $clonemsg.$linefeed;
9356:
9357: if (!$can_clone) {
9358: return (0,$outcome);
9359: }
9360: }
9361:
9362: #
9363: # Open course
9364: #
9365: my $crstype = lc($args->{'crstype'});
9366: my %cenv=();
9367: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
9368: $args->{'cdescr'},
9369: $args->{'curl'},
9370: $args->{'course_home'},
9371: $args->{'nonstandard'},
9372: $args->{'crscode'},
9373: $args->{'ccuname'}.':'.
9374: $args->{'ccdomain'},
9375: $args->{'crstype'});
9376:
9377: # Note: The testing routines depend on this being output; see
9378: # Utils::Course. This needs to at least be output as a comment
9379: # if anyone ever decides to not show this, and Utils::Course::new
9380: # will need to be suitably modified.
9381: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
9382: #
9383: # Check if created correctly
9384: #
9385: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
9386: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
9387: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
9388:
9389: #
9390: # Do the cloning
9391: #
9392: if ($can_clone && $cloneid) {
9393: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
9394: if ($context ne 'auto') {
9395: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
9396: }
9397: $outcome .= $clonemsg.$linefeed;
9398: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
9399: # Copy all files
9400: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
9401: # Restore URL
9402: $cenv{'url'}=$oldcenv{'url'};
9403: # Restore title
9404: $cenv{'description'}=$oldcenv{'description'};
9405: # Mark as cloned
9406: $cenv{'clonedfrom'}=$cloneid;
9407: # Need to clone grading mode
9408: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
9409: $cenv{'grading'}=$newenv{'grading'};
9410: # Do not clone these environment entries
9411: &Apache::lonnet::del('environment',
9412: ['default_enrollment_start_date',
9413: 'default_enrollment_end_date',
9414: 'question.email',
9415: 'policy.email',
9416: 'comment.email',
9417: 'pch.users.denied',
9418: 'plc.users.denied',
9419: 'hidefromcat',
9420: 'categories'],
9421: $$crsudom,$$crsunum);
9422: }
9423:
9424: #
9425: # Set environment (will override cloned, if existing)
9426: #
9427: my @sections = ();
9428: my @xlists = ();
9429: if ($args->{'crstype'}) {
9430: $cenv{'type'}=$args->{'crstype'};
9431: }
9432: if ($args->{'crsid'}) {
9433: $cenv{'courseid'}=$args->{'crsid'};
9434: }
9435: if ($args->{'crscode'}) {
9436: $cenv{'internal.coursecode'}=$args->{'crscode'};
9437: }
9438: if ($args->{'crsquota'} ne '') {
9439: $cenv{'internal.coursequota'}=$args->{'crsquota'};
9440: } else {
9441: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
9442: }
9443: if ($args->{'ccuname'}) {
9444: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
9445: ':'.$args->{'ccdomain'};
9446: } else {
9447: $cenv{'internal.courseowner'} = $args->{'curruser'};
9448: }
9449: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
9450: if ($args->{'crssections'}) {
9451: $cenv{'internal.sectionnums'} = '';
9452: if ($args->{'crssections'} =~ m/,/) {
9453: @sections = split/,/,$args->{'crssections'};
9454: } else {
9455: $sections[0] = $args->{'crssections'};
9456: }
9457: if (@sections > 0) {
9458: foreach my $item (@sections) {
9459: my ($sec,$gp) = split/:/,$item;
9460: my $class = $args->{'crscode'}.$sec;
9461: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
9462: $cenv{'internal.sectionnums'} .= $item.',';
9463: unless ($addcheck eq 'ok') {
9464: push @badclasses, $class;
9465: }
9466: }
9467: $cenv{'internal.sectionnums'} =~ s/,$//;
9468: }
9469: }
9470: # do not hide course coordinator from staff listing,
9471: # even if privileged
9472: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9473: # add crosslistings
9474: if ($args->{'crsxlist'}) {
9475: $cenv{'internal.crosslistings'}='';
9476: if ($args->{'crsxlist'} =~ m/,/) {
9477: @xlists = split/,/,$args->{'crsxlist'};
9478: } else {
9479: $xlists[0] = $args->{'crsxlist'};
9480: }
9481: if (@xlists > 0) {
9482: foreach my $item (@xlists) {
9483: my ($xl,$gp) = split/:/,$item;
9484: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
9485: $cenv{'internal.crosslistings'} .= $item.',';
9486: unless ($addcheck eq 'ok') {
9487: push @badclasses, $xl;
9488: }
9489: }
9490: $cenv{'internal.crosslistings'} =~ s/,$//;
9491: }
9492: }
9493: if ($args->{'autoadds'}) {
9494: $cenv{'internal.autoadds'}=$args->{'autoadds'};
9495: }
9496: if ($args->{'autodrops'}) {
9497: $cenv{'internal.autodrops'}=$args->{'autodrops'};
9498: }
9499: # check for notification of enrollment changes
9500: my @notified = ();
9501: if ($args->{'notify_owner'}) {
9502: if ($args->{'ccuname'} ne '') {
9503: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
9504: }
9505: }
9506: if ($args->{'notify_dc'}) {
9507: if ($uname ne '') {
9508: push(@notified,$uname.':'.$udom);
9509: }
9510: }
9511: if (@notified > 0) {
9512: my $notifylist;
9513: if (@notified > 1) {
9514: $notifylist = join(',',@notified);
9515: } else {
9516: $notifylist = $notified[0];
9517: }
9518: $cenv{'internal.notifylist'} = $notifylist;
9519: }
9520: if (@badclasses > 0) {
9521: my %lt=&Apache::lonlocal::texthash(
9522: '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',
9523: 'dnhr' => 'does not have rights to access enrollment in these classes',
9524: 'adby' => 'as determined by the policies of your institution on access to official classlists'
9525: );
9526: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
9527: ' ('.$lt{'adby'}.')';
9528: if ($context eq 'auto') {
9529: $outcome .= $badclass_msg.$linefeed;
9530: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
9531: foreach my $item (@badclasses) {
9532: if ($context eq 'auto') {
9533: $outcome .= " - $item\n";
9534: } else {
9535: $outcome .= "<li>$item</li>\n";
9536: }
9537: }
9538: if ($context eq 'auto') {
9539: $outcome .= $linefeed;
9540: } else {
9541: $outcome .= "</ul><br /><br /></div>\n";
9542: }
9543: }
9544: }
9545: if ($args->{'no_end_date'}) {
9546: $args->{'endaccess'} = 0;
9547: }
9548: $cenv{'internal.autostart'}=$args->{'enrollstart'};
9549: $cenv{'internal.autoend'}=$args->{'enrollend'};
9550: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
9551: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
9552: if ($args->{'showphotos'}) {
9553: $cenv{'internal.showphotos'}=$args->{'showphotos'};
9554: }
9555: $cenv{'internal.authtype'} = $args->{'authtype'};
9556: $cenv{'internal.autharg'} = $args->{'autharg'};
9557: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
9558: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
9559: 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');
9560: if ($context eq 'auto') {
9561: $outcome .= $krb_msg;
9562: } else {
9563: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
9564: }
9565: $outcome .= $linefeed;
9566: }
9567: }
9568: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
9569: if ($args->{'setpolicy'}) {
9570: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9571: }
9572: if ($args->{'setcontent'}) {
9573: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9574: }
9575: }
9576: if ($args->{'reshome'}) {
9577: $cenv{'reshome'}=$args->{'reshome'}.'/';
9578: $cenv{'reshome'}=~s/\/+$/\//;
9579: }
9580: #
9581: # course has keyed access
9582: #
9583: if ($args->{'setkeys'}) {
9584: $cenv{'keyaccess'}='yes';
9585: }
9586: # if specified, key authority is not course, but user
9587: # only active if keyaccess is yes
9588: if ($args->{'keyauth'}) {
9589: my ($user,$domain) = split(':',$args->{'keyauth'});
9590: $user = &LONCAPA::clean_username($user);
9591: $domain = &LONCAPA::clean_username($domain);
9592: if ($user ne '' && $domain ne '') {
9593: $cenv{'keyauth'}=$user.':'.$domain;
9594: }
9595: }
9596:
9597: if ($args->{'disresdis'}) {
9598: $cenv{'pch.roles.denied'}='st';
9599: }
9600: if ($args->{'disablechat'}) {
9601: $cenv{'plc.roles.denied'}='st';
9602: }
9603:
9604: # Record we've not yet viewed the Course Initialization Helper for this
9605: # course
9606: $cenv{'course.helper.not.run'} = 1;
9607: #
9608: # Use new Randomseed
9609: #
9610: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
9611: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
9612: #
9613: # The encryption code and receipt prefix for this course
9614: #
9615: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
9616: $cenv{'internal.encpref'}=100+int(9*rand(99));
9617: #
9618: # By default, use standard grading
9619: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
9620:
9621: $outcome .= $linefeed.&mt('Setting environment').': '.
9622: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
9623: #
9624: # Open all assignments
9625: #
9626: if ($args->{'openall'}) {
9627: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
9628: my %storecontent = ($storeunder => time,
9629: $storeunder.'.type' => 'date_start');
9630:
9631: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
9632: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
9633: }
9634: #
9635: # Set first page
9636: #
9637: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
9638: || ($cloneid)) {
9639: use LONCAPA::map;
9640: $outcome .= &mt('Setting first resource').': ';
9641:
9642: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
9643: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
9644:
9645: $outcome .= ($fatal?$errtext:'read ok').' - ';
9646: my $title; my $url;
9647: if ($args->{'firstres'} eq 'syl') {
9648: $title=&mt('Syllabus');
9649: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
9650: } else {
9651: $title=&mt('Navigate Contents');
9652: $url='/adm/navmaps';
9653: }
9654:
9655: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
9656: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
9657:
9658: if ($errtext) { $fatal=2; }
9659: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
9660: }
9661:
9662: return (1,$outcome);
9663: }
9664:
9665: ############################################################
9666: ############################################################
9667:
9668: sub course_type {
9669: my ($cid) = @_;
9670: if (!defined($cid)) {
9671: $cid = $env{'request.course.id'};
9672: }
9673: if (defined($env{'course.'.$cid.'.type'})) {
9674: return $env{'course.'.$cid.'.type'};
9675: } else {
9676: return 'Course';
9677: }
9678: }
9679:
9680: sub group_term {
9681: my $crstype = &course_type();
9682: my %names = (
9683: 'Course' => 'group',
9684: 'Group' => 'team',
9685: );
9686: return $names{$crstype};
9687: }
9688:
9689: sub icon {
9690: my ($file)=@_;
9691: my $curfext = lc((split(/\./,$file))[-1]);
9692: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
9693: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
9694: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
9695: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
9696: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
9697: $curfext.".gif") {
9698: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
9699: $curfext.".gif";
9700: }
9701: }
9702: return &lonhttpdurl($iconname);
9703: }
9704:
9705: sub lonhttpdurl {
9706: #
9707: # Had been used for "small fry" static images on separate port 8080.
9708: # Modify here if lightweight http functionality desired again.
9709: # Currently eliminated due to increasing firewall issues.
9710: #
9711: my ($url)=@_;
9712: return $url;
9713: }
9714:
9715: sub connection_aborted {
9716: my ($r)=@_;
9717: $r->print(" ");$r->rflush();
9718: my $c = $r->connection;
9719: return $c->aborted();
9720: }
9721:
9722: # Escapes strings that may have embedded 's that will be put into
9723: # strings as 'strings'.
9724: sub escape_single {
9725: my ($input) = @_;
9726: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
9727: $input =~ s/\'/\\\'/g; # Esacpe the 's....
9728: return $input;
9729: }
9730:
9731: # Same as escape_single, but escape's "'s This
9732: # can be used for "strings"
9733: sub escape_double {
9734: my ($input) = @_;
9735: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
9736: $input =~ s/\"/\\\"/g; # Esacpe the "s....
9737: return $input;
9738: }
9739:
9740: # Escapes the last element of a full URL.
9741: sub escape_url {
9742: my ($url) = @_;
9743: my @urlslices = split(/\//, $url,-1);
9744: my $lastitem = &escape(pop(@urlslices));
9745: return join('/',@urlslices).'/'.$lastitem;
9746: }
9747:
9748: # -------------------------------------------------------- Initliaze user login
9749: sub init_user_environment {
9750: my ($r, $username, $domain, $authhost, $form, $args) = @_;
9751: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
9752:
9753: my $public=($username eq 'public' && $domain eq 'public');
9754:
9755: # See if old ID present, if so, remove
9756:
9757: my ($filename,$cookie,$userroles);
9758: my $now=time;
9759:
9760: if ($public) {
9761: my $max_public=100;
9762: my $oldest;
9763: my $oldest_time=0;
9764: for(my $next=1;$next<=$max_public;$next++) {
9765: if (-e $lonids."/publicuser_$next.id") {
9766: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
9767: if ($mtime<$oldest_time || !$oldest_time) {
9768: $oldest_time=$mtime;
9769: $oldest=$next;
9770: }
9771: } else {
9772: $cookie="publicuser_$next";
9773: last;
9774: }
9775: }
9776: if (!$cookie) { $cookie="publicuser_$oldest"; }
9777: } else {
9778: # if this isn't a robot, kill any existing non-robot sessions
9779: if (!$args->{'robot'}) {
9780: opendir(DIR,$lonids);
9781: while ($filename=readdir(DIR)) {
9782: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
9783: unlink($lonids.'/'.$filename);
9784: }
9785: }
9786: closedir(DIR);
9787: }
9788: # Give them a new cookie
9789: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
9790: : $now.$$.int(rand(10000)));
9791: $cookie="$username\_$id\_$domain\_$authhost";
9792:
9793: # Initialize roles
9794:
9795: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
9796: }
9797: # ------------------------------------ Check browser type and MathML capability
9798:
9799: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
9800: $clientunicode,$clientos) = &decode_user_agent($r);
9801:
9802: # -------------------------------------- Any accessibility options to remember?
9803: if (($form->{'interface'}) && ($form->{'remember'} eq 'true')) {
9804: foreach my $option ('imagesuppress','appletsuppress',
9805: 'embedsuppress','fontenhance','blackwhite') {
9806: if ($form->{$option} eq 'true') {
9807: &Apache::lonnet::put('environment',{$option => 'on'},
9808: $domain,$username);
9809: } else {
9810: &Apache::lonnet::del('environment',[$option],
9811: $domain,$username);
9812: }
9813: }
9814: }
9815: # ------------------------------------------------------------- Get environment
9816:
9817: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
9818: my ($tmp) = keys(%userenv);
9819: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9820: # default remote control to off
9821: if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
9822: } else {
9823: undef(%userenv);
9824: }
9825: if (($userenv{'interface'}) && (!$form->{'interface'})) {
9826: $form->{'interface'}=$userenv{'interface'};
9827: }
9828: $env{'environment.remote'}=$userenv{'remote'};
9829: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
9830:
9831: # --------------- Do not trust query string to be put directly into environment
9832: foreach my $option ('imagesuppress','appletsuppress',
9833: 'embedsuppress','fontenhance','blackwhite',
9834: 'interface','localpath','localres') {
9835: $form->{$option}=~s/[\n\r\=]//gs;
9836: }
9837: # --------------------------------------------------------- Write first profile
9838:
9839: {
9840: my %initial_env =
9841: ("user.name" => $username,
9842: "user.domain" => $domain,
9843: "user.home" => $authhost,
9844: "browser.type" => $clientbrowser,
9845: "browser.version" => $clientversion,
9846: "browser.mathml" => $clientmathml,
9847: "browser.unicode" => $clientunicode,
9848: "browser.os" => $clientos,
9849: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
9850: "request.course.fn" => '',
9851: "request.course.uri" => '',
9852: "request.course.sec" => '',
9853: "request.role" => 'cm',
9854: "request.role.adv" => $env{'user.adv'},
9855: "request.host" => $ENV{'REMOTE_ADDR'},);
9856:
9857: if ($form->{'localpath'}) {
9858: $initial_env{"browser.localpath"} = $form->{'localpath'};
9859: $initial_env{"browser.localres"} = $form->{'localres'};
9860: }
9861:
9862: if ($public) {
9863: $initial_env{"environment.remote"} = "off";
9864: }
9865: if ($form->{'interface'}) {
9866: $form->{'interface'}=~s/\W//gs;
9867: $initial_env{"browser.interface"} = $form->{'interface'};
9868: $env{'browser.interface'}=$form->{'interface'};
9869: foreach my $option ('imagesuppress','appletsuppress',
9870: 'embedsuppress','fontenhance','blackwhite') {
9871: if (($form->{$option} eq 'true') ||
9872: ($userenv{$option} eq 'on')) {
9873: $initial_env{"browser.$option"} = "on";
9874: }
9875: }
9876: }
9877:
9878: foreach my $tool ('aboutme','blog','portfolio') {
9879: $userenv{'availabletools.'.$tool} =
9880: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload');
9881: }
9882:
9883: $env{'user.environment'} = "$lonids/$cookie.id";
9884:
9885: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
9886: &GDBM_WRCREAT(),0640)) {
9887: &_add_to_env(\%disk_env,\%initial_env);
9888: &_add_to_env(\%disk_env,\%userenv,'environment.');
9889: &_add_to_env(\%disk_env,$userroles);
9890: if (ref($args->{'extra_env'})) {
9891: &_add_to_env(\%disk_env,$args->{'extra_env'});
9892: }
9893: untie(%disk_env);
9894: } else {
9895: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
9896: 'Could not create environment storage in lonauth: '.$!.'</span>');
9897: return 'error: '.$!;
9898: }
9899: }
9900: $env{'request.role'}='cm';
9901: $env{'request.role.adv'}=$env{'user.adv'};
9902: $env{'browser.type'}=$clientbrowser;
9903:
9904: return $cookie;
9905:
9906: }
9907:
9908: sub _add_to_env {
9909: my ($idf,$env_data,$prefix) = @_;
9910: if (ref($env_data) eq 'HASH') {
9911: while (my ($key,$value) = each(%$env_data)) {
9912: $idf->{$prefix.$key} = $value;
9913: $env{$prefix.$key} = $value;
9914: }
9915: }
9916: }
9917:
9918: # --- Get the symbolic name of a problem and the url
9919: sub get_symb {
9920: my ($request,$silent) = @_;
9921: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
9922: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
9923: if ($symb eq '') {
9924: if (!$silent) {
9925: $request->print("Unable to handle ambiguous references:$url:.");
9926: return ();
9927: }
9928: }
9929: &Apache::lonenc::check_decrypt(\$symb);
9930: return ($symb);
9931: }
9932:
9933: # --------------------------------------------------------------Get annotation
9934:
9935: sub get_annotation {
9936: my ($symb,$enc) = @_;
9937:
9938: my $key = $symb;
9939: if (!$enc) {
9940: $key =
9941: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
9942: }
9943: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
9944: return $annotation{$key};
9945: }
9946:
9947: sub clean_symb {
9948: my ($symb,$delete_enc) = @_;
9949:
9950: &Apache::lonenc::check_decrypt(\$symb);
9951: my $enc = $env{'request.enc'};
9952: if ($delete_enc) {
9953: delete($env{'request.enc'});
9954: }
9955:
9956: return ($symb,$enc);
9957: }
9958:
9959: =pod
9960:
9961: =back
9962:
9963: =cut
9964:
9965: 1;
9966: __END__;
9967:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>