File:
[LON-CAPA] /
loncom /
interface /
loncommon.pm
Revision
1.743:
download - view:
text,
annotated -
select for diffs
Sat Feb 7 20:45:27 2009 UTC (15 years, 6 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
loncommon.pm:
&select_dom_form() takes a fifth argument - $autosubmit. If this is true, the domain selector includes an onchange action which will submit the form containing it.
coursecatalog.pm:
Fifth argument (set to 1) passed to &Apache::loncommon::select_dom_form() unless
textual interface mode ("Change" button displayed in this case).
1: # The LearningOnline Network with CAPA
2: # a pile of common routines
3: #
4: # $Id: loncommon.pm,v 1.743 2009/02/07 20:45:27 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,$autosubmit)
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: If the $autosubmit flag is set, the form containing the domain selector will be auto-submitted by an onchange action.
1761:
1762: =cut
1763:
1764: #-------------------------------------------
1765: sub select_dom_form {
1766: my ($defdom,$name,$includeempty,$showdomdesc,$autosubmit) = @_;
1767: my $onchange;
1768: if ($autosubmit) {
1769: $onchange = ' onchange="this.form.submit()"';
1770: }
1771: my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1772: if ($includeempty) { @domains=('',@domains); }
1773: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1774: foreach my $dom (@domains) {
1775: $selectdomain.="<option value=\"$dom\" ".
1776: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
1777: if ($showdomdesc) {
1778: if ($dom ne '') {
1779: my $domdesc = &Apache::lonnet::domain($dom,'description');
1780: if ($domdesc ne '') {
1781: $selectdomain .= ' ('.$domdesc.')';
1782: }
1783: }
1784: }
1785: $selectdomain .= "</option>\n";
1786: }
1787: $selectdomain.="</select>";
1788: return $selectdomain;
1789: }
1790:
1791: #-------------------------------------------
1792:
1793: =pod
1794:
1795: =item * &home_server_form_item($domain,$name,$defaultflag)
1796:
1797: input: 4 arguments (two required, two optional) -
1798: $domain - domain of new user
1799: $name - name of form element
1800: $default - Value of 'default' causes a default item to be first
1801: option, and selected by default.
1802: $hide - Value of 'hide' causes hiding of the name of the server,
1803: if 1 server found, or default, if 0 found.
1804: output: returns 2 items:
1805: (a) form element which contains either:
1806: (i) <select name="$name">
1807: <option value="$hostid1">$hostid $servers{$hostid}</option>
1808: <option value="$hostid2">$hostid $servers{$hostid}</option>
1809: </select>
1810: form item if there are multiple library servers in $domain, or
1811: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
1812: if there is only one library server in $domain.
1813:
1814: (b) number of library servers found.
1815:
1816: See loncreateuser.pm for example of use.
1817:
1818: =cut
1819:
1820: #-------------------------------------------
1821: sub home_server_form_item {
1822: my ($domain,$name,$default,$hide) = @_;
1823: my %servers = &Apache::lonnet::get_servers($domain,'library');
1824: my $result;
1825: my $numlib = keys(%servers);
1826: if ($numlib > 1) {
1827: $result .= '<select name="'.$name.'" />'."\n";
1828: if ($default) {
1829: $result .= '<option value="default" selected>'.&mt('default').
1830: '</option>'."\n";
1831: }
1832: foreach my $hostid (sort(keys(%servers))) {
1833: $result.= '<option value="'.$hostid.'">'.
1834: $hostid.' '.$servers{$hostid}."</option>\n";
1835: }
1836: $result .= '</select>'."\n";
1837: } elsif ($numlib == 1) {
1838: my $hostid;
1839: foreach my $item (keys(%servers)) {
1840: $hostid = $item;
1841: }
1842: $result .= '<input type="hidden" name="'.$name.'" value="'.
1843: $hostid.'" />';
1844: if (!$hide) {
1845: $result .= $hostid.' '.$servers{$hostid};
1846: }
1847: $result .= "\n";
1848: } elsif ($default) {
1849: $result .= '<input type="hidden" name="'.$name.
1850: '" value="default" />';
1851: if (!$hide) {
1852: $result .= &mt('default');
1853: }
1854: $result .= "\n";
1855: }
1856: return ($result,$numlib);
1857: }
1858:
1859: =pod
1860:
1861: =back
1862:
1863: =cut
1864:
1865: ###############################################################
1866: ## Decoding User Agent ##
1867: ###############################################################
1868:
1869: =pod
1870:
1871: =head1 Decoding the User Agent
1872:
1873: =over 4
1874:
1875: =item * &decode_user_agent()
1876:
1877: Inputs: $r
1878:
1879: Outputs:
1880:
1881: =over 4
1882:
1883: =item * $httpbrowser
1884:
1885: =item * $clientbrowser
1886:
1887: =item * $clientversion
1888:
1889: =item * $clientmathml
1890:
1891: =item * $clientunicode
1892:
1893: =item * $clientos
1894:
1895: =back
1896:
1897: =back
1898:
1899: =cut
1900:
1901: ###############################################################
1902: ###############################################################
1903: sub decode_user_agent {
1904: my ($r)=@_;
1905: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
1906: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
1907: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1908: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1909: my $clientbrowser='unknown';
1910: my $clientversion='0';
1911: my $clientmathml='';
1912: my $clientunicode='0';
1913: for (my $i=0;$i<=$#browsertype;$i++) {
1914: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
1915: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
1916: $clientbrowser=$bname;
1917: $httpbrowser=~/$vreg/i;
1918: $clientversion=$1;
1919: $clientmathml=($clientversion>=$minv);
1920: $clientunicode=($clientversion>=$univ);
1921: }
1922: }
1923: my $clientos='unknown';
1924: if (($httpbrowser=~/linux/i) ||
1925: ($httpbrowser=~/unix/i) ||
1926: ($httpbrowser=~/ux/i) ||
1927: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
1928: if (($httpbrowser=~/vax/i) ||
1929: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
1930: if ($httpbrowser=~/next/i) { $clientos='next'; }
1931: if (($httpbrowser=~/mac/i) ||
1932: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1933: if ($httpbrowser=~/win/i) { $clientos='win'; }
1934: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1935: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1936: $clientunicode,$clientos,);
1937: }
1938:
1939: ###############################################################
1940: ## Authentication changing form generation subroutines ##
1941: ###############################################################
1942: ##
1943: ## All of the authform_xxxxxxx subroutines take their inputs in a
1944: ## hash, and have reasonable default values.
1945: ##
1946: ## formname = the name given in the <form> tag.
1947: #-------------------------------------------
1948:
1949: =pod
1950:
1951: =head1 Authentication Routines
1952:
1953: =over 4
1954:
1955: =item * &authform_xxxxxx()
1956:
1957: The authform_xxxxxx subroutines provide javascript and html forms which
1958: handle some of the conveniences required for authentication forms.
1959: This is not an optimal method, but it works.
1960:
1961: =over 4
1962:
1963: =item * authform_header
1964:
1965: =item * authform_authorwarning
1966:
1967: =item * authform_nochange
1968:
1969: =item * authform_kerberos
1970:
1971: =item * authform_internal
1972:
1973: =item * authform_filesystem
1974:
1975: =back
1976:
1977: See loncreateuser.pm for invocation and use examples.
1978:
1979: =cut
1980:
1981: #-------------------------------------------
1982: sub authform_header{
1983: my %in = (
1984: formname => 'cu',
1985: kerb_def_dom => '',
1986: @_,
1987: );
1988: $in{'formname'} = 'document.' . $in{'formname'};
1989: my $result='';
1990:
1991: #---------------------------------------------- Code for upper case translation
1992: my $Javascript_toUpperCase;
1993: unless ($in{kerb_def_dom}) {
1994: $Javascript_toUpperCase =<<"END";
1995: switch (choice) {
1996: case 'krb': currentform.elements[choicearg].value =
1997: currentform.elements[choicearg].value.toUpperCase();
1998: break;
1999: default:
2000: }
2001: END
2002: } else {
2003: $Javascript_toUpperCase = "";
2004: }
2005:
2006: my $radioval = "'nochange'";
2007: if (defined($in{'curr_authtype'})) {
2008: if ($in{'curr_authtype'} ne '') {
2009: $radioval = "'".$in{'curr_authtype'}."arg'";
2010: }
2011: }
2012: my $argfield = 'null';
2013: if (defined($in{'mode'})) {
2014: if ($in{'mode'} eq 'modifycourse') {
2015: if (defined($in{'curr_autharg'})) {
2016: if ($in{'curr_autharg'} ne '') {
2017: $argfield = "'$in{'curr_autharg'}'";
2018: }
2019: }
2020: }
2021: }
2022:
2023: $result.=<<"END";
2024: var current = new Object();
2025: current.radiovalue = $radioval;
2026: current.argfield = $argfield;
2027:
2028: function changed_radio(choice,currentform) {
2029: var choicearg = choice + 'arg';
2030: // If a radio button in changed, we need to change the argfield
2031: if (current.radiovalue != choice) {
2032: current.radiovalue = choice;
2033: if (current.argfield != null) {
2034: currentform.elements[current.argfield].value = '';
2035: }
2036: if (choice == 'nochange') {
2037: current.argfield = null;
2038: } else {
2039: current.argfield = choicearg;
2040: switch(choice) {
2041: case 'krb':
2042: currentform.elements[current.argfield].value =
2043: "$in{'kerb_def_dom'}";
2044: break;
2045: default:
2046: break;
2047: }
2048: }
2049: }
2050: return;
2051: }
2052:
2053: function changed_text(choice,currentform) {
2054: var choicearg = choice + 'arg';
2055: if (currentform.elements[choicearg].value !='') {
2056: $Javascript_toUpperCase
2057: // clear old field
2058: if ((current.argfield != choicearg) && (current.argfield != null)) {
2059: currentform.elements[current.argfield].value = '';
2060: }
2061: current.argfield = choicearg;
2062: }
2063: set_auth_radio_buttons(choice,currentform);
2064: return;
2065: }
2066:
2067: function set_auth_radio_buttons(newvalue,currentform) {
2068: var i=0;
2069: while (i < currentform.login.length) {
2070: if (currentform.login[i].value == newvalue) { break; }
2071: i++;
2072: }
2073: if (i == currentform.login.length) {
2074: return;
2075: }
2076: current.radiovalue = newvalue;
2077: currentform.login[i].checked = true;
2078: return;
2079: }
2080: END
2081: return $result;
2082: }
2083:
2084: sub authform_authorwarning{
2085: my $result='';
2086: $result='<i>'.
2087: &mt('As a general rule, only authors or co-authors should be '.
2088: 'filesystem authenticated '.
2089: '(which allows access to the server filesystem).')."</i>\n";
2090: return $result;
2091: }
2092:
2093: sub authform_nochange{
2094: my %in = (
2095: formname => 'document.cu',
2096: kerb_def_dom => 'MSU.EDU',
2097: @_,
2098: );
2099: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2100: my $result;
2101: if (keys(%can_assign) == 0) {
2102: $result = &mt('Under you current role you are not permitted to change login settings for this user');
2103: } else {
2104: $result = '<label>'.&mt('[_1] Do not change login data',
2105: '<input type="radio" name="login" value="nochange" '.
2106: 'checked="checked" onclick="'.
2107: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2108: '</label>';
2109: }
2110: return $result;
2111: }
2112:
2113: sub authform_kerberos {
2114: my %in = (
2115: formname => 'document.cu',
2116: kerb_def_dom => 'MSU.EDU',
2117: kerb_def_auth => 'krb4',
2118: @_,
2119: );
2120: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2121: $autharg,$jscall);
2122: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2123: if ($in{'kerb_def_auth'} eq 'krb5') {
2124: $check5 = ' checked="on"';
2125: } else {
2126: $check4 = ' checked="on"';
2127: }
2128: $krbarg = $in{'kerb_def_dom'};
2129: if (defined($in{'curr_authtype'})) {
2130: if ($in{'curr_authtype'} eq 'krb') {
2131: $krbcheck = ' checked="on"';
2132: if (defined($in{'mode'})) {
2133: if ($in{'mode'} eq 'modifyuser') {
2134: $krbcheck = '';
2135: }
2136: }
2137: if (defined($in{'curr_kerb_ver'})) {
2138: if ($in{'curr_krb_ver'} eq '5') {
2139: $check5 = ' checked="on"';
2140: $check4 = '';
2141: } else {
2142: $check4 = ' checked="on"';
2143: $check5 = '';
2144: }
2145: }
2146: if (defined($in{'curr_autharg'})) {
2147: $krbarg = $in{'curr_autharg'};
2148: }
2149: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2150: if (defined($in{'curr_autharg'})) {
2151: $result =
2152: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2153: $in{'curr_autharg'},$krbver);
2154: } else {
2155: $result =
2156: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2157: }
2158: return $result;
2159: }
2160: }
2161: } else {
2162: if ($authnum == 1) {
2163: $authtype = '<input type="hidden" name="login" value="krb">';
2164: }
2165: }
2166: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2167: return;
2168: } elsif ($authtype eq '') {
2169: if (defined($in{'mode'})) {
2170: if ($in{'mode'} eq 'modifycourse') {
2171: if ($authnum == 1) {
2172: $authtype = '<input type="hidden" name="login" value="krb">';
2173: }
2174: }
2175: }
2176: }
2177: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2178: if ($authtype eq '') {
2179: $authtype = '<input type="radio" name="login" value="krb" '.
2180: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2181: $krbcheck.' />';
2182: }
2183: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
2184: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
2185: $in{'curr_authtype'} eq 'krb5') ||
2186: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
2187: $in{'curr_authtype'} eq 'krb4')) {
2188: $result .= &mt
2189: ('[_1] Kerberos authenticated with domain [_2] '.
2190: '[_3] Version 4 [_4] Version 5 [_5]',
2191: '<label>'.$authtype,
2192: '</label><input type="text" size="10" name="krbarg" '.
2193: 'value="'.$krbarg.'" '.
2194: 'onchange="'.$jscall.'" />',
2195: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2196: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2197: '</label>');
2198: } elsif ($can_assign{'krb4'}) {
2199: $result .= &mt
2200: ('[_1] Kerberos authenticated with domain [_2] '.
2201: '[_3] Version 4 [_4]',
2202: '<label>'.$authtype,
2203: '</label><input type="text" size="10" name="krbarg" '.
2204: 'value="'.$krbarg.'" '.
2205: 'onchange="'.$jscall.'" />',
2206: '<label><input type="hidden" name="krbver" value="4" />',
2207: '</label>');
2208: } elsif ($can_assign{'krb5'}) {
2209: $result .= &mt
2210: ('[_1] Kerberos authenticated with domain [_2] '.
2211: '[_3] Version 5 [_4]',
2212: '<label>'.$authtype,
2213: '</label><input type="text" size="10" name="krbarg" '.
2214: 'value="'.$krbarg.'" '.
2215: 'onchange="'.$jscall.'" />',
2216: '<label><input type="hidden" name="krbver" value="5" />',
2217: '</label>');
2218: }
2219: return $result;
2220: }
2221:
2222: sub authform_internal{
2223: my %in = (
2224: formname => 'document.cu',
2225: kerb_def_dom => 'MSU.EDU',
2226: @_,
2227: );
2228: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
2229: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2230: if (defined($in{'curr_authtype'})) {
2231: if ($in{'curr_authtype'} eq 'int') {
2232: if ($can_assign{'int'}) {
2233: $intcheck = 'checked="on" ';
2234: if (defined($in{'mode'})) {
2235: if ($in{'mode'} eq 'modifyuser') {
2236: $intcheck = '';
2237: }
2238: }
2239: if (defined($in{'curr_autharg'})) {
2240: $intarg = $in{'curr_autharg'};
2241: }
2242: } else {
2243: $result = &mt('Currently internally authenticated.');
2244: return $result;
2245: }
2246: }
2247: } else {
2248: if ($authnum == 1) {
2249: $authtype = '<input type="hidden" name="login" value="int">';
2250: }
2251: }
2252: if (!$can_assign{'int'}) {
2253: return;
2254: } elsif ($authtype eq '') {
2255: if (defined($in{'mode'})) {
2256: if ($in{'mode'} eq 'modifycourse') {
2257: if ($authnum == 1) {
2258: $authtype = '<input type="hidden" name="login" value="int">';
2259: }
2260: }
2261: }
2262: }
2263: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2264: if ($authtype eq '') {
2265: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2266: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2267: }
2268: $autharg = '<input type="password" size="10" name="intarg" value="'.
2269: $intarg.'" onchange="'.$jscall.'" />';
2270: $result = &mt
2271: ('[_1] Internally authenticated (with initial password [_2])',
2272: '<label>'.$authtype,'</label>'.$autharg);
2273: $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>';
2274: return $result;
2275: }
2276:
2277: sub authform_local{
2278: my %in = (
2279: formname => 'document.cu',
2280: kerb_def_dom => 'MSU.EDU',
2281: @_,
2282: );
2283: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
2284: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2285: if (defined($in{'curr_authtype'})) {
2286: if ($in{'curr_authtype'} eq 'loc') {
2287: if ($can_assign{'loc'}) {
2288: $loccheck = 'checked="on" ';
2289: if (defined($in{'mode'})) {
2290: if ($in{'mode'} eq 'modifyuser') {
2291: $loccheck = '';
2292: }
2293: }
2294: if (defined($in{'curr_autharg'})) {
2295: $locarg = $in{'curr_autharg'};
2296: }
2297: } else {
2298: $result = &mt('Currently using local (institutional) authentication.');
2299: return $result;
2300: }
2301: }
2302: } else {
2303: if ($authnum == 1) {
2304: $authtype = '<input type="hidden" name="login" value="loc">';
2305: }
2306: }
2307: if (!$can_assign{'loc'}) {
2308: return;
2309: } elsif ($authtype eq '') {
2310: if (defined($in{'mode'})) {
2311: if ($in{'mode'} eq 'modifycourse') {
2312: if ($authnum == 1) {
2313: $authtype = '<input type="hidden" name="login" value="loc">';
2314: }
2315: }
2316: }
2317: }
2318: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2319: if ($authtype eq '') {
2320: $authtype = '<input type="radio" name="login" value="loc" '.
2321: $loccheck.' onchange="'.$jscall.'" onclick="'.
2322: $jscall.'" />';
2323: }
2324: $autharg = '<input type="text" size="10" name="locarg" value="'.
2325: $locarg.'" onchange="'.$jscall.'" />';
2326: $result = &mt('[_1] Local Authentication with argument [_2]',
2327: '<label>'.$authtype,'</label>'.$autharg);
2328: return $result;
2329: }
2330:
2331: sub authform_filesystem{
2332: my %in = (
2333: formname => 'document.cu',
2334: kerb_def_dom => 'MSU.EDU',
2335: @_,
2336: );
2337: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
2338: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2339: if (defined($in{'curr_authtype'})) {
2340: if ($in{'curr_authtype'} eq 'fsys') {
2341: if ($can_assign{'fsys'}) {
2342: $fsyscheck = 'checked="on" ';
2343: if (defined($in{'mode'})) {
2344: if ($in{'mode'} eq 'modifyuser') {
2345: $fsyscheck = '';
2346: }
2347: }
2348: } else {
2349: $result = &mt('Currently Filesystem Authenticated.');
2350: return $result;
2351: }
2352: }
2353: } else {
2354: if ($authnum == 1) {
2355: $authtype = '<input type="hidden" name="login" value="fsys">';
2356: }
2357: }
2358: if (!$can_assign{'fsys'}) {
2359: return;
2360: } elsif ($authtype eq '') {
2361: if (defined($in{'mode'})) {
2362: if ($in{'mode'} eq 'modifycourse') {
2363: if ($authnum == 1) {
2364: $authtype = '<input type="hidden" name="login" value="fsys">';
2365: }
2366: }
2367: }
2368: }
2369: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2370: if ($authtype eq '') {
2371: $authtype = '<input type="radio" name="login" value="fsys" '.
2372: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2373: $jscall.'" />';
2374: }
2375: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2376: ' onchange="'.$jscall.'" />';
2377: $result = &mt
2378: ('[_1] Filesystem Authenticated (with initial password [_2])',
2379: '<label><input type="radio" name="login" value="fsys" '.
2380: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
2381: '</label><input type="password" size="10" name="fsysarg" value="" '.
2382: 'onchange="'.$jscall.'" />');
2383: return $result;
2384: }
2385:
2386: sub get_assignable_auth {
2387: my ($dom) = @_;
2388: if ($dom eq '') {
2389: $dom = $env{'request.role.domain'};
2390: }
2391: my %can_assign = (
2392: krb4 => 1,
2393: krb5 => 1,
2394: int => 1,
2395: loc => 1,
2396: );
2397: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2398: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2399: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2400: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2401: my $context;
2402: if ($env{'request.role'} =~ /^au/) {
2403: $context = 'author';
2404: } elsif ($env{'request.role'} =~ /^dc/) {
2405: $context = 'domain';
2406: } elsif ($env{'request.course.id'}) {
2407: $context = 'course';
2408: }
2409: if ($context) {
2410: if (ref($authhash->{$context}) eq 'HASH') {
2411: %can_assign = %{$authhash->{$context}};
2412: }
2413: }
2414: }
2415: }
2416: my $authnum = 0;
2417: foreach my $key (keys(%can_assign)) {
2418: if ($can_assign{$key}) {
2419: $authnum ++;
2420: }
2421: }
2422: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2423: $authnum --;
2424: }
2425: return ($authnum,%can_assign);
2426: }
2427:
2428: ###############################################################
2429: ## Get Kerberos Defaults for Domain ##
2430: ###############################################################
2431: ##
2432: ## Returns default kerberos version and an associated argument
2433: ## as listed in file domain.tab. If not listed, provides
2434: ## appropriate default domain and kerberos version.
2435: ##
2436: #-------------------------------------------
2437:
2438: =pod
2439:
2440: =item * &get_kerberos_defaults()
2441:
2442: get_kerberos_defaults($target_domain) returns the default kerberos
2443: version and domain. If not found, it defaults to version 4 and the
2444: domain of the server.
2445:
2446: =over 4
2447:
2448: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2449:
2450: =back
2451:
2452: =back
2453:
2454: =cut
2455:
2456: #-------------------------------------------
2457: sub get_kerberos_defaults {
2458: my $domain=shift;
2459: my ($krbdef,$krbdefdom);
2460: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2461: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2462: $krbdef = $domdefaults{'auth_def'};
2463: $krbdefdom = $domdefaults{'auth_arg_def'};
2464: } else {
2465: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2466: my $krbdefdom=$1;
2467: $krbdefdom=~tr/a-z/A-Z/;
2468: $krbdef = "krb4";
2469: }
2470: return ($krbdef,$krbdefdom);
2471: }
2472:
2473:
2474: ###############################################################
2475: ## Thesaurus Functions ##
2476: ###############################################################
2477:
2478: =pod
2479:
2480: =head1 Thesaurus Functions
2481:
2482: =over 4
2483:
2484: =item * &initialize_keywords()
2485:
2486: Initializes the package variable %Keywords if it is empty. Uses the
2487: package variable $thesaurus_db_file.
2488:
2489: =cut
2490:
2491: ###################################################
2492:
2493: sub initialize_keywords {
2494: return 1 if (scalar keys(%Keywords));
2495: # If we are here, %Keywords is empty, so fill it up
2496: # Make sure the file we need exists...
2497: if (! -e $thesaurus_db_file) {
2498: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2499: " failed because it does not exist");
2500: return 0;
2501: }
2502: # Set up the hash as a database
2503: my %thesaurus_db;
2504: if (! tie(%thesaurus_db,'GDBM_File',
2505: $thesaurus_db_file,&GDBM_READER(),0640)){
2506: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2507: $thesaurus_db_file);
2508: return 0;
2509: }
2510: # Get the average number of appearances of a word.
2511: my $avecount = $thesaurus_db{'average.count'};
2512: # Put keywords (those that appear > average) into %Keywords
2513: while (my ($word,$data)=each (%thesaurus_db)) {
2514: my ($count,undef) = split /:/,$data;
2515: $Keywords{$word}++ if ($count > $avecount);
2516: }
2517: untie %thesaurus_db;
2518: # Remove special values from %Keywords.
2519: foreach my $value ('total.count','average.count') {
2520: delete($Keywords{$value}) if (exists($Keywords{$value}));
2521: }
2522: return 1;
2523: }
2524:
2525: ###################################################
2526:
2527: =pod
2528:
2529: =item * &keyword($word)
2530:
2531: Returns true if $word is a keyword. A keyword is a word that appears more
2532: than the average number of times in the thesaurus database. Calls
2533: &initialize_keywords
2534:
2535: =cut
2536:
2537: ###################################################
2538:
2539: sub keyword {
2540: return if (!&initialize_keywords());
2541: my $word=lc(shift());
2542: $word=~s/\W//g;
2543: return exists($Keywords{$word});
2544: }
2545:
2546: ###############################################################
2547:
2548: =pod
2549:
2550: =item * &get_related_words()
2551:
2552: Look up a word in the thesaurus. Takes a scalar argument and returns
2553: an array of words. If the keyword is not in the thesaurus, an empty array
2554: will be returned. The order of the words returned is determined by the
2555: database which holds them.
2556:
2557: Uses global $thesaurus_db_file.
2558:
2559: =cut
2560:
2561: ###############################################################
2562: sub get_related_words {
2563: my $keyword = shift;
2564: my %thesaurus_db;
2565: if (! -e $thesaurus_db_file) {
2566: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
2567: "failed because the file does not exist");
2568: return ();
2569: }
2570: if (! tie(%thesaurus_db,'GDBM_File',
2571: $thesaurus_db_file,&GDBM_READER(),0640)){
2572: return ();
2573: }
2574: my @Words=();
2575: my $count=0;
2576: if (exists($thesaurus_db{$keyword})) {
2577: # The first element is the number of times
2578: # the word appears. We do not need it now.
2579: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
2580: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
2581: my $threshold=$mostfrequentcount/10;
2582: foreach my $possibleword (@RelatedWords) {
2583: my ($word,$wordcount)=split(/\,/,$possibleword);
2584: if ($wordcount>$threshold) {
2585: push(@Words,$word);
2586: $count++;
2587: if ($count>10) { last; }
2588: }
2589: }
2590: }
2591: untie %thesaurus_db;
2592: return @Words;
2593: }
2594:
2595: =pod
2596:
2597: =back
2598:
2599: =cut
2600:
2601: # -------------------------------------------------------------- Plaintext name
2602: =pod
2603:
2604: =head1 User Name Functions
2605:
2606: =over 4
2607:
2608: =item * &plainname($uname,$udom,$first)
2609:
2610: Takes a users logon name and returns it as a string in
2611: "first middle last generation" form
2612: if $first is set to 'lastname' then it returns it as
2613: 'lastname generation, firstname middlename' if their is a lastname
2614:
2615: =cut
2616:
2617:
2618: ###############################################################
2619: sub plainname {
2620: my ($uname,$udom,$first)=@_;
2621: return if (!defined($uname) || !defined($udom));
2622: my %names=&getnames($uname,$udom);
2623: my $name=&Apache::lonnet::format_name($names{'firstname'},
2624: $names{'middlename'},
2625: $names{'lastname'},
2626: $names{'generation'},$first);
2627: $name=~s/^\s+//;
2628: $name=~s/\s+$//;
2629: $name=~s/\s+/ /g;
2630: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
2631: return $name;
2632: }
2633:
2634: # -------------------------------------------------------------------- Nickname
2635: =pod
2636:
2637: =item * &nickname($uname,$udom)
2638:
2639: Gets a users name and returns it as a string as
2640:
2641: ""nickname""
2642:
2643: if the user has a nickname or
2644:
2645: "first middle last generation"
2646:
2647: if the user does not
2648:
2649: =cut
2650:
2651: sub nickname {
2652: my ($uname,$udom)=@_;
2653: return if (!defined($uname) || !defined($udom));
2654: my %names=&getnames($uname,$udom);
2655: my $name=$names{'nickname'};
2656: if ($name) {
2657: $name='"'.$name.'"';
2658: } else {
2659: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
2660: $names{'lastname'}.' '.$names{'generation'};
2661: $name=~s/\s+$//;
2662: $name=~s/\s+/ /g;
2663: }
2664: return $name;
2665: }
2666:
2667: sub getnames {
2668: my ($uname,$udom)=@_;
2669: return if (!defined($uname) || !defined($udom));
2670: if ($udom eq 'public' && $uname eq 'public') {
2671: return ('lastname' => &mt('Public'));
2672: }
2673: my $id=$uname.':'.$udom;
2674: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
2675: if ($cached) {
2676: return %{$names};
2677: } else {
2678: my %loadnames=&Apache::lonnet::get('environment',
2679: ['firstname','middlename','lastname','generation','nickname'],
2680: $udom,$uname);
2681: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
2682: return %loadnames;
2683: }
2684: }
2685:
2686: # -------------------------------------------------------------------- getemails
2687:
2688: =pod
2689:
2690: =item * &getemails($uname,$udom)
2691:
2692: Gets a user's email information and returns it as a hash with keys:
2693: notification, critnotification, permanentemail
2694:
2695: For notification and critnotification, values are comma-separated lists
2696: of e-mail addresses; for permanentemail, value is a single e-mail address.
2697:
2698:
2699: =cut
2700:
2701:
2702: sub getemails {
2703: my ($uname,$udom)=@_;
2704: if ($udom eq 'public' && $uname eq 'public') {
2705: return;
2706: }
2707: if (!$udom) { $udom=$env{'user.domain'}; }
2708: if (!$uname) { $uname=$env{'user.name'}; }
2709: my $id=$uname.':'.$udom;
2710: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
2711: if ($cached) {
2712: return %{$names};
2713: } else {
2714: my %loadnames=&Apache::lonnet::get('environment',
2715: ['notification','critnotification',
2716: 'permanentemail'],
2717: $udom,$uname);
2718: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
2719: return %loadnames;
2720: }
2721: }
2722:
2723: sub flush_email_cache {
2724: my ($uname,$udom)=@_;
2725: if (!$udom) { $udom =$env{'user.domain'}; }
2726: if (!$uname) { $uname=$env{'user.name'}; }
2727: return if ($udom eq 'public' && $uname eq 'public');
2728: my $id=$uname.':'.$udom;
2729: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
2730: }
2731:
2732: # -------------------------------------------------------------------- getlangs
2733:
2734: =pod
2735:
2736: =item * &getlangs($uname,$udom)
2737:
2738: Gets a user's language preference and returns it as a hash with key:
2739: language.
2740:
2741: =cut
2742:
2743:
2744: sub getlangs {
2745: my ($uname,$udom) = @_;
2746: if (!$udom) { $udom =$env{'user.domain'}; }
2747: if (!$uname) { $uname=$env{'user.name'}; }
2748: my $id=$uname.':'.$udom;
2749: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
2750: if ($cached) {
2751: return %{$langs};
2752: } else {
2753: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
2754: $udom,$uname);
2755: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
2756: return %loadlangs;
2757: }
2758: }
2759:
2760: sub flush_langs_cache {
2761: my ($uname,$udom)=@_;
2762: if (!$udom) { $udom =$env{'user.domain'}; }
2763: if (!$uname) { $uname=$env{'user.name'}; }
2764: return if ($udom eq 'public' && $uname eq 'public');
2765: my $id=$uname.':'.$udom;
2766: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
2767: }
2768:
2769: # ------------------------------------------------------------------ Screenname
2770:
2771: =pod
2772:
2773: =item * &screenname($uname,$udom)
2774:
2775: Gets a users screenname and returns it as a string
2776:
2777: =cut
2778:
2779: sub screenname {
2780: my ($uname,$udom)=@_;
2781: if ($uname eq $env{'user.name'} &&
2782: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
2783: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
2784: return $names{'screenname'};
2785: }
2786:
2787:
2788: # ------------------------------------------------------------- Message Wrapper
2789:
2790: sub messagewrapper {
2791: my ($link,$username,$domain,$subject,$text)=@_;
2792: return
2793: '<a href="/adm/email?compose=individual&'.
2794: 'recname='.$username.'&recdom='.$domain.
2795: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
2796: 'title="'.&mt('Send message').'">'.$link.'</a>';
2797: }
2798: # --------------------------------------------------------------- Notes Wrapper
2799:
2800: sub noteswrapper {
2801: my ($link,$un,$do)=@_;
2802: return
2803: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
2804: }
2805: # ------------------------------------------------------------- Aboutme Wrapper
2806:
2807: sub aboutmewrapper {
2808: my ($link,$username,$domain,$target)=@_;
2809: if (!defined($username) && !defined($domain)) {
2810: return;
2811: }
2812: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
2813: ($target?' target="$target"':'').' title="'.&mt("View this user's personal page").'">'.$link.'</a>';
2814: }
2815:
2816: # ------------------------------------------------------------ Syllabus Wrapper
2817:
2818:
2819: sub syllabuswrapper {
2820: my ($linktext,$coursedir,$domain)=@_;
2821: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
2822: }
2823:
2824: sub track_student_link {
2825: my ($linktext,$sname,$sdom,$target,$start) = @_;
2826: my $link ="/adm/trackstudent?";
2827: my $title = 'View recent activity';
2828: if (defined($sname) && $sname !~ /^\s*$/ &&
2829: defined($sdom) && $sdom !~ /^\s*$/) {
2830: $link .= "selected_student=$sname:$sdom";
2831: $title .= ' of this student';
2832: }
2833: if (defined($target) && $target !~ /^\s*$/) {
2834: $target = qq{target="$target"};
2835: } else {
2836: $target = '';
2837: }
2838: if ($start) { $link.='&start='.$start; }
2839: $title = &mt($title);
2840: $linktext = &mt($linktext);
2841: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
2842: &help_open_topic('View_recent_activity');
2843: }
2844:
2845: # ===================================================== Display a student photo
2846:
2847:
2848: sub student_image_tag {
2849: my ($domain,$user)=@_;
2850: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
2851: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
2852: return '<img src="'.$imgsrc.'" align="right" />';
2853: } else {
2854: return '';
2855: }
2856: }
2857:
2858: =pod
2859:
2860: =back
2861:
2862: =head1 Access .tab File Data
2863:
2864: =over 4
2865:
2866: =item * &languageids()
2867:
2868: returns list of all language ids
2869:
2870: =cut
2871:
2872: sub languageids {
2873: return sort(keys(%language));
2874: }
2875:
2876: =pod
2877:
2878: =item * &languagedescription()
2879:
2880: returns description of a specified language id
2881:
2882: =cut
2883:
2884: sub languagedescription {
2885: my $code=shift;
2886: return ($supported_language{$code}?'* ':'').
2887: $language{$code}.
2888: ($supported_language{$code}?' ('.&mt('interface available').')':'');
2889: }
2890:
2891: sub plainlanguagedescription {
2892: my $code=shift;
2893: return $language{$code};
2894: }
2895:
2896: sub supportedlanguagecode {
2897: my $code=shift;
2898: return $supported_language{$code};
2899: }
2900:
2901: =pod
2902:
2903: =item * ©rightids()
2904:
2905: returns list of all copyrights
2906:
2907: =cut
2908:
2909: sub copyrightids {
2910: return sort(keys(%cprtag));
2911: }
2912:
2913: =pod
2914:
2915: =item * ©rightdescription()
2916:
2917: returns description of a specified copyright id
2918:
2919: =cut
2920:
2921: sub copyrightdescription {
2922: return &mt($cprtag{shift(@_)});
2923: }
2924:
2925: =pod
2926:
2927: =item * &source_copyrightids()
2928:
2929: returns list of all source copyrights
2930:
2931: =cut
2932:
2933: sub source_copyrightids {
2934: return sort(keys(%scprtag));
2935: }
2936:
2937: =pod
2938:
2939: =item * &source_copyrightdescription()
2940:
2941: returns description of a specified source copyright id
2942:
2943: =cut
2944:
2945: sub source_copyrightdescription {
2946: return &mt($scprtag{shift(@_)});
2947: }
2948:
2949: =pod
2950:
2951: =item * &filecategories()
2952:
2953: returns list of all file categories
2954:
2955: =cut
2956:
2957: sub filecategories {
2958: return sort(keys(%category_extensions));
2959: }
2960:
2961: =pod
2962:
2963: =item * &filecategorytypes()
2964:
2965: returns list of file types belonging to a given file
2966: category
2967:
2968: =cut
2969:
2970: sub filecategorytypes {
2971: my ($cat) = @_;
2972: return @{$category_extensions{lc($cat)}};
2973: }
2974:
2975: =pod
2976:
2977: =item * &fileembstyle()
2978:
2979: returns embedding style for a specified file type
2980:
2981: =cut
2982:
2983: sub fileembstyle {
2984: return $fe{lc(shift(@_))};
2985: }
2986:
2987: sub filemimetype {
2988: return $fm{lc(shift(@_))};
2989: }
2990:
2991:
2992: sub filecategoryselect {
2993: my ($name,$value)=@_;
2994: return &select_form($value,$name,
2995: '' => &mt('Any category'),
2996: map { $_,$_ } sort(keys(%category_extensions)));
2997: }
2998:
2999: =pod
3000:
3001: =item * &filedescription()
3002:
3003: returns description for a specified file type
3004:
3005: =cut
3006:
3007: sub filedescription {
3008: my $file_description = $fd{lc(shift())};
3009: $file_description =~ s:([\[\]]):~$1:g;
3010: return &mt($file_description);
3011: }
3012:
3013: =pod
3014:
3015: =item * &filedescriptionex()
3016:
3017: returns description for a specified file type with
3018: extra formatting
3019:
3020: =cut
3021:
3022: sub filedescriptionex {
3023: my $ex=shift;
3024: my $file_description = $fd{lc($ex)};
3025: $file_description =~ s:([\[\]]):~$1:g;
3026: return '.'.$ex.' '.&mt($file_description);
3027: }
3028:
3029: # End of .tab access
3030: =pod
3031:
3032: =back
3033:
3034: =cut
3035:
3036: # ------------------------------------------------------------------ File Types
3037: sub fileextensions {
3038: return sort(keys(%fe));
3039: }
3040:
3041: # ----------------------------------------------------------- Display Languages
3042: # returns a hash with all desired display languages
3043: #
3044:
3045: sub display_languages {
3046: my %languages=();
3047: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
3048: $languages{$lang}=1;
3049: }
3050: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
3051: if ($env{'form.displaylanguage'}) {
3052: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3053: $languages{$lang}=1;
3054: }
3055: }
3056: return %languages;
3057: }
3058:
3059: sub languages {
3060: my ($possible_langs) = @_;
3061: my @preferred_langs = &Apache::lonlocal::preferred_languages();
3062: if (!ref($possible_langs)) {
3063: if( wantarray ) {
3064: return @preferred_langs;
3065: } else {
3066: return $preferred_langs[0];
3067: }
3068: }
3069: my %possibilities = map { $_ => 1 } (@$possible_langs);
3070: my @preferred_possibilities;
3071: foreach my $preferred_lang (@preferred_langs) {
3072: if (exists($possibilities{$preferred_lang})) {
3073: push(@preferred_possibilities, $preferred_lang);
3074: }
3075: }
3076: if( wantarray ) {
3077: return @preferred_possibilities;
3078: }
3079: return $preferred_possibilities[0];
3080: }
3081:
3082: sub user_lang {
3083: my ($touname,$toudom,$fromcid) = @_;
3084: my @userlangs;
3085: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3086: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3087: $env{'course.'.$fromcid.'.languages'}));
3088: } else {
3089: my %langhash = &getlangs($touname,$toudom);
3090: if ($langhash{'languages'} ne '') {
3091: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3092: } else {
3093: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3094: if ($domdefs{'lang_def'} ne '') {
3095: @userlangs = ($domdefs{'lang_def'});
3096: }
3097: }
3098: }
3099: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3100: my $user_lh = Apache::localize->get_handle(@languages);
3101: return $user_lh;
3102: }
3103:
3104:
3105: ###############################################################
3106: ## Student Answer Attempts ##
3107: ###############################################################
3108:
3109: =pod
3110:
3111: =head1 Alternate Problem Views
3112:
3113: =over 4
3114:
3115: =item * &get_previous_attempt($symb, $username, $domain, $course,
3116: $getattempt, $regexp, $gradesub)
3117:
3118: Return string with previous attempt on problem. Arguments:
3119:
3120: =over 4
3121:
3122: =item * $symb: Problem, including path
3123:
3124: =item * $username: username of the desired student
3125:
3126: =item * $domain: domain of the desired student
3127:
3128: =item * $course: Course ID
3129:
3130: =item * $getattempt: Leave blank for all attempts, otherwise put
3131: something
3132:
3133: =item * $regexp: if string matches this regexp, the string will be
3134: sent to $gradesub
3135:
3136: =item * $gradesub: routine that processes the string if it matches $regexp
3137:
3138: =back
3139:
3140: The output string is a table containing all desired attempts, if any.
3141:
3142: =cut
3143:
3144: sub get_previous_attempt {
3145: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
3146: my $prevattempts='';
3147: no strict 'refs';
3148: if ($symb) {
3149: my (%returnhash)=
3150: &Apache::lonnet::restore($symb,$course,$domain,$username);
3151: if ($returnhash{'version'}) {
3152: my %lasthash=();
3153: my $version;
3154: for ($version=1;$version<=$returnhash{'version'};$version++) {
3155: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3156: $lasthash{$key}=$returnhash{$version.':'.$key};
3157: }
3158: }
3159: $prevattempts=&start_data_table().&start_data_table_header_row();
3160: $prevattempts.='<th>'.&mt('History').'</th>';
3161: foreach my $key (sort(keys(%lasthash))) {
3162: my ($ign,@parts) = split(/\./,$key);
3163: if ($#parts > 0) {
3164: my $data=$parts[-1];
3165: pop(@parts);
3166: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
3167: } else {
3168: if ($#parts == 0) {
3169: $prevattempts.='<th>'.$parts[0].'</th>';
3170: } else {
3171: $prevattempts.='<th>'.$ign.'</th>';
3172: }
3173: }
3174: }
3175: $prevattempts.=&end_data_table_header_row();
3176: if ($getattempt eq '') {
3177: for ($version=1;$version<=$returnhash{'version'};$version++) {
3178: $prevattempts.=&start_data_table_row().
3179: '<td>'.&mt('Transaction [_1]',$version).'</td>';
3180: foreach my $key (sort(keys(%lasthash))) {
3181: my $value = &format_previous_attempt_value($key,
3182: $returnhash{$version.':'.$key});
3183: $prevattempts.='<td>'.$value.' </td>';
3184: }
3185: $prevattempts.=&end_data_table_row();
3186: }
3187: }
3188: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
3189: foreach my $key (sort(keys(%lasthash))) {
3190: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3191: if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
3192: $prevattempts.='<td>'.$value.' </td>';
3193: }
3194: $prevattempts.= &end_data_table_row().&end_data_table();
3195: } else {
3196: $prevattempts=
3197: &start_data_table().&start_data_table_row().
3198: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3199: &end_data_table_row().&end_data_table();
3200: }
3201: } else {
3202: $prevattempts=
3203: &start_data_table().&start_data_table_row().
3204: '<td>'.&mt('No data.').'</td>'.
3205: &end_data_table_row().&end_data_table();
3206: }
3207: }
3208:
3209: sub format_previous_attempt_value {
3210: my ($key,$value) = @_;
3211: if ($key =~ /timestamp/) {
3212: $value = &Apache::lonlocal::locallocaltime($value);
3213: } elsif (ref($value) eq 'ARRAY') {
3214: $value = '('.join(', ', @{ $value }).')';
3215: } else {
3216: $value = &unescape($value);
3217: }
3218: return $value;
3219: }
3220:
3221:
3222: sub relative_to_absolute {
3223: my ($url,$output)=@_;
3224: my $parser=HTML::TokeParser->new(\$output);
3225: my $token;
3226: my $thisdir=$url;
3227: my @rlinks=();
3228: while ($token=$parser->get_token) {
3229: if ($token->[0] eq 'S') {
3230: if ($token->[1] eq 'a') {
3231: if ($token->[2]->{'href'}) {
3232: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3233: }
3234: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3235: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3236: } elsif ($token->[1] eq 'base') {
3237: $thisdir=$token->[2]->{'href'};
3238: }
3239: }
3240: }
3241: $thisdir=~s-/[^/]*$--;
3242: foreach my $link (@rlinks) {
3243: unless (($link=~/^https?\:\/\//i) ||
3244: ($link=~/^\//) ||
3245: ($link=~/^javascript:/i) ||
3246: ($link=~/^mailto:/i) ||
3247: ($link=~/^\#/)) {
3248: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3249: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
3250: }
3251: }
3252: # -------------------------------------------------- Deal with Applet codebases
3253: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3254: return $output;
3255: }
3256:
3257: =pod
3258:
3259: =item * &get_student_view()
3260:
3261: show a snapshot of what student was looking at
3262:
3263: =cut
3264:
3265: sub get_student_view {
3266: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
3267: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
3268: my (%form);
3269: my @elements=('symb','courseid','domain','username');
3270: foreach my $element (@elements) {
3271: $form{'grade_'.$element}=eval '$'.$element #'
3272: }
3273: if (defined($moreenv)) {
3274: %form=(%form,%{$moreenv});
3275: }
3276: if (defined($target)) { $form{'grade_target'} = $target; }
3277: $feedurl=&Apache::lonnet::clutter($feedurl);
3278: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
3279: $userview=~s/\<body[^\>]*\>//gi;
3280: $userview=~s/\<\/body\>//gi;
3281: $userview=~s/\<html\>//gi;
3282: $userview=~s/\<\/html\>//gi;
3283: $userview=~s/\<head\>//gi;
3284: $userview=~s/\<\/head\>//gi;
3285: $userview=~s/action\s*\=/would_be_action\=/gi;
3286: $userview=&relative_to_absolute($feedurl,$userview);
3287: if (wantarray) {
3288: return ($userview,$response);
3289: } else {
3290: return $userview;
3291: }
3292: }
3293:
3294: sub get_student_view_with_retries {
3295: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3296:
3297: my $ok = 0; # True if we got a good response.
3298: my $content;
3299: my $response;
3300:
3301: # Try to get the student_view done. within the retries count:
3302:
3303: do {
3304: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3305: $ok = $response->is_success;
3306: if (!$ok) {
3307: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3308: }
3309: $retries--;
3310: } while (!$ok && ($retries > 0));
3311:
3312: if (!$ok) {
3313: $content = ''; # On error return an empty content.
3314: }
3315: if (wantarray) {
3316: return ($content, $response);
3317: } else {
3318: return $content;
3319: }
3320: }
3321:
3322: =pod
3323:
3324: =item * &get_student_answers()
3325:
3326: show a snapshot of how student was answering problem
3327:
3328: =cut
3329:
3330: sub get_student_answers {
3331: my ($symb,$username,$domain,$courseid,%form) = @_;
3332: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
3333: my (%moreenv);
3334: my @elements=('symb','courseid','domain','username');
3335: foreach my $element (@elements) {
3336: $moreenv{'grade_'.$element}=eval '$'.$element #'
3337: }
3338: $moreenv{'grade_target'}='answer';
3339: %moreenv=(%form,%moreenv);
3340: $feedurl = &Apache::lonnet::clutter($feedurl);
3341: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
3342: return $userview;
3343: }
3344:
3345: =pod
3346:
3347: =item * &submlink()
3348:
3349: Inputs: $text $uname $udom $symb $target
3350:
3351: Returns: A link to grades.pm such as to see the SUBM view of a student
3352:
3353: =cut
3354:
3355: ###############################################
3356: sub submlink {
3357: my ($text,$uname,$udom,$symb,$target)=@_;
3358: if (!($uname && $udom)) {
3359: (my $cursymb, my $courseid,$udom,$uname)=
3360: &Apache::lonnet::whichuser($symb);
3361: if (!$symb) { $symb=$cursymb; }
3362: }
3363: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
3364: $symb=&escape($symb);
3365: if ($target) { $target="target=\"$target\""; }
3366: return '<a href="/adm/grades?&command=submission&'.
3367: 'symb='.$symb.'&student='.$uname.
3368: '&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
3369: }
3370: ##############################################
3371:
3372: =pod
3373:
3374: =item * &pgrdlink()
3375:
3376: Inputs: $text $uname $udom $symb $target
3377:
3378: Returns: A link to grades.pm such as to see the PGRD view of a student
3379:
3380: =cut
3381:
3382: ###############################################
3383: sub pgrdlink {
3384: my $link=&submlink(@_);
3385: $link=~s/(&command=submission)/$1&showgrading=yes/;
3386: return $link;
3387: }
3388: ##############################################
3389:
3390: =pod
3391:
3392: =item * &pprmlink()
3393:
3394: Inputs: $text $uname $udom $symb $target
3395:
3396: Returns: A link to parmset.pm such as to see the PPRM view of a
3397: student and a specific resource
3398:
3399: =cut
3400:
3401: ###############################################
3402: sub pprmlink {
3403: my ($text,$uname,$udom,$symb,$target)=@_;
3404: if (!($uname && $udom)) {
3405: (my $cursymb, my $courseid,$udom,$uname)=
3406: &Apache::lonnet::whichuser($symb);
3407: if (!$symb) { $symb=$cursymb; }
3408: }
3409: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
3410: $symb=&escape($symb);
3411: if ($target) { $target="target=\"$target\""; }
3412: return '<a href="/adm/parmset?command=set&'.
3413: 'symb='.$symb.'&uname='.$uname.
3414: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
3415: }
3416: ##############################################
3417:
3418: =pod
3419:
3420: =back
3421:
3422: =cut
3423:
3424: ###############################################
3425:
3426:
3427: sub timehash {
3428: my ($thistime) = @_;
3429: my $timezone = &Apache::lonlocal::gettimezone();
3430: my $dt = DateTime->from_epoch(epoch => $thistime)
3431: ->set_time_zone($timezone);
3432: my $wday = $dt->day_of_week();
3433: if ($wday == 7) { $wday = 0; }
3434: return ( 'second' => $dt->second(),
3435: 'minute' => $dt->minute(),
3436: 'hour' => $dt->hour(),
3437: 'day' => $dt->day_of_month(),
3438: 'month' => $dt->month(),
3439: 'year' => $dt->year(),
3440: 'weekday' => $wday,
3441: 'dayyear' => $dt->day_of_year(),
3442: 'dlsav' => $dt->is_dst() );
3443: }
3444:
3445: sub utc_string {
3446: my ($date)=@_;
3447: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
3448: }
3449:
3450: sub maketime {
3451: my %th=@_;
3452: my ($epoch_time,$timezone,$dt);
3453: $timezone = &Apache::lonlocal::gettimezone();
3454: eval {
3455: $dt = DateTime->new( year => $th{'year'},
3456: month => $th{'month'},
3457: day => $th{'day'},
3458: hour => $th{'hour'},
3459: minute => $th{'minute'},
3460: second => $th{'second'},
3461: time_zone => $timezone,
3462: );
3463: };
3464: if (!$@) {
3465: $epoch_time = $dt->epoch;
3466: if ($epoch_time) {
3467: return $epoch_time;
3468: }
3469: }
3470: return POSIX::mktime(
3471: ($th{'seconds'},$th{'minutes'},$th{'hours'},
3472: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
3473: }
3474:
3475: #########################################
3476:
3477: sub findallcourses {
3478: my ($roles,$uname,$udom) = @_;
3479: my %roles;
3480: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
3481: my %courses;
3482: my $now=time;
3483: if (!defined($uname)) {
3484: $uname = $env{'user.name'};
3485: }
3486: if (!defined($udom)) {
3487: $udom = $env{'user.domain'};
3488: }
3489: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
3490: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
3491: if (!%roles) {
3492: %roles = (
3493: cc => 1,
3494: in => 1,
3495: ep => 1,
3496: ta => 1,
3497: cr => 1,
3498: st => 1,
3499: );
3500: }
3501: foreach my $entry (keys(%roleshash)) {
3502: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
3503: if ($trole =~ /^cr/) {
3504: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
3505: } else {
3506: next if (!exists($roles{$trole}));
3507: }
3508: if ($tend) {
3509: next if ($tend < $now);
3510: }
3511: if ($tstart) {
3512: next if ($tstart > $now);
3513: }
3514: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
3515: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
3516: if ($secpart eq '') {
3517: ($cnum,$role) = split(/_/,$cnumpart);
3518: $sec = 'none';
3519: $realsec = '';
3520: } else {
3521: $cnum = $cnumpart;
3522: ($sec,$role) = split(/_/,$secpart);
3523: $realsec = $sec;
3524: }
3525: $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
3526: }
3527: } else {
3528: foreach my $key (keys(%env)) {
3529: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
3530: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
3531: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
3532: next if ($role eq 'ca' || $role eq 'aa');
3533: next if (%roles && !exists($roles{$role}));
3534: my ($starttime,$endtime)=split(/\./,$env{$key});
3535: my $active=1;
3536: if ($starttime) {
3537: if ($now<$starttime) { $active=0; }
3538: }
3539: if ($endtime) {
3540: if ($now>$endtime) { $active=0; }
3541: }
3542: if ($active) {
3543: if ($sec eq '') {
3544: $sec = 'none';
3545: }
3546: $courses{$cdom.'_'.$cnum}{$sec} =
3547: $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
3548: }
3549: }
3550: }
3551: }
3552: return %courses;
3553: }
3554:
3555: ###############################################
3556:
3557: sub blockcheck {
3558: my ($setters,$activity,$uname,$udom) = @_;
3559:
3560: if (!defined($udom)) {
3561: $udom = $env{'user.domain'};
3562: }
3563: if (!defined($uname)) {
3564: $uname = $env{'user.name'};
3565: }
3566:
3567: # If uname and udom are for a course, check for blocks in the course.
3568:
3569: if (&Apache::lonnet::is_course($udom,$uname)) {
3570: my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
3571: my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
3572: return ($startblock,$endblock);
3573: }
3574:
3575: my $startblock = 0;
3576: my $endblock = 0;
3577: my %live_courses = &findallcourses(undef,$uname,$udom);
3578:
3579: # If uname is for a user, and activity is course-specific, i.e.,
3580: # boards, chat or groups, check for blocking in current course only.
3581:
3582: if (($activity eq 'boards' || $activity eq 'chat' ||
3583: $activity eq 'groups') && ($env{'request.course.id'})) {
3584: foreach my $key (keys(%live_courses)) {
3585: if ($key ne $env{'request.course.id'}) {
3586: delete($live_courses{$key});
3587: }
3588: }
3589: }
3590:
3591: my $otheruser = 0;
3592: my %own_courses;
3593: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
3594: # Resource belongs to user other than current user.
3595: $otheruser = 1;
3596: # Gather courses for current user
3597: %own_courses =
3598: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
3599: }
3600:
3601: # Gather active course roles - course coordinator, instructor,
3602: # exam proctor, ta, student, or custom role.
3603:
3604: foreach my $course (keys(%live_courses)) {
3605: my ($cdom,$cnum);
3606: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
3607: $cdom = $env{'course.'.$course.'.domain'};
3608: $cnum = $env{'course.'.$course.'.num'};
3609: } else {
3610: ($cdom,$cnum) = split(/_/,$course);
3611: }
3612: my $no_ownblock = 0;
3613: my $no_userblock = 0;
3614: if ($otheruser && $activity ne 'com') {
3615: # Check if current user has 'evb' priv for this
3616: if (defined($own_courses{$course})) {
3617: foreach my $sec (keys(%{$own_courses{$course}})) {
3618: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
3619: if ($sec ne 'none') {
3620: $checkrole .= '/'.$sec;
3621: }
3622: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3623: $no_ownblock = 1;
3624: last;
3625: }
3626: }
3627: }
3628: # if they have 'evb' priv and are currently not playing student
3629: next if (($no_ownblock) &&
3630: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
3631: }
3632: foreach my $sec (keys(%{$live_courses{$course}})) {
3633: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
3634: if ($sec ne 'none') {
3635: $checkrole .= '/'.$sec;
3636: }
3637: if ($otheruser) {
3638: # Resource belongs to user other than current user.
3639: # Assemble privs for that user, and check for 'evb' priv.
3640: my ($trole,$tdom,$tnum,$tsec);
3641: my $entry = $live_courses{$course}{$sec};
3642: if ($entry =~ /^cr/) {
3643: ($trole,$tdom,$tnum,$tsec) =
3644: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
3645: } else {
3646: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
3647: }
3648: my ($spec,$area,$trest,%allroles,%userroles);
3649: $area = '/'.$tdom.'/'.$tnum;
3650: $trest = $tnum;
3651: if ($tsec ne '') {
3652: $area .= '/'.$tsec;
3653: $trest .= '/'.$tsec;
3654: }
3655: $spec = $trole.'.'.$area;
3656: if ($trole =~ /^cr/) {
3657: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
3658: $tdom,$spec,$trest,$area);
3659: } else {
3660: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
3661: $tdom,$spec,$trest,$area);
3662: }
3663: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
3664: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
3665: if ($1) {
3666: $no_userblock = 1;
3667: last;
3668: }
3669: }
3670: } else {
3671: # Resource belongs to current user
3672: # Check for 'evb' priv via lonnet::allowed().
3673: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3674: $no_ownblock = 1;
3675: last;
3676: }
3677: }
3678: }
3679: # if they have the evb priv and are currently not playing student
3680: next if (($no_ownblock) &&
3681: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
3682: next if ($no_userblock);
3683:
3684: # Retrieve blocking times and identity of blocker for course
3685: # of specified user, unless user has 'evb' privilege.
3686:
3687: my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
3688: if (($start != 0) &&
3689: (($startblock == 0) || ($startblock > $start))) {
3690: $startblock = $start;
3691: }
3692: if (($end != 0) &&
3693: (($endblock == 0) || ($endblock < $end))) {
3694: $endblock = $end;
3695: }
3696: }
3697: return ($startblock,$endblock);
3698: }
3699:
3700: sub get_blocks {
3701: my ($setters,$activity,$cdom,$cnum) = @_;
3702: my $startblock = 0;
3703: my $endblock = 0;
3704: my $course = $cdom.'_'.$cnum;
3705: $setters->{$course} = {};
3706: $setters->{$course}{'staff'} = [];
3707: $setters->{$course}{'times'} = [];
3708: my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
3709: foreach my $record (keys(%records)) {
3710: my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
3711: if ($start <= time && $end >= time) {
3712: my ($staff_name,$staff_dom,$title,$blocks) =
3713: &parse_block_record($records{$record});
3714: if ($blocks->{$activity} eq 'on') {
3715: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
3716: push(@{$$setters{$course}{'times'}}, [$start,$end]);
3717: if ( ($startblock == 0) || ($startblock > $start) ) {
3718: $startblock = $start;
3719: }
3720: if ( ($endblock == 0) || ($endblock < $end) ) {
3721: $endblock = $end;
3722: }
3723: }
3724: }
3725: }
3726: return ($startblock,$endblock);
3727: }
3728:
3729: sub parse_block_record {
3730: my ($record) = @_;
3731: my ($setuname,$setudom,$title,$blocks);
3732: if (ref($record) eq 'HASH') {
3733: ($setuname,$setudom) = split(/:/,$record->{'setter'});
3734: $title = &unescape($record->{'event'});
3735: $blocks = $record->{'blocks'};
3736: } else {
3737: my @data = split(/:/,$record,3);
3738: if (scalar(@data) eq 2) {
3739: $title = $data[1];
3740: ($setuname,$setudom) = split(/@/,$data[0]);
3741: } else {
3742: ($setuname,$setudom,$title) = @data;
3743: }
3744: $blocks = { 'com' => 'on' };
3745: }
3746: return ($setuname,$setudom,$title,$blocks);
3747: }
3748:
3749: sub build_block_table {
3750: my ($startblock,$endblock,$setters) = @_;
3751: my %lt = &Apache::lonlocal::texthash(
3752: 'cacb' => 'Currently active communication blocks',
3753: 'cour' => 'Course',
3754: 'dura' => 'Duration',
3755: 'blse' => 'Block set by'
3756: );
3757: my $output;
3758: $output = '<br />'.$lt{'cacb'}.':<br />';
3759: $output .= &start_data_table();
3760: $output .= '
3761: <tr>
3762: <th>'.$lt{'cour'}.'</th>
3763: <th>'.$lt{'dura'}.'</th>
3764: <th>'.$lt{'blse'}.'</th>
3765: </tr>
3766: ';
3767: foreach my $course (keys(%{$setters})) {
3768: my %courseinfo=&Apache::lonnet::coursedescription($course);
3769: for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) {
3770: my ($uname,$udom) = @{$$setters{$course}{staff}[$i]};
3771: my $fullname = &plainname($uname,$udom);
3772: if (defined($env{'user.name'}) && defined($env{'user.domain'})
3773: && $env{'user.name'} ne 'public'
3774: && $env{'user.domain'} ne 'public') {
3775: $fullname = &aboutmewrapper($fullname,$uname,$udom);
3776: }
3777: my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]};
3778: $openblock = &Apache::lonlocal::locallocaltime($openblock);
3779: $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
3780: $output .= &Apache::loncommon::start_data_table_row().
3781: '<td>'.$courseinfo{'description'}.'</td>'.
3782: '<td>'.$openblock.' to '.$closeblock.'</td>'.
3783: '<td>'.$fullname.'</td>'.
3784: &Apache::loncommon::end_data_table_row();
3785: }
3786: }
3787: $output .= &end_data_table();
3788: }
3789:
3790: sub blocking_status {
3791: my ($activity,$uname,$udom) = @_;
3792: my %setters;
3793: my ($blocked,$output,$ownitem,$is_course);
3794: my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
3795: if ($startblock && $endblock) {
3796: $blocked = 1;
3797: if (wantarray) {
3798: my $category;
3799: if ($activity eq 'boards') {
3800: $category = 'Discussion posts in this course';
3801: } elsif ($activity eq 'blogs') {
3802: $category = 'Blogs';
3803: } elsif ($activity eq 'port') {
3804: if (defined($uname) && defined($udom)) {
3805: if ($uname eq $env{'user.name'} &&
3806: $udom eq $env{'user.domain'}) {
3807: $ownitem = 1;
3808: }
3809: }
3810: $is_course = &Apache::lonnet::is_course($udom,$uname);
3811: if ($ownitem) {
3812: $category = 'Your portfolio files';
3813: } elsif ($is_course) {
3814: my $coursedesc;
3815: foreach my $course (keys(%setters)) {
3816: my %courseinfo =
3817: &Apache::lonnet::coursedescription($course);
3818: $coursedesc = $courseinfo{'description'};
3819: }
3820: $category = "Group files in the course '$coursedesc'";
3821: } else {
3822: $category = 'Portfolio files belonging to ';
3823: if ($env{'user.name'} eq 'public' &&
3824: $env{'user.domain'} eq 'public') {
3825: $category .= &plainname($uname,$udom);
3826: } else {
3827: $category .= &aboutmewrapper(&plainname($uname,$udom),$uname,$udom);
3828: }
3829: }
3830: } elsif ($activity eq 'groups') {
3831: $category = 'Groups in this course';
3832: }
3833: my $showstart = &Apache::lonlocal::locallocaltime($startblock);
3834: my $showend = &Apache::lonlocal::locallocaltime($endblock);
3835: $output = '<br />'.&mt('[_1] will be inaccessible between [_2] and [_3] because communication is being blocked.',$category,$showstart,$showend).'<br />';
3836: if (!($activity eq 'port' && !($ownitem) && !($is_course))) {
3837: $output .= &build_block_table($startblock,$endblock,\%setters);
3838: }
3839: }
3840: }
3841: if (wantarray) {
3842: return ($blocked,$output);
3843: } else {
3844: return $blocked;
3845: }
3846: }
3847:
3848: ###############################################
3849:
3850: sub check_ip_acc {
3851: my ($acc)=@_;
3852: &Apache::lonxml::debug("acc is $acc");
3853: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
3854: return 1;
3855: }
3856: my $allowed=0;
3857: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
3858:
3859: my $name;
3860: foreach my $pattern (split(',',$acc)) {
3861: $pattern =~ s/^\s*//;
3862: $pattern =~ s/\s*$//;
3863: if ($pattern =~ /\*$/) {
3864: #35.8.*
3865: $pattern=~s/\*//;
3866: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
3867: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
3868: #35.8.3.[34-56]
3869: my $low=$2;
3870: my $high=$3;
3871: $pattern=$1;
3872: if ($ip =~ /^\Q$pattern\E/) {
3873: my $last=(split(/\./,$ip))[3];
3874: if ($last <=$high && $last >=$low) { $allowed=1; }
3875: }
3876: } elsif ($pattern =~ /^\*/) {
3877: #*.msu.edu
3878: $pattern=~s/\*//;
3879: if (!defined($name)) {
3880: use Socket;
3881: my $netaddr=inet_aton($ip);
3882: ($name)=gethostbyaddr($netaddr,AF_INET);
3883: }
3884: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
3885: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
3886: #127.0.0.1
3887: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
3888: } else {
3889: #some.name.com
3890: if (!defined($name)) {
3891: use Socket;
3892: my $netaddr=inet_aton($ip);
3893: ($name)=gethostbyaddr($netaddr,AF_INET);
3894: }
3895: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
3896: }
3897: if ($allowed) { last; }
3898: }
3899: return $allowed;
3900: }
3901:
3902: ###############################################
3903:
3904: =pod
3905:
3906: =head1 Domain Template Functions
3907:
3908: =over 4
3909:
3910: =item * &determinedomain()
3911:
3912: Inputs: $domain (usually will be undef)
3913:
3914: Returns: Determines which domain should be used for designs
3915:
3916: =cut
3917:
3918: ###############################################
3919: sub determinedomain {
3920: my $domain=shift;
3921: if (! $domain) {
3922: # Determine domain if we have not been given one
3923: $domain = $Apache::lonnet::perlvar{'lonDefDomain'};
3924: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
3925: if ($env{'request.role.domain'}) {
3926: $domain=$env{'request.role.domain'};
3927: }
3928: }
3929: return $domain;
3930: }
3931: ###############################################
3932:
3933: sub devalidate_domconfig_cache {
3934: my ($udom)=@_;
3935: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
3936: }
3937:
3938: # ---------------------- Get domain configuration for a domain
3939: sub get_domainconf {
3940: my ($udom) = @_;
3941: my $cachetime=1800;
3942: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
3943: if (defined($cached)) { return %{$result}; }
3944:
3945: my %domconfig = &Apache::lonnet::get_dom('configuration',
3946: ['login','rolecolors'],$udom);
3947: my (%designhash,%legacy);
3948: if (keys(%domconfig) > 0) {
3949: if (ref($domconfig{'login'}) eq 'HASH') {
3950: if (keys(%{$domconfig{'login'}})) {
3951: foreach my $key (keys(%{$domconfig{'login'}})) {
3952: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
3953: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
3954: $designhash{$udom.'.login.'.$key.'_'.$img} =
3955: $domconfig{'login'}{$key}{$img};
3956: }
3957: } else {
3958: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
3959: }
3960: }
3961: } else {
3962: $legacy{'login'} = 1;
3963: }
3964: } else {
3965: $legacy{'login'} = 1;
3966: }
3967: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
3968: if (keys(%{$domconfig{'rolecolors'}})) {
3969: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
3970: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
3971: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
3972: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
3973: }
3974: }
3975: }
3976: } else {
3977: $legacy{'rolecolors'} = 1;
3978: }
3979: } else {
3980: $legacy{'rolecolors'} = 1;
3981: }
3982: if (keys(%legacy) > 0) {
3983: my %legacyhash = &get_legacy_domconf($udom);
3984: foreach my $item (keys(%legacyhash)) {
3985: if ($item =~ /^\Q$udom\E\.login/) {
3986: if ($legacy{'login'}) {
3987: $designhash{$item} = $legacyhash{$item};
3988: }
3989: } else {
3990: if ($legacy{'rolecolors'}) {
3991: $designhash{$item} = $legacyhash{$item};
3992: }
3993: }
3994: }
3995: }
3996: } else {
3997: %designhash = &get_legacy_domconf($udom);
3998: }
3999: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4000: $cachetime);
4001: return %designhash;
4002: }
4003:
4004: sub get_legacy_domconf {
4005: my ($udom) = @_;
4006: my %legacyhash;
4007: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4008: my $designfile = $designdir.'/'.$udom.'.tab';
4009: if (-e $designfile) {
4010: if ( open (my $fh,"<$designfile") ) {
4011: while (my $line = <$fh>) {
4012: next if ($line =~ /^\#/);
4013: chomp($line);
4014: my ($key,$val)=(split(/\=/,$line));
4015: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4016: }
4017: close($fh);
4018: }
4019: }
4020: if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
4021: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4022: }
4023: return %legacyhash;
4024: }
4025:
4026: =pod
4027:
4028: =item * &domainlogo()
4029:
4030: Inputs: $domain (usually will be undef)
4031:
4032: Returns: A link to a domain logo, if the domain logo exists.
4033: If the domain logo does not exist, a description of the domain.
4034:
4035: =cut
4036:
4037: ###############################################
4038: sub domainlogo {
4039: my $domain = &determinedomain(shift);
4040: my %designhash = &get_domainconf($domain);
4041: # See if there is a logo
4042: if ($designhash{$domain.'.login.domlogo'} ne '') {
4043: my $imgsrc = $designhash{$domain.'.login.domlogo'};
4044: if ($imgsrc =~ m{^/(adm|res)/}) {
4045: if ($imgsrc =~ m{^/res/}) {
4046: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4047: &Apache::lonnet::repcopy($local_name);
4048: }
4049: $imgsrc = &lonhttpdurl($imgsrc);
4050: }
4051: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
4052: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4053: return &Apache::lonnet::domain($domain,'description');
4054: } else {
4055: return '';
4056: }
4057: }
4058: ##############################################
4059:
4060: =pod
4061:
4062: =item * &designparm()
4063:
4064: Inputs: $which parameter; $domain (usually will be undef)
4065:
4066: Returns: value of designparamter $which
4067:
4068: =cut
4069:
4070:
4071: ##############################################
4072: sub designparm {
4073: my ($which,$domain)=@_;
4074: if ($env{'browser.blackwhite'} eq 'on') {
4075: if ($which=~/\.(font|alink|vlink|link|textcol)$/) {
4076: return '#000000';
4077: }
4078: if ($which=~/\.(pgbg|sidebg|bgcol)$/) {
4079: return '#FFFFFF';
4080: }
4081: if ($which=~/\.tabbg$/) {
4082: return '#CCCCCC';
4083: }
4084: }
4085: if (exists($env{'environment.color.'.$which})) {
4086: return $env{'environment.color.'.$which};
4087: }
4088: $domain=&determinedomain($domain);
4089: my %domdesign = &get_domainconf($domain);
4090: my $output;
4091: if ($domdesign{$domain.'.'.$which} ne '') {
4092: $output = $domdesign{$domain.'.'.$which};
4093: } else {
4094: $output = $defaultdesign{$which};
4095: }
4096: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
4097: ($which =~ /login\.(img|logo|domlogo|login)/)) {
4098: if ($output =~ m{^/(adm|res)/}) {
4099: if ($output =~ m{^/res/}) {
4100: my $local_name = &Apache::lonnet::filelocation('',$output);
4101: &Apache::lonnet::repcopy($local_name);
4102: }
4103: $output = &lonhttpdurl($output);
4104: }
4105: }
4106: return $output;
4107: }
4108:
4109: ###############################################
4110: ###############################################
4111:
4112: =pod
4113:
4114: =back
4115:
4116: =head1 HTML Helpers
4117:
4118: =over 4
4119:
4120: =item * &bodytag()
4121:
4122: Returns a uniform header for LON-CAPA web pages.
4123:
4124: Inputs:
4125:
4126: =over 4
4127:
4128: =item * $title, A title to be displayed on the page.
4129:
4130: =item * $function, the current role (can be undef).
4131:
4132: =item * $addentries, extra parameters for the <body> tag.
4133:
4134: =item * $bodyonly, if defined, only return the <body> tag.
4135:
4136: =item * $domain, if defined, force a given domain.
4137:
4138: =item * $forcereg, if page should register as content page (relevant for
4139: text interface only)
4140:
4141: =item * $customtitle, alternate text to use instead of $title
4142: in the title box that appears, this text
4143: is not auto translated like the $title is
4144:
4145: =item * $notopbar, if true, keep the 'what is this' info but remove the
4146: navigational links
4147:
4148: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
4149:
4150: =item * $notitle, if true keep the nav controls, but remove the title bar
4151:
4152: =item * $no_inline_link, if true and in remote mode, don't show the
4153: 'Switch To Inline Menu' link
4154:
4155: =item * $args, optional argument valid values are
4156: no_auto_mt_title -> prevents &mt()ing the title arg
4157: inherit_jsmath -> when creating popup window in a page,
4158: should it have jsmath forced on by the
4159: current page
4160:
4161: =back
4162:
4163: Returns: A uniform header for LON-CAPA web pages.
4164: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
4165: If $bodyonly is undef or zero, an html string containing a <body> tag and
4166: other decorations will be returned.
4167:
4168: =cut
4169:
4170: sub bodytag {
4171: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,$customtitle,
4172: $notopbar,$bgcolor,$notitle,$no_inline_link,$args)=@_;
4173:
4174: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
4175:
4176: $function = &get_users_function() if (!$function);
4177: my $img = &designparm($function.'.img',$domain);
4178: my $font = &designparm($function.'.font',$domain);
4179: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
4180:
4181: my %design = ( 'style' => 'margin-top: 0px',
4182: 'bgcolor' => $pgbg,
4183: 'text' => $font,
4184: 'alink' => &designparm($function.'.alink',$domain),
4185: 'vlink' => &designparm($function.'.vlink',$domain),
4186: 'link' => &designparm($function.'.link',$domain),);
4187: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
4188:
4189: # role and realm
4190: my ($role,$realm) = split(/\./,$env{'request.role'},2);
4191: if ($role eq 'ca') {
4192: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
4193: $realm = &plainname($rname,$rdom);
4194: }
4195: # realm
4196: if ($env{'request.course.id'}) {
4197: if ($env{'request.role'} !~ /^cr/) {
4198: $role = &Apache::lonnet::plaintext($role,&course_type());
4199: }
4200: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
4201: } else {
4202: $role = &Apache::lonnet::plaintext($role);
4203: }
4204:
4205: if (!$realm) { $realm=' '; }
4206: # Set messages
4207: my $messages=&domainlogo($domain);
4208:
4209: my $extra_body_attr = &make_attr_string($forcereg,\%design);
4210:
4211: # construct main body tag
4212: my $bodytag = "<body $extra_body_attr>".
4213: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
4214:
4215: if ($bodyonly) {
4216: return $bodytag;
4217: } elsif ($env{'browser.interface'} eq 'textual') {
4218: # Accessibility
4219:
4220: $bodytag.=&Apache::lonmenu::menubuttons($forcereg,$forcereg);
4221: if (!$notitle) {
4222: $bodytag.='<h1>LON-CAPA: '.$title.'</h1>';
4223: }
4224: return $bodytag;
4225: }
4226:
4227: my $name = &plainname($env{'user.name'},$env{'user.domain'});
4228: if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
4229: undef($role);
4230: } else {
4231: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
4232: }
4233:
4234: my $roleinfo=(<<ENDROLE);
4235: <td class="LC_title_bar_who">
4236: <div class="LC_title_bar_name">
4237: $name
4238:
4239: </div>
4240: <div class="LC_title_bar_role">
4241: $role
4242: </div>
4243: <div class="LC_title_bar_realm">
4244: $realm
4245: </div>
4246: </td>
4247: ENDROLE
4248:
4249: my $titleinfo = '<span class="LC_title_bar_title">'.$title.'</span>';
4250: if ($customtitle) {
4251: $titleinfo = $customtitle;
4252: }
4253: #
4254: # Extra info if you are the DC
4255: my $dc_info = '';
4256: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
4257: $env{'course.'.$env{'request.course.id'}.
4258: '.domain'}.'/'})) {
4259: my $cid = $env{'request.course.id'};
4260: $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
4261: $dc_info =~ s/\s+$//;
4262: $dc_info = '('.$dc_info.')';
4263: }
4264:
4265: if (($env{'environment.remote'} eq 'off') || ($args->{'suppress_header_logos'})) {
4266: # No Remote
4267: if ($env{'request.state'} eq 'construct') {
4268: $forcereg=1;
4269: }
4270:
4271: if (!$customtitle && $env{'request.state'} eq 'construct') {
4272: # this is for resources; directories have customtitle, and crumbs
4273: # and select recent are created in lonpubdir.pm
4274: my ($uname,$thisdisfn)=
4275: ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
4276: my $formaction='/priv/'.$uname.'/'.$thisdisfn;
4277: $formaction=~s/\/+/\//g;
4278:
4279: my $parentpath = '';
4280: my $lastitem = '';
4281: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4282: $parentpath = $1;
4283: $lastitem = $2;
4284: } else {
4285: $lastitem = $thisdisfn;
4286: }
4287: $titleinfo =
4288: &Apache::loncommon::help_open_menu('','',3,'Authoring')
4289: .'<b>'.&mt('Construction Space').'</b>: '
4290: .'<form name="dirs" method="post" action="'.$formaction
4291: .'" target="_top"><tt><b>'
4292: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."<span class=\"LC_fontsize_big\">$lastitem</span></b></tt><br />"
4293: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4294: .'</form>'
4295: .&Apache::lonmenu::constspaceform();
4296: }
4297:
4298: my $titletable;
4299: if (!$notitle) {
4300: $titletable =
4301: '<table id="LC_title_bar">'.
4302: "<tr><td> $titleinfo $dc_info</td>".$roleinfo.
4303: '</tr></table>';
4304: }
4305: if ($notopbar) {
4306: $bodytag .= $titletable;
4307: } else {
4308: if ($env{'request.state'} eq 'construct') {
4309: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg,
4310: $titletable);
4311: } else {
4312: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg).
4313: $titletable;
4314: }
4315: }
4316: return $bodytag;
4317: }
4318:
4319: #
4320: # Top frame rendering, Remote is up
4321: #
4322:
4323: my $imgsrc = $img;
4324: if ($img =~ /^\/adm/) {
4325: $imgsrc = &lonhttpdurl($img);
4326: }
4327: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
4328:
4329: # Explicit link to get inline menu
4330: my $menu= ($no_inline_link?''
4331: :'<br /><a href="/adm/remote?action=collapse">'.&mt('Switch to Inline Menu Mode').'</a>');
4332: #
4333: if ($notitle) {
4334: return $bodytag;
4335: }
4336: return(<<ENDBODY);
4337: $bodytag
4338: <table id="LC_title_bar" class="LC_with_remote">
4339: <tr><td class="LC_title_bar_role_logo">$upperleft</td>
4340: <td class="LC_title_bar_domain_logo">$messages </td>
4341: </tr>
4342: <tr><td>$titleinfo $dc_info $menu</td>
4343: $roleinfo
4344: </tr>
4345: </table>
4346: ENDBODY
4347: }
4348:
4349: sub make_attr_string {
4350: my ($register,$attr_ref) = @_;
4351:
4352: if ($attr_ref && !ref($attr_ref)) {
4353: die("addentries Must be a hash ref ".
4354: join(':',caller(1))." ".
4355: join(':',caller(0))." ");
4356: }
4357:
4358: if ($register) {
4359: my ($on_load,$on_unload);
4360: foreach my $key (keys(%{$attr_ref})) {
4361: if (lc($key) eq 'onload') {
4362: $on_load.=$attr_ref->{$key}.';';
4363: delete($attr_ref->{$key});
4364:
4365: } elsif (lc($key) eq 'onunload') {
4366: $on_unload.=$attr_ref->{$key}.';';
4367: delete($attr_ref->{$key});
4368: }
4369: }
4370: $attr_ref->{'onload'} =
4371: &Apache::lonmenu::loadevents(). $on_load;
4372: $attr_ref->{'onunload'}=
4373: &Apache::lonmenu::unloadevents().$on_unload;
4374: }
4375:
4376: # Accessibility font enhance
4377: if ($env{'browser.fontenhance'} eq 'on') {
4378: my $style;
4379: foreach my $key (keys(%{$attr_ref})) {
4380: if (lc($key) eq 'style') {
4381: $style.=$attr_ref->{$key}.';';
4382: delete($attr_ref->{$key});
4383: }
4384: }
4385: $attr_ref->{'style'}=$style.'; font-size: x-large;';
4386: }
4387:
4388: if ($env{'browser.blackwhite'} eq 'on') {
4389: delete($attr_ref->{'font'});
4390: delete($attr_ref->{'link'});
4391: delete($attr_ref->{'alink'});
4392: delete($attr_ref->{'vlink'});
4393: delete($attr_ref->{'bgcolor'});
4394: delete($attr_ref->{'background'});
4395: }
4396:
4397: my $attr_string;
4398: foreach my $attr (keys(%$attr_ref)) {
4399: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
4400: }
4401: return $attr_string;
4402: }
4403:
4404:
4405: ###############################################
4406: ###############################################
4407:
4408: =pod
4409:
4410: =item * &endbodytag()
4411:
4412: Returns a uniform footer for LON-CAPA web pages.
4413:
4414: Inputs: 1 - optional reference to an args hash
4415: If in the hash, key for noredirectlink has a value which evaluates to true,
4416: a 'Continue' link is not displayed if the page contains an
4417: internal redirect in the <head></head> section,
4418: i.e., $env{'internal.head.redirect'} exists
4419:
4420: =cut
4421:
4422: sub endbodytag {
4423: my ($args) = @_;
4424: my $endbodytag='</body>';
4425: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
4426: if ( exists( $env{'internal.head.redirect'} ) ) {
4427: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
4428: $endbodytag=
4429: "<br /><a href=\"$env{'internal.head.redirect'}\">".
4430: &mt('Continue').'</a>'.
4431: $endbodytag;
4432: }
4433: }
4434: return $endbodytag;
4435: }
4436:
4437: =pod
4438:
4439: =item * &standard_css()
4440:
4441: Returns a style sheet
4442:
4443: Inputs: (all optional)
4444: domain -> force to color decorate a page for a specific
4445: domain
4446: function -> force usage of a specific rolish color scheme
4447: bgcolor -> override the default page bgcolor
4448:
4449: =cut
4450:
4451: sub standard_css {
4452: my ($function,$domain,$bgcolor) = @_;
4453: $function = &get_users_function() if (!$function);
4454: my $img = &designparm($function.'.img', $domain);
4455: my $tabbg = &designparm($function.'.tabbg', $domain);
4456: my $font = &designparm($function.'.font', $domain);
4457: my $sidebg = &designparm($function.'.sidebg',$domain);
4458: my $pgbg_or_bgcolor =
4459: $bgcolor ||
4460: &designparm($function.'.pgbg', $domain);
4461: my $pgbg = &designparm($function.'.pgbg', $domain);
4462: my $alink = &designparm($function.'.alink', $domain);
4463: my $vlink = &designparm($function.'.vlink', $domain);
4464: my $link = &designparm($function.'.link', $domain);
4465:
4466: my $loginbg = &designparm('login.sidebg',$domain);
4467: my $bgcol = &designparm('login.bgcol',$domain);
4468: my $textcol = &designparm('login.textcol',$domain);
4469:
4470: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
4471: my $mono = 'monospace';
4472: my $data_table_head = $tabbg;
4473: my $data_table_light = '#EEEEEE';
4474: my $data_table_dark = '#DDDDDD';
4475: my $data_table_darker = '#CCCCCC';
4476: my $data_table_highlight = '#FFFF00';
4477: my $mail_new = '#FFBB77';
4478: my $mail_new_hover = '#DD9955';
4479: my $mail_read = '#BBBB77';
4480: my $mail_read_hover = '#999944';
4481: my $mail_replied = '#AAAA88';
4482: my $mail_replied_hover = '#888855';
4483: my $mail_other = '#99BBBB';
4484: my $mail_other_hover = '#669999';
4485: my $table_header = '#DDDDDD';
4486: my $feedback_link_bg = '#BBBBBB';
4487: my $lg_border_color = '#C8C8C8';
4488:
4489: my $border = ($env{'browser.type'} eq 'explorer' ||
4490: $env{'browser.type'} eq 'safari' ) ? '0px 2px 0px 2px'
4491: : '0px 3px 0px 4px';
4492:
4493:
4494: return <<END;
4495: body{
4496: font-family: $sans;
4497: line-height:130%;
4498: font-size:0.83em;
4499: color:$font;
4500: }
4501: a:link, a:visited { font-size:100%; }
4502:
4503: a:focus { color: red; background: yellow }
4504: table.thinborder,
4505: table.thinborder tr th {
4506: border-style: solid;
4507: border-width: 1px;
4508: border-color: $lg_border_color;
4509: background: $tabbg;
4510: }
4511: table.thinborder tr td {
4512: border-style: solid;
4513: border-width: 1px;
4514: border-color: $lg_border_color;
4515: }
4516:
4517: form, .inline { display: inline; }
4518:
4519: .LC_center { text-align: center; }
4520: .LC_left { text-align:left; }
4521: .LC_right {text-align:right;}
4522: .LC_middle {vertical-align:middle;}
4523: .LC_top {vertical-align:top;}
4524: .LC_bottom {vertical-align:bottom;}
4525:
4526: /* just for tests */
4527: .LC_300Box { width:300px; }
4528: .LC_200Box {width:200px; }
4529: .LC_500Box {width:500px; }
4530: .LC_600Box {width:600px; }
4531: .LC_800Box {width:800px;}
4532: /* end */
4533:
4534: .LC_filename {font-family: $mono; white-space:pre;}
4535: .LC_error {
4536: color: red;
4537: font-size: larger;
4538: }
4539: .LC_warning,
4540: .LC_diff_removed {
4541: color: red;
4542: }
4543:
4544: .LC_info,
4545: .LC_success,
4546: .LC_diff_added {
4547: color: green;
4548: }
4549: .LC_unknown {
4550: color: yellow;
4551: }
4552:
4553: .LC_icon {
4554: border: 0px;
4555: }
4556: .LC_indexer_icon {
4557: border: 0px;
4558: height: 22px;
4559: }
4560: .LC_docs_spacer {
4561: width: 25px;
4562: height: 1px;
4563: border: 0px;
4564: }
4565:
4566: .LC_internal_info {
4567: color: #999999;
4568: }
4569:
4570: table.LC_pastsubmission {
4571: border: 1px solid black;
4572: margin: 2px;
4573: }
4574:
4575: table#LC_top_nav, table#LC_menubuttons,table#LC_nav_location {
4576: width: 100%;
4577: background: $pgbg;
4578: border: 2px;
4579: border-collapse: separate;
4580: padding: 0px;
4581: }
4582:
4583: table#LC_title_bar, table.LC_breadcrumbs,
4584: table#LC_title_bar.LC_with_remote {
4585: width: 100%;
4586: border-color: $pgbg;
4587: border-style: solid;
4588: border-width: $border;
4589:
4590: background: $pgbg;
4591: font-family: $sans;
4592: border-collapse: collapse;
4593: padding: 0px;
4594: }
4595: table.LC_docs_path {
4596: width: 100%;
4597: border: 0;
4598: background: $pgbg;
4599: font-family: $sans;
4600: border-collapse: collapse;
4601: padding: 0px;
4602: }
4603:
4604: table#LC_title_bar td {
4605: background: $tabbg;
4606: }
4607: table#LC_title_bar td.LC_title_bar_who {
4608: background: $tabbg;
4609: color: $font;
4610: font: small $sans;
4611: text-align: right;
4612: }
4613: span.LC_metadata {
4614: font-family: $sans;
4615: }
4616: span.LC_title_bar_title {
4617: font: bold x-large $sans;
4618: }
4619: table#LC_title_bar td.LC_title_bar_domain_logo {
4620: background: $sidebg;
4621: text-align: right;
4622: padding: 0px;
4623: }
4624: table#LC_title_bar td.LC_title_bar_role_logo {
4625: background: $sidebg;
4626: padding: 0px;
4627: }
4628:
4629: table#LC_menubuttons img{
4630: border: 0px;
4631: }
4632: table#LC_top_nav td {
4633: background: $tabbg;
4634: border: 0px;
4635: font-size: small;
4636: vertical-align:top;
4637: padding:2px 5px 2px 5px;
4638: }
4639: table#LC_top_nav td a, div#LC_top_nav a {
4640: color: $font;
4641: font-family: $sans;
4642: }
4643: table#LC_top_nav td.LC_top_nav_logo {
4644: background: $tabbg;
4645: text-align: left;
4646: white-space: nowrap;
4647: width: 31px;
4648: }
4649: table#LC_top_nav td.LC_top_nav_logo img {
4650: border: 0px;
4651: vertical-align: bottom;
4652: }
4653: table#LC_top_nav td.LC_top_nav_exit,
4654: table#LC_top_nav td.LC_top_nav_help {
4655: width: 2.0em;
4656: }
4657: table#LC_top_nav td.LC_top_nav_login {
4658: width: 4.0em;
4659: text-align: center;
4660: }
4661: table.LC_breadcrumbs td, table.LC_docs_path td {
4662: background: $tabbg;
4663: color: $font;
4664: font-family: $sans;
4665: font-size: smaller;
4666: }
4667: table.LC_breadcrumbs td.LC_breadcrumbs_component,
4668: table.LC_docs_path td.LC_docs_path_component {
4669: background: $tabbg;
4670: color: $font;
4671: font-family: $sans;
4672: font-size: larger;
4673: text-align: right;
4674: }
4675: td.LC_table_cell_checkbox {
4676: text-align: center;
4677: }
4678: table#LC_mainmenu td.LC_mainmenu_column {
4679: vertical-align: top;
4680: }
4681:
4682: .LC_fontsize_small
4683: {
4684: font-size: 70%;
4685: }
4686:
4687: .LC_fontsize_medium
4688: {
4689: font-size: 85%;
4690: }
4691:
4692: .LC_fontsize_large
4693: {
4694: font-size: 120%;
4695: }
4696:
4697: .LC_fontcolor_red
4698: {
4699: color: #FF0000;
4700: }
4701:
4702: .LC_menubuttons_inline_text {
4703: color: $font;
4704: font-family: $sans;
4705: font-size: 90%;
4706: padding-left:3px;
4707: }
4708:
4709: .LC_menubuttons_link {
4710: text-decoration: none;
4711: }
4712: /*2008--9-5: new menu style sheet.Changed category*/
4713: .LC_menubuttons_category {
4714: color: $font;
4715: background: $pgbg;
4716: font-family: $sans;
4717: font-size: larger;
4718: font-weight: bold;
4719: }
4720:
4721: td.LC_menubuttons_text {
4722: color: $font;
4723: }
4724:
4725:
4726:
4727: .LC_current_location {
4728: font-family: $sans;
4729: background: $tabbg;
4730: }
4731: .LC_new_mail {
4732: font-family: $sans;
4733: background: $tabbg;
4734: font-weight: bold;
4735: }
4736:
4737:
4738: .LC_dropadd_labeltext {
4739: font-family: $sans;
4740: text-align: right;
4741: }
4742:
4743: .LC_preferences_labeltext {
4744: font-family: $sans;
4745: text-align: right;
4746: }
4747:
4748: .LC_roleslog_note {
4749: font-size: small;
4750: }
4751:
4752: .LC_mail_functions {
4753: font-weight: bold;
4754: }
4755:
4756: table.LC_aboutme_port {
4757: border: 0px;
4758: border-collapse: collapse;
4759: border-spacing: 0px;
4760: }
4761: table.LC_data_table, table.LC_mail_list {
4762: border: 1px solid #000000;
4763: border-collapse: separate;
4764: border-spacing: 1px;
4765: background: $pgbg;
4766: }
4767: .LC_data_table_dense {
4768: font-size: small;
4769: }
4770: table.LC_nested_outer {
4771: border: 1px solid #000000;
4772: border-collapse: collapse;
4773: border-spacing: 0px;
4774: width: 100%;
4775: }
4776: table.LC_nested {
4777: border: 0px;
4778: border-collapse: collapse;
4779: border-spacing: 0px;
4780: width: 100%;
4781: }
4782: table.LC_data_table tr th, table.LC_calendar tr th, table.LC_mail_list tr th,
4783: table.LC_prior_tries tr th {
4784: font-weight: bold;
4785: background-color: $data_table_head;
4786: font-size:90%;
4787: }
4788: table.LC_data_table tr.LC_info_row > td {
4789: background-color: #CCCCCC;
4790: font-weight: bold;
4791: text-align: left;
4792: }
4793: table.LC_data_table tr.LC_odd_row > td,
4794: table.LC_pick_box tr > td.LC_odd_row,
4795: table.LC_aboutme_port tr td {
4796: background-color: $data_table_light;
4797: padding: 2px;
4798: }
4799: table.LC_data_table tr.LC_even_row > td,
4800: table.LC_pick_box tr > td.LC_even_row,
4801: table.LC_aboutme_port tr.LC_even_row td {
4802: background-color: $data_table_dark;
4803: padding: 2px;
4804: }
4805: table.LC_data_table tr.LC_data_table_highlight td {
4806: background-color: $data_table_darker;
4807: }
4808: table.LC_data_table tr td.LC_leftcol_header {
4809: background-color: $data_table_head;
4810: font-weight: bold;
4811: }
4812: table.LC_data_table tr.LC_empty_row td,
4813: table.LC_nested tr.LC_empty_row td {
4814: background-color: #FFFFFF;
4815: font-weight: bold;
4816: font-style: italic;
4817: text-align: center;
4818: padding: 8px;
4819: }
4820: table.LC_nested tr.LC_empty_row td {
4821: padding: 4ex
4822: }
4823: table.LC_nested_outer tr th {
4824: font-weight: bold;
4825: background-color: $data_table_head;
4826: font-size: small;
4827: border-bottom: 1px solid #000000;
4828: }
4829: table.LC_nested_outer tr td.LC_subheader {
4830: background-color: $data_table_head;
4831: font-weight: bold;
4832: font-size: small;
4833: border-bottom: 1px solid #000000;
4834: text-align: right;
4835: }
4836: table.LC_nested tr.LC_info_row td {
4837: background-color: #CCCCCC;
4838: font-weight: bold;
4839: font-size: small;
4840: text-align: center;
4841: }
4842: table.LC_nested tr.LC_info_row td.LC_left_item,
4843: table.LC_nested_outer tr th.LC_left_item {
4844: text-align: left;
4845: }
4846: table.LC_nested td {
4847: background-color: #FFFFFF;
4848: font-size: small;
4849: }
4850: table.LC_nested_outer tr th.LC_right_item,
4851: table.LC_nested tr.LC_info_row td.LC_right_item,
4852: table.LC_nested tr.LC_odd_row td.LC_right_item,
4853: table.LC_nested tr td.LC_right_item {
4854: text-align: right;
4855: }
4856:
4857: table.LC_nested tr.LC_odd_row td {
4858: background-color: #EEEEEE;
4859: }
4860:
4861: table.LC_createuser {
4862: }
4863:
4864: table.LC_createuser tr.LC_section_row td {
4865: font-size: small;
4866: }
4867:
4868: table.LC_createuser tr.LC_info_row td {
4869: background-color: #CCCCCC;
4870: font-weight: bold;
4871: text-align: center;
4872: }
4873:
4874: table.LC_calendar {
4875: border: 1px solid #000000;
4876: border-collapse: collapse;
4877: }
4878: table.LC_calendar_pickdate {
4879: font-size: xx-small;
4880: }
4881: table.LC_calendar tr td {
4882: border: 1px solid #000000;
4883: vertical-align: top;
4884: }
4885: table.LC_calendar tr td.LC_calendar_day_empty {
4886: background-color: $data_table_dark;
4887: }
4888: table.LC_calendar tr td.LC_calendar_day_current {
4889: background-color: $data_table_highlight;
4890: }
4891:
4892: table.LC_mail_list tr.LC_mail_new {
4893: background-color: $mail_new;
4894: }
4895: table.LC_mail_list tr.LC_mail_new:hover {
4896: background-color: $mail_new_hover;
4897: }
4898: table.LC_mail_list tr.LC_mail_read {
4899: background-color: $mail_read;
4900: }
4901: table.LC_mail_list tr.LC_mail_read:hover {
4902: background-color: $mail_read_hover;
4903: }
4904: table.LC_mail_list tr.LC_mail_replied {
4905: background-color: $mail_replied;
4906: }
4907: table.LC_mail_list tr.LC_mail_replied:hover {
4908: background-color: $mail_replied_hover;
4909: }
4910: table.LC_mail_list tr.LC_mail_other {
4911: background-color: $mail_other;
4912: }
4913: table.LC_mail_list tr.LC_mail_other:hover {
4914: background-color: $mail_other_hover;
4915: }
4916: table.LC_mail_list tr.LC_mail_even {
4917: }
4918: table.LC_mail_list tr.LC_mail_odd {
4919: }
4920:
4921: table.LC_data_table tr > td.LC_browser_file,
4922: table.LC_data_table tr > td.LC_browser_file_published {
4923: background: #CCFF88;
4924: }
4925: table.LC_data_table tr > td.LC_browser_file_locked,
4926: table.LC_data_table tr > td.LC_browser_file_unpublished {
4927: background: #FFAA99;
4928: }
4929: table.LC_data_table tr > td.LC_browser_file_obsolete {
4930: background: #AAAAAA;
4931: }
4932: table.LC_data_table tr > td.LC_browser_file_modified,
4933: table.LC_data_table tr > td.LC_browser_file_metamodified {
4934: background: #FFFF77;
4935: }
4936: table.LC_data_table tr.LC_browser_folder > td {
4937: background: #CCCCFF;
4938: }
4939:
4940: table.LC_data_table tr > td.LC_roles_is {
4941: /* background: #77FF77; */
4942: }
4943: table.LC_data_table tr > td.LC_roles_future {
4944: background: #FFFF77;
4945: }
4946: table.LC_data_table tr > td.LC_roles_will {
4947: background: #FFAA77;
4948: }
4949: table.LC_data_table tr > td.LC_roles_expired {
4950: background: #FF7777;
4951: }
4952: table.LC_data_table tr > td.LC_roles_will_not {
4953: background: #AAFF77;
4954: }
4955: table.LC_data_table tr > td.LC_roles_selected {
4956: background: #11CC55;
4957: }
4958:
4959: span.LC_current_location {
4960: font-size:larger;
4961: background: $pgbg;
4962: }
4963:
4964: span.LC_parm_menu_item {
4965: font-size: larger;
4966: font-family: $sans;
4967: }
4968: span.LC_parm_scope_all {
4969: color: red;
4970: }
4971: span.LC_parm_scope_folder {
4972: color: green;
4973: }
4974: span.LC_parm_scope_resource {
4975: color: orange;
4976: }
4977: span.LC_parm_part {
4978: color: blue;
4979: }
4980: span.LC_parm_folder, span.LC_parm_symb {
4981: font-size: x-small;
4982: font-family: $mono;
4983: color: #AAAAAA;
4984: }
4985:
4986: td.LC_parm_overview_level_menu, td.LC_parm_overview_map_menu,
4987: td.LC_parm_overview_parm_selectors, td.LC_parm_overview_parm_restrictions {
4988: border: 1px solid black;
4989: border-collapse: collapse;
4990: }
4991: table.LC_parm_overview_restrictions td {
4992: border-width: 1px 4px 1px 4px;
4993: border-style: solid;
4994: border-color: $pgbg;
4995: text-align: center;
4996: }
4997: table.LC_parm_overview_restrictions th {
4998: background: $tabbg;
4999: border-width: 1px 4px 1px 4px;
5000: border-style: solid;
5001: border-color: $pgbg;
5002: }
5003: table#LC_helpmenu {
5004: border: 0px;
5005: height: 55px;
5006: border-spacing: 0px;
5007: }
5008:
5009: table#LC_helpmenu fieldset legend {
5010: font-size: larger;
5011: font-weight: bold;
5012: }
5013: table#LC_helpmenu_links {
5014: width: 100%;
5015: border: 1px solid black;
5016: background: $pgbg;
5017: padding: 0px;
5018: border-spacing: 1px;
5019: }
5020: table#LC_helpmenu_links tr td {
5021: padding: 1px;
5022: background: $tabbg;
5023: text-align: center;
5024: font-weight: bold;
5025: }
5026:
5027: table#LC_helpmenu_links a:link, table#LC_helpmenu_links a:visited,
5028: table#LC_helpmenu_links a:active {
5029: text-decoration: none;
5030: color: $font;
5031: }
5032: table#LC_helpmenu_links a:hover {
5033: text-decoration: underline;
5034: color: $vlink;
5035: }
5036:
5037: .LC_chrt_popup_exists {
5038: border: 1px solid #339933;
5039: margin: -1px;
5040: }
5041: .LC_chrt_popup_up {
5042: border: 1px solid yellow;
5043: margin: -1px;
5044: }
5045: .LC_chrt_popup {
5046: border: 1px solid #8888FF;
5047: background: #CCCCFF;
5048: }
5049: table.LC_pick_box {
5050: border-collapse: separate;
5051: background: white;
5052: border: 1px solid black;
5053: border-spacing: 1px;
5054: }
5055: table.LC_pick_box td.LC_pick_box_title {
5056: background: $tabbg;
5057: font-weight: bold;
5058: text-align: right;
5059: vertical-align: top;
5060: width: 184px;
5061: padding: 8px;
5062: }
5063: table.LC_pick_box td.LC_selfenroll_pick_box_title {
5064: background: $tabbg;
5065: font-weight: bold;
5066: text-align: right;
5067: width: 350px;
5068: padding: 8px;
5069: }
5070:
5071: table.LC_pick_box td.LC_pick_box_value {
5072: text-align: left;
5073: padding: 8px;
5074: }
5075: table.LC_pick_box td.LC_pick_box_select {
5076: text-align: left;
5077: padding: 8px;
5078: }
5079: table.LC_pick_box td.LC_pick_box_separator {
5080: padding: 0px;
5081: height: 1px;
5082: background: black;
5083: }
5084: table.LC_pick_box td.LC_pick_box_submit {
5085: text-align: right;
5086: }
5087: table.LC_pick_box td.LC_evenrow_value {
5088: text-align: left;
5089: padding: 8px;
5090: background-color: $data_table_light;
5091: }
5092: table.LC_pick_box td.LC_oddrow_value {
5093: text-align: left;
5094: padding: 8px;
5095: background-color: $data_table_light;
5096: }
5097: table.LC_helpform_receipt {
5098: width: 620px;
5099: border-collapse: separate;
5100: background: white;
5101: border: 1px solid black;
5102: border-spacing: 1px;
5103: }
5104: table.LC_helpform_receipt td.LC_pick_box_title {
5105: background: $tabbg;
5106: font-weight: bold;
5107: text-align: right;
5108: width: 184px;
5109: padding: 8px;
5110: }
5111: table.LC_helpform_receipt td.LC_evenrow_value {
5112: text-align: left;
5113: padding: 8px;
5114: background-color: $data_table_light;
5115: }
5116: table.LC_helpform_receipt td.LC_oddrow_value {
5117: text-align: left;
5118: padding: 8px;
5119: background-color: $data_table_light;
5120: }
5121: table.LC_helpform_receipt td.LC_pick_box_separator {
5122: padding: 0px;
5123: height: 1px;
5124: background: black;
5125: }
5126: span.LC_helpform_receipt_cat {
5127: font-weight: bold;
5128: }
5129: table.LC_group_priv_box {
5130: background: white;
5131: border: 1px solid black;
5132: border-spacing: 1px;
5133: }
5134: table.LC_group_priv_box td.LC_pick_box_title {
5135: background: $tabbg;
5136: font-weight: bold;
5137: text-align: right;
5138: width: 184px;
5139: }
5140: table.LC_group_priv_box td.LC_groups_fixed {
5141: background: $data_table_light;
5142: text-align: center;
5143: }
5144: table.LC_group_priv_box td.LC_groups_optional {
5145: background: $data_table_dark;
5146: text-align: center;
5147: }
5148: table.LC_group_priv_box td.LC_groups_functionality {
5149: background: $data_table_darker;
5150: text-align: center;
5151: font-weight: bold;
5152: }
5153: table.LC_group_priv td {
5154: text-align: left;
5155: padding: 0px;
5156: }
5157:
5158: table.LC_notify_front_page {
5159: background: white;
5160: border: 1px solid black;
5161: padding: 8px;
5162: }
5163: table.LC_notify_front_page td {
5164: padding: 8px;
5165: }
5166: .LC_navbuttons {
5167: margin: 2ex 0ex 2ex 0ex;
5168: }
5169: .LC_topic_bar {
5170: font-family: $sans;
5171: font-weight: bold;
5172: width: 100%;
5173: background: $tabbg;
5174: vertical-align: middle;
5175: margin: 2ex 0ex 2ex 0ex;
5176: }
5177: .LC_topic_bar span {
5178: vertical-align: middle;
5179: }
5180: .LC_topic_bar img {
5181: vertical-align: bottom;
5182: }
5183: table.LC_course_group_status {
5184: margin: 20px;
5185: }
5186: table.LC_status_selector td {
5187: vertical-align: top;
5188: text-align: center;
5189: padding: 4px;
5190: }
5191: table.LC_descriptive_input td.LC_description {
5192: vertical-align: top;
5193: text-align: right;
5194: font-weight: bold;
5195: }
5196: div.LC_feedback_link {
5197: clear: both;
5198: background: white;
5199: width: 100%;
5200: }
5201: span.LC_feedback_link {
5202: background: $feedback_link_bg;
5203: font-size: larger;
5204: }
5205: span.LC_message_link {
5206: background: $feedback_link_bg;
5207: font-size: larger;
5208: position: absolute;
5209: right: 1em;
5210: }
5211:
5212: table.LC_prior_tries {
5213: border: 1px solid #000000;
5214: border-collapse: separate;
5215: border-spacing: 1px;
5216: }
5217:
5218: table.LC_prior_tries td {
5219: padding: 2px;
5220: }
5221:
5222: .LC_answer_correct {
5223: background: #AAFFAA;
5224: color: black;
5225: }
5226: .LC_answer_charged_try {
5227: background: #FFAAAA ! important;
5228: color: black;
5229: }
5230: .LC_answer_not_charged_try,
5231: .LC_answer_no_grade,
5232: .LC_answer_late {
5233: background: #FFFFAA;
5234: color: black;
5235: }
5236: .LC_answer_previous {
5237: background: #AAAAFF;
5238: color: black;
5239: }
5240: .LC_answer_no_message {
5241: background: #FFFFFF;
5242: color: black;
5243: }
5244: .LC_answer_unknown {
5245: background: orange;
5246: color: black;
5247: }
5248:
5249:
5250: span.LC_prior_numerical,
5251: span.LC_prior_string,
5252: span.LC_prior_custom,
5253: span.LC_prior_reaction,
5254: span.LC_prior_math {
5255: font-family: monospace;
5256: white-space: pre;
5257: }
5258:
5259: span.LC_prior_string {
5260: font-family: monospace;
5261: white-space: pre;
5262: }
5263:
5264: table.LC_prior_option {
5265: width: 100%;
5266: border-collapse: collapse;
5267: }
5268: table.LC_prior_rank, table.LC_prior_match {
5269: border-collapse: collapse;
5270: }
5271: table.LC_prior_option tr td,
5272: table.LC_prior_rank tr td,
5273: table.LC_prior_match tr td {
5274: border: 1px solid #000000;
5275: }
5276:
5277: span.LC_nobreak {
5278: white-space: nowrap;
5279: }
5280:
5281: span.LC_cusr_emph {
5282: font-style: italic;
5283: }
5284:
5285: span.LC_cusr_subheading {
5286: font-weight: normal;
5287: font-size: 85%;
5288: }
5289:
5290: table.LC_docs_documents {
5291: background: #BBBBBB;
5292: border-width: 0px;
5293: border-collapse: collapse;
5294: }
5295:
5296: table.LC_docs_documents td.LC_docs_document {
5297: border: 2px solid black;
5298: padding: 4px;
5299: }
5300:
5301: .LC_docs_entry_move {
5302: border: 0px;
5303: border-collapse: collapse;
5304: }
5305:
5306: .LC_docs_entry_move td {
5307: border: 2px solid #BBBBBB;
5308: background: #DDDDDD;
5309: }
5310:
5311: .LC_docs_editor td.LC_docs_entry_commands {
5312: background: #DDDDDD;
5313: font-size: x-small;
5314: }
5315: .LC_docs_copy {
5316: color: #000099;
5317: }
5318: .LC_docs_cut {
5319: color: #550044;
5320: }
5321: .LC_docs_rename {
5322: color: #009900;
5323: }
5324: .LC_docs_remove {
5325: color: #990000;
5326: }
5327:
5328: .LC_docs_reinit_warn,
5329: .LC_docs_ext_edit {
5330: font-size: x-small;
5331: }
5332:
5333: .LC_docs_editor td.LC_docs_entry_title,
5334: .LC_docs_editor td.LC_docs_entry_icon {
5335: background: #FFFFBB;
5336: }
5337: .LC_docs_editor td.LC_docs_entry_parameter {
5338: background: #BBBBFF;
5339: font-size: x-small;
5340: white-space: nowrap;
5341: }
5342:
5343: table.LC_docs_adddocs td,
5344: table.LC_docs_adddocs th {
5345: border: 1px solid #BBBBBB;
5346: padding: 4px;
5347: background: #DDDDDD;
5348: }
5349:
5350: table.LC_sty_begin {
5351: background: #BBFFBB;
5352: }
5353: table.LC_sty_end {
5354: background: #FFBBBB;
5355: }
5356:
5357: table.LC_double_column {
5358: border-width: 0px;
5359: border-collapse: collapse;
5360: width: 100%;
5361: padding: 2px;
5362: }
5363:
5364: table.LC_double_column tr td.LC_left_col {
5365: top: 2px;
5366: left: 2px;
5367: width: 47%;
5368: vertical-align: top;
5369: }
5370:
5371: table.LC_double_column tr td.LC_right_col {
5372: top: 2px;
5373: right: 2px;
5374: width: 47%;
5375: vertical-align: top;
5376: }
5377:
5378: span.LC_role_level {
5379: font-weight: bold;
5380: }
5381:
5382: div.LC_left_float {
5383: float: left;
5384: padding-right: 5%;
5385: padding-bottom: 4px;
5386: }
5387:
5388: div.LC_clear_float_header {
5389: padding-bottom: 2px;
5390: }
5391:
5392: div.LC_clear_float_footer {
5393: padding-top: 10px;
5394: clear: both;
5395: }
5396:
5397:
5398: div.LC_grade_show_user {
5399: margin-top: 20px;
5400: border: 1px solid black;
5401: }
5402: div.LC_grade_user_name {
5403: background: #DDDDEE;
5404: border-bottom: 1px solid black;
5405: font-weight: bold;
5406: font-size: large;
5407: }
5408: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
5409: background: #DDEEDD;
5410: }
5411:
5412: div.LC_grade_show_problem,
5413: div.LC_grade_submissions,
5414: div.LC_grade_message_center,
5415: div.LC_grade_info_links,
5416: div.LC_grade_assign {
5417: margin: 5px;
5418: width: 99%;
5419: background: #FFFFFF;
5420: }
5421: div.LC_grade_show_problem_header,
5422: div.LC_grade_submissions_header,
5423: div.LC_grade_message_center_header,
5424: div.LC_grade_assign_header {
5425: font-weight: bold;
5426: font-size: large;
5427: }
5428: div.LC_grade_show_problem_problem,
5429: div.LC_grade_submissions_body,
5430: div.LC_grade_message_center_body,
5431: div.LC_grade_assign_body {
5432: border: 1px solid black;
5433: width: 99%;
5434: background: #FFFFFF;
5435: }
5436: span.LC_grade_check_note {
5437: font-weight: normal;
5438: font-size: medium;
5439: display: inline;
5440: position: absolute;
5441: right: 1em;
5442: }
5443:
5444: table.LC_scantron_action {
5445: width: 100%;
5446: }
5447: table.LC_scantron_action tr th {
5448: font-weight:bold;
5449: font-style:normal;
5450: }
5451: .LC_edit_problem_header,
5452: div.LC_edit_problem_footer {
5453: font-weight: normal;
5454: font-size: medium;
5455: margin: 2px;
5456: }
5457: div.LC_edit_problem_header,
5458: div.LC_edit_problem_header div,
5459: div.LC_edit_problem_footer,
5460: div.LC_edit_problem_footer div,
5461: div.LC_edit_problem_editxml_header,
5462: div.LC_edit_problem_editxml_header div {
5463: margin-top: 5px;
5464: }
5465: div.LC_edit_problem_header_edit_row {
5466: background: $tabbg;
5467: padding: 3px;
5468: margin-bottom: 5px;
5469: }
5470: div.LC_edit_problem_header_title {
5471: font-weight: bold;
5472: font-size: larger;
5473: background: $tabbg;
5474: padding: 3px;
5475: }
5476: table.LC_edit_problem_header_title {
5477: font-size: larger;
5478: font-weight: bold;
5479: width: 100%;
5480: border-color: $pgbg;
5481: border-style: solid;
5482: border-width: $border;
5483:
5484: background: $tabbg;
5485: border-collapse: collapse;
5486: padding: 0px
5487: }
5488:
5489: div.LC_edit_problem_discards {
5490: float: left;
5491: padding-bottom: 5px;
5492: }
5493: div.LC_edit_problem_saves {
5494: float: right;
5495: padding-bottom: 5px;
5496: }
5497: hr.LC_edit_problem_divide {
5498: clear: both;
5499: color: $tabbg;
5500: background-color: $tabbg;
5501: height: 3px;
5502: border: 0px;
5503: }
5504: img.stift{
5505: border-width:0;
5506: vertical-align:middle;
5507: }
5508:
5509: table#LC_mainmenu{
5510: margin-top:10px;
5511: width:80%;
5512:
5513: }
5514:
5515: table#LC_mainmenu td.LC_mainmenu_col_fieldset{
5516: vertical-align: top;
5517: width: 45%;
5518: }
5519: .LC_mainmenu_fieldset_category {
5520: color: $font;
5521: background: $pgbg;
5522: font-family: $sans;
5523: font-size: small;
5524: font-weight: bold;
5525: }
5526:
5527: div.LC_createcourse {
5528: margin: 10px 10px 10px 10px;
5529: }
5530:
5531: /* ---- Remove when done ----
5532: # The following styles is part of the redesign of LON-CAPA and are
5533: # subject to change during this project.
5534: # Don't rely on their current functionality as they might be
5535: # changed or removed.
5536: # --------------------------*/
5537:
5538: a:hover,
5539: ol.LC_smallMenu a:hover,
5540: ol#LC_MenuBreadcrumbs a:hover,
5541: ol#LC_PathBreadcrumbs a:hover,
5542: ul#LC_TabMainMenuContent a:hover,
5543: .LC_FormSectionClearButton input:hover
5544: ul.LC_TabContent li:hover a{
5545: color:#BF2317;
5546: text-decoration:none;
5547: }
5548:
5549: h1 {
5550: padding:5px 10px 5px 20px;
5551: line-height:130%;
5552: }
5553:
5554: h2,h3,h4,h5,h6
5555: {
5556: margin:5px 0px 5px 0px;
5557: padding:0px;
5558: line-height:130%;
5559: }
5560: .LC_hcell{
5561: padding:3px 15px 3px 15px;
5562: margin:0px;
5563: background-color:$tabbg;
5564: border-bottom:solid 1px $lg_border_color;
5565: }
5566: .LC_noBorder {
5567: border:0px;
5568: }
5569:
5570: .LC_bgLightGrey{
5571: background:URL(/adm/lonIcons/lightGreyBG.png) repeat-x left bottom;
5572: }
5573:
5574:
5575: /* Main Header with discription of Person, Course, etc. */
5576: .LC_HeadRight {
5577: text-align: right;
5578: float: right;
5579: margin: 0px;
5580: padding: 0px;
5581: right:0;
5582: position:absolute;
5583: overflow:hidden;
5584: }
5585:
5586: p, .LC_ContentBox {
5587: padding: 10px;
5588:
5589: }
5590: .LC_FormSectionClearButton input {
5591: background-color:transparent;
5592: border:0px;
5593: cursor:pointer;
5594: text-decoration:underline;
5595: }
5596:
5597:
5598: dl,ul,div,fieldset {
5599: margin: 10px 10px 10px 0px;
5600: overflow:hidden;
5601: }
5602: ol.LC_smallMenu, ol#LC_PathBreadcrumbs {
5603: margin: 0px;
5604: }
5605:
5606: ol.LC_smallMenu li {
5607: display: inline;
5608: padding: 5px 5px 0px 10px;
5609: vertical-align: top;
5610: }
5611:
5612: ol.LC_smallMenu li img {
5613: vertical-align: bottom;
5614: }
5615:
5616: ol.LC_smallMenu a {
5617: font-size: 90%;
5618: color: RGB(80, 80, 80);
5619: text-decoration: none;
5620: }
5621: ol#LC_TabMainMenueContent, ul.LC_TabContent,
5622: ul.LC_TabContentBigger {
5623: display:block;
5624: list-style:none;
5625: margin: 0px;
5626: padding: 0px;
5627: }
5628:
5629: ol#LC_TabMainMenuContent li, ul.LC_TabContent,
5630: ul.LC_TabContentBigger li{
5631: display: inline;
5632: border-right: solid 1px $lg_border_color;
5633: float:left;
5634: line-height:140%;
5635: white-space:nowrap;
5636: }
5637: ol#LC_TabMainMenuContent li{
5638: vertical-align: bottom;
5639: border-bottom: solid 1px RGB(175, 175, 175);
5640: padding: 5px 10px 5px 10px;
5641: margin-right:5px;
5642: margin-bottom:3px;
5643: font-weight: bold;
5644: background: url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
5645: }
5646:
5647: ol#LC_TabMainMenuContent li a{
5648: color: RGB(47, 47, 47);
5649: text-decoration: none;
5650: }
5651: ul.LC_TabContent {
5652: min-height:1.6em;
5653: border-bottom:solid 1px $lg_border_color;
5654: }
5655: ul.LC_TabContent li{
5656: vertical-align:middle;
5657: padding:0px 10px 0px 10px;
5658: }
5659: ul.LC_TabContent li a, ul.LC_TabContent li{
5660: color:rgb(47,47,47);
5661: text-decoration:none;
5662: font-size:95%;
5663: font-weight:bold;
5664: }
5665: ul.LC_TabContentBigger li{
5666: vertical-align:bottom;
5667: border-top:solid 1px $lg_border_color;
5668: border-left:solid 1px $lg_border_color;
5669: padding:5px 10px 5px 10px;
5670: margin-left:2px;
5671: background:url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
5672: }
5673: ul.LC_TabContentBigger li, ul.LC_TabContentBigger li a{
5674: font-size:110%;
5675: font-weight:bold;
5676: }
5677: #LC_CourseDocuments, #LC_SupplementalCourseDocuments
5678: {
5679: margin:0px;
5680: }
5681:
5682: .LC_hideThis
5683: {
5684: display:none;
5685: visibility:hidden;
5686: }
5687:
5688: ol#LC_MenuBreadcrumbs, ol#LC_PathBreadcrumbs {
5689: border-top: solid 1px RGB(255, 255, 255);
5690: height: 20px;
5691: line-height: 20px;
5692: vertical-align: bottom;
5693: margin: 0px 0px 30px 0px;
5694: padding-left: 10px;
5695: list-style-position: inside;
5696: background: url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
5697: }
5698:
5699: ol#LC_MenuBreadcrumbs li, ol#LC_PathBreadcrumbs li {
5700: /*
5701: background: url(/adm/lonIcons/arrow_white.png) no-repeat left center;
5702: */
5703: display: inline;
5704: padding: 0px 0px 0px 10px;
5705: vertical-align: bottom;
5706: overflow:hidden;
5707: }
5708:
5709: ol#LC_MenuBreadcrumbs li a {
5710: text-decoration: none;
5711: font-size:90%;
5712: }
5713: ol#LC_PathBreadcrumbs li a{
5714: text-decoration:none;
5715: font-size:100%;
5716: font-weight:bold;
5717: }
5718: .LC_ContentBoxSpecial
5719: {
5720: border: solid 1px $lg_border_color;
5721: }
5722:
5723: dl.LC_ListStyleClean dt {
5724: padding-right: 5px;
5725: display: table-header-group;
5726: }
5727:
5728: dl.LC_ListStyleClean dd {
5729: display: table-row;
5730: }
5731:
5732: .LC_ListStyleClean,
5733: .LC_ListStyleSimple,
5734: .LC_ListStyleNormal,
5735: .LC_ListStyleNormal_Border,
5736: .LC_ListStyleSpecial
5737: {
5738: /*display:block; */
5739: list-style-position: inside;
5740: list-style-type: none;
5741: overflow: hidden;
5742: padding: 0px;
5743: }
5744:
5745: .LC_ListStyleSimple li,
5746: .LC_ListStyleSimple dd,
5747: .LC_ListStyleNormal li,
5748: .LC_ListStyleNormal dd,
5749: .LC_ListStyleSpecial li,
5750: .LC_ListStyleSpecial dd
5751: {
5752: margin: 0px;
5753: padding: 5px 5px 5px 10px;
5754: clear: both;
5755: }
5756:
5757: .LC_ListStyleClean li,
5758: .LC_ListStyleClean dd {
5759: padding-top: 0px;
5760: padding-bottom: 0px;
5761: }
5762:
5763: .LC_ListStyleSimple dd,
5764: .LC_ListStyleSimple li{
5765: border-bottom: solid 1px $lg_border_color;
5766: }
5767:
5768: .LC_ListStyleSpecial li,
5769: .LC_ListStyleSpecial dd {
5770: list-style-type: none;
5771: background-color: RGB(220, 220, 220);
5772: margin-bottom: 4px;
5773: }
5774:
5775: table.LC_SimpleTable {
5776: margin:5px;
5777: border:solid 1px $lg_border_color;
5778: }
5779:
5780: table.LC_SimpleTable tr {
5781: padding:0px;
5782: border:solid 1px $lg_border_color;
5783: }
5784: table.LC_SimpleTable thead{
5785: background:rgb(220,220,220);
5786: }
5787:
5788: div.LC_columnSection {
5789: display: block;
5790: clear: both;
5791: overflow: hidden;
5792: margin:0px;
5793: }
5794:
5795: div.LC_columnSection>* {
5796: float: left;
5797: margin: 10px 20px 10px 0px;
5798: overflow:hidden;
5799: }
5800: div.LC_columnSection > .LC_ContentBox,
5801: div.LC_columnSection > .LC_ContentBoxSpecial
5802: {
5803: width: 400px;
5804: }
5805:
5806: .ContentBoxSpecialTemplate
5807: {
5808: border: solid 1px $lg_border_color;
5809: }
5810: .ContentBoxTemplate {
5811: padding:10px;
5812: }
5813:
5814: div.LC_columnSection > .ContentBoxTemplate,
5815: div.LC_columnSection > .ContentBoxSpecialTemplate
5816: {
5817: width: 600px;
5818:
5819: }
5820:
5821: .clear{
5822: clear: both;
5823: line-height: 0px;
5824: font-size: 0px;
5825: height: 0px;
5826: }
5827:
5828: .LC_loginpage_container {
5829: text-align:left;
5830: margin : 0 auto;
5831: width:65%;
5832: padding: 10px;
5833: height: auto;
5834: background-color:#FFFFFF;
5835: border:1px solid #CCCCCC;
5836: }
5837:
5838:
5839: .LC_loginpage_loginContainer {
5840: float:left;
5841: width: 182px;
5842: border:1px solid #CCCCCC;
5843: background-color:$loginbg;
5844: }
5845:
5846: .LC_loginpage_loginContainer h2{
5847: margin-top:0;
5848: display:block;
5849: background:$bgcol;
5850: color:$textcol;
5851: padding-left:5px;
5852: }
5853: .LC_loginpage_loginInfo {
5854: margin-left:20px;
5855: float:left;
5856: width:30%;
5857: border:1px solid #CCCCCC;
5858: padding:10px;
5859: }
5860:
5861: .LC_loginpage_loginDomain {
5862: margin-right:20px;
5863: width:20%;
5864: float:left;
5865: padding:10px;
5866: }
5867:
5868: .LC_loginpage_space {
5869: clear:both;
5870: margin-bottom:20px;
5871: border-bottom: 1px solid #CCCCCC;
5872: }
5873:
5874: END
5875: }
5876:
5877: =pod
5878:
5879: =item * &headtag()
5880:
5881: Returns a uniform footer for LON-CAPA web pages.
5882:
5883: Inputs: $title - optional title for the head
5884: $head_extra - optional extra HTML to put inside the <head>
5885: $args - optional arguments
5886: force_register - if is true call registerurl so the remote is
5887: informed
5888: redirect -> array ref of
5889: 1- seconds before redirect occurs
5890: 2- url to redirect to
5891: 3- whether the side effect should occur
5892: (side effect of setting
5893: $env{'internal.head.redirect'} to the url
5894: redirected too)
5895: domain -> force to color decorate a page for a specific
5896: domain
5897: function -> force usage of a specific rolish color scheme
5898: bgcolor -> override the default page bgcolor
5899: no_auto_mt_title
5900: -> prevent &mt()ing the title arg
5901:
5902: =cut
5903:
5904: sub headtag {
5905: my ($title,$head_extra,$args) = @_;
5906:
5907: my $function = $args->{'function'} || &get_users_function();
5908: my $domain = $args->{'domain'} || &determinedomain();
5909: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
5910: my $url = join(':',$env{'user.name'},$env{'user.domain'},
5911: $Apache::lonnet::perlvar{'lonVersion'},
5912: #time(),
5913: $env{'environment.color.timestamp'},
5914: $function,$domain,$bgcolor);
5915:
5916: $url = '/adm/css/'.&escape($url).'.css';
5917:
5918: my $result =
5919: '<head>'.
5920: &font_settings();
5921:
5922: if (!$args->{'frameset'}) {
5923: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
5924: }
5925: if ($args->{'force_register'}) {
5926: $result .= &Apache::lonmenu::registerurl(1);
5927: }
5928: if (!$args->{'no_nav_bar'}
5929: && !$args->{'only_body'}
5930: && !$args->{'frameset'}) {
5931: $result .= &help_menu_js();
5932: }
5933:
5934: if (ref($args->{'redirect'})) {
5935: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
5936: $url = &Apache::lonenc::check_encrypt($url);
5937: if (!$inhibit_continue) {
5938: $env{'internal.head.redirect'} = $url;
5939: }
5940: $result.=<<ADDMETA
5941: <meta http-equiv="pragma" content="no-cache" />
5942: <meta http-equiv="Refresh" content="$time; url=$url" />
5943: ADDMETA
5944: }
5945: if (!defined($title)) {
5946: $title = 'The LearningOnline Network with CAPA';
5947: }
5948: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
5949: $result .= '<title> LON-CAPA '.$title.'</title>'
5950: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
5951: .$head_extra;
5952: return $result;
5953: }
5954:
5955: =pod
5956:
5957: =item * &font_settings()
5958:
5959: Returns neccessary <meta> to set the proper encoding
5960:
5961: Inputs: none
5962:
5963: =cut
5964:
5965: sub font_settings {
5966: my $headerstring='';
5967: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
5968: $headerstring.=
5969: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
5970: }
5971: return $headerstring;
5972: }
5973:
5974: =pod
5975:
5976: =item * &xml_begin()
5977:
5978: Returns the needed doctype and <html>
5979:
5980: Inputs: none
5981:
5982: =cut
5983:
5984: sub xml_begin {
5985: my $output='';
5986:
5987: if ($env{'internal.start_page'}==1) {
5988: &Apache::lonhtmlcommon::init_htmlareafields();
5989: }
5990:
5991: if ($env{'browser.mathml'}) {
5992: $output='<?xml version="1.0"?>'
5993: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
5994: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
5995:
5996: # .'<!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">] >'
5997: .'<!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">'
5998: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
5999: .'xmlns="http://www.w3.org/1999/xhtml">';
6000: } else {
6001: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>';
6002: }
6003: return $output;
6004: }
6005:
6006: =pod
6007:
6008: =item * &endheadtag()
6009:
6010: Returns a uniform </head> for LON-CAPA web pages.
6011:
6012: Inputs: none
6013:
6014: =cut
6015:
6016: sub endheadtag {
6017: return '</head>';
6018: }
6019:
6020: =pod
6021:
6022: =item * &head()
6023:
6024: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
6025:
6026: Inputs:
6027:
6028: =over 4
6029:
6030: $title - optional title for the page
6031:
6032: $head_extra - optional extra HTML to put inside the <head>
6033:
6034: =back
6035:
6036: =cut
6037:
6038: sub head {
6039: my ($title,$head_extra,$args) = @_;
6040: return &headtag($title,$head_extra,$args).&endheadtag();
6041: }
6042:
6043: =pod
6044:
6045: =item * &start_page()
6046:
6047: Returns a complete <html> .. <body> section for LON-CAPA web pages.
6048:
6049: Inputs:
6050:
6051: =over 4
6052:
6053: $title - optional title for the page
6054:
6055: $head_extra - optional extra HTML to incude inside the <head>
6056:
6057: $args - additional optional args supported are:
6058:
6059: =over 8
6060:
6061: only_body -> is true will set &bodytag() onlybodytag
6062: arg on
6063: no_nav_bar -> is true will set &bodytag() notopbar arg on
6064: add_entries -> additional attributes to add to the <body>
6065: domain -> force to color decorate a page for a
6066: specific domain
6067: function -> force usage of a specific rolish color
6068: scheme
6069: redirect -> see &headtag()
6070: bgcolor -> override the default page bg color
6071: js_ready -> return a string ready for being used in
6072: a javascript writeln
6073: html_encode -> return a string ready for being used in
6074: a html attribute
6075: force_register -> if is true will turn on the &bodytag()
6076: $forcereg arg
6077: body_title -> alternate text to use instead of $title
6078: in the title box that appears, this text
6079: is not auto translated like the $title is
6080: frameset -> if true will start with a <frameset>
6081: rather than <body>
6082: no_title -> if true the title bar won't be shown
6083: skip_phases -> hash ref of
6084: head -> skip the <html><head> generation
6085: body -> skip all <body> generation
6086: no_inline_link -> if true and in remote mode, don't show the
6087: 'Switch To Inline Menu' link
6088: no_auto_mt_title -> prevent &mt()ing the title arg
6089: inherit_jsmath -> when creating popup window in a page,
6090: should it have jsmath forced on by the
6091: current page
6092:
6093: =back
6094:
6095: =back
6096:
6097: =cut
6098:
6099: sub start_page {
6100: my ($title,$head_extra,$args) = @_;
6101: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
6102: my %head_args;
6103: foreach my $arg ('redirect','force_register','domain','function',
6104: 'bgcolor','frameset','no_nav_bar','only_body',
6105: 'no_auto_mt_title') {
6106: if (defined($args->{$arg})) {
6107: $head_args{$arg} = $args->{$arg};
6108: }
6109: }
6110:
6111: $env{'internal.start_page'}++;
6112: my $result;
6113: if (! exists($args->{'skip_phases'}{'head'}) ) {
6114: $result.=
6115: &xml_begin().
6116: &headtag($title,$head_extra,\%head_args).&endheadtag();
6117: }
6118:
6119: if (! exists($args->{'skip_phases'}{'body'}) ) {
6120: if ($args->{'frameset'}) {
6121: my $attr_string = &make_attr_string($args->{'force_register'},
6122: $args->{'add_entries'});
6123: $result .= "\n<frameset $attr_string>\n";
6124: } else {
6125: $result .=
6126: &bodytag($title,
6127: $args->{'function'}, $args->{'add_entries'},
6128: $args->{'only_body'}, $args->{'domain'},
6129: $args->{'force_register'}, $args->{'body_title'},
6130: $args->{'no_nav_bar'}, $args->{'bgcolor'},
6131: $args->{'no_title'}, $args->{'no_inline_link'},
6132: $args);
6133: }
6134: }
6135:
6136: if ($args->{'js_ready'}) {
6137: $result = &js_ready($result);
6138: }
6139: if ($args->{'html_encode'}) {
6140: $result = &html_encode($result);
6141: }
6142:
6143: if (exists($args->{'bread_crumbs'})) {
6144: &Apache::lonhtmlcommon::clear_breadcrumbs();
6145: if (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
6146: foreach my $crumb (@{$args->{'bread_crumbs'}}){
6147: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
6148: }
6149: }
6150: $result .= &Apache::lonhtmlcommon::breadcrumbs();
6151: }
6152:
6153: return $result;
6154: }
6155:
6156:
6157: =pod
6158:
6159: =item * &head()
6160:
6161: Returns a complete </body></html> section for LON-CAPA web pages.
6162:
6163: Inputs: $args - additional optional args supported are:
6164: js_ready -> return a string ready for being used in
6165: a javascript writeln
6166: html_encode -> return a string ready for being used in
6167: a html attribute
6168: frameset -> if true will start with a <frameset>
6169: rather than <body>
6170: dicsussion -> if true will get discussion from
6171: lonxml::xmlend
6172: (you can pass the target and parser arguments
6173: through optional 'target' and 'parser' args
6174: to this routine)
6175:
6176: =cut
6177:
6178: sub end_page {
6179: my ($args) = @_;
6180: $env{'internal.end_page'}++;
6181: my $result;
6182: if ($args->{'discussion'}) {
6183: my ($target,$parser);
6184: if (ref($args->{'discussion'})) {
6185: ($target,$parser) =($args->{'discussion'}{'target'},
6186: $args->{'discussion'}{'parser'});
6187: }
6188: $result .= &Apache::lonxml::xmlend($target,$parser);
6189: }
6190:
6191: if ($args->{'frameset'}) {
6192: $result .= '</frameset>';
6193: } else {
6194: $result .= &endbodytag($args);
6195: }
6196: $result .= "\n</html>";
6197:
6198: if ($args->{'js_ready'}) {
6199: $result = &js_ready($result);
6200: }
6201:
6202: if ($args->{'html_encode'}) {
6203: $result = &html_encode($result);
6204: }
6205:
6206: return $result;
6207: }
6208:
6209: sub html_encode {
6210: my ($result) = @_;
6211:
6212: $result = &HTML::Entities::encode($result,'<>&"');
6213:
6214: return $result;
6215: }
6216: sub js_ready {
6217: my ($result) = @_;
6218:
6219: $result =~ s/[\n\r]/ /xmsg;
6220: $result =~ s/\\/\\\\/xmsg;
6221: $result =~ s/'/\\'/xmsg;
6222: $result =~ s{</}{<\\/}xmsg;
6223:
6224: return $result;
6225: }
6226:
6227: sub validate_page {
6228: if ( exists($env{'internal.start_page'})
6229: && $env{'internal.start_page'} > 1) {
6230: &Apache::lonnet::logthis('start_page called multiple times '.
6231: $env{'internal.start_page'}.' '.
6232: $ENV{'request.filename'});
6233: }
6234: if ( exists($env{'internal.end_page'})
6235: && $env{'internal.end_page'} > 1) {
6236: &Apache::lonnet::logthis('end_page called multiple times '.
6237: $env{'internal.end_page'}.' '.
6238: $env{'request.filename'});
6239: }
6240: if ( exists($env{'internal.start_page'})
6241: && ! exists($env{'internal.end_page'})) {
6242: &Apache::lonnet::logthis('start_page called without end_page '.
6243: $env{'request.filename'});
6244: }
6245: if ( ! exists($env{'internal.start_page'})
6246: && exists($env{'internal.end_page'})) {
6247: &Apache::lonnet::logthis('end_page called without start_page'.
6248: $env{'request.filename'});
6249: }
6250: }
6251:
6252: sub simple_error_page {
6253: my ($r,$title,$msg) = @_;
6254: my $page =
6255: &Apache::loncommon::start_page($title).
6256: &mt($msg).
6257: &Apache::loncommon::end_page();
6258: if (ref($r)) {
6259: $r->print($page);
6260: return;
6261: }
6262: return $page;
6263: }
6264:
6265: {
6266: my @row_count;
6267: sub start_data_table {
6268: my ($add_class) = @_;
6269: my $css_class = (join(' ','LC_data_table',$add_class));
6270: unshift(@row_count,0);
6271: return '<table class="'.$css_class.'">'."\n";
6272: }
6273:
6274: sub end_data_table {
6275: shift(@row_count);
6276: return '</table>'."\n";;
6277: }
6278:
6279: sub start_data_table_row {
6280: my ($add_class) = @_;
6281: $row_count[0]++;
6282: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
6283: $css_class = (join(' ',$css_class,$add_class));
6284: return '<tr class="'.$css_class.'">'."\n";;
6285: }
6286:
6287: sub continue_data_table_row {
6288: my ($add_class) = @_;
6289: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
6290: $css_class = (join(' ',$css_class,$add_class));
6291: return '<tr class="'.$css_class.'">'."\n";;
6292: }
6293:
6294: sub end_data_table_row {
6295: return '</tr>'."\n";;
6296: }
6297:
6298: sub start_data_table_empty_row {
6299: # $row_count[0]++;
6300: return '<tr class="LC_empty_row" >'."\n";;
6301: }
6302:
6303: sub end_data_table_empty_row {
6304: return '</tr>'."\n";;
6305: }
6306:
6307: sub start_data_table_header_row {
6308: return '<tr class="LC_header_row">'."\n";;
6309: }
6310:
6311: sub end_data_table_header_row {
6312: return '</tr>'."\n";;
6313: }
6314: }
6315:
6316: =pod
6317:
6318: =item * &inhibit_menu_check($arg)
6319:
6320: Checks for a inhibitmenu state and generates output to preserve it
6321:
6322: Inputs: $arg - can be any of
6323: - undef - in which case the return value is a string
6324: to add into arguments list of a uri
6325: - 'input' - in which case the return value is a HTML
6326: <form> <input> field of type hidden to
6327: preserve the value
6328: - a url - in which case the return value is the url with
6329: the neccesary cgi args added to preserve the
6330: inhibitmenu state
6331: - a ref to a url - no return value, but the string is
6332: updated to include the neccessary cgi
6333: args to preserve the inhibitmenu state
6334:
6335: =cut
6336:
6337: sub inhibit_menu_check {
6338: my ($arg) = @_;
6339: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6340: if ($arg eq 'input') {
6341: if ($env{'form.inhibitmenu'}) {
6342: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
6343: } else {
6344: return
6345: }
6346: }
6347: if ($env{'form.inhibitmenu'}) {
6348: if (ref($arg)) {
6349: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6350: } elsif ($arg eq '') {
6351: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
6352: } else {
6353: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6354: }
6355: }
6356: if (!ref($arg)) {
6357: return $arg;
6358: }
6359: }
6360:
6361: ###############################################
6362:
6363: =pod
6364:
6365: =back
6366:
6367: =head1 User Information Routines
6368:
6369: =over 4
6370:
6371: =item * &get_users_function()
6372:
6373: Used by &bodytag to determine the current users primary role.
6374: Returns either 'student','coordinator','admin', or 'author'.
6375:
6376: =cut
6377:
6378: ###############################################
6379: sub get_users_function {
6380: my $function = 'student';
6381: if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
6382: $function='coordinator';
6383: }
6384: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
6385: $function='admin';
6386: }
6387: if (($env{'request.role'}=~/^(au|ca)/) ||
6388: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
6389: $function='author';
6390: }
6391: return $function;
6392: }
6393:
6394: ###############################################
6395:
6396: =pod
6397:
6398: =item * &check_user_status()
6399:
6400: Determines current status of supplied role for a
6401: specific user. Roles can be active, previous or future.
6402:
6403: Inputs:
6404: user's domain, user's username, course's domain,
6405: course's number, optional section ID.
6406:
6407: Outputs:
6408: role status: active, previous or future.
6409:
6410: =cut
6411:
6412: sub check_user_status {
6413: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
6414: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
6415: my @uroles = keys %userinfo;
6416: my $srchstr;
6417: my $active_chk = 'none';
6418: my $now = time;
6419: if (@uroles > 0) {
6420: if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
6421: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
6422: } else {
6423: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
6424: }
6425: if (grep/^\Q$srchstr\E$/,@uroles) {
6426: my $role_end = 0;
6427: my $role_start = 0;
6428: $active_chk = 'active';
6429: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
6430: $role_end = $1;
6431: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
6432: $role_start = $1;
6433: }
6434: }
6435: if ($role_start > 0) {
6436: if ($now < $role_start) {
6437: $active_chk = 'future';
6438: }
6439: }
6440: if ($role_end > 0) {
6441: if ($now > $role_end) {
6442: $active_chk = 'previous';
6443: }
6444: }
6445: }
6446: }
6447: return $active_chk;
6448: }
6449:
6450: ###############################################
6451:
6452: =pod
6453:
6454: =item * &get_sections()
6455:
6456: Determines all the sections for a course including
6457: sections with students and sections containing other roles.
6458: Incoming parameters:
6459:
6460: 1. domain
6461: 2. course number
6462: 3. reference to array containing roles for which sections should
6463: be gathered (optional).
6464: 4. reference to array containing status types for which sections
6465: should be gathered (optional).
6466:
6467: If the third argument is undefined, sections are gathered for any role.
6468: If the fourth argument is undefined, sections are gathered for any status.
6469: Permissible values are 'active' or 'future' or 'previous'.
6470:
6471: Returns section hash (keys are section IDs, values are
6472: number of users in each section), subject to the
6473: optional roles filter, optional status filter
6474:
6475: =cut
6476:
6477: ###############################################
6478: sub get_sections {
6479: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
6480: if (!defined($cdom) || !defined($cnum)) {
6481: my $cid = $env{'request.course.id'};
6482:
6483: return if (!defined($cid));
6484:
6485: $cdom = $env{'course.'.$cid.'.domain'};
6486: $cnum = $env{'course.'.$cid.'.num'};
6487: }
6488:
6489: my %sectioncount;
6490: my $now = time;
6491:
6492: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
6493: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
6494: my $sec_index = &Apache::loncoursedata::CL_SECTION();
6495: my $status_index = &Apache::loncoursedata::CL_STATUS();
6496: my $start_index = &Apache::loncoursedata::CL_START();
6497: my $end_index = &Apache::loncoursedata::CL_END();
6498: my $status;
6499: while (my ($student,$data) = each(%$classlist)) {
6500: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
6501: $data->[$status_index],
6502: $data->[$start_index],
6503: $data->[$end_index]);
6504: if ($stu_status eq 'Active') {
6505: $status = 'active';
6506: } elsif ($end < $now) {
6507: $status = 'previous';
6508: } elsif ($start > $now) {
6509: $status = 'future';
6510: }
6511: if ($section ne '-1' && $section !~ /^\s*$/) {
6512: if ((!defined($possible_status)) || (($status ne '') &&
6513: (grep/^\Q$status\E$/,@{$possible_status}))) {
6514: $sectioncount{$section}++;
6515: }
6516: }
6517: }
6518: }
6519: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6520: foreach my $user (sort(keys(%courseroles))) {
6521: if ($user !~ /^(\w{2})/) { next; }
6522: my ($role) = ($user =~ /^(\w{2})/);
6523: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
6524: my ($section,$status);
6525: if ($role eq 'cr' &&
6526: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
6527: $section=$1;
6528: }
6529: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
6530: if (!defined($section) || $section eq '-1') { next; }
6531: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
6532: if ($end == -1 && $start == -1) {
6533: next; #deleted role
6534: }
6535: if (!defined($possible_status)) {
6536: $sectioncount{$section}++;
6537: } else {
6538: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
6539: $status = 'active';
6540: } elsif ($end < $now) {
6541: $status = 'future';
6542: } elsif ($start > $now) {
6543: $status = 'previous';
6544: }
6545: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
6546: $sectioncount{$section}++;
6547: }
6548: }
6549: }
6550: return %sectioncount;
6551: }
6552:
6553: ###############################################
6554:
6555: =pod
6556:
6557: =item * &get_course_users()
6558:
6559: Retrieves usernames:domains for users in the specified course
6560: with specific role(s), and access status.
6561:
6562: Incoming parameters:
6563: 1. course domain
6564: 2. course number
6565: 3. access status: users must have - either active,
6566: previous, future, or all.
6567: 4. reference to array of permissible roles
6568: 5. reference to array of section restrictions (optional)
6569: 6. reference to results object (hash of hashes).
6570: 7. reference to optional userdata hash
6571: 8. reference to optional statushash
6572: 9. flag if privileged users (except those set to unhide in
6573: course settings) should be excluded
6574: Keys of top level results hash are roles.
6575: Keys of inner hashes are username:domain, with
6576: values set to access type.
6577: Optional userdata hash returns an array with arguments in the
6578: same order as loncoursedata::get_classlist() for student data.
6579:
6580: Optional statushash returns
6581:
6582: Entries for end, start, section and status are blank because
6583: of the possibility of multiple values for non-student roles.
6584:
6585: =cut
6586:
6587: ###############################################
6588:
6589: sub get_course_users {
6590: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
6591: my %idx = ();
6592: my %seclists;
6593:
6594: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
6595: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
6596: $idx{end} = &Apache::loncoursedata::CL_END();
6597: $idx{start} = &Apache::loncoursedata::CL_START();
6598: $idx{id} = &Apache::loncoursedata::CL_ID();
6599: $idx{section} = &Apache::loncoursedata::CL_SECTION();
6600: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
6601: $idx{status} = &Apache::loncoursedata::CL_STATUS();
6602:
6603: if (grep(/^st$/,@{$roles})) {
6604: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
6605: my $now = time;
6606: foreach my $student (keys(%{$classlist})) {
6607: my $match = 0;
6608: my $secmatch = 0;
6609: my $section = $$classlist{$student}[$idx{section}];
6610: my $status = $$classlist{$student}[$idx{status}];
6611: if ($section eq '') {
6612: $section = 'none';
6613: }
6614: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
6615: if (grep(/^all$/,@{$sections})) {
6616: $secmatch = 1;
6617: } elsif ($$classlist{$student}[$idx{section}] eq '') {
6618: if (grep(/^none$/,@{$sections})) {
6619: $secmatch = 1;
6620: }
6621: } else {
6622: if (grep(/^\Q$section\E$/,@{$sections})) {
6623: $secmatch = 1;
6624: }
6625: }
6626: if (!$secmatch) {
6627: next;
6628: }
6629: }
6630: if (defined($$types{'active'})) {
6631: if ($$classlist{$student}[$idx{status}] eq 'Active') {
6632: push(@{$$users{st}{$student}},'active');
6633: $match = 1;
6634: }
6635: }
6636: if (defined($$types{'previous'})) {
6637: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
6638: push(@{$$users{st}{$student}},'previous');
6639: $match = 1;
6640: }
6641: }
6642: if (defined($$types{'future'})) {
6643: if ($$classlist{$student}[$idx{status}] eq 'Future') {
6644: push(@{$$users{st}{$student}},'future');
6645: $match = 1;
6646: }
6647: }
6648: if ($match) {
6649: push(@{$seclists{$student}},$section);
6650: if (ref($userdata) eq 'HASH') {
6651: $$userdata{$student} = $$classlist{$student};
6652: }
6653: if (ref($statushash) eq 'HASH') {
6654: $statushash->{$student}{'st'}{$section} = $status;
6655: }
6656: }
6657: }
6658: }
6659: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
6660: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6661: my $now = time;
6662: my %displaystatus = ( previous => 'Expired',
6663: active => 'Active',
6664: future => 'Future',
6665: );
6666: my %nothide;
6667: if ($hidepriv) {
6668: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
6669: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
6670: if ($user !~ /:/) {
6671: $nothide{join(':',split(/[\@]/,$user))}=1;
6672: } else {
6673: $nothide{$user} = 1;
6674: }
6675: }
6676: }
6677: foreach my $person (sort(keys(%coursepersonnel))) {
6678: my $match = 0;
6679: my $secmatch = 0;
6680: my $status;
6681: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
6682: $user =~ s/:$//;
6683: my ($end,$start) = split(/:/,$coursepersonnel{$person});
6684: if ($end == -1 || $start == -1) {
6685: next;
6686: }
6687: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
6688: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
6689: my ($uname,$udom) = split(/:/,$user);
6690: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
6691: if (grep(/^all$/,@{$sections})) {
6692: $secmatch = 1;
6693: } elsif ($usec eq '') {
6694: if (grep(/^none$/,@{$sections})) {
6695: $secmatch = 1;
6696: }
6697: } else {
6698: if (grep(/^\Q$usec\E$/,@{$sections})) {
6699: $secmatch = 1;
6700: }
6701: }
6702: if (!$secmatch) {
6703: next;
6704: }
6705: }
6706: if ($usec eq '') {
6707: $usec = 'none';
6708: }
6709: if ($uname ne '' && $udom ne '') {
6710: if ($hidepriv) {
6711: if ((&Apache::lonnet::privileged($uname,$udom)) &&
6712: (!$nothide{$uname.':'.$udom})) {
6713: next;
6714: }
6715: }
6716: if ($end > 0 && $end < $now) {
6717: $status = 'previous';
6718: } elsif ($start > $now) {
6719: $status = 'future';
6720: } else {
6721: $status = 'active';
6722: }
6723: foreach my $type (keys(%{$types})) {
6724: if ($status eq $type) {
6725: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
6726: push(@{$$users{$role}{$user}},$type);
6727: }
6728: $match = 1;
6729: }
6730: }
6731: if (($match) && (ref($userdata) eq 'HASH')) {
6732: if (!exists($$userdata{$uname.':'.$udom})) {
6733: &get_user_info($udom,$uname,\%idx,$userdata);
6734: }
6735: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
6736: push(@{$seclists{$uname.':'.$udom}},$usec);
6737: }
6738: if (ref($statushash) eq 'HASH') {
6739: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
6740: }
6741: }
6742: }
6743: }
6744: }
6745: if (grep(/^ow$/,@{$roles})) {
6746: if ((defined($cdom)) && (defined($cnum))) {
6747: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
6748: if ( defined($csettings{'internal.courseowner'}) ) {
6749: my $owner = $csettings{'internal.courseowner'};
6750: next if ($owner eq '');
6751: my ($ownername,$ownerdom);
6752: if ($owner =~ /^([^:]+):([^:]+)$/) {
6753: $ownername = $1;
6754: $ownerdom = $2;
6755: } else {
6756: $ownername = $owner;
6757: $ownerdom = $cdom;
6758: $owner = $ownername.':'.$ownerdom;
6759: }
6760: @{$$users{'ow'}{$owner}} = 'any';
6761: if (defined($userdata) &&
6762: !exists($$userdata{$owner})) {
6763: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
6764: if (!grep(/^none$/,@{$seclists{$owner}})) {
6765: push(@{$seclists{$owner}},'none');
6766: }
6767: if (ref($statushash) eq 'HASH') {
6768: $statushash->{$owner}{'ow'}{'none'} = 'Any';
6769: }
6770: }
6771: }
6772: }
6773: }
6774: foreach my $user (keys(%seclists)) {
6775: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
6776: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
6777: }
6778: }
6779: return;
6780: }
6781:
6782: sub get_user_info {
6783: my ($udom,$uname,$idx,$userdata) = @_;
6784: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
6785: &plainname($uname,$udom,'lastname');
6786: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
6787: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
6788: my %idhash = &Apache::lonnet::idrget($udom,($uname));
6789: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
6790: return;
6791: }
6792:
6793: ###############################################
6794:
6795: =pod
6796:
6797: =item * &get_user_quota()
6798:
6799: Retrieves quota assigned for storage of portfolio files for a user
6800:
6801: Incoming parameters:
6802: 1. user's username
6803: 2. user's domain
6804:
6805: Returns:
6806: 1. Disk quota (in Mb) assigned to student.
6807: 2. (Optional) Type of setting: custom or default
6808: (individually assigned or default for user's
6809: institutional status).
6810: 3. (Optional) - User's institutional status (e.g., faculty, staff
6811: or student - types as defined in localenroll::inst_usertypes
6812: for user's domain, which determines default quota for user.
6813: 4. (Optional) - Default quota which would apply to the user.
6814:
6815: If a value has been stored in the user's environment,
6816: it will return that, otherwise it returns the maximal default
6817: defined for the user's instituional status(es) in the domain.
6818:
6819: =cut
6820:
6821: ###############################################
6822:
6823:
6824: sub get_user_quota {
6825: my ($uname,$udom) = @_;
6826: my ($quota,$quotatype,$settingstatus,$defquota);
6827: if (!defined($udom)) {
6828: $udom = $env{'user.domain'};
6829: }
6830: if (!defined($uname)) {
6831: $uname = $env{'user.name'};
6832: }
6833: if (($udom eq '' || $uname eq '') ||
6834: ($udom eq 'public') && ($uname eq 'public')) {
6835: $quota = 0;
6836: $quotatype = 'default';
6837: $defquota = 0;
6838: } else {
6839: my $inststatus;
6840: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
6841: $quota = $env{'environment.portfolioquota'};
6842: $inststatus = $env{'environment.inststatus'};
6843: } else {
6844: my %userenv =
6845: &Apache::lonnet::get('environment',['portfolioquota',
6846: 'inststatus'],$udom,$uname);
6847: my ($tmp) = keys(%userenv);
6848: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
6849: $quota = $userenv{'portfolioquota'};
6850: $inststatus = $userenv{'inststatus'};
6851: } else {
6852: undef(%userenv);
6853: }
6854: }
6855: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
6856: if ($quota eq '') {
6857: $quota = $defquota;
6858: $quotatype = 'default';
6859: } else {
6860: $quotatype = 'custom';
6861: }
6862: }
6863: if (wantarray) {
6864: return ($quota,$quotatype,$settingstatus,$defquota);
6865: } else {
6866: return $quota;
6867: }
6868: }
6869:
6870: ###############################################
6871:
6872: =pod
6873:
6874: =item * &default_quota()
6875:
6876: Retrieves default quota assigned for storage of user portfolio files,
6877: given an (optional) user's institutional status.
6878:
6879: Incoming parameters:
6880: 1. domain
6881: 2. (Optional) institutional status(es). This is a : separated list of
6882: status types (e.g., faculty, staff, student etc.)
6883: which apply to the user for whom the default is being retrieved.
6884: If the institutional status string in undefined, the domain
6885: default quota will be returned.
6886:
6887: Returns:
6888: 1. Default disk quota (in Mb) for user portfolios in the domain.
6889: 2. (Optional) institutional type which determined the value of the
6890: default quota.
6891:
6892: If a value has been stored in the domain's configuration db,
6893: it will return that, otherwise it returns 20 (for backwards
6894: compatibility with domains which have not set up a configuration
6895: db file; the original statically defined portfolio quota was 20 Mb).
6896:
6897: If the user's status includes multiple types (e.g., staff and student),
6898: the largest default quota which applies to the user determines the
6899: default quota returned.
6900:
6901: =cut
6902:
6903: ###############################################
6904:
6905:
6906: sub default_quota {
6907: my ($udom,$inststatus) = @_;
6908: my ($defquota,$settingstatus);
6909: my %quotahash = &Apache::lonnet::get_dom('configuration',
6910: ['quotas'],$udom);
6911: if (ref($quotahash{'quotas'}) eq 'HASH') {
6912: if ($inststatus ne '') {
6913: my @statuses = split(/:/,$inststatus);
6914: foreach my $item (@statuses) {
6915: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
6916: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
6917: if ($defquota eq '') {
6918: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
6919: $settingstatus = $item;
6920: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
6921: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
6922: $settingstatus = $item;
6923: }
6924: }
6925: } else {
6926: if ($quotahash{'quotas'}{$item} ne '') {
6927: if ($defquota eq '') {
6928: $defquota = $quotahash{'quotas'}{$item};
6929: $settingstatus = $item;
6930: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
6931: $defquota = $quotahash{'quotas'}{$item};
6932: $settingstatus = $item;
6933: }
6934: }
6935: }
6936: }
6937: }
6938: if ($defquota eq '') {
6939: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
6940: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
6941: } else {
6942: $defquota = $quotahash{'quotas'}{'default'};
6943: }
6944: $settingstatus = 'default';
6945: }
6946: } else {
6947: $settingstatus = 'default';
6948: $defquota = 20;
6949: }
6950: if (wantarray) {
6951: return ($defquota,$settingstatus);
6952: } else {
6953: return $defquota;
6954: }
6955: }
6956:
6957: sub get_secgrprole_info {
6958: my ($cdom,$cnum,$needroles,$type) = @_;
6959: my %sections_count = &get_sections($cdom,$cnum);
6960: my @sections = (sort {$a <=> $b} keys(%sections_count));
6961: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
6962: my @groups = sort(keys(%curr_groups));
6963: my $allroles = [];
6964: my $rolehash;
6965: my $accesshash = {
6966: active => 'Currently has access',
6967: future => 'Will have future access',
6968: previous => 'Previously had access',
6969: };
6970: if ($needroles) {
6971: $rolehash = {'all' => 'all'};
6972: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6973: if (&Apache::lonnet::error(%user_roles)) {
6974: undef(%user_roles);
6975: }
6976: foreach my $item (keys(%user_roles)) {
6977: my ($role)=split(/\:/,$item,2);
6978: if ($role eq 'cr') { next; }
6979: if ($role =~ /^cr/) {
6980: $$rolehash{$role} = (split('/',$role))[3];
6981: } else {
6982: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
6983: }
6984: }
6985: foreach my $key (sort(keys(%{$rolehash}))) {
6986: push(@{$allroles},$key);
6987: }
6988: push (@{$allroles},'st');
6989: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
6990: }
6991: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
6992: }
6993:
6994: sub user_picker {
6995: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
6996: my $currdom = $dom;
6997: my %curr_selected = (
6998: srchin => 'dom',
6999: srchby => 'lastname',
7000: );
7001: my $srchterm;
7002: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
7003: if ($srch->{'srchby'} ne '') {
7004: $curr_selected{'srchby'} = $srch->{'srchby'};
7005: }
7006: if ($srch->{'srchin'} ne '') {
7007: $curr_selected{'srchin'} = $srch->{'srchin'};
7008: }
7009: if ($srch->{'srchtype'} ne '') {
7010: $curr_selected{'srchtype'} = $srch->{'srchtype'};
7011: }
7012: if ($srch->{'srchdomain'} ne '') {
7013: $currdom = $srch->{'srchdomain'};
7014: }
7015: $srchterm = $srch->{'srchterm'};
7016: }
7017: my %lt=&Apache::lonlocal::texthash(
7018: 'usr' => 'Search criteria',
7019: 'doma' => 'Domain/institution to search',
7020: 'uname' => 'username',
7021: 'lastname' => 'last name',
7022: 'lastfirst' => 'last name, first name',
7023: 'crs' => 'in this course',
7024: 'dom' => 'in selected LON-CAPA domain',
7025: 'alc' => 'all LON-CAPA',
7026: 'instd' => 'in institutional directory for selected domain',
7027: 'exact' => 'is',
7028: 'contains' => 'contains',
7029: 'begins' => 'begins with',
7030: 'youm' => "You must include some text to search for.",
7031: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
7032: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
7033: 'yomc' => "You must choose a domain when using an institutional directory search.",
7034: 'ymcd' => "You must choose a domain when using a domain search.",
7035: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
7036: 'whse' => "When searching by last,first you must include at least one character in the first name.",
7037: 'thfo' => "The following need to be corrected before the search can be run:",
7038: );
7039: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
7040: my $srchinsel = ' <select name="srchin">';
7041:
7042: my @srchins = ('crs','dom','alc','instd');
7043:
7044: foreach my $option (@srchins) {
7045: # FIXME 'alc' option unavailable until
7046: # loncreateuser::print_user_query_page()
7047: # has been completed.
7048: next if ($option eq 'alc');
7049: next if ($option eq 'crs' && !$env{'request.course.id'});
7050: if ($curr_selected{'srchin'} eq $option) {
7051: $srchinsel .= '
7052: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7053: } else {
7054: $srchinsel .= '
7055: <option value="'.$option.'">'.$lt{$option}.'</option>';
7056: }
7057: }
7058: $srchinsel .= "\n </select>\n";
7059:
7060: my $srchbysel = ' <select name="srchby">';
7061: foreach my $option ('lastname','lastfirst','uname') {
7062: if ($curr_selected{'srchby'} eq $option) {
7063: $srchbysel .= '
7064: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7065: } else {
7066: $srchbysel .= '
7067: <option value="'.$option.'">'.$lt{$option}.'</option>';
7068: }
7069: }
7070: $srchbysel .= "\n </select>\n";
7071:
7072: my $srchtypesel = ' <select name="srchtype">';
7073: foreach my $option ('begins','contains','exact') {
7074: if ($curr_selected{'srchtype'} eq $option) {
7075: $srchtypesel .= '
7076: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7077: } else {
7078: $srchtypesel .= '
7079: <option value="'.$option.'">'.$lt{$option}.'</option>';
7080: }
7081: }
7082: $srchtypesel .= "\n </select>\n";
7083:
7084: my ($newuserscript,$new_user_create);
7085:
7086: if ($forcenewuser) {
7087: if (ref($srch) eq 'HASH') {
7088: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
7089: if ($cancreate) {
7090: $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>';
7091: } else {
7092: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
7093: my %usertypetext = (
7094: official => 'institutional',
7095: unofficial => 'non-institutional',
7096: );
7097: $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 />';
7098: }
7099: }
7100: }
7101:
7102: $newuserscript = <<"ENDSCRIPT";
7103:
7104: function setSearch(createnew,callingForm) {
7105: if (createnew == 1) {
7106: for (var i=0; i<callingForm.srchby.length; i++) {
7107: if (callingForm.srchby.options[i].value == 'uname') {
7108: callingForm.srchby.selectedIndex = i;
7109: }
7110: }
7111: for (var i=0; i<callingForm.srchin.length; i++) {
7112: if ( callingForm.srchin.options[i].value == 'dom') {
7113: callingForm.srchin.selectedIndex = i;
7114: }
7115: }
7116: for (var i=0; i<callingForm.srchtype.length; i++) {
7117: if (callingForm.srchtype.options[i].value == 'exact') {
7118: callingForm.srchtype.selectedIndex = i;
7119: }
7120: }
7121: for (var i=0; i<callingForm.srchdomain.length; i++) {
7122: if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
7123: callingForm.srchdomain.selectedIndex = i;
7124: }
7125: }
7126: }
7127: }
7128: ENDSCRIPT
7129:
7130: }
7131:
7132: my $output = <<"END_BLOCK";
7133: <script type="text/javascript">
7134: function validateEntry(callingForm) {
7135:
7136: var checkok = 1;
7137: var srchin;
7138: for (var i=0; i<callingForm.srchin.length; i++) {
7139: if ( callingForm.srchin[i].checked ) {
7140: srchin = callingForm.srchin[i].value;
7141: }
7142: }
7143:
7144: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
7145: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
7146: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
7147: var srchterm = callingForm.srchterm.value;
7148: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
7149: var msg = "";
7150:
7151: if (srchterm == "") {
7152: checkok = 0;
7153: msg += "$lt{'youm'}\\n";
7154: }
7155:
7156: if (srchtype== 'begins') {
7157: if (srchterm.length < 2) {
7158: checkok = 0;
7159: msg += "$lt{'thte'}\\n";
7160: }
7161: }
7162:
7163: if (srchtype== 'contains') {
7164: if (srchterm.length < 3) {
7165: checkok = 0;
7166: msg += "$lt{'thet'}\\n";
7167: }
7168: }
7169: if (srchin == 'instd') {
7170: if (srchdomain == '') {
7171: checkok = 0;
7172: msg += "$lt{'yomc'}\\n";
7173: }
7174: }
7175: if (srchin == 'dom') {
7176: if (srchdomain == '') {
7177: checkok = 0;
7178: msg += "$lt{'ymcd'}\\n";
7179: }
7180: }
7181: if (srchby == 'lastfirst') {
7182: if (srchterm.indexOf(",") == -1) {
7183: checkok = 0;
7184: msg += "$lt{'whus'}\\n";
7185: }
7186: if (srchterm.indexOf(",") == srchterm.length -1) {
7187: checkok = 0;
7188: msg += "$lt{'whse'}\\n";
7189: }
7190: }
7191: if (checkok == 0) {
7192: alert("$lt{'thfo'}\\n"+msg);
7193: return;
7194: }
7195: if (checkok == 1) {
7196: callingForm.submit();
7197: }
7198: }
7199:
7200: $newuserscript
7201:
7202: </script>
7203:
7204: $new_user_create
7205:
7206: <table>
7207: <tr>
7208: <td>$lt{'doma'}:</td>
7209: <td>$domform</td>
7210: </td>
7211: </tr>
7212: <tr>
7213: <td>$lt{'usr'}:</td>
7214: <td>$srchbysel
7215: $srchtypesel
7216: <input type="text" size="15" name="srchterm" value="$srchterm" />
7217: $srchinsel
7218: </td>
7219: </tr>
7220: </table>
7221: <br />
7222: END_BLOCK
7223:
7224: return $output;
7225: }
7226:
7227: sub user_rule_check {
7228: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
7229: my $response;
7230: if (ref($usershash) eq 'HASH') {
7231: foreach my $user (keys(%{$usershash})) {
7232: my ($uname,$udom) = split(/:/,$user);
7233: next if ($udom eq '' || $uname eq '');
7234: my ($id,$newuser);
7235: if (ref($usershash->{$user}) eq 'HASH') {
7236: $newuser = $usershash->{$user}->{'newuser'};
7237: $id = $usershash->{$user}->{'id'};
7238: }
7239: my $inst_response;
7240: if (ref($checks) eq 'HASH') {
7241: if (defined($checks->{'username'})) {
7242: ($inst_response,%{$inst_results->{$user}}) =
7243: &Apache::lonnet::get_instuser($udom,$uname);
7244: } elsif (defined($checks->{'id'})) {
7245: ($inst_response,%{$inst_results->{$user}}) =
7246: &Apache::lonnet::get_instuser($udom,undef,$id);
7247: }
7248: } else {
7249: ($inst_response,%{$inst_results->{$user}}) =
7250: &Apache::lonnet::get_instuser($udom,$uname);
7251: return;
7252: }
7253: if (!$got_rules->{$udom}) {
7254: my %domconfig = &Apache::lonnet::get_dom('configuration',
7255: ['usercreation'],$udom);
7256: if (ref($domconfig{'usercreation'}) eq 'HASH') {
7257: foreach my $item ('username','id') {
7258: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
7259: $$curr_rules{$udom}{$item} =
7260: $domconfig{'usercreation'}{$item.'_rule'};
7261: }
7262: }
7263: }
7264: $got_rules->{$udom} = 1;
7265: }
7266: foreach my $item (keys(%{$checks})) {
7267: if (ref($$curr_rules{$udom}) eq 'HASH') {
7268: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
7269: if (@{$$curr_rules{$udom}{$item}} > 0) {
7270: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
7271: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
7272: if ($rule_check{$rule}) {
7273: $$rulematch{$user}{$item} = $rule;
7274: if ($inst_response eq 'ok') {
7275: if (ref($inst_results) eq 'HASH') {
7276: if (ref($inst_results->{$user}) eq 'HASH') {
7277: if (keys(%{$inst_results->{$user}}) == 0) {
7278: $$alerts{$item}{$udom}{$uname} = 1;
7279: }
7280: }
7281: }
7282: }
7283: last;
7284: }
7285: }
7286: }
7287: }
7288: }
7289: }
7290: }
7291: }
7292: return;
7293: }
7294:
7295: sub user_rule_formats {
7296: my ($domain,$domdesc,$curr_rules,$check) = @_;
7297: my %text = (
7298: 'username' => 'Usernames',
7299: 'id' => 'IDs',
7300: );
7301: my $output;
7302: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
7303: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
7304: if (@{$ruleorder} > 0) {
7305: $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>';
7306: foreach my $rule (@{$ruleorder}) {
7307: if (ref($curr_rules) eq 'ARRAY') {
7308: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
7309: if (ref($rules->{$rule}) eq 'HASH') {
7310: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
7311: $rules->{$rule}{'desc'}.'</li>';
7312: }
7313: }
7314: }
7315: }
7316: $output .= '</ul>';
7317: }
7318: }
7319: return $output;
7320: }
7321:
7322: sub instrule_disallow_msg {
7323: my ($checkitem,$domdesc,$count,$mode) = @_;
7324: my $response;
7325: my %text = (
7326: item => 'username',
7327: items => 'usernames',
7328: match => 'matches',
7329: do => 'does',
7330: action => 'a username',
7331: one => 'one',
7332: );
7333: if ($count > 1) {
7334: $text{'item'} = 'usernames';
7335: $text{'match'} ='match';
7336: $text{'do'} = 'do';
7337: $text{'action'} = 'usernames',
7338: $text{'one'} = 'ones';
7339: }
7340: if ($checkitem eq 'id') {
7341: $text{'items'} = 'IDs';
7342: $text{'item'} = 'ID';
7343: $text{'action'} = 'an ID';
7344: if ($count > 1) {
7345: $text{'item'} = 'IDs';
7346: $text{'action'} = 'IDs';
7347: }
7348: }
7349: $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 />';
7350: if ($mode eq 'upload') {
7351: if ($checkitem eq 'username') {
7352: $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'}.");
7353: } elsif ($checkitem eq 'id') {
7354: $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.");
7355: }
7356: } elsif ($mode eq 'selfcreate') {
7357: if ($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: } else {
7361: if ($checkitem eq 'username') {
7362: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
7363: } elsif ($checkitem eq 'id') {
7364: $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.");
7365: }
7366: }
7367: return $response;
7368: }
7369:
7370: sub personal_data_fieldtitles {
7371: my %fieldtitles = &Apache::lonlocal::texthash (
7372: id => 'Student/Employee ID',
7373: permanentemail => 'E-mail address',
7374: lastname => 'Last Name',
7375: firstname => 'First Name',
7376: middlename => 'Middle Name',
7377: generation => 'Generation',
7378: gen => 'Generation',
7379: );
7380: return %fieldtitles;
7381: }
7382:
7383: sub sorted_inst_types {
7384: my ($dom) = @_;
7385: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
7386: my $othertitle = &mt('All users');
7387: if ($env{'request.course.id'}) {
7388: $othertitle = &mt('Any users');
7389: }
7390: my @types;
7391: if (ref($order) eq 'ARRAY') {
7392: @types = @{$order};
7393: }
7394: if (@types == 0) {
7395: if (ref($usertypes) eq 'HASH') {
7396: @types = sort(keys(%{$usertypes}));
7397: }
7398: }
7399: if (keys(%{$usertypes}) > 0) {
7400: $othertitle = &mt('Other users');
7401: }
7402: return ($othertitle,$usertypes,\@types);
7403: }
7404:
7405: sub get_institutional_codes {
7406: my ($settings,$allcourses,$LC_code) = @_;
7407: # Get complete list of course sections to update
7408: my @currsections = ();
7409: my @currxlists = ();
7410: my $coursecode = $$settings{'internal.coursecode'};
7411:
7412: if ($$settings{'internal.sectionnums'} ne '') {
7413: @currsections = split(/,/,$$settings{'internal.sectionnums'});
7414: }
7415:
7416: if ($$settings{'internal.crosslistings'} ne '') {
7417: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
7418: }
7419:
7420: if (@currxlists > 0) {
7421: foreach (@currxlists) {
7422: if (m/^([^:]+):(\w*)$/) {
7423: unless (grep/^$1$/,@{$allcourses}) {
7424: push @{$allcourses},$1;
7425: $$LC_code{$1} = $2;
7426: }
7427: }
7428: }
7429: }
7430:
7431: if (@currsections > 0) {
7432: foreach (@currsections) {
7433: if (m/^(\w+):(\w*)$/) {
7434: my $sec = $coursecode.$1;
7435: my $lc_sec = $2;
7436: unless (grep/^$sec$/,@{$allcourses}) {
7437: push @{$allcourses},$sec;
7438: $$LC_code{$sec} = $lc_sec;
7439: }
7440: }
7441: }
7442: }
7443: return;
7444: }
7445:
7446: =pod
7447:
7448: =back
7449:
7450: =head1 HTTP Helpers
7451:
7452: =over 4
7453:
7454: =item * &get_unprocessed_cgi($query,$possible_names)
7455:
7456: Modify the %env hash to contain unprocessed CGI form parameters held in
7457: $query. The parameters listed in $possible_names (an array reference),
7458: will be set in $env{'form.name'} if they do not already exist.
7459:
7460: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
7461: $possible_names is an ref to an array of form element names. As an example:
7462: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
7463: will result in $env{'form.uname'} and $env{'form.udom'} being set.
7464:
7465: =cut
7466:
7467: sub get_unprocessed_cgi {
7468: my ($query,$possible_names)= @_;
7469: # $Apache::lonxml::debug=1;
7470: foreach my $pair (split(/&/,$query)) {
7471: my ($name, $value) = split(/=/,$pair);
7472: $name = &unescape($name);
7473: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
7474: $value =~ tr/+/ /;
7475: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
7476: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
7477: }
7478: }
7479: }
7480:
7481: =pod
7482:
7483: =item * &cacheheader()
7484:
7485: returns cache-controlling header code
7486:
7487: =cut
7488:
7489: sub cacheheader {
7490: unless ($env{'request.method'} eq 'GET') { return ''; }
7491: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
7492: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
7493: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
7494: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
7495: return $output;
7496: }
7497:
7498: =pod
7499:
7500: =item * &no_cache($r)
7501:
7502: specifies header code to not have cache
7503:
7504: =cut
7505:
7506: sub no_cache {
7507: my ($r) = @_;
7508: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
7509: $env{'request.method'} ne 'GET') { return ''; }
7510: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
7511: $r->no_cache(1);
7512: $r->header_out("Expires" => $date);
7513: $r->header_out("Pragma" => "no-cache");
7514: }
7515:
7516: sub content_type {
7517: my ($r,$type,$charset) = @_;
7518: if ($r) {
7519: # Note that printout.pl calls this with undef for $r.
7520: &no_cache($r);
7521: }
7522: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
7523: unless ($charset) {
7524: $charset=&Apache::lonlocal::current_encoding;
7525: }
7526: if ($charset) { $type.='; charset='.$charset; }
7527: if ($r) {
7528: $r->content_type($type);
7529: } else {
7530: print("Content-type: $type\n\n");
7531: }
7532: }
7533:
7534: =pod
7535:
7536: =item * &add_to_env($name,$value)
7537:
7538: adds $name to the %env hash with value
7539: $value, if $name already exists, the entry is converted to an array
7540: reference and $value is added to the array.
7541:
7542: =cut
7543:
7544: sub add_to_env {
7545: my ($name,$value)=@_;
7546: if (defined($env{$name})) {
7547: if (ref($env{$name})) {
7548: #already have multiple values
7549: push(@{ $env{$name} },$value);
7550: } else {
7551: #first time seeing multiple values, convert hash entry to an arrayref
7552: my $first=$env{$name};
7553: undef($env{$name});
7554: push(@{ $env{$name} },$first,$value);
7555: }
7556: } else {
7557: $env{$name}=$value;
7558: }
7559: }
7560:
7561: =pod
7562:
7563: =item * &get_env_multiple($name)
7564:
7565: gets $name from the %env hash, it seemlessly handles the cases where multiple
7566: values may be defined and end up as an array ref.
7567:
7568: returns an array of values
7569:
7570: =cut
7571:
7572: sub get_env_multiple {
7573: my ($name) = @_;
7574: my @values;
7575: if (defined($env{$name})) {
7576: # exists is it an array
7577: if (ref($env{$name})) {
7578: @values=@{ $env{$name} };
7579: } else {
7580: $values[0]=$env{$name};
7581: }
7582: }
7583: return(@values);
7584: }
7585:
7586: sub ask_for_embedded_content {
7587: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
7588: my $upload_output = '
7589: <form name="upload_embedded" action="'.$actionurl.'"
7590: method="post" enctype="multipart/form-data">';
7591: $upload_output .= $state;
7592: $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
7593:
7594: my $num = 0;
7595: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
7596: $upload_output .= &start_data_table_row().
7597: '<td>'.$embed_file.'</td><td>';
7598: if ($args->{'ignore_remote_references'}
7599: && $embed_file =~ m{^\w+://}) {
7600: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
7601: } elsif ($args->{'error_on_invalid_names'}
7602: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
7603:
7604: $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
7605:
7606: } else {
7607: $upload_output .='
7608: <input name="embedded_item_'.$num.'" type="file" value="" />
7609: <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
7610: my $attrib = join(':',@{$$allfiles{$embed_file}});
7611: $upload_output .=
7612: "\n\t\t".
7613: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
7614: $attrib.'" />';
7615: if (exists($$codebase{$embed_file})) {
7616: $upload_output .=
7617: "\n\t\t".
7618: '<input name="codebase_'.$num.'" type="hidden" value="'.
7619: &escape($$codebase{$embed_file}).'" />';
7620: }
7621: }
7622: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
7623: $num++;
7624: }
7625: $upload_output .= &Apache::loncommon::end_data_table().'<br />
7626: <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
7627: <input type ="submit" value="'.&mt('Upload Listed Files').'" />
7628: '.&mt('(only files for which a location has been provided will be uploaded)').'
7629: </form>';
7630: return $upload_output;
7631: }
7632:
7633: sub upload_embedded {
7634: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
7635: $current_disk_usage) = @_;
7636: my $output;
7637: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
7638: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
7639: my $orig_uploaded_filename =
7640: $env{'form.embedded_item_'.$i.'.filename'};
7641:
7642: $env{'form.embedded_orig_'.$i} =
7643: &unescape($env{'form.embedded_orig_'.$i});
7644: my ($path,$fname) =
7645: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
7646: # no path, whole string is fname
7647: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
7648:
7649: $path = $env{'form.currentpath'}.$path;
7650: $fname = &Apache::lonnet::clean_filename($fname);
7651: # See if there is anything left
7652: next if ($fname eq '');
7653:
7654: # Check if file already exists as a file or directory.
7655: my ($state,$msg);
7656: if ($context eq 'portfolio') {
7657: my $port_path = $dirpath;
7658: if ($group ne '') {
7659: $port_path = "groups/$group/$port_path";
7660: }
7661: ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
7662: $dir_root,$port_path,$disk_quota,
7663: $current_disk_usage,$uname,$udom);
7664: if ($state eq 'will_exceed_quota'
7665: || $state eq 'file_locked'
7666: || $state eq 'file_exists' ) {
7667: $output .= $msg;
7668: next;
7669: }
7670: } elsif (($context eq 'author') || ($context eq 'testbank')) {
7671: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
7672: if ($state eq 'exists') {
7673: $output .= $msg;
7674: next;
7675: }
7676: }
7677: # Check if extension is valid
7678: if (($fname =~ /\.(\w+)$/) &&
7679: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
7680: $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
7681: next;
7682: } elsif (($fname =~ /\.(\w+)$/) &&
7683: (!defined(&Apache::loncommon::fileembstyle($1)))) {
7684: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
7685: next;
7686: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
7687: $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
7688: next;
7689: }
7690:
7691: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
7692: if ($context eq 'portfolio') {
7693: my $result=
7694: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
7695: $dirpath.$path);
7696: if ($result !~ m|^/uploaded/|) {
7697: $output .= '<span class="LC_error">'
7698: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
7699: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
7700: .'</span><br />';
7701: next;
7702: } else {
7703: $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
7704: $path.$fname.'</span>').'</p>';
7705: }
7706: } else {
7707: # Save the file
7708: my $target = $env{'form.embedded_item_'.$i};
7709: my $fullpath = $dir_root.$dirpath.'/'.$path;
7710: my $dest = $fullpath.$fname;
7711: my $url = $url_root.$dirpath.'/'.$path.$fname;
7712: my @parts=split(/\//,$fullpath);
7713: my $count;
7714: my $filepath = $dir_root;
7715: for ($count=4;$count<=$#parts;$count++) {
7716: $filepath .= "/$parts[$count]";
7717: if ((-e $filepath)!=1) {
7718: mkdir($filepath,0770);
7719: }
7720: }
7721: my $fh;
7722: if (!open($fh,'>'.$dest)) {
7723: &Apache::lonnet::logthis('Failed to create '.$dest);
7724: $output .= '<span class="LC_error">'.
7725: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
7726: '</span><br />';
7727: } else {
7728: if (!print $fh $env{'form.embedded_item_'.$i}) {
7729: &Apache::lonnet::logthis('Failed to write to '.$dest);
7730: $output .= '<span class="LC_error">'.
7731: &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
7732: '</span><br />';
7733: } else {
7734: if ($context eq 'testbank') {
7735: $output .= &mt('Embedded file uploaded successfully:').
7736: ' <a href="'.$url.'">'.
7737: $orig_uploaded_filename.'</a><br />';
7738: } else {
7739: $output .= '<span class=\"LC_fontsize_large\">'.
7740: &mt('View embedded file: [_1]','<a href="'.$url.'">'.
7741: $orig_uploaded_filename.'</a>').'</span><br />';
7742: }
7743: }
7744: close($fh);
7745: }
7746: }
7747: }
7748: return $output;
7749: }
7750:
7751: sub check_for_existing {
7752: my ($path,$fname,$element) = @_;
7753: my ($state,$msg);
7754: if (-d $path.'/'.$fname) {
7755: $state = 'exists';
7756: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
7757: } elsif (-e $path.'/'.$fname) {
7758: $state = 'exists';
7759: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
7760: }
7761: if ($state eq 'exists') {
7762: $msg = '<span class="LC_error">'.$msg.'</span><br />';
7763: }
7764: return ($state,$msg);
7765: }
7766:
7767: sub check_for_upload {
7768: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
7769: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
7770: my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
7771: my $getpropath = 1;
7772: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
7773: $getpropath);
7774: my $found_file = 0;
7775: my $locked_file = 0;
7776: foreach my $line (@dir_list) {
7777: my ($file_name)=split(/\&/,$line,2);
7778: if ($file_name eq $fname){
7779: $file_name = $path.$file_name;
7780: if ($group ne '') {
7781: $file_name = $group.$file_name;
7782: }
7783: $found_file = 1;
7784: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
7785: $locked_file = 1;
7786: }
7787: }
7788: }
7789: if (($current_disk_usage + $filesize) > $disk_quota){
7790: my $msg = '<span class="LC_error">'.
7791: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
7792: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
7793: return ('will_exceed_quota',$msg);
7794: } elsif ($found_file) {
7795: if ($locked_file) {
7796: my $msg = '<span class="LC_error">';
7797: $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>');
7798: $msg .= '</span><br />';
7799: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
7800: return ('file_locked',$msg);
7801: } else {
7802: my $msg = '<span class="LC_error">';
7803: $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'});
7804: $msg .= '</span>';
7805: $msg .= '<br />';
7806: $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
7807: return ('file_exists',$msg);
7808: }
7809: }
7810: }
7811:
7812:
7813: =pod
7814:
7815: =back
7816:
7817: =head1 CSV Upload/Handling functions
7818:
7819: =over 4
7820:
7821: =item * &upfile_store($r)
7822:
7823: Store uploaded file, $r should be the HTTP Request object,
7824: needs $env{'form.upfile'}
7825: returns $datatoken to be put into hidden field
7826:
7827: =cut
7828:
7829: sub upfile_store {
7830: my $r=shift;
7831: $env{'form.upfile'}=~s/\r/\n/gs;
7832: $env{'form.upfile'}=~s/\f/\n/gs;
7833: $env{'form.upfile'}=~s/\n+/\n/gs;
7834: $env{'form.upfile'}=~s/\n+$//gs;
7835:
7836: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
7837: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
7838: {
7839: my $datafile = $r->dir_config('lonDaemons').
7840: '/tmp/'.$datatoken.'.tmp';
7841: if ( open(my $fh,">$datafile") ) {
7842: print $fh $env{'form.upfile'};
7843: close($fh);
7844: }
7845: }
7846: return $datatoken;
7847: }
7848:
7849: =pod
7850:
7851: =item * &load_tmp_file($r)
7852:
7853: Load uploaded file from tmp, $r should be the HTTP Request object,
7854: needs $env{'form.datatoken'},
7855: sets $env{'form.upfile'} to the contents of the file
7856:
7857: =cut
7858:
7859: sub load_tmp_file {
7860: my $r=shift;
7861: my @studentdata=();
7862: {
7863: my $studentfile = $r->dir_config('lonDaemons').
7864: '/tmp/'.$env{'form.datatoken'}.'.tmp';
7865: if ( open(my $fh,"<$studentfile") ) {
7866: @studentdata=<$fh>;
7867: close($fh);
7868: }
7869: }
7870: $env{'form.upfile'}=join('',@studentdata);
7871: }
7872:
7873: =pod
7874:
7875: =item * &upfile_record_sep()
7876:
7877: Separate uploaded file into records
7878: returns array of records,
7879: needs $env{'form.upfile'} and $env{'form.upfiletype'}
7880:
7881: =cut
7882:
7883: sub upfile_record_sep {
7884: if ($env{'form.upfiletype'} eq 'xml') {
7885: } else {
7886: my @records;
7887: foreach my $line (split(/\n/,$env{'form.upfile'})) {
7888: if ($line=~/^\s*$/) { next; }
7889: push(@records,$line);
7890: }
7891: return @records;
7892: }
7893: }
7894:
7895: =pod
7896:
7897: =item * &record_sep($record)
7898:
7899: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
7900:
7901: =cut
7902:
7903: sub takeleft {
7904: my $index=shift;
7905: return substr('0000'.$index,-4,4);
7906: }
7907:
7908: sub record_sep {
7909: my $record=shift;
7910: my %components=();
7911: if ($env{'form.upfiletype'} eq 'xml') {
7912: } elsif ($env{'form.upfiletype'} eq 'space') {
7913: my $i=0;
7914: foreach my $field (split(/\s+/,$record)) {
7915: $field=~s/^(\"|\')//;
7916: $field=~s/(\"|\')$//;
7917: $components{&takeleft($i)}=$field;
7918: $i++;
7919: }
7920: } elsif ($env{'form.upfiletype'} eq 'tab') {
7921: my $i=0;
7922: foreach my $field (split(/\t/,$record)) {
7923: $field=~s/^(\"|\')//;
7924: $field=~s/(\"|\')$//;
7925: $components{&takeleft($i)}=$field;
7926: $i++;
7927: }
7928: } else {
7929: my $separator=',';
7930: if ($env{'form.upfiletype'} eq 'semisv') {
7931: $separator=';';
7932: }
7933: my $i=0;
7934: # the character we are looking for to indicate the end of a quote or a record
7935: my $looking_for=$separator;
7936: # do not add the characters to the fields
7937: my $ignore=0;
7938: # we just encountered a separator (or the beginning of the record)
7939: my $just_found_separator=1;
7940: # store the field we are working on here
7941: my $field='';
7942: # work our way through all characters in record
7943: foreach my $character ($record=~/(.)/g) {
7944: if ($character eq $looking_for) {
7945: if ($character ne $separator) {
7946: # Found the end of a quote, again looking for separator
7947: $looking_for=$separator;
7948: $ignore=1;
7949: } else {
7950: # Found a separator, store away what we got
7951: $components{&takeleft($i)}=$field;
7952: $i++;
7953: $just_found_separator=1;
7954: $ignore=0;
7955: $field='';
7956: }
7957: next;
7958: }
7959: # single or double quotation marks after a separator indicate beginning of a quote
7960: # we are now looking for the end of the quote and need to ignore separators
7961: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
7962: $looking_for=$character;
7963: next;
7964: }
7965: # ignore would be true after we reached the end of a quote
7966: if ($ignore) { next; }
7967: if (($just_found_separator) && ($character=~/\s/)) { next; }
7968: $field.=$character;
7969: $just_found_separator=0;
7970: }
7971: # catch the very last entry, since we never encountered the separator
7972: $components{&takeleft($i)}=$field;
7973: }
7974: return %components;
7975: }
7976:
7977: ######################################################
7978: ######################################################
7979:
7980: =pod
7981:
7982: =item * &upfile_select_html()
7983:
7984: Return HTML code to select a file from the users machine and specify
7985: the file type.
7986:
7987: =cut
7988:
7989: ######################################################
7990: ######################################################
7991: sub upfile_select_html {
7992: my %Types = (
7993: csv => &mt('CSV (comma separated values, spreadsheet)'),
7994: semisv => &mt('Semicolon separated values'),
7995: space => &mt('Space separated'),
7996: tab => &mt('Tabulator separated'),
7997: # xml => &mt('HTML/XML'),
7998: );
7999: my $Str = '<input type="file" name="upfile" size="50" />'.
8000: '<br />'.&mt('Type').': <select name="upfiletype">';
8001: foreach my $type (sort(keys(%Types))) {
8002: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
8003: }
8004: $Str .= "</select>\n";
8005: return $Str;
8006: }
8007:
8008: sub get_samples {
8009: my ($records,$toget) = @_;
8010: my @samples=({});
8011: my $got=0;
8012: foreach my $rec (@$records) {
8013: my %temp = &record_sep($rec);
8014: if (! grep(/\S/, values(%temp))) { next; }
8015: if (%temp) {
8016: $samples[$got]=\%temp;
8017: $got++;
8018: if ($got == $toget) { last; }
8019: }
8020: }
8021: return \@samples;
8022: }
8023:
8024: ######################################################
8025: ######################################################
8026:
8027: =pod
8028:
8029: =item * &csv_print_samples($r,$records)
8030:
8031: Prints a table of sample values from each column uploaded $r is an
8032: Apache Request ref, $records is an arrayref from
8033: &Apache::loncommon::upfile_record_sep
8034:
8035: =cut
8036:
8037: ######################################################
8038: ######################################################
8039: sub csv_print_samples {
8040: my ($r,$records) = @_;
8041: my $samples = &get_samples($records,5);
8042:
8043: $r->print(&mt('Samples').'<br />'.&start_data_table().
8044: &start_data_table_header_row());
8045: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8046: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
8047: $r->print(&end_data_table_header_row());
8048: foreach my $hash (@$samples) {
8049: $r->print(&start_data_table_row());
8050: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8051: $r->print('<td>');
8052: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
8053: $r->print('</td>');
8054: }
8055: $r->print(&end_data_table_row());
8056: }
8057: $r->print(&end_data_table().'<br />'."\n");
8058: }
8059:
8060: ######################################################
8061: ######################################################
8062:
8063: =pod
8064:
8065: =item * &csv_print_select_table($r,$records,$d)
8066:
8067: Prints a table to create associations between values and table columns.
8068:
8069: $r is an Apache Request ref,
8070: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
8071: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
8072:
8073: =cut
8074:
8075: ######################################################
8076: ######################################################
8077: sub csv_print_select_table {
8078: my ($r,$records,$d) = @_;
8079: my $i=0;
8080: my $samples = &get_samples($records,1);
8081: $r->print(&mt('Associate columns with student attributes.')."\n".
8082: &start_data_table().&start_data_table_header_row().
8083: '<th>'.&mt('Attribute').'</th>'.
8084: '<th>'.&mt('Column').'</th>'.
8085: &end_data_table_header_row()."\n");
8086: foreach my $array_ref (@$d) {
8087: my ($value,$display,$defaultcol)=@{ $array_ref };
8088: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
8089:
8090: $r->print('<td><select name=f'.$i.
8091: ' onchange="javascript:flip(this.form,'.$i.');">');
8092: $r->print('<option value="none"></option>');
8093: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8094: $r->print('<option value="'.$sample.'"'.
8095: ($sample eq $defaultcol ? ' selected="selected" ' : '').
8096: '>'.&mt('Column [_1]',($sample+1)).'</option>');
8097: }
8098: $r->print('</select></td>'.&end_data_table_row()."\n");
8099: $i++;
8100: }
8101: $r->print(&end_data_table());
8102: $i--;
8103: return $i;
8104: }
8105:
8106: ######################################################
8107: ######################################################
8108:
8109: =pod
8110:
8111: =item * &csv_samples_select_table($r,$records,$d)
8112:
8113: Prints a table of sample values from the upload and can make associate samples to internal names.
8114:
8115: $r is an Apache Request ref,
8116: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
8117: $d is an array of 2 element arrays (internal name, displayed name)
8118:
8119: =cut
8120:
8121: ######################################################
8122: ######################################################
8123: sub csv_samples_select_table {
8124: my ($r,$records,$d) = @_;
8125: my $i=0;
8126: #
8127: my $max_samples = 5;
8128: my $samples = &get_samples($records,$max_samples);
8129: $r->print(&start_data_table().
8130: &start_data_table_header_row().'<th>'.
8131: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
8132: &end_data_table_header_row());
8133:
8134: foreach my $key (sort(keys(%{ $samples->[0] }))) {
8135: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
8136: ' onchange="javascript:flip(this.form,'.$i.');">');
8137: foreach my $option (@$d) {
8138: my ($value,$display,$defaultcol)=@{ $option };
8139: $r->print('<option value="'.$value.'"'.
8140: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
8141: $display.'</option>');
8142: }
8143: $r->print('</select></td><td>');
8144: foreach my $line (0..($max_samples-1)) {
8145: if (defined($samples->[$line]{$key})) {
8146: $r->print($samples->[$line]{$key}."<br />\n");
8147: }
8148: }
8149: $r->print('</td>'.&end_data_table_row());
8150: $i++;
8151: }
8152: $r->print(&end_data_table());
8153: $i--;
8154: return($i);
8155: }
8156:
8157: ######################################################
8158: ######################################################
8159:
8160: =pod
8161:
8162: =item * &clean_excel_name($name)
8163:
8164: Returns a replacement for $name which does not contain any illegal characters.
8165:
8166: =cut
8167:
8168: ######################################################
8169: ######################################################
8170: sub clean_excel_name {
8171: my ($name) = @_;
8172: $name =~ s/[:\*\?\/\\]//g;
8173: if (length($name) > 31) {
8174: $name = substr($name,0,31);
8175: }
8176: return $name;
8177: }
8178:
8179: =pod
8180:
8181: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
8182:
8183: Returns either 1 or undef
8184:
8185: 1 if the part is to be hidden, undef if it is to be shown
8186:
8187: Arguments are:
8188:
8189: $id the id of the part to be checked
8190: $symb, optional the symb of the resource to check
8191: $udom, optional the domain of the user to check for
8192: $uname, optional the username of the user to check for
8193:
8194: =cut
8195:
8196: sub check_if_partid_hidden {
8197: my ($id,$symb,$udom,$uname) = @_;
8198: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
8199: $symb,$udom,$uname);
8200: my $truth=1;
8201: #if the string starts with !, then the list is the list to show not hide
8202: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
8203: my @hiddenlist=split(/,/,$hiddenparts);
8204: foreach my $checkid (@hiddenlist) {
8205: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
8206: }
8207: return !$truth;
8208: }
8209:
8210:
8211: ############################################################
8212: ############################################################
8213:
8214: =pod
8215:
8216: =back
8217:
8218: =head1 cgi-bin script and graphing routines
8219:
8220: =over 4
8221:
8222: =item * &get_cgi_id()
8223:
8224: Inputs: none
8225:
8226: Returns an id which can be used to pass environment variables
8227: to various cgi-bin scripts. These environment variables will
8228: be removed from the users environment after a given time by
8229: the routine &Apache::lonnet::transfer_profile_to_env.
8230:
8231: =cut
8232:
8233: ############################################################
8234: ############################################################
8235: my $uniq=0;
8236: sub get_cgi_id {
8237: $uniq=($uniq+1)%100000;
8238: return (time.'_'.$$.'_'.$uniq);
8239: }
8240:
8241: ############################################################
8242: ############################################################
8243:
8244: =pod
8245:
8246: =item * &DrawBarGraph()
8247:
8248: Facilitates the plotting of data in a (stacked) bar graph.
8249: Puts plot definition data into the users environment in order for
8250: graph.png to plot it. Returns an <img> tag for the plot.
8251: The bars on the plot are labeled '1','2',...,'n'.
8252:
8253: Inputs:
8254:
8255: =over 4
8256:
8257: =item $Title: string, the title of the plot
8258:
8259: =item $xlabel: string, text describing the X-axis of the plot
8260:
8261: =item $ylabel: string, text describing the Y-axis of the plot
8262:
8263: =item $Max: scalar, the maximum Y value to use in the plot
8264: If $Max is < any data point, the graph will not be rendered.
8265:
8266: =item $colors: array ref holding the colors to be used for the data sets when
8267: they are plotted. If undefined, default values will be used.
8268:
8269: =item $labels: array ref holding the labels to use on the x-axis for the bars.
8270:
8271: =item @Values: An array of array references. Each array reference holds data
8272: to be plotted in a stacked bar chart.
8273:
8274: =item If the final element of @Values is a hash reference the key/value
8275: pairs will be added to the graph definition.
8276:
8277: =back
8278:
8279: Returns:
8280:
8281: An <img> tag which references graph.png and the appropriate identifying
8282: information for the plot.
8283:
8284: =cut
8285:
8286: ############################################################
8287: ############################################################
8288: sub DrawBarGraph {
8289: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
8290: #
8291: if (! defined($colors)) {
8292: $colors = ['#33ff00',
8293: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
8294: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
8295: ];
8296: }
8297: my $extra_settings = {};
8298: if (ref($Values[-1]) eq 'HASH') {
8299: $extra_settings = pop(@Values);
8300: }
8301: #
8302: my $identifier = &get_cgi_id();
8303: my $id = 'cgi.'.$identifier;
8304: if (! @Values || ref($Values[0]) ne 'ARRAY') {
8305: return '';
8306: }
8307: #
8308: my @Labels;
8309: if (defined($labels)) {
8310: @Labels = @$labels;
8311: } else {
8312: for (my $i=0;$i<@{$Values[0]};$i++) {
8313: push (@Labels,$i+1);
8314: }
8315: }
8316: #
8317: my $NumBars = scalar(@{$Values[0]});
8318: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
8319: my %ValuesHash;
8320: my $NumSets=1;
8321: foreach my $array (@Values) {
8322: next if (! ref($array));
8323: $ValuesHash{$id.'.data.'.$NumSets++} =
8324: join(',',@$array);
8325: }
8326: #
8327: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
8328: if ($NumBars < 3) {
8329: $width = 120+$NumBars*32;
8330: $xskip = 1;
8331: $bar_width = 30;
8332: } elsif ($NumBars < 5) {
8333: $width = 120+$NumBars*20;
8334: $xskip = 1;
8335: $bar_width = 20;
8336: } elsif ($NumBars < 10) {
8337: $width = 120+$NumBars*15;
8338: $xskip = 1;
8339: $bar_width = 15;
8340: } elsif ($NumBars <= 25) {
8341: $width = 120+$NumBars*11;
8342: $xskip = 5;
8343: $bar_width = 8;
8344: } elsif ($NumBars <= 50) {
8345: $width = 120+$NumBars*8;
8346: $xskip = 5;
8347: $bar_width = 4;
8348: } else {
8349: $width = 120+$NumBars*8;
8350: $xskip = 5;
8351: $bar_width = 4;
8352: }
8353: #
8354: $Max = 1 if ($Max < 1);
8355: if ( int($Max) < $Max ) {
8356: $Max++;
8357: $Max = int($Max);
8358: }
8359: $Title = '' if (! defined($Title));
8360: $xlabel = '' if (! defined($xlabel));
8361: $ylabel = '' if (! defined($ylabel));
8362: $ValuesHash{$id.'.title'} = &escape($Title);
8363: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
8364: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
8365: $ValuesHash{$id.'.y_max_value'} = $Max;
8366: $ValuesHash{$id.'.NumBars'} = $NumBars;
8367: $ValuesHash{$id.'.NumSets'} = $NumSets;
8368: $ValuesHash{$id.'.PlotType'} = 'bar';
8369: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8370: $ValuesHash{$id.'.height'} = $height;
8371: $ValuesHash{$id.'.width'} = $width;
8372: $ValuesHash{$id.'.xskip'} = $xskip;
8373: $ValuesHash{$id.'.bar_width'} = $bar_width;
8374: $ValuesHash{$id.'.labels'} = join(',',@Labels);
8375: #
8376: # Deal with other parameters
8377: while (my ($key,$value) = each(%$extra_settings)) {
8378: $ValuesHash{$id.'.'.$key} = $value;
8379: }
8380: #
8381: &Apache::lonnet::appenv(\%ValuesHash);
8382: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8383: }
8384:
8385: ############################################################
8386: ############################################################
8387:
8388: =pod
8389:
8390: =item * &DrawXYGraph()
8391:
8392: Facilitates the plotting of data in an XY graph.
8393: Puts plot definition data into the users environment in order for
8394: graph.png to plot it. Returns an <img> tag for the plot.
8395:
8396: Inputs:
8397:
8398: =over 4
8399:
8400: =item $Title: string, the title of the plot
8401:
8402: =item $xlabel: string, text describing the X-axis of the plot
8403:
8404: =item $ylabel: string, text describing the Y-axis of the plot
8405:
8406: =item $Max: scalar, the maximum Y value to use in the plot
8407: If $Max is < any data point, the graph will not be rendered.
8408:
8409: =item $colors: Array ref containing the hex color codes for the data to be
8410: plotted in. If undefined, default values will be used.
8411:
8412: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8413:
8414: =item $Ydata: Array ref containing Array refs.
8415: Each of the contained arrays will be plotted as a separate curve.
8416:
8417: =item %Values: hash indicating or overriding any default values which are
8418: passed to graph.png.
8419: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
8420:
8421: =back
8422:
8423: Returns:
8424:
8425: An <img> tag which references graph.png and the appropriate identifying
8426: information for the plot.
8427:
8428: =cut
8429:
8430: ############################################################
8431: ############################################################
8432: sub DrawXYGraph {
8433: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
8434: #
8435: # Create the identifier for the graph
8436: my $identifier = &get_cgi_id();
8437: my $id = 'cgi.'.$identifier;
8438: #
8439: $Title = '' if (! defined($Title));
8440: $xlabel = '' if (! defined($xlabel));
8441: $ylabel = '' if (! defined($ylabel));
8442: my %ValuesHash =
8443: (
8444: $id.'.title' => &escape($Title),
8445: $id.'.xlabel' => &escape($xlabel),
8446: $id.'.ylabel' => &escape($ylabel),
8447: $id.'.y_max_value'=> $Max,
8448: $id.'.labels' => join(',',@$Xlabels),
8449: $id.'.PlotType' => 'XY',
8450: );
8451: #
8452: if (defined($colors) && ref($colors) eq 'ARRAY') {
8453: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8454: }
8455: #
8456: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
8457: return '';
8458: }
8459: my $NumSets=1;
8460: foreach my $array (@{$Ydata}){
8461: next if (! ref($array));
8462: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
8463: }
8464: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
8465: #
8466: # Deal with other parameters
8467: while (my ($key,$value) = each(%Values)) {
8468: $ValuesHash{$id.'.'.$key} = $value;
8469: }
8470: #
8471: &Apache::lonnet::appenv(\%ValuesHash);
8472: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8473: }
8474:
8475: ############################################################
8476: ############################################################
8477:
8478: =pod
8479:
8480: =item * &DrawXYYGraph()
8481:
8482: Facilitates the plotting of data in an XY graph with two Y axes.
8483: Puts plot definition data into the users environment in order for
8484: graph.png to plot it. Returns an <img> tag for the plot.
8485:
8486: Inputs:
8487:
8488: =over 4
8489:
8490: =item $Title: string, the title of the plot
8491:
8492: =item $xlabel: string, text describing the X-axis of the plot
8493:
8494: =item $ylabel: string, text describing the Y-axis of the plot
8495:
8496: =item $colors: Array ref containing the hex color codes for the data to be
8497: plotted in. If undefined, default values will be used.
8498:
8499: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8500:
8501: =item $Ydata1: The first data set
8502:
8503: =item $Min1: The minimum value of the left Y-axis
8504:
8505: =item $Max1: The maximum value of the left Y-axis
8506:
8507: =item $Ydata2: The second data set
8508:
8509: =item $Min2: The minimum value of the right Y-axis
8510:
8511: =item $Max2: The maximum value of the left Y-axis
8512:
8513: =item %Values: hash indicating or overriding any default values which are
8514: passed to graph.png.
8515: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
8516:
8517: =back
8518:
8519: Returns:
8520:
8521: An <img> tag which references graph.png and the appropriate identifying
8522: information for the plot.
8523:
8524: =cut
8525:
8526: ############################################################
8527: ############################################################
8528: sub DrawXYYGraph {
8529: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
8530: $Ydata2,$Min2,$Max2,%Values)=@_;
8531: #
8532: # Create the identifier for the graph
8533: my $identifier = &get_cgi_id();
8534: my $id = 'cgi.'.$identifier;
8535: #
8536: $Title = '' if (! defined($Title));
8537: $xlabel = '' if (! defined($xlabel));
8538: $ylabel = '' if (! defined($ylabel));
8539: my %ValuesHash =
8540: (
8541: $id.'.title' => &escape($Title),
8542: $id.'.xlabel' => &escape($xlabel),
8543: $id.'.ylabel' => &escape($ylabel),
8544: $id.'.labels' => join(',',@$Xlabels),
8545: $id.'.PlotType' => 'XY',
8546: $id.'.NumSets' => 2,
8547: $id.'.two_axes' => 1,
8548: $id.'.y1_max_value' => $Max1,
8549: $id.'.y1_min_value' => $Min1,
8550: $id.'.y2_max_value' => $Max2,
8551: $id.'.y2_min_value' => $Min2,
8552: );
8553: #
8554: if (defined($colors) && ref($colors) eq 'ARRAY') {
8555: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8556: }
8557: #
8558: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
8559: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
8560: return '';
8561: }
8562: my $NumSets=1;
8563: foreach my $array ($Ydata1,$Ydata2){
8564: next if (! ref($array));
8565: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
8566: }
8567: #
8568: # Deal with other parameters
8569: while (my ($key,$value) = each(%Values)) {
8570: $ValuesHash{$id.'.'.$key} = $value;
8571: }
8572: #
8573: &Apache::lonnet::appenv(\%ValuesHash);
8574: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8575: }
8576:
8577: ############################################################
8578: ############################################################
8579:
8580: =pod
8581:
8582: =back
8583:
8584: =head1 Statistics helper routines?
8585:
8586: Bad place for them but what the hell.
8587:
8588: =over 4
8589:
8590: =item * &chartlink()
8591:
8592: Returns a link to the chart for a specific student.
8593:
8594: Inputs:
8595:
8596: =over 4
8597:
8598: =item $linktext: The text of the link
8599:
8600: =item $sname: The students username
8601:
8602: =item $sdomain: The students domain
8603:
8604: =back
8605:
8606: =back
8607:
8608: =cut
8609:
8610: ############################################################
8611: ############################################################
8612: sub chartlink {
8613: my ($linktext, $sname, $sdomain) = @_;
8614: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
8615: '&SelectedStudent='.&escape($sname.':'.$sdomain).
8616: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
8617: '">'.$linktext.'</a>';
8618: }
8619:
8620: #######################################################
8621: #######################################################
8622:
8623: =pod
8624:
8625: =head1 Course Environment Routines
8626:
8627: =over 4
8628:
8629: =item * &restore_course_settings()
8630:
8631: =item * &store_course_settings()
8632:
8633: Restores/Store indicated form parameters from the course environment.
8634: Will not overwrite existing values of the form parameters.
8635:
8636: Inputs:
8637: a scalar describing the data (e.g. 'chart', 'problem_analysis')
8638:
8639: a hash ref describing the data to be stored. For example:
8640:
8641: %Save_Parameters = ('Status' => 'scalar',
8642: 'chartoutputmode' => 'scalar',
8643: 'chartoutputdata' => 'scalar',
8644: 'Section' => 'array',
8645: 'Group' => 'array',
8646: 'StudentData' => 'array',
8647: 'Maps' => 'array');
8648:
8649: Returns: both routines return nothing
8650:
8651: =back
8652:
8653: =cut
8654:
8655: #######################################################
8656: #######################################################
8657: sub store_course_settings {
8658: return &store_settings($env{'request.course.id'},@_);
8659: }
8660:
8661: sub store_settings {
8662: # save to the environment
8663: # appenv the same items, just to be safe
8664: my $udom = $env{'user.domain'};
8665: my $uname = $env{'user.name'};
8666: my ($context,$prefix,$Settings) = @_;
8667: my %SaveHash;
8668: my %AppHash;
8669: while (my ($setting,$type) = each(%$Settings)) {
8670: my $basename = join('.','internal',$context,$prefix,$setting);
8671: my $envname = 'environment.'.$basename;
8672: if (exists($env{'form.'.$setting})) {
8673: # Save this value away
8674: if ($type eq 'scalar' &&
8675: (! exists($env{$envname}) ||
8676: $env{$envname} ne $env{'form.'.$setting})) {
8677: $SaveHash{$basename} = $env{'form.'.$setting};
8678: $AppHash{$envname} = $env{'form.'.$setting};
8679: } elsif ($type eq 'array') {
8680: my $stored_form;
8681: if (ref($env{'form.'.$setting})) {
8682: $stored_form = join(',',
8683: map {
8684: &escape($_);
8685: } sort(@{$env{'form.'.$setting}}));
8686: } else {
8687: $stored_form =
8688: &escape($env{'form.'.$setting});
8689: }
8690: # Determine if the array contents are the same.
8691: if ($stored_form ne $env{$envname}) {
8692: $SaveHash{$basename} = $stored_form;
8693: $AppHash{$envname} = $stored_form;
8694: }
8695: }
8696: }
8697: }
8698: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
8699: $udom,$uname);
8700: if ($put_result !~ /^(ok|delayed)/) {
8701: &Apache::lonnet::logthis('unable to save form parameters, '.
8702: 'got error:'.$put_result);
8703: }
8704: # Make sure these settings stick around in this session, too
8705: &Apache::lonnet::appenv(\%AppHash);
8706: return;
8707: }
8708:
8709: sub restore_course_settings {
8710: return &restore_settings($env{'request.course.id'},@_);
8711: }
8712:
8713: sub restore_settings {
8714: my ($context,$prefix,$Settings) = @_;
8715: while (my ($setting,$type) = each(%$Settings)) {
8716: next if (exists($env{'form.'.$setting}));
8717: my $envname = 'environment.internal.'.$context.'.'.$prefix.
8718: '.'.$setting;
8719: if (exists($env{$envname})) {
8720: if ($type eq 'scalar') {
8721: $env{'form.'.$setting} = $env{$envname};
8722: } elsif ($type eq 'array') {
8723: $env{'form.'.$setting} = [
8724: map {
8725: &unescape($_);
8726: } split(',',$env{$envname})
8727: ];
8728: }
8729: }
8730: }
8731: }
8732:
8733: #######################################################
8734: #######################################################
8735:
8736: =pod
8737:
8738: =head1 Domain E-mail Routines
8739:
8740: =over 4
8741:
8742: =item * &build_recipient_list()
8743:
8744: Build recipient lists for three types of e-mail:
8745: (a) Error Reports, (b) Package Updates, (c) Help requests, generated by
8746: lonerrorhandler.pm, CHECKRPMS and lonsupportreq.pm respectively.
8747:
8748: Inputs:
8749: defmail (scalar - email address of default recipient),
8750: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
8751: defdom (domain for which to retrieve configuration settings),
8752: origmail (scalar - email address of recipient from loncapa.conf,
8753: i.e., predates configuration by DC via domainprefs.pm
8754:
8755: Returns: comma separated list of addresses to which to send e-mail.
8756:
8757: =back
8758:
8759: =cut
8760:
8761: ############################################################
8762: ############################################################
8763: sub build_recipient_list {
8764: my ($defmail,$mailing,$defdom,$origmail) = @_;
8765: my @recipients;
8766: my $otheremails;
8767: my %domconfig =
8768: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
8769: if (ref($domconfig{'contacts'}) eq 'HASH') {
8770: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
8771: my @contacts = ('adminemail','supportemail');
8772: foreach my $item (@contacts) {
8773: if ($domconfig{'contacts'}{$mailing}{$item}) {
8774: my $addr = $domconfig{'contacts'}{$item};
8775: if (!grep(/^\Q$addr\E$/,@recipients)) {
8776: push(@recipients,$addr);
8777: }
8778: }
8779: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
8780: }
8781: }
8782: } elsif ($origmail ne '') {
8783: push(@recipients,$origmail);
8784: }
8785: if (defined($defmail)) {
8786: if ($defmail ne '') {
8787: push(@recipients,$defmail);
8788: }
8789: }
8790: if ($otheremails) {
8791: my @others;
8792: if ($otheremails =~ /,/) {
8793: @others = split(/,/,$otheremails);
8794: } else {
8795: push(@others,$otheremails);
8796: }
8797: foreach my $addr (@others) {
8798: if (!grep(/^\Q$addr\E$/,@recipients)) {
8799: push(@recipients,$addr);
8800: }
8801: }
8802: }
8803: my $recipientlist = join(',',@recipients);
8804: return $recipientlist;
8805: }
8806:
8807: ############################################################
8808: ############################################################
8809:
8810: =pod
8811:
8812: =head1 Course Catalog Routines
8813:
8814: =over 4
8815:
8816: =item * &gather_categories()
8817:
8818: Converts category definitions - keys of categories hash stored in
8819: coursecategories in configuration.db on the primary library server in a
8820: domain - to an array. Also generates javascript and idx hash used to
8821: generate Domain Coordinator interface for editing Course Categories.
8822:
8823: Inputs:
8824:
8825: categories (reference to hash of category definitions).
8826:
8827: cats (reference to array of arrays/hashes which encapsulates hierarchy of
8828: categories and subcategories).
8829:
8830: idx (reference to hash of counters used in Domain Coordinator interface for
8831: editing Course Categories).
8832:
8833: jsarray (reference to array of categories used to create Javascript arrays for
8834: Domain Coordinator interface for editing Course Categories).
8835:
8836: Returns: nothing
8837:
8838: Side effects: populates cats, idx and jsarray.
8839:
8840: =cut
8841:
8842: sub gather_categories {
8843: my ($categories,$cats,$idx,$jsarray) = @_;
8844: my %counters;
8845: my $num = 0;
8846: foreach my $item (keys(%{$categories})) {
8847: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
8848: if ($container eq '' && $depth == 0) {
8849: $cats->[$depth][$categories->{$item}] = $cat;
8850: } else {
8851: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
8852: }
8853: my ($escitem,$tail) = split(/:/,$item,2);
8854: if ($counters{$tail} eq '') {
8855: $counters{$tail} = $num;
8856: $num ++;
8857: }
8858: if (ref($idx) eq 'HASH') {
8859: $idx->{$item} = $counters{$tail};
8860: }
8861: if (ref($jsarray) eq 'ARRAY') {
8862: push(@{$jsarray->[$counters{$tail}]},$item);
8863: }
8864: }
8865: return;
8866: }
8867:
8868: =pod
8869:
8870: =item * &extract_categories()
8871:
8872: Used to generate breadcrumb trails for course categories.
8873:
8874: Inputs:
8875:
8876: categories (reference to hash of category definitions).
8877:
8878: cats (reference to array of arrays/hashes which encapsulates hierarchy of
8879: categories and subcategories).
8880:
8881: trails (reference to array of breacrumb trails for each category).
8882:
8883: allitems (reference to hash - key is category key
8884: (format: escaped(name):escaped(parent category):depth in hierarchy).
8885:
8886: idx (reference to hash of counters used in Domain Coordinator interface for
8887: editing Course Categories).
8888:
8889: jsarray (reference to array of categories used to create Javascript arrays for
8890: Domain Coordinator interface for editing Course Categories).
8891:
8892: subcats (reference to hash of arrays containing all subcategories within each
8893: category, -recursive)
8894:
8895: Returns: nothing
8896:
8897: Side effects: populates trails and allitems hash references.
8898:
8899: =cut
8900:
8901: sub extract_categories {
8902: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
8903: if (ref($categories) eq 'HASH') {
8904: &gather_categories($categories,$cats,$idx,$jsarray);
8905: if (ref($cats->[0]) eq 'ARRAY') {
8906: for (my $i=0; $i<@{$cats->[0]}; $i++) {
8907: my $name = $cats->[0][$i];
8908: my $item = &escape($name).'::0';
8909: my $trailstr;
8910: if ($name eq 'instcode') {
8911: $trailstr = &mt('Official courses (with institutional codes)');
8912: } else {
8913: $trailstr = $name;
8914: }
8915: if ($allitems->{$item} eq '') {
8916: push(@{$trails},$trailstr);
8917: $allitems->{$item} = scalar(@{$trails})-1;
8918: }
8919: my @parents = ($name);
8920: if (ref($cats->[1]{$name}) eq 'ARRAY') {
8921: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
8922: my $category = $cats->[1]{$name}[$j];
8923: if (ref($subcats) eq 'HASH') {
8924: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
8925: }
8926: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
8927: }
8928: } else {
8929: if (ref($subcats) eq 'HASH') {
8930: $subcats->{$item} = [];
8931: }
8932: }
8933: }
8934: }
8935: }
8936: return;
8937: }
8938:
8939: =pod
8940:
8941: =item *&recurse_categories()
8942:
8943: Recursively used to generate breadcrumb trails for course categories.
8944:
8945: Inputs:
8946:
8947: cats (reference to array of arrays/hashes which encapsulates hierarchy of
8948: categories and subcategories).
8949:
8950: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
8951:
8952: category (current course category, for which breadcrumb trail is being generated).
8953:
8954: trails (reference to array of breadcrumb trails for each category).
8955:
8956: allitems (reference to hash - key is category key
8957: (format: escaped(name):escaped(parent category):depth in hierarchy).
8958:
8959: parents (array containing containers directories for current category,
8960: back to top level).
8961:
8962: Returns: nothing
8963:
8964: Side effects: populates trails and allitems hash references
8965:
8966: =cut
8967:
8968: sub recurse_categories {
8969: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
8970: my $shallower = $depth - 1;
8971: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
8972: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
8973: my $name = $cats->[$depth]{$category}[$k];
8974: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
8975: my $trailstr = join(' -> ',(@{$parents},$category));
8976: if ($allitems->{$item} eq '') {
8977: push(@{$trails},$trailstr);
8978: $allitems->{$item} = scalar(@{$trails})-1;
8979: }
8980: my $deeper = $depth+1;
8981: push(@{$parents},$category);
8982: if (ref($subcats) eq 'HASH') {
8983: my $subcat = &escape($name).':'.$category.':'.$depth;
8984: for (my $j=@{$parents}; $j>=0; $j--) {
8985: my $higher;
8986: if ($j > 0) {
8987: $higher = &escape($parents->[$j]).':'.
8988: &escape($parents->[$j-1]).':'.$j;
8989: } else {
8990: $higher = &escape($parents->[$j]).'::'.$j;
8991: }
8992: push(@{$subcats->{$higher}},$subcat);
8993: }
8994: }
8995: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
8996: $subcats);
8997: pop(@{$parents});
8998: }
8999: } else {
9000: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9001: my $trailstr = join(' -> ',(@{$parents},$category));
9002: if ($allitems->{$item} eq '') {
9003: push(@{$trails},$trailstr);
9004: $allitems->{$item} = scalar(@{$trails})-1;
9005: }
9006: }
9007: return;
9008: }
9009:
9010: =pod
9011:
9012: =item *&assign_categories_table()
9013:
9014: Create a datatable for display of hierarchical categories in a domain,
9015: with checkboxes to allow a course to be categorized.
9016:
9017: Inputs:
9018:
9019: cathash - reference to hash of categories defined for the domain (from
9020: configuration.db)
9021:
9022: currcat - scalar with an & separated list of categories assigned to a course.
9023:
9024: Returns: $output (markup to be displayed)
9025:
9026: =cut
9027:
9028: sub assign_categories_table {
9029: my ($cathash,$currcat) = @_;
9030: my $output;
9031: if (ref($cathash) eq 'HASH') {
9032: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
9033: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
9034: $maxdepth = scalar(@cats);
9035: if (@cats > 0) {
9036: my $itemcount = 0;
9037: if (ref($cats[0]) eq 'ARRAY') {
9038: $output = &Apache::loncommon::start_data_table();
9039: my @currcategories;
9040: if ($currcat ne '') {
9041: @currcategories = split('&',$currcat);
9042: }
9043: for (my $i=0; $i<@{$cats[0]}; $i++) {
9044: my $parent = $cats[0][$i];
9045: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9046: next if ($parent eq 'instcode');
9047: my $item = &escape($parent).'::0';
9048: my $checked = '';
9049: if (@currcategories > 0) {
9050: if (grep(/^\Q$item\E$/,@currcategories)) {
9051: $checked = ' checked="checked" ';
9052: }
9053: }
9054: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
9055: '<input type="checkbox" name="usecategory" value="'.
9056: $item.'"'.$checked.' />'.$parent.'</span>'.
9057: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
9058: my $depth = 1;
9059: push(@path,$parent);
9060: $output .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
9061: pop(@path);
9062: $output .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
9063: $itemcount ++;
9064: }
9065: $output .= &Apache::loncommon::end_data_table();
9066: }
9067: }
9068: }
9069: return $output;
9070: }
9071:
9072: =pod
9073:
9074: =item *&assign_category_rows()
9075:
9076: Create a datatable row for display of nested categories in a domain,
9077: with checkboxes to allow a course to be categorized,called recursively.
9078:
9079: Inputs:
9080:
9081: itemcount - track row number for alternating colors
9082:
9083: cats - reference to array of arrays/hashes which encapsulates hierarchy of
9084: categories and subcategories.
9085:
9086: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
9087:
9088: parent - parent of current category item
9089:
9090: path - Array containing all categories back up through the hierarchy from the
9091: current category to the top level.
9092:
9093: currcategories - reference to array of current categories assigned to the course
9094:
9095: Returns: $output (markup to be displayed).
9096:
9097: =cut
9098:
9099: sub assign_category_rows {
9100: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
9101: my ($text,$name,$item,$chgstr);
9102: if (ref($cats) eq 'ARRAY') {
9103: my $maxdepth = scalar(@{$cats});
9104: if (ref($cats->[$depth]) eq 'HASH') {
9105: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
9106: my $numchildren = @{$cats->[$depth]{$parent}};
9107: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9108: $text .= '<td><table class="LC_datatable">';
9109: for (my $j=0; $j<$numchildren; $j++) {
9110: $name = $cats->[$depth]{$parent}[$j];
9111: $item = &escape($name).':'.&escape($parent).':'.$depth;
9112: my $deeper = $depth+1;
9113: my $checked = '';
9114: if (ref($currcategories) eq 'ARRAY') {
9115: if (@{$currcategories} > 0) {
9116: if (grep(/^\Q$item\E$/,@{$currcategories})) {
9117: $checked = ' checked="checked" ';
9118: }
9119: }
9120: }
9121: $text .= '<tr><td><span class="LC_nobreak"><label>'.
9122: '<input type="checkbox" name="usecategory" value="'.
9123: $item.'"'.$checked.' />'.$name.'</label></span>'.
9124: '<input type="hidden" name="catname" value="'.$name.'" />'.
9125: '</td><td>';
9126: if (ref($path) eq 'ARRAY') {
9127: push(@{$path},$name);
9128: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
9129: pop(@{$path});
9130: }
9131: $text .= '</td></tr>';
9132: }
9133: $text .= '</table></td>';
9134: }
9135: }
9136: }
9137: return $text;
9138: }
9139:
9140: ############################################################
9141: ############################################################
9142:
9143:
9144: sub commit_customrole {
9145: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
9146: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
9147: ($start?', '.&mt('starting').' '.localtime($start):'').
9148: ($end?', ending '.localtime($end):'').': <b>'.
9149: &Apache::lonnet::assigncustomrole(
9150: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
9151: '</b><br />';
9152: return $output;
9153: }
9154:
9155: sub commit_standardrole {
9156: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
9157: my ($output,$logmsg,$linefeed);
9158: if ($context eq 'auto') {
9159: $linefeed = "\n";
9160: } else {
9161: $linefeed = "<br />\n";
9162: }
9163: if ($three eq 'st') {
9164: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
9165: $one,$two,$sec,$context);
9166: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
9167: ($result eq 'unknown_course') || ($result eq 'refused')) {
9168: $output = $logmsg.' '.&mt('Error: ').$result."\n";
9169: } else {
9170: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
9171: ($start?', '.&mt('starting').' '.localtime($start):'').
9172: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
9173: if ($context eq 'auto') {
9174: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
9175: } else {
9176: $output .= '<b>'.$result.'</b>'.$linefeed.
9177: &mt('Add to classlist').': <b>ok</b>';
9178: }
9179: $output .= $linefeed;
9180: }
9181: } else {
9182: $output = &mt('Assigning').' '.$three.' in '.$url.
9183: ($start?', '.&mt('starting').' '.localtime($start):'').
9184: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
9185: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
9186: if ($context eq 'auto') {
9187: $output .= $result.$linefeed;
9188: } else {
9189: $output .= '<b>'.$result.'</b>'.$linefeed;
9190: }
9191: }
9192: return $output;
9193: }
9194:
9195: sub commit_studentrole {
9196: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
9197: my ($result,$linefeed,$oldsecurl,$newsecurl);
9198: if ($context eq 'auto') {
9199: $linefeed = "\n";
9200: } else {
9201: $linefeed = '<br />'."\n";
9202: }
9203: if (defined($one) && defined($two)) {
9204: my $cid=$one.'_'.$two;
9205: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
9206: my $secchange = 0;
9207: my $expire_role_result;
9208: my $modify_section_result;
9209: if ($oldsec ne '-1') {
9210: if ($oldsec ne $sec) {
9211: $secchange = 1;
9212: my $now = time;
9213: my $uurl='/'.$cid;
9214: $uurl=~s/\_/\//g;
9215: if ($oldsec) {
9216: $uurl.='/'.$oldsec;
9217: }
9218: $oldsecurl = $uurl;
9219: $expire_role_result =
9220: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
9221: if ($env{'request.course.sec'} ne '') {
9222: if ($expire_role_result eq 'refused') {
9223: my @roles = ('st');
9224: my @statuses = ('previous');
9225: my @roledoms = ($one);
9226: my $withsec = 1;
9227: my %roleshash =
9228: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
9229: \@statuses,\@roles,\@roledoms,$withsec);
9230: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
9231: my ($oldstart,$oldend) =
9232: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
9233: if ($oldend > 0 && $oldend <= $now) {
9234: $expire_role_result = 'ok';
9235: }
9236: }
9237: }
9238: }
9239: $result = $expire_role_result;
9240: }
9241: }
9242: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
9243: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
9244: if ($modify_section_result =~ /^ok/) {
9245: if ($secchange == 1) {
9246: if ($sec eq '') {
9247: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
9248: } else {
9249: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
9250: }
9251: } elsif ($oldsec eq '-1') {
9252: if ($sec eq '') {
9253: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
9254: } else {
9255: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9256: }
9257: } else {
9258: if ($sec eq '') {
9259: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
9260: } else {
9261: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9262: }
9263: }
9264: } else {
9265: if ($secchange) {
9266: $$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;
9267: } else {
9268: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
9269: }
9270: }
9271: $result = $modify_section_result;
9272: } elsif ($secchange == 1) {
9273: if ($oldsec eq '') {
9274: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
9275: } else {
9276: $$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;
9277: }
9278: if ($expire_role_result eq 'refused') {
9279: my $newsecurl = '/'.$cid;
9280: $newsecurl =~ s/\_/\//g;
9281: if ($sec ne '') {
9282: $newsecurl.='/'.$sec;
9283: }
9284: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
9285: if ($sec eq '') {
9286: $$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;
9287: } else {
9288: $$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;
9289: }
9290: }
9291: }
9292: }
9293: } else {
9294: $$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;
9295: $result = "error: incomplete course id\n";
9296: }
9297: return $result;
9298: }
9299:
9300: ############################################################
9301: ############################################################
9302:
9303: sub check_clone {
9304: my ($args,$linefeed) = @_;
9305: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
9306: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
9307: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
9308: my $clonemsg;
9309: my $can_clone = 0;
9310:
9311: if ($clonehome eq 'no_host') {
9312: $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'});
9313: } else {
9314: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
9315: if ($env{'request.role.domain'} eq $args->{'clonedomain'}) {
9316: $can_clone = 1;
9317: } else {
9318: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
9319: $args->{'clonedomain'},$args->{'clonecourse'});
9320: my @cloners = split(/,/,$clonehash{'cloners'});
9321: if (grep(/^\*$/,@cloners)) {
9322: $can_clone = 1;
9323: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
9324: $can_clone = 1;
9325: } else {
9326: my %roleshash =
9327: &Apache::lonnet::get_my_roles($args->{'ccuname'},
9328: $args->{'ccdomain'},
9329: 'userroles',['active'],['cc'],
9330: [$args->{'clonedomain'}]);
9331: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
9332: $can_clone = 1;
9333: } else {
9334: $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'});
9335: }
9336: }
9337: }
9338: }
9339: return ($can_clone, $clonemsg, $cloneid, $clonehome);
9340: }
9341:
9342: sub construct_course {
9343: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context) = @_;
9344: my $outcome;
9345: my $linefeed = '<br />'."\n";
9346: if ($context eq 'auto') {
9347: $linefeed = "\n";
9348: }
9349:
9350: #
9351: # Are we cloning?
9352: #
9353: my ($can_clone, $clonemsg, $cloneid, $clonehome);
9354: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
9355: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
9356: if ($context ne 'auto') {
9357: if ($clonemsg ne '') {
9358: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
9359: }
9360: }
9361: $outcome .= $clonemsg.$linefeed;
9362:
9363: if (!$can_clone) {
9364: return (0,$outcome);
9365: }
9366: }
9367:
9368: #
9369: # Open course
9370: #
9371: my $crstype = lc($args->{'crstype'});
9372: my %cenv=();
9373: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
9374: $args->{'cdescr'},
9375: $args->{'curl'},
9376: $args->{'course_home'},
9377: $args->{'nonstandard'},
9378: $args->{'crscode'},
9379: $args->{'ccuname'}.':'.
9380: $args->{'ccdomain'},
9381: $args->{'crstype'});
9382:
9383: # Note: The testing routines depend on this being output; see
9384: # Utils::Course. This needs to at least be output as a comment
9385: # if anyone ever decides to not show this, and Utils::Course::new
9386: # will need to be suitably modified.
9387: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
9388: #
9389: # Check if created correctly
9390: #
9391: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
9392: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
9393: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
9394:
9395: #
9396: # Do the cloning
9397: #
9398: if ($can_clone && $cloneid) {
9399: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
9400: if ($context ne 'auto') {
9401: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
9402: }
9403: $outcome .= $clonemsg.$linefeed;
9404: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
9405: # Copy all files
9406: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
9407: # Restore URL
9408: $cenv{'url'}=$oldcenv{'url'};
9409: # Restore title
9410: $cenv{'description'}=$oldcenv{'description'};
9411: # Mark as cloned
9412: $cenv{'clonedfrom'}=$cloneid;
9413: # Need to clone grading mode
9414: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
9415: $cenv{'grading'}=$newenv{'grading'};
9416: # Do not clone these environment entries
9417: &Apache::lonnet::del('environment',
9418: ['default_enrollment_start_date',
9419: 'default_enrollment_end_date',
9420: 'question.email',
9421: 'policy.email',
9422: 'comment.email',
9423: 'pch.users.denied',
9424: 'plc.users.denied',
9425: 'hidefromcat',
9426: 'categories'],
9427: $$crsudom,$$crsunum);
9428: }
9429:
9430: #
9431: # Set environment (will override cloned, if existing)
9432: #
9433: my @sections = ();
9434: my @xlists = ();
9435: if ($args->{'crstype'}) {
9436: $cenv{'type'}=$args->{'crstype'};
9437: }
9438: if ($args->{'crsid'}) {
9439: $cenv{'courseid'}=$args->{'crsid'};
9440: }
9441: if ($args->{'crscode'}) {
9442: $cenv{'internal.coursecode'}=$args->{'crscode'};
9443: }
9444: if ($args->{'crsquota'} ne '') {
9445: $cenv{'internal.coursequota'}=$args->{'crsquota'};
9446: } else {
9447: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
9448: }
9449: if ($args->{'ccuname'}) {
9450: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
9451: ':'.$args->{'ccdomain'};
9452: } else {
9453: $cenv{'internal.courseowner'} = $args->{'curruser'};
9454: }
9455: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
9456: if ($args->{'crssections'}) {
9457: $cenv{'internal.sectionnums'} = '';
9458: if ($args->{'crssections'} =~ m/,/) {
9459: @sections = split/,/,$args->{'crssections'};
9460: } else {
9461: $sections[0] = $args->{'crssections'};
9462: }
9463: if (@sections > 0) {
9464: foreach my $item (@sections) {
9465: my ($sec,$gp) = split/:/,$item;
9466: my $class = $args->{'crscode'}.$sec;
9467: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
9468: $cenv{'internal.sectionnums'} .= $item.',';
9469: unless ($addcheck eq 'ok') {
9470: push @badclasses, $class;
9471: }
9472: }
9473: $cenv{'internal.sectionnums'} =~ s/,$//;
9474: }
9475: }
9476: # do not hide course coordinator from staff listing,
9477: # even if privileged
9478: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9479: # add crosslistings
9480: if ($args->{'crsxlist'}) {
9481: $cenv{'internal.crosslistings'}='';
9482: if ($args->{'crsxlist'} =~ m/,/) {
9483: @xlists = split/,/,$args->{'crsxlist'};
9484: } else {
9485: $xlists[0] = $args->{'crsxlist'};
9486: }
9487: if (@xlists > 0) {
9488: foreach my $item (@xlists) {
9489: my ($xl,$gp) = split/:/,$item;
9490: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
9491: $cenv{'internal.crosslistings'} .= $item.',';
9492: unless ($addcheck eq 'ok') {
9493: push @badclasses, $xl;
9494: }
9495: }
9496: $cenv{'internal.crosslistings'} =~ s/,$//;
9497: }
9498: }
9499: if ($args->{'autoadds'}) {
9500: $cenv{'internal.autoadds'}=$args->{'autoadds'};
9501: }
9502: if ($args->{'autodrops'}) {
9503: $cenv{'internal.autodrops'}=$args->{'autodrops'};
9504: }
9505: # check for notification of enrollment changes
9506: my @notified = ();
9507: if ($args->{'notify_owner'}) {
9508: if ($args->{'ccuname'} ne '') {
9509: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
9510: }
9511: }
9512: if ($args->{'notify_dc'}) {
9513: if ($uname ne '') {
9514: push(@notified,$uname.':'.$udom);
9515: }
9516: }
9517: if (@notified > 0) {
9518: my $notifylist;
9519: if (@notified > 1) {
9520: $notifylist = join(',',@notified);
9521: } else {
9522: $notifylist = $notified[0];
9523: }
9524: $cenv{'internal.notifylist'} = $notifylist;
9525: }
9526: if (@badclasses > 0) {
9527: my %lt=&Apache::lonlocal::texthash(
9528: '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',
9529: 'dnhr' => 'does not have rights to access enrollment in these classes',
9530: 'adby' => 'as determined by the policies of your institution on access to official classlists'
9531: );
9532: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
9533: ' ('.$lt{'adby'}.')';
9534: if ($context eq 'auto') {
9535: $outcome .= $badclass_msg.$linefeed;
9536: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
9537: foreach my $item (@badclasses) {
9538: if ($context eq 'auto') {
9539: $outcome .= " - $item\n";
9540: } else {
9541: $outcome .= "<li>$item</li>\n";
9542: }
9543: }
9544: if ($context eq 'auto') {
9545: $outcome .= $linefeed;
9546: } else {
9547: $outcome .= "</ul><br /><br /></div>\n";
9548: }
9549: }
9550: }
9551: if ($args->{'no_end_date'}) {
9552: $args->{'endaccess'} = 0;
9553: }
9554: $cenv{'internal.autostart'}=$args->{'enrollstart'};
9555: $cenv{'internal.autoend'}=$args->{'enrollend'};
9556: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
9557: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
9558: if ($args->{'showphotos'}) {
9559: $cenv{'internal.showphotos'}=$args->{'showphotos'};
9560: }
9561: $cenv{'internal.authtype'} = $args->{'authtype'};
9562: $cenv{'internal.autharg'} = $args->{'autharg'};
9563: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
9564: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
9565: 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');
9566: if ($context eq 'auto') {
9567: $outcome .= $krb_msg;
9568: } else {
9569: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
9570: }
9571: $outcome .= $linefeed;
9572: }
9573: }
9574: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
9575: if ($args->{'setpolicy'}) {
9576: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9577: }
9578: if ($args->{'setcontent'}) {
9579: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9580: }
9581: }
9582: if ($args->{'reshome'}) {
9583: $cenv{'reshome'}=$args->{'reshome'}.'/';
9584: $cenv{'reshome'}=~s/\/+$/\//;
9585: }
9586: #
9587: # course has keyed access
9588: #
9589: if ($args->{'setkeys'}) {
9590: $cenv{'keyaccess'}='yes';
9591: }
9592: # if specified, key authority is not course, but user
9593: # only active if keyaccess is yes
9594: if ($args->{'keyauth'}) {
9595: my ($user,$domain) = split(':',$args->{'keyauth'});
9596: $user = &LONCAPA::clean_username($user);
9597: $domain = &LONCAPA::clean_username($domain);
9598: if ($user ne '' && $domain ne '') {
9599: $cenv{'keyauth'}=$user.':'.$domain;
9600: }
9601: }
9602:
9603: if ($args->{'disresdis'}) {
9604: $cenv{'pch.roles.denied'}='st';
9605: }
9606: if ($args->{'disablechat'}) {
9607: $cenv{'plc.roles.denied'}='st';
9608: }
9609:
9610: # Record we've not yet viewed the Course Initialization Helper for this
9611: # course
9612: $cenv{'course.helper.not.run'} = 1;
9613: #
9614: # Use new Randomseed
9615: #
9616: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
9617: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
9618: #
9619: # The encryption code and receipt prefix for this course
9620: #
9621: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
9622: $cenv{'internal.encpref'}=100+int(9*rand(99));
9623: #
9624: # By default, use standard grading
9625: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
9626:
9627: $outcome .= $linefeed.&mt('Setting environment').': '.
9628: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
9629: #
9630: # Open all assignments
9631: #
9632: if ($args->{'openall'}) {
9633: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
9634: my %storecontent = ($storeunder => time,
9635: $storeunder.'.type' => 'date_start');
9636:
9637: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
9638: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
9639: }
9640: #
9641: # Set first page
9642: #
9643: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
9644: || ($cloneid)) {
9645: use LONCAPA::map;
9646: $outcome .= &mt('Setting first resource').': ';
9647:
9648: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
9649: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
9650:
9651: $outcome .= ($fatal?$errtext:'read ok').' - ';
9652: my $title; my $url;
9653: if ($args->{'firstres'} eq 'syl') {
9654: $title=&mt('Syllabus');
9655: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
9656: } else {
9657: $title=&mt('Navigate Contents');
9658: $url='/adm/navmaps';
9659: }
9660:
9661: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
9662: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
9663:
9664: if ($errtext) { $fatal=2; }
9665: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
9666: }
9667:
9668: return (1,$outcome);
9669: }
9670:
9671: ############################################################
9672: ############################################################
9673:
9674: sub course_type {
9675: my ($cid) = @_;
9676: if (!defined($cid)) {
9677: $cid = $env{'request.course.id'};
9678: }
9679: if (defined($env{'course.'.$cid.'.type'})) {
9680: return $env{'course.'.$cid.'.type'};
9681: } else {
9682: return 'Course';
9683: }
9684: }
9685:
9686: sub group_term {
9687: my $crstype = &course_type();
9688: my %names = (
9689: 'Course' => 'group',
9690: 'Group' => 'team',
9691: );
9692: return $names{$crstype};
9693: }
9694:
9695: sub icon {
9696: my ($file)=@_;
9697: my $curfext = lc((split(/\./,$file))[-1]);
9698: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
9699: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
9700: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
9701: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
9702: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
9703: $curfext.".gif") {
9704: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
9705: $curfext.".gif";
9706: }
9707: }
9708: return &lonhttpdurl($iconname);
9709: }
9710:
9711: sub lonhttpdurl {
9712: #
9713: # Had been used for "small fry" static images on separate port 8080.
9714: # Modify here if lightweight http functionality desired again.
9715: # Currently eliminated due to increasing firewall issues.
9716: #
9717: my ($url)=@_;
9718: return $url;
9719: }
9720:
9721: sub connection_aborted {
9722: my ($r)=@_;
9723: $r->print(" ");$r->rflush();
9724: my $c = $r->connection;
9725: return $c->aborted();
9726: }
9727:
9728: # Escapes strings that may have embedded 's that will be put into
9729: # strings as 'strings'.
9730: sub escape_single {
9731: my ($input) = @_;
9732: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
9733: $input =~ s/\'/\\\'/g; # Esacpe the 's....
9734: return $input;
9735: }
9736:
9737: # Same as escape_single, but escape's "'s This
9738: # can be used for "strings"
9739: sub escape_double {
9740: my ($input) = @_;
9741: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
9742: $input =~ s/\"/\\\"/g; # Esacpe the "s....
9743: return $input;
9744: }
9745:
9746: # Escapes the last element of a full URL.
9747: sub escape_url {
9748: my ($url) = @_;
9749: my @urlslices = split(/\//, $url,-1);
9750: my $lastitem = &escape(pop(@urlslices));
9751: return join('/',@urlslices).'/'.$lastitem;
9752: }
9753:
9754: # -------------------------------------------------------- Initliaze user login
9755: sub init_user_environment {
9756: my ($r, $username, $domain, $authhost, $form, $args) = @_;
9757: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
9758:
9759: my $public=($username eq 'public' && $domain eq 'public');
9760:
9761: # See if old ID present, if so, remove
9762:
9763: my ($filename,$cookie,$userroles);
9764: my $now=time;
9765:
9766: if ($public) {
9767: my $max_public=100;
9768: my $oldest;
9769: my $oldest_time=0;
9770: for(my $next=1;$next<=$max_public;$next++) {
9771: if (-e $lonids."/publicuser_$next.id") {
9772: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
9773: if ($mtime<$oldest_time || !$oldest_time) {
9774: $oldest_time=$mtime;
9775: $oldest=$next;
9776: }
9777: } else {
9778: $cookie="publicuser_$next";
9779: last;
9780: }
9781: }
9782: if (!$cookie) { $cookie="publicuser_$oldest"; }
9783: } else {
9784: # if this isn't a robot, kill any existing non-robot sessions
9785: if (!$args->{'robot'}) {
9786: opendir(DIR,$lonids);
9787: while ($filename=readdir(DIR)) {
9788: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
9789: unlink($lonids.'/'.$filename);
9790: }
9791: }
9792: closedir(DIR);
9793: }
9794: # Give them a new cookie
9795: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
9796: : $now.$$.int(rand(10000)));
9797: $cookie="$username\_$id\_$domain\_$authhost";
9798:
9799: # Initialize roles
9800:
9801: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
9802: }
9803: # ------------------------------------ Check browser type and MathML capability
9804:
9805: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
9806: $clientunicode,$clientos) = &decode_user_agent($r);
9807:
9808: # -------------------------------------- Any accessibility options to remember?
9809: if (($form->{'interface'}) && ($form->{'remember'} eq 'true')) {
9810: foreach my $option ('imagesuppress','appletsuppress',
9811: 'embedsuppress','fontenhance','blackwhite') {
9812: if ($form->{$option} eq 'true') {
9813: &Apache::lonnet::put('environment',{$option => 'on'},
9814: $domain,$username);
9815: } else {
9816: &Apache::lonnet::del('environment',[$option],
9817: $domain,$username);
9818: }
9819: }
9820: }
9821: # ------------------------------------------------------------- Get environment
9822:
9823: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
9824: my ($tmp) = keys(%userenv);
9825: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9826: # default remote control to off
9827: if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
9828: } else {
9829: undef(%userenv);
9830: }
9831: if (($userenv{'interface'}) && (!$form->{'interface'})) {
9832: $form->{'interface'}=$userenv{'interface'};
9833: }
9834: $env{'environment.remote'}=$userenv{'remote'};
9835: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
9836:
9837: # --------------- Do not trust query string to be put directly into environment
9838: foreach my $option ('imagesuppress','appletsuppress',
9839: 'embedsuppress','fontenhance','blackwhite',
9840: 'interface','localpath','localres') {
9841: $form->{$option}=~s/[\n\r\=]//gs;
9842: }
9843: # --------------------------------------------------------- Write first profile
9844:
9845: {
9846: my %initial_env =
9847: ("user.name" => $username,
9848: "user.domain" => $domain,
9849: "user.home" => $authhost,
9850: "browser.type" => $clientbrowser,
9851: "browser.version" => $clientversion,
9852: "browser.mathml" => $clientmathml,
9853: "browser.unicode" => $clientunicode,
9854: "browser.os" => $clientos,
9855: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
9856: "request.course.fn" => '',
9857: "request.course.uri" => '',
9858: "request.course.sec" => '',
9859: "request.role" => 'cm',
9860: "request.role.adv" => $env{'user.adv'},
9861: "request.host" => $ENV{'REMOTE_ADDR'},);
9862:
9863: if ($form->{'localpath'}) {
9864: $initial_env{"browser.localpath"} = $form->{'localpath'};
9865: $initial_env{"browser.localres"} = $form->{'localres'};
9866: }
9867:
9868: if ($public) {
9869: $initial_env{"environment.remote"} = "off";
9870: }
9871: if ($form->{'interface'}) {
9872: $form->{'interface'}=~s/\W//gs;
9873: $initial_env{"browser.interface"} = $form->{'interface'};
9874: $env{'browser.interface'}=$form->{'interface'};
9875: foreach my $option ('imagesuppress','appletsuppress',
9876: 'embedsuppress','fontenhance','blackwhite') {
9877: if (($form->{$option} eq 'true') ||
9878: ($userenv{$option} eq 'on')) {
9879: $initial_env{"browser.$option"} = "on";
9880: }
9881: }
9882: }
9883:
9884: foreach my $tool ('aboutme','blog','portfolio') {
9885: $userenv{'availabletools.'.$tool} =
9886: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload');
9887: }
9888:
9889: $env{'user.environment'} = "$lonids/$cookie.id";
9890:
9891: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
9892: &GDBM_WRCREAT(),0640)) {
9893: &_add_to_env(\%disk_env,\%initial_env);
9894: &_add_to_env(\%disk_env,\%userenv,'environment.');
9895: &_add_to_env(\%disk_env,$userroles);
9896: if (ref($args->{'extra_env'})) {
9897: &_add_to_env(\%disk_env,$args->{'extra_env'});
9898: }
9899: untie(%disk_env);
9900: } else {
9901: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
9902: 'Could not create environment storage in lonauth: '.$!.'</span>');
9903: return 'error: '.$!;
9904: }
9905: }
9906: $env{'request.role'}='cm';
9907: $env{'request.role.adv'}=$env{'user.adv'};
9908: $env{'browser.type'}=$clientbrowser;
9909:
9910: return $cookie;
9911:
9912: }
9913:
9914: sub _add_to_env {
9915: my ($idf,$env_data,$prefix) = @_;
9916: if (ref($env_data) eq 'HASH') {
9917: while (my ($key,$value) = each(%$env_data)) {
9918: $idf->{$prefix.$key} = $value;
9919: $env{$prefix.$key} = $value;
9920: }
9921: }
9922: }
9923:
9924: # --- Get the symbolic name of a problem and the url
9925: sub get_symb {
9926: my ($request,$silent) = @_;
9927: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
9928: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
9929: if ($symb eq '') {
9930: if (!$silent) {
9931: $request->print("Unable to handle ambiguous references:$url:.");
9932: return ();
9933: }
9934: }
9935: &Apache::lonenc::check_decrypt(\$symb);
9936: return ($symb);
9937: }
9938:
9939: # --------------------------------------------------------------Get annotation
9940:
9941: sub get_annotation {
9942: my ($symb,$enc) = @_;
9943:
9944: my $key = $symb;
9945: if (!$enc) {
9946: $key =
9947: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
9948: }
9949: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
9950: return $annotation{$key};
9951: }
9952:
9953: sub clean_symb {
9954: my ($symb,$delete_enc) = @_;
9955:
9956: &Apache::lonenc::check_decrypt(\$symb);
9957: my $enc = $env{'request.enc'};
9958: if ($delete_enc) {
9959: delete($env{'request.enc'});
9960: }
9961:
9962: return ($symb,$enc);
9963: }
9964:
9965: =pod
9966:
9967: =back
9968:
9969: =cut
9970:
9971: 1;
9972: __END__;
9973:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>