1: # The LearningOnline Network with CAPA
2: # a pile of common routines
3: #
4: # $Id: loncommon.pm,v 1.795 2009/04/25 16:53:13 www Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: # Makes a table out of the previous attempts
30: # Inputs result_from_symbread, user, domain, course_id
31: # Reads in non-network-related .tab files
32:
33: # POD header:
34:
35: =pod
36:
37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
45:
46: =head1 OVERVIEW
47:
48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
55: package Apache::loncommon;
56:
57: use strict;
58: use Apache::lonnet;
59: use GDBM_File;
60: use POSIX qw(strftime mktime);
61: use Apache::lonmenu();
62: use Apache::lonenc();
63: use Apache::lonlocal;
64: use Apache::lonnet();
65: use HTML::Entities;
66: use Apache::lonhtmlcommon();
67: use Apache::loncoursedata();
68: use Apache::lontexconvert();
69: use Apache::lonclonecourse();
70: use LONCAPA qw(:DEFAULT :match);
71: use DateTime::TimeZone;
72: use DateTime::Locale::Catalog;
73:
74: # ---------------------------------------------- Designs
75: use vars qw(%defaultdesign);
76:
77: my $readit;
78:
79:
80: ##
81: ## Global Variables
82: ##
83:
84:
85: # ----------------------------------------------- SSI with retries:
86: #
87:
88: =pod
89:
90: =head1 Server Side include with retries:
91:
92: =over 4
93:
94: =item * &ssi_with_retries(resource,retries form)
95:
96: Performs an ssi with some number of retries. Retries continue either
97: until the result is ok or until the retry count supplied by the
98: caller is exhausted.
99:
100: Inputs:
101:
102: =over 4
103:
104: resource - Identifies the resource to insert.
105:
106: retries - Count of the number of retries allowed.
107:
108: form - Hash that identifies the rendering options.
109:
110: =back
111:
112: Returns:
113:
114: =over 4
115:
116: content - The content of the response. If retries were exhausted this is empty.
117:
118: response - The response from the last attempt (which may or may not have been successful.
119:
120: =back
121:
122: =back
123:
124: =cut
125:
126: sub ssi_with_retries {
127: my ($resource, $retries, %form) = @_;
128:
129:
130: my $ok = 0; # True if we got a good response.
131: my $content;
132: my $response;
133:
134: # Try to get the ssi done. within the retries count:
135:
136: do {
137: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
138: $ok = $response->is_success;
139: if (!$ok) {
140: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
141: }
142: $retries--;
143: } while (!$ok && ($retries > 0));
144:
145: if (!$ok) {
146: $content = ''; # On error return an empty content.
147: }
148: return ($content, $response);
149:
150: }
151:
152:
153:
154: # ----------------------------------------------- Filetypes/Languages/Copyright
155: my %language;
156: my %supported_language;
157: my %cprtag;
158: my %scprtag;
159: my %fe; my %fd; my %fm;
160: my %category_extensions;
161:
162: # ---------------------------------------------- Thesaurus variables
163: #
164: # %Keywords:
165: # A hash used by &keyword to determine if a word is considered a keyword.
166: # $thesaurus_db_file
167: # Scalar containing the full path to the thesaurus database.
168:
169: my %Keywords;
170: my $thesaurus_db_file;
171:
172: #
173: # Initialize values from language.tab, copyright.tab, filetypes.tab,
174: # thesaurus.tab, and filecategories.tab.
175: #
176: BEGIN {
177: # Variable initialization
178: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
179: #
180: unless ($readit) {
181: # ------------------------------------------------------------------- languages
182: {
183: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
184: '/language.tab';
185: if ( open(my $fh,"<$langtabfile") ) {
186: while (my $line = <$fh>) {
187: next if ($line=~/^\#/);
188: chomp($line);
189: my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$line));
190: $language{$key}=$val.' - '.$enc;
191: if ($sup) {
192: $supported_language{$key}=$sup;
193: }
194: }
195: close($fh);
196: }
197: }
198: # ------------------------------------------------------------------ copyrights
199: {
200: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
201: '/copyright.tab';
202: if ( open (my $fh,"<$copyrightfile") ) {
203: while (my $line = <$fh>) {
204: next if ($line=~/^\#/);
205: chomp($line);
206: my ($key,$val)=(split(/\s+/,$line,2));
207: $cprtag{$key}=$val;
208: }
209: close($fh);
210: }
211: }
212: # ----------------------------------------------------------- source copyrights
213: {
214: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
215: '/source_copyright.tab';
216: if ( open (my $fh,"<$sourcecopyrightfile") ) {
217: while (my $line = <$fh>) {
218: next if ($line =~ /^\#/);
219: chomp($line);
220: my ($key,$val)=(split(/\s+/,$line,2));
221: $scprtag{$key}=$val;
222: }
223: close($fh);
224: }
225: }
226:
227: # -------------------------------------------------------------- default domain designs
228: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
229: my $designfile = $designdir.'/default.tab';
230: if ( open (my $fh,"<$designfile") ) {
231: while (my $line = <$fh>) {
232: next if ($line =~ /^\#/);
233: chomp($line);
234: my ($key,$val)=(split(/\=/,$line));
235: if ($val) { $defaultdesign{$key}=$val; }
236: }
237: close($fh);
238: }
239:
240: # ------------------------------------------------------------- file categories
241: {
242: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
243: '/filecategories.tab';
244: if ( open (my $fh,"<$categoryfile") ) {
245: while (my $line = <$fh>) {
246: next if ($line =~ /^\#/);
247: chomp($line);
248: my ($extension,$category)=(split(/\s+/,$line,2));
249: push @{$category_extensions{lc($category)}},$extension;
250: }
251: close($fh);
252: }
253:
254: }
255: # ------------------------------------------------------------------ file types
256: {
257: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
258: '/filetypes.tab';
259: if ( open (my $fh,"<$typesfile") ) {
260: while (my $line = <$fh>) {
261: next if ($line =~ /^\#/);
262: chomp($line);
263: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
264: if ($descr ne '') {
265: $fe{$ending}=lc($emb);
266: $fd{$ending}=$descr;
267: if ($mime ne 'unk') { $fm{$ending}=$mime; }
268: }
269: }
270: close($fh);
271: }
272: }
273: &Apache::lonnet::logthis(
274: "<span style='color:yellow;'>INFO: Read file types</span>");
275: $readit=1;
276: } # end of unless($readit)
277:
278: }
279:
280: ###############################################################
281: ## HTML and Javascript Helper Functions ##
282: ###############################################################
283:
284: =pod
285:
286: =head1 HTML and Javascript Functions
287:
288: =over 4
289:
290: =item * &browser_and_searcher_javascript()
291:
292: X<browsing, javascript>X<searching, javascript>Returns a string
293: containing javascript with two functions, C<openbrowser> and
294: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
295: tags.
296:
297: =item * &openbrowser(formname,elementname,only,omit) [javascript]
298:
299: inputs: formname, elementname, only, omit
300:
301: formname and elementname indicate the name of the html form and name of
302: the element that the results of the browsing selection are to be placed in.
303:
304: Specifying 'only' will restrict the browser to displaying only files
305: with the given extension. Can be a comma separated list.
306:
307: Specifying 'omit' will restrict the browser to NOT displaying files
308: with the given extension. Can be a comma separated list.
309:
310: =item * &opensearcher(formname,elementname) [javascript]
311:
312: Inputs: formname, elementname
313:
314: formname and elementname specify the name of the html form and the name
315: of the element the selection from the search results will be placed in.
316:
317: =cut
318:
319: sub browser_and_searcher_javascript {
320: my ($mode)=@_;
321: if (!defined($mode)) { $mode='edit'; }
322: my $resurl=&escape_single(&lastresurl());
323: return <<END;
324: // <!-- BEGIN LON-CAPA Internal
325: var editbrowser = null;
326: function openbrowser(formname,elementname,only,omit,titleelement) {
327: var url = '$resurl/?';
328: if (editbrowser == null) {
329: url += 'launch=1&';
330: }
331: url += 'catalogmode=interactive&';
332: url += 'mode=$mode&';
333: url += 'inhibitmenu=yes&';
334: url += 'form=' + formname + '&';
335: if (only != null) {
336: url += 'only=' + only + '&';
337: } else {
338: url += 'only=&';
339: }
340: if (omit != null) {
341: url += 'omit=' + omit + '&';
342: } else {
343: url += 'omit=&';
344: }
345: if (titleelement != null) {
346: url += 'titleelement=' + titleelement + '&';
347: } else {
348: url += 'titleelement=&';
349: }
350: url += 'element=' + elementname + '';
351: var title = 'Browser';
352: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
353: options += ',width=700,height=600';
354: editbrowser = open(url,title,options,'1');
355: editbrowser.focus();
356: }
357: var editsearcher;
358: function opensearcher(formname,elementname,titleelement) {
359: var url = '/adm/searchcat?';
360: if (editsearcher == null) {
361: url += 'launch=1&';
362: }
363: url += 'catalogmode=interactive&';
364: url += 'mode=$mode&';
365: url += 'form=' + formname + '&';
366: if (titleelement != null) {
367: url += 'titleelement=' + titleelement + '&';
368: } else {
369: url += 'titleelement=&';
370: }
371: url += 'element=' + elementname + '';
372: var title = 'Search';
373: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
374: options += ',width=700,height=600';
375: editsearcher = open(url,title,options,'1');
376: editsearcher.focus();
377: }
378: // END LON-CAPA Internal -->
379: END
380: }
381:
382: sub lastresurl {
383: if ($env{'environment.lastresurl'}) {
384: return $env{'environment.lastresurl'}
385: } else {
386: return '/res';
387: }
388: }
389:
390: sub storeresurl {
391: my $resurl=&Apache::lonnet::clutter(shift);
392: unless ($resurl=~/^\/res/) { return 0; }
393: $resurl=~s/\/$//;
394: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
395: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
396: return 1;
397: }
398:
399: sub studentbrowser_javascript {
400: unless (
401: (($env{'request.course.id'}) &&
402: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
403: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
404: '/'.$env{'request.course.sec'})
405: ))
406: || ($env{'request.role'}=~/^(au|dc|su)/)
407: ) { return ''; }
408: return (<<'ENDSTDBRW');
409: <script type="text/javascript" language="Javascript">
410: var stdeditbrowser;
411: function openstdbrowser(formname,uname,udom,roleflag,ignorefilter,courseadvonly) {
412: var url = '/adm/pickstudent?';
413: var filter;
414: if (!ignorefilter) {
415: eval('filter=document.'+formname+'.'+uname+'.value;');
416: }
417: if (filter != null) {
418: if (filter != '') {
419: url += 'filter='+filter+'&';
420: }
421: }
422: url += 'form=' + formname + '&unameelement='+uname+
423: '&udomelement='+udom;
424: if (roleflag) { url+="&roles=1"; }
425: if (courseadvonly) { url+="&courseadvonly=1"; }
426: var title = 'Student_Browser';
427: var options = 'scrollbars=1,resizable=1,menubar=0';
428: options += ',width=700,height=600';
429: stdeditbrowser = open(url,title,options,'1');
430: stdeditbrowser.focus();
431: }
432: </script>
433: ENDSTDBRW
434: }
435:
436: sub selectstudent_link {
437: my ($form,$unameele,$udomele,$courseadvonly)=@_;
438: my $callargs = "'".$form."','".$unameele."','".$udomele."'";
439: if ($env{'request.course.id'}) {
440: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
441: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
442: '/'.$env{'request.course.sec'})) {
443: return '';
444: }
445: if ($courseadvonly) {
446: $callargs .= ",'',1,1";
447: }
448: return '<span class="LC_nobreak">'.
449: '<a href="javascript:openstdbrowser('.$callargs.');">'.
450: &mt('Select User').'</a></span>';
451: }
452: if ($env{'request.role'}=~/^(au|dc|su)/) {
453: $callargs .= ",1";
454: return '<span class="LC_nobreak">'.
455: '<a href="javascript:openstdbrowser('.$callargs.');">'.
456: &mt('Select User').'</a></span>';
457: }
458: return '';
459: }
460:
461: sub authorbrowser_javascript {
462: return <<"ENDAUTHORBRW";
463: <script type="text/javascript" language="JavaScript">
464: var stdeditbrowser;
465:
466: function openauthorbrowser(formname,udom) {
467: var url = '/adm/pickauthor?';
468: url += 'form='+formname+'&roledom='+udom;
469: var title = 'Author_Browser';
470: var options = 'scrollbars=1,resizable=1,menubar=0';
471: options += ',width=700,height=600';
472: stdeditbrowser = open(url,title,options,'1');
473: stdeditbrowser.focus();
474: }
475:
476: </script>
477: ENDAUTHORBRW
478: }
479:
480: sub coursebrowser_javascript {
481: my ($domainfilter,$sec_element,$formname)=@_;
482: 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');
483: my $output = '
484: <script type="text/javascript" language="JavaScript">
485: var stdeditbrowser;'."\n";
486: $output .= <<"ENDSTDBRW";
487: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,crstype) {
488: var url = '/adm/pickcourse?';
489: var domainfilter = '';
490: var formid = getFormIdByName(formname);
491: if (formid > -1) {
492: var domid = getIndexByName(formid,udom);
493: if (domid > -1) {
494: if (document.forms[formid].elements[domid].type == 'select-one') {
495: domainfilter=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
496: }
497: if (document.forms[formid].elements[domid].type == 'hidden') {
498: domainfilter=document.forms[formid].elements[domid].value;
499: }
500: }
501: }
502: if (domainfilter != null) {
503: if (domainfilter != '') {
504: url += 'domainfilter='+domainfilter+'&';
505: }
506: }
507: url += 'form=' + formname + '&cnumelement='+uname+
508: '&cdomelement='+udom+
509: '&cnameelement='+desc;
510: if (extra_element !=null && extra_element != '') {
511: if (formname == 'rolechoice' || formname == 'studentform') {
512: url += '&roleelement='+extra_element;
513: if (domainfilter == null || domainfilter == '') {
514: url += '&domainfilter='+extra_element;
515: }
516: }
517: else {
518: if (formname == 'portform') {
519: url += '&setroles='+extra_element;
520: }
521: }
522: }
523: if (multflag !=null && multflag != '') {
524: url += '&multiple='+multflag;
525: }
526: if (crstype == 'Course/Group') {
527: if (formname == 'cu') {
528: crstype = document.cu.crstype.options[document.cu.crstype.selectedIndex].value;
529: if (crstype == "") {
530: alert("$crs_or_grp_alert");
531: return;
532: }
533: }
534: }
535: if (crstype !=null && crstype != '') {
536: url += '&type='+crstype;
537: }
538: var title = 'Course_Browser';
539: var options = 'scrollbars=1,resizable=1,menubar=0';
540: options += ',width=700,height=600';
541: stdeditbrowser = open(url,title,options,'1');
542: stdeditbrowser.focus();
543: }
544:
545: function getFormIdByName(formname) {
546: for (var i=0;i<document.forms.length;i++) {
547: if (document.forms[i].name == formname) {
548: return i;
549: }
550: }
551: return -1;
552: }
553:
554: function getIndexByName(formid,item) {
555: for (var i=0;i<document.forms[formid].elements.length;i++) {
556: if (document.forms[formid].elements[i].name == item) {
557: return i;
558: }
559: }
560: return -1;
561: }
562: ENDSTDBRW
563: if ($sec_element ne '') {
564: $output .= &setsec_javascript($sec_element,$formname);
565: }
566: $output .= '
567: </script>';
568: return $output;
569: }
570:
571: sub setsec_javascript {
572: my ($sec_element,$formname) = @_;
573: my $setsections = qq|
574: function setSect(sectionlist) {
575: var sectionsArray = new Array();
576: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
577: sectionsArray = sectionlist.split(",");
578: }
579: var numSections = sectionsArray.length;
580: document.$formname.$sec_element.length = 0;
581: if (numSections == 0) {
582: document.$formname.$sec_element.multiple=false;
583: document.$formname.$sec_element.size=1;
584: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
585: } else {
586: if (numSections == 1) {
587: document.$formname.$sec_element.multiple=false;
588: document.$formname.$sec_element.size=1;
589: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
590: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
591: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
592: } else {
593: for (var i=0; i<numSections; i++) {
594: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
595: }
596: document.$formname.$sec_element.multiple=true
597: if (numSections < 3) {
598: document.$formname.$sec_element.size=numSections;
599: } else {
600: document.$formname.$sec_element.size=3;
601: }
602: document.$formname.$sec_element.options[0].selected = false
603: }
604: }
605: }
606: |;
607: return $setsections;
608: }
609:
610:
611: sub selectcourse_link {
612: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype)=@_;
613: return '<span class="LC_nobreak">'
614: ."<a href='"
615: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
616: .'","'.$udomele.'","'.$desc.'","'.$extra_element
617: .'","'.$multflag.'","'.$selecttype.'");'
618: ."'>".&mt('Select Course').'</a>'
619: .'</span>';
620: }
621:
622: sub selectauthor_link {
623: my ($form,$udom)=@_;
624: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
625: &mt('Select Author').'</a>';
626: }
627:
628: sub check_uncheck_jscript {
629: my $jscript = <<"ENDSCRT";
630: function checkAll(field) {
631: if (field.length > 0) {
632: for (i = 0; i < field.length; i++) {
633: field[i].checked = true ;
634: }
635: } else {
636: field.checked = true
637: }
638: }
639:
640: function uncheckAll(field) {
641: if (field.length > 0) {
642: for (i = 0; i < field.length; i++) {
643: field[i].checked = false ;
644: }
645: } else {
646: field.checked = false ;
647: }
648: }
649: ENDSCRT
650: return $jscript;
651: }
652:
653: sub select_timezone {
654: my ($name,$selected,$onchange,$includeempty)=@_;
655: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
656: if ($includeempty) {
657: $output .= '<option value=""';
658: if (($selected eq '') || ($selected eq 'local')) {
659: $output .= ' selected="selected" ';
660: }
661: $output .= '> </option>';
662: }
663: my @timezones = DateTime::TimeZone->all_names;
664: foreach my $tzone (@timezones) {
665: $output.= '<option value="'.$tzone.'"';
666: if ($tzone eq $selected) {
667: $output.=' selected="selected"';
668: }
669: $output.=">$tzone</option>\n";
670: }
671: $output.="</select>";
672: return $output;
673: }
674:
675: sub select_datelocale {
676: my ($name,$selected,$onchange,$includeempty)=@_;
677: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
678: if ($includeempty) {
679: $output .= '<option value=""';
680: if ($selected eq '') {
681: $output .= ' selected="selected" ';
682: }
683: $output .= '> </option>';
684: }
685: my (@possibles,%locale_names);
686: my @locales = DateTime::Locale::Catalog::Locales;
687: foreach my $locale (@locales) {
688: if (ref($locale) eq 'HASH') {
689: my $id = $locale->{'id'};
690: if ($id ne '') {
691: my $en_terr = $locale->{'en_territory'};
692: my $native_terr = $locale->{'native_territory'};
693: my @languages = &Apache::lonlocal::preferred_languages();
694: if (grep(/^en$/,@languages) || !@languages) {
695: if ($en_terr ne '') {
696: $locale_names{$id} = '('.$en_terr.')';
697: } elsif ($native_terr ne '') {
698: $locale_names{$id} = $native_terr;
699: }
700: } else {
701: if ($native_terr ne '') {
702: $locale_names{$id} = $native_terr.' ';
703: } elsif ($en_terr ne '') {
704: $locale_names{$id} = '('.$en_terr.')';
705: }
706: }
707: push (@possibles,$id);
708: }
709: }
710: }
711: foreach my $item (sort(@possibles)) {
712: $output.= '<option value="'.$item.'"';
713: if ($item eq $selected) {
714: $output.=' selected="selected"';
715: }
716: $output.=">$item";
717: if ($locale_names{$item} ne '') {
718: $output.=" $locale_names{$item}</option>\n";
719: }
720: $output.="</option>\n";
721: }
722: $output.="</select>";
723: return $output;
724: }
725:
726: sub select_language {
727: my ($name,$selected,$includeempty) = @_;
728: my %langchoices;
729: if ($includeempty) {
730: %langchoices = ('' => 'No language preference');
731: }
732: foreach my $id (&languageids()) {
733: my $code = &supportedlanguagecode($id);
734: if ($code) {
735: $langchoices{$code} = &plainlanguagedescription($id);
736: }
737: }
738: return &select_form($selected,$name,%langchoices);
739: }
740:
741: =pod
742:
743: =item * &linked_select_forms(...)
744:
745: linked_select_forms returns a string containing a <script></script> block
746: and html for two <select> menus. The select menus will be linked in that
747: changing the value of the first menu will result in new values being placed
748: in the second menu. The values in the select menu will appear in alphabetical
749: order unless a defined order is provided.
750:
751: linked_select_forms takes the following ordered inputs:
752:
753: =over 4
754:
755: =item * $formname, the name of the <form> tag
756:
757: =item * $middletext, the text which appears between the <select> tags
758:
759: =item * $firstdefault, the default value for the first menu
760:
761: =item * $firstselectname, the name of the first <select> tag
762:
763: =item * $secondselectname, the name of the second <select> tag
764:
765: =item * $hashref, a reference to a hash containing the data for the menus.
766:
767: =item * $menuorder, the order of values in the first menu
768:
769: =back
770:
771: Below is an example of such a hash. Only the 'text', 'default', and
772: 'select2' keys must appear as stated. keys(%menu) are the possible
773: values for the first select menu. The text that coincides with the
774: first menu value is given in $menu{$choice1}->{'text'}. The values
775: and text for the second menu are given in the hash pointed to by
776: $menu{$choice1}->{'select2'}.
777:
778: my %menu = ( A1 => { text =>"Choice A1" ,
779: default => "B3",
780: select2 => {
781: B1 => "Choice B1",
782: B2 => "Choice B2",
783: B3 => "Choice B3",
784: B4 => "Choice B4"
785: },
786: order => ['B4','B3','B1','B2'],
787: },
788: A2 => { text =>"Choice A2" ,
789: default => "C2",
790: select2 => {
791: C1 => "Choice C1",
792: C2 => "Choice C2",
793: C3 => "Choice C3"
794: },
795: order => ['C2','C1','C3'],
796: },
797: A3 => { text =>"Choice A3" ,
798: default => "D6",
799: select2 => {
800: D1 => "Choice D1",
801: D2 => "Choice D2",
802: D3 => "Choice D3",
803: D4 => "Choice D4",
804: D5 => "Choice D5",
805: D6 => "Choice D6",
806: D7 => "Choice D7"
807: },
808: order => ['D4','D3','D2','D1','D7','D6','D5'],
809: }
810: );
811:
812: =cut
813:
814: sub linked_select_forms {
815: my ($formname,
816: $middletext,
817: $firstdefault,
818: $firstselectname,
819: $secondselectname,
820: $hashref,
821: $menuorder,
822: ) = @_;
823: my $second = "document.$formname.$secondselectname";
824: my $first = "document.$formname.$firstselectname";
825: # output the javascript to do the changing
826: my $result = '';
827: $result.='<script type="text/javascript" language="JavaScript">'."\n";
828: $result.="var select2data = new Object();\n";
829: $" = '","';
830: my $debug = '';
831: foreach my $s1 (sort(keys(%$hashref))) {
832: $result.="select2data.d_$s1 = new Object();\n";
833: $result.="select2data.d_$s1.def = new String('".
834: $hashref->{$s1}->{'default'}."');\n";
835: $result.="select2data.d_$s1.values = new Array(";
836: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
837: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
838: @s2values = @{$hashref->{$s1}->{'order'}};
839: }
840: $result.="\"@s2values\");\n";
841: $result.="select2data.d_$s1.texts = new Array(";
842: my @s2texts;
843: foreach my $value (@s2values) {
844: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
845: }
846: $result.="\"@s2texts\");\n";
847: }
848: $"=' ';
849: $result.= <<"END";
850:
851: function select1_changed() {
852: // Determine new choice
853: var newvalue = "d_" + $first.value;
854: // update select2
855: var values = select2data[newvalue].values;
856: var texts = select2data[newvalue].texts;
857: var select2def = select2data[newvalue].def;
858: var i;
859: // out with the old
860: for (i = 0; i < $second.options.length; i++) {
861: $second.options[i] = null;
862: }
863: // in with the nuclear
864: for (i=0;i<values.length; i++) {
865: $second.options[i] = new Option(values[i]);
866: $second.options[i].value = values[i];
867: $second.options[i].text = texts[i];
868: if (values[i] == select2def) {
869: $second.options[i].selected = true;
870: }
871: }
872: }
873: </script>
874: END
875: # output the initial values for the selection lists
876: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
877: my @order = sort(keys(%{$hashref}));
878: if (ref($menuorder) eq 'ARRAY') {
879: @order = @{$menuorder};
880: }
881: foreach my $value (@order) {
882: $result.=" <option value=\"$value\" ";
883: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
884: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
885: }
886: $result .= "</select>\n";
887: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
888: $result .= $middletext;
889: $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
890: my $seconddefault = $hashref->{$firstdefault}->{'default'};
891:
892: my @secondorder = sort(keys(%select2));
893: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
894: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
895: }
896: foreach my $value (@secondorder) {
897: $result.=" <option value=\"$value\" ";
898: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
899: $result.=">".&mt($select2{$value})."</option>\n";
900: }
901: $result .= "</select>\n";
902: # return $debug;
903: return $result;
904: } # end of sub linked_select_forms {
905:
906: =pod
907:
908: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height)
909:
910: Returns a string corresponding to an HTML link to the given help
911: $topic, where $topic corresponds to the name of a .tex file in
912: /home/httpd/html/adm/help/tex, with underscores replaced by
913: spaces.
914:
915: $text will optionally be linked to the same topic, allowing you to
916: link text in addition to the graphic. If you do not want to link
917: text, but wish to specify one of the later parameters, pass an
918: empty string.
919:
920: $stayOnPage is a value that will be interpreted as a boolean. If true,
921: the link will not open a new window. If false, the link will open
922: a new window using Javascript. (Default is false.)
923:
924: $width and $height are optional numerical parameters that will
925: override the width and height of the popped up window, which may
926: be useful for certain help topics with big pictures included.
927:
928: =cut
929:
930: sub help_open_topic {
931: my ($topic, $text, $stayOnPage, $width, $height) = @_;
932: $text = "" if (not defined $text);
933: $stayOnPage = 0 if (not defined $stayOnPage);
934: if ($env{'browser.interface'} eq 'textual') {
935: $stayOnPage=1;
936: }
937: $width = 350 if (not defined $width);
938: $height = 400 if (not defined $height);
939: my $filename = $topic;
940: $filename =~ s/ /_/g;
941:
942: my $template = "";
943: my $link;
944:
945: $topic=~s/\W/\_/g;
946:
947: if (!$stayOnPage) {
948: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
949: } else {
950: $link = "/adm/help/${filename}.hlp";
951: }
952:
953: # Add the text
954: if ($text ne "") {
955: $template.='<span class="LC_help_open_topic">'
956: .'<a target="_top" href="'.$link.'">'
957: .$text.'</a>';
958: }
959:
960: # (Always) Add the graphic
961: my $title = &mt('Online Help');
962: my $helpicon=&lonhttpdurl("/adm/help/help.png");
963: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
964: .'<img src="'.$helpicon.'" border="0"'
965: .' alt="'.&mt('Help: [_1]',$topic).'"'
966: .' title="'.$title.'"'
967: .' /></a>';
968: if ($text ne "") {
969: $template.='</span>';
970: }
971: return $template;
972:
973: }
974:
975: # This is a quicky function for Latex cheatsheet editing, since it
976: # appears in at least four places
977: sub helpLatexCheatsheet {
978: my ($topic,$text,$not_author) = @_;
979: my $out;
980: my $addOther = '';
981: if ($topic) {
982: $addOther = '<span>'.&Apache::loncommon::help_open_topic($topic,&mt($text),
983: undef, undef, 600).
984: '</span> ';
985: }
986: $out = '<span>' # Start cheatsheet
987: .$addOther
988: .'<span>'
989: .&Apache::loncommon::help_open_topic('Greek_Symbols',&mt('Greek Symbols'),
990: undef,undef,600)
991: .'</span> <span>'
992: .&Apache::loncommon::help_open_topic('Other_Symbols',&mt('Other Symbols'),
993: undef,undef,600)
994: .'</span>';
995: unless ($not_author) {
996: $out .= ' <span>'
997: .&Apache::loncommon::help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),
998: undef,undef,600)
999: .'</span>';
1000: }
1001: $out .= '</span>'; # End cheatsheet
1002: return $out;
1003: }
1004:
1005: sub general_help {
1006: my $helptopic='Student_Intro';
1007: if ($env{'request.role'}=~/^(ca|au)/) {
1008: $helptopic='Authoring_Intro';
1009: } elsif ($env{'request.role'}=~/^cc/) {
1010: $helptopic='Course_Coordination_Intro';
1011: } elsif ($env{'request.role'}=~/^dc/) {
1012: $helptopic='Domain_Coordination_Intro';
1013: }
1014: return $helptopic;
1015: }
1016:
1017: sub update_help_link {
1018: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1019: my $origurl = $ENV{'REQUEST_URI'};
1020: $origurl=~s|^/~|/priv/|;
1021: my $timestamp = time;
1022: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1023: $$datum = &escape($$datum);
1024: }
1025:
1026: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1027: my $output .= <<"ENDOUTPUT";
1028: <script type="text/javascript">
1029: banner_link = '$banner_link';
1030: </script>
1031: ENDOUTPUT
1032: return $output;
1033: }
1034:
1035: # now just updates the help link and generates a blue icon
1036: sub help_open_menu {
1037: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1038: = @_;
1039: $stayOnPage = 0 if (not defined $stayOnPage);
1040: # only use pop-up help (stayOnPage == 0)
1041: # if environment.remote is on (using remote control UI)
1042: if ($env{'browser.interface'} eq 'textual' ||
1043: $env{'environment.remote'} eq 'off' ) {
1044: $stayOnPage=1;
1045: }
1046: my $output;
1047: if ($component_help) {
1048: if (!$text) {
1049: $output=&help_open_topic($component_help,undef,$stayOnPage,
1050: $width,$height);
1051: } else {
1052: my $help_text;
1053: $help_text=&unescape($topic);
1054: $output='<table><tr><td>'.
1055: &help_open_topic($component_help,$help_text,$stayOnPage,
1056: $width,$height).'</td></tr></table>';
1057: }
1058: }
1059: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1060: return $output.$banner_link;
1061: }
1062:
1063: sub top_nav_help {
1064: my ($text) = @_;
1065: $text = &mt($text);
1066: my $stay_on_page =
1067: ($env{'browser.interface'} eq 'textual' ||
1068: $env{'environment.remote'} eq 'off' );
1069: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1070: : "javascript:helpMenu('open')";
1071: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1072:
1073: my $title = &mt('Get help');
1074:
1075: return <<"END";
1076: $banner_link
1077: <a href="$link" title="$title">$text</a>
1078: END
1079: }
1080:
1081: sub help_menu_js {
1082: my ($text) = @_;
1083:
1084: my $stayOnPage =
1085: ($env{'browser.interface'} eq 'textual' ||
1086: $env{'environment.remote'} eq 'off' );
1087:
1088: my $width = 620;
1089: my $height = 600;
1090: my $helptopic=&general_help();
1091: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1092: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1093: my $start_page =
1094: &Apache::loncommon::start_page('Help Menu', undef,
1095: {'frameset' => 1,
1096: 'js_ready' => 1,
1097: 'add_entries' => {
1098: 'border' => '0',
1099: 'rows' => "110,*",},});
1100: my $end_page =
1101: &Apache::loncommon::end_page({'frameset' => 1,
1102: 'js_ready' => 1,});
1103:
1104: my $template .= <<"ENDTEMPLATE";
1105: <script type="text/javascript">
1106: // <!-- BEGIN LON-CAPA Internal
1107: // <![CDATA[
1108: var banner_link = '';
1109: function helpMenu(target) {
1110: var caller = this;
1111: if (target == 'open') {
1112: var newWindow = null;
1113: try {
1114: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1115: }
1116: catch(error) {
1117: writeHelp(caller);
1118: return;
1119: }
1120: if (newWindow) {
1121: caller = newWindow;
1122: }
1123: }
1124: writeHelp(caller);
1125: return;
1126: }
1127: function writeHelp(caller) {
1128: caller.document.writeln('$start_page<frame name="bannerframe" src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1129: caller.document.close()
1130: caller.focus()
1131: }
1132: // ]]>
1133: // END LON-CAPA Internal -->
1134: </script>
1135: ENDTEMPLATE
1136: return $template;
1137: }
1138:
1139: sub help_open_bug {
1140: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1141: unless ($env{'user.adv'}) { return ''; }
1142: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1143: $text = "" if (not defined $text);
1144: $stayOnPage = 0 if (not defined $stayOnPage);
1145: if ($env{'browser.interface'} eq 'textual' ||
1146: $env{'environment.remote'} eq 'off' ) {
1147: $stayOnPage=1;
1148: }
1149: $width = 600 if (not defined $width);
1150: $height = 600 if (not defined $height);
1151:
1152: $topic=~s/\W+/\+/g;
1153: my $link='';
1154: my $template='';
1155: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1156: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1157: if (!$stayOnPage)
1158: {
1159: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1160: }
1161: else
1162: {
1163: $link = $url;
1164: }
1165: # Add the text
1166: if ($text ne "")
1167: {
1168: $template .=
1169: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1170: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1171: }
1172:
1173: # Add the graphic
1174: my $title = &mt('Report a Bug');
1175: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1176: $template .= <<"ENDTEMPLATE";
1177: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1178: ENDTEMPLATE
1179: if ($text ne '') { $template.='</td></tr></table>' };
1180: return $template;
1181:
1182: }
1183:
1184: sub help_open_faq {
1185: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1186: unless ($env{'user.adv'}) { return ''; }
1187: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1188: $text = "" if (not defined $text);
1189: $stayOnPage = 0 if (not defined $stayOnPage);
1190: if ($env{'browser.interface'} eq 'textual' ||
1191: $env{'environment.remote'} eq 'off' ) {
1192: $stayOnPage=1;
1193: }
1194: $width = 350 if (not defined $width);
1195: $height = 400 if (not defined $height);
1196:
1197: $topic=~s/\W+/\+/g;
1198: my $link='';
1199: my $template='';
1200: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1201: if (!$stayOnPage)
1202: {
1203: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1204: }
1205: else
1206: {
1207: $link = $url;
1208: }
1209:
1210: # Add the text
1211: if ($text ne "")
1212: {
1213: $template .=
1214: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1215: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1216: }
1217:
1218: # Add the graphic
1219: my $title = &mt('View the FAQ');
1220: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1221: $template .= <<"ENDTEMPLATE";
1222: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1223: ENDTEMPLATE
1224: if ($text ne '') { $template.='</td></tr></table>' };
1225: return $template;
1226:
1227: }
1228:
1229: ###############################################################
1230: ###############################################################
1231:
1232: =pod
1233:
1234: =item * &change_content_javascript():
1235:
1236: This and the next function allow you to create small sections of an
1237: otherwise static HTML page that you can update on the fly with
1238: Javascript, even in Netscape 4.
1239:
1240: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1241: must be written to the HTML page once. It will prove the Javascript
1242: function "change(name, content)". Calling the change function with the
1243: name of the section
1244: you want to update, matching the name passed to C<changable_area>, and
1245: the new content you want to put in there, will put the content into
1246: that area.
1247:
1248: B<Note>: Netscape 4 only reserves enough space for the changable area
1249: to contain room for the original contents. You need to "make space"
1250: for whatever changes you wish to make, and be B<sure> to check your
1251: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1252: it's adequate for updating a one-line status display, but little more.
1253: This script will set the space to 100% width, so you only need to
1254: worry about height in Netscape 4.
1255:
1256: Modern browsers are much less limiting, and if you can commit to the
1257: user not using Netscape 4, this feature may be used freely with
1258: pretty much any HTML.
1259:
1260: =cut
1261:
1262: sub change_content_javascript {
1263: # If we're on Netscape 4, we need to use Layer-based code
1264: if ($env{'browser.type'} eq 'netscape' &&
1265: $env{'browser.version'} =~ /^4\./) {
1266: return (<<NETSCAPE4);
1267: function change(name, content) {
1268: doc = document.layers[name+"___escape"].layers[0].document;
1269: doc.open();
1270: doc.write(content);
1271: doc.close();
1272: }
1273: NETSCAPE4
1274: } else {
1275: # Otherwise, we need to use semi-standards-compliant code
1276: # (technically, "innerHTML" isn't standard but the equivalent
1277: # is really scary, and every useful browser supports it
1278: return (<<DOMBASED);
1279: function change(name, content) {
1280: element = document.getElementById(name);
1281: element.innerHTML = content;
1282: }
1283: DOMBASED
1284: }
1285: }
1286:
1287: =pod
1288:
1289: =item * &changable_area($name,$origContent):
1290:
1291: This provides a "changable area" that can be modified on the fly via
1292: the Javascript code provided in C<change_content_javascript>. $name is
1293: the name you will use to reference the area later; do not repeat the
1294: same name on a given HTML page more then once. $origContent is what
1295: the area will originally contain, which can be left blank.
1296:
1297: =cut
1298:
1299: sub changable_area {
1300: my ($name, $origContent) = @_;
1301:
1302: if ($env{'browser.type'} eq 'netscape' &&
1303: $env{'browser.version'} =~ /^4\./) {
1304: # If this is netscape 4, we need to use the Layer tag
1305: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1306: } else {
1307: return "<span id='$name'>$origContent</span>";
1308: }
1309: }
1310:
1311: =pod
1312:
1313: =item * &viewport_geometry_js
1314:
1315: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1316:
1317: =cut
1318:
1319:
1320: sub viewport_geometry_js {
1321: return <<"GEOMETRY";
1322: var Geometry = {};
1323: function init_geometry() {
1324: if (Geometry.init) { return };
1325: Geometry.init=1;
1326: if (window.innerHeight) {
1327: Geometry.getViewportHeight = function() { return window.innerHeight; };
1328: Geometry.getViewportWidth = function() { return window.innerWidth; };
1329: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1330: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1331: }
1332: else if (document.documentElement && document.documentElement.clientHeight) {
1333: Geometry.getViewportHeight =
1334: function() { return document.documentElement.clientHeight; };
1335: Geometry.getViewportWidth =
1336: function() { return document.documentElement.clientWidth; };
1337:
1338: Geometry.getHorizontalScroll =
1339: function() { return document.documentElement.scrollLeft; };
1340: Geometry.getVerticalScroll =
1341: function() { return document.documentElement.scrollTop; };
1342: }
1343: else if (document.body.clientHeight) {
1344: Geometry.getViewportHeight =
1345: function() { return document.body.clientHeight; };
1346: Geometry.getViewportWidth =
1347: function() { return document.body.clientWidth; };
1348: Geometry.getHorizontalScroll =
1349: function() { return document.body.scrollLeft; };
1350: Geometry.getVerticalScroll =
1351: function() { return document.body.scrollTop; };
1352: }
1353: }
1354:
1355: GEOMETRY
1356: }
1357:
1358: =pod
1359:
1360: =item * &viewport_size_js()
1361:
1362: 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.
1363:
1364: =cut
1365:
1366: sub viewport_size_js {
1367: my $geometry = &viewport_geometry_js();
1368: return <<"DIMS";
1369:
1370: $geometry
1371:
1372: function getViewportDims(width,height) {
1373: init_geometry();
1374: width.value = Geometry.getViewportWidth();
1375: height.value = Geometry.getViewportHeight();
1376: return;
1377: }
1378:
1379: DIMS
1380: }
1381:
1382: =pod
1383:
1384: =item * &resize_textarea_js()
1385:
1386: emits the needed javascript to resize a textarea to be as big as possible
1387:
1388: creates a function resize_textrea that takes two IDs first should be
1389: the id of the element to resize, second should be the id of a div that
1390: surrounds everything that comes after the textarea, this routine needs
1391: to be attached to the <body> for the onload and onresize events.
1392:
1393: =back
1394:
1395: =cut
1396:
1397: sub resize_textarea_js {
1398: my $geometry = &viewport_geometry_js();
1399: return <<"RESIZE";
1400: <script type="text/javascript">
1401: $geometry
1402:
1403: function getX(element) {
1404: var x = 0;
1405: while (element) {
1406: x += element.offsetLeft;
1407: element = element.offsetParent;
1408: }
1409: return x;
1410: }
1411: function getY(element) {
1412: var y = 0;
1413: while (element) {
1414: y += element.offsetTop;
1415: element = element.offsetParent;
1416: }
1417: return y;
1418: }
1419:
1420:
1421: function resize_textarea(textarea_id,bottom_id) {
1422: init_geometry();
1423: var textarea = document.getElementById(textarea_id);
1424: //alert(textarea);
1425:
1426: var textarea_top = getY(textarea);
1427: var textarea_height = textarea.offsetHeight;
1428: var bottom = document.getElementById(bottom_id);
1429: var bottom_top = getY(bottom);
1430: var bottom_height = bottom.offsetHeight;
1431: var window_height = Geometry.getViewportHeight();
1432: var fudge = 23;
1433: var new_height = window_height-fudge-textarea_top-bottom_height;
1434: if (new_height < 300) {
1435: new_height = 300;
1436: }
1437: textarea.style.height=new_height+'px';
1438: }
1439: </script>
1440: RESIZE
1441:
1442: }
1443:
1444: =pod
1445:
1446: =head1 Excel and CSV file utility routines
1447:
1448: =over 4
1449:
1450: =cut
1451:
1452: ###############################################################
1453: ###############################################################
1454:
1455: =pod
1456:
1457: =item * &csv_translate($text)
1458:
1459: Translate $text to allow it to be output as a 'comma separated values'
1460: format.
1461:
1462: =cut
1463:
1464: ###############################################################
1465: ###############################################################
1466: sub csv_translate {
1467: my $text = shift;
1468: $text =~ s/\"/\"\"/g;
1469: $text =~ s/\n/ /g;
1470: return $text;
1471: }
1472:
1473: ###############################################################
1474: ###############################################################
1475:
1476: =pod
1477:
1478: =item * &define_excel_formats()
1479:
1480: Define some commonly used Excel cell formats.
1481:
1482: Currently supported formats:
1483:
1484: =over 4
1485:
1486: =item header
1487:
1488: =item bold
1489:
1490: =item h1
1491:
1492: =item h2
1493:
1494: =item h3
1495:
1496: =item h4
1497:
1498: =item i
1499:
1500: =item date
1501:
1502: =back
1503:
1504: Inputs: $workbook
1505:
1506: Returns: $format, a hash reference.
1507:
1508: =cut
1509:
1510: ###############################################################
1511: ###############################################################
1512: sub define_excel_formats {
1513: my ($workbook) = @_;
1514: my $format;
1515: $format->{'header'} = $workbook->add_format(bold => 1,
1516: bottom => 1,
1517: align => 'center');
1518: $format->{'bold'} = $workbook->add_format(bold=>1);
1519: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1520: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1521: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1522: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1523: $format->{'i'} = $workbook->add_format(italic=>1);
1524: $format->{'date'} = $workbook->add_format(num_format=>
1525: 'mm/dd/yyyy hh:mm:ss');
1526: return $format;
1527: }
1528:
1529: ###############################################################
1530: ###############################################################
1531:
1532: =pod
1533:
1534: =item * &create_workbook()
1535:
1536: Create an Excel worksheet. If it fails, output message on the
1537: request object and return undefs.
1538:
1539: Inputs: Apache request object
1540:
1541: Returns (undef) on failure,
1542: Excel worksheet object, scalar with filename, and formats
1543: from &Apache::loncommon::define_excel_formats on success
1544:
1545: =cut
1546:
1547: ###############################################################
1548: ###############################################################
1549: sub create_workbook {
1550: my ($r) = @_;
1551: #
1552: # Create the excel spreadsheet
1553: my $filename = '/prtspool/'.
1554: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1555: time.'_'.rand(1000000000).'.xls';
1556: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1557: if (! defined($workbook)) {
1558: $r->log_error("Error creating excel spreadsheet $filename: $!");
1559: $r->print('<p>'.&mt("Unable to create new Excel file. ".
1560: "This error has been logged. ".
1561: "Please alert your LON-CAPA administrator").
1562: '</p>');
1563: return (undef);
1564: }
1565: #
1566: $workbook->set_tempdir('/home/httpd/perl/tmp');
1567: #
1568: my $format = &Apache::loncommon::define_excel_formats($workbook);
1569: return ($workbook,$filename,$format);
1570: }
1571:
1572: ###############################################################
1573: ###############################################################
1574:
1575: =pod
1576:
1577: =item * &create_text_file()
1578:
1579: Create a file to write to and eventually make available to the user.
1580: If file creation fails, outputs an error message on the request object and
1581: return undefs.
1582:
1583: Inputs: Apache request object, and file suffix
1584:
1585: Returns (undef) on failure,
1586: Filehandle and filename on success.
1587:
1588: =cut
1589:
1590: ###############################################################
1591: ###############################################################
1592: sub create_text_file {
1593: my ($r,$suffix) = @_;
1594: if (! defined($suffix)) { $suffix = 'txt'; };
1595: my $fh;
1596: my $filename = '/prtspool/'.
1597: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1598: time.'_'.rand(1000000000).'.'.$suffix;
1599: $fh = Apache::File->new('>/home/httpd'.$filename);
1600: if (! defined($fh)) {
1601: $r->log_error("Couldn't open $filename for output $!");
1602: $r->print(&mt('Problems occurred in creating the output file. '
1603: .'This error has been logged. '
1604: .'Please alert your LON-CAPA administrator.'));
1605: }
1606: return ($fh,$filename)
1607: }
1608:
1609:
1610: =pod
1611:
1612: =back
1613:
1614: =cut
1615:
1616: ###############################################################
1617: ## Home server <option> list generating code ##
1618: ###############################################################
1619:
1620: # ------------------------------------------
1621:
1622: sub domain_select {
1623: my ($name,$value,$multiple)=@_;
1624: my %domains=map {
1625: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1626: } &Apache::lonnet::all_domains();
1627: if ($multiple) {
1628: $domains{''}=&mt('Any domain');
1629: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1630: return &multiple_select_form($name,$value,4,\%domains);
1631: } else {
1632: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1633: return &select_form($name,$value,%domains);
1634: }
1635: }
1636:
1637: #-------------------------------------------
1638:
1639: =pod
1640:
1641: =head1 Routines for form select boxes
1642:
1643: =over 4
1644:
1645: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1646:
1647: Returns a string containing a <select> element int multiple mode
1648:
1649:
1650: Args:
1651: $name - name of the <select> element
1652: $value - scalar or array ref of values that should already be selected
1653: $size - number of rows long the select element is
1654: $hash - the elements should be 'option' => 'shown text'
1655: (shown text should already have been &mt())
1656: $order - (optional) array ref of the order to show the elements in
1657:
1658: =cut
1659:
1660: #-------------------------------------------
1661: sub multiple_select_form {
1662: my ($name,$value,$size,$hash,$order)=@_;
1663: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1664: my $output='';
1665: if (! defined($size)) {
1666: $size = 4;
1667: if (scalar(keys(%$hash))<4) {
1668: $size = scalar(keys(%$hash));
1669: }
1670: }
1671: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1672: my @order;
1673: if (ref($order) eq 'ARRAY') {
1674: @order = @{$order};
1675: } else {
1676: @order = sort(keys(%$hash));
1677: }
1678: if (exists($$hash{'select_form_order'})) {
1679: @order = @{$$hash{'select_form_order'}};
1680: }
1681:
1682: foreach my $key (@order) {
1683: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1684: $output.='selected="selected" ' if ($selected{$key});
1685: $output.='>'.$hash->{$key}."</option>\n";
1686: }
1687: $output.="</select>\n";
1688: return $output;
1689: }
1690:
1691: #-------------------------------------------
1692:
1693: =pod
1694:
1695: =item * &select_form($defdom,$name,%hash)
1696:
1697: Returns a string containing a <select name='$name' size='1'> form to
1698: allow a user to select options from a hash option_name => displayed text.
1699: See lonrights.pm for an example invocation and use.
1700:
1701: =cut
1702:
1703: #-------------------------------------------
1704: sub select_form {
1705: my ($def,$name,%hash) = @_;
1706: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1707: my @keys;
1708: if (exists($hash{'select_form_order'})) {
1709: @keys=@{$hash{'select_form_order'}};
1710: } else {
1711: @keys=sort(keys(%hash));
1712: }
1713: foreach my $key (@keys) {
1714: $selectform.=
1715: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
1716: ($key eq $def ? 'selected="selected" ' : '').
1717: ">".&mt($hash{$key})."</option>\n";
1718: }
1719: $selectform.="</select>";
1720: return $selectform;
1721: }
1722:
1723: # For display filters
1724:
1725: sub display_filter {
1726: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1727: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1728: return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1729: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
1730: (&mt('all'),10,20,50,100,1000,10000))).
1731: '</label></span> <span class="LC_nobreak">'.
1732: &mt('Filter [_1]',
1733: &select_form($env{'form.displayfilter'},
1734: 'displayfilter',
1735: ('currentfolder' => 'Current folder/page',
1736: 'containing' => 'Containing phrase',
1737: 'none' => 'None'))).
1738: '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1739: }
1740:
1741: sub gradeleveldescription {
1742: my $gradelevel=shift;
1743: my %gradelevels=(0 => 'Not specified',
1744: 1 => 'Grade 1',
1745: 2 => 'Grade 2',
1746: 3 => 'Grade 3',
1747: 4 => 'Grade 4',
1748: 5 => 'Grade 5',
1749: 6 => 'Grade 6',
1750: 7 => 'Grade 7',
1751: 8 => 'Grade 8',
1752: 9 => 'Grade 9',
1753: 10 => 'Grade 10',
1754: 11 => 'Grade 11',
1755: 12 => 'Grade 12',
1756: 13 => 'Grade 13',
1757: 14 => '100 Level',
1758: 15 => '200 Level',
1759: 16 => '300 Level',
1760: 17 => '400 Level',
1761: 18 => 'Graduate Level');
1762: return &mt($gradelevels{$gradelevel});
1763: }
1764:
1765: sub select_level_form {
1766: my ($deflevel,$name)=@_;
1767: unless ($deflevel) { $deflevel=0; }
1768: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1769: for (my $i=0; $i<=18; $i++) {
1770: $selectform.="<option value=\"$i\" ".
1771: ($i==$deflevel ? 'selected="selected" ' : '').
1772: ">".&gradeleveldescription($i)."</option>\n";
1773: }
1774: $selectform.="</select>";
1775: return $selectform;
1776: }
1777:
1778: #-------------------------------------------
1779:
1780: =pod
1781:
1782: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$autosubmit)
1783:
1784: Returns a string containing a <select name='$name' size='1'> form to
1785: allow a user to select the domain to preform an operation in.
1786: See loncreateuser.pm for an example invocation and use.
1787:
1788: If the $includeempty flag is set, it also includes an empty choice ("no domain
1789: selected");
1790:
1791: If the $showdomdesc flag is set, the domain name is followed by the domain description.
1792:
1793: If the $autosubmit flag is set, the form containing the domain selector will be auto-submitted by an onchange action.
1794:
1795: =cut
1796:
1797: #-------------------------------------------
1798: sub select_dom_form {
1799: my ($defdom,$name,$includeempty,$showdomdesc,$autosubmit) = @_;
1800: my $onchange;
1801: if ($autosubmit) {
1802: $onchange = ' onchange="this.form.submit()"';
1803: }
1804: my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1805: if ($includeempty) { @domains=('',@domains); }
1806: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1807: foreach my $dom (@domains) {
1808: $selectdomain.="<option value=\"$dom\" ".
1809: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
1810: if ($showdomdesc) {
1811: if ($dom ne '') {
1812: my $domdesc = &Apache::lonnet::domain($dom,'description');
1813: if ($domdesc ne '') {
1814: $selectdomain .= ' ('.$domdesc.')';
1815: }
1816: }
1817: }
1818: $selectdomain .= "</option>\n";
1819: }
1820: $selectdomain.="</select>";
1821: return $selectdomain;
1822: }
1823:
1824: #-------------------------------------------
1825:
1826: =pod
1827:
1828: =item * &home_server_form_item($domain,$name,$defaultflag)
1829:
1830: input: 4 arguments (two required, two optional) -
1831: $domain - domain of new user
1832: $name - name of form element
1833: $default - Value of 'default' causes a default item to be first
1834: option, and selected by default.
1835: $hide - Value of 'hide' causes hiding of the name of the server,
1836: if 1 server found, or default, if 0 found.
1837: output: returns 2 items:
1838: (a) form element which contains either:
1839: (i) <select name="$name">
1840: <option value="$hostid1">$hostid $servers{$hostid}</option>
1841: <option value="$hostid2">$hostid $servers{$hostid}</option>
1842: </select>
1843: form item if there are multiple library servers in $domain, or
1844: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
1845: if there is only one library server in $domain.
1846:
1847: (b) number of library servers found.
1848:
1849: See loncreateuser.pm for example of use.
1850:
1851: =cut
1852:
1853: #-------------------------------------------
1854: sub home_server_form_item {
1855: my ($domain,$name,$default,$hide) = @_;
1856: my %servers = &Apache::lonnet::get_servers($domain,'library');
1857: my $result;
1858: my $numlib = keys(%servers);
1859: if ($numlib > 1) {
1860: $result .= '<select name="'.$name.'" />'."\n";
1861: if ($default) {
1862: $result .= '<option value="default" selected>'.&mt('default').
1863: '</option>'."\n";
1864: }
1865: foreach my $hostid (sort(keys(%servers))) {
1866: $result.= '<option value="'.$hostid.'">'.
1867: $hostid.' '.$servers{$hostid}."</option>\n";
1868: }
1869: $result .= '</select>'."\n";
1870: } elsif ($numlib == 1) {
1871: my $hostid;
1872: foreach my $item (keys(%servers)) {
1873: $hostid = $item;
1874: }
1875: $result .= '<input type="hidden" name="'.$name.'" value="'.
1876: $hostid.'" />';
1877: if (!$hide) {
1878: $result .= $hostid.' '.$servers{$hostid};
1879: }
1880: $result .= "\n";
1881: } elsif ($default) {
1882: $result .= '<input type="hidden" name="'.$name.
1883: '" value="default" />';
1884: if (!$hide) {
1885: $result .= &mt('default');
1886: }
1887: $result .= "\n";
1888: }
1889: return ($result,$numlib);
1890: }
1891:
1892: =pod
1893:
1894: =back
1895:
1896: =cut
1897:
1898: ###############################################################
1899: ## Decoding User Agent ##
1900: ###############################################################
1901:
1902: =pod
1903:
1904: =head1 Decoding the User Agent
1905:
1906: =over 4
1907:
1908: =item * &decode_user_agent()
1909:
1910: Inputs: $r
1911:
1912: Outputs:
1913:
1914: =over 4
1915:
1916: =item * $httpbrowser
1917:
1918: =item * $clientbrowser
1919:
1920: =item * $clientversion
1921:
1922: =item * $clientmathml
1923:
1924: =item * $clientunicode
1925:
1926: =item * $clientos
1927:
1928: =back
1929:
1930: =back
1931:
1932: =cut
1933:
1934: ###############################################################
1935: ###############################################################
1936: sub decode_user_agent {
1937: my ($r)=@_;
1938: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
1939: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
1940: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1941: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1942: my $clientbrowser='unknown';
1943: my $clientversion='0';
1944: my $clientmathml='';
1945: my $clientunicode='0';
1946: for (my $i=0;$i<=$#browsertype;$i++) {
1947: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
1948: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
1949: $clientbrowser=$bname;
1950: $httpbrowser=~/$vreg/i;
1951: $clientversion=$1;
1952: $clientmathml=($clientversion>=$minv);
1953: $clientunicode=($clientversion>=$univ);
1954: }
1955: }
1956: my $clientos='unknown';
1957: if (($httpbrowser=~/linux/i) ||
1958: ($httpbrowser=~/unix/i) ||
1959: ($httpbrowser=~/ux/i) ||
1960: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
1961: if (($httpbrowser=~/vax/i) ||
1962: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
1963: if ($httpbrowser=~/next/i) { $clientos='next'; }
1964: if (($httpbrowser=~/mac/i) ||
1965: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1966: if ($httpbrowser=~/win/i) { $clientos='win'; }
1967: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1968: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1969: $clientunicode,$clientos,);
1970: }
1971:
1972: ###############################################################
1973: ## Authentication changing form generation subroutines ##
1974: ###############################################################
1975: ##
1976: ## All of the authform_xxxxxxx subroutines take their inputs in a
1977: ## hash, and have reasonable default values.
1978: ##
1979: ## formname = the name given in the <form> tag.
1980: #-------------------------------------------
1981:
1982: =pod
1983:
1984: =head1 Authentication Routines
1985:
1986: =over 4
1987:
1988: =item * &authform_xxxxxx()
1989:
1990: The authform_xxxxxx subroutines provide javascript and html forms which
1991: handle some of the conveniences required for authentication forms.
1992: This is not an optimal method, but it works.
1993:
1994: =over 4
1995:
1996: =item * authform_header
1997:
1998: =item * authform_authorwarning
1999:
2000: =item * authform_nochange
2001:
2002: =item * authform_kerberos
2003:
2004: =item * authform_internal
2005:
2006: =item * authform_filesystem
2007:
2008: =back
2009:
2010: See loncreateuser.pm for invocation and use examples.
2011:
2012: =cut
2013:
2014: #-------------------------------------------
2015: sub authform_header{
2016: my %in = (
2017: formname => 'cu',
2018: kerb_def_dom => '',
2019: @_,
2020: );
2021: $in{'formname'} = 'document.' . $in{'formname'};
2022: my $result='';
2023:
2024: #---------------------------------------------- Code for upper case translation
2025: my $Javascript_toUpperCase;
2026: unless ($in{kerb_def_dom}) {
2027: $Javascript_toUpperCase =<<"END";
2028: switch (choice) {
2029: case 'krb': currentform.elements[choicearg].value =
2030: currentform.elements[choicearg].value.toUpperCase();
2031: break;
2032: default:
2033: }
2034: END
2035: } else {
2036: $Javascript_toUpperCase = "";
2037: }
2038:
2039: my $radioval = "'nochange'";
2040: if (defined($in{'curr_authtype'})) {
2041: if ($in{'curr_authtype'} ne '') {
2042: $radioval = "'".$in{'curr_authtype'}."arg'";
2043: }
2044: }
2045: my $argfield = 'null';
2046: if (defined($in{'mode'})) {
2047: if ($in{'mode'} eq 'modifycourse') {
2048: if (defined($in{'curr_autharg'})) {
2049: if ($in{'curr_autharg'} ne '') {
2050: $argfield = "'$in{'curr_autharg'}'";
2051: }
2052: }
2053: }
2054: }
2055:
2056: $result.=<<"END";
2057: var current = new Object();
2058: current.radiovalue = $radioval;
2059: current.argfield = $argfield;
2060:
2061: function changed_radio(choice,currentform) {
2062: var choicearg = choice + 'arg';
2063: // If a radio button in changed, we need to change the argfield
2064: if (current.radiovalue != choice) {
2065: current.radiovalue = choice;
2066: if (current.argfield != null) {
2067: currentform.elements[current.argfield].value = '';
2068: }
2069: if (choice == 'nochange') {
2070: current.argfield = null;
2071: } else {
2072: current.argfield = choicearg;
2073: switch(choice) {
2074: case 'krb':
2075: currentform.elements[current.argfield].value =
2076: "$in{'kerb_def_dom'}";
2077: break;
2078: default:
2079: break;
2080: }
2081: }
2082: }
2083: return;
2084: }
2085:
2086: function changed_text(choice,currentform) {
2087: var choicearg = choice + 'arg';
2088: if (currentform.elements[choicearg].value !='') {
2089: $Javascript_toUpperCase
2090: // clear old field
2091: if ((current.argfield != choicearg) && (current.argfield != null)) {
2092: currentform.elements[current.argfield].value = '';
2093: }
2094: current.argfield = choicearg;
2095: }
2096: set_auth_radio_buttons(choice,currentform);
2097: return;
2098: }
2099:
2100: function set_auth_radio_buttons(newvalue,currentform) {
2101: var i=0;
2102: while (i < currentform.login.length) {
2103: if (currentform.login[i].value == newvalue) { break; }
2104: i++;
2105: }
2106: if (i == currentform.login.length) {
2107: return;
2108: }
2109: current.radiovalue = newvalue;
2110: currentform.login[i].checked = true;
2111: return;
2112: }
2113: END
2114: return $result;
2115: }
2116:
2117: sub authform_authorwarning{
2118: my $result='';
2119: $result='<i>'.
2120: &mt('As a general rule, only authors or co-authors should be '.
2121: 'filesystem authenticated '.
2122: '(which allows access to the server filesystem).')."</i>\n";
2123: return $result;
2124: }
2125:
2126: sub authform_nochange{
2127: my %in = (
2128: formname => 'document.cu',
2129: kerb_def_dom => 'MSU.EDU',
2130: @_,
2131: );
2132: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2133: my $result;
2134: if (keys(%can_assign) == 0) {
2135: $result = &mt('Under you current role you are not permitted to change login settings for this user');
2136: } else {
2137: $result = '<label>'.&mt('[_1] Do not change login data',
2138: '<input type="radio" name="login" value="nochange" '.
2139: 'checked="checked" onclick="'.
2140: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2141: '</label>';
2142: }
2143: return $result;
2144: }
2145:
2146: sub authform_kerberos {
2147: my %in = (
2148: formname => 'document.cu',
2149: kerb_def_dom => 'MSU.EDU',
2150: kerb_def_auth => 'krb4',
2151: @_,
2152: );
2153: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2154: $autharg,$jscall);
2155: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2156: if ($in{'kerb_def_auth'} eq 'krb5') {
2157: $check5 = ' checked="checked"';
2158: } else {
2159: $check4 = ' checked="checked"';
2160: }
2161: $krbarg = $in{'kerb_def_dom'};
2162: if (defined($in{'curr_authtype'})) {
2163: if ($in{'curr_authtype'} eq 'krb') {
2164: $krbcheck = ' checked="checked"';
2165: if (defined($in{'mode'})) {
2166: if ($in{'mode'} eq 'modifyuser') {
2167: $krbcheck = '';
2168: }
2169: }
2170: if (defined($in{'curr_kerb_ver'})) {
2171: if ($in{'curr_krb_ver'} eq '5') {
2172: $check5 = ' checked="checked"';
2173: $check4 = '';
2174: } else {
2175: $check4 = ' checked="checked"';
2176: $check5 = '';
2177: }
2178: }
2179: if (defined($in{'curr_autharg'})) {
2180: $krbarg = $in{'curr_autharg'};
2181: }
2182: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2183: if (defined($in{'curr_autharg'})) {
2184: $result =
2185: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2186: $in{'curr_autharg'},$krbver);
2187: } else {
2188: $result =
2189: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2190: }
2191: return $result;
2192: }
2193: }
2194: } else {
2195: if ($authnum == 1) {
2196: $authtype = '<input type="hidden" name="login" value="krb" />';
2197: }
2198: }
2199: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2200: return;
2201: } elsif ($authtype eq '') {
2202: if (defined($in{'mode'})) {
2203: if ($in{'mode'} eq 'modifycourse') {
2204: if ($authnum == 1) {
2205: $authtype = '<input type="hidden" name="login" value="krb" />';
2206: }
2207: }
2208: }
2209: }
2210: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2211: if ($authtype eq '') {
2212: $authtype = '<input type="radio" name="login" value="krb" '.
2213: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2214: $krbcheck.' />';
2215: }
2216: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
2217: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
2218: $in{'curr_authtype'} eq 'krb5') ||
2219: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
2220: $in{'curr_authtype'} eq 'krb4')) {
2221: $result .= &mt
2222: ('[_1] Kerberos authenticated with domain [_2] '.
2223: '[_3] Version 4 [_4] Version 5 [_5]',
2224: '<label>'.$authtype,
2225: '</label><input type="text" size="10" name="krbarg" '.
2226: 'value="'.$krbarg.'" '.
2227: 'onchange="'.$jscall.'" />',
2228: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2229: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2230: '</label>');
2231: } elsif ($can_assign{'krb4'}) {
2232: $result .= &mt
2233: ('[_1] Kerberos authenticated with domain [_2] '.
2234: '[_3] Version 4 [_4]',
2235: '<label>'.$authtype,
2236: '</label><input type="text" size="10" name="krbarg" '.
2237: 'value="'.$krbarg.'" '.
2238: 'onchange="'.$jscall.'" />',
2239: '<label><input type="hidden" name="krbver" value="4" />',
2240: '</label>');
2241: } elsif ($can_assign{'krb5'}) {
2242: $result .= &mt
2243: ('[_1] Kerberos authenticated with domain [_2] '.
2244: '[_3] Version 5 [_4]',
2245: '<label>'.$authtype,
2246: '</label><input type="text" size="10" name="krbarg" '.
2247: 'value="'.$krbarg.'" '.
2248: 'onchange="'.$jscall.'" />',
2249: '<label><input type="hidden" name="krbver" value="5" />',
2250: '</label>');
2251: }
2252: return $result;
2253: }
2254:
2255: sub authform_internal{
2256: my %in = (
2257: formname => 'document.cu',
2258: kerb_def_dom => 'MSU.EDU',
2259: @_,
2260: );
2261: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
2262: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2263: if (defined($in{'curr_authtype'})) {
2264: if ($in{'curr_authtype'} eq 'int') {
2265: if ($can_assign{'int'}) {
2266: $intcheck = 'checked="checked" ';
2267: if (defined($in{'mode'})) {
2268: if ($in{'mode'} eq 'modifyuser') {
2269: $intcheck = '';
2270: }
2271: }
2272: if (defined($in{'curr_autharg'})) {
2273: $intarg = $in{'curr_autharg'};
2274: }
2275: } else {
2276: $result = &mt('Currently internally authenticated.');
2277: return $result;
2278: }
2279: }
2280: } else {
2281: if ($authnum == 1) {
2282: $authtype = '<input type="hidden" name="login" value="int" />';
2283: }
2284: }
2285: if (!$can_assign{'int'}) {
2286: return;
2287: } elsif ($authtype eq '') {
2288: if (defined($in{'mode'})) {
2289: if ($in{'mode'} eq 'modifycourse') {
2290: if ($authnum == 1) {
2291: $authtype = '<input type="hidden" name="login" value="int" />';
2292: }
2293: }
2294: }
2295: }
2296: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2297: if ($authtype eq '') {
2298: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2299: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2300: }
2301: $autharg = '<input type="password" size="10" name="intarg" value="'.
2302: $intarg.'" onchange="'.$jscall.'" />';
2303: $result = &mt
2304: ('[_1] Internally authenticated (with initial password [_2])',
2305: '<label>'.$authtype,'</label>'.$autharg);
2306: $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>';
2307: return $result;
2308: }
2309:
2310: sub authform_local{
2311: my %in = (
2312: formname => 'document.cu',
2313: kerb_def_dom => 'MSU.EDU',
2314: @_,
2315: );
2316: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
2317: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2318: if (defined($in{'curr_authtype'})) {
2319: if ($in{'curr_authtype'} eq 'loc') {
2320: if ($can_assign{'loc'}) {
2321: $loccheck = 'checked="checked" ';
2322: if (defined($in{'mode'})) {
2323: if ($in{'mode'} eq 'modifyuser') {
2324: $loccheck = '';
2325: }
2326: }
2327: if (defined($in{'curr_autharg'})) {
2328: $locarg = $in{'curr_autharg'};
2329: }
2330: } else {
2331: $result = &mt('Currently using local (institutional) authentication.');
2332: return $result;
2333: }
2334: }
2335: } else {
2336: if ($authnum == 1) {
2337: $authtype = '<input type="hidden" name="login" value="loc" />';
2338: }
2339: }
2340: if (!$can_assign{'loc'}) {
2341: return;
2342: } elsif ($authtype eq '') {
2343: if (defined($in{'mode'})) {
2344: if ($in{'mode'} eq 'modifycourse') {
2345: if ($authnum == 1) {
2346: $authtype = '<input type="hidden" name="login" value="loc" />';
2347: }
2348: }
2349: }
2350: }
2351: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2352: if ($authtype eq '') {
2353: $authtype = '<input type="radio" name="login" value="loc" '.
2354: $loccheck.' onchange="'.$jscall.'" onclick="'.
2355: $jscall.'" />';
2356: }
2357: $autharg = '<input type="text" size="10" name="locarg" value="'.
2358: $locarg.'" onchange="'.$jscall.'" />';
2359: $result = &mt('[_1] Local Authentication with argument [_2]',
2360: '<label>'.$authtype,'</label>'.$autharg);
2361: return $result;
2362: }
2363:
2364: sub authform_filesystem{
2365: my %in = (
2366: formname => 'document.cu',
2367: kerb_def_dom => 'MSU.EDU',
2368: @_,
2369: );
2370: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
2371: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2372: if (defined($in{'curr_authtype'})) {
2373: if ($in{'curr_authtype'} eq 'fsys') {
2374: if ($can_assign{'fsys'}) {
2375: $fsyscheck = 'checked="checked" ';
2376: if (defined($in{'mode'})) {
2377: if ($in{'mode'} eq 'modifyuser') {
2378: $fsyscheck = '';
2379: }
2380: }
2381: } else {
2382: $result = &mt('Currently Filesystem Authenticated.');
2383: return $result;
2384: }
2385: }
2386: } else {
2387: if ($authnum == 1) {
2388: $authtype = '<input type="hidden" name="login" value="fsys" />';
2389: }
2390: }
2391: if (!$can_assign{'fsys'}) {
2392: return;
2393: } elsif ($authtype eq '') {
2394: if (defined($in{'mode'})) {
2395: if ($in{'mode'} eq 'modifycourse') {
2396: if ($authnum == 1) {
2397: $authtype = '<input type="hidden" name="login" value="fsys" />';
2398: }
2399: }
2400: }
2401: }
2402: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2403: if ($authtype eq '') {
2404: $authtype = '<input type="radio" name="login" value="fsys" '.
2405: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2406: $jscall.'" />';
2407: }
2408: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2409: ' onchange="'.$jscall.'" />';
2410: $result = &mt
2411: ('[_1] Filesystem Authenticated (with initial password [_2])',
2412: '<label><input type="radio" name="login" value="fsys" '.
2413: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
2414: '</label><input type="password" size="10" name="fsysarg" value="" '.
2415: 'onchange="'.$jscall.'" />');
2416: return $result;
2417: }
2418:
2419: sub get_assignable_auth {
2420: my ($dom) = @_;
2421: if ($dom eq '') {
2422: $dom = $env{'request.role.domain'};
2423: }
2424: my %can_assign = (
2425: krb4 => 1,
2426: krb5 => 1,
2427: int => 1,
2428: loc => 1,
2429: );
2430: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2431: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2432: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2433: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2434: my $context;
2435: if ($env{'request.role'} =~ /^au/) {
2436: $context = 'author';
2437: } elsif ($env{'request.role'} =~ /^dc/) {
2438: $context = 'domain';
2439: } elsif ($env{'request.course.id'}) {
2440: $context = 'course';
2441: }
2442: if ($context) {
2443: if (ref($authhash->{$context}) eq 'HASH') {
2444: %can_assign = %{$authhash->{$context}};
2445: }
2446: }
2447: }
2448: }
2449: my $authnum = 0;
2450: foreach my $key (keys(%can_assign)) {
2451: if ($can_assign{$key}) {
2452: $authnum ++;
2453: }
2454: }
2455: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2456: $authnum --;
2457: }
2458: return ($authnum,%can_assign);
2459: }
2460:
2461: ###############################################################
2462: ## Get Kerberos Defaults for Domain ##
2463: ###############################################################
2464: ##
2465: ## Returns default kerberos version and an associated argument
2466: ## as listed in file domain.tab. If not listed, provides
2467: ## appropriate default domain and kerberos version.
2468: ##
2469: #-------------------------------------------
2470:
2471: =pod
2472:
2473: =item * &get_kerberos_defaults()
2474:
2475: get_kerberos_defaults($target_domain) returns the default kerberos
2476: version and domain. If not found, it defaults to version 4 and the
2477: domain of the server.
2478:
2479: =over 4
2480:
2481: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2482:
2483: =back
2484:
2485: =back
2486:
2487: =cut
2488:
2489: #-------------------------------------------
2490: sub get_kerberos_defaults {
2491: my $domain=shift;
2492: my ($krbdef,$krbdefdom);
2493: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2494: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2495: $krbdef = $domdefaults{'auth_def'};
2496: $krbdefdom = $domdefaults{'auth_arg_def'};
2497: } else {
2498: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2499: my $krbdefdom=$1;
2500: $krbdefdom=~tr/a-z/A-Z/;
2501: $krbdef = "krb4";
2502: }
2503: return ($krbdef,$krbdefdom);
2504: }
2505:
2506:
2507: ###############################################################
2508: ## Thesaurus Functions ##
2509: ###############################################################
2510:
2511: =pod
2512:
2513: =head1 Thesaurus Functions
2514:
2515: =over 4
2516:
2517: =item * &initialize_keywords()
2518:
2519: Initializes the package variable %Keywords if it is empty. Uses the
2520: package variable $thesaurus_db_file.
2521:
2522: =cut
2523:
2524: ###################################################
2525:
2526: sub initialize_keywords {
2527: return 1 if (scalar keys(%Keywords));
2528: # If we are here, %Keywords is empty, so fill it up
2529: # Make sure the file we need exists...
2530: if (! -e $thesaurus_db_file) {
2531: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2532: " failed because it does not exist");
2533: return 0;
2534: }
2535: # Set up the hash as a database
2536: my %thesaurus_db;
2537: if (! tie(%thesaurus_db,'GDBM_File',
2538: $thesaurus_db_file,&GDBM_READER(),0640)){
2539: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2540: $thesaurus_db_file);
2541: return 0;
2542: }
2543: # Get the average number of appearances of a word.
2544: my $avecount = $thesaurus_db{'average.count'};
2545: # Put keywords (those that appear > average) into %Keywords
2546: while (my ($word,$data)=each (%thesaurus_db)) {
2547: my ($count,undef) = split /:/,$data;
2548: $Keywords{$word}++ if ($count > $avecount);
2549: }
2550: untie %thesaurus_db;
2551: # Remove special values from %Keywords.
2552: foreach my $value ('total.count','average.count') {
2553: delete($Keywords{$value}) if (exists($Keywords{$value}));
2554: }
2555: return 1;
2556: }
2557:
2558: ###################################################
2559:
2560: =pod
2561:
2562: =item * &keyword($word)
2563:
2564: Returns true if $word is a keyword. A keyword is a word that appears more
2565: than the average number of times in the thesaurus database. Calls
2566: &initialize_keywords
2567:
2568: =cut
2569:
2570: ###################################################
2571:
2572: sub keyword {
2573: return if (!&initialize_keywords());
2574: my $word=lc(shift());
2575: $word=~s/\W//g;
2576: return exists($Keywords{$word});
2577: }
2578:
2579: ###############################################################
2580:
2581: =pod
2582:
2583: =item * &get_related_words()
2584:
2585: Look up a word in the thesaurus. Takes a scalar argument and returns
2586: an array of words. If the keyword is not in the thesaurus, an empty array
2587: will be returned. The order of the words returned is determined by the
2588: database which holds them.
2589:
2590: Uses global $thesaurus_db_file.
2591:
2592: =cut
2593:
2594: ###############################################################
2595: sub get_related_words {
2596: my $keyword = shift;
2597: my %thesaurus_db;
2598: if (! -e $thesaurus_db_file) {
2599: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
2600: "failed because the file does not exist");
2601: return ();
2602: }
2603: if (! tie(%thesaurus_db,'GDBM_File',
2604: $thesaurus_db_file,&GDBM_READER(),0640)){
2605: return ();
2606: }
2607: my @Words=();
2608: my $count=0;
2609: if (exists($thesaurus_db{$keyword})) {
2610: # The first element is the number of times
2611: # the word appears. We do not need it now.
2612: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
2613: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
2614: my $threshold=$mostfrequentcount/10;
2615: foreach my $possibleword (@RelatedWords) {
2616: my ($word,$wordcount)=split(/\,/,$possibleword);
2617: if ($wordcount>$threshold) {
2618: push(@Words,$word);
2619: $count++;
2620: if ($count>10) { last; }
2621: }
2622: }
2623: }
2624: untie %thesaurus_db;
2625: return @Words;
2626: }
2627:
2628: =pod
2629:
2630: =back
2631:
2632: =cut
2633:
2634: # -------------------------------------------------------------- Plaintext name
2635: =pod
2636:
2637: =head1 User Name Functions
2638:
2639: =over 4
2640:
2641: =item * &plainname($uname,$udom,$first)
2642:
2643: Takes a users logon name and returns it as a string in
2644: "first middle last generation" form
2645: if $first is set to 'lastname' then it returns it as
2646: 'lastname generation, firstname middlename' if their is a lastname
2647:
2648: =cut
2649:
2650:
2651: ###############################################################
2652: sub plainname {
2653: my ($uname,$udom,$first)=@_;
2654: return if (!defined($uname) || !defined($udom));
2655: my %names=&getnames($uname,$udom);
2656: my $name=&Apache::lonnet::format_name($names{'firstname'},
2657: $names{'middlename'},
2658: $names{'lastname'},
2659: $names{'generation'},$first);
2660: $name=~s/^\s+//;
2661: $name=~s/\s+$//;
2662: $name=~s/\s+/ /g;
2663: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
2664: return $name;
2665: }
2666:
2667: # -------------------------------------------------------------------- Nickname
2668: =pod
2669:
2670: =item * &nickname($uname,$udom)
2671:
2672: Gets a users name and returns it as a string as
2673:
2674: ""nickname""
2675:
2676: if the user has a nickname or
2677:
2678: "first middle last generation"
2679:
2680: if the user does not
2681:
2682: =cut
2683:
2684: sub nickname {
2685: my ($uname,$udom)=@_;
2686: return if (!defined($uname) || !defined($udom));
2687: my %names=&getnames($uname,$udom);
2688: my $name=$names{'nickname'};
2689: if ($name) {
2690: $name='"'.$name.'"';
2691: } else {
2692: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
2693: $names{'lastname'}.' '.$names{'generation'};
2694: $name=~s/\s+$//;
2695: $name=~s/\s+/ /g;
2696: }
2697: return $name;
2698: }
2699:
2700: sub getnames {
2701: my ($uname,$udom)=@_;
2702: return if (!defined($uname) || !defined($udom));
2703: if ($udom eq 'public' && $uname eq 'public') {
2704: return ('lastname' => &mt('Public'));
2705: }
2706: my $id=$uname.':'.$udom;
2707: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
2708: if ($cached) {
2709: return %{$names};
2710: } else {
2711: my %loadnames=&Apache::lonnet::get('environment',
2712: ['firstname','middlename','lastname','generation','nickname'],
2713: $udom,$uname);
2714: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
2715: return %loadnames;
2716: }
2717: }
2718:
2719: # -------------------------------------------------------------------- getemails
2720:
2721: =pod
2722:
2723: =item * &getemails($uname,$udom)
2724:
2725: Gets a user's email information and returns it as a hash with keys:
2726: notification, critnotification, permanentemail
2727:
2728: For notification and critnotification, values are comma-separated lists
2729: of e-mail addresses; for permanentemail, value is a single e-mail address.
2730:
2731:
2732: =cut
2733:
2734:
2735: sub getemails {
2736: my ($uname,$udom)=@_;
2737: if ($udom eq 'public' && $uname eq 'public') {
2738: return;
2739: }
2740: if (!$udom) { $udom=$env{'user.domain'}; }
2741: if (!$uname) { $uname=$env{'user.name'}; }
2742: my $id=$uname.':'.$udom;
2743: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
2744: if ($cached) {
2745: return %{$names};
2746: } else {
2747: my %loadnames=&Apache::lonnet::get('environment',
2748: ['notification','critnotification',
2749: 'permanentemail'],
2750: $udom,$uname);
2751: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
2752: return %loadnames;
2753: }
2754: }
2755:
2756: sub flush_email_cache {
2757: my ($uname,$udom)=@_;
2758: if (!$udom) { $udom =$env{'user.domain'}; }
2759: if (!$uname) { $uname=$env{'user.name'}; }
2760: return if ($udom eq 'public' && $uname eq 'public');
2761: my $id=$uname.':'.$udom;
2762: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
2763: }
2764:
2765: # -------------------------------------------------------------------- getlangs
2766:
2767: =pod
2768:
2769: =item * &getlangs($uname,$udom)
2770:
2771: Gets a user's language preference and returns it as a hash with key:
2772: language.
2773:
2774: =cut
2775:
2776:
2777: sub getlangs {
2778: my ($uname,$udom) = @_;
2779: if (!$udom) { $udom =$env{'user.domain'}; }
2780: if (!$uname) { $uname=$env{'user.name'}; }
2781: my $id=$uname.':'.$udom;
2782: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
2783: if ($cached) {
2784: return %{$langs};
2785: } else {
2786: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
2787: $udom,$uname);
2788: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
2789: return %loadlangs;
2790: }
2791: }
2792:
2793: sub flush_langs_cache {
2794: my ($uname,$udom)=@_;
2795: if (!$udom) { $udom =$env{'user.domain'}; }
2796: if (!$uname) { $uname=$env{'user.name'}; }
2797: return if ($udom eq 'public' && $uname eq 'public');
2798: my $id=$uname.':'.$udom;
2799: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
2800: }
2801:
2802: # ------------------------------------------------------------------ Screenname
2803:
2804: =pod
2805:
2806: =item * &screenname($uname,$udom)
2807:
2808: Gets a users screenname and returns it as a string
2809:
2810: =cut
2811:
2812: sub screenname {
2813: my ($uname,$udom)=@_;
2814: if ($uname eq $env{'user.name'} &&
2815: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
2816: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
2817: return $names{'screenname'};
2818: }
2819:
2820:
2821: # ------------------------------------------------------------- Message Wrapper
2822:
2823: sub messagewrapper {
2824: my ($link,$username,$domain,$subject,$text)=@_;
2825: return
2826: '<a href="/adm/email?compose=individual&'.
2827: 'recname='.$username.'&recdom='.$domain.
2828: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
2829: 'title="'.&mt('Send message').'">'.$link.'</a>';
2830: }
2831: # --------------------------------------------------------------- Notes Wrapper
2832:
2833: sub noteswrapper {
2834: my ($link,$un,$do)=@_;
2835: return
2836: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
2837: }
2838: # ------------------------------------------------------------- Aboutme Wrapper
2839:
2840: sub aboutmewrapper {
2841: my ($link,$username,$domain,$target)=@_;
2842: if (!defined($username) && !defined($domain)) {
2843: return;
2844: }
2845: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
2846: ($target?' target="$target"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
2847: }
2848:
2849: # ------------------------------------------------------------ Syllabus Wrapper
2850:
2851:
2852: sub syllabuswrapper {
2853: my ($linktext,$coursedir,$domain)=@_;
2854: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
2855: }
2856:
2857: sub track_student_link {
2858: my ($linktext,$sname,$sdom,$target,$start) = @_;
2859: my $link ="/adm/trackstudent?";
2860: my $title = 'View recent activity';
2861: if (defined($sname) && $sname !~ /^\s*$/ &&
2862: defined($sdom) && $sdom !~ /^\s*$/) {
2863: $link .= "selected_student=$sname:$sdom";
2864: $title .= ' of this student';
2865: }
2866: if (defined($target) && $target !~ /^\s*$/) {
2867: $target = qq{target="$target"};
2868: } else {
2869: $target = '';
2870: }
2871: if ($start) { $link.='&start='.$start; }
2872: $title = &mt($title);
2873: $linktext = &mt($linktext);
2874: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
2875: &help_open_topic('View_recent_activity');
2876: }
2877:
2878: sub slot_reservations_link {
2879: my ($linktext,$sname,$sdom,$target) = @_;
2880: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
2881: my $title = 'View slot reservation history';
2882: if (defined($sname) && $sname !~ /^\s*$/ &&
2883: defined($sdom) && $sdom !~ /^\s*$/) {
2884: $link .= "&uname=$sname&udom=$sdom";
2885: $title .= ' of this student';
2886: }
2887: if (defined($target) && $target !~ /^\s*$/) {
2888: $target = qq{target="$target"};
2889: } else {
2890: $target = '';
2891: }
2892: $title = &mt($title);
2893: $linktext = &mt($linktext);
2894: return qq{<a href="$link" title="$title" $target>$linktext</a>};
2895: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
2896:
2897: }
2898:
2899: # ===================================================== Display a student photo
2900:
2901:
2902: sub student_image_tag {
2903: my ($domain,$user)=@_;
2904: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
2905: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
2906: return '<img src="'.$imgsrc.'" align="right" />';
2907: } else {
2908: return '';
2909: }
2910: }
2911:
2912: =pod
2913:
2914: =back
2915:
2916: =head1 Access .tab File Data
2917:
2918: =over 4
2919:
2920: =item * &languageids()
2921:
2922: returns list of all language ids
2923:
2924: =cut
2925:
2926: sub languageids {
2927: return sort(keys(%language));
2928: }
2929:
2930: =pod
2931:
2932: =item * &languagedescription()
2933:
2934: returns description of a specified language id
2935:
2936: =cut
2937:
2938: sub languagedescription {
2939: my $code=shift;
2940: return ($supported_language{$code}?'* ':'').
2941: $language{$code}.
2942: ($supported_language{$code}?' ('.&mt('interface available').')':'');
2943: }
2944:
2945: sub plainlanguagedescription {
2946: my $code=shift;
2947: return $language{$code};
2948: }
2949:
2950: sub supportedlanguagecode {
2951: my $code=shift;
2952: return $supported_language{$code};
2953: }
2954:
2955: =pod
2956:
2957: =item * ©rightids()
2958:
2959: returns list of all copyrights
2960:
2961: =cut
2962:
2963: sub copyrightids {
2964: return sort(keys(%cprtag));
2965: }
2966:
2967: =pod
2968:
2969: =item * ©rightdescription()
2970:
2971: returns description of a specified copyright id
2972:
2973: =cut
2974:
2975: sub copyrightdescription {
2976: return &mt($cprtag{shift(@_)});
2977: }
2978:
2979: =pod
2980:
2981: =item * &source_copyrightids()
2982:
2983: returns list of all source copyrights
2984:
2985: =cut
2986:
2987: sub source_copyrightids {
2988: return sort(keys(%scprtag));
2989: }
2990:
2991: =pod
2992:
2993: =item * &source_copyrightdescription()
2994:
2995: returns description of a specified source copyright id
2996:
2997: =cut
2998:
2999: sub source_copyrightdescription {
3000: return &mt($scprtag{shift(@_)});
3001: }
3002:
3003: =pod
3004:
3005: =item * &filecategories()
3006:
3007: returns list of all file categories
3008:
3009: =cut
3010:
3011: sub filecategories {
3012: return sort(keys(%category_extensions));
3013: }
3014:
3015: =pod
3016:
3017: =item * &filecategorytypes()
3018:
3019: returns list of file types belonging to a given file
3020: category
3021:
3022: =cut
3023:
3024: sub filecategorytypes {
3025: my ($cat) = @_;
3026: return @{$category_extensions{lc($cat)}};
3027: }
3028:
3029: =pod
3030:
3031: =item * &fileembstyle()
3032:
3033: returns embedding style for a specified file type
3034:
3035: =cut
3036:
3037: sub fileembstyle {
3038: return $fe{lc(shift(@_))};
3039: }
3040:
3041: sub filemimetype {
3042: return $fm{lc(shift(@_))};
3043: }
3044:
3045:
3046: sub filecategoryselect {
3047: my ($name,$value)=@_;
3048: return &select_form($value,$name,
3049: '' => &mt('Any category'),
3050: map { $_,$_ } sort(keys(%category_extensions)));
3051: }
3052:
3053: =pod
3054:
3055: =item * &filedescription()
3056:
3057: returns description for a specified file type
3058:
3059: =cut
3060:
3061: sub filedescription {
3062: my $file_description = $fd{lc(shift())};
3063: $file_description =~ s:([\[\]]):~$1:g;
3064: return &mt($file_description);
3065: }
3066:
3067: =pod
3068:
3069: =item * &filedescriptionex()
3070:
3071: returns description for a specified file type with
3072: extra formatting
3073:
3074: =cut
3075:
3076: sub filedescriptionex {
3077: my $ex=shift;
3078: my $file_description = $fd{lc($ex)};
3079: $file_description =~ s:([\[\]]):~$1:g;
3080: return '.'.$ex.' '.&mt($file_description);
3081: }
3082:
3083: # End of .tab access
3084: =pod
3085:
3086: =back
3087:
3088: =cut
3089:
3090: # ------------------------------------------------------------------ File Types
3091: sub fileextensions {
3092: return sort(keys(%fe));
3093: }
3094:
3095: # ----------------------------------------------------------- Display Languages
3096: # returns a hash with all desired display languages
3097: #
3098:
3099: sub display_languages {
3100: my %languages=();
3101: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
3102: $languages{$lang}=1;
3103: }
3104: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
3105: if ($env{'form.displaylanguage'}) {
3106: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3107: $languages{$lang}=1;
3108: }
3109: }
3110: return %languages;
3111: }
3112:
3113: sub languages {
3114: my ($possible_langs) = @_;
3115: my @preferred_langs = &Apache::lonlocal::preferred_languages();
3116: if (!ref($possible_langs)) {
3117: if( wantarray ) {
3118: return @preferred_langs;
3119: } else {
3120: return $preferred_langs[0];
3121: }
3122: }
3123: my %possibilities = map { $_ => 1 } (@$possible_langs);
3124: my @preferred_possibilities;
3125: foreach my $preferred_lang (@preferred_langs) {
3126: if (exists($possibilities{$preferred_lang})) {
3127: push(@preferred_possibilities, $preferred_lang);
3128: }
3129: }
3130: if( wantarray ) {
3131: return @preferred_possibilities;
3132: }
3133: return $preferred_possibilities[0];
3134: }
3135:
3136: sub user_lang {
3137: my ($touname,$toudom,$fromcid) = @_;
3138: my @userlangs;
3139: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3140: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3141: $env{'course.'.$fromcid.'.languages'}));
3142: } else {
3143: my %langhash = &getlangs($touname,$toudom);
3144: if ($langhash{'languages'} ne '') {
3145: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3146: } else {
3147: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3148: if ($domdefs{'lang_def'} ne '') {
3149: @userlangs = ($domdefs{'lang_def'});
3150: }
3151: }
3152: }
3153: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3154: my $user_lh = Apache::localize->get_handle(@languages);
3155: return $user_lh;
3156: }
3157:
3158:
3159: ###############################################################
3160: ## Student Answer Attempts ##
3161: ###############################################################
3162:
3163: =pod
3164:
3165: =head1 Alternate Problem Views
3166:
3167: =over 4
3168:
3169: =item * &get_previous_attempt($symb, $username, $domain, $course,
3170: $getattempt, $regexp, $gradesub)
3171:
3172: Return string with previous attempt on problem. Arguments:
3173:
3174: =over 4
3175:
3176: =item * $symb: Problem, including path
3177:
3178: =item * $username: username of the desired student
3179:
3180: =item * $domain: domain of the desired student
3181:
3182: =item * $course: Course ID
3183:
3184: =item * $getattempt: Leave blank for all attempts, otherwise put
3185: something
3186:
3187: =item * $regexp: if string matches this regexp, the string will be
3188: sent to $gradesub
3189:
3190: =item * $gradesub: routine that processes the string if it matches $regexp
3191:
3192: =back
3193:
3194: The output string is a table containing all desired attempts, if any.
3195:
3196: =cut
3197:
3198: sub get_previous_attempt {
3199: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
3200: my $prevattempts='';
3201: no strict 'refs';
3202: if ($symb) {
3203: my (%returnhash)=
3204: &Apache::lonnet::restore($symb,$course,$domain,$username);
3205: if ($returnhash{'version'}) {
3206: my %lasthash=();
3207: my $version;
3208: for ($version=1;$version<=$returnhash{'version'};$version++) {
3209: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3210: $lasthash{$key}=$returnhash{$version.':'.$key};
3211: }
3212: }
3213: $prevattempts=&start_data_table().&start_data_table_header_row();
3214: $prevattempts.='<th>'.&mt('History').'</th>';
3215: foreach my $key (sort(keys(%lasthash))) {
3216: my ($ign,@parts) = split(/\./,$key);
3217: if ($#parts > 0) {
3218: my $data=$parts[-1];
3219: pop(@parts);
3220: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
3221: } else {
3222: if ($#parts == 0) {
3223: $prevattempts.='<th>'.$parts[0].'</th>';
3224: } else {
3225: $prevattempts.='<th>'.$ign.'</th>';
3226: }
3227: }
3228: }
3229: $prevattempts.=&end_data_table_header_row();
3230: if ($getattempt eq '') {
3231: for ($version=1;$version<=$returnhash{'version'};$version++) {
3232: $prevattempts.=&start_data_table_row().
3233: '<td>'.&mt('Transaction [_1]',$version).'</td>';
3234: foreach my $key (sort(keys(%lasthash))) {
3235: my $value = &format_previous_attempt_value($key,
3236: $returnhash{$version.':'.$key});
3237: $prevattempts.='<td>'.$value.' </td>';
3238: }
3239: $prevattempts.=&end_data_table_row();
3240: }
3241: }
3242: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
3243: foreach my $key (sort(keys(%lasthash))) {
3244: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3245: if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
3246: $prevattempts.='<td>'.$value.' </td>';
3247: }
3248: $prevattempts.= &end_data_table_row().&end_data_table();
3249: } else {
3250: $prevattempts=
3251: &start_data_table().&start_data_table_row().
3252: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3253: &end_data_table_row().&end_data_table();
3254: }
3255: } else {
3256: $prevattempts=
3257: &start_data_table().&start_data_table_row().
3258: '<td>'.&mt('No data.').'</td>'.
3259: &end_data_table_row().&end_data_table();
3260: }
3261: }
3262:
3263: sub format_previous_attempt_value {
3264: my ($key,$value) = @_;
3265: if ($key =~ /timestamp/) {
3266: $value = &Apache::lonlocal::locallocaltime($value);
3267: } elsif (ref($value) eq 'ARRAY') {
3268: $value = '('.join(', ', @{ $value }).')';
3269: } else {
3270: $value = &unescape($value);
3271: }
3272: return $value;
3273: }
3274:
3275:
3276: sub relative_to_absolute {
3277: my ($url,$output)=@_;
3278: my $parser=HTML::TokeParser->new(\$output);
3279: my $token;
3280: my $thisdir=$url;
3281: my @rlinks=();
3282: while ($token=$parser->get_token) {
3283: if ($token->[0] eq 'S') {
3284: if ($token->[1] eq 'a') {
3285: if ($token->[2]->{'href'}) {
3286: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3287: }
3288: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3289: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3290: } elsif ($token->[1] eq 'base') {
3291: $thisdir=$token->[2]->{'href'};
3292: }
3293: }
3294: }
3295: $thisdir=~s-/[^/]*$--;
3296: foreach my $link (@rlinks) {
3297: unless (($link=~/^https?\:\/\//i) ||
3298: ($link=~/^\//) ||
3299: ($link=~/^javascript:/i) ||
3300: ($link=~/^mailto:/i) ||
3301: ($link=~/^\#/)) {
3302: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3303: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
3304: }
3305: }
3306: # -------------------------------------------------- Deal with Applet codebases
3307: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3308: return $output;
3309: }
3310:
3311: =pod
3312:
3313: =item * &get_student_view()
3314:
3315: show a snapshot of what student was looking at
3316:
3317: =cut
3318:
3319: sub get_student_view {
3320: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
3321: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
3322: my (%form);
3323: my @elements=('symb','courseid','domain','username');
3324: foreach my $element (@elements) {
3325: $form{'grade_'.$element}=eval '$'.$element #'
3326: }
3327: if (defined($moreenv)) {
3328: %form=(%form,%{$moreenv});
3329: }
3330: if (defined($target)) { $form{'grade_target'} = $target; }
3331: $feedurl=&Apache::lonnet::clutter($feedurl);
3332: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
3333: $userview=~s/\<body[^\>]*\>//gi;
3334: $userview=~s/\<\/body\>//gi;
3335: $userview=~s/\<html\>//gi;
3336: $userview=~s/\<\/html\>//gi;
3337: $userview=~s/\<head\>//gi;
3338: $userview=~s/\<\/head\>//gi;
3339: $userview=~s/action\s*\=/would_be_action\=/gi;
3340: $userview=&relative_to_absolute($feedurl,$userview);
3341: if (wantarray) {
3342: return ($userview,$response);
3343: } else {
3344: return $userview;
3345: }
3346: }
3347:
3348: sub get_student_view_with_retries {
3349: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3350:
3351: my $ok = 0; # True if we got a good response.
3352: my $content;
3353: my $response;
3354:
3355: # Try to get the student_view done. within the retries count:
3356:
3357: do {
3358: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3359: $ok = $response->is_success;
3360: if (!$ok) {
3361: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3362: }
3363: $retries--;
3364: } while (!$ok && ($retries > 0));
3365:
3366: if (!$ok) {
3367: $content = ''; # On error return an empty content.
3368: }
3369: if (wantarray) {
3370: return ($content, $response);
3371: } else {
3372: return $content;
3373: }
3374: }
3375:
3376: =pod
3377:
3378: =item * &get_student_answers()
3379:
3380: show a snapshot of how student was answering problem
3381:
3382: =cut
3383:
3384: sub get_student_answers {
3385: my ($symb,$username,$domain,$courseid,%form) = @_;
3386: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
3387: my (%moreenv);
3388: my @elements=('symb','courseid','domain','username');
3389: foreach my $element (@elements) {
3390: $moreenv{'grade_'.$element}=eval '$'.$element #'
3391: }
3392: $moreenv{'grade_target'}='answer';
3393: %moreenv=(%form,%moreenv);
3394: $feedurl = &Apache::lonnet::clutter($feedurl);
3395: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
3396: return $userview;
3397: }
3398:
3399: =pod
3400:
3401: =item * &submlink()
3402:
3403: Inputs: $text $uname $udom $symb $target
3404:
3405: Returns: A link to grades.pm such as to see the SUBM view of a student
3406:
3407: =cut
3408:
3409: ###############################################
3410: sub submlink {
3411: my ($text,$uname,$udom,$symb,$target)=@_;
3412: if (!($uname && $udom)) {
3413: (my $cursymb, my $courseid,$udom,$uname)=
3414: &Apache::lonnet::whichuser($symb);
3415: if (!$symb) { $symb=$cursymb; }
3416: }
3417: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
3418: $symb=&escape($symb);
3419: if ($target) { $target="target=\"$target\""; }
3420: return '<a href="/adm/grades?&command=submission&'.
3421: 'symb='.$symb.'&student='.$uname.
3422: '&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
3423: }
3424: ##############################################
3425:
3426: =pod
3427:
3428: =item * &pgrdlink()
3429:
3430: Inputs: $text $uname $udom $symb $target
3431:
3432: Returns: A link to grades.pm such as to see the PGRD view of a student
3433:
3434: =cut
3435:
3436: ###############################################
3437: sub pgrdlink {
3438: my $link=&submlink(@_);
3439: $link=~s/(&command=submission)/$1&showgrading=yes/;
3440: return $link;
3441: }
3442: ##############################################
3443:
3444: =pod
3445:
3446: =item * &pprmlink()
3447:
3448: Inputs: $text $uname $udom $symb $target
3449:
3450: Returns: A link to parmset.pm such as to see the PPRM view of a
3451: student and a specific resource
3452:
3453: =cut
3454:
3455: ###############################################
3456: sub pprmlink {
3457: my ($text,$uname,$udom,$symb,$target)=@_;
3458: if (!($uname && $udom)) {
3459: (my $cursymb, my $courseid,$udom,$uname)=
3460: &Apache::lonnet::whichuser($symb);
3461: if (!$symb) { $symb=$cursymb; }
3462: }
3463: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
3464: $symb=&escape($symb);
3465: if ($target) { $target="target=\"$target\""; }
3466: return '<a href="/adm/parmset?command=set&'.
3467: 'symb='.$symb.'&uname='.$uname.
3468: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
3469: }
3470: ##############################################
3471:
3472: =pod
3473:
3474: =back
3475:
3476: =cut
3477:
3478: ###############################################
3479:
3480:
3481: sub timehash {
3482: my ($thistime) = @_;
3483: my $timezone = &Apache::lonlocal::gettimezone();
3484: my $dt = DateTime->from_epoch(epoch => $thistime)
3485: ->set_time_zone($timezone);
3486: my $wday = $dt->day_of_week();
3487: if ($wday == 7) { $wday = 0; }
3488: return ( 'second' => $dt->second(),
3489: 'minute' => $dt->minute(),
3490: 'hour' => $dt->hour(),
3491: 'day' => $dt->day_of_month(),
3492: 'month' => $dt->month(),
3493: 'year' => $dt->year(),
3494: 'weekday' => $wday,
3495: 'dayyear' => $dt->day_of_year(),
3496: 'dlsav' => $dt->is_dst() );
3497: }
3498:
3499: sub utc_string {
3500: my ($date)=@_;
3501: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
3502: }
3503:
3504: sub maketime {
3505: my %th=@_;
3506: my ($epoch_time,$timezone,$dt);
3507: $timezone = &Apache::lonlocal::gettimezone();
3508: eval {
3509: $dt = DateTime->new( year => $th{'year'},
3510: month => $th{'month'},
3511: day => $th{'day'},
3512: hour => $th{'hour'},
3513: minute => $th{'minute'},
3514: second => $th{'second'},
3515: time_zone => $timezone,
3516: );
3517: };
3518: if (!$@) {
3519: $epoch_time = $dt->epoch;
3520: if ($epoch_time) {
3521: return $epoch_time;
3522: }
3523: }
3524: return POSIX::mktime(
3525: ($th{'seconds'},$th{'minutes'},$th{'hours'},
3526: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
3527: }
3528:
3529: #########################################
3530:
3531: sub findallcourses {
3532: my ($roles,$uname,$udom) = @_;
3533: my %roles;
3534: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
3535: my %courses;
3536: my $now=time;
3537: if (!defined($uname)) {
3538: $uname = $env{'user.name'};
3539: }
3540: if (!defined($udom)) {
3541: $udom = $env{'user.domain'};
3542: }
3543: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
3544: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
3545: if (!%roles) {
3546: %roles = (
3547: cc => 1,
3548: in => 1,
3549: ep => 1,
3550: ta => 1,
3551: cr => 1,
3552: st => 1,
3553: );
3554: }
3555: foreach my $entry (keys(%roleshash)) {
3556: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
3557: if ($trole =~ /^cr/) {
3558: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
3559: } else {
3560: next if (!exists($roles{$trole}));
3561: }
3562: if ($tend) {
3563: next if ($tend < $now);
3564: }
3565: if ($tstart) {
3566: next if ($tstart > $now);
3567: }
3568: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
3569: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
3570: if ($secpart eq '') {
3571: ($cnum,$role) = split(/_/,$cnumpart);
3572: $sec = 'none';
3573: $realsec = '';
3574: } else {
3575: $cnum = $cnumpart;
3576: ($sec,$role) = split(/_/,$secpart);
3577: $realsec = $sec;
3578: }
3579: $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
3580: }
3581: } else {
3582: foreach my $key (keys(%env)) {
3583: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
3584: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
3585: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
3586: next if ($role eq 'ca' || $role eq 'aa');
3587: next if (%roles && !exists($roles{$role}));
3588: my ($starttime,$endtime)=split(/\./,$env{$key});
3589: my $active=1;
3590: if ($starttime) {
3591: if ($now<$starttime) { $active=0; }
3592: }
3593: if ($endtime) {
3594: if ($now>$endtime) { $active=0; }
3595: }
3596: if ($active) {
3597: if ($sec eq '') {
3598: $sec = 'none';
3599: }
3600: $courses{$cdom.'_'.$cnum}{$sec} =
3601: $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
3602: }
3603: }
3604: }
3605: }
3606: return %courses;
3607: }
3608:
3609: ###############################################
3610:
3611: sub blockcheck {
3612: my ($setters,$activity,$uname,$udom) = @_;
3613:
3614: if (!defined($udom)) {
3615: $udom = $env{'user.domain'};
3616: }
3617: if (!defined($uname)) {
3618: $uname = $env{'user.name'};
3619: }
3620:
3621: # If uname and udom are for a course, check for blocks in the course.
3622:
3623: if (&Apache::lonnet::is_course($udom,$uname)) {
3624: my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
3625: my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
3626: return ($startblock,$endblock);
3627: }
3628:
3629: my $startblock = 0;
3630: my $endblock = 0;
3631: my %live_courses = &findallcourses(undef,$uname,$udom);
3632:
3633: # If uname is for a user, and activity is course-specific, i.e.,
3634: # boards, chat or groups, check for blocking in current course only.
3635:
3636: if (($activity eq 'boards' || $activity eq 'chat' ||
3637: $activity eq 'groups') && ($env{'request.course.id'})) {
3638: foreach my $key (keys(%live_courses)) {
3639: if ($key ne $env{'request.course.id'}) {
3640: delete($live_courses{$key});
3641: }
3642: }
3643: }
3644:
3645: my $otheruser = 0;
3646: my %own_courses;
3647: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
3648: # Resource belongs to user other than current user.
3649: $otheruser = 1;
3650: # Gather courses for current user
3651: %own_courses =
3652: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
3653: }
3654:
3655: # Gather active course roles - course coordinator, instructor,
3656: # exam proctor, ta, student, or custom role.
3657:
3658: foreach my $course (keys(%live_courses)) {
3659: my ($cdom,$cnum);
3660: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
3661: $cdom = $env{'course.'.$course.'.domain'};
3662: $cnum = $env{'course.'.$course.'.num'};
3663: } else {
3664: ($cdom,$cnum) = split(/_/,$course);
3665: }
3666: my $no_ownblock = 0;
3667: my $no_userblock = 0;
3668: if ($otheruser && $activity ne 'com') {
3669: # Check if current user has 'evb' priv for this
3670: if (defined($own_courses{$course})) {
3671: foreach my $sec (keys(%{$own_courses{$course}})) {
3672: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
3673: if ($sec ne 'none') {
3674: $checkrole .= '/'.$sec;
3675: }
3676: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3677: $no_ownblock = 1;
3678: last;
3679: }
3680: }
3681: }
3682: # if they have 'evb' priv and are currently not playing student
3683: next if (($no_ownblock) &&
3684: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
3685: }
3686: foreach my $sec (keys(%{$live_courses{$course}})) {
3687: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
3688: if ($sec ne 'none') {
3689: $checkrole .= '/'.$sec;
3690: }
3691: if ($otheruser) {
3692: # Resource belongs to user other than current user.
3693: # Assemble privs for that user, and check for 'evb' priv.
3694: my ($trole,$tdom,$tnum,$tsec);
3695: my $entry = $live_courses{$course}{$sec};
3696: if ($entry =~ /^cr/) {
3697: ($trole,$tdom,$tnum,$tsec) =
3698: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
3699: } else {
3700: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
3701: }
3702: my ($spec,$area,$trest,%allroles,%userroles);
3703: $area = '/'.$tdom.'/'.$tnum;
3704: $trest = $tnum;
3705: if ($tsec ne '') {
3706: $area .= '/'.$tsec;
3707: $trest .= '/'.$tsec;
3708: }
3709: $spec = $trole.'.'.$area;
3710: if ($trole =~ /^cr/) {
3711: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
3712: $tdom,$spec,$trest,$area);
3713: } else {
3714: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
3715: $tdom,$spec,$trest,$area);
3716: }
3717: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
3718: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
3719: if ($1) {
3720: $no_userblock = 1;
3721: last;
3722: }
3723: }
3724: } else {
3725: # Resource belongs to current user
3726: # Check for 'evb' priv via lonnet::allowed().
3727: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3728: $no_ownblock = 1;
3729: last;
3730: }
3731: }
3732: }
3733: # if they have the evb priv and are currently not playing student
3734: next if (($no_ownblock) &&
3735: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
3736: next if ($no_userblock);
3737:
3738: # Retrieve blocking times and identity of blocker for course
3739: # of specified user, unless user has 'evb' privilege.
3740:
3741: my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
3742: if (($start != 0) &&
3743: (($startblock == 0) || ($startblock > $start))) {
3744: $startblock = $start;
3745: }
3746: if (($end != 0) &&
3747: (($endblock == 0) || ($endblock < $end))) {
3748: $endblock = $end;
3749: }
3750: }
3751: return ($startblock,$endblock);
3752: }
3753:
3754: sub get_blocks {
3755: my ($setters,$activity,$cdom,$cnum) = @_;
3756: my $startblock = 0;
3757: my $endblock = 0;
3758: my $course = $cdom.'_'.$cnum;
3759: $setters->{$course} = {};
3760: $setters->{$course}{'staff'} = [];
3761: $setters->{$course}{'times'} = [];
3762: my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
3763: foreach my $record (keys(%records)) {
3764: my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
3765: if ($start <= time && $end >= time) {
3766: my ($staff_name,$staff_dom,$title,$blocks) =
3767: &parse_block_record($records{$record});
3768: if ($blocks->{$activity} eq 'on') {
3769: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
3770: push(@{$$setters{$course}{'times'}}, [$start,$end]);
3771: if ( ($startblock == 0) || ($startblock > $start) ) {
3772: $startblock = $start;
3773: }
3774: if ( ($endblock == 0) || ($endblock < $end) ) {
3775: $endblock = $end;
3776: }
3777: }
3778: }
3779: }
3780: return ($startblock,$endblock);
3781: }
3782:
3783: sub parse_block_record {
3784: my ($record) = @_;
3785: my ($setuname,$setudom,$title,$blocks);
3786: if (ref($record) eq 'HASH') {
3787: ($setuname,$setudom) = split(/:/,$record->{'setter'});
3788: $title = &unescape($record->{'event'});
3789: $blocks = $record->{'blocks'};
3790: } else {
3791: my @data = split(/:/,$record,3);
3792: if (scalar(@data) eq 2) {
3793: $title = $data[1];
3794: ($setuname,$setudom) = split(/@/,$data[0]);
3795: } else {
3796: ($setuname,$setudom,$title) = @data;
3797: }
3798: $blocks = { 'com' => 'on' };
3799: }
3800: return ($setuname,$setudom,$title,$blocks);
3801: }
3802:
3803: sub build_block_table {
3804: my ($startblock,$endblock,$setters) = @_;
3805: my %lt = &Apache::lonlocal::texthash(
3806: 'cacb' => 'Currently active communication blocks',
3807: 'cour' => 'Course',
3808: 'dura' => 'Duration',
3809: 'blse' => 'Block set by'
3810: );
3811: my $output;
3812: $output = '<br />'.$lt{'cacb'}.':<br />';
3813: $output .= &start_data_table();
3814: $output .= '
3815: <tr>
3816: <th>'.$lt{'cour'}.'</th>
3817: <th>'.$lt{'dura'}.'</th>
3818: <th>'.$lt{'blse'}.'</th>
3819: </tr>
3820: ';
3821: foreach my $course (keys(%{$setters})) {
3822: my %courseinfo=&Apache::lonnet::coursedescription($course);
3823: for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) {
3824: my ($uname,$udom) = @{$$setters{$course}{staff}[$i]};
3825: my $fullname = &plainname($uname,$udom);
3826: if (defined($env{'user.name'}) && defined($env{'user.domain'})
3827: && $env{'user.name'} ne 'public'
3828: && $env{'user.domain'} ne 'public') {
3829: $fullname = &aboutmewrapper($fullname,$uname,$udom);
3830: }
3831: my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]};
3832: $openblock = &Apache::lonlocal::locallocaltime($openblock);
3833: $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
3834: $output .= &Apache::loncommon::start_data_table_row().
3835: '<td>'.$courseinfo{'description'}.'</td>'.
3836: '<td>'.$openblock.' to '.$closeblock.'</td>'.
3837: '<td>'.$fullname.'</td>'.
3838: &Apache::loncommon::end_data_table_row();
3839: }
3840: }
3841: $output .= &end_data_table();
3842: }
3843:
3844: sub blocking_status {
3845: my ($activity,$uname,$udom) = @_;
3846: my %setters;
3847: my ($blocked,$output,$ownitem,$is_course);
3848: my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
3849: if ($startblock && $endblock) {
3850: $blocked = 1;
3851: if (wantarray) {
3852: my $category;
3853: if ($activity eq 'boards') {
3854: $category = 'Discussion posts in this course';
3855: } elsif ($activity eq 'blogs') {
3856: $category = 'Blogs';
3857: } elsif ($activity eq 'port') {
3858: if (defined($uname) && defined($udom)) {
3859: if ($uname eq $env{'user.name'} &&
3860: $udom eq $env{'user.domain'}) {
3861: $ownitem = 1;
3862: }
3863: }
3864: $is_course = &Apache::lonnet::is_course($udom,$uname);
3865: if ($ownitem) {
3866: $category = 'Your portfolio files';
3867: } elsif ($is_course) {
3868: my $coursedesc;
3869: foreach my $course (keys(%setters)) {
3870: my %courseinfo =
3871: &Apache::lonnet::coursedescription($course);
3872: $coursedesc = $courseinfo{'description'};
3873: }
3874: $category = "Group portfolio in the course '$coursedesc'";
3875: } else {
3876: $category = 'Portfolio files belonging to ';
3877: if ($env{'user.name'} eq 'public' &&
3878: $env{'user.domain'} eq 'public') {
3879: $category .= &plainname($uname,$udom);
3880: } else {
3881: $category .= &aboutmewrapper(&plainname($uname,$udom),$uname,$udom);
3882: }
3883: }
3884: } elsif ($activity eq 'groups') {
3885: $category = 'Groups in this course';
3886: }
3887: my $showstart = &Apache::lonlocal::locallocaltime($startblock);
3888: my $showend = &Apache::lonlocal::locallocaltime($endblock);
3889: $output = '<br />'.&mt('[_1] will be inaccessible between [_2] and [_3] because communication is being blocked.',$category,$showstart,$showend).'<br />';
3890: if (!($activity eq 'port' && !($ownitem) && !($is_course))) {
3891: $output .= &build_block_table($startblock,$endblock,\%setters);
3892: }
3893: }
3894: }
3895: if (wantarray) {
3896: return ($blocked,$output);
3897: } else {
3898: return $blocked;
3899: }
3900: }
3901:
3902: ###############################################
3903:
3904: sub check_ip_acc {
3905: my ($acc)=@_;
3906: &Apache::lonxml::debug("acc is $acc");
3907: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
3908: return 1;
3909: }
3910: my $allowed=0;
3911: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
3912:
3913: my $name;
3914: foreach my $pattern (split(',',$acc)) {
3915: $pattern =~ s/^\s*//;
3916: $pattern =~ s/\s*$//;
3917: if ($pattern =~ /\*$/) {
3918: #35.8.*
3919: $pattern=~s/\*//;
3920: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
3921: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
3922: #35.8.3.[34-56]
3923: my $low=$2;
3924: my $high=$3;
3925: $pattern=$1;
3926: if ($ip =~ /^\Q$pattern\E/) {
3927: my $last=(split(/\./,$ip))[3];
3928: if ($last <=$high && $last >=$low) { $allowed=1; }
3929: }
3930: } elsif ($pattern =~ /^\*/) {
3931: #*.msu.edu
3932: $pattern=~s/\*//;
3933: if (!defined($name)) {
3934: use Socket;
3935: my $netaddr=inet_aton($ip);
3936: ($name)=gethostbyaddr($netaddr,AF_INET);
3937: }
3938: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
3939: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
3940: #127.0.0.1
3941: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
3942: } else {
3943: #some.name.com
3944: if (!defined($name)) {
3945: use Socket;
3946: my $netaddr=inet_aton($ip);
3947: ($name)=gethostbyaddr($netaddr,AF_INET);
3948: }
3949: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
3950: }
3951: if ($allowed) { last; }
3952: }
3953: return $allowed;
3954: }
3955:
3956: ###############################################
3957:
3958: =pod
3959:
3960: =head1 Domain Template Functions
3961:
3962: =over 4
3963:
3964: =item * &determinedomain()
3965:
3966: Inputs: $domain (usually will be undef)
3967:
3968: Returns: Determines which domain should be used for designs
3969:
3970: =cut
3971:
3972: ###############################################
3973: sub determinedomain {
3974: my $domain=shift;
3975: if (! $domain) {
3976: # Determine domain if we have not been given one
3977: $domain = $Apache::lonnet::perlvar{'lonDefDomain'};
3978: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
3979: if ($env{'request.role.domain'}) {
3980: $domain=$env{'request.role.domain'};
3981: }
3982: }
3983: return $domain;
3984: }
3985: ###############################################
3986:
3987: sub devalidate_domconfig_cache {
3988: my ($udom)=@_;
3989: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
3990: }
3991:
3992: # ---------------------- Get domain configuration for a domain
3993: sub get_domainconf {
3994: my ($udom) = @_;
3995: my $cachetime=1800;
3996: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
3997: if (defined($cached)) { return %{$result}; }
3998:
3999: my %domconfig = &Apache::lonnet::get_dom('configuration',
4000: ['login','rolecolors'],$udom);
4001: my (%designhash,%legacy);
4002: if (keys(%domconfig) > 0) {
4003: if (ref($domconfig{'login'}) eq 'HASH') {
4004: if (keys(%{$domconfig{'login'}})) {
4005: foreach my $key (keys(%{$domconfig{'login'}})) {
4006: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
4007: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4008: $designhash{$udom.'.login.'.$key.'_'.$img} =
4009: $domconfig{'login'}{$key}{$img};
4010: }
4011: } else {
4012: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4013: }
4014: }
4015: } else {
4016: $legacy{'login'} = 1;
4017: }
4018: } else {
4019: $legacy{'login'} = 1;
4020: }
4021: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
4022: if (keys(%{$domconfig{'rolecolors'}})) {
4023: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4024: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4025: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4026: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4027: }
4028: }
4029: }
4030: } else {
4031: $legacy{'rolecolors'} = 1;
4032: }
4033: } else {
4034: $legacy{'rolecolors'} = 1;
4035: }
4036: if (keys(%legacy) > 0) {
4037: my %legacyhash = &get_legacy_domconf($udom);
4038: foreach my $item (keys(%legacyhash)) {
4039: if ($item =~ /^\Q$udom\E\.login/) {
4040: if ($legacy{'login'}) {
4041: $designhash{$item} = $legacyhash{$item};
4042: }
4043: } else {
4044: if ($legacy{'rolecolors'}) {
4045: $designhash{$item} = $legacyhash{$item};
4046: }
4047: }
4048: }
4049: }
4050: } else {
4051: %designhash = &get_legacy_domconf($udom);
4052: }
4053: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4054: $cachetime);
4055: return %designhash;
4056: }
4057:
4058: sub get_legacy_domconf {
4059: my ($udom) = @_;
4060: my %legacyhash;
4061: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4062: my $designfile = $designdir.'/'.$udom.'.tab';
4063: if (-e $designfile) {
4064: if ( open (my $fh,"<$designfile") ) {
4065: while (my $line = <$fh>) {
4066: next if ($line =~ /^\#/);
4067: chomp($line);
4068: my ($key,$val)=(split(/\=/,$line));
4069: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4070: }
4071: close($fh);
4072: }
4073: }
4074: if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
4075: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4076: }
4077: return %legacyhash;
4078: }
4079:
4080: =pod
4081:
4082: =item * &domainlogo()
4083:
4084: Inputs: $domain (usually will be undef)
4085:
4086: Returns: A link to a domain logo, if the domain logo exists.
4087: If the domain logo does not exist, a description of the domain.
4088:
4089: =cut
4090:
4091: ###############################################
4092: sub domainlogo {
4093: my $domain = &determinedomain(shift);
4094: my %designhash = &get_domainconf($domain);
4095: # See if there is a logo
4096: if ($designhash{$domain.'.login.domlogo'} ne '') {
4097: my $imgsrc = $designhash{$domain.'.login.domlogo'};
4098: if ($imgsrc =~ m{^/(adm|res)/}) {
4099: if ($imgsrc =~ m{^/res/}) {
4100: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4101: &Apache::lonnet::repcopy($local_name);
4102: }
4103: $imgsrc = &lonhttpdurl($imgsrc);
4104: }
4105: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
4106: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4107: return &Apache::lonnet::domain($domain,'description');
4108: } else {
4109: return '';
4110: }
4111: }
4112: ##############################################
4113:
4114: =pod
4115:
4116: =item * &designparm()
4117:
4118: Inputs: $which parameter; $domain (usually will be undef)
4119:
4120: Returns: value of designparamter $which
4121:
4122: =cut
4123:
4124:
4125: ##############################################
4126: sub designparm {
4127: my ($which,$domain)=@_;
4128: if ($env{'browser.blackwhite'} eq 'on') {
4129: if ($which=~/\.(font|alink|vlink|link|textcol)$/) {
4130: return '#000000';
4131: }
4132: if ($which=~/\.(pgbg|sidebg|bgcol)$/) {
4133: return '#FFFFFF';
4134: }
4135: if ($which=~/\.tabbg$/) {
4136: return '#CCCCCC';
4137: }
4138: }
4139: if (exists($env{'environment.color.'.$which})) {
4140: return $env{'environment.color.'.$which};
4141: }
4142: $domain=&determinedomain($domain);
4143: my %domdesign = &get_domainconf($domain);
4144: my $output;
4145: if ($domdesign{$domain.'.'.$which} ne '') {
4146: $output = $domdesign{$domain.'.'.$which};
4147: } else {
4148: $output = $defaultdesign{$which};
4149: }
4150: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
4151: ($which =~ /login\.(img|logo|domlogo|login)/)) {
4152: if ($output =~ m{^/(adm|res)/}) {
4153: if ($output =~ m{^/res/}) {
4154: my $local_name = &Apache::lonnet::filelocation('',$output);
4155: &Apache::lonnet::repcopy($local_name);
4156: }
4157: $output = &lonhttpdurl($output);
4158: }
4159: }
4160: return $output;
4161: }
4162:
4163: ###############################################
4164: ###############################################
4165:
4166: =pod
4167:
4168: =back
4169:
4170: =head1 HTML Helpers
4171:
4172: =over 4
4173:
4174: =item * &bodytag()
4175:
4176: Returns a uniform header for LON-CAPA web pages.
4177:
4178: Inputs:
4179:
4180: =over 4
4181:
4182: =item * $title, A title to be displayed on the page.
4183:
4184: =item * $function, the current role (can be undef).
4185:
4186: =item * $addentries, extra parameters for the <body> tag.
4187:
4188: =item * $bodyonly, if defined, only return the <body> tag.
4189:
4190: =item * $domain, if defined, force a given domain.
4191:
4192: =item * $forcereg, if page should register as content page (relevant for
4193: text interface only)
4194:
4195: =item * $customtitle, alternate text to use instead of $title
4196: in the title box that appears, this text
4197: is not auto translated like the $title is
4198:
4199: =item * $notopbar, if true, keep the 'what is this' info but remove the
4200: navigational links
4201:
4202: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
4203:
4204: =item * $notitle, if true keep the nav controls, but remove the title bar
4205:
4206: =item * $no_inline_link, if true and in remote mode, don't show the
4207: 'Switch To Inline Menu' link
4208:
4209: =item * $args, optional argument valid values are
4210: no_auto_mt_title -> prevents &mt()ing the title arg
4211: inherit_jsmath -> when creating popup window in a page,
4212: should it have jsmath forced on by the
4213: current page
4214:
4215: =back
4216:
4217: Returns: A uniform header for LON-CAPA web pages.
4218: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
4219: If $bodyonly is undef or zero, an html string containing a <body> tag and
4220: other decorations will be returned.
4221:
4222: =cut
4223:
4224: sub bodytag {
4225: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,$customtitle,
4226: $notopbar,$bgcolor,$notitle,$no_inline_link,$args)=@_;
4227:
4228: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
4229:
4230: $function = &get_users_function() if (!$function);
4231: my $img = &designparm($function.'.img',$domain);
4232: my $font = &designparm($function.'.font',$domain);
4233: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
4234:
4235: my %design = ( 'style' => 'margin-top: 0px',
4236: 'bgcolor' => $pgbg,
4237: 'text' => $font,
4238: 'alink' => &designparm($function.'.alink',$domain),
4239: 'vlink' => &designparm($function.'.vlink',$domain),
4240: 'link' => &designparm($function.'.link',$domain),);
4241: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
4242:
4243: # role and realm
4244: my ($role,$realm) = split(/\./,$env{'request.role'},2);
4245: if ($role eq 'ca') {
4246: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
4247: $realm = &plainname($rname,$rdom);
4248: }
4249: # realm
4250: if ($env{'request.course.id'}) {
4251: if ($env{'request.role'} !~ /^cr/) {
4252: $role = &Apache::lonnet::plaintext($role,&course_type());
4253: }
4254: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
4255: } else {
4256: $role = &Apache::lonnet::plaintext($role);
4257: }
4258:
4259: if (!$realm) { $realm=' '; }
4260: # Set messages
4261: my $messages=&domainlogo($domain);
4262:
4263: my $extra_body_attr = &make_attr_string($forcereg,\%design);
4264:
4265: # construct main body tag
4266: my $bodytag = "<body $extra_body_attr>".
4267: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
4268:
4269: if ($bodyonly) {
4270: return $bodytag;
4271: } elsif ($env{'browser.interface'} eq 'textual') {
4272: # Accessibility
4273:
4274: $bodytag.=&Apache::lonmenu::menubuttons($forcereg,$forcereg);
4275: if (!$notitle) {
4276: $bodytag.='<h1>LON-CAPA: '.$title.'</h1>';
4277: }
4278: return $bodytag;
4279: }
4280:
4281: my $name = &plainname($env{'user.name'},$env{'user.domain'});
4282: if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
4283: undef($role);
4284: } else {
4285: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
4286: }
4287:
4288: my $roleinfo=(<<ENDROLE);
4289: <td class="LC_title_bar_who">
4290: <div class="LC_title_bar_name">
4291: $name
4292:
4293: </div>
4294: <div class="LC_title_bar_role">
4295: $role
4296: </div>
4297: <div class="LC_title_bar_realm">
4298: $realm
4299: </div>
4300: </td>
4301: ENDROLE
4302:
4303: my $titleinfo = '<h1>'.$title.'</h1>';
4304: if ($customtitle) {
4305: $titleinfo = $customtitle;
4306: }
4307: #
4308: # Extra info if you are the DC
4309: my $dc_info = '';
4310: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
4311: $env{'course.'.$env{'request.course.id'}.
4312: '.domain'}.'/'})) {
4313: my $cid = $env{'request.course.id'};
4314: $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
4315: $dc_info =~ s/\s+$//;
4316: $dc_info = '('.$dc_info.')';
4317: }
4318:
4319: if (($env{'environment.remote'} eq 'off') || ($args->{'suppress_header_logos'})) {
4320: # No Remote
4321: if ($env{'request.state'} eq 'construct') {
4322: $forcereg=1;
4323: }
4324:
4325: if (!$customtitle && $env{'request.state'} eq 'construct') {
4326: # this is for resources; directories have customtitle, and crumbs
4327: # and select recent are created in lonpubdir.pm
4328: my ($uname,$thisdisfn)=
4329: ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
4330: my $formaction='/priv/'.$uname.'/'.$thisdisfn;
4331: $formaction=~s/\/+/\//g;
4332:
4333: my $parentpath = '';
4334: my $lastitem = '';
4335: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4336: $parentpath = $1;
4337: $lastitem = $2;
4338: } else {
4339: $lastitem = $thisdisfn;
4340: }
4341: $titleinfo =
4342: &Apache::loncommon::help_open_menu('','',3,'Authoring')
4343: .'<b>'.&mt('Construction Space').'</b>: '
4344: .'<form name="dirs" method="post" action="'.$formaction
4345: .'" target="_top"><tt><b>'
4346: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."<span class=\"LC_fontsize_big\">$lastitem</span></b></tt><br />"
4347: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4348: .'</form>'
4349: .&Apache::lonmenu::constspaceform();
4350: }
4351:
4352: my $titletable;
4353: if (!$notitle) {
4354: $titletable =
4355: '<table id="LC_title_bar">'.
4356: "<tr><td> $titleinfo $dc_info</td>".$roleinfo.
4357: '</tr></table>';
4358: }
4359: if ($notopbar) {
4360: $bodytag .= $titletable;
4361: } else {
4362: if ($env{'request.state'} eq 'construct') {
4363: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg,
4364: $titletable);
4365: } else {
4366: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg).
4367: $titletable;
4368: }
4369: }
4370: return $bodytag;
4371: }
4372:
4373: #
4374: # Top frame rendering, Remote is up
4375: #
4376:
4377: my $imgsrc = $img;
4378: if ($img =~ /^\/adm/) {
4379: $imgsrc = &lonhttpdurl($img);
4380: }
4381: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
4382:
4383: # Explicit link to get inline menu
4384: my $menu= ($no_inline_link?''
4385: :'<br /><a href="/adm/remote?action=collapse">'.&mt('Switch to Inline Menu Mode').'</a>');
4386: #
4387: if ($notitle) {
4388: return $bodytag;
4389: }
4390: return(<<ENDBODY);
4391: $bodytag
4392: <table id="LC_title_bar" class="LC_with_remote">
4393: <tr><td>$upperleft</td>
4394: <td>$messages </td>
4395: </tr>
4396: <tr><td>$titleinfo $dc_info $menu</td>
4397: $roleinfo
4398: </tr>
4399: </table>
4400: ENDBODY
4401: }
4402:
4403: sub make_attr_string {
4404: my ($register,$attr_ref) = @_;
4405:
4406: if ($attr_ref && !ref($attr_ref)) {
4407: die("addentries Must be a hash ref ".
4408: join(':',caller(1))." ".
4409: join(':',caller(0))." ");
4410: }
4411:
4412: if ($register) {
4413: my ($on_load,$on_unload);
4414: foreach my $key (keys(%{$attr_ref})) {
4415: if (lc($key) eq 'onload') {
4416: $on_load.=$attr_ref->{$key}.';';
4417: delete($attr_ref->{$key});
4418:
4419: } elsif (lc($key) eq 'onunload') {
4420: $on_unload.=$attr_ref->{$key}.';';
4421: delete($attr_ref->{$key});
4422: }
4423: }
4424: $attr_ref->{'onload'} =
4425: &Apache::lonmenu::loadevents(). $on_load;
4426: $attr_ref->{'onunload'}=
4427: &Apache::lonmenu::unloadevents().$on_unload;
4428: }
4429:
4430: # Accessibility font enhance
4431: if ($env{'browser.fontenhance'} eq 'on') {
4432: my $style;
4433: foreach my $key (keys(%{$attr_ref})) {
4434: if (lc($key) eq 'style') {
4435: $style.=$attr_ref->{$key}.';';
4436: delete($attr_ref->{$key});
4437: }
4438: }
4439: $attr_ref->{'style'}=$style.'; font-size: x-large;';
4440: }
4441:
4442: if ($env{'browser.blackwhite'} eq 'on') {
4443: delete($attr_ref->{'font'});
4444: delete($attr_ref->{'link'});
4445: delete($attr_ref->{'alink'});
4446: delete($attr_ref->{'vlink'});
4447: delete($attr_ref->{'bgcolor'});
4448: delete($attr_ref->{'background'});
4449: }
4450:
4451: my $attr_string;
4452: foreach my $attr (keys(%$attr_ref)) {
4453: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
4454: }
4455: return $attr_string;
4456: }
4457:
4458:
4459: ###############################################
4460: ###############################################
4461:
4462: =pod
4463:
4464: =item * &endbodytag()
4465:
4466: Returns a uniform footer for LON-CAPA web pages.
4467:
4468: Inputs: 1 - optional reference to an args hash
4469: If in the hash, key for noredirectlink has a value which evaluates to true,
4470: a 'Continue' link is not displayed if the page contains an
4471: internal redirect in the <head></head> section,
4472: i.e., $env{'internal.head.redirect'} exists
4473:
4474: =cut
4475:
4476: sub endbodytag {
4477: my ($args) = @_;
4478: my $endbodytag='</body>';
4479: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
4480: if ( exists( $env{'internal.head.redirect'} ) ) {
4481: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
4482: $endbodytag=
4483: "<br /><a href=\"$env{'internal.head.redirect'}\">".
4484: &mt('Continue').'</a>'.
4485: $endbodytag;
4486: }
4487: }
4488: return $endbodytag;
4489: }
4490:
4491: =pod
4492:
4493: =item * &standard_css()
4494:
4495: Returns a style sheet
4496:
4497: Inputs: (all optional)
4498: domain -> force to color decorate a page for a specific
4499: domain
4500: function -> force usage of a specific rolish color scheme
4501: bgcolor -> override the default page bgcolor
4502:
4503: =cut
4504:
4505: sub standard_css {
4506: my ($function,$domain,$bgcolor) = @_;
4507: $function = &get_users_function() if (!$function);
4508: my $img = &designparm($function.'.img', $domain);
4509: my $tabbg = &designparm($function.'.tabbg', $domain);
4510: my $font = &designparm($function.'.font', $domain);
4511: #second colour for later usage
4512: my $sidebg = &designparm($function.'.sidebg',$domain);
4513: my $pgbg_or_bgcolor =
4514: $bgcolor ||
4515: &designparm($function.'.pgbg', $domain);
4516: my $pgbg = &designparm($function.'.pgbg', $domain);
4517: my $alink = &designparm($function.'.alink', $domain);
4518: my $vlink = &designparm($function.'.vlink', $domain);
4519: my $link = &designparm($function.'.link', $domain);
4520:
4521: my $loginbg = &designparm('login.sidebg',$domain);
4522: my $bgcol = &designparm('login.bgcol',$domain);
4523: my $textcol = &designparm('login.textcol',$domain);
4524:
4525: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
4526: my $mono = 'monospace';
4527: my $data_table_head = $tabbg;
4528: my $data_table_light = '#EEEEEE';
4529: my $data_table_dark = '#DDDDDD';
4530: my $data_table_darker = '#CCCCCC';
4531: my $data_table_highlight = '#FFFF00';
4532: my $mail_new = '#FFBB77';
4533: my $mail_new_hover = '#DD9955';
4534: my $mail_read = '#BBBB77';
4535: my $mail_read_hover = '#999944';
4536: my $mail_replied = '#AAAA88';
4537: my $mail_replied_hover = '#888855';
4538: my $mail_other = '#99BBBB';
4539: my $mail_other_hover = '#669999';
4540: my $table_header = '#DDDDDD';
4541: my $feedback_link_bg = '#BBBBBB';
4542: my $lg_border_color = '#C8C8C8';
4543:
4544: my $border = ($env{'browser.type'} eq 'explorer' ||
4545: $env{'browser.type'} eq 'safari' ) ? '0px 2px 0px 2px'
4546: : '0px 3px 0px 4px';
4547:
4548:
4549: return <<END;
4550: body {
4551: font-family: $sans;
4552: line-height:130%;
4553: font-size:0.83em;
4554: color:$font;
4555: }
4556:
4557: a:link, a:visited {
4558: font-size:100%;
4559: }
4560:
4561: a:focus {
4562: color: red;
4563: background: yellow
4564: }
4565:
4566: table.thinborder,
4567: table.thinborder tr th {
4568: border-style: solid;
4569: border-width: 1px;
4570: border-color: $lg_border_color;
4571: background: $tabbg;
4572: }
4573:
4574: table.thinborder tr td {
4575: border-style: solid;
4576: border-width: 1px;
4577: border-color: $lg_border_color;
4578: }
4579:
4580: form, .inline {
4581: display: inline;
4582: }
4583:
4584: .LC_right {
4585: text-align:right;
4586: }
4587:
4588: .LC_middle {
4589: vertical-align:middle;
4590: }
4591:
4592: /* just for tests */
4593: .LC_400Box {width:400px; }
4594: /* end */
4595:
4596: .LC_filename {
4597: font-family: $mono;
4598: white-space:pre;
4599: }
4600:
4601: .LC_fileicon {
4602: border: none;
4603: height: 1.3em;
4604: vertical-align: text-bottom;
4605: margin-right: 0.3em;
4606: text-decoration:none;
4607: }
4608:
4609: .LC_error {
4610: color: red;
4611: font-size: larger;
4612: }
4613:
4614: .LC_warning,
4615: .LC_diff_removed {
4616: color: red;
4617: }
4618:
4619: .LC_info,
4620: .LC_success,
4621: .LC_diff_added {
4622: color: green;
4623: }
4624:
4625: .LC_unknown {
4626: color: yellow;
4627: }
4628:
4629: .LC_icon {
4630: border: none;
4631: vertical-align: middle;
4632: }
4633:
4634: .LC_indexer_icon {
4635: border: 0px;
4636: height: 22px;
4637: }
4638:
4639: .LC_docs_spacer {
4640: width: 25px;
4641: height: 1px;
4642: border: none;
4643: }
4644:
4645: .LC_internal_info {
4646: color: #999999;
4647: }
4648:
4649: .LC_discussion {
4650: background: $tabbg;
4651: border: 1px solid black;
4652: margin: 2px;
4653: }
4654:
4655: .LC_disc_action_links_bar {
4656: background: $tabbg;
4657: font-family: $sans;
4658: border: 0px;
4659: margin: 4px;
4660: }
4661:
4662: .LC_disc_action_left {
4663: text-align: left;
4664: }
4665:
4666: .LC_disc_action_right {
4667: text-align: right;
4668: }
4669:
4670: .LC_disc_new_item {
4671: background: white;
4672: border: 2px solid red;
4673: margin: 2px;
4674: }
4675:
4676: .LC_disc_old_item {
4677: background: white;
4678: border: 1px solid black;
4679: margin: 2px;
4680: }
4681:
4682: .LC_success_confirm {
4683: font-family: $sans;
4684: color: darkgreen;
4685: }
4686:
4687: table.LC_pastsubmission {
4688: border: 1px solid black;
4689: margin: 2px;
4690: }
4691:
4692: table#LC_top_nav,
4693: table#LC_menubuttons,
4694: table#LC_nav_location {
4695: width: 100%;
4696: background: $pgbg;
4697: border: 2px;
4698: border-collapse: separate;
4699: padding: 0px;
4700: }
4701:
4702: table#LC_title_bar,
4703: table.LC_breadcrumbs,
4704: table#LC_title_bar.LC_with_remote {
4705: width: 100%;
4706: border-color: $pgbg;
4707: border-style: solid;
4708: border-width: $border;
4709: background: $pgbg;
4710: font-family: $sans;
4711: border-collapse: collapse;
4712: padding: 0px;
4713: }
4714:
4715: table.LC_docs_path {
4716: width: 100%;
4717: border: 0;
4718: background: $pgbg;
4719: font-family: $sans;
4720: border-collapse: collapse;
4721: padding: 0px;
4722: }
4723:
4724: table#LC_title_bar td {
4725: background: $tabbg;
4726: }
4727:
4728: table#LC_title_bar .LC_title_bar_who {
4729: background: $tabbg;
4730: color: $font;
4731: font: small $sans;
4732: text-align: right;
4733: margin: 0px;
4734: }
4735:
4736: table#LC_title_bar .LC_title_bar_name {
4737: margin: 0px;
4738: }
4739:
4740: table#LC_title_bar .LC_title_bar_role {
4741: margin: 0px;
4742: }
4743:
4744: table#LC_title_bar .LC_title_bar_realm {
4745: margin: 0px;
4746: }
4747:
4748: span.LC_metadata {
4749: font-family: $sans;
4750: }
4751:
4752: table#LC_menubuttons img{
4753: border: 0px;
4754: }
4755:
4756: table#LC_top_nav td {
4757: background: $tabbg;
4758: border: 0px;
4759: font-size: small;
4760: vertical-align:top;
4761: padding:2px 5px 2px 5px;
4762: }
4763:
4764: table#LC_top_nav td a,
4765: div#LC_top_nav a {
4766: color: $font;
4767: font-family: $sans;
4768: }
4769:
4770: table#LC_top_nav td.LC_top_nav_logo {
4771: background: $tabbg;
4772: text-align: left;
4773: white-space: nowrap;
4774: width: 31px;
4775: }
4776:
4777: table#LC_top_nav td.LC_top_nav_logo img {
4778: border: 0px;
4779: vertical-align: bottom;
4780: }
4781:
4782: table#LC_top_nav td.LC_top_nav_exit,
4783: table#LC_top_nav td.LC_top_nav_help {
4784: width: 2.0em;
4785: }
4786:
4787: table#LC_top_nav td.LC_top_nav_login {
4788: width: 4.0em;
4789: text-align: center;
4790: }
4791:
4792: table.LC_breadcrumbs td,
4793: table.LC_docs_path td {
4794: background: $tabbg;
4795: color: $font;
4796: font-family: $sans;
4797: font-size: smaller;
4798: }
4799:
4800: table.LC_breadcrumbs td.LC_breadcrumbs_component,
4801: table.LC_docs_path td.LC_docs_path_component {
4802: background: $tabbg;
4803: color: $font;
4804: font-family: $sans;
4805: font-size: larger;
4806: text-align: right;
4807: }
4808:
4809: td.LC_table_cell_checkbox {
4810: text-align: center;
4811: }
4812:
4813: table#LC_mainmenu td.LC_mainmenu_column {
4814: vertical-align: top;
4815: }
4816:
4817: .LC_fontsize_small {
4818: font-size: 70%;
4819: }
4820:
4821: .LC_fontsize_medium {
4822: font-size: 85%;
4823: }
4824:
4825: .LC_fontsize_large {
4826: font-size: 120%;
4827: }
4828:
4829: .LC_menubuttons_inline_text {
4830: color: $font;
4831: font-family: $sans;
4832: font-size: 90%;
4833: padding-left:3px;
4834: }
4835:
4836: .LC_menubuttons_link {
4837: text-decoration: none;
4838: }
4839:
4840: .LC_menubuttons_category {
4841: color: $font;
4842: background: $pgbg;
4843: font-family: $sans;
4844: font-size: larger;
4845: font-weight: bold;
4846: }
4847:
4848: td.LC_menubuttons_text {
4849: color: $font;
4850: }
4851:
4852: .LC_current_location {
4853: font-family: $sans;
4854: background: $tabbg;
4855: }
4856:
4857: .LC_new_mail {
4858: font-family: $sans;
4859: background: $tabbg;
4860: font-weight: bold;
4861: }
4862:
4863: .LC_dropadd_labeltext {
4864: font-family: $sans;
4865: text-align: right;
4866: }
4867:
4868: .LC_preferences_labeltext {
4869: font-family: $sans;
4870: text-align: right;
4871: }
4872:
4873: .LC_roleslog_note {
4874: font-size: small;
4875: }
4876:
4877: .LC_mail_functions {
4878: font-weight: bold;
4879: }
4880:
4881: table.LC_aboutme_port {
4882: border: 0px;
4883: border-collapse: collapse;
4884: border-spacing: 0px;
4885: }
4886:
4887: table.LC_data_table,
4888: table.LC_mail_list {
4889: border: 1px solid #000000;
4890: border-collapse: separate;
4891: border-spacing: 1px;
4892: background: $pgbg;
4893: }
4894:
4895: .LC_data_table_dense {
4896: font-size: small;
4897: }
4898:
4899: table.LC_nested_outer {
4900: border: 1px solid #000000;
4901: border-collapse: collapse;
4902: border-spacing: 0px;
4903: width: 100%;
4904: }
4905:
4906: table.LC_nested {
4907: border: 0px;
4908: border-collapse: collapse;
4909: border-spacing: 0px;
4910: width: 100%;
4911: }
4912:
4913: table.LC_data_table tr th,
4914: table.LC_calendar tr th,
4915: table.LC_mail_list tr th,
4916: table.LC_prior_tries tr th {
4917: font-weight: bold;
4918: background-color: $data_table_head;
4919: font-size:90%;
4920: }
4921:
4922: table.LC_data_table tr.LC_info_row > td {
4923: background-color: #CCCCCC;
4924: font-weight: bold;
4925: text-align: left;
4926: }
4927:
4928: table.LC_data_table tr.LC_odd_row > td,
4929: table.LC_pick_box tr > td.LC_odd_row,
4930: table.LC_aboutme_port tr td {
4931: background-color: $data_table_light;
4932: padding: 2px;
4933: }
4934:
4935: table.LC_data_table tr.LC_even_row > td,
4936: table.LC_pick_box tr > td.LC_even_row,
4937: table.LC_aboutme_port tr.LC_even_row td {
4938: background-color: $data_table_dark;
4939: padding: 2px;
4940: }
4941:
4942: table.LC_data_table tr.LC_data_table_highlight td {
4943: background-color: $data_table_darker;
4944: }
4945:
4946: table.LC_data_table tr td.LC_leftcol_header {
4947: background-color: $data_table_head;
4948: font-weight: bold;
4949: }
4950:
4951: table.LC_data_table tr.LC_empty_row td,
4952: table.LC_nested tr.LC_empty_row td {
4953: background-color: #FFFFFF;
4954: font-weight: bold;
4955: font-style: italic;
4956: text-align: center;
4957: padding: 8px;
4958: }
4959:
4960: table.LC_nested tr.LC_empty_row td {
4961: padding: 4ex
4962: }
4963:
4964: table.LC_nested_outer tr th {
4965: font-weight: bold;
4966: background-color: $data_table_head;
4967: font-size: small;
4968: border-bottom: 1px solid #000000;
4969: }
4970:
4971: table.LC_nested_outer tr td.LC_subheader {
4972: background-color: $data_table_head;
4973: font-weight: bold;
4974: font-size: small;
4975: border-bottom: 1px solid #000000;
4976: text-align: right;
4977: }
4978:
4979: table.LC_nested tr.LC_info_row td {
4980: background-color: #CCCCCC;
4981: font-weight: bold;
4982: font-size: small;
4983: text-align: center;
4984: }
4985:
4986: table.LC_nested tr.LC_info_row td.LC_left_item,
4987: table.LC_nested_outer tr th.LC_left_item {
4988: text-align: left;
4989: }
4990:
4991: table.LC_nested td {
4992: background-color: #FFFFFF;
4993: font-size: small;
4994: }
4995:
4996: table.LC_nested_outer tr th.LC_right_item,
4997: table.LC_nested tr.LC_info_row td.LC_right_item,
4998: table.LC_nested tr.LC_odd_row td.LC_right_item,
4999: table.LC_nested tr td.LC_right_item {
5000: text-align: right;
5001: }
5002:
5003: table.LC_nested tr.LC_odd_row td {
5004: background-color: #EEEEEE;
5005: }
5006:
5007: table.LC_createuser {
5008: }
5009:
5010: table.LC_createuser tr.LC_section_row td {
5011: font-size: small;
5012: }
5013:
5014: table.LC_createuser tr.LC_info_row td {
5015: background-color: #CCCCCC;
5016: font-weight: bold;
5017: text-align: center;
5018: }
5019:
5020: table.LC_calendar {
5021: border: 1px solid #000000;
5022: border-collapse: collapse;
5023: }
5024:
5025: table.LC_calendar_pickdate {
5026: font-size: xx-small;
5027: }
5028:
5029: table.LC_calendar tr td {
5030: border: 1px solid #000000;
5031: vertical-align: top;
5032: }
5033:
5034: table.LC_calendar tr td.LC_calendar_day_empty {
5035: background-color: $data_table_dark;
5036: }
5037:
5038: table.LC_calendar tr td.LC_calendar_day_current {
5039: background-color: $data_table_highlight;
5040: }
5041:
5042: table.LC_mail_list tr.LC_mail_new {
5043: background-color: $mail_new;
5044: }
5045:
5046: table.LC_mail_list tr.LC_mail_new:hover {
5047: background-color: $mail_new_hover;
5048: }
5049:
5050: table.LC_mail_list tr.LC_mail_even {
5051: }
5052:
5053: table.LC_mail_list tr.LC_mail_odd {
5054: }
5055:
5056: table.LC_mail_list tr.LC_mail_read {
5057: background-color: $mail_read;
5058: }
5059:
5060: table.LC_mail_list tr.LC_mail_read:hover {
5061: background-color: $mail_read_hover;
5062: }
5063:
5064: table.LC_mail_list tr.LC_mail_replied {
5065: background-color: $mail_replied;
5066: }
5067:
5068: table.LC_mail_list tr.LC_mail_replied:hover {
5069: background-color: $mail_replied_hover;
5070: }
5071:
5072: table.LC_mail_list tr.LC_mail_other {
5073: background-color: $mail_other;
5074: }
5075:
5076: table.LC_mail_list tr.LC_mail_other:hover {
5077: background-color: $mail_other_hover;
5078: }
5079:
5080: table.LC_data_table tr > td.LC_browser_file,
5081: table.LC_data_table tr > td.LC_browser_file_published {
5082: background: #CCFF88;
5083: }
5084:
5085: table.LC_data_table tr > td.LC_browser_file_locked,
5086: table.LC_data_table tr > td.LC_browser_file_unpublished {
5087: background: #FFAA99;
5088: }
5089:
5090: table.LC_data_table tr > td.LC_browser_file_obsolete {
5091: background: #AAAAAA;
5092: }
5093:
5094: table.LC_data_table tr > td.LC_browser_file_modified,
5095: table.LC_data_table tr > td.LC_browser_file_metamodified {
5096: background: #FFFF77;
5097: }
5098:
5099: table.LC_data_table tr.LC_browser_folder > td {
5100: background: #CCCCFF;
5101: }
5102:
5103: table.LC_data_table tr > td.LC_roles_is {
5104: /* background: #77FF77; */
5105: }
5106:
5107: table.LC_data_table tr > td.LC_roles_future {
5108: background: #FFFF77;
5109: }
5110:
5111: table.LC_data_table tr > td.LC_roles_will {
5112: background: #FFAA77;
5113: }
5114:
5115: table.LC_data_table tr > td.LC_roles_expired {
5116: background: #FF7777;
5117: }
5118:
5119: table.LC_data_table tr > td.LC_roles_will_not {
5120: background: #AAFF77;
5121: }
5122:
5123: table.LC_data_table tr > td.LC_roles_selected {
5124: background: #11CC55;
5125: }
5126:
5127: span.LC_current_location {
5128: font-size:larger;
5129: background: $pgbg;
5130: }
5131:
5132: span.LC_parm_menu_item {
5133: font-size: larger;
5134: font-family: $sans;
5135: }
5136:
5137: span.LC_parm_scope_all {
5138: color: red;
5139: }
5140:
5141: span.LC_parm_scope_folder {
5142: color: green;
5143: }
5144:
5145: span.LC_parm_scope_resource {
5146: color: orange;
5147: }
5148:
5149: span.LC_parm_part {
5150: color: blue;
5151: }
5152:
5153: span.LC_parm_folder, span.LC_parm_symb {
5154: font-size: x-small;
5155: font-family: $mono;
5156: color: #AAAAAA;
5157: }
5158:
5159: td.LC_parm_overview_level_menu,
5160: td.LC_parm_overview_map_menu,
5161: td.LC_parm_overview_parm_selectors,
5162: td.LC_parm_overview_restrictions {
5163: border: 1px solid black;
5164: border-collapse: collapse;
5165: }
5166:
5167: table.LC_parm_overview_restrictions td {
5168: border-width: 1px 4px 1px 4px;
5169: border-style: solid;
5170: border-color: $pgbg;
5171: text-align: center;
5172: }
5173:
5174: table.LC_parm_overview_restrictions th {
5175: background: $tabbg;
5176: border-width: 1px 4px 1px 4px;
5177: border-style: solid;
5178: border-color: $pgbg;
5179: }
5180:
5181: table#LC_helpmenu {
5182: border: 0px;
5183: height: 55px;
5184: border-spacing: 0px;
5185: }
5186:
5187: table#LC_helpmenu fieldset legend {
5188: font-size: larger;
5189: font-weight: bold;
5190: }
5191:
5192: table#LC_helpmenu_links {
5193: width: 100%;
5194: border: 1px solid black;
5195: background: $pgbg;
5196: padding: 0px;
5197: border-spacing: 1px;
5198: }
5199:
5200: table#LC_helpmenu_links tr td {
5201: padding: 1px;
5202: background: $tabbg;
5203: text-align: center;
5204: font-weight: bold;
5205: }
5206:
5207: table#LC_helpmenu_links a:link,
5208: table#LC_helpmenu_links a:visited,
5209: table#LC_helpmenu_links a:active {
5210: text-decoration: none;
5211: color: $font;
5212: }
5213:
5214: table#LC_helpmenu_links a:hover {
5215: text-decoration: underline;
5216: color: $vlink;
5217: }
5218:
5219: .LC_chrt_popup_exists {
5220: border: 1px solid #339933;
5221: margin: -1px;
5222: }
5223:
5224: .LC_chrt_popup_up {
5225: border: 1px solid yellow;
5226: margin: -1px;
5227: }
5228:
5229: .LC_chrt_popup {
5230: border: 1px solid #8888FF;
5231: background: #CCCCFF;
5232: }
5233:
5234: table.LC_pick_box {
5235: border-collapse: separate;
5236: background: white;
5237: border: 1px solid black;
5238: border-spacing: 1px;
5239: }
5240:
5241: table.LC_pick_box td.LC_pick_box_title {
5242: background: $tabbg;
5243: font-weight: bold;
5244: text-align: right;
5245: vertical-align: top;
5246: width: 184px;
5247: padding: 8px;
5248: }
5249:
5250: table.LC_pick_box td.LC_selfenroll_pick_box_title {
5251: background: $tabbg;
5252: font-weight: bold;
5253: text-align: right;
5254: width: 350px;
5255: padding: 8px;
5256: }
5257:
5258: table.LC_pick_box td.LC_pick_box_value {
5259: text-align: left;
5260: padding: 8px;
5261: }
5262:
5263: table.LC_pick_box td.LC_pick_box_select {
5264: text-align: left;
5265: padding: 8px;
5266: }
5267:
5268: table.LC_pick_box td.LC_pick_box_separator {
5269: padding: 0px;
5270: height: 1px;
5271: background: black;
5272: }
5273:
5274: table.LC_pick_box td.LC_pick_box_submit {
5275: text-align: right;
5276: }
5277:
5278: table.LC_pick_box td.LC_evenrow_value {
5279: text-align: left;
5280: padding: 8px;
5281: background-color: $data_table_light;
5282: }
5283:
5284: table.LC_pick_box td.LC_oddrow_value {
5285: text-align: left;
5286: padding: 8px;
5287: background-color: $data_table_light;
5288: }
5289:
5290: table.LC_helpform_receipt {
5291: width: 620px;
5292: border-collapse: separate;
5293: background: white;
5294: border: 1px solid black;
5295: border-spacing: 1px;
5296: }
5297:
5298: table.LC_helpform_receipt td.LC_pick_box_title {
5299: background: $tabbg;
5300: font-weight: bold;
5301: text-align: right;
5302: width: 184px;
5303: padding: 8px;
5304: }
5305:
5306: table.LC_helpform_receipt td.LC_evenrow_value {
5307: text-align: left;
5308: padding: 8px;
5309: background-color: $data_table_light;
5310: }
5311:
5312: table.LC_helpform_receipt td.LC_oddrow_value {
5313: text-align: left;
5314: padding: 8px;
5315: background-color: $data_table_light;
5316: }
5317:
5318: table.LC_helpform_receipt td.LC_pick_box_separator {
5319: padding: 0px;
5320: height: 1px;
5321: background: black;
5322: }
5323:
5324: span.LC_helpform_receipt_cat {
5325: font-weight: bold;
5326: }
5327:
5328: table.LC_group_priv_box {
5329: background: white;
5330: border: 1px solid black;
5331: border-spacing: 1px;
5332: }
5333:
5334: table.LC_group_priv_box td.LC_pick_box_title {
5335: background: $tabbg;
5336: font-weight: bold;
5337: text-align: right;
5338: width: 184px;
5339: }
5340:
5341: table.LC_group_priv_box td.LC_groups_fixed {
5342: background: $data_table_light;
5343: text-align: center;
5344: }
5345:
5346: table.LC_group_priv_box td.LC_groups_optional {
5347: background: $data_table_dark;
5348: text-align: center;
5349: }
5350:
5351: table.LC_group_priv_box td.LC_groups_functionality {
5352: background: $data_table_darker;
5353: text-align: center;
5354: font-weight: bold;
5355: }
5356:
5357: table.LC_group_priv td {
5358: text-align: left;
5359: padding: 0px;
5360: }
5361:
5362: table.LC_notify_front_page {
5363: background: white;
5364: border: 1px solid black;
5365: padding: 8px;
5366: }
5367:
5368: table.LC_notify_front_page td {
5369: padding: 8px;
5370: }
5371:
5372: .LC_navbuttons {
5373: margin: 2ex 0ex 2ex 0ex;
5374: }
5375:
5376: .LC_topic_bar {
5377: font-family: $sans;
5378: font-weight: bold;
5379: width: 100%;
5380: background: $tabbg;
5381: vertical-align: middle;
5382: margin: 2ex 0ex 2ex 0ex;
5383: }
5384:
5385: .LC_topic_bar span {
5386: vertical-align: middle;
5387: }
5388:
5389: .LC_topic_bar img {
5390: vertical-align: bottom;
5391: }
5392:
5393: table.LC_course_group_status {
5394: margin: 20px;
5395: }
5396:
5397: table.LC_status_selector td {
5398: vertical-align: top;
5399: text-align: center;
5400: padding: 4px;
5401: }
5402:
5403: table.LC_descriptive_input td.LC_description {
5404: vertical-align: top;
5405: text-align: right;
5406: font-weight: bold;
5407: }
5408:
5409: div.LC_feedback_link {
5410: clear: both;
5411: background: white;
5412: width: 100%;
5413: }
5414:
5415: span.LC_feedback_link {
5416: background: $feedback_link_bg;
5417: font-size: larger;
5418: }
5419:
5420: span.LC_message_link {
5421: background: $feedback_link_bg;
5422: font-size: larger;
5423: position: absolute;
5424: right: 1em;
5425: }
5426:
5427: table.LC_prior_tries {
5428: border: 1px solid #000000;
5429: border-collapse: separate;
5430: border-spacing: 1px;
5431: }
5432:
5433: table.LC_prior_tries td {
5434: padding: 2px;
5435: }
5436:
5437: .LC_answer_correct {
5438: background: lightgreen;
5439: font-family: $sans;
5440: color: darkgreen;
5441: padding: 6px;
5442: }
5443:
5444: .LC_answer_charged_try {
5445: background: lightred;
5446: font-family: $sans;
5447: color: darkred;
5448: padding: 6px;
5449: }
5450:
5451: .LC_answer_not_charged_try,
5452: .LC_answer_no_grade,
5453: .LC_answer_late {
5454: background: lightyellow;
5455: font-family: $sans;
5456: color: black;
5457: padding: 6px;
5458: }
5459:
5460: .LC_answer_previous {
5461: background: lightblue;
5462: font-family: $sans;
5463: color: darkblue;
5464: padding: 6px;
5465: }
5466:
5467: .LC_answer_no_message {
5468: background: #FFFFFF;
5469: font-family: $sans;
5470: color: black;
5471: padding: 6px;
5472: }
5473:
5474: .LC_answer_unknown {
5475: background: orange;
5476: font-family: $sans;
5477: color: black;
5478: padding: 6px;
5479: }
5480:
5481: span.LC_prior_numerical,
5482: span.LC_prior_string,
5483: span.LC_prior_custom,
5484: span.LC_prior_reaction,
5485: span.LC_prior_math {
5486: font-family: monospace;
5487: white-space: pre;
5488: }
5489:
5490: span.LC_prior_string {
5491: font-family: monospace;
5492: white-space: pre;
5493: }
5494:
5495: table.LC_prior_option {
5496: width: 100%;
5497: border-collapse: collapse;
5498: }
5499:
5500: table.LC_prior_rank,
5501: table.LC_prior_match {
5502: border-collapse: collapse;
5503: }
5504:
5505: table.LC_prior_option tr td,
5506: table.LC_prior_rank tr td,
5507: table.LC_prior_match tr td {
5508: border: 1px solid #000000;
5509: }
5510:
5511: td.LC_nobreak,
5512: span.LC_nobreak {
5513: white-space: nowrap;
5514: }
5515:
5516: span.LC_cusr_emph {
5517: font-style: italic;
5518: }
5519:
5520: span.LC_cusr_subheading {
5521: font-weight: normal;
5522: font-size: 85%;
5523: }
5524:
5525: table.LC_docs_documents {
5526: background: #BBBBBB;
5527: border-width: 0px;
5528: border-collapse: collapse;
5529: }
5530:
5531: table.LC_docs_documents td.LC_docs_document {
5532: border: 2px solid black;
5533: padding: 4px;
5534: }
5535:
5536: .LC_docs_entry_move {
5537: border: 0px;
5538: border-collapse: collapse;
5539: }
5540:
5541: .LC_docs_entry_move td {
5542: border: 2px solid #BBBBBB;
5543: background: #DDDDDD;
5544: }
5545:
5546: .LC_docs_editor td.LC_docs_entry_commands {
5547: background: #DDDDDD;
5548: font-size: x-small;
5549: }
5550:
5551: .LC_docs_copy {
5552: color: #000099;
5553: }
5554:
5555: .LC_docs_cut {
5556: color: #550044;
5557: }
5558:
5559: .LC_docs_rename {
5560: color: #009900;
5561: }
5562:
5563: .LC_docs_remove {
5564: color: #990000;
5565: }
5566:
5567: .LC_docs_reinit_warn,
5568: .LC_docs_ext_edit {
5569: font-size: x-small;
5570: }
5571:
5572: .LC_docs_editor td.LC_docs_entry_title,
5573: .LC_docs_editor td.LC_docs_entry_icon {
5574: background: #FFFFBB;
5575: }
5576:
5577: .LC_docs_editor td.LC_docs_entry_parameter {
5578: background: #BBBBFF;
5579: font-size: x-small;
5580: white-space: nowrap;
5581: }
5582:
5583: table.LC_docs_adddocs td,
5584: table.LC_docs_adddocs th {
5585: border: 1px solid #BBBBBB;
5586: padding: 4px;
5587: background: #DDDDDD;
5588: }
5589:
5590: table.LC_sty_begin {
5591: background: #BBFFBB;
5592: }
5593:
5594: table.LC_sty_end {
5595: background: #FFBBBB;
5596: }
5597:
5598: table.LC_double_column {
5599: border-width: 0px;
5600: border-collapse: collapse;
5601: width: 100%;
5602: padding: 2px;
5603: }
5604:
5605: table.LC_double_column tr td.LC_left_col {
5606: top: 2px;
5607: left: 2px;
5608: width: 47%;
5609: vertical-align: top;
5610: }
5611:
5612: table.LC_double_column tr td.LC_right_col {
5613: top: 2px;
5614: right: 2px;
5615: width: 47%;
5616: vertical-align: top;
5617: }
5618:
5619: span.LC_role_level {
5620: font-weight: bold;
5621: }
5622:
5623: div.LC_left_float {
5624: float: left;
5625: padding-right: 5%;
5626: padding-bottom: 4px;
5627: }
5628:
5629: div.LC_clear_float_header {
5630: padding-bottom: 2px;
5631: }
5632:
5633: div.LC_clear_float_footer {
5634: padding-top: 10px;
5635: clear: both;
5636: }
5637:
5638: div.LC_grade_show_user {
5639: margin-top: 20px;
5640: border: 1px solid black;
5641: }
5642:
5643: div.LC_grade_user_name {
5644: background: #DDDDEE;
5645: border-bottom: 1px solid black;
5646: font-weight: bold;
5647: font-size: large;
5648: }
5649:
5650: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
5651: background: #DDEEDD;
5652: }
5653:
5654: div.LC_grade_show_problem,
5655: div.LC_grade_submissions,
5656: div.LC_grade_message_center,
5657: div.LC_grade_info_links,
5658: div.LC_grade_assign {
5659: margin: 5px;
5660: width: 99%;
5661: background: #FFFFFF;
5662: }
5663:
5664: div.LC_grade_show_problem_header,
5665: div.LC_grade_submissions_header,
5666: div.LC_grade_message_center_header,
5667: div.LC_grade_assign_header {
5668: font-weight: bold;
5669: font-size: large;
5670: }
5671:
5672: div.LC_grade_show_problem_problem,
5673: div.LC_grade_submissions_body,
5674: div.LC_grade_message_center_body,
5675: div.LC_grade_assign_body {
5676: border: 1px solid black;
5677: width: 99%;
5678: background: #FFFFFF;
5679: }
5680:
5681: span.LC_grade_check_note {
5682: font-weight: normal;
5683: font-size: medium;
5684: display: inline;
5685: position: absolute;
5686: right: 1em;
5687: }
5688:
5689: table.LC_scantron_action {
5690: width: 100%;
5691: }
5692:
5693: table.LC_scantron_action tr th {
5694: font-weight:bold;
5695: font-style:normal;
5696: }
5697:
5698: .LC_edit_problem_header,
5699: div.LC_edit_problem_footer {
5700: font-weight: normal;
5701: font-size: medium;
5702: margin: 2px;
5703: }
5704:
5705: div.LC_edit_problem_header,
5706: div.LC_edit_problem_header div,
5707: div.LC_edit_problem_footer,
5708: div.LC_edit_problem_footer div,
5709: div.LC_edit_problem_editxml_header,
5710: div.LC_edit_problem_editxml_header div {
5711: margin-top: 5px;
5712: }
5713:
5714: div.LC_edit_problem_header_edit_row {
5715: background: $tabbg;
5716: padding: 3px;
5717: margin-bottom: 5px;
5718: }
5719:
5720: div.LC_edit_problem_header_title {
5721: font-weight: bold;
5722: font-size: larger;
5723: background: $tabbg;
5724: padding: 3px;
5725: }
5726:
5727: table.LC_edit_problem_header_title {
5728: font-size: larger;
5729: font-weight: bold;
5730: width: 100%;
5731: border-color: $pgbg;
5732: border-style: solid;
5733: border-width: $border;
5734: background: $tabbg;
5735: border-collapse: collapse;
5736: padding: 0px
5737: }
5738:
5739: div.LC_edit_problem_discards {
5740: float: left;
5741: padding-bottom: 5px;
5742: }
5743:
5744: div.LC_edit_problem_saves {
5745: float: right;
5746: padding-bottom: 5px;
5747: }
5748:
5749: hr.LC_edit_problem_divide {
5750: clear: both;
5751: color: $tabbg;
5752: background-color: $tabbg;
5753: height: 3px;
5754: border: 0px;
5755: }
5756:
5757: img.stift{
5758: border-width:0;
5759: vertical-align:middle;
5760: }
5761:
5762: table#LC_mainmenu{
5763: margin-top:10px;
5764: width:80%;
5765: }
5766:
5767: table#LC_mainmenu td.LC_mainmenu_col_fieldset{
5768: vertical-align: top;
5769: width: 45%;
5770: }
5771:
5772: .LC_mainmenu_fieldset_category {
5773: color: $font;
5774: background: $pgbg;
5775: font-family: $sans;
5776: font-size: small;
5777: font-weight: bold;
5778: }
5779:
5780: div.LC_createcourse {
5781: margin: 10px 10px 10px 10px;
5782: }
5783:
5784: /* ---- Remove when done ----
5785: # The following styles is part of the redesign of LON-CAPA and are
5786: # subject to change during this project.
5787: # Don't rely on their current functionality as they might be
5788: # changed or removed.
5789: # --------------------------*/
5790:
5791: a:hover,
5792: ol.LC_smallMenu a:hover,
5793: ol#LC_MenuBreadcrumbs a:hover,
5794: ol#LC_PathBreadcrumbs a:hover,
5795: ul#LC_TabMainMenuContent a:hover,
5796: .LC_FormSectionClearButton input:hover
5797: ul.LC_TabContent li:hover a {
5798: color:#BF2317;
5799: text-decoration:none;
5800: }
5801:
5802: h1 {
5803: padding:5px 10px 5px 20px;
5804: line-height:130%;
5805: }
5806:
5807: h2,h3,h4,h5,h6 {
5808: margin:5px 0px 5px 0px;
5809: padding:0px;
5810: line-height:130%;
5811: }
5812:
5813: .LC_hcell {
5814: padding:3px 15px 3px 15px;
5815: margin:0px;
5816: background-color:$tabbg;
5817: border-bottom:solid 1px $lg_border_color;
5818: }
5819:
5820: .LC_noBorder {
5821: border:0px;
5822: }
5823:
5824:
5825: /* Main Header with discription of Person, Course, etc. */
5826:
5827: .LC_Right {
5828: float: right;
5829: margin: 0px;
5830: padding: 0px;
5831: }
5832:
5833: .LC_FormSectionClearButton input {
5834: background-color:transparent;
5835: border:0px;
5836: cursor:pointer;
5837: text-decoration:underline;
5838: }
5839:
5840: .LC_help_open_topic {
5841: color: #FFFFFF;
5842: background-color: #EEEEFF;
5843: margin: 1px;
5844: padding: 4px;
5845: border: 1px solid #000033;
5846: white-space: nowrap;
5847: /* vertical-align: middle; */
5848: }
5849:
5850: dl,ul,div,fieldset {
5851: margin: 10px 10px 10px 0px;
5852: overflow:hidden;
5853: }
5854:
5855: ol.LC_smallMenu, ol#LC_PathBreadcrumbs {
5856: margin: 0px;
5857: }
5858:
5859: ol.LC_smallMenu li {
5860: display: inline;
5861: padding: 5px 5px 0px 10px;
5862: vertical-align: top;
5863: }
5864:
5865: ol.LC_smallMenu li img {
5866: vertical-align: bottom;
5867: }
5868:
5869: ol.LC_smallMenu a {
5870: font-size: 90%;
5871: color: RGB(80, 80, 80);
5872: text-decoration: none;
5873: }
5874:
5875: ol#LC_TabMainMenuContent,
5876: ul.LC_TabContent ,
5877: ul.LC_TabContentBigger {
5878: display:block;
5879: list-style:none;
5880: margin: 0px;
5881: padding: 0px;
5882: }
5883:
5884: ol#LC_TabMainMenuContent li,
5885: ul.LC_TabContent li,
5886: ul.LC_TabContentBigger li {
5887: display: inline;
5888: border-right: solid 1px $lg_border_color;
5889: float:left;
5890: line-height:140%;
5891: white-space:nowrap;
5892: }
5893:
5894: ol#LC_TabMainMenuContent li {
5895: vertical-align: bottom;
5896: border-bottom: solid 1px RGB(175, 175, 175);
5897: padding: 5px 10px 5px 10px;
5898: margin-right:5px;
5899: margin-bottom:3px;
5900: font-weight: bold;
5901: background: url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
5902: }
5903:
5904: ol#LC_TabMainMenuContent li a {
5905: color: RGB(47, 47, 47);
5906: text-decoration: none;
5907: }
5908:
5909: ul.LC_TabContent {
5910: min-height:1.6em;
5911: }
5912:
5913: ul.LC_TabContent li {
5914: vertical-align:middle;
5915: padding:0px 10px 0px 10px;
5916: background-color:$tabbg;
5917: border-bottom:solid 1px $lg_border_color;
5918: }
5919:
5920: ul.LC_TabContent li a, ul.LC_TabContent li {
5921: color:rgb(47,47,47);
5922: text-decoration:none;
5923: font-size:95%;
5924: font-weight:bold;
5925: padding-right: 16px;
5926: }
5927:
5928: ul.LC_TabContent li:hover, ul.LC_TabContent li.active {
5929: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
5930: border-bottom:solid 1px #FFFFFF;
5931: padding-right: 16px;
5932: }
5933:
5934: ul.LC_TabContentBigger li {
5935: vertical-align:bottom;
5936: border-top:solid 1px $lg_border_color;
5937: border-left:solid 1px $lg_border_color;
5938: padding:5px 10px 5px 10px;
5939: margin-left:2px;
5940: background:url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
5941: }
5942:
5943: ul.LC_TabContentBigger li:hover,
5944: ul.LC_TabContentBigger li.active {
5945: background:url(/adm/lonIcons/lightGreyBG.png) repeat-x right bottom;
5946: }
5947:
5948: ul.LC_TabContentBigger li,
5949: ul.LC_TabContentBigger li a {
5950: font-size:110%;
5951: font-weight:bold;
5952: }
5953:
5954: ol#LC_MenuBreadcrumbs,
5955: ol#LC_PathBreadcrumbs,
5956: ul.LC_CourseBreadcrumbs {
5957: border-top: solid 1px RGB(255, 255, 255);
5958: height: 20px;
5959: line-height: 20px;
5960: vertical-align: bottom;
5961: margin: 0px 0px 30px 0px;
5962: padding-left: 10px;
5963: list-style-position: inside;
5964: background: url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
5965: }
5966:
5967: ol#LC_MenuBreadcrumbs li,
5968: ol#LC_PathBreadcrumbs li,
5969: ul.LC_CourseBreadcrumbs li {
5970: /*
5971: background: url(/adm/lonIcons/arrow_white.png) no-repeat left center;
5972: */
5973: display: inline;
5974: padding: 0px 0px 0px 10px;
5975: /* vertical-align: bottom; */
5976: overflow:hidden;
5977: }
5978:
5979: ol#LC_MenuBreadcrumbs li a, ul.LC_CourseBreadcrumbs li a {
5980: text-decoration: none;
5981: font-size:90%;
5982: }
5983:
5984: ol#LC_PathBreadcrumbs li a {
5985: text-decoration:none;
5986: font-size:100%;
5987: font-weight:bold;
5988: }
5989:
5990: .LC_BoxPadding {
5991: padding: 10px;
5992: }
5993:
5994: .LC_ContentBoxSpecial {
5995: border: solid 1px $lg_border_color;
5996: }
5997:
5998: .LC_ContentBoxSpecialContactInfo {
5999: border: solid 1px $lg_border_color;
6000: max-width:25%;
6001: min-width:25%;
6002: }
6003:
6004: .LC_AboutMe_Image {
6005: float:left;
6006: margin-right:10px;
6007: }
6008:
6009: .LC_Clear_AboutMe_Image {
6010: clear:left;
6011: }
6012:
6013: dl.LC_ListStyleClean dt {
6014: padding-right: 5px;
6015: display: table-header-group;
6016: }
6017:
6018: dl.LC_ListStyleClean dd {
6019: display: table-row;
6020: }
6021:
6022: .LC_ListStyleClean,
6023: .LC_ListStyleSimple,
6024: .LC_ListStyleNormal,
6025: .LC_ListStyle_Border,
6026: .LC_ListStyleSpecial {
6027: /*display:block; */
6028: list-style-position: inside;
6029: list-style-type: none;
6030: overflow: hidden;
6031: padding: 0px;
6032: }
6033:
6034: .LC_ListStyleSimple li,
6035: .LC_ListStyleSimple dd,
6036: .LC_ListStyleNormal li,
6037: .LC_ListStyleNormal dd,
6038: .LC_ListStyleSpecial li,
6039: .LC_ListStyleSpecial dd {
6040: margin: 0px;
6041: padding: 5px 5px 5px 10px;
6042: clear: both;
6043: }
6044:
6045: .LC_ListStyleClean li,
6046: .LC_ListStyleClean dd {
6047: padding-top: 0px;
6048: padding-bottom: 0px;
6049: }
6050:
6051: .LC_ListStyleSimple dd,
6052: .LC_ListStyleSimple li {
6053: border-bottom: solid 1px $lg_border_color;
6054: }
6055:
6056: .LC_ListStyleSpecial li,
6057: .LC_ListStyleSpecial dd {
6058: list-style-type: none;
6059: background-color: RGB(220, 220, 220);
6060: margin-bottom: 4px;
6061: }
6062:
6063: table.LC_SimpleTable {
6064: margin:5px;
6065: border:solid 1px $lg_border_color;
6066: }
6067:
6068: table.LC_SimpleTable tr {
6069: padding:0px;
6070: border:solid 1px $lg_border_color;
6071: }
6072:
6073: table.LC_SimpleTable thead {
6074: background:rgb(220,220,220);
6075: }
6076:
6077: div.LC_columnSection {
6078: display: block;
6079: clear: both;
6080: overflow: hidden;
6081: margin:0px;
6082: }
6083:
6084: div.LC_columnSection>* {
6085: float: left;
6086: margin: 10px 20px 10px 0px;
6087: overflow:hidden;
6088: }
6089:
6090: .ContentBoxSpecialTemplate {
6091: border: solid 1px $lg_border_color;
6092: }
6093:
6094: .ContentBoxTemplate {
6095: padding:10px;
6096: }
6097:
6098: div.LC_columnSection > .ContentBoxTemplate,
6099: div.LC_columnSection > .ContentBoxSpecialTemplate {
6100: width: 600px;
6101: }
6102:
6103: .clear {
6104: clear: both;
6105: line-height: 0px;
6106: font-size: 0px;
6107: height: 0px;
6108: }
6109:
6110: .LC_loginpage_container {
6111: text-align:left;
6112: margin : 0 auto;
6113: width:90%;
6114: padding: 10px;
6115: height: auto;
6116: background-color:#FFFFFF;
6117: border:1px solid #CCCCCC;
6118: }
6119:
6120:
6121: .LC_loginpage_loginContainer {
6122: float:left;
6123: width: 182px;
6124: padding: 2px;
6125: border:1px solid #CCCCCC;
6126: background-color:$loginbg;
6127: }
6128:
6129: .LC_loginpage_loginContainer h2 {
6130: margin-top:0;
6131: display:block;
6132: background:$bgcol;
6133: color:$textcol;
6134: padding-left:5px;
6135: }
6136:
6137: .LC_loginpage_loginInfo {
6138: float:left;
6139: width:182px;
6140: border:1px solid #CCCCCC;
6141: padding:2px;
6142: }
6143:
6144: .LC_loginpage_space {
6145: clear: both;
6146: margin-bottom: 20px;
6147: border-bottom: 1px solid #CCCCCC;
6148: }
6149:
6150: .LC_loginpage_floatLeft {
6151: float: left;
6152: width: 200px;
6153: margin: 0;
6154: }
6155:
6156: table em {
6157: font-weight: bold;
6158: font-style: normal;
6159: }
6160:
6161: table.LC_tableBrowseRes,
6162: table.LC_tableOfContent {
6163: border:none;
6164: border-spacing: 1;
6165: padding: 3px;
6166: background-color: #FFFFFF;
6167: font-size: 90%;
6168: }
6169:
6170: table.LC_tableOfContent{
6171: border-collapse: collapse;
6172: }
6173:
6174: table.LC_tableBrowseRes a,
6175: table.LC_tableOfContent a {
6176: background-color: transparent;
6177: text-decoration: none;
6178: }
6179:
6180: table.LC_tableBrowseRes tr.LC_trOdd,
6181: table.LC_tableOfContent tr.LC_trOdd{
6182: background-color: #EEEEEE;
6183: }
6184:
6185: table.LC_tableOfContent img {
6186: border: none;
6187: height: 1.3em;
6188: vertical-align: text-bottom;
6189: margin-right: 0.3em;
6190: }
6191:
6192: a#LC_content_toolbar_firsthomework {
6193: background-image:url(/res/adm/pages/open-first-problem.gif);
6194: }
6195:
6196: a#LC_content_toolbar_launchnav {
6197: background-image:url(/res/adm/pages/start-navigation.gif);
6198: }
6199:
6200: a#LC_content_toolbar_closenav {
6201: background-image:url(/res/adm/pages/close-navigation.gif);
6202: }
6203:
6204: a#LC_content_toolbar_everything {
6205: background-image:url(/res/adm/pages/show-all.gif);
6206: }
6207:
6208: a#LC_content_toolbar_uncompleted {
6209: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
6210: }
6211:
6212: #LC_content_toolbar_clearbubbles {
6213: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
6214: }
6215:
6216: a#LC_content_toolbar_changefolder {
6217: background : url(/res/adm/pages/close-all-folders.gif) top center ;
6218: }
6219:
6220: a#LC_content_toolbar_changefolder_toggled {
6221: background-image:url(/res/adm/pages/open-all-folders.gif);
6222: }
6223:
6224: ul#LC_toolbar li a:hover {
6225: background-position: bottom center;
6226: }
6227:
6228: ul#LC_toolbar {
6229: padding:0;
6230: margin: 2px;
6231: list-style:none;
6232: position:relative;
6233: background-color:white;
6234: }
6235:
6236: ul#LC_toolbar li {
6237: border:1px solid white;
6238: padding:0;
6239: margin: 0;
6240: float: left;
6241: display:inline;
6242: vertical-align:middle;
6243: }
6244:
6245:
6246: a.LC_toolbarItem {
6247: display:block;
6248: padding:0;
6249: margin:0;
6250: height: 32px;
6251: width: 32px;
6252: color:white;
6253: border:0 none;
6254: background-repeat:no-repeat;
6255: background-color:transparent;
6256: }
6257:
6258: ul.LC_functionslist li {
6259: float: left;
6260: white-space: nowrap;
6261: height: 35px; /* at least as high as heighest list item */
6262: margin: 0px 15px 15px 10px;
6263: }
6264:
6265:
6266: END
6267: }
6268:
6269: =pod
6270:
6271: =item * &headtag()
6272:
6273: Returns a uniform footer for LON-CAPA web pages.
6274:
6275: Inputs: $title - optional title for the head
6276: $head_extra - optional extra HTML to put inside the <head>
6277: $args - optional arguments
6278: force_register - if is true call registerurl so the remote is
6279: informed
6280: redirect -> array ref of
6281: 1- seconds before redirect occurs
6282: 2- url to redirect to
6283: 3- whether the side effect should occur
6284: (side effect of setting
6285: $env{'internal.head.redirect'} to the url
6286: redirected too)
6287: domain -> force to color decorate a page for a specific
6288: domain
6289: function -> force usage of a specific rolish color scheme
6290: bgcolor -> override the default page bgcolor
6291: no_auto_mt_title
6292: -> prevent &mt()ing the title arg
6293:
6294: =cut
6295:
6296: sub headtag {
6297: my ($title,$head_extra,$args) = @_;
6298:
6299: my $function = $args->{'function'} || &get_users_function();
6300: my $domain = $args->{'domain'} || &determinedomain();
6301: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
6302: my $url = join(':',$env{'user.name'},$env{'user.domain'},
6303: $Apache::lonnet::perlvar{'lonVersion'},
6304: #time(),
6305: $env{'environment.color.timestamp'},
6306: $function,$domain,$bgcolor);
6307:
6308: $url = '/adm/css/'.&escape($url).'.css';
6309:
6310: my $result =
6311: '<head>'.
6312: &font_settings();
6313:
6314: if (!$args->{'frameset'}) {
6315: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
6316: }
6317: if ($args->{'force_register'}) {
6318: $result .= &Apache::lonmenu::registerurl(1);
6319: }
6320: if (!$args->{'no_nav_bar'}
6321: && !$args->{'only_body'}
6322: && !$args->{'frameset'}) {
6323: $result .= &help_menu_js();
6324: }
6325:
6326: if (ref($args->{'redirect'})) {
6327: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
6328: $url = &Apache::lonenc::check_encrypt($url);
6329: if (!$inhibit_continue) {
6330: $env{'internal.head.redirect'} = $url;
6331: }
6332: $result.=<<ADDMETA
6333: <meta http-equiv="pragma" content="no-cache" />
6334: <meta http-equiv="Refresh" content="$time; url=$url" />
6335: ADDMETA
6336: }
6337: if (!defined($title)) {
6338: $title = 'The LearningOnline Network with CAPA';
6339: }
6340: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
6341: $result .= '<title> LON-CAPA '.$title.'</title>'
6342: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
6343: .$head_extra;
6344: return $result;
6345: }
6346:
6347: =pod
6348:
6349: =item * &font_settings()
6350:
6351: Returns neccessary <meta> to set the proper encoding
6352:
6353: Inputs: none
6354:
6355: =cut
6356:
6357: sub font_settings {
6358: my $headerstring='';
6359: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
6360: $headerstring.=
6361: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
6362: }
6363: return $headerstring;
6364: }
6365:
6366: =pod
6367:
6368: =item * &xml_begin()
6369:
6370: Returns the needed doctype and <html>
6371:
6372: Inputs: none
6373:
6374: =cut
6375:
6376: sub xml_begin {
6377: my $output='';
6378:
6379: if ($env{'internal.start_page'}==1) {
6380: &Apache::lonhtmlcommon::init_htmlareafields();
6381: }
6382:
6383: if ($env{'browser.mathml'}) {
6384: $output='<?xml version="1.0"?>'
6385: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
6386: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
6387:
6388: # .'<!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">] >'
6389: .'<!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">'
6390: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
6391: .'xmlns="http://www.w3.org/1999/xhtml">';
6392: } else {
6393: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>';
6394: }
6395: return $output;
6396: }
6397:
6398: =pod
6399:
6400: =item * &endheadtag()
6401:
6402: Returns a uniform </head> for LON-CAPA web pages.
6403:
6404: Inputs: none
6405:
6406: =cut
6407:
6408: sub endheadtag {
6409: return '</head>';
6410: }
6411:
6412: =pod
6413:
6414: =item * &head()
6415:
6416: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
6417:
6418: Inputs:
6419:
6420: =over 4
6421:
6422: $title - optional title for the page
6423:
6424: $head_extra - optional extra HTML to put inside the <head>
6425:
6426: =back
6427:
6428: =cut
6429:
6430: sub head {
6431: my ($title,$head_extra,$args) = @_;
6432: return &headtag($title,$head_extra,$args).&endheadtag();
6433: }
6434:
6435: =pod
6436:
6437: =item * &start_page()
6438:
6439: Returns a complete <html> .. <body> 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 incude inside the <head>
6448:
6449: $args - additional optional args supported are:
6450:
6451: =over 8
6452:
6453: only_body -> is true will set &bodytag() onlybodytag
6454: arg on
6455: no_nav_bar -> is true will set &bodytag() notopbar arg on
6456: add_entries -> additional attributes to add to the <body>
6457: domain -> force to color decorate a page for a
6458: specific domain
6459: function -> force usage of a specific rolish color
6460: scheme
6461: redirect -> see &headtag()
6462: bgcolor -> override the default page bg color
6463: js_ready -> return a string ready for being used in
6464: a javascript writeln
6465: html_encode -> return a string ready for being used in
6466: a html attribute
6467: force_register -> if is true will turn on the &bodytag()
6468: $forcereg arg
6469: body_title -> alternate text to use instead of $title
6470: in the title box that appears, this text
6471: is not auto translated like the $title is
6472: frameset -> if true will start with a <frameset>
6473: rather than <body>
6474: no_title -> if true the title bar won't be shown
6475: skip_phases -> hash ref of
6476: head -> skip the <html><head> generation
6477: body -> skip all <body> generation
6478: no_inline_link -> if true and in remote mode, don't show the
6479: 'Switch To Inline Menu' link
6480: no_auto_mt_title -> prevent &mt()ing the title arg
6481: inherit_jsmath -> when creating popup window in a page,
6482: should it have jsmath forced on by the
6483: current page
6484:
6485: =back
6486:
6487: =back
6488:
6489: =cut
6490:
6491: sub start_page {
6492: my ($title,$head_extra,$args) = @_;
6493: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
6494: my %head_args;
6495: foreach my $arg ('redirect','force_register','domain','function',
6496: 'bgcolor','frameset','no_nav_bar','only_body',
6497: 'no_auto_mt_title') {
6498: if (defined($args->{$arg})) {
6499: $head_args{$arg} = $args->{$arg};
6500: }
6501: }
6502:
6503: $env{'internal.start_page'}++;
6504: my $result;
6505: if (! exists($args->{'skip_phases'}{'head'}) ) {
6506: $result.=
6507: &xml_begin().
6508: &headtag($title,$head_extra,\%head_args).&endheadtag();
6509: }
6510:
6511: if (! exists($args->{'skip_phases'}{'body'}) ) {
6512: if ($args->{'frameset'}) {
6513: my $attr_string = &make_attr_string($args->{'force_register'},
6514: $args->{'add_entries'});
6515: $result .= "\n<frameset $attr_string>\n";
6516: } else {
6517: $result .=
6518: &bodytag($title,
6519: $args->{'function'}, $args->{'add_entries'},
6520: $args->{'only_body'}, $args->{'domain'},
6521: $args->{'force_register'}, $args->{'body_title'},
6522: $args->{'no_nav_bar'}, $args->{'bgcolor'},
6523: $args->{'no_title'}, $args->{'no_inline_link'},
6524: $args);
6525: }
6526: }
6527:
6528: if ($args->{'js_ready'}) {
6529: $result = &js_ready($result);
6530: }
6531: if ($args->{'html_encode'}) {
6532: $result = &html_encode($result);
6533: }
6534:
6535: #Breadcrumbs
6536: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
6537: &Apache::lonhtmlcommon::clear_breadcrumbs();
6538: #if any br links exists, add them to the breadcrumbs
6539: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
6540: foreach my $crumb (@{$args->{'bread_crumbs'}}){
6541: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
6542: }
6543: }
6544:
6545: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
6546: if(exists($args->{'bread_crumbs_component'})){
6547: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
6548: }else{
6549: $result .= &Apache::lonhtmlcommon::breadcrumbs();
6550: }
6551: }
6552: return $result;
6553: }
6554:
6555:
6556: =pod
6557:
6558: =item * &head()
6559:
6560: Returns a complete </body></html> section for LON-CAPA web pages.
6561:
6562: Inputs: $args - additional optional args supported are:
6563: js_ready -> return a string ready for being used in
6564: a javascript writeln
6565: html_encode -> return a string ready for being used in
6566: a html attribute
6567: frameset -> if true will start with a <frameset>
6568: rather than <body>
6569: dicsussion -> if true will get discussion from
6570: lonxml::xmlend
6571: (you can pass the target and parser arguments
6572: through optional 'target' and 'parser' args
6573: to this routine)
6574:
6575: =cut
6576:
6577: sub end_page {
6578: my ($args) = @_;
6579: $env{'internal.end_page'}++;
6580: my $result;
6581: if ($args->{'discussion'}) {
6582: my ($target,$parser);
6583: if (ref($args->{'discussion'})) {
6584: ($target,$parser) =($args->{'discussion'}{'target'},
6585: $args->{'discussion'}{'parser'});
6586: }
6587: $result .= &Apache::lonxml::xmlend($target,$parser);
6588: }
6589:
6590: if ($args->{'frameset'}) {
6591: $result .= '</frameset>';
6592: } else {
6593: $result .= &endbodytag($args);
6594: }
6595: $result .= "\n</html>";
6596:
6597: if ($args->{'js_ready'}) {
6598: $result = &js_ready($result);
6599: }
6600:
6601: if ($args->{'html_encode'}) {
6602: $result = &html_encode($result);
6603: }
6604:
6605: return $result;
6606: }
6607:
6608: sub html_encode {
6609: my ($result) = @_;
6610:
6611: $result = &HTML::Entities::encode($result,'<>&"');
6612:
6613: return $result;
6614: }
6615: sub js_ready {
6616: my ($result) = @_;
6617:
6618: $result =~ s/[\n\r]/ /xmsg;
6619: $result =~ s/\\/\\\\/xmsg;
6620: $result =~ s/'/\\'/xmsg;
6621: $result =~ s{</}{<\\/}xmsg;
6622:
6623: return $result;
6624: }
6625:
6626: sub validate_page {
6627: if ( exists($env{'internal.start_page'})
6628: && $env{'internal.start_page'} > 1) {
6629: &Apache::lonnet::logthis('start_page called multiple times '.
6630: $env{'internal.start_page'}.' '.
6631: $ENV{'request.filename'});
6632: }
6633: if ( exists($env{'internal.end_page'})
6634: && $env{'internal.end_page'} > 1) {
6635: &Apache::lonnet::logthis('end_page called multiple times '.
6636: $env{'internal.end_page'}.' '.
6637: $env{'request.filename'});
6638: }
6639: if ( exists($env{'internal.start_page'})
6640: && ! exists($env{'internal.end_page'})) {
6641: &Apache::lonnet::logthis('start_page called without end_page '.
6642: $env{'request.filename'});
6643: }
6644: if ( ! exists($env{'internal.start_page'})
6645: && exists($env{'internal.end_page'})) {
6646: &Apache::lonnet::logthis('end_page called without start_page'.
6647: $env{'request.filename'});
6648: }
6649: }
6650:
6651: sub simple_error_page {
6652: my ($r,$title,$msg) = @_;
6653: my $page =
6654: &Apache::loncommon::start_page($title).
6655: &mt($msg).
6656: &Apache::loncommon::end_page();
6657: if (ref($r)) {
6658: $r->print($page);
6659: return;
6660: }
6661: return $page;
6662: }
6663:
6664: {
6665: my @row_count;
6666: sub start_data_table {
6667: my ($add_class) = @_;
6668: my $css_class = (join(' ','LC_data_table',$add_class));
6669: unshift(@row_count,0);
6670: return '<table class="'.$css_class.'">'."\n";
6671: }
6672:
6673: sub end_data_table {
6674: shift(@row_count);
6675: return '</table>'."\n";;
6676: }
6677:
6678: sub start_data_table_row {
6679: my ($add_class) = @_;
6680: $row_count[0]++;
6681: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
6682: $css_class = (join(' ',$css_class,$add_class));
6683: return '<tr class="'.$css_class.'">'."\n";;
6684: }
6685:
6686: sub continue_data_table_row {
6687: my ($add_class) = @_;
6688: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
6689: $css_class = (join(' ',$css_class,$add_class));
6690: return '<tr class="'.$css_class.'">'."\n";;
6691: }
6692:
6693: sub end_data_table_row {
6694: return '</tr>'."\n";;
6695: }
6696:
6697: sub start_data_table_empty_row {
6698: # $row_count[0]++;
6699: return '<tr class="LC_empty_row" >'."\n";;
6700: }
6701:
6702: sub end_data_table_empty_row {
6703: return '</tr>'."\n";;
6704: }
6705:
6706: sub start_data_table_header_row {
6707: return '<tr class="LC_header_row">'."\n";;
6708: }
6709:
6710: sub end_data_table_header_row {
6711: return '</tr>'."\n";;
6712: }
6713: }
6714:
6715: =pod
6716:
6717: =item * &inhibit_menu_check($arg)
6718:
6719: Checks for a inhibitmenu state and generates output to preserve it
6720:
6721: Inputs: $arg - can be any of
6722: - undef - in which case the return value is a string
6723: to add into arguments list of a uri
6724: - 'input' - in which case the return value is a HTML
6725: <form> <input> field of type hidden to
6726: preserve the value
6727: - a url - in which case the return value is the url with
6728: the neccesary cgi args added to preserve the
6729: inhibitmenu state
6730: - a ref to a url - no return value, but the string is
6731: updated to include the neccessary cgi
6732: args to preserve the inhibitmenu state
6733:
6734: =cut
6735:
6736: sub inhibit_menu_check {
6737: my ($arg) = @_;
6738: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6739: if ($arg eq 'input') {
6740: if ($env{'form.inhibitmenu'}) {
6741: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
6742: } else {
6743: return
6744: }
6745: }
6746: if ($env{'form.inhibitmenu'}) {
6747: if (ref($arg)) {
6748: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6749: } elsif ($arg eq '') {
6750: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
6751: } else {
6752: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6753: }
6754: }
6755: if (!ref($arg)) {
6756: return $arg;
6757: }
6758: }
6759:
6760: ###############################################
6761:
6762: =pod
6763:
6764: =back
6765:
6766: =head1 User Information Routines
6767:
6768: =over 4
6769:
6770: =item * &get_users_function()
6771:
6772: Used by &bodytag to determine the current users primary role.
6773: Returns either 'student','coordinator','admin', or 'author'.
6774:
6775: =cut
6776:
6777: ###############################################
6778: sub get_users_function {
6779: my $function = 'student';
6780: if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
6781: $function='coordinator';
6782: }
6783: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
6784: $function='admin';
6785: }
6786: if (($env{'request.role'}=~/^(au|ca)/) ||
6787: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
6788: $function='author';
6789: }
6790: return $function;
6791: }
6792:
6793: ###############################################
6794:
6795: =pod
6796:
6797: =item * &check_user_status()
6798:
6799: Determines current status of supplied role for a
6800: specific user. Roles can be active, previous or future.
6801:
6802: Inputs:
6803: user's domain, user's username, course's domain,
6804: course's number, optional section ID.
6805:
6806: Outputs:
6807: role status: active, previous or future.
6808:
6809: =cut
6810:
6811: sub check_user_status {
6812: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
6813: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
6814: my @uroles = keys %userinfo;
6815: my $srchstr;
6816: my $active_chk = 'none';
6817: my $now = time;
6818: if (@uroles > 0) {
6819: if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
6820: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
6821: } else {
6822: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
6823: }
6824: if (grep/^\Q$srchstr\E$/,@uroles) {
6825: my $role_end = 0;
6826: my $role_start = 0;
6827: $active_chk = 'active';
6828: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
6829: $role_end = $1;
6830: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
6831: $role_start = $1;
6832: }
6833: }
6834: if ($role_start > 0) {
6835: if ($now < $role_start) {
6836: $active_chk = 'future';
6837: }
6838: }
6839: if ($role_end > 0) {
6840: if ($now > $role_end) {
6841: $active_chk = 'previous';
6842: }
6843: }
6844: }
6845: }
6846: return $active_chk;
6847: }
6848:
6849: ###############################################
6850:
6851: =pod
6852:
6853: =item * &get_sections()
6854:
6855: Determines all the sections for a course including
6856: sections with students and sections containing other roles.
6857: Incoming parameters:
6858:
6859: 1. domain
6860: 2. course number
6861: 3. reference to array containing roles for which sections should
6862: be gathered (optional).
6863: 4. reference to array containing status types for which sections
6864: should be gathered (optional).
6865:
6866: If the third argument is undefined, sections are gathered for any role.
6867: If the fourth argument is undefined, sections are gathered for any status.
6868: Permissible values are 'active' or 'future' or 'previous'.
6869:
6870: Returns section hash (keys are section IDs, values are
6871: number of users in each section), subject to the
6872: optional roles filter, optional status filter
6873:
6874: =cut
6875:
6876: ###############################################
6877: sub get_sections {
6878: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
6879: if (!defined($cdom) || !defined($cnum)) {
6880: my $cid = $env{'request.course.id'};
6881:
6882: return if (!defined($cid));
6883:
6884: $cdom = $env{'course.'.$cid.'.domain'};
6885: $cnum = $env{'course.'.$cid.'.num'};
6886: }
6887:
6888: my %sectioncount;
6889: my $now = time;
6890:
6891: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
6892: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
6893: my $sec_index = &Apache::loncoursedata::CL_SECTION();
6894: my $status_index = &Apache::loncoursedata::CL_STATUS();
6895: my $start_index = &Apache::loncoursedata::CL_START();
6896: my $end_index = &Apache::loncoursedata::CL_END();
6897: my $status;
6898: while (my ($student,$data) = each(%$classlist)) {
6899: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
6900: $data->[$status_index],
6901: $data->[$start_index],
6902: $data->[$end_index]);
6903: if ($stu_status eq 'Active') {
6904: $status = 'active';
6905: } elsif ($end < $now) {
6906: $status = 'previous';
6907: } elsif ($start > $now) {
6908: $status = 'future';
6909: }
6910: if ($section ne '-1' && $section !~ /^\s*$/) {
6911: if ((!defined($possible_status)) || (($status ne '') &&
6912: (grep/^\Q$status\E$/,@{$possible_status}))) {
6913: $sectioncount{$section}++;
6914: }
6915: }
6916: }
6917: }
6918: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6919: foreach my $user (sort(keys(%courseroles))) {
6920: if ($user !~ /^(\w{2})/) { next; }
6921: my ($role) = ($user =~ /^(\w{2})/);
6922: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
6923: my ($section,$status);
6924: if ($role eq 'cr' &&
6925: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
6926: $section=$1;
6927: }
6928: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
6929: if (!defined($section) || $section eq '-1') { next; }
6930: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
6931: if ($end == -1 && $start == -1) {
6932: next; #deleted role
6933: }
6934: if (!defined($possible_status)) {
6935: $sectioncount{$section}++;
6936: } else {
6937: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
6938: $status = 'active';
6939: } elsif ($end < $now) {
6940: $status = 'future';
6941: } elsif ($start > $now) {
6942: $status = 'previous';
6943: }
6944: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
6945: $sectioncount{$section}++;
6946: }
6947: }
6948: }
6949: return %sectioncount;
6950: }
6951:
6952: ###############################################
6953:
6954: =pod
6955:
6956: =item * &get_course_users()
6957:
6958: Retrieves usernames:domains for users in the specified course
6959: with specific role(s), and access status.
6960:
6961: Incoming parameters:
6962: 1. course domain
6963: 2. course number
6964: 3. access status: users must have - either active,
6965: previous, future, or all.
6966: 4. reference to array of permissible roles
6967: 5. reference to array of section restrictions (optional)
6968: 6. reference to results object (hash of hashes).
6969: 7. reference to optional userdata hash
6970: 8. reference to optional statushash
6971: 9. flag if privileged users (except those set to unhide in
6972: course settings) should be excluded
6973: Keys of top level results hash are roles.
6974: Keys of inner hashes are username:domain, with
6975: values set to access type.
6976: Optional userdata hash returns an array with arguments in the
6977: same order as loncoursedata::get_classlist() for student data.
6978:
6979: Optional statushash returns
6980:
6981: Entries for end, start, section and status are blank because
6982: of the possibility of multiple values for non-student roles.
6983:
6984: =cut
6985:
6986: ###############################################
6987:
6988: sub get_course_users {
6989: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
6990: my %idx = ();
6991: my %seclists;
6992:
6993: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
6994: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
6995: $idx{end} = &Apache::loncoursedata::CL_END();
6996: $idx{start} = &Apache::loncoursedata::CL_START();
6997: $idx{id} = &Apache::loncoursedata::CL_ID();
6998: $idx{section} = &Apache::loncoursedata::CL_SECTION();
6999: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
7000: $idx{status} = &Apache::loncoursedata::CL_STATUS();
7001:
7002: if (grep(/^st$/,@{$roles})) {
7003: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
7004: my $now = time;
7005: foreach my $student (keys(%{$classlist})) {
7006: my $match = 0;
7007: my $secmatch = 0;
7008: my $section = $$classlist{$student}[$idx{section}];
7009: my $status = $$classlist{$student}[$idx{status}];
7010: if ($section eq '') {
7011: $section = 'none';
7012: }
7013: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
7014: if (grep(/^all$/,@{$sections})) {
7015: $secmatch = 1;
7016: } elsif ($$classlist{$student}[$idx{section}] eq '') {
7017: if (grep(/^none$/,@{$sections})) {
7018: $secmatch = 1;
7019: }
7020: } else {
7021: if (grep(/^\Q$section\E$/,@{$sections})) {
7022: $secmatch = 1;
7023: }
7024: }
7025: if (!$secmatch) {
7026: next;
7027: }
7028: }
7029: if (defined($$types{'active'})) {
7030: if ($$classlist{$student}[$idx{status}] eq 'Active') {
7031: push(@{$$users{st}{$student}},'active');
7032: $match = 1;
7033: }
7034: }
7035: if (defined($$types{'previous'})) {
7036: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
7037: push(@{$$users{st}{$student}},'previous');
7038: $match = 1;
7039: }
7040: }
7041: if (defined($$types{'future'})) {
7042: if ($$classlist{$student}[$idx{status}] eq 'Future') {
7043: push(@{$$users{st}{$student}},'future');
7044: $match = 1;
7045: }
7046: }
7047: if ($match) {
7048: push(@{$seclists{$student}},$section);
7049: if (ref($userdata) eq 'HASH') {
7050: $$userdata{$student} = $$classlist{$student};
7051: }
7052: if (ref($statushash) eq 'HASH') {
7053: $statushash->{$student}{'st'}{$section} = $status;
7054: }
7055: }
7056: }
7057: }
7058: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
7059: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7060: my $now = time;
7061: my %displaystatus = ( previous => 'Expired',
7062: active => 'Active',
7063: future => 'Future',
7064: );
7065: my %nothide;
7066: if ($hidepriv) {
7067: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
7068: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
7069: if ($user !~ /:/) {
7070: $nothide{join(':',split(/[\@]/,$user))}=1;
7071: } else {
7072: $nothide{$user} = 1;
7073: }
7074: }
7075: }
7076: foreach my $person (sort(keys(%coursepersonnel))) {
7077: my $match = 0;
7078: my $secmatch = 0;
7079: my $status;
7080: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
7081: $user =~ s/:$//;
7082: my ($end,$start) = split(/:/,$coursepersonnel{$person});
7083: if ($end == -1 || $start == -1) {
7084: next;
7085: }
7086: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
7087: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
7088: my ($uname,$udom) = split(/:/,$user);
7089: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
7090: if (grep(/^all$/,@{$sections})) {
7091: $secmatch = 1;
7092: } elsif ($usec eq '') {
7093: if (grep(/^none$/,@{$sections})) {
7094: $secmatch = 1;
7095: }
7096: } else {
7097: if (grep(/^\Q$usec\E$/,@{$sections})) {
7098: $secmatch = 1;
7099: }
7100: }
7101: if (!$secmatch) {
7102: next;
7103: }
7104: }
7105: if ($usec eq '') {
7106: $usec = 'none';
7107: }
7108: if ($uname ne '' && $udom ne '') {
7109: if ($hidepriv) {
7110: if ((&Apache::lonnet::privileged($uname,$udom)) &&
7111: (!$nothide{$uname.':'.$udom})) {
7112: next;
7113: }
7114: }
7115: if ($end > 0 && $end < $now) {
7116: $status = 'previous';
7117: } elsif ($start > $now) {
7118: $status = 'future';
7119: } else {
7120: $status = 'active';
7121: }
7122: foreach my $type (keys(%{$types})) {
7123: if ($status eq $type) {
7124: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
7125: push(@{$$users{$role}{$user}},$type);
7126: }
7127: $match = 1;
7128: }
7129: }
7130: if (($match) && (ref($userdata) eq 'HASH')) {
7131: if (!exists($$userdata{$uname.':'.$udom})) {
7132: &get_user_info($udom,$uname,\%idx,$userdata);
7133: }
7134: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
7135: push(@{$seclists{$uname.':'.$udom}},$usec);
7136: }
7137: if (ref($statushash) eq 'HASH') {
7138: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
7139: }
7140: }
7141: }
7142: }
7143: }
7144: if (grep(/^ow$/,@{$roles})) {
7145: if ((defined($cdom)) && (defined($cnum))) {
7146: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
7147: if ( defined($csettings{'internal.courseowner'}) ) {
7148: my $owner = $csettings{'internal.courseowner'};
7149: next if ($owner eq '');
7150: my ($ownername,$ownerdom);
7151: if ($owner =~ /^([^:]+):([^:]+)$/) {
7152: $ownername = $1;
7153: $ownerdom = $2;
7154: } else {
7155: $ownername = $owner;
7156: $ownerdom = $cdom;
7157: $owner = $ownername.':'.$ownerdom;
7158: }
7159: @{$$users{'ow'}{$owner}} = 'any';
7160: if (defined($userdata) &&
7161: !exists($$userdata{$owner})) {
7162: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
7163: if (!grep(/^none$/,@{$seclists{$owner}})) {
7164: push(@{$seclists{$owner}},'none');
7165: }
7166: if (ref($statushash) eq 'HASH') {
7167: $statushash->{$owner}{'ow'}{'none'} = 'Any';
7168: }
7169: }
7170: }
7171: }
7172: }
7173: foreach my $user (keys(%seclists)) {
7174: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
7175: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
7176: }
7177: }
7178: return;
7179: }
7180:
7181: sub get_user_info {
7182: my ($udom,$uname,$idx,$userdata) = @_;
7183: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
7184: &plainname($uname,$udom,'lastname');
7185: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
7186: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
7187: my %idhash = &Apache::lonnet::idrget($udom,($uname));
7188: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
7189: return;
7190: }
7191:
7192: ###############################################
7193:
7194: =pod
7195:
7196: =item * &get_user_quota()
7197:
7198: Retrieves quota assigned for storage of portfolio files for a user
7199:
7200: Incoming parameters:
7201: 1. user's username
7202: 2. user's domain
7203:
7204: Returns:
7205: 1. Disk quota (in Mb) assigned to student.
7206: 2. (Optional) Type of setting: custom or default
7207: (individually assigned or default for user's
7208: institutional status).
7209: 3. (Optional) - User's institutional status (e.g., faculty, staff
7210: or student - types as defined in localenroll::inst_usertypes
7211: for user's domain, which determines default quota for user.
7212: 4. (Optional) - Default quota which would apply to the user.
7213:
7214: If a value has been stored in the user's environment,
7215: it will return that, otherwise it returns the maximal default
7216: defined for the user's instituional status(es) in the domain.
7217:
7218: =cut
7219:
7220: ###############################################
7221:
7222:
7223: sub get_user_quota {
7224: my ($uname,$udom) = @_;
7225: my ($quota,$quotatype,$settingstatus,$defquota);
7226: if (!defined($udom)) {
7227: $udom = $env{'user.domain'};
7228: }
7229: if (!defined($uname)) {
7230: $uname = $env{'user.name'};
7231: }
7232: if (($udom eq '' || $uname eq '') ||
7233: ($udom eq 'public') && ($uname eq 'public')) {
7234: $quota = 0;
7235: $quotatype = 'default';
7236: $defquota = 0;
7237: } else {
7238: my $inststatus;
7239: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
7240: $quota = $env{'environment.portfolioquota'};
7241: $inststatus = $env{'environment.inststatus'};
7242: } else {
7243: my %userenv =
7244: &Apache::lonnet::get('environment',['portfolioquota',
7245: 'inststatus'],$udom,$uname);
7246: my ($tmp) = keys(%userenv);
7247: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
7248: $quota = $userenv{'portfolioquota'};
7249: $inststatus = $userenv{'inststatus'};
7250: } else {
7251: undef(%userenv);
7252: }
7253: }
7254: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
7255: if ($quota eq '') {
7256: $quota = $defquota;
7257: $quotatype = 'default';
7258: } else {
7259: $quotatype = 'custom';
7260: }
7261: }
7262: if (wantarray) {
7263: return ($quota,$quotatype,$settingstatus,$defquota);
7264: } else {
7265: return $quota;
7266: }
7267: }
7268:
7269: ###############################################
7270:
7271: =pod
7272:
7273: =item * &default_quota()
7274:
7275: Retrieves default quota assigned for storage of user portfolio files,
7276: given an (optional) user's institutional status.
7277:
7278: Incoming parameters:
7279: 1. domain
7280: 2. (Optional) institutional status(es). This is a : separated list of
7281: status types (e.g., faculty, staff, student etc.)
7282: which apply to the user for whom the default is being retrieved.
7283: If the institutional status string in undefined, the domain
7284: default quota will be returned.
7285:
7286: Returns:
7287: 1. Default disk quota (in Mb) for user portfolios in the domain.
7288: 2. (Optional) institutional type which determined the value of the
7289: default quota.
7290:
7291: If a value has been stored in the domain's configuration db,
7292: it will return that, otherwise it returns 20 (for backwards
7293: compatibility with domains which have not set up a configuration
7294: db file; the original statically defined portfolio quota was 20 Mb).
7295:
7296: If the user's status includes multiple types (e.g., staff and student),
7297: the largest default quota which applies to the user determines the
7298: default quota returned.
7299:
7300: =back
7301:
7302: =cut
7303:
7304: ###############################################
7305:
7306:
7307: sub default_quota {
7308: my ($udom,$inststatus) = @_;
7309: my ($defquota,$settingstatus);
7310: my %quotahash = &Apache::lonnet::get_dom('configuration',
7311: ['quotas'],$udom);
7312: if (ref($quotahash{'quotas'}) eq 'HASH') {
7313: if ($inststatus ne '') {
7314: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
7315: foreach my $item (@statuses) {
7316: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7317: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
7318: if ($defquota eq '') {
7319: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7320: $settingstatus = $item;
7321: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
7322: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7323: $settingstatus = $item;
7324: }
7325: }
7326: } else {
7327: if ($quotahash{'quotas'}{$item} ne '') {
7328: if ($defquota eq '') {
7329: $defquota = $quotahash{'quotas'}{$item};
7330: $settingstatus = $item;
7331: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
7332: $defquota = $quotahash{'quotas'}{$item};
7333: $settingstatus = $item;
7334: }
7335: }
7336: }
7337: }
7338: }
7339: if ($defquota eq '') {
7340: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7341: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
7342: } else {
7343: $defquota = $quotahash{'quotas'}{'default'};
7344: }
7345: $settingstatus = 'default';
7346: }
7347: } else {
7348: $settingstatus = 'default';
7349: $defquota = 20;
7350: }
7351: if (wantarray) {
7352: return ($defquota,$settingstatus);
7353: } else {
7354: return $defquota;
7355: }
7356: }
7357:
7358: sub get_secgrprole_info {
7359: my ($cdom,$cnum,$needroles,$type) = @_;
7360: my %sections_count = &get_sections($cdom,$cnum);
7361: my @sections = (sort {$a <=> $b} keys(%sections_count));
7362: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
7363: my @groups = sort(keys(%curr_groups));
7364: my $allroles = [];
7365: my $rolehash;
7366: my $accesshash = {
7367: active => 'Currently has access',
7368: future => 'Will have future access',
7369: previous => 'Previously had access',
7370: };
7371: if ($needroles) {
7372: $rolehash = {'all' => 'all'};
7373: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7374: if (&Apache::lonnet::error(%user_roles)) {
7375: undef(%user_roles);
7376: }
7377: foreach my $item (keys(%user_roles)) {
7378: my ($role)=split(/\:/,$item,2);
7379: if ($role eq 'cr') { next; }
7380: if ($role =~ /^cr/) {
7381: $$rolehash{$role} = (split('/',$role))[3];
7382: } else {
7383: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
7384: }
7385: }
7386: foreach my $key (sort(keys(%{$rolehash}))) {
7387: push(@{$allroles},$key);
7388: }
7389: push (@{$allroles},'st');
7390: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
7391: }
7392: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
7393: }
7394:
7395: sub user_picker {
7396: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
7397: my $currdom = $dom;
7398: my %curr_selected = (
7399: srchin => 'dom',
7400: srchby => 'lastname',
7401: );
7402: my $srchterm;
7403: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
7404: if ($srch->{'srchby'} ne '') {
7405: $curr_selected{'srchby'} = $srch->{'srchby'};
7406: }
7407: if ($srch->{'srchin'} ne '') {
7408: $curr_selected{'srchin'} = $srch->{'srchin'};
7409: }
7410: if ($srch->{'srchtype'} ne '') {
7411: $curr_selected{'srchtype'} = $srch->{'srchtype'};
7412: }
7413: if ($srch->{'srchdomain'} ne '') {
7414: $currdom = $srch->{'srchdomain'};
7415: }
7416: $srchterm = $srch->{'srchterm'};
7417: }
7418: my %lt=&Apache::lonlocal::texthash(
7419: 'usr' => 'Search criteria',
7420: 'doma' => 'Domain/institution to search',
7421: 'uname' => 'username',
7422: 'lastname' => 'last name',
7423: 'lastfirst' => 'last name, first name',
7424: 'crs' => 'in this course',
7425: 'dom' => 'in selected LON-CAPA domain',
7426: 'alc' => 'all LON-CAPA',
7427: 'instd' => 'in institutional directory for selected domain',
7428: 'exact' => 'is',
7429: 'contains' => 'contains',
7430: 'begins' => 'begins with',
7431: 'youm' => "You must include some text to search for.",
7432: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
7433: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
7434: 'yomc' => "You must choose a domain when using an institutional directory search.",
7435: 'ymcd' => "You must choose a domain when using a domain search.",
7436: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
7437: 'whse' => "When searching by last,first you must include at least one character in the first name.",
7438: 'thfo' => "The following need to be corrected before the search can be run:",
7439: );
7440: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
7441: my $srchinsel = ' <select name="srchin">';
7442:
7443: my @srchins = ('crs','dom','alc','instd');
7444:
7445: foreach my $option (@srchins) {
7446: # FIXME 'alc' option unavailable until
7447: # loncreateuser::print_user_query_page()
7448: # has been completed.
7449: next if ($option eq 'alc');
7450: next if ($option eq 'crs' && !$env{'request.course.id'});
7451: if ($curr_selected{'srchin'} eq $option) {
7452: $srchinsel .= '
7453: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7454: } else {
7455: $srchinsel .= '
7456: <option value="'.$option.'">'.$lt{$option}.'</option>';
7457: }
7458: }
7459: $srchinsel .= "\n </select>\n";
7460:
7461: my $srchbysel = ' <select name="srchby">';
7462: foreach my $option ('lastname','lastfirst','uname') {
7463: if ($curr_selected{'srchby'} eq $option) {
7464: $srchbysel .= '
7465: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7466: } else {
7467: $srchbysel .= '
7468: <option value="'.$option.'">'.$lt{$option}.'</option>';
7469: }
7470: }
7471: $srchbysel .= "\n </select>\n";
7472:
7473: my $srchtypesel = ' <select name="srchtype">';
7474: foreach my $option ('begins','contains','exact') {
7475: if ($curr_selected{'srchtype'} eq $option) {
7476: $srchtypesel .= '
7477: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7478: } else {
7479: $srchtypesel .= '
7480: <option value="'.$option.'">'.$lt{$option}.'</option>';
7481: }
7482: }
7483: $srchtypesel .= "\n </select>\n";
7484:
7485: my ($newuserscript,$new_user_create);
7486:
7487: if ($forcenewuser) {
7488: if (ref($srch) eq 'HASH') {
7489: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
7490: if ($cancreate) {
7491: $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>';
7492: } else {
7493: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
7494: my %usertypetext = (
7495: official => 'institutional',
7496: unofficial => 'non-institutional',
7497: );
7498: $new_user_create = '<br /><span class="LC_warning">'.&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.").' '.&mt('Contact the <a[_1]>helpdesk</a> for assistance.',$helplink).'</span><br /><br />';
7499: }
7500: }
7501: }
7502:
7503: $newuserscript = <<"ENDSCRIPT";
7504:
7505: function setSearch(createnew,callingForm) {
7506: if (createnew == 1) {
7507: for (var i=0; i<callingForm.srchby.length; i++) {
7508: if (callingForm.srchby.options[i].value == 'uname') {
7509: callingForm.srchby.selectedIndex = i;
7510: }
7511: }
7512: for (var i=0; i<callingForm.srchin.length; i++) {
7513: if ( callingForm.srchin.options[i].value == 'dom') {
7514: callingForm.srchin.selectedIndex = i;
7515: }
7516: }
7517: for (var i=0; i<callingForm.srchtype.length; i++) {
7518: if (callingForm.srchtype.options[i].value == 'exact') {
7519: callingForm.srchtype.selectedIndex = i;
7520: }
7521: }
7522: for (var i=0; i<callingForm.srchdomain.length; i++) {
7523: if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
7524: callingForm.srchdomain.selectedIndex = i;
7525: }
7526: }
7527: }
7528: }
7529: ENDSCRIPT
7530:
7531: }
7532:
7533: my $output = <<"END_BLOCK";
7534: <script type="text/javascript">
7535: function validateEntry(callingForm) {
7536:
7537: var checkok = 1;
7538: var srchin;
7539: for (var i=0; i<callingForm.srchin.length; i++) {
7540: if ( callingForm.srchin[i].checked ) {
7541: srchin = callingForm.srchin[i].value;
7542: }
7543: }
7544:
7545: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
7546: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
7547: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
7548: var srchterm = callingForm.srchterm.value;
7549: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
7550: var msg = "";
7551:
7552: if (srchterm == "") {
7553: checkok = 0;
7554: msg += "$lt{'youm'}\\n";
7555: }
7556:
7557: if (srchtype== 'begins') {
7558: if (srchterm.length < 2) {
7559: checkok = 0;
7560: msg += "$lt{'thte'}\\n";
7561: }
7562: }
7563:
7564: if (srchtype== 'contains') {
7565: if (srchterm.length < 3) {
7566: checkok = 0;
7567: msg += "$lt{'thet'}\\n";
7568: }
7569: }
7570: if (srchin == 'instd') {
7571: if (srchdomain == '') {
7572: checkok = 0;
7573: msg += "$lt{'yomc'}\\n";
7574: }
7575: }
7576: if (srchin == 'dom') {
7577: if (srchdomain == '') {
7578: checkok = 0;
7579: msg += "$lt{'ymcd'}\\n";
7580: }
7581: }
7582: if (srchby == 'lastfirst') {
7583: if (srchterm.indexOf(",") == -1) {
7584: checkok = 0;
7585: msg += "$lt{'whus'}\\n";
7586: }
7587: if (srchterm.indexOf(",") == srchterm.length -1) {
7588: checkok = 0;
7589: msg += "$lt{'whse'}\\n";
7590: }
7591: }
7592: if (checkok == 0) {
7593: alert("$lt{'thfo'}\\n"+msg);
7594: return;
7595: }
7596: if (checkok == 1) {
7597: callingForm.submit();
7598: }
7599: }
7600:
7601: $newuserscript
7602:
7603: </script>
7604:
7605: $new_user_create
7606:
7607: <table>
7608: <tr>
7609: <td>$lt{'doma'}:</td>
7610: <td>$domform</td>
7611: </td>
7612: </tr>
7613: <tr>
7614: <td>$lt{'usr'}:</td>
7615: <td>$srchbysel
7616: $srchtypesel
7617: <input type="text" size="15" name="srchterm" value="$srchterm" />
7618: $srchinsel
7619: </td>
7620: </tr>
7621: </table>
7622: <br />
7623: END_BLOCK
7624:
7625: return $output;
7626: }
7627:
7628: sub user_rule_check {
7629: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
7630: my $response;
7631: if (ref($usershash) eq 'HASH') {
7632: foreach my $user (keys(%{$usershash})) {
7633: my ($uname,$udom) = split(/:/,$user);
7634: next if ($udom eq '' || $uname eq '');
7635: my ($id,$newuser);
7636: if (ref($usershash->{$user}) eq 'HASH') {
7637: $newuser = $usershash->{$user}->{'newuser'};
7638: $id = $usershash->{$user}->{'id'};
7639: }
7640: my $inst_response;
7641: if (ref($checks) eq 'HASH') {
7642: if (defined($checks->{'username'})) {
7643: ($inst_response,%{$inst_results->{$user}}) =
7644: &Apache::lonnet::get_instuser($udom,$uname);
7645: } elsif (defined($checks->{'id'})) {
7646: ($inst_response,%{$inst_results->{$user}}) =
7647: &Apache::lonnet::get_instuser($udom,undef,$id);
7648: }
7649: } else {
7650: ($inst_response,%{$inst_results->{$user}}) =
7651: &Apache::lonnet::get_instuser($udom,$uname);
7652: return;
7653: }
7654: if (!$got_rules->{$udom}) {
7655: my %domconfig = &Apache::lonnet::get_dom('configuration',
7656: ['usercreation'],$udom);
7657: if (ref($domconfig{'usercreation'}) eq 'HASH') {
7658: foreach my $item ('username','id') {
7659: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
7660: $$curr_rules{$udom}{$item} =
7661: $domconfig{'usercreation'}{$item.'_rule'};
7662: }
7663: }
7664: }
7665: $got_rules->{$udom} = 1;
7666: }
7667: foreach my $item (keys(%{$checks})) {
7668: if (ref($$curr_rules{$udom}) eq 'HASH') {
7669: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
7670: if (@{$$curr_rules{$udom}{$item}} > 0) {
7671: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
7672: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
7673: if ($rule_check{$rule}) {
7674: $$rulematch{$user}{$item} = $rule;
7675: if ($inst_response eq 'ok') {
7676: if (ref($inst_results) eq 'HASH') {
7677: if (ref($inst_results->{$user}) eq 'HASH') {
7678: if (keys(%{$inst_results->{$user}}) == 0) {
7679: $$alerts{$item}{$udom}{$uname} = 1;
7680: }
7681: }
7682: }
7683: }
7684: last;
7685: }
7686: }
7687: }
7688: }
7689: }
7690: }
7691: }
7692: }
7693: return;
7694: }
7695:
7696: sub user_rule_formats {
7697: my ($domain,$domdesc,$curr_rules,$check) = @_;
7698: my %text = (
7699: 'username' => 'Usernames',
7700: 'id' => 'IDs',
7701: );
7702: my $output;
7703: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
7704: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
7705: if (@{$ruleorder} > 0) {
7706: $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>';
7707: foreach my $rule (@{$ruleorder}) {
7708: if (ref($curr_rules) eq 'ARRAY') {
7709: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
7710: if (ref($rules->{$rule}) eq 'HASH') {
7711: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
7712: $rules->{$rule}{'desc'}.'</li>';
7713: }
7714: }
7715: }
7716: }
7717: $output .= '</ul>';
7718: }
7719: }
7720: return $output;
7721: }
7722:
7723: sub instrule_disallow_msg {
7724: my ($checkitem,$domdesc,$count,$mode) = @_;
7725: my $response;
7726: my %text = (
7727: item => 'username',
7728: items => 'usernames',
7729: match => 'matches',
7730: do => 'does',
7731: action => 'a username',
7732: one => 'one',
7733: );
7734: if ($count > 1) {
7735: $text{'item'} = 'usernames';
7736: $text{'match'} ='match';
7737: $text{'do'} = 'do';
7738: $text{'action'} = 'usernames',
7739: $text{'one'} = 'ones';
7740: }
7741: if ($checkitem eq 'id') {
7742: $text{'items'} = 'IDs';
7743: $text{'item'} = 'ID';
7744: $text{'action'} = 'an ID';
7745: if ($count > 1) {
7746: $text{'item'} = 'IDs';
7747: $text{'action'} = 'IDs';
7748: }
7749: }
7750: $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 />';
7751: if ($mode eq 'upload') {
7752: if ($checkitem eq 'username') {
7753: $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'}.");
7754: } elsif ($checkitem eq 'id') {
7755: $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.");
7756: }
7757: } elsif ($mode eq 'selfcreate') {
7758: if ($checkitem eq 'id') {
7759: $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.");
7760: }
7761: } else {
7762: if ($checkitem eq 'username') {
7763: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
7764: } elsif ($checkitem eq 'id') {
7765: $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.");
7766: }
7767: }
7768: return $response;
7769: }
7770:
7771: sub personal_data_fieldtitles {
7772: my %fieldtitles = &Apache::lonlocal::texthash (
7773: id => 'Student/Employee ID',
7774: permanentemail => 'E-mail address',
7775: lastname => 'Last Name',
7776: firstname => 'First Name',
7777: middlename => 'Middle Name',
7778: generation => 'Generation',
7779: gen => 'Generation',
7780: inststatus => 'Affiliation',
7781: );
7782: return %fieldtitles;
7783: }
7784:
7785: sub sorted_inst_types {
7786: my ($dom) = @_;
7787: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
7788: my $othertitle = &mt('All users');
7789: if ($env{'request.course.id'}) {
7790: $othertitle = &mt('Any users');
7791: }
7792: my @types;
7793: if (ref($order) eq 'ARRAY') {
7794: @types = @{$order};
7795: }
7796: if (@types == 0) {
7797: if (ref($usertypes) eq 'HASH') {
7798: @types = sort(keys(%{$usertypes}));
7799: }
7800: }
7801: if (keys(%{$usertypes}) > 0) {
7802: $othertitle = &mt('Other users');
7803: }
7804: return ($othertitle,$usertypes,\@types);
7805: }
7806:
7807: sub get_institutional_codes {
7808: my ($settings,$allcourses,$LC_code) = @_;
7809: # Get complete list of course sections to update
7810: my @currsections = ();
7811: my @currxlists = ();
7812: my $coursecode = $$settings{'internal.coursecode'};
7813:
7814: if ($$settings{'internal.sectionnums'} ne '') {
7815: @currsections = split(/,/,$$settings{'internal.sectionnums'});
7816: }
7817:
7818: if ($$settings{'internal.crosslistings'} ne '') {
7819: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
7820: }
7821:
7822: if (@currxlists > 0) {
7823: foreach (@currxlists) {
7824: if (m/^([^:]+):(\w*)$/) {
7825: unless (grep/^$1$/,@{$allcourses}) {
7826: push @{$allcourses},$1;
7827: $$LC_code{$1} = $2;
7828: }
7829: }
7830: }
7831: }
7832:
7833: if (@currsections > 0) {
7834: foreach (@currsections) {
7835: if (m/^(\w+):(\w*)$/) {
7836: my $sec = $coursecode.$1;
7837: my $lc_sec = $2;
7838: unless (grep/^$sec$/,@{$allcourses}) {
7839: push @{$allcourses},$sec;
7840: $$LC_code{$sec} = $lc_sec;
7841: }
7842: }
7843: }
7844: }
7845: return;
7846: }
7847:
7848: =pod
7849:
7850: =head1 Slot Helpers
7851:
7852: =over 4
7853:
7854: =item * sorted_slots()
7855:
7856: Sorts an array of slot names in order of slot start time (earliest first).
7857:
7858: Inputs:
7859:
7860: =over 4
7861:
7862: slotsarr - Reference to array of unsorted slot names.
7863:
7864: slots - Reference to hash of hash, where outer hash keys are slot names.
7865:
7866: =back
7867:
7868: Returns:
7869:
7870: =over 4
7871:
7872: sorted - An array of slot names sorted by the start time of the slot.
7873:
7874: =back
7875:
7876: =back
7877:
7878: =cut
7879:
7880:
7881: sub sorted_slots {
7882: my ($slotsarr,$slots) = @_;
7883: my @sorted;
7884: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
7885: @sorted =
7886: sort {
7887: if (ref($slots->{$a}) && ref($slots->{$b})) {
7888: return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
7889: }
7890: if (ref($slots->{$a})) { return -1;}
7891: if (ref($slots->{$b})) { return 1;}
7892: return 0;
7893: } @{$slotsarr};
7894: }
7895: return @sorted;
7896: }
7897:
7898:
7899: =pod
7900:
7901: =head1 HTTP Helpers
7902:
7903: =over 4
7904:
7905: =item * &get_unprocessed_cgi($query,$possible_names)
7906:
7907: Modify the %env hash to contain unprocessed CGI form parameters held in
7908: $query. The parameters listed in $possible_names (an array reference),
7909: will be set in $env{'form.name'} if they do not already exist.
7910:
7911: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
7912: $possible_names is an ref to an array of form element names. As an example:
7913: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
7914: will result in $env{'form.uname'} and $env{'form.udom'} being set.
7915:
7916: =cut
7917:
7918: sub get_unprocessed_cgi {
7919: my ($query,$possible_names)= @_;
7920: # $Apache::lonxml::debug=1;
7921: foreach my $pair (split(/&/,$query)) {
7922: my ($name, $value) = split(/=/,$pair);
7923: $name = &unescape($name);
7924: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
7925: $value =~ tr/+/ /;
7926: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
7927: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
7928: }
7929: }
7930: }
7931:
7932: =pod
7933:
7934: =item * &cacheheader()
7935:
7936: returns cache-controlling header code
7937:
7938: =cut
7939:
7940: sub cacheheader {
7941: unless ($env{'request.method'} eq 'GET') { return ''; }
7942: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
7943: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
7944: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
7945: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
7946: return $output;
7947: }
7948:
7949: =pod
7950:
7951: =item * &no_cache($r)
7952:
7953: specifies header code to not have cache
7954:
7955: =cut
7956:
7957: sub no_cache {
7958: my ($r) = @_;
7959: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
7960: $env{'request.method'} ne 'GET') { return ''; }
7961: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
7962: $r->no_cache(1);
7963: $r->header_out("Expires" => $date);
7964: $r->header_out("Pragma" => "no-cache");
7965: }
7966:
7967: sub content_type {
7968: my ($r,$type,$charset) = @_;
7969: if ($r) {
7970: # Note that printout.pl calls this with undef for $r.
7971: &no_cache($r);
7972: }
7973: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
7974: unless ($charset) {
7975: $charset=&Apache::lonlocal::current_encoding;
7976: }
7977: if ($charset) { $type.='; charset='.$charset; }
7978: if ($r) {
7979: $r->content_type($type);
7980: } else {
7981: print("Content-type: $type\n\n");
7982: }
7983: }
7984:
7985: =pod
7986:
7987: =item * &add_to_env($name,$value)
7988:
7989: adds $name to the %env hash with value
7990: $value, if $name already exists, the entry is converted to an array
7991: reference and $value is added to the array.
7992:
7993: =cut
7994:
7995: sub add_to_env {
7996: my ($name,$value)=@_;
7997: if (defined($env{$name})) {
7998: if (ref($env{$name})) {
7999: #already have multiple values
8000: push(@{ $env{$name} },$value);
8001: } else {
8002: #first time seeing multiple values, convert hash entry to an arrayref
8003: my $first=$env{$name};
8004: undef($env{$name});
8005: push(@{ $env{$name} },$first,$value);
8006: }
8007: } else {
8008: $env{$name}=$value;
8009: }
8010: }
8011:
8012: =pod
8013:
8014: =item * &get_env_multiple($name)
8015:
8016: gets $name from the %env hash, it seemlessly handles the cases where multiple
8017: values may be defined and end up as an array ref.
8018:
8019: returns an array of values
8020:
8021: =cut
8022:
8023: sub get_env_multiple {
8024: my ($name) = @_;
8025: my @values;
8026: if (defined($env{$name})) {
8027: # exists is it an array
8028: if (ref($env{$name})) {
8029: @values=@{ $env{$name} };
8030: } else {
8031: $values[0]=$env{$name};
8032: }
8033: }
8034: return(@values);
8035: }
8036:
8037: sub ask_for_embedded_content {
8038: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
8039: my $upload_output = '
8040: <form name="upload_embedded" action="'.$actionurl.'"
8041: method="post" enctype="multipart/form-data">';
8042: $upload_output .= $state;
8043: $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
8044:
8045: my $num = 0;
8046: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
8047: $upload_output .= &start_data_table_row().
8048: '<td>'.$embed_file.'</td><td>';
8049: if ($args->{'ignore_remote_references'}
8050: && $embed_file =~ m{^\w+://}) {
8051: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
8052: } elsif ($args->{'error_on_invalid_names'}
8053: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
8054:
8055: $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
8056:
8057: } else {
8058: $upload_output .='
8059: <input name="embedded_item_'.$num.'" type="file" value="" />
8060: <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
8061: my $attrib = join(':',@{$$allfiles{$embed_file}});
8062: $upload_output .=
8063: "\n\t\t".
8064: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
8065: $attrib.'" />';
8066: if (exists($$codebase{$embed_file})) {
8067: $upload_output .=
8068: "\n\t\t".
8069: '<input name="codebase_'.$num.'" type="hidden" value="'.
8070: &escape($$codebase{$embed_file}).'" />';
8071: }
8072: }
8073: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
8074: $num++;
8075: }
8076: $upload_output .= &Apache::loncommon::end_data_table().'<br />
8077: <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
8078: <input type ="submit" value="'.&mt('Upload Listed Files').'" />
8079: '.&mt('(only files for which a location has been provided will be uploaded)').'
8080: </form>';
8081: return $upload_output;
8082: }
8083:
8084: sub upload_embedded {
8085: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
8086: $current_disk_usage) = @_;
8087: my $output;
8088: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
8089: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
8090: my $orig_uploaded_filename =
8091: $env{'form.embedded_item_'.$i.'.filename'};
8092:
8093: $env{'form.embedded_orig_'.$i} =
8094: &unescape($env{'form.embedded_orig_'.$i});
8095: my ($path,$fname) =
8096: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
8097: # no path, whole string is fname
8098: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
8099:
8100: $path = $env{'form.currentpath'}.$path;
8101: $fname = &Apache::lonnet::clean_filename($fname);
8102: # See if there is anything left
8103: next if ($fname eq '');
8104:
8105: # Check if file already exists as a file or directory.
8106: my ($state,$msg);
8107: if ($context eq 'portfolio') {
8108: my $port_path = $dirpath;
8109: if ($group ne '') {
8110: $port_path = "groups/$group/$port_path";
8111: }
8112: ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
8113: $dir_root,$port_path,$disk_quota,
8114: $current_disk_usage,$uname,$udom);
8115: if ($state eq 'will_exceed_quota'
8116: || $state eq 'file_locked'
8117: || $state eq 'file_exists' ) {
8118: $output .= $msg;
8119: next;
8120: }
8121: } elsif (($context eq 'author') || ($context eq 'testbank')) {
8122: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
8123: if ($state eq 'exists') {
8124: $output .= $msg;
8125: next;
8126: }
8127: }
8128: # Check if extension is valid
8129: if (($fname =~ /\.(\w+)$/) &&
8130: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
8131: $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
8132: next;
8133: } elsif (($fname =~ /\.(\w+)$/) &&
8134: (!defined(&Apache::loncommon::fileembstyle($1)))) {
8135: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
8136: next;
8137: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
8138: $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
8139: next;
8140: }
8141:
8142: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
8143: if ($context eq 'portfolio') {
8144: my $result=
8145: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
8146: $dirpath.$path);
8147: if ($result !~ m|^/uploaded/|) {
8148: $output .= '<span class="LC_error">'
8149: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
8150: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
8151: .'</span><br />';
8152: next;
8153: } else {
8154: $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
8155: $path.$fname.'</span>').'</p>';
8156: }
8157: } else {
8158: # Save the file
8159: my $target = $env{'form.embedded_item_'.$i};
8160: my $fullpath = $dir_root.$dirpath.'/'.$path;
8161: my $dest = $fullpath.$fname;
8162: my $url = $url_root.$dirpath.'/'.$path.$fname;
8163: my @parts=split(/\//,$fullpath);
8164: my $count;
8165: my $filepath = $dir_root;
8166: for ($count=4;$count<=$#parts;$count++) {
8167: $filepath .= "/$parts[$count]";
8168: if ((-e $filepath)!=1) {
8169: mkdir($filepath,0770);
8170: }
8171: }
8172: my $fh;
8173: if (!open($fh,'>'.$dest)) {
8174: &Apache::lonnet::logthis('Failed to create '.$dest);
8175: $output .= '<span class="LC_error">'.
8176: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8177: '</span><br />';
8178: } else {
8179: if (!print $fh $env{'form.embedded_item_'.$i}) {
8180: &Apache::lonnet::logthis('Failed to write to '.$dest);
8181: $output .= '<span class="LC_error">'.
8182: &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8183: '</span><br />';
8184: } else {
8185: if ($context eq 'testbank') {
8186: $output .= &mt('Embedded file uploaded successfully:').
8187: ' <a href="'.$url.'">'.
8188: $orig_uploaded_filename.'</a><br />';
8189: } else {
8190: $output .= '<span class=\"LC_fontsize_large\">'.
8191: &mt('View embedded file: [_1]','<a href="'.$url.'">'.
8192: $orig_uploaded_filename.'</a>').'</span><br />';
8193: }
8194: }
8195: close($fh);
8196: }
8197: }
8198: }
8199: return $output;
8200: }
8201:
8202: sub check_for_existing {
8203: my ($path,$fname,$element) = @_;
8204: my ($state,$msg);
8205: if (-d $path.'/'.$fname) {
8206: $state = 'exists';
8207: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
8208: } elsif (-e $path.'/'.$fname) {
8209: $state = 'exists';
8210: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
8211: }
8212: if ($state eq 'exists') {
8213: $msg = '<span class="LC_error">'.$msg.'</span><br />';
8214: }
8215: return ($state,$msg);
8216: }
8217:
8218: sub check_for_upload {
8219: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
8220: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
8221: my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
8222: my $getpropath = 1;
8223: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
8224: $getpropath);
8225: my $found_file = 0;
8226: my $locked_file = 0;
8227: foreach my $line (@dir_list) {
8228: my ($file_name)=split(/\&/,$line,2);
8229: if ($file_name eq $fname){
8230: $file_name = $path.$file_name;
8231: if ($group ne '') {
8232: $file_name = $group.$file_name;
8233: }
8234: $found_file = 1;
8235: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
8236: $locked_file = 1;
8237: }
8238: }
8239: }
8240: if (($current_disk_usage + $filesize) > $disk_quota){
8241: my $msg = '<span class="LC_error">'.
8242: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
8243: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
8244: return ('will_exceed_quota',$msg);
8245: } elsif ($found_file) {
8246: if ($locked_file) {
8247: my $msg = '<span class="LC_error">';
8248: $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>');
8249: $msg .= '</span><br />';
8250: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
8251: return ('file_locked',$msg);
8252: } else {
8253: my $msg = '<span class="LC_error">';
8254: $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'});
8255: $msg .= '</span>';
8256: $msg .= '<br />';
8257: $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
8258: return ('file_exists',$msg);
8259: }
8260: }
8261: }
8262:
8263:
8264: =pod
8265:
8266: =back
8267:
8268: =head1 CSV Upload/Handling functions
8269:
8270: =over 4
8271:
8272: =item * &upfile_store($r)
8273:
8274: Store uploaded file, $r should be the HTTP Request object,
8275: needs $env{'form.upfile'}
8276: returns $datatoken to be put into hidden field
8277:
8278: =cut
8279:
8280: sub upfile_store {
8281: my $r=shift;
8282: $env{'form.upfile'}=~s/\r/\n/gs;
8283: $env{'form.upfile'}=~s/\f/\n/gs;
8284: $env{'form.upfile'}=~s/\n+/\n/gs;
8285: $env{'form.upfile'}=~s/\n+$//gs;
8286:
8287: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
8288: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
8289: {
8290: my $datafile = $r->dir_config('lonDaemons').
8291: '/tmp/'.$datatoken.'.tmp';
8292: if ( open(my $fh,">$datafile") ) {
8293: print $fh $env{'form.upfile'};
8294: close($fh);
8295: }
8296: }
8297: return $datatoken;
8298: }
8299:
8300: =pod
8301:
8302: =item * &load_tmp_file($r)
8303:
8304: Load uploaded file from tmp, $r should be the HTTP Request object,
8305: needs $env{'form.datatoken'},
8306: sets $env{'form.upfile'} to the contents of the file
8307:
8308: =cut
8309:
8310: sub load_tmp_file {
8311: my $r=shift;
8312: my @studentdata=();
8313: {
8314: my $studentfile = $r->dir_config('lonDaemons').
8315: '/tmp/'.$env{'form.datatoken'}.'.tmp';
8316: if ( open(my $fh,"<$studentfile") ) {
8317: @studentdata=<$fh>;
8318: close($fh);
8319: }
8320: }
8321: $env{'form.upfile'}=join('',@studentdata);
8322: }
8323:
8324: =pod
8325:
8326: =item * &upfile_record_sep()
8327:
8328: Separate uploaded file into records
8329: returns array of records,
8330: needs $env{'form.upfile'} and $env{'form.upfiletype'}
8331:
8332: =cut
8333:
8334: sub upfile_record_sep {
8335: if ($env{'form.upfiletype'} eq 'xml') {
8336: } else {
8337: my @records;
8338: foreach my $line (split(/\n/,$env{'form.upfile'})) {
8339: if ($line=~/^\s*$/) { next; }
8340: push(@records,$line);
8341: }
8342: return @records;
8343: }
8344: }
8345:
8346: =pod
8347:
8348: =item * &record_sep($record)
8349:
8350: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
8351:
8352: =cut
8353:
8354: sub takeleft {
8355: my $index=shift;
8356: return substr('0000'.$index,-4,4);
8357: }
8358:
8359: sub record_sep {
8360: my $record=shift;
8361: my %components=();
8362: if ($env{'form.upfiletype'} eq 'xml') {
8363: } elsif ($env{'form.upfiletype'} eq 'space') {
8364: my $i=0;
8365: foreach my $field (split(/\s+/,$record)) {
8366: $field=~s/^(\"|\')//;
8367: $field=~s/(\"|\')$//;
8368: $components{&takeleft($i)}=$field;
8369: $i++;
8370: }
8371: } elsif ($env{'form.upfiletype'} eq 'tab') {
8372: my $i=0;
8373: foreach my $field (split(/\t/,$record)) {
8374: $field=~s/^(\"|\')//;
8375: $field=~s/(\"|\')$//;
8376: $components{&takeleft($i)}=$field;
8377: $i++;
8378: }
8379: } else {
8380: my $separator=',';
8381: if ($env{'form.upfiletype'} eq 'semisv') {
8382: $separator=';';
8383: }
8384: my $i=0;
8385: # the character we are looking for to indicate the end of a quote or a record
8386: my $looking_for=$separator;
8387: # do not add the characters to the fields
8388: my $ignore=0;
8389: # we just encountered a separator (or the beginning of the record)
8390: my $just_found_separator=1;
8391: # store the field we are working on here
8392: my $field='';
8393: # work our way through all characters in record
8394: foreach my $character ($record=~/(.)/g) {
8395: if ($character eq $looking_for) {
8396: if ($character ne $separator) {
8397: # Found the end of a quote, again looking for separator
8398: $looking_for=$separator;
8399: $ignore=1;
8400: } else {
8401: # Found a separator, store away what we got
8402: $components{&takeleft($i)}=$field;
8403: $i++;
8404: $just_found_separator=1;
8405: $ignore=0;
8406: $field='';
8407: }
8408: next;
8409: }
8410: # single or double quotation marks after a separator indicate beginning of a quote
8411: # we are now looking for the end of the quote and need to ignore separators
8412: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
8413: $looking_for=$character;
8414: next;
8415: }
8416: # ignore would be true after we reached the end of a quote
8417: if ($ignore) { next; }
8418: if (($just_found_separator) && ($character=~/\s/)) { next; }
8419: $field.=$character;
8420: $just_found_separator=0;
8421: }
8422: # catch the very last entry, since we never encountered the separator
8423: $components{&takeleft($i)}=$field;
8424: }
8425: return %components;
8426: }
8427:
8428: ######################################################
8429: ######################################################
8430:
8431: =pod
8432:
8433: =item * &upfile_select_html()
8434:
8435: Return HTML code to select a file from the users machine and specify
8436: the file type.
8437:
8438: =cut
8439:
8440: ######################################################
8441: ######################################################
8442: sub upfile_select_html {
8443: my %Types = (
8444: csv => &mt('CSV (comma separated values, spreadsheet)'),
8445: semisv => &mt('Semicolon separated values'),
8446: space => &mt('Space separated'),
8447: tab => &mt('Tabulator separated'),
8448: # xml => &mt('HTML/XML'),
8449: );
8450: my $Str = '<input type="file" name="upfile" size="50" />'.
8451: '<br />'.&mt('Type').': <select name="upfiletype">';
8452: foreach my $type (sort(keys(%Types))) {
8453: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
8454: }
8455: $Str .= "</select>\n";
8456: return $Str;
8457: }
8458:
8459: sub get_samples {
8460: my ($records,$toget) = @_;
8461: my @samples=({});
8462: my $got=0;
8463: foreach my $rec (@$records) {
8464: my %temp = &record_sep($rec);
8465: if (! grep(/\S/, values(%temp))) { next; }
8466: if (%temp) {
8467: $samples[$got]=\%temp;
8468: $got++;
8469: if ($got == $toget) { last; }
8470: }
8471: }
8472: return \@samples;
8473: }
8474:
8475: ######################################################
8476: ######################################################
8477:
8478: =pod
8479:
8480: =item * &csv_print_samples($r,$records)
8481:
8482: Prints a table of sample values from each column uploaded $r is an
8483: Apache Request ref, $records is an arrayref from
8484: &Apache::loncommon::upfile_record_sep
8485:
8486: =cut
8487:
8488: ######################################################
8489: ######################################################
8490: sub csv_print_samples {
8491: my ($r,$records) = @_;
8492: my $samples = &get_samples($records,5);
8493:
8494: $r->print(&mt('Samples').'<br />'.&start_data_table().
8495: &start_data_table_header_row());
8496: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8497: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
8498: $r->print(&end_data_table_header_row());
8499: foreach my $hash (@$samples) {
8500: $r->print(&start_data_table_row());
8501: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8502: $r->print('<td>');
8503: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
8504: $r->print('</td>');
8505: }
8506: $r->print(&end_data_table_row());
8507: }
8508: $r->print(&end_data_table().'<br />'."\n");
8509: }
8510:
8511: ######################################################
8512: ######################################################
8513:
8514: =pod
8515:
8516: =item * &csv_print_select_table($r,$records,$d)
8517:
8518: Prints a table to create associations between values and table columns.
8519:
8520: $r is an Apache Request ref,
8521: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
8522: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
8523:
8524: =cut
8525:
8526: ######################################################
8527: ######################################################
8528: sub csv_print_select_table {
8529: my ($r,$records,$d) = @_;
8530: my $i=0;
8531: my $samples = &get_samples($records,1);
8532: $r->print(&mt('Associate columns with student attributes.')."\n".
8533: &start_data_table().&start_data_table_header_row().
8534: '<th>'.&mt('Attribute').'</th>'.
8535: '<th>'.&mt('Column').'</th>'.
8536: &end_data_table_header_row()."\n");
8537: foreach my $array_ref (@$d) {
8538: my ($value,$display,$defaultcol)=@{ $array_ref };
8539: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
8540:
8541: $r->print('<td><select name=f'.$i.
8542: ' onchange="javascript:flip(this.form,'.$i.');">');
8543: $r->print('<option value="none"></option>');
8544: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8545: $r->print('<option value="'.$sample.'"'.
8546: ($sample eq $defaultcol ? ' selected="selected" ' : '').
8547: '>'.&mt('Column [_1]',($sample+1)).'</option>');
8548: }
8549: $r->print('</select></td>'.&end_data_table_row()."\n");
8550: $i++;
8551: }
8552: $r->print(&end_data_table());
8553: $i--;
8554: return $i;
8555: }
8556:
8557: ######################################################
8558: ######################################################
8559:
8560: =pod
8561:
8562: =item * &csv_samples_select_table($r,$records,$d)
8563:
8564: Prints a table of sample values from the upload and can make associate samples to internal names.
8565:
8566: $r is an Apache Request ref,
8567: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
8568: $d is an array of 2 element arrays (internal name, displayed name)
8569:
8570: =cut
8571:
8572: ######################################################
8573: ######################################################
8574: sub csv_samples_select_table {
8575: my ($r,$records,$d) = @_;
8576: my $i=0;
8577: #
8578: my $max_samples = 5;
8579: my $samples = &get_samples($records,$max_samples);
8580: $r->print(&start_data_table().
8581: &start_data_table_header_row().'<th>'.
8582: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
8583: &end_data_table_header_row());
8584:
8585: foreach my $key (sort(keys(%{ $samples->[0] }))) {
8586: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
8587: ' onchange="javascript:flip(this.form,'.$i.');">');
8588: foreach my $option (@$d) {
8589: my ($value,$display,$defaultcol)=@{ $option };
8590: $r->print('<option value="'.$value.'"'.
8591: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
8592: $display.'</option>');
8593: }
8594: $r->print('</select></td><td>');
8595: foreach my $line (0..($max_samples-1)) {
8596: if (defined($samples->[$line]{$key})) {
8597: $r->print($samples->[$line]{$key}."<br />\n");
8598: }
8599: }
8600: $r->print('</td>'.&end_data_table_row());
8601: $i++;
8602: }
8603: $r->print(&end_data_table());
8604: $i--;
8605: return($i);
8606: }
8607:
8608: ######################################################
8609: ######################################################
8610:
8611: =pod
8612:
8613: =item * &clean_excel_name($name)
8614:
8615: Returns a replacement for $name which does not contain any illegal characters.
8616:
8617: =cut
8618:
8619: ######################################################
8620: ######################################################
8621: sub clean_excel_name {
8622: my ($name) = @_;
8623: $name =~ s/[:\*\?\/\\]//g;
8624: if (length($name) > 31) {
8625: $name = substr($name,0,31);
8626: }
8627: return $name;
8628: }
8629:
8630: =pod
8631:
8632: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
8633:
8634: Returns either 1 or undef
8635:
8636: 1 if the part is to be hidden, undef if it is to be shown
8637:
8638: Arguments are:
8639:
8640: $id the id of the part to be checked
8641: $symb, optional the symb of the resource to check
8642: $udom, optional the domain of the user to check for
8643: $uname, optional the username of the user to check for
8644:
8645: =cut
8646:
8647: sub check_if_partid_hidden {
8648: my ($id,$symb,$udom,$uname) = @_;
8649: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
8650: $symb,$udom,$uname);
8651: my $truth=1;
8652: #if the string starts with !, then the list is the list to show not hide
8653: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
8654: my @hiddenlist=split(/,/,$hiddenparts);
8655: foreach my $checkid (@hiddenlist) {
8656: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
8657: }
8658: return !$truth;
8659: }
8660:
8661:
8662: ############################################################
8663: ############################################################
8664:
8665: =pod
8666:
8667: =back
8668:
8669: =head1 cgi-bin script and graphing routines
8670:
8671: =over 4
8672:
8673: =item * &get_cgi_id()
8674:
8675: Inputs: none
8676:
8677: Returns an id which can be used to pass environment variables
8678: to various cgi-bin scripts. These environment variables will
8679: be removed from the users environment after a given time by
8680: the routine &Apache::lonnet::transfer_profile_to_env.
8681:
8682: =cut
8683:
8684: ############################################################
8685: ############################################################
8686: my $uniq=0;
8687: sub get_cgi_id {
8688: $uniq=($uniq+1)%100000;
8689: return (time.'_'.$$.'_'.$uniq);
8690: }
8691:
8692: ############################################################
8693: ############################################################
8694:
8695: =pod
8696:
8697: =item * &DrawBarGraph()
8698:
8699: Facilitates the plotting of data in a (stacked) bar graph.
8700: Puts plot definition data into the users environment in order for
8701: graph.png to plot it. Returns an <img> tag for the plot.
8702: The bars on the plot are labeled '1','2',...,'n'.
8703:
8704: Inputs:
8705:
8706: =over 4
8707:
8708: =item $Title: string, the title of the plot
8709:
8710: =item $xlabel: string, text describing the X-axis of the plot
8711:
8712: =item $ylabel: string, text describing the Y-axis of the plot
8713:
8714: =item $Max: scalar, the maximum Y value to use in the plot
8715: If $Max is < any data point, the graph will not be rendered.
8716:
8717: =item $colors: array ref holding the colors to be used for the data sets when
8718: they are plotted. If undefined, default values will be used.
8719:
8720: =item $labels: array ref holding the labels to use on the x-axis for the bars.
8721:
8722: =item @Values: An array of array references. Each array reference holds data
8723: to be plotted in a stacked bar chart.
8724:
8725: =item If the final element of @Values is a hash reference the key/value
8726: pairs will be added to the graph definition.
8727:
8728: =back
8729:
8730: Returns:
8731:
8732: An <img> tag which references graph.png and the appropriate identifying
8733: information for the plot.
8734:
8735: =cut
8736:
8737: ############################################################
8738: ############################################################
8739: sub DrawBarGraph {
8740: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
8741: #
8742: if (! defined($colors)) {
8743: $colors = ['#33ff00',
8744: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
8745: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
8746: ];
8747: }
8748: my $extra_settings = {};
8749: if (ref($Values[-1]) eq 'HASH') {
8750: $extra_settings = pop(@Values);
8751: }
8752: #
8753: my $identifier = &get_cgi_id();
8754: my $id = 'cgi.'.$identifier;
8755: if (! @Values || ref($Values[0]) ne 'ARRAY') {
8756: return '';
8757: }
8758: #
8759: my @Labels;
8760: if (defined($labels)) {
8761: @Labels = @$labels;
8762: } else {
8763: for (my $i=0;$i<@{$Values[0]};$i++) {
8764: push (@Labels,$i+1);
8765: }
8766: }
8767: #
8768: my $NumBars = scalar(@{$Values[0]});
8769: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
8770: my %ValuesHash;
8771: my $NumSets=1;
8772: foreach my $array (@Values) {
8773: next if (! ref($array));
8774: $ValuesHash{$id.'.data.'.$NumSets++} =
8775: join(',',@$array);
8776: }
8777: #
8778: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
8779: if ($NumBars < 3) {
8780: $width = 120+$NumBars*32;
8781: $xskip = 1;
8782: $bar_width = 30;
8783: } elsif ($NumBars < 5) {
8784: $width = 120+$NumBars*20;
8785: $xskip = 1;
8786: $bar_width = 20;
8787: } elsif ($NumBars < 10) {
8788: $width = 120+$NumBars*15;
8789: $xskip = 1;
8790: $bar_width = 15;
8791: } elsif ($NumBars <= 25) {
8792: $width = 120+$NumBars*11;
8793: $xskip = 5;
8794: $bar_width = 8;
8795: } elsif ($NumBars <= 50) {
8796: $width = 120+$NumBars*8;
8797: $xskip = 5;
8798: $bar_width = 4;
8799: } else {
8800: $width = 120+$NumBars*8;
8801: $xskip = 5;
8802: $bar_width = 4;
8803: }
8804: #
8805: $Max = 1 if ($Max < 1);
8806: if ( int($Max) < $Max ) {
8807: $Max++;
8808: $Max = int($Max);
8809: }
8810: $Title = '' if (! defined($Title));
8811: $xlabel = '' if (! defined($xlabel));
8812: $ylabel = '' if (! defined($ylabel));
8813: $ValuesHash{$id.'.title'} = &escape($Title);
8814: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
8815: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
8816: $ValuesHash{$id.'.y_max_value'} = $Max;
8817: $ValuesHash{$id.'.NumBars'} = $NumBars;
8818: $ValuesHash{$id.'.NumSets'} = $NumSets;
8819: $ValuesHash{$id.'.PlotType'} = 'bar';
8820: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8821: $ValuesHash{$id.'.height'} = $height;
8822: $ValuesHash{$id.'.width'} = $width;
8823: $ValuesHash{$id.'.xskip'} = $xskip;
8824: $ValuesHash{$id.'.bar_width'} = $bar_width;
8825: $ValuesHash{$id.'.labels'} = join(',',@Labels);
8826: #
8827: # Deal with other parameters
8828: while (my ($key,$value) = each(%$extra_settings)) {
8829: $ValuesHash{$id.'.'.$key} = $value;
8830: }
8831: #
8832: &Apache::lonnet::appenv(\%ValuesHash);
8833: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8834: }
8835:
8836: ############################################################
8837: ############################################################
8838:
8839: =pod
8840:
8841: =item * &DrawXYGraph()
8842:
8843: Facilitates the plotting of data in an XY graph.
8844: Puts plot definition data into the users environment in order for
8845: graph.png to plot it. Returns an <img> tag for the plot.
8846:
8847: Inputs:
8848:
8849: =over 4
8850:
8851: =item $Title: string, the title of the plot
8852:
8853: =item $xlabel: string, text describing the X-axis of the plot
8854:
8855: =item $ylabel: string, text describing the Y-axis of the plot
8856:
8857: =item $Max: scalar, the maximum Y value to use in the plot
8858: If $Max is < any data point, the graph will not be rendered.
8859:
8860: =item $colors: Array ref containing the hex color codes for the data to be
8861: plotted in. If undefined, default values will be used.
8862:
8863: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8864:
8865: =item $Ydata: Array ref containing Array refs.
8866: Each of the contained arrays will be plotted as a separate curve.
8867:
8868: =item %Values: hash indicating or overriding any default values which are
8869: passed to graph.png.
8870: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
8871:
8872: =back
8873:
8874: Returns:
8875:
8876: An <img> tag which references graph.png and the appropriate identifying
8877: information for the plot.
8878:
8879: =cut
8880:
8881: ############################################################
8882: ############################################################
8883: sub DrawXYGraph {
8884: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
8885: #
8886: # Create the identifier for the graph
8887: my $identifier = &get_cgi_id();
8888: my $id = 'cgi.'.$identifier;
8889: #
8890: $Title = '' if (! defined($Title));
8891: $xlabel = '' if (! defined($xlabel));
8892: $ylabel = '' if (! defined($ylabel));
8893: my %ValuesHash =
8894: (
8895: $id.'.title' => &escape($Title),
8896: $id.'.xlabel' => &escape($xlabel),
8897: $id.'.ylabel' => &escape($ylabel),
8898: $id.'.y_max_value'=> $Max,
8899: $id.'.labels' => join(',',@$Xlabels),
8900: $id.'.PlotType' => 'XY',
8901: );
8902: #
8903: if (defined($colors) && ref($colors) eq 'ARRAY') {
8904: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8905: }
8906: #
8907: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
8908: return '';
8909: }
8910: my $NumSets=1;
8911: foreach my $array (@{$Ydata}){
8912: next if (! ref($array));
8913: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
8914: }
8915: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
8916: #
8917: # Deal with other parameters
8918: while (my ($key,$value) = each(%Values)) {
8919: $ValuesHash{$id.'.'.$key} = $value;
8920: }
8921: #
8922: &Apache::lonnet::appenv(\%ValuesHash);
8923: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8924: }
8925:
8926: ############################################################
8927: ############################################################
8928:
8929: =pod
8930:
8931: =item * &DrawXYYGraph()
8932:
8933: Facilitates the plotting of data in an XY graph with two Y axes.
8934: Puts plot definition data into the users environment in order for
8935: graph.png to plot it. Returns an <img> tag for the plot.
8936:
8937: Inputs:
8938:
8939: =over 4
8940:
8941: =item $Title: string, the title of the plot
8942:
8943: =item $xlabel: string, text describing the X-axis of the plot
8944:
8945: =item $ylabel: string, text describing the Y-axis of the plot
8946:
8947: =item $colors: Array ref containing the hex color codes for the data to be
8948: plotted in. If undefined, default values will be used.
8949:
8950: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8951:
8952: =item $Ydata1: The first data set
8953:
8954: =item $Min1: The minimum value of the left Y-axis
8955:
8956: =item $Max1: The maximum value of the left Y-axis
8957:
8958: =item $Ydata2: The second data set
8959:
8960: =item $Min2: The minimum value of the right Y-axis
8961:
8962: =item $Max2: The maximum value of the left Y-axis
8963:
8964: =item %Values: hash indicating or overriding any default values which are
8965: passed to graph.png.
8966: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
8967:
8968: =back
8969:
8970: Returns:
8971:
8972: An <img> tag which references graph.png and the appropriate identifying
8973: information for the plot.
8974:
8975: =cut
8976:
8977: ############################################################
8978: ############################################################
8979: sub DrawXYYGraph {
8980: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
8981: $Ydata2,$Min2,$Max2,%Values)=@_;
8982: #
8983: # Create the identifier for the graph
8984: my $identifier = &get_cgi_id();
8985: my $id = 'cgi.'.$identifier;
8986: #
8987: $Title = '' if (! defined($Title));
8988: $xlabel = '' if (! defined($xlabel));
8989: $ylabel = '' if (! defined($ylabel));
8990: my %ValuesHash =
8991: (
8992: $id.'.title' => &escape($Title),
8993: $id.'.xlabel' => &escape($xlabel),
8994: $id.'.ylabel' => &escape($ylabel),
8995: $id.'.labels' => join(',',@$Xlabels),
8996: $id.'.PlotType' => 'XY',
8997: $id.'.NumSets' => 2,
8998: $id.'.two_axes' => 1,
8999: $id.'.y1_max_value' => $Max1,
9000: $id.'.y1_min_value' => $Min1,
9001: $id.'.y2_max_value' => $Max2,
9002: $id.'.y2_min_value' => $Min2,
9003: );
9004: #
9005: if (defined($colors) && ref($colors) eq 'ARRAY') {
9006: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9007: }
9008: #
9009: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
9010: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
9011: return '';
9012: }
9013: my $NumSets=1;
9014: foreach my $array ($Ydata1,$Ydata2){
9015: next if (! ref($array));
9016: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
9017: }
9018: #
9019: # Deal with other parameters
9020: while (my ($key,$value) = each(%Values)) {
9021: $ValuesHash{$id.'.'.$key} = $value;
9022: }
9023: #
9024: &Apache::lonnet::appenv(\%ValuesHash);
9025: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
9026: }
9027:
9028: ############################################################
9029: ############################################################
9030:
9031: =pod
9032:
9033: =back
9034:
9035: =head1 Statistics helper routines?
9036:
9037: Bad place for them but what the hell.
9038:
9039: =over 4
9040:
9041: =item * &chartlink()
9042:
9043: Returns a link to the chart for a specific student.
9044:
9045: Inputs:
9046:
9047: =over 4
9048:
9049: =item $linktext: The text of the link
9050:
9051: =item $sname: The students username
9052:
9053: =item $sdomain: The students domain
9054:
9055: =back
9056:
9057: =back
9058:
9059: =cut
9060:
9061: ############################################################
9062: ############################################################
9063: sub chartlink {
9064: my ($linktext, $sname, $sdomain) = @_;
9065: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
9066: '&SelectedStudent='.&escape($sname.':'.$sdomain).
9067: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
9068: '">'.$linktext.'</a>';
9069: }
9070:
9071: #######################################################
9072: #######################################################
9073:
9074: =pod
9075:
9076: =head1 Course Environment Routines
9077:
9078: =over 4
9079:
9080: =item * &restore_course_settings()
9081:
9082: =item * &store_course_settings()
9083:
9084: Restores/Store indicated form parameters from the course environment.
9085: Will not overwrite existing values of the form parameters.
9086:
9087: Inputs:
9088: a scalar describing the data (e.g. 'chart', 'problem_analysis')
9089:
9090: a hash ref describing the data to be stored. For example:
9091:
9092: %Save_Parameters = ('Status' => 'scalar',
9093: 'chartoutputmode' => 'scalar',
9094: 'chartoutputdata' => 'scalar',
9095: 'Section' => 'array',
9096: 'Group' => 'array',
9097: 'StudentData' => 'array',
9098: 'Maps' => 'array');
9099:
9100: Returns: both routines return nothing
9101:
9102: =back
9103:
9104: =cut
9105:
9106: #######################################################
9107: #######################################################
9108: sub store_course_settings {
9109: return &store_settings($env{'request.course.id'},@_);
9110: }
9111:
9112: sub store_settings {
9113: # save to the environment
9114: # appenv the same items, just to be safe
9115: my $udom = $env{'user.domain'};
9116: my $uname = $env{'user.name'};
9117: my ($context,$prefix,$Settings) = @_;
9118: my %SaveHash;
9119: my %AppHash;
9120: while (my ($setting,$type) = each(%$Settings)) {
9121: my $basename = join('.','internal',$context,$prefix,$setting);
9122: my $envname = 'environment.'.$basename;
9123: if (exists($env{'form.'.$setting})) {
9124: # Save this value away
9125: if ($type eq 'scalar' &&
9126: (! exists($env{$envname}) ||
9127: $env{$envname} ne $env{'form.'.$setting})) {
9128: $SaveHash{$basename} = $env{'form.'.$setting};
9129: $AppHash{$envname} = $env{'form.'.$setting};
9130: } elsif ($type eq 'array') {
9131: my $stored_form;
9132: if (ref($env{'form.'.$setting})) {
9133: $stored_form = join(',',
9134: map {
9135: &escape($_);
9136: } sort(@{$env{'form.'.$setting}}));
9137: } else {
9138: $stored_form =
9139: &escape($env{'form.'.$setting});
9140: }
9141: # Determine if the array contents are the same.
9142: if ($stored_form ne $env{$envname}) {
9143: $SaveHash{$basename} = $stored_form;
9144: $AppHash{$envname} = $stored_form;
9145: }
9146: }
9147: }
9148: }
9149: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
9150: $udom,$uname);
9151: if ($put_result !~ /^(ok|delayed)/) {
9152: &Apache::lonnet::logthis('unable to save form parameters, '.
9153: 'got error:'.$put_result);
9154: }
9155: # Make sure these settings stick around in this session, too
9156: &Apache::lonnet::appenv(\%AppHash);
9157: return;
9158: }
9159:
9160: sub restore_course_settings {
9161: return &restore_settings($env{'request.course.id'},@_);
9162: }
9163:
9164: sub restore_settings {
9165: my ($context,$prefix,$Settings) = @_;
9166: while (my ($setting,$type) = each(%$Settings)) {
9167: next if (exists($env{'form.'.$setting}));
9168: my $envname = 'environment.internal.'.$context.'.'.$prefix.
9169: '.'.$setting;
9170: if (exists($env{$envname})) {
9171: if ($type eq 'scalar') {
9172: $env{'form.'.$setting} = $env{$envname};
9173: } elsif ($type eq 'array') {
9174: $env{'form.'.$setting} = [
9175: map {
9176: &unescape($_);
9177: } split(',',$env{$envname})
9178: ];
9179: }
9180: }
9181: }
9182: }
9183:
9184: #######################################################
9185: #######################################################
9186:
9187: =pod
9188:
9189: =head1 Domain E-mail Routines
9190:
9191: =over 4
9192:
9193: =item * &build_recipient_list()
9194:
9195: Build recipient lists for four types of e-mail:
9196: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
9197: (d) Help requests, generated by
9198: lonerrorhandler.pm, CHECKRPMS, loncron, and lonsupportreq.pm respectively.
9199:
9200: Inputs:
9201: defmail (scalar - email address of default recipient),
9202: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
9203: defdom (domain for which to retrieve configuration settings),
9204: origmail (scalar - email address of recipient from loncapa.conf,
9205: i.e., predates configuration by DC via domainprefs.pm
9206:
9207: Returns: comma separated list of addresses to which to send e-mail.
9208:
9209: =back
9210:
9211: =cut
9212:
9213: ############################################################
9214: ############################################################
9215: sub build_recipient_list {
9216: my ($defmail,$mailing,$defdom,$origmail) = @_;
9217: my @recipients;
9218: my $otheremails;
9219: my %domconfig =
9220: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
9221: if (ref($domconfig{'contacts'}) eq 'HASH') {
9222: if (exists($domconfig{'contacts'}{$mailing})) {
9223: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
9224: my @contacts = ('adminemail','supportemail');
9225: foreach my $item (@contacts) {
9226: if ($domconfig{'contacts'}{$mailing}{$item}) {
9227: my $addr = $domconfig{'contacts'}{$item};
9228: if (!grep(/^\Q$addr\E$/,@recipients)) {
9229: push(@recipients,$addr);
9230: }
9231: }
9232: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
9233: }
9234: }
9235: } elsif ($origmail ne '') {
9236: push(@recipients,$origmail);
9237: }
9238: } elsif ($origmail ne '') {
9239: push(@recipients,$origmail);
9240: }
9241: if (defined($defmail)) {
9242: if ($defmail ne '') {
9243: push(@recipients,$defmail);
9244: }
9245: }
9246: if ($otheremails) {
9247: my @others;
9248: if ($otheremails =~ /,/) {
9249: @others = split(/,/,$otheremails);
9250: } else {
9251: push(@others,$otheremails);
9252: }
9253: foreach my $addr (@others) {
9254: if (!grep(/^\Q$addr\E$/,@recipients)) {
9255: push(@recipients,$addr);
9256: }
9257: }
9258: }
9259: my $recipientlist = join(',',@recipients);
9260: return $recipientlist;
9261: }
9262:
9263: ############################################################
9264: ############################################################
9265:
9266: =pod
9267:
9268: =head1 Course Catalog Routines
9269:
9270: =over 4
9271:
9272: =item * &gather_categories()
9273:
9274: Converts category definitions - keys of categories hash stored in
9275: coursecategories in configuration.db on the primary library server in a
9276: domain - to an array. Also generates javascript and idx hash used to
9277: generate Domain Coordinator interface for editing Course Categories.
9278:
9279: Inputs:
9280:
9281: categories (reference to hash of category definitions).
9282:
9283: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9284: categories and subcategories).
9285:
9286: idx (reference to hash of counters used in Domain Coordinator interface for
9287: editing Course Categories).
9288:
9289: jsarray (reference to array of categories used to create Javascript arrays for
9290: Domain Coordinator interface for editing Course Categories).
9291:
9292: Returns: nothing
9293:
9294: Side effects: populates cats, idx and jsarray.
9295:
9296: =cut
9297:
9298: sub gather_categories {
9299: my ($categories,$cats,$idx,$jsarray) = @_;
9300: my %counters;
9301: my $num = 0;
9302: foreach my $item (keys(%{$categories})) {
9303: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
9304: if ($container eq '' && $depth == 0) {
9305: $cats->[$depth][$categories->{$item}] = $cat;
9306: } else {
9307: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
9308: }
9309: my ($escitem,$tail) = split(/:/,$item,2);
9310: if ($counters{$tail} eq '') {
9311: $counters{$tail} = $num;
9312: $num ++;
9313: }
9314: if (ref($idx) eq 'HASH') {
9315: $idx->{$item} = $counters{$tail};
9316: }
9317: if (ref($jsarray) eq 'ARRAY') {
9318: push(@{$jsarray->[$counters{$tail}]},$item);
9319: }
9320: }
9321: return;
9322: }
9323:
9324: =pod
9325:
9326: =item * &extract_categories()
9327:
9328: Used to generate breadcrumb trails for course categories.
9329:
9330: Inputs:
9331:
9332: categories (reference to hash of category definitions).
9333:
9334: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9335: categories and subcategories).
9336:
9337: trails (reference to array of breacrumb trails for each category).
9338:
9339: allitems (reference to hash - key is category key
9340: (format: escaped(name):escaped(parent category):depth in hierarchy).
9341:
9342: idx (reference to hash of counters used in Domain Coordinator interface for
9343: editing Course Categories).
9344:
9345: jsarray (reference to array of categories used to create Javascript arrays for
9346: Domain Coordinator interface for editing Course Categories).
9347:
9348: subcats (reference to hash of arrays containing all subcategories within each
9349: category, -recursive)
9350:
9351: Returns: nothing
9352:
9353: Side effects: populates trails and allitems hash references.
9354:
9355: =cut
9356:
9357: sub extract_categories {
9358: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
9359: if (ref($categories) eq 'HASH') {
9360: &gather_categories($categories,$cats,$idx,$jsarray);
9361: if (ref($cats->[0]) eq 'ARRAY') {
9362: for (my $i=0; $i<@{$cats->[0]}; $i++) {
9363: my $name = $cats->[0][$i];
9364: my $item = &escape($name).'::0';
9365: my $trailstr;
9366: if ($name eq 'instcode') {
9367: $trailstr = &mt('Official courses (with institutional codes)');
9368: } else {
9369: $trailstr = $name;
9370: }
9371: if ($allitems->{$item} eq '') {
9372: push(@{$trails},$trailstr);
9373: $allitems->{$item} = scalar(@{$trails})-1;
9374: }
9375: my @parents = ($name);
9376: if (ref($cats->[1]{$name}) eq 'ARRAY') {
9377: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
9378: my $category = $cats->[1]{$name}[$j];
9379: if (ref($subcats) eq 'HASH') {
9380: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
9381: }
9382: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
9383: }
9384: } else {
9385: if (ref($subcats) eq 'HASH') {
9386: $subcats->{$item} = [];
9387: }
9388: }
9389: }
9390: }
9391: }
9392: return;
9393: }
9394:
9395: =pod
9396:
9397: =item *&recurse_categories()
9398:
9399: Recursively used to generate breadcrumb trails for course categories.
9400:
9401: Inputs:
9402:
9403: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9404: categories and subcategories).
9405:
9406: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
9407:
9408: category (current course category, for which breadcrumb trail is being generated).
9409:
9410: trails (reference to array of breadcrumb trails for each category).
9411:
9412: allitems (reference to hash - key is category key
9413: (format: escaped(name):escaped(parent category):depth in hierarchy).
9414:
9415: parents (array containing containers directories for current category,
9416: back to top level).
9417:
9418: Returns: nothing
9419:
9420: Side effects: populates trails and allitems hash references
9421:
9422: =cut
9423:
9424: sub recurse_categories {
9425: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
9426: my $shallower = $depth - 1;
9427: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
9428: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
9429: my $name = $cats->[$depth]{$category}[$k];
9430: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9431: my $trailstr = join(' -> ',(@{$parents},$category));
9432: if ($allitems->{$item} eq '') {
9433: push(@{$trails},$trailstr);
9434: $allitems->{$item} = scalar(@{$trails})-1;
9435: }
9436: my $deeper = $depth+1;
9437: push(@{$parents},$category);
9438: if (ref($subcats) eq 'HASH') {
9439: my $subcat = &escape($name).':'.$category.':'.$depth;
9440: for (my $j=@{$parents}; $j>=0; $j--) {
9441: my $higher;
9442: if ($j > 0) {
9443: $higher = &escape($parents->[$j]).':'.
9444: &escape($parents->[$j-1]).':'.$j;
9445: } else {
9446: $higher = &escape($parents->[$j]).'::'.$j;
9447: }
9448: push(@{$subcats->{$higher}},$subcat);
9449: }
9450: }
9451: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
9452: $subcats);
9453: pop(@{$parents});
9454: }
9455: } else {
9456: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9457: my $trailstr = join(' -> ',(@{$parents},$category));
9458: if ($allitems->{$item} eq '') {
9459: push(@{$trails},$trailstr);
9460: $allitems->{$item} = scalar(@{$trails})-1;
9461: }
9462: }
9463: return;
9464: }
9465:
9466: =pod
9467:
9468: =item *&assign_categories_table()
9469:
9470: Create a datatable for display of hierarchical categories in a domain,
9471: with checkboxes to allow a course to be categorized.
9472:
9473: Inputs:
9474:
9475: cathash - reference to hash of categories defined for the domain (from
9476: configuration.db)
9477:
9478: currcat - scalar with an & separated list of categories assigned to a course.
9479:
9480: Returns: $output (markup to be displayed)
9481:
9482: =cut
9483:
9484: sub assign_categories_table {
9485: my ($cathash,$currcat) = @_;
9486: my $output;
9487: if (ref($cathash) eq 'HASH') {
9488: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
9489: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
9490: $maxdepth = scalar(@cats);
9491: if (@cats > 0) {
9492: my $itemcount = 0;
9493: if (ref($cats[0]) eq 'ARRAY') {
9494: $output = &Apache::loncommon::start_data_table();
9495: my @currcategories;
9496: if ($currcat ne '') {
9497: @currcategories = split('&',$currcat);
9498: }
9499: for (my $i=0; $i<@{$cats[0]}; $i++) {
9500: my $parent = $cats[0][$i];
9501: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9502: next if ($parent eq 'instcode');
9503: my $item = &escape($parent).'::0';
9504: my $checked = '';
9505: if (@currcategories > 0) {
9506: if (grep(/^\Q$item\E$/,@currcategories)) {
9507: $checked = ' checked="checked"';
9508: }
9509: }
9510: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
9511: '<input type="checkbox" name="usecategory" value="'.
9512: $item.'"'.$checked.' />'.$parent.'</span>'.
9513: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
9514: my $depth = 1;
9515: push(@path,$parent);
9516: $output .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
9517: pop(@path);
9518: $output .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
9519: $itemcount ++;
9520: }
9521: $output .= &Apache::loncommon::end_data_table();
9522: }
9523: }
9524: }
9525: return $output;
9526: }
9527:
9528: =pod
9529:
9530: =item *&assign_category_rows()
9531:
9532: Create a datatable row for display of nested categories in a domain,
9533: with checkboxes to allow a course to be categorized,called recursively.
9534:
9535: Inputs:
9536:
9537: itemcount - track row number for alternating colors
9538:
9539: cats - reference to array of arrays/hashes which encapsulates hierarchy of
9540: categories and subcategories.
9541:
9542: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
9543:
9544: parent - parent of current category item
9545:
9546: path - Array containing all categories back up through the hierarchy from the
9547: current category to the top level.
9548:
9549: currcategories - reference to array of current categories assigned to the course
9550:
9551: Returns: $output (markup to be displayed).
9552:
9553: =cut
9554:
9555: sub assign_category_rows {
9556: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
9557: my ($text,$name,$item,$chgstr);
9558: if (ref($cats) eq 'ARRAY') {
9559: my $maxdepth = scalar(@{$cats});
9560: if (ref($cats->[$depth]) eq 'HASH') {
9561: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
9562: my $numchildren = @{$cats->[$depth]{$parent}};
9563: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9564: $text .= '<td><table class="LC_datatable">';
9565: for (my $j=0; $j<$numchildren; $j++) {
9566: $name = $cats->[$depth]{$parent}[$j];
9567: $item = &escape($name).':'.&escape($parent).':'.$depth;
9568: my $deeper = $depth+1;
9569: my $checked = '';
9570: if (ref($currcategories) eq 'ARRAY') {
9571: if (@{$currcategories} > 0) {
9572: if (grep(/^\Q$item\E$/,@{$currcategories})) {
9573: $checked = ' checked="checked"';
9574: }
9575: }
9576: }
9577: $text .= '<tr><td><span class="LC_nobreak"><label>'.
9578: '<input type="checkbox" name="usecategory" value="'.
9579: $item.'"'.$checked.' />'.$name.'</label></span>'.
9580: '<input type="hidden" name="catname" value="'.$name.'" />'.
9581: '</td><td>';
9582: if (ref($path) eq 'ARRAY') {
9583: push(@{$path},$name);
9584: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
9585: pop(@{$path});
9586: }
9587: $text .= '</td></tr>';
9588: }
9589: $text .= '</table></td>';
9590: }
9591: }
9592: }
9593: return $text;
9594: }
9595:
9596: ############################################################
9597: ############################################################
9598:
9599:
9600: sub commit_customrole {
9601: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
9602: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
9603: ($start?', '.&mt('starting').' '.localtime($start):'').
9604: ($end?', ending '.localtime($end):'').': <b>'.
9605: &Apache::lonnet::assigncustomrole(
9606: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
9607: '</b><br />';
9608: return $output;
9609: }
9610:
9611: sub commit_standardrole {
9612: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
9613: my ($output,$logmsg,$linefeed);
9614: if ($context eq 'auto') {
9615: $linefeed = "\n";
9616: } else {
9617: $linefeed = "<br />\n";
9618: }
9619: if ($three eq 'st') {
9620: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
9621: $one,$two,$sec,$context);
9622: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
9623: ($result eq 'unknown_course') || ($result eq 'refused')) {
9624: $output = $logmsg.' '.&mt('Error: ').$result."\n";
9625: } else {
9626: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
9627: ($start?', '.&mt('starting').' '.localtime($start):'').
9628: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
9629: if ($context eq 'auto') {
9630: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
9631: } else {
9632: $output .= '<b>'.$result.'</b>'.$linefeed.
9633: &mt('Add to classlist').': <b>ok</b>';
9634: }
9635: $output .= $linefeed;
9636: }
9637: } else {
9638: $output = &mt('Assigning').' '.$three.' in '.$url.
9639: ($start?', '.&mt('starting').' '.localtime($start):'').
9640: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
9641: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
9642: if ($context eq 'auto') {
9643: $output .= $result.$linefeed;
9644: } else {
9645: $output .= '<b>'.$result.'</b>'.$linefeed;
9646: }
9647: }
9648: return $output;
9649: }
9650:
9651: sub commit_studentrole {
9652: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
9653: my ($result,$linefeed,$oldsecurl,$newsecurl);
9654: if ($context eq 'auto') {
9655: $linefeed = "\n";
9656: } else {
9657: $linefeed = '<br />'."\n";
9658: }
9659: if (defined($one) && defined($two)) {
9660: my $cid=$one.'_'.$two;
9661: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
9662: my $secchange = 0;
9663: my $expire_role_result;
9664: my $modify_section_result;
9665: if ($oldsec ne '-1') {
9666: if ($oldsec ne $sec) {
9667: $secchange = 1;
9668: my $now = time;
9669: my $uurl='/'.$cid;
9670: $uurl=~s/\_/\//g;
9671: if ($oldsec) {
9672: $uurl.='/'.$oldsec;
9673: }
9674: $oldsecurl = $uurl;
9675: $expire_role_result =
9676: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
9677: if ($env{'request.course.sec'} ne '') {
9678: if ($expire_role_result eq 'refused') {
9679: my @roles = ('st');
9680: my @statuses = ('previous');
9681: my @roledoms = ($one);
9682: my $withsec = 1;
9683: my %roleshash =
9684: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
9685: \@statuses,\@roles,\@roledoms,$withsec);
9686: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
9687: my ($oldstart,$oldend) =
9688: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
9689: if ($oldend > 0 && $oldend <= $now) {
9690: $expire_role_result = 'ok';
9691: }
9692: }
9693: }
9694: }
9695: $result = $expire_role_result;
9696: }
9697: }
9698: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
9699: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
9700: if ($modify_section_result =~ /^ok/) {
9701: if ($secchange == 1) {
9702: if ($sec eq '') {
9703: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
9704: } else {
9705: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
9706: }
9707: } elsif ($oldsec eq '-1') {
9708: if ($sec eq '') {
9709: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
9710: } else {
9711: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9712: }
9713: } else {
9714: if ($sec eq '') {
9715: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
9716: } else {
9717: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9718: }
9719: }
9720: } else {
9721: if ($secchange) {
9722: $$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;
9723: } else {
9724: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
9725: }
9726: }
9727: $result = $modify_section_result;
9728: } elsif ($secchange == 1) {
9729: if ($oldsec eq '') {
9730: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
9731: } else {
9732: $$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;
9733: }
9734: if ($expire_role_result eq 'refused') {
9735: my $newsecurl = '/'.$cid;
9736: $newsecurl =~ s/\_/\//g;
9737: if ($sec ne '') {
9738: $newsecurl.='/'.$sec;
9739: }
9740: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
9741: if ($sec eq '') {
9742: $$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;
9743: } else {
9744: $$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;
9745: }
9746: }
9747: }
9748: }
9749: } else {
9750: $$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;
9751: $result = "error: incomplete course id\n";
9752: }
9753: return $result;
9754: }
9755:
9756: ############################################################
9757: ############################################################
9758:
9759: sub check_clone {
9760: my ($args,$linefeed) = @_;
9761: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
9762: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
9763: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
9764: my $clonemsg;
9765: my $can_clone = 0;
9766:
9767: if ($clonehome eq 'no_host') {
9768: $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'});
9769: } else {
9770: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
9771: if ($env{'request.role.domain'} eq $args->{'clonedomain'}) {
9772: $can_clone = 1;
9773: } else {
9774: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
9775: $args->{'clonedomain'},$args->{'clonecourse'});
9776: my @cloners = split(/,/,$clonehash{'cloners'});
9777: if (grep(/^\*$/,@cloners)) {
9778: $can_clone = 1;
9779: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
9780: $can_clone = 1;
9781: } else {
9782: my %roleshash =
9783: &Apache::lonnet::get_my_roles($args->{'ccuname'},
9784: $args->{'ccdomain'},
9785: 'userroles',['active'],['cc'],
9786: [$args->{'clonedomain'}]);
9787: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
9788: $can_clone = 1;
9789: } else {
9790: $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'});
9791: }
9792: }
9793: }
9794: }
9795: return ($can_clone, $clonemsg, $cloneid, $clonehome);
9796: }
9797:
9798: sub construct_course {
9799: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context) = @_;
9800: my $outcome;
9801: my $linefeed = '<br />'."\n";
9802: if ($context eq 'auto') {
9803: $linefeed = "\n";
9804: }
9805:
9806: #
9807: # Are we cloning?
9808: #
9809: my ($can_clone, $clonemsg, $cloneid, $clonehome);
9810: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
9811: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
9812: if ($context ne 'auto') {
9813: if ($clonemsg ne '') {
9814: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
9815: }
9816: }
9817: $outcome .= $clonemsg.$linefeed;
9818:
9819: if (!$can_clone) {
9820: return (0,$outcome);
9821: }
9822: }
9823:
9824: #
9825: # Open course
9826: #
9827: my $crstype = lc($args->{'crstype'});
9828: my %cenv=();
9829: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
9830: $args->{'cdescr'},
9831: $args->{'curl'},
9832: $args->{'course_home'},
9833: $args->{'nonstandard'},
9834: $args->{'crscode'},
9835: $args->{'ccuname'}.':'.
9836: $args->{'ccdomain'},
9837: $args->{'crstype'});
9838:
9839: # Note: The testing routines depend on this being output; see
9840: # Utils::Course. This needs to at least be output as a comment
9841: # if anyone ever decides to not show this, and Utils::Course::new
9842: # will need to be suitably modified.
9843: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
9844: #
9845: # Check if created correctly
9846: #
9847: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
9848: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
9849: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
9850:
9851: #
9852: # Do the cloning
9853: #
9854: if ($can_clone && $cloneid) {
9855: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
9856: if ($context ne 'auto') {
9857: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
9858: }
9859: $outcome .= $clonemsg.$linefeed;
9860: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
9861: # Copy all files
9862: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
9863: # Restore URL
9864: $cenv{'url'}=$oldcenv{'url'};
9865: # Restore title
9866: $cenv{'description'}=$oldcenv{'description'};
9867: # Mark as cloned
9868: $cenv{'clonedfrom'}=$cloneid;
9869: # Need to clone grading mode
9870: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
9871: $cenv{'grading'}=$newenv{'grading'};
9872: # Do not clone these environment entries
9873: &Apache::lonnet::del('environment',
9874: ['default_enrollment_start_date',
9875: 'default_enrollment_end_date',
9876: 'question.email',
9877: 'policy.email',
9878: 'comment.email',
9879: 'pch.users.denied',
9880: 'plc.users.denied',
9881: 'hidefromcat',
9882: 'categories'],
9883: $$crsudom,$$crsunum);
9884: }
9885:
9886: #
9887: # Set environment (will override cloned, if existing)
9888: #
9889: my @sections = ();
9890: my @xlists = ();
9891: if ($args->{'crstype'}) {
9892: $cenv{'type'}=$args->{'crstype'};
9893: }
9894: if ($args->{'crsid'}) {
9895: $cenv{'courseid'}=$args->{'crsid'};
9896: }
9897: if ($args->{'crscode'}) {
9898: $cenv{'internal.coursecode'}=$args->{'crscode'};
9899: }
9900: if ($args->{'crsquota'} ne '') {
9901: $cenv{'internal.coursequota'}=$args->{'crsquota'};
9902: } else {
9903: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
9904: }
9905: if ($args->{'ccuname'}) {
9906: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
9907: ':'.$args->{'ccdomain'};
9908: } else {
9909: $cenv{'internal.courseowner'} = $args->{'curruser'};
9910: }
9911: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
9912: if ($args->{'crssections'}) {
9913: $cenv{'internal.sectionnums'} = '';
9914: if ($args->{'crssections'} =~ m/,/) {
9915: @sections = split/,/,$args->{'crssections'};
9916: } else {
9917: $sections[0] = $args->{'crssections'};
9918: }
9919: if (@sections > 0) {
9920: foreach my $item (@sections) {
9921: my ($sec,$gp) = split/:/,$item;
9922: my $class = $args->{'crscode'}.$sec;
9923: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
9924: $cenv{'internal.sectionnums'} .= $item.',';
9925: unless ($addcheck eq 'ok') {
9926: push @badclasses, $class;
9927: }
9928: }
9929: $cenv{'internal.sectionnums'} =~ s/,$//;
9930: }
9931: }
9932: # do not hide course coordinator from staff listing,
9933: # even if privileged
9934: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9935: # add crosslistings
9936: if ($args->{'crsxlist'}) {
9937: $cenv{'internal.crosslistings'}='';
9938: if ($args->{'crsxlist'} =~ m/,/) {
9939: @xlists = split/,/,$args->{'crsxlist'};
9940: } else {
9941: $xlists[0] = $args->{'crsxlist'};
9942: }
9943: if (@xlists > 0) {
9944: foreach my $item (@xlists) {
9945: my ($xl,$gp) = split/:/,$item;
9946: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
9947: $cenv{'internal.crosslistings'} .= $item.',';
9948: unless ($addcheck eq 'ok') {
9949: push @badclasses, $xl;
9950: }
9951: }
9952: $cenv{'internal.crosslistings'} =~ s/,$//;
9953: }
9954: }
9955: if ($args->{'autoadds'}) {
9956: $cenv{'internal.autoadds'}=$args->{'autoadds'};
9957: }
9958: if ($args->{'autodrops'}) {
9959: $cenv{'internal.autodrops'}=$args->{'autodrops'};
9960: }
9961: # check for notification of enrollment changes
9962: my @notified = ();
9963: if ($args->{'notify_owner'}) {
9964: if ($args->{'ccuname'} ne '') {
9965: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
9966: }
9967: }
9968: if ($args->{'notify_dc'}) {
9969: if ($uname ne '') {
9970: push(@notified,$uname.':'.$udom);
9971: }
9972: }
9973: if (@notified > 0) {
9974: my $notifylist;
9975: if (@notified > 1) {
9976: $notifylist = join(',',@notified);
9977: } else {
9978: $notifylist = $notified[0];
9979: }
9980: $cenv{'internal.notifylist'} = $notifylist;
9981: }
9982: if (@badclasses > 0) {
9983: my %lt=&Apache::lonlocal::texthash(
9984: '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',
9985: 'dnhr' => 'does not have rights to access enrollment in these classes',
9986: 'adby' => 'as determined by the policies of your institution on access to official classlists'
9987: );
9988: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
9989: ' ('.$lt{'adby'}.')';
9990: if ($context eq 'auto') {
9991: $outcome .= $badclass_msg.$linefeed;
9992: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
9993: foreach my $item (@badclasses) {
9994: if ($context eq 'auto') {
9995: $outcome .= " - $item\n";
9996: } else {
9997: $outcome .= "<li>$item</li>\n";
9998: }
9999: }
10000: if ($context eq 'auto') {
10001: $outcome .= $linefeed;
10002: } else {
10003: $outcome .= "</ul><br /><br /></div>\n";
10004: }
10005: }
10006: }
10007: if ($args->{'no_end_date'}) {
10008: $args->{'endaccess'} = 0;
10009: }
10010: $cenv{'internal.autostart'}=$args->{'enrollstart'};
10011: $cenv{'internal.autoend'}=$args->{'enrollend'};
10012: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
10013: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
10014: if ($args->{'showphotos'}) {
10015: $cenv{'internal.showphotos'}=$args->{'showphotos'};
10016: }
10017: $cenv{'internal.authtype'} = $args->{'authtype'};
10018: $cenv{'internal.autharg'} = $args->{'autharg'};
10019: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
10020: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
10021: 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');
10022: if ($context eq 'auto') {
10023: $outcome .= $krb_msg;
10024: } else {
10025: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
10026: }
10027: $outcome .= $linefeed;
10028: }
10029: }
10030: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
10031: if ($args->{'setpolicy'}) {
10032: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10033: }
10034: if ($args->{'setcontent'}) {
10035: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10036: }
10037: }
10038: if ($args->{'reshome'}) {
10039: $cenv{'reshome'}=$args->{'reshome'}.'/';
10040: $cenv{'reshome'}=~s/\/+$/\//;
10041: }
10042: #
10043: # course has keyed access
10044: #
10045: if ($args->{'setkeys'}) {
10046: $cenv{'keyaccess'}='yes';
10047: }
10048: # if specified, key authority is not course, but user
10049: # only active if keyaccess is yes
10050: if ($args->{'keyauth'}) {
10051: my ($user,$domain) = split(':',$args->{'keyauth'});
10052: $user = &LONCAPA::clean_username($user);
10053: $domain = &LONCAPA::clean_username($domain);
10054: if ($user ne '' && $domain ne '') {
10055: $cenv{'keyauth'}=$user.':'.$domain;
10056: }
10057: }
10058:
10059: if ($args->{'disresdis'}) {
10060: $cenv{'pch.roles.denied'}='st';
10061: }
10062: if ($args->{'disablechat'}) {
10063: $cenv{'plc.roles.denied'}='st';
10064: }
10065:
10066: # Record we've not yet viewed the Course Initialization Helper for this
10067: # course
10068: $cenv{'course.helper.not.run'} = 1;
10069: #
10070: # Use new Randomseed
10071: #
10072: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
10073: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
10074: #
10075: # The encryption code and receipt prefix for this course
10076: #
10077: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
10078: $cenv{'internal.encpref'}=100+int(9*rand(99));
10079: #
10080: # By default, use standard grading
10081: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
10082:
10083: $outcome .= $linefeed.&mt('Setting environment').': '.
10084: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
10085: #
10086: # Open all assignments
10087: #
10088: if ($args->{'openall'}) {
10089: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
10090: my %storecontent = ($storeunder => time,
10091: $storeunder.'.type' => 'date_start');
10092:
10093: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
10094: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
10095: }
10096: #
10097: # Set first page
10098: #
10099: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
10100: || ($cloneid)) {
10101: use LONCAPA::map;
10102: $outcome .= &mt('Setting first resource').': ';
10103:
10104: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
10105: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
10106:
10107: $outcome .= ($fatal?$errtext:'read ok').' - ';
10108: my $title; my $url;
10109: if ($args->{'firstres'} eq 'syl') {
10110: $title=&mt('Syllabus');
10111: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
10112: } else {
10113: $title=&mt('Navigate Contents');
10114: $url='/adm/navmaps';
10115: }
10116:
10117: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
10118: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
10119:
10120: if ($errtext) { $fatal=2; }
10121: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
10122: }
10123:
10124: return (1,$outcome);
10125: }
10126:
10127: ############################################################
10128: ############################################################
10129:
10130: sub course_type {
10131: my ($cid) = @_;
10132: if (!defined($cid)) {
10133: $cid = $env{'request.course.id'};
10134: }
10135: if (defined($env{'course.'.$cid.'.type'})) {
10136: return $env{'course.'.$cid.'.type'};
10137: } else {
10138: return 'Course';
10139: }
10140: }
10141:
10142: sub group_term {
10143: my $crstype = &course_type();
10144: my %names = (
10145: 'Course' => 'group',
10146: 'Group' => 'team',
10147: );
10148: return $names{$crstype};
10149: }
10150:
10151: sub icon {
10152: my ($file)=@_;
10153: my $curfext = lc((split(/\./,$file))[-1]);
10154: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
10155: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
10156: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
10157: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
10158: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
10159: $curfext.".gif") {
10160: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
10161: $curfext.".gif";
10162: }
10163: }
10164: return &lonhttpdurl($iconname);
10165: }
10166:
10167: sub lonhttpdurl {
10168: #
10169: # Had been used for "small fry" static images on separate port 8080.
10170: # Modify here if lightweight http functionality desired again.
10171: # Currently eliminated due to increasing firewall issues.
10172: #
10173: my ($url)=@_;
10174: return $url;
10175: }
10176:
10177: sub connection_aborted {
10178: my ($r)=@_;
10179: $r->print(" ");$r->rflush();
10180: my $c = $r->connection;
10181: return $c->aborted();
10182: }
10183:
10184: # Escapes strings that may have embedded 's that will be put into
10185: # strings as 'strings'.
10186: sub escape_single {
10187: my ($input) = @_;
10188: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
10189: $input =~ s/\'/\\\'/g; # Esacpe the 's....
10190: return $input;
10191: }
10192:
10193: # Same as escape_single, but escape's "'s This
10194: # can be used for "strings"
10195: sub escape_double {
10196: my ($input) = @_;
10197: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
10198: $input =~ s/\"/\\\"/g; # Esacpe the "s....
10199: return $input;
10200: }
10201:
10202: # Escapes the last element of a full URL.
10203: sub escape_url {
10204: my ($url) = @_;
10205: my @urlslices = split(/\//, $url,-1);
10206: my $lastitem = &escape(pop(@urlslices));
10207: return join('/',@urlslices).'/'.$lastitem;
10208: }
10209:
10210: # -------------------------------------------------------- Initliaze user login
10211: sub init_user_environment {
10212: my ($r, $username, $domain, $authhost, $form, $args) = @_;
10213: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
10214:
10215: my $public=($username eq 'public' && $domain eq 'public');
10216:
10217: # See if old ID present, if so, remove
10218:
10219: my ($filename,$cookie,$userroles);
10220: my $now=time;
10221:
10222: if ($public) {
10223: my $max_public=100;
10224: my $oldest;
10225: my $oldest_time=0;
10226: for(my $next=1;$next<=$max_public;$next++) {
10227: if (-e $lonids."/publicuser_$next.id") {
10228: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
10229: if ($mtime<$oldest_time || !$oldest_time) {
10230: $oldest_time=$mtime;
10231: $oldest=$next;
10232: }
10233: } else {
10234: $cookie="publicuser_$next";
10235: last;
10236: }
10237: }
10238: if (!$cookie) { $cookie="publicuser_$oldest"; }
10239: } else {
10240: # if this isn't a robot, kill any existing non-robot sessions
10241: if (!$args->{'robot'}) {
10242: opendir(DIR,$lonids);
10243: while ($filename=readdir(DIR)) {
10244: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
10245: unlink($lonids.'/'.$filename);
10246: }
10247: }
10248: closedir(DIR);
10249: }
10250: # Give them a new cookie
10251: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
10252: : $now.$$.int(rand(10000)));
10253: $cookie="$username\_$id\_$domain\_$authhost";
10254:
10255: # Initialize roles
10256:
10257: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
10258: }
10259: # ------------------------------------ Check browser type and MathML capability
10260:
10261: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
10262: $clientunicode,$clientos) = &decode_user_agent($r);
10263:
10264: # -------------------------------------- Any accessibility options to remember?
10265: if (($form->{'interface'}) && ($form->{'remember'} eq 'true')) {
10266: foreach my $option ('imagesuppress','appletsuppress',
10267: 'embedsuppress','fontenhance','blackwhite') {
10268: if ($form->{$option} eq 'true') {
10269: &Apache::lonnet::put('environment',{$option => 'on'},
10270: $domain,$username);
10271: } else {
10272: &Apache::lonnet::del('environment',[$option],
10273: $domain,$username);
10274: }
10275: }
10276: }
10277: # ------------------------------------------------------------- Get environment
10278:
10279: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
10280: my ($tmp) = keys(%userenv);
10281: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
10282: # default remote control to off
10283: if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
10284: } else {
10285: undef(%userenv);
10286: }
10287: if (($userenv{'interface'}) && (!$form->{'interface'})) {
10288: $form->{'interface'}=$userenv{'interface'};
10289: }
10290: $env{'environment.remote'}=$userenv{'remote'};
10291: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
10292:
10293: # --------------- Do not trust query string to be put directly into environment
10294: foreach my $option ('imagesuppress','appletsuppress',
10295: 'embedsuppress','fontenhance','blackwhite',
10296: 'interface','localpath','localres') {
10297: $form->{$option}=~s/[\n\r\=]//gs;
10298: }
10299: # --------------------------------------------------------- Write first profile
10300:
10301: {
10302: my %initial_env =
10303: ("user.name" => $username,
10304: "user.domain" => $domain,
10305: "user.home" => $authhost,
10306: "browser.type" => $clientbrowser,
10307: "browser.version" => $clientversion,
10308: "browser.mathml" => $clientmathml,
10309: "browser.unicode" => $clientunicode,
10310: "browser.os" => $clientos,
10311: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
10312: "request.course.fn" => '',
10313: "request.course.uri" => '',
10314: "request.course.sec" => '',
10315: "request.role" => 'cm',
10316: "request.role.adv" => $env{'user.adv'},
10317: "request.host" => $ENV{'REMOTE_ADDR'},);
10318:
10319: if ($form->{'localpath'}) {
10320: $initial_env{"browser.localpath"} = $form->{'localpath'};
10321: $initial_env{"browser.localres"} = $form->{'localres'};
10322: }
10323:
10324: if ($public) {
10325: $initial_env{"environment.remote"} = "off";
10326: }
10327: if ($form->{'interface'}) {
10328: $form->{'interface'}=~s/\W//gs;
10329: $initial_env{"browser.interface"} = $form->{'interface'};
10330: $env{'browser.interface'}=$form->{'interface'};
10331: foreach my $option ('imagesuppress','appletsuppress',
10332: 'embedsuppress','fontenhance','blackwhite') {
10333: if (($form->{$option} eq 'true') ||
10334: ($userenv{$option} eq 'on')) {
10335: $initial_env{"browser.$option"} = "on";
10336: }
10337: }
10338: }
10339:
10340: foreach my $tool ('aboutme','blog','portfolio') {
10341: $userenv{'availabletools.'.$tool} =
10342: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload');
10343: }
10344:
10345: foreach my $crstype ('official','unofficial') {
10346: $userenv{'canrequest.'.$crstype} =
10347: &Apache::lonnet::usertools_access($username,$domain,$crstype,
10348: 'reload','requestcourses');
10349: }
10350:
10351: $env{'user.environment'} = "$lonids/$cookie.id";
10352:
10353: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
10354: &GDBM_WRCREAT(),0640)) {
10355: &_add_to_env(\%disk_env,\%initial_env);
10356: &_add_to_env(\%disk_env,\%userenv,'environment.');
10357: &_add_to_env(\%disk_env,$userroles);
10358: if (ref($args->{'extra_env'})) {
10359: &_add_to_env(\%disk_env,$args->{'extra_env'});
10360: }
10361: untie(%disk_env);
10362: } else {
10363: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
10364: 'Could not create environment storage in lonauth: '.$!.'</span>');
10365: return 'error: '.$!;
10366: }
10367: }
10368: $env{'request.role'}='cm';
10369: $env{'request.role.adv'}=$env{'user.adv'};
10370: $env{'browser.type'}=$clientbrowser;
10371:
10372: return $cookie;
10373:
10374: }
10375:
10376: sub _add_to_env {
10377: my ($idf,$env_data,$prefix) = @_;
10378: if (ref($env_data) eq 'HASH') {
10379: while (my ($key,$value) = each(%$env_data)) {
10380: $idf->{$prefix.$key} = $value;
10381: $env{$prefix.$key} = $value;
10382: }
10383: }
10384: }
10385:
10386: # --- Get the symbolic name of a problem and the url
10387: sub get_symb {
10388: my ($request,$silent) = @_;
10389: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
10390: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
10391: if ($symb eq '') {
10392: if (!$silent) {
10393: $request->print("Unable to handle ambiguous references:$url:.");
10394: return ();
10395: }
10396: }
10397: &Apache::lonenc::check_decrypt(\$symb);
10398: return ($symb);
10399: }
10400:
10401: # --------------------------------------------------------------Get annotation
10402:
10403: sub get_annotation {
10404: my ($symb,$enc) = @_;
10405:
10406: my $key = $symb;
10407: if (!$enc) {
10408: $key =
10409: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
10410: }
10411: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
10412: return $annotation{$key};
10413: }
10414:
10415: sub clean_symb {
10416: my ($symb,$delete_enc) = @_;
10417:
10418: &Apache::lonenc::check_decrypt(\$symb);
10419: my $enc = $env{'request.enc'};
10420: if ($delete_enc) {
10421: delete($env{'request.enc'});
10422: }
10423:
10424: return ($symb,$enc);
10425: }
10426:
10427: =pod
10428:
10429: =back
10430:
10431: =cut
10432:
10433: 1;
10434: __END__;
10435:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>