1: # The LearningOnline Network with CAPA
2: # a pile of common routines
3: #
4: # $Id: loncommon.pm,v 1.907 2009/10/31 16:17:07 raeburn Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: # Makes a table out of the previous attempts
30: # Inputs result_from_symbread, user, domain, course_id
31: # Reads in non-network-related .tab files
32:
33: # POD header:
34:
35: =pod
36:
37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
45:
46: =head1 OVERVIEW
47:
48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
55: package Apache::loncommon;
56:
57: use strict;
58: use Apache::lonnet;
59: use GDBM_File;
60: use POSIX qw(strftime mktime);
61: use Apache::lonmenu();
62: use Apache::lonenc();
63: use Apache::lonlocal;
64: use Apache::lonnet();
65: use HTML::Entities;
66: use Apache::lonhtmlcommon();
67: use Apache::loncoursedata();
68: use Apache::lontexconvert();
69: use Apache::lonclonecourse();
70: use LONCAPA qw(:DEFAULT :match);
71: use DateTime::TimeZone;
72: use DateTime::Locale::Catalog;
73:
74: # ---------------------------------------------- Designs
75: use vars qw(%defaultdesign);
76:
77: my $readit;
78:
79:
80: ##
81: ## Global Variables
82: ##
83:
84:
85: # ----------------------------------------------- SSI with retries:
86: #
87:
88: =pod
89:
90: =head1 Server Side include with retries:
91:
92: =over 4
93:
94: =item * &ssi_with_retries(resource,retries form)
95:
96: Performs an ssi with some number of retries. Retries continue either
97: until the result is ok or until the retry count supplied by the
98: caller is exhausted.
99:
100: Inputs:
101:
102: =over 4
103:
104: resource - Identifies the resource to insert.
105:
106: retries - Count of the number of retries allowed.
107:
108: form - Hash that identifies the rendering options.
109:
110: =back
111:
112: Returns:
113:
114: =over 4
115:
116: content - The content of the response. If retries were exhausted this is empty.
117:
118: response - The response from the last attempt (which may or may not have been successful.
119:
120: =back
121:
122: =back
123:
124: =cut
125:
126: sub ssi_with_retries {
127: my ($resource, $retries, %form) = @_;
128:
129:
130: my $ok = 0; # True if we got a good response.
131: my $content;
132: my $response;
133:
134: # Try to get the ssi done. within the retries count:
135:
136: do {
137: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
138: $ok = $response->is_success;
139: if (!$ok) {
140: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
141: }
142: $retries--;
143: } while (!$ok && ($retries > 0));
144:
145: if (!$ok) {
146: $content = ''; # On error return an empty content.
147: }
148: return ($content, $response);
149:
150: }
151:
152:
153:
154: # ----------------------------------------------- Filetypes/Languages/Copyright
155: my %language;
156: my %supported_language;
157: my %cprtag;
158: my %scprtag;
159: my %fe; my %fd; my %fm;
160: my %category_extensions;
161:
162: # ---------------------------------------------- Thesaurus variables
163: #
164: # %Keywords:
165: # A hash used by &keyword to determine if a word is considered a keyword.
166: # $thesaurus_db_file
167: # Scalar containing the full path to the thesaurus database.
168:
169: my %Keywords;
170: my $thesaurus_db_file;
171:
172: #
173: # Initialize values from language.tab, copyright.tab, filetypes.tab,
174: # thesaurus.tab, and filecategories.tab.
175: #
176: BEGIN {
177: # Variable initialization
178: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
179: #
180: unless ($readit) {
181: # ------------------------------------------------------------------- languages
182: {
183: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
184: '/language.tab';
185: if ( open(my $fh,"<$langtabfile") ) {
186: while (my $line = <$fh>) {
187: next if ($line=~/^\#/);
188: chomp($line);
189: my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$line));
190: $language{$key}=$val.' - '.$enc;
191: if ($sup) {
192: $supported_language{$key}=$sup;
193: }
194: }
195: close($fh);
196: }
197: }
198: # ------------------------------------------------------------------ copyrights
199: {
200: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
201: '/copyright.tab';
202: if ( open (my $fh,"<$copyrightfile") ) {
203: while (my $line = <$fh>) {
204: next if ($line=~/^\#/);
205: chomp($line);
206: my ($key,$val)=(split(/\s+/,$line,2));
207: $cprtag{$key}=$val;
208: }
209: close($fh);
210: }
211: }
212: # ----------------------------------------------------------- source copyrights
213: {
214: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
215: '/source_copyright.tab';
216: if ( open (my $fh,"<$sourcecopyrightfile") ) {
217: while (my $line = <$fh>) {
218: next if ($line =~ /^\#/);
219: chomp($line);
220: my ($key,$val)=(split(/\s+/,$line,2));
221: $scprtag{$key}=$val;
222: }
223: close($fh);
224: }
225: }
226:
227: # -------------------------------------------------------------- default domain designs
228: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
229: my $designfile = $designdir.'/default.tab';
230: if ( open (my $fh,"<$designfile") ) {
231: while (my $line = <$fh>) {
232: next if ($line =~ /^\#/);
233: chomp($line);
234: my ($key,$val)=(split(/\=/,$line));
235: if ($val) { $defaultdesign{$key}=$val; }
236: }
237: close($fh);
238: }
239:
240: # ------------------------------------------------------------- file categories
241: {
242: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
243: '/filecategories.tab';
244: if ( open (my $fh,"<$categoryfile") ) {
245: while (my $line = <$fh>) {
246: next if ($line =~ /^\#/);
247: chomp($line);
248: my ($extension,$category)=(split(/\s+/,$line,2));
249: push @{$category_extensions{lc($category)}},$extension;
250: }
251: close($fh);
252: }
253:
254: }
255: # ------------------------------------------------------------------ file types
256: {
257: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
258: '/filetypes.tab';
259: if ( open (my $fh,"<$typesfile") ) {
260: while (my $line = <$fh>) {
261: next if ($line =~ /^\#/);
262: chomp($line);
263: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
264: if ($descr ne '') {
265: $fe{$ending}=lc($emb);
266: $fd{$ending}=$descr;
267: if ($mime ne 'unk') { $fm{$ending}=$mime; }
268: }
269: }
270: close($fh);
271: }
272: }
273: &Apache::lonnet::logthis(
274: "<span style='color:yellow;'>INFO: Read file types</span>");
275: $readit=1;
276: } # end of unless($readit)
277:
278: }
279:
280: ###############################################################
281: ## HTML and Javascript Helper Functions ##
282: ###############################################################
283:
284: =pod
285:
286: =head1 HTML and Javascript Functions
287:
288: =over 4
289:
290: =item * &browser_and_searcher_javascript()
291:
292: X<browsing, javascript>X<searching, javascript>Returns a string
293: containing javascript with two functions, C<openbrowser> and
294: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
295: tags.
296:
297: =item * &openbrowser(formname,elementname,only,omit) [javascript]
298:
299: inputs: formname, elementname, only, omit
300:
301: formname and elementname indicate the name of the html form and name of
302: the element that the results of the browsing selection are to be placed in.
303:
304: Specifying 'only' will restrict the browser to displaying only files
305: with the given extension. Can be a comma separated list.
306:
307: Specifying 'omit' will restrict the browser to NOT displaying files
308: with the given extension. Can be a comma separated list.
309:
310: =item * &opensearcher(formname,elementname) [javascript]
311:
312: Inputs: formname, elementname
313:
314: formname and elementname specify the name of the html form and the name
315: of the element the selection from the search results will be placed in.
316:
317: =cut
318:
319: sub browser_and_searcher_javascript {
320: my ($mode)=@_;
321: if (!defined($mode)) { $mode='edit'; }
322: my $resurl=&escape_single(&lastresurl());
323: return <<END;
324: // <!-- BEGIN LON-CAPA Internal
325: var editbrowser = null;
326: function openbrowser(formname,elementname,only,omit,titleelement) {
327: var url = '$resurl/?';
328: if (editbrowser == null) {
329: url += 'launch=1&';
330: }
331: url += 'catalogmode=interactive&';
332: url += 'mode=$mode&';
333: url += 'inhibitmenu=yes&';
334: url += 'form=' + formname + '&';
335: if (only != null) {
336: url += 'only=' + only + '&';
337: } else {
338: url += 'only=&';
339: }
340: if (omit != null) {
341: url += 'omit=' + omit + '&';
342: } else {
343: url += 'omit=&';
344: }
345: if (titleelement != null) {
346: url += 'titleelement=' + titleelement + '&';
347: } else {
348: url += 'titleelement=&';
349: }
350: url += 'element=' + elementname + '';
351: var title = 'Browser';
352: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
353: options += ',width=700,height=600';
354: editbrowser = open(url,title,options,'1');
355: editbrowser.focus();
356: }
357: var editsearcher;
358: function opensearcher(formname,elementname,titleelement) {
359: var url = '/adm/searchcat?';
360: if (editsearcher == null) {
361: url += 'launch=1&';
362: }
363: url += 'catalogmode=interactive&';
364: url += 'mode=$mode&';
365: url += 'form=' + formname + '&';
366: if (titleelement != null) {
367: url += 'titleelement=' + titleelement + '&';
368: } else {
369: url += 'titleelement=&';
370: }
371: url += 'element=' + elementname + '';
372: var title = 'Search';
373: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
374: options += ',width=700,height=600';
375: editsearcher = open(url,title,options,'1');
376: editsearcher.focus();
377: }
378: // END LON-CAPA Internal -->
379: END
380: }
381:
382: sub lastresurl {
383: if ($env{'environment.lastresurl'}) {
384: return $env{'environment.lastresurl'}
385: } else {
386: return '/res';
387: }
388: }
389:
390: sub storeresurl {
391: my $resurl=&Apache::lonnet::clutter(shift);
392: unless ($resurl=~/^\/res/) { return 0; }
393: $resurl=~s/\/$//;
394: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
395: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
396: return 1;
397: }
398:
399: sub studentbrowser_javascript {
400: unless (
401: (($env{'request.course.id'}) &&
402: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
403: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
404: '/'.$env{'request.course.sec'})
405: ))
406: || ($env{'request.role'}=~/^(au|dc|su)/)
407: ) { return ''; }
408: return (<<'ENDSTDBRW');
409: <script type="text/javascript" language="Javascript">
410: // <![CDATA[
411: var stdeditbrowser;
412: function openstdbrowser(formname,uname,udom,roleflag,ignorefilter,courseadvonly) {
413: var url = '/adm/pickstudent?';
414: var filter;
415: if (!ignorefilter) {
416: eval('filter=document.'+formname+'.'+uname+'.value;');
417: }
418: if (filter != null) {
419: if (filter != '') {
420: url += 'filter='+filter+'&';
421: }
422: }
423: url += 'form=' + formname + '&unameelement='+uname+
424: '&udomelement='+udom;
425: if (roleflag) { url+="&roles=1"; }
426: if (courseadvonly) { url+="&courseadvonly=1"; }
427: var title = 'Student_Browser';
428: var options = 'scrollbars=1,resizable=1,menubar=0';
429: options += ',width=700,height=600';
430: stdeditbrowser = open(url,title,options,'1');
431: stdeditbrowser.focus();
432: }
433: // ]]>
434: </script>
435: ENDSTDBRW
436: }
437:
438: sub selectstudent_link {
439: my ($form,$unameele,$udomele,$courseadvonly)=@_;
440: my $callargs = "'".$form."','".$unameele."','".$udomele."'";
441: if ($env{'request.course.id'}) {
442: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
443: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
444: '/'.$env{'request.course.sec'})) {
445: return '';
446: }
447: if ($courseadvonly) {
448: $callargs .= ",'',1,1";
449: }
450: return '<span class="LC_nobreak">'.
451: '<a href="javascript:openstdbrowser('.$callargs.');">'.
452: &mt('Select User').'</a></span>';
453: }
454: if ($env{'request.role'}=~/^(au|dc|su)/) {
455: $callargs .= ",1";
456: return '<span class="LC_nobreak">'.
457: '<a href="javascript:openstdbrowser('.$callargs.');">'.
458: &mt('Select User').'</a></span>';
459: }
460: return '';
461: }
462:
463: sub authorbrowser_javascript {
464: return <<"ENDAUTHORBRW";
465: <script type="text/javascript" language="JavaScript">
466: // <![CDATA[
467: var stdeditbrowser;
468:
469: function openauthorbrowser(formname,udom) {
470: var url = '/adm/pickauthor?';
471: url += 'form='+formname+'&roledom='+udom;
472: var title = 'Author_Browser';
473: var options = 'scrollbars=1,resizable=1,menubar=0';
474: options += ',width=700,height=600';
475: stdeditbrowser = open(url,title,options,'1');
476: stdeditbrowser.focus();
477: }
478:
479: // ]]>
480: </script>
481: ENDAUTHORBRW
482: }
483:
484: sub coursebrowser_javascript {
485: my ($domainfilter,$sec_element,$formname,$role_element)=@_;
486: my $crs_or_grp_alert = &mt('Please select the type of LON-CAPA entity - Course or Community - for which you wish to add/modify a user role.');
487: my $id_functions = &javascript_index_functions();
488: my $output = '
489: <script type="text/javascript" language="JavaScript">
490: // <![CDATA[
491: var stdeditbrowser;'."\n";
492:
493: $output .= <<"ENDSTDBRW";
494: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,crstype) {
495: var url = '/adm/pickcourse?';
496: var formid = getFormIdByName(formname);
497: var domainfilter = getDomainFromSelectbox(formname,udom);
498: if (domainfilter != null) {
499: if (domainfilter != '') {
500: url += 'domainfilter='+domainfilter+'&';
501: }
502: }
503: url += 'form=' + formname + '&cnumelement='+uname+
504: '&cdomelement='+udom+
505: '&cnameelement='+desc;
506: if (extra_element !=null && extra_element != '') {
507: if (formname == 'rolechoice' || formname == 'studentform') {
508: url += '&roleelement='+extra_element;
509: if (domainfilter == null || domainfilter == '') {
510: url += '&domainfilter='+extra_element;
511: }
512: }
513: else {
514: if (formname == 'portform') {
515: url += '&setroles='+extra_element;
516: } else {
517: if (formname == 'rules') {
518: url += '&fixeddom='+extra_element;
519: }
520: }
521: }
522: }
523: if (formname == 'ccrs') {
524: var ownername = document.forms[formid].ccuname.value;
525: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
526: url += '&cloner='+ownername+':'+ownerdom;
527: }
528: if (multflag !=null && multflag != '') {
529: url += '&multiple='+multflag;
530: }
531: if (crstype == 'Course/Community') {
532: if (formname == 'cu') {
533: crstype = document.cu.crstype.options[document.cu.crstype.selectedIndex].value;
534: if (crstype == "") {
535: alert("$crs_or_grp_alert");
536: return;
537: }
538: }
539: }
540: if (crstype !=null && crstype != '') {
541: url += '&type='+crstype;
542: }
543: var title = 'Course_Browser';
544: var options = 'scrollbars=1,resizable=1,menubar=0';
545: options += ',width=700,height=600';
546: stdeditbrowser = open(url,title,options,'1');
547: stdeditbrowser.focus();
548: }
549: $id_functions
550: ENDSTDBRW
551: if (($sec_element ne '') || ($role_element ne '')) {
552: $output .= &setsec_javascript($sec_element,$formname,$role_element);
553: }
554: $output .= '
555: // ]]>
556: </script>';
557: return $output;
558: }
559:
560: sub javascript_index_functions {
561: return <<"ENDJS";
562:
563: function getFormIdByName(formname) {
564: for (var i=0;i<document.forms.length;i++) {
565: if (document.forms[i].name == formname) {
566: return i;
567: }
568: }
569: return -1;
570: }
571:
572: function getIndexByName(formid,item) {
573: for (var i=0;i<document.forms[formid].elements.length;i++) {
574: if (document.forms[formid].elements[i].name == item) {
575: return i;
576: }
577: }
578: return -1;
579: }
580:
581: function getDomainFromSelectbox(formname,udom) {
582: var userdom;
583: var formid = getFormIdByName(formname);
584: if (formid > -1) {
585: var domid = getIndexByName(formid,udom);
586: if (domid > -1) {
587: if (document.forms[formid].elements[domid].type == 'select-one') {
588: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
589: }
590: if (document.forms[formid].elements[domid].type == 'hidden') {
591: userdom=document.forms[formid].elements[domid].value;
592: }
593: }
594: }
595: return userdom;
596: }
597:
598: ENDJS
599:
600: }
601:
602: sub userbrowser_javascript {
603: my $id_functions = &javascript_index_functions();
604: return <<"ENDUSERBRW";
605:
606: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
607: var url = '/adm/pickuser?';
608: var userdom = getDomainFromSelectbox(formname,udom);
609: if (userdom != null) {
610: if (userdom != '') {
611: url += 'srchdom='+userdom+'&';
612: }
613: }
614: url += 'form=' + formname + '&unameelement='+uname+
615: '&udomelement='+udom+
616: '&ulastelement='+ulast+
617: '&ufirstelement='+ufirst+
618: '&uemailelement='+uemail+
619: '&hideudomelement='+hideudom+
620: '&coursedom='+crsdom;
621: if ((caller != null) && (caller != undefined)) {
622: url += '&caller='+caller;
623: }
624: var title = 'User_Browser';
625: var options = 'scrollbars=1,resizable=1,menubar=0';
626: options += ',width=700,height=600';
627: var stdeditbrowser = open(url,title,options,'1');
628: stdeditbrowser.focus();
629: }
630:
631: function fix_domain (formname,udom,origdom,uname) {
632: var formid = getFormIdByName(formname);
633: if (formid > -1) {
634: var unameid = getIndexByName(formid,uname);
635: var domid = getIndexByName(formid,udom);
636: var hidedomid = getIndexByName(formid,origdom);
637: if (hidedomid > -1) {
638: var fixeddom = document.forms[formid].elements[hidedomid].value;
639: var unameval = document.forms[formid].elements[unameid].value;
640: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
641: if (domid > -1) {
642: var slct = document.forms[formid].elements[domid];
643: if (slct.type == 'select-one') {
644: var i;
645: for (i=0;i<slct.length;i++) {
646: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
647: }
648: }
649: if (slct.type == 'hidden') {
650: slct.value = fixeddom;
651: }
652: }
653: }
654: }
655: }
656: return;
657: }
658:
659: $id_functions
660: ENDUSERBRW
661: }
662:
663: sub setsec_javascript {
664: my ($sec_element,$formname,$role_element) = @_;
665: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
666: $communityrolestr);
667: if ($role_element ne '') {
668: my @allroles = ('st','ta','ep','in','ad');
669: foreach my $crstype ('Course','Community') {
670: if ($crstype eq 'Community') {
671: foreach my $role (@allroles) {
672: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
673: }
674: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
675: } else {
676: foreach my $role (@allroles) {
677: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
678: }
679: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
680: }
681: }
682: $rolestr = '"'.join('","',@allroles).'"';
683: $courserolestr = '"'.join('","',@courserolenames).'"';
684: $communityrolestr = '"'.join('","',@communityrolenames).'"';
685: }
686: my $setsections = qq|
687: function setSect(sectionlist) {
688: var sectionsArray = new Array();
689: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
690: sectionsArray = sectionlist.split(",");
691: }
692: var numSections = sectionsArray.length;
693: document.$formname.$sec_element.length = 0;
694: if (numSections == 0) {
695: document.$formname.$sec_element.multiple=false;
696: document.$formname.$sec_element.size=1;
697: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
698: } else {
699: if (numSections == 1) {
700: document.$formname.$sec_element.multiple=false;
701: document.$formname.$sec_element.size=1;
702: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
703: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
704: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
705: } else {
706: for (var i=0; i<numSections; i++) {
707: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
708: }
709: document.$formname.$sec_element.multiple=true
710: if (numSections < 3) {
711: document.$formname.$sec_element.size=numSections;
712: } else {
713: document.$formname.$sec_element.size=3;
714: }
715: document.$formname.$sec_element.options[0].selected = false
716: }
717: }
718: }
719:
720: function setRole(crstype) {
721: |;
722: if ($role_element eq '') {
723: $setsections .= ' return;
724: }
725: ';
726: } else {
727: $setsections .= qq|
728: var elementLength = document.$formname.$role_element.length;
729: var allroles = Array($rolestr);
730: var courserolenames = Array($courserolestr);
731: var communityrolenames = Array($communityrolestr);
732: if (elementLength != undefined) {
733: if (document.$formname.$role_element.options[5].value == 'cc') {
734: if (crstype == 'Course') {
735: return;
736: } else {
737: allroles[5] = 'co';
738: for (var i=0; i<6; i++) {
739: document.$formname.$role_element.options[i].value = allroles[i];
740: document.$formname.$role_element.options[i].text = communityrolenames[i];
741: }
742: }
743: } else {
744: if (crstype == 'Community') {
745: return;
746: } else {
747: allroles[5] = 'cc';
748: for (var i=0; i<6; i++) {
749: document.$formname.$role_element.options[i].value = allroles[i];
750: document.$formname.$role_element.options[i].text = courserolenames[i];
751: }
752: }
753: }
754: }
755: return;
756: }
757: |;
758: }
759: return $setsections;
760: }
761:
762: sub selectcourse_link {
763: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype)=@_;
764: my $linktext = &mt('Select Course');
765: if ($selecttype eq 'Community') {
766: $linktext = &mt('Select Community');
767: } elsif ($selecttype eq 'Course/Community') {
768: $linktext = &mt('Select Course/Community');
769: $selecttype = 'Course';
770: }
771: return '<span class="LC_nobreak">'
772: ."<a href='"
773: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
774: .'","'.$udomele.'","'.$desc.'","'.$extra_element
775: .'","'.$multflag.'","'.$selecttype.'");'
776: ."'>".$linktext.'</a>'
777: .'</span>';
778: }
779:
780: sub selectauthor_link {
781: my ($form,$udom)=@_;
782: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
783: &mt('Select Author').'</a>';
784: }
785:
786: sub selectuser_link {
787: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
788: $coursedom,$linktext,$caller) = @_;
789: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
790: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
791: ');">'.$linktext.'</a>';
792: }
793:
794: sub check_uncheck_jscript {
795: my $jscript = <<"ENDSCRT";
796: function checkAll(field) {
797: if (field.length > 0) {
798: for (i = 0; i < field.length; i++) {
799: field[i].checked = true ;
800: }
801: } else {
802: field.checked = true
803: }
804: }
805:
806: function uncheckAll(field) {
807: if (field.length > 0) {
808: for (i = 0; i < field.length; i++) {
809: field[i].checked = false ;
810: }
811: } else {
812: field.checked = false ;
813: }
814: }
815: ENDSCRT
816: return $jscript;
817: }
818:
819: sub select_timezone {
820: my ($name,$selected,$onchange,$includeempty)=@_;
821: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
822: if ($includeempty) {
823: $output .= '<option value=""';
824: if (($selected eq '') || ($selected eq 'local')) {
825: $output .= ' selected="selected" ';
826: }
827: $output .= '> </option>';
828: }
829: my @timezones = DateTime::TimeZone->all_names;
830: foreach my $tzone (@timezones) {
831: $output.= '<option value="'.$tzone.'"';
832: if ($tzone eq $selected) {
833: $output.=' selected="selected"';
834: }
835: $output.=">$tzone</option>\n";
836: }
837: $output.="</select>";
838: return $output;
839: }
840:
841: sub select_datelocale {
842: my ($name,$selected,$onchange,$includeempty)=@_;
843: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
844: if ($includeempty) {
845: $output .= '<option value=""';
846: if ($selected eq '') {
847: $output .= ' selected="selected" ';
848: }
849: $output .= '> </option>';
850: }
851: my (@possibles,%locale_names);
852: my @locales = DateTime::Locale::Catalog::Locales;
853: foreach my $locale (@locales) {
854: if (ref($locale) eq 'HASH') {
855: my $id = $locale->{'id'};
856: if ($id ne '') {
857: my $en_terr = $locale->{'en_territory'};
858: my $native_terr = $locale->{'native_territory'};
859: my @languages = &Apache::lonlocal::preferred_languages();
860: if (grep(/^en$/,@languages) || !@languages) {
861: if ($en_terr ne '') {
862: $locale_names{$id} = '('.$en_terr.')';
863: } elsif ($native_terr ne '') {
864: $locale_names{$id} = $native_terr;
865: }
866: } else {
867: if ($native_terr ne '') {
868: $locale_names{$id} = $native_terr.' ';
869: } elsif ($en_terr ne '') {
870: $locale_names{$id} = '('.$en_terr.')';
871: }
872: }
873: push (@possibles,$id);
874: }
875: }
876: }
877: foreach my $item (sort(@possibles)) {
878: $output.= '<option value="'.$item.'"';
879: if ($item eq $selected) {
880: $output.=' selected="selected"';
881: }
882: $output.=">$item";
883: if ($locale_names{$item} ne '') {
884: $output.=" $locale_names{$item}</option>\n";
885: }
886: $output.="</option>\n";
887: }
888: $output.="</select>";
889: return $output;
890: }
891:
892: sub select_language {
893: my ($name,$selected,$includeempty) = @_;
894: my %langchoices;
895: if ($includeempty) {
896: %langchoices = ('' => 'No language preference');
897: }
898: foreach my $id (&languageids()) {
899: my $code = &supportedlanguagecode($id);
900: if ($code) {
901: $langchoices{$code} = &plainlanguagedescription($id);
902: }
903: }
904: return &select_form($selected,$name,%langchoices);
905: }
906:
907: =pod
908:
909: =item * &linked_select_forms(...)
910:
911: linked_select_forms returns a string containing a <script></script> block
912: and html for two <select> menus. The select menus will be linked in that
913: changing the value of the first menu will result in new values being placed
914: in the second menu. The values in the select menu will appear in alphabetical
915: order unless a defined order is provided.
916:
917: linked_select_forms takes the following ordered inputs:
918:
919: =over 4
920:
921: =item * $formname, the name of the <form> tag
922:
923: =item * $middletext, the text which appears between the <select> tags
924:
925: =item * $firstdefault, the default value for the first menu
926:
927: =item * $firstselectname, the name of the first <select> tag
928:
929: =item * $secondselectname, the name of the second <select> tag
930:
931: =item * $hashref, a reference to a hash containing the data for the menus.
932:
933: =item * $menuorder, the order of values in the first menu
934:
935: =back
936:
937: Below is an example of such a hash. Only the 'text', 'default', and
938: 'select2' keys must appear as stated. keys(%menu) are the possible
939: values for the first select menu. The text that coincides with the
940: first menu value is given in $menu{$choice1}->{'text'}. The values
941: and text for the second menu are given in the hash pointed to by
942: $menu{$choice1}->{'select2'}.
943:
944: my %menu = ( A1 => { text =>"Choice A1" ,
945: default => "B3",
946: select2 => {
947: B1 => "Choice B1",
948: B2 => "Choice B2",
949: B3 => "Choice B3",
950: B4 => "Choice B4"
951: },
952: order => ['B4','B3','B1','B2'],
953: },
954: A2 => { text =>"Choice A2" ,
955: default => "C2",
956: select2 => {
957: C1 => "Choice C1",
958: C2 => "Choice C2",
959: C3 => "Choice C3"
960: },
961: order => ['C2','C1','C3'],
962: },
963: A3 => { text =>"Choice A3" ,
964: default => "D6",
965: select2 => {
966: D1 => "Choice D1",
967: D2 => "Choice D2",
968: D3 => "Choice D3",
969: D4 => "Choice D4",
970: D5 => "Choice D5",
971: D6 => "Choice D6",
972: D7 => "Choice D7"
973: },
974: order => ['D4','D3','D2','D1','D7','D6','D5'],
975: }
976: );
977:
978: =cut
979:
980: sub linked_select_forms {
981: my ($formname,
982: $middletext,
983: $firstdefault,
984: $firstselectname,
985: $secondselectname,
986: $hashref,
987: $menuorder,
988: ) = @_;
989: my $second = "document.$formname.$secondselectname";
990: my $first = "document.$formname.$firstselectname";
991: # output the javascript to do the changing
992: my $result = '';
993: $result.='<script type="text/javascript" language="JavaScript">'."\n";
994: $result.="// <![CDATA[\n";
995: $result.="var select2data = new Object();\n";
996: $" = '","';
997: my $debug = '';
998: foreach my $s1 (sort(keys(%$hashref))) {
999: $result.="select2data.d_$s1 = new Object();\n";
1000: $result.="select2data.d_$s1.def = new String('".
1001: $hashref->{$s1}->{'default'}."');\n";
1002: $result.="select2data.d_$s1.values = new Array(";
1003: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1004: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1005: @s2values = @{$hashref->{$s1}->{'order'}};
1006: }
1007: $result.="\"@s2values\");\n";
1008: $result.="select2data.d_$s1.texts = new Array(";
1009: my @s2texts;
1010: foreach my $value (@s2values) {
1011: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
1012: }
1013: $result.="\"@s2texts\");\n";
1014: }
1015: $"=' ';
1016: $result.= <<"END";
1017:
1018: function select1_changed() {
1019: // Determine new choice
1020: var newvalue = "d_" + $first.value;
1021: // update select2
1022: var values = select2data[newvalue].values;
1023: var texts = select2data[newvalue].texts;
1024: var select2def = select2data[newvalue].def;
1025: var i;
1026: // out with the old
1027: for (i = 0; i < $second.options.length; i++) {
1028: $second.options[i] = null;
1029: }
1030: // in with the nuclear
1031: for (i=0;i<values.length; i++) {
1032: $second.options[i] = new Option(values[i]);
1033: $second.options[i].value = values[i];
1034: $second.options[i].text = texts[i];
1035: if (values[i] == select2def) {
1036: $second.options[i].selected = true;
1037: }
1038: }
1039: }
1040: // ]]>
1041: </script>
1042: END
1043: # output the initial values for the selection lists
1044: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1045: my @order = sort(keys(%{$hashref}));
1046: if (ref($menuorder) eq 'ARRAY') {
1047: @order = @{$menuorder};
1048: }
1049: foreach my $value (@order) {
1050: $result.=" <option value=\"$value\" ";
1051: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1052: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1053: }
1054: $result .= "</select>\n";
1055: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1056: $result .= $middletext;
1057: $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
1058: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1059:
1060: my @secondorder = sort(keys(%select2));
1061: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1062: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1063: }
1064: foreach my $value (@secondorder) {
1065: $result.=" <option value=\"$value\" ";
1066: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1067: $result.=">".&mt($select2{$value})."</option>\n";
1068: }
1069: $result .= "</select>\n";
1070: # return $debug;
1071: return $result;
1072: } # end of sub linked_select_forms {
1073:
1074: =pod
1075:
1076: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height)
1077:
1078: Returns a string corresponding to an HTML link to the given help
1079: $topic, where $topic corresponds to the name of a .tex file in
1080: /home/httpd/html/adm/help/tex, with underscores replaced by
1081: spaces.
1082:
1083: $text will optionally be linked to the same topic, allowing you to
1084: link text in addition to the graphic. If you do not want to link
1085: text, but wish to specify one of the later parameters, pass an
1086: empty string.
1087:
1088: $stayOnPage is a value that will be interpreted as a boolean. If true,
1089: the link will not open a new window. If false, the link will open
1090: a new window using Javascript. (Default is false.)
1091:
1092: $width and $height are optional numerical parameters that will
1093: override the width and height of the popped up window, which may
1094: be useful for certain help topics with big pictures included.
1095:
1096: =cut
1097:
1098: sub help_open_topic {
1099: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1100: $text = "" if (not defined $text);
1101: $stayOnPage = 0 if (not defined $stayOnPage);
1102: $width = 350 if (not defined $width);
1103: $height = 400 if (not defined $height);
1104: my $filename = $topic;
1105: $filename =~ s/ /_/g;
1106:
1107: my $template = "";
1108: my $link;
1109:
1110: $topic=~s/\W/\_/g;
1111:
1112: if (!$stayOnPage) {
1113: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1114: } else {
1115: $link = "/adm/help/${filename}.hlp";
1116: }
1117:
1118: # Add the text
1119: if ($text ne "") {
1120: $template.='<span class="LC_help_open_topic">'
1121: .'<a target="_top" href="'.$link.'">'
1122: .$text.'</a>';
1123: }
1124:
1125: # (Always) Add the graphic
1126: my $title = &mt('Online Help');
1127: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1128: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1129: .'<img src="'.$helpicon.'" border="0"'
1130: .' alt="'.&mt('Help: [_1]',$topic).'"'
1131: .' title="'.$title.'"'
1132: .' /></a>';
1133: if ($text ne "") {
1134: $template.='</span>';
1135: }
1136: return $template;
1137:
1138: }
1139:
1140: # This is a quicky function for Latex cheatsheet editing, since it
1141: # appears in at least four places
1142: sub helpLatexCheatsheet {
1143: my ($topic,$text,$not_author) = @_;
1144: my $out;
1145: my $addOther = '';
1146: if ($topic) {
1147: $addOther = '<span>'.&Apache::loncommon::help_open_topic($topic,&mt($text),
1148: undef, undef, 600).
1149: '</span> ';
1150: }
1151: $out = '<span>' # Start cheatsheet
1152: .$addOther
1153: .'<span>'
1154: .&Apache::loncommon::help_open_topic('Greek_Symbols',&mt('Greek Symbols'),
1155: undef,undef,600)
1156: .'</span> <span>'
1157: .&Apache::loncommon::help_open_topic('Other_Symbols',&mt('Other Symbols'),
1158: undef,undef,600)
1159: .'</span>';
1160: unless ($not_author) {
1161: $out .= ' <span>'
1162: .&Apache::loncommon::help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),
1163: undef,undef,600)
1164: .'</span>';
1165: }
1166: $out .= '</span>'; # End cheatsheet
1167: return $out;
1168: }
1169:
1170: sub general_help {
1171: my $helptopic='Student_Intro';
1172: if ($env{'request.role'}=~/^(ca|au)/) {
1173: $helptopic='Authoring_Intro';
1174: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1175: $helptopic='Course_Coordination_Intro';
1176: } elsif ($env{'request.role'}=~/^dc/) {
1177: $helptopic='Domain_Coordination_Intro';
1178: }
1179: return $helptopic;
1180: }
1181:
1182: sub update_help_link {
1183: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1184: my $origurl = $ENV{'REQUEST_URI'};
1185: $origurl=~s|^/~|/priv/|;
1186: my $timestamp = time;
1187: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1188: $$datum = &escape($$datum);
1189: }
1190:
1191: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1192: my $output .= <<"ENDOUTPUT";
1193: <script type="text/javascript">
1194: // <![CDATA[
1195: banner_link = '$banner_link';
1196: // ]]>
1197: </script>
1198: ENDOUTPUT
1199: return $output;
1200: }
1201:
1202: # now just updates the help link and generates a blue icon
1203: sub help_open_menu {
1204: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1205: = @_;
1206: $stayOnPage = 0 if (not defined $stayOnPage);
1207: # only use pop-up help (stayOnPage == 0)
1208: # if environment.remote is on (using remote control UI)
1209: if ($env{'environment.remote'} eq 'off' ) {
1210: $stayOnPage=1;
1211: }
1212: my $output;
1213: if ($component_help) {
1214: if (!$text) {
1215: $output=&help_open_topic($component_help,undef,$stayOnPage,
1216: $width,$height);
1217: } else {
1218: my $help_text;
1219: $help_text=&unescape($topic);
1220: $output='<table><tr><td>'.
1221: &help_open_topic($component_help,$help_text,$stayOnPage,
1222: $width,$height).'</td></tr></table>';
1223: }
1224: }
1225: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1226: return $output.$banner_link;
1227: }
1228:
1229: sub top_nav_help {
1230: my ($text) = @_;
1231: $text = &mt($text);
1232: my $stay_on_page =
1233: ($env{'environment.remote'} eq 'off' );
1234: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1235: : "javascript:helpMenu('open')";
1236: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1237:
1238: my $title = &mt('Get help');
1239:
1240: return <<"END";
1241: $banner_link
1242: <a href="$link" title="$title">$text</a>
1243: END
1244: }
1245:
1246: sub help_menu_js {
1247: my ($text) = @_;
1248:
1249: my $stayOnPage =
1250: ($env{'environment.remote'} eq 'off' );
1251:
1252: my $width = 620;
1253: my $height = 600;
1254: my $helptopic=&general_help();
1255: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1256: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1257: my $start_page =
1258: &Apache::loncommon::start_page('Help Menu', undef,
1259: {'frameset' => 1,
1260: 'js_ready' => 1,
1261: 'add_entries' => {
1262: 'border' => '0',
1263: 'rows' => "110,*",},});
1264: my $end_page =
1265: &Apache::loncommon::end_page({'frameset' => 1,
1266: 'js_ready' => 1,});
1267:
1268: my $template .= <<"ENDTEMPLATE";
1269: <script type="text/javascript">
1270: // <![CDATA[
1271: // <!-- BEGIN LON-CAPA Internal
1272: var banner_link = '';
1273: function helpMenu(target) {
1274: var caller = this;
1275: if (target == 'open') {
1276: var newWindow = null;
1277: try {
1278: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1279: }
1280: catch(error) {
1281: writeHelp(caller);
1282: return;
1283: }
1284: if (newWindow) {
1285: caller = newWindow;
1286: }
1287: }
1288: writeHelp(caller);
1289: return;
1290: }
1291: function writeHelp(caller) {
1292: caller.document.writeln('$start_page<frame name="bannerframe" src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1293: caller.document.close()
1294: caller.focus()
1295: }
1296: // END LON-CAPA Internal -->
1297: // ]]>
1298: </script>
1299: ENDTEMPLATE
1300: return $template;
1301: }
1302:
1303: sub help_open_bug {
1304: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1305: unless ($env{'user.adv'}) { return ''; }
1306: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1307: $text = "" if (not defined $text);
1308: $stayOnPage = 0 if (not defined $stayOnPage);
1309: if ($env{'environment.remote'} eq 'off' ) {
1310: $stayOnPage=1;
1311: }
1312: $width = 600 if (not defined $width);
1313: $height = 600 if (not defined $height);
1314:
1315: $topic=~s/\W+/\+/g;
1316: my $link='';
1317: my $template='';
1318: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1319: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1320: if (!$stayOnPage)
1321: {
1322: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1323: }
1324: else
1325: {
1326: $link = $url;
1327: }
1328: # Add the text
1329: if ($text ne "")
1330: {
1331: $template .=
1332: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1333: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1334: }
1335:
1336: # Add the graphic
1337: my $title = &mt('Report a Bug');
1338: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1339: $template .= <<"ENDTEMPLATE";
1340: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1341: ENDTEMPLATE
1342: if ($text ne '') { $template.='</td></tr></table>' };
1343: return $template;
1344:
1345: }
1346:
1347: sub help_open_faq {
1348: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1349: unless ($env{'user.adv'}) { return ''; }
1350: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1351: $text = "" if (not defined $text);
1352: $stayOnPage = 0 if (not defined $stayOnPage);
1353: if ($env{'environment.remote'} eq 'off' ) {
1354: $stayOnPage=1;
1355: }
1356: $width = 350 if (not defined $width);
1357: $height = 400 if (not defined $height);
1358:
1359: $topic=~s/\W+/\+/g;
1360: my $link='';
1361: my $template='';
1362: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1363: if (!$stayOnPage)
1364: {
1365: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1366: }
1367: else
1368: {
1369: $link = $url;
1370: }
1371:
1372: # Add the text
1373: if ($text ne "")
1374: {
1375: $template .=
1376: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1377: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1378: }
1379:
1380: # Add the graphic
1381: my $title = &mt('View the FAQ');
1382: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1383: $template .= <<"ENDTEMPLATE";
1384: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1385: ENDTEMPLATE
1386: if ($text ne '') { $template.='</td></tr></table>' };
1387: return $template;
1388:
1389: }
1390:
1391: ###############################################################
1392: ###############################################################
1393:
1394: =pod
1395:
1396: =item * &change_content_javascript():
1397:
1398: This and the next function allow you to create small sections of an
1399: otherwise static HTML page that you can update on the fly with
1400: Javascript, even in Netscape 4.
1401:
1402: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1403: must be written to the HTML page once. It will prove the Javascript
1404: function "change(name, content)". Calling the change function with the
1405: name of the section
1406: you want to update, matching the name passed to C<changable_area>, and
1407: the new content you want to put in there, will put the content into
1408: that area.
1409:
1410: B<Note>: Netscape 4 only reserves enough space for the changable area
1411: to contain room for the original contents. You need to "make space"
1412: for whatever changes you wish to make, and be B<sure> to check your
1413: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1414: it's adequate for updating a one-line status display, but little more.
1415: This script will set the space to 100% width, so you only need to
1416: worry about height in Netscape 4.
1417:
1418: Modern browsers are much less limiting, and if you can commit to the
1419: user not using Netscape 4, this feature may be used freely with
1420: pretty much any HTML.
1421:
1422: =cut
1423:
1424: sub change_content_javascript {
1425: # If we're on Netscape 4, we need to use Layer-based code
1426: if ($env{'browser.type'} eq 'netscape' &&
1427: $env{'browser.version'} =~ /^4\./) {
1428: return (<<NETSCAPE4);
1429: function change(name, content) {
1430: doc = document.layers[name+"___escape"].layers[0].document;
1431: doc.open();
1432: doc.write(content);
1433: doc.close();
1434: }
1435: NETSCAPE4
1436: } else {
1437: # Otherwise, we need to use semi-standards-compliant code
1438: # (technically, "innerHTML" isn't standard but the equivalent
1439: # is really scary, and every useful browser supports it
1440: return (<<DOMBASED);
1441: function change(name, content) {
1442: element = document.getElementById(name);
1443: element.innerHTML = content;
1444: }
1445: DOMBASED
1446: }
1447: }
1448:
1449: =pod
1450:
1451: =item * &changable_area($name,$origContent):
1452:
1453: This provides a "changable area" that can be modified on the fly via
1454: the Javascript code provided in C<change_content_javascript>. $name is
1455: the name you will use to reference the area later; do not repeat the
1456: same name on a given HTML page more then once. $origContent is what
1457: the area will originally contain, which can be left blank.
1458:
1459: =cut
1460:
1461: sub changable_area {
1462: my ($name, $origContent) = @_;
1463:
1464: if ($env{'browser.type'} eq 'netscape' &&
1465: $env{'browser.version'} =~ /^4\./) {
1466: # If this is netscape 4, we need to use the Layer tag
1467: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1468: } else {
1469: return "<span id='$name'>$origContent</span>";
1470: }
1471: }
1472:
1473: =pod
1474:
1475: =item * &viewport_geometry_js
1476:
1477: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1478:
1479: =cut
1480:
1481:
1482: sub viewport_geometry_js {
1483: return <<"GEOMETRY";
1484: var Geometry = {};
1485: function init_geometry() {
1486: if (Geometry.init) { return };
1487: Geometry.init=1;
1488: if (window.innerHeight) {
1489: Geometry.getViewportHeight = function() { return window.innerHeight; };
1490: Geometry.getViewportWidth = function() { return window.innerWidth; };
1491: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1492: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1493: }
1494: else if (document.documentElement && document.documentElement.clientHeight) {
1495: Geometry.getViewportHeight =
1496: function() { return document.documentElement.clientHeight; };
1497: Geometry.getViewportWidth =
1498: function() { return document.documentElement.clientWidth; };
1499:
1500: Geometry.getHorizontalScroll =
1501: function() { return document.documentElement.scrollLeft; };
1502: Geometry.getVerticalScroll =
1503: function() { return document.documentElement.scrollTop; };
1504: }
1505: else if (document.body.clientHeight) {
1506: Geometry.getViewportHeight =
1507: function() { return document.body.clientHeight; };
1508: Geometry.getViewportWidth =
1509: function() { return document.body.clientWidth; };
1510: Geometry.getHorizontalScroll =
1511: function() { return document.body.scrollLeft; };
1512: Geometry.getVerticalScroll =
1513: function() { return document.body.scrollTop; };
1514: }
1515: }
1516:
1517: GEOMETRY
1518: }
1519:
1520: =pod
1521:
1522: =item * &viewport_size_js()
1523:
1524: 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.
1525:
1526: =cut
1527:
1528: sub viewport_size_js {
1529: my $geometry = &viewport_geometry_js();
1530: return <<"DIMS";
1531:
1532: $geometry
1533:
1534: function getViewportDims(width,height) {
1535: init_geometry();
1536: width.value = Geometry.getViewportWidth();
1537: height.value = Geometry.getViewportHeight();
1538: return;
1539: }
1540:
1541: DIMS
1542: }
1543:
1544: =pod
1545:
1546: =item * &resize_textarea_js()
1547:
1548: emits the needed javascript to resize a textarea to be as big as possible
1549:
1550: creates a function resize_textrea that takes two IDs first should be
1551: the id of the element to resize, second should be the id of a div that
1552: surrounds everything that comes after the textarea, this routine needs
1553: to be attached to the <body> for the onload and onresize events.
1554:
1555: =back
1556:
1557: =cut
1558:
1559: sub resize_textarea_js {
1560: my $geometry = &viewport_geometry_js();
1561: return <<"RESIZE";
1562: <script type="text/javascript">
1563: // <![CDATA[
1564: $geometry
1565:
1566: function getX(element) {
1567: var x = 0;
1568: while (element) {
1569: x += element.offsetLeft;
1570: element = element.offsetParent;
1571: }
1572: return x;
1573: }
1574: function getY(element) {
1575: var y = 0;
1576: while (element) {
1577: y += element.offsetTop;
1578: element = element.offsetParent;
1579: }
1580: return y;
1581: }
1582:
1583:
1584: function resize_textarea(textarea_id,bottom_id) {
1585: init_geometry();
1586: var textarea = document.getElementById(textarea_id);
1587: //alert(textarea);
1588:
1589: var textarea_top = getY(textarea);
1590: var textarea_height = textarea.offsetHeight;
1591: var bottom = document.getElementById(bottom_id);
1592: var bottom_top = getY(bottom);
1593: var bottom_height = bottom.offsetHeight;
1594: var window_height = Geometry.getViewportHeight();
1595: var fudge = 23;
1596: var new_height = window_height-fudge-textarea_top-bottom_height;
1597: if (new_height < 300) {
1598: new_height = 300;
1599: }
1600: textarea.style.height=new_height+'px';
1601: }
1602: // ]]>
1603: </script>
1604: RESIZE
1605:
1606: }
1607:
1608: =pod
1609:
1610: =head1 Excel and CSV file utility routines
1611:
1612: =over 4
1613:
1614: =cut
1615:
1616: ###############################################################
1617: ###############################################################
1618:
1619: =pod
1620:
1621: =item * &csv_translate($text)
1622:
1623: Translate $text to allow it to be output as a 'comma separated values'
1624: format.
1625:
1626: =cut
1627:
1628: ###############################################################
1629: ###############################################################
1630: sub csv_translate {
1631: my $text = shift;
1632: $text =~ s/\"/\"\"/g;
1633: $text =~ s/\n/ /g;
1634: return $text;
1635: }
1636:
1637: ###############################################################
1638: ###############################################################
1639:
1640: =pod
1641:
1642: =item * &define_excel_formats()
1643:
1644: Define some commonly used Excel cell formats.
1645:
1646: Currently supported formats:
1647:
1648: =over 4
1649:
1650: =item header
1651:
1652: =item bold
1653:
1654: =item h1
1655:
1656: =item h2
1657:
1658: =item h3
1659:
1660: =item h4
1661:
1662: =item i
1663:
1664: =item date
1665:
1666: =back
1667:
1668: Inputs: $workbook
1669:
1670: Returns: $format, a hash reference.
1671:
1672: =cut
1673:
1674: ###############################################################
1675: ###############################################################
1676: sub define_excel_formats {
1677: my ($workbook) = @_;
1678: my $format;
1679: $format->{'header'} = $workbook->add_format(bold => 1,
1680: bottom => 1,
1681: align => 'center');
1682: $format->{'bold'} = $workbook->add_format(bold=>1);
1683: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1684: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1685: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1686: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1687: $format->{'i'} = $workbook->add_format(italic=>1);
1688: $format->{'date'} = $workbook->add_format(num_format=>
1689: 'mm/dd/yyyy hh:mm:ss');
1690: return $format;
1691: }
1692:
1693: ###############################################################
1694: ###############################################################
1695:
1696: =pod
1697:
1698: =item * &create_workbook()
1699:
1700: Create an Excel worksheet. If it fails, output message on the
1701: request object and return undefs.
1702:
1703: Inputs: Apache request object
1704:
1705: Returns (undef) on failure,
1706: Excel worksheet object, scalar with filename, and formats
1707: from &Apache::loncommon::define_excel_formats on success
1708:
1709: =cut
1710:
1711: ###############################################################
1712: ###############################################################
1713: sub create_workbook {
1714: my ($r) = @_;
1715: #
1716: # Create the excel spreadsheet
1717: my $filename = '/prtspool/'.
1718: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1719: time.'_'.rand(1000000000).'.xls';
1720: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1721: if (! defined($workbook)) {
1722: $r->log_error("Error creating excel spreadsheet $filename: $!");
1723: $r->print('<p>'.&mt("Unable to create new Excel file. ".
1724: "This error has been logged. ".
1725: "Please alert your LON-CAPA administrator").
1726: '</p>');
1727: return (undef);
1728: }
1729: #
1730: $workbook->set_tempdir('/home/httpd/perl/tmp');
1731: #
1732: my $format = &Apache::loncommon::define_excel_formats($workbook);
1733: return ($workbook,$filename,$format);
1734: }
1735:
1736: ###############################################################
1737: ###############################################################
1738:
1739: =pod
1740:
1741: =item * &create_text_file()
1742:
1743: Create a file to write to and eventually make available to the user.
1744: If file creation fails, outputs an error message on the request object and
1745: return undefs.
1746:
1747: Inputs: Apache request object, and file suffix
1748:
1749: Returns (undef) on failure,
1750: Filehandle and filename on success.
1751:
1752: =cut
1753:
1754: ###############################################################
1755: ###############################################################
1756: sub create_text_file {
1757: my ($r,$suffix) = @_;
1758: if (! defined($suffix)) { $suffix = 'txt'; };
1759: my $fh;
1760: my $filename = '/prtspool/'.
1761: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1762: time.'_'.rand(1000000000).'.'.$suffix;
1763: $fh = Apache::File->new('>/home/httpd'.$filename);
1764: if (! defined($fh)) {
1765: $r->log_error("Couldn't open $filename for output $!");
1766: $r->print(&mt('Problems occurred in creating the output file. '
1767: .'This error has been logged. '
1768: .'Please alert your LON-CAPA administrator.'));
1769: }
1770: return ($fh,$filename)
1771: }
1772:
1773:
1774: =pod
1775:
1776: =back
1777:
1778: =cut
1779:
1780: ###############################################################
1781: ## Home server <option> list generating code ##
1782: ###############################################################
1783:
1784: # ------------------------------------------
1785:
1786: sub domain_select {
1787: my ($name,$value,$multiple)=@_;
1788: my %domains=map {
1789: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1790: } &Apache::lonnet::all_domains();
1791: if ($multiple) {
1792: $domains{''}=&mt('Any domain');
1793: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1794: return &multiple_select_form($name,$value,4,\%domains);
1795: } else {
1796: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1797: return &select_form($name,$value,%domains);
1798: }
1799: }
1800:
1801: #-------------------------------------------
1802:
1803: =pod
1804:
1805: =head1 Routines for form select boxes
1806:
1807: =over 4
1808:
1809: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1810:
1811: Returns a string containing a <select> element int multiple mode
1812:
1813:
1814: Args:
1815: $name - name of the <select> element
1816: $value - scalar or array ref of values that should already be selected
1817: $size - number of rows long the select element is
1818: $hash - the elements should be 'option' => 'shown text'
1819: (shown text should already have been &mt())
1820: $order - (optional) array ref of the order to show the elements in
1821:
1822: =cut
1823:
1824: #-------------------------------------------
1825: sub multiple_select_form {
1826: my ($name,$value,$size,$hash,$order)=@_;
1827: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1828: my $output='';
1829: if (! defined($size)) {
1830: $size = 4;
1831: if (scalar(keys(%$hash))<4) {
1832: $size = scalar(keys(%$hash));
1833: }
1834: }
1835: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1836: my @order;
1837: if (ref($order) eq 'ARRAY') {
1838: @order = @{$order};
1839: } else {
1840: @order = sort(keys(%$hash));
1841: }
1842: if (exists($$hash{'select_form_order'})) {
1843: @order = @{$$hash{'select_form_order'}};
1844: }
1845:
1846: foreach my $key (@order) {
1847: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1848: $output.='selected="selected" ' if ($selected{$key});
1849: $output.='>'.$hash->{$key}."</option>\n";
1850: }
1851: $output.="</select>\n";
1852: return $output;
1853: }
1854:
1855: #-------------------------------------------
1856:
1857: =pod
1858:
1859: =item * &select_form($defdom,$name,%hash)
1860:
1861: Returns a string containing a <select name='$name' size='1'> form to
1862: allow a user to select options from a hash option_name => displayed text.
1863: See lonrights.pm for an example invocation and use.
1864:
1865: =cut
1866:
1867: #-------------------------------------------
1868: sub select_form {
1869: my ($def,$name,%hash) = @_;
1870: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1871: my @keys;
1872: if (exists($hash{'select_form_order'})) {
1873: @keys=@{$hash{'select_form_order'}};
1874: } else {
1875: @keys=sort(keys(%hash));
1876: }
1877: foreach my $key (@keys) {
1878: $selectform.=
1879: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
1880: ($key eq $def ? 'selected="selected" ' : '').
1881: ">".&mt($hash{$key})."</option>\n";
1882: }
1883: $selectform.="</select>";
1884: return $selectform;
1885: }
1886:
1887: # For display filters
1888:
1889: sub display_filter {
1890: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1891: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1892: return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1893: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
1894: (&mt('all'),10,20,50,100,1000,10000))).
1895: '</label></span> <span class="LC_nobreak">'.
1896: &mt('Filter [_1]',
1897: &select_form($env{'form.displayfilter'},
1898: 'displayfilter',
1899: ('currentfolder' => 'Current folder/page',
1900: 'containing' => 'Containing phrase',
1901: 'none' => 'None'))).
1902: '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1903: }
1904:
1905: sub gradeleveldescription {
1906: my $gradelevel=shift;
1907: my %gradelevels=(0 => 'Not specified',
1908: 1 => 'Grade 1',
1909: 2 => 'Grade 2',
1910: 3 => 'Grade 3',
1911: 4 => 'Grade 4',
1912: 5 => 'Grade 5',
1913: 6 => 'Grade 6',
1914: 7 => 'Grade 7',
1915: 8 => 'Grade 8',
1916: 9 => 'Grade 9',
1917: 10 => 'Grade 10',
1918: 11 => 'Grade 11',
1919: 12 => 'Grade 12',
1920: 13 => 'Grade 13',
1921: 14 => '100 Level',
1922: 15 => '200 Level',
1923: 16 => '300 Level',
1924: 17 => '400 Level',
1925: 18 => 'Graduate Level');
1926: return &mt($gradelevels{$gradelevel});
1927: }
1928:
1929: sub select_level_form {
1930: my ($deflevel,$name)=@_;
1931: unless ($deflevel) { $deflevel=0; }
1932: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1933: for (my $i=0; $i<=18; $i++) {
1934: $selectform.="<option value=\"$i\" ".
1935: ($i==$deflevel ? 'selected="selected" ' : '').
1936: ">".&gradeleveldescription($i)."</option>\n";
1937: }
1938: $selectform.="</select>";
1939: return $selectform;
1940: }
1941:
1942: #-------------------------------------------
1943:
1944: =pod
1945:
1946: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange)
1947:
1948: Returns a string containing a <select name='$name' size='1'> form to
1949: allow a user to select the domain to preform an operation in.
1950: See loncreateuser.pm for an example invocation and use.
1951:
1952: If the $includeempty flag is set, it also includes an empty choice ("no domain
1953: selected");
1954:
1955: If the $showdomdesc flag is set, the domain name is followed by the domain description.
1956:
1957: The optional $onchange argumnet specifies what should occur if the domain selector is changed, e.g., 'this.form.submit()' if the form is to be automatically submitted.
1958:
1959: =cut
1960:
1961: #-------------------------------------------
1962: sub select_dom_form {
1963: my ($defdom,$name,$includeempty,$showdomdesc,$onchange) = @_;
1964: if ($onchange) {
1965: $onchange = ' onchange="'.$onchange.'"';
1966: }
1967: my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1968: if ($includeempty) { @domains=('',@domains); }
1969: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1970: foreach my $dom (@domains) {
1971: $selectdomain.="<option value=\"$dom\" ".
1972: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
1973: if ($showdomdesc) {
1974: if ($dom ne '') {
1975: my $domdesc = &Apache::lonnet::domain($dom,'description');
1976: if ($domdesc ne '') {
1977: $selectdomain .= ' ('.$domdesc.')';
1978: }
1979: }
1980: }
1981: $selectdomain .= "</option>\n";
1982: }
1983: $selectdomain.="</select>";
1984: return $selectdomain;
1985: }
1986:
1987: #-------------------------------------------
1988:
1989: =pod
1990:
1991: =item * &home_server_form_item($domain,$name,$defaultflag)
1992:
1993: input: 4 arguments (two required, two optional) -
1994: $domain - domain of new user
1995: $name - name of form element
1996: $default - Value of 'default' causes a default item to be first
1997: option, and selected by default.
1998: $hide - Value of 'hide' causes hiding of the name of the server,
1999: if 1 server found, or default, if 0 found.
2000: output: returns 2 items:
2001: (a) form element which contains either:
2002: (i) <select name="$name">
2003: <option value="$hostid1">$hostid $servers{$hostid}</option>
2004: <option value="$hostid2">$hostid $servers{$hostid}</option>
2005: </select>
2006: form item if there are multiple library servers in $domain, or
2007: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2008: if there is only one library server in $domain.
2009:
2010: (b) number of library servers found.
2011:
2012: See loncreateuser.pm for example of use.
2013:
2014: =cut
2015:
2016: #-------------------------------------------
2017: sub home_server_form_item {
2018: my ($domain,$name,$default,$hide) = @_;
2019: my %servers = &Apache::lonnet::get_servers($domain,'library');
2020: my $result;
2021: my $numlib = keys(%servers);
2022: if ($numlib > 1) {
2023: $result .= '<select name="'.$name.'" />'."\n";
2024: if ($default) {
2025: $result .= '<option value="default" selected="selected">'.&mt('default').
2026: '</option>'."\n";
2027: }
2028: foreach my $hostid (sort(keys(%servers))) {
2029: $result.= '<option value="'.$hostid.'">'.
2030: $hostid.' '.$servers{$hostid}."</option>\n";
2031: }
2032: $result .= '</select>'."\n";
2033: } elsif ($numlib == 1) {
2034: my $hostid;
2035: foreach my $item (keys(%servers)) {
2036: $hostid = $item;
2037: }
2038: $result .= '<input type="hidden" name="'.$name.'" value="'.
2039: $hostid.'" />';
2040: if (!$hide) {
2041: $result .= $hostid.' '.$servers{$hostid};
2042: }
2043: $result .= "\n";
2044: } elsif ($default) {
2045: $result .= '<input type="hidden" name="'.$name.
2046: '" value="default" />';
2047: if (!$hide) {
2048: $result .= &mt('default');
2049: }
2050: $result .= "\n";
2051: }
2052: return ($result,$numlib);
2053: }
2054:
2055: =pod
2056:
2057: =back
2058:
2059: =cut
2060:
2061: ###############################################################
2062: ## Decoding User Agent ##
2063: ###############################################################
2064:
2065: =pod
2066:
2067: =head1 Decoding the User Agent
2068:
2069: =over 4
2070:
2071: =item * &decode_user_agent()
2072:
2073: Inputs: $r
2074:
2075: Outputs:
2076:
2077: =over 4
2078:
2079: =item * $httpbrowser
2080:
2081: =item * $clientbrowser
2082:
2083: =item * $clientversion
2084:
2085: =item * $clientmathml
2086:
2087: =item * $clientunicode
2088:
2089: =item * $clientos
2090:
2091: =back
2092:
2093: =back
2094:
2095: =cut
2096:
2097: ###############################################################
2098: ###############################################################
2099: sub decode_user_agent {
2100: my ($r)=@_;
2101: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2102: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2103: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
2104: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
2105: my $clientbrowser='unknown';
2106: my $clientversion='0';
2107: my $clientmathml='';
2108: my $clientunicode='0';
2109: for (my $i=0;$i<=$#browsertype;$i++) {
2110: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
2111: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2112: $clientbrowser=$bname;
2113: $httpbrowser=~/$vreg/i;
2114: $clientversion=$1;
2115: $clientmathml=($clientversion>=$minv);
2116: $clientunicode=($clientversion>=$univ);
2117: }
2118: }
2119: my $clientos='unknown';
2120: if (($httpbrowser=~/linux/i) ||
2121: ($httpbrowser=~/unix/i) ||
2122: ($httpbrowser=~/ux/i) ||
2123: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2124: if (($httpbrowser=~/vax/i) ||
2125: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2126: if ($httpbrowser=~/next/i) { $clientos='next'; }
2127: if (($httpbrowser=~/mac/i) ||
2128: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
2129: if ($httpbrowser=~/win/i) { $clientos='win'; }
2130: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
2131: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
2132: $clientunicode,$clientos,);
2133: }
2134:
2135: ###############################################################
2136: ## Authentication changing form generation subroutines ##
2137: ###############################################################
2138: ##
2139: ## All of the authform_xxxxxxx subroutines take their inputs in a
2140: ## hash, and have reasonable default values.
2141: ##
2142: ## formname = the name given in the <form> tag.
2143: #-------------------------------------------
2144:
2145: =pod
2146:
2147: =head1 Authentication Routines
2148:
2149: =over 4
2150:
2151: =item * &authform_xxxxxx()
2152:
2153: The authform_xxxxxx subroutines provide javascript and html forms which
2154: handle some of the conveniences required for authentication forms.
2155: This is not an optimal method, but it works.
2156:
2157: =over 4
2158:
2159: =item * authform_header
2160:
2161: =item * authform_authorwarning
2162:
2163: =item * authform_nochange
2164:
2165: =item * authform_kerberos
2166:
2167: =item * authform_internal
2168:
2169: =item * authform_filesystem
2170:
2171: =back
2172:
2173: See loncreateuser.pm for invocation and use examples.
2174:
2175: =cut
2176:
2177: #-------------------------------------------
2178: sub authform_header{
2179: my %in = (
2180: formname => 'cu',
2181: kerb_def_dom => '',
2182: @_,
2183: );
2184: $in{'formname'} = 'document.' . $in{'formname'};
2185: my $result='';
2186:
2187: #---------------------------------------------- Code for upper case translation
2188: my $Javascript_toUpperCase;
2189: unless ($in{kerb_def_dom}) {
2190: $Javascript_toUpperCase =<<"END";
2191: switch (choice) {
2192: case 'krb': currentform.elements[choicearg].value =
2193: currentform.elements[choicearg].value.toUpperCase();
2194: break;
2195: default:
2196: }
2197: END
2198: } else {
2199: $Javascript_toUpperCase = "";
2200: }
2201:
2202: my $radioval = "'nochange'";
2203: if (defined($in{'curr_authtype'})) {
2204: if ($in{'curr_authtype'} ne '') {
2205: $radioval = "'".$in{'curr_authtype'}."arg'";
2206: }
2207: }
2208: my $argfield = 'null';
2209: if (defined($in{'mode'})) {
2210: if ($in{'mode'} eq 'modifycourse') {
2211: if (defined($in{'curr_autharg'})) {
2212: if ($in{'curr_autharg'} ne '') {
2213: $argfield = "'$in{'curr_autharg'}'";
2214: }
2215: }
2216: }
2217: }
2218:
2219: $result.=<<"END";
2220: var current = new Object();
2221: current.radiovalue = $radioval;
2222: current.argfield = $argfield;
2223:
2224: function changed_radio(choice,currentform) {
2225: var choicearg = choice + 'arg';
2226: // If a radio button in changed, we need to change the argfield
2227: if (current.radiovalue != choice) {
2228: current.radiovalue = choice;
2229: if (current.argfield != null) {
2230: currentform.elements[current.argfield].value = '';
2231: }
2232: if (choice == 'nochange') {
2233: current.argfield = null;
2234: } else {
2235: current.argfield = choicearg;
2236: switch(choice) {
2237: case 'krb':
2238: currentform.elements[current.argfield].value =
2239: "$in{'kerb_def_dom'}";
2240: break;
2241: default:
2242: break;
2243: }
2244: }
2245: }
2246: return;
2247: }
2248:
2249: function changed_text(choice,currentform) {
2250: var choicearg = choice + 'arg';
2251: if (currentform.elements[choicearg].value !='') {
2252: $Javascript_toUpperCase
2253: // clear old field
2254: if ((current.argfield != choicearg) && (current.argfield != null)) {
2255: currentform.elements[current.argfield].value = '';
2256: }
2257: current.argfield = choicearg;
2258: }
2259: set_auth_radio_buttons(choice,currentform);
2260: return;
2261: }
2262:
2263: function set_auth_radio_buttons(newvalue,currentform) {
2264: var i=0;
2265: while (i < currentform.login.length) {
2266: if (currentform.login[i].value == newvalue) { break; }
2267: i++;
2268: }
2269: if (i == currentform.login.length) {
2270: return;
2271: }
2272: current.radiovalue = newvalue;
2273: currentform.login[i].checked = true;
2274: return;
2275: }
2276: END
2277: return $result;
2278: }
2279:
2280: sub authform_authorwarning{
2281: my $result='';
2282: $result='<i>'.
2283: &mt('As a general rule, only authors or co-authors should be '.
2284: 'filesystem authenticated '.
2285: '(which allows access to the server filesystem).')."</i>\n";
2286: return $result;
2287: }
2288:
2289: sub authform_nochange{
2290: my %in = (
2291: formname => 'document.cu',
2292: kerb_def_dom => 'MSU.EDU',
2293: @_,
2294: );
2295: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2296: my $result;
2297: if (keys(%can_assign) == 0) {
2298: $result = &mt('Under you current role you are not permitted to change login settings for this user');
2299: } else {
2300: $result = '<label>'.&mt('[_1] Do not change login data',
2301: '<input type="radio" name="login" value="nochange" '.
2302: 'checked="checked" onclick="'.
2303: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2304: '</label>';
2305: }
2306: return $result;
2307: }
2308:
2309: sub authform_kerberos {
2310: my %in = (
2311: formname => 'document.cu',
2312: kerb_def_dom => 'MSU.EDU',
2313: kerb_def_auth => 'krb4',
2314: @_,
2315: );
2316: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2317: $autharg,$jscall);
2318: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2319: if ($in{'kerb_def_auth'} eq 'krb5') {
2320: $check5 = ' checked="checked"';
2321: } else {
2322: $check4 = ' checked="checked"';
2323: }
2324: $krbarg = $in{'kerb_def_dom'};
2325: if (defined($in{'curr_authtype'})) {
2326: if ($in{'curr_authtype'} eq 'krb') {
2327: $krbcheck = ' checked="checked"';
2328: if (defined($in{'mode'})) {
2329: if ($in{'mode'} eq 'modifyuser') {
2330: $krbcheck = '';
2331: }
2332: }
2333: if (defined($in{'curr_kerb_ver'})) {
2334: if ($in{'curr_krb_ver'} eq '5') {
2335: $check5 = ' checked="checked"';
2336: $check4 = '';
2337: } else {
2338: $check4 = ' checked="checked"';
2339: $check5 = '';
2340: }
2341: }
2342: if (defined($in{'curr_autharg'})) {
2343: $krbarg = $in{'curr_autharg'};
2344: }
2345: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2346: if (defined($in{'curr_autharg'})) {
2347: $result =
2348: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2349: $in{'curr_autharg'},$krbver);
2350: } else {
2351: $result =
2352: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2353: }
2354: return $result;
2355: }
2356: }
2357: } else {
2358: if ($authnum == 1) {
2359: $authtype = '<input type="hidden" name="login" value="krb" />';
2360: }
2361: }
2362: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2363: return;
2364: } elsif ($authtype eq '') {
2365: if (defined($in{'mode'})) {
2366: if ($in{'mode'} eq 'modifycourse') {
2367: if ($authnum == 1) {
2368: $authtype = '<input type="hidden" name="login" value="krb" />';
2369: }
2370: }
2371: }
2372: }
2373: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2374: if ($authtype eq '') {
2375: $authtype = '<input type="radio" name="login" value="krb" '.
2376: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2377: $krbcheck.' />';
2378: }
2379: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
2380: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
2381: $in{'curr_authtype'} eq 'krb5') ||
2382: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
2383: $in{'curr_authtype'} eq 'krb4')) {
2384: $result .= &mt
2385: ('[_1] Kerberos authenticated with domain [_2] '.
2386: '[_3] Version 4 [_4] Version 5 [_5]',
2387: '<label>'.$authtype,
2388: '</label><input type="text" size="10" name="krbarg" '.
2389: 'value="'.$krbarg.'" '.
2390: 'onchange="'.$jscall.'" />',
2391: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2392: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2393: '</label>');
2394: } elsif ($can_assign{'krb4'}) {
2395: $result .= &mt
2396: ('[_1] Kerberos authenticated with domain [_2] '.
2397: '[_3] Version 4 [_4]',
2398: '<label>'.$authtype,
2399: '</label><input type="text" size="10" name="krbarg" '.
2400: 'value="'.$krbarg.'" '.
2401: 'onchange="'.$jscall.'" />',
2402: '<label><input type="hidden" name="krbver" value="4" />',
2403: '</label>');
2404: } elsif ($can_assign{'krb5'}) {
2405: $result .= &mt
2406: ('[_1] Kerberos authenticated with domain [_2] '.
2407: '[_3] Version 5 [_4]',
2408: '<label>'.$authtype,
2409: '</label><input type="text" size="10" name="krbarg" '.
2410: 'value="'.$krbarg.'" '.
2411: 'onchange="'.$jscall.'" />',
2412: '<label><input type="hidden" name="krbver" value="5" />',
2413: '</label>');
2414: }
2415: return $result;
2416: }
2417:
2418: sub authform_internal{
2419: my %in = (
2420: formname => 'document.cu',
2421: kerb_def_dom => 'MSU.EDU',
2422: @_,
2423: );
2424: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
2425: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2426: if (defined($in{'curr_authtype'})) {
2427: if ($in{'curr_authtype'} eq 'int') {
2428: if ($can_assign{'int'}) {
2429: $intcheck = 'checked="checked" ';
2430: if (defined($in{'mode'})) {
2431: if ($in{'mode'} eq 'modifyuser') {
2432: $intcheck = '';
2433: }
2434: }
2435: if (defined($in{'curr_autharg'})) {
2436: $intarg = $in{'curr_autharg'};
2437: }
2438: } else {
2439: $result = &mt('Currently internally authenticated.');
2440: return $result;
2441: }
2442: }
2443: } else {
2444: if ($authnum == 1) {
2445: $authtype = '<input type="hidden" name="login" value="int" />';
2446: }
2447: }
2448: if (!$can_assign{'int'}) {
2449: return;
2450: } elsif ($authtype eq '') {
2451: if (defined($in{'mode'})) {
2452: if ($in{'mode'} eq 'modifycourse') {
2453: if ($authnum == 1) {
2454: $authtype = '<input type="hidden" name="login" value="int" />';
2455: }
2456: }
2457: }
2458: }
2459: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2460: if ($authtype eq '') {
2461: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2462: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2463: }
2464: $autharg = '<input type="password" size="10" name="intarg" value="'.
2465: $intarg.'" onchange="'.$jscall.'" />';
2466: $result = &mt
2467: ('[_1] Internally authenticated (with initial password [_2])',
2468: '<label>'.$authtype,'</label>'.$autharg);
2469: $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>';
2470: return $result;
2471: }
2472:
2473: sub authform_local{
2474: my %in = (
2475: formname => 'document.cu',
2476: kerb_def_dom => 'MSU.EDU',
2477: @_,
2478: );
2479: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
2480: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2481: if (defined($in{'curr_authtype'})) {
2482: if ($in{'curr_authtype'} eq 'loc') {
2483: if ($can_assign{'loc'}) {
2484: $loccheck = 'checked="checked" ';
2485: if (defined($in{'mode'})) {
2486: if ($in{'mode'} eq 'modifyuser') {
2487: $loccheck = '';
2488: }
2489: }
2490: if (defined($in{'curr_autharg'})) {
2491: $locarg = $in{'curr_autharg'};
2492: }
2493: } else {
2494: $result = &mt('Currently using local (institutional) authentication.');
2495: return $result;
2496: }
2497: }
2498: } else {
2499: if ($authnum == 1) {
2500: $authtype = '<input type="hidden" name="login" value="loc" />';
2501: }
2502: }
2503: if (!$can_assign{'loc'}) {
2504: return;
2505: } elsif ($authtype eq '') {
2506: if (defined($in{'mode'})) {
2507: if ($in{'mode'} eq 'modifycourse') {
2508: if ($authnum == 1) {
2509: $authtype = '<input type="hidden" name="login" value="loc" />';
2510: }
2511: }
2512: }
2513: }
2514: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2515: if ($authtype eq '') {
2516: $authtype = '<input type="radio" name="login" value="loc" '.
2517: $loccheck.' onchange="'.$jscall.'" onclick="'.
2518: $jscall.'" />';
2519: }
2520: $autharg = '<input type="text" size="10" name="locarg" value="'.
2521: $locarg.'" onchange="'.$jscall.'" />';
2522: $result = &mt('[_1] Local Authentication with argument [_2]',
2523: '<label>'.$authtype,'</label>'.$autharg);
2524: return $result;
2525: }
2526:
2527: sub authform_filesystem{
2528: my %in = (
2529: formname => 'document.cu',
2530: kerb_def_dom => 'MSU.EDU',
2531: @_,
2532: );
2533: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
2534: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2535: if (defined($in{'curr_authtype'})) {
2536: if ($in{'curr_authtype'} eq 'fsys') {
2537: if ($can_assign{'fsys'}) {
2538: $fsyscheck = 'checked="checked" ';
2539: if (defined($in{'mode'})) {
2540: if ($in{'mode'} eq 'modifyuser') {
2541: $fsyscheck = '';
2542: }
2543: }
2544: } else {
2545: $result = &mt('Currently Filesystem Authenticated.');
2546: return $result;
2547: }
2548: }
2549: } else {
2550: if ($authnum == 1) {
2551: $authtype = '<input type="hidden" name="login" value="fsys" />';
2552: }
2553: }
2554: if (!$can_assign{'fsys'}) {
2555: return;
2556: } elsif ($authtype eq '') {
2557: if (defined($in{'mode'})) {
2558: if ($in{'mode'} eq 'modifycourse') {
2559: if ($authnum == 1) {
2560: $authtype = '<input type="hidden" name="login" value="fsys" />';
2561: }
2562: }
2563: }
2564: }
2565: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2566: if ($authtype eq '') {
2567: $authtype = '<input type="radio" name="login" value="fsys" '.
2568: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2569: $jscall.'" />';
2570: }
2571: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2572: ' onchange="'.$jscall.'" />';
2573: $result = &mt
2574: ('[_1] Filesystem Authenticated (with initial password [_2])',
2575: '<label><input type="radio" name="login" value="fsys" '.
2576: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
2577: '</label><input type="password" size="10" name="fsysarg" value="" '.
2578: 'onchange="'.$jscall.'" />');
2579: return $result;
2580: }
2581:
2582: sub get_assignable_auth {
2583: my ($dom) = @_;
2584: if ($dom eq '') {
2585: $dom = $env{'request.role.domain'};
2586: }
2587: my %can_assign = (
2588: krb4 => 1,
2589: krb5 => 1,
2590: int => 1,
2591: loc => 1,
2592: );
2593: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2594: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2595: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2596: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2597: my $context;
2598: if ($env{'request.role'} =~ /^au/) {
2599: $context = 'author';
2600: } elsif ($env{'request.role'} =~ /^dc/) {
2601: $context = 'domain';
2602: } elsif ($env{'request.course.id'}) {
2603: $context = 'course';
2604: }
2605: if ($context) {
2606: if (ref($authhash->{$context}) eq 'HASH') {
2607: %can_assign = %{$authhash->{$context}};
2608: }
2609: }
2610: }
2611: }
2612: my $authnum = 0;
2613: foreach my $key (keys(%can_assign)) {
2614: if ($can_assign{$key}) {
2615: $authnum ++;
2616: }
2617: }
2618: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2619: $authnum --;
2620: }
2621: return ($authnum,%can_assign);
2622: }
2623:
2624: ###############################################################
2625: ## Get Kerberos Defaults for Domain ##
2626: ###############################################################
2627: ##
2628: ## Returns default kerberos version and an associated argument
2629: ## as listed in file domain.tab. If not listed, provides
2630: ## appropriate default domain and kerberos version.
2631: ##
2632: #-------------------------------------------
2633:
2634: =pod
2635:
2636: =item * &get_kerberos_defaults()
2637:
2638: get_kerberos_defaults($target_domain) returns the default kerberos
2639: version and domain. If not found, it defaults to version 4 and the
2640: domain of the server.
2641:
2642: =over 4
2643:
2644: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2645:
2646: =back
2647:
2648: =back
2649:
2650: =cut
2651:
2652: #-------------------------------------------
2653: sub get_kerberos_defaults {
2654: my $domain=shift;
2655: my ($krbdef,$krbdefdom);
2656: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2657: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2658: $krbdef = $domdefaults{'auth_def'};
2659: $krbdefdom = $domdefaults{'auth_arg_def'};
2660: } else {
2661: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2662: my $krbdefdom=$1;
2663: $krbdefdom=~tr/a-z/A-Z/;
2664: $krbdef = "krb4";
2665: }
2666: return ($krbdef,$krbdefdom);
2667: }
2668:
2669:
2670: ###############################################################
2671: ## Thesaurus Functions ##
2672: ###############################################################
2673:
2674: =pod
2675:
2676: =head1 Thesaurus Functions
2677:
2678: =over 4
2679:
2680: =item * &initialize_keywords()
2681:
2682: Initializes the package variable %Keywords if it is empty. Uses the
2683: package variable $thesaurus_db_file.
2684:
2685: =cut
2686:
2687: ###################################################
2688:
2689: sub initialize_keywords {
2690: return 1 if (scalar keys(%Keywords));
2691: # If we are here, %Keywords is empty, so fill it up
2692: # Make sure the file we need exists...
2693: if (! -e $thesaurus_db_file) {
2694: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2695: " failed because it does not exist");
2696: return 0;
2697: }
2698: # Set up the hash as a database
2699: my %thesaurus_db;
2700: if (! tie(%thesaurus_db,'GDBM_File',
2701: $thesaurus_db_file,&GDBM_READER(),0640)){
2702: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2703: $thesaurus_db_file);
2704: return 0;
2705: }
2706: # Get the average number of appearances of a word.
2707: my $avecount = $thesaurus_db{'average.count'};
2708: # Put keywords (those that appear > average) into %Keywords
2709: while (my ($word,$data)=each (%thesaurus_db)) {
2710: my ($count,undef) = split /:/,$data;
2711: $Keywords{$word}++ if ($count > $avecount);
2712: }
2713: untie %thesaurus_db;
2714: # Remove special values from %Keywords.
2715: foreach my $value ('total.count','average.count') {
2716: delete($Keywords{$value}) if (exists($Keywords{$value}));
2717: }
2718: return 1;
2719: }
2720:
2721: ###################################################
2722:
2723: =pod
2724:
2725: =item * &keyword($word)
2726:
2727: Returns true if $word is a keyword. A keyword is a word that appears more
2728: than the average number of times in the thesaurus database. Calls
2729: &initialize_keywords
2730:
2731: =cut
2732:
2733: ###################################################
2734:
2735: sub keyword {
2736: return if (!&initialize_keywords());
2737: my $word=lc(shift());
2738: $word=~s/\W//g;
2739: return exists($Keywords{$word});
2740: }
2741:
2742: ###############################################################
2743:
2744: =pod
2745:
2746: =item * &get_related_words()
2747:
2748: Look up a word in the thesaurus. Takes a scalar argument and returns
2749: an array of words. If the keyword is not in the thesaurus, an empty array
2750: will be returned. The order of the words returned is determined by the
2751: database which holds them.
2752:
2753: Uses global $thesaurus_db_file.
2754:
2755: =cut
2756:
2757: ###############################################################
2758: sub get_related_words {
2759: my $keyword = shift;
2760: my %thesaurus_db;
2761: if (! -e $thesaurus_db_file) {
2762: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
2763: "failed because the file does not exist");
2764: return ();
2765: }
2766: if (! tie(%thesaurus_db,'GDBM_File',
2767: $thesaurus_db_file,&GDBM_READER(),0640)){
2768: return ();
2769: }
2770: my @Words=();
2771: my $count=0;
2772: if (exists($thesaurus_db{$keyword})) {
2773: # The first element is the number of times
2774: # the word appears. We do not need it now.
2775: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
2776: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
2777: my $threshold=$mostfrequentcount/10;
2778: foreach my $possibleword (@RelatedWords) {
2779: my ($word,$wordcount)=split(/\,/,$possibleword);
2780: if ($wordcount>$threshold) {
2781: push(@Words,$word);
2782: $count++;
2783: if ($count>10) { last; }
2784: }
2785: }
2786: }
2787: untie %thesaurus_db;
2788: return @Words;
2789: }
2790:
2791: =pod
2792:
2793: =back
2794:
2795: =cut
2796:
2797: # -------------------------------------------------------------- Plaintext name
2798: =pod
2799:
2800: =head1 User Name Functions
2801:
2802: =over 4
2803:
2804: =item * &plainname($uname,$udom,$first)
2805:
2806: Takes a users logon name and returns it as a string in
2807: "first middle last generation" form
2808: if $first is set to 'lastname' then it returns it as
2809: 'lastname generation, firstname middlename' if their is a lastname
2810:
2811: =cut
2812:
2813:
2814: ###############################################################
2815: sub plainname {
2816: my ($uname,$udom,$first)=@_;
2817: return if (!defined($uname) || !defined($udom));
2818: my %names=&getnames($uname,$udom);
2819: my $name=&Apache::lonnet::format_name($names{'firstname'},
2820: $names{'middlename'},
2821: $names{'lastname'},
2822: $names{'generation'},$first);
2823: $name=~s/^\s+//;
2824: $name=~s/\s+$//;
2825: $name=~s/\s+/ /g;
2826: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
2827: return $name;
2828: }
2829:
2830: # -------------------------------------------------------------------- Nickname
2831: =pod
2832:
2833: =item * &nickname($uname,$udom)
2834:
2835: Gets a users name and returns it as a string as
2836:
2837: ""nickname""
2838:
2839: if the user has a nickname or
2840:
2841: "first middle last generation"
2842:
2843: if the user does not
2844:
2845: =cut
2846:
2847: sub nickname {
2848: my ($uname,$udom)=@_;
2849: return if (!defined($uname) || !defined($udom));
2850: my %names=&getnames($uname,$udom);
2851: my $name=$names{'nickname'};
2852: if ($name) {
2853: $name='"'.$name.'"';
2854: } else {
2855: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
2856: $names{'lastname'}.' '.$names{'generation'};
2857: $name=~s/\s+$//;
2858: $name=~s/\s+/ /g;
2859: }
2860: return $name;
2861: }
2862:
2863: sub getnames {
2864: my ($uname,$udom)=@_;
2865: return if (!defined($uname) || !defined($udom));
2866: if ($udom eq 'public' && $uname eq 'public') {
2867: return ('lastname' => &mt('Public'));
2868: }
2869: my $id=$uname.':'.$udom;
2870: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
2871: if ($cached) {
2872: return %{$names};
2873: } else {
2874: my %loadnames=&Apache::lonnet::get('environment',
2875: ['firstname','middlename','lastname','generation','nickname'],
2876: $udom,$uname);
2877: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
2878: return %loadnames;
2879: }
2880: }
2881:
2882: # -------------------------------------------------------------------- getemails
2883:
2884: =pod
2885:
2886: =item * &getemails($uname,$udom)
2887:
2888: Gets a user's email information and returns it as a hash with keys:
2889: notification, critnotification, permanentemail
2890:
2891: For notification and critnotification, values are comma-separated lists
2892: of e-mail addresses; for permanentemail, value is a single e-mail address.
2893:
2894:
2895: =cut
2896:
2897:
2898: sub getemails {
2899: my ($uname,$udom)=@_;
2900: if ($udom eq 'public' && $uname eq 'public') {
2901: return;
2902: }
2903: if (!$udom) { $udom=$env{'user.domain'}; }
2904: if (!$uname) { $uname=$env{'user.name'}; }
2905: my $id=$uname.':'.$udom;
2906: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
2907: if ($cached) {
2908: return %{$names};
2909: } else {
2910: my %loadnames=&Apache::lonnet::get('environment',
2911: ['notification','critnotification',
2912: 'permanentemail'],
2913: $udom,$uname);
2914: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
2915: return %loadnames;
2916: }
2917: }
2918:
2919: sub flush_email_cache {
2920: my ($uname,$udom)=@_;
2921: if (!$udom) { $udom =$env{'user.domain'}; }
2922: if (!$uname) { $uname=$env{'user.name'}; }
2923: return if ($udom eq 'public' && $uname eq 'public');
2924: my $id=$uname.':'.$udom;
2925: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
2926: }
2927:
2928: # -------------------------------------------------------------------- getlangs
2929:
2930: =pod
2931:
2932: =item * &getlangs($uname,$udom)
2933:
2934: Gets a user's language preference and returns it as a hash with key:
2935: language.
2936:
2937: =cut
2938:
2939:
2940: sub getlangs {
2941: my ($uname,$udom) = @_;
2942: if (!$udom) { $udom =$env{'user.domain'}; }
2943: if (!$uname) { $uname=$env{'user.name'}; }
2944: my $id=$uname.':'.$udom;
2945: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
2946: if ($cached) {
2947: return %{$langs};
2948: } else {
2949: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
2950: $udom,$uname);
2951: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
2952: return %loadlangs;
2953: }
2954: }
2955:
2956: sub flush_langs_cache {
2957: my ($uname,$udom)=@_;
2958: if (!$udom) { $udom =$env{'user.domain'}; }
2959: if (!$uname) { $uname=$env{'user.name'}; }
2960: return if ($udom eq 'public' && $uname eq 'public');
2961: my $id=$uname.':'.$udom;
2962: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
2963: }
2964:
2965: # ------------------------------------------------------------------ Screenname
2966:
2967: =pod
2968:
2969: =item * &screenname($uname,$udom)
2970:
2971: Gets a users screenname and returns it as a string
2972:
2973: =cut
2974:
2975: sub screenname {
2976: my ($uname,$udom)=@_;
2977: if ($uname eq $env{'user.name'} &&
2978: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
2979: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
2980: return $names{'screenname'};
2981: }
2982:
2983:
2984: # ------------------------------------------------------------- Confirm Wrapper
2985: =pod
2986:
2987: =item confirmwrapper
2988:
2989: Wrap messages about completion of operation in box
2990:
2991: =cut
2992:
2993: sub confirmwrapper {
2994: my ($message)=@_;
2995: if ($message) {
2996: return "\n".'<div class="LC_confirm_box">'."\n"
2997: .$message."\n"
2998: .'</div>'."\n";
2999: } else {
3000: return $message;
3001: }
3002: }
3003:
3004: # ------------------------------------------------------------- Message Wrapper
3005:
3006: sub messagewrapper {
3007: my ($link,$username,$domain,$subject,$text)=@_;
3008: return
3009: '<a href="/adm/email?compose=individual&'.
3010: 'recname='.$username.'&recdom='.$domain.
3011: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
3012: 'title="'.&mt('Send message').'">'.$link.'</a>';
3013: }
3014:
3015: # --------------------------------------------------------------- Notes Wrapper
3016:
3017: sub noteswrapper {
3018: my ($link,$un,$do)=@_;
3019: return
3020: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
3021: }
3022:
3023: # ------------------------------------------------------------- Aboutme Wrapper
3024:
3025: sub aboutmewrapper {
3026: my ($link,$username,$domain,$target)=@_;
3027: if (!defined($username) && !defined($domain)) {
3028: return;
3029: }
3030: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme?forcestudent=1"'.
3031: ($target?' target="$target"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
3032: }
3033:
3034: # ------------------------------------------------------------ Syllabus Wrapper
3035:
3036: sub syllabuswrapper {
3037: my ($linktext,$coursedir,$domain)=@_;
3038: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
3039: }
3040:
3041: # -----------------------------------------------------------------------------
3042:
3043: sub track_student_link {
3044: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
3045: my $link ="/adm/trackstudent?";
3046: my $title = 'View recent activity';
3047: if (defined($sname) && $sname !~ /^\s*$/ &&
3048: defined($sdom) && $sdom !~ /^\s*$/) {
3049: $link .= "selected_student=$sname:$sdom";
3050: $title .= ' of this student';
3051: }
3052: if (defined($target) && $target !~ /^\s*$/) {
3053: $target = qq{target="$target"};
3054: } else {
3055: $target = '';
3056: }
3057: if ($start) { $link.='&start='.$start; }
3058: if ($only_body) { $link .= '&only_body=1'; }
3059: $title = &mt($title);
3060: $linktext = &mt($linktext);
3061: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3062: &help_open_topic('View_recent_activity');
3063: }
3064:
3065: sub slot_reservations_link {
3066: my ($linktext,$sname,$sdom,$target) = @_;
3067: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3068: my $title = 'View slot reservation history';
3069: if (defined($sname) && $sname !~ /^\s*$/ &&
3070: defined($sdom) && $sdom !~ /^\s*$/) {
3071: $link .= "&uname=$sname&udom=$sdom";
3072: $title .= ' of this student';
3073: }
3074: if (defined($target) && $target !~ /^\s*$/) {
3075: $target = qq{target="$target"};
3076: } else {
3077: $target = '';
3078: }
3079: $title = &mt($title);
3080: $linktext = &mt($linktext);
3081: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3082: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3083:
3084: }
3085:
3086: # ===================================================== Display a student photo
3087:
3088:
3089: sub student_image_tag {
3090: my ($domain,$user)=@_;
3091: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3092: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3093: return '<img src="'.$imgsrc.'" align="right" />';
3094: } else {
3095: return '';
3096: }
3097: }
3098:
3099: =pod
3100:
3101: =back
3102:
3103: =head1 Access .tab File Data
3104:
3105: =over 4
3106:
3107: =item * &languageids()
3108:
3109: returns list of all language ids
3110:
3111: =cut
3112:
3113: sub languageids {
3114: return sort(keys(%language));
3115: }
3116:
3117: =pod
3118:
3119: =item * &languagedescription()
3120:
3121: returns description of a specified language id
3122:
3123: =cut
3124:
3125: sub languagedescription {
3126: my $code=shift;
3127: return ($supported_language{$code}?'* ':'').
3128: $language{$code}.
3129: ($supported_language{$code}?' ('.&mt('interface available').')':'');
3130: }
3131:
3132: sub plainlanguagedescription {
3133: my $code=shift;
3134: return $language{$code};
3135: }
3136:
3137: sub supportedlanguagecode {
3138: my $code=shift;
3139: return $supported_language{$code};
3140: }
3141:
3142: =pod
3143:
3144: =item * ©rightids()
3145:
3146: returns list of all copyrights
3147:
3148: =cut
3149:
3150: sub copyrightids {
3151: return sort(keys(%cprtag));
3152: }
3153:
3154: =pod
3155:
3156: =item * ©rightdescription()
3157:
3158: returns description of a specified copyright id
3159:
3160: =cut
3161:
3162: sub copyrightdescription {
3163: return &mt($cprtag{shift(@_)});
3164: }
3165:
3166: =pod
3167:
3168: =item * &source_copyrightids()
3169:
3170: returns list of all source copyrights
3171:
3172: =cut
3173:
3174: sub source_copyrightids {
3175: return sort(keys(%scprtag));
3176: }
3177:
3178: =pod
3179:
3180: =item * &source_copyrightdescription()
3181:
3182: returns description of a specified source copyright id
3183:
3184: =cut
3185:
3186: sub source_copyrightdescription {
3187: return &mt($scprtag{shift(@_)});
3188: }
3189:
3190: =pod
3191:
3192: =item * &filecategories()
3193:
3194: returns list of all file categories
3195:
3196: =cut
3197:
3198: sub filecategories {
3199: return sort(keys(%category_extensions));
3200: }
3201:
3202: =pod
3203:
3204: =item * &filecategorytypes()
3205:
3206: returns list of file types belonging to a given file
3207: category
3208:
3209: =cut
3210:
3211: sub filecategorytypes {
3212: my ($cat) = @_;
3213: return @{$category_extensions{lc($cat)}};
3214: }
3215:
3216: =pod
3217:
3218: =item * &fileembstyle()
3219:
3220: returns embedding style for a specified file type
3221:
3222: =cut
3223:
3224: sub fileembstyle {
3225: return $fe{lc(shift(@_))};
3226: }
3227:
3228: sub filemimetype {
3229: return $fm{lc(shift(@_))};
3230: }
3231:
3232:
3233: sub filecategoryselect {
3234: my ($name,$value)=@_;
3235: return &select_form($value,$name,
3236: '' => &mt('Any category'),
3237: map { $_,$_ } sort(keys(%category_extensions)));
3238: }
3239:
3240: =pod
3241:
3242: =item * &filedescription()
3243:
3244: returns description for a specified file type
3245:
3246: =cut
3247:
3248: sub filedescription {
3249: my $file_description = $fd{lc(shift())};
3250: $file_description =~ s:([\[\]]):~$1:g;
3251: return &mt($file_description);
3252: }
3253:
3254: =pod
3255:
3256: =item * &filedescriptionex()
3257:
3258: returns description for a specified file type with
3259: extra formatting
3260:
3261: =cut
3262:
3263: sub filedescriptionex {
3264: my $ex=shift;
3265: my $file_description = $fd{lc($ex)};
3266: $file_description =~ s:([\[\]]):~$1:g;
3267: return '.'.$ex.' '.&mt($file_description);
3268: }
3269:
3270: # End of .tab access
3271: =pod
3272:
3273: =back
3274:
3275: =cut
3276:
3277: # ------------------------------------------------------------------ File Types
3278: sub fileextensions {
3279: return sort(keys(%fe));
3280: }
3281:
3282: # ----------------------------------------------------------- Display Languages
3283: # returns a hash with all desired display languages
3284: #
3285:
3286: sub display_languages {
3287: my %languages=();
3288: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
3289: $languages{$lang}=1;
3290: }
3291: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
3292: if ($env{'form.displaylanguage'}) {
3293: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3294: $languages{$lang}=1;
3295: }
3296: }
3297: return %languages;
3298: }
3299:
3300: sub languages {
3301: my ($possible_langs) = @_;
3302: my @preferred_langs = &Apache::lonlocal::preferred_languages();
3303: if (!ref($possible_langs)) {
3304: if( wantarray ) {
3305: return @preferred_langs;
3306: } else {
3307: return $preferred_langs[0];
3308: }
3309: }
3310: my %possibilities = map { $_ => 1 } (@$possible_langs);
3311: my @preferred_possibilities;
3312: foreach my $preferred_lang (@preferred_langs) {
3313: if (exists($possibilities{$preferred_lang})) {
3314: push(@preferred_possibilities, $preferred_lang);
3315: }
3316: }
3317: if( wantarray ) {
3318: return @preferred_possibilities;
3319: }
3320: return $preferred_possibilities[0];
3321: }
3322:
3323: sub user_lang {
3324: my ($touname,$toudom,$fromcid) = @_;
3325: my @userlangs;
3326: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3327: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3328: $env{'course.'.$fromcid.'.languages'}));
3329: } else {
3330: my %langhash = &getlangs($touname,$toudom);
3331: if ($langhash{'languages'} ne '') {
3332: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3333: } else {
3334: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3335: if ($domdefs{'lang_def'} ne '') {
3336: @userlangs = ($domdefs{'lang_def'});
3337: }
3338: }
3339: }
3340: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3341: my $user_lh = Apache::localize->get_handle(@languages);
3342: return $user_lh;
3343: }
3344:
3345:
3346: ###############################################################
3347: ## Student Answer Attempts ##
3348: ###############################################################
3349:
3350: =pod
3351:
3352: =head1 Alternate Problem Views
3353:
3354: =over 4
3355:
3356: =item * &get_previous_attempt($symb, $username, $domain, $course,
3357: $getattempt, $regexp, $gradesub)
3358:
3359: Return string with previous attempt on problem. Arguments:
3360:
3361: =over 4
3362:
3363: =item * $symb: Problem, including path
3364:
3365: =item * $username: username of the desired student
3366:
3367: =item * $domain: domain of the desired student
3368:
3369: =item * $course: Course ID
3370:
3371: =item * $getattempt: Leave blank for all attempts, otherwise put
3372: something
3373:
3374: =item * $regexp: if string matches this regexp, the string will be
3375: sent to $gradesub
3376:
3377: =item * $gradesub: routine that processes the string if it matches $regexp
3378:
3379: =back
3380:
3381: The output string is a table containing all desired attempts, if any.
3382:
3383: =cut
3384:
3385: sub get_previous_attempt {
3386: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
3387: my $prevattempts='';
3388: no strict 'refs';
3389: if ($symb) {
3390: my (%returnhash)=
3391: &Apache::lonnet::restore($symb,$course,$domain,$username);
3392: if ($returnhash{'version'}) {
3393: my %lasthash=();
3394: my $version;
3395: for ($version=1;$version<=$returnhash{'version'};$version++) {
3396: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3397: $lasthash{$key}=$returnhash{$version.':'.$key};
3398: }
3399: }
3400: $prevattempts=&start_data_table().&start_data_table_header_row();
3401: $prevattempts.='<th>'.&mt('History').'</th>';
3402: foreach my $key (sort(keys(%lasthash))) {
3403: my ($ign,@parts) = split(/\./,$key);
3404: if ($#parts > 0) {
3405: my $data=$parts[-1];
3406: pop(@parts);
3407: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
3408: } else {
3409: if ($#parts == 0) {
3410: $prevattempts.='<th>'.$parts[0].'</th>';
3411: } else {
3412: $prevattempts.='<th>'.$ign.'</th>';
3413: }
3414: }
3415: }
3416: $prevattempts.=&end_data_table_header_row();
3417: if ($getattempt eq '') {
3418: for ($version=1;$version<=$returnhash{'version'};$version++) {
3419: $prevattempts.=&start_data_table_row().
3420: '<td>'.&mt('Transaction [_1]',$version).'</td>';
3421: foreach my $key (sort(keys(%lasthash))) {
3422: my $value = &format_previous_attempt_value($key,
3423: $returnhash{$version.':'.$key});
3424: $prevattempts.='<td>'.$value.' </td>';
3425: }
3426: $prevattempts.=&end_data_table_row();
3427: }
3428: }
3429: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
3430: foreach my $key (sort(keys(%lasthash))) {
3431: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3432: if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
3433: $prevattempts.='<td>'.$value.' </td>';
3434: }
3435: $prevattempts.= &end_data_table_row().&end_data_table();
3436: } else {
3437: $prevattempts=
3438: &start_data_table().&start_data_table_row().
3439: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3440: &end_data_table_row().&end_data_table();
3441: }
3442: } else {
3443: $prevattempts=
3444: &start_data_table().&start_data_table_row().
3445: '<td>'.&mt('No data.').'</td>'.
3446: &end_data_table_row().&end_data_table();
3447: }
3448: }
3449:
3450: sub format_previous_attempt_value {
3451: my ($key,$value) = @_;
3452: if ($key =~ /timestamp/) {
3453: $value = &Apache::lonlocal::locallocaltime($value);
3454: } elsif (ref($value) eq 'ARRAY') {
3455: $value = '('.join(', ', @{ $value }).')';
3456: } else {
3457: $value = &unescape($value);
3458: }
3459: return $value;
3460: }
3461:
3462:
3463: sub relative_to_absolute {
3464: my ($url,$output)=@_;
3465: my $parser=HTML::TokeParser->new(\$output);
3466: my $token;
3467: my $thisdir=$url;
3468: my @rlinks=();
3469: while ($token=$parser->get_token) {
3470: if ($token->[0] eq 'S') {
3471: if ($token->[1] eq 'a') {
3472: if ($token->[2]->{'href'}) {
3473: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3474: }
3475: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3476: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3477: } elsif ($token->[1] eq 'base') {
3478: $thisdir=$token->[2]->{'href'};
3479: }
3480: }
3481: }
3482: $thisdir=~s-/[^/]*$--;
3483: foreach my $link (@rlinks) {
3484: unless (($link=~/^https?\:\/\//i) ||
3485: ($link=~/^\//) ||
3486: ($link=~/^javascript:/i) ||
3487: ($link=~/^mailto:/i) ||
3488: ($link=~/^\#/)) {
3489: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3490: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
3491: }
3492: }
3493: # -------------------------------------------------- Deal with Applet codebases
3494: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3495: return $output;
3496: }
3497:
3498: =pod
3499:
3500: =item * &get_student_view()
3501:
3502: show a snapshot of what student was looking at
3503:
3504: =cut
3505:
3506: sub get_student_view {
3507: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
3508: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
3509: my (%form);
3510: my @elements=('symb','courseid','domain','username');
3511: foreach my $element (@elements) {
3512: $form{'grade_'.$element}=eval '$'.$element #'
3513: }
3514: if (defined($moreenv)) {
3515: %form=(%form,%{$moreenv});
3516: }
3517: if (defined($target)) { $form{'grade_target'} = $target; }
3518: $feedurl=&Apache::lonnet::clutter($feedurl);
3519: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
3520: $userview=~s/\<body[^\>]*\>//gi;
3521: $userview=~s/\<\/body\>//gi;
3522: $userview=~s/\<html\>//gi;
3523: $userview=~s/\<\/html\>//gi;
3524: $userview=~s/\<head\>//gi;
3525: $userview=~s/\<\/head\>//gi;
3526: $userview=~s/action\s*\=/would_be_action\=/gi;
3527: $userview=&relative_to_absolute($feedurl,$userview);
3528: if (wantarray) {
3529: return ($userview,$response);
3530: } else {
3531: return $userview;
3532: }
3533: }
3534:
3535: sub get_student_view_with_retries {
3536: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3537:
3538: my $ok = 0; # True if we got a good response.
3539: my $content;
3540: my $response;
3541:
3542: # Try to get the student_view done. within the retries count:
3543:
3544: do {
3545: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3546: $ok = $response->is_success;
3547: if (!$ok) {
3548: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3549: }
3550: $retries--;
3551: } while (!$ok && ($retries > 0));
3552:
3553: if (!$ok) {
3554: $content = ''; # On error return an empty content.
3555: }
3556: if (wantarray) {
3557: return ($content, $response);
3558: } else {
3559: return $content;
3560: }
3561: }
3562:
3563: =pod
3564:
3565: =item * &get_student_answers()
3566:
3567: show a snapshot of how student was answering problem
3568:
3569: =cut
3570:
3571: sub get_student_answers {
3572: my ($symb,$username,$domain,$courseid,%form) = @_;
3573: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
3574: my (%moreenv);
3575: my @elements=('symb','courseid','domain','username');
3576: foreach my $element (@elements) {
3577: $moreenv{'grade_'.$element}=eval '$'.$element #'
3578: }
3579: $moreenv{'grade_target'}='answer';
3580: %moreenv=(%form,%moreenv);
3581: $feedurl = &Apache::lonnet::clutter($feedurl);
3582: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
3583: return $userview;
3584: }
3585:
3586: =pod
3587:
3588: =item * &submlink()
3589:
3590: Inputs: $text $uname $udom $symb $target
3591:
3592: Returns: A link to grades.pm such as to see the SUBM view of a student
3593:
3594: =cut
3595:
3596: ###############################################
3597: sub submlink {
3598: my ($text,$uname,$udom,$symb,$target)=@_;
3599: if (!($uname && $udom)) {
3600: (my $cursymb, my $courseid,$udom,$uname)=
3601: &Apache::lonnet::whichuser($symb);
3602: if (!$symb) { $symb=$cursymb; }
3603: }
3604: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
3605: $symb=&escape($symb);
3606: if ($target) { $target="target=\"$target\""; }
3607: return '<a href="/adm/grades?&command=submission&'.
3608: 'symb='.$symb.'&student='.$uname.
3609: '&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
3610: }
3611: ##############################################
3612:
3613: =pod
3614:
3615: =item * &pgrdlink()
3616:
3617: Inputs: $text $uname $udom $symb $target
3618:
3619: Returns: A link to grades.pm such as to see the PGRD view of a student
3620:
3621: =cut
3622:
3623: ###############################################
3624: sub pgrdlink {
3625: my $link=&submlink(@_);
3626: $link=~s/(&command=submission)/$1&showgrading=yes/;
3627: return $link;
3628: }
3629: ##############################################
3630:
3631: =pod
3632:
3633: =item * &pprmlink()
3634:
3635: Inputs: $text $uname $udom $symb $target
3636:
3637: Returns: A link to parmset.pm such as to see the PPRM view of a
3638: student and a specific resource
3639:
3640: =cut
3641:
3642: ###############################################
3643: sub pprmlink {
3644: my ($text,$uname,$udom,$symb,$target)=@_;
3645: if (!($uname && $udom)) {
3646: (my $cursymb, my $courseid,$udom,$uname)=
3647: &Apache::lonnet::whichuser($symb);
3648: if (!$symb) { $symb=$cursymb; }
3649: }
3650: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
3651: $symb=&escape($symb);
3652: if ($target) { $target="target=\"$target\""; }
3653: return '<a href="/adm/parmset?command=set&'.
3654: 'symb='.$symb.'&uname='.$uname.
3655: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
3656: }
3657: ##############################################
3658:
3659: =pod
3660:
3661: =back
3662:
3663: =cut
3664:
3665: ###############################################
3666:
3667:
3668: sub timehash {
3669: my ($thistime) = @_;
3670: my $timezone = &Apache::lonlocal::gettimezone();
3671: my $dt = DateTime->from_epoch(epoch => $thistime)
3672: ->set_time_zone($timezone);
3673: my $wday = $dt->day_of_week();
3674: if ($wday == 7) { $wday = 0; }
3675: return ( 'second' => $dt->second(),
3676: 'minute' => $dt->minute(),
3677: 'hour' => $dt->hour(),
3678: 'day' => $dt->day_of_month(),
3679: 'month' => $dt->month(),
3680: 'year' => $dt->year(),
3681: 'weekday' => $wday,
3682: 'dayyear' => $dt->day_of_year(),
3683: 'dlsav' => $dt->is_dst() );
3684: }
3685:
3686: sub utc_string {
3687: my ($date)=@_;
3688: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
3689: }
3690:
3691: sub maketime {
3692: my %th=@_;
3693: my ($epoch_time,$timezone,$dt);
3694: $timezone = &Apache::lonlocal::gettimezone();
3695: eval {
3696: $dt = DateTime->new( year => $th{'year'},
3697: month => $th{'month'},
3698: day => $th{'day'},
3699: hour => $th{'hour'},
3700: minute => $th{'minute'},
3701: second => $th{'second'},
3702: time_zone => $timezone,
3703: );
3704: };
3705: if (!$@) {
3706: $epoch_time = $dt->epoch;
3707: if ($epoch_time) {
3708: return $epoch_time;
3709: }
3710: }
3711: return POSIX::mktime(
3712: ($th{'seconds'},$th{'minutes'},$th{'hours'},
3713: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
3714: }
3715:
3716: #########################################
3717:
3718: sub findallcourses {
3719: my ($roles,$uname,$udom) = @_;
3720: my %roles;
3721: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
3722: my %courses;
3723: my $now=time;
3724: if (!defined($uname)) {
3725: $uname = $env{'user.name'};
3726: }
3727: if (!defined($udom)) {
3728: $udom = $env{'user.domain'};
3729: }
3730: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
3731: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
3732: if (!%roles) {
3733: %roles = (
3734: cc => 1,
3735: co => 1,
3736: in => 1,
3737: ep => 1,
3738: ta => 1,
3739: cr => 1,
3740: st => 1,
3741: );
3742: }
3743: foreach my $entry (keys(%roleshash)) {
3744: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
3745: if ($trole =~ /^cr/) {
3746: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
3747: } else {
3748: next if (!exists($roles{$trole}));
3749: }
3750: if ($tend) {
3751: next if ($tend < $now);
3752: }
3753: if ($tstart) {
3754: next if ($tstart > $now);
3755: }
3756: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
3757: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
3758: if ($secpart eq '') {
3759: ($cnum,$role) = split(/_/,$cnumpart);
3760: $sec = 'none';
3761: $realsec = '';
3762: } else {
3763: $cnum = $cnumpart;
3764: ($sec,$role) = split(/_/,$secpart);
3765: $realsec = $sec;
3766: }
3767: $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
3768: }
3769: } else {
3770: foreach my $key (keys(%env)) {
3771: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
3772: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
3773: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
3774: next if ($role eq 'ca' || $role eq 'aa');
3775: next if (%roles && !exists($roles{$role}));
3776: my ($starttime,$endtime)=split(/\./,$env{$key});
3777: my $active=1;
3778: if ($starttime) {
3779: if ($now<$starttime) { $active=0; }
3780: }
3781: if ($endtime) {
3782: if ($now>$endtime) { $active=0; }
3783: }
3784: if ($active) {
3785: if ($sec eq '') {
3786: $sec = 'none';
3787: }
3788: $courses{$cdom.'_'.$cnum}{$sec} =
3789: $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
3790: }
3791: }
3792: }
3793: }
3794: return %courses;
3795: }
3796:
3797: ###############################################
3798:
3799: sub blockcheck {
3800: my ($setters,$activity,$uname,$udom) = @_;
3801:
3802: if (!defined($udom)) {
3803: $udom = $env{'user.domain'};
3804: }
3805: if (!defined($uname)) {
3806: $uname = $env{'user.name'};
3807: }
3808:
3809: # If uname and udom are for a course, check for blocks in the course.
3810:
3811: if (&Apache::lonnet::is_course($udom,$uname)) {
3812: my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
3813: my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
3814: return ($startblock,$endblock);
3815: }
3816:
3817: my $startblock = 0;
3818: my $endblock = 0;
3819: my %live_courses = &findallcourses(undef,$uname,$udom);
3820:
3821: # If uname is for a user, and activity is course-specific, i.e.,
3822: # boards, chat or groups, check for blocking in current course only.
3823:
3824: if (($activity eq 'boards' || $activity eq 'chat' ||
3825: $activity eq 'groups') && ($env{'request.course.id'})) {
3826: foreach my $key (keys(%live_courses)) {
3827: if ($key ne $env{'request.course.id'}) {
3828: delete($live_courses{$key});
3829: }
3830: }
3831: }
3832:
3833: my $otheruser = 0;
3834: my %own_courses;
3835: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
3836: # Resource belongs to user other than current user.
3837: $otheruser = 1;
3838: # Gather courses for current user
3839: %own_courses =
3840: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
3841: }
3842:
3843: # Gather active course roles - course coordinator, instructor,
3844: # exam proctor, ta, student, or custom role.
3845:
3846: foreach my $course (keys(%live_courses)) {
3847: my ($cdom,$cnum);
3848: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
3849: $cdom = $env{'course.'.$course.'.domain'};
3850: $cnum = $env{'course.'.$course.'.num'};
3851: } else {
3852: ($cdom,$cnum) = split(/_/,$course);
3853: }
3854: my $no_ownblock = 0;
3855: my $no_userblock = 0;
3856: if ($otheruser && $activity ne 'com') {
3857: # Check if current user has 'evb' priv for this
3858: if (defined($own_courses{$course})) {
3859: foreach my $sec (keys(%{$own_courses{$course}})) {
3860: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
3861: if ($sec ne 'none') {
3862: $checkrole .= '/'.$sec;
3863: }
3864: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3865: $no_ownblock = 1;
3866: last;
3867: }
3868: }
3869: }
3870: # if they have 'evb' priv and are currently not playing student
3871: next if (($no_ownblock) &&
3872: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
3873: }
3874: foreach my $sec (keys(%{$live_courses{$course}})) {
3875: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
3876: if ($sec ne 'none') {
3877: $checkrole .= '/'.$sec;
3878: }
3879: if ($otheruser) {
3880: # Resource belongs to user other than current user.
3881: # Assemble privs for that user, and check for 'evb' priv.
3882: my ($trole,$tdom,$tnum,$tsec);
3883: my $entry = $live_courses{$course}{$sec};
3884: if ($entry =~ /^cr/) {
3885: ($trole,$tdom,$tnum,$tsec) =
3886: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
3887: } else {
3888: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
3889: }
3890: my ($spec,$area,$trest,%allroles,%userroles);
3891: $area = '/'.$tdom.'/'.$tnum;
3892: $trest = $tnum;
3893: if ($tsec ne '') {
3894: $area .= '/'.$tsec;
3895: $trest .= '/'.$tsec;
3896: }
3897: $spec = $trole.'.'.$area;
3898: if ($trole =~ /^cr/) {
3899: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
3900: $tdom,$spec,$trest,$area);
3901: } else {
3902: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
3903: $tdom,$spec,$trest,$area);
3904: }
3905: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
3906: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
3907: if ($1) {
3908: $no_userblock = 1;
3909: last;
3910: }
3911: }
3912: } else {
3913: # Resource belongs to current user
3914: # Check for 'evb' priv via lonnet::allowed().
3915: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3916: $no_ownblock = 1;
3917: last;
3918: }
3919: }
3920: }
3921: # if they have the evb priv and are currently not playing student
3922: next if (($no_ownblock) &&
3923: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
3924: next if ($no_userblock);
3925:
3926: # Retrieve blocking times and identity of locker for course
3927: # of specified user, unless user has 'evb' privilege.
3928:
3929: my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
3930: if (($start != 0) &&
3931: (($startblock == 0) || ($startblock > $start))) {
3932: $startblock = $start;
3933: }
3934: if (($end != 0) &&
3935: (($endblock == 0) || ($endblock < $end))) {
3936: $endblock = $end;
3937: }
3938: }
3939: return ($startblock,$endblock);
3940: }
3941:
3942: sub get_blocks {
3943: my ($setters,$activity,$cdom,$cnum) = @_;
3944: my $startblock = 0;
3945: my $endblock = 0;
3946: my $course = $cdom.'_'.$cnum;
3947: $setters->{$course} = {};
3948: $setters->{$course}{'staff'} = [];
3949: $setters->{$course}{'times'} = [];
3950: my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
3951: foreach my $record (keys(%records)) {
3952: my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
3953: if ($start <= time && $end >= time) {
3954: my ($staff_name,$staff_dom,$title,$blocks) =
3955: &parse_block_record($records{$record});
3956: if ($blocks->{$activity} eq 'on') {
3957: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
3958: push(@{$$setters{$course}{'times'}}, [$start,$end]);
3959: if ( ($startblock == 0) || ($startblock > $start) ) {
3960: $startblock = $start;
3961: }
3962: if ( ($endblock == 0) || ($endblock < $end) ) {
3963: $endblock = $end;
3964: }
3965: }
3966: }
3967: }
3968: return ($startblock,$endblock);
3969: }
3970:
3971: sub parse_block_record {
3972: my ($record) = @_;
3973: my ($setuname,$setudom,$title,$blocks);
3974: if (ref($record) eq 'HASH') {
3975: ($setuname,$setudom) = split(/:/,$record->{'setter'});
3976: $title = &unescape($record->{'event'});
3977: $blocks = $record->{'blocks'};
3978: } else {
3979: my @data = split(/:/,$record,3);
3980: if (scalar(@data) eq 2) {
3981: $title = $data[1];
3982: ($setuname,$setudom) = split(/@/,$data[0]);
3983: } else {
3984: ($setuname,$setudom,$title) = @data;
3985: }
3986: $blocks = { 'com' => 'on' };
3987: }
3988: return ($setuname,$setudom,$title,$blocks);
3989: }
3990:
3991: sub blocking_status {
3992: my ($activity,$uname,$udom) = @_;
3993: my %setters;
3994:
3995: # check for active blocking
3996: my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
3997:
3998: my $blocked = $startblock && $endblock ? 1 : 0;
3999:
4000: # caller just wants to know whether a block is active
4001: if (!wantarray) { return $blocked; }
4002:
4003: # build a link to a popup window containing the details
4004: my $querystring = "?activity=$activity";
4005: # $uname and $udom decide whose portfolio the user is trying to look at
4006: $querystring .= "&udom=$udom" if $udom;
4007: $querystring .= "&uname=$uname" if $uname;
4008:
4009: my $output .= <<'END_MYBLOCK';
4010: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4011: var options = "width=" + w + ",height=" + h + ",";
4012: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4013: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4014: var newWin = window.open(url, wdwName, options);
4015: newWin.focus();
4016: }
4017: END_MYBLOCK
4018:
4019: $output = Apache::lonhtmlcommon::scripttag($output);
4020:
4021: my $popupUrl = "/adm/blockingstatus/$querystring";
4022: my $text = mt('Communication Blocked');
4023:
4024: $output .= <<"END_BLOCK";
4025: <div class='LC_comblock'>
4026: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
4027: title='$text'>
4028: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
4029: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
4030: title='$text'>$text</a>
4031: </div>
4032:
4033: END_BLOCK
4034:
4035: return ($blocked, $output);
4036: }
4037:
4038: ###############################################
4039:
4040: sub check_ip_acc {
4041: my ($acc)=@_;
4042: &Apache::lonxml::debug("acc is $acc");
4043: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
4044: return 1;
4045: }
4046: my $allowed=0;
4047: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
4048:
4049: my $name;
4050: foreach my $pattern (split(',',$acc)) {
4051: $pattern =~ s/^\s*//;
4052: $pattern =~ s/\s*$//;
4053: if ($pattern =~ /\*$/) {
4054: #35.8.*
4055: $pattern=~s/\*//;
4056: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4057: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
4058: #35.8.3.[34-56]
4059: my $low=$2;
4060: my $high=$3;
4061: $pattern=$1;
4062: if ($ip =~ /^\Q$pattern\E/) {
4063: my $last=(split(/\./,$ip))[3];
4064: if ($last <=$high && $last >=$low) { $allowed=1; }
4065: }
4066: } elsif ($pattern =~ /^\*/) {
4067: #*.msu.edu
4068: $pattern=~s/\*//;
4069: if (!defined($name)) {
4070: use Socket;
4071: my $netaddr=inet_aton($ip);
4072: ($name)=gethostbyaddr($netaddr,AF_INET);
4073: }
4074: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4075: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
4076: #127.0.0.1
4077: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4078: } else {
4079: #some.name.com
4080: if (!defined($name)) {
4081: use Socket;
4082: my $netaddr=inet_aton($ip);
4083: ($name)=gethostbyaddr($netaddr,AF_INET);
4084: }
4085: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4086: }
4087: if ($allowed) { last; }
4088: }
4089: return $allowed;
4090: }
4091:
4092: ###############################################
4093:
4094: =pod
4095:
4096: =head1 Domain Template Functions
4097:
4098: =over 4
4099:
4100: =item * &determinedomain()
4101:
4102: Inputs: $domain (usually will be undef)
4103:
4104: Returns: Determines which domain should be used for designs
4105:
4106: =cut
4107:
4108: ###############################################
4109: sub determinedomain {
4110: my $domain=shift;
4111: if (! $domain) {
4112: # Determine domain if we have not been given one
4113: $domain = &Apache::lonnet::default_login_domain();
4114: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
4115: if ($env{'request.role.domain'}) {
4116: $domain=$env{'request.role.domain'};
4117: }
4118: }
4119: return $domain;
4120: }
4121: ###############################################
4122:
4123: sub devalidate_domconfig_cache {
4124: my ($udom)=@_;
4125: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
4126: }
4127:
4128: # ---------------------- Get domain configuration for a domain
4129: sub get_domainconf {
4130: my ($udom) = @_;
4131: my $cachetime=1800;
4132: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
4133: if (defined($cached)) { return %{$result}; }
4134:
4135: my %domconfig = &Apache::lonnet::get_dom('configuration',
4136: ['login','rolecolors'],$udom);
4137: my (%designhash,%legacy);
4138: if (keys(%domconfig) > 0) {
4139: if (ref($domconfig{'login'}) eq 'HASH') {
4140: if (keys(%{$domconfig{'login'}})) {
4141: foreach my $key (keys(%{$domconfig{'login'}})) {
4142: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
4143: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4144: $designhash{$udom.'.login.'.$key.'_'.$img} =
4145: $domconfig{'login'}{$key}{$img};
4146: }
4147: } else {
4148: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4149: }
4150: }
4151: } else {
4152: $legacy{'login'} = 1;
4153: }
4154: } else {
4155: $legacy{'login'} = 1;
4156: }
4157: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
4158: if (keys(%{$domconfig{'rolecolors'}})) {
4159: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4160: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4161: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4162: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4163: }
4164: }
4165: }
4166: } else {
4167: $legacy{'rolecolors'} = 1;
4168: }
4169: } else {
4170: $legacy{'rolecolors'} = 1;
4171: }
4172: if (keys(%legacy) > 0) {
4173: my %legacyhash = &get_legacy_domconf($udom);
4174: foreach my $item (keys(%legacyhash)) {
4175: if ($item =~ /^\Q$udom\E\.login/) {
4176: if ($legacy{'login'}) {
4177: $designhash{$item} = $legacyhash{$item};
4178: }
4179: } else {
4180: if ($legacy{'rolecolors'}) {
4181: $designhash{$item} = $legacyhash{$item};
4182: }
4183: }
4184: }
4185: }
4186: } else {
4187: %designhash = &get_legacy_domconf($udom);
4188: }
4189: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4190: $cachetime);
4191: return %designhash;
4192: }
4193:
4194: sub get_legacy_domconf {
4195: my ($udom) = @_;
4196: my %legacyhash;
4197: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4198: my $designfile = $designdir.'/'.$udom.'.tab';
4199: if (-e $designfile) {
4200: if ( open (my $fh,"<$designfile") ) {
4201: while (my $line = <$fh>) {
4202: next if ($line =~ /^\#/);
4203: chomp($line);
4204: my ($key,$val)=(split(/\=/,$line));
4205: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4206: }
4207: close($fh);
4208: }
4209: }
4210: if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
4211: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4212: }
4213: return %legacyhash;
4214: }
4215:
4216: =pod
4217:
4218: =item * &domainlogo()
4219:
4220: Inputs: $domain (usually will be undef)
4221:
4222: Returns: A link to a domain logo, if the domain logo exists.
4223: If the domain logo does not exist, a description of the domain.
4224:
4225: =cut
4226:
4227: ###############################################
4228: sub domainlogo {
4229: my $domain = &determinedomain(shift);
4230: my %designhash = &get_domainconf($domain);
4231: # See if there is a logo
4232: if ($designhash{$domain.'.login.domlogo'} ne '') {
4233: my $imgsrc = $designhash{$domain.'.login.domlogo'};
4234: if ($imgsrc =~ m{^/(adm|res)/}) {
4235: if ($imgsrc =~ m{^/res/}) {
4236: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4237: &Apache::lonnet::repcopy($local_name);
4238: }
4239: $imgsrc = &lonhttpdurl($imgsrc);
4240: }
4241: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
4242: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4243: return &Apache::lonnet::domain($domain,'description');
4244: } else {
4245: return '';
4246: }
4247: }
4248: ##############################################
4249:
4250: =pod
4251:
4252: =item * &designparm()
4253:
4254: Inputs: $which parameter; $domain (usually will be undef)
4255:
4256: Returns: value of designparamter $which
4257:
4258: =cut
4259:
4260:
4261: ##############################################
4262: sub designparm {
4263: my ($which,$domain)=@_;
4264: if (exists($env{'environment.color.'.$which})) {
4265: return $env{'environment.color.'.$which};
4266: }
4267: $domain=&determinedomain($domain);
4268: my %domdesign = &get_domainconf($domain);
4269: my $output;
4270: if ($domdesign{$domain.'.'.$which} ne '') {
4271: $output = $domdesign{$domain.'.'.$which};
4272: } else {
4273: $output = $defaultdesign{$which};
4274: }
4275: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
4276: ($which =~ /login\.(img|logo|domlogo|login)/)) {
4277: if ($output =~ m{^/(adm|res)/}) {
4278: if ($output =~ m{^/res/}) {
4279: my $local_name = &Apache::lonnet::filelocation('',$output);
4280: &Apache::lonnet::repcopy($local_name);
4281: }
4282: $output = &lonhttpdurl($output);
4283: }
4284: }
4285: return $output;
4286: }
4287:
4288: ##############################################
4289: =pod
4290:
4291: =item * &authorspace()
4292:
4293: Inputs: ./.
4294:
4295: Returns: Path to the Construction Space of the current user's
4296: accessed author space
4297: The author space will be that of the current user
4298: when accessing the own author space
4299: and that of the co-author/assistent co-author
4300: when accessing the co-author's/assistent co-author's
4301: space
4302:
4303: =cut
4304:
4305: sub authorspace {
4306: my $caname = '';
4307: if ($env{'request.role'} =~ /^ca|^aa/) {
4308: (undef,$caname) =
4309: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
4310: } else {
4311: $caname = $env{'user.name'};
4312: }
4313: return '/priv/'.$caname.'/';
4314: }
4315:
4316: ##############################################
4317: =pod
4318:
4319: =item * &head_subbox()
4320:
4321: Inputs: $content (contains HTML code with page functions, etc.)
4322:
4323: Returns: HTML div with $content
4324: To be included in page header
4325:
4326: =cut
4327:
4328: sub head_subbox {
4329: my ($content)=@_;
4330: my $output =
4331: '<div id="LC_head_subbox">'
4332: .$content
4333: .'</div>'
4334: }
4335:
4336: ##############################################
4337: =pod
4338:
4339: =item * &CSTR_pageheader()
4340:
4341: Inputs: ./.
4342:
4343: Returns: HTML div with CSTR path and recent box
4344: To be included on Construction Space pages
4345:
4346: =cut
4347:
4348: sub CSTR_pageheader {
4349: # this is for resources; directories have customtitle, and crumbs
4350: # and select recent are created in lonpubdir.pm
4351: my ($uname,$thisdisfn)=
4352: ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
4353: my $formaction='/priv/'.$uname.'/'.$thisdisfn;
4354: $formaction=~s/\/+/\//g;
4355:
4356: my $parentpath = '';
4357: my $lastitem = '';
4358: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4359: $parentpath = $1;
4360: $lastitem = $2;
4361: } else {
4362: $lastitem = $thisdisfn;
4363: }
4364: return
4365: '<div>'
4366: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
4367: .'<b>'.&mt('Construction Space:').'</b> '
4368: .'<form name="dirs" method="post" action="'.$formaction
4369: .'" target="_top"><tt><b>' #FIXME lonpubdir: target="_parent"
4370: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."$lastitem</b></tt><br />"
4371: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
4372: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4373: .'</form>'
4374: .&Apache::lonmenu::constspaceform()
4375: .'</div>';
4376: }
4377:
4378: ###############################################
4379: ###############################################
4380:
4381: =pod
4382:
4383: =back
4384:
4385: =head1 HTML Helpers
4386:
4387: =over 4
4388:
4389: =item * &bodytag()
4390:
4391: Returns a uniform header for LON-CAPA web pages.
4392:
4393: Inputs:
4394:
4395: =over 4
4396:
4397: =item * $title, A title to be displayed on the page.
4398:
4399: =item * $function, the current role (can be undef).
4400:
4401: =item * $addentries, extra parameters for the <body> tag.
4402:
4403: =item * $bodyonly, if defined, only return the <body> tag.
4404:
4405: =item * $domain, if defined, force a given domain.
4406:
4407: =item * $forcereg, if page should register as content page (relevant for
4408: text interface only)
4409:
4410: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
4411: navigational links
4412:
4413: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
4414:
4415: =item * $no_inline_link, if true and in remote mode, don't show the
4416: 'Switch To Inline Menu' link
4417:
4418: =item * $args, optional argument valid values are
4419: no_auto_mt_title -> prevents &mt()ing the title arg
4420: inherit_jsmath -> when creating popup window in a page,
4421: should it have jsmath forced on by the
4422: current page
4423:
4424: =back
4425:
4426: Returns: A uniform header for LON-CAPA web pages.
4427: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
4428: If $bodyonly is undef or zero, an html string containing a <body> tag and
4429: other decorations will be returned.
4430:
4431: =cut
4432:
4433: sub bodytag {
4434: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
4435: $no_nav_bar,$bgcolor,$no_inline_link,$args)=@_;
4436:
4437: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
4438:
4439: $function = &get_users_function() if (!$function);
4440: my $img = &designparm($function.'.img',$domain);
4441: my $font = &designparm($function.'.font',$domain);
4442: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
4443:
4444: my %design = ( 'style' => 'margin-top: 0',
4445: 'bgcolor' => $pgbg,
4446: 'text' => $font,
4447: 'alink' => &designparm($function.'.alink',$domain),
4448: 'vlink' => &designparm($function.'.vlink',$domain),
4449: 'link' => &designparm($function.'.link',$domain),);
4450: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
4451:
4452: # role and realm
4453: my ($role,$realm) = split(/\./,$env{'request.role'},2);
4454: if ($role eq 'ca') {
4455: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
4456: $realm = &plainname($rname,$rdom);
4457: }
4458: # realm
4459: if ($env{'request.course.id'}) {
4460: if ($env{'request.role'} !~ /^cr/) {
4461: $role = &Apache::lonnet::plaintext($role,&course_type());
4462: }
4463: if ($env{'request.course.sec'}) {
4464: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
4465: }
4466: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
4467: } else {
4468: $role = &Apache::lonnet::plaintext($role);
4469: }
4470:
4471: if (!$realm) { $realm=' '; }
4472: # Set messages
4473: my $messages=&domainlogo($domain);
4474:
4475: my $extra_body_attr = &make_attr_string($forcereg,\%design);
4476:
4477: # construct main body tag
4478: my $bodytag = "<body $extra_body_attr>".
4479: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
4480:
4481: if ($bodyonly) {
4482: return $bodytag;
4483: }
4484:
4485: my $name = &plainname($env{'user.name'},$env{'user.domain'});
4486: if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
4487: undef($role);
4488: } else {
4489: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
4490: }
4491:
4492: my $titleinfo = '<h1>'.$title.'</h1>';
4493: #
4494: # Extra info if you are the DC
4495: my $dc_info = '';
4496: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
4497: $env{'course.'.$env{'request.course.id'}.
4498: '.domain'}.'/'})) {
4499: my $cid = $env{'request.course.id'};
4500: $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
4501: $dc_info =~ s/\s+$//;
4502: $dc_info = '('.$dc_info.')';
4503: }
4504:
4505: $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
4506: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
4507:
4508: if ($env{'environment.remote'} eq 'off') {
4509: # No Remote
4510: if ($no_nav_bar) { return $bodytag; }
4511:
4512: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
4513:
4514: # if ($env{'request.state'} eq 'construct') {
4515: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
4516: # }
4517:
4518: $bodytag .= qq|<div id="LC_nav_bar">$name $role<br />
4519: <em>$realm</em> $dc_info</div>| unless $env{'form.inhibitmenu'};
4520:
4521: if ( $env{'form.inhibitmenu'} eq 'yes'
4522: || $ENV{'REQUEST_URI'} eq '/adm/logout'
4523: || $env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
4524:
4525: return $bodytag;
4526: }
4527:
4528: $bodytag .= Apache::lonhtmlcommon::scripttag(
4529: Apache::lonmenu::utilityfunctions(), 'start');
4530:
4531: $bodytag .= Apache::lonmenu::primary_menu();
4532:
4533: #don't show menus for public users
4534: if($env{'user.name'} ne 'public' && $env{'user.domain'} ne 'public'){
4535: $bodytag .= Apache::lonmenu::secondary_menu();
4536: $bodytag .= Apache::lonmenu::serverform();
4537: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
4538: $bodytag .= Apache::lonmenu::innerregister($forcereg) if $forcereg;
4539: }else{
4540: # this is to seperate menu from content when there's no secondary
4541: # menu. Especially needed for public accessible ressources.
4542: $bodytag .= '<hr style="clear:both" />';
4543: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
4544: }
4545:
4546: #SD testing
4547: #$bodytag .= Apache::lonmenu::menubuttons($forcereg);
4548: return $bodytag;
4549: }
4550:
4551: #
4552: # Top frame rendering, Remote is up
4553: #
4554:
4555: my $imgsrc = $img;
4556: if ($img =~ /^\/adm/) {
4557: $imgsrc = &lonhttpdurl($img);
4558: }
4559: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
4560:
4561: # Explicit link to get inline menu
4562: my $menu= ($no_inline_link?''
4563: :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
4564: $bodytag .= qq|<div id="LC_nav_bar">$name $role
4565: <em>$realm</em> $dc_info </div>
4566: <ol class="LC_primary_menu LC_right">
4567: <li>$menu</li>
4568: </ol>| unless $env{'form.inhibitmenu'};
4569: #
4570: return(<<ENDBODY);
4571: $bodytag
4572: <table id="LC_title_bar" class="LC_with_remote">
4573: <tr><td>$upperleft</td>
4574: <td>$messages </td>
4575: </tr>
4576: <tr><td>$titleinfo $dc_info $menu</td>
4577: </tr>
4578: </table>
4579: ENDBODY
4580: }
4581:
4582: sub make_attr_string {
4583: my ($register,$attr_ref) = @_;
4584:
4585: if ($attr_ref && !ref($attr_ref)) {
4586: die("addentries Must be a hash ref ".
4587: join(':',caller(1))." ".
4588: join(':',caller(0))." ");
4589: }
4590:
4591: if ($register) {
4592: my ($on_load,$on_unload);
4593: foreach my $key (keys(%{$attr_ref})) {
4594: if (lc($key) eq 'onload') {
4595: $on_load.=$attr_ref->{$key}.';';
4596: delete($attr_ref->{$key});
4597:
4598: } elsif (lc($key) eq 'onunload') {
4599: $on_unload.=$attr_ref->{$key}.';';
4600: delete($attr_ref->{$key});
4601: }
4602: }
4603: $attr_ref->{'onload'} =
4604: &Apache::lonmenu::loadevents(). $on_load;
4605: $attr_ref->{'onunload'}=
4606: &Apache::lonmenu::unloadevents().$on_unload;
4607: }
4608:
4609: # Accessibility font enhance
4610: if ($env{'browser.fontenhance'} eq 'on') {
4611: my $style;
4612: foreach my $key (keys(%{$attr_ref})) {
4613: if (lc($key) eq 'style') {
4614: $style.=$attr_ref->{$key}.';';
4615: delete($attr_ref->{$key});
4616: }
4617: }
4618: $attr_ref->{'style'}=$style.'; font-size: x-large;';
4619: }
4620:
4621: my $attr_string;
4622: foreach my $attr (keys(%$attr_ref)) {
4623: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
4624: }
4625: return $attr_string;
4626: }
4627:
4628:
4629: ###############################################
4630: ###############################################
4631:
4632: =pod
4633:
4634: =item * &endbodytag()
4635:
4636: Returns a uniform footer for LON-CAPA web pages.
4637:
4638: Inputs: 1 - optional reference to an args hash
4639: If in the hash, key for noredirectlink has a value which evaluates to true,
4640: a 'Continue' link is not displayed if the page contains an
4641: internal redirect in the <head></head> section,
4642: i.e., $env{'internal.head.redirect'} exists
4643:
4644: =cut
4645:
4646: sub endbodytag {
4647: my ($args) = @_;
4648: my $endbodytag='</body>';
4649: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
4650: if ( exists( $env{'internal.head.redirect'} ) ) {
4651: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
4652: $endbodytag=
4653: "<br /><a href=\"$env{'internal.head.redirect'}\">".
4654: &mt('Continue').'</a>'.
4655: $endbodytag;
4656: }
4657: }
4658: return $endbodytag;
4659: }
4660:
4661: =pod
4662:
4663: =item * &standard_css()
4664:
4665: Returns a style sheet
4666:
4667: Inputs: (all optional)
4668: domain -> force to color decorate a page for a specific
4669: domain
4670: function -> force usage of a specific rolish color scheme
4671: bgcolor -> override the default page bgcolor
4672:
4673: =cut
4674:
4675: sub standard_css {
4676: my ($function,$domain,$bgcolor) = @_;
4677: $function = &get_users_function() if (!$function);
4678: my $img = &designparm($function.'.img', $domain);
4679: my $tabbg = &designparm($function.'.tabbg', $domain);
4680: my $font = &designparm($function.'.font', $domain);
4681: my $fontmenu = &designparm($function.'.fontmenu', $domain);
4682: #second colour for later usage
4683: my $sidebg = &designparm($function.'.sidebg',$domain);
4684: my $pgbg_or_bgcolor =
4685: $bgcolor ||
4686: &designparm($function.'.pgbg', $domain);
4687: my $pgbg = &designparm($function.'.pgbg', $domain);
4688: my $alink = &designparm($function.'.alink', $domain);
4689: my $vlink = &designparm($function.'.vlink', $domain);
4690: my $link = &designparm($function.'.link', $domain);
4691:
4692: my $loginbg = &designparm('login.sidebg',$domain);
4693: my $bgcol = &designparm('login.bgcol',$domain);
4694: my $textcol = &designparm('login.textcol',$domain);
4695:
4696: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
4697: my $mono = 'monospace';
4698: my $data_table_head = $sidebg;
4699: my $data_table_light = '#FAFAFA';
4700: my $data_table_dark = '#F0F0F0';
4701: my $data_table_darker = '#CCCCCC';
4702: my $data_table_highlight = '#FFFF00';
4703: my $mail_new = '#FFBB77';
4704: my $mail_new_hover = '#DD9955';
4705: my $mail_read = '#BBBB77';
4706: my $mail_read_hover = '#999944';
4707: my $mail_replied = '#AAAA88';
4708: my $mail_replied_hover = '#888855';
4709: my $mail_other = '#99BBBB';
4710: my $mail_other_hover = '#669999';
4711: my $table_header = '#DDDDDD';
4712: my $feedback_link_bg = '#BBBBBB';
4713: my $lg_border_color = '#C8C8C8';
4714:
4715: my $border = ($env{'browser.type'} eq 'explorer' ||
4716: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
4717: : '0 3px 0 4px';
4718:
4719:
4720: return <<END;
4721: body {
4722: font-family: $sans;
4723: line-height:130%;
4724: font-size:0.83em;
4725: color:$font;
4726: }
4727:
4728: a:link, a:visited {
4729: font-size:100%;
4730: }
4731:
4732: a:focus {
4733: color: red;
4734: background: yellow
4735: }
4736:
4737: form, .inline {
4738: display: inline;
4739: }
4740:
4741: .LC_right {
4742: text-align:right;
4743: }
4744:
4745: .LC_middle {
4746: vertical-align:middle;
4747: }
4748:
4749: /* just for tests */
4750: .LC_400Box {width:400px; }
4751: /* end */
4752:
4753: .LC_filename {
4754: font-family: $mono;
4755: white-space:pre;
4756: }
4757:
4758: .LC_fileicon {
4759: border: none;
4760: height: 1.3em;
4761: vertical-align: text-bottom;
4762: margin-right: 0.3em;
4763: text-decoration:none;
4764: }
4765:
4766: .LC_error {
4767: color: red;
4768: font-size: larger;
4769: }
4770:
4771: .LC_warning,
4772: .LC_diff_removed {
4773: color: red;
4774: }
4775:
4776: .LC_info,
4777: .LC_success,
4778: .LC_diff_added {
4779: color: green;
4780: }
4781:
4782: div.LC_confirm_box {
4783: background-color: #FAFAFA;
4784: border: 1px solid $lg_border_color;
4785: margin-right: 0;
4786: padding: 5px;
4787: }
4788:
4789: div.LC_confirm_box .LC_error img,
4790: div.LC_confirm_box .LC_success img {
4791: vertical-align: middle;
4792: }
4793:
4794: .LC_icon {
4795: border: none;
4796: vertical-align: middle;
4797: }
4798:
4799: .LC_docs_spacer {
4800: width: 25px;
4801: height: 1px;
4802: border: none;
4803: }
4804:
4805: .LC_internal_info {
4806: color: #999999;
4807: }
4808:
4809: .LC_discussion {
4810: background: $tabbg;
4811: border: 1px solid black;
4812: margin: 2px;
4813: }
4814:
4815: .LC_disc_action_links_bar {
4816: background: $tabbg;
4817: border: none;
4818: margin: 4px;
4819: }
4820:
4821: .LC_disc_action_left {
4822: text-align: left;
4823: }
4824:
4825: .LC_disc_action_right {
4826: text-align: right;
4827: }
4828:
4829: .LC_disc_new_item {
4830: background: white;
4831: border: 2px solid red;
4832: margin: 2px;
4833: }
4834:
4835: .LC_disc_old_item {
4836: background: white;
4837: border: 1px solid black;
4838: margin: 2px;
4839: }
4840:
4841: table.LC_pastsubmission {
4842: border: 1px solid black;
4843: margin: 2px;
4844: }
4845:
4846: table#LC_top_nav,
4847: table#LC_menubuttons,
4848: table#LC_nav_location {
4849: width: 100%;
4850: background: $pgbg;
4851: border: 2px;
4852: border-collapse: separate;
4853: padding: 0;
4854: }
4855:
4856: table#LC_title_bar a {
4857: color: $fontmenu;
4858: }
4859:
4860: table#LC_title_bar {
4861: clear: both;
4862: display: none;
4863: }
4864:
4865: table#LC_title_bar,
4866: table.LC_breadcrumbs,
4867: table#LC_title_bar.LC_with_remote {
4868: width: 100%;
4869: border-color: $pgbg;
4870: border-style: solid;
4871: border-width: $border;
4872: background: $pgbg;
4873: color: $fontmenu;
4874: border-collapse: collapse;
4875: padding: 0;
4876: margin: 0;
4877: }
4878:
4879: table#LC_title_bar td {
4880: background: $tabbg;
4881: }
4882:
4883: table#LC_menubuttons img{
4884: border: none;
4885: }
4886:
4887: table#LC_top_nav td {
4888: background: $tabbg;
4889: border: none;
4890: font-size: small;
4891: vertical-align:top;
4892: padding:2px 5px 2px 5px;
4893: }
4894:
4895: table#LC_top_nav td a,
4896: div#LC_top_nav a {
4897: color: $font;
4898: }
4899:
4900: table#LC_top_nav td.LC_top_nav_logo {
4901: background: $tabbg;
4902: text-align: left;
4903: white-space: nowrap;
4904: width: 31px;
4905: }
4906:
4907: table#LC_top_nav td.LC_top_nav_logo img {
4908: border: none;
4909: vertical-align: bottom;
4910: }
4911:
4912: table#LC_top_nav td.LC_top_nav_exit,
4913: table#LC_top_nav td.LC_top_nav_help {
4914: width: 2.0em;
4915: }
4916:
4917: table#LC_top_nav td.LC_top_nav_login {
4918: width: 4.0em;
4919: text-align: center;
4920: }
4921:
4922: .LC_breadcrumbs_component {
4923: float: right;
4924: margin: 0 1em;
4925: }
4926: .LC_breadcrumbs_component img {
4927: vertical-align: middle;
4928: }
4929:
4930: td.LC_table_cell_checkbox {
4931: text-align: center;
4932: }
4933:
4934: table#LC_mainmenu td.LC_mainmenu_column {
4935: vertical-align: top;
4936: }
4937:
4938: .LC_fontsize_small {
4939: font-size: 70%;
4940: }
4941:
4942: #LC_breadcrumbs {
4943: clear:both;
4944: background: $sidebg;
4945: border-bottom: 1px solid $lg_border_color;
4946: line-height: 2.5em;
4947: /* SD working here
4948: height: 2.5em;
4949: overflow: hidden; */
4950: margin: 0;
4951: padding: 0;
4952: }
4953:
4954: /* Preliminary fix to hide breadcrumbs inside remote control window */
4955: #LC_remote #LC_breadcrumbs {
4956: display:none;
4957: }
4958:
4959: #LC_head_subbox {
4960: clear:both;
4961: background: #F8F8F8; /* $sidebg; */
4962: border-bottom: 1px solid $lg_border_color;
4963: margin: 0 0 10px 0;
4964: padding: 5px;
4965: }
4966:
4967: .LC_fontsize_medium {
4968: font-size: 85%;
4969: }
4970:
4971: .LC_fontsize_large {
4972: font-size: 120%;
4973: }
4974:
4975: .LC_menubuttons_inline_text {
4976: color: $font;
4977: font-size: 90%;
4978: padding-left:3px;
4979: }
4980:
4981: .LC_menubuttons_link {
4982: text-decoration: none;
4983: }
4984:
4985: .LC_menubuttons_category {
4986: color: $font;
4987: background: $pgbg;
4988: font-size: larger;
4989: font-weight: bold;
4990: }
4991:
4992: td.LC_menubuttons_text {
4993: color: $font;
4994: }
4995:
4996: .LC_current_location {
4997: background: $tabbg;
4998: }
4999:
5000: .LC_new_mail {
5001: background: $tabbg;
5002: font-weight: bold;
5003: }
5004:
5005: table.LC_data_table,
5006: table.LC_mail_list {
5007: border: 1px solid #000000;
5008: border-collapse: separate;
5009: border-spacing: 1px;
5010: background: $pgbg;
5011: }
5012:
5013: .LC_data_table_dense {
5014: font-size: small;
5015: }
5016:
5017: table.LC_nested_outer {
5018: border: 1px solid #000000;
5019: border-collapse: collapse;
5020: border-spacing: 0;
5021: width: 100%;
5022: }
5023:
5024: table.LC_innerpickbox,
5025: table.LC_nested {
5026: border: none;
5027: border-collapse: collapse;
5028: border-spacing: 0;
5029: width: 100%;
5030: }
5031:
5032: table.LC_data_table tr th,
5033: table.LC_calendar tr th,
5034: table.LC_mail_list tr th,
5035: table.LC_prior_tries tr th,
5036: table.LC_innerpickbox tr th {
5037: font-weight: bold;
5038: background-color: $data_table_head;
5039: color:$fontmenu;
5040: font-size:90%;
5041: }
5042:
5043: table.LC_innerpickbox tr th,
5044: table.LC_innerpickbox tr td {
5045: vertical-align: top;
5046: }
5047:
5048: table.LC_data_table tr.LC_info_row > td {
5049: background-color: #CCCCCC;
5050: font-weight: bold;
5051: text-align: left;
5052: }
5053:
5054: table.LC_data_table tr.LC_odd_row > td,
5055: table.LC_pick_box tr > td.LC_odd_row {
5056: background-color: $data_table_light;
5057: padding: 2px;
5058: vertical-align: top;
5059: }
5060:
5061: table.LC_data_table tr.LC_even_row > td,
5062: table.LC_pick_box tr > td.LC_even_row {
5063: background-color: $data_table_dark;
5064: padding: 2px;
5065: vertical-align: top;
5066: }
5067:
5068: table.LC_data_table tr.LC_data_table_highlight td {
5069: background-color: $data_table_darker;
5070: }
5071:
5072: table.LC_data_table tr td.LC_leftcol_header {
5073: background-color: $data_table_head;
5074: font-weight: bold;
5075: }
5076:
5077: table.LC_data_table tr.LC_empty_row td,
5078: table.LC_nested tr.LC_empty_row td {
5079: background-color: #FFFFFF;
5080: font-weight: bold;
5081: font-style: italic;
5082: text-align: center;
5083: padding: 8px;
5084: }
5085:
5086: table.LC_caption {
5087: }
5088:
5089: table.LC_nested tr.LC_empty_row td {
5090: padding: 4ex
5091: }
5092:
5093: table.LC_nested_outer tr th {
5094: font-weight: bold;
5095: color:$fontmenu;
5096: background-color: $data_table_head;
5097: font-size: small;
5098: border-bottom: 1px solid #000000;
5099: }
5100:
5101: table.LC_nested_outer tr td.LC_subheader {
5102: background-color: $data_table_head;
5103: font-weight: bold;
5104: font-size: small;
5105: border-bottom: 1px solid #000000;
5106: text-align: right;
5107: }
5108:
5109: table.LC_nested tr.LC_info_row td {
5110: background-color: #CCCCCC;
5111: font-weight: bold;
5112: font-size: small;
5113: text-align: center;
5114: }
5115:
5116: table.LC_nested tr.LC_info_row td.LC_left_item,
5117: table.LC_nested_outer tr th.LC_left_item {
5118: text-align: left;
5119: }
5120:
5121: table.LC_nested td {
5122: background-color: #FFFFFF;
5123: font-size: small;
5124: }
5125:
5126: table.LC_nested_outer tr th.LC_right_item,
5127: table.LC_nested tr.LC_info_row td.LC_right_item,
5128: table.LC_nested tr.LC_odd_row td.LC_right_item,
5129: table.LC_nested tr td.LC_right_item {
5130: text-align: right;
5131: }
5132:
5133: table.LC_nested tr.LC_odd_row td {
5134: background-color: #EEEEEE;
5135: }
5136:
5137: table.LC_createuser {
5138: }
5139:
5140: table.LC_createuser tr.LC_section_row td {
5141: font-size: small;
5142: }
5143:
5144: table.LC_createuser tr.LC_info_row td {
5145: background-color: #CCCCCC;
5146: font-weight: bold;
5147: text-align: center;
5148: }
5149:
5150: table.LC_calendar {
5151: border: 1px solid #000000;
5152: border-collapse: collapse;
5153: }
5154:
5155: table.LC_calendar_pickdate {
5156: font-size: xx-small;
5157: }
5158:
5159: table.LC_calendar tr td {
5160: border: 1px solid #000000;
5161: vertical-align: top;
5162: }
5163:
5164: table.LC_calendar tr td.LC_calendar_day_empty {
5165: background-color: $data_table_dark;
5166: }
5167:
5168: table.LC_calendar tr td.LC_calendar_day_current {
5169: background-color: $data_table_highlight;
5170: }
5171:
5172: table.LC_mail_list tr.LC_mail_new {
5173: background-color: $mail_new;
5174: }
5175:
5176: table.LC_mail_list tr.LC_mail_new:hover {
5177: background-color: $mail_new_hover;
5178: }
5179:
5180: table.LC_mail_list tr.LC_mail_even {
5181: }
5182:
5183: table.LC_mail_list tr.LC_mail_odd {
5184: }
5185:
5186: table.LC_mail_list tr.LC_mail_read {
5187: background-color: $mail_read;
5188: }
5189:
5190: table.LC_mail_list tr.LC_mail_read:hover {
5191: background-color: $mail_read_hover;
5192: }
5193:
5194: table.LC_mail_list tr.LC_mail_replied {
5195: background-color: $mail_replied;
5196: }
5197:
5198: table.LC_mail_list tr.LC_mail_replied:hover {
5199: background-color: $mail_replied_hover;
5200: }
5201:
5202: table.LC_mail_list tr.LC_mail_other {
5203: background-color: $mail_other;
5204: }
5205:
5206: table.LC_mail_list tr.LC_mail_other:hover {
5207: background-color: $mail_other_hover;
5208: }
5209:
5210: table.LC_data_table tr > td.LC_browser_file,
5211: table.LC_data_table tr > td.LC_browser_file_published {
5212: background: #AAEE77;
5213: }
5214:
5215: table.LC_data_table tr > td.LC_browser_file_locked,
5216: table.LC_data_table tr > td.LC_browser_file_unpublished {
5217: background: #FFAA99;
5218: }
5219:
5220: table.LC_data_table tr > td.LC_browser_file_obsolete {
5221: background: #888888;
5222: }
5223:
5224: table.LC_data_table tr > td.LC_browser_file_modified,
5225: table.LC_data_table tr > td.LC_browser_file_metamodified {
5226: background: #F8F866;
5227: }
5228:
5229: table.LC_data_table tr.LC_browser_folder > td {
5230: background: #E0E8FF;
5231: }
5232:
5233: table.LC_data_table tr > td.LC_roles_is {
5234: /* background: #77FF77; */
5235: }
5236:
5237: table.LC_data_table tr > td.LC_roles_future {
5238: background: #FFFF77;
5239: }
5240:
5241: table.LC_data_table tr > td.LC_roles_will {
5242: background: #FFAA77;
5243: }
5244:
5245: table.LC_data_table tr > td.LC_roles_expired {
5246: background: #FF7777;
5247: }
5248:
5249: table.LC_data_table tr > td.LC_roles_will_not {
5250: background: #AAFF77;
5251: }
5252:
5253: table.LC_data_table tr > td.LC_roles_selected {
5254: background: #11CC55;
5255: }
5256:
5257: span.LC_current_location {
5258: font-size:larger;
5259: background: $pgbg;
5260: }
5261:
5262: span.LC_parm_menu_item {
5263: font-size: larger;
5264: }
5265:
5266: span.LC_parm_scope_all {
5267: color: red;
5268: }
5269:
5270: span.LC_parm_scope_folder {
5271: color: green;
5272: }
5273:
5274: span.LC_parm_scope_resource {
5275: color: orange;
5276: }
5277:
5278: span.LC_parm_part {
5279: color: blue;
5280: }
5281:
5282: span.LC_parm_folder, span.LC_parm_symb {
5283: font-size: x-small;
5284: font-family: $mono;
5285: color: #AAAAAA;
5286: }
5287:
5288: td.LC_parm_overview_level_menu,
5289: td.LC_parm_overview_map_menu,
5290: td.LC_parm_overview_parm_selectors,
5291: td.LC_parm_overview_restrictions {
5292: border: 1px solid black;
5293: border-collapse: collapse;
5294: }
5295:
5296: table.LC_parm_overview_restrictions td {
5297: border-width: 1px 4px 1px 4px;
5298: border-style: solid;
5299: border-color: $pgbg;
5300: text-align: center;
5301: }
5302:
5303: table.LC_parm_overview_restrictions th {
5304: background: $tabbg;
5305: border-width: 1px 4px 1px 4px;
5306: border-style: solid;
5307: border-color: $pgbg;
5308: }
5309:
5310: table#LC_helpmenu {
5311: border: none;
5312: height: 55px;
5313: border-spacing: 0;
5314: }
5315:
5316: table#LC_helpmenu fieldset legend {
5317: font-size: larger;
5318: }
5319:
5320: table#LC_helpmenu_links {
5321: width: 100%;
5322: border: 1px solid black;
5323: background: $pgbg;
5324: padding: 0;
5325: border-spacing: 1px;
5326: }
5327:
5328: table#LC_helpmenu_links tr td {
5329: padding: 1px;
5330: background: $tabbg;
5331: text-align: center;
5332: font-weight: bold;
5333: }
5334:
5335: table#LC_helpmenu_links a:link,
5336: table#LC_helpmenu_links a:visited,
5337: table#LC_helpmenu_links a:active {
5338: text-decoration: none;
5339: color: $font;
5340: }
5341:
5342: table#LC_helpmenu_links a:hover {
5343: text-decoration: underline;
5344: color: $vlink;
5345: }
5346:
5347: .LC_chrt_popup_exists {
5348: border: 1px solid #339933;
5349: margin: -1px;
5350: }
5351:
5352: .LC_chrt_popup_up {
5353: border: 1px solid yellow;
5354: margin: -1px;
5355: }
5356:
5357: .LC_chrt_popup {
5358: border: 1px solid #8888FF;
5359: background: #CCCCFF;
5360: }
5361:
5362: table.LC_pick_box {
5363: border-collapse: separate;
5364: background: white;
5365: border: 1px solid black;
5366: border-spacing: 1px;
5367: }
5368:
5369: table.LC_pick_box td.LC_pick_box_title {
5370: background: $sidebg;
5371: font-weight: bold;
5372: text-align: left;
5373: vertical-align: top;
5374: width: 184px;
5375: padding: 8px;
5376: }
5377:
5378: table.LC_pick_box td.LC_pick_box_value {
5379: text-align: left;
5380: padding: 8px;
5381: }
5382:
5383: table.LC_pick_box td.LC_pick_box_select {
5384: text-align: left;
5385: padding: 8px;
5386: }
5387:
5388: table.LC_pick_box td.LC_pick_box_separator {
5389: padding: 0;
5390: height: 1px;
5391: background: black;
5392: }
5393:
5394: table.LC_pick_box td.LC_pick_box_submit {
5395: text-align: right;
5396: }
5397:
5398: table.LC_pick_box td.LC_evenrow_value {
5399: text-align: left;
5400: padding: 8px;
5401: background-color: $data_table_light;
5402: }
5403:
5404: table.LC_pick_box td.LC_oddrow_value {
5405: text-align: left;
5406: padding: 8px;
5407: background-color: $data_table_light;
5408: }
5409:
5410: span.LC_helpform_receipt_cat {
5411: font-weight: bold;
5412: }
5413:
5414: table.LC_group_priv_box {
5415: background: white;
5416: border: 1px solid black;
5417: border-spacing: 1px;
5418: }
5419:
5420: table.LC_group_priv_box td.LC_pick_box_title {
5421: background: $tabbg;
5422: font-weight: bold;
5423: text-align: right;
5424: width: 184px;
5425: }
5426:
5427: table.LC_group_priv_box td.LC_groups_fixed {
5428: background: $data_table_light;
5429: text-align: center;
5430: }
5431:
5432: table.LC_group_priv_box td.LC_groups_optional {
5433: background: $data_table_dark;
5434: text-align: center;
5435: }
5436:
5437: table.LC_group_priv_box td.LC_groups_functionality {
5438: background: $data_table_darker;
5439: text-align: center;
5440: font-weight: bold;
5441: }
5442:
5443: table.LC_group_priv td {
5444: text-align: left;
5445: padding: 0;
5446: }
5447:
5448: table.LC_notify_front_page {
5449: background: white;
5450: border: 1px solid black;
5451: padding: 8px;
5452: }
5453:
5454: table.LC_notify_front_page td {
5455: padding: 8px;
5456: }
5457:
5458: .LC_navbuttons {
5459: margin: 2ex 0ex 2ex 0ex;
5460: }
5461:
5462: .LC_topic_bar {
5463: font-weight: bold;
5464: width: 100%;
5465: background: $tabbg;
5466: vertical-align: middle;
5467: margin: 2ex 0ex 2ex 0ex;
5468: padding: 3px;
5469: }
5470:
5471: .LC_topic_bar span {
5472: vertical-align: middle;
5473: }
5474:
5475: .LC_topic_bar img {
5476: vertical-align: bottom;
5477: }
5478:
5479: table.LC_course_group_status {
5480: margin: 20px;
5481: }
5482:
5483: table.LC_status_selector td {
5484: vertical-align: top;
5485: text-align: center;
5486: padding: 4px;
5487: }
5488:
5489: div.LC_feedback_link {
5490: clear: both;
5491: background: $sidebg;
5492: width: 100%;
5493: padding-bottom: 10px;
5494: border: 1px $tabbg solid;
5495: height: 22px;
5496: line-height: 22px;
5497: padding-top: 5px;
5498: }
5499:
5500: div.LC_feedback_link img {
5501: height: 22px;
5502: vertical-align:middle;
5503: }
5504:
5505: div.LC_feedback_link a{
5506: text-decoration: none;
5507: }
5508:
5509: div.LC_comblock {
5510: display:inline;
5511: color:$font;
5512: font-size:90%;
5513: }
5514:
5515: div.LC_feedback_link div.LC_comblock {
5516: padding-left:5px;
5517: }
5518:
5519: div.LC_feedback_link div.LC_comblock a {
5520: color:$font;
5521: }
5522:
5523: span.LC_feedback_link {
5524: /* background: $feedback_link_bg; */
5525: font-size: larger;
5526: }
5527:
5528: span.LC_message_link {
5529: /* background: $feedback_link_bg; */
5530: font-size: larger;
5531: position: absolute;
5532: right: 1em;
5533: }
5534:
5535: table.LC_prior_tries {
5536: border: 1px solid #000000;
5537: border-collapse: separate;
5538: border-spacing: 1px;
5539: }
5540:
5541: table.LC_prior_tries td {
5542: padding: 2px;
5543: }
5544:
5545: .LC_answer_correct {
5546: background: lightgreen;
5547: color: darkgreen;
5548: padding: 6px;
5549: }
5550:
5551: .LC_answer_charged_try {
5552: background: #FFAAAA;
5553: color: darkred;
5554: padding: 6px;
5555: }
5556:
5557: .LC_answer_not_charged_try,
5558: .LC_answer_no_grade,
5559: .LC_answer_late {
5560: background: lightyellow;
5561: color: black;
5562: padding: 6px;
5563: }
5564:
5565: .LC_answer_previous {
5566: background: lightblue;
5567: color: darkblue;
5568: padding: 6px;
5569: }
5570:
5571: .LC_answer_no_message {
5572: background: #FFFFFF;
5573: color: black;
5574: padding: 6px;
5575: }
5576:
5577: .LC_answer_unknown {
5578: background: orange;
5579: color: black;
5580: padding: 6px;
5581: }
5582:
5583: span.LC_prior_numerical,
5584: span.LC_prior_string,
5585: span.LC_prior_custom,
5586: span.LC_prior_reaction,
5587: span.LC_prior_math {
5588: font-family: monospace;
5589: white-space: pre;
5590: }
5591:
5592: span.LC_prior_string {
5593: font-family: monospace;
5594: white-space: pre;
5595: }
5596:
5597: table.LC_prior_option {
5598: width: 100%;
5599: border-collapse: collapse;
5600: }
5601:
5602: table.LC_prior_rank,
5603: table.LC_prior_match {
5604: border-collapse: collapse;
5605: }
5606:
5607: table.LC_prior_option tr td,
5608: table.LC_prior_rank tr td,
5609: table.LC_prior_match tr td {
5610: border: 1px solid #000000;
5611: }
5612:
5613: .LC_nobreak {
5614: white-space: nowrap;
5615: }
5616:
5617: span.LC_cusr_emph {
5618: font-style: italic;
5619: }
5620:
5621: span.LC_cusr_subheading {
5622: font-weight: normal;
5623: font-size: 85%;
5624: }
5625:
5626: table.LC_docs_documents {
5627: background: #BBBBBB;
5628: border-width: 0;
5629: border-collapse: collapse;
5630: }
5631:
5632: table.LC_docs_documents td.LC_docs_document {
5633: border: 2px solid black;
5634: padding: 4px;
5635: }
5636:
5637: div.LC_docs_entry_move {
5638: border: 1px solid #BBBBBB;
5639: background: #DDDDDD;
5640: width: 22px;
5641: padding: 1px;
5642: margin: 0;
5643: }
5644:
5645: table.LC_data_table tr > td.LC_docs_entry_commands,
5646: table.LC_data_table tr > td.LC_docs_entry_parameter {
5647: background: #DDDDDD;
5648: font-size: x-small;
5649: }
5650:
5651: .LC_docs_entry_parameter {
5652: white-space: nowrap;
5653: }
5654:
5655: .LC_docs_copy {
5656: color: #000099;
5657: }
5658:
5659: .LC_docs_cut {
5660: color: #550044;
5661: }
5662:
5663: .LC_docs_rename {
5664: color: #009900;
5665: }
5666:
5667: .LC_docs_remove {
5668: color: #990000;
5669: }
5670:
5671: .LC_docs_reinit_warn,
5672: .LC_docs_ext_edit {
5673: font-size: x-small;
5674: }
5675:
5676: table.LC_docs_adddocs td,
5677: table.LC_docs_adddocs th {
5678: border: 1px solid #BBBBBB;
5679: padding: 4px;
5680: background: #DDDDDD;
5681: }
5682:
5683: table.LC_sty_begin {
5684: background: #BBFFBB;
5685: }
5686:
5687: table.LC_sty_end {
5688: background: #FFBBBB;
5689: }
5690:
5691: table.LC_double_column {
5692: border-width: 0;
5693: border-collapse: collapse;
5694: width: 100%;
5695: padding: 2px;
5696: }
5697:
5698: table.LC_double_column tr td.LC_left_col {
5699: top: 2px;
5700: left: 2px;
5701: width: 47%;
5702: vertical-align: top;
5703: }
5704:
5705: table.LC_double_column tr td.LC_right_col {
5706: top: 2px;
5707: right: 2px;
5708: width: 47%;
5709: vertical-align: top;
5710: }
5711:
5712: div.LC_left_float {
5713: float: left;
5714: padding-right: 5%;
5715: padding-bottom: 4px;
5716: }
5717:
5718: div.LC_clear_float_header {
5719: padding-bottom: 2px;
5720: }
5721:
5722: div.LC_clear_float_footer {
5723: padding-top: 10px;
5724: clear: both;
5725: }
5726:
5727: div.LC_grade_show_user {
5728: margin-top: 20px;
5729: border: 1px solid black;
5730: }
5731:
5732: div.LC_grade_user_name {
5733: background: #DDDDEE;
5734: border-bottom: 1px solid black;
5735: font-weight: bold;
5736: font-size: large;
5737: }
5738:
5739: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
5740: background: #DDEEDD;
5741: }
5742:
5743: div.LC_grade_show_problem,
5744: div.LC_grade_submissions,
5745: div.LC_grade_message_center,
5746: div.LC_grade_info_links,
5747: div.LC_grade_assign {
5748: margin: 5px;
5749: width: 99%;
5750: background: #FFFFFF;
5751: }
5752:
5753: div.LC_grade_show_problem_header,
5754: div.LC_grade_submissions_header,
5755: div.LC_grade_message_center_header,
5756: div.LC_grade_assign_header {
5757: font-weight: bold;
5758: font-size: large;
5759: }
5760:
5761: div.LC_grade_show_problem_problem,
5762: div.LC_grade_submissions_body,
5763: div.LC_grade_message_center_body,
5764: div.LC_grade_assign_body {
5765: border: 1px solid black;
5766: width: 99%;
5767: background: #FFFFFF;
5768: }
5769:
5770: span.LC_grade_check_note {
5771: font-weight: normal;
5772: font-size: medium;
5773: display: inline;
5774: position: absolute;
5775: right: 1em;
5776: }
5777:
5778: table.LC_scantron_action {
5779: width: 100%;
5780: }
5781:
5782: table.LC_scantron_action tr th {
5783: font-weight:bold;
5784: font-style:normal;
5785: }
5786:
5787: .LC_edit_problem_header,
5788: div.LC_edit_problem_footer {
5789: font-weight: normal;
5790: font-size: medium;
5791: margin: 2px;
5792: }
5793:
5794: div.LC_edit_problem_header,
5795: div.LC_edit_problem_header div,
5796: div.LC_edit_problem_footer,
5797: div.LC_edit_problem_footer div,
5798: div.LC_edit_problem_editxml_header,
5799: div.LC_edit_problem_editxml_header div {
5800: margin-top: 5px;
5801: }
5802:
5803: div.LC_edit_problem_header_title {
5804: font-weight: bold;
5805: font-size: larger;
5806: background: $tabbg;
5807: padding: 3px;
5808: }
5809:
5810: table.LC_edit_problem_header_title {
5811: font-size: larger;
5812: font-weight: bold;
5813: width: 100%;
5814: border-color: $pgbg;
5815: border-style: solid;
5816: border-width: $border;
5817: background: $tabbg;
5818: border-collapse: collapse;
5819: padding: 0;
5820: }
5821:
5822: div.LC_edit_problem_discards {
5823: float: left;
5824: padding-bottom: 5px;
5825: }
5826:
5827: div.LC_edit_problem_saves {
5828: float: right;
5829: padding-bottom: 5px;
5830: }
5831:
5832: img.stift{
5833: border-width: 0;
5834: vertical-align: middle;
5835: }
5836:
5837: table#LC_mainmenu{
5838: margin-top:10px;
5839: width:80%;
5840: }
5841:
5842: table#LC_mainmenu td.LC_mainmenu_col_fieldset{
5843: vertical-align: top;
5844: width: 45%;
5845: }
5846:
5847: .LC_mainmenu_fieldset_category {
5848: color: $font;
5849: background: $pgbg;
5850: font-size: small;
5851: font-weight: bold;
5852: }
5853:
5854: div.LC_createcourse {
5855: margin: 10px 10px 10px 10px;
5856: }
5857:
5858: /* ---- Remove when done ----
5859: # The following styles is part of the redesign of LON-CAPA and are
5860: # subject to change during this project.
5861: # Don't rely on their current functionality as they might be
5862: # changed or removed.
5863: # --------------------------*/
5864:
5865: a:hover,
5866: ol.LC_primary_menu a:hover,
5867: ol#LC_MenuBreadcrumbs a:hover,
5868: ol#LC_PathBreadcrumbs a:hover,
5869: ul#LC_secondary_menu a:hover,
5870: .LC_FormSectionClearButton input:hover
5871: ul.LC_TabContent li:hover a {
5872: color:#BF2317;
5873: text-decoration:none;
5874: }
5875:
5876: h1 {
5877: padding: 0;
5878: line-height:130%;
5879: }
5880:
5881: h2,h3,h4,h5,h6 {
5882: margin: 5px 0 5px 0;
5883: padding: 0;
5884: line-height:130%;
5885: }
5886:
5887: .LC_hcell {
5888: padding:3px 15px 3px 15px;
5889: margin: 0;
5890: background-color:$tabbg;
5891: color:$fontmenu;
5892: border-bottom:solid 1px $lg_border_color;
5893: }
5894:
5895: .LC_Box > .LC_hcell {
5896: margin: 0 -10px 10px -10px;
5897: }
5898:
5899: .LC_noBorder {
5900: border: 0;
5901: }
5902:
5903: .LC_Right {
5904: float: right;
5905: margin: 0;
5906: padding: 0;
5907: }
5908:
5909: .LC_FormSectionClearButton input {
5910: background-color:transparent;
5911: border: none;
5912: cursor:pointer;
5913: text-decoration:underline;
5914: }
5915:
5916: .LC_help_open_topic {
5917: color: #FFFFFF;
5918: background-color: #EEEEFF;
5919: margin: 1px;
5920: padding: 4px;
5921: border: 1px solid #000033;
5922: white-space: nowrap;
5923: /* vertical-align: middle; */
5924: }
5925:
5926: dl,ul,div,fieldset {
5927: margin: 10px 10px 10px 0;
5928: /* overflow: hidden; */
5929: }
5930:
5931: fieldset > legend {
5932: font-weight: bold;
5933: padding: 0 5px 0 5px;
5934: }
5935:
5936: #LC_nav_bar {
5937: float: left;
5938: margin: 0.2em 0 0 0;
5939: }
5940:
5941: #LC_nav_bar em{
5942: font-weight: bold;
5943: font-style: normal;
5944: }
5945:
5946: ol.LC_primary_menu {
5947: float: right;
5948: margin: 0.2em 0 0 0;
5949: }
5950:
5951: ol#LC_PathBreadcrumbs {
5952: margin: 0;
5953: }
5954:
5955: ol.LC_primary_menu li {
5956: display: inline;
5957: padding: 5px 5px 0 10px;
5958: vertical-align: top;
5959: }
5960:
5961: ol.LC_primary_menu li img {
5962: vertical-align: bottom;
5963: }
5964:
5965: ol.LC_primary_menu a {
5966: font-size: 90%;
5967: color: RGB(80, 80, 80);
5968: text-decoration: none;
5969: }
5970:
5971: ul#LC_secondary_menu {
5972: clear: both;
5973: color: $fontmenu;
5974: background: $tabbg;
5975: list-style: none;
5976: padding: 0;
5977: margin: 0;
5978: width: 100%;
5979: }
5980:
5981: ul#LC_secondary_menu li {
5982: font-weight: bold;
5983: line-height: 1.8em;
5984: padding: 0 0.8em;
5985: border-right: 1px solid black;
5986: display: inline;
5987: vertical-align: middle;
5988: }
5989:
5990: ul.LC_TabContent {
5991: display:block;
5992: background: $sidebg;
5993: border-bottom: solid 1px $lg_border_color;
5994: list-style:none;
5995: margin: 0 -10px;
5996: padding: 0;
5997: }
5998:
5999: ul.LC_TabContent li,
6000: ul.LC_TabContentBigger li {
6001: float:left;
6002: }
6003:
6004: ul#LC_secondary_menu li a {
6005: color: $fontmenu;
6006: text-decoration: none;
6007: }
6008:
6009: ul.LC_TabContent {
6010: min-height:1.5em;
6011: }
6012:
6013: ul.LC_TabContent li {
6014: vertical-align:middle;
6015: padding: 0 10px 0 10px;
6016: background-color:$tabbg;
6017: border-bottom:solid 1px $lg_border_color;
6018: }
6019:
6020: ul.LC_TabContent .right {
6021: float:right;
6022: }
6023:
6024: ul.LC_TabContent li a, ul.LC_TabContent li {
6025: color:rgb(47,47,47);
6026: text-decoration:none;
6027: font-size:95%;
6028: font-weight:bold;
6029: padding-right: 16px;
6030: }
6031:
6032: ul.LC_TabContent li:hover, ul.LC_TabContent li.active {
6033: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
6034: border-bottom:solid 2px #FFFFFF;
6035: padding-right: 16px;
6036: }
6037:
6038: #maincoursedoc {
6039: clear:both;
6040: }
6041:
6042: ul.LC_TabContentBigger {
6043: display:block;
6044: list-style:none;
6045: padding: 0;
6046: }
6047:
6048: ul.LC_TabContentBigger li {
6049: vertical-align:bottom;
6050: height: 30px;
6051: font-size:110%;
6052: font-weight:bold;
6053: color: #737373;
6054: }
6055:
6056:
6057: ul.LC_TabContentBigger li a {
6058: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
6059: height: 30px;
6060: line-height: 30px;
6061: text-align: center;
6062: display: block;
6063: text-decoration: none;
6064: }
6065:
6066: ul.LC_TabContentBigger li:hover a,
6067: ul.LC_TabContentBigger li.active a {
6068: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
6069: color:$font;
6070: text-decoration: underline;
6071: }
6072:
6073:
6074: ul.LC_TabContentBigger li b {
6075: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
6076: display: block;
6077: float: left;
6078: padding: 0 30px;
6079: }
6080:
6081: ul.LC_TabContentBigger li:hover b,
6082: ul.LC_TabContentBigger li.active b {
6083: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
6084: color:$font;
6085: border-bottom: 1px solid #FFFFFF;
6086: }
6087:
6088:
6089: ul.LC_CourseBreadcrumbs {
6090: background: $sidebg;
6091: line-height: 32px;
6092: padding-left: 10px;
6093: margin: 0 0 10px 0;
6094: list-style-position: inside;
6095:
6096: }
6097:
6098: ol#LC_MenuBreadcrumbs,
6099: ol#LC_PathBreadcrumbs {
6100: padding-left: 10px;
6101: margin: 0;
6102: list-style-position: inside;
6103: /* SD working here
6104: white-space: nowrap; */
6105: }
6106:
6107: ol#LC_MenuBreadcrumbs li,
6108: ol#LC_PathBreadcrumbs li,
6109: ul.LC_CourseBreadcrumbs li {
6110: display: inline;
6111: white-space: nowrap;
6112: /* SD working here
6113: white-space: normal; */
6114: }
6115:
6116: ol#LC_MenuBreadcrumbs li a,
6117: ul.LC_CourseBreadcrumbs li a {
6118: text-decoration: none;
6119: font-size:90%;
6120: }
6121:
6122: ol#LC_PathBreadcrumbs li a {
6123: text-decoration:none;
6124: font-size:100%;
6125: font-weight:bold;
6126: }
6127:
6128: .LC_Box {
6129: border: solid 1px $lg_border_color;
6130: padding: 0 10px 10px 10px;
6131: }
6132:
6133: .LC_AboutMe_Image {
6134: float:left;
6135: margin-right:10px;
6136: }
6137:
6138: .LC_Clear_AboutMe_Image {
6139: clear:left;
6140: }
6141:
6142: dl.LC_ListStyleClean dt {
6143: padding-right: 5px;
6144: display: table-header-group;
6145: }
6146:
6147: dl.LC_ListStyleClean dd {
6148: display: table-row;
6149: }
6150:
6151: .LC_ListStyleClean,
6152: .LC_ListStyleSimple,
6153: .LC_ListStyleNormal,
6154: .LC_ListStyle_Border,
6155: .LC_ListStyleSpecial {
6156: /*display:block; */
6157: list-style-position: inside;
6158: list-style-type: none;
6159: overflow: hidden;
6160: padding: 0;
6161: }
6162:
6163: .LC_ListStyleSimple li,
6164: .LC_ListStyleSimple dd,
6165: .LC_ListStyleNormal li,
6166: .LC_ListStyleNormal dd,
6167: .LC_ListStyleSpecial li,
6168: .LC_ListStyleSpecial dd {
6169: margin: 0;
6170: padding: 5px 5px 5px 10px;
6171: clear: both;
6172: }
6173:
6174: .LC_ListStyleClean li,
6175: .LC_ListStyleClean dd {
6176: padding-top: 0;
6177: padding-bottom: 0;
6178: }
6179:
6180: .LC_ListStyleSimple dd,
6181: .LC_ListStyleSimple li {
6182: border-bottom: solid 1px $lg_border_color;
6183: }
6184:
6185: .LC_ListStyleSpecial li,
6186: .LC_ListStyleSpecial dd {
6187: list-style-type: none;
6188: background-color: RGB(220, 220, 220);
6189: margin-bottom: 4px;
6190: }
6191:
6192: table.LC_SimpleTable {
6193: margin:5px;
6194: border:solid 1px $lg_border_color;
6195: }
6196:
6197: table.LC_SimpleTable tr {
6198: padding: 0;
6199: border:solid 1px $lg_border_color;
6200: }
6201:
6202: table.LC_SimpleTable thead {
6203: background:rgb(220,220,220);
6204: }
6205:
6206: div.LC_columnSection {
6207: display: block;
6208: clear: both;
6209: overflow: hidden;
6210: margin: 0;
6211: }
6212:
6213: div.LC_columnSection>* {
6214: float: left;
6215: margin: 10px 20px 10px 0;
6216: overflow:hidden;
6217: }
6218:
6219: .LC_loginpage_container {
6220: text-align:left;
6221: margin : 0 auto;
6222: width:90%;
6223: padding: 10px;
6224: height: auto;
6225: background-color:#FFFFFF;
6226: border:1px solid #CCCCCC;
6227: }
6228:
6229:
6230: .LC_loginpage_loginContainer {
6231: float:left;
6232: width: 182px;
6233: padding: 2px;
6234: border:1px solid #CCCCCC;
6235: background-color:$loginbg;
6236: }
6237:
6238: .LC_loginpage_loginContainer h2 {
6239: margin-top: 0;
6240: display:block;
6241: background:$bgcol;
6242: color:$textcol;
6243: padding-left:5px;
6244: }
6245:
6246: .LC_loginpage_loginInfo {
6247: float:left;
6248: width:182px;
6249: border:1px solid #CCCCCC;
6250: padding:2px;
6251: }
6252:
6253: .LC_loginpage_space {
6254: clear: both;
6255: margin-bottom: 20px;
6256: border-bottom: 1px solid #CCCCCC;
6257: }
6258:
6259: .LC_loginpage_floatLeft {
6260: float: left;
6261: width: 200px;
6262: margin: 0;
6263: }
6264:
6265: table em {
6266: font-weight: bold;
6267: font-style: normal;
6268: }
6269:
6270: table.LC_tableBrowseRes,
6271: table.LC_tableOfContent {
6272: border:none;
6273: border-spacing: 1px;
6274: padding: 3px;
6275: background-color: #FFFFFF;
6276: font-size: 90%;
6277: }
6278:
6279: table.LC_tableOfContent{
6280: border-collapse: collapse;
6281: }
6282:
6283: table.LC_tableBrowseRes a,
6284: table.LC_tableOfContent a {
6285: background-color: transparent;
6286: text-decoration: none;
6287: }
6288:
6289: table.LC_tableBrowseRes tr.LC_trOdd,
6290: table.LC_tableOfContent tr.LC_trOdd{
6291: background-color: #EEEEEE;
6292: }
6293:
6294: table.LC_tableOfContent img {
6295: border: none;
6296: height: 1.3em;
6297: vertical-align: text-bottom;
6298: margin-right: 0.3em;
6299: }
6300:
6301: a#LC_content_toolbar_firsthomework {
6302: background-image:url(/res/adm/pages/open-first-problem.gif);
6303: }
6304:
6305: a#LC_content_toolbar_launchnav {
6306: background-image:url(/res/adm/pages/start-navigation.gif);
6307: }
6308:
6309: a#LC_content_toolbar_closenav {
6310: background-image:url(/res/adm/pages/close-navigation.gif);
6311: }
6312:
6313: a#LC_content_toolbar_everything {
6314: background-image:url(/res/adm/pages/show-all.gif);
6315: }
6316:
6317: a#LC_content_toolbar_uncompleted {
6318: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
6319: }
6320:
6321: #LC_content_toolbar_clearbubbles {
6322: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
6323: }
6324:
6325: a#LC_content_toolbar_changefolder {
6326: background : url(/res/adm/pages/close-all-folders.gif) top center ;
6327: }
6328:
6329: a#LC_content_toolbar_changefolder_toggled {
6330: background-image:url(/res/adm/pages/open-all-folders.gif);
6331: }
6332:
6333: ul#LC_toolbar li a:hover {
6334: background-position: bottom center;
6335: }
6336:
6337: ul#LC_toolbar {
6338: padding: 0;
6339: margin: 2px;
6340: list-style:none;
6341: position:relative;
6342: background-color:white;
6343: }
6344:
6345: ul#LC_toolbar li {
6346: border:1px solid white;
6347: padding: 0;
6348: margin: 0;
6349: float: left;
6350: display:inline;
6351: vertical-align:middle;
6352: }
6353:
6354:
6355: a.LC_toolbarItem {
6356: display:block;
6357: padding: 0;
6358: margin: 0;
6359: height: 32px;
6360: width: 32px;
6361: color:white;
6362: border: none;
6363: background-repeat:no-repeat;
6364: background-color:transparent;
6365: }
6366:
6367: ul.LC_funclist li {
6368: float: left;
6369: white-space: nowrap;
6370: height: 35px; /* at least as high as heighest list item */
6371: margin: 0 15px 15px 10px;
6372: }
6373:
6374:
6375: END
6376: }
6377:
6378: =pod
6379:
6380: =item * &headtag()
6381:
6382: Returns a uniform footer for LON-CAPA web pages.
6383:
6384: Inputs: $title - optional title for the head
6385: $head_extra - optional extra HTML to put inside the <head>
6386: $args - optional arguments
6387: force_register - if is true call registerurl so the remote is
6388: informed
6389: redirect -> array ref of
6390: 1- seconds before redirect occurs
6391: 2- url to redirect to
6392: 3- whether the side effect should occur
6393: (side effect of setting
6394: $env{'internal.head.redirect'} to the url
6395: redirected too)
6396: domain -> force to color decorate a page for a specific
6397: domain
6398: function -> force usage of a specific rolish color scheme
6399: bgcolor -> override the default page bgcolor
6400: no_auto_mt_title
6401: -> prevent &mt()ing the title arg
6402:
6403: =cut
6404:
6405: sub headtag {
6406: my ($title,$head_extra,$args) = @_;
6407:
6408: my $function = $args->{'function'} || &get_users_function();
6409: my $domain = $args->{'domain'} || &determinedomain();
6410: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
6411: my $url = join(':',$env{'user.name'},$env{'user.domain'},
6412: $Apache::lonnet::perlvar{'lonVersion'},
6413: #time(),
6414: $env{'environment.color.timestamp'},
6415: $function,$domain,$bgcolor);
6416:
6417: $url = '/adm/css/'.&escape($url).'.css';
6418:
6419: my $result =
6420: '<head>'.
6421: &font_settings();
6422:
6423: if (!$args->{'frameset'}) {
6424: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
6425: }
6426: if ($args->{'force_register'}) {
6427: $result .= &Apache::lonmenu::registerurl(1);
6428: }
6429: if (!$args->{'no_nav_bar'}
6430: && !$args->{'only_body'}
6431: && !$args->{'frameset'}) {
6432: $result .= &help_menu_js();
6433: }
6434:
6435: if (ref($args->{'redirect'})) {
6436: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
6437: $url = &Apache::lonenc::check_encrypt($url);
6438: if (!$inhibit_continue) {
6439: $env{'internal.head.redirect'} = $url;
6440: }
6441: $result.=<<ADDMETA
6442: <meta http-equiv="pragma" content="no-cache" />
6443: <meta http-equiv="Refresh" content="$time; url=$url" />
6444: ADDMETA
6445: }
6446: if (!defined($title)) {
6447: $title = 'The LearningOnline Network with CAPA';
6448: }
6449: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
6450: $result .= '<title> LON-CAPA '.$title.'</title>'
6451: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
6452: .$head_extra;
6453: return $result;
6454: }
6455:
6456: =pod
6457:
6458: =item * &font_settings()
6459:
6460: Returns neccessary <meta> to set the proper encoding
6461:
6462: Inputs: none
6463:
6464: =cut
6465:
6466: sub font_settings {
6467: my $headerstring='';
6468: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
6469: $headerstring.=
6470: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
6471: }
6472: return $headerstring;
6473: }
6474:
6475: =pod
6476:
6477: =item * &xml_begin()
6478:
6479: Returns the needed doctype and <html>
6480:
6481: Inputs: none
6482:
6483: =cut
6484:
6485: sub xml_begin {
6486: my $output='';
6487:
6488: if ($env{'internal.start_page'}==1) {
6489: &Apache::lonhtmlcommon::init_htmlareafields();
6490: }
6491:
6492: if ($env{'browser.mathml'}) {
6493: $output='<?xml version="1.0"?>'
6494: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
6495: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
6496:
6497: # .'<!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">] >'
6498: .'<!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">'
6499: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
6500: .'xmlns="http://www.w3.org/1999/xhtml">';
6501: } else {
6502: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
6503: .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
6504: }
6505: return $output;
6506: }
6507:
6508: =pod
6509:
6510: =item * &endheadtag()
6511:
6512: Returns a uniform </head> for LON-CAPA web pages.
6513:
6514: Inputs: none
6515:
6516: =cut
6517:
6518: sub endheadtag {
6519: return '</head>';
6520: }
6521:
6522: =pod
6523:
6524: =item * &head()
6525:
6526: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
6527:
6528: Inputs:
6529:
6530: =over 4
6531:
6532: $title - optional title for the page
6533:
6534: $head_extra - optional extra HTML to put inside the <head>
6535:
6536: =back
6537:
6538: =cut
6539:
6540: sub head {
6541: my ($title,$head_extra,$args) = @_;
6542: return &headtag($title,$head_extra,$args).&endheadtag();
6543: }
6544:
6545: =pod
6546:
6547: =item * &start_page()
6548:
6549: Returns a complete <html> .. <body> section for LON-CAPA web pages.
6550:
6551: Inputs:
6552:
6553: =over 4
6554:
6555: $title - optional title for the page
6556:
6557: $head_extra - optional extra HTML to incude inside the <head>
6558:
6559: $args - additional optional args supported are:
6560:
6561: =over 8
6562:
6563: only_body -> is true will set &bodytag() onlybodytag
6564: arg on
6565: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
6566: add_entries -> additional attributes to add to the <body>
6567: domain -> force to color decorate a page for a
6568: specific domain
6569: function -> force usage of a specific rolish color
6570: scheme
6571: redirect -> see &headtag()
6572: bgcolor -> override the default page bg color
6573: js_ready -> return a string ready for being used in
6574: a javascript writeln
6575: html_encode -> return a string ready for being used in
6576: a html attribute
6577: force_register -> if is true will turn on the &bodytag()
6578: $forcereg arg
6579: frameset -> if true will start with a <frameset>
6580: rather than <body>
6581: skip_phases -> hash ref of
6582: head -> skip the <html><head> generation
6583: body -> skip all <body> generation
6584: no_inline_link -> if true and in remote mode, don't show the
6585: 'Switch To Inline Menu' link
6586: no_auto_mt_title -> prevent &mt()ing the title arg
6587: inherit_jsmath -> when creating popup window in a page,
6588: should it have jsmath forced on by the
6589: current page
6590: bread_crumbs -> Array containing breadcrumbs
6591: bread_crumbs_components -> if exists show it as headline else show only the breadcrumbs
6592:
6593: =back
6594:
6595: =back
6596:
6597: =cut
6598:
6599: sub start_page {
6600: my ($title,$head_extra,$args) = @_;
6601: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
6602: my %head_args;
6603: foreach my $arg ('redirect','force_register','domain','function',
6604: 'bgcolor','frameset','no_nav_bar','only_body',
6605: 'no_auto_mt_title') {
6606: if (defined($args->{$arg})) {
6607: $head_args{$arg} = $args->{$arg};
6608: }
6609: }
6610:
6611: $env{'internal.start_page'}++;
6612: my $result;
6613: if (! exists($args->{'skip_phases'}{'head'}) ) {
6614: $result.=
6615: &xml_begin().
6616: &headtag($title,$head_extra,\%head_args).&endheadtag();
6617: }
6618:
6619: if (! exists($args->{'skip_phases'}{'body'}) ) {
6620: if ($args->{'frameset'}) {
6621: my $attr_string = &make_attr_string($args->{'force_register'},
6622: $args->{'add_entries'});
6623: $result .= "\n<frameset $attr_string>\n";
6624: } else {
6625: $result .=
6626: &bodytag($title,
6627: $args->{'function'}, $args->{'add_entries'},
6628: $args->{'only_body'}, $args->{'domain'},
6629: $args->{'force_register'}, $args->{'no_nav_bar'},
6630: $args->{'bgcolor'}, $args->{'no_inline_link'},
6631: $args);
6632: }
6633: }
6634:
6635: if ($args->{'js_ready'}) {
6636: $result = &js_ready($result);
6637: }
6638: if ($args->{'html_encode'}) {
6639: $result = &html_encode($result);
6640: }
6641:
6642: # Preparation for new and consistent functionlist at top of screen
6643: # if ($args->{'functionlist'}) {
6644: # $result .= &build_functionlist();
6645: #}
6646:
6647: # Don't add anything more if only_body wanted
6648: return $result if $args->{'only_body'};
6649:
6650: #Breadcrumbs
6651: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
6652: &Apache::lonhtmlcommon::clear_breadcrumbs();
6653: #if any br links exists, add them to the breadcrumbs
6654: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
6655: foreach my $crumb (@{$args->{'bread_crumbs'}}){
6656: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
6657: }
6658: }
6659:
6660: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
6661: if(exists($args->{'bread_crumbs_component'})){
6662: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
6663: }else{
6664: $result .= &Apache::lonhtmlcommon::breadcrumbs();
6665: }
6666: }
6667: return $result;
6668: }
6669:
6670:
6671: =pod
6672:
6673: =item * &head()
6674:
6675: Returns a complete </body></html> section for LON-CAPA web pages.
6676:
6677: Inputs: $args - additional optional args supported are:
6678: js_ready -> return a string ready for being used in
6679: a javascript writeln
6680: html_encode -> return a string ready for being used in
6681: a html attribute
6682: frameset -> if true will start with a <frameset>
6683: rather than <body>
6684: dicsussion -> if true will get discussion from
6685: lonxml::xmlend
6686: (you can pass the target and parser arguments
6687: through optional 'target' and 'parser' args
6688: to this routine)
6689:
6690: =cut
6691:
6692: sub end_page {
6693: my ($args) = @_;
6694: $env{'internal.end_page'}++;
6695: my $result;
6696: if ($args->{'discussion'}) {
6697: my ($target,$parser);
6698: if (ref($args->{'discussion'})) {
6699: ($target,$parser) =($args->{'discussion'}{'target'},
6700: $args->{'discussion'}{'parser'});
6701: }
6702: $result .= &Apache::lonxml::xmlend($target,$parser);
6703: }
6704:
6705: if ($args->{'frameset'}) {
6706: $result .= '</frameset>';
6707: } else {
6708: $result .= &endbodytag($args);
6709: }
6710: $result .= "\n</html>";
6711:
6712: if ($args->{'js_ready'}) {
6713: $result = &js_ready($result);
6714: }
6715:
6716: if ($args->{'html_encode'}) {
6717: $result = &html_encode($result);
6718: }
6719:
6720: return $result;
6721: }
6722:
6723: sub html_encode {
6724: my ($result) = @_;
6725:
6726: $result = &HTML::Entities::encode($result,'<>&"');
6727:
6728: return $result;
6729: }
6730: sub js_ready {
6731: my ($result) = @_;
6732:
6733: $result =~ s/[\n\r]/ /xmsg;
6734: $result =~ s/\\/\\\\/xmsg;
6735: $result =~ s/'/\\'/xmsg;
6736: $result =~ s{</}{<\\/}xmsg;
6737:
6738: return $result;
6739: }
6740:
6741: sub validate_page {
6742: if ( exists($env{'internal.start_page'})
6743: && $env{'internal.start_page'} > 1) {
6744: &Apache::lonnet::logthis('start_page called multiple times '.
6745: $env{'internal.start_page'}.' '.
6746: $ENV{'request.filename'});
6747: }
6748: if ( exists($env{'internal.end_page'})
6749: && $env{'internal.end_page'} > 1) {
6750: &Apache::lonnet::logthis('end_page called multiple times '.
6751: $env{'internal.end_page'}.' '.
6752: $env{'request.filename'});
6753: }
6754: if ( exists($env{'internal.start_page'})
6755: && ! exists($env{'internal.end_page'})) {
6756: &Apache::lonnet::logthis('start_page called without end_page '.
6757: $env{'request.filename'});
6758: }
6759: if ( ! exists($env{'internal.start_page'})
6760: && exists($env{'internal.end_page'})) {
6761: &Apache::lonnet::logthis('end_page called without start_page'.
6762: $env{'request.filename'});
6763: }
6764: }
6765:
6766: sub simple_error_page {
6767: my ($r,$title,$msg) = @_;
6768: my $page =
6769: &Apache::loncommon::start_page($title).
6770: &mt($msg).
6771: &Apache::loncommon::end_page();
6772: if (ref($r)) {
6773: $r->print($page);
6774: return;
6775: }
6776: return $page;
6777: }
6778:
6779: {
6780: my @row_count;
6781: sub start_data_table {
6782: my ($add_class) = @_;
6783: my $css_class = (join(' ','LC_data_table',$add_class));
6784: unshift(@row_count,0);
6785: return '<table class="'.$css_class.'">'."\n";
6786: }
6787:
6788: sub end_data_table {
6789: shift(@row_count);
6790: return '</table>'."\n";;
6791: }
6792:
6793: sub start_data_table_row {
6794: my ($add_class) = @_;
6795: $row_count[0]++;
6796: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
6797: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
6798: return '<tr class="'.$css_class.'">'."\n";;
6799: }
6800:
6801: sub continue_data_table_row {
6802: my ($add_class) = @_;
6803: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
6804: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');;
6805: return '<tr class="'.$css_class.'">'."\n";;
6806: }
6807:
6808: sub end_data_table_row {
6809: return '</tr>'."\n";;
6810: }
6811:
6812: sub start_data_table_empty_row {
6813: # $row_count[0]++;
6814: return '<tr class="LC_empty_row" >'."\n";;
6815: }
6816:
6817: sub end_data_table_empty_row {
6818: return '</tr>'."\n";;
6819: }
6820:
6821: sub start_data_table_header_row {
6822: return '<tr class="LC_header_row">'."\n";;
6823: }
6824:
6825: sub end_data_table_header_row {
6826: return '</tr>'."\n";;
6827: }
6828:
6829: sub data_table_caption {
6830: my $caption = shift;
6831: return "<caption class=\"LC_caption\">$caption</caption>";
6832: }
6833: }
6834:
6835: =pod
6836:
6837: =item * &inhibit_menu_check($arg)
6838:
6839: Checks for a inhibitmenu state and generates output to preserve it
6840:
6841: Inputs: $arg - can be any of
6842: - undef - in which case the return value is a string
6843: to add into arguments list of a uri
6844: - 'input' - in which case the return value is a HTML
6845: <form> <input> field of type hidden to
6846: preserve the value
6847: - a url - in which case the return value is the url with
6848: the neccesary cgi args added to preserve the
6849: inhibitmenu state
6850: - a ref to a url - no return value, but the string is
6851: updated to include the neccessary cgi
6852: args to preserve the inhibitmenu state
6853:
6854: =cut
6855:
6856: sub inhibit_menu_check {
6857: my ($arg) = @_;
6858: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6859: if ($arg eq 'input') {
6860: if ($env{'form.inhibitmenu'}) {
6861: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
6862: } else {
6863: return
6864: }
6865: }
6866: if ($env{'form.inhibitmenu'}) {
6867: if (ref($arg)) {
6868: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6869: } elsif ($arg eq '') {
6870: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
6871: } else {
6872: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6873: }
6874: }
6875: if (!ref($arg)) {
6876: return $arg;
6877: }
6878: }
6879:
6880: ###############################################
6881:
6882: =pod
6883:
6884: =back
6885:
6886: =head1 User Information Routines
6887:
6888: =over 4
6889:
6890: =item * &get_users_function()
6891:
6892: Used by &bodytag to determine the current users primary role.
6893: Returns either 'student','coordinator','admin', or 'author'.
6894:
6895: =cut
6896:
6897: ###############################################
6898: sub get_users_function {
6899: my $function = 'norole';
6900: if ($env{'request.role'}=~/^(st)/) {
6901: $function='student';
6902: }
6903: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
6904: $function='coordinator';
6905: }
6906: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
6907: $function='admin';
6908: }
6909: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
6910: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
6911: $function='author';
6912: }
6913: return $function;
6914: }
6915:
6916: ###############################################
6917:
6918: =pod
6919:
6920: =item * &show_course()
6921:
6922: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
6923: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
6924:
6925: Inputs:
6926: None
6927:
6928: Outputs:
6929: Scalar: 1 if 'Course' to be used, 0 otherwise.
6930:
6931: =cut
6932:
6933: ###############################################
6934: sub show_course {
6935: my $course = !$env{'user.adv'};
6936: if (!$env{'user.adv'}) {
6937: foreach my $env (keys(%env)) {
6938: next if ($env !~ m/^user\.priv\./);
6939: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
6940: $course = 0;
6941: last;
6942: }
6943: }
6944: }
6945: return $course;
6946: }
6947:
6948: ###############################################
6949:
6950: =pod
6951:
6952: =item * &check_user_status()
6953:
6954: Determines current status of supplied role for a
6955: specific user. Roles can be active, previous or future.
6956:
6957: Inputs:
6958: user's domain, user's username, course's domain,
6959: course's number, optional section ID.
6960:
6961: Outputs:
6962: role status: active, previous or future.
6963:
6964: =cut
6965:
6966: sub check_user_status {
6967: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
6968: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
6969: my @uroles = keys %userinfo;
6970: my $srchstr;
6971: my $active_chk = 'none';
6972: my $now = time;
6973: if (@uroles > 0) {
6974: if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
6975: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
6976: } else {
6977: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
6978: }
6979: if (grep/^\Q$srchstr\E$/,@uroles) {
6980: my $role_end = 0;
6981: my $role_start = 0;
6982: $active_chk = 'active';
6983: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
6984: $role_end = $1;
6985: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
6986: $role_start = $1;
6987: }
6988: }
6989: if ($role_start > 0) {
6990: if ($now < $role_start) {
6991: $active_chk = 'future';
6992: }
6993: }
6994: if ($role_end > 0) {
6995: if ($now > $role_end) {
6996: $active_chk = 'previous';
6997: }
6998: }
6999: }
7000: }
7001: return $active_chk;
7002: }
7003:
7004: ###############################################
7005:
7006: =pod
7007:
7008: =item * &get_sections()
7009:
7010: Determines all the sections for a course including
7011: sections with students and sections containing other roles.
7012: Incoming parameters:
7013:
7014: 1. domain
7015: 2. course number
7016: 3. reference to array containing roles for which sections should
7017: be gathered (optional).
7018: 4. reference to array containing status types for which sections
7019: should be gathered (optional).
7020:
7021: If the third argument is undefined, sections are gathered for any role.
7022: If the fourth argument is undefined, sections are gathered for any status.
7023: Permissible values are 'active' or 'future' or 'previous'.
7024:
7025: Returns section hash (keys are section IDs, values are
7026: number of users in each section), subject to the
7027: optional roles filter, optional status filter
7028:
7029: =cut
7030:
7031: ###############################################
7032: sub get_sections {
7033: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
7034: if (!defined($cdom) || !defined($cnum)) {
7035: my $cid = $env{'request.course.id'};
7036:
7037: return if (!defined($cid));
7038:
7039: $cdom = $env{'course.'.$cid.'.domain'};
7040: $cnum = $env{'course.'.$cid.'.num'};
7041: }
7042:
7043: my %sectioncount;
7044: my $now = time;
7045:
7046: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
7047: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
7048: my $sec_index = &Apache::loncoursedata::CL_SECTION();
7049: my $status_index = &Apache::loncoursedata::CL_STATUS();
7050: my $start_index = &Apache::loncoursedata::CL_START();
7051: my $end_index = &Apache::loncoursedata::CL_END();
7052: my $status;
7053: while (my ($student,$data) = each(%$classlist)) {
7054: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
7055: $data->[$status_index],
7056: $data->[$start_index],
7057: $data->[$end_index]);
7058: if ($stu_status eq 'Active') {
7059: $status = 'active';
7060: } elsif ($end < $now) {
7061: $status = 'previous';
7062: } elsif ($start > $now) {
7063: $status = 'future';
7064: }
7065: if ($section ne '-1' && $section !~ /^\s*$/) {
7066: if ((!defined($possible_status)) || (($status ne '') &&
7067: (grep/^\Q$status\E$/,@{$possible_status}))) {
7068: $sectioncount{$section}++;
7069: }
7070: }
7071: }
7072: }
7073: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7074: foreach my $user (sort(keys(%courseroles))) {
7075: if ($user !~ /^(\w{2})/) { next; }
7076: my ($role) = ($user =~ /^(\w{2})/);
7077: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
7078: my ($section,$status);
7079: if ($role eq 'cr' &&
7080: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
7081: $section=$1;
7082: }
7083: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
7084: if (!defined($section) || $section eq '-1') { next; }
7085: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
7086: if ($end == -1 && $start == -1) {
7087: next; #deleted role
7088: }
7089: if (!defined($possible_status)) {
7090: $sectioncount{$section}++;
7091: } else {
7092: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
7093: $status = 'active';
7094: } elsif ($end < $now) {
7095: $status = 'future';
7096: } elsif ($start > $now) {
7097: $status = 'previous';
7098: }
7099: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
7100: $sectioncount{$section}++;
7101: }
7102: }
7103: }
7104: return %sectioncount;
7105: }
7106:
7107: ###############################################
7108:
7109: =pod
7110:
7111: =item * &get_course_users()
7112:
7113: Retrieves usernames:domains for users in the specified course
7114: with specific role(s), and access status.
7115:
7116: Incoming parameters:
7117: 1. course domain
7118: 2. course number
7119: 3. access status: users must have - either active,
7120: previous, future, or all.
7121: 4. reference to array of permissible roles
7122: 5. reference to array of section restrictions (optional)
7123: 6. reference to results object (hash of hashes).
7124: 7. reference to optional userdata hash
7125: 8. reference to optional statushash
7126: 9. flag if privileged users (except those set to unhide in
7127: course settings) should be excluded
7128: Keys of top level results hash are roles.
7129: Keys of inner hashes are username:domain, with
7130: values set to access type.
7131: Optional userdata hash returns an array with arguments in the
7132: same order as loncoursedata::get_classlist() for student data.
7133:
7134: Optional statushash returns
7135:
7136: Entries for end, start, section and status are blank because
7137: of the possibility of multiple values for non-student roles.
7138:
7139: =cut
7140:
7141: ###############################################
7142:
7143: sub get_course_users {
7144: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
7145: my %idx = ();
7146: my %seclists;
7147:
7148: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
7149: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
7150: $idx{end} = &Apache::loncoursedata::CL_END();
7151: $idx{start} = &Apache::loncoursedata::CL_START();
7152: $idx{id} = &Apache::loncoursedata::CL_ID();
7153: $idx{section} = &Apache::loncoursedata::CL_SECTION();
7154: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
7155: $idx{status} = &Apache::loncoursedata::CL_STATUS();
7156:
7157: if (grep(/^st$/,@{$roles})) {
7158: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
7159: my $now = time;
7160: foreach my $student (keys(%{$classlist})) {
7161: my $match = 0;
7162: my $secmatch = 0;
7163: my $section = $$classlist{$student}[$idx{section}];
7164: my $status = $$classlist{$student}[$idx{status}];
7165: if ($section eq '') {
7166: $section = 'none';
7167: }
7168: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
7169: if (grep(/^all$/,@{$sections})) {
7170: $secmatch = 1;
7171: } elsif ($$classlist{$student}[$idx{section}] eq '') {
7172: if (grep(/^none$/,@{$sections})) {
7173: $secmatch = 1;
7174: }
7175: } else {
7176: if (grep(/^\Q$section\E$/,@{$sections})) {
7177: $secmatch = 1;
7178: }
7179: }
7180: if (!$secmatch) {
7181: next;
7182: }
7183: }
7184: if (defined($$types{'active'})) {
7185: if ($$classlist{$student}[$idx{status}] eq 'Active') {
7186: push(@{$$users{st}{$student}},'active');
7187: $match = 1;
7188: }
7189: }
7190: if (defined($$types{'previous'})) {
7191: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
7192: push(@{$$users{st}{$student}},'previous');
7193: $match = 1;
7194: }
7195: }
7196: if (defined($$types{'future'})) {
7197: if ($$classlist{$student}[$idx{status}] eq 'Future') {
7198: push(@{$$users{st}{$student}},'future');
7199: $match = 1;
7200: }
7201: }
7202: if ($match) {
7203: push(@{$seclists{$student}},$section);
7204: if (ref($userdata) eq 'HASH') {
7205: $$userdata{$student} = $$classlist{$student};
7206: }
7207: if (ref($statushash) eq 'HASH') {
7208: $statushash->{$student}{'st'}{$section} = $status;
7209: }
7210: }
7211: }
7212: }
7213: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
7214: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7215: my $now = time;
7216: my %displaystatus = ( previous => 'Expired',
7217: active => 'Active',
7218: future => 'Future',
7219: );
7220: my %nothide;
7221: if ($hidepriv) {
7222: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
7223: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
7224: if ($user !~ /:/) {
7225: $nothide{join(':',split(/[\@]/,$user))}=1;
7226: } else {
7227: $nothide{$user} = 1;
7228: }
7229: }
7230: }
7231: foreach my $person (sort(keys(%coursepersonnel))) {
7232: my $match = 0;
7233: my $secmatch = 0;
7234: my $status;
7235: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
7236: $user =~ s/:$//;
7237: my ($end,$start) = split(/:/,$coursepersonnel{$person});
7238: if ($end == -1 || $start == -1) {
7239: next;
7240: }
7241: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
7242: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
7243: my ($uname,$udom) = split(/:/,$user);
7244: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
7245: if (grep(/^all$/,@{$sections})) {
7246: $secmatch = 1;
7247: } elsif ($usec eq '') {
7248: if (grep(/^none$/,@{$sections})) {
7249: $secmatch = 1;
7250: }
7251: } else {
7252: if (grep(/^\Q$usec\E$/,@{$sections})) {
7253: $secmatch = 1;
7254: }
7255: }
7256: if (!$secmatch) {
7257: next;
7258: }
7259: }
7260: if ($usec eq '') {
7261: $usec = 'none';
7262: }
7263: if ($uname ne '' && $udom ne '') {
7264: if ($hidepriv) {
7265: if ((&Apache::lonnet::privileged($uname,$udom)) &&
7266: (!$nothide{$uname.':'.$udom})) {
7267: next;
7268: }
7269: }
7270: if ($end > 0 && $end < $now) {
7271: $status = 'previous';
7272: } elsif ($start > $now) {
7273: $status = 'future';
7274: } else {
7275: $status = 'active';
7276: }
7277: foreach my $type (keys(%{$types})) {
7278: if ($status eq $type) {
7279: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
7280: push(@{$$users{$role}{$user}},$type);
7281: }
7282: $match = 1;
7283: }
7284: }
7285: if (($match) && (ref($userdata) eq 'HASH')) {
7286: if (!exists($$userdata{$uname.':'.$udom})) {
7287: &get_user_info($udom,$uname,\%idx,$userdata);
7288: }
7289: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
7290: push(@{$seclists{$uname.':'.$udom}},$usec);
7291: }
7292: if (ref($statushash) eq 'HASH') {
7293: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
7294: }
7295: }
7296: }
7297: }
7298: }
7299: if (grep(/^ow$/,@{$roles})) {
7300: if ((defined($cdom)) && (defined($cnum))) {
7301: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
7302: if ( defined($csettings{'internal.courseowner'}) ) {
7303: my $owner = $csettings{'internal.courseowner'};
7304: next if ($owner eq '');
7305: my ($ownername,$ownerdom);
7306: if ($owner =~ /^([^:]+):([^:]+)$/) {
7307: $ownername = $1;
7308: $ownerdom = $2;
7309: } else {
7310: $ownername = $owner;
7311: $ownerdom = $cdom;
7312: $owner = $ownername.':'.$ownerdom;
7313: }
7314: @{$$users{'ow'}{$owner}} = 'any';
7315: if (defined($userdata) &&
7316: !exists($$userdata{$owner})) {
7317: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
7318: if (!grep(/^none$/,@{$seclists{$owner}})) {
7319: push(@{$seclists{$owner}},'none');
7320: }
7321: if (ref($statushash) eq 'HASH') {
7322: $statushash->{$owner}{'ow'}{'none'} = 'Any';
7323: }
7324: }
7325: }
7326: }
7327: }
7328: foreach my $user (keys(%seclists)) {
7329: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
7330: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
7331: }
7332: }
7333: return;
7334: }
7335:
7336: sub get_user_info {
7337: my ($udom,$uname,$idx,$userdata) = @_;
7338: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
7339: &plainname($uname,$udom,'lastname');
7340: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
7341: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
7342: my %idhash = &Apache::lonnet::idrget($udom,($uname));
7343: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
7344: return;
7345: }
7346:
7347: ###############################################
7348:
7349: =pod
7350:
7351: =item * &get_user_quota()
7352:
7353: Retrieves quota assigned for storage of portfolio files for a user
7354:
7355: Incoming parameters:
7356: 1. user's username
7357: 2. user's domain
7358:
7359: Returns:
7360: 1. Disk quota (in Mb) assigned to student.
7361: 2. (Optional) Type of setting: custom or default
7362: (individually assigned or default for user's
7363: institutional status).
7364: 3. (Optional) - User's institutional status (e.g., faculty, staff
7365: or student - types as defined in localenroll::inst_usertypes
7366: for user's domain, which determines default quota for user.
7367: 4. (Optional) - Default quota which would apply to the user.
7368:
7369: If a value has been stored in the user's environment,
7370: it will return that, otherwise it returns the maximal default
7371: defined for the user's instituional status(es) in the domain.
7372:
7373: =cut
7374:
7375: ###############################################
7376:
7377:
7378: sub get_user_quota {
7379: my ($uname,$udom) = @_;
7380: my ($quota,$quotatype,$settingstatus,$defquota);
7381: if (!defined($udom)) {
7382: $udom = $env{'user.domain'};
7383: }
7384: if (!defined($uname)) {
7385: $uname = $env{'user.name'};
7386: }
7387: if (($udom eq '' || $uname eq '') ||
7388: ($udom eq 'public') && ($uname eq 'public')) {
7389: $quota = 0;
7390: $quotatype = 'default';
7391: $defquota = 0;
7392: } else {
7393: my $inststatus;
7394: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
7395: $quota = $env{'environment.portfolioquota'};
7396: $inststatus = $env{'environment.inststatus'};
7397: } else {
7398: my %userenv =
7399: &Apache::lonnet::get('environment',['portfolioquota',
7400: 'inststatus'],$udom,$uname);
7401: my ($tmp) = keys(%userenv);
7402: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
7403: $quota = $userenv{'portfolioquota'};
7404: $inststatus = $userenv{'inststatus'};
7405: } else {
7406: undef(%userenv);
7407: }
7408: }
7409: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
7410: if ($quota eq '') {
7411: $quota = $defquota;
7412: $quotatype = 'default';
7413: } else {
7414: $quotatype = 'custom';
7415: }
7416: }
7417: if (wantarray) {
7418: return ($quota,$quotatype,$settingstatus,$defquota);
7419: } else {
7420: return $quota;
7421: }
7422: }
7423:
7424: ###############################################
7425:
7426: =pod
7427:
7428: =item * &default_quota()
7429:
7430: Retrieves default quota assigned for storage of user portfolio files,
7431: given an (optional) user's institutional status.
7432:
7433: Incoming parameters:
7434: 1. domain
7435: 2. (Optional) institutional status(es). This is a : separated list of
7436: status types (e.g., faculty, staff, student etc.)
7437: which apply to the user for whom the default is being retrieved.
7438: If the institutional status string in undefined, the domain
7439: default quota will be returned.
7440:
7441: Returns:
7442: 1. Default disk quota (in Mb) for user portfolios in the domain.
7443: 2. (Optional) institutional type which determined the value of the
7444: default quota.
7445:
7446: If a value has been stored in the domain's configuration db,
7447: it will return that, otherwise it returns 20 (for backwards
7448: compatibility with domains which have not set up a configuration
7449: db file; the original statically defined portfolio quota was 20 Mb).
7450:
7451: If the user's status includes multiple types (e.g., staff and student),
7452: the largest default quota which applies to the user determines the
7453: default quota returned.
7454:
7455: =back
7456:
7457: =cut
7458:
7459: ###############################################
7460:
7461:
7462: sub default_quota {
7463: my ($udom,$inststatus) = @_;
7464: my ($defquota,$settingstatus);
7465: my %quotahash = &Apache::lonnet::get_dom('configuration',
7466: ['quotas'],$udom);
7467: if (ref($quotahash{'quotas'}) eq 'HASH') {
7468: if ($inststatus ne '') {
7469: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
7470: foreach my $item (@statuses) {
7471: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7472: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
7473: if ($defquota eq '') {
7474: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7475: $settingstatus = $item;
7476: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
7477: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7478: $settingstatus = $item;
7479: }
7480: }
7481: } else {
7482: if ($quotahash{'quotas'}{$item} ne '') {
7483: if ($defquota eq '') {
7484: $defquota = $quotahash{'quotas'}{$item};
7485: $settingstatus = $item;
7486: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
7487: $defquota = $quotahash{'quotas'}{$item};
7488: $settingstatus = $item;
7489: }
7490: }
7491: }
7492: }
7493: }
7494: if ($defquota eq '') {
7495: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7496: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
7497: } else {
7498: $defquota = $quotahash{'quotas'}{'default'};
7499: }
7500: $settingstatus = 'default';
7501: }
7502: } else {
7503: $settingstatus = 'default';
7504: $defquota = 20;
7505: }
7506: if (wantarray) {
7507: return ($defquota,$settingstatus);
7508: } else {
7509: return $defquota;
7510: }
7511: }
7512:
7513: sub get_secgrprole_info {
7514: my ($cdom,$cnum,$needroles,$type) = @_;
7515: my %sections_count = &get_sections($cdom,$cnum);
7516: my @sections = (sort {$a <=> $b} keys(%sections_count));
7517: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
7518: my @groups = sort(keys(%curr_groups));
7519: my $allroles = [];
7520: my $rolehash;
7521: my $accesshash = {
7522: active => 'Currently has access',
7523: future => 'Will have future access',
7524: previous => 'Previously had access',
7525: };
7526: if ($needroles) {
7527: $rolehash = {'all' => 'all'};
7528: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7529: if (&Apache::lonnet::error(%user_roles)) {
7530: undef(%user_roles);
7531: }
7532: foreach my $item (keys(%user_roles)) {
7533: my ($role)=split(/\:/,$item,2);
7534: if ($role eq 'cr') { next; }
7535: if ($role =~ /^cr/) {
7536: $$rolehash{$role} = (split('/',$role))[3];
7537: } else {
7538: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
7539: }
7540: }
7541: foreach my $key (sort(keys(%{$rolehash}))) {
7542: push(@{$allroles},$key);
7543: }
7544: push (@{$allroles},'st');
7545: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
7546: }
7547: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
7548: }
7549:
7550: sub user_picker {
7551: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
7552: my $currdom = $dom;
7553: my %curr_selected = (
7554: srchin => 'dom',
7555: srchby => 'lastname',
7556: );
7557: my $srchterm;
7558: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
7559: if ($srch->{'srchby'} ne '') {
7560: $curr_selected{'srchby'} = $srch->{'srchby'};
7561: }
7562: if ($srch->{'srchin'} ne '') {
7563: $curr_selected{'srchin'} = $srch->{'srchin'};
7564: }
7565: if ($srch->{'srchtype'} ne '') {
7566: $curr_selected{'srchtype'} = $srch->{'srchtype'};
7567: }
7568: if ($srch->{'srchdomain'} ne '') {
7569: $currdom = $srch->{'srchdomain'};
7570: }
7571: $srchterm = $srch->{'srchterm'};
7572: }
7573: my %lt=&Apache::lonlocal::texthash(
7574: 'usr' => 'Search criteria',
7575: 'doma' => 'Domain/institution to search',
7576: 'uname' => 'username',
7577: 'lastname' => 'last name',
7578: 'lastfirst' => 'last name, first name',
7579: 'crs' => 'in this course',
7580: 'dom' => 'in selected LON-CAPA domain',
7581: 'alc' => 'all LON-CAPA',
7582: 'instd' => 'in institutional directory for selected domain',
7583: 'exact' => 'is',
7584: 'contains' => 'contains',
7585: 'begins' => 'begins with',
7586: 'youm' => "You must include some text to search for.",
7587: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
7588: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
7589: 'yomc' => "You must choose a domain when using an institutional directory search.",
7590: 'ymcd' => "You must choose a domain when using a domain search.",
7591: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
7592: 'whse' => "When searching by last,first you must include at least one character in the first name.",
7593: 'thfo' => "The following need to be corrected before the search can be run:",
7594: );
7595: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
7596: my $srchinsel = ' <select name="srchin">';
7597:
7598: my @srchins = ('crs','dom','alc','instd');
7599:
7600: foreach my $option (@srchins) {
7601: # FIXME 'alc' option unavailable until
7602: # loncreateuser::print_user_query_page()
7603: # has been completed.
7604: next if ($option eq 'alc');
7605: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
7606: next if ($option eq 'crs' && !$env{'request.course.id'});
7607: if ($curr_selected{'srchin'} eq $option) {
7608: $srchinsel .= '
7609: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7610: } else {
7611: $srchinsel .= '
7612: <option value="'.$option.'">'.$lt{$option}.'</option>';
7613: }
7614: }
7615: $srchinsel .= "\n </select>\n";
7616:
7617: my $srchbysel = ' <select name="srchby">';
7618: foreach my $option ('lastname','lastfirst','uname') {
7619: if ($curr_selected{'srchby'} eq $option) {
7620: $srchbysel .= '
7621: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7622: } else {
7623: $srchbysel .= '
7624: <option value="'.$option.'">'.$lt{$option}.'</option>';
7625: }
7626: }
7627: $srchbysel .= "\n </select>\n";
7628:
7629: my $srchtypesel = ' <select name="srchtype">';
7630: foreach my $option ('begins','contains','exact') {
7631: if ($curr_selected{'srchtype'} eq $option) {
7632: $srchtypesel .= '
7633: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7634: } else {
7635: $srchtypesel .= '
7636: <option value="'.$option.'">'.$lt{$option}.'</option>';
7637: }
7638: }
7639: $srchtypesel .= "\n </select>\n";
7640:
7641: my ($newuserscript,$new_user_create);
7642:
7643: if ($forcenewuser) {
7644: if (ref($srch) eq 'HASH') {
7645: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
7646: if ($cancreate) {
7647: $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>';
7648: } else {
7649: my $helplink = 'javascript:helpMenu('."'display'".')';
7650: my %usertypetext = (
7651: official => 'institutional',
7652: unofficial => 'non-institutional',
7653: );
7654: $new_user_create = '<p class="LC_warning">'
7655: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
7656: .' '
7657: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
7658: ,'<a href="'.$helplink.'">','</a>')
7659: .'</p><br />';
7660: }
7661: }
7662: }
7663:
7664: $newuserscript = <<"ENDSCRIPT";
7665:
7666: function setSearch(createnew,callingForm) {
7667: if (createnew == 1) {
7668: for (var i=0; i<callingForm.srchby.length; i++) {
7669: if (callingForm.srchby.options[i].value == 'uname') {
7670: callingForm.srchby.selectedIndex = i;
7671: }
7672: }
7673: for (var i=0; i<callingForm.srchin.length; i++) {
7674: if ( callingForm.srchin.options[i].value == 'dom') {
7675: callingForm.srchin.selectedIndex = i;
7676: }
7677: }
7678: for (var i=0; i<callingForm.srchtype.length; i++) {
7679: if (callingForm.srchtype.options[i].value == 'exact') {
7680: callingForm.srchtype.selectedIndex = i;
7681: }
7682: }
7683: for (var i=0; i<callingForm.srchdomain.length; i++) {
7684: if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
7685: callingForm.srchdomain.selectedIndex = i;
7686: }
7687: }
7688: }
7689: }
7690: ENDSCRIPT
7691:
7692: }
7693:
7694: my $output = <<"END_BLOCK";
7695: <script type="text/javascript">
7696: // <![CDATA[
7697: function validateEntry(callingForm) {
7698:
7699: var checkok = 1;
7700: var srchin;
7701: for (var i=0; i<callingForm.srchin.length; i++) {
7702: if ( callingForm.srchin[i].checked ) {
7703: srchin = callingForm.srchin[i].value;
7704: }
7705: }
7706:
7707: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
7708: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
7709: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
7710: var srchterm = callingForm.srchterm.value;
7711: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
7712: var msg = "";
7713:
7714: if (srchterm == "") {
7715: checkok = 0;
7716: msg += "$lt{'youm'}\\n";
7717: }
7718:
7719: if (srchtype== 'begins') {
7720: if (srchterm.length < 2) {
7721: checkok = 0;
7722: msg += "$lt{'thte'}\\n";
7723: }
7724: }
7725:
7726: if (srchtype== 'contains') {
7727: if (srchterm.length < 3) {
7728: checkok = 0;
7729: msg += "$lt{'thet'}\\n";
7730: }
7731: }
7732: if (srchin == 'instd') {
7733: if (srchdomain == '') {
7734: checkok = 0;
7735: msg += "$lt{'yomc'}\\n";
7736: }
7737: }
7738: if (srchin == 'dom') {
7739: if (srchdomain == '') {
7740: checkok = 0;
7741: msg += "$lt{'ymcd'}\\n";
7742: }
7743: }
7744: if (srchby == 'lastfirst') {
7745: if (srchterm.indexOf(",") == -1) {
7746: checkok = 0;
7747: msg += "$lt{'whus'}\\n";
7748: }
7749: if (srchterm.indexOf(",") == srchterm.length -1) {
7750: checkok = 0;
7751: msg += "$lt{'whse'}\\n";
7752: }
7753: }
7754: if (checkok == 0) {
7755: alert("$lt{'thfo'}\\n"+msg);
7756: return;
7757: }
7758: if (checkok == 1) {
7759: callingForm.submit();
7760: }
7761: }
7762:
7763: $newuserscript
7764:
7765: // ]]>
7766: </script>
7767:
7768: $new_user_create
7769:
7770: END_BLOCK
7771:
7772: $output .= &Apache::lonhtmlcommon::start_pick_box().
7773: &Apache::lonhtmlcommon::row_title($lt{'doma'}).
7774: $domform.
7775: &Apache::lonhtmlcommon::row_closure().
7776: &Apache::lonhtmlcommon::row_title($lt{'usr'}).
7777: $srchbysel.
7778: $srchtypesel.
7779: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
7780: $srchinsel.
7781: &Apache::lonhtmlcommon::row_closure(1).
7782: &Apache::lonhtmlcommon::end_pick_box().
7783: '<br />';
7784: return $output;
7785: }
7786:
7787: sub user_rule_check {
7788: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
7789: my $response;
7790: if (ref($usershash) eq 'HASH') {
7791: foreach my $user (keys(%{$usershash})) {
7792: my ($uname,$udom) = split(/:/,$user);
7793: next if ($udom eq '' || $uname eq '');
7794: my ($id,$newuser);
7795: if (ref($usershash->{$user}) eq 'HASH') {
7796: $newuser = $usershash->{$user}->{'newuser'};
7797: $id = $usershash->{$user}->{'id'};
7798: }
7799: my $inst_response;
7800: if (ref($checks) eq 'HASH') {
7801: if (defined($checks->{'username'})) {
7802: ($inst_response,%{$inst_results->{$user}}) =
7803: &Apache::lonnet::get_instuser($udom,$uname);
7804: } elsif (defined($checks->{'id'})) {
7805: ($inst_response,%{$inst_results->{$user}}) =
7806: &Apache::lonnet::get_instuser($udom,undef,$id);
7807: }
7808: } else {
7809: ($inst_response,%{$inst_results->{$user}}) =
7810: &Apache::lonnet::get_instuser($udom,$uname);
7811: return;
7812: }
7813: if (!$got_rules->{$udom}) {
7814: my %domconfig = &Apache::lonnet::get_dom('configuration',
7815: ['usercreation'],$udom);
7816: if (ref($domconfig{'usercreation'}) eq 'HASH') {
7817: foreach my $item ('username','id') {
7818: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
7819: $$curr_rules{$udom}{$item} =
7820: $domconfig{'usercreation'}{$item.'_rule'};
7821: }
7822: }
7823: }
7824: $got_rules->{$udom} = 1;
7825: }
7826: foreach my $item (keys(%{$checks})) {
7827: if (ref($$curr_rules{$udom}) eq 'HASH') {
7828: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
7829: if (@{$$curr_rules{$udom}{$item}} > 0) {
7830: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
7831: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
7832: if ($rule_check{$rule}) {
7833: $$rulematch{$user}{$item} = $rule;
7834: if ($inst_response eq 'ok') {
7835: if (ref($inst_results) eq 'HASH') {
7836: if (ref($inst_results->{$user}) eq 'HASH') {
7837: if (keys(%{$inst_results->{$user}}) == 0) {
7838: $$alerts{$item}{$udom}{$uname} = 1;
7839: }
7840: }
7841: }
7842: }
7843: last;
7844: }
7845: }
7846: }
7847: }
7848: }
7849: }
7850: }
7851: }
7852: return;
7853: }
7854:
7855: sub user_rule_formats {
7856: my ($domain,$domdesc,$curr_rules,$check) = @_;
7857: my %text = (
7858: 'username' => 'Usernames',
7859: 'id' => 'IDs',
7860: );
7861: my $output;
7862: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
7863: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
7864: if (@{$ruleorder} > 0) {
7865: $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>';
7866: foreach my $rule (@{$ruleorder}) {
7867: if (ref($curr_rules) eq 'ARRAY') {
7868: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
7869: if (ref($rules->{$rule}) eq 'HASH') {
7870: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
7871: $rules->{$rule}{'desc'}.'</li>';
7872: }
7873: }
7874: }
7875: }
7876: $output .= '</ul>';
7877: }
7878: }
7879: return $output;
7880: }
7881:
7882: sub instrule_disallow_msg {
7883: my ($checkitem,$domdesc,$count,$mode) = @_;
7884: my $response;
7885: my %text = (
7886: item => 'username',
7887: items => 'usernames',
7888: match => 'matches',
7889: do => 'does',
7890: action => 'a username',
7891: one => 'one',
7892: );
7893: if ($count > 1) {
7894: $text{'item'} = 'usernames';
7895: $text{'match'} ='match';
7896: $text{'do'} = 'do';
7897: $text{'action'} = 'usernames',
7898: $text{'one'} = 'ones';
7899: }
7900: if ($checkitem eq 'id') {
7901: $text{'items'} = 'IDs';
7902: $text{'item'} = 'ID';
7903: $text{'action'} = 'an ID';
7904: if ($count > 1) {
7905: $text{'item'} = 'IDs';
7906: $text{'action'} = 'IDs';
7907: }
7908: }
7909: $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 />';
7910: if ($mode eq 'upload') {
7911: if ($checkitem eq 'username') {
7912: $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'}.");
7913: } elsif ($checkitem eq 'id') {
7914: $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.");
7915: }
7916: } elsif ($mode eq 'selfcreate') {
7917: if ($checkitem eq 'id') {
7918: $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.");
7919: }
7920: } else {
7921: if ($checkitem eq 'username') {
7922: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
7923: } elsif ($checkitem eq 'id') {
7924: $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.");
7925: }
7926: }
7927: return $response;
7928: }
7929:
7930: sub personal_data_fieldtitles {
7931: my %fieldtitles = &Apache::lonlocal::texthash (
7932: id => 'Student/Employee ID',
7933: permanentemail => 'E-mail address',
7934: lastname => 'Last Name',
7935: firstname => 'First Name',
7936: middlename => 'Middle Name',
7937: generation => 'Generation',
7938: gen => 'Generation',
7939: inststatus => 'Affiliation',
7940: );
7941: return %fieldtitles;
7942: }
7943:
7944: sub sorted_inst_types {
7945: my ($dom) = @_;
7946: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
7947: my $othertitle = &mt('All users');
7948: if ($env{'request.course.id'}) {
7949: $othertitle = &mt('Any users');
7950: }
7951: my @types;
7952: if (ref($order) eq 'ARRAY') {
7953: @types = @{$order};
7954: }
7955: if (@types == 0) {
7956: if (ref($usertypes) eq 'HASH') {
7957: @types = sort(keys(%{$usertypes}));
7958: }
7959: }
7960: if (keys(%{$usertypes}) > 0) {
7961: $othertitle = &mt('Other users');
7962: }
7963: return ($othertitle,$usertypes,\@types);
7964: }
7965:
7966: sub get_institutional_codes {
7967: my ($settings,$allcourses,$LC_code) = @_;
7968: # Get complete list of course sections to update
7969: my @currsections = ();
7970: my @currxlists = ();
7971: my $coursecode = $$settings{'internal.coursecode'};
7972:
7973: if ($$settings{'internal.sectionnums'} ne '') {
7974: @currsections = split(/,/,$$settings{'internal.sectionnums'});
7975: }
7976:
7977: if ($$settings{'internal.crosslistings'} ne '') {
7978: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
7979: }
7980:
7981: if (@currxlists > 0) {
7982: foreach (@currxlists) {
7983: if (m/^([^:]+):(\w*)$/) {
7984: unless (grep/^$1$/,@{$allcourses}) {
7985: push @{$allcourses},$1;
7986: $$LC_code{$1} = $2;
7987: }
7988: }
7989: }
7990: }
7991:
7992: if (@currsections > 0) {
7993: foreach (@currsections) {
7994: if (m/^(\w+):(\w*)$/) {
7995: my $sec = $coursecode.$1;
7996: my $lc_sec = $2;
7997: unless (grep/^$sec$/,@{$allcourses}) {
7998: push @{$allcourses},$sec;
7999: $$LC_code{$sec} = $lc_sec;
8000: }
8001: }
8002: }
8003: }
8004: return;
8005: }
8006:
8007: =pod
8008:
8009: =head1 Slot Helpers
8010:
8011: =over 4
8012:
8013: =item * sorted_slots()
8014:
8015: Sorts an array of slot names in order of slot start time (earliest first).
8016:
8017: Inputs:
8018:
8019: =over 4
8020:
8021: slotsarr - Reference to array of unsorted slot names.
8022:
8023: slots - Reference to hash of hash, where outer hash keys are slot names.
8024:
8025: =back
8026:
8027: Returns:
8028:
8029: =over 4
8030:
8031: sorted - An array of slot names sorted by the start time of the slot.
8032:
8033: =back
8034:
8035: =back
8036:
8037: =cut
8038:
8039:
8040: sub sorted_slots {
8041: my ($slotsarr,$slots) = @_;
8042: my @sorted;
8043: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
8044: @sorted =
8045: sort {
8046: if (ref($slots->{$a}) && ref($slots->{$b})) {
8047: return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
8048: }
8049: if (ref($slots->{$a})) { return -1;}
8050: if (ref($slots->{$b})) { return 1;}
8051: return 0;
8052: } @{$slotsarr};
8053: }
8054: return @sorted;
8055: }
8056:
8057:
8058: =pod
8059:
8060: =head1 HTTP Helpers
8061:
8062: =over 4
8063:
8064: =item * &get_unprocessed_cgi($query,$possible_names)
8065:
8066: Modify the %env hash to contain unprocessed CGI form parameters held in
8067: $query. The parameters listed in $possible_names (an array reference),
8068: will be set in $env{'form.name'} if they do not already exist.
8069:
8070: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
8071: $possible_names is an ref to an array of form element names. As an example:
8072: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
8073: will result in $env{'form.uname'} and $env{'form.udom'} being set.
8074:
8075: =cut
8076:
8077: sub get_unprocessed_cgi {
8078: my ($query,$possible_names)= @_;
8079: # $Apache::lonxml::debug=1;
8080: foreach my $pair (split(/&/,$query)) {
8081: my ($name, $value) = split(/=/,$pair);
8082: $name = &unescape($name);
8083: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
8084: $value =~ tr/+/ /;
8085: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
8086: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
8087: }
8088: }
8089: }
8090:
8091: =pod
8092:
8093: =item * &cacheheader()
8094:
8095: returns cache-controlling header code
8096:
8097: =cut
8098:
8099: sub cacheheader {
8100: unless ($env{'request.method'} eq 'GET') { return ''; }
8101: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
8102: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
8103: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
8104: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
8105: return $output;
8106: }
8107:
8108: =pod
8109:
8110: =item * &no_cache($r)
8111:
8112: specifies header code to not have cache
8113:
8114: =cut
8115:
8116: sub no_cache {
8117: my ($r) = @_;
8118: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
8119: $env{'request.method'} ne 'GET') { return ''; }
8120: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
8121: $r->no_cache(1);
8122: $r->header_out("Expires" => $date);
8123: $r->header_out("Pragma" => "no-cache");
8124: }
8125:
8126: sub content_type {
8127: my ($r,$type,$charset) = @_;
8128: if ($r) {
8129: # Note that printout.pl calls this with undef for $r.
8130: &no_cache($r);
8131: }
8132: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
8133: unless ($charset) {
8134: $charset=&Apache::lonlocal::current_encoding;
8135: }
8136: if ($charset) { $type.='; charset='.$charset; }
8137: if ($r) {
8138: $r->content_type($type);
8139: } else {
8140: print("Content-type: $type\n\n");
8141: }
8142: }
8143:
8144: =pod
8145:
8146: =item * &add_to_env($name,$value)
8147:
8148: adds $name to the %env hash with value
8149: $value, if $name already exists, the entry is converted to an array
8150: reference and $value is added to the array.
8151:
8152: =cut
8153:
8154: sub add_to_env {
8155: my ($name,$value)=@_;
8156: if (defined($env{$name})) {
8157: if (ref($env{$name})) {
8158: #already have multiple values
8159: push(@{ $env{$name} },$value);
8160: } else {
8161: #first time seeing multiple values, convert hash entry to an arrayref
8162: my $first=$env{$name};
8163: undef($env{$name});
8164: push(@{ $env{$name} },$first,$value);
8165: }
8166: } else {
8167: $env{$name}=$value;
8168: }
8169: }
8170:
8171: =pod
8172:
8173: =item * &get_env_multiple($name)
8174:
8175: gets $name from the %env hash, it seemlessly handles the cases where multiple
8176: values may be defined and end up as an array ref.
8177:
8178: returns an array of values
8179:
8180: =cut
8181:
8182: sub get_env_multiple {
8183: my ($name) = @_;
8184: my @values;
8185: if (defined($env{$name})) {
8186: # exists is it an array
8187: if (ref($env{$name})) {
8188: @values=@{ $env{$name} };
8189: } else {
8190: $values[0]=$env{$name};
8191: }
8192: }
8193: return(@values);
8194: }
8195:
8196: sub ask_for_embedded_content {
8197: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
8198: my $upload_output = '
8199: <form name="upload_embedded" action="'.$actionurl.'"
8200: method="post" enctype="multipart/form-data">';
8201: $upload_output .= $state;
8202: $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
8203:
8204: my $num = 0;
8205: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
8206: $upload_output .= &start_data_table_row().
8207: '<td>'.$embed_file.'</td><td>';
8208: if ($args->{'ignore_remote_references'}
8209: && $embed_file =~ m{^\w+://}) {
8210: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
8211: } elsif ($args->{'error_on_invalid_names'}
8212: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
8213:
8214: $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
8215:
8216: } else {
8217: $upload_output .='
8218: <input name="embedded_item_'.$num.'" type="file" value="" />
8219: <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
8220: my $attrib = join(':',@{$$allfiles{$embed_file}});
8221: $upload_output .=
8222: "\n\t\t".
8223: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
8224: $attrib.'" />';
8225: if (exists($$codebase{$embed_file})) {
8226: $upload_output .=
8227: "\n\t\t".
8228: '<input name="codebase_'.$num.'" type="hidden" value="'.
8229: &escape($$codebase{$embed_file}).'" />';
8230: }
8231: }
8232: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
8233: $num++;
8234: }
8235: $upload_output .= &Apache::loncommon::end_data_table().'<br />
8236: <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
8237: <input type ="submit" value="'.&mt('Upload Listed Files').'" />
8238: '.&mt('(only files for which a location has been provided will be uploaded)').'
8239: </form>';
8240: return $upload_output;
8241: }
8242:
8243: sub upload_embedded {
8244: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
8245: $current_disk_usage) = @_;
8246: my $output;
8247: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
8248: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
8249: my $orig_uploaded_filename =
8250: $env{'form.embedded_item_'.$i.'.filename'};
8251:
8252: $env{'form.embedded_orig_'.$i} =
8253: &unescape($env{'form.embedded_orig_'.$i});
8254: my ($path,$fname) =
8255: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
8256: # no path, whole string is fname
8257: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
8258:
8259: $path = $env{'form.currentpath'}.$path;
8260: $fname = &Apache::lonnet::clean_filename($fname);
8261: # See if there is anything left
8262: next if ($fname eq '');
8263:
8264: # Check if file already exists as a file or directory.
8265: my ($state,$msg);
8266: if ($context eq 'portfolio') {
8267: my $port_path = $dirpath;
8268: if ($group ne '') {
8269: $port_path = "groups/$group/$port_path";
8270: }
8271: ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
8272: $dir_root,$port_path,$disk_quota,
8273: $current_disk_usage,$uname,$udom);
8274: if ($state eq 'will_exceed_quota'
8275: || $state eq 'file_locked'
8276: || $state eq 'file_exists' ) {
8277: $output .= $msg;
8278: next;
8279: }
8280: } elsif (($context eq 'author') || ($context eq 'testbank')) {
8281: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
8282: if ($state eq 'exists') {
8283: $output .= $msg;
8284: next;
8285: }
8286: }
8287: # Check if extension is valid
8288: if (($fname =~ /\.(\w+)$/) &&
8289: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
8290: $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
8291: next;
8292: } elsif (($fname =~ /\.(\w+)$/) &&
8293: (!defined(&Apache::loncommon::fileembstyle($1)))) {
8294: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
8295: next;
8296: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
8297: $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
8298: next;
8299: }
8300:
8301: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
8302: if ($context eq 'portfolio') {
8303: my $result=
8304: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
8305: $dirpath.$path);
8306: if ($result !~ m|^/uploaded/|) {
8307: $output .= '<span class="LC_error">'
8308: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
8309: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
8310: .'</span><br />';
8311: next;
8312: } else {
8313: $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
8314: $path.$fname.'</span>').'</p>';
8315: }
8316: } else {
8317: # Save the file
8318: my $target = $env{'form.embedded_item_'.$i};
8319: my $fullpath = $dir_root.$dirpath.'/'.$path;
8320: my $dest = $fullpath.$fname;
8321: my $url = $url_root.$dirpath.'/'.$path.$fname;
8322: my @parts=split(/\//,$fullpath);
8323: my $count;
8324: my $filepath = $dir_root;
8325: for ($count=4;$count<=$#parts;$count++) {
8326: $filepath .= "/$parts[$count]";
8327: if ((-e $filepath)!=1) {
8328: mkdir($filepath,0770);
8329: }
8330: }
8331: my $fh;
8332: if (!open($fh,'>'.$dest)) {
8333: &Apache::lonnet::logthis('Failed to create '.$dest);
8334: $output .= '<span class="LC_error">'.
8335: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8336: '</span><br />';
8337: } else {
8338: if (!print $fh $env{'form.embedded_item_'.$i}) {
8339: &Apache::lonnet::logthis('Failed to write to '.$dest);
8340: $output .= '<span class="LC_error">'.
8341: &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8342: '</span><br />';
8343: } else {
8344: if ($context eq 'testbank') {
8345: $output .= &mt('Embedded file uploaded successfully:').
8346: ' <a href="'.$url.'">'.
8347: $orig_uploaded_filename.'</a><br />';
8348: } else {
8349: $output .= '<span class=\"LC_fontsize_large\">'.
8350: &mt('View embedded file: [_1]','<a href="'.$url.'">'.
8351: $orig_uploaded_filename.'</a>').'</span><br />';
8352: }
8353: }
8354: close($fh);
8355: }
8356: }
8357: }
8358: return $output;
8359: }
8360:
8361: sub check_for_existing {
8362: my ($path,$fname,$element) = @_;
8363: my ($state,$msg);
8364: if (-d $path.'/'.$fname) {
8365: $state = 'exists';
8366: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
8367: } elsif (-e $path.'/'.$fname) {
8368: $state = 'exists';
8369: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
8370: }
8371: if ($state eq 'exists') {
8372: $msg = '<span class="LC_error">'.$msg.'</span><br />';
8373: }
8374: return ($state,$msg);
8375: }
8376:
8377: sub check_for_upload {
8378: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
8379: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
8380: my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
8381: my $getpropath = 1;
8382: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
8383: $getpropath);
8384: my $found_file = 0;
8385: my $locked_file = 0;
8386: foreach my $line (@dir_list) {
8387: my ($file_name)=split(/\&/,$line,2);
8388: if ($file_name eq $fname){
8389: $file_name = $path.$file_name;
8390: if ($group ne '') {
8391: $file_name = $group.$file_name;
8392: }
8393: $found_file = 1;
8394: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
8395: $locked_file = 1;
8396: }
8397: }
8398: }
8399: if (($current_disk_usage + $filesize) > $disk_quota){
8400: my $msg = '<span class="LC_error">'.
8401: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
8402: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
8403: return ('will_exceed_quota',$msg);
8404: } elsif ($found_file) {
8405: if ($locked_file) {
8406: my $msg = '<span class="LC_error">';
8407: $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>');
8408: $msg .= '</span><br />';
8409: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
8410: return ('file_locked',$msg);
8411: } else {
8412: my $msg = '<span class="LC_error">';
8413: $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'});
8414: $msg .= '</span>';
8415: $msg .= '<br />';
8416: $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
8417: return ('file_exists',$msg);
8418: }
8419: }
8420: }
8421:
8422:
8423: =pod
8424:
8425: =back
8426:
8427: =head1 CSV Upload/Handling functions
8428:
8429: =over 4
8430:
8431: =item * &upfile_store($r)
8432:
8433: Store uploaded file, $r should be the HTTP Request object,
8434: needs $env{'form.upfile'}
8435: returns $datatoken to be put into hidden field
8436:
8437: =cut
8438:
8439: sub upfile_store {
8440: my $r=shift;
8441: $env{'form.upfile'}=~s/\r/\n/gs;
8442: $env{'form.upfile'}=~s/\f/\n/gs;
8443: $env{'form.upfile'}=~s/\n+/\n/gs;
8444: $env{'form.upfile'}=~s/\n+$//gs;
8445:
8446: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
8447: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
8448: {
8449: my $datafile = $r->dir_config('lonDaemons').
8450: '/tmp/'.$datatoken.'.tmp';
8451: if ( open(my $fh,">$datafile") ) {
8452: print $fh $env{'form.upfile'};
8453: close($fh);
8454: }
8455: }
8456: return $datatoken;
8457: }
8458:
8459: =pod
8460:
8461: =item * &load_tmp_file($r)
8462:
8463: Load uploaded file from tmp, $r should be the HTTP Request object,
8464: needs $env{'form.datatoken'},
8465: sets $env{'form.upfile'} to the contents of the file
8466:
8467: =cut
8468:
8469: sub load_tmp_file {
8470: my $r=shift;
8471: my @studentdata=();
8472: {
8473: my $studentfile = $r->dir_config('lonDaemons').
8474: '/tmp/'.$env{'form.datatoken'}.'.tmp';
8475: if ( open(my $fh,"<$studentfile") ) {
8476: @studentdata=<$fh>;
8477: close($fh);
8478: }
8479: }
8480: $env{'form.upfile'}=join('',@studentdata);
8481: }
8482:
8483: =pod
8484:
8485: =item * &upfile_record_sep()
8486:
8487: Separate uploaded file into records
8488: returns array of records,
8489: needs $env{'form.upfile'} and $env{'form.upfiletype'}
8490:
8491: =cut
8492:
8493: sub upfile_record_sep {
8494: if ($env{'form.upfiletype'} eq 'xml') {
8495: } else {
8496: my @records;
8497: foreach my $line (split(/\n/,$env{'form.upfile'})) {
8498: if ($line=~/^\s*$/) { next; }
8499: push(@records,$line);
8500: }
8501: return @records;
8502: }
8503: }
8504:
8505: =pod
8506:
8507: =item * &record_sep($record)
8508:
8509: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
8510:
8511: =cut
8512:
8513: sub takeleft {
8514: my $index=shift;
8515: return substr('0000'.$index,-4,4);
8516: }
8517:
8518: sub record_sep {
8519: my $record=shift;
8520: my %components=();
8521: if ($env{'form.upfiletype'} eq 'xml') {
8522: } elsif ($env{'form.upfiletype'} eq 'space') {
8523: my $i=0;
8524: foreach my $field (split(/\s+/,$record)) {
8525: $field=~s/^(\"|\')//;
8526: $field=~s/(\"|\')$//;
8527: $components{&takeleft($i)}=$field;
8528: $i++;
8529: }
8530: } elsif ($env{'form.upfiletype'} eq 'tab') {
8531: my $i=0;
8532: foreach my $field (split(/\t/,$record)) {
8533: $field=~s/^(\"|\')//;
8534: $field=~s/(\"|\')$//;
8535: $components{&takeleft($i)}=$field;
8536: $i++;
8537: }
8538: } else {
8539: my $separator=',';
8540: if ($env{'form.upfiletype'} eq 'semisv') {
8541: $separator=';';
8542: }
8543: my $i=0;
8544: # the character we are looking for to indicate the end of a quote or a record
8545: my $looking_for=$separator;
8546: # do not add the characters to the fields
8547: my $ignore=0;
8548: # we just encountered a separator (or the beginning of the record)
8549: my $just_found_separator=1;
8550: # store the field we are working on here
8551: my $field='';
8552: # work our way through all characters in record
8553: foreach my $character ($record=~/(.)/g) {
8554: if ($character eq $looking_for) {
8555: if ($character ne $separator) {
8556: # Found the end of a quote, again looking for separator
8557: $looking_for=$separator;
8558: $ignore=1;
8559: } else {
8560: # Found a separator, store away what we got
8561: $components{&takeleft($i)}=$field;
8562: $i++;
8563: $just_found_separator=1;
8564: $ignore=0;
8565: $field='';
8566: }
8567: next;
8568: }
8569: # single or double quotation marks after a separator indicate beginning of a quote
8570: # we are now looking for the end of the quote and need to ignore separators
8571: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
8572: $looking_for=$character;
8573: next;
8574: }
8575: # ignore would be true after we reached the end of a quote
8576: if ($ignore) { next; }
8577: if (($just_found_separator) && ($character=~/\s/)) { next; }
8578: $field.=$character;
8579: $just_found_separator=0;
8580: }
8581: # catch the very last entry, since we never encountered the separator
8582: $components{&takeleft($i)}=$field;
8583: }
8584: return %components;
8585: }
8586:
8587: ######################################################
8588: ######################################################
8589:
8590: =pod
8591:
8592: =item * &upfile_select_html()
8593:
8594: Return HTML code to select a file from the users machine and specify
8595: the file type.
8596:
8597: =cut
8598:
8599: ######################################################
8600: ######################################################
8601: sub upfile_select_html {
8602: my %Types = (
8603: csv => &mt('CSV (comma separated values, spreadsheet)'),
8604: semisv => &mt('Semicolon separated values'),
8605: space => &mt('Space separated'),
8606: tab => &mt('Tabulator separated'),
8607: # xml => &mt('HTML/XML'),
8608: );
8609: my $Str = '<input type="file" name="upfile" size="50" />'.
8610: '<br />'.&mt('Type').': <select name="upfiletype">';
8611: foreach my $type (sort(keys(%Types))) {
8612: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
8613: }
8614: $Str .= "</select>\n";
8615: return $Str;
8616: }
8617:
8618: sub get_samples {
8619: my ($records,$toget) = @_;
8620: my @samples=({});
8621: my $got=0;
8622: foreach my $rec (@$records) {
8623: my %temp = &record_sep($rec);
8624: if (! grep(/\S/, values(%temp))) { next; }
8625: if (%temp) {
8626: $samples[$got]=\%temp;
8627: $got++;
8628: if ($got == $toget) { last; }
8629: }
8630: }
8631: return \@samples;
8632: }
8633:
8634: ######################################################
8635: ######################################################
8636:
8637: =pod
8638:
8639: =item * &csv_print_samples($r,$records)
8640:
8641: Prints a table of sample values from each column uploaded $r is an
8642: Apache Request ref, $records is an arrayref from
8643: &Apache::loncommon::upfile_record_sep
8644:
8645: =cut
8646:
8647: ######################################################
8648: ######################################################
8649: sub csv_print_samples {
8650: my ($r,$records) = @_;
8651: my $samples = &get_samples($records,5);
8652:
8653: $r->print(&mt('Samples').'<br />'.&start_data_table().
8654: &start_data_table_header_row());
8655: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8656: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
8657: $r->print(&end_data_table_header_row());
8658: foreach my $hash (@$samples) {
8659: $r->print(&start_data_table_row());
8660: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8661: $r->print('<td>');
8662: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
8663: $r->print('</td>');
8664: }
8665: $r->print(&end_data_table_row());
8666: }
8667: $r->print(&end_data_table().'<br />'."\n");
8668: }
8669:
8670: ######################################################
8671: ######################################################
8672:
8673: =pod
8674:
8675: =item * &csv_print_select_table($r,$records,$d)
8676:
8677: Prints a table to create associations between values and table columns.
8678:
8679: $r is an Apache Request ref,
8680: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
8681: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
8682:
8683: =cut
8684:
8685: ######################################################
8686: ######################################################
8687: sub csv_print_select_table {
8688: my ($r,$records,$d) = @_;
8689: my $i=0;
8690: my $samples = &get_samples($records,1);
8691: $r->print(&mt('Associate columns with student attributes.')."\n".
8692: &start_data_table().&start_data_table_header_row().
8693: '<th>'.&mt('Attribute').'</th>'.
8694: '<th>'.&mt('Column').'</th>'.
8695: &end_data_table_header_row()."\n");
8696: foreach my $array_ref (@$d) {
8697: my ($value,$display,$defaultcol)=@{ $array_ref };
8698: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
8699:
8700: $r->print('<td><select name="f'.$i.'"'.
8701: ' onchange="javascript:flip(this.form,'.$i.');">');
8702: $r->print('<option value="none"></option>');
8703: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8704: $r->print('<option value="'.$sample.'"'.
8705: ($sample eq $defaultcol ? ' selected="selected" ' : '').
8706: '>'.&mt('Column [_1]',($sample+1)).'</option>');
8707: }
8708: $r->print('</select></td>'.&end_data_table_row()."\n");
8709: $i++;
8710: }
8711: $r->print(&end_data_table());
8712: $i--;
8713: return $i;
8714: }
8715:
8716: ######################################################
8717: ######################################################
8718:
8719: =pod
8720:
8721: =item * &csv_samples_select_table($r,$records,$d)
8722:
8723: Prints a table of sample values from the upload and can make associate samples to internal names.
8724:
8725: $r is an Apache Request ref,
8726: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
8727: $d is an array of 2 element arrays (internal name, displayed name)
8728:
8729: =cut
8730:
8731: ######################################################
8732: ######################################################
8733: sub csv_samples_select_table {
8734: my ($r,$records,$d) = @_;
8735: my $i=0;
8736: #
8737: my $max_samples = 5;
8738: my $samples = &get_samples($records,$max_samples);
8739: $r->print(&start_data_table().
8740: &start_data_table_header_row().'<th>'.
8741: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
8742: &end_data_table_header_row());
8743:
8744: foreach my $key (sort(keys(%{ $samples->[0] }))) {
8745: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
8746: ' onchange="javascript:flip(this.form,'.$i.');">');
8747: foreach my $option (@$d) {
8748: my ($value,$display,$defaultcol)=@{ $option };
8749: $r->print('<option value="'.$value.'"'.
8750: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
8751: $display.'</option>');
8752: }
8753: $r->print('</select></td><td>');
8754: foreach my $line (0..($max_samples-1)) {
8755: if (defined($samples->[$line]{$key})) {
8756: $r->print($samples->[$line]{$key}."<br />\n");
8757: }
8758: }
8759: $r->print('</td>'.&end_data_table_row());
8760: $i++;
8761: }
8762: $r->print(&end_data_table());
8763: $i--;
8764: return($i);
8765: }
8766:
8767: ######################################################
8768: ######################################################
8769:
8770: =pod
8771:
8772: =item * &clean_excel_name($name)
8773:
8774: Returns a replacement for $name which does not contain any illegal characters.
8775:
8776: =cut
8777:
8778: ######################################################
8779: ######################################################
8780: sub clean_excel_name {
8781: my ($name) = @_;
8782: $name =~ s/[:\*\?\/\\]//g;
8783: if (length($name) > 31) {
8784: $name = substr($name,0,31);
8785: }
8786: return $name;
8787: }
8788:
8789: =pod
8790:
8791: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
8792:
8793: Returns either 1 or undef
8794:
8795: 1 if the part is to be hidden, undef if it is to be shown
8796:
8797: Arguments are:
8798:
8799: $id the id of the part to be checked
8800: $symb, optional the symb of the resource to check
8801: $udom, optional the domain of the user to check for
8802: $uname, optional the username of the user to check for
8803:
8804: =cut
8805:
8806: sub check_if_partid_hidden {
8807: my ($id,$symb,$udom,$uname) = @_;
8808: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
8809: $symb,$udom,$uname);
8810: my $truth=1;
8811: #if the string starts with !, then the list is the list to show not hide
8812: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
8813: my @hiddenlist=split(/,/,$hiddenparts);
8814: foreach my $checkid (@hiddenlist) {
8815: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
8816: }
8817: return !$truth;
8818: }
8819:
8820:
8821: ############################################################
8822: ############################################################
8823:
8824: =pod
8825:
8826: =back
8827:
8828: =head1 cgi-bin script and graphing routines
8829:
8830: =over 4
8831:
8832: =item * &get_cgi_id()
8833:
8834: Inputs: none
8835:
8836: Returns an id which can be used to pass environment variables
8837: to various cgi-bin scripts. These environment variables will
8838: be removed from the users environment after a given time by
8839: the routine &Apache::lonnet::transfer_profile_to_env.
8840:
8841: =cut
8842:
8843: ############################################################
8844: ############################################################
8845: my $uniq=0;
8846: sub get_cgi_id {
8847: $uniq=($uniq+1)%100000;
8848: return (time.'_'.$$.'_'.$uniq);
8849: }
8850:
8851: ############################################################
8852: ############################################################
8853:
8854: =pod
8855:
8856: =item * &DrawBarGraph()
8857:
8858: Facilitates the plotting of data in a (stacked) bar graph.
8859: Puts plot definition data into the users environment in order for
8860: graph.png to plot it. Returns an <img> tag for the plot.
8861: The bars on the plot are labeled '1','2',...,'n'.
8862:
8863: Inputs:
8864:
8865: =over 4
8866:
8867: =item $Title: string, the title of the plot
8868:
8869: =item $xlabel: string, text describing the X-axis of the plot
8870:
8871: =item $ylabel: string, text describing the Y-axis of the plot
8872:
8873: =item $Max: scalar, the maximum Y value to use in the plot
8874: If $Max is < any data point, the graph will not be rendered.
8875:
8876: =item $colors: array ref holding the colors to be used for the data sets when
8877: they are plotted. If undefined, default values will be used.
8878:
8879: =item $labels: array ref holding the labels to use on the x-axis for the bars.
8880:
8881: =item @Values: An array of array references. Each array reference holds data
8882: to be plotted in a stacked bar chart.
8883:
8884: =item If the final element of @Values is a hash reference the key/value
8885: pairs will be added to the graph definition.
8886:
8887: =back
8888:
8889: Returns:
8890:
8891: An <img> tag which references graph.png and the appropriate identifying
8892: information for the plot.
8893:
8894: =cut
8895:
8896: ############################################################
8897: ############################################################
8898: sub DrawBarGraph {
8899: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
8900: #
8901: if (! defined($colors)) {
8902: $colors = ['#33ff00',
8903: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
8904: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
8905: ];
8906: }
8907: my $extra_settings = {};
8908: if (ref($Values[-1]) eq 'HASH') {
8909: $extra_settings = pop(@Values);
8910: }
8911: #
8912: my $identifier = &get_cgi_id();
8913: my $id = 'cgi.'.$identifier;
8914: if (! @Values || ref($Values[0]) ne 'ARRAY') {
8915: return '';
8916: }
8917: #
8918: my @Labels;
8919: if (defined($labels)) {
8920: @Labels = @$labels;
8921: } else {
8922: for (my $i=0;$i<@{$Values[0]};$i++) {
8923: push (@Labels,$i+1);
8924: }
8925: }
8926: #
8927: my $NumBars = scalar(@{$Values[0]});
8928: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
8929: my %ValuesHash;
8930: my $NumSets=1;
8931: foreach my $array (@Values) {
8932: next if (! ref($array));
8933: $ValuesHash{$id.'.data.'.$NumSets++} =
8934: join(',',@$array);
8935: }
8936: #
8937: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
8938: if ($NumBars < 3) {
8939: $width = 120+$NumBars*32;
8940: $xskip = 1;
8941: $bar_width = 30;
8942: } elsif ($NumBars < 5) {
8943: $width = 120+$NumBars*20;
8944: $xskip = 1;
8945: $bar_width = 20;
8946: } elsif ($NumBars < 10) {
8947: $width = 120+$NumBars*15;
8948: $xskip = 1;
8949: $bar_width = 15;
8950: } elsif ($NumBars <= 25) {
8951: $width = 120+$NumBars*11;
8952: $xskip = 5;
8953: $bar_width = 8;
8954: } elsif ($NumBars <= 50) {
8955: $width = 120+$NumBars*8;
8956: $xskip = 5;
8957: $bar_width = 4;
8958: } else {
8959: $width = 120+$NumBars*8;
8960: $xskip = 5;
8961: $bar_width = 4;
8962: }
8963: #
8964: $Max = 1 if ($Max < 1);
8965: if ( int($Max) < $Max ) {
8966: $Max++;
8967: $Max = int($Max);
8968: }
8969: $Title = '' if (! defined($Title));
8970: $xlabel = '' if (! defined($xlabel));
8971: $ylabel = '' if (! defined($ylabel));
8972: $ValuesHash{$id.'.title'} = &escape($Title);
8973: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
8974: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
8975: $ValuesHash{$id.'.y_max_value'} = $Max;
8976: $ValuesHash{$id.'.NumBars'} = $NumBars;
8977: $ValuesHash{$id.'.NumSets'} = $NumSets;
8978: $ValuesHash{$id.'.PlotType'} = 'bar';
8979: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8980: $ValuesHash{$id.'.height'} = $height;
8981: $ValuesHash{$id.'.width'} = $width;
8982: $ValuesHash{$id.'.xskip'} = $xskip;
8983: $ValuesHash{$id.'.bar_width'} = $bar_width;
8984: $ValuesHash{$id.'.labels'} = join(',',@Labels);
8985: #
8986: # Deal with other parameters
8987: while (my ($key,$value) = each(%$extra_settings)) {
8988: $ValuesHash{$id.'.'.$key} = $value;
8989: }
8990: #
8991: &Apache::lonnet::appenv(\%ValuesHash);
8992: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8993: }
8994:
8995: ############################################################
8996: ############################################################
8997:
8998: =pod
8999:
9000: =item * &DrawXYGraph()
9001:
9002: Facilitates the plotting of data in an XY graph.
9003: Puts plot definition data into the users environment in order for
9004: graph.png to plot it. Returns an <img> tag for the plot.
9005:
9006: Inputs:
9007:
9008: =over 4
9009:
9010: =item $Title: string, the title of the plot
9011:
9012: =item $xlabel: string, text describing the X-axis of the plot
9013:
9014: =item $ylabel: string, text describing the Y-axis of the plot
9015:
9016: =item $Max: scalar, the maximum Y value to use in the plot
9017: If $Max is < any data point, the graph will not be rendered.
9018:
9019: =item $colors: Array ref containing the hex color codes for the data to be
9020: plotted in. If undefined, default values will be used.
9021:
9022: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
9023:
9024: =item $Ydata: Array ref containing Array refs.
9025: Each of the contained arrays will be plotted as a separate curve.
9026:
9027: =item %Values: hash indicating or overriding any default values which are
9028: passed to graph.png.
9029: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
9030:
9031: =back
9032:
9033: Returns:
9034:
9035: An <img> tag which references graph.png and the appropriate identifying
9036: information for the plot.
9037:
9038: =cut
9039:
9040: ############################################################
9041: ############################################################
9042: sub DrawXYGraph {
9043: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
9044: #
9045: # Create the identifier for the graph
9046: my $identifier = &get_cgi_id();
9047: my $id = 'cgi.'.$identifier;
9048: #
9049: $Title = '' if (! defined($Title));
9050: $xlabel = '' if (! defined($xlabel));
9051: $ylabel = '' if (! defined($ylabel));
9052: my %ValuesHash =
9053: (
9054: $id.'.title' => &escape($Title),
9055: $id.'.xlabel' => &escape($xlabel),
9056: $id.'.ylabel' => &escape($ylabel),
9057: $id.'.y_max_value'=> $Max,
9058: $id.'.labels' => join(',',@$Xlabels),
9059: $id.'.PlotType' => 'XY',
9060: );
9061: #
9062: if (defined($colors) && ref($colors) eq 'ARRAY') {
9063: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9064: }
9065: #
9066: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
9067: return '';
9068: }
9069: my $NumSets=1;
9070: foreach my $array (@{$Ydata}){
9071: next if (! ref($array));
9072: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
9073: }
9074: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
9075: #
9076: # Deal with other parameters
9077: while (my ($key,$value) = each(%Values)) {
9078: $ValuesHash{$id.'.'.$key} = $value;
9079: }
9080: #
9081: &Apache::lonnet::appenv(\%ValuesHash);
9082: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
9083: }
9084:
9085: ############################################################
9086: ############################################################
9087:
9088: =pod
9089:
9090: =item * &DrawXYYGraph()
9091:
9092: Facilitates the plotting of data in an XY graph with two Y axes.
9093: Puts plot definition data into the users environment in order for
9094: graph.png to plot it. Returns an <img> tag for the plot.
9095:
9096: Inputs:
9097:
9098: =over 4
9099:
9100: =item $Title: string, the title of the plot
9101:
9102: =item $xlabel: string, text describing the X-axis of the plot
9103:
9104: =item $ylabel: string, text describing the Y-axis of the plot
9105:
9106: =item $colors: Array ref containing the hex color codes for the data to be
9107: plotted in. If undefined, default values will be used.
9108:
9109: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
9110:
9111: =item $Ydata1: The first data set
9112:
9113: =item $Min1: The minimum value of the left Y-axis
9114:
9115: =item $Max1: The maximum value of the left Y-axis
9116:
9117: =item $Ydata2: The second data set
9118:
9119: =item $Min2: The minimum value of the right Y-axis
9120:
9121: =item $Max2: The maximum value of the left Y-axis
9122:
9123: =item %Values: hash indicating or overriding any default values which are
9124: passed to graph.png.
9125: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
9126:
9127: =back
9128:
9129: Returns:
9130:
9131: An <img> tag which references graph.png and the appropriate identifying
9132: information for the plot.
9133:
9134: =cut
9135:
9136: ############################################################
9137: ############################################################
9138: sub DrawXYYGraph {
9139: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
9140: $Ydata2,$Min2,$Max2,%Values)=@_;
9141: #
9142: # Create the identifier for the graph
9143: my $identifier = &get_cgi_id();
9144: my $id = 'cgi.'.$identifier;
9145: #
9146: $Title = '' if (! defined($Title));
9147: $xlabel = '' if (! defined($xlabel));
9148: $ylabel = '' if (! defined($ylabel));
9149: my %ValuesHash =
9150: (
9151: $id.'.title' => &escape($Title),
9152: $id.'.xlabel' => &escape($xlabel),
9153: $id.'.ylabel' => &escape($ylabel),
9154: $id.'.labels' => join(',',@$Xlabels),
9155: $id.'.PlotType' => 'XY',
9156: $id.'.NumSets' => 2,
9157: $id.'.two_axes' => 1,
9158: $id.'.y1_max_value' => $Max1,
9159: $id.'.y1_min_value' => $Min1,
9160: $id.'.y2_max_value' => $Max2,
9161: $id.'.y2_min_value' => $Min2,
9162: );
9163: #
9164: if (defined($colors) && ref($colors) eq 'ARRAY') {
9165: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9166: }
9167: #
9168: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
9169: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
9170: return '';
9171: }
9172: my $NumSets=1;
9173: foreach my $array ($Ydata1,$Ydata2){
9174: next if (! ref($array));
9175: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
9176: }
9177: #
9178: # Deal with other parameters
9179: while (my ($key,$value) = each(%Values)) {
9180: $ValuesHash{$id.'.'.$key} = $value;
9181: }
9182: #
9183: &Apache::lonnet::appenv(\%ValuesHash);
9184: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
9185: }
9186:
9187: ############################################################
9188: ############################################################
9189:
9190: =pod
9191:
9192: =back
9193:
9194: =head1 Statistics helper routines?
9195:
9196: Bad place for them but what the hell.
9197:
9198: =over 4
9199:
9200: =item * &chartlink()
9201:
9202: Returns a link to the chart for a specific student.
9203:
9204: Inputs:
9205:
9206: =over 4
9207:
9208: =item $linktext: The text of the link
9209:
9210: =item $sname: The students username
9211:
9212: =item $sdomain: The students domain
9213:
9214: =back
9215:
9216: =back
9217:
9218: =cut
9219:
9220: ############################################################
9221: ############################################################
9222: sub chartlink {
9223: my ($linktext, $sname, $sdomain) = @_;
9224: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
9225: '&SelectedStudent='.&escape($sname.':'.$sdomain).
9226: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
9227: '">'.$linktext.'</a>';
9228: }
9229:
9230: #######################################################
9231: #######################################################
9232:
9233: =pod
9234:
9235: =head1 Course Environment Routines
9236:
9237: =over 4
9238:
9239: =item * &restore_course_settings()
9240:
9241: =item * &store_course_settings()
9242:
9243: Restores/Store indicated form parameters from the course environment.
9244: Will not overwrite existing values of the form parameters.
9245:
9246: Inputs:
9247: a scalar describing the data (e.g. 'chart', 'problem_analysis')
9248:
9249: a hash ref describing the data to be stored. For example:
9250:
9251: %Save_Parameters = ('Status' => 'scalar',
9252: 'chartoutputmode' => 'scalar',
9253: 'chartoutputdata' => 'scalar',
9254: 'Section' => 'array',
9255: 'Group' => 'array',
9256: 'StudentData' => 'array',
9257: 'Maps' => 'array');
9258:
9259: Returns: both routines return nothing
9260:
9261: =back
9262:
9263: =cut
9264:
9265: #######################################################
9266: #######################################################
9267: sub store_course_settings {
9268: return &store_settings($env{'request.course.id'},@_);
9269: }
9270:
9271: sub store_settings {
9272: # save to the environment
9273: # appenv the same items, just to be safe
9274: my $udom = $env{'user.domain'};
9275: my $uname = $env{'user.name'};
9276: my ($context,$prefix,$Settings) = @_;
9277: my %SaveHash;
9278: my %AppHash;
9279: while (my ($setting,$type) = each(%$Settings)) {
9280: my $basename = join('.','internal',$context,$prefix,$setting);
9281: my $envname = 'environment.'.$basename;
9282: if (exists($env{'form.'.$setting})) {
9283: # Save this value away
9284: if ($type eq 'scalar' &&
9285: (! exists($env{$envname}) ||
9286: $env{$envname} ne $env{'form.'.$setting})) {
9287: $SaveHash{$basename} = $env{'form.'.$setting};
9288: $AppHash{$envname} = $env{'form.'.$setting};
9289: } elsif ($type eq 'array') {
9290: my $stored_form;
9291: if (ref($env{'form.'.$setting})) {
9292: $stored_form = join(',',
9293: map {
9294: &escape($_);
9295: } sort(@{$env{'form.'.$setting}}));
9296: } else {
9297: $stored_form =
9298: &escape($env{'form.'.$setting});
9299: }
9300: # Determine if the array contents are the same.
9301: if ($stored_form ne $env{$envname}) {
9302: $SaveHash{$basename} = $stored_form;
9303: $AppHash{$envname} = $stored_form;
9304: }
9305: }
9306: }
9307: }
9308: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
9309: $udom,$uname);
9310: if ($put_result !~ /^(ok|delayed)/) {
9311: &Apache::lonnet::logthis('unable to save form parameters, '.
9312: 'got error:'.$put_result);
9313: }
9314: # Make sure these settings stick around in this session, too
9315: &Apache::lonnet::appenv(\%AppHash);
9316: return;
9317: }
9318:
9319: sub restore_course_settings {
9320: return &restore_settings($env{'request.course.id'},@_);
9321: }
9322:
9323: sub restore_settings {
9324: my ($context,$prefix,$Settings) = @_;
9325: while (my ($setting,$type) = each(%$Settings)) {
9326: next if (exists($env{'form.'.$setting}));
9327: my $envname = 'environment.internal.'.$context.'.'.$prefix.
9328: '.'.$setting;
9329: if (exists($env{$envname})) {
9330: if ($type eq 'scalar') {
9331: $env{'form.'.$setting} = $env{$envname};
9332: } elsif ($type eq 'array') {
9333: $env{'form.'.$setting} = [
9334: map {
9335: &unescape($_);
9336: } split(',',$env{$envname})
9337: ];
9338: }
9339: }
9340: }
9341: }
9342:
9343: #######################################################
9344: #######################################################
9345:
9346: =pod
9347:
9348: =head1 Domain E-mail Routines
9349:
9350: =over 4
9351:
9352: =item * &build_recipient_list()
9353:
9354: Build recipient lists for five types of e-mail:
9355: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
9356: (d) Help requests, (e) Course requests needing approval, generated by
9357: lonerrorhandler.pm, CHECKRPMS, loncron, lonsupportreq.pm and
9358: loncoursequeueadmin.pm respectively.
9359:
9360: Inputs:
9361: defmail (scalar - email address of default recipient),
9362: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
9363: defdom (domain for which to retrieve configuration settings),
9364: origmail (scalar - email address of recipient from loncapa.conf,
9365: i.e., predates configuration by DC via domainprefs.pm
9366:
9367: Returns: comma separated list of addresses to which to send e-mail.
9368:
9369: =back
9370:
9371: =cut
9372:
9373: ############################################################
9374: ############################################################
9375: sub build_recipient_list {
9376: my ($defmail,$mailing,$defdom,$origmail) = @_;
9377: my @recipients;
9378: my $otheremails;
9379: my %domconfig =
9380: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
9381: if (ref($domconfig{'contacts'}) eq 'HASH') {
9382: if (exists($domconfig{'contacts'}{$mailing})) {
9383: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
9384: my @contacts = ('adminemail','supportemail');
9385: foreach my $item (@contacts) {
9386: if ($domconfig{'contacts'}{$mailing}{$item}) {
9387: my $addr = $domconfig{'contacts'}{$item};
9388: if (!grep(/^\Q$addr\E$/,@recipients)) {
9389: push(@recipients,$addr);
9390: }
9391: }
9392: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
9393: }
9394: }
9395: } elsif ($origmail ne '') {
9396: push(@recipients,$origmail);
9397: }
9398: } elsif ($origmail ne '') {
9399: push(@recipients,$origmail);
9400: }
9401: if (defined($defmail)) {
9402: if ($defmail ne '') {
9403: push(@recipients,$defmail);
9404: }
9405: }
9406: if ($otheremails) {
9407: my @others;
9408: if ($otheremails =~ /,/) {
9409: @others = split(/,/,$otheremails);
9410: } else {
9411: push(@others,$otheremails);
9412: }
9413: foreach my $addr (@others) {
9414: if (!grep(/^\Q$addr\E$/,@recipients)) {
9415: push(@recipients,$addr);
9416: }
9417: }
9418: }
9419: my $recipientlist = join(',',@recipients);
9420: return $recipientlist;
9421: }
9422:
9423: ############################################################
9424: ############################################################
9425:
9426: =pod
9427:
9428: =head1 Course Catalog Routines
9429:
9430: =over 4
9431:
9432: =item * &gather_categories()
9433:
9434: Converts category definitions - keys of categories hash stored in
9435: coursecategories in configuration.db on the primary library server in a
9436: domain - to an array. Also generates javascript and idx hash used to
9437: generate Domain Coordinator interface for editing Course Categories.
9438:
9439: Inputs:
9440:
9441: categories (reference to hash of category definitions).
9442:
9443: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9444: categories and subcategories).
9445:
9446: idx (reference to hash of counters used in Domain Coordinator interface for
9447: editing Course Categories).
9448:
9449: jsarray (reference to array of categories used to create Javascript arrays for
9450: Domain Coordinator interface for editing Course Categories).
9451:
9452: Returns: nothing
9453:
9454: Side effects: populates cats, idx and jsarray.
9455:
9456: =cut
9457:
9458: sub gather_categories {
9459: my ($categories,$cats,$idx,$jsarray) = @_;
9460: my %counters;
9461: my $num = 0;
9462: foreach my $item (keys(%{$categories})) {
9463: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
9464: if ($container eq '' && $depth == 0) {
9465: $cats->[$depth][$categories->{$item}] = $cat;
9466: } else {
9467: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
9468: }
9469: my ($escitem,$tail) = split(/:/,$item,2);
9470: if ($counters{$tail} eq '') {
9471: $counters{$tail} = $num;
9472: $num ++;
9473: }
9474: if (ref($idx) eq 'HASH') {
9475: $idx->{$item} = $counters{$tail};
9476: }
9477: if (ref($jsarray) eq 'ARRAY') {
9478: push(@{$jsarray->[$counters{$tail}]},$item);
9479: }
9480: }
9481: return;
9482: }
9483:
9484: =pod
9485:
9486: =item * &extract_categories()
9487:
9488: Used to generate breadcrumb trails for course categories.
9489:
9490: Inputs:
9491:
9492: categories (reference to hash of category definitions).
9493:
9494: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9495: categories and subcategories).
9496:
9497: trails (reference to array of breacrumb trails for each category).
9498:
9499: allitems (reference to hash - key is category key
9500: (format: escaped(name):escaped(parent category):depth in hierarchy).
9501:
9502: idx (reference to hash of counters used in Domain Coordinator interface for
9503: editing Course Categories).
9504:
9505: jsarray (reference to array of categories used to create Javascript arrays for
9506: Domain Coordinator interface for editing Course Categories).
9507:
9508: subcats (reference to hash of arrays containing all subcategories within each
9509: category, -recursive)
9510:
9511: Returns: nothing
9512:
9513: Side effects: populates trails and allitems hash references.
9514:
9515: =cut
9516:
9517: sub extract_categories {
9518: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
9519: if (ref($categories) eq 'HASH') {
9520: &gather_categories($categories,$cats,$idx,$jsarray);
9521: if (ref($cats->[0]) eq 'ARRAY') {
9522: for (my $i=0; $i<@{$cats->[0]}; $i++) {
9523: my $name = $cats->[0][$i];
9524: my $item = &escape($name).'::0';
9525: my $trailstr;
9526: if ($name eq 'instcode') {
9527: $trailstr = &mt('Official courses (with institutional codes)');
9528: } else {
9529: $trailstr = $name;
9530: }
9531: if ($allitems->{$item} eq '') {
9532: push(@{$trails},$trailstr);
9533: $allitems->{$item} = scalar(@{$trails})-1;
9534: }
9535: my @parents = ($name);
9536: if (ref($cats->[1]{$name}) eq 'ARRAY') {
9537: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
9538: my $category = $cats->[1]{$name}[$j];
9539: if (ref($subcats) eq 'HASH') {
9540: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
9541: }
9542: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
9543: }
9544: } else {
9545: if (ref($subcats) eq 'HASH') {
9546: $subcats->{$item} = [];
9547: }
9548: }
9549: }
9550: }
9551: }
9552: return;
9553: }
9554:
9555: =pod
9556:
9557: =item *&recurse_categories()
9558:
9559: Recursively used to generate breadcrumb trails for course categories.
9560:
9561: Inputs:
9562:
9563: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9564: categories and subcategories).
9565:
9566: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
9567:
9568: category (current course category, for which breadcrumb trail is being generated).
9569:
9570: trails (reference to array of breadcrumb trails for each category).
9571:
9572: allitems (reference to hash - key is category key
9573: (format: escaped(name):escaped(parent category):depth in hierarchy).
9574:
9575: parents (array containing containers directories for current category,
9576: back to top level).
9577:
9578: Returns: nothing
9579:
9580: Side effects: populates trails and allitems hash references
9581:
9582: =cut
9583:
9584: sub recurse_categories {
9585: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
9586: my $shallower = $depth - 1;
9587: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
9588: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
9589: my $name = $cats->[$depth]{$category}[$k];
9590: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9591: my $trailstr = join(' -> ',(@{$parents},$category));
9592: if ($allitems->{$item} eq '') {
9593: push(@{$trails},$trailstr);
9594: $allitems->{$item} = scalar(@{$trails})-1;
9595: }
9596: my $deeper = $depth+1;
9597: push(@{$parents},$category);
9598: if (ref($subcats) eq 'HASH') {
9599: my $subcat = &escape($name).':'.$category.':'.$depth;
9600: for (my $j=@{$parents}; $j>=0; $j--) {
9601: my $higher;
9602: if ($j > 0) {
9603: $higher = &escape($parents->[$j]).':'.
9604: &escape($parents->[$j-1]).':'.$j;
9605: } else {
9606: $higher = &escape($parents->[$j]).'::'.$j;
9607: }
9608: push(@{$subcats->{$higher}},$subcat);
9609: }
9610: }
9611: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
9612: $subcats);
9613: pop(@{$parents});
9614: }
9615: } else {
9616: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9617: my $trailstr = join(' -> ',(@{$parents},$category));
9618: if ($allitems->{$item} eq '') {
9619: push(@{$trails},$trailstr);
9620: $allitems->{$item} = scalar(@{$trails})-1;
9621: }
9622: }
9623: return;
9624: }
9625:
9626: =pod
9627:
9628: =item *&assign_categories_table()
9629:
9630: Create a datatable for display of hierarchical categories in a domain,
9631: with checkboxes to allow a course to be categorized.
9632:
9633: Inputs:
9634:
9635: cathash - reference to hash of categories defined for the domain (from
9636: configuration.db)
9637:
9638: currcat - scalar with an & separated list of categories assigned to a course.
9639:
9640: Returns: $output (markup to be displayed)
9641:
9642: =cut
9643:
9644: sub assign_categories_table {
9645: my ($cathash,$currcat) = @_;
9646: my $output;
9647: if (ref($cathash) eq 'HASH') {
9648: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
9649: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
9650: $maxdepth = scalar(@cats);
9651: if (@cats > 0) {
9652: my $itemcount = 0;
9653: if (ref($cats[0]) eq 'ARRAY') {
9654: $output = &Apache::loncommon::start_data_table();
9655: my @currcategories;
9656: if ($currcat ne '') {
9657: @currcategories = split('&',$currcat);
9658: }
9659: for (my $i=0; $i<@{$cats[0]}; $i++) {
9660: my $parent = $cats[0][$i];
9661: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9662: next if ($parent eq 'instcode');
9663: my $item = &escape($parent).'::0';
9664: my $checked = '';
9665: if (@currcategories > 0) {
9666: if (grep(/^\Q$item\E$/,@currcategories)) {
9667: $checked = ' checked="checked"';
9668: }
9669: }
9670: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
9671: '<input type="checkbox" name="usecategory" value="'.
9672: $item.'"'.$checked.' />'.$parent.'</span>'.
9673: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
9674: my $depth = 1;
9675: push(@path,$parent);
9676: $output .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
9677: pop(@path);
9678: $output .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
9679: $itemcount ++;
9680: }
9681: $output .= &Apache::loncommon::end_data_table();
9682: }
9683: }
9684: }
9685: return $output;
9686: }
9687:
9688: =pod
9689:
9690: =item *&assign_category_rows()
9691:
9692: Create a datatable row for display of nested categories in a domain,
9693: with checkboxes to allow a course to be categorized,called recursively.
9694:
9695: Inputs:
9696:
9697: itemcount - track row number for alternating colors
9698:
9699: cats - reference to array of arrays/hashes which encapsulates hierarchy of
9700: categories and subcategories.
9701:
9702: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
9703:
9704: parent - parent of current category item
9705:
9706: path - Array containing all categories back up through the hierarchy from the
9707: current category to the top level.
9708:
9709: currcategories - reference to array of current categories assigned to the course
9710:
9711: Returns: $output (markup to be displayed).
9712:
9713: =cut
9714:
9715: sub assign_category_rows {
9716: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
9717: my ($text,$name,$item,$chgstr);
9718: if (ref($cats) eq 'ARRAY') {
9719: my $maxdepth = scalar(@{$cats});
9720: if (ref($cats->[$depth]) eq 'HASH') {
9721: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
9722: my $numchildren = @{$cats->[$depth]{$parent}};
9723: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9724: $text .= '<td><table class="LC_datatable">';
9725: for (my $j=0; $j<$numchildren; $j++) {
9726: $name = $cats->[$depth]{$parent}[$j];
9727: $item = &escape($name).':'.&escape($parent).':'.$depth;
9728: my $deeper = $depth+1;
9729: my $checked = '';
9730: if (ref($currcategories) eq 'ARRAY') {
9731: if (@{$currcategories} > 0) {
9732: if (grep(/^\Q$item\E$/,@{$currcategories})) {
9733: $checked = ' checked="checked"';
9734: }
9735: }
9736: }
9737: $text .= '<tr><td><span class="LC_nobreak"><label>'.
9738: '<input type="checkbox" name="usecategory" value="'.
9739: $item.'"'.$checked.' />'.$name.'</label></span>'.
9740: '<input type="hidden" name="catname" value="'.$name.'" />'.
9741: '</td><td>';
9742: if (ref($path) eq 'ARRAY') {
9743: push(@{$path},$name);
9744: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
9745: pop(@{$path});
9746: }
9747: $text .= '</td></tr>';
9748: }
9749: $text .= '</table></td>';
9750: }
9751: }
9752: }
9753: return $text;
9754: }
9755:
9756: ############################################################
9757: ############################################################
9758:
9759:
9760: sub commit_customrole {
9761: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
9762: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
9763: ($start?', '.&mt('starting').' '.localtime($start):'').
9764: ($end?', ending '.localtime($end):'').': <b>'.
9765: &Apache::lonnet::assigncustomrole(
9766: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
9767: '</b><br />';
9768: return $output;
9769: }
9770:
9771: sub commit_standardrole {
9772: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
9773: my ($output,$logmsg,$linefeed);
9774: if ($context eq 'auto') {
9775: $linefeed = "\n";
9776: } else {
9777: $linefeed = "<br />\n";
9778: }
9779: if ($three eq 'st') {
9780: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
9781: $one,$two,$sec,$context);
9782: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
9783: ($result eq 'unknown_course') || ($result eq 'refused')) {
9784: $output = $logmsg.' '.&mt('Error: ').$result."\n";
9785: } else {
9786: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
9787: ($start?', '.&mt('starting').' '.localtime($start):'').
9788: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
9789: if ($context eq 'auto') {
9790: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
9791: } else {
9792: $output .= '<b>'.$result.'</b>'.$linefeed.
9793: &mt('Add to classlist').': <b>ok</b>';
9794: }
9795: $output .= $linefeed;
9796: }
9797: } else {
9798: $output = &mt('Assigning').' '.$three.' in '.$url.
9799: ($start?', '.&mt('starting').' '.localtime($start):'').
9800: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
9801: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
9802: if ($context eq 'auto') {
9803: $output .= $result.$linefeed;
9804: } else {
9805: $output .= '<b>'.$result.'</b>'.$linefeed;
9806: }
9807: }
9808: return $output;
9809: }
9810:
9811: sub commit_studentrole {
9812: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
9813: my ($result,$linefeed,$oldsecurl,$newsecurl);
9814: if ($context eq 'auto') {
9815: $linefeed = "\n";
9816: } else {
9817: $linefeed = '<br />'."\n";
9818: }
9819: if (defined($one) && defined($two)) {
9820: my $cid=$one.'_'.$two;
9821: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
9822: my $secchange = 0;
9823: my $expire_role_result;
9824: my $modify_section_result;
9825: if ($oldsec ne '-1') {
9826: if ($oldsec ne $sec) {
9827: $secchange = 1;
9828: my $now = time;
9829: my $uurl='/'.$cid;
9830: $uurl=~s/\_/\//g;
9831: if ($oldsec) {
9832: $uurl.='/'.$oldsec;
9833: }
9834: $oldsecurl = $uurl;
9835: $expire_role_result =
9836: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
9837: if ($env{'request.course.sec'} ne '') {
9838: if ($expire_role_result eq 'refused') {
9839: my @roles = ('st');
9840: my @statuses = ('previous');
9841: my @roledoms = ($one);
9842: my $withsec = 1;
9843: my %roleshash =
9844: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
9845: \@statuses,\@roles,\@roledoms,$withsec);
9846: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
9847: my ($oldstart,$oldend) =
9848: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
9849: if ($oldend > 0 && $oldend <= $now) {
9850: $expire_role_result = 'ok';
9851: }
9852: }
9853: }
9854: }
9855: $result = $expire_role_result;
9856: }
9857: }
9858: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
9859: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
9860: if ($modify_section_result =~ /^ok/) {
9861: if ($secchange == 1) {
9862: if ($sec eq '') {
9863: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
9864: } else {
9865: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
9866: }
9867: } elsif ($oldsec eq '-1') {
9868: if ($sec eq '') {
9869: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
9870: } else {
9871: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9872: }
9873: } else {
9874: if ($sec eq '') {
9875: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
9876: } else {
9877: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9878: }
9879: }
9880: } else {
9881: if ($secchange) {
9882: $$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;
9883: } else {
9884: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
9885: }
9886: }
9887: $result = $modify_section_result;
9888: } elsif ($secchange == 1) {
9889: if ($oldsec eq '') {
9890: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
9891: } else {
9892: $$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;
9893: }
9894: if ($expire_role_result eq 'refused') {
9895: my $newsecurl = '/'.$cid;
9896: $newsecurl =~ s/\_/\//g;
9897: if ($sec ne '') {
9898: $newsecurl.='/'.$sec;
9899: }
9900: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
9901: if ($sec eq '') {
9902: $$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;
9903: } else {
9904: $$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;
9905: }
9906: }
9907: }
9908: }
9909: } else {
9910: $$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;
9911: $result = "error: incomplete course id\n";
9912: }
9913: return $result;
9914: }
9915:
9916: ############################################################
9917: ############################################################
9918:
9919: sub check_clone {
9920: my ($args,$linefeed) = @_;
9921: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
9922: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
9923: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
9924: my $clonemsg;
9925: my $can_clone = 0;
9926:
9927: if ($clonehome eq 'no_host') {
9928: $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'});
9929: } else {
9930: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
9931: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
9932: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
9933: $can_clone = 1;
9934: } else {
9935: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
9936: $args->{'clonedomain'},$args->{'clonecourse'});
9937: my @cloners = split(/,/,$clonehash{'cloners'});
9938: if (grep(/^\*$/,@cloners)) {
9939: $can_clone = 1;
9940: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
9941: $can_clone = 1;
9942: } else {
9943: my %roleshash =
9944: &Apache::lonnet::get_my_roles($args->{'ccuname'},
9945: $args->{'ccdomain'},
9946: 'userroles',['active'],['cc'],
9947: [$args->{'clonedomain'}]);
9948: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
9949: $can_clone = 1;
9950: } else {
9951: $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'});
9952: }
9953: }
9954: }
9955: }
9956: return ($can_clone, $clonemsg, $cloneid, $clonehome);
9957: }
9958:
9959: sub construct_course {
9960: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category) = @_;
9961: my $outcome;
9962: my $linefeed = '<br />'."\n";
9963: if ($context eq 'auto') {
9964: $linefeed = "\n";
9965: }
9966:
9967: #
9968: # Are we cloning?
9969: #
9970: my ($can_clone, $clonemsg, $cloneid, $clonehome);
9971: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
9972: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
9973: if ($context ne 'auto') {
9974: if ($clonemsg ne '') {
9975: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
9976: }
9977: }
9978: $outcome .= $clonemsg.$linefeed;
9979:
9980: if (!$can_clone) {
9981: return (0,$outcome);
9982: }
9983: }
9984:
9985: #
9986: # Open course
9987: #
9988: my $crstype = lc($args->{'crstype'});
9989: my %cenv=();
9990: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
9991: $args->{'cdescr'},
9992: $args->{'curl'},
9993: $args->{'course_home'},
9994: $args->{'nonstandard'},
9995: $args->{'crscode'},
9996: $args->{'ccuname'}.':'.
9997: $args->{'ccdomain'},
9998: $args->{'crstype'},
9999: $cnum,$context,$category);
10000:
10001: # Note: The testing routines depend on this being output; see
10002: # Utils::Course. This needs to at least be output as a comment
10003: # if anyone ever decides to not show this, and Utils::Course::new
10004: # will need to be suitably modified.
10005: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
10006: #
10007: # Check if created correctly
10008: #
10009: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
10010: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
10011: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
10012:
10013: #
10014: # Do the cloning
10015: #
10016: if ($can_clone && $cloneid) {
10017: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
10018: if ($context ne 'auto') {
10019: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
10020: }
10021: $outcome .= $clonemsg.$linefeed;
10022: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
10023: # Copy all files
10024: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
10025: # Restore URL
10026: $cenv{'url'}=$oldcenv{'url'};
10027: # Restore title
10028: $cenv{'description'}=$oldcenv{'description'};
10029: # Mark as cloned
10030: $cenv{'clonedfrom'}=$cloneid;
10031: # Need to clone grading mode
10032: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
10033: $cenv{'grading'}=$newenv{'grading'};
10034: # Do not clone these environment entries
10035: &Apache::lonnet::del('environment',
10036: ['default_enrollment_start_date',
10037: 'default_enrollment_end_date',
10038: 'question.email',
10039: 'policy.email',
10040: 'comment.email',
10041: 'pch.users.denied',
10042: 'plc.users.denied',
10043: 'hidefromcat',
10044: 'categories'],
10045: $$crsudom,$$crsunum);
10046: }
10047:
10048: #
10049: # Set environment (will override cloned, if existing)
10050: #
10051: my @sections = ();
10052: my @xlists = ();
10053: if ($args->{'crstype'}) {
10054: $cenv{'type'}=$args->{'crstype'};
10055: }
10056: if ($args->{'crsid'}) {
10057: $cenv{'courseid'}=$args->{'crsid'};
10058: }
10059: if ($args->{'crscode'}) {
10060: $cenv{'internal.coursecode'}=$args->{'crscode'};
10061: }
10062: if ($args->{'crsquota'} ne '') {
10063: $cenv{'internal.coursequota'}=$args->{'crsquota'};
10064: } else {
10065: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
10066: }
10067: if ($args->{'ccuname'}) {
10068: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
10069: ':'.$args->{'ccdomain'};
10070: } else {
10071: $cenv{'internal.courseowner'} = $args->{'curruser'};
10072: }
10073: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
10074: if ($args->{'crssections'}) {
10075: $cenv{'internal.sectionnums'} = '';
10076: if ($args->{'crssections'} =~ m/,/) {
10077: @sections = split/,/,$args->{'crssections'};
10078: } else {
10079: $sections[0] = $args->{'crssections'};
10080: }
10081: if (@sections > 0) {
10082: foreach my $item (@sections) {
10083: my ($sec,$gp) = split/:/,$item;
10084: my $class = $args->{'crscode'}.$sec;
10085: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
10086: $cenv{'internal.sectionnums'} .= $item.',';
10087: unless ($addcheck eq 'ok') {
10088: push @badclasses, $class;
10089: }
10090: }
10091: $cenv{'internal.sectionnums'} =~ s/,$//;
10092: }
10093: }
10094: # do not hide course coordinator from staff listing,
10095: # even if privileged
10096: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10097: # add crosslistings
10098: if ($args->{'crsxlist'}) {
10099: $cenv{'internal.crosslistings'}='';
10100: if ($args->{'crsxlist'} =~ m/,/) {
10101: @xlists = split/,/,$args->{'crsxlist'};
10102: } else {
10103: $xlists[0] = $args->{'crsxlist'};
10104: }
10105: if (@xlists > 0) {
10106: foreach my $item (@xlists) {
10107: my ($xl,$gp) = split/:/,$item;
10108: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
10109: $cenv{'internal.crosslistings'} .= $item.',';
10110: unless ($addcheck eq 'ok') {
10111: push @badclasses, $xl;
10112: }
10113: }
10114: $cenv{'internal.crosslistings'} =~ s/,$//;
10115: }
10116: }
10117: if ($args->{'autoadds'}) {
10118: $cenv{'internal.autoadds'}=$args->{'autoadds'};
10119: }
10120: if ($args->{'autodrops'}) {
10121: $cenv{'internal.autodrops'}=$args->{'autodrops'};
10122: }
10123: # check for notification of enrollment changes
10124: my @notified = ();
10125: if ($args->{'notify_owner'}) {
10126: if ($args->{'ccuname'} ne '') {
10127: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
10128: }
10129: }
10130: if ($args->{'notify_dc'}) {
10131: if ($uname ne '') {
10132: push(@notified,$uname.':'.$udom);
10133: }
10134: }
10135: if (@notified > 0) {
10136: my $notifylist;
10137: if (@notified > 1) {
10138: $notifylist = join(',',@notified);
10139: } else {
10140: $notifylist = $notified[0];
10141: }
10142: $cenv{'internal.notifylist'} = $notifylist;
10143: }
10144: if (@badclasses > 0) {
10145: my %lt=&Apache::lonlocal::texthash(
10146: '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',
10147: 'dnhr' => 'does not have rights to access enrollment in these classes',
10148: 'adby' => 'as determined by the policies of your institution on access to official classlists'
10149: );
10150: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
10151: ' ('.$lt{'adby'}.')';
10152: if ($context eq 'auto') {
10153: $outcome .= $badclass_msg.$linefeed;
10154: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
10155: foreach my $item (@badclasses) {
10156: if ($context eq 'auto') {
10157: $outcome .= " - $item\n";
10158: } else {
10159: $outcome .= "<li>$item</li>\n";
10160: }
10161: }
10162: if ($context eq 'auto') {
10163: $outcome .= $linefeed;
10164: } else {
10165: $outcome .= "</ul><br /><br /></div>\n";
10166: }
10167: }
10168: }
10169: if ($args->{'no_end_date'}) {
10170: $args->{'endaccess'} = 0;
10171: }
10172: $cenv{'internal.autostart'}=$args->{'enrollstart'};
10173: $cenv{'internal.autoend'}=$args->{'enrollend'};
10174: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
10175: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
10176: if ($args->{'showphotos'}) {
10177: $cenv{'internal.showphotos'}=$args->{'showphotos'};
10178: }
10179: $cenv{'internal.authtype'} = $args->{'authtype'};
10180: $cenv{'internal.autharg'} = $args->{'autharg'};
10181: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
10182: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
10183: 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');
10184: if ($context eq 'auto') {
10185: $outcome .= $krb_msg;
10186: } else {
10187: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
10188: }
10189: $outcome .= $linefeed;
10190: }
10191: }
10192: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
10193: if ($args->{'setpolicy'}) {
10194: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10195: }
10196: if ($args->{'setcontent'}) {
10197: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10198: }
10199: }
10200: if ($args->{'reshome'}) {
10201: $cenv{'reshome'}=$args->{'reshome'}.'/';
10202: $cenv{'reshome'}=~s/\/+$/\//;
10203: }
10204: #
10205: # course has keyed access
10206: #
10207: if ($args->{'setkeys'}) {
10208: $cenv{'keyaccess'}='yes';
10209: }
10210: # if specified, key authority is not course, but user
10211: # only active if keyaccess is yes
10212: if ($args->{'keyauth'}) {
10213: my ($user,$domain) = split(':',$args->{'keyauth'});
10214: $user = &LONCAPA::clean_username($user);
10215: $domain = &LONCAPA::clean_username($domain);
10216: if ($user ne '' && $domain ne '') {
10217: $cenv{'keyauth'}=$user.':'.$domain;
10218: }
10219: }
10220:
10221: if ($args->{'disresdis'}) {
10222: $cenv{'pch.roles.denied'}='st';
10223: }
10224: if ($args->{'disablechat'}) {
10225: $cenv{'plc.roles.denied'}='st';
10226: }
10227:
10228: # Record we've not yet viewed the Course Initialization Helper for this
10229: # course
10230: $cenv{'course.helper.not.run'} = 1;
10231: #
10232: # Use new Randomseed
10233: #
10234: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
10235: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
10236: #
10237: # The encryption code and receipt prefix for this course
10238: #
10239: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
10240: $cenv{'internal.encpref'}=100+int(9*rand(99));
10241: #
10242: # By default, use standard grading
10243: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
10244:
10245: $outcome .= $linefeed.&mt('Setting environment').': '.
10246: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
10247: #
10248: # Open all assignments
10249: #
10250: if ($args->{'openall'}) {
10251: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
10252: my %storecontent = ($storeunder => time,
10253: $storeunder.'.type' => 'date_start');
10254:
10255: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
10256: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
10257: }
10258: #
10259: # Set first page
10260: #
10261: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
10262: || ($cloneid)) {
10263: use LONCAPA::map;
10264: $outcome .= &mt('Setting first resource').': ';
10265:
10266: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
10267: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
10268:
10269: $outcome .= ($fatal?$errtext:'read ok').' - ';
10270: my $title; my $url;
10271: if ($args->{'firstres'} eq 'syl') {
10272: $title=&mt('Syllabus');
10273: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
10274: } else {
10275: $title=&mt('Navigate Contents');
10276: $url='/adm/navmaps';
10277: }
10278:
10279: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
10280: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
10281:
10282: if ($errtext) { $fatal=2; }
10283: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
10284: }
10285:
10286: return (1,$outcome);
10287: }
10288:
10289: ############################################################
10290: ############################################################
10291:
10292: sub course_type {
10293: my ($cid) = @_;
10294: if (!defined($cid)) {
10295: $cid = $env{'request.course.id'};
10296: }
10297: if (defined($env{'course.'.$cid.'.type'})) {
10298: return $env{'course.'.$cid.'.type'};
10299: } else {
10300: return 'Course';
10301: }
10302: }
10303:
10304: sub group_term {
10305: my $crstype = &course_type();
10306: my %names = (
10307: 'Course' => 'group',
10308: 'Community' => 'group',
10309: );
10310: return $names{$crstype};
10311: }
10312:
10313: sub course_types {
10314: my @types = ('official','unofficial','community');
10315: my %typename = (
10316: official => 'Official course',
10317: unofficial => 'Unofficial course',
10318: community => 'Community',
10319: );
10320: return (\@types,\%typename);
10321: }
10322:
10323: sub icon {
10324: my ($file)=@_;
10325: my $curfext = lc((split(/\./,$file))[-1]);
10326: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
10327: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
10328: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
10329: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
10330: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
10331: $curfext.".gif") {
10332: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
10333: $curfext.".gif";
10334: }
10335: }
10336: return &lonhttpdurl($iconname);
10337: }
10338:
10339: sub lonhttpdurl {
10340: #
10341: # Had been used for "small fry" static images on separate port 8080.
10342: # Modify here if lightweight http functionality desired again.
10343: # Currently eliminated due to increasing firewall issues.
10344: #
10345: my ($url)=@_;
10346: return $url;
10347: }
10348:
10349: sub connection_aborted {
10350: my ($r)=@_;
10351: $r->print(" ");$r->rflush();
10352: my $c = $r->connection;
10353: return $c->aborted();
10354: }
10355:
10356: # Escapes strings that may have embedded 's that will be put into
10357: # strings as 'strings'.
10358: sub escape_single {
10359: my ($input) = @_;
10360: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
10361: $input =~ s/\'/\\\'/g; # Esacpe the 's....
10362: return $input;
10363: }
10364:
10365: # Same as escape_single, but escape's "'s This
10366: # can be used for "strings"
10367: sub escape_double {
10368: my ($input) = @_;
10369: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
10370: $input =~ s/\"/\\\"/g; # Esacpe the "s....
10371: return $input;
10372: }
10373:
10374: # Escapes the last element of a full URL.
10375: sub escape_url {
10376: my ($url) = @_;
10377: my @urlslices = split(/\//, $url,-1);
10378: my $lastitem = &escape(pop(@urlslices));
10379: return join('/',@urlslices).'/'.$lastitem;
10380: }
10381:
10382: sub compare_arrays {
10383: my ($arrayref1,$arrayref2) = @_;
10384: my (@difference,%count);
10385: @difference = ();
10386: %count = ();
10387: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
10388: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
10389: foreach my $element (keys(%count)) {
10390: if ($count{$element} == 1) {
10391: push(@difference,$element);
10392: }
10393: }
10394: }
10395: return @difference;
10396: }
10397:
10398: # -------------------------------------------------------- Initialize user login
10399: sub init_user_environment {
10400: my ($r, $username, $domain, $authhost, $form, $args) = @_;
10401: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
10402:
10403: my $public=($username eq 'public' && $domain eq 'public');
10404:
10405: # See if old ID present, if so, remove
10406:
10407: my ($filename,$cookie,$userroles);
10408: my $now=time;
10409:
10410: if ($public) {
10411: my $max_public=100;
10412: my $oldest;
10413: my $oldest_time=0;
10414: for(my $next=1;$next<=$max_public;$next++) {
10415: if (-e $lonids."/publicuser_$next.id") {
10416: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
10417: if ($mtime<$oldest_time || !$oldest_time) {
10418: $oldest_time=$mtime;
10419: $oldest=$next;
10420: }
10421: } else {
10422: $cookie="publicuser_$next";
10423: last;
10424: }
10425: }
10426: if (!$cookie) { $cookie="publicuser_$oldest"; }
10427: } else {
10428: # if this isn't a robot, kill any existing non-robot sessions
10429: if (!$args->{'robot'}) {
10430: opendir(DIR,$lonids);
10431: while ($filename=readdir(DIR)) {
10432: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
10433: unlink($lonids.'/'.$filename);
10434: }
10435: }
10436: closedir(DIR);
10437: }
10438: # Give them a new cookie
10439: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
10440: : $now.$$.int(rand(10000)));
10441: $cookie="$username\_$id\_$domain\_$authhost";
10442:
10443: # Initialize roles
10444:
10445: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
10446: }
10447: # ------------------------------------ Check browser type and MathML capability
10448:
10449: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
10450: $clientunicode,$clientos) = &decode_user_agent($r);
10451:
10452: # ------------------------------------------------------------- Get environment
10453:
10454: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
10455: my ($tmp) = keys(%userenv);
10456: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
10457: # default remote control to off
10458: if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
10459: } else {
10460: undef(%userenv);
10461: }
10462: if (($userenv{'interface'}) && (!$form->{'interface'})) {
10463: $form->{'interface'}=$userenv{'interface'};
10464: }
10465: $env{'environment.remote'}=$userenv{'remote'};
10466: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
10467:
10468: # --------------- Do not trust query string to be put directly into environment
10469: foreach my $option ('interface','localpath','localres') {
10470: $form->{$option}=~s/[\n\r\=]//gs;
10471: }
10472: # --------------------------------------------------------- Write first profile
10473:
10474: {
10475: my %initial_env =
10476: ("user.name" => $username,
10477: "user.domain" => $domain,
10478: "user.home" => $authhost,
10479: "browser.type" => $clientbrowser,
10480: "browser.version" => $clientversion,
10481: "browser.mathml" => $clientmathml,
10482: "browser.unicode" => $clientunicode,
10483: "browser.os" => $clientos,
10484: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
10485: "request.course.fn" => '',
10486: "request.course.uri" => '',
10487: "request.course.sec" => '',
10488: "request.role" => 'cm',
10489: "request.role.adv" => $env{'user.adv'},
10490: "request.host" => $ENV{'REMOTE_ADDR'},);
10491:
10492: if ($form->{'localpath'}) {
10493: $initial_env{"browser.localpath"} = $form->{'localpath'};
10494: $initial_env{"browser.localres"} = $form->{'localres'};
10495: }
10496:
10497: if ($public) {
10498: $initial_env{"environment.remote"} = "off";
10499: }
10500: if ($form->{'interface'}) {
10501: $form->{'interface'}=~s/\W//gs;
10502: $initial_env{"browser.interface"} = $form->{'interface'};
10503: $env{'browser.interface'}=$form->{'interface'};
10504: }
10505:
10506: foreach my $tool ('aboutme','blog','portfolio') {
10507: $userenv{'availabletools.'.$tool} =
10508: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload');
10509: }
10510:
10511: foreach my $crstype ('official','unofficial','community') {
10512: $userenv{'canrequest.'.$crstype} =
10513: &Apache::lonnet::usertools_access($username,$domain,$crstype,
10514: 'reload','requestcourses');
10515: }
10516:
10517: $env{'user.environment'} = "$lonids/$cookie.id";
10518:
10519: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
10520: &GDBM_WRCREAT(),0640)) {
10521: &_add_to_env(\%disk_env,\%initial_env);
10522: &_add_to_env(\%disk_env,\%userenv,'environment.');
10523: &_add_to_env(\%disk_env,$userroles);
10524: if (ref($args->{'extra_env'})) {
10525: &_add_to_env(\%disk_env,$args->{'extra_env'});
10526: }
10527: untie(%disk_env);
10528: } else {
10529: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
10530: 'Could not create environment storage in lonauth: '.$!.'</span>');
10531: return 'error: '.$!;
10532: }
10533: }
10534: $env{'request.role'}='cm';
10535: $env{'request.role.adv'}=$env{'user.adv'};
10536: $env{'browser.type'}=$clientbrowser;
10537:
10538: return $cookie;
10539:
10540: }
10541:
10542: sub _add_to_env {
10543: my ($idf,$env_data,$prefix) = @_;
10544: if (ref($env_data) eq 'HASH') {
10545: while (my ($key,$value) = each(%$env_data)) {
10546: $idf->{$prefix.$key} = $value;
10547: $env{$prefix.$key} = $value;
10548: }
10549: }
10550: }
10551:
10552: # --- Get the symbolic name of a problem and the url
10553: sub get_symb {
10554: my ($request,$silent) = @_;
10555: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
10556: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
10557: if ($symb eq '') {
10558: if (!$silent) {
10559: $request->print("Unable to handle ambiguous references:$url:.");
10560: return ();
10561: }
10562: }
10563: &Apache::lonenc::check_decrypt(\$symb);
10564: return ($symb);
10565: }
10566:
10567: # --------------------------------------------------------------Get annotation
10568:
10569: sub get_annotation {
10570: my ($symb,$enc) = @_;
10571:
10572: my $key = $symb;
10573: if (!$enc) {
10574: $key =
10575: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
10576: }
10577: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
10578: return $annotation{$key};
10579: }
10580:
10581: sub clean_symb {
10582: my ($symb,$delete_enc) = @_;
10583:
10584: &Apache::lonenc::check_decrypt(\$symb);
10585: my $enc = $env{'request.enc'};
10586: if ($delete_enc) {
10587: delete($env{'request.enc'});
10588: }
10589:
10590: return ($symb,$enc);
10591: }
10592:
10593: =pod
10594:
10595: =back
10596:
10597: =cut
10598:
10599: 1;
10600: __END__;
10601:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>