File:
[LON-CAPA] /
loncom /
interface /
loncommon.pm
Revision
1.864:
download - view:
text,
annotated -
select for diffs
Sat Jul 25 14:44:50 2009 UTC (15 years, 1 month ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
- Additional course type which can be requested - "community".
- This is to facilitate collaborative activities for non-instructional purposes,
e.g., in a campus organization. Some other LMSs use the term "Group".
1: # The LearningOnline Network with CAPA
2: # a pile of common routines
3: #
4: # $Id: loncommon.pm,v 1.864 2009/07/25 14:44:50 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: // <![CDATA[
411: var stdeditbrowser;
412: function openstdbrowser(formname,uname,udom,roleflag,ignorefilter,courseadvonly) {
413: var url = '/adm/pickstudent?';
414: var filter;
415: if (!ignorefilter) {
416: eval('filter=document.'+formname+'.'+uname+'.value;');
417: }
418: if (filter != null) {
419: if (filter != '') {
420: url += 'filter='+filter+'&';
421: }
422: }
423: url += 'form=' + formname + '&unameelement='+uname+
424: '&udomelement='+udom;
425: if (roleflag) { url+="&roles=1"; }
426: if (courseadvonly) { url+="&courseadvonly=1"; }
427: var title = 'Student_Browser';
428: var options = 'scrollbars=1,resizable=1,menubar=0';
429: options += ',width=700,height=600';
430: stdeditbrowser = open(url,title,options,'1');
431: stdeditbrowser.focus();
432: }
433: // ]]>
434: </script>
435: ENDSTDBRW
436: }
437:
438: sub selectstudent_link {
439: my ($form,$unameele,$udomele,$courseadvonly)=@_;
440: my $callargs = "'".$form."','".$unameele."','".$udomele."'";
441: if ($env{'request.course.id'}) {
442: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
443: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
444: '/'.$env{'request.course.sec'})) {
445: return '';
446: }
447: if ($courseadvonly) {
448: $callargs .= ",'',1,1";
449: }
450: return '<span class="LC_nobreak">'.
451: '<a href="javascript:openstdbrowser('.$callargs.');">'.
452: &mt('Select User').'</a></span>';
453: }
454: if ($env{'request.role'}=~/^(au|dc|su)/) {
455: $callargs .= ",1";
456: return '<span class="LC_nobreak">'.
457: '<a href="javascript:openstdbrowser('.$callargs.');">'.
458: &mt('Select User').'</a></span>';
459: }
460: return '';
461: }
462:
463: sub authorbrowser_javascript {
464: return <<"ENDAUTHORBRW";
465: <script type="text/javascript" language="JavaScript">
466: // <![CDATA[
467: var stdeditbrowser;
468:
469: function openauthorbrowser(formname,udom) {
470: var url = '/adm/pickauthor?';
471: url += 'form='+formname+'&roledom='+udom;
472: var title = 'Author_Browser';
473: var options = 'scrollbars=1,resizable=1,menubar=0';
474: options += ',width=700,height=600';
475: stdeditbrowser = open(url,title,options,'1');
476: stdeditbrowser.focus();
477: }
478:
479: // ]]>
480: </script>
481: ENDAUTHORBRW
482: }
483:
484: sub coursebrowser_javascript {
485: my ($domainfilter,$sec_element,$formname)=@_;
486: 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');
487: my $output = '
488: <script type="text/javascript" language="JavaScript">
489: // <![CDATA[
490: var stdeditbrowser;'."\n";
491: $output .= <<"ENDSTDBRW";
492: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,crstype) {
493: var url = '/adm/pickcourse?';
494: var domainfilter = '';
495: var formid = getFormIdByName(formname);
496: if (formid > -1) {
497: var domid = getIndexByName(formid,udom);
498: if (domid > -1) {
499: if (document.forms[formid].elements[domid].type == 'select-one') {
500: domainfilter=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
501: }
502: if (document.forms[formid].elements[domid].type == 'hidden') {
503: domainfilter=document.forms[formid].elements[domid].value;
504: }
505: }
506: }
507: if (domainfilter != null) {
508: if (domainfilter != '') {
509: url += 'domainfilter='+domainfilter+'&';
510: }
511: }
512: url += 'form=' + formname + '&cnumelement='+uname+
513: '&cdomelement='+udom+
514: '&cnameelement='+desc;
515: if (extra_element !=null && extra_element != '') {
516: if (formname == 'rolechoice' || formname == 'studentform') {
517: url += '&roleelement='+extra_element;
518: if (domainfilter == null || domainfilter == '') {
519: url += '&domainfilter='+extra_element;
520: }
521: }
522: else {
523: if (formname == 'portform') {
524: url += '&setroles='+extra_element;
525: } else {
526: if (formname == 'rules') {
527: url += '&fixeddom='+extra_element;
528: }
529: }
530: }
531: }
532: if (multflag !=null && multflag != '') {
533: url += '&multiple='+multflag;
534: }
535: if (crstype == 'Course/Group') {
536: if (formname == 'cu') {
537: crstype = document.cu.crstype.options[document.cu.crstype.selectedIndex].value;
538: if (crstype == "") {
539: alert("$crs_or_grp_alert");
540: return;
541: }
542: }
543: }
544: if (crstype !=null && crstype != '') {
545: url += '&type='+crstype;
546: }
547: var title = 'Course_Browser';
548: var options = 'scrollbars=1,resizable=1,menubar=0';
549: options += ',width=700,height=600';
550: stdeditbrowser = open(url,title,options,'1');
551: stdeditbrowser.focus();
552: }
553:
554: function getFormIdByName(formname) {
555: for (var i=0;i<document.forms.length;i++) {
556: if (document.forms[i].name == formname) {
557: return i;
558: }
559: }
560: return -1;
561: }
562:
563: function getIndexByName(formid,item) {
564: for (var i=0;i<document.forms[formid].elements.length;i++) {
565: if (document.forms[formid].elements[i].name == item) {
566: return i;
567: }
568: }
569: return -1;
570: }
571: ENDSTDBRW
572: if ($sec_element ne '') {
573: $output .= &setsec_javascript($sec_element,$formname);
574: }
575: $output .= '
576: // ]]>
577: </script>';
578: return $output;
579: }
580:
581: sub setsec_javascript {
582: my ($sec_element,$formname) = @_;
583: my $setsections = qq|
584: function setSect(sectionlist) {
585: var sectionsArray = new Array();
586: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
587: sectionsArray = sectionlist.split(",");
588: }
589: var numSections = sectionsArray.length;
590: document.$formname.$sec_element.length = 0;
591: if (numSections == 0) {
592: document.$formname.$sec_element.multiple=false;
593: document.$formname.$sec_element.size=1;
594: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
595: } else {
596: if (numSections == 1) {
597: document.$formname.$sec_element.multiple=false;
598: document.$formname.$sec_element.size=1;
599: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
600: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
601: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
602: } else {
603: for (var i=0; i<numSections; i++) {
604: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
605: }
606: document.$formname.$sec_element.multiple=true
607: if (numSections < 3) {
608: document.$formname.$sec_element.size=numSections;
609: } else {
610: document.$formname.$sec_element.size=3;
611: }
612: document.$formname.$sec_element.options[0].selected = false
613: }
614: }
615: }
616: |;
617: return $setsections;
618: }
619:
620:
621: sub selectcourse_link {
622: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype)=@_;
623: return '<span class="LC_nobreak">'
624: ."<a href='"
625: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
626: .'","'.$udomele.'","'.$desc.'","'.$extra_element
627: .'","'.$multflag.'","'.$selecttype.'");'
628: ."'>".&mt('Select Course').'</a>'
629: .'</span>';
630: }
631:
632: sub selectauthor_link {
633: my ($form,$udom)=@_;
634: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
635: &mt('Select Author').'</a>';
636: }
637:
638: sub check_uncheck_jscript {
639: my $jscript = <<"ENDSCRT";
640: function checkAll(field) {
641: if (field.length > 0) {
642: for (i = 0; i < field.length; i++) {
643: field[i].checked = true ;
644: }
645: } else {
646: field.checked = true
647: }
648: }
649:
650: function uncheckAll(field) {
651: if (field.length > 0) {
652: for (i = 0; i < field.length; i++) {
653: field[i].checked = false ;
654: }
655: } else {
656: field.checked = false ;
657: }
658: }
659: ENDSCRT
660: return $jscript;
661: }
662:
663: sub select_timezone {
664: my ($name,$selected,$onchange,$includeempty)=@_;
665: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
666: if ($includeempty) {
667: $output .= '<option value=""';
668: if (($selected eq '') || ($selected eq 'local')) {
669: $output .= ' selected="selected" ';
670: }
671: $output .= '> </option>';
672: }
673: my @timezones = DateTime::TimeZone->all_names;
674: foreach my $tzone (@timezones) {
675: $output.= '<option value="'.$tzone.'"';
676: if ($tzone eq $selected) {
677: $output.=' selected="selected"';
678: }
679: $output.=">$tzone</option>\n";
680: }
681: $output.="</select>";
682: return $output;
683: }
684:
685: sub select_datelocale {
686: my ($name,$selected,$onchange,$includeempty)=@_;
687: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
688: if ($includeempty) {
689: $output .= '<option value=""';
690: if ($selected eq '') {
691: $output .= ' selected="selected" ';
692: }
693: $output .= '> </option>';
694: }
695: my (@possibles,%locale_names);
696: my @locales = DateTime::Locale::Catalog::Locales;
697: foreach my $locale (@locales) {
698: if (ref($locale) eq 'HASH') {
699: my $id = $locale->{'id'};
700: if ($id ne '') {
701: my $en_terr = $locale->{'en_territory'};
702: my $native_terr = $locale->{'native_territory'};
703: my @languages = &Apache::lonlocal::preferred_languages();
704: if (grep(/^en$/,@languages) || !@languages) {
705: if ($en_terr ne '') {
706: $locale_names{$id} = '('.$en_terr.')';
707: } elsif ($native_terr ne '') {
708: $locale_names{$id} = $native_terr;
709: }
710: } else {
711: if ($native_terr ne '') {
712: $locale_names{$id} = $native_terr.' ';
713: } elsif ($en_terr ne '') {
714: $locale_names{$id} = '('.$en_terr.')';
715: }
716: }
717: push (@possibles,$id);
718: }
719: }
720: }
721: foreach my $item (sort(@possibles)) {
722: $output.= '<option value="'.$item.'"';
723: if ($item eq $selected) {
724: $output.=' selected="selected"';
725: }
726: $output.=">$item";
727: if ($locale_names{$item} ne '') {
728: $output.=" $locale_names{$item}</option>\n";
729: }
730: $output.="</option>\n";
731: }
732: $output.="</select>";
733: return $output;
734: }
735:
736: sub select_language {
737: my ($name,$selected,$includeempty) = @_;
738: my %langchoices;
739: if ($includeempty) {
740: %langchoices = ('' => 'No language preference');
741: }
742: foreach my $id (&languageids()) {
743: my $code = &supportedlanguagecode($id);
744: if ($code) {
745: $langchoices{$code} = &plainlanguagedescription($id);
746: }
747: }
748: return &select_form($selected,$name,%langchoices);
749: }
750:
751: =pod
752:
753: =item * &linked_select_forms(...)
754:
755: linked_select_forms returns a string containing a <script></script> block
756: and html for two <select> menus. The select menus will be linked in that
757: changing the value of the first menu will result in new values being placed
758: in the second menu. The values in the select menu will appear in alphabetical
759: order unless a defined order is provided.
760:
761: linked_select_forms takes the following ordered inputs:
762:
763: =over 4
764:
765: =item * $formname, the name of the <form> tag
766:
767: =item * $middletext, the text which appears between the <select> tags
768:
769: =item * $firstdefault, the default value for the first menu
770:
771: =item * $firstselectname, the name of the first <select> tag
772:
773: =item * $secondselectname, the name of the second <select> tag
774:
775: =item * $hashref, a reference to a hash containing the data for the menus.
776:
777: =item * $menuorder, the order of values in the first menu
778:
779: =back
780:
781: Below is an example of such a hash. Only the 'text', 'default', and
782: 'select2' keys must appear as stated. keys(%menu) are the possible
783: values for the first select menu. The text that coincides with the
784: first menu value is given in $menu{$choice1}->{'text'}. The values
785: and text for the second menu are given in the hash pointed to by
786: $menu{$choice1}->{'select2'}.
787:
788: my %menu = ( A1 => { text =>"Choice A1" ,
789: default => "B3",
790: select2 => {
791: B1 => "Choice B1",
792: B2 => "Choice B2",
793: B3 => "Choice B3",
794: B4 => "Choice B4"
795: },
796: order => ['B4','B3','B1','B2'],
797: },
798: A2 => { text =>"Choice A2" ,
799: default => "C2",
800: select2 => {
801: C1 => "Choice C1",
802: C2 => "Choice C2",
803: C3 => "Choice C3"
804: },
805: order => ['C2','C1','C3'],
806: },
807: A3 => { text =>"Choice A3" ,
808: default => "D6",
809: select2 => {
810: D1 => "Choice D1",
811: D2 => "Choice D2",
812: D3 => "Choice D3",
813: D4 => "Choice D4",
814: D5 => "Choice D5",
815: D6 => "Choice D6",
816: D7 => "Choice D7"
817: },
818: order => ['D4','D3','D2','D1','D7','D6','D5'],
819: }
820: );
821:
822: =cut
823:
824: sub linked_select_forms {
825: my ($formname,
826: $middletext,
827: $firstdefault,
828: $firstselectname,
829: $secondselectname,
830: $hashref,
831: $menuorder,
832: ) = @_;
833: my $second = "document.$formname.$secondselectname";
834: my $first = "document.$formname.$firstselectname";
835: # output the javascript to do the changing
836: my $result = '';
837: $result.='<script type="text/javascript" language="JavaScript">'."\n";
838: $result.="// <![CDATA[\n";
839: $result.="var select2data = new Object();\n";
840: $" = '","';
841: my $debug = '';
842: foreach my $s1 (sort(keys(%$hashref))) {
843: $result.="select2data.d_$s1 = new Object();\n";
844: $result.="select2data.d_$s1.def = new String('".
845: $hashref->{$s1}->{'default'}."');\n";
846: $result.="select2data.d_$s1.values = new Array(";
847: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
848: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
849: @s2values = @{$hashref->{$s1}->{'order'}};
850: }
851: $result.="\"@s2values\");\n";
852: $result.="select2data.d_$s1.texts = new Array(";
853: my @s2texts;
854: foreach my $value (@s2values) {
855: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
856: }
857: $result.="\"@s2texts\");\n";
858: }
859: $"=' ';
860: $result.= <<"END";
861:
862: function select1_changed() {
863: // Determine new choice
864: var newvalue = "d_" + $first.value;
865: // update select2
866: var values = select2data[newvalue].values;
867: var texts = select2data[newvalue].texts;
868: var select2def = select2data[newvalue].def;
869: var i;
870: // out with the old
871: for (i = 0; i < $second.options.length; i++) {
872: $second.options[i] = null;
873: }
874: // in with the nuclear
875: for (i=0;i<values.length; i++) {
876: $second.options[i] = new Option(values[i]);
877: $second.options[i].value = values[i];
878: $second.options[i].text = texts[i];
879: if (values[i] == select2def) {
880: $second.options[i].selected = true;
881: }
882: }
883: }
884: // ]]>
885: </script>
886: END
887: # output the initial values for the selection lists
888: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
889: my @order = sort(keys(%{$hashref}));
890: if (ref($menuorder) eq 'ARRAY') {
891: @order = @{$menuorder};
892: }
893: foreach my $value (@order) {
894: $result.=" <option value=\"$value\" ";
895: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
896: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
897: }
898: $result .= "</select>\n";
899: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
900: $result .= $middletext;
901: $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
902: my $seconddefault = $hashref->{$firstdefault}->{'default'};
903:
904: my @secondorder = sort(keys(%select2));
905: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
906: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
907: }
908: foreach my $value (@secondorder) {
909: $result.=" <option value=\"$value\" ";
910: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
911: $result.=">".&mt($select2{$value})."</option>\n";
912: }
913: $result .= "</select>\n";
914: # return $debug;
915: return $result;
916: } # end of sub linked_select_forms {
917:
918: =pod
919:
920: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height)
921:
922: Returns a string corresponding to an HTML link to the given help
923: $topic, where $topic corresponds to the name of a .tex file in
924: /home/httpd/html/adm/help/tex, with underscores replaced by
925: spaces.
926:
927: $text will optionally be linked to the same topic, allowing you to
928: link text in addition to the graphic. If you do not want to link
929: text, but wish to specify one of the later parameters, pass an
930: empty string.
931:
932: $stayOnPage is a value that will be interpreted as a boolean. If true,
933: the link will not open a new window. If false, the link will open
934: a new window using Javascript. (Default is false.)
935:
936: $width and $height are optional numerical parameters that will
937: override the width and height of the popped up window, which may
938: be useful for certain help topics with big pictures included.
939:
940: =cut
941:
942: sub help_open_topic {
943: my ($topic, $text, $stayOnPage, $width, $height) = @_;
944: $text = "" if (not defined $text);
945: $stayOnPage = 0 if (not defined $stayOnPage);
946: $width = 350 if (not defined $width);
947: $height = 400 if (not defined $height);
948: my $filename = $topic;
949: $filename =~ s/ /_/g;
950:
951: my $template = "";
952: my $link;
953:
954: $topic=~s/\W/\_/g;
955:
956: if (!$stayOnPage) {
957: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
958: } else {
959: $link = "/adm/help/${filename}.hlp";
960: }
961:
962: # Add the text
963: if ($text ne "") {
964: $template.='<span class="LC_help_open_topic">'
965: .'<a target="_top" href="'.$link.'">'
966: .$text.'</a>';
967: }
968:
969: # (Always) Add the graphic
970: my $title = &mt('Online Help');
971: my $helpicon=&lonhttpdurl("/adm/help/help.png");
972: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
973: .'<img src="'.$helpicon.'" border="0"'
974: .' alt="'.&mt('Help: [_1]',$topic).'"'
975: .' title="'.$title.'"'
976: .' /></a>';
977: if ($text ne "") {
978: $template.='</span>';
979: }
980: return $template;
981:
982: }
983:
984: # This is a quicky function for Latex cheatsheet editing, since it
985: # appears in at least four places
986: sub helpLatexCheatsheet {
987: my ($topic,$text,$not_author) = @_;
988: my $out;
989: my $addOther = '';
990: if ($topic) {
991: $addOther = '<span>'.&Apache::loncommon::help_open_topic($topic,&mt($text),
992: undef, undef, 600).
993: '</span> ';
994: }
995: $out = '<span>' # Start cheatsheet
996: .$addOther
997: .'<span>'
998: .&Apache::loncommon::help_open_topic('Greek_Symbols',&mt('Greek Symbols'),
999: undef,undef,600)
1000: .'</span> <span>'
1001: .&Apache::loncommon::help_open_topic('Other_Symbols',&mt('Other Symbols'),
1002: undef,undef,600)
1003: .'</span>';
1004: unless ($not_author) {
1005: $out .= ' <span>'
1006: .&Apache::loncommon::help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),
1007: undef,undef,600)
1008: .'</span>';
1009: }
1010: $out .= '</span>'; # End cheatsheet
1011: return $out;
1012: }
1013:
1014: sub general_help {
1015: my $helptopic='Student_Intro';
1016: if ($env{'request.role'}=~/^(ca|au)/) {
1017: $helptopic='Authoring_Intro';
1018: } elsif ($env{'request.role'}=~/^cc/) {
1019: $helptopic='Course_Coordination_Intro';
1020: } elsif ($env{'request.role'}=~/^dc/) {
1021: $helptopic='Domain_Coordination_Intro';
1022: }
1023: return $helptopic;
1024: }
1025:
1026: sub update_help_link {
1027: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1028: my $origurl = $ENV{'REQUEST_URI'};
1029: $origurl=~s|^/~|/priv/|;
1030: my $timestamp = time;
1031: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1032: $$datum = &escape($$datum);
1033: }
1034:
1035: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1036: my $output .= <<"ENDOUTPUT";
1037: <script type="text/javascript">
1038: // <![CDATA[
1039: banner_link = '$banner_link';
1040: // ]]>
1041: </script>
1042: ENDOUTPUT
1043: return $output;
1044: }
1045:
1046: # now just updates the help link and generates a blue icon
1047: sub help_open_menu {
1048: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1049: = @_;
1050: $stayOnPage = 0 if (not defined $stayOnPage);
1051: # only use pop-up help (stayOnPage == 0)
1052: # if environment.remote is on (using remote control UI)
1053: if ($env{'environment.remote'} eq 'off' ) {
1054: $stayOnPage=1;
1055: }
1056: my $output;
1057: if ($component_help) {
1058: if (!$text) {
1059: $output=&help_open_topic($component_help,undef,$stayOnPage,
1060: $width,$height);
1061: } else {
1062: my $help_text;
1063: $help_text=&unescape($topic);
1064: $output='<table><tr><td>'.
1065: &help_open_topic($component_help,$help_text,$stayOnPage,
1066: $width,$height).'</td></tr></table>';
1067: }
1068: }
1069: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1070: return $output.$banner_link;
1071: }
1072:
1073: sub top_nav_help {
1074: my ($text) = @_;
1075: $text = &mt($text);
1076: my $stay_on_page =
1077: ($env{'environment.remote'} eq 'off' );
1078: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1079: : "javascript:helpMenu('open')";
1080: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1081:
1082: my $title = &mt('Get help');
1083:
1084: return <<"END";
1085: $banner_link
1086: <a href="$link" title="$title">$text</a>
1087: END
1088: }
1089:
1090: sub help_menu_js {
1091: my ($text) = @_;
1092:
1093: my $stayOnPage =
1094: ($env{'environment.remote'} eq 'off' );
1095:
1096: my $width = 620;
1097: my $height = 600;
1098: my $helptopic=&general_help();
1099: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1100: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1101: my $start_page =
1102: &Apache::loncommon::start_page('Help Menu', undef,
1103: {'frameset' => 1,
1104: 'js_ready' => 1,
1105: 'add_entries' => {
1106: 'border' => '0',
1107: 'rows' => "110,*",},});
1108: my $end_page =
1109: &Apache::loncommon::end_page({'frameset' => 1,
1110: 'js_ready' => 1,});
1111:
1112: my $template .= <<"ENDTEMPLATE";
1113: <script type="text/javascript">
1114: // <!-- BEGIN LON-CAPA Internal
1115: // <![CDATA[
1116: var banner_link = '';
1117: function helpMenu(target) {
1118: var caller = this;
1119: if (target == 'open') {
1120: var newWindow = null;
1121: try {
1122: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1123: }
1124: catch(error) {
1125: writeHelp(caller);
1126: return;
1127: }
1128: if (newWindow) {
1129: caller = newWindow;
1130: }
1131: }
1132: writeHelp(caller);
1133: return;
1134: }
1135: function writeHelp(caller) {
1136: caller.document.writeln('$start_page<frame name="bannerframe" src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1137: caller.document.close()
1138: caller.focus()
1139: }
1140: // ]]>
1141: // END LON-CAPA Internal -->
1142: </script>
1143: ENDTEMPLATE
1144: return $template;
1145: }
1146:
1147: sub help_open_bug {
1148: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1149: unless ($env{'user.adv'}) { return ''; }
1150: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1151: $text = "" if (not defined $text);
1152: $stayOnPage = 0 if (not defined $stayOnPage);
1153: if ($env{'environment.remote'} eq 'off' ) {
1154: $stayOnPage=1;
1155: }
1156: $width = 600 if (not defined $width);
1157: $height = 600 if (not defined $height);
1158:
1159: $topic=~s/\W+/\+/g;
1160: my $link='';
1161: my $template='';
1162: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1163: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1164: if (!$stayOnPage)
1165: {
1166: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1167: }
1168: else
1169: {
1170: $link = $url;
1171: }
1172: # Add the text
1173: if ($text ne "")
1174: {
1175: $template .=
1176: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1177: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1178: }
1179:
1180: # Add the graphic
1181: my $title = &mt('Report a Bug');
1182: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1183: $template .= <<"ENDTEMPLATE";
1184: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1185: ENDTEMPLATE
1186: if ($text ne '') { $template.='</td></tr></table>' };
1187: return $template;
1188:
1189: }
1190:
1191: sub help_open_faq {
1192: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1193: unless ($env{'user.adv'}) { return ''; }
1194: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1195: $text = "" if (not defined $text);
1196: $stayOnPage = 0 if (not defined $stayOnPage);
1197: if ($env{'environment.remote'} eq 'off' ) {
1198: $stayOnPage=1;
1199: }
1200: $width = 350 if (not defined $width);
1201: $height = 400 if (not defined $height);
1202:
1203: $topic=~s/\W+/\+/g;
1204: my $link='';
1205: my $template='';
1206: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1207: if (!$stayOnPage)
1208: {
1209: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1210: }
1211: else
1212: {
1213: $link = $url;
1214: }
1215:
1216: # Add the text
1217: if ($text ne "")
1218: {
1219: $template .=
1220: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1221: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1222: }
1223:
1224: # Add the graphic
1225: my $title = &mt('View the FAQ');
1226: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1227: $template .= <<"ENDTEMPLATE";
1228: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1229: ENDTEMPLATE
1230: if ($text ne '') { $template.='</td></tr></table>' };
1231: return $template;
1232:
1233: }
1234:
1235: ###############################################################
1236: ###############################################################
1237:
1238: =pod
1239:
1240: =item * &change_content_javascript():
1241:
1242: This and the next function allow you to create small sections of an
1243: otherwise static HTML page that you can update on the fly with
1244: Javascript, even in Netscape 4.
1245:
1246: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1247: must be written to the HTML page once. It will prove the Javascript
1248: function "change(name, content)". Calling the change function with the
1249: name of the section
1250: you want to update, matching the name passed to C<changable_area>, and
1251: the new content you want to put in there, will put the content into
1252: that area.
1253:
1254: B<Note>: Netscape 4 only reserves enough space for the changable area
1255: to contain room for the original contents. You need to "make space"
1256: for whatever changes you wish to make, and be B<sure> to check your
1257: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1258: it's adequate for updating a one-line status display, but little more.
1259: This script will set the space to 100% width, so you only need to
1260: worry about height in Netscape 4.
1261:
1262: Modern browsers are much less limiting, and if you can commit to the
1263: user not using Netscape 4, this feature may be used freely with
1264: pretty much any HTML.
1265:
1266: =cut
1267:
1268: sub change_content_javascript {
1269: # If we're on Netscape 4, we need to use Layer-based code
1270: if ($env{'browser.type'} eq 'netscape' &&
1271: $env{'browser.version'} =~ /^4\./) {
1272: return (<<NETSCAPE4);
1273: function change(name, content) {
1274: doc = document.layers[name+"___escape"].layers[0].document;
1275: doc.open();
1276: doc.write(content);
1277: doc.close();
1278: }
1279: NETSCAPE4
1280: } else {
1281: # Otherwise, we need to use semi-standards-compliant code
1282: # (technically, "innerHTML" isn't standard but the equivalent
1283: # is really scary, and every useful browser supports it
1284: return (<<DOMBASED);
1285: function change(name, content) {
1286: element = document.getElementById(name);
1287: element.innerHTML = content;
1288: }
1289: DOMBASED
1290: }
1291: }
1292:
1293: =pod
1294:
1295: =item * &changable_area($name,$origContent):
1296:
1297: This provides a "changable area" that can be modified on the fly via
1298: the Javascript code provided in C<change_content_javascript>. $name is
1299: the name you will use to reference the area later; do not repeat the
1300: same name on a given HTML page more then once. $origContent is what
1301: the area will originally contain, which can be left blank.
1302:
1303: =cut
1304:
1305: sub changable_area {
1306: my ($name, $origContent) = @_;
1307:
1308: if ($env{'browser.type'} eq 'netscape' &&
1309: $env{'browser.version'} =~ /^4\./) {
1310: # If this is netscape 4, we need to use the Layer tag
1311: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1312: } else {
1313: return "<span id='$name'>$origContent</span>";
1314: }
1315: }
1316:
1317: =pod
1318:
1319: =item * &viewport_geometry_js
1320:
1321: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1322:
1323: =cut
1324:
1325:
1326: sub viewport_geometry_js {
1327: return <<"GEOMETRY";
1328: var Geometry = {};
1329: function init_geometry() {
1330: if (Geometry.init) { return };
1331: Geometry.init=1;
1332: if (window.innerHeight) {
1333: Geometry.getViewportHeight = function() { return window.innerHeight; };
1334: Geometry.getViewportWidth = function() { return window.innerWidth; };
1335: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1336: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1337: }
1338: else if (document.documentElement && document.documentElement.clientHeight) {
1339: Geometry.getViewportHeight =
1340: function() { return document.documentElement.clientHeight; };
1341: Geometry.getViewportWidth =
1342: function() { return document.documentElement.clientWidth; };
1343:
1344: Geometry.getHorizontalScroll =
1345: function() { return document.documentElement.scrollLeft; };
1346: Geometry.getVerticalScroll =
1347: function() { return document.documentElement.scrollTop; };
1348: }
1349: else if (document.body.clientHeight) {
1350: Geometry.getViewportHeight =
1351: function() { return document.body.clientHeight; };
1352: Geometry.getViewportWidth =
1353: function() { return document.body.clientWidth; };
1354: Geometry.getHorizontalScroll =
1355: function() { return document.body.scrollLeft; };
1356: Geometry.getVerticalScroll =
1357: function() { return document.body.scrollTop; };
1358: }
1359: }
1360:
1361: GEOMETRY
1362: }
1363:
1364: =pod
1365:
1366: =item * &viewport_size_js()
1367:
1368: 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.
1369:
1370: =cut
1371:
1372: sub viewport_size_js {
1373: my $geometry = &viewport_geometry_js();
1374: return <<"DIMS";
1375:
1376: $geometry
1377:
1378: function getViewportDims(width,height) {
1379: init_geometry();
1380: width.value = Geometry.getViewportWidth();
1381: height.value = Geometry.getViewportHeight();
1382: return;
1383: }
1384:
1385: DIMS
1386: }
1387:
1388: =pod
1389:
1390: =item * &resize_textarea_js()
1391:
1392: emits the needed javascript to resize a textarea to be as big as possible
1393:
1394: creates a function resize_textrea that takes two IDs first should be
1395: the id of the element to resize, second should be the id of a div that
1396: surrounds everything that comes after the textarea, this routine needs
1397: to be attached to the <body> for the onload and onresize events.
1398:
1399: =back
1400:
1401: =cut
1402:
1403: sub resize_textarea_js {
1404: my $geometry = &viewport_geometry_js();
1405: return <<"RESIZE";
1406: <script type="text/javascript">
1407: // <![CDATA[
1408: $geometry
1409:
1410: function getX(element) {
1411: var x = 0;
1412: while (element) {
1413: x += element.offsetLeft;
1414: element = element.offsetParent;
1415: }
1416: return x;
1417: }
1418: function getY(element) {
1419: var y = 0;
1420: while (element) {
1421: y += element.offsetTop;
1422: element = element.offsetParent;
1423: }
1424: return y;
1425: }
1426:
1427:
1428: function resize_textarea(textarea_id,bottom_id) {
1429: init_geometry();
1430: var textarea = document.getElementById(textarea_id);
1431: //alert(textarea);
1432:
1433: var textarea_top = getY(textarea);
1434: var textarea_height = textarea.offsetHeight;
1435: var bottom = document.getElementById(bottom_id);
1436: var bottom_top = getY(bottom);
1437: var bottom_height = bottom.offsetHeight;
1438: var window_height = Geometry.getViewportHeight();
1439: var fudge = 23;
1440: var new_height = window_height-fudge-textarea_top-bottom_height;
1441: if (new_height < 300) {
1442: new_height = 300;
1443: }
1444: textarea.style.height=new_height+'px';
1445: }
1446: // ]]>
1447: </script>
1448: RESIZE
1449:
1450: }
1451:
1452: =pod
1453:
1454: =head1 Excel and CSV file utility routines
1455:
1456: =over 4
1457:
1458: =cut
1459:
1460: ###############################################################
1461: ###############################################################
1462:
1463: =pod
1464:
1465: =item * &csv_translate($text)
1466:
1467: Translate $text to allow it to be output as a 'comma separated values'
1468: format.
1469:
1470: =cut
1471:
1472: ###############################################################
1473: ###############################################################
1474: sub csv_translate {
1475: my $text = shift;
1476: $text =~ s/\"/\"\"/g;
1477: $text =~ s/\n/ /g;
1478: return $text;
1479: }
1480:
1481: ###############################################################
1482: ###############################################################
1483:
1484: =pod
1485:
1486: =item * &define_excel_formats()
1487:
1488: Define some commonly used Excel cell formats.
1489:
1490: Currently supported formats:
1491:
1492: =over 4
1493:
1494: =item header
1495:
1496: =item bold
1497:
1498: =item h1
1499:
1500: =item h2
1501:
1502: =item h3
1503:
1504: =item h4
1505:
1506: =item i
1507:
1508: =item date
1509:
1510: =back
1511:
1512: Inputs: $workbook
1513:
1514: Returns: $format, a hash reference.
1515:
1516: =cut
1517:
1518: ###############################################################
1519: ###############################################################
1520: sub define_excel_formats {
1521: my ($workbook) = @_;
1522: my $format;
1523: $format->{'header'} = $workbook->add_format(bold => 1,
1524: bottom => 1,
1525: align => 'center');
1526: $format->{'bold'} = $workbook->add_format(bold=>1);
1527: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1528: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1529: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1530: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1531: $format->{'i'} = $workbook->add_format(italic=>1);
1532: $format->{'date'} = $workbook->add_format(num_format=>
1533: 'mm/dd/yyyy hh:mm:ss');
1534: return $format;
1535: }
1536:
1537: ###############################################################
1538: ###############################################################
1539:
1540: =pod
1541:
1542: =item * &create_workbook()
1543:
1544: Create an Excel worksheet. If it fails, output message on the
1545: request object and return undefs.
1546:
1547: Inputs: Apache request object
1548:
1549: Returns (undef) on failure,
1550: Excel worksheet object, scalar with filename, and formats
1551: from &Apache::loncommon::define_excel_formats on success
1552:
1553: =cut
1554:
1555: ###############################################################
1556: ###############################################################
1557: sub create_workbook {
1558: my ($r) = @_;
1559: #
1560: # Create the excel spreadsheet
1561: my $filename = '/prtspool/'.
1562: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1563: time.'_'.rand(1000000000).'.xls';
1564: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1565: if (! defined($workbook)) {
1566: $r->log_error("Error creating excel spreadsheet $filename: $!");
1567: $r->print('<p>'.&mt("Unable to create new Excel file. ".
1568: "This error has been logged. ".
1569: "Please alert your LON-CAPA administrator").
1570: '</p>');
1571: return (undef);
1572: }
1573: #
1574: $workbook->set_tempdir('/home/httpd/perl/tmp');
1575: #
1576: my $format = &Apache::loncommon::define_excel_formats($workbook);
1577: return ($workbook,$filename,$format);
1578: }
1579:
1580: ###############################################################
1581: ###############################################################
1582:
1583: =pod
1584:
1585: =item * &create_text_file()
1586:
1587: Create a file to write to and eventually make available to the user.
1588: If file creation fails, outputs an error message on the request object and
1589: return undefs.
1590:
1591: Inputs: Apache request object, and file suffix
1592:
1593: Returns (undef) on failure,
1594: Filehandle and filename on success.
1595:
1596: =cut
1597:
1598: ###############################################################
1599: ###############################################################
1600: sub create_text_file {
1601: my ($r,$suffix) = @_;
1602: if (! defined($suffix)) { $suffix = 'txt'; };
1603: my $fh;
1604: my $filename = '/prtspool/'.
1605: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1606: time.'_'.rand(1000000000).'.'.$suffix;
1607: $fh = Apache::File->new('>/home/httpd'.$filename);
1608: if (! defined($fh)) {
1609: $r->log_error("Couldn't open $filename for output $!");
1610: $r->print(&mt('Problems occurred in creating the output file. '
1611: .'This error has been logged. '
1612: .'Please alert your LON-CAPA administrator.'));
1613: }
1614: return ($fh,$filename)
1615: }
1616:
1617:
1618: =pod
1619:
1620: =back
1621:
1622: =cut
1623:
1624: ###############################################################
1625: ## Home server <option> list generating code ##
1626: ###############################################################
1627:
1628: # ------------------------------------------
1629:
1630: sub domain_select {
1631: my ($name,$value,$multiple)=@_;
1632: my %domains=map {
1633: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1634: } &Apache::lonnet::all_domains();
1635: if ($multiple) {
1636: $domains{''}=&mt('Any domain');
1637: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1638: return &multiple_select_form($name,$value,4,\%domains);
1639: } else {
1640: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1641: return &select_form($name,$value,%domains);
1642: }
1643: }
1644:
1645: #-------------------------------------------
1646:
1647: =pod
1648:
1649: =head1 Routines for form select boxes
1650:
1651: =over 4
1652:
1653: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1654:
1655: Returns a string containing a <select> element int multiple mode
1656:
1657:
1658: Args:
1659: $name - name of the <select> element
1660: $value - scalar or array ref of values that should already be selected
1661: $size - number of rows long the select element is
1662: $hash - the elements should be 'option' => 'shown text'
1663: (shown text should already have been &mt())
1664: $order - (optional) array ref of the order to show the elements in
1665:
1666: =cut
1667:
1668: #-------------------------------------------
1669: sub multiple_select_form {
1670: my ($name,$value,$size,$hash,$order)=@_;
1671: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1672: my $output='';
1673: if (! defined($size)) {
1674: $size = 4;
1675: if (scalar(keys(%$hash))<4) {
1676: $size = scalar(keys(%$hash));
1677: }
1678: }
1679: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1680: my @order;
1681: if (ref($order) eq 'ARRAY') {
1682: @order = @{$order};
1683: } else {
1684: @order = sort(keys(%$hash));
1685: }
1686: if (exists($$hash{'select_form_order'})) {
1687: @order = @{$$hash{'select_form_order'}};
1688: }
1689:
1690: foreach my $key (@order) {
1691: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1692: $output.='selected="selected" ' if ($selected{$key});
1693: $output.='>'.$hash->{$key}."</option>\n";
1694: }
1695: $output.="</select>\n";
1696: return $output;
1697: }
1698:
1699: #-------------------------------------------
1700:
1701: =pod
1702:
1703: =item * &select_form($defdom,$name,%hash)
1704:
1705: Returns a string containing a <select name='$name' size='1'> form to
1706: allow a user to select options from a hash option_name => displayed text.
1707: See lonrights.pm for an example invocation and use.
1708:
1709: =cut
1710:
1711: #-------------------------------------------
1712: sub select_form {
1713: my ($def,$name,%hash) = @_;
1714: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1715: my @keys;
1716: if (exists($hash{'select_form_order'})) {
1717: @keys=@{$hash{'select_form_order'}};
1718: } else {
1719: @keys=sort(keys(%hash));
1720: }
1721: foreach my $key (@keys) {
1722: $selectform.=
1723: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
1724: ($key eq $def ? 'selected="selected" ' : '').
1725: ">".&mt($hash{$key})."</option>\n";
1726: }
1727: $selectform.="</select>";
1728: return $selectform;
1729: }
1730:
1731: # For display filters
1732:
1733: sub display_filter {
1734: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1735: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1736: return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1737: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
1738: (&mt('all'),10,20,50,100,1000,10000))).
1739: '</label></span> <span class="LC_nobreak">'.
1740: &mt('Filter [_1]',
1741: &select_form($env{'form.displayfilter'},
1742: 'displayfilter',
1743: ('currentfolder' => 'Current folder/page',
1744: 'containing' => 'Containing phrase',
1745: 'none' => 'None'))).
1746: '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1747: }
1748:
1749: sub gradeleveldescription {
1750: my $gradelevel=shift;
1751: my %gradelevels=(0 => 'Not specified',
1752: 1 => 'Grade 1',
1753: 2 => 'Grade 2',
1754: 3 => 'Grade 3',
1755: 4 => 'Grade 4',
1756: 5 => 'Grade 5',
1757: 6 => 'Grade 6',
1758: 7 => 'Grade 7',
1759: 8 => 'Grade 8',
1760: 9 => 'Grade 9',
1761: 10 => 'Grade 10',
1762: 11 => 'Grade 11',
1763: 12 => 'Grade 12',
1764: 13 => 'Grade 13',
1765: 14 => '100 Level',
1766: 15 => '200 Level',
1767: 16 => '300 Level',
1768: 17 => '400 Level',
1769: 18 => 'Graduate Level');
1770: return &mt($gradelevels{$gradelevel});
1771: }
1772:
1773: sub select_level_form {
1774: my ($deflevel,$name)=@_;
1775: unless ($deflevel) { $deflevel=0; }
1776: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1777: for (my $i=0; $i<=18; $i++) {
1778: $selectform.="<option value=\"$i\" ".
1779: ($i==$deflevel ? 'selected="selected" ' : '').
1780: ">".&gradeleveldescription($i)."</option>\n";
1781: }
1782: $selectform.="</select>";
1783: return $selectform;
1784: }
1785:
1786: #-------------------------------------------
1787:
1788: =pod
1789:
1790: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$autosubmit)
1791:
1792: Returns a string containing a <select name='$name' size='1'> form to
1793: allow a user to select the domain to preform an operation in.
1794: See loncreateuser.pm for an example invocation and use.
1795:
1796: If the $includeempty flag is set, it also includes an empty choice ("no domain
1797: selected");
1798:
1799: If the $showdomdesc flag is set, the domain name is followed by the domain description.
1800:
1801: If the $autosubmit flag is set, the form containing the domain selector will be auto-submitted by an onchange action.
1802:
1803: =cut
1804:
1805: #-------------------------------------------
1806: sub select_dom_form {
1807: my ($defdom,$name,$includeempty,$showdomdesc,$autosubmit) = @_;
1808: my $onchange;
1809: if ($autosubmit) {
1810: $onchange = ' onchange="this.form.submit()"';
1811: }
1812: my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1813: if ($includeempty) { @domains=('',@domains); }
1814: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1815: foreach my $dom (@domains) {
1816: $selectdomain.="<option value=\"$dom\" ".
1817: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
1818: if ($showdomdesc) {
1819: if ($dom ne '') {
1820: my $domdesc = &Apache::lonnet::domain($dom,'description');
1821: if ($domdesc ne '') {
1822: $selectdomain .= ' ('.$domdesc.')';
1823: }
1824: }
1825: }
1826: $selectdomain .= "</option>\n";
1827: }
1828: $selectdomain.="</select>";
1829: return $selectdomain;
1830: }
1831:
1832: #-------------------------------------------
1833:
1834: =pod
1835:
1836: =item * &home_server_form_item($domain,$name,$defaultflag)
1837:
1838: input: 4 arguments (two required, two optional) -
1839: $domain - domain of new user
1840: $name - name of form element
1841: $default - Value of 'default' causes a default item to be first
1842: option, and selected by default.
1843: $hide - Value of 'hide' causes hiding of the name of the server,
1844: if 1 server found, or default, if 0 found.
1845: output: returns 2 items:
1846: (a) form element which contains either:
1847: (i) <select name="$name">
1848: <option value="$hostid1">$hostid $servers{$hostid}</option>
1849: <option value="$hostid2">$hostid $servers{$hostid}</option>
1850: </select>
1851: form item if there are multiple library servers in $domain, or
1852: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
1853: if there is only one library server in $domain.
1854:
1855: (b) number of library servers found.
1856:
1857: See loncreateuser.pm for example of use.
1858:
1859: =cut
1860:
1861: #-------------------------------------------
1862: sub home_server_form_item {
1863: my ($domain,$name,$default,$hide) = @_;
1864: my %servers = &Apache::lonnet::get_servers($domain,'library');
1865: my $result;
1866: my $numlib = keys(%servers);
1867: if ($numlib > 1) {
1868: $result .= '<select name="'.$name.'" />'."\n";
1869: if ($default) {
1870: $result .= '<option value="default" selected="selected">'.&mt('default').
1871: '</option>'."\n";
1872: }
1873: foreach my $hostid (sort(keys(%servers))) {
1874: $result.= '<option value="'.$hostid.'">'.
1875: $hostid.' '.$servers{$hostid}."</option>\n";
1876: }
1877: $result .= '</select>'."\n";
1878: } elsif ($numlib == 1) {
1879: my $hostid;
1880: foreach my $item (keys(%servers)) {
1881: $hostid = $item;
1882: }
1883: $result .= '<input type="hidden" name="'.$name.'" value="'.
1884: $hostid.'" />';
1885: if (!$hide) {
1886: $result .= $hostid.' '.$servers{$hostid};
1887: }
1888: $result .= "\n";
1889: } elsif ($default) {
1890: $result .= '<input type="hidden" name="'.$name.
1891: '" value="default" />';
1892: if (!$hide) {
1893: $result .= &mt('default');
1894: }
1895: $result .= "\n";
1896: }
1897: return ($result,$numlib);
1898: }
1899:
1900: =pod
1901:
1902: =back
1903:
1904: =cut
1905:
1906: ###############################################################
1907: ## Decoding User Agent ##
1908: ###############################################################
1909:
1910: =pod
1911:
1912: =head1 Decoding the User Agent
1913:
1914: =over 4
1915:
1916: =item * &decode_user_agent()
1917:
1918: Inputs: $r
1919:
1920: Outputs:
1921:
1922: =over 4
1923:
1924: =item * $httpbrowser
1925:
1926: =item * $clientbrowser
1927:
1928: =item * $clientversion
1929:
1930: =item * $clientmathml
1931:
1932: =item * $clientunicode
1933:
1934: =item * $clientos
1935:
1936: =back
1937:
1938: =back
1939:
1940: =cut
1941:
1942: ###############################################################
1943: ###############################################################
1944: sub decode_user_agent {
1945: my ($r)=@_;
1946: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
1947: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
1948: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1949: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1950: my $clientbrowser='unknown';
1951: my $clientversion='0';
1952: my $clientmathml='';
1953: my $clientunicode='0';
1954: for (my $i=0;$i<=$#browsertype;$i++) {
1955: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
1956: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
1957: $clientbrowser=$bname;
1958: $httpbrowser=~/$vreg/i;
1959: $clientversion=$1;
1960: $clientmathml=($clientversion>=$minv);
1961: $clientunicode=($clientversion>=$univ);
1962: }
1963: }
1964: my $clientos='unknown';
1965: if (($httpbrowser=~/linux/i) ||
1966: ($httpbrowser=~/unix/i) ||
1967: ($httpbrowser=~/ux/i) ||
1968: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
1969: if (($httpbrowser=~/vax/i) ||
1970: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
1971: if ($httpbrowser=~/next/i) { $clientos='next'; }
1972: if (($httpbrowser=~/mac/i) ||
1973: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1974: if ($httpbrowser=~/win/i) { $clientos='win'; }
1975: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1976: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1977: $clientunicode,$clientos,);
1978: }
1979:
1980: ###############################################################
1981: ## Authentication changing form generation subroutines ##
1982: ###############################################################
1983: ##
1984: ## All of the authform_xxxxxxx subroutines take their inputs in a
1985: ## hash, and have reasonable default values.
1986: ##
1987: ## formname = the name given in the <form> tag.
1988: #-------------------------------------------
1989:
1990: =pod
1991:
1992: =head1 Authentication Routines
1993:
1994: =over 4
1995:
1996: =item * &authform_xxxxxx()
1997:
1998: The authform_xxxxxx subroutines provide javascript and html forms which
1999: handle some of the conveniences required for authentication forms.
2000: This is not an optimal method, but it works.
2001:
2002: =over 4
2003:
2004: =item * authform_header
2005:
2006: =item * authform_authorwarning
2007:
2008: =item * authform_nochange
2009:
2010: =item * authform_kerberos
2011:
2012: =item * authform_internal
2013:
2014: =item * authform_filesystem
2015:
2016: =back
2017:
2018: See loncreateuser.pm for invocation and use examples.
2019:
2020: =cut
2021:
2022: #-------------------------------------------
2023: sub authform_header{
2024: my %in = (
2025: formname => 'cu',
2026: kerb_def_dom => '',
2027: @_,
2028: );
2029: $in{'formname'} = 'document.' . $in{'formname'};
2030: my $result='';
2031:
2032: #---------------------------------------------- Code for upper case translation
2033: my $Javascript_toUpperCase;
2034: unless ($in{kerb_def_dom}) {
2035: $Javascript_toUpperCase =<<"END";
2036: switch (choice) {
2037: case 'krb': currentform.elements[choicearg].value =
2038: currentform.elements[choicearg].value.toUpperCase();
2039: break;
2040: default:
2041: }
2042: END
2043: } else {
2044: $Javascript_toUpperCase = "";
2045: }
2046:
2047: my $radioval = "'nochange'";
2048: if (defined($in{'curr_authtype'})) {
2049: if ($in{'curr_authtype'} ne '') {
2050: $radioval = "'".$in{'curr_authtype'}."arg'";
2051: }
2052: }
2053: my $argfield = 'null';
2054: if (defined($in{'mode'})) {
2055: if ($in{'mode'} eq 'modifycourse') {
2056: if (defined($in{'curr_autharg'})) {
2057: if ($in{'curr_autharg'} ne '') {
2058: $argfield = "'$in{'curr_autharg'}'";
2059: }
2060: }
2061: }
2062: }
2063:
2064: $result.=<<"END";
2065: var current = new Object();
2066: current.radiovalue = $radioval;
2067: current.argfield = $argfield;
2068:
2069: function changed_radio(choice,currentform) {
2070: var choicearg = choice + 'arg';
2071: // If a radio button in changed, we need to change the argfield
2072: if (current.radiovalue != choice) {
2073: current.radiovalue = choice;
2074: if (current.argfield != null) {
2075: currentform.elements[current.argfield].value = '';
2076: }
2077: if (choice == 'nochange') {
2078: current.argfield = null;
2079: } else {
2080: current.argfield = choicearg;
2081: switch(choice) {
2082: case 'krb':
2083: currentform.elements[current.argfield].value =
2084: "$in{'kerb_def_dom'}";
2085: break;
2086: default:
2087: break;
2088: }
2089: }
2090: }
2091: return;
2092: }
2093:
2094: function changed_text(choice,currentform) {
2095: var choicearg = choice + 'arg';
2096: if (currentform.elements[choicearg].value !='') {
2097: $Javascript_toUpperCase
2098: // clear old field
2099: if ((current.argfield != choicearg) && (current.argfield != null)) {
2100: currentform.elements[current.argfield].value = '';
2101: }
2102: current.argfield = choicearg;
2103: }
2104: set_auth_radio_buttons(choice,currentform);
2105: return;
2106: }
2107:
2108: function set_auth_radio_buttons(newvalue,currentform) {
2109: var i=0;
2110: while (i < currentform.login.length) {
2111: if (currentform.login[i].value == newvalue) { break; }
2112: i++;
2113: }
2114: if (i == currentform.login.length) {
2115: return;
2116: }
2117: current.radiovalue = newvalue;
2118: currentform.login[i].checked = true;
2119: return;
2120: }
2121: END
2122: return $result;
2123: }
2124:
2125: sub authform_authorwarning{
2126: my $result='';
2127: $result='<i>'.
2128: &mt('As a general rule, only authors or co-authors should be '.
2129: 'filesystem authenticated '.
2130: '(which allows access to the server filesystem).')."</i>\n";
2131: return $result;
2132: }
2133:
2134: sub authform_nochange{
2135: my %in = (
2136: formname => 'document.cu',
2137: kerb_def_dom => 'MSU.EDU',
2138: @_,
2139: );
2140: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2141: my $result;
2142: if (keys(%can_assign) == 0) {
2143: $result = &mt('Under you current role you are not permitted to change login settings for this user');
2144: } else {
2145: $result = '<label>'.&mt('[_1] Do not change login data',
2146: '<input type="radio" name="login" value="nochange" '.
2147: 'checked="checked" onclick="'.
2148: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2149: '</label>';
2150: }
2151: return $result;
2152: }
2153:
2154: sub authform_kerberos {
2155: my %in = (
2156: formname => 'document.cu',
2157: kerb_def_dom => 'MSU.EDU',
2158: kerb_def_auth => 'krb4',
2159: @_,
2160: );
2161: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2162: $autharg,$jscall);
2163: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2164: if ($in{'kerb_def_auth'} eq 'krb5') {
2165: $check5 = ' checked="checked"';
2166: } else {
2167: $check4 = ' checked="checked"';
2168: }
2169: $krbarg = $in{'kerb_def_dom'};
2170: if (defined($in{'curr_authtype'})) {
2171: if ($in{'curr_authtype'} eq 'krb') {
2172: $krbcheck = ' checked="checked"';
2173: if (defined($in{'mode'})) {
2174: if ($in{'mode'} eq 'modifyuser') {
2175: $krbcheck = '';
2176: }
2177: }
2178: if (defined($in{'curr_kerb_ver'})) {
2179: if ($in{'curr_krb_ver'} eq '5') {
2180: $check5 = ' checked="checked"';
2181: $check4 = '';
2182: } else {
2183: $check4 = ' checked="checked"';
2184: $check5 = '';
2185: }
2186: }
2187: if (defined($in{'curr_autharg'})) {
2188: $krbarg = $in{'curr_autharg'};
2189: }
2190: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2191: if (defined($in{'curr_autharg'})) {
2192: $result =
2193: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2194: $in{'curr_autharg'},$krbver);
2195: } else {
2196: $result =
2197: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2198: }
2199: return $result;
2200: }
2201: }
2202: } else {
2203: if ($authnum == 1) {
2204: $authtype = '<input type="hidden" name="login" value="krb" />';
2205: }
2206: }
2207: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2208: return;
2209: } elsif ($authtype eq '') {
2210: if (defined($in{'mode'})) {
2211: if ($in{'mode'} eq 'modifycourse') {
2212: if ($authnum == 1) {
2213: $authtype = '<input type="hidden" name="login" value="krb" />';
2214: }
2215: }
2216: }
2217: }
2218: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2219: if ($authtype eq '') {
2220: $authtype = '<input type="radio" name="login" value="krb" '.
2221: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2222: $krbcheck.' />';
2223: }
2224: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
2225: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
2226: $in{'curr_authtype'} eq 'krb5') ||
2227: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
2228: $in{'curr_authtype'} eq 'krb4')) {
2229: $result .= &mt
2230: ('[_1] Kerberos authenticated with domain [_2] '.
2231: '[_3] Version 4 [_4] Version 5 [_5]',
2232: '<label>'.$authtype,
2233: '</label><input type="text" size="10" name="krbarg" '.
2234: 'value="'.$krbarg.'" '.
2235: 'onchange="'.$jscall.'" />',
2236: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2237: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2238: '</label>');
2239: } elsif ($can_assign{'krb4'}) {
2240: $result .= &mt
2241: ('[_1] Kerberos authenticated with domain [_2] '.
2242: '[_3] Version 4 [_4]',
2243: '<label>'.$authtype,
2244: '</label><input type="text" size="10" name="krbarg" '.
2245: 'value="'.$krbarg.'" '.
2246: 'onchange="'.$jscall.'" />',
2247: '<label><input type="hidden" name="krbver" value="4" />',
2248: '</label>');
2249: } elsif ($can_assign{'krb5'}) {
2250: $result .= &mt
2251: ('[_1] Kerberos authenticated with domain [_2] '.
2252: '[_3] Version 5 [_4]',
2253: '<label>'.$authtype,
2254: '</label><input type="text" size="10" name="krbarg" '.
2255: 'value="'.$krbarg.'" '.
2256: 'onchange="'.$jscall.'" />',
2257: '<label><input type="hidden" name="krbver" value="5" />',
2258: '</label>');
2259: }
2260: return $result;
2261: }
2262:
2263: sub authform_internal{
2264: my %in = (
2265: formname => 'document.cu',
2266: kerb_def_dom => 'MSU.EDU',
2267: @_,
2268: );
2269: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
2270: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2271: if (defined($in{'curr_authtype'})) {
2272: if ($in{'curr_authtype'} eq 'int') {
2273: if ($can_assign{'int'}) {
2274: $intcheck = 'checked="checked" ';
2275: if (defined($in{'mode'})) {
2276: if ($in{'mode'} eq 'modifyuser') {
2277: $intcheck = '';
2278: }
2279: }
2280: if (defined($in{'curr_autharg'})) {
2281: $intarg = $in{'curr_autharg'};
2282: }
2283: } else {
2284: $result = &mt('Currently internally authenticated.');
2285: return $result;
2286: }
2287: }
2288: } else {
2289: if ($authnum == 1) {
2290: $authtype = '<input type="hidden" name="login" value="int" />';
2291: }
2292: }
2293: if (!$can_assign{'int'}) {
2294: return;
2295: } elsif ($authtype eq '') {
2296: if (defined($in{'mode'})) {
2297: if ($in{'mode'} eq 'modifycourse') {
2298: if ($authnum == 1) {
2299: $authtype = '<input type="hidden" name="login" value="int" />';
2300: }
2301: }
2302: }
2303: }
2304: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2305: if ($authtype eq '') {
2306: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2307: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2308: }
2309: $autharg = '<input type="password" size="10" name="intarg" value="'.
2310: $intarg.'" onchange="'.$jscall.'" />';
2311: $result = &mt
2312: ('[_1] Internally authenticated (with initial password [_2])',
2313: '<label>'.$authtype,'</label>'.$autharg);
2314: $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>';
2315: return $result;
2316: }
2317:
2318: sub authform_local{
2319: my %in = (
2320: formname => 'document.cu',
2321: kerb_def_dom => 'MSU.EDU',
2322: @_,
2323: );
2324: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
2325: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2326: if (defined($in{'curr_authtype'})) {
2327: if ($in{'curr_authtype'} eq 'loc') {
2328: if ($can_assign{'loc'}) {
2329: $loccheck = 'checked="checked" ';
2330: if (defined($in{'mode'})) {
2331: if ($in{'mode'} eq 'modifyuser') {
2332: $loccheck = '';
2333: }
2334: }
2335: if (defined($in{'curr_autharg'})) {
2336: $locarg = $in{'curr_autharg'};
2337: }
2338: } else {
2339: $result = &mt('Currently using local (institutional) authentication.');
2340: return $result;
2341: }
2342: }
2343: } else {
2344: if ($authnum == 1) {
2345: $authtype = '<input type="hidden" name="login" value="loc" />';
2346: }
2347: }
2348: if (!$can_assign{'loc'}) {
2349: return;
2350: } elsif ($authtype eq '') {
2351: if (defined($in{'mode'})) {
2352: if ($in{'mode'} eq 'modifycourse') {
2353: if ($authnum == 1) {
2354: $authtype = '<input type="hidden" name="login" value="loc" />';
2355: }
2356: }
2357: }
2358: }
2359: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2360: if ($authtype eq '') {
2361: $authtype = '<input type="radio" name="login" value="loc" '.
2362: $loccheck.' onchange="'.$jscall.'" onclick="'.
2363: $jscall.'" />';
2364: }
2365: $autharg = '<input type="text" size="10" name="locarg" value="'.
2366: $locarg.'" onchange="'.$jscall.'" />';
2367: $result = &mt('[_1] Local Authentication with argument [_2]',
2368: '<label>'.$authtype,'</label>'.$autharg);
2369: return $result;
2370: }
2371:
2372: sub authform_filesystem{
2373: my %in = (
2374: formname => 'document.cu',
2375: kerb_def_dom => 'MSU.EDU',
2376: @_,
2377: );
2378: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
2379: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2380: if (defined($in{'curr_authtype'})) {
2381: if ($in{'curr_authtype'} eq 'fsys') {
2382: if ($can_assign{'fsys'}) {
2383: $fsyscheck = 'checked="checked" ';
2384: if (defined($in{'mode'})) {
2385: if ($in{'mode'} eq 'modifyuser') {
2386: $fsyscheck = '';
2387: }
2388: }
2389: } else {
2390: $result = &mt('Currently Filesystem Authenticated.');
2391: return $result;
2392: }
2393: }
2394: } else {
2395: if ($authnum == 1) {
2396: $authtype = '<input type="hidden" name="login" value="fsys" />';
2397: }
2398: }
2399: if (!$can_assign{'fsys'}) {
2400: return;
2401: } elsif ($authtype eq '') {
2402: if (defined($in{'mode'})) {
2403: if ($in{'mode'} eq 'modifycourse') {
2404: if ($authnum == 1) {
2405: $authtype = '<input type="hidden" name="login" value="fsys" />';
2406: }
2407: }
2408: }
2409: }
2410: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2411: if ($authtype eq '') {
2412: $authtype = '<input type="radio" name="login" value="fsys" '.
2413: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2414: $jscall.'" />';
2415: }
2416: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2417: ' onchange="'.$jscall.'" />';
2418: $result = &mt
2419: ('[_1] Filesystem Authenticated (with initial password [_2])',
2420: '<label><input type="radio" name="login" value="fsys" '.
2421: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
2422: '</label><input type="password" size="10" name="fsysarg" value="" '.
2423: 'onchange="'.$jscall.'" />');
2424: return $result;
2425: }
2426:
2427: sub get_assignable_auth {
2428: my ($dom) = @_;
2429: if ($dom eq '') {
2430: $dom = $env{'request.role.domain'};
2431: }
2432: my %can_assign = (
2433: krb4 => 1,
2434: krb5 => 1,
2435: int => 1,
2436: loc => 1,
2437: );
2438: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2439: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2440: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2441: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2442: my $context;
2443: if ($env{'request.role'} =~ /^au/) {
2444: $context = 'author';
2445: } elsif ($env{'request.role'} =~ /^dc/) {
2446: $context = 'domain';
2447: } elsif ($env{'request.course.id'}) {
2448: $context = 'course';
2449: }
2450: if ($context) {
2451: if (ref($authhash->{$context}) eq 'HASH') {
2452: %can_assign = %{$authhash->{$context}};
2453: }
2454: }
2455: }
2456: }
2457: my $authnum = 0;
2458: foreach my $key (keys(%can_assign)) {
2459: if ($can_assign{$key}) {
2460: $authnum ++;
2461: }
2462: }
2463: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2464: $authnum --;
2465: }
2466: return ($authnum,%can_assign);
2467: }
2468:
2469: ###############################################################
2470: ## Get Kerberos Defaults for Domain ##
2471: ###############################################################
2472: ##
2473: ## Returns default kerberos version and an associated argument
2474: ## as listed in file domain.tab. If not listed, provides
2475: ## appropriate default domain and kerberos version.
2476: ##
2477: #-------------------------------------------
2478:
2479: =pod
2480:
2481: =item * &get_kerberos_defaults()
2482:
2483: get_kerberos_defaults($target_domain) returns the default kerberos
2484: version and domain. If not found, it defaults to version 4 and the
2485: domain of the server.
2486:
2487: =over 4
2488:
2489: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2490:
2491: =back
2492:
2493: =back
2494:
2495: =cut
2496:
2497: #-------------------------------------------
2498: sub get_kerberos_defaults {
2499: my $domain=shift;
2500: my ($krbdef,$krbdefdom);
2501: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2502: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2503: $krbdef = $domdefaults{'auth_def'};
2504: $krbdefdom = $domdefaults{'auth_arg_def'};
2505: } else {
2506: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2507: my $krbdefdom=$1;
2508: $krbdefdom=~tr/a-z/A-Z/;
2509: $krbdef = "krb4";
2510: }
2511: return ($krbdef,$krbdefdom);
2512: }
2513:
2514:
2515: ###############################################################
2516: ## Thesaurus Functions ##
2517: ###############################################################
2518:
2519: =pod
2520:
2521: =head1 Thesaurus Functions
2522:
2523: =over 4
2524:
2525: =item * &initialize_keywords()
2526:
2527: Initializes the package variable %Keywords if it is empty. Uses the
2528: package variable $thesaurus_db_file.
2529:
2530: =cut
2531:
2532: ###################################################
2533:
2534: sub initialize_keywords {
2535: return 1 if (scalar keys(%Keywords));
2536: # If we are here, %Keywords is empty, so fill it up
2537: # Make sure the file we need exists...
2538: if (! -e $thesaurus_db_file) {
2539: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2540: " failed because it does not exist");
2541: return 0;
2542: }
2543: # Set up the hash as a database
2544: my %thesaurus_db;
2545: if (! tie(%thesaurus_db,'GDBM_File',
2546: $thesaurus_db_file,&GDBM_READER(),0640)){
2547: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2548: $thesaurus_db_file);
2549: return 0;
2550: }
2551: # Get the average number of appearances of a word.
2552: my $avecount = $thesaurus_db{'average.count'};
2553: # Put keywords (those that appear > average) into %Keywords
2554: while (my ($word,$data)=each (%thesaurus_db)) {
2555: my ($count,undef) = split /:/,$data;
2556: $Keywords{$word}++ if ($count > $avecount);
2557: }
2558: untie %thesaurus_db;
2559: # Remove special values from %Keywords.
2560: foreach my $value ('total.count','average.count') {
2561: delete($Keywords{$value}) if (exists($Keywords{$value}));
2562: }
2563: return 1;
2564: }
2565:
2566: ###################################################
2567:
2568: =pod
2569:
2570: =item * &keyword($word)
2571:
2572: Returns true if $word is a keyword. A keyword is a word that appears more
2573: than the average number of times in the thesaurus database. Calls
2574: &initialize_keywords
2575:
2576: =cut
2577:
2578: ###################################################
2579:
2580: sub keyword {
2581: return if (!&initialize_keywords());
2582: my $word=lc(shift());
2583: $word=~s/\W//g;
2584: return exists($Keywords{$word});
2585: }
2586:
2587: ###############################################################
2588:
2589: =pod
2590:
2591: =item * &get_related_words()
2592:
2593: Look up a word in the thesaurus. Takes a scalar argument and returns
2594: an array of words. If the keyword is not in the thesaurus, an empty array
2595: will be returned. The order of the words returned is determined by the
2596: database which holds them.
2597:
2598: Uses global $thesaurus_db_file.
2599:
2600: =cut
2601:
2602: ###############################################################
2603: sub get_related_words {
2604: my $keyword = shift;
2605: my %thesaurus_db;
2606: if (! -e $thesaurus_db_file) {
2607: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
2608: "failed because the file does not exist");
2609: return ();
2610: }
2611: if (! tie(%thesaurus_db,'GDBM_File',
2612: $thesaurus_db_file,&GDBM_READER(),0640)){
2613: return ();
2614: }
2615: my @Words=();
2616: my $count=0;
2617: if (exists($thesaurus_db{$keyword})) {
2618: # The first element is the number of times
2619: # the word appears. We do not need it now.
2620: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
2621: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
2622: my $threshold=$mostfrequentcount/10;
2623: foreach my $possibleword (@RelatedWords) {
2624: my ($word,$wordcount)=split(/\,/,$possibleword);
2625: if ($wordcount>$threshold) {
2626: push(@Words,$word);
2627: $count++;
2628: if ($count>10) { last; }
2629: }
2630: }
2631: }
2632: untie %thesaurus_db;
2633: return @Words;
2634: }
2635:
2636: =pod
2637:
2638: =back
2639:
2640: =cut
2641:
2642: # -------------------------------------------------------------- Plaintext name
2643: =pod
2644:
2645: =head1 User Name Functions
2646:
2647: =over 4
2648:
2649: =item * &plainname($uname,$udom,$first)
2650:
2651: Takes a users logon name and returns it as a string in
2652: "first middle last generation" form
2653: if $first is set to 'lastname' then it returns it as
2654: 'lastname generation, firstname middlename' if their is a lastname
2655:
2656: =cut
2657:
2658:
2659: ###############################################################
2660: sub plainname {
2661: my ($uname,$udom,$first)=@_;
2662: return if (!defined($uname) || !defined($udom));
2663: my %names=&getnames($uname,$udom);
2664: my $name=&Apache::lonnet::format_name($names{'firstname'},
2665: $names{'middlename'},
2666: $names{'lastname'},
2667: $names{'generation'},$first);
2668: $name=~s/^\s+//;
2669: $name=~s/\s+$//;
2670: $name=~s/\s+/ /g;
2671: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
2672: return $name;
2673: }
2674:
2675: # -------------------------------------------------------------------- Nickname
2676: =pod
2677:
2678: =item * &nickname($uname,$udom)
2679:
2680: Gets a users name and returns it as a string as
2681:
2682: ""nickname""
2683:
2684: if the user has a nickname or
2685:
2686: "first middle last generation"
2687:
2688: if the user does not
2689:
2690: =cut
2691:
2692: sub nickname {
2693: my ($uname,$udom)=@_;
2694: return if (!defined($uname) || !defined($udom));
2695: my %names=&getnames($uname,$udom);
2696: my $name=$names{'nickname'};
2697: if ($name) {
2698: $name='"'.$name.'"';
2699: } else {
2700: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
2701: $names{'lastname'}.' '.$names{'generation'};
2702: $name=~s/\s+$//;
2703: $name=~s/\s+/ /g;
2704: }
2705: return $name;
2706: }
2707:
2708: sub getnames {
2709: my ($uname,$udom)=@_;
2710: return if (!defined($uname) || !defined($udom));
2711: if ($udom eq 'public' && $uname eq 'public') {
2712: return ('lastname' => &mt('Public'));
2713: }
2714: my $id=$uname.':'.$udom;
2715: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
2716: if ($cached) {
2717: return %{$names};
2718: } else {
2719: my %loadnames=&Apache::lonnet::get('environment',
2720: ['firstname','middlename','lastname','generation','nickname'],
2721: $udom,$uname);
2722: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
2723: return %loadnames;
2724: }
2725: }
2726:
2727: # -------------------------------------------------------------------- getemails
2728:
2729: =pod
2730:
2731: =item * &getemails($uname,$udom)
2732:
2733: Gets a user's email information and returns it as a hash with keys:
2734: notification, critnotification, permanentemail
2735:
2736: For notification and critnotification, values are comma-separated lists
2737: of e-mail addresses; for permanentemail, value is a single e-mail address.
2738:
2739:
2740: =cut
2741:
2742:
2743: sub getemails {
2744: my ($uname,$udom)=@_;
2745: if ($udom eq 'public' && $uname eq 'public') {
2746: return;
2747: }
2748: if (!$udom) { $udom=$env{'user.domain'}; }
2749: if (!$uname) { $uname=$env{'user.name'}; }
2750: my $id=$uname.':'.$udom;
2751: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
2752: if ($cached) {
2753: return %{$names};
2754: } else {
2755: my %loadnames=&Apache::lonnet::get('environment',
2756: ['notification','critnotification',
2757: 'permanentemail'],
2758: $udom,$uname);
2759: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
2760: return %loadnames;
2761: }
2762: }
2763:
2764: sub flush_email_cache {
2765: my ($uname,$udom)=@_;
2766: if (!$udom) { $udom =$env{'user.domain'}; }
2767: if (!$uname) { $uname=$env{'user.name'}; }
2768: return if ($udom eq 'public' && $uname eq 'public');
2769: my $id=$uname.':'.$udom;
2770: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
2771: }
2772:
2773: # -------------------------------------------------------------------- getlangs
2774:
2775: =pod
2776:
2777: =item * &getlangs($uname,$udom)
2778:
2779: Gets a user's language preference and returns it as a hash with key:
2780: language.
2781:
2782: =cut
2783:
2784:
2785: sub getlangs {
2786: my ($uname,$udom) = @_;
2787: if (!$udom) { $udom =$env{'user.domain'}; }
2788: if (!$uname) { $uname=$env{'user.name'}; }
2789: my $id=$uname.':'.$udom;
2790: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
2791: if ($cached) {
2792: return %{$langs};
2793: } else {
2794: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
2795: $udom,$uname);
2796: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
2797: return %loadlangs;
2798: }
2799: }
2800:
2801: sub flush_langs_cache {
2802: my ($uname,$udom)=@_;
2803: if (!$udom) { $udom =$env{'user.domain'}; }
2804: if (!$uname) { $uname=$env{'user.name'}; }
2805: return if ($udom eq 'public' && $uname eq 'public');
2806: my $id=$uname.':'.$udom;
2807: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
2808: }
2809:
2810: # ------------------------------------------------------------------ Screenname
2811:
2812: =pod
2813:
2814: =item * &screenname($uname,$udom)
2815:
2816: Gets a users screenname and returns it as a string
2817:
2818: =cut
2819:
2820: sub screenname {
2821: my ($uname,$udom)=@_;
2822: if ($uname eq $env{'user.name'} &&
2823: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
2824: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
2825: return $names{'screenname'};
2826: }
2827:
2828:
2829: # ------------------------------------------------------------- Confirm Wrapper
2830: =pod
2831:
2832: =item confirmwrapper
2833:
2834: Wrap messages about completion of operation in box
2835:
2836: =cut
2837:
2838: sub confirmwrapper {
2839: my ($message)=@_;
2840: if ($message) {
2841: return "\n".'<div class="LC_confirm_box">'."\n"
2842: .$message."\n"
2843: .'</div>'."\n";
2844: } else {
2845: return $message;
2846: }
2847: }
2848:
2849: # ------------------------------------------------------------- Message Wrapper
2850:
2851: sub messagewrapper {
2852: my ($link,$username,$domain,$subject,$text)=@_;
2853: return
2854: '<a href="/adm/email?compose=individual&'.
2855: 'recname='.$username.'&recdom='.$domain.
2856: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
2857: 'title="'.&mt('Send message').'">'.$link.'</a>';
2858: }
2859:
2860: # --------------------------------------------------------------- Notes Wrapper
2861:
2862: sub noteswrapper {
2863: my ($link,$un,$do)=@_;
2864: return
2865: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
2866: }
2867:
2868: # ------------------------------------------------------------- Aboutme Wrapper
2869:
2870: sub aboutmewrapper {
2871: my ($link,$username,$domain,$target)=@_;
2872: if (!defined($username) && !defined($domain)) {
2873: return;
2874: }
2875: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
2876: ($target?' target="$target"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
2877: }
2878:
2879: # ------------------------------------------------------------ Syllabus Wrapper
2880:
2881: sub syllabuswrapper {
2882: my ($linktext,$coursedir,$domain)=@_;
2883: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
2884: }
2885:
2886: # -----------------------------------------------------------------------------
2887:
2888: sub track_student_link {
2889: my ($linktext,$sname,$sdom,$target,$start) = @_;
2890: my $link ="/adm/trackstudent?";
2891: my $title = 'View recent activity';
2892: if (defined($sname) && $sname !~ /^\s*$/ &&
2893: defined($sdom) && $sdom !~ /^\s*$/) {
2894: $link .= "selected_student=$sname:$sdom";
2895: $title .= ' of this student';
2896: }
2897: if (defined($target) && $target !~ /^\s*$/) {
2898: $target = qq{target="$target"};
2899: } else {
2900: $target = '';
2901: }
2902: if ($start) { $link.='&start='.$start; }
2903: $title = &mt($title);
2904: $linktext = &mt($linktext);
2905: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
2906: &help_open_topic('View_recent_activity');
2907: }
2908:
2909: sub slot_reservations_link {
2910: my ($linktext,$sname,$sdom,$target) = @_;
2911: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
2912: my $title = 'View slot reservation history';
2913: if (defined($sname) && $sname !~ /^\s*$/ &&
2914: defined($sdom) && $sdom !~ /^\s*$/) {
2915: $link .= "&uname=$sname&udom=$sdom";
2916: $title .= ' of this student';
2917: }
2918: if (defined($target) && $target !~ /^\s*$/) {
2919: $target = qq{target="$target"};
2920: } else {
2921: $target = '';
2922: }
2923: $title = &mt($title);
2924: $linktext = &mt($linktext);
2925: return qq{<a href="$link" title="$title" $target>$linktext</a>};
2926: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
2927:
2928: }
2929:
2930: # ===================================================== Display a student photo
2931:
2932:
2933: sub student_image_tag {
2934: my ($domain,$user)=@_;
2935: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
2936: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
2937: return '<img src="'.$imgsrc.'" align="right" />';
2938: } else {
2939: return '';
2940: }
2941: }
2942:
2943: =pod
2944:
2945: =back
2946:
2947: =head1 Access .tab File Data
2948:
2949: =over 4
2950:
2951: =item * &languageids()
2952:
2953: returns list of all language ids
2954:
2955: =cut
2956:
2957: sub languageids {
2958: return sort(keys(%language));
2959: }
2960:
2961: =pod
2962:
2963: =item * &languagedescription()
2964:
2965: returns description of a specified language id
2966:
2967: =cut
2968:
2969: sub languagedescription {
2970: my $code=shift;
2971: return ($supported_language{$code}?'* ':'').
2972: $language{$code}.
2973: ($supported_language{$code}?' ('.&mt('interface available').')':'');
2974: }
2975:
2976: sub plainlanguagedescription {
2977: my $code=shift;
2978: return $language{$code};
2979: }
2980:
2981: sub supportedlanguagecode {
2982: my $code=shift;
2983: return $supported_language{$code};
2984: }
2985:
2986: =pod
2987:
2988: =item * ©rightids()
2989:
2990: returns list of all copyrights
2991:
2992: =cut
2993:
2994: sub copyrightids {
2995: return sort(keys(%cprtag));
2996: }
2997:
2998: =pod
2999:
3000: =item * ©rightdescription()
3001:
3002: returns description of a specified copyright id
3003:
3004: =cut
3005:
3006: sub copyrightdescription {
3007: return &mt($cprtag{shift(@_)});
3008: }
3009:
3010: =pod
3011:
3012: =item * &source_copyrightids()
3013:
3014: returns list of all source copyrights
3015:
3016: =cut
3017:
3018: sub source_copyrightids {
3019: return sort(keys(%scprtag));
3020: }
3021:
3022: =pod
3023:
3024: =item * &source_copyrightdescription()
3025:
3026: returns description of a specified source copyright id
3027:
3028: =cut
3029:
3030: sub source_copyrightdescription {
3031: return &mt($scprtag{shift(@_)});
3032: }
3033:
3034: =pod
3035:
3036: =item * &filecategories()
3037:
3038: returns list of all file categories
3039:
3040: =cut
3041:
3042: sub filecategories {
3043: return sort(keys(%category_extensions));
3044: }
3045:
3046: =pod
3047:
3048: =item * &filecategorytypes()
3049:
3050: returns list of file types belonging to a given file
3051: category
3052:
3053: =cut
3054:
3055: sub filecategorytypes {
3056: my ($cat) = @_;
3057: return @{$category_extensions{lc($cat)}};
3058: }
3059:
3060: =pod
3061:
3062: =item * &fileembstyle()
3063:
3064: returns embedding style for a specified file type
3065:
3066: =cut
3067:
3068: sub fileembstyle {
3069: return $fe{lc(shift(@_))};
3070: }
3071:
3072: sub filemimetype {
3073: return $fm{lc(shift(@_))};
3074: }
3075:
3076:
3077: sub filecategoryselect {
3078: my ($name,$value)=@_;
3079: return &select_form($value,$name,
3080: '' => &mt('Any category'),
3081: map { $_,$_ } sort(keys(%category_extensions)));
3082: }
3083:
3084: =pod
3085:
3086: =item * &filedescription()
3087:
3088: returns description for a specified file type
3089:
3090: =cut
3091:
3092: sub filedescription {
3093: my $file_description = $fd{lc(shift())};
3094: $file_description =~ s:([\[\]]):~$1:g;
3095: return &mt($file_description);
3096: }
3097:
3098: =pod
3099:
3100: =item * &filedescriptionex()
3101:
3102: returns description for a specified file type with
3103: extra formatting
3104:
3105: =cut
3106:
3107: sub filedescriptionex {
3108: my $ex=shift;
3109: my $file_description = $fd{lc($ex)};
3110: $file_description =~ s:([\[\]]):~$1:g;
3111: return '.'.$ex.' '.&mt($file_description);
3112: }
3113:
3114: # End of .tab access
3115: =pod
3116:
3117: =back
3118:
3119: =cut
3120:
3121: # ------------------------------------------------------------------ File Types
3122: sub fileextensions {
3123: return sort(keys(%fe));
3124: }
3125:
3126: # ----------------------------------------------------------- Display Languages
3127: # returns a hash with all desired display languages
3128: #
3129:
3130: sub display_languages {
3131: my %languages=();
3132: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
3133: $languages{$lang}=1;
3134: }
3135: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
3136: if ($env{'form.displaylanguage'}) {
3137: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3138: $languages{$lang}=1;
3139: }
3140: }
3141: return %languages;
3142: }
3143:
3144: sub languages {
3145: my ($possible_langs) = @_;
3146: my @preferred_langs = &Apache::lonlocal::preferred_languages();
3147: if (!ref($possible_langs)) {
3148: if( wantarray ) {
3149: return @preferred_langs;
3150: } else {
3151: return $preferred_langs[0];
3152: }
3153: }
3154: my %possibilities = map { $_ => 1 } (@$possible_langs);
3155: my @preferred_possibilities;
3156: foreach my $preferred_lang (@preferred_langs) {
3157: if (exists($possibilities{$preferred_lang})) {
3158: push(@preferred_possibilities, $preferred_lang);
3159: }
3160: }
3161: if( wantarray ) {
3162: return @preferred_possibilities;
3163: }
3164: return $preferred_possibilities[0];
3165: }
3166:
3167: sub user_lang {
3168: my ($touname,$toudom,$fromcid) = @_;
3169: my @userlangs;
3170: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3171: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3172: $env{'course.'.$fromcid.'.languages'}));
3173: } else {
3174: my %langhash = &getlangs($touname,$toudom);
3175: if ($langhash{'languages'} ne '') {
3176: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3177: } else {
3178: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3179: if ($domdefs{'lang_def'} ne '') {
3180: @userlangs = ($domdefs{'lang_def'});
3181: }
3182: }
3183: }
3184: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3185: my $user_lh = Apache::localize->get_handle(@languages);
3186: return $user_lh;
3187: }
3188:
3189:
3190: ###############################################################
3191: ## Student Answer Attempts ##
3192: ###############################################################
3193:
3194: =pod
3195:
3196: =head1 Alternate Problem Views
3197:
3198: =over 4
3199:
3200: =item * &get_previous_attempt($symb, $username, $domain, $course,
3201: $getattempt, $regexp, $gradesub)
3202:
3203: Return string with previous attempt on problem. Arguments:
3204:
3205: =over 4
3206:
3207: =item * $symb: Problem, including path
3208:
3209: =item * $username: username of the desired student
3210:
3211: =item * $domain: domain of the desired student
3212:
3213: =item * $course: Course ID
3214:
3215: =item * $getattempt: Leave blank for all attempts, otherwise put
3216: something
3217:
3218: =item * $regexp: if string matches this regexp, the string will be
3219: sent to $gradesub
3220:
3221: =item * $gradesub: routine that processes the string if it matches $regexp
3222:
3223: =back
3224:
3225: The output string is a table containing all desired attempts, if any.
3226:
3227: =cut
3228:
3229: sub get_previous_attempt {
3230: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
3231: my $prevattempts='';
3232: no strict 'refs';
3233: if ($symb) {
3234: my (%returnhash)=
3235: &Apache::lonnet::restore($symb,$course,$domain,$username);
3236: if ($returnhash{'version'}) {
3237: my %lasthash=();
3238: my $version;
3239: for ($version=1;$version<=$returnhash{'version'};$version++) {
3240: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3241: $lasthash{$key}=$returnhash{$version.':'.$key};
3242: }
3243: }
3244: $prevattempts=&start_data_table().&start_data_table_header_row();
3245: $prevattempts.='<th>'.&mt('History').'</th>';
3246: foreach my $key (sort(keys(%lasthash))) {
3247: my ($ign,@parts) = split(/\./,$key);
3248: if ($#parts > 0) {
3249: my $data=$parts[-1];
3250: pop(@parts);
3251: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
3252: } else {
3253: if ($#parts == 0) {
3254: $prevattempts.='<th>'.$parts[0].'</th>';
3255: } else {
3256: $prevattempts.='<th>'.$ign.'</th>';
3257: }
3258: }
3259: }
3260: $prevattempts.=&end_data_table_header_row();
3261: if ($getattempt eq '') {
3262: for ($version=1;$version<=$returnhash{'version'};$version++) {
3263: $prevattempts.=&start_data_table_row().
3264: '<td>'.&mt('Transaction [_1]',$version).'</td>';
3265: foreach my $key (sort(keys(%lasthash))) {
3266: my $value = &format_previous_attempt_value($key,
3267: $returnhash{$version.':'.$key});
3268: $prevattempts.='<td>'.$value.' </td>';
3269: }
3270: $prevattempts.=&end_data_table_row();
3271: }
3272: }
3273: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
3274: foreach my $key (sort(keys(%lasthash))) {
3275: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3276: if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
3277: $prevattempts.='<td>'.$value.' </td>';
3278: }
3279: $prevattempts.= &end_data_table_row().&end_data_table();
3280: } else {
3281: $prevattempts=
3282: &start_data_table().&start_data_table_row().
3283: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3284: &end_data_table_row().&end_data_table();
3285: }
3286: } else {
3287: $prevattempts=
3288: &start_data_table().&start_data_table_row().
3289: '<td>'.&mt('No data.').'</td>'.
3290: &end_data_table_row().&end_data_table();
3291: }
3292: }
3293:
3294: sub format_previous_attempt_value {
3295: my ($key,$value) = @_;
3296: if ($key =~ /timestamp/) {
3297: $value = &Apache::lonlocal::locallocaltime($value);
3298: } elsif (ref($value) eq 'ARRAY') {
3299: $value = '('.join(', ', @{ $value }).')';
3300: } else {
3301: $value = &unescape($value);
3302: }
3303: return $value;
3304: }
3305:
3306:
3307: sub relative_to_absolute {
3308: my ($url,$output)=@_;
3309: my $parser=HTML::TokeParser->new(\$output);
3310: my $token;
3311: my $thisdir=$url;
3312: my @rlinks=();
3313: while ($token=$parser->get_token) {
3314: if ($token->[0] eq 'S') {
3315: if ($token->[1] eq 'a') {
3316: if ($token->[2]->{'href'}) {
3317: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3318: }
3319: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3320: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3321: } elsif ($token->[1] eq 'base') {
3322: $thisdir=$token->[2]->{'href'};
3323: }
3324: }
3325: }
3326: $thisdir=~s-/[^/]*$--;
3327: foreach my $link (@rlinks) {
3328: unless (($link=~/^https?\:\/\//i) ||
3329: ($link=~/^\//) ||
3330: ($link=~/^javascript:/i) ||
3331: ($link=~/^mailto:/i) ||
3332: ($link=~/^\#/)) {
3333: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3334: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
3335: }
3336: }
3337: # -------------------------------------------------- Deal with Applet codebases
3338: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3339: return $output;
3340: }
3341:
3342: =pod
3343:
3344: =item * &get_student_view()
3345:
3346: show a snapshot of what student was looking at
3347:
3348: =cut
3349:
3350: sub get_student_view {
3351: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
3352: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
3353: my (%form);
3354: my @elements=('symb','courseid','domain','username');
3355: foreach my $element (@elements) {
3356: $form{'grade_'.$element}=eval '$'.$element #'
3357: }
3358: if (defined($moreenv)) {
3359: %form=(%form,%{$moreenv});
3360: }
3361: if (defined($target)) { $form{'grade_target'} = $target; }
3362: $feedurl=&Apache::lonnet::clutter($feedurl);
3363: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
3364: $userview=~s/\<body[^\>]*\>//gi;
3365: $userview=~s/\<\/body\>//gi;
3366: $userview=~s/\<html\>//gi;
3367: $userview=~s/\<\/html\>//gi;
3368: $userview=~s/\<head\>//gi;
3369: $userview=~s/\<\/head\>//gi;
3370: $userview=~s/action\s*\=/would_be_action\=/gi;
3371: $userview=&relative_to_absolute($feedurl,$userview);
3372: if (wantarray) {
3373: return ($userview,$response);
3374: } else {
3375: return $userview;
3376: }
3377: }
3378:
3379: sub get_student_view_with_retries {
3380: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3381:
3382: my $ok = 0; # True if we got a good response.
3383: my $content;
3384: my $response;
3385:
3386: # Try to get the student_view done. within the retries count:
3387:
3388: do {
3389: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3390: $ok = $response->is_success;
3391: if (!$ok) {
3392: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3393: }
3394: $retries--;
3395: } while (!$ok && ($retries > 0));
3396:
3397: if (!$ok) {
3398: $content = ''; # On error return an empty content.
3399: }
3400: if (wantarray) {
3401: return ($content, $response);
3402: } else {
3403: return $content;
3404: }
3405: }
3406:
3407: =pod
3408:
3409: =item * &get_student_answers()
3410:
3411: show a snapshot of how student was answering problem
3412:
3413: =cut
3414:
3415: sub get_student_answers {
3416: my ($symb,$username,$domain,$courseid,%form) = @_;
3417: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
3418: my (%moreenv);
3419: my @elements=('symb','courseid','domain','username');
3420: foreach my $element (@elements) {
3421: $moreenv{'grade_'.$element}=eval '$'.$element #'
3422: }
3423: $moreenv{'grade_target'}='answer';
3424: %moreenv=(%form,%moreenv);
3425: $feedurl = &Apache::lonnet::clutter($feedurl);
3426: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
3427: return $userview;
3428: }
3429:
3430: =pod
3431:
3432: =item * &submlink()
3433:
3434: Inputs: $text $uname $udom $symb $target
3435:
3436: Returns: A link to grades.pm such as to see the SUBM view of a student
3437:
3438: =cut
3439:
3440: ###############################################
3441: sub submlink {
3442: my ($text,$uname,$udom,$symb,$target)=@_;
3443: if (!($uname && $udom)) {
3444: (my $cursymb, my $courseid,$udom,$uname)=
3445: &Apache::lonnet::whichuser($symb);
3446: if (!$symb) { $symb=$cursymb; }
3447: }
3448: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
3449: $symb=&escape($symb);
3450: if ($target) { $target="target=\"$target\""; }
3451: return '<a href="/adm/grades?&command=submission&'.
3452: 'symb='.$symb.'&student='.$uname.
3453: '&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
3454: }
3455: ##############################################
3456:
3457: =pod
3458:
3459: =item * &pgrdlink()
3460:
3461: Inputs: $text $uname $udom $symb $target
3462:
3463: Returns: A link to grades.pm such as to see the PGRD view of a student
3464:
3465: =cut
3466:
3467: ###############################################
3468: sub pgrdlink {
3469: my $link=&submlink(@_);
3470: $link=~s/(&command=submission)/$1&showgrading=yes/;
3471: return $link;
3472: }
3473: ##############################################
3474:
3475: =pod
3476:
3477: =item * &pprmlink()
3478:
3479: Inputs: $text $uname $udom $symb $target
3480:
3481: Returns: A link to parmset.pm such as to see the PPRM view of a
3482: student and a specific resource
3483:
3484: =cut
3485:
3486: ###############################################
3487: sub pprmlink {
3488: my ($text,$uname,$udom,$symb,$target)=@_;
3489: if (!($uname && $udom)) {
3490: (my $cursymb, my $courseid,$udom,$uname)=
3491: &Apache::lonnet::whichuser($symb);
3492: if (!$symb) { $symb=$cursymb; }
3493: }
3494: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
3495: $symb=&escape($symb);
3496: if ($target) { $target="target=\"$target\""; }
3497: return '<a href="/adm/parmset?command=set&'.
3498: 'symb='.$symb.'&uname='.$uname.
3499: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
3500: }
3501: ##############################################
3502:
3503: =pod
3504:
3505: =back
3506:
3507: =cut
3508:
3509: ###############################################
3510:
3511:
3512: sub timehash {
3513: my ($thistime) = @_;
3514: my $timezone = &Apache::lonlocal::gettimezone();
3515: my $dt = DateTime->from_epoch(epoch => $thistime)
3516: ->set_time_zone($timezone);
3517: my $wday = $dt->day_of_week();
3518: if ($wday == 7) { $wday = 0; }
3519: return ( 'second' => $dt->second(),
3520: 'minute' => $dt->minute(),
3521: 'hour' => $dt->hour(),
3522: 'day' => $dt->day_of_month(),
3523: 'month' => $dt->month(),
3524: 'year' => $dt->year(),
3525: 'weekday' => $wday,
3526: 'dayyear' => $dt->day_of_year(),
3527: 'dlsav' => $dt->is_dst() );
3528: }
3529:
3530: sub utc_string {
3531: my ($date)=@_;
3532: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
3533: }
3534:
3535: sub maketime {
3536: my %th=@_;
3537: my ($epoch_time,$timezone,$dt);
3538: $timezone = &Apache::lonlocal::gettimezone();
3539: eval {
3540: $dt = DateTime->new( year => $th{'year'},
3541: month => $th{'month'},
3542: day => $th{'day'},
3543: hour => $th{'hour'},
3544: minute => $th{'minute'},
3545: second => $th{'second'},
3546: time_zone => $timezone,
3547: );
3548: };
3549: if (!$@) {
3550: $epoch_time = $dt->epoch;
3551: if ($epoch_time) {
3552: return $epoch_time;
3553: }
3554: }
3555: return POSIX::mktime(
3556: ($th{'seconds'},$th{'minutes'},$th{'hours'},
3557: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
3558: }
3559:
3560: #########################################
3561:
3562: sub findallcourses {
3563: my ($roles,$uname,$udom) = @_;
3564: my %roles;
3565: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
3566: my %courses;
3567: my $now=time;
3568: if (!defined($uname)) {
3569: $uname = $env{'user.name'};
3570: }
3571: if (!defined($udom)) {
3572: $udom = $env{'user.domain'};
3573: }
3574: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
3575: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
3576: if (!%roles) {
3577: %roles = (
3578: cc => 1,
3579: in => 1,
3580: ep => 1,
3581: ta => 1,
3582: cr => 1,
3583: st => 1,
3584: );
3585: }
3586: foreach my $entry (keys(%roleshash)) {
3587: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
3588: if ($trole =~ /^cr/) {
3589: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
3590: } else {
3591: next if (!exists($roles{$trole}));
3592: }
3593: if ($tend) {
3594: next if ($tend < $now);
3595: }
3596: if ($tstart) {
3597: next if ($tstart > $now);
3598: }
3599: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
3600: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
3601: if ($secpart eq '') {
3602: ($cnum,$role) = split(/_/,$cnumpart);
3603: $sec = 'none';
3604: $realsec = '';
3605: } else {
3606: $cnum = $cnumpart;
3607: ($sec,$role) = split(/_/,$secpart);
3608: $realsec = $sec;
3609: }
3610: $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
3611: }
3612: } else {
3613: foreach my $key (keys(%env)) {
3614: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
3615: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
3616: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
3617: next if ($role eq 'ca' || $role eq 'aa');
3618: next if (%roles && !exists($roles{$role}));
3619: my ($starttime,$endtime)=split(/\./,$env{$key});
3620: my $active=1;
3621: if ($starttime) {
3622: if ($now<$starttime) { $active=0; }
3623: }
3624: if ($endtime) {
3625: if ($now>$endtime) { $active=0; }
3626: }
3627: if ($active) {
3628: if ($sec eq '') {
3629: $sec = 'none';
3630: }
3631: $courses{$cdom.'_'.$cnum}{$sec} =
3632: $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
3633: }
3634: }
3635: }
3636: }
3637: return %courses;
3638: }
3639:
3640: ###############################################
3641:
3642: sub blockcheck {
3643: my ($setters,$activity,$uname,$udom) = @_;
3644:
3645: if (!defined($udom)) {
3646: $udom = $env{'user.domain'};
3647: }
3648: if (!defined($uname)) {
3649: $uname = $env{'user.name'};
3650: }
3651:
3652: # If uname and udom are for a course, check for blocks in the course.
3653:
3654: if (&Apache::lonnet::is_course($udom,$uname)) {
3655: my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
3656: my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
3657: return ($startblock,$endblock);
3658: }
3659:
3660: my $startblock = 0;
3661: my $endblock = 0;
3662: my %live_courses = &findallcourses(undef,$uname,$udom);
3663:
3664: # If uname is for a user, and activity is course-specific, i.e.,
3665: # boards, chat or groups, check for blocking in current course only.
3666:
3667: if (($activity eq 'boards' || $activity eq 'chat' ||
3668: $activity eq 'groups') && ($env{'request.course.id'})) {
3669: foreach my $key (keys(%live_courses)) {
3670: if ($key ne $env{'request.course.id'}) {
3671: delete($live_courses{$key});
3672: }
3673: }
3674: }
3675:
3676: my $otheruser = 0;
3677: my %own_courses;
3678: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
3679: # Resource belongs to user other than current user.
3680: $otheruser = 1;
3681: # Gather courses for current user
3682: %own_courses =
3683: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
3684: }
3685:
3686: # Gather active course roles - course coordinator, instructor,
3687: # exam proctor, ta, student, or custom role.
3688:
3689: foreach my $course (keys(%live_courses)) {
3690: my ($cdom,$cnum);
3691: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
3692: $cdom = $env{'course.'.$course.'.domain'};
3693: $cnum = $env{'course.'.$course.'.num'};
3694: } else {
3695: ($cdom,$cnum) = split(/_/,$course);
3696: }
3697: my $no_ownblock = 0;
3698: my $no_userblock = 0;
3699: if ($otheruser && $activity ne 'com') {
3700: # Check if current user has 'evb' priv for this
3701: if (defined($own_courses{$course})) {
3702: foreach my $sec (keys(%{$own_courses{$course}})) {
3703: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
3704: if ($sec ne 'none') {
3705: $checkrole .= '/'.$sec;
3706: }
3707: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3708: $no_ownblock = 1;
3709: last;
3710: }
3711: }
3712: }
3713: # if they have 'evb' priv and are currently not playing student
3714: next if (($no_ownblock) &&
3715: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
3716: }
3717: foreach my $sec (keys(%{$live_courses{$course}})) {
3718: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
3719: if ($sec ne 'none') {
3720: $checkrole .= '/'.$sec;
3721: }
3722: if ($otheruser) {
3723: # Resource belongs to user other than current user.
3724: # Assemble privs for that user, and check for 'evb' priv.
3725: my ($trole,$tdom,$tnum,$tsec);
3726: my $entry = $live_courses{$course}{$sec};
3727: if ($entry =~ /^cr/) {
3728: ($trole,$tdom,$tnum,$tsec) =
3729: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
3730: } else {
3731: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
3732: }
3733: my ($spec,$area,$trest,%allroles,%userroles);
3734: $area = '/'.$tdom.'/'.$tnum;
3735: $trest = $tnum;
3736: if ($tsec ne '') {
3737: $area .= '/'.$tsec;
3738: $trest .= '/'.$tsec;
3739: }
3740: $spec = $trole.'.'.$area;
3741: if ($trole =~ /^cr/) {
3742: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
3743: $tdom,$spec,$trest,$area);
3744: } else {
3745: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
3746: $tdom,$spec,$trest,$area);
3747: }
3748: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
3749: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
3750: if ($1) {
3751: $no_userblock = 1;
3752: last;
3753: }
3754: }
3755: } else {
3756: # Resource belongs to current user
3757: # Check for 'evb' priv via lonnet::allowed().
3758: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3759: $no_ownblock = 1;
3760: last;
3761: }
3762: }
3763: }
3764: # if they have the evb priv and are currently not playing student
3765: next if (($no_ownblock) &&
3766: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
3767: next if ($no_userblock);
3768:
3769: # Retrieve blocking times and identity of blocker for course
3770: # of specified user, unless user has 'evb' privilege.
3771:
3772: my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
3773: if (($start != 0) &&
3774: (($startblock == 0) || ($startblock > $start))) {
3775: $startblock = $start;
3776: }
3777: if (($end != 0) &&
3778: (($endblock == 0) || ($endblock < $end))) {
3779: $endblock = $end;
3780: }
3781: }
3782: return ($startblock,$endblock);
3783: }
3784:
3785: sub get_blocks {
3786: my ($setters,$activity,$cdom,$cnum) = @_;
3787: my $startblock = 0;
3788: my $endblock = 0;
3789: my $course = $cdom.'_'.$cnum;
3790: $setters->{$course} = {};
3791: $setters->{$course}{'staff'} = [];
3792: $setters->{$course}{'times'} = [];
3793: my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
3794: foreach my $record (keys(%records)) {
3795: my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
3796: if ($start <= time && $end >= time) {
3797: my ($staff_name,$staff_dom,$title,$blocks) =
3798: &parse_block_record($records{$record});
3799: if ($blocks->{$activity} eq 'on') {
3800: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
3801: push(@{$$setters{$course}{'times'}}, [$start,$end]);
3802: if ( ($startblock == 0) || ($startblock > $start) ) {
3803: $startblock = $start;
3804: }
3805: if ( ($endblock == 0) || ($endblock < $end) ) {
3806: $endblock = $end;
3807: }
3808: }
3809: }
3810: }
3811: return ($startblock,$endblock);
3812: }
3813:
3814: sub parse_block_record {
3815: my ($record) = @_;
3816: my ($setuname,$setudom,$title,$blocks);
3817: if (ref($record) eq 'HASH') {
3818: ($setuname,$setudom) = split(/:/,$record->{'setter'});
3819: $title = &unescape($record->{'event'});
3820: $blocks = $record->{'blocks'};
3821: } else {
3822: my @data = split(/:/,$record,3);
3823: if (scalar(@data) eq 2) {
3824: $title = $data[1];
3825: ($setuname,$setudom) = split(/@/,$data[0]);
3826: } else {
3827: ($setuname,$setudom,$title) = @data;
3828: }
3829: $blocks = { 'com' => 'on' };
3830: }
3831: return ($setuname,$setudom,$title,$blocks);
3832: }
3833:
3834: sub build_block_table {
3835: my ($startblock,$endblock,$setters) = @_;
3836: my %lt = &Apache::lonlocal::texthash(
3837: 'cacb' => 'Currently active communication blocks',
3838: 'cour' => 'Course',
3839: 'dura' => 'Duration',
3840: 'blse' => 'Block set by'
3841: );
3842: my $output;
3843: $output = '<br />'.$lt{'cacb'}.':<br />';
3844: $output .= &start_data_table();
3845: $output .= '
3846: <tr>
3847: <th>'.$lt{'cour'}.'</th>
3848: <th>'.$lt{'dura'}.'</th>
3849: <th>'.$lt{'blse'}.'</th>
3850: </tr>
3851: ';
3852: foreach my $course (keys(%{$setters})) {
3853: my %courseinfo=&Apache::lonnet::coursedescription($course);
3854: for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) {
3855: my ($uname,$udom) = @{$$setters{$course}{staff}[$i]};
3856: my $fullname = &plainname($uname,$udom);
3857: if (defined($env{'user.name'}) && defined($env{'user.domain'})
3858: && $env{'user.name'} ne 'public'
3859: && $env{'user.domain'} ne 'public') {
3860: $fullname = &aboutmewrapper($fullname,$uname,$udom);
3861: }
3862: my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]};
3863: $openblock = &Apache::lonlocal::locallocaltime($openblock);
3864: $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
3865: $output .= &Apache::loncommon::start_data_table_row().
3866: '<td>'.$courseinfo{'description'}.'</td>'.
3867: '<td>'.$openblock.' to '.$closeblock.'</td>'.
3868: '<td>'.$fullname.'</td>'.
3869: &Apache::loncommon::end_data_table_row();
3870: }
3871: }
3872: $output .= &end_data_table();
3873: }
3874: sub blocking_status {
3875: my $blocked = blocking_status_print(@_);
3876: my ($activity,$uname,$udom) = @_;
3877: if(!wantarray) {
3878: return $blocked;
3879: }
3880: my $output;
3881: my $querystring;
3882: $querystring = "?activity=$activity";
3883: if(defined($uname)) {
3884: $querystring .= "&uname=$uname";
3885: }if(defined($udom)) {
3886: $querystring .= "&udom=$udom";
3887: }
3888:
3889: $output .= <<"END_MYBLOCK";
3890: <script type="text/javascript">
3891: // <![CDATA[
3892: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
3893: var options = "width=" + w + ",height=" + h + ",";
3894: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
3895: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
3896: var newWin = window.open(url, wdwName, options);
3897: newWin.focus();
3898: }
3899:
3900: // ]]>
3901: </script>
3902: END_MYBLOCK
3903: my $popupUrl = "/adm/blockingstatus/$querystring";
3904: $output.="\n<img src='/res/adm/pages/emblem-readonly.png' /><a onclick='openWindow(\"$popupUrl\",\"Blocking Table\",600,300,\"no\",\"no\");return false;' href='/adm/blockingstatus/$querystring'>Blocking Table</a>";
3905:
3906: return ($blocked, $output);
3907: }
3908: sub blocking_status_print {
3909: my ($activity,$uname,$udom) = @_;
3910: my %setters;
3911: my ($blocked,$output,$ownitem,$is_course);
3912: my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
3913: if ($startblock && $endblock) {
3914: $blocked = 1;
3915: if (wantarray) {
3916: my $category;
3917: if ($activity eq 'boards') {
3918: $category = 'Discussion posts in this course';
3919: } elsif ($activity eq 'blogs') {
3920: $category = 'Blogs';
3921: } elsif ($activity eq 'port') {
3922: if (defined($uname) && defined($udom)) {
3923: if ($uname eq $env{'user.name'} &&
3924: $udom eq $env{'user.domain'}) {
3925: $ownitem = 1;
3926: }
3927: }
3928: $is_course = &Apache::lonnet::is_course($udom,$uname);
3929: if ($ownitem) {
3930: $category = 'Your portfolio files';
3931: } elsif ($is_course) {
3932: my $coursedesc;
3933: foreach my $course (keys(%setters)) {
3934: my %courseinfo =
3935: &Apache::lonnet::coursedescription($course);
3936: $coursedesc = $courseinfo{'description'};
3937: }
3938: $category = "Group portfolio in the course '$coursedesc'";
3939: } else {
3940: $category = 'Portfolio files belonging to ';
3941: if ($env{'user.name'} eq 'public' &&
3942: $env{'user.domain'} eq 'public') {
3943: $category .= &plainname($uname,$udom);
3944: } else {
3945: $category .= &aboutmewrapper(&plainname($uname,$udom),$uname,$udom);
3946: }
3947: }
3948: } elsif ($activity eq 'groups') {
3949: $category = 'Groups in this course';
3950: }
3951: my $showstart = &Apache::lonlocal::locallocaltime($startblock);
3952: my $showend = &Apache::lonlocal::locallocaltime($endblock);
3953: $output = '<br />'.&mt('[_1] will be inaccessible between [_2] and [_3] because communication is being blocked.',$category,$showstart,$showend).'<br />';
3954: if (!($activity eq 'port' && !($ownitem) && !($is_course))) {
3955: $output .= &build_block_table($startblock,$endblock,\%setters);
3956: }
3957: }
3958: }
3959: if (wantarray) {
3960: return ($blocked,$output);
3961: } else {
3962: return $blocked;
3963: }
3964: }
3965:
3966: ###############################################
3967:
3968: sub check_ip_acc {
3969: my ($acc)=@_;
3970: &Apache::lonxml::debug("acc is $acc");
3971: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
3972: return 1;
3973: }
3974: my $allowed=0;
3975: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
3976:
3977: my $name;
3978: foreach my $pattern (split(',',$acc)) {
3979: $pattern =~ s/^\s*//;
3980: $pattern =~ s/\s*$//;
3981: if ($pattern =~ /\*$/) {
3982: #35.8.*
3983: $pattern=~s/\*//;
3984: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
3985: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
3986: #35.8.3.[34-56]
3987: my $low=$2;
3988: my $high=$3;
3989: $pattern=$1;
3990: if ($ip =~ /^\Q$pattern\E/) {
3991: my $last=(split(/\./,$ip))[3];
3992: if ($last <=$high && $last >=$low) { $allowed=1; }
3993: }
3994: } elsif ($pattern =~ /^\*/) {
3995: #*.msu.edu
3996: $pattern=~s/\*//;
3997: if (!defined($name)) {
3998: use Socket;
3999: my $netaddr=inet_aton($ip);
4000: ($name)=gethostbyaddr($netaddr,AF_INET);
4001: }
4002: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4003: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
4004: #127.0.0.1
4005: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4006: } else {
4007: #some.name.com
4008: if (!defined($name)) {
4009: use Socket;
4010: my $netaddr=inet_aton($ip);
4011: ($name)=gethostbyaddr($netaddr,AF_INET);
4012: }
4013: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4014: }
4015: if ($allowed) { last; }
4016: }
4017: return $allowed;
4018: }
4019:
4020: ###############################################
4021:
4022: =pod
4023:
4024: =head1 Domain Template Functions
4025:
4026: =over 4
4027:
4028: =item * &determinedomain()
4029:
4030: Inputs: $domain (usually will be undef)
4031:
4032: Returns: Determines which domain should be used for designs
4033:
4034: =cut
4035:
4036: ###############################################
4037: sub determinedomain {
4038: my $domain=shift;
4039: if (! $domain) {
4040: # Determine domain if we have not been given one
4041: $domain = $Apache::lonnet::perlvar{'lonDefDomain'};
4042: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
4043: if ($env{'request.role.domain'}) {
4044: $domain=$env{'request.role.domain'};
4045: }
4046: }
4047: return $domain;
4048: }
4049: ###############################################
4050:
4051: sub devalidate_domconfig_cache {
4052: my ($udom)=@_;
4053: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
4054: }
4055:
4056: # ---------------------- Get domain configuration for a domain
4057: sub get_domainconf {
4058: my ($udom) = @_;
4059: my $cachetime=1800;
4060: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
4061: if (defined($cached)) { return %{$result}; }
4062:
4063: my %domconfig = &Apache::lonnet::get_dom('configuration',
4064: ['login','rolecolors'],$udom);
4065: my (%designhash,%legacy);
4066: if (keys(%domconfig) > 0) {
4067: if (ref($domconfig{'login'}) eq 'HASH') {
4068: if (keys(%{$domconfig{'login'}})) {
4069: foreach my $key (keys(%{$domconfig{'login'}})) {
4070: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
4071: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4072: $designhash{$udom.'.login.'.$key.'_'.$img} =
4073: $domconfig{'login'}{$key}{$img};
4074: }
4075: } else {
4076: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4077: }
4078: }
4079: } else {
4080: $legacy{'login'} = 1;
4081: }
4082: } else {
4083: $legacy{'login'} = 1;
4084: }
4085: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
4086: if (keys(%{$domconfig{'rolecolors'}})) {
4087: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4088: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4089: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4090: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4091: }
4092: }
4093: }
4094: } else {
4095: $legacy{'rolecolors'} = 1;
4096: }
4097: } else {
4098: $legacy{'rolecolors'} = 1;
4099: }
4100: if (keys(%legacy) > 0) {
4101: my %legacyhash = &get_legacy_domconf($udom);
4102: foreach my $item (keys(%legacyhash)) {
4103: if ($item =~ /^\Q$udom\E\.login/) {
4104: if ($legacy{'login'}) {
4105: $designhash{$item} = $legacyhash{$item};
4106: }
4107: } else {
4108: if ($legacy{'rolecolors'}) {
4109: $designhash{$item} = $legacyhash{$item};
4110: }
4111: }
4112: }
4113: }
4114: } else {
4115: %designhash = &get_legacy_domconf($udom);
4116: }
4117: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4118: $cachetime);
4119: return %designhash;
4120: }
4121:
4122: sub get_legacy_domconf {
4123: my ($udom) = @_;
4124: my %legacyhash;
4125: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4126: my $designfile = $designdir.'/'.$udom.'.tab';
4127: if (-e $designfile) {
4128: if ( open (my $fh,"<$designfile") ) {
4129: while (my $line = <$fh>) {
4130: next if ($line =~ /^\#/);
4131: chomp($line);
4132: my ($key,$val)=(split(/\=/,$line));
4133: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4134: }
4135: close($fh);
4136: }
4137: }
4138: if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
4139: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4140: }
4141: return %legacyhash;
4142: }
4143:
4144: =pod
4145:
4146: =item * &domainlogo()
4147:
4148: Inputs: $domain (usually will be undef)
4149:
4150: Returns: A link to a domain logo, if the domain logo exists.
4151: If the domain logo does not exist, a description of the domain.
4152:
4153: =cut
4154:
4155: ###############################################
4156: sub domainlogo {
4157: my $domain = &determinedomain(shift);
4158: my %designhash = &get_domainconf($domain);
4159: # See if there is a logo
4160: if ($designhash{$domain.'.login.domlogo'} ne '') {
4161: my $imgsrc = $designhash{$domain.'.login.domlogo'};
4162: if ($imgsrc =~ m{^/(adm|res)/}) {
4163: if ($imgsrc =~ m{^/res/}) {
4164: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4165: &Apache::lonnet::repcopy($local_name);
4166: }
4167: $imgsrc = &lonhttpdurl($imgsrc);
4168: }
4169: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
4170: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4171: return &Apache::lonnet::domain($domain,'description');
4172: } else {
4173: return '';
4174: }
4175: }
4176: ##############################################
4177:
4178: =pod
4179:
4180: =item * &designparm()
4181:
4182: Inputs: $which parameter; $domain (usually will be undef)
4183:
4184: Returns: value of designparamter $which
4185:
4186: =cut
4187:
4188:
4189: ##############################################
4190: sub designparm {
4191: my ($which,$domain)=@_;
4192: if (exists($env{'environment.color.'.$which})) {
4193: return $env{'environment.color.'.$which};
4194: }
4195: $domain=&determinedomain($domain);
4196: my %domdesign = &get_domainconf($domain);
4197: my $output;
4198: if ($domdesign{$domain.'.'.$which} ne '') {
4199: $output = $domdesign{$domain.'.'.$which};
4200: } else {
4201: $output = $defaultdesign{$which};
4202: }
4203: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
4204: ($which =~ /login\.(img|logo|domlogo|login)/)) {
4205: if ($output =~ m{^/(adm|res)/}) {
4206: if ($output =~ m{^/res/}) {
4207: my $local_name = &Apache::lonnet::filelocation('',$output);
4208: &Apache::lonnet::repcopy($local_name);
4209: }
4210: $output = &lonhttpdurl($output);
4211: }
4212: }
4213: return $output;
4214: }
4215:
4216: ##############################################
4217: =pod
4218:
4219: =item * &authorspace()
4220:
4221: Inputs: ./.
4222:
4223: Returns: Path to the Construction Space of the current user's
4224: accessed author space
4225: The author space will be that of the current user
4226: when accessing the own author space
4227: and that of the co-author/assistent co-author
4228: when accessing the co-author's/assistent co-author's
4229: space
4230:
4231: =cut
4232:
4233: sub authorspace {
4234: my $caname = '';
4235: if ($env{'request.role'} =~ /^ca|^aa/) {
4236: (undef,$caname) =
4237: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
4238: } else {
4239: $caname = $env{'user.name'};
4240: }
4241: return '/priv/'.$caname.'/';
4242: }
4243:
4244: ##############################################
4245: =pod
4246:
4247: =item * &head_subbox()
4248:
4249: Inputs: $content (contains HTML code with page functions, etc.)
4250:
4251: Returns: HTML div with $content
4252: To be included in page header
4253:
4254: =cut
4255:
4256: sub head_subbox {
4257: my ($content)=@_;
4258: my $output =
4259: '<div id="LC_head_subbox">'
4260: .$content
4261: .'</div>'
4262: }
4263:
4264: ##############################################
4265: =pod
4266:
4267: =item * &CSTR_pageheader()
4268:
4269: Inputs: ./.
4270:
4271: Returns: HTML div with CSTR path and recent box
4272: To be included on Construction Space pages
4273:
4274: =cut
4275:
4276: sub CSTR_pageheader {
4277: # this is for resources; directories have customtitle, and crumbs
4278: # and select recent are created in lonpubdir.pm
4279: my ($uname,$thisdisfn)=
4280: ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
4281: my $formaction='/priv/'.$uname.'/'.$thisdisfn;
4282: $formaction=~s/\/+/\//g;
4283:
4284: my $parentpath = '';
4285: my $lastitem = '';
4286: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4287: $parentpath = $1;
4288: $lastitem = $2;
4289: } else {
4290: $lastitem = $thisdisfn;
4291: }
4292: return
4293: '<div>'
4294: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
4295: .'<b>'.&mt('Construction Space:').'</b> '
4296: .'<form name="dirs" method="post" action="'.$formaction
4297: .'" target="_top"><tt><b>' #FIXME lonpubdir: target="_parent"
4298: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."$lastitem</b></tt><br />"
4299: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
4300: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4301: .'</form>'
4302: .&Apache::lonmenu::constspaceform()
4303: .'</div>';
4304: }
4305:
4306: ###############################################
4307: ###############################################
4308:
4309: =pod
4310:
4311: =back
4312:
4313: =head1 HTML Helpers
4314:
4315: =over 4
4316:
4317: =item * &bodytag()
4318:
4319: Returns a uniform header for LON-CAPA web pages.
4320:
4321: Inputs:
4322:
4323: =over 4
4324:
4325: =item * $title, A title to be displayed on the page.
4326:
4327: =item * $function, the current role (can be undef).
4328:
4329: =item * $addentries, extra parameters for the <body> tag.
4330:
4331: =item * $bodyonly, if defined, only return the <body> tag.
4332:
4333: =item * $domain, if defined, force a given domain.
4334:
4335: =item * $forcereg, if page should register as content page (relevant for
4336: text interface only)
4337:
4338: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
4339: navigational links
4340:
4341: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
4342:
4343: =item * $no_inline_link, if true and in remote mode, don't show the
4344: 'Switch To Inline Menu' link
4345:
4346: =item * $args, optional argument valid values are
4347: no_auto_mt_title -> prevents &mt()ing the title arg
4348: inherit_jsmath -> when creating popup window in a page,
4349: should it have jsmath forced on by the
4350: current page
4351:
4352: =back
4353:
4354: Returns: A uniform header for LON-CAPA web pages.
4355: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
4356: If $bodyonly is undef or zero, an html string containing a <body> tag and
4357: other decorations will be returned.
4358:
4359: =cut
4360:
4361: sub bodytag {
4362: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
4363: $no_nav_bar,$bgcolor,$no_inline_link,$args)=@_;
4364:
4365: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
4366:
4367: $function = &get_users_function() if (!$function);
4368: my $img = &designparm($function.'.img',$domain);
4369: my $font = &designparm($function.'.font',$domain);
4370: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
4371:
4372: my %design = ( 'style' => 'margin-top: 0',
4373: 'bgcolor' => $pgbg,
4374: 'text' => $font,
4375: 'alink' => &designparm($function.'.alink',$domain),
4376: 'vlink' => &designparm($function.'.vlink',$domain),
4377: 'link' => &designparm($function.'.link',$domain),);
4378: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
4379:
4380: # role and realm
4381: my ($role,$realm) = split(/\./,$env{'request.role'},2);
4382: if ($role eq 'ca') {
4383: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
4384: $realm = &plainname($rname,$rdom);
4385: }
4386: # realm
4387: if ($env{'request.course.id'}) {
4388: if ($env{'request.role'} !~ /^cr/) {
4389: $role = &Apache::lonnet::plaintext($role,&course_type());
4390: }
4391: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
4392: } else {
4393: $role = &Apache::lonnet::plaintext($role);
4394: }
4395:
4396: if (!$realm) { $realm=' '; }
4397: # Set messages
4398: my $messages=&domainlogo($domain);
4399:
4400: my $extra_body_attr = &make_attr_string($forcereg,\%design);
4401:
4402: # construct main body tag
4403: my $bodytag = "<body $extra_body_attr>".
4404: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
4405:
4406: if ($bodyonly) {
4407: return $bodytag;
4408: }
4409:
4410: my $name = &plainname($env{'user.name'},$env{'user.domain'});
4411: if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
4412: undef($role);
4413: } else {
4414: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
4415: }
4416:
4417: my $titleinfo = '<h1>'.$title.'</h1>';
4418: #
4419: # Extra info if you are the DC
4420: my $dc_info = '';
4421: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
4422: $env{'course.'.$env{'request.course.id'}.
4423: '.domain'}.'/'})) {
4424: my $cid = $env{'request.course.id'};
4425: $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
4426: $dc_info =~ s/\s+$//;
4427: $dc_info = '('.$dc_info.')';
4428: }
4429:
4430: $role = "($role)" if $role;
4431: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
4432:
4433: if ($env{'environment.remote'} eq 'off') {
4434: # No Remote
4435: if ($env{'request.state'} eq 'construct') {
4436: $forcereg=1;
4437: }
4438:
4439: # if ($env{'request.state'} eq 'construct') {
4440: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
4441: # }
4442:
4443: my $titletable = '<table id="LC_title_bar">'
4444: ."<tr><td> $titleinfo $dc_info</td>"
4445: .'</tr></table>';
4446:
4447: if ($no_nav_bar) {
4448: $bodytag .= $titletable;
4449: } else {
4450: $bodytag .= qq|<div id="LC_nav_bar">$name $role<br />
4451: <em>$realm</em> $dc_info</div>| unless $env{'form.inhibitmenu'};
4452:
4453: if ($env{'request.state'} eq 'construct') {
4454: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$titletable);
4455: } else {
4456: $bodytag .= &Apache::lonmenu::menubuttons($forcereg).$titletable;
4457: }
4458: }
4459: return $bodytag;
4460: }
4461:
4462: #
4463: # Top frame rendering, Remote is up
4464: #
4465:
4466: my $imgsrc = $img;
4467: if ($img =~ /^\/adm/) {
4468: $imgsrc = &lonhttpdurl($img);
4469: }
4470: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
4471:
4472: # Explicit link to get inline menu
4473: my $menu= ($no_inline_link?''
4474: :'<a href="/adm/remote?action=collapse">'.&mt('Switch to Inline Menu Mode').'</a>');
4475: $bodytag .= qq|<div id="LC_nav_bar">$name $role
4476: <em>$realm</em> $dc_info </div>
4477: <ol class="LC_smallMenu LC_right">
4478: <li>$menu</li>
4479: </ol>| unless $env{'form.inhibitmenu'};
4480: #
4481: return(<<ENDBODY);
4482: $bodytag
4483: <table id="LC_title_bar" class="LC_with_remote">
4484: <tr><td>$upperleft</td>
4485: <td>$messages </td>
4486: </tr>
4487: <tr><td>$titleinfo $dc_info $menu</td>
4488: </tr>
4489: </table>
4490: ENDBODY
4491: }
4492:
4493: sub make_attr_string {
4494: my ($register,$attr_ref) = @_;
4495:
4496: if ($attr_ref && !ref($attr_ref)) {
4497: die("addentries Must be a hash ref ".
4498: join(':',caller(1))." ".
4499: join(':',caller(0))." ");
4500: }
4501:
4502: if ($register) {
4503: my ($on_load,$on_unload);
4504: foreach my $key (keys(%{$attr_ref})) {
4505: if (lc($key) eq 'onload') {
4506: $on_load.=$attr_ref->{$key}.';';
4507: delete($attr_ref->{$key});
4508:
4509: } elsif (lc($key) eq 'onunload') {
4510: $on_unload.=$attr_ref->{$key}.';';
4511: delete($attr_ref->{$key});
4512: }
4513: }
4514: $attr_ref->{'onload'} =
4515: &Apache::lonmenu::loadevents(). $on_load;
4516: $attr_ref->{'onunload'}=
4517: &Apache::lonmenu::unloadevents().$on_unload;
4518: }
4519:
4520: # Accessibility font enhance
4521: if ($env{'browser.fontenhance'} eq 'on') {
4522: my $style;
4523: foreach my $key (keys(%{$attr_ref})) {
4524: if (lc($key) eq 'style') {
4525: $style.=$attr_ref->{$key}.';';
4526: delete($attr_ref->{$key});
4527: }
4528: }
4529: $attr_ref->{'style'}=$style.'; font-size: x-large;';
4530: }
4531:
4532: my $attr_string;
4533: foreach my $attr (keys(%$attr_ref)) {
4534: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
4535: }
4536: return $attr_string;
4537: }
4538:
4539:
4540: ###############################################
4541: ###############################################
4542:
4543: =pod
4544:
4545: =item * &endbodytag()
4546:
4547: Returns a uniform footer for LON-CAPA web pages.
4548:
4549: Inputs: 1 - optional reference to an args hash
4550: If in the hash, key for noredirectlink has a value which evaluates to true,
4551: a 'Continue' link is not displayed if the page contains an
4552: internal redirect in the <head></head> section,
4553: i.e., $env{'internal.head.redirect'} exists
4554:
4555: =cut
4556:
4557: sub endbodytag {
4558: my ($args) = @_;
4559: my $endbodytag='</body>';
4560: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
4561: if ( exists( $env{'internal.head.redirect'} ) ) {
4562: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
4563: $endbodytag=
4564: "<br /><a href=\"$env{'internal.head.redirect'}\">".
4565: &mt('Continue').'</a>'.
4566: $endbodytag;
4567: }
4568: }
4569: return $endbodytag;
4570: }
4571:
4572: =pod
4573:
4574: =item * &standard_css()
4575:
4576: Returns a style sheet
4577:
4578: Inputs: (all optional)
4579: domain -> force to color decorate a page for a specific
4580: domain
4581: function -> force usage of a specific rolish color scheme
4582: bgcolor -> override the default page bgcolor
4583:
4584: =cut
4585:
4586: sub standard_css {
4587: my ($function,$domain,$bgcolor) = @_;
4588: $function = &get_users_function() if (!$function);
4589: my $img = &designparm($function.'.img', $domain);
4590: my $tabbg = &designparm($function.'.tabbg', $domain);
4591: my $font = &designparm($function.'.font', $domain);
4592: my $fontmenu = &designparm($function.'.fontmenu', $domain);
4593: #second colour for later usage
4594: my $sidebg = &designparm($function.'.sidebg',$domain);
4595: my $pgbg_or_bgcolor =
4596: $bgcolor ||
4597: &designparm($function.'.pgbg', $domain);
4598: my $pgbg = &designparm($function.'.pgbg', $domain);
4599: my $alink = &designparm($function.'.alink', $domain);
4600: my $vlink = &designparm($function.'.vlink', $domain);
4601: my $link = &designparm($function.'.link', $domain);
4602:
4603: my $loginbg = &designparm('login.sidebg',$domain);
4604: my $bgcol = &designparm('login.bgcol',$domain);
4605: my $textcol = &designparm('login.textcol',$domain);
4606:
4607: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
4608: my $mono = 'monospace';
4609: my $data_table_head = $sidebg;
4610: my $data_table_light = '#FAFAFA';
4611: my $data_table_dark = '#F0F0F0';
4612: my $data_table_darker = '#CCCCCC';
4613: my $data_table_highlight = '#FFFF00';
4614: my $mail_new = '#FFBB77';
4615: my $mail_new_hover = '#DD9955';
4616: my $mail_read = '#BBBB77';
4617: my $mail_read_hover = '#999944';
4618: my $mail_replied = '#AAAA88';
4619: my $mail_replied_hover = '#888855';
4620: my $mail_other = '#99BBBB';
4621: my $mail_other_hover = '#669999';
4622: my $table_header = '#DDDDDD';
4623: my $feedback_link_bg = '#BBBBBB';
4624: my $lg_border_color = '#C8C8C8';
4625:
4626: my $border = ($env{'browser.type'} eq 'explorer' ||
4627: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
4628: : '0 3px 0 4px';
4629:
4630:
4631: return <<END;
4632: body {
4633: font-family: $sans;
4634: line-height:130%;
4635: font-size:0.83em;
4636: color:$font;
4637: }
4638:
4639: a:link, a:visited {
4640: font-size:100%;
4641: }
4642:
4643: a:focus {
4644: color: red;
4645: background: yellow
4646: }
4647:
4648: hr {
4649: clear: both;
4650: color: $tabbg;
4651: background-color: $tabbg;
4652: height: 3px;
4653: border: none;
4654: }
4655:
4656: form, .inline {
4657: display: inline;
4658: }
4659:
4660: .LC_right {
4661: text-align:right;
4662: }
4663:
4664: .LC_middle {
4665: vertical-align:middle;
4666: }
4667:
4668: /* just for tests */
4669: .LC_400Box {width:400px; }
4670: /* end */
4671:
4672: .LC_filename {
4673: font-family: $mono;
4674: white-space:pre;
4675: }
4676:
4677: .LC_fileicon {
4678: border: none;
4679: height: 1.3em;
4680: vertical-align: text-bottom;
4681: margin-right: 0.3em;
4682: text-decoration:none;
4683: }
4684:
4685: .LC_error {
4686: color: red;
4687: font-size: larger;
4688: }
4689:
4690: .LC_warning,
4691: .LC_diff_removed {
4692: color: red;
4693: }
4694:
4695: .LC_info,
4696: .LC_success,
4697: .LC_diff_added {
4698: color: green;
4699: }
4700:
4701: div.LC_confirm_box {
4702: background-color: #FAFAFA;
4703: border: 1px solid $lg_border_color;
4704: margin-right: 0;
4705: padding: 5px;
4706: }
4707:
4708: div.LC_confirm_box .LC_error img,
4709: div.LC_confirm_box .LC_success img {
4710: vertical-align: middle;
4711: }
4712:
4713: .LC_icon {
4714: border: none;
4715: vertical-align: middle;
4716: }
4717:
4718: .LC_docs_spacer {
4719: width: 25px;
4720: height: 1px;
4721: border: none;
4722: }
4723:
4724: .LC_internal_info {
4725: color: #999999;
4726: }
4727:
4728: .LC_discussion {
4729: background: $tabbg;
4730: border: 1px solid black;
4731: margin: 2px;
4732: }
4733:
4734: .LC_disc_action_links_bar {
4735: background: $tabbg;
4736: border: none;
4737: margin: 4px;
4738: }
4739:
4740: .LC_disc_action_left {
4741: text-align: left;
4742: }
4743:
4744: .LC_disc_action_right {
4745: text-align: right;
4746: }
4747:
4748: .LC_disc_new_item {
4749: background: white;
4750: border: 2px solid red;
4751: margin: 2px;
4752: }
4753:
4754: .LC_disc_old_item {
4755: background: white;
4756: border: 1px solid black;
4757: margin: 2px;
4758: }
4759:
4760: table.LC_pastsubmission {
4761: border: 1px solid black;
4762: margin: 2px;
4763: }
4764:
4765: table#LC_top_nav,
4766: table#LC_menubuttons,
4767: table#LC_nav_location {
4768: width: 100%;
4769: background: $pgbg;
4770: border: 2px;
4771: border-collapse: separate;
4772: padding: 0;
4773: }
4774:
4775: table#LC_title_bar a {
4776: color: $fontmenu;
4777: }
4778:
4779: table#LC_title_bar {
4780: clear: both;
4781: display: none;
4782: }
4783:
4784: table#LC_title_bar,
4785: table.LC_breadcrumbs,
4786: table#LC_title_bar.LC_with_remote {
4787: width: 100%;
4788: border-color: $pgbg;
4789: border-style: solid;
4790: border-width: $border;
4791: background: $pgbg;
4792: color: $fontmenu;
4793: border-collapse: collapse;
4794: padding: 0;
4795: margin: 0;
4796: }
4797:
4798: table#LC_title_bar td {
4799: background: $tabbg;
4800: }
4801:
4802: table#LC_menubuttons img{
4803: border: none;
4804: }
4805:
4806: table#LC_top_nav td {
4807: background: $tabbg;
4808: border: none;
4809: font-size: small;
4810: vertical-align:top;
4811: padding:2px 5px 2px 5px;
4812: }
4813:
4814: table#LC_top_nav td a,
4815: div#LC_top_nav a {
4816: color: $font;
4817: }
4818:
4819: table#LC_top_nav td.LC_top_nav_logo {
4820: background: $tabbg;
4821: text-align: left;
4822: white-space: nowrap;
4823: width: 31px;
4824: }
4825:
4826: table#LC_top_nav td.LC_top_nav_logo img {
4827: border: none;
4828: vertical-align: bottom;
4829: }
4830:
4831: table#LC_top_nav td.LC_top_nav_exit,
4832: table#LC_top_nav td.LC_top_nav_help {
4833: width: 2.0em;
4834: }
4835:
4836: table#LC_top_nav td.LC_top_nav_login {
4837: width: 4.0em;
4838: text-align: center;
4839: }
4840:
4841: .LC_breadcrumbs_component {
4842: float: right;
4843: margin: 0 1em;
4844: }
4845: .LC_breadcrumbs_component img {
4846: vertical-align: middle;
4847: }
4848:
4849: td.LC_table_cell_checkbox {
4850: text-align: center;
4851: }
4852:
4853: table#LC_mainmenu td.LC_mainmenu_column {
4854: vertical-align: top;
4855: }
4856:
4857: .LC_fontsize_small {
4858: font-size: 70%;
4859: }
4860:
4861: #LC_breadcrumbs {
4862: clear:both;
4863: background: $sidebg;
4864: border-bottom: 1px solid $lg_border_color;
4865: line-height: 32px;
4866: margin: 0;
4867: padding: 0;
4868: }
4869:
4870: /* Preliminary fix to hide breadcrumbs inside remote control window */
4871: #LC_remote #LC_breadcrumbs {
4872: display:none;
4873: }
4874:
4875: #LC_head_subbox {
4876: clear:both;
4877: background: #F8F8F8; /* $sidebg; */
4878: border-bottom: 1px solid $lg_border_color;
4879: margin: 0 0 10px 0;
4880: padding: 5px;
4881: }
4882:
4883: .LC_fontsize_medium {
4884: font-size: 85%;
4885: }
4886:
4887: .LC_fontsize_large {
4888: font-size: 120%;
4889: }
4890:
4891: .LC_menubuttons_inline_text {
4892: color: $font;
4893: font-size: 90%;
4894: padding-left:3px;
4895: }
4896:
4897: .LC_menubuttons_link {
4898: text-decoration: none;
4899: }
4900:
4901: .LC_menubuttons_category {
4902: color: $font;
4903: background: $pgbg;
4904: font-size: larger;
4905: font-weight: bold;
4906: }
4907:
4908: td.LC_menubuttons_text {
4909: color: $font;
4910: }
4911:
4912: .LC_current_location {
4913: background: $tabbg;
4914: }
4915:
4916: .LC_new_mail {
4917: background: $tabbg;
4918: font-weight: bold;
4919: }
4920:
4921: .LC_roleslog_note {
4922: font-size: small;
4923: }
4924:
4925: table.LC_data_table,
4926: table.LC_mail_list {
4927: border: 1px solid #000000;
4928: border-collapse: separate;
4929: border-spacing: 1px;
4930: background: $pgbg;
4931: }
4932:
4933: .LC_data_table_dense {
4934: font-size: small;
4935: }
4936:
4937: table.LC_nested_outer {
4938: border: 1px solid #000000;
4939: border-collapse: collapse;
4940: border-spacing: 0;
4941: width: 100%;
4942: }
4943:
4944: table.LC_nested {
4945: border: none;
4946: border-collapse: collapse;
4947: border-spacing: 0;
4948: width: 100%;
4949: }
4950:
4951: table.LC_data_table tr th,
4952: table.LC_calendar tr th,
4953: table.LC_mail_list tr th,
4954: table.LC_prior_tries tr th {
4955: font-weight: bold;
4956: background-color: $data_table_head;
4957: color:$fontmenu;
4958: font-size:90%;
4959: }
4960:
4961: table.LC_data_table tr.LC_info_row > td {
4962: background-color: #CCCCCC;
4963: font-weight: bold;
4964: text-align: left;
4965: }
4966:
4967: table.LC_data_table tr.LC_odd_row > td,
4968: table.LC_pick_box tr > td.LC_odd_row {
4969: background-color: $data_table_light;
4970: padding: 2px;
4971: }
4972:
4973: table.LC_data_table tr.LC_even_row > td,
4974: table.LC_pick_box tr > td.LC_even_row {
4975: background-color: $data_table_dark;
4976: padding: 2px;
4977: }
4978:
4979: table.LC_data_table tr.LC_data_table_highlight td {
4980: background-color: $data_table_darker;
4981: }
4982:
4983: table.LC_data_table tr td.LC_leftcol_header {
4984: background-color: $data_table_head;
4985: font-weight: bold;
4986: }
4987:
4988: table.LC_data_table tr.LC_empty_row td,
4989: table.LC_nested tr.LC_empty_row td {
4990: background-color: #FFFFFF;
4991: font-weight: bold;
4992: font-style: italic;
4993: text-align: center;
4994: padding: 8px;
4995: }
4996:
4997: table.LC_nested tr.LC_empty_row td {
4998: padding: 4ex
4999: }
5000:
5001: table.LC_nested_outer tr th {
5002: font-weight: bold;
5003: color:$fontmenu;
5004: background-color: $data_table_head;
5005: font-size: small;
5006: border-bottom: 1px solid #000000;
5007: }
5008:
5009: table.LC_nested_outer tr td.LC_subheader {
5010: background-color: $data_table_head;
5011: font-weight: bold;
5012: font-size: small;
5013: border-bottom: 1px solid #000000;
5014: text-align: right;
5015: }
5016:
5017: table.LC_nested tr.LC_info_row td {
5018: background-color: #CCCCCC;
5019: font-weight: bold;
5020: font-size: small;
5021: text-align: center;
5022: }
5023:
5024: table.LC_nested tr.LC_info_row td.LC_left_item,
5025: table.LC_nested_outer tr th.LC_left_item {
5026: text-align: left;
5027: }
5028:
5029: table.LC_nested td {
5030: background-color: #FFFFFF;
5031: font-size: small;
5032: }
5033:
5034: table.LC_nested_outer tr th.LC_right_item,
5035: table.LC_nested tr.LC_info_row td.LC_right_item,
5036: table.LC_nested tr.LC_odd_row td.LC_right_item,
5037: table.LC_nested tr td.LC_right_item {
5038: text-align: right;
5039: }
5040:
5041: table.LC_nested tr.LC_odd_row td {
5042: background-color: #EEEEEE;
5043: }
5044:
5045: table.LC_createuser {
5046: }
5047:
5048: table.LC_createuser tr.LC_section_row td {
5049: font-size: small;
5050: }
5051:
5052: table.LC_createuser tr.LC_info_row td {
5053: background-color: #CCCCCC;
5054: font-weight: bold;
5055: text-align: center;
5056: }
5057:
5058: table.LC_calendar {
5059: border: 1px solid #000000;
5060: border-collapse: collapse;
5061: }
5062:
5063: table.LC_calendar_pickdate {
5064: font-size: xx-small;
5065: }
5066:
5067: table.LC_calendar tr td {
5068: border: 1px solid #000000;
5069: vertical-align: top;
5070: }
5071:
5072: table.LC_calendar tr td.LC_calendar_day_empty {
5073: background-color: $data_table_dark;
5074: }
5075:
5076: table.LC_calendar tr td.LC_calendar_day_current {
5077: background-color: $data_table_highlight;
5078: }
5079:
5080: table.LC_mail_list tr.LC_mail_new {
5081: background-color: $mail_new;
5082: }
5083:
5084: table.LC_mail_list tr.LC_mail_new:hover {
5085: background-color: $mail_new_hover;
5086: }
5087:
5088: table.LC_mail_list tr.LC_mail_even {
5089: }
5090:
5091: table.LC_mail_list tr.LC_mail_odd {
5092: }
5093:
5094: table.LC_mail_list tr.LC_mail_read {
5095: background-color: $mail_read;
5096: }
5097:
5098: table.LC_mail_list tr.LC_mail_read:hover {
5099: background-color: $mail_read_hover;
5100: }
5101:
5102: table.LC_mail_list tr.LC_mail_replied {
5103: background-color: $mail_replied;
5104: }
5105:
5106: table.LC_mail_list tr.LC_mail_replied:hover {
5107: background-color: $mail_replied_hover;
5108: }
5109:
5110: table.LC_mail_list tr.LC_mail_other {
5111: background-color: $mail_other;
5112: }
5113:
5114: table.LC_mail_list tr.LC_mail_other:hover {
5115: background-color: $mail_other_hover;
5116: }
5117:
5118: table.LC_data_table tr > td.LC_browser_file,
5119: table.LC_data_table tr > td.LC_browser_file_published {
5120: background: #CCFF88;
5121: }
5122:
5123: table.LC_data_table tr > td.LC_browser_file_locked,
5124: table.LC_data_table tr > td.LC_browser_file_unpublished {
5125: background: #FFAA99;
5126: }
5127:
5128: table.LC_data_table tr > td.LC_browser_file_obsolete {
5129: background: #AAAAAA;
5130: }
5131:
5132: table.LC_data_table tr > td.LC_browser_file_modified,
5133: table.LC_data_table tr > td.LC_browser_file_metamodified {
5134: background: #FFFF77;
5135: }
5136:
5137: table.LC_data_table tr.LC_browser_folder > td {
5138: background: #CCCCFF;
5139: }
5140:
5141: table.LC_data_table tr > td.LC_roles_is {
5142: /* background: #77FF77; */
5143: }
5144:
5145: table.LC_data_table tr > td.LC_roles_future {
5146: background: #FFFF77;
5147: }
5148:
5149: table.LC_data_table tr > td.LC_roles_will {
5150: background: #FFAA77;
5151: }
5152:
5153: table.LC_data_table tr > td.LC_roles_expired {
5154: background: #FF7777;
5155: }
5156:
5157: table.LC_data_table tr > td.LC_roles_will_not {
5158: background: #AAFF77;
5159: }
5160:
5161: table.LC_data_table tr > td.LC_roles_selected {
5162: background: #11CC55;
5163: }
5164:
5165: span.LC_current_location {
5166: font-size:larger;
5167: background: $pgbg;
5168: }
5169:
5170: span.LC_parm_menu_item {
5171: font-size: larger;
5172: }
5173:
5174: span.LC_parm_scope_all {
5175: color: red;
5176: }
5177:
5178: span.LC_parm_scope_folder {
5179: color: green;
5180: }
5181:
5182: span.LC_parm_scope_resource {
5183: color: orange;
5184: }
5185:
5186: span.LC_parm_part {
5187: color: blue;
5188: }
5189:
5190: span.LC_parm_folder, span.LC_parm_symb {
5191: font-size: x-small;
5192: font-family: $mono;
5193: color: #AAAAAA;
5194: }
5195:
5196: td.LC_parm_overview_level_menu,
5197: td.LC_parm_overview_map_menu,
5198: td.LC_parm_overview_parm_selectors,
5199: td.LC_parm_overview_restrictions {
5200: border: 1px solid black;
5201: border-collapse: collapse;
5202: }
5203:
5204: table.LC_parm_overview_restrictions td {
5205: border-width: 1px 4px 1px 4px;
5206: border-style: solid;
5207: border-color: $pgbg;
5208: text-align: center;
5209: }
5210:
5211: table.LC_parm_overview_restrictions th {
5212: background: $tabbg;
5213: border-width: 1px 4px 1px 4px;
5214: border-style: solid;
5215: border-color: $pgbg;
5216: }
5217:
5218: table#LC_helpmenu {
5219: border: none;
5220: height: 55px;
5221: border-spacing: 0;
5222: }
5223:
5224: table#LC_helpmenu fieldset legend {
5225: font-size: larger;
5226: }
5227:
5228: table#LC_helpmenu_links {
5229: width: 100%;
5230: border: 1px solid black;
5231: background: $pgbg;
5232: padding: 0;
5233: border-spacing: 1px;
5234: }
5235:
5236: table#LC_helpmenu_links tr td {
5237: padding: 1px;
5238: background: $tabbg;
5239: text-align: center;
5240: font-weight: bold;
5241: }
5242:
5243: table#LC_helpmenu_links a:link,
5244: table#LC_helpmenu_links a:visited,
5245: table#LC_helpmenu_links a:active {
5246: text-decoration: none;
5247: color: $font;
5248: }
5249:
5250: table#LC_helpmenu_links a:hover {
5251: text-decoration: underline;
5252: color: $vlink;
5253: }
5254:
5255: .LC_chrt_popup_exists {
5256: border: 1px solid #339933;
5257: margin: -1px;
5258: }
5259:
5260: .LC_chrt_popup_up {
5261: border: 1px solid yellow;
5262: margin: -1px;
5263: }
5264:
5265: .LC_chrt_popup {
5266: border: 1px solid #8888FF;
5267: background: #CCCCFF;
5268: }
5269:
5270: table.LC_pick_box {
5271: border-collapse: separate;
5272: background: white;
5273: border: 1px solid black;
5274: border-spacing: 1px;
5275: }
5276:
5277: table.LC_pick_box td.LC_pick_box_title {
5278: background: $sidebg;
5279: font-weight: bold;
5280: text-align: right;
5281: vertical-align: top;
5282: width: 184px;
5283: padding: 8px;
5284: }
5285:
5286: table.LC_pick_box td.LC_pick_box_value {
5287: text-align: left;
5288: padding: 8px;
5289: }
5290:
5291: table.LC_pick_box td.LC_pick_box_select {
5292: text-align: left;
5293: padding: 8px;
5294: }
5295:
5296: table.LC_pick_box td.LC_pick_box_separator {
5297: padding: 0;
5298: height: 1px;
5299: background: black;
5300: }
5301:
5302: table.LC_pick_box td.LC_pick_box_submit {
5303: text-align: right;
5304: }
5305:
5306: table.LC_pick_box td.LC_evenrow_value {
5307: text-align: left;
5308: padding: 8px;
5309: background-color: $data_table_light;
5310: }
5311:
5312: table.LC_pick_box td.LC_oddrow_value {
5313: text-align: left;
5314: padding: 8px;
5315: background-color: $data_table_light;
5316: }
5317:
5318: table.LC_helpform_receipt {
5319: width: 620px;
5320: border-collapse: separate;
5321: background: white;
5322: border: 1px solid black;
5323: border-spacing: 1px;
5324: }
5325:
5326: table.LC_helpform_receipt td.LC_pick_box_title {
5327: background: $tabbg;
5328: font-weight: bold;
5329: text-align: right;
5330: width: 184px;
5331: padding: 8px;
5332: }
5333:
5334: table.LC_helpform_receipt td.LC_evenrow_value {
5335: text-align: left;
5336: padding: 8px;
5337: background-color: $data_table_light;
5338: }
5339:
5340: table.LC_helpform_receipt td.LC_oddrow_value {
5341: text-align: left;
5342: padding: 8px;
5343: background-color: $data_table_light;
5344: }
5345:
5346: table.LC_helpform_receipt td.LC_pick_box_separator {
5347: padding: 0;
5348: height: 1px;
5349: background: black;
5350: }
5351:
5352: span.LC_helpform_receipt_cat {
5353: font-weight: bold;
5354: }
5355:
5356: table.LC_group_priv_box {
5357: background: white;
5358: border: 1px solid black;
5359: border-spacing: 1px;
5360: }
5361:
5362: table.LC_group_priv_box td.LC_pick_box_title {
5363: background: $tabbg;
5364: font-weight: bold;
5365: text-align: right;
5366: width: 184px;
5367: }
5368:
5369: table.LC_group_priv_box td.LC_groups_fixed {
5370: background: $data_table_light;
5371: text-align: center;
5372: }
5373:
5374: table.LC_group_priv_box td.LC_groups_optional {
5375: background: $data_table_dark;
5376: text-align: center;
5377: }
5378:
5379: table.LC_group_priv_box td.LC_groups_functionality {
5380: background: $data_table_darker;
5381: text-align: center;
5382: font-weight: bold;
5383: }
5384:
5385: table.LC_group_priv td {
5386: text-align: left;
5387: padding: 0;
5388: }
5389:
5390: table.LC_notify_front_page {
5391: background: white;
5392: border: 1px solid black;
5393: padding: 8px;
5394: }
5395:
5396: table.LC_notify_front_page td {
5397: padding: 8px;
5398: }
5399:
5400: .LC_navbuttons {
5401: margin: 2ex 0ex 2ex 0ex;
5402: }
5403:
5404: .LC_topic_bar {
5405: font-weight: bold;
5406: width: 100%;
5407: background: $tabbg;
5408: vertical-align: middle;
5409: margin: 2ex 0ex 2ex 0ex;
5410: padding: 3px;
5411: }
5412:
5413: .LC_topic_bar span {
5414: vertical-align: middle;
5415: }
5416:
5417: .LC_topic_bar img {
5418: vertical-align: bottom;
5419: }
5420:
5421: table.LC_course_group_status {
5422: margin: 20px;
5423: }
5424:
5425: table.LC_status_selector td {
5426: vertical-align: top;
5427: text-align: center;
5428: padding: 4px;
5429: }
5430:
5431: div.LC_feedback_link {
5432: clear: both;
5433: background: $sidebg;
5434: width: 100%;
5435: padding-bottom: 10px;
5436: border: 1px $tabbg solid;
5437: height: 22px;
5438: line-height: 22px;
5439: padding-top: 5px;
5440: }
5441:
5442: div.LC_feedback_link img {
5443: height: 22px;
5444: }
5445:
5446: div.LC_feedback_link a{
5447: text-decoration: none;
5448: }
5449:
5450: span.LC_feedback_link {
5451: /* background: $feedback_link_bg; */
5452: font-size: larger;
5453: }
5454:
5455: span.LC_message_link {
5456: /* background: $feedback_link_bg; */
5457: font-size: larger;
5458: position: absolute;
5459: right: 1em;
5460: }
5461:
5462: table.LC_prior_tries {
5463: border: 1px solid #000000;
5464: border-collapse: separate;
5465: border-spacing: 1px;
5466: }
5467:
5468: table.LC_prior_tries td {
5469: padding: 2px;
5470: }
5471:
5472: .LC_answer_correct {
5473: background: lightgreen;
5474: color: darkgreen;
5475: padding: 6px;
5476: }
5477:
5478: .LC_answer_charged_try {
5479: background: #FFAAAA;
5480: color: darkred;
5481: padding: 6px;
5482: }
5483:
5484: .LC_answer_not_charged_try,
5485: .LC_answer_no_grade,
5486: .LC_answer_late {
5487: background: lightyellow;
5488: color: black;
5489: padding: 6px;
5490: }
5491:
5492: .LC_answer_previous {
5493: background: lightblue;
5494: color: darkblue;
5495: padding: 6px;
5496: }
5497:
5498: .LC_answer_no_message {
5499: background: #FFFFFF;
5500: color: black;
5501: padding: 6px;
5502: }
5503:
5504: .LC_answer_unknown {
5505: background: orange;
5506: color: black;
5507: padding: 6px;
5508: }
5509:
5510: span.LC_prior_numerical,
5511: span.LC_prior_string,
5512: span.LC_prior_custom,
5513: span.LC_prior_reaction,
5514: span.LC_prior_math {
5515: font-family: monospace;
5516: white-space: pre;
5517: }
5518:
5519: span.LC_prior_string {
5520: font-family: monospace;
5521: white-space: pre;
5522: }
5523:
5524: table.LC_prior_option {
5525: width: 100%;
5526: border-collapse: collapse;
5527: }
5528:
5529: table.LC_prior_rank,
5530: table.LC_prior_match {
5531: border-collapse: collapse;
5532: }
5533:
5534: table.LC_prior_option tr td,
5535: table.LC_prior_rank tr td,
5536: table.LC_prior_match tr td {
5537: border: 1px solid #000000;
5538: }
5539:
5540: .LC_nobreak {
5541: white-space: nowrap;
5542: }
5543:
5544: span.LC_cusr_emph {
5545: font-style: italic;
5546: }
5547:
5548: span.LC_cusr_subheading {
5549: font-weight: normal;
5550: font-size: 85%;
5551: }
5552:
5553: table.LC_docs_documents {
5554: background: #BBBBBB;
5555: border-width: 0;
5556: border-collapse: collapse;
5557: }
5558:
5559: table.LC_docs_documents td.LC_docs_document {
5560: border: 2px solid black;
5561: padding: 4px;
5562: }
5563:
5564: div.LC_docs_entry_move {
5565: border: 1px solid #BBBBBB;
5566: background: #DDDDDD;
5567: width: 22px;
5568: padding: 1px;
5569: margin: 0;
5570: }
5571:
5572: table.LC_data_table tr > td.LC_docs_entry_commands,
5573: table.LC_data_table tr > td.LC_docs_entry_parameter {
5574: background: #DDDDDD;
5575: font-size: x-small;
5576: }
5577:
5578: .LC_docs_entry_parameter {
5579: white-space: nowrap;
5580: }
5581:
5582: .LC_docs_copy {
5583: color: #000099;
5584: }
5585:
5586: .LC_docs_cut {
5587: color: #550044;
5588: }
5589:
5590: .LC_docs_rename {
5591: color: #009900;
5592: }
5593:
5594: .LC_docs_remove {
5595: color: #990000;
5596: }
5597:
5598: .LC_docs_reinit_warn,
5599: .LC_docs_ext_edit {
5600: font-size: x-small;
5601: }
5602:
5603: table.LC_docs_adddocs td,
5604: table.LC_docs_adddocs th {
5605: border: 1px solid #BBBBBB;
5606: padding: 4px;
5607: background: #DDDDDD;
5608: }
5609:
5610: table.LC_sty_begin {
5611: background: #BBFFBB;
5612: }
5613:
5614: table.LC_sty_end {
5615: background: #FFBBBB;
5616: }
5617:
5618: table.LC_double_column {
5619: border-width: 0;
5620: border-collapse: collapse;
5621: width: 100%;
5622: padding: 2px;
5623: }
5624:
5625: table.LC_double_column tr td.LC_left_col {
5626: top: 2px;
5627: left: 2px;
5628: width: 47%;
5629: vertical-align: top;
5630: }
5631:
5632: table.LC_double_column tr td.LC_right_col {
5633: top: 2px;
5634: right: 2px;
5635: width: 47%;
5636: vertical-align: top;
5637: }
5638:
5639: span.LC_role_level {
5640: font-weight: bold;
5641: }
5642:
5643: div.LC_left_float {
5644: float: left;
5645: padding-right: 5%;
5646: padding-bottom: 4px;
5647: }
5648:
5649: div.LC_clear_float_header {
5650: padding-bottom: 2px;
5651: }
5652:
5653: div.LC_clear_float_footer {
5654: padding-top: 10px;
5655: clear: both;
5656: }
5657:
5658: div.LC_grade_show_user {
5659: margin-top: 20px;
5660: border: 1px solid black;
5661: }
5662:
5663: div.LC_grade_user_name {
5664: background: #DDDDEE;
5665: border-bottom: 1px solid black;
5666: font-weight: bold;
5667: font-size: large;
5668: }
5669:
5670: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
5671: background: #DDEEDD;
5672: }
5673:
5674: div.LC_grade_show_problem,
5675: div.LC_grade_submissions,
5676: div.LC_grade_message_center,
5677: div.LC_grade_info_links,
5678: div.LC_grade_assign {
5679: margin: 5px;
5680: width: 99%;
5681: background: #FFFFFF;
5682: }
5683:
5684: div.LC_grade_show_problem_header,
5685: div.LC_grade_submissions_header,
5686: div.LC_grade_message_center_header,
5687: div.LC_grade_assign_header {
5688: font-weight: bold;
5689: font-size: large;
5690: }
5691:
5692: div.LC_grade_show_problem_problem,
5693: div.LC_grade_submissions_body,
5694: div.LC_grade_message_center_body,
5695: div.LC_grade_assign_body {
5696: border: 1px solid black;
5697: width: 99%;
5698: background: #FFFFFF;
5699: }
5700:
5701: span.LC_grade_check_note {
5702: font-weight: normal;
5703: font-size: medium;
5704: display: inline;
5705: position: absolute;
5706: right: 1em;
5707: }
5708:
5709: table.LC_scantron_action {
5710: width: 100%;
5711: }
5712:
5713: table.LC_scantron_action tr th {
5714: font-weight:bold;
5715: font-style:normal;
5716: }
5717:
5718: .LC_edit_problem_header,
5719: div.LC_edit_problem_footer {
5720: font-weight: normal;
5721: font-size: medium;
5722: margin: 2px;
5723: }
5724:
5725: div.LC_edit_problem_header,
5726: div.LC_edit_problem_header div,
5727: div.LC_edit_problem_footer,
5728: div.LC_edit_problem_footer div,
5729: div.LC_edit_problem_editxml_header,
5730: div.LC_edit_problem_editxml_header div {
5731: margin-top: 5px;
5732: }
5733:
5734: div.LC_edit_problem_header_title {
5735: font-weight: bold;
5736: font-size: larger;
5737: background: $tabbg;
5738: padding: 3px;
5739: }
5740:
5741: table.LC_edit_problem_header_title {
5742: font-size: larger;
5743: font-weight: bold;
5744: width: 100%;
5745: border-color: $pgbg;
5746: border-style: solid;
5747: border-width: $border;
5748: background: $tabbg;
5749: border-collapse: collapse;
5750: padding: 0;
5751: }
5752:
5753: div.LC_edit_problem_discards {
5754: float: left;
5755: padding-bottom: 5px;
5756: }
5757:
5758: div.LC_edit_problem_saves {
5759: float: right;
5760: padding-bottom: 5px;
5761: }
5762:
5763: img.stift{
5764: border-width: 0;
5765: vertical-align: middle;
5766: }
5767:
5768: table#LC_mainmenu{
5769: margin-top:10px;
5770: width:80%;
5771: }
5772:
5773: table#LC_mainmenu td.LC_mainmenu_col_fieldset{
5774: vertical-align: top;
5775: width: 45%;
5776: }
5777:
5778: .LC_mainmenu_fieldset_category {
5779: color: $font;
5780: background: $pgbg;
5781: font-size: small;
5782: font-weight: bold;
5783: }
5784:
5785: div.LC_createcourse {
5786: margin: 10px 10px 10px 10px;
5787: }
5788:
5789: /* ---- Remove when done ----
5790: # The following styles is part of the redesign of LON-CAPA and are
5791: # subject to change during this project.
5792: # Don't rely on their current functionality as they might be
5793: # changed or removed.
5794: # --------------------------*/
5795:
5796: a:hover,
5797: ol.LC_smallMenu a:hover,
5798: ol#LC_MenuBreadcrumbs a:hover,
5799: ol#LC_PathBreadcrumbs a:hover,
5800: ul#LC_TabMainMenuContent a:hover,
5801: .LC_FormSectionClearButton input:hover
5802: ul.LC_TabContent li:hover a {
5803: color:#BF2317;
5804: text-decoration:none;
5805: }
5806:
5807: h1 {
5808: padding: 0;
5809: line-height:130%;
5810: }
5811:
5812: h2,h3,h4,h5,h6 {
5813: margin: 5px 0 5px 0;
5814: padding: 0;
5815: line-height:130%;
5816: }
5817:
5818: .LC_hcell {
5819: padding:3px 15px 3px 15px;
5820: margin: 0;
5821: background-color:$tabbg;
5822: color:$fontmenu;
5823: border-bottom:solid 1px $lg_border_color;
5824: }
5825:
5826: .LC_Box > .LC_hcell {
5827: margin: 0 -10px 10px -10px;
5828: }
5829:
5830: .LC_noBorder {
5831: border: 0;
5832: }
5833:
5834: .LC_Right {
5835: float: right;
5836: margin: 0;
5837: padding: 0;
5838: }
5839:
5840: .LC_FormSectionClearButton input {
5841: background-color:transparent;
5842: border: none;
5843: cursor:pointer;
5844: text-decoration:underline;
5845: }
5846:
5847: .LC_help_open_topic {
5848: color: #FFFFFF;
5849: background-color: #EEEEFF;
5850: margin: 1px;
5851: padding: 4px;
5852: border: 1px solid #000033;
5853: white-space: nowrap;
5854: /* vertical-align: middle; */
5855: }
5856:
5857: dl,ul,div,fieldset {
5858: margin: 10px 10px 10px 0;
5859: /* overflow: hidden; */
5860: }
5861:
5862: fieldset > legend {
5863: font-weight: bold;
5864: padding: 0 5px 0 5px;
5865: }
5866:
5867: #LC_nav_bar {
5868: float: left;
5869: margin: 0.2em 0 0 0;
5870: }
5871:
5872: #LC_nav_bar em{
5873: font-weight: bold;
5874: font-style: normal;
5875: }
5876:
5877: ol.LC_smallMenu {
5878: float: right;
5879: margin: 0.2em 0 0 0;
5880: }
5881:
5882: ol#LC_PathBreadcrumbs {
5883: margin: 0;
5884: }
5885:
5886: ol.LC_smallMenu li {
5887: display: inline;
5888: padding: 5px 5px 0 10px;
5889: vertical-align: top;
5890: }
5891:
5892: ol.LC_smallMenu li img {
5893: vertical-align: bottom;
5894: }
5895:
5896: ol.LC_smallMenu a {
5897: font-size: 90%;
5898: color: RGB(80, 80, 80);
5899: text-decoration: none;
5900: }
5901:
5902: ul#LC_TabMainMenuContent {
5903: clear: both;
5904: color: $fontmenu;
5905: background: $tabbg;
5906: list-style: none;
5907: padding: 0;
5908: margin: 0;
5909: width: 100%;
5910: }
5911:
5912: ul#LC_TabMainMenuContent li {
5913: font-weight: bold;
5914: line-height: 1.8em;
5915: padding: 0 0.8em;
5916: border-right: 1px solid black;
5917: display: inline;
5918: vertical-align: middle;
5919: }
5920:
5921: ul.LC_TabContent {
5922: display:block;
5923: background: $sidebg;
5924: border-bottom: solid 1px $lg_border_color;
5925: list-style:none;
5926: margin: -10px -10px 0 -10px;
5927: padding: 0;
5928: }
5929:
5930: ul.LC_TabContentBigger {
5931: display:block;
5932: list-style:none;
5933: padding: 0;
5934: }
5935:
5936:
5937: ul.LC_TabContent li,
5938: ul.LC_TabContentBigger li {
5939: display: inline;
5940: border-right: solid 1px $lg_border_color;
5941: float:left;
5942: line-height:140%;
5943: white-space:nowrap;
5944: }
5945:
5946: ul#LC_TabMainMenuContent li a {
5947: color: $fontmenu;
5948: text-decoration: none;
5949: }
5950:
5951: ul.LC_TabContent {
5952: min-height:1.5em;
5953: }
5954:
5955: ul.LC_TabContent li {
5956: vertical-align:middle;
5957: padding: 0 10px 0 10px;
5958: background-color:$tabbg;
5959: border-bottom:solid 1px $lg_border_color;
5960: }
5961:
5962: ul.LC_TabContent .right {
5963: float:right;
5964: }
5965:
5966: ul.LC_TabContent li a, ul.LC_TabContent li {
5967: color:rgb(47,47,47);
5968: text-decoration:none;
5969: font-size:95%;
5970: font-weight:bold;
5971: padding-right: 16px;
5972: }
5973:
5974: ul.LC_TabContent li:hover, ul.LC_TabContent li.active {
5975: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
5976: border-bottom:solid 2px #FFFFFF;
5977: padding-right: 16px;
5978: }
5979:
5980: ul.LC_TabContentBigger li {
5981: vertical-align:bottom;
5982: border-top:solid 1px $lg_border_color;
5983: border-left:solid 1px $lg_border_color;
5984: padding:5px 10px 5px 10px;
5985: margin-left:2px;
5986: background: #d9d9d9;
5987: }
5988:
5989: #maincoursedoc {
5990: clear:both;
5991: }
5992:
5993: ul.LC_TabContentBigger li:hover,
5994: ul.LC_TabContentBigger li.active {
5995: background: #ffffff;
5996: color:$font;
5997: }
5998:
5999: ul.LC_TabContentBigger li,
6000: ul.LC_TabContentBigger li a {
6001: font-size:110%;
6002: font-weight:bold;
6003: color: #737373;
6004: }
6005:
6006: ul.LC_CourseBreadcrumbs {
6007: background: $sidebg;
6008: line-height: 32px;
6009: padding-left: 10px;
6010: margin: 0 0 10px 0;
6011: list-style-position: inside;
6012:
6013: }
6014:
6015: ol#LC_MenuBreadcrumbs,
6016: ol#LC_PathBreadcrumbs {
6017: padding-left: 10px;
6018: margin: 0;
6019: list-style-position: inside;
6020: }
6021:
6022: ol#LC_MenuBreadcrumbs li,
6023: ol#LC_PathBreadcrumbs li,
6024: ul.LC_CourseBreadcrumbs li {
6025: display: inline;
6026: white-space: nowrap;
6027: }
6028:
6029: ol#LC_MenuBreadcrumbs li a,
6030: ul.LC_CourseBreadcrumbs li a {
6031: text-decoration: none;
6032: font-size:90%;
6033: }
6034:
6035: ol#LC_PathBreadcrumbs li a {
6036: text-decoration:none;
6037: font-size:100%;
6038: font-weight:bold;
6039: }
6040:
6041: .LC_Box {
6042: border: solid 1px $lg_border_color;
6043: padding: 0 10px 10px 10px;
6044: }
6045:
6046: .LC_AboutMe_Image {
6047: float:left;
6048: margin-right:10px;
6049: }
6050:
6051: .LC_Clear_AboutMe_Image {
6052: clear:left;
6053: }
6054:
6055: dl.LC_ListStyleClean dt {
6056: padding-right: 5px;
6057: display: table-header-group;
6058: }
6059:
6060: dl.LC_ListStyleClean dd {
6061: display: table-row;
6062: }
6063:
6064: .LC_ListStyleClean,
6065: .LC_ListStyleSimple,
6066: .LC_ListStyleNormal,
6067: .LC_ListStyle_Border,
6068: .LC_ListStyleSpecial {
6069: /*display:block; */
6070: list-style-position: inside;
6071: list-style-type: none;
6072: overflow: hidden;
6073: padding: 0;
6074: }
6075:
6076: .LC_ListStyleSimple li,
6077: .LC_ListStyleSimple dd,
6078: .LC_ListStyleNormal li,
6079: .LC_ListStyleNormal dd,
6080: .LC_ListStyleSpecial li,
6081: .LC_ListStyleSpecial dd {
6082: margin: 0;
6083: padding: 5px 5px 5px 10px;
6084: clear: both;
6085: }
6086:
6087: .LC_ListStyleClean li,
6088: .LC_ListStyleClean dd {
6089: padding-top: 0;
6090: padding-bottom: 0;
6091: }
6092:
6093: .LC_ListStyleSimple dd,
6094: .LC_ListStyleSimple li {
6095: border-bottom: solid 1px $lg_border_color;
6096: }
6097:
6098: .LC_ListStyleSpecial li,
6099: .LC_ListStyleSpecial dd {
6100: list-style-type: none;
6101: background-color: RGB(220, 220, 220);
6102: margin-bottom: 4px;
6103: }
6104:
6105: table.LC_SimpleTable {
6106: margin:5px;
6107: border:solid 1px $lg_border_color;
6108: }
6109:
6110: table.LC_SimpleTable tr {
6111: padding: 0;
6112: border:solid 1px $lg_border_color;
6113: }
6114:
6115: table.LC_SimpleTable thead {
6116: background:rgb(220,220,220);
6117: }
6118:
6119: div.LC_columnSection {
6120: display: block;
6121: clear: both;
6122: overflow: hidden;
6123: margin: 0;
6124: }
6125:
6126: div.LC_columnSection>* {
6127: float: left;
6128: margin: 10px 20px 10px 0;
6129: overflow:hidden;
6130: }
6131:
6132: .LC_loginpage_container {
6133: text-align:left;
6134: margin : 0 auto;
6135: width:90%;
6136: padding: 10px;
6137: height: auto;
6138: background-color:#FFFFFF;
6139: border:1px solid #CCCCCC;
6140: }
6141:
6142:
6143: .LC_loginpage_loginContainer {
6144: float:left;
6145: width: 182px;
6146: padding: 2px;
6147: border:1px solid #CCCCCC;
6148: background-color:$loginbg;
6149: }
6150:
6151: .LC_loginpage_loginContainer h2 {
6152: margin-top: 0;
6153: display:block;
6154: background:$bgcol;
6155: color:$textcol;
6156: padding-left:5px;
6157: }
6158:
6159: .LC_loginpage_loginInfo {
6160: float:left;
6161: width:182px;
6162: border:1px solid #CCCCCC;
6163: padding:2px;
6164: }
6165:
6166: .LC_loginpage_space {
6167: clear: both;
6168: margin-bottom: 20px;
6169: border-bottom: 1px solid #CCCCCC;
6170: }
6171:
6172: .LC_loginpage_floatLeft {
6173: float: left;
6174: width: 200px;
6175: margin: 0;
6176: }
6177:
6178: table em {
6179: font-weight: bold;
6180: font-style: normal;
6181: }
6182:
6183: table.LC_tableBrowseRes,
6184: table.LC_tableOfContent {
6185: border:none;
6186: border-spacing: 1px;
6187: padding: 3px;
6188: background-color: #FFFFFF;
6189: font-size: 90%;
6190: }
6191:
6192: table.LC_tableOfContent{
6193: border-collapse: collapse;
6194: }
6195:
6196: table.LC_tableBrowseRes a,
6197: table.LC_tableOfContent a {
6198: background-color: transparent;
6199: text-decoration: none;
6200: }
6201:
6202: table.LC_tableBrowseRes tr.LC_trOdd,
6203: table.LC_tableOfContent tr.LC_trOdd{
6204: background-color: #EEEEEE;
6205: }
6206:
6207: table.LC_tableOfContent img {
6208: border: none;
6209: height: 1.3em;
6210: vertical-align: text-bottom;
6211: margin-right: 0.3em;
6212: }
6213:
6214: a#LC_content_toolbar_firsthomework {
6215: background-image:url(/res/adm/pages/open-first-problem.gif);
6216: }
6217:
6218: a#LC_content_toolbar_launchnav {
6219: background-image:url(/res/adm/pages/start-navigation.gif);
6220: }
6221:
6222: a#LC_content_toolbar_closenav {
6223: background-image:url(/res/adm/pages/close-navigation.gif);
6224: }
6225:
6226: a#LC_content_toolbar_everything {
6227: background-image:url(/res/adm/pages/show-all.gif);
6228: }
6229:
6230: a#LC_content_toolbar_uncompleted {
6231: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
6232: }
6233:
6234: #LC_content_toolbar_clearbubbles {
6235: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
6236: }
6237:
6238: a#LC_content_toolbar_changefolder {
6239: background : url(/res/adm/pages/close-all-folders.gif) top center ;
6240: }
6241:
6242: a#LC_content_toolbar_changefolder_toggled {
6243: background-image:url(/res/adm/pages/open-all-folders.gif);
6244: }
6245:
6246: ul#LC_toolbar li a:hover {
6247: background-position: bottom center;
6248: }
6249:
6250: ul#LC_toolbar {
6251: padding: 0;
6252: margin: 2px;
6253: list-style:none;
6254: position:relative;
6255: background-color:white;
6256: }
6257:
6258: ul#LC_toolbar li {
6259: border:1px solid white;
6260: padding: 0;
6261: margin: 0;
6262: float: left;
6263: display:inline;
6264: vertical-align:middle;
6265: }
6266:
6267:
6268: a.LC_toolbarItem {
6269: display:block;
6270: padding: 0;
6271: margin: 0;
6272: height: 32px;
6273: width: 32px;
6274: color:white;
6275: border: none;
6276: background-repeat:no-repeat;
6277: background-color:transparent;
6278: }
6279:
6280: ul.LC_funclist li {
6281: float: left;
6282: white-space: nowrap;
6283: height: 35px; /* at least as high as heighest list item */
6284: margin: 0 15px 15px 10px;
6285: }
6286:
6287:
6288: END
6289: }
6290:
6291: =pod
6292:
6293: =item * &headtag()
6294:
6295: Returns a uniform footer for LON-CAPA web pages.
6296:
6297: Inputs: $title - optional title for the head
6298: $head_extra - optional extra HTML to put inside the <head>
6299: $args - optional arguments
6300: force_register - if is true call registerurl so the remote is
6301: informed
6302: redirect -> array ref of
6303: 1- seconds before redirect occurs
6304: 2- url to redirect to
6305: 3- whether the side effect should occur
6306: (side effect of setting
6307: $env{'internal.head.redirect'} to the url
6308: redirected too)
6309: domain -> force to color decorate a page for a specific
6310: domain
6311: function -> force usage of a specific rolish color scheme
6312: bgcolor -> override the default page bgcolor
6313: no_auto_mt_title
6314: -> prevent &mt()ing the title arg
6315:
6316: =cut
6317:
6318: sub headtag {
6319: my ($title,$head_extra,$args) = @_;
6320:
6321: my $function = $args->{'function'} || &get_users_function();
6322: my $domain = $args->{'domain'} || &determinedomain();
6323: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
6324: my $url = join(':',$env{'user.name'},$env{'user.domain'},
6325: $Apache::lonnet::perlvar{'lonVersion'},
6326: #time(),
6327: $env{'environment.color.timestamp'},
6328: $function,$domain,$bgcolor);
6329:
6330: $url = '/adm/css/'.&escape($url).'.css';
6331:
6332: my $result =
6333: '<head>'.
6334: &font_settings();
6335:
6336: if (!$args->{'frameset'}) {
6337: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
6338: }
6339: if ($args->{'force_register'}) {
6340: $result .= &Apache::lonmenu::registerurl(1);
6341: }
6342: if (!$args->{'no_nav_bar'}
6343: && !$args->{'only_body'}
6344: && !$args->{'frameset'}) {
6345: $result .= &help_menu_js();
6346: }
6347:
6348: if (ref($args->{'redirect'})) {
6349: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
6350: $url = &Apache::lonenc::check_encrypt($url);
6351: if (!$inhibit_continue) {
6352: $env{'internal.head.redirect'} = $url;
6353: }
6354: $result.=<<ADDMETA
6355: <meta http-equiv="pragma" content="no-cache" />
6356: <meta http-equiv="Refresh" content="$time; url=$url" />
6357: ADDMETA
6358: }
6359: if (!defined($title)) {
6360: $title = 'The LearningOnline Network with CAPA';
6361: }
6362: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
6363: $result .= '<title> LON-CAPA '.$title.'</title>'
6364: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
6365: .$head_extra;
6366: return $result;
6367: }
6368:
6369: =pod
6370:
6371: =item * &font_settings()
6372:
6373: Returns neccessary <meta> to set the proper encoding
6374:
6375: Inputs: none
6376:
6377: =cut
6378:
6379: sub font_settings {
6380: my $headerstring='';
6381: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
6382: $headerstring.=
6383: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
6384: }
6385: return $headerstring;
6386: }
6387:
6388: =pod
6389:
6390: =item * &xml_begin()
6391:
6392: Returns the needed doctype and <html>
6393:
6394: Inputs: none
6395:
6396: =cut
6397:
6398: sub xml_begin {
6399: my $output='';
6400:
6401: if ($env{'internal.start_page'}==1) {
6402: &Apache::lonhtmlcommon::init_htmlareafields();
6403: }
6404:
6405: if ($env{'browser.mathml'}) {
6406: $output='<?xml version="1.0"?>'
6407: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
6408: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
6409:
6410: # .'<!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">] >'
6411: .'<!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">'
6412: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
6413: .'xmlns="http://www.w3.org/1999/xhtml">';
6414: } else {
6415: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
6416: .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
6417: }
6418: return $output;
6419: }
6420:
6421: =pod
6422:
6423: =item * &endheadtag()
6424:
6425: Returns a uniform </head> for LON-CAPA web pages.
6426:
6427: Inputs: none
6428:
6429: =cut
6430:
6431: sub endheadtag {
6432: return '</head>';
6433: }
6434:
6435: =pod
6436:
6437: =item * &head()
6438:
6439: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
6440:
6441: Inputs:
6442:
6443: =over 4
6444:
6445: $title - optional title for the page
6446:
6447: $head_extra - optional extra HTML to put inside the <head>
6448:
6449: =back
6450:
6451: =cut
6452:
6453: sub head {
6454: my ($title,$head_extra,$args) = @_;
6455: return &headtag($title,$head_extra,$args).&endheadtag();
6456: }
6457:
6458: =pod
6459:
6460: =item * &start_page()
6461:
6462: Returns a complete <html> .. <body> section for LON-CAPA web pages.
6463:
6464: Inputs:
6465:
6466: =over 4
6467:
6468: $title - optional title for the page
6469:
6470: $head_extra - optional extra HTML to incude inside the <head>
6471:
6472: $args - additional optional args supported are:
6473:
6474: =over 8
6475:
6476: only_body -> is true will set &bodytag() onlybodytag
6477: arg on
6478: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
6479: add_entries -> additional attributes to add to the <body>
6480: domain -> force to color decorate a page for a
6481: specific domain
6482: function -> force usage of a specific rolish color
6483: scheme
6484: redirect -> see &headtag()
6485: bgcolor -> override the default page bg color
6486: js_ready -> return a string ready for being used in
6487: a javascript writeln
6488: html_encode -> return a string ready for being used in
6489: a html attribute
6490: force_register -> if is true will turn on the &bodytag()
6491: $forcereg arg
6492: frameset -> if true will start with a <frameset>
6493: rather than <body>
6494: skip_phases -> hash ref of
6495: head -> skip the <html><head> generation
6496: body -> skip all <body> generation
6497: no_inline_link -> if true and in remote mode, don't show the
6498: 'Switch To Inline Menu' link
6499: no_auto_mt_title -> prevent &mt()ing the title arg
6500: inherit_jsmath -> when creating popup window in a page,
6501: should it have jsmath forced on by the
6502: current page
6503:
6504: =back
6505:
6506: =back
6507:
6508: =cut
6509:
6510: sub start_page {
6511: my ($title,$head_extra,$args) = @_;
6512: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
6513: my %head_args;
6514: foreach my $arg ('redirect','force_register','domain','function',
6515: 'bgcolor','frameset','no_nav_bar','only_body',
6516: 'no_auto_mt_title') {
6517: if (defined($args->{$arg})) {
6518: $head_args{$arg} = $args->{$arg};
6519: }
6520: }
6521:
6522: $env{'internal.start_page'}++;
6523: my $result;
6524: if (! exists($args->{'skip_phases'}{'head'}) ) {
6525: $result.=
6526: &xml_begin().
6527: &headtag($title,$head_extra,\%head_args).&endheadtag();
6528: }
6529:
6530: if (! exists($args->{'skip_phases'}{'body'}) ) {
6531: if ($args->{'frameset'}) {
6532: my $attr_string = &make_attr_string($args->{'force_register'},
6533: $args->{'add_entries'});
6534: $result .= "\n<frameset $attr_string>\n";
6535: } else {
6536: $result .=
6537: &bodytag($title,
6538: $args->{'function'}, $args->{'add_entries'},
6539: $args->{'only_body'}, $args->{'domain'},
6540: $args->{'force_register'}, $args->{'no_nav_bar'},
6541: $args->{'bgcolor'}, $args->{'no_inline_link'},
6542: $args);
6543: }
6544: }
6545:
6546: if ($args->{'js_ready'}) {
6547: $result = &js_ready($result);
6548: }
6549: if ($args->{'html_encode'}) {
6550: $result = &html_encode($result);
6551: }
6552:
6553: # Preparation for new and consistent functionlist at top of screen
6554: # if ($args->{'functionlist'}) {
6555: # $result .= &build_functionlist();
6556: #}
6557:
6558: # Don't add anything more if only_body wanted
6559: return $result if $args->{'only_body'};
6560:
6561: #Breadcrumbs
6562: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
6563: &Apache::lonhtmlcommon::clear_breadcrumbs();
6564: #if any br links exists, add them to the breadcrumbs
6565: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
6566: foreach my $crumb (@{$args->{'bread_crumbs'}}){
6567: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
6568: }
6569: }
6570:
6571: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
6572: if(exists($args->{'bread_crumbs_component'})){
6573: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
6574: }else{
6575: $result .= &Apache::lonhtmlcommon::breadcrumbs();
6576: }
6577: }
6578: return $result;
6579: }
6580:
6581:
6582: =pod
6583:
6584: =item * &head()
6585:
6586: Returns a complete </body></html> section for LON-CAPA web pages.
6587:
6588: Inputs: $args - additional optional args supported are:
6589: js_ready -> return a string ready for being used in
6590: a javascript writeln
6591: html_encode -> return a string ready for being used in
6592: a html attribute
6593: frameset -> if true will start with a <frameset>
6594: rather than <body>
6595: dicsussion -> if true will get discussion from
6596: lonxml::xmlend
6597: (you can pass the target and parser arguments
6598: through optional 'target' and 'parser' args
6599: to this routine)
6600:
6601: =cut
6602:
6603: sub end_page {
6604: my ($args) = @_;
6605: $env{'internal.end_page'}++;
6606: my $result;
6607: if ($args->{'discussion'}) {
6608: my ($target,$parser);
6609: if (ref($args->{'discussion'})) {
6610: ($target,$parser) =($args->{'discussion'}{'target'},
6611: $args->{'discussion'}{'parser'});
6612: }
6613: $result .= &Apache::lonxml::xmlend($target,$parser);
6614: }
6615:
6616: if ($args->{'frameset'}) {
6617: $result .= '</frameset>';
6618: } else {
6619: $result .= &endbodytag($args);
6620: }
6621: $result .= "\n</html>";
6622:
6623: if ($args->{'js_ready'}) {
6624: $result = &js_ready($result);
6625: }
6626:
6627: if ($args->{'html_encode'}) {
6628: $result = &html_encode($result);
6629: }
6630:
6631: return $result;
6632: }
6633:
6634: sub html_encode {
6635: my ($result) = @_;
6636:
6637: $result = &HTML::Entities::encode($result,'<>&"');
6638:
6639: return $result;
6640: }
6641: sub js_ready {
6642: my ($result) = @_;
6643:
6644: $result =~ s/[\n\r]/ /xmsg;
6645: $result =~ s/\\/\\\\/xmsg;
6646: $result =~ s/'/\\'/xmsg;
6647: $result =~ s{</}{<\\/}xmsg;
6648:
6649: return $result;
6650: }
6651:
6652: sub validate_page {
6653: if ( exists($env{'internal.start_page'})
6654: && $env{'internal.start_page'} > 1) {
6655: &Apache::lonnet::logthis('start_page called multiple times '.
6656: $env{'internal.start_page'}.' '.
6657: $ENV{'request.filename'});
6658: }
6659: if ( exists($env{'internal.end_page'})
6660: && $env{'internal.end_page'} > 1) {
6661: &Apache::lonnet::logthis('end_page called multiple times '.
6662: $env{'internal.end_page'}.' '.
6663: $env{'request.filename'});
6664: }
6665: if ( exists($env{'internal.start_page'})
6666: && ! exists($env{'internal.end_page'})) {
6667: &Apache::lonnet::logthis('start_page called without end_page '.
6668: $env{'request.filename'});
6669: }
6670: if ( ! exists($env{'internal.start_page'})
6671: && exists($env{'internal.end_page'})) {
6672: &Apache::lonnet::logthis('end_page called without start_page'.
6673: $env{'request.filename'});
6674: }
6675: }
6676:
6677: sub simple_error_page {
6678: my ($r,$title,$msg) = @_;
6679: my $page =
6680: &Apache::loncommon::start_page($title).
6681: &mt($msg).
6682: &Apache::loncommon::end_page();
6683: if (ref($r)) {
6684: $r->print($page);
6685: return;
6686: }
6687: return $page;
6688: }
6689:
6690: {
6691: my @row_count;
6692: sub start_data_table {
6693: my ($add_class) = @_;
6694: my $css_class = (join(' ','LC_data_table',$add_class));
6695: unshift(@row_count,0);
6696: return '<table class="'.$css_class.'">'."\n";
6697: }
6698:
6699: sub end_data_table {
6700: shift(@row_count);
6701: return '</table>'."\n";;
6702: }
6703:
6704: sub start_data_table_row {
6705: my ($add_class) = @_;
6706: $row_count[0]++;
6707: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
6708: $css_class = (join(' ',$css_class,$add_class));
6709: return '<tr class="'.$css_class.'">'."\n";;
6710: }
6711:
6712: sub continue_data_table_row {
6713: my ($add_class) = @_;
6714: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
6715: $css_class = (join(' ',$css_class,$add_class));
6716: return '<tr class="'.$css_class.'">'."\n";;
6717: }
6718:
6719: sub end_data_table_row {
6720: return '</tr>'."\n";;
6721: }
6722:
6723: sub start_data_table_empty_row {
6724: # $row_count[0]++;
6725: return '<tr class="LC_empty_row" >'."\n";;
6726: }
6727:
6728: sub end_data_table_empty_row {
6729: return '</tr>'."\n";;
6730: }
6731:
6732: sub start_data_table_header_row {
6733: return '<tr class="LC_header_row">'."\n";;
6734: }
6735:
6736: sub end_data_table_header_row {
6737: return '</tr>'."\n";;
6738: }
6739: }
6740:
6741: =pod
6742:
6743: =item * &inhibit_menu_check($arg)
6744:
6745: Checks for a inhibitmenu state and generates output to preserve it
6746:
6747: Inputs: $arg - can be any of
6748: - undef - in which case the return value is a string
6749: to add into arguments list of a uri
6750: - 'input' - in which case the return value is a HTML
6751: <form> <input> field of type hidden to
6752: preserve the value
6753: - a url - in which case the return value is the url with
6754: the neccesary cgi args added to preserve the
6755: inhibitmenu state
6756: - a ref to a url - no return value, but the string is
6757: updated to include the neccessary cgi
6758: args to preserve the inhibitmenu state
6759:
6760: =cut
6761:
6762: sub inhibit_menu_check {
6763: my ($arg) = @_;
6764: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6765: if ($arg eq 'input') {
6766: if ($env{'form.inhibitmenu'}) {
6767: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
6768: } else {
6769: return
6770: }
6771: }
6772: if ($env{'form.inhibitmenu'}) {
6773: if (ref($arg)) {
6774: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6775: } elsif ($arg eq '') {
6776: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
6777: } else {
6778: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6779: }
6780: }
6781: if (!ref($arg)) {
6782: return $arg;
6783: }
6784: }
6785:
6786: ###############################################
6787:
6788: =pod
6789:
6790: =back
6791:
6792: =head1 User Information Routines
6793:
6794: =over 4
6795:
6796: =item * &get_users_function()
6797:
6798: Used by &bodytag to determine the current users primary role.
6799: Returns either 'student','coordinator','admin', or 'author'.
6800:
6801: =cut
6802:
6803: ###############################################
6804: sub get_users_function {
6805: my $function = 'norole';
6806: if ($env{'request.role'}=~/^(st)/) {
6807: $function='student';
6808: }
6809: if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
6810: $function='coordinator';
6811: }
6812: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
6813: $function='admin';
6814: }
6815: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
6816: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
6817: $function='author';
6818: }
6819: return $function;
6820: }
6821:
6822: ###############################################
6823:
6824: =pod
6825:
6826: =item * &show_course()
6827:
6828: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
6829: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
6830:
6831: Inputs:
6832: None
6833:
6834: Outputs:
6835: Scalar: 1 if 'Course' to be used, 0 otherwise.
6836:
6837: =cut
6838:
6839: ###############################################
6840: sub show_course {
6841: my $course = !$env{'user.adv'};
6842: if (!$env{'user.adv'}) {
6843: foreach my $env (keys(%env)) {
6844: next if ($env !~ m/^user\.priv\./);
6845: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
6846: $course = 0;
6847: last;
6848: }
6849: }
6850: }
6851: return $course;
6852: }
6853:
6854: ###############################################
6855:
6856: =pod
6857:
6858: =item * &check_user_status()
6859:
6860: Determines current status of supplied role for a
6861: specific user. Roles can be active, previous or future.
6862:
6863: Inputs:
6864: user's domain, user's username, course's domain,
6865: course's number, optional section ID.
6866:
6867: Outputs:
6868: role status: active, previous or future.
6869:
6870: =cut
6871:
6872: sub check_user_status {
6873: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
6874: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
6875: my @uroles = keys %userinfo;
6876: my $srchstr;
6877: my $active_chk = 'none';
6878: my $now = time;
6879: if (@uroles > 0) {
6880: if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
6881: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
6882: } else {
6883: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
6884: }
6885: if (grep/^\Q$srchstr\E$/,@uroles) {
6886: my $role_end = 0;
6887: my $role_start = 0;
6888: $active_chk = 'active';
6889: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
6890: $role_end = $1;
6891: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
6892: $role_start = $1;
6893: }
6894: }
6895: if ($role_start > 0) {
6896: if ($now < $role_start) {
6897: $active_chk = 'future';
6898: }
6899: }
6900: if ($role_end > 0) {
6901: if ($now > $role_end) {
6902: $active_chk = 'previous';
6903: }
6904: }
6905: }
6906: }
6907: return $active_chk;
6908: }
6909:
6910: ###############################################
6911:
6912: =pod
6913:
6914: =item * &get_sections()
6915:
6916: Determines all the sections for a course including
6917: sections with students and sections containing other roles.
6918: Incoming parameters:
6919:
6920: 1. domain
6921: 2. course number
6922: 3. reference to array containing roles for which sections should
6923: be gathered (optional).
6924: 4. reference to array containing status types for which sections
6925: should be gathered (optional).
6926:
6927: If the third argument is undefined, sections are gathered for any role.
6928: If the fourth argument is undefined, sections are gathered for any status.
6929: Permissible values are 'active' or 'future' or 'previous'.
6930:
6931: Returns section hash (keys are section IDs, values are
6932: number of users in each section), subject to the
6933: optional roles filter, optional status filter
6934:
6935: =cut
6936:
6937: ###############################################
6938: sub get_sections {
6939: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
6940: if (!defined($cdom) || !defined($cnum)) {
6941: my $cid = $env{'request.course.id'};
6942:
6943: return if (!defined($cid));
6944:
6945: $cdom = $env{'course.'.$cid.'.domain'};
6946: $cnum = $env{'course.'.$cid.'.num'};
6947: }
6948:
6949: my %sectioncount;
6950: my $now = time;
6951:
6952: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
6953: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
6954: my $sec_index = &Apache::loncoursedata::CL_SECTION();
6955: my $status_index = &Apache::loncoursedata::CL_STATUS();
6956: my $start_index = &Apache::loncoursedata::CL_START();
6957: my $end_index = &Apache::loncoursedata::CL_END();
6958: my $status;
6959: while (my ($student,$data) = each(%$classlist)) {
6960: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
6961: $data->[$status_index],
6962: $data->[$start_index],
6963: $data->[$end_index]);
6964: if ($stu_status eq 'Active') {
6965: $status = 'active';
6966: } elsif ($end < $now) {
6967: $status = 'previous';
6968: } elsif ($start > $now) {
6969: $status = 'future';
6970: }
6971: if ($section ne '-1' && $section !~ /^\s*$/) {
6972: if ((!defined($possible_status)) || (($status ne '') &&
6973: (grep/^\Q$status\E$/,@{$possible_status}))) {
6974: $sectioncount{$section}++;
6975: }
6976: }
6977: }
6978: }
6979: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6980: foreach my $user (sort(keys(%courseroles))) {
6981: if ($user !~ /^(\w{2})/) { next; }
6982: my ($role) = ($user =~ /^(\w{2})/);
6983: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
6984: my ($section,$status);
6985: if ($role eq 'cr' &&
6986: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
6987: $section=$1;
6988: }
6989: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
6990: if (!defined($section) || $section eq '-1') { next; }
6991: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
6992: if ($end == -1 && $start == -1) {
6993: next; #deleted role
6994: }
6995: if (!defined($possible_status)) {
6996: $sectioncount{$section}++;
6997: } else {
6998: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
6999: $status = 'active';
7000: } elsif ($end < $now) {
7001: $status = 'future';
7002: } elsif ($start > $now) {
7003: $status = 'previous';
7004: }
7005: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
7006: $sectioncount{$section}++;
7007: }
7008: }
7009: }
7010: return %sectioncount;
7011: }
7012:
7013: ###############################################
7014:
7015: =pod
7016:
7017: =item * &get_course_users()
7018:
7019: Retrieves usernames:domains for users in the specified course
7020: with specific role(s), and access status.
7021:
7022: Incoming parameters:
7023: 1. course domain
7024: 2. course number
7025: 3. access status: users must have - either active,
7026: previous, future, or all.
7027: 4. reference to array of permissible roles
7028: 5. reference to array of section restrictions (optional)
7029: 6. reference to results object (hash of hashes).
7030: 7. reference to optional userdata hash
7031: 8. reference to optional statushash
7032: 9. flag if privileged users (except those set to unhide in
7033: course settings) should be excluded
7034: Keys of top level results hash are roles.
7035: Keys of inner hashes are username:domain, with
7036: values set to access type.
7037: Optional userdata hash returns an array with arguments in the
7038: same order as loncoursedata::get_classlist() for student data.
7039:
7040: Optional statushash returns
7041:
7042: Entries for end, start, section and status are blank because
7043: of the possibility of multiple values for non-student roles.
7044:
7045: =cut
7046:
7047: ###############################################
7048:
7049: sub get_course_users {
7050: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
7051: my %idx = ();
7052: my %seclists;
7053:
7054: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
7055: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
7056: $idx{end} = &Apache::loncoursedata::CL_END();
7057: $idx{start} = &Apache::loncoursedata::CL_START();
7058: $idx{id} = &Apache::loncoursedata::CL_ID();
7059: $idx{section} = &Apache::loncoursedata::CL_SECTION();
7060: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
7061: $idx{status} = &Apache::loncoursedata::CL_STATUS();
7062:
7063: if (grep(/^st$/,@{$roles})) {
7064: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
7065: my $now = time;
7066: foreach my $student (keys(%{$classlist})) {
7067: my $match = 0;
7068: my $secmatch = 0;
7069: my $section = $$classlist{$student}[$idx{section}];
7070: my $status = $$classlist{$student}[$idx{status}];
7071: if ($section eq '') {
7072: $section = 'none';
7073: }
7074: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
7075: if (grep(/^all$/,@{$sections})) {
7076: $secmatch = 1;
7077: } elsif ($$classlist{$student}[$idx{section}] eq '') {
7078: if (grep(/^none$/,@{$sections})) {
7079: $secmatch = 1;
7080: }
7081: } else {
7082: if (grep(/^\Q$section\E$/,@{$sections})) {
7083: $secmatch = 1;
7084: }
7085: }
7086: if (!$secmatch) {
7087: next;
7088: }
7089: }
7090: if (defined($$types{'active'})) {
7091: if ($$classlist{$student}[$idx{status}] eq 'Active') {
7092: push(@{$$users{st}{$student}},'active');
7093: $match = 1;
7094: }
7095: }
7096: if (defined($$types{'previous'})) {
7097: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
7098: push(@{$$users{st}{$student}},'previous');
7099: $match = 1;
7100: }
7101: }
7102: if (defined($$types{'future'})) {
7103: if ($$classlist{$student}[$idx{status}] eq 'Future') {
7104: push(@{$$users{st}{$student}},'future');
7105: $match = 1;
7106: }
7107: }
7108: if ($match) {
7109: push(@{$seclists{$student}},$section);
7110: if (ref($userdata) eq 'HASH') {
7111: $$userdata{$student} = $$classlist{$student};
7112: }
7113: if (ref($statushash) eq 'HASH') {
7114: $statushash->{$student}{'st'}{$section} = $status;
7115: }
7116: }
7117: }
7118: }
7119: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
7120: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7121: my $now = time;
7122: my %displaystatus = ( previous => 'Expired',
7123: active => 'Active',
7124: future => 'Future',
7125: );
7126: my %nothide;
7127: if ($hidepriv) {
7128: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
7129: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
7130: if ($user !~ /:/) {
7131: $nothide{join(':',split(/[\@]/,$user))}=1;
7132: } else {
7133: $nothide{$user} = 1;
7134: }
7135: }
7136: }
7137: foreach my $person (sort(keys(%coursepersonnel))) {
7138: my $match = 0;
7139: my $secmatch = 0;
7140: my $status;
7141: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
7142: $user =~ s/:$//;
7143: my ($end,$start) = split(/:/,$coursepersonnel{$person});
7144: if ($end == -1 || $start == -1) {
7145: next;
7146: }
7147: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
7148: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
7149: my ($uname,$udom) = split(/:/,$user);
7150: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
7151: if (grep(/^all$/,@{$sections})) {
7152: $secmatch = 1;
7153: } elsif ($usec eq '') {
7154: if (grep(/^none$/,@{$sections})) {
7155: $secmatch = 1;
7156: }
7157: } else {
7158: if (grep(/^\Q$usec\E$/,@{$sections})) {
7159: $secmatch = 1;
7160: }
7161: }
7162: if (!$secmatch) {
7163: next;
7164: }
7165: }
7166: if ($usec eq '') {
7167: $usec = 'none';
7168: }
7169: if ($uname ne '' && $udom ne '') {
7170: if ($hidepriv) {
7171: if ((&Apache::lonnet::privileged($uname,$udom)) &&
7172: (!$nothide{$uname.':'.$udom})) {
7173: next;
7174: }
7175: }
7176: if ($end > 0 && $end < $now) {
7177: $status = 'previous';
7178: } elsif ($start > $now) {
7179: $status = 'future';
7180: } else {
7181: $status = 'active';
7182: }
7183: foreach my $type (keys(%{$types})) {
7184: if ($status eq $type) {
7185: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
7186: push(@{$$users{$role}{$user}},$type);
7187: }
7188: $match = 1;
7189: }
7190: }
7191: if (($match) && (ref($userdata) eq 'HASH')) {
7192: if (!exists($$userdata{$uname.':'.$udom})) {
7193: &get_user_info($udom,$uname,\%idx,$userdata);
7194: }
7195: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
7196: push(@{$seclists{$uname.':'.$udom}},$usec);
7197: }
7198: if (ref($statushash) eq 'HASH') {
7199: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
7200: }
7201: }
7202: }
7203: }
7204: }
7205: if (grep(/^ow$/,@{$roles})) {
7206: if ((defined($cdom)) && (defined($cnum))) {
7207: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
7208: if ( defined($csettings{'internal.courseowner'}) ) {
7209: my $owner = $csettings{'internal.courseowner'};
7210: next if ($owner eq '');
7211: my ($ownername,$ownerdom);
7212: if ($owner =~ /^([^:]+):([^:]+)$/) {
7213: $ownername = $1;
7214: $ownerdom = $2;
7215: } else {
7216: $ownername = $owner;
7217: $ownerdom = $cdom;
7218: $owner = $ownername.':'.$ownerdom;
7219: }
7220: @{$$users{'ow'}{$owner}} = 'any';
7221: if (defined($userdata) &&
7222: !exists($$userdata{$owner})) {
7223: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
7224: if (!grep(/^none$/,@{$seclists{$owner}})) {
7225: push(@{$seclists{$owner}},'none');
7226: }
7227: if (ref($statushash) eq 'HASH') {
7228: $statushash->{$owner}{'ow'}{'none'} = 'Any';
7229: }
7230: }
7231: }
7232: }
7233: }
7234: foreach my $user (keys(%seclists)) {
7235: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
7236: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
7237: }
7238: }
7239: return;
7240: }
7241:
7242: sub get_user_info {
7243: my ($udom,$uname,$idx,$userdata) = @_;
7244: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
7245: &plainname($uname,$udom,'lastname');
7246: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
7247: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
7248: my %idhash = &Apache::lonnet::idrget($udom,($uname));
7249: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
7250: return;
7251: }
7252:
7253: ###############################################
7254:
7255: =pod
7256:
7257: =item * &get_user_quota()
7258:
7259: Retrieves quota assigned for storage of portfolio files for a user
7260:
7261: Incoming parameters:
7262: 1. user's username
7263: 2. user's domain
7264:
7265: Returns:
7266: 1. Disk quota (in Mb) assigned to student.
7267: 2. (Optional) Type of setting: custom or default
7268: (individually assigned or default for user's
7269: institutional status).
7270: 3. (Optional) - User's institutional status (e.g., faculty, staff
7271: or student - types as defined in localenroll::inst_usertypes
7272: for user's domain, which determines default quota for user.
7273: 4. (Optional) - Default quota which would apply to the user.
7274:
7275: If a value has been stored in the user's environment,
7276: it will return that, otherwise it returns the maximal default
7277: defined for the user's instituional status(es) in the domain.
7278:
7279: =cut
7280:
7281: ###############################################
7282:
7283:
7284: sub get_user_quota {
7285: my ($uname,$udom) = @_;
7286: my ($quota,$quotatype,$settingstatus,$defquota);
7287: if (!defined($udom)) {
7288: $udom = $env{'user.domain'};
7289: }
7290: if (!defined($uname)) {
7291: $uname = $env{'user.name'};
7292: }
7293: if (($udom eq '' || $uname eq '') ||
7294: ($udom eq 'public') && ($uname eq 'public')) {
7295: $quota = 0;
7296: $quotatype = 'default';
7297: $defquota = 0;
7298: } else {
7299: my $inststatus;
7300: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
7301: $quota = $env{'environment.portfolioquota'};
7302: $inststatus = $env{'environment.inststatus'};
7303: } else {
7304: my %userenv =
7305: &Apache::lonnet::get('environment',['portfolioquota',
7306: 'inststatus'],$udom,$uname);
7307: my ($tmp) = keys(%userenv);
7308: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
7309: $quota = $userenv{'portfolioquota'};
7310: $inststatus = $userenv{'inststatus'};
7311: } else {
7312: undef(%userenv);
7313: }
7314: }
7315: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
7316: if ($quota eq '') {
7317: $quota = $defquota;
7318: $quotatype = 'default';
7319: } else {
7320: $quotatype = 'custom';
7321: }
7322: }
7323: if (wantarray) {
7324: return ($quota,$quotatype,$settingstatus,$defquota);
7325: } else {
7326: return $quota;
7327: }
7328: }
7329:
7330: ###############################################
7331:
7332: =pod
7333:
7334: =item * &default_quota()
7335:
7336: Retrieves default quota assigned for storage of user portfolio files,
7337: given an (optional) user's institutional status.
7338:
7339: Incoming parameters:
7340: 1. domain
7341: 2. (Optional) institutional status(es). This is a : separated list of
7342: status types (e.g., faculty, staff, student etc.)
7343: which apply to the user for whom the default is being retrieved.
7344: If the institutional status string in undefined, the domain
7345: default quota will be returned.
7346:
7347: Returns:
7348: 1. Default disk quota (in Mb) for user portfolios in the domain.
7349: 2. (Optional) institutional type which determined the value of the
7350: default quota.
7351:
7352: If a value has been stored in the domain's configuration db,
7353: it will return that, otherwise it returns 20 (for backwards
7354: compatibility with domains which have not set up a configuration
7355: db file; the original statically defined portfolio quota was 20 Mb).
7356:
7357: If the user's status includes multiple types (e.g., staff and student),
7358: the largest default quota which applies to the user determines the
7359: default quota returned.
7360:
7361: =back
7362:
7363: =cut
7364:
7365: ###############################################
7366:
7367:
7368: sub default_quota {
7369: my ($udom,$inststatus) = @_;
7370: my ($defquota,$settingstatus);
7371: my %quotahash = &Apache::lonnet::get_dom('configuration',
7372: ['quotas'],$udom);
7373: if (ref($quotahash{'quotas'}) eq 'HASH') {
7374: if ($inststatus ne '') {
7375: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
7376: foreach my $item (@statuses) {
7377: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7378: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
7379: if ($defquota eq '') {
7380: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7381: $settingstatus = $item;
7382: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
7383: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7384: $settingstatus = $item;
7385: }
7386: }
7387: } else {
7388: if ($quotahash{'quotas'}{$item} ne '') {
7389: if ($defquota eq '') {
7390: $defquota = $quotahash{'quotas'}{$item};
7391: $settingstatus = $item;
7392: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
7393: $defquota = $quotahash{'quotas'}{$item};
7394: $settingstatus = $item;
7395: }
7396: }
7397: }
7398: }
7399: }
7400: if ($defquota eq '') {
7401: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7402: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
7403: } else {
7404: $defquota = $quotahash{'quotas'}{'default'};
7405: }
7406: $settingstatus = 'default';
7407: }
7408: } else {
7409: $settingstatus = 'default';
7410: $defquota = 20;
7411: }
7412: if (wantarray) {
7413: return ($defquota,$settingstatus);
7414: } else {
7415: return $defquota;
7416: }
7417: }
7418:
7419: sub get_secgrprole_info {
7420: my ($cdom,$cnum,$needroles,$type) = @_;
7421: my %sections_count = &get_sections($cdom,$cnum);
7422: my @sections = (sort {$a <=> $b} keys(%sections_count));
7423: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
7424: my @groups = sort(keys(%curr_groups));
7425: my $allroles = [];
7426: my $rolehash;
7427: my $accesshash = {
7428: active => 'Currently has access',
7429: future => 'Will have future access',
7430: previous => 'Previously had access',
7431: };
7432: if ($needroles) {
7433: $rolehash = {'all' => 'all'};
7434: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7435: if (&Apache::lonnet::error(%user_roles)) {
7436: undef(%user_roles);
7437: }
7438: foreach my $item (keys(%user_roles)) {
7439: my ($role)=split(/\:/,$item,2);
7440: if ($role eq 'cr') { next; }
7441: if ($role =~ /^cr/) {
7442: $$rolehash{$role} = (split('/',$role))[3];
7443: } else {
7444: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
7445: }
7446: }
7447: foreach my $key (sort(keys(%{$rolehash}))) {
7448: push(@{$allroles},$key);
7449: }
7450: push (@{$allroles},'st');
7451: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
7452: }
7453: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
7454: }
7455:
7456: sub user_picker {
7457: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
7458: my $currdom = $dom;
7459: my %curr_selected = (
7460: srchin => 'dom',
7461: srchby => 'lastname',
7462: );
7463: my $srchterm;
7464: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
7465: if ($srch->{'srchby'} ne '') {
7466: $curr_selected{'srchby'} = $srch->{'srchby'};
7467: }
7468: if ($srch->{'srchin'} ne '') {
7469: $curr_selected{'srchin'} = $srch->{'srchin'};
7470: }
7471: if ($srch->{'srchtype'} ne '') {
7472: $curr_selected{'srchtype'} = $srch->{'srchtype'};
7473: }
7474: if ($srch->{'srchdomain'} ne '') {
7475: $currdom = $srch->{'srchdomain'};
7476: }
7477: $srchterm = $srch->{'srchterm'};
7478: }
7479: my %lt=&Apache::lonlocal::texthash(
7480: 'usr' => 'Search criteria',
7481: 'doma' => 'Domain/institution to search',
7482: 'uname' => 'username',
7483: 'lastname' => 'last name',
7484: 'lastfirst' => 'last name, first name',
7485: 'crs' => 'in this course',
7486: 'dom' => 'in selected LON-CAPA domain',
7487: 'alc' => 'all LON-CAPA',
7488: 'instd' => 'in institutional directory for selected domain',
7489: 'exact' => 'is',
7490: 'contains' => 'contains',
7491: 'begins' => 'begins with',
7492: 'youm' => "You must include some text to search for.",
7493: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
7494: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
7495: 'yomc' => "You must choose a domain when using an institutional directory search.",
7496: 'ymcd' => "You must choose a domain when using a domain search.",
7497: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
7498: 'whse' => "When searching by last,first you must include at least one character in the first name.",
7499: 'thfo' => "The following need to be corrected before the search can be run:",
7500: );
7501: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
7502: my $srchinsel = ' <select name="srchin">';
7503:
7504: my @srchins = ('crs','dom','alc','instd');
7505:
7506: foreach my $option (@srchins) {
7507: # FIXME 'alc' option unavailable until
7508: # loncreateuser::print_user_query_page()
7509: # has been completed.
7510: next if ($option eq 'alc');
7511: next if ($option eq 'crs' && !$env{'request.course.id'});
7512: if ($curr_selected{'srchin'} eq $option) {
7513: $srchinsel .= '
7514: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7515: } else {
7516: $srchinsel .= '
7517: <option value="'.$option.'">'.$lt{$option}.'</option>';
7518: }
7519: }
7520: $srchinsel .= "\n </select>\n";
7521:
7522: my $srchbysel = ' <select name="srchby">';
7523: foreach my $option ('lastname','lastfirst','uname') {
7524: if ($curr_selected{'srchby'} eq $option) {
7525: $srchbysel .= '
7526: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7527: } else {
7528: $srchbysel .= '
7529: <option value="'.$option.'">'.$lt{$option}.'</option>';
7530: }
7531: }
7532: $srchbysel .= "\n </select>\n";
7533:
7534: my $srchtypesel = ' <select name="srchtype">';
7535: foreach my $option ('begins','contains','exact') {
7536: if ($curr_selected{'srchtype'} eq $option) {
7537: $srchtypesel .= '
7538: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7539: } else {
7540: $srchtypesel .= '
7541: <option value="'.$option.'">'.$lt{$option}.'</option>';
7542: }
7543: }
7544: $srchtypesel .= "\n </select>\n";
7545:
7546: my ($newuserscript,$new_user_create);
7547:
7548: if ($forcenewuser) {
7549: if (ref($srch) eq 'HASH') {
7550: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
7551: if ($cancreate) {
7552: $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>';
7553: } else {
7554: my $helplink = 'javascript:helpMenu('."'display'".')';
7555: my %usertypetext = (
7556: official => 'institutional',
7557: unofficial => 'non-institutional',
7558: );
7559: $new_user_create = '<p class="LC_warning">'
7560: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
7561: .' '
7562: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
7563: ,'<a href="'.$helplink.'">','</a>')
7564: .'</p><br />';
7565: }
7566: }
7567: }
7568:
7569: $newuserscript = <<"ENDSCRIPT";
7570:
7571: function setSearch(createnew,callingForm) {
7572: if (createnew == 1) {
7573: for (var i=0; i<callingForm.srchby.length; i++) {
7574: if (callingForm.srchby.options[i].value == 'uname') {
7575: callingForm.srchby.selectedIndex = i;
7576: }
7577: }
7578: for (var i=0; i<callingForm.srchin.length; i++) {
7579: if ( callingForm.srchin.options[i].value == 'dom') {
7580: callingForm.srchin.selectedIndex = i;
7581: }
7582: }
7583: for (var i=0; i<callingForm.srchtype.length; i++) {
7584: if (callingForm.srchtype.options[i].value == 'exact') {
7585: callingForm.srchtype.selectedIndex = i;
7586: }
7587: }
7588: for (var i=0; i<callingForm.srchdomain.length; i++) {
7589: if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
7590: callingForm.srchdomain.selectedIndex = i;
7591: }
7592: }
7593: }
7594: }
7595: ENDSCRIPT
7596:
7597: }
7598:
7599: my $output = <<"END_BLOCK";
7600: <script type="text/javascript">
7601: // <![CDATA[
7602: function validateEntry(callingForm) {
7603:
7604: var checkok = 1;
7605: var srchin;
7606: for (var i=0; i<callingForm.srchin.length; i++) {
7607: if ( callingForm.srchin[i].checked ) {
7608: srchin = callingForm.srchin[i].value;
7609: }
7610: }
7611:
7612: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
7613: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
7614: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
7615: var srchterm = callingForm.srchterm.value;
7616: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
7617: var msg = "";
7618:
7619: if (srchterm == "") {
7620: checkok = 0;
7621: msg += "$lt{'youm'}\\n";
7622: }
7623:
7624: if (srchtype== 'begins') {
7625: if (srchterm.length < 2) {
7626: checkok = 0;
7627: msg += "$lt{'thte'}\\n";
7628: }
7629: }
7630:
7631: if (srchtype== 'contains') {
7632: if (srchterm.length < 3) {
7633: checkok = 0;
7634: msg += "$lt{'thet'}\\n";
7635: }
7636: }
7637: if (srchin == 'instd') {
7638: if (srchdomain == '') {
7639: checkok = 0;
7640: msg += "$lt{'yomc'}\\n";
7641: }
7642: }
7643: if (srchin == 'dom') {
7644: if (srchdomain == '') {
7645: checkok = 0;
7646: msg += "$lt{'ymcd'}\\n";
7647: }
7648: }
7649: if (srchby == 'lastfirst') {
7650: if (srchterm.indexOf(",") == -1) {
7651: checkok = 0;
7652: msg += "$lt{'whus'}\\n";
7653: }
7654: if (srchterm.indexOf(",") == srchterm.length -1) {
7655: checkok = 0;
7656: msg += "$lt{'whse'}\\n";
7657: }
7658: }
7659: if (checkok == 0) {
7660: alert("$lt{'thfo'}\\n"+msg);
7661: return;
7662: }
7663: if (checkok == 1) {
7664: callingForm.submit();
7665: }
7666: }
7667:
7668: $newuserscript
7669:
7670: // ]]>
7671: </script>
7672:
7673: $new_user_create
7674:
7675: <table>
7676: <tr>
7677: <td>$lt{'doma'}:</td>
7678: <td>$domform</td>
7679: </td>
7680: </tr>
7681: <tr>
7682: <td>$lt{'usr'}:</td>
7683: <td>$srchbysel
7684: $srchtypesel
7685: <input type="text" size="15" name="srchterm" value="$srchterm" />
7686: $srchinsel
7687: </td>
7688: </tr>
7689: </table>
7690: <br />
7691: END_BLOCK
7692:
7693: return $output;
7694: }
7695:
7696: sub user_rule_check {
7697: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
7698: my $response;
7699: if (ref($usershash) eq 'HASH') {
7700: foreach my $user (keys(%{$usershash})) {
7701: my ($uname,$udom) = split(/:/,$user);
7702: next if ($udom eq '' || $uname eq '');
7703: my ($id,$newuser);
7704: if (ref($usershash->{$user}) eq 'HASH') {
7705: $newuser = $usershash->{$user}->{'newuser'};
7706: $id = $usershash->{$user}->{'id'};
7707: }
7708: my $inst_response;
7709: if (ref($checks) eq 'HASH') {
7710: if (defined($checks->{'username'})) {
7711: ($inst_response,%{$inst_results->{$user}}) =
7712: &Apache::lonnet::get_instuser($udom,$uname);
7713: } elsif (defined($checks->{'id'})) {
7714: ($inst_response,%{$inst_results->{$user}}) =
7715: &Apache::lonnet::get_instuser($udom,undef,$id);
7716: }
7717: } else {
7718: ($inst_response,%{$inst_results->{$user}}) =
7719: &Apache::lonnet::get_instuser($udom,$uname);
7720: return;
7721: }
7722: if (!$got_rules->{$udom}) {
7723: my %domconfig = &Apache::lonnet::get_dom('configuration',
7724: ['usercreation'],$udom);
7725: if (ref($domconfig{'usercreation'}) eq 'HASH') {
7726: foreach my $item ('username','id') {
7727: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
7728: $$curr_rules{$udom}{$item} =
7729: $domconfig{'usercreation'}{$item.'_rule'};
7730: }
7731: }
7732: }
7733: $got_rules->{$udom} = 1;
7734: }
7735: foreach my $item (keys(%{$checks})) {
7736: if (ref($$curr_rules{$udom}) eq 'HASH') {
7737: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
7738: if (@{$$curr_rules{$udom}{$item}} > 0) {
7739: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
7740: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
7741: if ($rule_check{$rule}) {
7742: $$rulematch{$user}{$item} = $rule;
7743: if ($inst_response eq 'ok') {
7744: if (ref($inst_results) eq 'HASH') {
7745: if (ref($inst_results->{$user}) eq 'HASH') {
7746: if (keys(%{$inst_results->{$user}}) == 0) {
7747: $$alerts{$item}{$udom}{$uname} = 1;
7748: }
7749: }
7750: }
7751: }
7752: last;
7753: }
7754: }
7755: }
7756: }
7757: }
7758: }
7759: }
7760: }
7761: return;
7762: }
7763:
7764: sub user_rule_formats {
7765: my ($domain,$domdesc,$curr_rules,$check) = @_;
7766: my %text = (
7767: 'username' => 'Usernames',
7768: 'id' => 'IDs',
7769: );
7770: my $output;
7771: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
7772: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
7773: if (@{$ruleorder} > 0) {
7774: $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>';
7775: foreach my $rule (@{$ruleorder}) {
7776: if (ref($curr_rules) eq 'ARRAY') {
7777: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
7778: if (ref($rules->{$rule}) eq 'HASH') {
7779: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
7780: $rules->{$rule}{'desc'}.'</li>';
7781: }
7782: }
7783: }
7784: }
7785: $output .= '</ul>';
7786: }
7787: }
7788: return $output;
7789: }
7790:
7791: sub instrule_disallow_msg {
7792: my ($checkitem,$domdesc,$count,$mode) = @_;
7793: my $response;
7794: my %text = (
7795: item => 'username',
7796: items => 'usernames',
7797: match => 'matches',
7798: do => 'does',
7799: action => 'a username',
7800: one => 'one',
7801: );
7802: if ($count > 1) {
7803: $text{'item'} = 'usernames';
7804: $text{'match'} ='match';
7805: $text{'do'} = 'do';
7806: $text{'action'} = 'usernames',
7807: $text{'one'} = 'ones';
7808: }
7809: if ($checkitem eq 'id') {
7810: $text{'items'} = 'IDs';
7811: $text{'item'} = 'ID';
7812: $text{'action'} = 'an ID';
7813: if ($count > 1) {
7814: $text{'item'} = 'IDs';
7815: $text{'action'} = 'IDs';
7816: }
7817: }
7818: $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 />';
7819: if ($mode eq 'upload') {
7820: if ($checkitem eq 'username') {
7821: $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'}.");
7822: } elsif ($checkitem eq 'id') {
7823: $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.");
7824: }
7825: } elsif ($mode eq 'selfcreate') {
7826: if ($checkitem eq 'id') {
7827: $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.");
7828: }
7829: } else {
7830: if ($checkitem eq 'username') {
7831: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
7832: } elsif ($checkitem eq 'id') {
7833: $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.");
7834: }
7835: }
7836: return $response;
7837: }
7838:
7839: sub personal_data_fieldtitles {
7840: my %fieldtitles = &Apache::lonlocal::texthash (
7841: id => 'Student/Employee ID',
7842: permanentemail => 'E-mail address',
7843: lastname => 'Last Name',
7844: firstname => 'First Name',
7845: middlename => 'Middle Name',
7846: generation => 'Generation',
7847: gen => 'Generation',
7848: inststatus => 'Affiliation',
7849: );
7850: return %fieldtitles;
7851: }
7852:
7853: sub sorted_inst_types {
7854: my ($dom) = @_;
7855: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
7856: my $othertitle = &mt('All users');
7857: if ($env{'request.course.id'}) {
7858: $othertitle = &mt('Any users');
7859: }
7860: my @types;
7861: if (ref($order) eq 'ARRAY') {
7862: @types = @{$order};
7863: }
7864: if (@types == 0) {
7865: if (ref($usertypes) eq 'HASH') {
7866: @types = sort(keys(%{$usertypes}));
7867: }
7868: }
7869: if (keys(%{$usertypes}) > 0) {
7870: $othertitle = &mt('Other users');
7871: }
7872: return ($othertitle,$usertypes,\@types);
7873: }
7874:
7875: sub get_institutional_codes {
7876: my ($settings,$allcourses,$LC_code) = @_;
7877: # Get complete list of course sections to update
7878: my @currsections = ();
7879: my @currxlists = ();
7880: my $coursecode = $$settings{'internal.coursecode'};
7881:
7882: if ($$settings{'internal.sectionnums'} ne '') {
7883: @currsections = split(/,/,$$settings{'internal.sectionnums'});
7884: }
7885:
7886: if ($$settings{'internal.crosslistings'} ne '') {
7887: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
7888: }
7889:
7890: if (@currxlists > 0) {
7891: foreach (@currxlists) {
7892: if (m/^([^:]+):(\w*)$/) {
7893: unless (grep/^$1$/,@{$allcourses}) {
7894: push @{$allcourses},$1;
7895: $$LC_code{$1} = $2;
7896: }
7897: }
7898: }
7899: }
7900:
7901: if (@currsections > 0) {
7902: foreach (@currsections) {
7903: if (m/^(\w+):(\w*)$/) {
7904: my $sec = $coursecode.$1;
7905: my $lc_sec = $2;
7906: unless (grep/^$sec$/,@{$allcourses}) {
7907: push @{$allcourses},$sec;
7908: $$LC_code{$sec} = $lc_sec;
7909: }
7910: }
7911: }
7912: }
7913: return;
7914: }
7915:
7916: =pod
7917:
7918: =head1 Slot Helpers
7919:
7920: =over 4
7921:
7922: =item * sorted_slots()
7923:
7924: Sorts an array of slot names in order of slot start time (earliest first).
7925:
7926: Inputs:
7927:
7928: =over 4
7929:
7930: slotsarr - Reference to array of unsorted slot names.
7931:
7932: slots - Reference to hash of hash, where outer hash keys are slot names.
7933:
7934: =back
7935:
7936: Returns:
7937:
7938: =over 4
7939:
7940: sorted - An array of slot names sorted by the start time of the slot.
7941:
7942: =back
7943:
7944: =back
7945:
7946: =cut
7947:
7948:
7949: sub sorted_slots {
7950: my ($slotsarr,$slots) = @_;
7951: my @sorted;
7952: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
7953: @sorted =
7954: sort {
7955: if (ref($slots->{$a}) && ref($slots->{$b})) {
7956: return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
7957: }
7958: if (ref($slots->{$a})) { return -1;}
7959: if (ref($slots->{$b})) { return 1;}
7960: return 0;
7961: } @{$slotsarr};
7962: }
7963: return @sorted;
7964: }
7965:
7966:
7967: =pod
7968:
7969: =head1 HTTP Helpers
7970:
7971: =over 4
7972:
7973: =item * &get_unprocessed_cgi($query,$possible_names)
7974:
7975: Modify the %env hash to contain unprocessed CGI form parameters held in
7976: $query. The parameters listed in $possible_names (an array reference),
7977: will be set in $env{'form.name'} if they do not already exist.
7978:
7979: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
7980: $possible_names is an ref to an array of form element names. As an example:
7981: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
7982: will result in $env{'form.uname'} and $env{'form.udom'} being set.
7983:
7984: =cut
7985:
7986: sub get_unprocessed_cgi {
7987: my ($query,$possible_names)= @_;
7988: # $Apache::lonxml::debug=1;
7989: foreach my $pair (split(/&/,$query)) {
7990: my ($name, $value) = split(/=/,$pair);
7991: $name = &unescape($name);
7992: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
7993: $value =~ tr/+/ /;
7994: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
7995: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
7996: }
7997: }
7998: }
7999:
8000: =pod
8001:
8002: =item * &cacheheader()
8003:
8004: returns cache-controlling header code
8005:
8006: =cut
8007:
8008: sub cacheheader {
8009: unless ($env{'request.method'} eq 'GET') { return ''; }
8010: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
8011: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
8012: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
8013: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
8014: return $output;
8015: }
8016:
8017: =pod
8018:
8019: =item * &no_cache($r)
8020:
8021: specifies header code to not have cache
8022:
8023: =cut
8024:
8025: sub no_cache {
8026: my ($r) = @_;
8027: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
8028: $env{'request.method'} ne 'GET') { return ''; }
8029: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
8030: $r->no_cache(1);
8031: $r->header_out("Expires" => $date);
8032: $r->header_out("Pragma" => "no-cache");
8033: }
8034:
8035: sub content_type {
8036: my ($r,$type,$charset) = @_;
8037: if ($r) {
8038: # Note that printout.pl calls this with undef for $r.
8039: &no_cache($r);
8040: }
8041: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
8042: unless ($charset) {
8043: $charset=&Apache::lonlocal::current_encoding;
8044: }
8045: if ($charset) { $type.='; charset='.$charset; }
8046: if ($r) {
8047: $r->content_type($type);
8048: } else {
8049: print("Content-type: $type\n\n");
8050: }
8051: }
8052:
8053: =pod
8054:
8055: =item * &add_to_env($name,$value)
8056:
8057: adds $name to the %env hash with value
8058: $value, if $name already exists, the entry is converted to an array
8059: reference and $value is added to the array.
8060:
8061: =cut
8062:
8063: sub add_to_env {
8064: my ($name,$value)=@_;
8065: if (defined($env{$name})) {
8066: if (ref($env{$name})) {
8067: #already have multiple values
8068: push(@{ $env{$name} },$value);
8069: } else {
8070: #first time seeing multiple values, convert hash entry to an arrayref
8071: my $first=$env{$name};
8072: undef($env{$name});
8073: push(@{ $env{$name} },$first,$value);
8074: }
8075: } else {
8076: $env{$name}=$value;
8077: }
8078: }
8079:
8080: =pod
8081:
8082: =item * &get_env_multiple($name)
8083:
8084: gets $name from the %env hash, it seemlessly handles the cases where multiple
8085: values may be defined and end up as an array ref.
8086:
8087: returns an array of values
8088:
8089: =cut
8090:
8091: sub get_env_multiple {
8092: my ($name) = @_;
8093: my @values;
8094: if (defined($env{$name})) {
8095: # exists is it an array
8096: if (ref($env{$name})) {
8097: @values=@{ $env{$name} };
8098: } else {
8099: $values[0]=$env{$name};
8100: }
8101: }
8102: return(@values);
8103: }
8104:
8105: sub ask_for_embedded_content {
8106: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
8107: my $upload_output = '
8108: <form name="upload_embedded" action="'.$actionurl.'"
8109: method="post" enctype="multipart/form-data">';
8110: $upload_output .= $state;
8111: $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
8112:
8113: my $num = 0;
8114: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
8115: $upload_output .= &start_data_table_row().
8116: '<td>'.$embed_file.'</td><td>';
8117: if ($args->{'ignore_remote_references'}
8118: && $embed_file =~ m{^\w+://}) {
8119: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
8120: } elsif ($args->{'error_on_invalid_names'}
8121: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
8122:
8123: $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
8124:
8125: } else {
8126: $upload_output .='
8127: <input name="embedded_item_'.$num.'" type="file" value="" />
8128: <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
8129: my $attrib = join(':',@{$$allfiles{$embed_file}});
8130: $upload_output .=
8131: "\n\t\t".
8132: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
8133: $attrib.'" />';
8134: if (exists($$codebase{$embed_file})) {
8135: $upload_output .=
8136: "\n\t\t".
8137: '<input name="codebase_'.$num.'" type="hidden" value="'.
8138: &escape($$codebase{$embed_file}).'" />';
8139: }
8140: }
8141: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
8142: $num++;
8143: }
8144: $upload_output .= &Apache::loncommon::end_data_table().'<br />
8145: <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
8146: <input type ="submit" value="'.&mt('Upload Listed Files').'" />
8147: '.&mt('(only files for which a location has been provided will be uploaded)').'
8148: </form>';
8149: return $upload_output;
8150: }
8151:
8152: sub upload_embedded {
8153: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
8154: $current_disk_usage) = @_;
8155: my $output;
8156: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
8157: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
8158: my $orig_uploaded_filename =
8159: $env{'form.embedded_item_'.$i.'.filename'};
8160:
8161: $env{'form.embedded_orig_'.$i} =
8162: &unescape($env{'form.embedded_orig_'.$i});
8163: my ($path,$fname) =
8164: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
8165: # no path, whole string is fname
8166: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
8167:
8168: $path = $env{'form.currentpath'}.$path;
8169: $fname = &Apache::lonnet::clean_filename($fname);
8170: # See if there is anything left
8171: next if ($fname eq '');
8172:
8173: # Check if file already exists as a file or directory.
8174: my ($state,$msg);
8175: if ($context eq 'portfolio') {
8176: my $port_path = $dirpath;
8177: if ($group ne '') {
8178: $port_path = "groups/$group/$port_path";
8179: }
8180: ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
8181: $dir_root,$port_path,$disk_quota,
8182: $current_disk_usage,$uname,$udom);
8183: if ($state eq 'will_exceed_quota'
8184: || $state eq 'file_locked'
8185: || $state eq 'file_exists' ) {
8186: $output .= $msg;
8187: next;
8188: }
8189: } elsif (($context eq 'author') || ($context eq 'testbank')) {
8190: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
8191: if ($state eq 'exists') {
8192: $output .= $msg;
8193: next;
8194: }
8195: }
8196: # Check if extension is valid
8197: if (($fname =~ /\.(\w+)$/) &&
8198: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
8199: $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
8200: next;
8201: } elsif (($fname =~ /\.(\w+)$/) &&
8202: (!defined(&Apache::loncommon::fileembstyle($1)))) {
8203: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
8204: next;
8205: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
8206: $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
8207: next;
8208: }
8209:
8210: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
8211: if ($context eq 'portfolio') {
8212: my $result=
8213: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
8214: $dirpath.$path);
8215: if ($result !~ m|^/uploaded/|) {
8216: $output .= '<span class="LC_error">'
8217: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
8218: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
8219: .'</span><br />';
8220: next;
8221: } else {
8222: $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
8223: $path.$fname.'</span>').'</p>';
8224: }
8225: } else {
8226: # Save the file
8227: my $target = $env{'form.embedded_item_'.$i};
8228: my $fullpath = $dir_root.$dirpath.'/'.$path;
8229: my $dest = $fullpath.$fname;
8230: my $url = $url_root.$dirpath.'/'.$path.$fname;
8231: my @parts=split(/\//,$fullpath);
8232: my $count;
8233: my $filepath = $dir_root;
8234: for ($count=4;$count<=$#parts;$count++) {
8235: $filepath .= "/$parts[$count]";
8236: if ((-e $filepath)!=1) {
8237: mkdir($filepath,0770);
8238: }
8239: }
8240: my $fh;
8241: if (!open($fh,'>'.$dest)) {
8242: &Apache::lonnet::logthis('Failed to create '.$dest);
8243: $output .= '<span class="LC_error">'.
8244: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8245: '</span><br />';
8246: } else {
8247: if (!print $fh $env{'form.embedded_item_'.$i}) {
8248: &Apache::lonnet::logthis('Failed to write to '.$dest);
8249: $output .= '<span class="LC_error">'.
8250: &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8251: '</span><br />';
8252: } else {
8253: if ($context eq 'testbank') {
8254: $output .= &mt('Embedded file uploaded successfully:').
8255: ' <a href="'.$url.'">'.
8256: $orig_uploaded_filename.'</a><br />';
8257: } else {
8258: $output .= '<span class=\"LC_fontsize_large\">'.
8259: &mt('View embedded file: [_1]','<a href="'.$url.'">'.
8260: $orig_uploaded_filename.'</a>').'</span><br />';
8261: }
8262: }
8263: close($fh);
8264: }
8265: }
8266: }
8267: return $output;
8268: }
8269:
8270: sub check_for_existing {
8271: my ($path,$fname,$element) = @_;
8272: my ($state,$msg);
8273: if (-d $path.'/'.$fname) {
8274: $state = 'exists';
8275: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
8276: } elsif (-e $path.'/'.$fname) {
8277: $state = 'exists';
8278: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
8279: }
8280: if ($state eq 'exists') {
8281: $msg = '<span class="LC_error">'.$msg.'</span><br />';
8282: }
8283: return ($state,$msg);
8284: }
8285:
8286: sub check_for_upload {
8287: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
8288: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
8289: my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
8290: my $getpropath = 1;
8291: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
8292: $getpropath);
8293: my $found_file = 0;
8294: my $locked_file = 0;
8295: foreach my $line (@dir_list) {
8296: my ($file_name)=split(/\&/,$line,2);
8297: if ($file_name eq $fname){
8298: $file_name = $path.$file_name;
8299: if ($group ne '') {
8300: $file_name = $group.$file_name;
8301: }
8302: $found_file = 1;
8303: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
8304: $locked_file = 1;
8305: }
8306: }
8307: }
8308: if (($current_disk_usage + $filesize) > $disk_quota){
8309: my $msg = '<span class="LC_error">'.
8310: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
8311: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
8312: return ('will_exceed_quota',$msg);
8313: } elsif ($found_file) {
8314: if ($locked_file) {
8315: my $msg = '<span class="LC_error">';
8316: $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>');
8317: $msg .= '</span><br />';
8318: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
8319: return ('file_locked',$msg);
8320: } else {
8321: my $msg = '<span class="LC_error">';
8322: $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'});
8323: $msg .= '</span>';
8324: $msg .= '<br />';
8325: $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
8326: return ('file_exists',$msg);
8327: }
8328: }
8329: }
8330:
8331:
8332: =pod
8333:
8334: =back
8335:
8336: =head1 CSV Upload/Handling functions
8337:
8338: =over 4
8339:
8340: =item * &upfile_store($r)
8341:
8342: Store uploaded file, $r should be the HTTP Request object,
8343: needs $env{'form.upfile'}
8344: returns $datatoken to be put into hidden field
8345:
8346: =cut
8347:
8348: sub upfile_store {
8349: my $r=shift;
8350: $env{'form.upfile'}=~s/\r/\n/gs;
8351: $env{'form.upfile'}=~s/\f/\n/gs;
8352: $env{'form.upfile'}=~s/\n+/\n/gs;
8353: $env{'form.upfile'}=~s/\n+$//gs;
8354:
8355: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
8356: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
8357: {
8358: my $datafile = $r->dir_config('lonDaemons').
8359: '/tmp/'.$datatoken.'.tmp';
8360: if ( open(my $fh,">$datafile") ) {
8361: print $fh $env{'form.upfile'};
8362: close($fh);
8363: }
8364: }
8365: return $datatoken;
8366: }
8367:
8368: =pod
8369:
8370: =item * &load_tmp_file($r)
8371:
8372: Load uploaded file from tmp, $r should be the HTTP Request object,
8373: needs $env{'form.datatoken'},
8374: sets $env{'form.upfile'} to the contents of the file
8375:
8376: =cut
8377:
8378: sub load_tmp_file {
8379: my $r=shift;
8380: my @studentdata=();
8381: {
8382: my $studentfile = $r->dir_config('lonDaemons').
8383: '/tmp/'.$env{'form.datatoken'}.'.tmp';
8384: if ( open(my $fh,"<$studentfile") ) {
8385: @studentdata=<$fh>;
8386: close($fh);
8387: }
8388: }
8389: $env{'form.upfile'}=join('',@studentdata);
8390: }
8391:
8392: =pod
8393:
8394: =item * &upfile_record_sep()
8395:
8396: Separate uploaded file into records
8397: returns array of records,
8398: needs $env{'form.upfile'} and $env{'form.upfiletype'}
8399:
8400: =cut
8401:
8402: sub upfile_record_sep {
8403: if ($env{'form.upfiletype'} eq 'xml') {
8404: } else {
8405: my @records;
8406: foreach my $line (split(/\n/,$env{'form.upfile'})) {
8407: if ($line=~/^\s*$/) { next; }
8408: push(@records,$line);
8409: }
8410: return @records;
8411: }
8412: }
8413:
8414: =pod
8415:
8416: =item * &record_sep($record)
8417:
8418: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
8419:
8420: =cut
8421:
8422: sub takeleft {
8423: my $index=shift;
8424: return substr('0000'.$index,-4,4);
8425: }
8426:
8427: sub record_sep {
8428: my $record=shift;
8429: my %components=();
8430: if ($env{'form.upfiletype'} eq 'xml') {
8431: } elsif ($env{'form.upfiletype'} eq 'space') {
8432: my $i=0;
8433: foreach my $field (split(/\s+/,$record)) {
8434: $field=~s/^(\"|\')//;
8435: $field=~s/(\"|\')$//;
8436: $components{&takeleft($i)}=$field;
8437: $i++;
8438: }
8439: } elsif ($env{'form.upfiletype'} eq 'tab') {
8440: my $i=0;
8441: foreach my $field (split(/\t/,$record)) {
8442: $field=~s/^(\"|\')//;
8443: $field=~s/(\"|\')$//;
8444: $components{&takeleft($i)}=$field;
8445: $i++;
8446: }
8447: } else {
8448: my $separator=',';
8449: if ($env{'form.upfiletype'} eq 'semisv') {
8450: $separator=';';
8451: }
8452: my $i=0;
8453: # the character we are looking for to indicate the end of a quote or a record
8454: my $looking_for=$separator;
8455: # do not add the characters to the fields
8456: my $ignore=0;
8457: # we just encountered a separator (or the beginning of the record)
8458: my $just_found_separator=1;
8459: # store the field we are working on here
8460: my $field='';
8461: # work our way through all characters in record
8462: foreach my $character ($record=~/(.)/g) {
8463: if ($character eq $looking_for) {
8464: if ($character ne $separator) {
8465: # Found the end of a quote, again looking for separator
8466: $looking_for=$separator;
8467: $ignore=1;
8468: } else {
8469: # Found a separator, store away what we got
8470: $components{&takeleft($i)}=$field;
8471: $i++;
8472: $just_found_separator=1;
8473: $ignore=0;
8474: $field='';
8475: }
8476: next;
8477: }
8478: # single or double quotation marks after a separator indicate beginning of a quote
8479: # we are now looking for the end of the quote and need to ignore separators
8480: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
8481: $looking_for=$character;
8482: next;
8483: }
8484: # ignore would be true after we reached the end of a quote
8485: if ($ignore) { next; }
8486: if (($just_found_separator) && ($character=~/\s/)) { next; }
8487: $field.=$character;
8488: $just_found_separator=0;
8489: }
8490: # catch the very last entry, since we never encountered the separator
8491: $components{&takeleft($i)}=$field;
8492: }
8493: return %components;
8494: }
8495:
8496: ######################################################
8497: ######################################################
8498:
8499: =pod
8500:
8501: =item * &upfile_select_html()
8502:
8503: Return HTML code to select a file from the users machine and specify
8504: the file type.
8505:
8506: =cut
8507:
8508: ######################################################
8509: ######################################################
8510: sub upfile_select_html {
8511: my %Types = (
8512: csv => &mt('CSV (comma separated values, spreadsheet)'),
8513: semisv => &mt('Semicolon separated values'),
8514: space => &mt('Space separated'),
8515: tab => &mt('Tabulator separated'),
8516: # xml => &mt('HTML/XML'),
8517: );
8518: my $Str = '<input type="file" name="upfile" size="50" />'.
8519: '<br />'.&mt('Type').': <select name="upfiletype">';
8520: foreach my $type (sort(keys(%Types))) {
8521: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
8522: }
8523: $Str .= "</select>\n";
8524: return $Str;
8525: }
8526:
8527: sub get_samples {
8528: my ($records,$toget) = @_;
8529: my @samples=({});
8530: my $got=0;
8531: foreach my $rec (@$records) {
8532: my %temp = &record_sep($rec);
8533: if (! grep(/\S/, values(%temp))) { next; }
8534: if (%temp) {
8535: $samples[$got]=\%temp;
8536: $got++;
8537: if ($got == $toget) { last; }
8538: }
8539: }
8540: return \@samples;
8541: }
8542:
8543: ######################################################
8544: ######################################################
8545:
8546: =pod
8547:
8548: =item * &csv_print_samples($r,$records)
8549:
8550: Prints a table of sample values from each column uploaded $r is an
8551: Apache Request ref, $records is an arrayref from
8552: &Apache::loncommon::upfile_record_sep
8553:
8554: =cut
8555:
8556: ######################################################
8557: ######################################################
8558: sub csv_print_samples {
8559: my ($r,$records) = @_;
8560: my $samples = &get_samples($records,5);
8561:
8562: $r->print(&mt('Samples').'<br />'.&start_data_table().
8563: &start_data_table_header_row());
8564: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8565: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
8566: $r->print(&end_data_table_header_row());
8567: foreach my $hash (@$samples) {
8568: $r->print(&start_data_table_row());
8569: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8570: $r->print('<td>');
8571: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
8572: $r->print('</td>');
8573: }
8574: $r->print(&end_data_table_row());
8575: }
8576: $r->print(&end_data_table().'<br />'."\n");
8577: }
8578:
8579: ######################################################
8580: ######################################################
8581:
8582: =pod
8583:
8584: =item * &csv_print_select_table($r,$records,$d)
8585:
8586: Prints a table to create associations between values and table columns.
8587:
8588: $r is an Apache Request ref,
8589: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
8590: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
8591:
8592: =cut
8593:
8594: ######################################################
8595: ######################################################
8596: sub csv_print_select_table {
8597: my ($r,$records,$d) = @_;
8598: my $i=0;
8599: my $samples = &get_samples($records,1);
8600: $r->print(&mt('Associate columns with student attributes.')."\n".
8601: &start_data_table().&start_data_table_header_row().
8602: '<th>'.&mt('Attribute').'</th>'.
8603: '<th>'.&mt('Column').'</th>'.
8604: &end_data_table_header_row()."\n");
8605: foreach my $array_ref (@$d) {
8606: my ($value,$display,$defaultcol)=@{ $array_ref };
8607: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
8608:
8609: $r->print('<td><select name=f'.$i.
8610: ' onchange="javascript:flip(this.form,'.$i.');">');
8611: $r->print('<option value="none"></option>');
8612: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8613: $r->print('<option value="'.$sample.'"'.
8614: ($sample eq $defaultcol ? ' selected="selected" ' : '').
8615: '>'.&mt('Column [_1]',($sample+1)).'</option>');
8616: }
8617: $r->print('</select></td>'.&end_data_table_row()."\n");
8618: $i++;
8619: }
8620: $r->print(&end_data_table());
8621: $i--;
8622: return $i;
8623: }
8624:
8625: ######################################################
8626: ######################################################
8627:
8628: =pod
8629:
8630: =item * &csv_samples_select_table($r,$records,$d)
8631:
8632: Prints a table of sample values from the upload and can make associate samples to internal names.
8633:
8634: $r is an Apache Request ref,
8635: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
8636: $d is an array of 2 element arrays (internal name, displayed name)
8637:
8638: =cut
8639:
8640: ######################################################
8641: ######################################################
8642: sub csv_samples_select_table {
8643: my ($r,$records,$d) = @_;
8644: my $i=0;
8645: #
8646: my $max_samples = 5;
8647: my $samples = &get_samples($records,$max_samples);
8648: $r->print(&start_data_table().
8649: &start_data_table_header_row().'<th>'.
8650: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
8651: &end_data_table_header_row());
8652:
8653: foreach my $key (sort(keys(%{ $samples->[0] }))) {
8654: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
8655: ' onchange="javascript:flip(this.form,'.$i.');">');
8656: foreach my $option (@$d) {
8657: my ($value,$display,$defaultcol)=@{ $option };
8658: $r->print('<option value="'.$value.'"'.
8659: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
8660: $display.'</option>');
8661: }
8662: $r->print('</select></td><td>');
8663: foreach my $line (0..($max_samples-1)) {
8664: if (defined($samples->[$line]{$key})) {
8665: $r->print($samples->[$line]{$key}."<br />\n");
8666: }
8667: }
8668: $r->print('</td>'.&end_data_table_row());
8669: $i++;
8670: }
8671: $r->print(&end_data_table());
8672: $i--;
8673: return($i);
8674: }
8675:
8676: ######################################################
8677: ######################################################
8678:
8679: =pod
8680:
8681: =item * &clean_excel_name($name)
8682:
8683: Returns a replacement for $name which does not contain any illegal characters.
8684:
8685: =cut
8686:
8687: ######################################################
8688: ######################################################
8689: sub clean_excel_name {
8690: my ($name) = @_;
8691: $name =~ s/[:\*\?\/\\]//g;
8692: if (length($name) > 31) {
8693: $name = substr($name,0,31);
8694: }
8695: return $name;
8696: }
8697:
8698: =pod
8699:
8700: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
8701:
8702: Returns either 1 or undef
8703:
8704: 1 if the part is to be hidden, undef if it is to be shown
8705:
8706: Arguments are:
8707:
8708: $id the id of the part to be checked
8709: $symb, optional the symb of the resource to check
8710: $udom, optional the domain of the user to check for
8711: $uname, optional the username of the user to check for
8712:
8713: =cut
8714:
8715: sub check_if_partid_hidden {
8716: my ($id,$symb,$udom,$uname) = @_;
8717: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
8718: $symb,$udom,$uname);
8719: my $truth=1;
8720: #if the string starts with !, then the list is the list to show not hide
8721: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
8722: my @hiddenlist=split(/,/,$hiddenparts);
8723: foreach my $checkid (@hiddenlist) {
8724: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
8725: }
8726: return !$truth;
8727: }
8728:
8729:
8730: ############################################################
8731: ############################################################
8732:
8733: =pod
8734:
8735: =back
8736:
8737: =head1 cgi-bin script and graphing routines
8738:
8739: =over 4
8740:
8741: =item * &get_cgi_id()
8742:
8743: Inputs: none
8744:
8745: Returns an id which can be used to pass environment variables
8746: to various cgi-bin scripts. These environment variables will
8747: be removed from the users environment after a given time by
8748: the routine &Apache::lonnet::transfer_profile_to_env.
8749:
8750: =cut
8751:
8752: ############################################################
8753: ############################################################
8754: my $uniq=0;
8755: sub get_cgi_id {
8756: $uniq=($uniq+1)%100000;
8757: return (time.'_'.$$.'_'.$uniq);
8758: }
8759:
8760: ############################################################
8761: ############################################################
8762:
8763: =pod
8764:
8765: =item * &DrawBarGraph()
8766:
8767: Facilitates the plotting of data in a (stacked) bar graph.
8768: Puts plot definition data into the users environment in order for
8769: graph.png to plot it. Returns an <img> tag for the plot.
8770: The bars on the plot are labeled '1','2',...,'n'.
8771:
8772: Inputs:
8773:
8774: =over 4
8775:
8776: =item $Title: string, the title of the plot
8777:
8778: =item $xlabel: string, text describing the X-axis of the plot
8779:
8780: =item $ylabel: string, text describing the Y-axis of the plot
8781:
8782: =item $Max: scalar, the maximum Y value to use in the plot
8783: If $Max is < any data point, the graph will not be rendered.
8784:
8785: =item $colors: array ref holding the colors to be used for the data sets when
8786: they are plotted. If undefined, default values will be used.
8787:
8788: =item $labels: array ref holding the labels to use on the x-axis for the bars.
8789:
8790: =item @Values: An array of array references. Each array reference holds data
8791: to be plotted in a stacked bar chart.
8792:
8793: =item If the final element of @Values is a hash reference the key/value
8794: pairs will be added to the graph definition.
8795:
8796: =back
8797:
8798: Returns:
8799:
8800: An <img> tag which references graph.png and the appropriate identifying
8801: information for the plot.
8802:
8803: =cut
8804:
8805: ############################################################
8806: ############################################################
8807: sub DrawBarGraph {
8808: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
8809: #
8810: if (! defined($colors)) {
8811: $colors = ['#33ff00',
8812: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
8813: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
8814: ];
8815: }
8816: my $extra_settings = {};
8817: if (ref($Values[-1]) eq 'HASH') {
8818: $extra_settings = pop(@Values);
8819: }
8820: #
8821: my $identifier = &get_cgi_id();
8822: my $id = 'cgi.'.$identifier;
8823: if (! @Values || ref($Values[0]) ne 'ARRAY') {
8824: return '';
8825: }
8826: #
8827: my @Labels;
8828: if (defined($labels)) {
8829: @Labels = @$labels;
8830: } else {
8831: for (my $i=0;$i<@{$Values[0]};$i++) {
8832: push (@Labels,$i+1);
8833: }
8834: }
8835: #
8836: my $NumBars = scalar(@{$Values[0]});
8837: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
8838: my %ValuesHash;
8839: my $NumSets=1;
8840: foreach my $array (@Values) {
8841: next if (! ref($array));
8842: $ValuesHash{$id.'.data.'.$NumSets++} =
8843: join(',',@$array);
8844: }
8845: #
8846: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
8847: if ($NumBars < 3) {
8848: $width = 120+$NumBars*32;
8849: $xskip = 1;
8850: $bar_width = 30;
8851: } elsif ($NumBars < 5) {
8852: $width = 120+$NumBars*20;
8853: $xskip = 1;
8854: $bar_width = 20;
8855: } elsif ($NumBars < 10) {
8856: $width = 120+$NumBars*15;
8857: $xskip = 1;
8858: $bar_width = 15;
8859: } elsif ($NumBars <= 25) {
8860: $width = 120+$NumBars*11;
8861: $xskip = 5;
8862: $bar_width = 8;
8863: } elsif ($NumBars <= 50) {
8864: $width = 120+$NumBars*8;
8865: $xskip = 5;
8866: $bar_width = 4;
8867: } else {
8868: $width = 120+$NumBars*8;
8869: $xskip = 5;
8870: $bar_width = 4;
8871: }
8872: #
8873: $Max = 1 if ($Max < 1);
8874: if ( int($Max) < $Max ) {
8875: $Max++;
8876: $Max = int($Max);
8877: }
8878: $Title = '' if (! defined($Title));
8879: $xlabel = '' if (! defined($xlabel));
8880: $ylabel = '' if (! defined($ylabel));
8881: $ValuesHash{$id.'.title'} = &escape($Title);
8882: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
8883: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
8884: $ValuesHash{$id.'.y_max_value'} = $Max;
8885: $ValuesHash{$id.'.NumBars'} = $NumBars;
8886: $ValuesHash{$id.'.NumSets'} = $NumSets;
8887: $ValuesHash{$id.'.PlotType'} = 'bar';
8888: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8889: $ValuesHash{$id.'.height'} = $height;
8890: $ValuesHash{$id.'.width'} = $width;
8891: $ValuesHash{$id.'.xskip'} = $xskip;
8892: $ValuesHash{$id.'.bar_width'} = $bar_width;
8893: $ValuesHash{$id.'.labels'} = join(',',@Labels);
8894: #
8895: # Deal with other parameters
8896: while (my ($key,$value) = each(%$extra_settings)) {
8897: $ValuesHash{$id.'.'.$key} = $value;
8898: }
8899: #
8900: &Apache::lonnet::appenv(\%ValuesHash);
8901: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8902: }
8903:
8904: ############################################################
8905: ############################################################
8906:
8907: =pod
8908:
8909: =item * &DrawXYGraph()
8910:
8911: Facilitates the plotting of data in an XY graph.
8912: Puts plot definition data into the users environment in order for
8913: graph.png to plot it. Returns an <img> tag for the plot.
8914:
8915: Inputs:
8916:
8917: =over 4
8918:
8919: =item $Title: string, the title of the plot
8920:
8921: =item $xlabel: string, text describing the X-axis of the plot
8922:
8923: =item $ylabel: string, text describing the Y-axis of the plot
8924:
8925: =item $Max: scalar, the maximum Y value to use in the plot
8926: If $Max is < any data point, the graph will not be rendered.
8927:
8928: =item $colors: Array ref containing the hex color codes for the data to be
8929: plotted in. If undefined, default values will be used.
8930:
8931: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8932:
8933: =item $Ydata: Array ref containing Array refs.
8934: Each of the contained arrays will be plotted as a separate curve.
8935:
8936: =item %Values: hash indicating or overriding any default values which are
8937: passed to graph.png.
8938: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
8939:
8940: =back
8941:
8942: Returns:
8943:
8944: An <img> tag which references graph.png and the appropriate identifying
8945: information for the plot.
8946:
8947: =cut
8948:
8949: ############################################################
8950: ############################################################
8951: sub DrawXYGraph {
8952: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
8953: #
8954: # Create the identifier for the graph
8955: my $identifier = &get_cgi_id();
8956: my $id = 'cgi.'.$identifier;
8957: #
8958: $Title = '' if (! defined($Title));
8959: $xlabel = '' if (! defined($xlabel));
8960: $ylabel = '' if (! defined($ylabel));
8961: my %ValuesHash =
8962: (
8963: $id.'.title' => &escape($Title),
8964: $id.'.xlabel' => &escape($xlabel),
8965: $id.'.ylabel' => &escape($ylabel),
8966: $id.'.y_max_value'=> $Max,
8967: $id.'.labels' => join(',',@$Xlabels),
8968: $id.'.PlotType' => 'XY',
8969: );
8970: #
8971: if (defined($colors) && ref($colors) eq 'ARRAY') {
8972: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8973: }
8974: #
8975: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
8976: return '';
8977: }
8978: my $NumSets=1;
8979: foreach my $array (@{$Ydata}){
8980: next if (! ref($array));
8981: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
8982: }
8983: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
8984: #
8985: # Deal with other parameters
8986: while (my ($key,$value) = each(%Values)) {
8987: $ValuesHash{$id.'.'.$key} = $value;
8988: }
8989: #
8990: &Apache::lonnet::appenv(\%ValuesHash);
8991: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8992: }
8993:
8994: ############################################################
8995: ############################################################
8996:
8997: =pod
8998:
8999: =item * &DrawXYYGraph()
9000:
9001: Facilitates the plotting of data in an XY graph with two Y axes.
9002: Puts plot definition data into the users environment in order for
9003: graph.png to plot it. Returns an <img> tag for the plot.
9004:
9005: Inputs:
9006:
9007: =over 4
9008:
9009: =item $Title: string, the title of the plot
9010:
9011: =item $xlabel: string, text describing the X-axis of the plot
9012:
9013: =item $ylabel: string, text describing the Y-axis of the plot
9014:
9015: =item $colors: Array ref containing the hex color codes for the data to be
9016: plotted in. If undefined, default values will be used.
9017:
9018: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
9019:
9020: =item $Ydata1: The first data set
9021:
9022: =item $Min1: The minimum value of the left Y-axis
9023:
9024: =item $Max1: The maximum value of the left Y-axis
9025:
9026: =item $Ydata2: The second data set
9027:
9028: =item $Min2: The minimum value of the right Y-axis
9029:
9030: =item $Max2: The maximum value of the left Y-axis
9031:
9032: =item %Values: hash indicating or overriding any default values which are
9033: passed to graph.png.
9034: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
9035:
9036: =back
9037:
9038: Returns:
9039:
9040: An <img> tag which references graph.png and the appropriate identifying
9041: information for the plot.
9042:
9043: =cut
9044:
9045: ############################################################
9046: ############################################################
9047: sub DrawXYYGraph {
9048: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
9049: $Ydata2,$Min2,$Max2,%Values)=@_;
9050: #
9051: # Create the identifier for the graph
9052: my $identifier = &get_cgi_id();
9053: my $id = 'cgi.'.$identifier;
9054: #
9055: $Title = '' if (! defined($Title));
9056: $xlabel = '' if (! defined($xlabel));
9057: $ylabel = '' if (! defined($ylabel));
9058: my %ValuesHash =
9059: (
9060: $id.'.title' => &escape($Title),
9061: $id.'.xlabel' => &escape($xlabel),
9062: $id.'.ylabel' => &escape($ylabel),
9063: $id.'.labels' => join(',',@$Xlabels),
9064: $id.'.PlotType' => 'XY',
9065: $id.'.NumSets' => 2,
9066: $id.'.two_axes' => 1,
9067: $id.'.y1_max_value' => $Max1,
9068: $id.'.y1_min_value' => $Min1,
9069: $id.'.y2_max_value' => $Max2,
9070: $id.'.y2_min_value' => $Min2,
9071: );
9072: #
9073: if (defined($colors) && ref($colors) eq 'ARRAY') {
9074: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9075: }
9076: #
9077: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
9078: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
9079: return '';
9080: }
9081: my $NumSets=1;
9082: foreach my $array ($Ydata1,$Ydata2){
9083: next if (! ref($array));
9084: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
9085: }
9086: #
9087: # Deal with other parameters
9088: while (my ($key,$value) = each(%Values)) {
9089: $ValuesHash{$id.'.'.$key} = $value;
9090: }
9091: #
9092: &Apache::lonnet::appenv(\%ValuesHash);
9093: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
9094: }
9095:
9096: ############################################################
9097: ############################################################
9098:
9099: =pod
9100:
9101: =back
9102:
9103: =head1 Statistics helper routines?
9104:
9105: Bad place for them but what the hell.
9106:
9107: =over 4
9108:
9109: =item * &chartlink()
9110:
9111: Returns a link to the chart for a specific student.
9112:
9113: Inputs:
9114:
9115: =over 4
9116:
9117: =item $linktext: The text of the link
9118:
9119: =item $sname: The students username
9120:
9121: =item $sdomain: The students domain
9122:
9123: =back
9124:
9125: =back
9126:
9127: =cut
9128:
9129: ############################################################
9130: ############################################################
9131: sub chartlink {
9132: my ($linktext, $sname, $sdomain) = @_;
9133: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
9134: '&SelectedStudent='.&escape($sname.':'.$sdomain).
9135: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
9136: '">'.$linktext.'</a>';
9137: }
9138:
9139: #######################################################
9140: #######################################################
9141:
9142: =pod
9143:
9144: =head1 Course Environment Routines
9145:
9146: =over 4
9147:
9148: =item * &restore_course_settings()
9149:
9150: =item * &store_course_settings()
9151:
9152: Restores/Store indicated form parameters from the course environment.
9153: Will not overwrite existing values of the form parameters.
9154:
9155: Inputs:
9156: a scalar describing the data (e.g. 'chart', 'problem_analysis')
9157:
9158: a hash ref describing the data to be stored. For example:
9159:
9160: %Save_Parameters = ('Status' => 'scalar',
9161: 'chartoutputmode' => 'scalar',
9162: 'chartoutputdata' => 'scalar',
9163: 'Section' => 'array',
9164: 'Group' => 'array',
9165: 'StudentData' => 'array',
9166: 'Maps' => 'array');
9167:
9168: Returns: both routines return nothing
9169:
9170: =back
9171:
9172: =cut
9173:
9174: #######################################################
9175: #######################################################
9176: sub store_course_settings {
9177: return &store_settings($env{'request.course.id'},@_);
9178: }
9179:
9180: sub store_settings {
9181: # save to the environment
9182: # appenv the same items, just to be safe
9183: my $udom = $env{'user.domain'};
9184: my $uname = $env{'user.name'};
9185: my ($context,$prefix,$Settings) = @_;
9186: my %SaveHash;
9187: my %AppHash;
9188: while (my ($setting,$type) = each(%$Settings)) {
9189: my $basename = join('.','internal',$context,$prefix,$setting);
9190: my $envname = 'environment.'.$basename;
9191: if (exists($env{'form.'.$setting})) {
9192: # Save this value away
9193: if ($type eq 'scalar' &&
9194: (! exists($env{$envname}) ||
9195: $env{$envname} ne $env{'form.'.$setting})) {
9196: $SaveHash{$basename} = $env{'form.'.$setting};
9197: $AppHash{$envname} = $env{'form.'.$setting};
9198: } elsif ($type eq 'array') {
9199: my $stored_form;
9200: if (ref($env{'form.'.$setting})) {
9201: $stored_form = join(',',
9202: map {
9203: &escape($_);
9204: } sort(@{$env{'form.'.$setting}}));
9205: } else {
9206: $stored_form =
9207: &escape($env{'form.'.$setting});
9208: }
9209: # Determine if the array contents are the same.
9210: if ($stored_form ne $env{$envname}) {
9211: $SaveHash{$basename} = $stored_form;
9212: $AppHash{$envname} = $stored_form;
9213: }
9214: }
9215: }
9216: }
9217: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
9218: $udom,$uname);
9219: if ($put_result !~ /^(ok|delayed)/) {
9220: &Apache::lonnet::logthis('unable to save form parameters, '.
9221: 'got error:'.$put_result);
9222: }
9223: # Make sure these settings stick around in this session, too
9224: &Apache::lonnet::appenv(\%AppHash);
9225: return;
9226: }
9227:
9228: sub restore_course_settings {
9229: return &restore_settings($env{'request.course.id'},@_);
9230: }
9231:
9232: sub restore_settings {
9233: my ($context,$prefix,$Settings) = @_;
9234: while (my ($setting,$type) = each(%$Settings)) {
9235: next if (exists($env{'form.'.$setting}));
9236: my $envname = 'environment.internal.'.$context.'.'.$prefix.
9237: '.'.$setting;
9238: if (exists($env{$envname})) {
9239: if ($type eq 'scalar') {
9240: $env{'form.'.$setting} = $env{$envname};
9241: } elsif ($type eq 'array') {
9242: $env{'form.'.$setting} = [
9243: map {
9244: &unescape($_);
9245: } split(',',$env{$envname})
9246: ];
9247: }
9248: }
9249: }
9250: }
9251:
9252: #######################################################
9253: #######################################################
9254:
9255: =pod
9256:
9257: =head1 Domain E-mail Routines
9258:
9259: =over 4
9260:
9261: =item * &build_recipient_list()
9262:
9263: Build recipient lists for four types of e-mail:
9264: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
9265: (d) Help requests, generated by
9266: lonerrorhandler.pm, CHECKRPMS, loncron, and lonsupportreq.pm respectively.
9267:
9268: Inputs:
9269: defmail (scalar - email address of default recipient),
9270: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
9271: defdom (domain for which to retrieve configuration settings),
9272: origmail (scalar - email address of recipient from loncapa.conf,
9273: i.e., predates configuration by DC via domainprefs.pm
9274:
9275: Returns: comma separated list of addresses to which to send e-mail.
9276:
9277: =back
9278:
9279: =cut
9280:
9281: ############################################################
9282: ############################################################
9283: sub build_recipient_list {
9284: my ($defmail,$mailing,$defdom,$origmail) = @_;
9285: my @recipients;
9286: my $otheremails;
9287: my %domconfig =
9288: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
9289: if (ref($domconfig{'contacts'}) eq 'HASH') {
9290: if (exists($domconfig{'contacts'}{$mailing})) {
9291: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
9292: my @contacts = ('adminemail','supportemail');
9293: foreach my $item (@contacts) {
9294: if ($domconfig{'contacts'}{$mailing}{$item}) {
9295: my $addr = $domconfig{'contacts'}{$item};
9296: if (!grep(/^\Q$addr\E$/,@recipients)) {
9297: push(@recipients,$addr);
9298: }
9299: }
9300: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
9301: }
9302: }
9303: } elsif ($origmail ne '') {
9304: push(@recipients,$origmail);
9305: }
9306: } elsif ($origmail ne '') {
9307: push(@recipients,$origmail);
9308: }
9309: if (defined($defmail)) {
9310: if ($defmail ne '') {
9311: push(@recipients,$defmail);
9312: }
9313: }
9314: if ($otheremails) {
9315: my @others;
9316: if ($otheremails =~ /,/) {
9317: @others = split(/,/,$otheremails);
9318: } else {
9319: push(@others,$otheremails);
9320: }
9321: foreach my $addr (@others) {
9322: if (!grep(/^\Q$addr\E$/,@recipients)) {
9323: push(@recipients,$addr);
9324: }
9325: }
9326: }
9327: my $recipientlist = join(',',@recipients);
9328: return $recipientlist;
9329: }
9330:
9331: ############################################################
9332: ############################################################
9333:
9334: =pod
9335:
9336: =head1 Course Catalog Routines
9337:
9338: =over 4
9339:
9340: =item * &gather_categories()
9341:
9342: Converts category definitions - keys of categories hash stored in
9343: coursecategories in configuration.db on the primary library server in a
9344: domain - to an array. Also generates javascript and idx hash used to
9345: generate Domain Coordinator interface for editing Course Categories.
9346:
9347: Inputs:
9348:
9349: categories (reference to hash of category definitions).
9350:
9351: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9352: categories and subcategories).
9353:
9354: idx (reference to hash of counters used in Domain Coordinator interface for
9355: editing Course Categories).
9356:
9357: jsarray (reference to array of categories used to create Javascript arrays for
9358: Domain Coordinator interface for editing Course Categories).
9359:
9360: Returns: nothing
9361:
9362: Side effects: populates cats, idx and jsarray.
9363:
9364: =cut
9365:
9366: sub gather_categories {
9367: my ($categories,$cats,$idx,$jsarray) = @_;
9368: my %counters;
9369: my $num = 0;
9370: foreach my $item (keys(%{$categories})) {
9371: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
9372: if ($container eq '' && $depth == 0) {
9373: $cats->[$depth][$categories->{$item}] = $cat;
9374: } else {
9375: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
9376: }
9377: my ($escitem,$tail) = split(/:/,$item,2);
9378: if ($counters{$tail} eq '') {
9379: $counters{$tail} = $num;
9380: $num ++;
9381: }
9382: if (ref($idx) eq 'HASH') {
9383: $idx->{$item} = $counters{$tail};
9384: }
9385: if (ref($jsarray) eq 'ARRAY') {
9386: push(@{$jsarray->[$counters{$tail}]},$item);
9387: }
9388: }
9389: return;
9390: }
9391:
9392: =pod
9393:
9394: =item * &extract_categories()
9395:
9396: Used to generate breadcrumb trails for course categories.
9397:
9398: Inputs:
9399:
9400: categories (reference to hash of category definitions).
9401:
9402: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9403: categories and subcategories).
9404:
9405: trails (reference to array of breacrumb trails for each category).
9406:
9407: allitems (reference to hash - key is category key
9408: (format: escaped(name):escaped(parent category):depth in hierarchy).
9409:
9410: idx (reference to hash of counters used in Domain Coordinator interface for
9411: editing Course Categories).
9412:
9413: jsarray (reference to array of categories used to create Javascript arrays for
9414: Domain Coordinator interface for editing Course Categories).
9415:
9416: subcats (reference to hash of arrays containing all subcategories within each
9417: category, -recursive)
9418:
9419: Returns: nothing
9420:
9421: Side effects: populates trails and allitems hash references.
9422:
9423: =cut
9424:
9425: sub extract_categories {
9426: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
9427: if (ref($categories) eq 'HASH') {
9428: &gather_categories($categories,$cats,$idx,$jsarray);
9429: if (ref($cats->[0]) eq 'ARRAY') {
9430: for (my $i=0; $i<@{$cats->[0]}; $i++) {
9431: my $name = $cats->[0][$i];
9432: my $item = &escape($name).'::0';
9433: my $trailstr;
9434: if ($name eq 'instcode') {
9435: $trailstr = &mt('Official courses (with institutional codes)');
9436: } else {
9437: $trailstr = $name;
9438: }
9439: if ($allitems->{$item} eq '') {
9440: push(@{$trails},$trailstr);
9441: $allitems->{$item} = scalar(@{$trails})-1;
9442: }
9443: my @parents = ($name);
9444: if (ref($cats->[1]{$name}) eq 'ARRAY') {
9445: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
9446: my $category = $cats->[1]{$name}[$j];
9447: if (ref($subcats) eq 'HASH') {
9448: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
9449: }
9450: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
9451: }
9452: } else {
9453: if (ref($subcats) eq 'HASH') {
9454: $subcats->{$item} = [];
9455: }
9456: }
9457: }
9458: }
9459: }
9460: return;
9461: }
9462:
9463: =pod
9464:
9465: =item *&recurse_categories()
9466:
9467: Recursively used to generate breadcrumb trails for course categories.
9468:
9469: Inputs:
9470:
9471: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9472: categories and subcategories).
9473:
9474: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
9475:
9476: category (current course category, for which breadcrumb trail is being generated).
9477:
9478: trails (reference to array of breadcrumb trails for each category).
9479:
9480: allitems (reference to hash - key is category key
9481: (format: escaped(name):escaped(parent category):depth in hierarchy).
9482:
9483: parents (array containing containers directories for current category,
9484: back to top level).
9485:
9486: Returns: nothing
9487:
9488: Side effects: populates trails and allitems hash references
9489:
9490: =cut
9491:
9492: sub recurse_categories {
9493: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
9494: my $shallower = $depth - 1;
9495: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
9496: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
9497: my $name = $cats->[$depth]{$category}[$k];
9498: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9499: my $trailstr = join(' -> ',(@{$parents},$category));
9500: if ($allitems->{$item} eq '') {
9501: push(@{$trails},$trailstr);
9502: $allitems->{$item} = scalar(@{$trails})-1;
9503: }
9504: my $deeper = $depth+1;
9505: push(@{$parents},$category);
9506: if (ref($subcats) eq 'HASH') {
9507: my $subcat = &escape($name).':'.$category.':'.$depth;
9508: for (my $j=@{$parents}; $j>=0; $j--) {
9509: my $higher;
9510: if ($j > 0) {
9511: $higher = &escape($parents->[$j]).':'.
9512: &escape($parents->[$j-1]).':'.$j;
9513: } else {
9514: $higher = &escape($parents->[$j]).'::'.$j;
9515: }
9516: push(@{$subcats->{$higher}},$subcat);
9517: }
9518: }
9519: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
9520: $subcats);
9521: pop(@{$parents});
9522: }
9523: } else {
9524: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9525: my $trailstr = join(' -> ',(@{$parents},$category));
9526: if ($allitems->{$item} eq '') {
9527: push(@{$trails},$trailstr);
9528: $allitems->{$item} = scalar(@{$trails})-1;
9529: }
9530: }
9531: return;
9532: }
9533:
9534: =pod
9535:
9536: =item *&assign_categories_table()
9537:
9538: Create a datatable for display of hierarchical categories in a domain,
9539: with checkboxes to allow a course to be categorized.
9540:
9541: Inputs:
9542:
9543: cathash - reference to hash of categories defined for the domain (from
9544: configuration.db)
9545:
9546: currcat - scalar with an & separated list of categories assigned to a course.
9547:
9548: Returns: $output (markup to be displayed)
9549:
9550: =cut
9551:
9552: sub assign_categories_table {
9553: my ($cathash,$currcat) = @_;
9554: my $output;
9555: if (ref($cathash) eq 'HASH') {
9556: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
9557: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
9558: $maxdepth = scalar(@cats);
9559: if (@cats > 0) {
9560: my $itemcount = 0;
9561: if (ref($cats[0]) eq 'ARRAY') {
9562: $output = &Apache::loncommon::start_data_table();
9563: my @currcategories;
9564: if ($currcat ne '') {
9565: @currcategories = split('&',$currcat);
9566: }
9567: for (my $i=0; $i<@{$cats[0]}; $i++) {
9568: my $parent = $cats[0][$i];
9569: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9570: next if ($parent eq 'instcode');
9571: my $item = &escape($parent).'::0';
9572: my $checked = '';
9573: if (@currcategories > 0) {
9574: if (grep(/^\Q$item\E$/,@currcategories)) {
9575: $checked = ' checked="checked"';
9576: }
9577: }
9578: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
9579: '<input type="checkbox" name="usecategory" value="'.
9580: $item.'"'.$checked.' />'.$parent.'</span>'.
9581: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
9582: my $depth = 1;
9583: push(@path,$parent);
9584: $output .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
9585: pop(@path);
9586: $output .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
9587: $itemcount ++;
9588: }
9589: $output .= &Apache::loncommon::end_data_table();
9590: }
9591: }
9592: }
9593: return $output;
9594: }
9595:
9596: =pod
9597:
9598: =item *&assign_category_rows()
9599:
9600: Create a datatable row for display of nested categories in a domain,
9601: with checkboxes to allow a course to be categorized,called recursively.
9602:
9603: Inputs:
9604:
9605: itemcount - track row number for alternating colors
9606:
9607: cats - reference to array of arrays/hashes which encapsulates hierarchy of
9608: categories and subcategories.
9609:
9610: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
9611:
9612: parent - parent of current category item
9613:
9614: path - Array containing all categories back up through the hierarchy from the
9615: current category to the top level.
9616:
9617: currcategories - reference to array of current categories assigned to the course
9618:
9619: Returns: $output (markup to be displayed).
9620:
9621: =cut
9622:
9623: sub assign_category_rows {
9624: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
9625: my ($text,$name,$item,$chgstr);
9626: if (ref($cats) eq 'ARRAY') {
9627: my $maxdepth = scalar(@{$cats});
9628: if (ref($cats->[$depth]) eq 'HASH') {
9629: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
9630: my $numchildren = @{$cats->[$depth]{$parent}};
9631: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9632: $text .= '<td><table class="LC_datatable">';
9633: for (my $j=0; $j<$numchildren; $j++) {
9634: $name = $cats->[$depth]{$parent}[$j];
9635: $item = &escape($name).':'.&escape($parent).':'.$depth;
9636: my $deeper = $depth+1;
9637: my $checked = '';
9638: if (ref($currcategories) eq 'ARRAY') {
9639: if (@{$currcategories} > 0) {
9640: if (grep(/^\Q$item\E$/,@{$currcategories})) {
9641: $checked = ' checked="checked"';
9642: }
9643: }
9644: }
9645: $text .= '<tr><td><span class="LC_nobreak"><label>'.
9646: '<input type="checkbox" name="usecategory" value="'.
9647: $item.'"'.$checked.' />'.$name.'</label></span>'.
9648: '<input type="hidden" name="catname" value="'.$name.'" />'.
9649: '</td><td>';
9650: if (ref($path) eq 'ARRAY') {
9651: push(@{$path},$name);
9652: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
9653: pop(@{$path});
9654: }
9655: $text .= '</td></tr>';
9656: }
9657: $text .= '</table></td>';
9658: }
9659: }
9660: }
9661: return $text;
9662: }
9663:
9664: ############################################################
9665: ############################################################
9666:
9667:
9668: sub commit_customrole {
9669: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
9670: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
9671: ($start?', '.&mt('starting').' '.localtime($start):'').
9672: ($end?', ending '.localtime($end):'').': <b>'.
9673: &Apache::lonnet::assigncustomrole(
9674: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
9675: '</b><br />';
9676: return $output;
9677: }
9678:
9679: sub commit_standardrole {
9680: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
9681: my ($output,$logmsg,$linefeed);
9682: if ($context eq 'auto') {
9683: $linefeed = "\n";
9684: } else {
9685: $linefeed = "<br />\n";
9686: }
9687: if ($three eq 'st') {
9688: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
9689: $one,$two,$sec,$context);
9690: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
9691: ($result eq 'unknown_course') || ($result eq 'refused')) {
9692: $output = $logmsg.' '.&mt('Error: ').$result."\n";
9693: } else {
9694: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
9695: ($start?', '.&mt('starting').' '.localtime($start):'').
9696: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
9697: if ($context eq 'auto') {
9698: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
9699: } else {
9700: $output .= '<b>'.$result.'</b>'.$linefeed.
9701: &mt('Add to classlist').': <b>ok</b>';
9702: }
9703: $output .= $linefeed;
9704: }
9705: } else {
9706: $output = &mt('Assigning').' '.$three.' in '.$url.
9707: ($start?', '.&mt('starting').' '.localtime($start):'').
9708: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
9709: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
9710: if ($context eq 'auto') {
9711: $output .= $result.$linefeed;
9712: } else {
9713: $output .= '<b>'.$result.'</b>'.$linefeed;
9714: }
9715: }
9716: return $output;
9717: }
9718:
9719: sub commit_studentrole {
9720: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
9721: my ($result,$linefeed,$oldsecurl,$newsecurl);
9722: if ($context eq 'auto') {
9723: $linefeed = "\n";
9724: } else {
9725: $linefeed = '<br />'."\n";
9726: }
9727: if (defined($one) && defined($two)) {
9728: my $cid=$one.'_'.$two;
9729: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
9730: my $secchange = 0;
9731: my $expire_role_result;
9732: my $modify_section_result;
9733: if ($oldsec ne '-1') {
9734: if ($oldsec ne $sec) {
9735: $secchange = 1;
9736: my $now = time;
9737: my $uurl='/'.$cid;
9738: $uurl=~s/\_/\//g;
9739: if ($oldsec) {
9740: $uurl.='/'.$oldsec;
9741: }
9742: $oldsecurl = $uurl;
9743: $expire_role_result =
9744: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
9745: if ($env{'request.course.sec'} ne '') {
9746: if ($expire_role_result eq 'refused') {
9747: my @roles = ('st');
9748: my @statuses = ('previous');
9749: my @roledoms = ($one);
9750: my $withsec = 1;
9751: my %roleshash =
9752: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
9753: \@statuses,\@roles,\@roledoms,$withsec);
9754: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
9755: my ($oldstart,$oldend) =
9756: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
9757: if ($oldend > 0 && $oldend <= $now) {
9758: $expire_role_result = 'ok';
9759: }
9760: }
9761: }
9762: }
9763: $result = $expire_role_result;
9764: }
9765: }
9766: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
9767: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
9768: if ($modify_section_result =~ /^ok/) {
9769: if ($secchange == 1) {
9770: if ($sec eq '') {
9771: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
9772: } else {
9773: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
9774: }
9775: } elsif ($oldsec eq '-1') {
9776: if ($sec eq '') {
9777: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
9778: } else {
9779: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9780: }
9781: } else {
9782: if ($sec eq '') {
9783: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
9784: } else {
9785: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9786: }
9787: }
9788: } else {
9789: if ($secchange) {
9790: $$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;
9791: } else {
9792: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
9793: }
9794: }
9795: $result = $modify_section_result;
9796: } elsif ($secchange == 1) {
9797: if ($oldsec eq '') {
9798: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
9799: } else {
9800: $$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;
9801: }
9802: if ($expire_role_result eq 'refused') {
9803: my $newsecurl = '/'.$cid;
9804: $newsecurl =~ s/\_/\//g;
9805: if ($sec ne '') {
9806: $newsecurl.='/'.$sec;
9807: }
9808: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
9809: if ($sec eq '') {
9810: $$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;
9811: } else {
9812: $$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;
9813: }
9814: }
9815: }
9816: }
9817: } else {
9818: $$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;
9819: $result = "error: incomplete course id\n";
9820: }
9821: return $result;
9822: }
9823:
9824: ############################################################
9825: ############################################################
9826:
9827: sub check_clone {
9828: my ($args,$linefeed) = @_;
9829: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
9830: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
9831: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
9832: my $clonemsg;
9833: my $can_clone = 0;
9834:
9835: if ($clonehome eq 'no_host') {
9836: $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'});
9837: } else {
9838: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
9839: if ($env{'request.role.domain'} eq $args->{'clonedomain'}) {
9840: $can_clone = 1;
9841: } else {
9842: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
9843: $args->{'clonedomain'},$args->{'clonecourse'});
9844: my @cloners = split(/,/,$clonehash{'cloners'});
9845: if (grep(/^\*$/,@cloners)) {
9846: $can_clone = 1;
9847: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
9848: $can_clone = 1;
9849: } else {
9850: my %roleshash =
9851: &Apache::lonnet::get_my_roles($args->{'ccuname'},
9852: $args->{'ccdomain'},
9853: 'userroles',['active'],['cc'],
9854: [$args->{'clonedomain'}]);
9855: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
9856: $can_clone = 1;
9857: } else {
9858: $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'});
9859: }
9860: }
9861: }
9862: }
9863: return ($can_clone, $clonemsg, $cloneid, $clonehome);
9864: }
9865:
9866: sub construct_course {
9867: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context) = @_;
9868: my $outcome;
9869: my $linefeed = '<br />'."\n";
9870: if ($context eq 'auto') {
9871: $linefeed = "\n";
9872: }
9873:
9874: #
9875: # Are we cloning?
9876: #
9877: my ($can_clone, $clonemsg, $cloneid, $clonehome);
9878: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
9879: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
9880: if ($context ne 'auto') {
9881: if ($clonemsg ne '') {
9882: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
9883: }
9884: }
9885: $outcome .= $clonemsg.$linefeed;
9886:
9887: if (!$can_clone) {
9888: return (0,$outcome);
9889: }
9890: }
9891:
9892: #
9893: # Open course
9894: #
9895: my $crstype = lc($args->{'crstype'});
9896: my %cenv=();
9897: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
9898: $args->{'cdescr'},
9899: $args->{'curl'},
9900: $args->{'course_home'},
9901: $args->{'nonstandard'},
9902: $args->{'crscode'},
9903: $args->{'ccuname'}.':'.
9904: $args->{'ccdomain'},
9905: $args->{'crstype'});
9906:
9907: # Note: The testing routines depend on this being output; see
9908: # Utils::Course. This needs to at least be output as a comment
9909: # if anyone ever decides to not show this, and Utils::Course::new
9910: # will need to be suitably modified.
9911: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
9912: #
9913: # Check if created correctly
9914: #
9915: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
9916: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
9917: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
9918:
9919: #
9920: # Do the cloning
9921: #
9922: if ($can_clone && $cloneid) {
9923: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
9924: if ($context ne 'auto') {
9925: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
9926: }
9927: $outcome .= $clonemsg.$linefeed;
9928: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
9929: # Copy all files
9930: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
9931: # Restore URL
9932: $cenv{'url'}=$oldcenv{'url'};
9933: # Restore title
9934: $cenv{'description'}=$oldcenv{'description'};
9935: # Mark as cloned
9936: $cenv{'clonedfrom'}=$cloneid;
9937: # Need to clone grading mode
9938: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
9939: $cenv{'grading'}=$newenv{'grading'};
9940: # Do not clone these environment entries
9941: &Apache::lonnet::del('environment',
9942: ['default_enrollment_start_date',
9943: 'default_enrollment_end_date',
9944: 'question.email',
9945: 'policy.email',
9946: 'comment.email',
9947: 'pch.users.denied',
9948: 'plc.users.denied',
9949: 'hidefromcat',
9950: 'categories'],
9951: $$crsudom,$$crsunum);
9952: }
9953:
9954: #
9955: # Set environment (will override cloned, if existing)
9956: #
9957: my @sections = ();
9958: my @xlists = ();
9959: if ($args->{'crstype'}) {
9960: $cenv{'type'}=$args->{'crstype'};
9961: }
9962: if ($args->{'crsid'}) {
9963: $cenv{'courseid'}=$args->{'crsid'};
9964: }
9965: if ($args->{'crscode'}) {
9966: $cenv{'internal.coursecode'}=$args->{'crscode'};
9967: }
9968: if ($args->{'crsquota'} ne '') {
9969: $cenv{'internal.coursequota'}=$args->{'crsquota'};
9970: } else {
9971: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
9972: }
9973: if ($args->{'ccuname'}) {
9974: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
9975: ':'.$args->{'ccdomain'};
9976: } else {
9977: $cenv{'internal.courseowner'} = $args->{'curruser'};
9978: }
9979: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
9980: if ($args->{'crssections'}) {
9981: $cenv{'internal.sectionnums'} = '';
9982: if ($args->{'crssections'} =~ m/,/) {
9983: @sections = split/,/,$args->{'crssections'};
9984: } else {
9985: $sections[0] = $args->{'crssections'};
9986: }
9987: if (@sections > 0) {
9988: foreach my $item (@sections) {
9989: my ($sec,$gp) = split/:/,$item;
9990: my $class = $args->{'crscode'}.$sec;
9991: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
9992: $cenv{'internal.sectionnums'} .= $item.',';
9993: unless ($addcheck eq 'ok') {
9994: push @badclasses, $class;
9995: }
9996: }
9997: $cenv{'internal.sectionnums'} =~ s/,$//;
9998: }
9999: }
10000: # do not hide course coordinator from staff listing,
10001: # even if privileged
10002: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10003: # add crosslistings
10004: if ($args->{'crsxlist'}) {
10005: $cenv{'internal.crosslistings'}='';
10006: if ($args->{'crsxlist'} =~ m/,/) {
10007: @xlists = split/,/,$args->{'crsxlist'};
10008: } else {
10009: $xlists[0] = $args->{'crsxlist'};
10010: }
10011: if (@xlists > 0) {
10012: foreach my $item (@xlists) {
10013: my ($xl,$gp) = split/:/,$item;
10014: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
10015: $cenv{'internal.crosslistings'} .= $item.',';
10016: unless ($addcheck eq 'ok') {
10017: push @badclasses, $xl;
10018: }
10019: }
10020: $cenv{'internal.crosslistings'} =~ s/,$//;
10021: }
10022: }
10023: if ($args->{'autoadds'}) {
10024: $cenv{'internal.autoadds'}=$args->{'autoadds'};
10025: }
10026: if ($args->{'autodrops'}) {
10027: $cenv{'internal.autodrops'}=$args->{'autodrops'};
10028: }
10029: # check for notification of enrollment changes
10030: my @notified = ();
10031: if ($args->{'notify_owner'}) {
10032: if ($args->{'ccuname'} ne '') {
10033: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
10034: }
10035: }
10036: if ($args->{'notify_dc'}) {
10037: if ($uname ne '') {
10038: push(@notified,$uname.':'.$udom);
10039: }
10040: }
10041: if (@notified > 0) {
10042: my $notifylist;
10043: if (@notified > 1) {
10044: $notifylist = join(',',@notified);
10045: } else {
10046: $notifylist = $notified[0];
10047: }
10048: $cenv{'internal.notifylist'} = $notifylist;
10049: }
10050: if (@badclasses > 0) {
10051: my %lt=&Apache::lonlocal::texthash(
10052: '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',
10053: 'dnhr' => 'does not have rights to access enrollment in these classes',
10054: 'adby' => 'as determined by the policies of your institution on access to official classlists'
10055: );
10056: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
10057: ' ('.$lt{'adby'}.')';
10058: if ($context eq 'auto') {
10059: $outcome .= $badclass_msg.$linefeed;
10060: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
10061: foreach my $item (@badclasses) {
10062: if ($context eq 'auto') {
10063: $outcome .= " - $item\n";
10064: } else {
10065: $outcome .= "<li>$item</li>\n";
10066: }
10067: }
10068: if ($context eq 'auto') {
10069: $outcome .= $linefeed;
10070: } else {
10071: $outcome .= "</ul><br /><br /></div>\n";
10072: }
10073: }
10074: }
10075: if ($args->{'no_end_date'}) {
10076: $args->{'endaccess'} = 0;
10077: }
10078: $cenv{'internal.autostart'}=$args->{'enrollstart'};
10079: $cenv{'internal.autoend'}=$args->{'enrollend'};
10080: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
10081: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
10082: if ($args->{'showphotos'}) {
10083: $cenv{'internal.showphotos'}=$args->{'showphotos'};
10084: }
10085: $cenv{'internal.authtype'} = $args->{'authtype'};
10086: $cenv{'internal.autharg'} = $args->{'autharg'};
10087: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
10088: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
10089: 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');
10090: if ($context eq 'auto') {
10091: $outcome .= $krb_msg;
10092: } else {
10093: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
10094: }
10095: $outcome .= $linefeed;
10096: }
10097: }
10098: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
10099: if ($args->{'setpolicy'}) {
10100: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10101: }
10102: if ($args->{'setcontent'}) {
10103: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10104: }
10105: }
10106: if ($args->{'reshome'}) {
10107: $cenv{'reshome'}=$args->{'reshome'}.'/';
10108: $cenv{'reshome'}=~s/\/+$/\//;
10109: }
10110: #
10111: # course has keyed access
10112: #
10113: if ($args->{'setkeys'}) {
10114: $cenv{'keyaccess'}='yes';
10115: }
10116: # if specified, key authority is not course, but user
10117: # only active if keyaccess is yes
10118: if ($args->{'keyauth'}) {
10119: my ($user,$domain) = split(':',$args->{'keyauth'});
10120: $user = &LONCAPA::clean_username($user);
10121: $domain = &LONCAPA::clean_username($domain);
10122: if ($user ne '' && $domain ne '') {
10123: $cenv{'keyauth'}=$user.':'.$domain;
10124: }
10125: }
10126:
10127: if ($args->{'disresdis'}) {
10128: $cenv{'pch.roles.denied'}='st';
10129: }
10130: if ($args->{'disablechat'}) {
10131: $cenv{'plc.roles.denied'}='st';
10132: }
10133:
10134: # Record we've not yet viewed the Course Initialization Helper for this
10135: # course
10136: $cenv{'course.helper.not.run'} = 1;
10137: #
10138: # Use new Randomseed
10139: #
10140: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
10141: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
10142: #
10143: # The encryption code and receipt prefix for this course
10144: #
10145: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
10146: $cenv{'internal.encpref'}=100+int(9*rand(99));
10147: #
10148: # By default, use standard grading
10149: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
10150:
10151: $outcome .= $linefeed.&mt('Setting environment').': '.
10152: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
10153: #
10154: # Open all assignments
10155: #
10156: if ($args->{'openall'}) {
10157: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
10158: my %storecontent = ($storeunder => time,
10159: $storeunder.'.type' => 'date_start');
10160:
10161: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
10162: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
10163: }
10164: #
10165: # Set first page
10166: #
10167: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
10168: || ($cloneid)) {
10169: use LONCAPA::map;
10170: $outcome .= &mt('Setting first resource').': ';
10171:
10172: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
10173: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
10174:
10175: $outcome .= ($fatal?$errtext:'read ok').' - ';
10176: my $title; my $url;
10177: if ($args->{'firstres'} eq 'syl') {
10178: $title=&mt('Syllabus');
10179: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
10180: } else {
10181: $title=&mt('Navigate Contents');
10182: $url='/adm/navmaps';
10183: }
10184:
10185: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
10186: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
10187:
10188: if ($errtext) { $fatal=2; }
10189: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
10190: }
10191:
10192: return (1,$outcome);
10193: }
10194:
10195: ############################################################
10196: ############################################################
10197:
10198: sub course_type {
10199: my ($cid) = @_;
10200: if (!defined($cid)) {
10201: $cid = $env{'request.course.id'};
10202: }
10203: if (defined($env{'course.'.$cid.'.type'})) {
10204: return $env{'course.'.$cid.'.type'};
10205: } else {
10206: return 'Course';
10207: }
10208: }
10209:
10210: sub group_term {
10211: my $crstype = &course_type();
10212: my %names = (
10213: 'Course' => 'group',
10214: 'Group' => 'team',
10215: );
10216: return $names{$crstype};
10217: }
10218:
10219: sub icon {
10220: my ($file)=@_;
10221: my $curfext = lc((split(/\./,$file))[-1]);
10222: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
10223: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
10224: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
10225: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
10226: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
10227: $curfext.".gif") {
10228: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
10229: $curfext.".gif";
10230: }
10231: }
10232: return &lonhttpdurl($iconname);
10233: }
10234:
10235: sub lonhttpdurl {
10236: #
10237: # Had been used for "small fry" static images on separate port 8080.
10238: # Modify here if lightweight http functionality desired again.
10239: # Currently eliminated due to increasing firewall issues.
10240: #
10241: my ($url)=@_;
10242: return $url;
10243: }
10244:
10245: sub connection_aborted {
10246: my ($r)=@_;
10247: $r->print(" ");$r->rflush();
10248: my $c = $r->connection;
10249: return $c->aborted();
10250: }
10251:
10252: # Escapes strings that may have embedded 's that will be put into
10253: # strings as 'strings'.
10254: sub escape_single {
10255: my ($input) = @_;
10256: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
10257: $input =~ s/\'/\\\'/g; # Esacpe the 's....
10258: return $input;
10259: }
10260:
10261: # Same as escape_single, but escape's "'s This
10262: # can be used for "strings"
10263: sub escape_double {
10264: my ($input) = @_;
10265: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
10266: $input =~ s/\"/\\\"/g; # Esacpe the "s....
10267: return $input;
10268: }
10269:
10270: # Escapes the last element of a full URL.
10271: sub escape_url {
10272: my ($url) = @_;
10273: my @urlslices = split(/\//, $url,-1);
10274: my $lastitem = &escape(pop(@urlslices));
10275: return join('/',@urlslices).'/'.$lastitem;
10276: }
10277:
10278: sub compare_arrays {
10279: my ($arrayref1,$arrayref2) = @_;
10280: my (@difference,%count);
10281: @difference = ();
10282: %count = ();
10283: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
10284: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
10285: foreach my $element (keys(%count)) {
10286: if ($count{$element} == 1) {
10287: push(@difference,$element);
10288: }
10289: }
10290: }
10291: return @difference;
10292: }
10293:
10294: # -------------------------------------------------------- Initialize user login
10295: sub init_user_environment {
10296: my ($r, $username, $domain, $authhost, $form, $args) = @_;
10297: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
10298:
10299: my $public=($username eq 'public' && $domain eq 'public');
10300:
10301: # See if old ID present, if so, remove
10302:
10303: my ($filename,$cookie,$userroles);
10304: my $now=time;
10305:
10306: if ($public) {
10307: my $max_public=100;
10308: my $oldest;
10309: my $oldest_time=0;
10310: for(my $next=1;$next<=$max_public;$next++) {
10311: if (-e $lonids."/publicuser_$next.id") {
10312: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
10313: if ($mtime<$oldest_time || !$oldest_time) {
10314: $oldest_time=$mtime;
10315: $oldest=$next;
10316: }
10317: } else {
10318: $cookie="publicuser_$next";
10319: last;
10320: }
10321: }
10322: if (!$cookie) { $cookie="publicuser_$oldest"; }
10323: } else {
10324: # if this isn't a robot, kill any existing non-robot sessions
10325: if (!$args->{'robot'}) {
10326: opendir(DIR,$lonids);
10327: while ($filename=readdir(DIR)) {
10328: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
10329: unlink($lonids.'/'.$filename);
10330: }
10331: }
10332: closedir(DIR);
10333: }
10334: # Give them a new cookie
10335: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
10336: : $now.$$.int(rand(10000)));
10337: $cookie="$username\_$id\_$domain\_$authhost";
10338:
10339: # Initialize roles
10340:
10341: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
10342: }
10343: # ------------------------------------ Check browser type and MathML capability
10344:
10345: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
10346: $clientunicode,$clientos) = &decode_user_agent($r);
10347:
10348: # ------------------------------------------------------------- Get environment
10349:
10350: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
10351: my ($tmp) = keys(%userenv);
10352: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
10353: # default remote control to off
10354: if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
10355: } else {
10356: undef(%userenv);
10357: }
10358: if (($userenv{'interface'}) && (!$form->{'interface'})) {
10359: $form->{'interface'}=$userenv{'interface'};
10360: }
10361: $env{'environment.remote'}=$userenv{'remote'};
10362: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
10363:
10364: # --------------- Do not trust query string to be put directly into environment
10365: foreach my $option ('interface','localpath','localres') {
10366: $form->{$option}=~s/[\n\r\=]//gs;
10367: }
10368: # --------------------------------------------------------- Write first profile
10369:
10370: {
10371: my %initial_env =
10372: ("user.name" => $username,
10373: "user.domain" => $domain,
10374: "user.home" => $authhost,
10375: "browser.type" => $clientbrowser,
10376: "browser.version" => $clientversion,
10377: "browser.mathml" => $clientmathml,
10378: "browser.unicode" => $clientunicode,
10379: "browser.os" => $clientos,
10380: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
10381: "request.course.fn" => '',
10382: "request.course.uri" => '',
10383: "request.course.sec" => '',
10384: "request.role" => 'cm',
10385: "request.role.adv" => $env{'user.adv'},
10386: "request.host" => $ENV{'REMOTE_ADDR'},);
10387:
10388: if ($form->{'localpath'}) {
10389: $initial_env{"browser.localpath"} = $form->{'localpath'};
10390: $initial_env{"browser.localres"} = $form->{'localres'};
10391: }
10392:
10393: if ($public) {
10394: $initial_env{"environment.remote"} = "off";
10395: }
10396: if ($form->{'interface'}) {
10397: $form->{'interface'}=~s/\W//gs;
10398: $initial_env{"browser.interface"} = $form->{'interface'};
10399: $env{'browser.interface'}=$form->{'interface'};
10400: }
10401:
10402: foreach my $tool ('aboutme','blog','portfolio') {
10403: $userenv{'availabletools.'.$tool} =
10404: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload');
10405: }
10406:
10407: foreach my $crstype ('official','unofficial','community') {
10408: $userenv{'canrequest.'.$crstype} =
10409: &Apache::lonnet::usertools_access($username,$domain,$crstype,
10410: 'reload','requestcourses');
10411: }
10412:
10413: $env{'user.environment'} = "$lonids/$cookie.id";
10414:
10415: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
10416: &GDBM_WRCREAT(),0640)) {
10417: &_add_to_env(\%disk_env,\%initial_env);
10418: &_add_to_env(\%disk_env,\%userenv,'environment.');
10419: &_add_to_env(\%disk_env,$userroles);
10420: if (ref($args->{'extra_env'})) {
10421: &_add_to_env(\%disk_env,$args->{'extra_env'});
10422: }
10423: untie(%disk_env);
10424: } else {
10425: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
10426: 'Could not create environment storage in lonauth: '.$!.'</span>');
10427: return 'error: '.$!;
10428: }
10429: }
10430: $env{'request.role'}='cm';
10431: $env{'request.role.adv'}=$env{'user.adv'};
10432: $env{'browser.type'}=$clientbrowser;
10433:
10434: return $cookie;
10435:
10436: }
10437:
10438: sub _add_to_env {
10439: my ($idf,$env_data,$prefix) = @_;
10440: if (ref($env_data) eq 'HASH') {
10441: while (my ($key,$value) = each(%$env_data)) {
10442: $idf->{$prefix.$key} = $value;
10443: $env{$prefix.$key} = $value;
10444: }
10445: }
10446: }
10447:
10448: # --- Get the symbolic name of a problem and the url
10449: sub get_symb {
10450: my ($request,$silent) = @_;
10451: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
10452: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
10453: if ($symb eq '') {
10454: if (!$silent) {
10455: $request->print("Unable to handle ambiguous references:$url:.");
10456: return ();
10457: }
10458: }
10459: &Apache::lonenc::check_decrypt(\$symb);
10460: return ($symb);
10461: }
10462:
10463: # --------------------------------------------------------------Get annotation
10464:
10465: sub get_annotation {
10466: my ($symb,$enc) = @_;
10467:
10468: my $key = $symb;
10469: if (!$enc) {
10470: $key =
10471: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
10472: }
10473: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
10474: return $annotation{$key};
10475: }
10476:
10477: sub clean_symb {
10478: my ($symb,$delete_enc) = @_;
10479:
10480: &Apache::lonenc::check_decrypt(\$symb);
10481: my $enc = $env{'request.enc'};
10482: if ($delete_enc) {
10483: delete($env{'request.enc'});
10484: }
10485:
10486: return ($symb,$enc);
10487: }
10488:
10489: =pod
10490:
10491: =back
10492:
10493: =cut
10494:
10495: 1;
10496: __END__;
10497:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>