Annotation of loncom/interface/loncommon.pm, revision 1.781
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.781 ! raeburn 4: # $Id: loncommon.pm,v 1.780 2009/03/27 02:14:43 raeburn Exp $
1.10 albertel 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: #
1.1 albertel 28:
29: # Makes a table out of the previous attempts
1.2 albertel 30: # Inputs result_from_symbread, user, domain, course_id
1.16 harris41 31: # Reads in non-network-related .tab files
1.1 albertel 32:
1.35 matthew 33: # POD header:
34:
1.45 matthew 35: =pod
36:
1.35 matthew 37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
1.112 bowersj2 43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
1.35 matthew 45:
1.112 bowersj2 46: =head1 OVERVIEW
1.35 matthew 47:
1.112 bowersj2 48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
1.35 matthew 50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
1.1 albertel 55: package Apache::loncommon;
56:
57: use strict;
1.258 albertel 58: use Apache::lonnet;
1.46 matthew 59: use GDBM_File;
1.51 www 60: use POSIX qw(strftime mktime);
1.82 www 61: use Apache::lonmenu();
1.498 albertel 62: use Apache::lonenc();
1.117 www 63: use Apache::lonlocal;
1.685 tempelho 64: use Apache::lonnet();
1.139 matthew 65: use HTML::Entities;
1.334 albertel 66: use Apache::lonhtmlcommon();
67: use Apache::loncoursedata();
1.344 albertel 68: use Apache::lontexconvert();
1.444 albertel 69: use Apache::lonclonecourse();
1.479 albertel 70: use LONCAPA qw(:DEFAULT :match);
1.657 raeburn 71: use DateTime::TimeZone;
1.687 raeburn 72: use DateTime::Locale::Catalog;
1.117 www 73:
1.517 raeburn 74: # ---------------------------------------------- Designs
75: use vars qw(%defaultdesign);
76:
1.22 www 77: my $readit;
78:
1.517 raeburn 79:
1.157 matthew 80: ##
81: ## Global Variables
82: ##
1.46 matthew 83:
1.643 foxr 84:
85: # ----------------------------------------------- SSI with retries:
86: #
87:
88: =pod
89:
1.648 raeburn 90: =head1 Server Side include with retries:
1.643 foxr 91:
92: =over 4
93:
1.648 raeburn 94: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 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:
1.648 raeburn 101:
102: =over 4
103:
1.643 foxr 104: resource - Identifies the resource to insert.
1.648 raeburn 105:
1.643 foxr 106: retries - Count of the number of retries allowed.
1.648 raeburn 107:
1.643 foxr 108: form - Hash that identifies the rendering options.
109:
1.648 raeburn 110: =back
111:
112: Returns:
113:
114: =over 4
115:
1.643 foxr 116: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 117:
1.643 foxr 118: response - The response from the last attempt (which may or may not have been successful.
119:
1.648 raeburn 120: =back
121:
122: =back
123:
1.643 foxr 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;
1.650 www 139: if (!$ok) {
140: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
141: }
1.643 foxr 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:
1.20 www 154: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 155: my %language;
1.124 www 156: my %supported_language;
1.12 harris41 157: my %cprtag;
1.192 taceyjo1 158: my %scprtag;
1.351 www 159: my %fe; my %fd; my %fm;
1.41 ng 160: my %category_extensions;
1.12 harris41 161:
1.46 matthew 162: # ---------------------------------------------- Thesaurus variables
1.144 matthew 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.
1.46 matthew 168:
169: my %Keywords;
170: my $thesaurus_db_file;
171:
1.144 matthew 172: #
173: # Initialize values from language.tab, copyright.tab, filetypes.tab,
174: # thesaurus.tab, and filecategories.tab.
175: #
1.18 www 176: BEGIN {
1.46 matthew 177: # Variable initialization
178: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
179: #
1.22 www 180: unless ($readit) {
1.12 harris41 181: # ------------------------------------------------------------------- languages
182: {
1.158 raeburn 183: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
184: '/language.tab';
185: if ( open(my $fh,"<$langtabfile") ) {
1.356 albertel 186: while (my $line = <$fh>) {
187: next if ($line=~/^\#/);
188: chomp($line);
189: my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$line));
1.158 raeburn 190: $language{$key}=$val.' - '.$enc;
191: if ($sup) {
192: $supported_language{$key}=$sup;
193: }
194: }
195: close($fh);
196: }
1.12 harris41 197: }
198: # ------------------------------------------------------------------ copyrights
199: {
1.158 raeburn 200: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
201: '/copyright.tab';
202: if ( open (my $fh,"<$copyrightfile") ) {
1.356 albertel 203: while (my $line = <$fh>) {
204: next if ($line=~/^\#/);
205: chomp($line);
206: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 207: $cprtag{$key}=$val;
208: }
209: close($fh);
210: }
1.12 harris41 211: }
1.351 www 212: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 213: {
214: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
215: '/source_copyright.tab';
216: if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356 albertel 217: while (my $line = <$fh>) {
218: next if ($line =~ /^\#/);
219: chomp($line);
220: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 221: $scprtag{$key}=$val;
222: }
223: close($fh);
224: }
225: }
1.63 www 226:
1.517 raeburn 227: # -------------------------------------------------------------- default domain designs
1.63 www 228: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 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);
1.63 www 238: }
239:
1.15 harris41 240: # ------------------------------------------------------------- file categories
241: {
1.158 raeburn 242: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
243: '/filecategories.tab';
244: if ( open (my $fh,"<$categoryfile") ) {
1.356 albertel 245: while (my $line = <$fh>) {
246: next if ($line =~ /^\#/);
247: chomp($line);
248: my ($extension,$category)=(split(/\s+/,$line,2));
1.158 raeburn 249: push @{$category_extensions{lc($category)}},$extension;
250: }
251: close($fh);
252: }
253:
1.15 harris41 254: }
1.12 harris41 255: # ------------------------------------------------------------------ file types
256: {
1.158 raeburn 257: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
258: '/filetypes.tab';
259: if ( open (my $fh,"<$typesfile") ) {
1.356 albertel 260: while (my $line = <$fh>) {
261: next if ($line =~ /^\#/);
262: chomp($line);
263: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 264: if ($descr ne '') {
265: $fe{$ending}=lc($emb);
266: $fd{$ending}=$descr;
1.351 www 267: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 268: }
269: }
270: close($fh);
271: }
1.12 harris41 272: }
1.22 www 273: &Apache::lonnet::logthis(
1.705 tempelho 274: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 275: $readit=1;
1.46 matthew 276: } # end of unless($readit)
1.32 matthew 277:
278: }
1.112 bowersj2 279:
1.42 matthew 280: ###############################################################
281: ## HTML and Javascript Helper Functions ##
282: ###############################################################
283:
284: =pod
285:
1.112 bowersj2 286: =head1 HTML and Javascript Functions
1.42 matthew 287:
1.112 bowersj2 288: =over 4
289:
1.648 raeburn 290: =item * &browser_and_searcher_javascript()
1.112 bowersj2 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.
1.42 matthew 296:
1.648 raeburn 297: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 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
1.185 www 305: with the given extension. Can be a comma separated list.
1.42 matthew 306:
307: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 308: with the given extension. Can be a comma separated list.
1.42 matthew 309:
1.648 raeburn 310: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 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.
1.542 raeburn 316:
1.42 matthew 317: =cut
318:
319: sub browser_and_searcher_javascript {
1.199 albertel 320: my ($mode)=@_;
321: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 322: my $resurl=&escape_single(&lastresurl());
1.42 matthew 323: return <<END;
1.219 albertel 324: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 325: var editbrowser = null;
1.135 albertel 326: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 327: var url = '$resurl/?';
1.42 matthew 328: if (editbrowser == null) {
329: url += 'launch=1&';
330: }
331: url += 'catalogmode=interactive&';
1.199 albertel 332: url += 'mode=$mode&';
1.611 albertel 333: url += 'inhibitmenu=yes&';
1.42 matthew 334: url += 'form=' + formname + '&';
335: if (only != null) {
336: url += 'only=' + only + '&';
1.217 albertel 337: } else {
338: url += 'only=&';
339: }
1.42 matthew 340: if (omit != null) {
341: url += 'omit=' + omit + '&';
1.217 albertel 342: } else {
343: url += 'omit=&';
344: }
1.135 albertel 345: if (titleelement != null) {
346: url += 'titleelement=' + titleelement + '&';
1.217 albertel 347: } else {
348: url += 'titleelement=&';
349: }
1.42 matthew 350: url += 'element=' + elementname + '';
351: var title = 'Browser';
1.435 albertel 352: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 353: options += ',width=700,height=600';
354: editbrowser = open(url,title,options,'1');
355: editbrowser.focus();
356: }
357: var editsearcher;
1.135 albertel 358: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 359: var url = '/adm/searchcat?';
360: if (editsearcher == null) {
361: url += 'launch=1&';
362: }
363: url += 'catalogmode=interactive&';
1.199 albertel 364: url += 'mode=$mode&';
1.42 matthew 365: url += 'form=' + formname + '&';
1.135 albertel 366: if (titleelement != null) {
367: url += 'titleelement=' + titleelement + '&';
1.217 albertel 368: } else {
369: url += 'titleelement=&';
370: }
1.42 matthew 371: url += 'element=' + elementname + '';
372: var title = 'Search';
1.435 albertel 373: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 374: options += ',width=700,height=600';
375: editsearcher = open(url,title,options,'1');
376: editsearcher.focus();
377: }
1.219 albertel 378: // END LON-CAPA Internal -->
1.42 matthew 379: END
1.170 www 380: }
381:
382: sub lastresurl {
1.258 albertel 383: if ($env{'environment.lastresurl'}) {
384: return $env{'environment.lastresurl'}
1.170 www 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});
1.646 raeburn 395: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 396: return 1;
1.42 matthew 397: }
398:
1.74 www 399: sub studentbrowser_javascript {
1.111 www 400: unless (
1.258 albertel 401: (($env{'request.course.id'}) &&
1.302 albertel 402: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
403: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
404: '/'.$env{'request.course.sec'})
405: ))
1.258 albertel 406: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 407: ) { return ''; }
1.74 www 408: return (<<'ENDSTDBRW');
1.776 bisitz 409: <script type="text/javascript" language="Javascript">
1.74 www 410: var stdeditbrowser;
1.558 albertel 411: function openstdbrowser(formname,uname,udom,roleflag,ignorefilter) {
1.74 www 412: var url = '/adm/pickstudent?';
413: var filter;
1.558 albertel 414: if (!ignorefilter) {
415: eval('filter=document.'+formname+'.'+uname+'.value;');
416: }
1.74 www 417: if (filter != null) {
418: if (filter != '') {
419: url += 'filter='+filter+'&';
420: }
421: }
422: url += 'form=' + formname + '&unameelement='+uname+
423: '&udomelement='+udom;
1.111 www 424: if (roleflag) { url+="&roles=1"; }
1.102 www 425: var title = 'Student_Browser';
1.74 www 426: var options = 'scrollbars=1,resizable=1,menubar=0';
427: options += ',width=700,height=600';
428: stdeditbrowser = open(url,title,options,'1');
429: stdeditbrowser.focus();
430: }
431: </script>
432: ENDSTDBRW
433: }
1.42 matthew 434:
1.74 www 435: sub selectstudent_link {
1.111 www 436: my ($form,$unameele,$udomele)=@_;
1.258 albertel 437: if ($env{'request.course.id'}) {
1.302 albertel 438: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
439: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
440: '/'.$env{'request.course.sec'})) {
1.111 www 441: return '';
442: }
443: return "<a href='".'javascript:openstdbrowser("'.$form.'","'.$unameele.
1.607 albertel 444: '","'.$udomele.'");'."'>".&mt('Select User')."</a>";
1.74 www 445: }
1.258 albertel 446: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.111 www 447: return "<a href='".'javascript:openstdbrowser("'.$form.'","'.$unameele.
1.119 www 448: '","'.$udomele.'",1);'."'>".&mt('Select User')."</a>";
1.111 www 449: }
450: return '';
1.91 www 451: }
452:
1.653 raeburn 453: sub authorbrowser_javascript {
454: return <<"ENDAUTHORBRW";
1.776 bisitz 455: <script type="text/javascript" language="JavaScript">
1.653 raeburn 456: var stdeditbrowser;
457:
458: function openauthorbrowser(formname,udom) {
459: var url = '/adm/pickauthor?';
460: url += 'form='+formname+'&roledom='+udom;
461: var title = 'Author_Browser';
462: var options = 'scrollbars=1,resizable=1,menubar=0';
463: options += ',width=700,height=600';
464: stdeditbrowser = open(url,title,options,'1');
465: stdeditbrowser.focus();
466: }
467:
468: </script>
469: ENDAUTHORBRW
470: }
471:
1.91 www 472: sub coursebrowser_javascript {
1.468 raeburn 473: my ($domainfilter,$sec_element,$formname)=@_;
1.377 raeburn 474: my $crs_or_grp_alert = &mt('Please select the type of LON-CAPA entity - Course or Group - for which you wish to add/modify a user role');
1.468 raeburn 475: my $output = '
1.776 bisitz 476: <script type="text/javascript" language="JavaScript">
1.468 raeburn 477: var stdeditbrowser;'."\n";
478: $output .= <<"ENDSTDBRW";
1.377 raeburn 479: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,crstype) {
1.91 www 480: var url = '/adm/pickcourse?';
1.468 raeburn 481: var domainfilter = '';
482: var formid = getFormIdByName(formname);
483: if (formid > -1) {
484: var domid = getIndexByName(formid,udom);
485: if (domid > -1) {
486: if (document.forms[formid].elements[domid].type == 'select-one') {
487: domainfilter=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
488: }
489: if (document.forms[formid].elements[domid].type == 'hidden') {
490: domainfilter=document.forms[formid].elements[domid].value;
491: }
492: }
1.91 www 493: }
1.128 albertel 494: if (domainfilter != null) {
495: if (domainfilter != '') {
496: url += 'domainfilter='+domainfilter+'&';
497: }
498: }
1.91 www 499: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 500: '&cdomelement='+udom+
501: '&cnameelement='+desc;
1.468 raeburn 502: if (extra_element !=null && extra_element != '') {
1.594 raeburn 503: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 504: url += '&roleelement='+extra_element;
505: if (domainfilter == null || domainfilter == '') {
506: url += '&domainfilter='+extra_element;
507: }
1.234 raeburn 508: }
1.468 raeburn 509: else {
510: if (formname == 'portform') {
511: url += '&setroles='+extra_element;
512: }
513: }
1.230 raeburn 514: }
1.293 raeburn 515: if (multflag !=null && multflag != '') {
516: url += '&multiple='+multflag;
517: }
1.377 raeburn 518: if (crstype == 'Course/Group') {
519: if (formname == 'cu') {
520: crstype = document.cu.crstype.options[document.cu.crstype.selectedIndex].value;
521: if (crstype == "") {
522: alert("$crs_or_grp_alert");
523: return;
524: }
525: }
526: }
527: if (crstype !=null && crstype != '') {
528: url += '&type='+crstype;
529: }
1.102 www 530: var title = 'Course_Browser';
1.91 www 531: var options = 'scrollbars=1,resizable=1,menubar=0';
532: options += ',width=700,height=600';
533: stdeditbrowser = open(url,title,options,'1');
534: stdeditbrowser.focus();
535: }
1.468 raeburn 536:
537: function getFormIdByName(formname) {
538: for (var i=0;i<document.forms.length;i++) {
539: if (document.forms[i].name == formname) {
540: return i;
541: }
542: }
543: return -1;
544: }
545:
546: function getIndexByName(formid,item) {
547: for (var i=0;i<document.forms[formid].elements.length;i++) {
548: if (document.forms[formid].elements[i].name == item) {
549: return i;
550: }
551: }
552: return -1;
553: }
1.91 www 554: ENDSTDBRW
1.468 raeburn 555: if ($sec_element ne '') {
556: $output .= &setsec_javascript($sec_element,$formname);
557: }
558: $output .= '
559: </script>';
560: return $output;
561: }
562:
563: sub setsec_javascript {
564: my ($sec_element,$formname) = @_;
565: my $setsections = qq|
566: function setSect(sectionlist) {
1.629 raeburn 567: var sectionsArray = new Array();
568: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
569: sectionsArray = sectionlist.split(",");
570: }
1.468 raeburn 571: var numSections = sectionsArray.length;
572: document.$formname.$sec_element.length = 0;
573: if (numSections == 0) {
574: document.$formname.$sec_element.multiple=false;
575: document.$formname.$sec_element.size=1;
576: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
577: } else {
578: if (numSections == 1) {
579: document.$formname.$sec_element.multiple=false;
580: document.$formname.$sec_element.size=1;
581: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
582: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
583: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
584: } else {
585: for (var i=0; i<numSections; i++) {
586: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
587: }
588: document.$formname.$sec_element.multiple=true
589: if (numSections < 3) {
590: document.$formname.$sec_element.size=numSections;
591: } else {
592: document.$formname.$sec_element.size=3;
593: }
594: document.$formname.$sec_element.options[0].selected = false
595: }
596: }
1.91 www 597: }
1.468 raeburn 598: |;
599: return $setsections;
600: }
601:
1.91 www 602:
603: sub selectcourse_link {
1.377 raeburn 604: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype)=@_;
1.492 albertel 605: return "<a href='".'javascript:opencrsbrowser("'.$form.'","'.$unameele.
606: '","'.$udomele.'","'.$desc.'","'.$extra_element.'","'.$multflag.'","'.$selecttype.'");'."'>".&mt('Select Course')."</a>";
1.74 www 607: }
1.42 matthew 608:
1.653 raeburn 609: sub selectauthor_link {
610: my ($form,$udom)=@_;
611: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
612: &mt('Select Author').'</a>';
613: }
614:
1.273 raeburn 615: sub check_uncheck_jscript {
616: my $jscript = <<"ENDSCRT";
617: function checkAll(field) {
618: if (field.length > 0) {
619: for (i = 0; i < field.length; i++) {
620: field[i].checked = true ;
621: }
622: } else {
623: field.checked = true
624: }
625: }
626:
627: function uncheckAll(field) {
628: if (field.length > 0) {
629: for (i = 0; i < field.length; i++) {
630: field[i].checked = false ;
1.543 albertel 631: }
632: } else {
1.273 raeburn 633: field.checked = false ;
634: }
635: }
636: ENDSCRT
637: return $jscript;
638: }
639:
1.656 www 640: sub select_timezone {
1.659 raeburn 641: my ($name,$selected,$onchange,$includeempty)=@_;
642: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
643: if ($includeempty) {
644: $output .= '<option value=""';
645: if (($selected eq '') || ($selected eq 'local')) {
646: $output .= ' selected="selected" ';
647: }
648: $output .= '> </option>';
649: }
1.657 raeburn 650: my @timezones = DateTime::TimeZone->all_names;
651: foreach my $tzone (@timezones) {
652: $output.= '<option value="'.$tzone.'"';
653: if ($tzone eq $selected) {
654: $output.=' selected="selected"';
655: }
656: $output.=">$tzone</option>\n";
1.656 www 657: }
658: $output.="</select>";
659: return $output;
660: }
1.273 raeburn 661:
1.687 raeburn 662: sub select_datelocale {
663: my ($name,$selected,$onchange,$includeempty)=@_;
664: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
665: if ($includeempty) {
666: $output .= '<option value=""';
667: if ($selected eq '') {
668: $output .= ' selected="selected" ';
669: }
670: $output .= '> </option>';
671: }
672: my (@possibles,%locale_names);
673: my @locales = DateTime::Locale::Catalog::Locales;
674: foreach my $locale (@locales) {
675: if (ref($locale) eq 'HASH') {
676: my $id = $locale->{'id'};
677: if ($id ne '') {
678: my $en_terr = $locale->{'en_territory'};
679: my $native_terr = $locale->{'native_territory'};
1.695 raeburn 680: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 681: if (grep(/^en$/,@languages) || !@languages) {
682: if ($en_terr ne '') {
683: $locale_names{$id} = '('.$en_terr.')';
684: } elsif ($native_terr ne '') {
685: $locale_names{$id} = $native_terr;
686: }
687: } else {
688: if ($native_terr ne '') {
689: $locale_names{$id} = $native_terr.' ';
690: } elsif ($en_terr ne '') {
691: $locale_names{$id} = '('.$en_terr.')';
692: }
693: }
694: push (@possibles,$id);
695: }
696: }
697: }
698: foreach my $item (sort(@possibles)) {
699: $output.= '<option value="'.$item.'"';
700: if ($item eq $selected) {
701: $output.=' selected="selected"';
702: }
703: $output.=">$item";
704: if ($locale_names{$item} ne '') {
705: $output.=" $locale_names{$item}</option>\n";
706: }
707: $output.="</option>\n";
708: }
709: $output.="</select>";
710: return $output;
711: }
712:
1.42 matthew 713: =pod
1.36 matthew 714:
1.648 raeburn 715: =item * &linked_select_forms(...)
1.36 matthew 716:
717: linked_select_forms returns a string containing a <script></script> block
718: and html for two <select> menus. The select menus will be linked in that
719: changing the value of the first menu will result in new values being placed
720: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 721: order unless a defined order is provided.
1.36 matthew 722:
723: linked_select_forms takes the following ordered inputs:
724:
725: =over 4
726:
1.112 bowersj2 727: =item * $formname, the name of the <form> tag
1.36 matthew 728:
1.112 bowersj2 729: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 730:
1.112 bowersj2 731: =item * $firstdefault, the default value for the first menu
1.36 matthew 732:
1.112 bowersj2 733: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 734:
1.112 bowersj2 735: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 736:
1.112 bowersj2 737: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 738:
1.609 raeburn 739: =item * $menuorder, the order of values in the first menu
740:
1.41 ng 741: =back
742:
1.36 matthew 743: Below is an example of such a hash. Only the 'text', 'default', and
744: 'select2' keys must appear as stated. keys(%menu) are the possible
745: values for the first select menu. The text that coincides with the
1.41 ng 746: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 747: and text for the second menu are given in the hash pointed to by
748: $menu{$choice1}->{'select2'}.
749:
1.112 bowersj2 750: my %menu = ( A1 => { text =>"Choice A1" ,
751: default => "B3",
752: select2 => {
753: B1 => "Choice B1",
754: B2 => "Choice B2",
755: B3 => "Choice B3",
756: B4 => "Choice B4"
1.609 raeburn 757: },
758: order => ['B4','B3','B1','B2'],
1.112 bowersj2 759: },
760: A2 => { text =>"Choice A2" ,
761: default => "C2",
762: select2 => {
763: C1 => "Choice C1",
764: C2 => "Choice C2",
765: C3 => "Choice C3"
1.609 raeburn 766: },
767: order => ['C2','C1','C3'],
1.112 bowersj2 768: },
769: A3 => { text =>"Choice A3" ,
770: default => "D6",
771: select2 => {
772: D1 => "Choice D1",
773: D2 => "Choice D2",
774: D3 => "Choice D3",
775: D4 => "Choice D4",
776: D5 => "Choice D5",
777: D6 => "Choice D6",
778: D7 => "Choice D7"
1.609 raeburn 779: },
780: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 781: }
782: );
1.36 matthew 783:
784: =cut
785:
786: sub linked_select_forms {
787: my ($formname,
788: $middletext,
789: $firstdefault,
790: $firstselectname,
791: $secondselectname,
1.609 raeburn 792: $hashref,
793: $menuorder,
1.36 matthew 794: ) = @_;
795: my $second = "document.$formname.$secondselectname";
796: my $first = "document.$formname.$firstselectname";
797: # output the javascript to do the changing
798: my $result = '';
1.776 bisitz 799: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.36 matthew 800: $result.="var select2data = new Object();\n";
801: $" = '","';
802: my $debug = '';
803: foreach my $s1 (sort(keys(%$hashref))) {
804: $result.="select2data.d_$s1 = new Object();\n";
805: $result.="select2data.d_$s1.def = new String('".
806: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 807: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 808: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 809: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
810: @s2values = @{$hashref->{$s1}->{'order'}};
811: }
1.36 matthew 812: $result.="\"@s2values\");\n";
813: $result.="select2data.d_$s1.texts = new Array(";
814: my @s2texts;
815: foreach my $value (@s2values) {
816: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
817: }
818: $result.="\"@s2texts\");\n";
819: }
820: $"=' ';
821: $result.= <<"END";
822:
823: function select1_changed() {
824: // Determine new choice
825: var newvalue = "d_" + $first.value;
826: // update select2
827: var values = select2data[newvalue].values;
828: var texts = select2data[newvalue].texts;
829: var select2def = select2data[newvalue].def;
830: var i;
831: // out with the old
832: for (i = 0; i < $second.options.length; i++) {
833: $second.options[i] = null;
834: }
835: // in with the nuclear
836: for (i=0;i<values.length; i++) {
837: $second.options[i] = new Option(values[i]);
1.143 matthew 838: $second.options[i].value = values[i];
1.36 matthew 839: $second.options[i].text = texts[i];
840: if (values[i] == select2def) {
841: $second.options[i].selected = true;
842: }
843: }
844: }
845: </script>
846: END
847: # output the initial values for the selection lists
848: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609 raeburn 849: my @order = sort(keys(%{$hashref}));
850: if (ref($menuorder) eq 'ARRAY') {
851: @order = @{$menuorder};
852: }
853: foreach my $value (@order) {
1.36 matthew 854: $result.=" <option value=\"$value\" ";
1.253 albertel 855: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 856: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 857: }
858: $result .= "</select>\n";
859: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
860: $result .= $middletext;
861: $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
862: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 863:
864: my @secondorder = sort(keys(%select2));
865: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
866: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
867: }
868: foreach my $value (@secondorder) {
1.36 matthew 869: $result.=" <option value=\"$value\" ";
1.253 albertel 870: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 871: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 872: }
873: $result .= "</select>\n";
874: # return $debug;
875: return $result;
876: } # end of sub linked_select_forms {
877:
1.45 matthew 878: =pod
1.44 bowersj2 879:
1.648 raeburn 880: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height)
1.44 bowersj2 881:
1.112 bowersj2 882: Returns a string corresponding to an HTML link to the given help
883: $topic, where $topic corresponds to the name of a .tex file in
884: /home/httpd/html/adm/help/tex, with underscores replaced by
885: spaces.
886:
887: $text will optionally be linked to the same topic, allowing you to
888: link text in addition to the graphic. If you do not want to link
889: text, but wish to specify one of the later parameters, pass an
890: empty string.
891:
892: $stayOnPage is a value that will be interpreted as a boolean. If true,
893: the link will not open a new window. If false, the link will open
894: a new window using Javascript. (Default is false.)
895:
896: $width and $height are optional numerical parameters that will
897: override the width and height of the popped up window, which may
898: be useful for certain help topics with big pictures included.
1.44 bowersj2 899:
900: =cut
901:
902: sub help_open_topic {
1.48 bowersj2 903: my ($topic, $text, $stayOnPage, $width, $height) = @_;
904: $text = "" if (not defined $text);
1.44 bowersj2 905: $stayOnPage = 0 if (not defined $stayOnPage);
1.552 banghart 906: if ($env{'browser.interface'} eq 'textual') {
1.79 www 907: $stayOnPage=1;
908: }
1.44 bowersj2 909: $width = 350 if (not defined $width);
910: $height = 400 if (not defined $height);
911: my $filename = $topic;
912: $filename =~ s/ /_/g;
913:
1.48 bowersj2 914: my $template = "";
915: my $link;
1.572 banghart 916:
1.159 www 917: $topic=~s/\W/\_/g;
1.44 bowersj2 918:
1.572 banghart 919: if (!$stayOnPage) {
1.72 bowersj2 920: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1.572 banghart 921: } else {
1.48 bowersj2 922: $link = "/adm/help/${filename}.hlp";
923: }
924:
925: # Add the text
1.755 neumanie 926: if ($text ne "") {
1.763 bisitz 927: $template.='<span class="LC_help_open_topic">'
928: .'<a target="_top" href="'.$link.'">'
929: .$text.'</a>';
1.48 bowersj2 930: }
931:
1.763 bisitz 932: # (Always) Add the graphic
1.179 matthew 933: my $title = &mt('Online Help');
1.667 raeburn 934: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.763 bisitz 935: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
936: .'<img src="'.$helpicon.'" border="0"'
937: .' alt="'.&mt('Help: [_1]',$topic).'"'
938: .' title="'.$title.'"'
939: .' /></a>';
940: if ($text ne "") {
941: $template.='</span>';
942: }
1.44 bowersj2 943: return $template;
944:
1.106 bowersj2 945: }
946:
947: # This is a quicky function for Latex cheatsheet editing, since it
948: # appears in at least four places
949: sub helpLatexCheatsheet {
1.732 raeburn 950: my ($topic,$text,$not_author) = @_;
951: my $out;
1.106 bowersj2 952: my $addOther = '';
1.732 raeburn 953: if ($topic) {
1.763 bisitz 954: $addOther = '<span>'.&Apache::loncommon::help_open_topic($topic,&mt($text),
955: undef, undef, 600).
956: '</span> ';
957: }
958: $out = '<span>' # Start cheatsheet
959: .$addOther
960: .'<span>'
961: .&Apache::loncommon::help_open_topic('Greek_Symbols',&mt('Greek Symbols'),
962: undef,undef,600)
963: .'</span> <span>'
964: .&Apache::loncommon::help_open_topic('Other_Symbols',&mt('Other Symbols'),
965: undef,undef,600)
966: .'</span>';
1.732 raeburn 967: unless ($not_author) {
1.763 bisitz 968: $out .= ' <span>'
969: .&Apache::loncommon::help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),
970: undef,undef,600)
971: .'</span>';
1.732 raeburn 972: }
1.763 bisitz 973: $out .= '</span>'; # End cheatsheet
1.732 raeburn 974: return $out;
1.172 www 975: }
976:
1.430 albertel 977: sub general_help {
978: my $helptopic='Student_Intro';
979: if ($env{'request.role'}=~/^(ca|au)/) {
980: $helptopic='Authoring_Intro';
981: } elsif ($env{'request.role'}=~/^cc/) {
982: $helptopic='Course_Coordination_Intro';
1.672 raeburn 983: } elsif ($env{'request.role'}=~/^dc/) {
984: $helptopic='Domain_Coordination_Intro';
1.430 albertel 985: }
986: return $helptopic;
987: }
988:
989: sub update_help_link {
990: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
991: my $origurl = $ENV{'REQUEST_URI'};
992: $origurl=~s|^/~|/priv/|;
993: my $timestamp = time;
994: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
995: $$datum = &escape($$datum);
996: }
997:
998: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
999: my $output .= <<"ENDOUTPUT";
1000: <script type="text/javascript">
1001: banner_link = '$banner_link';
1002: </script>
1003: ENDOUTPUT
1004: return $output;
1005: }
1006:
1007: # now just updates the help link and generates a blue icon
1.193 raeburn 1008: sub help_open_menu {
1.430 albertel 1009: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1010: = @_;
1.430 albertel 1011: $stayOnPage = 0 if (not defined $stayOnPage);
1.572 banghart 1012: # only use pop-up help (stayOnPage == 0)
1.552 banghart 1013: # if environment.remote is on (using remote control UI)
1.572 banghart 1014: if ($env{'browser.interface'} eq 'textual' ||
1015: $env{'environment.remote'} eq 'off' ) {
1.552 banghart 1016: $stayOnPage=1;
1.430 albertel 1017: }
1018: my $output;
1019: if ($component_help) {
1020: if (!$text) {
1021: $output=&help_open_topic($component_help,undef,$stayOnPage,
1022: $width,$height);
1023: } else {
1024: my $help_text;
1025: $help_text=&unescape($topic);
1026: $output='<table><tr><td>'.
1027: &help_open_topic($component_help,$help_text,$stayOnPage,
1028: $width,$height).'</td></tr></table>';
1029: }
1030: }
1031: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1032: return $output.$banner_link;
1033: }
1034:
1035: sub top_nav_help {
1036: my ($text) = @_;
1.436 albertel 1037: $text = &mt($text);
1.572 banghart 1038: my $stay_on_page =
1.436 albertel 1039: ($env{'browser.interface'} eq 'textual' ||
1040: $env{'environment.remote'} eq 'off' );
1.572 banghart 1041: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436 albertel 1042: : "javascript:helpMenu('open')";
1.572 banghart 1043: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436 albertel 1044:
1.201 raeburn 1045: my $title = &mt('Get help');
1.436 albertel 1046:
1047: return <<"END";
1048: $banner_link
1049: <a href="$link" title="$title">$text</a>
1050: END
1051: }
1052:
1053: sub help_menu_js {
1054: my ($text) = @_;
1055:
1056: my $stayOnPage =
1057: ($env{'browser.interface'} eq 'textual' ||
1058: $env{'environment.remote'} eq 'off' );
1059:
1060: my $width = 620;
1061: my $height = 600;
1.430 albertel 1062: my $helptopic=&general_help();
1063: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1064: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1065: my $start_page =
1066: &Apache::loncommon::start_page('Help Menu', undef,
1067: {'frameset' => 1,
1068: 'js_ready' => 1,
1069: 'add_entries' => {
1070: 'border' => '0',
1.579 raeburn 1071: 'rows' => "110,*",},});
1.331 albertel 1072: my $end_page =
1073: &Apache::loncommon::end_page({'frameset' => 1,
1074: 'js_ready' => 1,});
1075:
1.436 albertel 1076: my $template .= <<"ENDTEMPLATE";
1077: <script type="text/javascript">
1.253 albertel 1078: // <!-- BEGIN LON-CAPA Internal
1079: // <![CDATA[
1.430 albertel 1080: var banner_link = '';
1.243 raeburn 1081: function helpMenu(target) {
1082: var caller = this;
1083: if (target == 'open') {
1084: var newWindow = null;
1085: try {
1.262 albertel 1086: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1087: }
1088: catch(error) {
1089: writeHelp(caller);
1090: return;
1091: }
1092: if (newWindow) {
1093: caller = newWindow;
1094: }
1.193 raeburn 1095: }
1.243 raeburn 1096: writeHelp(caller);
1097: return;
1098: }
1099: function writeHelp(caller) {
1.430 albertel 1100: caller.document.writeln('$start_page<frame name="bannerframe" src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243 raeburn 1101: caller.document.close()
1102: caller.focus()
1.193 raeburn 1103: }
1.253 albertel 1104: // ]]>
1.219 albertel 1105: // END LON-CAPA Internal -->
1.436 albertel 1106: </script>
1.193 raeburn 1107: ENDTEMPLATE
1108: return $template;
1109: }
1110:
1.172 www 1111: sub help_open_bug {
1112: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1113: unless ($env{'user.adv'}) { return ''; }
1.172 www 1114: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1115: $text = "" if (not defined $text);
1116: $stayOnPage = 0 if (not defined $stayOnPage);
1.258 albertel 1117: if ($env{'browser.interface'} eq 'textual' ||
1118: $env{'environment.remote'} eq 'off' ) {
1.172 www 1119: $stayOnPage=1;
1120: }
1.184 albertel 1121: $width = 600 if (not defined $width);
1122: $height = 600 if (not defined $height);
1.172 www 1123:
1124: $topic=~s/\W+/\+/g;
1125: my $link='';
1126: my $template='';
1.379 albertel 1127: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1128: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1129: if (!$stayOnPage)
1130: {
1131: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1132: }
1133: else
1134: {
1135: $link = $url;
1136: }
1137: # Add the text
1138: if ($text ne "")
1139: {
1140: $template .=
1141: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1142: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1143: }
1144:
1145: # Add the graphic
1.179 matthew 1146: my $title = &mt('Report a Bug');
1.215 albertel 1147: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1148: $template .= <<"ENDTEMPLATE";
1.436 albertel 1149: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1150: ENDTEMPLATE
1151: if ($text ne '') { $template.='</td></tr></table>' };
1152: return $template;
1153:
1154: }
1155:
1156: sub help_open_faq {
1157: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1158: unless ($env{'user.adv'}) { return ''; }
1.172 www 1159: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1160: $text = "" if (not defined $text);
1161: $stayOnPage = 0 if (not defined $stayOnPage);
1.258 albertel 1162: if ($env{'browser.interface'} eq 'textual' ||
1163: $env{'environment.remote'} eq 'off' ) {
1.172 www 1164: $stayOnPage=1;
1165: }
1166: $width = 350 if (not defined $width);
1167: $height = 400 if (not defined $height);
1168:
1169: $topic=~s/\W+/\+/g;
1170: my $link='';
1171: my $template='';
1172: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1173: if (!$stayOnPage)
1174: {
1175: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1176: }
1177: else
1178: {
1179: $link = $url;
1180: }
1181:
1182: # Add the text
1183: if ($text ne "")
1184: {
1185: $template .=
1.173 www 1186: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1187: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1188: }
1189:
1190: # Add the graphic
1.179 matthew 1191: my $title = &mt('View the FAQ');
1.215 albertel 1192: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1193: $template .= <<"ENDTEMPLATE";
1.436 albertel 1194: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1195: ENDTEMPLATE
1196: if ($text ne '') { $template.='</td></tr></table>' };
1197: return $template;
1198:
1.44 bowersj2 1199: }
1.37 matthew 1200:
1.180 matthew 1201: ###############################################################
1202: ###############################################################
1203:
1.45 matthew 1204: =pod
1205:
1.648 raeburn 1206: =item * &change_content_javascript():
1.256 matthew 1207:
1208: This and the next function allow you to create small sections of an
1209: otherwise static HTML page that you can update on the fly with
1210: Javascript, even in Netscape 4.
1211:
1212: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1213: must be written to the HTML page once. It will prove the Javascript
1214: function "change(name, content)". Calling the change function with the
1215: name of the section
1216: you want to update, matching the name passed to C<changable_area>, and
1217: the new content you want to put in there, will put the content into
1218: that area.
1219:
1220: B<Note>: Netscape 4 only reserves enough space for the changable area
1221: to contain room for the original contents. You need to "make space"
1222: for whatever changes you wish to make, and be B<sure> to check your
1223: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1224: it's adequate for updating a one-line status display, but little more.
1225: This script will set the space to 100% width, so you only need to
1226: worry about height in Netscape 4.
1227:
1228: Modern browsers are much less limiting, and if you can commit to the
1229: user not using Netscape 4, this feature may be used freely with
1230: pretty much any HTML.
1231:
1232: =cut
1233:
1234: sub change_content_javascript {
1235: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1236: if ($env{'browser.type'} eq 'netscape' &&
1237: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1238: return (<<NETSCAPE4);
1239: function change(name, content) {
1240: doc = document.layers[name+"___escape"].layers[0].document;
1241: doc.open();
1242: doc.write(content);
1243: doc.close();
1244: }
1245: NETSCAPE4
1246: } else {
1247: # Otherwise, we need to use semi-standards-compliant code
1248: # (technically, "innerHTML" isn't standard but the equivalent
1249: # is really scary, and every useful browser supports it
1250: return (<<DOMBASED);
1251: function change(name, content) {
1252: element = document.getElementById(name);
1253: element.innerHTML = content;
1254: }
1255: DOMBASED
1256: }
1257: }
1258:
1259: =pod
1260:
1.648 raeburn 1261: =item * &changable_area($name,$origContent):
1.256 matthew 1262:
1263: This provides a "changable area" that can be modified on the fly via
1264: the Javascript code provided in C<change_content_javascript>. $name is
1265: the name you will use to reference the area later; do not repeat the
1266: same name on a given HTML page more then once. $origContent is what
1267: the area will originally contain, which can be left blank.
1268:
1269: =cut
1270:
1271: sub changable_area {
1272: my ($name, $origContent) = @_;
1273:
1.258 albertel 1274: if ($env{'browser.type'} eq 'netscape' &&
1275: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1276: # If this is netscape 4, we need to use the Layer tag
1277: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1278: } else {
1279: return "<span id='$name'>$origContent</span>";
1280: }
1281: }
1282:
1283: =pod
1284:
1.648 raeburn 1285: =item * &viewport_geometry_js
1.590 raeburn 1286:
1287: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1288:
1289: =cut
1290:
1291:
1292: sub viewport_geometry_js {
1293: return <<"GEOMETRY";
1294: var Geometry = {};
1295: function init_geometry() {
1296: if (Geometry.init) { return };
1297: Geometry.init=1;
1298: if (window.innerHeight) {
1299: Geometry.getViewportHeight = function() { return window.innerHeight; };
1300: Geometry.getViewportWidth = function() { return window.innerWidth; };
1301: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1302: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1303: }
1304: else if (document.documentElement && document.documentElement.clientHeight) {
1305: Geometry.getViewportHeight =
1306: function() { return document.documentElement.clientHeight; };
1307: Geometry.getViewportWidth =
1308: function() { return document.documentElement.clientWidth; };
1309:
1310: Geometry.getHorizontalScroll =
1311: function() { return document.documentElement.scrollLeft; };
1312: Geometry.getVerticalScroll =
1313: function() { return document.documentElement.scrollTop; };
1314: }
1315: else if (document.body.clientHeight) {
1316: Geometry.getViewportHeight =
1317: function() { return document.body.clientHeight; };
1318: Geometry.getViewportWidth =
1319: function() { return document.body.clientWidth; };
1320: Geometry.getHorizontalScroll =
1321: function() { return document.body.scrollLeft; };
1322: Geometry.getVerticalScroll =
1323: function() { return document.body.scrollTop; };
1324: }
1325: }
1326:
1327: GEOMETRY
1328: }
1329:
1330: =pod
1331:
1.648 raeburn 1332: =item * &viewport_size_js()
1.590 raeburn 1333:
1334: 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.
1335:
1336: =cut
1337:
1338: sub viewport_size_js {
1339: my $geometry = &viewport_geometry_js();
1340: return <<"DIMS";
1341:
1342: $geometry
1343:
1344: function getViewportDims(width,height) {
1345: init_geometry();
1346: width.value = Geometry.getViewportWidth();
1347: height.value = Geometry.getViewportHeight();
1348: return;
1349: }
1350:
1351: DIMS
1352: }
1353:
1354: =pod
1355:
1.648 raeburn 1356: =item * &resize_textarea_js()
1.565 albertel 1357:
1358: emits the needed javascript to resize a textarea to be as big as possible
1359:
1360: creates a function resize_textrea that takes two IDs first should be
1361: the id of the element to resize, second should be the id of a div that
1362: surrounds everything that comes after the textarea, this routine needs
1363: to be attached to the <body> for the onload and onresize events.
1364:
1.648 raeburn 1365: =back
1.565 albertel 1366:
1367: =cut
1368:
1369: sub resize_textarea_js {
1.590 raeburn 1370: my $geometry = &viewport_geometry_js();
1.565 albertel 1371: return <<"RESIZE";
1372: <script type="text/javascript">
1.590 raeburn 1373: $geometry
1.565 albertel 1374:
1.588 albertel 1375: function getX(element) {
1376: var x = 0;
1377: while (element) {
1378: x += element.offsetLeft;
1379: element = element.offsetParent;
1380: }
1381: return x;
1382: }
1383: function getY(element) {
1384: var y = 0;
1385: while (element) {
1386: y += element.offsetTop;
1387: element = element.offsetParent;
1388: }
1389: return y;
1390: }
1391:
1392:
1.565 albertel 1393: function resize_textarea(textarea_id,bottom_id) {
1394: init_geometry();
1395: var textarea = document.getElementById(textarea_id);
1396: //alert(textarea);
1397:
1.588 albertel 1398: var textarea_top = getY(textarea);
1.565 albertel 1399: var textarea_height = textarea.offsetHeight;
1400: var bottom = document.getElementById(bottom_id);
1.588 albertel 1401: var bottom_top = getY(bottom);
1.565 albertel 1402: var bottom_height = bottom.offsetHeight;
1403: var window_height = Geometry.getViewportHeight();
1.588 albertel 1404: var fudge = 23;
1.565 albertel 1405: var new_height = window_height-fudge-textarea_top-bottom_height;
1406: if (new_height < 300) {
1407: new_height = 300;
1408: }
1409: textarea.style.height=new_height+'px';
1410: }
1411: </script>
1412: RESIZE
1413:
1414: }
1415:
1416: =pod
1417:
1.256 matthew 1418: =head1 Excel and CSV file utility routines
1419:
1420: =over 4
1421:
1422: =cut
1423:
1424: ###############################################################
1425: ###############################################################
1426:
1427: =pod
1428:
1.648 raeburn 1429: =item * &csv_translate($text)
1.37 matthew 1430:
1.185 www 1431: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1432: format.
1433:
1434: =cut
1435:
1.180 matthew 1436: ###############################################################
1437: ###############################################################
1.37 matthew 1438: sub csv_translate {
1439: my $text = shift;
1440: $text =~ s/\"/\"\"/g;
1.209 albertel 1441: $text =~ s/\n/ /g;
1.37 matthew 1442: return $text;
1443: }
1.180 matthew 1444:
1445: ###############################################################
1446: ###############################################################
1447:
1448: =pod
1449:
1.648 raeburn 1450: =item * &define_excel_formats()
1.180 matthew 1451:
1452: Define some commonly used Excel cell formats.
1453:
1454: Currently supported formats:
1455:
1456: =over 4
1457:
1458: =item header
1459:
1460: =item bold
1461:
1462: =item h1
1463:
1464: =item h2
1465:
1466: =item h3
1467:
1.256 matthew 1468: =item h4
1469:
1470: =item i
1471:
1.180 matthew 1472: =item date
1473:
1474: =back
1475:
1476: Inputs: $workbook
1477:
1478: Returns: $format, a hash reference.
1479:
1480: =cut
1481:
1482: ###############################################################
1483: ###############################################################
1484: sub define_excel_formats {
1485: my ($workbook) = @_;
1486: my $format;
1487: $format->{'header'} = $workbook->add_format(bold => 1,
1488: bottom => 1,
1489: align => 'center');
1490: $format->{'bold'} = $workbook->add_format(bold=>1);
1491: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1492: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1493: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1494: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1495: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1496: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1497: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1498: return $format;
1499: }
1500:
1501: ###############################################################
1502: ###############################################################
1.113 bowersj2 1503:
1504: =pod
1505:
1.648 raeburn 1506: =item * &create_workbook()
1.255 matthew 1507:
1508: Create an Excel worksheet. If it fails, output message on the
1509: request object and return undefs.
1510:
1511: Inputs: Apache request object
1512:
1513: Returns (undef) on failure,
1514: Excel worksheet object, scalar with filename, and formats
1515: from &Apache::loncommon::define_excel_formats on success
1516:
1517: =cut
1518:
1519: ###############################################################
1520: ###############################################################
1521: sub create_workbook {
1522: my ($r) = @_;
1523: #
1524: # Create the excel spreadsheet
1525: my $filename = '/prtspool/'.
1.258 albertel 1526: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1527: time.'_'.rand(1000000000).'.xls';
1528: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1529: if (! defined($workbook)) {
1530: $r->log_error("Error creating excel spreadsheet $filename: $!");
1531: $r->print('<p>'.&mt("Unable to create new Excel file. ".
1532: "This error has been logged. ".
1533: "Please alert your LON-CAPA administrator").
1534: '</p>');
1535: return (undef);
1536: }
1537: #
1538: $workbook->set_tempdir('/home/httpd/perl/tmp');
1539: #
1540: my $format = &Apache::loncommon::define_excel_formats($workbook);
1541: return ($workbook,$filename,$format);
1542: }
1543:
1544: ###############################################################
1545: ###############################################################
1546:
1547: =pod
1548:
1.648 raeburn 1549: =item * &create_text_file()
1.113 bowersj2 1550:
1.542 raeburn 1551: Create a file to write to and eventually make available to the user.
1.256 matthew 1552: If file creation fails, outputs an error message on the request object and
1553: return undefs.
1.113 bowersj2 1554:
1.256 matthew 1555: Inputs: Apache request object, and file suffix
1.113 bowersj2 1556:
1.256 matthew 1557: Returns (undef) on failure,
1558: Filehandle and filename on success.
1.113 bowersj2 1559:
1560: =cut
1561:
1.256 matthew 1562: ###############################################################
1563: ###############################################################
1564: sub create_text_file {
1565: my ($r,$suffix) = @_;
1566: if (! defined($suffix)) { $suffix = 'txt'; };
1567: my $fh;
1568: my $filename = '/prtspool/'.
1.258 albertel 1569: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1570: time.'_'.rand(1000000000).'.'.$suffix;
1571: $fh = Apache::File->new('>/home/httpd'.$filename);
1572: if (! defined($fh)) {
1573: $r->log_error("Couldn't open $filename for output $!");
1.683 bisitz 1574: $r->print(&mt('Problems occurred in creating the output file. '
1575: .'This error has been logged. '
1576: .'Please alert your LON-CAPA administrator.'));
1.113 bowersj2 1577: }
1.256 matthew 1578: return ($fh,$filename)
1.113 bowersj2 1579: }
1580:
1581:
1.256 matthew 1582: =pod
1.113 bowersj2 1583:
1584: =back
1585:
1586: =cut
1.37 matthew 1587:
1588: ###############################################################
1.33 matthew 1589: ## Home server <option> list generating code ##
1590: ###############################################################
1.35 matthew 1591:
1.169 www 1592: # ------------------------------------------
1593:
1594: sub domain_select {
1595: my ($name,$value,$multiple)=@_;
1596: my %domains=map {
1.514 albertel 1597: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1598: } &Apache::lonnet::all_domains();
1.169 www 1599: if ($multiple) {
1600: $domains{''}=&mt('Any domain');
1.550 albertel 1601: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1602: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1603: } else {
1.550 albertel 1604: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.169 www 1605: return &select_form($name,$value,%domains);
1606: }
1607: }
1608:
1.282 albertel 1609: #-------------------------------------------
1610:
1611: =pod
1612:
1.519 raeburn 1613: =head1 Routines for form select boxes
1614:
1615: =over 4
1616:
1.648 raeburn 1617: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1618:
1619: Returns a string containing a <select> element int multiple mode
1620:
1621:
1622: Args:
1623: $name - name of the <select> element
1.506 raeburn 1624: $value - scalar or array ref of values that should already be selected
1.282 albertel 1625: $size - number of rows long the select element is
1.283 albertel 1626: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1627: (shown text should already have been &mt())
1.506 raeburn 1628: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1629:
1.282 albertel 1630: =cut
1631:
1632: #-------------------------------------------
1.169 www 1633: sub multiple_select_form {
1.284 albertel 1634: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1635: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1636: my $output='';
1.191 matthew 1637: if (! defined($size)) {
1638: $size = 4;
1.283 albertel 1639: if (scalar(keys(%$hash))<4) {
1640: $size = scalar(keys(%$hash));
1.191 matthew 1641: }
1642: }
1.734 bisitz 1643: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 1644: my @order;
1.506 raeburn 1645: if (ref($order) eq 'ARRAY') {
1646: @order = @{$order};
1647: } else {
1648: @order = sort(keys(%$hash));
1.501 banghart 1649: }
1650: if (exists($$hash{'select_form_order'})) {
1651: @order = @{$$hash{'select_form_order'}};
1652: }
1653:
1.284 albertel 1654: foreach my $key (@order) {
1.356 albertel 1655: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1656: $output.='selected="selected" ' if ($selected{$key});
1657: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1658: }
1659: $output.="</select>\n";
1660: return $output;
1661: }
1662:
1.88 www 1663: #-------------------------------------------
1664:
1665: =pod
1666:
1.648 raeburn 1667: =item * &select_form($defdom,$name,%hash)
1.88 www 1668:
1669: Returns a string containing a <select name='$name' size='1'> form to
1670: allow a user to select options from a hash option_name => displayed text.
1671: See lonrights.pm for an example invocation and use.
1672:
1673: =cut
1674:
1675: #-------------------------------------------
1676: sub select_form {
1677: my ($def,$name,%hash) = @_;
1678: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1.128 albertel 1679: my @keys;
1680: if (exists($hash{'select_form_order'})) {
1681: @keys=@{$hash{'select_form_order'}};
1682: } else {
1683: @keys=sort(keys(%hash));
1684: }
1.356 albertel 1685: foreach my $key (@keys) {
1686: $selectform.=
1687: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
1688: ($key eq $def ? 'selected="selected" ' : '').
1689: ">".&mt($hash{$key})."</option>\n";
1.88 www 1690: }
1691: $selectform.="</select>";
1692: return $selectform;
1693: }
1694:
1.475 www 1695: # For display filters
1696:
1697: sub display_filter {
1698: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 1699: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.714 bisitz 1700: return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1.475 www 1701: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
1702: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 1703: '</label></span> <span class="LC_nobreak">'.
1.475 www 1704: &mt('Filter [_1]',
1.477 www 1705: &select_form($env{'form.displayfilter'},
1706: 'displayfilter',
1707: ('currentfolder' => 'Current folder/page',
1708: 'containing' => 'Containing phrase',
1709: 'none' => 'None'))).
1.714 bisitz 1710: '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1.475 www 1711: }
1712:
1.167 www 1713: sub gradeleveldescription {
1714: my $gradelevel=shift;
1715: my %gradelevels=(0 => 'Not specified',
1716: 1 => 'Grade 1',
1717: 2 => 'Grade 2',
1718: 3 => 'Grade 3',
1719: 4 => 'Grade 4',
1720: 5 => 'Grade 5',
1721: 6 => 'Grade 6',
1722: 7 => 'Grade 7',
1723: 8 => 'Grade 8',
1724: 9 => 'Grade 9',
1725: 10 => 'Grade 10',
1726: 11 => 'Grade 11',
1727: 12 => 'Grade 12',
1728: 13 => 'Grade 13',
1729: 14 => '100 Level',
1730: 15 => '200 Level',
1731: 16 => '300 Level',
1732: 17 => '400 Level',
1733: 18 => 'Graduate Level');
1734: return &mt($gradelevels{$gradelevel});
1735: }
1736:
1.163 www 1737: sub select_level_form {
1738: my ($deflevel,$name)=@_;
1739: unless ($deflevel) { $deflevel=0; }
1.167 www 1740: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1741: for (my $i=0; $i<=18; $i++) {
1742: $selectform.="<option value=\"$i\" ".
1.253 albertel 1743: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 1744: ">".&gradeleveldescription($i)."</option>\n";
1745: }
1746: $selectform.="</select>";
1747: return $selectform;
1.163 www 1748: }
1.167 www 1749:
1.35 matthew 1750: #-------------------------------------------
1751:
1.45 matthew 1752: =pod
1753:
1.743 raeburn 1754: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$autosubmit)
1.35 matthew 1755:
1756: Returns a string containing a <select name='$name' size='1'> form to
1757: allow a user to select the domain to preform an operation in.
1758: See loncreateuser.pm for an example invocation and use.
1759:
1.90 www 1760: If the $includeempty flag is set, it also includes an empty choice ("no domain
1761: selected");
1762:
1.743 raeburn 1763: If the $showdomdesc flag is set, the domain name is followed by the domain description.
1764:
1765: If the $autosubmit flag is set, the form containing the domain selector will be auto-submitted by an onchange action.
1.563 raeburn 1766:
1.35 matthew 1767: =cut
1768:
1769: #-------------------------------------------
1.34 matthew 1770: sub select_dom_form {
1.743 raeburn 1771: my ($defdom,$name,$includeempty,$showdomdesc,$autosubmit) = @_;
1772: my $onchange;
1773: if ($autosubmit) {
1774: $onchange = ' onchange="this.form.submit()"';
1775: }
1.550 albertel 1776: my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1.90 www 1777: if ($includeempty) { @domains=('',@domains); }
1.743 raeburn 1778: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 1779: foreach my $dom (@domains) {
1780: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 1781: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
1782: if ($showdomdesc) {
1783: if ($dom ne '') {
1784: my $domdesc = &Apache::lonnet::domain($dom,'description');
1785: if ($domdesc ne '') {
1786: $selectdomain .= ' ('.$domdesc.')';
1787: }
1788: }
1789: }
1790: $selectdomain .= "</option>\n";
1.34 matthew 1791: }
1792: $selectdomain.="</select>";
1793: return $selectdomain;
1794: }
1795:
1.35 matthew 1796: #-------------------------------------------
1797:
1.45 matthew 1798: =pod
1799:
1.648 raeburn 1800: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 1801:
1.586 raeburn 1802: input: 4 arguments (two required, two optional) -
1803: $domain - domain of new user
1804: $name - name of form element
1805: $default - Value of 'default' causes a default item to be first
1806: option, and selected by default.
1807: $hide - Value of 'hide' causes hiding of the name of the server,
1808: if 1 server found, or default, if 0 found.
1.594 raeburn 1809: output: returns 2 items:
1.586 raeburn 1810: (a) form element which contains either:
1811: (i) <select name="$name">
1812: <option value="$hostid1">$hostid $servers{$hostid}</option>
1813: <option value="$hostid2">$hostid $servers{$hostid}</option>
1814: </select>
1815: form item if there are multiple library servers in $domain, or
1816: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
1817: if there is only one library server in $domain.
1818:
1819: (b) number of library servers found.
1820:
1821: See loncreateuser.pm for example of use.
1.35 matthew 1822:
1823: =cut
1824:
1825: #-------------------------------------------
1.586 raeburn 1826: sub home_server_form_item {
1827: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 1828: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 1829: my $result;
1830: my $numlib = keys(%servers);
1831: if ($numlib > 1) {
1832: $result .= '<select name="'.$name.'" />'."\n";
1833: if ($default) {
1834: $result .= '<option value="default" selected>'.&mt('default').
1835: '</option>'."\n";
1836: }
1837: foreach my $hostid (sort(keys(%servers))) {
1838: $result.= '<option value="'.$hostid.'">'.
1839: $hostid.' '.$servers{$hostid}."</option>\n";
1840: }
1841: $result .= '</select>'."\n";
1842: } elsif ($numlib == 1) {
1843: my $hostid;
1844: foreach my $item (keys(%servers)) {
1845: $hostid = $item;
1846: }
1847: $result .= '<input type="hidden" name="'.$name.'" value="'.
1848: $hostid.'" />';
1849: if (!$hide) {
1850: $result .= $hostid.' '.$servers{$hostid};
1851: }
1852: $result .= "\n";
1853: } elsif ($default) {
1854: $result .= '<input type="hidden" name="'.$name.
1855: '" value="default" />';
1856: if (!$hide) {
1857: $result .= &mt('default');
1858: }
1859: $result .= "\n";
1.33 matthew 1860: }
1.586 raeburn 1861: return ($result,$numlib);
1.33 matthew 1862: }
1.112 bowersj2 1863:
1864: =pod
1865:
1.534 albertel 1866: =back
1867:
1.112 bowersj2 1868: =cut
1.87 matthew 1869:
1870: ###############################################################
1.112 bowersj2 1871: ## Decoding User Agent ##
1.87 matthew 1872: ###############################################################
1873:
1874: =pod
1875:
1.112 bowersj2 1876: =head1 Decoding the User Agent
1877:
1878: =over 4
1879:
1880: =item * &decode_user_agent()
1.87 matthew 1881:
1882: Inputs: $r
1883:
1884: Outputs:
1885:
1886: =over 4
1887:
1.112 bowersj2 1888: =item * $httpbrowser
1.87 matthew 1889:
1.112 bowersj2 1890: =item * $clientbrowser
1.87 matthew 1891:
1.112 bowersj2 1892: =item * $clientversion
1.87 matthew 1893:
1.112 bowersj2 1894: =item * $clientmathml
1.87 matthew 1895:
1.112 bowersj2 1896: =item * $clientunicode
1.87 matthew 1897:
1.112 bowersj2 1898: =item * $clientos
1.87 matthew 1899:
1900: =back
1901:
1.157 matthew 1902: =back
1903:
1.87 matthew 1904: =cut
1905:
1906: ###############################################################
1907: ###############################################################
1908: sub decode_user_agent {
1.247 albertel 1909: my ($r)=@_;
1.87 matthew 1910: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
1911: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
1912: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 1913: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 1914: my $clientbrowser='unknown';
1915: my $clientversion='0';
1916: my $clientmathml='';
1917: my $clientunicode='0';
1918: for (my $i=0;$i<=$#browsertype;$i++) {
1919: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
1920: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
1921: $clientbrowser=$bname;
1922: $httpbrowser=~/$vreg/i;
1923: $clientversion=$1;
1924: $clientmathml=($clientversion>=$minv);
1925: $clientunicode=($clientversion>=$univ);
1926: }
1927: }
1928: my $clientos='unknown';
1929: if (($httpbrowser=~/linux/i) ||
1930: ($httpbrowser=~/unix/i) ||
1931: ($httpbrowser=~/ux/i) ||
1932: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
1933: if (($httpbrowser=~/vax/i) ||
1934: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
1935: if ($httpbrowser=~/next/i) { $clientos='next'; }
1936: if (($httpbrowser=~/mac/i) ||
1937: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1938: if ($httpbrowser=~/win/i) { $clientos='win'; }
1939: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1940: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1941: $clientunicode,$clientos,);
1942: }
1943:
1.32 matthew 1944: ###############################################################
1945: ## Authentication changing form generation subroutines ##
1946: ###############################################################
1947: ##
1948: ## All of the authform_xxxxxxx subroutines take their inputs in a
1949: ## hash, and have reasonable default values.
1950: ##
1951: ## formname = the name given in the <form> tag.
1.35 matthew 1952: #-------------------------------------------
1953:
1.45 matthew 1954: =pod
1955:
1.112 bowersj2 1956: =head1 Authentication Routines
1957:
1958: =over 4
1959:
1.648 raeburn 1960: =item * &authform_xxxxxx()
1.35 matthew 1961:
1962: The authform_xxxxxx subroutines provide javascript and html forms which
1963: handle some of the conveniences required for authentication forms.
1964: This is not an optimal method, but it works.
1965:
1966: =over 4
1967:
1.112 bowersj2 1968: =item * authform_header
1.35 matthew 1969:
1.112 bowersj2 1970: =item * authform_authorwarning
1.35 matthew 1971:
1.112 bowersj2 1972: =item * authform_nochange
1.35 matthew 1973:
1.112 bowersj2 1974: =item * authform_kerberos
1.35 matthew 1975:
1.112 bowersj2 1976: =item * authform_internal
1.35 matthew 1977:
1.112 bowersj2 1978: =item * authform_filesystem
1.35 matthew 1979:
1980: =back
1981:
1.648 raeburn 1982: See loncreateuser.pm for invocation and use examples.
1.157 matthew 1983:
1.35 matthew 1984: =cut
1985:
1986: #-------------------------------------------
1.32 matthew 1987: sub authform_header{
1988: my %in = (
1989: formname => 'cu',
1.80 albertel 1990: kerb_def_dom => '',
1.32 matthew 1991: @_,
1992: );
1993: $in{'formname'} = 'document.' . $in{'formname'};
1994: my $result='';
1.80 albertel 1995:
1996: #---------------------------------------------- Code for upper case translation
1997: my $Javascript_toUpperCase;
1998: unless ($in{kerb_def_dom}) {
1999: $Javascript_toUpperCase =<<"END";
2000: switch (choice) {
2001: case 'krb': currentform.elements[choicearg].value =
2002: currentform.elements[choicearg].value.toUpperCase();
2003: break;
2004: default:
2005: }
2006: END
2007: } else {
2008: $Javascript_toUpperCase = "";
2009: }
2010:
1.165 raeburn 2011: my $radioval = "'nochange'";
1.591 raeburn 2012: if (defined($in{'curr_authtype'})) {
2013: if ($in{'curr_authtype'} ne '') {
2014: $radioval = "'".$in{'curr_authtype'}."arg'";
2015: }
1.174 matthew 2016: }
1.165 raeburn 2017: my $argfield = 'null';
1.591 raeburn 2018: if (defined($in{'mode'})) {
1.165 raeburn 2019: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2020: if (defined($in{'curr_autharg'})) {
2021: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2022: $argfield = "'$in{'curr_autharg'}'";
2023: }
2024: }
2025: }
2026: }
2027:
1.32 matthew 2028: $result.=<<"END";
2029: var current = new Object();
1.165 raeburn 2030: current.radiovalue = $radioval;
2031: current.argfield = $argfield;
1.32 matthew 2032:
2033: function changed_radio(choice,currentform) {
2034: var choicearg = choice + 'arg';
2035: // If a radio button in changed, we need to change the argfield
2036: if (current.radiovalue != choice) {
2037: current.radiovalue = choice;
2038: if (current.argfield != null) {
2039: currentform.elements[current.argfield].value = '';
2040: }
2041: if (choice == 'nochange') {
2042: current.argfield = null;
2043: } else {
2044: current.argfield = choicearg;
2045: switch(choice) {
2046: case 'krb':
2047: currentform.elements[current.argfield].value =
2048: "$in{'kerb_def_dom'}";
2049: break;
2050: default:
2051: break;
2052: }
2053: }
2054: }
2055: return;
2056: }
1.22 www 2057:
1.32 matthew 2058: function changed_text(choice,currentform) {
2059: var choicearg = choice + 'arg';
2060: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2061: $Javascript_toUpperCase
1.32 matthew 2062: // clear old field
2063: if ((current.argfield != choicearg) && (current.argfield != null)) {
2064: currentform.elements[current.argfield].value = '';
2065: }
2066: current.argfield = choicearg;
2067: }
2068: set_auth_radio_buttons(choice,currentform);
2069: return;
1.20 www 2070: }
1.32 matthew 2071:
2072: function set_auth_radio_buttons(newvalue,currentform) {
2073: var i=0;
2074: while (i < currentform.login.length) {
2075: if (currentform.login[i].value == newvalue) { break; }
2076: i++;
2077: }
2078: if (i == currentform.login.length) {
2079: return;
2080: }
2081: current.radiovalue = newvalue;
2082: currentform.login[i].checked = true;
2083: return;
2084: }
2085: END
2086: return $result;
2087: }
2088:
2089: sub authform_authorwarning{
2090: my $result='';
1.144 matthew 2091: $result='<i>'.
2092: &mt('As a general rule, only authors or co-authors should be '.
2093: 'filesystem authenticated '.
2094: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2095: return $result;
2096: }
2097:
2098: sub authform_nochange{
2099: my %in = (
2100: formname => 'document.cu',
2101: kerb_def_dom => 'MSU.EDU',
2102: @_,
2103: );
1.586 raeburn 2104: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2105: my $result;
2106: if (keys(%can_assign) == 0) {
2107: $result = &mt('Under you current role you are not permitted to change login settings for this user');
2108: } else {
2109: $result = '<label>'.&mt('[_1] Do not change login data',
2110: '<input type="radio" name="login" value="nochange" '.
2111: 'checked="checked" onclick="'.
1.281 albertel 2112: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2113: '</label>';
1.586 raeburn 2114: }
1.32 matthew 2115: return $result;
2116: }
2117:
1.591 raeburn 2118: sub authform_kerberos {
1.32 matthew 2119: my %in = (
2120: formname => 'document.cu',
2121: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2122: kerb_def_auth => 'krb4',
1.32 matthew 2123: @_,
2124: );
1.586 raeburn 2125: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2126: $autharg,$jscall);
2127: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2128: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2129: $check5 = ' checked="checked"';
1.80 albertel 2130: } else {
1.772 bisitz 2131: $check4 = ' checked="checked"';
1.80 albertel 2132: }
1.165 raeburn 2133: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2134: if (defined($in{'curr_authtype'})) {
2135: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2136: $krbcheck = ' checked="checked"';
1.623 raeburn 2137: if (defined($in{'mode'})) {
2138: if ($in{'mode'} eq 'modifyuser') {
2139: $krbcheck = '';
2140: }
2141: }
1.591 raeburn 2142: if (defined($in{'curr_kerb_ver'})) {
2143: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2144: $check5 = ' checked="checked"';
1.591 raeburn 2145: $check4 = '';
2146: } else {
1.772 bisitz 2147: $check4 = ' checked="checked"';
1.591 raeburn 2148: $check5 = '';
2149: }
1.586 raeburn 2150: }
1.591 raeburn 2151: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2152: $krbarg = $in{'curr_autharg'};
2153: }
1.586 raeburn 2154: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2155: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2156: $result =
2157: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2158: $in{'curr_autharg'},$krbver);
2159: } else {
2160: $result =
2161: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2162: }
2163: return $result;
2164: }
2165: }
2166: } else {
2167: if ($authnum == 1) {
2168: $authtype = '<input type="hidden" name="login" value="krb">';
1.165 raeburn 2169: }
2170: }
1.586 raeburn 2171: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2172: return;
1.587 raeburn 2173: } elsif ($authtype eq '') {
1.591 raeburn 2174: if (defined($in{'mode'})) {
1.587 raeburn 2175: if ($in{'mode'} eq 'modifycourse') {
2176: if ($authnum == 1) {
2177: $authtype = '<input type="hidden" name="login" value="krb">';
2178: }
2179: }
2180: }
1.586 raeburn 2181: }
2182: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2183: if ($authtype eq '') {
2184: $authtype = '<input type="radio" name="login" value="krb" '.
2185: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2186: $krbcheck.' />';
2187: }
2188: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
2189: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
2190: $in{'curr_authtype'} eq 'krb5') ||
2191: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
2192: $in{'curr_authtype'} eq 'krb4')) {
2193: $result .= &mt
1.144 matthew 2194: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2195: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2196: '<label>'.$authtype,
1.281 albertel 2197: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2198: 'value="'.$krbarg.'" '.
1.144 matthew 2199: 'onchange="'.$jscall.'" />',
1.281 albertel 2200: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2201: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2202: '</label>');
1.586 raeburn 2203: } elsif ($can_assign{'krb4'}) {
2204: $result .= &mt
2205: ('[_1] Kerberos authenticated with domain [_2] '.
2206: '[_3] Version 4 [_4]',
2207: '<label>'.$authtype,
2208: '</label><input type="text" size="10" name="krbarg" '.
2209: 'value="'.$krbarg.'" '.
2210: 'onchange="'.$jscall.'" />',
2211: '<label><input type="hidden" name="krbver" value="4" />',
2212: '</label>');
2213: } elsif ($can_assign{'krb5'}) {
2214: $result .= &mt
2215: ('[_1] Kerberos authenticated with domain [_2] '.
2216: '[_3] Version 5 [_4]',
2217: '<label>'.$authtype,
2218: '</label><input type="text" size="10" name="krbarg" '.
2219: 'value="'.$krbarg.'" '.
2220: 'onchange="'.$jscall.'" />',
2221: '<label><input type="hidden" name="krbver" value="5" />',
2222: '</label>');
2223: }
1.32 matthew 2224: return $result;
2225: }
2226:
2227: sub authform_internal{
1.586 raeburn 2228: my %in = (
1.32 matthew 2229: formname => 'document.cu',
2230: kerb_def_dom => 'MSU.EDU',
2231: @_,
2232: );
1.586 raeburn 2233: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
2234: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2235: if (defined($in{'curr_authtype'})) {
2236: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2237: if ($can_assign{'int'}) {
1.772 bisitz 2238: $intcheck = 'checked="checked" ';
1.623 raeburn 2239: if (defined($in{'mode'})) {
2240: if ($in{'mode'} eq 'modifyuser') {
2241: $intcheck = '';
2242: }
2243: }
1.591 raeburn 2244: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2245: $intarg = $in{'curr_autharg'};
2246: }
2247: } else {
2248: $result = &mt('Currently internally authenticated.');
2249: return $result;
1.165 raeburn 2250: }
2251: }
1.586 raeburn 2252: } else {
2253: if ($authnum == 1) {
2254: $authtype = '<input type="hidden" name="login" value="int">';
2255: }
2256: }
2257: if (!$can_assign{'int'}) {
2258: return;
1.587 raeburn 2259: } elsif ($authtype eq '') {
1.591 raeburn 2260: if (defined($in{'mode'})) {
1.587 raeburn 2261: if ($in{'mode'} eq 'modifycourse') {
2262: if ($authnum == 1) {
2263: $authtype = '<input type="hidden" name="login" value="int">';
2264: }
2265: }
2266: }
1.165 raeburn 2267: }
1.586 raeburn 2268: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2269: if ($authtype eq '') {
2270: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2271: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2272: }
1.605 bisitz 2273: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2274: $intarg.'" onchange="'.$jscall.'" />';
2275: $result = &mt
1.144 matthew 2276: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2277: '<label>'.$authtype,'</label>'.$autharg);
1.620 www 2278: $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>';
1.32 matthew 2279: return $result;
2280: }
2281:
2282: sub authform_local{
2283: my %in = (
2284: formname => 'document.cu',
2285: kerb_def_dom => 'MSU.EDU',
2286: @_,
2287: );
1.586 raeburn 2288: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
2289: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2290: if (defined($in{'curr_authtype'})) {
2291: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2292: if ($can_assign{'loc'}) {
1.772 bisitz 2293: $loccheck = 'checked="checked" ';
1.623 raeburn 2294: if (defined($in{'mode'})) {
2295: if ($in{'mode'} eq 'modifyuser') {
2296: $loccheck = '';
2297: }
2298: }
1.591 raeburn 2299: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2300: $locarg = $in{'curr_autharg'};
2301: }
2302: } else {
2303: $result = &mt('Currently using local (institutional) authentication.');
2304: return $result;
1.165 raeburn 2305: }
2306: }
1.586 raeburn 2307: } else {
2308: if ($authnum == 1) {
2309: $authtype = '<input type="hidden" name="login" value="loc">';
2310: }
2311: }
2312: if (!$can_assign{'loc'}) {
2313: return;
1.587 raeburn 2314: } elsif ($authtype eq '') {
1.591 raeburn 2315: if (defined($in{'mode'})) {
1.587 raeburn 2316: if ($in{'mode'} eq 'modifycourse') {
2317: if ($authnum == 1) {
2318: $authtype = '<input type="hidden" name="login" value="loc">';
2319: }
2320: }
2321: }
1.165 raeburn 2322: }
1.586 raeburn 2323: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2324: if ($authtype eq '') {
2325: $authtype = '<input type="radio" name="login" value="loc" '.
2326: $loccheck.' onchange="'.$jscall.'" onclick="'.
2327: $jscall.'" />';
2328: }
2329: $autharg = '<input type="text" size="10" name="locarg" value="'.
2330: $locarg.'" onchange="'.$jscall.'" />';
2331: $result = &mt('[_1] Local Authentication with argument [_2]',
2332: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2333: return $result;
2334: }
2335:
2336: sub authform_filesystem{
2337: my %in = (
2338: formname => 'document.cu',
2339: kerb_def_dom => 'MSU.EDU',
2340: @_,
2341: );
1.586 raeburn 2342: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
2343: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2344: if (defined($in{'curr_authtype'})) {
2345: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2346: if ($can_assign{'fsys'}) {
1.772 bisitz 2347: $fsyscheck = 'checked="checked" ';
1.623 raeburn 2348: if (defined($in{'mode'})) {
2349: if ($in{'mode'} eq 'modifyuser') {
2350: $fsyscheck = '';
2351: }
2352: }
1.586 raeburn 2353: } else {
2354: $result = &mt('Currently Filesystem Authenticated.');
2355: return $result;
2356: }
2357: }
2358: } else {
2359: if ($authnum == 1) {
2360: $authtype = '<input type="hidden" name="login" value="fsys">';
2361: }
2362: }
2363: if (!$can_assign{'fsys'}) {
2364: return;
1.587 raeburn 2365: } elsif ($authtype eq '') {
1.591 raeburn 2366: if (defined($in{'mode'})) {
1.587 raeburn 2367: if ($in{'mode'} eq 'modifycourse') {
2368: if ($authnum == 1) {
2369: $authtype = '<input type="hidden" name="login" value="fsys">';
2370: }
2371: }
2372: }
1.586 raeburn 2373: }
2374: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2375: if ($authtype eq '') {
2376: $authtype = '<input type="radio" name="login" value="fsys" '.
2377: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2378: $jscall.'" />';
2379: }
2380: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2381: ' onchange="'.$jscall.'" />';
2382: $result = &mt
1.144 matthew 2383: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2384: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2385: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2386: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2387: 'onchange="'.$jscall.'" />');
1.32 matthew 2388: return $result;
2389: }
2390:
1.586 raeburn 2391: sub get_assignable_auth {
2392: my ($dom) = @_;
2393: if ($dom eq '') {
2394: $dom = $env{'request.role.domain'};
2395: }
2396: my %can_assign = (
2397: krb4 => 1,
2398: krb5 => 1,
2399: int => 1,
2400: loc => 1,
2401: );
2402: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2403: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2404: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2405: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2406: my $context;
2407: if ($env{'request.role'} =~ /^au/) {
2408: $context = 'author';
2409: } elsif ($env{'request.role'} =~ /^dc/) {
2410: $context = 'domain';
2411: } elsif ($env{'request.course.id'}) {
2412: $context = 'course';
2413: }
2414: if ($context) {
2415: if (ref($authhash->{$context}) eq 'HASH') {
2416: %can_assign = %{$authhash->{$context}};
2417: }
2418: }
2419: }
2420: }
2421: my $authnum = 0;
2422: foreach my $key (keys(%can_assign)) {
2423: if ($can_assign{$key}) {
2424: $authnum ++;
2425: }
2426: }
2427: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2428: $authnum --;
2429: }
2430: return ($authnum,%can_assign);
2431: }
2432:
1.80 albertel 2433: ###############################################################
2434: ## Get Kerberos Defaults for Domain ##
2435: ###############################################################
2436: ##
2437: ## Returns default kerberos version and an associated argument
2438: ## as listed in file domain.tab. If not listed, provides
2439: ## appropriate default domain and kerberos version.
2440: ##
2441: #-------------------------------------------
2442:
2443: =pod
2444:
1.648 raeburn 2445: =item * &get_kerberos_defaults()
1.80 albertel 2446:
2447: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2448: version and domain. If not found, it defaults to version 4 and the
2449: domain of the server.
1.80 albertel 2450:
1.648 raeburn 2451: =over 4
2452:
1.80 albertel 2453: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2454:
1.648 raeburn 2455: =back
2456:
2457: =back
2458:
1.80 albertel 2459: =cut
2460:
2461: #-------------------------------------------
2462: sub get_kerberos_defaults {
2463: my $domain=shift;
1.641 raeburn 2464: my ($krbdef,$krbdefdom);
2465: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2466: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2467: $krbdef = $domdefaults{'auth_def'};
2468: $krbdefdom = $domdefaults{'auth_arg_def'};
2469: } else {
1.80 albertel 2470: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2471: my $krbdefdom=$1;
2472: $krbdefdom=~tr/a-z/A-Z/;
2473: $krbdef = "krb4";
2474: }
2475: return ($krbdef,$krbdefdom);
2476: }
1.112 bowersj2 2477:
1.32 matthew 2478:
1.46 matthew 2479: ###############################################################
2480: ## Thesaurus Functions ##
2481: ###############################################################
1.20 www 2482:
1.46 matthew 2483: =pod
1.20 www 2484:
1.112 bowersj2 2485: =head1 Thesaurus Functions
2486:
2487: =over 4
2488:
1.648 raeburn 2489: =item * &initialize_keywords()
1.46 matthew 2490:
2491: Initializes the package variable %Keywords if it is empty. Uses the
2492: package variable $thesaurus_db_file.
2493:
2494: =cut
2495:
2496: ###################################################
2497:
2498: sub initialize_keywords {
2499: return 1 if (scalar keys(%Keywords));
2500: # If we are here, %Keywords is empty, so fill it up
2501: # Make sure the file we need exists...
2502: if (! -e $thesaurus_db_file) {
2503: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2504: " failed because it does not exist");
2505: return 0;
2506: }
2507: # Set up the hash as a database
2508: my %thesaurus_db;
2509: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2510: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2511: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2512: $thesaurus_db_file);
2513: return 0;
2514: }
2515: # Get the average number of appearances of a word.
2516: my $avecount = $thesaurus_db{'average.count'};
2517: # Put keywords (those that appear > average) into %Keywords
2518: while (my ($word,$data)=each (%thesaurus_db)) {
2519: my ($count,undef) = split /:/,$data;
2520: $Keywords{$word}++ if ($count > $avecount);
2521: }
2522: untie %thesaurus_db;
2523: # Remove special values from %Keywords.
1.356 albertel 2524: foreach my $value ('total.count','average.count') {
2525: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2526: }
1.46 matthew 2527: return 1;
2528: }
2529:
2530: ###################################################
2531:
2532: =pod
2533:
1.648 raeburn 2534: =item * &keyword($word)
1.46 matthew 2535:
2536: Returns true if $word is a keyword. A keyword is a word that appears more
2537: than the average number of times in the thesaurus database. Calls
2538: &initialize_keywords
2539:
2540: =cut
2541:
2542: ###################################################
1.20 www 2543:
2544: sub keyword {
1.46 matthew 2545: return if (!&initialize_keywords());
2546: my $word=lc(shift());
2547: $word=~s/\W//g;
2548: return exists($Keywords{$word});
1.20 www 2549: }
1.46 matthew 2550:
2551: ###############################################################
2552:
2553: =pod
1.20 www 2554:
1.648 raeburn 2555: =item * &get_related_words()
1.46 matthew 2556:
1.160 matthew 2557: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 2558: an array of words. If the keyword is not in the thesaurus, an empty array
2559: will be returned. The order of the words returned is determined by the
2560: database which holds them.
2561:
2562: Uses global $thesaurus_db_file.
2563:
2564: =cut
2565:
2566: ###############################################################
2567: sub get_related_words {
2568: my $keyword = shift;
2569: my %thesaurus_db;
2570: if (! -e $thesaurus_db_file) {
2571: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
2572: "failed because the file does not exist");
2573: return ();
2574: }
2575: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2576: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2577: return ();
2578: }
2579: my @Words=();
1.429 www 2580: my $count=0;
1.46 matthew 2581: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 2582: # The first element is the number of times
2583: # the word appears. We do not need it now.
1.429 www 2584: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
2585: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
2586: my $threshold=$mostfrequentcount/10;
2587: foreach my $possibleword (@RelatedWords) {
2588: my ($word,$wordcount)=split(/\,/,$possibleword);
2589: if ($wordcount>$threshold) {
2590: push(@Words,$word);
2591: $count++;
2592: if ($count>10) { last; }
2593: }
1.20 www 2594: }
2595: }
1.46 matthew 2596: untie %thesaurus_db;
2597: return @Words;
1.14 harris41 2598: }
1.46 matthew 2599:
1.112 bowersj2 2600: =pod
2601:
2602: =back
2603:
2604: =cut
1.61 www 2605:
2606: # -------------------------------------------------------------- Plaintext name
1.81 albertel 2607: =pod
2608:
1.112 bowersj2 2609: =head1 User Name Functions
2610:
2611: =over 4
2612:
1.648 raeburn 2613: =item * &plainname($uname,$udom,$first)
1.81 albertel 2614:
1.112 bowersj2 2615: Takes a users logon name and returns it as a string in
1.226 albertel 2616: "first middle last generation" form
2617: if $first is set to 'lastname' then it returns it as
2618: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 2619:
2620: =cut
1.61 www 2621:
1.295 www 2622:
1.81 albertel 2623: ###############################################################
1.61 www 2624: sub plainname {
1.226 albertel 2625: my ($uname,$udom,$first)=@_;
1.537 albertel 2626: return if (!defined($uname) || !defined($udom));
1.295 www 2627: my %names=&getnames($uname,$udom);
1.226 albertel 2628: my $name=&Apache::lonnet::format_name($names{'firstname'},
2629: $names{'middlename'},
2630: $names{'lastname'},
2631: $names{'generation'},$first);
2632: $name=~s/^\s+//;
1.62 www 2633: $name=~s/\s+$//;
2634: $name=~s/\s+/ /g;
1.353 albertel 2635: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 2636: return $name;
1.61 www 2637: }
1.66 www 2638:
2639: # -------------------------------------------------------------------- Nickname
1.81 albertel 2640: =pod
2641:
1.648 raeburn 2642: =item * &nickname($uname,$udom)
1.81 albertel 2643:
2644: Gets a users name and returns it as a string as
2645:
2646: ""nickname""
1.66 www 2647:
1.81 albertel 2648: if the user has a nickname or
2649:
2650: "first middle last generation"
2651:
2652: if the user does not
2653:
2654: =cut
1.66 www 2655:
2656: sub nickname {
2657: my ($uname,$udom)=@_;
1.537 albertel 2658: return if (!defined($uname) || !defined($udom));
1.295 www 2659: my %names=&getnames($uname,$udom);
1.68 albertel 2660: my $name=$names{'nickname'};
1.66 www 2661: if ($name) {
2662: $name='"'.$name.'"';
2663: } else {
2664: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
2665: $names{'lastname'}.' '.$names{'generation'};
2666: $name=~s/\s+$//;
2667: $name=~s/\s+/ /g;
2668: }
2669: return $name;
2670: }
2671:
1.295 www 2672: sub getnames {
2673: my ($uname,$udom)=@_;
1.537 albertel 2674: return if (!defined($uname) || !defined($udom));
1.433 albertel 2675: if ($udom eq 'public' && $uname eq 'public') {
2676: return ('lastname' => &mt('Public'));
2677: }
1.295 www 2678: my $id=$uname.':'.$udom;
2679: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
2680: if ($cached) {
2681: return %{$names};
2682: } else {
2683: my %loadnames=&Apache::lonnet::get('environment',
2684: ['firstname','middlename','lastname','generation','nickname'],
2685: $udom,$uname);
2686: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
2687: return %loadnames;
2688: }
2689: }
1.61 www 2690:
1.542 raeburn 2691: # -------------------------------------------------------------------- getemails
1.648 raeburn 2692:
1.542 raeburn 2693: =pod
2694:
1.648 raeburn 2695: =item * &getemails($uname,$udom)
1.542 raeburn 2696:
2697: Gets a user's email information and returns it as a hash with keys:
2698: notification, critnotification, permanentemail
2699:
2700: For notification and critnotification, values are comma-separated lists
1.648 raeburn 2701: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 2702:
1.648 raeburn 2703:
1.542 raeburn 2704: =cut
2705:
1.648 raeburn 2706:
1.466 albertel 2707: sub getemails {
2708: my ($uname,$udom)=@_;
2709: if ($udom eq 'public' && $uname eq 'public') {
2710: return;
2711: }
1.467 www 2712: if (!$udom) { $udom=$env{'user.domain'}; }
2713: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 2714: my $id=$uname.':'.$udom;
2715: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
2716: if ($cached) {
2717: return %{$names};
2718: } else {
2719: my %loadnames=&Apache::lonnet::get('environment',
2720: ['notification','critnotification',
2721: 'permanentemail'],
2722: $udom,$uname);
2723: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
2724: return %loadnames;
2725: }
2726: }
2727:
1.551 albertel 2728: sub flush_email_cache {
2729: my ($uname,$udom)=@_;
2730: if (!$udom) { $udom =$env{'user.domain'}; }
2731: if (!$uname) { $uname=$env{'user.name'}; }
2732: return if ($udom eq 'public' && $uname eq 'public');
2733: my $id=$uname.':'.$udom;
2734: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
2735: }
2736:
1.728 raeburn 2737: # -------------------------------------------------------------------- getlangs
2738:
2739: =pod
2740:
2741: =item * &getlangs($uname,$udom)
2742:
2743: Gets a user's language preference and returns it as a hash with key:
2744: language.
2745:
2746: =cut
2747:
2748:
2749: sub getlangs {
2750: my ($uname,$udom) = @_;
2751: if (!$udom) { $udom =$env{'user.domain'}; }
2752: if (!$uname) { $uname=$env{'user.name'}; }
2753: my $id=$uname.':'.$udom;
2754: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
2755: if ($cached) {
2756: return %{$langs};
2757: } else {
2758: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
2759: $udom,$uname);
2760: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
2761: return %loadlangs;
2762: }
2763: }
2764:
2765: sub flush_langs_cache {
2766: my ($uname,$udom)=@_;
2767: if (!$udom) { $udom =$env{'user.domain'}; }
2768: if (!$uname) { $uname=$env{'user.name'}; }
2769: return if ($udom eq 'public' && $uname eq 'public');
2770: my $id=$uname.':'.$udom;
2771: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
2772: }
2773:
1.61 www 2774: # ------------------------------------------------------------------ Screenname
1.81 albertel 2775:
2776: =pod
2777:
1.648 raeburn 2778: =item * &screenname($uname,$udom)
1.81 albertel 2779:
2780: Gets a users screenname and returns it as a string
2781:
2782: =cut
1.61 www 2783:
2784: sub screenname {
2785: my ($uname,$udom)=@_;
1.258 albertel 2786: if ($uname eq $env{'user.name'} &&
2787: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 2788: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 2789: return $names{'screenname'};
1.62 www 2790: }
2791:
1.212 albertel 2792:
1.62 www 2793: # ------------------------------------------------------------- Message Wrapper
2794:
2795: sub messagewrapper {
1.369 www 2796: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 2797: return
1.441 albertel 2798: '<a href="/adm/email?compose=individual&'.
2799: 'recname='.$username.'&recdom='.$domain.
2800: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 2801: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 2802: }
2803: # --------------------------------------------------------------- Notes Wrapper
2804:
2805: sub noteswrapper {
2806: my ($link,$un,$do)=@_;
2807: return
2808: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 2809: }
2810: # ------------------------------------------------------------- Aboutme Wrapper
2811:
2812: sub aboutmewrapper {
1.166 www 2813: my ($link,$username,$domain,$target)=@_;
1.447 raeburn 2814: if (!defined($username) && !defined($domain)) {
2815: return;
2816: }
1.205 www 2817: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.756 weissno 2818: ($target?' target="$target"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 2819: }
2820:
2821: # ------------------------------------------------------------ Syllabus Wrapper
2822:
2823:
2824: sub syllabuswrapper {
1.707 bisitz 2825: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 2826: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 2827: }
1.14 harris41 2828:
1.208 matthew 2829: sub track_student_link {
1.268 albertel 2830: my ($linktext,$sname,$sdom,$target,$start) = @_;
2831: my $link ="/adm/trackstudent?";
1.208 matthew 2832: my $title = 'View recent activity';
2833: if (defined($sname) && $sname !~ /^\s*$/ &&
2834: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 2835: $link .= "selected_student=$sname:$sdom";
1.208 matthew 2836: $title .= ' of this student';
1.268 albertel 2837: }
1.208 matthew 2838: if (defined($target) && $target !~ /^\s*$/) {
2839: $target = qq{target="$target"};
2840: } else {
2841: $target = '';
2842: }
1.268 albertel 2843: if ($start) { $link.='&start='.$start; }
1.554 albertel 2844: $title = &mt($title);
2845: $linktext = &mt($linktext);
1.448 albertel 2846: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
2847: &help_open_topic('View_recent_activity');
1.208 matthew 2848: }
2849:
1.781 ! raeburn 2850: sub slot_reservations_link {
! 2851: my ($linktext,$sname,$sdom,$target) = @_;
! 2852: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
! 2853: my $title = 'View slot reservation history';
! 2854: if (defined($sname) && $sname !~ /^\s*$/ &&
! 2855: defined($sdom) && $sdom !~ /^\s*$/) {
! 2856: $link .= "&uname=$sname&udom=$sdom";
! 2857: $title .= ' of this student';
! 2858: }
! 2859: if (defined($target) && $target !~ /^\s*$/) {
! 2860: $target = qq{target="$target"};
! 2861: } else {
! 2862: $target = '';
! 2863: }
! 2864: $title = &mt($title);
! 2865: $linktext = &mt($linktext);
! 2866: return qq{<a href="$link" title="$title" $target>$linktext</a>};
! 2867: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
! 2868:
! 2869: }
! 2870:
1.508 www 2871: # ===================================================== Display a student photo
2872:
2873:
1.509 albertel 2874: sub student_image_tag {
1.508 www 2875: my ($domain,$user)=@_;
2876: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
2877: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
2878: return '<img src="'.$imgsrc.'" align="right" />';
2879: } else {
2880: return '';
2881: }
2882: }
2883:
1.112 bowersj2 2884: =pod
2885:
2886: =back
2887:
2888: =head1 Access .tab File Data
2889:
2890: =over 4
2891:
1.648 raeburn 2892: =item * &languageids()
1.112 bowersj2 2893:
2894: returns list of all language ids
2895:
2896: =cut
2897:
1.14 harris41 2898: sub languageids {
1.16 harris41 2899: return sort(keys(%language));
1.14 harris41 2900: }
2901:
1.112 bowersj2 2902: =pod
2903:
1.648 raeburn 2904: =item * &languagedescription()
1.112 bowersj2 2905:
2906: returns description of a specified language id
2907:
2908: =cut
2909:
1.14 harris41 2910: sub languagedescription {
1.125 www 2911: my $code=shift;
2912: return ($supported_language{$code}?'* ':'').
2913: $language{$code}.
1.126 www 2914: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 2915: }
2916:
2917: sub plainlanguagedescription {
2918: my $code=shift;
2919: return $language{$code};
2920: }
2921:
2922: sub supportedlanguagecode {
2923: my $code=shift;
2924: return $supported_language{$code};
1.97 www 2925: }
2926:
1.112 bowersj2 2927: =pod
2928:
1.648 raeburn 2929: =item * ©rightids()
1.112 bowersj2 2930:
2931: returns list of all copyrights
2932:
2933: =cut
2934:
2935: sub copyrightids {
2936: return sort(keys(%cprtag));
2937: }
2938:
2939: =pod
2940:
1.648 raeburn 2941: =item * ©rightdescription()
1.112 bowersj2 2942:
2943: returns description of a specified copyright id
2944:
2945: =cut
2946:
2947: sub copyrightdescription {
1.166 www 2948: return &mt($cprtag{shift(@_)});
1.112 bowersj2 2949: }
1.197 matthew 2950:
2951: =pod
2952:
1.648 raeburn 2953: =item * &source_copyrightids()
1.192 taceyjo1 2954:
2955: returns list of all source copyrights
2956:
2957: =cut
2958:
2959: sub source_copyrightids {
2960: return sort(keys(%scprtag));
2961: }
2962:
2963: =pod
2964:
1.648 raeburn 2965: =item * &source_copyrightdescription()
1.192 taceyjo1 2966:
2967: returns description of a specified source copyright id
2968:
2969: =cut
2970:
2971: sub source_copyrightdescription {
2972: return &mt($scprtag{shift(@_)});
2973: }
1.112 bowersj2 2974:
2975: =pod
2976:
1.648 raeburn 2977: =item * &filecategories()
1.112 bowersj2 2978:
2979: returns list of all file categories
2980:
2981: =cut
2982:
2983: sub filecategories {
2984: return sort(keys(%category_extensions));
2985: }
2986:
2987: =pod
2988:
1.648 raeburn 2989: =item * &filecategorytypes()
1.112 bowersj2 2990:
2991: returns list of file types belonging to a given file
2992: category
2993:
2994: =cut
2995:
2996: sub filecategorytypes {
1.356 albertel 2997: my ($cat) = @_;
2998: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 2999: }
3000:
3001: =pod
3002:
1.648 raeburn 3003: =item * &fileembstyle()
1.112 bowersj2 3004:
3005: returns embedding style for a specified file type
3006:
3007: =cut
3008:
3009: sub fileembstyle {
3010: return $fe{lc(shift(@_))};
1.169 www 3011: }
3012:
1.351 www 3013: sub filemimetype {
3014: return $fm{lc(shift(@_))};
3015: }
3016:
1.169 www 3017:
3018: sub filecategoryselect {
3019: my ($name,$value)=@_;
1.189 matthew 3020: return &select_form($value,$name,
1.169 www 3021: '' => &mt('Any category'),
3022: map { $_,$_ } sort(keys(%category_extensions)));
1.112 bowersj2 3023: }
3024:
3025: =pod
3026:
1.648 raeburn 3027: =item * &filedescription()
1.112 bowersj2 3028:
3029: returns description for a specified file type
3030:
3031: =cut
3032:
3033: sub filedescription {
1.188 matthew 3034: my $file_description = $fd{lc(shift())};
3035: $file_description =~ s:([\[\]]):~$1:g;
3036: return &mt($file_description);
1.112 bowersj2 3037: }
3038:
3039: =pod
3040:
1.648 raeburn 3041: =item * &filedescriptionex()
1.112 bowersj2 3042:
3043: returns description for a specified file type with
3044: extra formatting
3045:
3046: =cut
3047:
3048: sub filedescriptionex {
3049: my $ex=shift;
1.188 matthew 3050: my $file_description = $fd{lc($ex)};
3051: $file_description =~ s:([\[\]]):~$1:g;
3052: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3053: }
3054:
3055: # End of .tab access
3056: =pod
3057:
3058: =back
3059:
3060: =cut
3061:
3062: # ------------------------------------------------------------------ File Types
3063: sub fileextensions {
3064: return sort(keys(%fe));
3065: }
3066:
1.97 www 3067: # ----------------------------------------------------------- Display Languages
3068: # returns a hash with all desired display languages
3069: #
3070:
3071: sub display_languages {
3072: my %languages=();
1.695 raeburn 3073: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3074: $languages{$lang}=1;
1.97 www 3075: }
3076: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3077: if ($env{'form.displaylanguage'}) {
1.356 albertel 3078: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3079: $languages{$lang}=1;
1.97 www 3080: }
3081: }
3082: return %languages;
1.14 harris41 3083: }
3084:
1.582 albertel 3085: sub languages {
3086: my ($possible_langs) = @_;
1.695 raeburn 3087: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3088: if (!ref($possible_langs)) {
3089: if( wantarray ) {
3090: return @preferred_langs;
3091: } else {
3092: return $preferred_langs[0];
3093: }
3094: }
3095: my %possibilities = map { $_ => 1 } (@$possible_langs);
3096: my @preferred_possibilities;
3097: foreach my $preferred_lang (@preferred_langs) {
3098: if (exists($possibilities{$preferred_lang})) {
3099: push(@preferred_possibilities, $preferred_lang);
3100: }
3101: }
3102: if( wantarray ) {
3103: return @preferred_possibilities;
3104: }
3105: return $preferred_possibilities[0];
3106: }
3107:
1.742 raeburn 3108: sub user_lang {
3109: my ($touname,$toudom,$fromcid) = @_;
3110: my @userlangs;
3111: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3112: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3113: $env{'course.'.$fromcid.'.languages'}));
3114: } else {
3115: my %langhash = &getlangs($touname,$toudom);
3116: if ($langhash{'languages'} ne '') {
3117: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3118: } else {
3119: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3120: if ($domdefs{'lang_def'} ne '') {
3121: @userlangs = ($domdefs{'lang_def'});
3122: }
3123: }
3124: }
3125: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3126: my $user_lh = Apache::localize->get_handle(@languages);
3127: return $user_lh;
3128: }
3129:
3130:
1.112 bowersj2 3131: ###############################################################
3132: ## Student Answer Attempts ##
3133: ###############################################################
3134:
3135: =pod
3136:
3137: =head1 Alternate Problem Views
3138:
3139: =over 4
3140:
1.648 raeburn 3141: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3142: $getattempt, $regexp, $gradesub)
3143:
3144: Return string with previous attempt on problem. Arguments:
3145:
3146: =over 4
3147:
3148: =item * $symb: Problem, including path
3149:
3150: =item * $username: username of the desired student
3151:
3152: =item * $domain: domain of the desired student
1.14 harris41 3153:
1.112 bowersj2 3154: =item * $course: Course ID
1.14 harris41 3155:
1.112 bowersj2 3156: =item * $getattempt: Leave blank for all attempts, otherwise put
3157: something
1.14 harris41 3158:
1.112 bowersj2 3159: =item * $regexp: if string matches this regexp, the string will be
3160: sent to $gradesub
1.14 harris41 3161:
1.112 bowersj2 3162: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3163:
1.112 bowersj2 3164: =back
1.14 harris41 3165:
1.112 bowersj2 3166: The output string is a table containing all desired attempts, if any.
1.16 harris41 3167:
1.112 bowersj2 3168: =cut
1.1 albertel 3169:
3170: sub get_previous_attempt {
1.43 ng 3171: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3172: my $prevattempts='';
1.43 ng 3173: no strict 'refs';
1.1 albertel 3174: if ($symb) {
1.3 albertel 3175: my (%returnhash)=
3176: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3177: if ($returnhash{'version'}) {
3178: my %lasthash=();
3179: my $version;
3180: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3181: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3182: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3183: }
1.1 albertel 3184: }
1.596 albertel 3185: $prevattempts=&start_data_table().&start_data_table_header_row();
3186: $prevattempts.='<th>'.&mt('History').'</th>';
1.356 albertel 3187: foreach my $key (sort(keys(%lasthash))) {
3188: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3189: if ($#parts > 0) {
1.31 albertel 3190: my $data=$parts[-1];
3191: pop(@parts);
1.596 albertel 3192: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.31 albertel 3193: } else {
1.41 ng 3194: if ($#parts == 0) {
3195: $prevattempts.='<th>'.$parts[0].'</th>';
3196: } else {
3197: $prevattempts.='<th>'.$ign.'</th>';
3198: }
1.31 albertel 3199: }
1.16 harris41 3200: }
1.596 albertel 3201: $prevattempts.=&end_data_table_header_row();
1.40 ng 3202: if ($getattempt eq '') {
3203: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.596 albertel 3204: $prevattempts.=&start_data_table_row().
3205: '<td>'.&mt('Transaction [_1]',$version).'</td>';
1.356 albertel 3206: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3207: my $value = &format_previous_attempt_value($key,
3208: $returnhash{$version.':'.$key});
3209: $prevattempts.='<td>'.$value.' </td>';
1.40 ng 3210: }
1.596 albertel 3211: $prevattempts.=&end_data_table_row();
1.40 ng 3212: }
1.1 albertel 3213: }
1.596 albertel 3214: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3215: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3216: my $value = &format_previous_attempt_value($key,$lasthash{$key});
1.356 albertel 3217: if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
1.40 ng 3218: $prevattempts.='<td>'.$value.' </td>';
1.16 harris41 3219: }
1.596 albertel 3220: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3221: } else {
1.596 albertel 3222: $prevattempts=
3223: &start_data_table().&start_data_table_row().
3224: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3225: &end_data_table_row().&end_data_table();
1.1 albertel 3226: }
3227: } else {
1.596 albertel 3228: $prevattempts=
3229: &start_data_table().&start_data_table_row().
3230: '<td>'.&mt('No data.').'</td>'.
3231: &end_data_table_row().&end_data_table();
1.1 albertel 3232: }
1.10 albertel 3233: }
3234:
1.581 albertel 3235: sub format_previous_attempt_value {
3236: my ($key,$value) = @_;
3237: if ($key =~ /timestamp/) {
3238: $value = &Apache::lonlocal::locallocaltime($value);
3239: } elsif (ref($value) eq 'ARRAY') {
3240: $value = '('.join(', ', @{ $value }).')';
3241: } else {
3242: $value = &unescape($value);
3243: }
3244: return $value;
3245: }
3246:
3247:
1.107 albertel 3248: sub relative_to_absolute {
3249: my ($url,$output)=@_;
3250: my $parser=HTML::TokeParser->new(\$output);
3251: my $token;
3252: my $thisdir=$url;
3253: my @rlinks=();
3254: while ($token=$parser->get_token) {
3255: if ($token->[0] eq 'S') {
3256: if ($token->[1] eq 'a') {
3257: if ($token->[2]->{'href'}) {
3258: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3259: }
3260: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3261: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3262: } elsif ($token->[1] eq 'base') {
3263: $thisdir=$token->[2]->{'href'};
3264: }
3265: }
3266: }
3267: $thisdir=~s-/[^/]*$--;
1.356 albertel 3268: foreach my $link (@rlinks) {
1.726 raeburn 3269: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3270: ($link=~/^\//) ||
3271: ($link=~/^javascript:/i) ||
3272: ($link=~/^mailto:/i) ||
3273: ($link=~/^\#/)) {
3274: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3275: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3276: }
3277: }
3278: # -------------------------------------------------- Deal with Applet codebases
3279: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3280: return $output;
3281: }
3282:
1.112 bowersj2 3283: =pod
3284:
1.648 raeburn 3285: =item * &get_student_view()
1.112 bowersj2 3286:
3287: show a snapshot of what student was looking at
3288:
3289: =cut
3290:
1.10 albertel 3291: sub get_student_view {
1.186 albertel 3292: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3293: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3294: my (%form);
1.10 albertel 3295: my @elements=('symb','courseid','domain','username');
3296: foreach my $element (@elements) {
1.186 albertel 3297: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3298: }
1.186 albertel 3299: if (defined($moreenv)) {
3300: %form=(%form,%{$moreenv});
3301: }
1.236 albertel 3302: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3303: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 3304: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3305: $userview=~s/\<body[^\>]*\>//gi;
3306: $userview=~s/\<\/body\>//gi;
3307: $userview=~s/\<html\>//gi;
3308: $userview=~s/\<\/html\>//gi;
3309: $userview=~s/\<head\>//gi;
3310: $userview=~s/\<\/head\>//gi;
3311: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 3312: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 3313: if (wantarray) {
3314: return ($userview,$response);
3315: } else {
3316: return $userview;
3317: }
3318: }
3319:
3320: sub get_student_view_with_retries {
3321: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3322:
3323: my $ok = 0; # True if we got a good response.
3324: my $content;
3325: my $response;
3326:
3327: # Try to get the student_view done. within the retries count:
3328:
3329: do {
3330: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3331: $ok = $response->is_success;
3332: if (!$ok) {
3333: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3334: }
3335: $retries--;
3336: } while (!$ok && ($retries > 0));
3337:
3338: if (!$ok) {
3339: $content = ''; # On error return an empty content.
3340: }
1.651 www 3341: if (wantarray) {
3342: return ($content, $response);
3343: } else {
3344: return $content;
3345: }
1.11 albertel 3346: }
3347:
1.112 bowersj2 3348: =pod
3349:
1.648 raeburn 3350: =item * &get_student_answers()
1.112 bowersj2 3351:
3352: show a snapshot of how student was answering problem
3353:
3354: =cut
3355:
1.11 albertel 3356: sub get_student_answers {
1.100 sakharuk 3357: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 3358: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3359: my (%moreenv);
1.11 albertel 3360: my @elements=('symb','courseid','domain','username');
3361: foreach my $element (@elements) {
1.186 albertel 3362: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3363: }
1.186 albertel 3364: $moreenv{'grade_target'}='answer';
3365: %moreenv=(%form,%moreenv);
1.497 raeburn 3366: $feedurl = &Apache::lonnet::clutter($feedurl);
3367: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 3368: return $userview;
1.1 albertel 3369: }
1.116 albertel 3370:
3371: =pod
3372:
3373: =item * &submlink()
3374:
1.242 albertel 3375: Inputs: $text $uname $udom $symb $target
1.116 albertel 3376:
3377: Returns: A link to grades.pm such as to see the SUBM view of a student
3378:
3379: =cut
3380:
3381: ###############################################
3382: sub submlink {
1.242 albertel 3383: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 3384: if (!($uname && $udom)) {
3385: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3386: &Apache::lonnet::whichuser($symb);
1.116 albertel 3387: if (!$symb) { $symb=$cursymb; }
3388: }
1.254 matthew 3389: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3390: $symb=&escape($symb);
1.242 albertel 3391: if ($target) { $target="target=\"$target\""; }
3392: return '<a href="/adm/grades?&command=submission&'.
3393: 'symb='.$symb.'&student='.$uname.
3394: '&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
3395: }
3396: ##############################################
3397:
3398: =pod
3399:
3400: =item * &pgrdlink()
3401:
3402: Inputs: $text $uname $udom $symb $target
3403:
3404: Returns: A link to grades.pm such as to see the PGRD view of a student
3405:
3406: =cut
3407:
3408: ###############################################
3409: sub pgrdlink {
3410: my $link=&submlink(@_);
3411: $link=~s/(&command=submission)/$1&showgrading=yes/;
3412: return $link;
3413: }
3414: ##############################################
3415:
3416: =pod
3417:
3418: =item * &pprmlink()
3419:
3420: Inputs: $text $uname $udom $symb $target
3421:
3422: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 3423: student and a specific resource
1.242 albertel 3424:
3425: =cut
3426:
3427: ###############################################
3428: sub pprmlink {
3429: my ($text,$uname,$udom,$symb,$target)=@_;
3430: if (!($uname && $udom)) {
3431: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3432: &Apache::lonnet::whichuser($symb);
1.242 albertel 3433: if (!$symb) { $symb=$cursymb; }
3434: }
1.254 matthew 3435: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3436: $symb=&escape($symb);
1.242 albertel 3437: if ($target) { $target="target=\"$target\""; }
1.595 albertel 3438: return '<a href="/adm/parmset?command=set&'.
3439: 'symb='.$symb.'&uname='.$uname.
3440: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 3441: }
3442: ##############################################
1.37 matthew 3443:
1.112 bowersj2 3444: =pod
3445:
3446: =back
3447:
3448: =cut
3449:
1.37 matthew 3450: ###############################################
1.51 www 3451:
3452:
3453: sub timehash {
1.687 raeburn 3454: my ($thistime) = @_;
3455: my $timezone = &Apache::lonlocal::gettimezone();
3456: my $dt = DateTime->from_epoch(epoch => $thistime)
3457: ->set_time_zone($timezone);
3458: my $wday = $dt->day_of_week();
3459: if ($wday == 7) { $wday = 0; }
3460: return ( 'second' => $dt->second(),
3461: 'minute' => $dt->minute(),
3462: 'hour' => $dt->hour(),
3463: 'day' => $dt->day_of_month(),
3464: 'month' => $dt->month(),
3465: 'year' => $dt->year(),
3466: 'weekday' => $wday,
3467: 'dayyear' => $dt->day_of_year(),
3468: 'dlsav' => $dt->is_dst() );
1.51 www 3469: }
3470:
1.370 www 3471: sub utc_string {
3472: my ($date)=@_;
1.371 www 3473: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 3474: }
3475:
1.51 www 3476: sub maketime {
3477: my %th=@_;
1.687 raeburn 3478: my ($epoch_time,$timezone,$dt);
3479: $timezone = &Apache::lonlocal::gettimezone();
3480: eval {
3481: $dt = DateTime->new( year => $th{'year'},
3482: month => $th{'month'},
3483: day => $th{'day'},
3484: hour => $th{'hour'},
3485: minute => $th{'minute'},
3486: second => $th{'second'},
3487: time_zone => $timezone,
3488: );
3489: };
3490: if (!$@) {
3491: $epoch_time = $dt->epoch;
3492: if ($epoch_time) {
3493: return $epoch_time;
3494: }
3495: }
1.51 www 3496: return POSIX::mktime(
3497: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 3498: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 3499: }
3500:
3501: #########################################
1.51 www 3502:
3503: sub findallcourses {
1.482 raeburn 3504: my ($roles,$uname,$udom) = @_;
1.355 albertel 3505: my %roles;
3506: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 3507: my %courses;
1.51 www 3508: my $now=time;
1.482 raeburn 3509: if (!defined($uname)) {
3510: $uname = $env{'user.name'};
3511: }
3512: if (!defined($udom)) {
3513: $udom = $env{'user.domain'};
3514: }
3515: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
3516: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
3517: if (!%roles) {
3518: %roles = (
3519: cc => 1,
3520: in => 1,
3521: ep => 1,
3522: ta => 1,
3523: cr => 1,
3524: st => 1,
3525: );
3526: }
3527: foreach my $entry (keys(%roleshash)) {
3528: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
3529: if ($trole =~ /^cr/) {
3530: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
3531: } else {
3532: next if (!exists($roles{$trole}));
3533: }
3534: if ($tend) {
3535: next if ($tend < $now);
3536: }
3537: if ($tstart) {
3538: next if ($tstart > $now);
3539: }
3540: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
3541: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
3542: if ($secpart eq '') {
3543: ($cnum,$role) = split(/_/,$cnumpart);
3544: $sec = 'none';
3545: $realsec = '';
3546: } else {
3547: $cnum = $cnumpart;
3548: ($sec,$role) = split(/_/,$secpart);
3549: $realsec = $sec;
1.490 raeburn 3550: }
1.482 raeburn 3551: $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
3552: }
3553: } else {
3554: foreach my $key (keys(%env)) {
1.483 albertel 3555: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
3556: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 3557: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
3558: next if ($role eq 'ca' || $role eq 'aa');
3559: next if (%roles && !exists($roles{$role}));
3560: my ($starttime,$endtime)=split(/\./,$env{$key});
3561: my $active=1;
3562: if ($starttime) {
3563: if ($now<$starttime) { $active=0; }
3564: }
3565: if ($endtime) {
3566: if ($now>$endtime) { $active=0; }
3567: }
3568: if ($active) {
3569: if ($sec eq '') {
3570: $sec = 'none';
3571: }
3572: $courses{$cdom.'_'.$cnum}{$sec} =
3573: $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474 raeburn 3574: }
3575: }
1.51 www 3576: }
3577: }
1.474 raeburn 3578: return %courses;
1.51 www 3579: }
1.37 matthew 3580:
1.54 www 3581: ###############################################
1.474 raeburn 3582:
3583: sub blockcheck {
1.482 raeburn 3584: my ($setters,$activity,$uname,$udom) = @_;
1.490 raeburn 3585:
3586: if (!defined($udom)) {
3587: $udom = $env{'user.domain'};
3588: }
3589: if (!defined($uname)) {
3590: $uname = $env{'user.name'};
3591: }
3592:
3593: # If uname and udom are for a course, check for blocks in the course.
3594:
3595: if (&Apache::lonnet::is_course($udom,$uname)) {
3596: my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502 raeburn 3597: my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490 raeburn 3598: return ($startblock,$endblock);
3599: }
1.474 raeburn 3600:
1.502 raeburn 3601: my $startblock = 0;
3602: my $endblock = 0;
1.482 raeburn 3603: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 3604:
1.490 raeburn 3605: # If uname is for a user, and activity is course-specific, i.e.,
3606: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 3607:
1.490 raeburn 3608: if (($activity eq 'boards' || $activity eq 'chat' ||
3609: $activity eq 'groups') && ($env{'request.course.id'})) {
3610: foreach my $key (keys(%live_courses)) {
3611: if ($key ne $env{'request.course.id'}) {
3612: delete($live_courses{$key});
3613: }
3614: }
3615: }
3616:
3617: my $otheruser = 0;
3618: my %own_courses;
3619: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
3620: # Resource belongs to user other than current user.
3621: $otheruser = 1;
3622: # Gather courses for current user
3623: %own_courses =
3624: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
3625: }
3626:
3627: # Gather active course roles - course coordinator, instructor,
3628: # exam proctor, ta, student, or custom role.
1.474 raeburn 3629:
3630: foreach my $course (keys(%live_courses)) {
1.482 raeburn 3631: my ($cdom,$cnum);
3632: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
3633: $cdom = $env{'course.'.$course.'.domain'};
3634: $cnum = $env{'course.'.$course.'.num'};
3635: } else {
1.490 raeburn 3636: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 3637: }
3638: my $no_ownblock = 0;
3639: my $no_userblock = 0;
1.533 raeburn 3640: if ($otheruser && $activity ne 'com') {
1.490 raeburn 3641: # Check if current user has 'evb' priv for this
3642: if (defined($own_courses{$course})) {
3643: foreach my $sec (keys(%{$own_courses{$course}})) {
3644: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
3645: if ($sec ne 'none') {
3646: $checkrole .= '/'.$sec;
3647: }
3648: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3649: $no_ownblock = 1;
3650: last;
3651: }
3652: }
3653: }
3654: # if they have 'evb' priv and are currently not playing student
3655: next if (($no_ownblock) &&
3656: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
3657: }
1.474 raeburn 3658: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 3659: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 3660: if ($sec ne 'none') {
1.482 raeburn 3661: $checkrole .= '/'.$sec;
1.474 raeburn 3662: }
1.490 raeburn 3663: if ($otheruser) {
3664: # Resource belongs to user other than current user.
3665: # Assemble privs for that user, and check for 'evb' priv.
1.482 raeburn 3666: my ($trole,$tdom,$tnum,$tsec);
3667: my $entry = $live_courses{$course}{$sec};
3668: if ($entry =~ /^cr/) {
3669: ($trole,$tdom,$tnum,$tsec) =
3670: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
3671: } else {
3672: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
3673: }
3674: my ($spec,$area,$trest,%allroles,%userroles);
3675: $area = '/'.$tdom.'/'.$tnum;
3676: $trest = $tnum;
3677: if ($tsec ne '') {
3678: $area .= '/'.$tsec;
3679: $trest .= '/'.$tsec;
3680: }
3681: $spec = $trole.'.'.$area;
3682: if ($trole =~ /^cr/) {
3683: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
3684: $tdom,$spec,$trest,$area);
3685: } else {
3686: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
3687: $tdom,$spec,$trest,$area);
3688: }
3689: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486 raeburn 3690: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
3691: if ($1) {
3692: $no_userblock = 1;
3693: last;
3694: }
3695: }
1.490 raeburn 3696: } else {
3697: # Resource belongs to current user
3698: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 3699: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3700: $no_ownblock = 1;
3701: last;
3702: }
1.474 raeburn 3703: }
3704: }
3705: # if they have the evb priv and are currently not playing student
1.482 raeburn 3706: next if (($no_ownblock) &&
1.491 albertel 3707: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 3708: next if ($no_userblock);
1.474 raeburn 3709:
1.490 raeburn 3710: # Retrieve blocking times and identity of blocker for course
3711: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 3712:
3713: my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
3714: if (($start != 0) &&
3715: (($startblock == 0) || ($startblock > $start))) {
3716: $startblock = $start;
3717: }
3718: if (($end != 0) &&
3719: (($endblock == 0) || ($endblock < $end))) {
3720: $endblock = $end;
3721: }
1.490 raeburn 3722: }
3723: return ($startblock,$endblock);
3724: }
3725:
3726: sub get_blocks {
3727: my ($setters,$activity,$cdom,$cnum) = @_;
3728: my $startblock = 0;
3729: my $endblock = 0;
3730: my $course = $cdom.'_'.$cnum;
3731: $setters->{$course} = {};
3732: $setters->{$course}{'staff'} = [];
3733: $setters->{$course}{'times'} = [];
3734: my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
3735: foreach my $record (keys(%records)) {
3736: my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
3737: if ($start <= time && $end >= time) {
3738: my ($staff_name,$staff_dom,$title,$blocks) =
3739: &parse_block_record($records{$record});
3740: if ($blocks->{$activity} eq 'on') {
3741: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
3742: push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491 albertel 3743: if ( ($startblock == 0) || ($startblock > $start) ) {
3744: $startblock = $start;
1.490 raeburn 3745: }
1.491 albertel 3746: if ( ($endblock == 0) || ($endblock < $end) ) {
3747: $endblock = $end;
1.474 raeburn 3748: }
3749: }
3750: }
3751: }
3752: return ($startblock,$endblock);
3753: }
3754:
3755: sub parse_block_record {
3756: my ($record) = @_;
3757: my ($setuname,$setudom,$title,$blocks);
3758: if (ref($record) eq 'HASH') {
3759: ($setuname,$setudom) = split(/:/,$record->{'setter'});
3760: $title = &unescape($record->{'event'});
3761: $blocks = $record->{'blocks'};
3762: } else {
3763: my @data = split(/:/,$record,3);
3764: if (scalar(@data) eq 2) {
3765: $title = $data[1];
3766: ($setuname,$setudom) = split(/@/,$data[0]);
3767: } else {
3768: ($setuname,$setudom,$title) = @data;
3769: }
3770: $blocks = { 'com' => 'on' };
3771: }
3772: return ($setuname,$setudom,$title,$blocks);
3773: }
3774:
3775: sub build_block_table {
3776: my ($startblock,$endblock,$setters) = @_;
3777: my %lt = &Apache::lonlocal::texthash(
3778: 'cacb' => 'Currently active communication blocks',
3779: 'cour' => 'Course',
3780: 'dura' => 'Duration',
3781: 'blse' => 'Block set by'
3782: );
3783: my $output;
1.476 raeburn 3784: $output = '<br />'.$lt{'cacb'}.':<br />';
1.474 raeburn 3785: $output .= &start_data_table();
3786: $output .= '
3787: <tr>
3788: <th>'.$lt{'cour'}.'</th>
3789: <th>'.$lt{'dura'}.'</th>
3790: <th>'.$lt{'blse'}.'</th>
3791: </tr>
3792: ';
3793: foreach my $course (keys(%{$setters})) {
3794: my %courseinfo=&Apache::lonnet::coursedescription($course);
3795: for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) {
3796: my ($uname,$udom) = @{$$setters{$course}{staff}[$i]};
1.490 raeburn 3797: my $fullname = &plainname($uname,$udom);
3798: if (defined($env{'user.name'}) && defined($env{'user.domain'})
3799: && $env{'user.name'} ne 'public'
3800: && $env{'user.domain'} ne 'public') {
3801: $fullname = &aboutmewrapper($fullname,$uname,$udom);
3802: }
1.474 raeburn 3803: my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]};
3804: $openblock = &Apache::lonlocal::locallocaltime($openblock);
3805: $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
3806: $output .= &Apache::loncommon::start_data_table_row().
3807: '<td>'.$courseinfo{'description'}.'</td>'.
3808: '<td>'.$openblock.' to '.$closeblock.'</td>'.
1.490 raeburn 3809: '<td>'.$fullname.'</td>'.
1.474 raeburn 3810: &Apache::loncommon::end_data_table_row();
3811: }
3812: }
3813: $output .= &end_data_table();
3814: }
3815:
1.490 raeburn 3816: sub blocking_status {
3817: my ($activity,$uname,$udom) = @_;
3818: my %setters;
3819: my ($blocked,$output,$ownitem,$is_course);
3820: my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
3821: if ($startblock && $endblock) {
3822: $blocked = 1;
3823: if (wantarray) {
3824: my $category;
3825: if ($activity eq 'boards') {
3826: $category = 'Discussion posts in this course';
3827: } elsif ($activity eq 'blogs') {
3828: $category = 'Blogs';
3829: } elsif ($activity eq 'port') {
3830: if (defined($uname) && defined($udom)) {
3831: if ($uname eq $env{'user.name'} &&
3832: $udom eq $env{'user.domain'}) {
3833: $ownitem = 1;
3834: }
3835: }
3836: $is_course = &Apache::lonnet::is_course($udom,$uname);
3837: if ($ownitem) {
3838: $category = 'Your portfolio files';
3839: } elsif ($is_course) {
3840: my $coursedesc;
3841: foreach my $course (keys(%setters)) {
3842: my %courseinfo =
3843: &Apache::lonnet::coursedescription($course);
3844: $coursedesc = $courseinfo{'description'};
3845: }
1.764 weissno 3846: $category = "Group portfolio in the course '$coursedesc'";
1.490 raeburn 3847: } else {
3848: $category = 'Portfolio files belonging to ';
3849: if ($env{'user.name'} eq 'public' &&
3850: $env{'user.domain'} eq 'public') {
3851: $category .= &plainname($uname,$udom);
3852: } else {
3853: $category .= &aboutmewrapper(&plainname($uname,$udom),$uname,$udom);
3854: }
3855: }
3856: } elsif ($activity eq 'groups') {
3857: $category = 'Groups in this course';
3858: }
3859: my $showstart = &Apache::lonlocal::locallocaltime($startblock);
3860: my $showend = &Apache::lonlocal::locallocaltime($endblock);
3861: $output = '<br />'.&mt('[_1] will be inaccessible between [_2] and [_3] because communication is being blocked.',$category,$showstart,$showend).'<br />';
3862: if (!($activity eq 'port' && !($ownitem) && !($is_course))) {
3863: $output .= &build_block_table($startblock,$endblock,\%setters);
3864: }
3865: }
3866: }
3867: if (wantarray) {
3868: return ($blocked,$output);
3869: } else {
3870: return $blocked;
3871: }
3872: }
3873:
1.60 matthew 3874: ###############################################
3875:
1.682 raeburn 3876: sub check_ip_acc {
3877: my ($acc)=@_;
3878: &Apache::lonxml::debug("acc is $acc");
3879: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
3880: return 1;
3881: }
3882: my $allowed=0;
3883: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
3884:
3885: my $name;
3886: foreach my $pattern (split(',',$acc)) {
3887: $pattern =~ s/^\s*//;
3888: $pattern =~ s/\s*$//;
3889: if ($pattern =~ /\*$/) {
3890: #35.8.*
3891: $pattern=~s/\*//;
3892: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
3893: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
3894: #35.8.3.[34-56]
3895: my $low=$2;
3896: my $high=$3;
3897: $pattern=$1;
3898: if ($ip =~ /^\Q$pattern\E/) {
3899: my $last=(split(/\./,$ip))[3];
3900: if ($last <=$high && $last >=$low) { $allowed=1; }
3901: }
3902: } elsif ($pattern =~ /^\*/) {
3903: #*.msu.edu
3904: $pattern=~s/\*//;
3905: if (!defined($name)) {
3906: use Socket;
3907: my $netaddr=inet_aton($ip);
3908: ($name)=gethostbyaddr($netaddr,AF_INET);
3909: }
3910: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
3911: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
3912: #127.0.0.1
3913: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
3914: } else {
3915: #some.name.com
3916: if (!defined($name)) {
3917: use Socket;
3918: my $netaddr=inet_aton($ip);
3919: ($name)=gethostbyaddr($netaddr,AF_INET);
3920: }
3921: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
3922: }
3923: if ($allowed) { last; }
3924: }
3925: return $allowed;
3926: }
3927:
3928: ###############################################
3929:
1.60 matthew 3930: =pod
3931:
1.112 bowersj2 3932: =head1 Domain Template Functions
3933:
3934: =over 4
3935:
3936: =item * &determinedomain()
1.60 matthew 3937:
3938: Inputs: $domain (usually will be undef)
3939:
1.63 www 3940: Returns: Determines which domain should be used for designs
1.60 matthew 3941:
3942: =cut
1.54 www 3943:
1.60 matthew 3944: ###############################################
1.63 www 3945: sub determinedomain {
3946: my $domain=shift;
1.531 albertel 3947: if (! $domain) {
1.60 matthew 3948: # Determine domain if we have not been given one
3949: $domain = $Apache::lonnet::perlvar{'lonDefDomain'};
1.258 albertel 3950: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
3951: if ($env{'request.role.domain'}) {
3952: $domain=$env{'request.role.domain'};
1.60 matthew 3953: }
3954: }
1.63 www 3955: return $domain;
3956: }
3957: ###############################################
1.517 raeburn 3958:
1.518 albertel 3959: sub devalidate_domconfig_cache {
3960: my ($udom)=@_;
3961: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
3962: }
3963:
3964: # ---------------------- Get domain configuration for a domain
3965: sub get_domainconf {
3966: my ($udom) = @_;
3967: my $cachetime=1800;
3968: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
3969: if (defined($cached)) { return %{$result}; }
3970:
3971: my %domconfig = &Apache::lonnet::get_dom('configuration',
3972: ['login','rolecolors'],$udom);
1.632 raeburn 3973: my (%designhash,%legacy);
1.518 albertel 3974: if (keys(%domconfig) > 0) {
3975: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 3976: if (keys(%{$domconfig{'login'}})) {
3977: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 3978: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
3979: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
3980: $designhash{$udom.'.login.'.$key.'_'.$img} =
3981: $domconfig{'login'}{$key}{$img};
3982: }
3983: } else {
3984: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
3985: }
1.632 raeburn 3986: }
3987: } else {
3988: $legacy{'login'} = 1;
1.518 albertel 3989: }
1.632 raeburn 3990: } else {
3991: $legacy{'login'} = 1;
1.518 albertel 3992: }
3993: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 3994: if (keys(%{$domconfig{'rolecolors'}})) {
3995: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
3996: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
3997: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
3998: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
3999: }
1.518 albertel 4000: }
4001: }
1.632 raeburn 4002: } else {
4003: $legacy{'rolecolors'} = 1;
1.518 albertel 4004: }
1.632 raeburn 4005: } else {
4006: $legacy{'rolecolors'} = 1;
1.518 albertel 4007: }
1.632 raeburn 4008: if (keys(%legacy) > 0) {
4009: my %legacyhash = &get_legacy_domconf($udom);
4010: foreach my $item (keys(%legacyhash)) {
4011: if ($item =~ /^\Q$udom\E\.login/) {
4012: if ($legacy{'login'}) {
4013: $designhash{$item} = $legacyhash{$item};
4014: }
4015: } else {
4016: if ($legacy{'rolecolors'}) {
4017: $designhash{$item} = $legacyhash{$item};
4018: }
1.518 albertel 4019: }
4020: }
4021: }
1.632 raeburn 4022: } else {
4023: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4024: }
4025: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4026: $cachetime);
4027: return %designhash;
4028: }
4029:
1.632 raeburn 4030: sub get_legacy_domconf {
4031: my ($udom) = @_;
4032: my %legacyhash;
4033: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4034: my $designfile = $designdir.'/'.$udom.'.tab';
4035: if (-e $designfile) {
4036: if ( open (my $fh,"<$designfile") ) {
4037: while (my $line = <$fh>) {
4038: next if ($line =~ /^\#/);
4039: chomp($line);
4040: my ($key,$val)=(split(/\=/,$line));
4041: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4042: }
4043: close($fh);
4044: }
4045: }
4046: if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
4047: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4048: }
4049: return %legacyhash;
4050: }
4051:
1.63 www 4052: =pod
4053:
1.112 bowersj2 4054: =item * &domainlogo()
1.63 www 4055:
4056: Inputs: $domain (usually will be undef)
4057:
4058: Returns: A link to a domain logo, if the domain logo exists.
4059: If the domain logo does not exist, a description of the domain.
4060:
4061: =cut
1.112 bowersj2 4062:
1.63 www 4063: ###############################################
4064: sub domainlogo {
1.517 raeburn 4065: my $domain = &determinedomain(shift);
1.518 albertel 4066: my %designhash = &get_domainconf($domain);
1.517 raeburn 4067: # See if there is a logo
4068: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4069: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4070: if ($imgsrc =~ m{^/(adm|res)/}) {
4071: if ($imgsrc =~ m{^/res/}) {
4072: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4073: &Apache::lonnet::repcopy($local_name);
4074: }
4075: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4076: }
4077: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4078: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4079: return &Apache::lonnet::domain($domain,'description');
1.59 www 4080: } else {
1.60 matthew 4081: return '';
1.59 www 4082: }
4083: }
1.63 www 4084: ##############################################
4085:
4086: =pod
4087:
1.112 bowersj2 4088: =item * &designparm()
1.63 www 4089:
4090: Inputs: $which parameter; $domain (usually will be undef)
4091:
4092: Returns: value of designparamter $which
4093:
4094: =cut
1.112 bowersj2 4095:
1.397 albertel 4096:
1.400 albertel 4097: ##############################################
1.397 albertel 4098: sub designparm {
4099: my ($which,$domain)=@_;
1.258 albertel 4100: if ($env{'browser.blackwhite'} eq 'on') {
1.635 raeburn 4101: if ($which=~/\.(font|alink|vlink|link|textcol)$/) {
1.110 www 4102: return '#000000';
4103: }
1.635 raeburn 4104: if ($which=~/\.(pgbg|sidebg|bgcol)$/) {
1.110 www 4105: return '#FFFFFF';
4106: }
4107: if ($which=~/\.tabbg$/) {
4108: return '#CCCCCC';
4109: }
4110: }
1.397 albertel 4111: if (exists($env{'environment.color.'.$which})) {
1.258 albertel 4112: return $env{'environment.color.'.$which};
1.96 www 4113: }
1.63 www 4114: $domain=&determinedomain($domain);
1.518 albertel 4115: my %domdesign = &get_domainconf($domain);
1.520 raeburn 4116: my $output;
1.517 raeburn 4117: if ($domdesign{$domain.'.'.$which} ne '') {
1.520 raeburn 4118: $output = $domdesign{$domain.'.'.$which};
1.63 www 4119: } else {
1.520 raeburn 4120: $output = $defaultdesign{$which};
4121: }
4122: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4123: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4124: if ($output =~ m{^/(adm|res)/}) {
4125: if ($output =~ m{^/res/}) {
4126: my $local_name = &Apache::lonnet::filelocation('',$output);
4127: &Apache::lonnet::repcopy($local_name);
4128: }
1.520 raeburn 4129: $output = &lonhttpdurl($output);
4130: }
1.63 www 4131: }
1.520 raeburn 4132: return $output;
1.63 www 4133: }
1.59 www 4134:
1.60 matthew 4135: ###############################################
4136: ###############################################
4137:
4138: =pod
4139:
1.112 bowersj2 4140: =back
4141:
1.549 albertel 4142: =head1 HTML Helpers
1.112 bowersj2 4143:
4144: =over 4
4145:
4146: =item * &bodytag()
1.60 matthew 4147:
4148: Returns a uniform header for LON-CAPA web pages.
4149:
4150: Inputs:
4151:
1.112 bowersj2 4152: =over 4
4153:
4154: =item * $title, A title to be displayed on the page.
4155:
4156: =item * $function, the current role (can be undef).
4157:
4158: =item * $addentries, extra parameters for the <body> tag.
4159:
4160: =item * $bodyonly, if defined, only return the <body> tag.
4161:
4162: =item * $domain, if defined, force a given domain.
4163:
4164: =item * $forcereg, if page should register as content page (relevant for
1.86 www 4165: text interface only)
1.60 matthew 4166:
1.326 albertel 4167: =item * $customtitle, alternate text to use instead of $title
4168: in the title box that appears, this text
4169: is not auto translated like the $title is
1.309 albertel 4170:
4171: =item * $notopbar, if true, keep the 'what is this' info but remove the
4172: navigational links
1.317 albertel 4173:
1.338 albertel 4174: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
4175:
4176: =item * $notitle, if true keep the nav controls, but remove the title bar
4177:
1.361 albertel 4178: =item * $no_inline_link, if true and in remote mode, don't show the
4179: 'Switch To Inline Menu' link
4180:
1.460 albertel 4181: =item * $args, optional argument valid values are
4182: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 4183: inherit_jsmath -> when creating popup window in a page,
4184: should it have jsmath forced on by the
4185: current page
1.460 albertel 4186:
1.112 bowersj2 4187: =back
4188:
1.60 matthew 4189: Returns: A uniform header for LON-CAPA web pages.
4190: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
4191: If $bodyonly is undef or zero, an html string containing a <body> tag and
4192: other decorations will be returned.
4193:
4194: =cut
4195:
1.54 www 4196: sub bodytag {
1.309 albertel 4197: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,$customtitle,
1.460 albertel 4198: $notopbar,$bgcolor,$notitle,$no_inline_link,$args)=@_;
1.339 albertel 4199:
1.460 albertel 4200: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 4201:
1.183 matthew 4202: $function = &get_users_function() if (!$function);
1.339 albertel 4203: my $img = &designparm($function.'.img',$domain);
4204: my $font = &designparm($function.'.font',$domain);
4205: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
4206:
4207: my %design = ( 'style' => 'margin-top: 0px',
1.535 albertel 4208: 'bgcolor' => $pgbg,
1.339 albertel 4209: 'text' => $font,
4210: 'alink' => &designparm($function.'.alink',$domain),
4211: 'vlink' => &designparm($function.'.vlink',$domain),
4212: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 4213: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 4214:
1.63 www 4215: # role and realm
1.378 raeburn 4216: my ($role,$realm) = split(/\./,$env{'request.role'},2);
4217: if ($role eq 'ca') {
1.479 albertel 4218: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 4219: $realm = &plainname($rname,$rdom);
1.378 raeburn 4220: }
1.55 www 4221: # realm
1.258 albertel 4222: if ($env{'request.course.id'}) {
1.378 raeburn 4223: if ($env{'request.role'} !~ /^cr/) {
4224: $role = &Apache::lonnet::plaintext($role,&course_type());
4225: }
1.359 albertel 4226: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 4227: } else {
4228: $role = &Apache::lonnet::plaintext($role);
1.54 www 4229: }
1.433 albertel 4230:
1.359 albertel 4231: if (!$realm) { $realm=' '; }
1.55 www 4232: # Set messages
1.60 matthew 4233: my $messages=&domainlogo($domain);
1.330 albertel 4234:
1.438 albertel 4235: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 4236:
1.101 www 4237: # construct main body tag
1.359 albertel 4238: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 4239: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 4240:
1.530 albertel 4241: if ($bodyonly) {
1.60 matthew 4242: return $bodytag;
1.258 albertel 4243: } elsif ($env{'browser.interface'} eq 'textual') {
1.95 www 4244: # Accessibility
1.224 raeburn 4245:
1.337 albertel 4246: $bodytag.=&Apache::lonmenu::menubuttons($forcereg,$forcereg);
1.338 albertel 4247: if (!$notitle) {
1.337 albertel 4248: $bodytag.='<h1>LON-CAPA: '.$title.'</h1>';
4249: }
4250: return $bodytag;
1.359 albertel 4251: }
4252:
1.410 albertel 4253: my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.433 albertel 4254: if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
4255: undef($role);
1.434 albertel 4256: } else {
4257: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433 albertel 4258: }
1.359 albertel 4259:
4260: my $roleinfo=(<<ENDROLE);
4261: <td class="LC_title_bar_who">
4262: <div class="LC_title_bar_name">
1.410 albertel 4263: $name
1.361 albertel 4264:
1.359 albertel 4265: </div>
4266: <div class="LC_title_bar_role">
1.361 albertel 4267: $role
1.359 albertel 4268: </div>
4269: <div class="LC_title_bar_realm">
1.361 albertel 4270: $realm
1.359 albertel 4271: </div>
1.206 albertel 4272: </td>
4273: ENDROLE
1.235 raeburn 4274:
1.762 bisitz 4275: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 4276: if ($customtitle) {
4277: $titleinfo = $customtitle;
4278: }
4279: #
4280: # Extra info if you are the DC
4281: my $dc_info = '';
4282: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
4283: $env{'course.'.$env{'request.course.id'}.
4284: '.domain'}.'/'})) {
4285: my $cid = $env{'request.course.id'};
4286: $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 4287: $dc_info =~ s/\s+$//;
1.359 albertel 4288: $dc_info = '('.$dc_info.')';
4289: }
4290:
1.644 www 4291: if (($env{'environment.remote'} eq 'off') || ($args->{'suppress_header_logos'})) {
1.359 albertel 4292: # No Remote
1.258 albertel 4293: if ($env{'request.state'} eq 'construct') {
1.359 albertel 4294: $forcereg=1;
4295: }
4296:
4297: if (!$customtitle && $env{'request.state'} eq 'construct') {
4298: # this is for resources; directories have customtitle, and crumbs
4299: # and select recent are created in lonpubdir.pm
1.229 albertel 4300: my ($uname,$thisdisfn)=
1.258 albertel 4301: ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
1.229 albertel 4302: my $formaction='/priv/'.$uname.'/'.$thisdisfn;
4303: $formaction=~s/\/+/\//g;
4304:
1.359 albertel 4305: my $parentpath = '';
4306: my $lastitem = '';
4307: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4308: $parentpath = $1;
4309: $lastitem = $2;
4310: } else {
4311: $lastitem = $thisdisfn;
4312: }
4313: $titleinfo =
1.640 bisitz 4314: &Apache::loncommon::help_open_menu('','',3,'Authoring')
4315: .'<b>'.&mt('Construction Space').'</b>: '
4316: .'<form name="dirs" method="post" action="'.$formaction
1.359 albertel 4317: .'" target="_top"><tt><b>'
1.705 tempelho 4318: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."<span class=\"LC_fontsize_big\">$lastitem</span></b></tt><br />"
1.359 albertel 4319: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4320: .'</form>'
4321: .&Apache::lonmenu::constspaceform();
1.235 raeburn 4322: }
1.359 albertel 4323:
1.337 albertel 4324: my $titletable;
1.338 albertel 4325: if (!$notitle) {
1.337 albertel 4326: $titletable =
1.359 albertel 4327: '<table id="LC_title_bar">'.
4328: "<tr><td> $titleinfo $dc_info</td>".$roleinfo.
4329: '</tr></table>';
1.337 albertel 4330: }
1.359 albertel 4331: if ($notopbar) {
4332: $bodytag .= $titletable;
4333: } else {
4334: if ($env{'request.state'} eq 'construct') {
1.337 albertel 4335: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg,
4336: $titletable);
1.272 raeburn 4337: } else {
1.336 albertel 4338: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg).
1.359 albertel 4339: $titletable;
1.272 raeburn 4340: }
1.235 raeburn 4341: }
4342: return $bodytag;
1.94 www 4343: }
1.95 www 4344:
1.93 www 4345: #
1.95 www 4346: # Top frame rendering, Remote is up
1.93 www 4347: #
1.359 albertel 4348:
1.517 raeburn 4349: my $imgsrc = $img;
4350: if ($img =~ /^\/adm/) {
1.575 albertel 4351: $imgsrc = &lonhttpdurl($img);
1.517 raeburn 4352: }
4353: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359 albertel 4354:
1.305 www 4355: # Explicit link to get inline menu
1.361 albertel 4356: my $menu= ($no_inline_link?''
4357: :'<br /><a href="/adm/remote?action=collapse">'.&mt('Switch to Inline Menu Mode').'</a>');
1.245 matthew 4358: #
1.338 albertel 4359: if ($notitle) {
1.337 albertel 4360: return $bodytag;
4361: }
1.94 www 4362: return(<<ENDBODY);
1.60 matthew 4363: $bodytag
1.359 albertel 4364: <table id="LC_title_bar" class="LC_with_remote">
1.368 albertel 4365: <tr><td class="LC_title_bar_role_logo">$upperleft</td>
1.359 albertel 4366: <td class="LC_title_bar_domain_logo">$messages </td>
1.54 www 4367: </tr>
1.359 albertel 4368: <tr><td>$titleinfo $dc_info $menu</td>
4369: $roleinfo
1.368 albertel 4370: </tr>
1.356 albertel 4371: </table>
1.54 www 4372: ENDBODY
1.182 matthew 4373: }
4374:
1.330 albertel 4375: sub make_attr_string {
4376: my ($register,$attr_ref) = @_;
4377:
4378: if ($attr_ref && !ref($attr_ref)) {
4379: die("addentries Must be a hash ref ".
4380: join(':',caller(1))." ".
4381: join(':',caller(0))." ");
4382: }
4383:
4384: if ($register) {
1.339 albertel 4385: my ($on_load,$on_unload);
4386: foreach my $key (keys(%{$attr_ref})) {
4387: if (lc($key) eq 'onload') {
4388: $on_load.=$attr_ref->{$key}.';';
4389: delete($attr_ref->{$key});
4390:
4391: } elsif (lc($key) eq 'onunload') {
4392: $on_unload.=$attr_ref->{$key}.';';
4393: delete($attr_ref->{$key});
4394: }
4395: }
4396: $attr_ref->{'onload'} =
4397: &Apache::lonmenu::loadevents(). $on_load;
4398: $attr_ref->{'onunload'}=
4399: &Apache::lonmenu::unloadevents().$on_unload;
4400: }
4401:
4402: # Accessibility font enhance
4403: if ($env{'browser.fontenhance'} eq 'on') {
4404: my $style;
4405: foreach my $key (keys(%{$attr_ref})) {
4406: if (lc($key) eq 'style') {
4407: $style.=$attr_ref->{$key}.';';
4408: delete($attr_ref->{$key});
4409: }
4410: }
4411: $attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330 albertel 4412: }
1.339 albertel 4413:
4414: if ($env{'browser.blackwhite'} eq 'on') {
4415: delete($attr_ref->{'font'});
4416: delete($attr_ref->{'link'});
4417: delete($attr_ref->{'alink'});
4418: delete($attr_ref->{'vlink'});
4419: delete($attr_ref->{'bgcolor'});
4420: delete($attr_ref->{'background'});
4421: }
4422:
1.330 albertel 4423: my $attr_string;
4424: foreach my $attr (keys(%$attr_ref)) {
4425: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
4426: }
4427: return $attr_string;
4428: }
4429:
4430:
1.182 matthew 4431: ###############################################
1.251 albertel 4432: ###############################################
4433:
4434: =pod
4435:
4436: =item * &endbodytag()
4437:
4438: Returns a uniform footer for LON-CAPA web pages.
4439:
1.635 raeburn 4440: Inputs: 1 - optional reference to an args hash
4441: If in the hash, key for noredirectlink has a value which evaluates to true,
4442: a 'Continue' link is not displayed if the page contains an
4443: internal redirect in the <head></head> section,
4444: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 4445:
4446: =cut
4447:
4448: sub endbodytag {
1.635 raeburn 4449: my ($args) = @_;
1.251 albertel 4450: my $endbodytag='</body>';
1.269 albertel 4451: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 4452: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 4453: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
4454: $endbodytag=
4455: "<br /><a href=\"$env{'internal.head.redirect'}\">".
4456: &mt('Continue').'</a>'.
4457: $endbodytag;
4458: }
1.315 albertel 4459: }
1.251 albertel 4460: return $endbodytag;
4461: }
4462:
1.352 albertel 4463: =pod
4464:
4465: =item * &standard_css()
4466:
4467: Returns a style sheet
4468:
4469: Inputs: (all optional)
4470: domain -> force to color decorate a page for a specific
4471: domain
4472: function -> force usage of a specific rolish color scheme
4473: bgcolor -> override the default page bgcolor
4474:
4475: =cut
4476:
1.343 albertel 4477: sub standard_css {
1.345 albertel 4478: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 4479: $function = &get_users_function() if (!$function);
4480: my $img = &designparm($function.'.img', $domain);
4481: my $tabbg = &designparm($function.'.tabbg', $domain);
4482: my $font = &designparm($function.'.font', $domain);
1.345 albertel 4483: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 4484: my $pgbg_or_bgcolor =
4485: $bgcolor ||
1.352 albertel 4486: &designparm($function.'.pgbg', $domain);
1.382 albertel 4487: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 4488: my $alink = &designparm($function.'.alink', $domain);
4489: my $vlink = &designparm($function.'.vlink', $domain);
4490: my $link = &designparm($function.'.link', $domain);
4491:
1.704 muellerd 4492: my $loginbg = &designparm('login.sidebg',$domain);
1.712 muellerd 4493: my $bgcol = &designparm('login.bgcol',$domain);
4494: my $textcol = &designparm('login.textcol',$domain);
1.704 muellerd 4495:
1.602 albertel 4496: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 4497: my $mono = 'monospace';
1.352 albertel 4498: my $data_table_head = $tabbg;
4499: my $data_table_light = '#EEEEEE';
1.470 banghart 4500: my $data_table_dark = '#DDDDDD';
4501: my $data_table_darker = '#CCCCCC';
1.349 albertel 4502: my $data_table_highlight = '#FFFF00';
1.352 albertel 4503: my $mail_new = '#FFBB77';
4504: my $mail_new_hover = '#DD9955';
4505: my $mail_read = '#BBBB77';
4506: my $mail_read_hover = '#999944';
4507: my $mail_replied = '#AAAA88';
4508: my $mail_replied_hover = '#888855';
4509: my $mail_other = '#99BBBB';
4510: my $mail_other_hover = '#669999';
1.391 albertel 4511: my $table_header = '#DDDDDD';
1.489 raeburn 4512: my $feedback_link_bg = '#BBBBBB';
1.701 harmsja 4513: my $lg_border_color = '#C8C8C8';
1.392 albertel 4514:
1.608 albertel 4515: my $border = ($env{'browser.type'} eq 'explorer' ||
4516: $env{'browser.type'} eq 'safari' ) ? '0px 2px 0px 2px'
4517: : '0px 3px 0px 4px';
1.448 albertel 4518:
1.523 albertel 4519:
1.343 albertel 4520: return <<END;
1.698 harmsja 4521: body{
4522: font-family: $sans;
4523: line-height:130%;
1.701 harmsja 4524: font-size:0.83em;
1.698 harmsja 4525: color:$font;
4526: }
1.701 harmsja 4527: a:link, a:visited { font-size:100%; }
1.698 harmsja 4528:
1.779 bisitz 4529: a:focus { color: red; background: yellow }
1.510 albertel 4530: table.thinborder,
4531: table.thinborder tr th {
4532: border-style: solid;
4533: border-width: 1px;
1.698 harmsja 4534: border-color: $lg_border_color;
1.510 albertel 4535: background: $tabbg;
4536: }
1.523 albertel 4537: table.thinborder tr td {
1.510 albertel 4538: border-style: solid;
1.698 harmsja 4539: border-width: 1px;
4540: border-color: $lg_border_color;
1.510 albertel 4541: }
1.426 albertel 4542:
1.343 albertel 4543: form, .inline { display: inline; }
1.721 harmsja 4544:
4545: .LC_right {text-align:right;}
4546: .LC_middle {vertical-align:middle;}
4547:
4548: /* just for tests */
1.754 droeschl 4549: .LC_400Box {width:400px; }
1.721 harmsja 4550: /* end */
4551:
1.778 bisitz 4552: .LC_filename {
4553: font-family: $mono;
4554: white-space:pre;
4555: }
4556:
4557: .LC_fileicon {
4558: border: none;
4559: height: 1.3em;
4560: vertical-align: text-bottom;
4561: margin-right: 0.3em;
4562: text-decoration:none;
4563: }
4564:
1.350 albertel 4565: .LC_error {
4566: color: red;
4567: font-size: larger;
4568: }
1.457 albertel 4569: .LC_warning,
4570: .LC_diff_removed {
1.733 bisitz 4571: color: red;
1.394 albertel 4572: }
1.532 albertel 4573:
4574: .LC_info,
1.457 albertel 4575: .LC_success,
4576: .LC_diff_added {
1.350 albertel 4577: color: green;
4578: }
1.543 albertel 4579: .LC_unknown {
4580: color: yellow;
4581: }
4582:
1.440 albertel 4583: .LC_icon {
1.771 droeschl 4584: border: none;
4585: }
4586:
1.539 albertel 4587: .LC_indexer_icon {
4588: border: 0px;
4589: height: 22px;
4590: }
1.543 albertel 4591: .LC_docs_spacer {
4592: width: 25px;
4593: height: 1px;
1.771 droeschl 4594: border: none;
1.543 albertel 4595: }
1.346 albertel 4596:
1.532 albertel 4597: .LC_internal_info {
1.735 bisitz 4598: color: #999999;
1.532 albertel 4599: }
4600:
1.458 albertel 4601: table.LC_pastsubmission {
4602: border: 1px solid black;
4603: margin: 2px;
4604: }
4605:
1.606 albertel 4606: table#LC_top_nav, table#LC_menubuttons,table#LC_nav_location {
1.345 albertel 4607: width: 100%;
4608: background: $pgbg;
1.392 albertel 4609: border: 2px;
1.402 albertel 4610: border-collapse: separate;
1.403 albertel 4611: padding: 0px;
1.345 albertel 4612: }
1.392 albertel 4613:
1.779 bisitz 4614: table#LC_title_bar, table.LC_breadcrumbs,
1.393 albertel 4615: table#LC_title_bar.LC_with_remote {
1.359 albertel 4616: width: 100%;
1.392 albertel 4617: border-color: $pgbg;
4618: border-style: solid;
4619: border-width: $border;
4620:
1.379 albertel 4621: background: $pgbg;
4622: font-family: $sans;
1.392 albertel 4623: border-collapse: collapse;
1.403 albertel 4624: padding: 0px;
1.359 albertel 4625: }
1.409 albertel 4626: table.LC_docs_path {
4627: width: 100%;
4628: border: 0;
4629: background: $pgbg;
4630: font-family: $sans;
4631: border-collapse: collapse;
4632: padding: 0px;
4633: }
4634:
1.359 albertel 4635: table#LC_title_bar td {
4636: background: $tabbg;
4637: }
1.773 ehlerst 4638: table#LC_title_bar .LC_title_bar_who {
1.359 albertel 4639: background: $tabbg;
4640: color: $font;
1.427 albertel 4641: font: small $sans;
1.359 albertel 4642: text-align: right;
1.773 ehlerst 4643: margin: 0px;
4644: }
4645: table#LC_title_bar .LC_title_bar_name {
4646: margin: 0px;
4647: }
4648: table#LC_title_bar .LC_title_bar_role {
4649: margin: 0px;
4650: }
1.775 bisitz 4651: table#LC_title_bar .LC_title_bar_realm {
1.773 ehlerst 4652: margin: 0px;
1.359 albertel 4653: }
1.469 banghart 4654: span.LC_metadata {
4655: font-family: $sans;
4656: }
1.359 albertel 4657: table#LC_title_bar td.LC_title_bar_domain_logo {
4658: background: $sidebg;
4659: text-align: right;
1.368 albertel 4660: padding: 0px;
4661: }
4662: table#LC_title_bar td.LC_title_bar_role_logo {
4663: background: $sidebg;
4664: padding: 0px;
1.359 albertel 4665: }
4666:
1.706 harmsja 4667: table#LC_menubuttons img{
1.346 albertel 4668: border: 0px;
4669: }
1.345 albertel 4670: table#LC_top_nav td {
4671: background: $tabbg;
1.392 albertel 4672: border: 0px;
1.407 albertel 4673: font-size: small;
1.706 harmsja 4674: vertical-align:top;
4675: padding:2px 5px 2px 5px;
1.345 albertel 4676: }
4677: table#LC_top_nav td a, div#LC_top_nav a {
4678: color: $font;
4679: font-family: $sans;
4680: }
1.364 albertel 4681: table#LC_top_nav td.LC_top_nav_logo {
4682: background: $tabbg;
1.432 albertel 4683: text-align: left;
1.408 albertel 4684: white-space: nowrap;
1.432 albertel 4685: width: 31px;
1.408 albertel 4686: }
4687: table#LC_top_nav td.LC_top_nav_logo img {
1.432 albertel 4688: border: 0px;
1.408 albertel 4689: vertical-align: bottom;
1.364 albertel 4690: }
1.777 tempelho 4691: table#LC_top_nav td.LC_top_nav_exit,
1.779 bisitz 4692: table#LC_top_nav td.LC_top_nav_help {
1.777 tempelho 4693: width: 2.0em;
4694: }
1.442 albertel 4695: table#LC_top_nav td.LC_top_nav_login {
4696: width: 4.0em;
4697: text-align: center;
4698: }
1.409 albertel 4699: table.LC_breadcrumbs td, table.LC_docs_path td {
1.357 albertel 4700: background: $tabbg;
4701: color: $font;
4702: font-family: $sans;
1.358 albertel 4703: font-size: smaller;
1.357 albertel 4704: }
1.777 tempelho 4705: table.LC_breadcrumbs td.LC_breadcrumbs_component,
4706: table.LC_docs_path td.LC_docs_path_component {
1.779 bisitz 4707: background: $tabbg;
1.777 tempelho 4708: color: $font;
4709: font-family: $sans;
1.779 bisitz 4710: font-size: larger;
4711: text-align: right;
1.777 tempelho 4712: }
1.383 albertel 4713: td.LC_table_cell_checkbox {
4714: text-align: center;
4715: }
1.779 bisitz 4716: table#LC_mainmenu td.LC_mainmenu_column {
4717: vertical-align: top;
1.777 tempelho 4718: }
1.522 albertel 4719:
1.705 tempelho 4720: .LC_fontsize_small
4721: {
4722: font-size: 70%;
4723: }
4724:
4725: .LC_fontsize_medium
4726: {
4727: font-size: 85%;
4728: }
4729:
4730: .LC_fontsize_large
4731: {
4732: font-size: 120%;
4733: }
4734:
1.346 albertel 4735: .LC_menubuttons_inline_text {
4736: color: $font;
4737: font-family: $sans;
1.698 harmsja 4738: font-size: 90%;
1.701 harmsja 4739: padding-left:3px;
1.346 albertel 4740: }
4741:
1.526 www 4742: .LC_menubuttons_link {
4743: text-decoration: none;
4744: }
1.698 harmsja 4745: /*2008--9-5: new menu style sheet.Changed category*/
1.522 albertel 4746: .LC_menubuttons_category {
1.521 www 4747: color: $font;
1.526 www 4748: background: $pgbg;
1.521 www 4749: font-family: $sans;
4750: font-size: larger;
4751: font-weight: bold;
4752: }
4753:
1.346 albertel 4754: td.LC_menubuttons_text {
1.779 bisitz 4755: color: $font;
1.346 albertel 4756: }
1.706 harmsja 4757:
4758:
1.526 www 4759:
1.346 albertel 4760: .LC_current_location {
4761: font-family: $sans;
4762: background: $tabbg;
4763: }
4764: .LC_new_mail {
4765: font-family: $sans;
1.634 www 4766: background: $tabbg;
1.346 albertel 4767: font-weight: bold;
4768: }
1.347 albertel 4769:
1.526 www 4770:
1.527 www 4771: .LC_dropadd_labeltext {
4772: font-family: $sans;
4773: text-align: right;
4774: }
4775:
4776: .LC_preferences_labeltext {
4777: font-family: $sans;
4778: text-align: right;
4779: }
4780:
1.666 raeburn 4781: .LC_roleslog_note {
1.701 harmsja 4782: font-size: small;
1.666 raeburn 4783: }
4784:
1.715 raeburn 4785: .LC_mail_functions {
4786: font-weight: bold;
4787: }
4788:
1.440 albertel 4789: table.LC_aboutme_port {
4790: border: 0px;
4791: border-collapse: collapse;
4792: border-spacing: 0px;
4793: }
1.349 albertel 4794: table.LC_data_table, table.LC_mail_list {
1.347 albertel 4795: border: 1px solid #000000;
1.402 albertel 4796: border-collapse: separate;
1.426 albertel 4797: border-spacing: 1px;
1.610 albertel 4798: background: $pgbg;
1.347 albertel 4799: }
1.422 albertel 4800: .LC_data_table_dense {
4801: font-size: small;
4802: }
1.507 raeburn 4803: table.LC_nested_outer {
4804: border: 1px solid #000000;
1.589 raeburn 4805: border-collapse: collapse;
1.507 raeburn 4806: border-spacing: 0px;
4807: width: 100%;
4808: }
4809: table.LC_nested {
4810: border: 0px;
1.589 raeburn 4811: border-collapse: collapse;
1.507 raeburn 4812: border-spacing: 0px;
4813: width: 100%;
4814: }
1.523 albertel 4815: table.LC_data_table tr th, table.LC_calendar tr th, table.LC_mail_list tr th,
4816: table.LC_prior_tries tr th {
1.349 albertel 4817: font-weight: bold;
4818: background-color: $data_table_head;
1.701 harmsja 4819: font-size:90%;
1.347 albertel 4820: }
1.711 raeburn 4821: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 4822: background-color: #CCCCCC;
1.711 raeburn 4823: font-weight: bold;
4824: text-align: left;
4825: }
1.779 bisitz 4826: table.LC_data_table tr.LC_odd_row > td,
1.709 bisitz 4827: table.LC_pick_box tr > td.LC_odd_row,
1.440 albertel 4828: table.LC_aboutme_port tr td {
1.349 albertel 4829: background-color: $data_table_light;
1.425 albertel 4830: padding: 2px;
1.347 albertel 4831: }
1.610 albertel 4832: table.LC_data_table tr.LC_even_row > td,
1.709 bisitz 4833: table.LC_pick_box tr > td.LC_even_row,
1.440 albertel 4834: table.LC_aboutme_port tr.LC_even_row td {
1.349 albertel 4835: background-color: $data_table_dark;
1.709 bisitz 4836: padding: 2px;
1.347 albertel 4837: }
1.425 albertel 4838: table.LC_data_table tr.LC_data_table_highlight td {
4839: background-color: $data_table_darker;
4840: }
1.639 raeburn 4841: table.LC_data_table tr td.LC_leftcol_header {
4842: background-color: $data_table_head;
4843: font-weight: bold;
4844: }
1.451 albertel 4845: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 4846: table.LC_nested tr.LC_empty_row td {
1.347 albertel 4847: background-color: #FFFFFF;
1.421 albertel 4848: font-weight: bold;
4849: font-style: italic;
4850: text-align: center;
4851: padding: 8px;
1.347 albertel 4852: }
1.507 raeburn 4853: table.LC_nested tr.LC_empty_row td {
1.465 albertel 4854: padding: 4ex
4855: }
1.507 raeburn 4856: table.LC_nested_outer tr th {
4857: font-weight: bold;
4858: background-color: $data_table_head;
1.701 harmsja 4859: font-size: small;
1.507 raeburn 4860: border-bottom: 1px solid #000000;
4861: }
4862: table.LC_nested_outer tr td.LC_subheader {
4863: background-color: $data_table_head;
4864: font-weight: bold;
4865: font-size: small;
4866: border-bottom: 1px solid #000000;
4867: text-align: right;
1.451 albertel 4868: }
1.507 raeburn 4869: table.LC_nested tr.LC_info_row td {
1.735 bisitz 4870: background-color: #CCCCCC;
1.451 albertel 4871: font-weight: bold;
4872: font-size: small;
1.507 raeburn 4873: text-align: center;
4874: }
1.589 raeburn 4875: table.LC_nested tr.LC_info_row td.LC_left_item,
4876: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 4877: text-align: left;
1.451 albertel 4878: }
1.507 raeburn 4879: table.LC_nested td {
1.735 bisitz 4880: background-color: #FFFFFF;
1.451 albertel 4881: font-size: small;
1.507 raeburn 4882: }
4883: table.LC_nested_outer tr th.LC_right_item,
4884: table.LC_nested tr.LC_info_row td.LC_right_item,
4885: table.LC_nested tr.LC_odd_row td.LC_right_item,
4886: table.LC_nested tr td.LC_right_item {
1.451 albertel 4887: text-align: right;
4888: }
4889:
1.507 raeburn 4890: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 4891: background-color: #EEEEEE;
1.451 albertel 4892: }
4893:
1.473 raeburn 4894: table.LC_createuser {
4895: }
4896:
4897: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 4898: font-size: small;
1.473 raeburn 4899: }
4900:
4901: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 4902: background-color: #CCCCCC;
1.473 raeburn 4903: font-weight: bold;
4904: text-align: center;
4905: }
4906:
1.349 albertel 4907: table.LC_calendar {
4908: border: 1px solid #000000;
4909: border-collapse: collapse;
4910: }
4911: table.LC_calendar_pickdate {
4912: font-size: xx-small;
4913: }
4914: table.LC_calendar tr td {
4915: border: 1px solid #000000;
4916: vertical-align: top;
4917: }
4918: table.LC_calendar tr td.LC_calendar_day_empty {
4919: background-color: $data_table_dark;
4920: }
1.779 bisitz 4921: table.LC_calendar tr td.LC_calendar_day_current {
4922: background-color: $data_table_highlight;
1.777 tempelho 4923: }
1.349 albertel 4924: table.LC_mail_list tr.LC_mail_new {
4925: background-color: $mail_new;
4926: }
4927: table.LC_mail_list tr.LC_mail_new:hover {
4928: background-color: $mail_new_hover;
4929: }
1.777 tempelho 4930: table.LC_mail_list tr.LC_mail_even{
4931: }
4932: table.LC_mail_list tr.LC_mail_odd{
4933: }
1.349 albertel 4934: table.LC_mail_list tr.LC_mail_read {
4935: background-color: $mail_read;
4936: }
4937: table.LC_mail_list tr.LC_mail_read:hover {
4938: background-color: $mail_read_hover;
4939: }
4940: table.LC_mail_list tr.LC_mail_replied {
4941: background-color: $mail_replied;
4942: }
4943: table.LC_mail_list tr.LC_mail_replied:hover {
4944: background-color: $mail_replied_hover;
4945: }
4946: table.LC_mail_list tr.LC_mail_other {
4947: background-color: $mail_other;
4948: }
4949: table.LC_mail_list tr.LC_mail_other:hover {
4950: background-color: $mail_other_hover;
4951: }
1.494 raeburn 4952:
1.777 tempelho 4953: table.LC_data_table tr > td.LC_browser_file,
4954: table.LC_data_table tr > td.LC_browser_file_published {
1.389 albertel 4955: background: #CCFF88;
4956: }
1.777 tempelho 4957: table.LC_data_table tr > td.LC_browser_file_locked,
4958: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 4959: background: #FFAA99;
1.387 albertel 4960: }
1.777 tempelho 4961: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.779 bisitz 4962: background: #AAAAAA;
4963: }
1.777 tempelho 4964: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 4965: table.LC_data_table tr > td.LC_browser_file_metamodified {
4966: background: #FFFF77;
1.777 tempelho 4967: }
1.696 bisitz 4968: table.LC_data_table tr.LC_browser_folder > td {
1.389 albertel 4969: background: #CCCCFF;
1.387 albertel 4970: }
1.696 bisitz 4971:
1.707 bisitz 4972: table.LC_data_table tr > td.LC_roles_is {
4973: /* background: #77FF77; */
4974: }
4975: table.LC_data_table tr > td.LC_roles_future {
4976: background: #FFFF77;
4977: }
4978: table.LC_data_table tr > td.LC_roles_will {
4979: background: #FFAA77;
4980: }
4981: table.LC_data_table tr > td.LC_roles_expired {
4982: background: #FF7777;
4983: }
4984: table.LC_data_table tr > td.LC_roles_will_not {
4985: background: #AAFF77;
4986: }
4987: table.LC_data_table tr > td.LC_roles_selected {
4988: background: #11CC55;
4989: }
4990:
1.388 albertel 4991: span.LC_current_location {
1.701 harmsja 4992: font-size:larger;
1.388 albertel 4993: background: $pgbg;
4994: }
1.387 albertel 4995:
1.395 albertel 4996: span.LC_parm_menu_item {
4997: font-size: larger;
4998: font-family: $sans;
4999: }
5000: span.LC_parm_scope_all {
5001: color: red;
5002: }
5003: span.LC_parm_scope_folder {
5004: color: green;
5005: }
5006: span.LC_parm_scope_resource {
5007: color: orange;
5008: }
5009: span.LC_parm_part {
5010: color: blue;
5011: }
5012: span.LC_parm_folder, span.LC_parm_symb {
5013: font-size: x-small;
5014: font-family: $mono;
5015: color: #AAAAAA;
5016: }
5017:
1.396 albertel 5018: td.LC_parm_overview_level_menu, td.LC_parm_overview_map_menu,
1.777 tempelho 5019: td.LC_parm_overview_parm_selectors,td.LC_parm_overview_restrictions {
1.396 albertel 5020: border: 1px solid black;
5021: border-collapse: collapse;
5022: }
5023: table.LC_parm_overview_restrictions td {
5024: border-width: 1px 4px 1px 4px;
5025: border-style: solid;
5026: border-color: $pgbg;
5027: text-align: center;
5028: }
5029: table.LC_parm_overview_restrictions th {
5030: background: $tabbg;
5031: border-width: 1px 4px 1px 4px;
5032: border-style: solid;
5033: border-color: $pgbg;
5034: }
1.398 albertel 5035: table#LC_helpmenu {
5036: border: 0px;
5037: height: 55px;
5038: border-spacing: 0px;
5039: }
5040:
5041: table#LC_helpmenu fieldset legend {
5042: font-size: larger;
5043: font-weight: bold;
5044: }
1.397 albertel 5045: table#LC_helpmenu_links {
5046: width: 100%;
5047: border: 1px solid black;
5048: background: $pgbg;
5049: padding: 0px;
5050: border-spacing: 1px;
5051: }
5052: table#LC_helpmenu_links tr td {
5053: padding: 1px;
5054: background: $tabbg;
1.399 albertel 5055: text-align: center;
5056: font-weight: bold;
1.397 albertel 5057: }
1.396 albertel 5058:
1.397 albertel 5059: table#LC_helpmenu_links a:link, table#LC_helpmenu_links a:visited,
5060: table#LC_helpmenu_links a:active {
5061: text-decoration: none;
5062: color: $font;
5063: }
5064: table#LC_helpmenu_links a:hover {
5065: text-decoration: underline;
5066: color: $vlink;
5067: }
1.396 albertel 5068:
1.417 albertel 5069: .LC_chrt_popup_exists {
5070: border: 1px solid #339933;
5071: margin: -1px;
5072: }
5073: .LC_chrt_popup_up {
5074: border: 1px solid yellow;
5075: margin: -1px;
5076: }
5077: .LC_chrt_popup {
5078: border: 1px solid #8888FF;
5079: background: #CCCCFF;
5080: }
1.421 albertel 5081: table.LC_pick_box {
5082: border-collapse: separate;
5083: background: white;
5084: border: 1px solid black;
5085: border-spacing: 1px;
5086: }
5087: table.LC_pick_box td.LC_pick_box_title {
5088: background: $tabbg;
5089: font-weight: bold;
5090: text-align: right;
1.740 bisitz 5091: vertical-align: top;
1.421 albertel 5092: width: 184px;
5093: padding: 8px;
5094: }
1.645 raeburn 5095: table.LC_pick_box td.LC_selfenroll_pick_box_title {
5096: background: $tabbg;
5097: font-weight: bold;
5098: text-align: right;
5099: width: 350px;
5100: padding: 8px;
5101: }
5102:
1.579 raeburn 5103: table.LC_pick_box td.LC_pick_box_value {
5104: text-align: left;
5105: padding: 8px;
5106: }
5107: table.LC_pick_box td.LC_pick_box_select {
5108: text-align: left;
5109: padding: 8px;
5110: }
1.424 albertel 5111: table.LC_pick_box td.LC_pick_box_separator {
1.421 albertel 5112: padding: 0px;
5113: height: 1px;
5114: background: black;
5115: }
5116: table.LC_pick_box td.LC_pick_box_submit {
5117: text-align: right;
5118: }
1.579 raeburn 5119: table.LC_pick_box td.LC_evenrow_value {
5120: text-align: left;
5121: padding: 8px;
5122: background-color: $data_table_light;
5123: }
5124: table.LC_pick_box td.LC_oddrow_value {
5125: text-align: left;
5126: padding: 8px;
5127: background-color: $data_table_light;
5128: }
5129: table.LC_helpform_receipt {
5130: width: 620px;
5131: border-collapse: separate;
5132: background: white;
5133: border: 1px solid black;
5134: border-spacing: 1px;
5135: }
5136: table.LC_helpform_receipt td.LC_pick_box_title {
5137: background: $tabbg;
5138: font-weight: bold;
5139: text-align: right;
5140: width: 184px;
5141: padding: 8px;
5142: }
5143: table.LC_helpform_receipt td.LC_evenrow_value {
5144: text-align: left;
5145: padding: 8px;
5146: background-color: $data_table_light;
5147: }
5148: table.LC_helpform_receipt td.LC_oddrow_value {
5149: text-align: left;
5150: padding: 8px;
5151: background-color: $data_table_light;
5152: }
5153: table.LC_helpform_receipt td.LC_pick_box_separator {
5154: padding: 0px;
5155: height: 1px;
5156: background: black;
5157: }
5158: span.LC_helpform_receipt_cat {
5159: font-weight: bold;
5160: }
1.424 albertel 5161: table.LC_group_priv_box {
5162: background: white;
5163: border: 1px solid black;
5164: border-spacing: 1px;
5165: }
5166: table.LC_group_priv_box td.LC_pick_box_title {
5167: background: $tabbg;
5168: font-weight: bold;
5169: text-align: right;
5170: width: 184px;
5171: }
5172: table.LC_group_priv_box td.LC_groups_fixed {
5173: background: $data_table_light;
5174: text-align: center;
5175: }
5176: table.LC_group_priv_box td.LC_groups_optional {
5177: background: $data_table_dark;
5178: text-align: center;
5179: }
5180: table.LC_group_priv_box td.LC_groups_functionality {
5181: background: $data_table_darker;
5182: text-align: center;
5183: font-weight: bold;
5184: }
5185: table.LC_group_priv td {
5186: text-align: left;
5187: padding: 0px;
5188: }
5189:
1.421 albertel 5190: table.LC_notify_front_page {
5191: background: white;
5192: border: 1px solid black;
5193: padding: 8px;
5194: }
5195: table.LC_notify_front_page td {
5196: padding: 8px;
5197: }
1.424 albertel 5198: .LC_navbuttons {
5199: margin: 2ex 0ex 2ex 0ex;
5200: }
1.423 albertel 5201: .LC_topic_bar {
5202: font-family: $sans;
5203: font-weight: bold;
5204: width: 100%;
5205: background: $tabbg;
5206: vertical-align: middle;
5207: margin: 2ex 0ex 2ex 0ex;
5208: }
5209: .LC_topic_bar span {
5210: vertical-align: middle;
5211: }
5212: .LC_topic_bar img {
5213: vertical-align: bottom;
5214: }
5215: table.LC_course_group_status {
5216: margin: 20px;
5217: }
5218: table.LC_status_selector td {
5219: vertical-align: top;
5220: text-align: center;
1.424 albertel 5221: padding: 4px;
5222: }
5223: table.LC_descriptive_input td.LC_description {
5224: vertical-align: top;
5225: text-align: right;
5226: font-weight: bold;
1.423 albertel 5227: }
1.599 albertel 5228: div.LC_feedback_link {
1.616 albertel 5229: clear: both;
1.599 albertel 5230: background: white;
1.779 bisitz 5231: width: 100%;
1.489 raeburn 5232: }
5233: span.LC_feedback_link {
1.599 albertel 5234: background: $feedback_link_bg;
5235: font-size: larger;
5236: }
5237: span.LC_message_link {
5238: background: $feedback_link_bg;
5239: font-size: larger;
5240: position: absolute;
5241: right: 1em;
1.489 raeburn 5242: }
1.421 albertel 5243:
1.515 albertel 5244: table.LC_prior_tries {
1.524 albertel 5245: border: 1px solid #000000;
5246: border-collapse: separate;
5247: border-spacing: 1px;
1.515 albertel 5248: }
1.523 albertel 5249:
1.515 albertel 5250: table.LC_prior_tries td {
1.524 albertel 5251: padding: 2px;
1.515 albertel 5252: }
1.523 albertel 5253:
5254: .LC_answer_correct {
5255: background: #AAFFAA;
5256: color: black;
5257: }
5258: .LC_answer_charged_try {
5259: background: #FFAAAA ! important;
5260: color: black;
5261: }
1.779 bisitz 5262: .LC_answer_not_charged_try,
1.523 albertel 5263: .LC_answer_no_grade,
5264: .LC_answer_late {
5265: background: #FFFFAA;
5266: color: black;
5267: }
5268: .LC_answer_previous {
5269: background: #AAAAFF;
5270: color: black;
5271: }
1.779 bisitz 5272: .LC_answer_no_message {
1.777 tempelho 5273: background: #FFFFFF;
5274: color: black;
1.779 bisitz 5275: }
5276: .LC_answer_unknown {
5277: background: orange;
5278: color: black;
1.777 tempelho 5279: }
1.529 albertel 5280: span.LC_prior_numerical,
5281: span.LC_prior_string,
5282: span.LC_prior_custom,
5283: span.LC_prior_reaction,
5284: span.LC_prior_math {
1.523 albertel 5285: font-family: monospace;
5286: white-space: pre;
5287: }
5288:
1.525 albertel 5289: span.LC_prior_string {
5290: font-family: monospace;
5291: white-space: pre;
5292: }
5293:
1.523 albertel 5294: table.LC_prior_option {
5295: width: 100%;
5296: border-collapse: collapse;
5297: }
1.528 albertel 5298: table.LC_prior_rank, table.LC_prior_match {
5299: border-collapse: collapse;
5300: }
5301: table.LC_prior_option tr td,
5302: table.LC_prior_rank tr td,
5303: table.LC_prior_match tr td {
1.524 albertel 5304: border: 1px solid #000000;
1.515 albertel 5305: }
5306:
1.770 droeschl 5307: td.LC_nobreak,
1.519 raeburn 5308: span.LC_nobreak {
1.544 albertel 5309: white-space: nowrap;
1.519 raeburn 5310: }
5311:
1.576 raeburn 5312: span.LC_cusr_emph {
5313: font-style: italic;
5314: }
5315:
1.633 raeburn 5316: span.LC_cusr_subheading {
5317: font-weight: normal;
5318: font-size: 85%;
5319: }
5320:
1.545 albertel 5321: table.LC_docs_documents {
5322: background: #BBBBBB;
1.547 albertel 5323: border-width: 0px;
1.545 albertel 5324: border-collapse: collapse;
5325: }
1.777 tempelho 5326: table.LC_docs_documents td.LC_docs_document {
1.779 bisitz 5327: border: 2px solid black;
5328: padding: 4px;
1.777 tempelho 5329: }
1.545 albertel 5330: .LC_docs_entry_move {
5331: border: 0px;
5332: border-collapse: collapse;
1.544 albertel 5333: }
5334:
1.545 albertel 5335: .LC_docs_entry_move td {
5336: border: 2px solid #BBBBBB;
5337: background: #DDDDDD;
5338: }
5339:
5340: .LC_docs_editor td.LC_docs_entry_commands {
5341: background: #DDDDDD;
5342: font-size: x-small;
5343: }
1.544 albertel 5344: .LC_docs_copy {
1.545 albertel 5345: color: #000099;
1.544 albertel 5346: }
5347: .LC_docs_cut {
1.545 albertel 5348: color: #550044;
1.544 albertel 5349: }
5350: .LC_docs_rename {
1.545 albertel 5351: color: #009900;
1.544 albertel 5352: }
5353: .LC_docs_remove {
1.545 albertel 5354: color: #990000;
5355: }
5356:
1.547 albertel 5357: .LC_docs_reinit_warn,
5358: .LC_docs_ext_edit {
5359: font-size: x-small;
5360: }
5361:
1.545 albertel 5362: .LC_docs_editor td.LC_docs_entry_title,
5363: .LC_docs_editor td.LC_docs_entry_icon {
5364: background: #FFFFBB;
5365: }
5366: .LC_docs_editor td.LC_docs_entry_parameter {
5367: background: #BBBBFF;
5368: font-size: x-small;
5369: white-space: nowrap;
5370: }
5371:
5372: table.LC_docs_adddocs td,
5373: table.LC_docs_adddocs th {
5374: border: 1px solid #BBBBBB;
5375: padding: 4px;
5376: background: #DDDDDD;
1.543 albertel 5377: }
5378:
1.584 albertel 5379: table.LC_sty_begin {
5380: background: #BBFFBB;
5381: }
5382: table.LC_sty_end {
5383: background: #FFBBBB;
5384: }
5385:
1.589 raeburn 5386: table.LC_double_column {
5387: border-width: 0px;
5388: border-collapse: collapse;
5389: width: 100%;
5390: padding: 2px;
5391: }
5392:
5393: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 5394: top: 2px;
1.589 raeburn 5395: left: 2px;
5396: width: 47%;
5397: vertical-align: top;
5398: }
5399:
5400: table.LC_double_column tr td.LC_right_col {
5401: top: 2px;
1.779 bisitz 5402: right: 2px;
1.589 raeburn 5403: width: 47%;
5404: vertical-align: top;
5405: }
5406:
1.594 raeburn 5407: span.LC_role_level {
5408: font-weight: bold;
5409: }
5410:
1.591 raeburn 5411: div.LC_left_float {
5412: float: left;
5413: padding-right: 5%;
1.597 albertel 5414: padding-bottom: 4px;
1.591 raeburn 5415: }
5416:
5417: div.LC_clear_float_header {
1.597 albertel 5418: padding-bottom: 2px;
1.591 raeburn 5419: }
5420:
5421: div.LC_clear_float_footer {
1.597 albertel 5422: padding-top: 10px;
1.591 raeburn 5423: clear: both;
5424: }
5425:
1.597 albertel 5426:
5427: div.LC_grade_show_user {
5428: margin-top: 20px;
5429: border: 1px solid black;
5430: }
5431: div.LC_grade_user_name {
5432: background: #DDDDEE;
5433: border-bottom: 1px solid black;
1.705 tempelho 5434: font-weight: bold;
5435: font-size: large;
1.597 albertel 5436: }
5437: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
5438: background: #DDEEDD;
5439: }
5440:
5441: div.LC_grade_show_problem,
5442: div.LC_grade_submissions,
5443: div.LC_grade_message_center,
5444: div.LC_grade_info_links,
5445: div.LC_grade_assign {
5446: margin: 5px;
5447: width: 99%;
5448: background: #FFFFFF;
5449: }
5450: div.LC_grade_show_problem_header,
5451: div.LC_grade_submissions_header,
5452: div.LC_grade_message_center_header,
5453: div.LC_grade_assign_header {
1.705 tempelho 5454: font-weight: bold;
5455: font-size: large;
1.597 albertel 5456: }
5457: div.LC_grade_show_problem_problem,
5458: div.LC_grade_submissions_body,
5459: div.LC_grade_message_center_body,
5460: div.LC_grade_assign_body {
5461: border: 1px solid black;
5462: width: 99%;
5463: background: #FFFFFF;
5464: }
1.598 albertel 5465: span.LC_grade_check_note {
1.705 tempelho 5466: font-weight: normal;
5467: font-size: medium;
1.598 albertel 5468: display: inline;
5469: position: absolute;
5470: right: 1em;
5471: }
1.597 albertel 5472:
1.613 albertel 5473: table.LC_scantron_action {
5474: width: 100%;
5475: }
5476: table.LC_scantron_action tr th {
1.698 harmsja 5477: font-weight:bold;
5478: font-style:normal;
1.613 albertel 5479: }
1.779 bisitz 5480: .LC_edit_problem_header,
1.614 albertel 5481: div.LC_edit_problem_footer {
1.705 tempelho 5482: font-weight: normal;
5483: font-size: medium;
1.602 albertel 5484: margin: 2px;
1.600 albertel 5485: }
5486: div.LC_edit_problem_header,
1.602 albertel 5487: div.LC_edit_problem_header div,
1.614 albertel 5488: div.LC_edit_problem_footer,
5489: div.LC_edit_problem_footer div,
1.602 albertel 5490: div.LC_edit_problem_editxml_header,
5491: div.LC_edit_problem_editxml_header div {
1.600 albertel 5492: margin-top: 5px;
5493: }
1.602 albertel 5494: div.LC_edit_problem_header_edit_row {
5495: background: $tabbg;
5496: padding: 3px;
5497: margin-bottom: 5px;
5498: }
1.600 albertel 5499: div.LC_edit_problem_header_title {
1.705 tempelho 5500: font-weight: bold;
5501: font-size: larger;
1.602 albertel 5502: background: $tabbg;
5503: padding: 3px;
5504: }
5505: table.LC_edit_problem_header_title {
1.705 tempelho 5506: font-size: larger;
5507: font-weight: bold;
1.602 albertel 5508: width: 100%;
5509: border-color: $pgbg;
5510: border-style: solid;
5511: border-width: $border;
5512:
1.600 albertel 5513: background: $tabbg;
1.602 albertel 5514: border-collapse: collapse;
5515: padding: 0px
5516: }
5517:
5518: div.LC_edit_problem_discards {
5519: float: left;
5520: padding-bottom: 5px;
5521: }
5522: div.LC_edit_problem_saves {
5523: float: right;
5524: padding-bottom: 5px;
1.600 albertel 5525: }
5526: hr.LC_edit_problem_divide {
1.602 albertel 5527: clear: both;
1.600 albertel 5528: color: $tabbg;
5529: background-color: $tabbg;
5530: height: 3px;
5531: border: 0px;
5532: }
1.679 riegler 5533: img.stift{
1.678 riegler 5534: border-width:0;
1.679 riegler 5535: vertical-align:middle;
1.677 riegler 5536: }
1.680 riegler 5537:
1.681 riegler 5538: table#LC_mainmenu{
5539: margin-top:10px;
5540: width:80%;
5541:
5542: }
5543:
1.680 riegler 5544: table#LC_mainmenu td.LC_mainmenu_col_fieldset{
5545: vertical-align: top;
5546: width: 45%;
5547: }
1.779 bisitz 5548: .LC_mainmenu_fieldset_category {
5549: color: $font;
5550: background: $pgbg;
5551: font-family: $sans;
5552: font-size: small;
5553: font-weight: bold;
1.777 tempelho 5554: }
1.716 raeburn 5555: div.LC_createcourse {
5556: margin: 10px 10px 10px 10px;
5557: }
5558:
1.693 droeschl 5559: /* ---- Remove when done ----
5560: # The following styles is part of the redesign of LON-CAPA and are
5561: # subject to change during this project.
5562: # Don't rely on their current functionality as they might be
5563: # changed or removed.
5564: # --------------------------*/
5565:
1.698 harmsja 5566: a:hover,
1.721 harmsja 5567: ol.LC_smallMenu a:hover,
5568: ol#LC_MenuBreadcrumbs a:hover,
5569: ol#LC_PathBreadcrumbs a:hover,
5570: ul#LC_TabMainMenuContent a:hover,
5571: .LC_FormSectionClearButton input:hover
5572: ul.LC_TabContent li:hover a{
1.698 harmsja 5573: color:#BF2317;
5574: text-decoration:none;
1.693 droeschl 5575: }
5576:
1.779 bisitz 5577: h1 {
1.721 harmsja 5578: padding:5px 10px 5px 20px;
1.693 droeschl 5579: line-height:130%;
5580: }
1.698 harmsja 5581:
1.693 droeschl 5582: h2,h3,h4,h5,h6
5583: {
1.721 harmsja 5584: margin:5px 0px 5px 0px;
5585: padding:0px;
5586: line-height:130%;
1.693 droeschl 5587: }
1.721 harmsja 5588: .LC_hcell{
1.698 harmsja 5589: padding:3px 15px 3px 15px;
5590: margin:0px;
1.703 harmsja 5591: background-color:$tabbg;
1.779 bisitz 5592: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 5593: }
1.721 harmsja 5594: .LC_noBorder {
1.698 harmsja 5595: border:0px;
5596: }
1.693 droeschl 5597:
5598:
1.698 harmsja 5599: /* Main Header with discription of Person, Course, etc. */
1.693 droeschl 5600:
1.761 tempelho 5601: .LC_Right {
5602: float: right;
5603: margin: 0px;
5604: padding: 0px;
5605: }
5606:
1.721 harmsja 5607: p, .LC_ContentBox {
1.698 harmsja 5608: padding: 10px;
5609:
5610: }
1.721 harmsja 5611: .LC_FormSectionClearButton input {
1.779 bisitz 5612: background-color:transparent;
1.698 harmsja 5613: border:0px;
5614: cursor:pointer;
5615: text-decoration:underline;
1.693 droeschl 5616: }
1.763 bisitz 5617:
5618: .LC_help_open_topic {
5619: color: #FFFFFF;
5620: background-color: #EEEEFF;
5621: margin: 1px;
5622: padding: 4px;
5623: border: 1px solid #000033;
5624: white-space: nowrap;
1.759 neumanie 5625: }
1.693 droeschl 5626:
1.698 harmsja 5627: dl,ul,div,fieldset {
5628: margin: 10px 10px 10px 0px;
1.693 droeschl 5629: overflow:hidden;
5630: }
1.721 harmsja 5631: ol.LC_smallMenu, ol#LC_PathBreadcrumbs {
1.698 harmsja 5632: margin: 0px;
1.693 droeschl 5633: }
5634:
1.721 harmsja 5635: ol.LC_smallMenu li {
1.693 droeschl 5636: display: inline;
5637: padding: 5px 5px 0px 10px;
5638: vertical-align: top;
5639: }
5640:
1.721 harmsja 5641: ol.LC_smallMenu li img {
1.693 droeschl 5642: vertical-align: bottom;
5643: }
5644:
1.721 harmsja 5645: ol.LC_smallMenu a {
1.693 droeschl 5646: font-size: 90%;
5647: color: RGB(80, 80, 80);
5648: text-decoration: none;
5649: }
1.760 harmsja 5650: ol#LC_TabMainMenuContent, ul.LC_TabContent ,
1.741 harmsja 5651: ul.LC_TabContentBigger {
1.721 harmsja 5652: display:block;
5653: list-style:none;
1.741 harmsja 5654: margin: 0px;
1.693 droeschl 5655: padding: 0px;
5656: }
5657:
1.744 ehlerst 5658: ol#LC_TabMainMenuContent li, ul.LC_TabContent li,
1.741 harmsja 5659: ul.LC_TabContentBigger li{
1.693 droeschl 5660: display: inline;
1.741 harmsja 5661: border-right: solid 1px $lg_border_color;
5662: float:left;
5663: line-height:140%;
5664: white-space:nowrap;
5665: }
5666: ol#LC_TabMainMenuContent li{
1.693 droeschl 5667: vertical-align: bottom;
5668: border-bottom: solid 1px RGB(175, 175, 175);
1.721 harmsja 5669: padding: 5px 10px 5px 10px;
1.741 harmsja 5670: margin-right:5px;
5671: margin-bottom:3px;
1.693 droeschl 5672: font-weight: bold;
1.723 riegler 5673: background: url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
1.693 droeschl 5674: }
5675:
1.721 harmsja 5676: ol#LC_TabMainMenuContent li a{
1.693 droeschl 5677: color: RGB(47, 47, 47);
5678: text-decoration: none;
5679: }
1.721 harmsja 5680: ul.LC_TabContent {
1.741 harmsja 5681: min-height:1.6em;
1.721 harmsja 5682: }
5683: ul.LC_TabContent li{
1.741 harmsja 5684: vertical-align:middle;
5685: padding:0px 10px 0px 10px;
1.745 ehlerst 5686: background-color:$tabbg;
5687: border-bottom:solid 1px $lg_border_color;
1.721 harmsja 5688: }
1.779 bisitz 5689: ul.LC_TabContent li a, ul.LC_TabContent li{
1.721 harmsja 5690: color:rgb(47,47,47);
5691: text-decoration:none;
5692: font-size:95%;
5693: font-weight:bold;
1.761 tempelho 5694: padding-right: 16px;
1.721 harmsja 5695: }
1.744 ehlerst 5696: ul.LC_TabContent li:hover, ul.LC_TabContent li.active{
1.761 tempelho 5697: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.745 ehlerst 5698: border-bottom:solid 1px #FFFFFF;
1.761 tempelho 5699: padding-right: 16px;
1.744 ehlerst 5700: }
1.741 harmsja 5701: ul.LC_TabContentBigger li{
5702: vertical-align:bottom;
5703: border-top:solid 1px $lg_border_color;
5704: border-left:solid 1px $lg_border_color;
5705: padding:5px 10px 5px 10px;
5706: margin-left:2px;
5707: background:url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
5708: }
1.744 ehlerst 5709: ul.LC_TabContentBigger li:hover, ul.LC_TabContentBigger li.active{
5710: background:url(/adm/lonIcons/lightGreyBG.png) repeat-x right bottom;
5711: }
1.741 harmsja 5712: ul.LC_TabContentBigger li, ul.LC_TabContentBigger li a{
5713: font-size:110%;
5714: font-weight:bold;
5715: }
1.693 droeschl 5716:
1.721 harmsja 5717: ol#LC_MenuBreadcrumbs, ol#LC_PathBreadcrumbs {
1.693 droeschl 5718: border-top: solid 1px RGB(255, 255, 255);
5719: height: 20px;
5720: line-height: 20px;
5721: vertical-align: bottom;
5722: margin: 0px 0px 30px 0px;
5723: padding-left: 10px;
5724: list-style-position: inside;
1.723 riegler 5725: background: url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
1.693 droeschl 5726: }
5727:
1.721 harmsja 5728: ol#LC_MenuBreadcrumbs li, ol#LC_PathBreadcrumbs li {
1.741 harmsja 5729: /*
1.723 riegler 5730: background: url(/adm/lonIcons/arrow_white.png) no-repeat left center;
1.779 bisitz 5731: */
1.693 droeschl 5732: display: inline;
5733: padding: 0px 0px 0px 10px;
5734: vertical-align: bottom;
5735: overflow:hidden;
5736: }
5737:
1.721 harmsja 5738: ol#LC_MenuBreadcrumbs li a {
1.693 droeschl 5739: text-decoration: none;
5740: font-size:90%;
5741: }
1.721 harmsja 5742: ol#LC_PathBreadcrumbs li a{
1.698 harmsja 5743: text-decoration:none;
5744: font-size:100%;
5745: font-weight:bold;
1.693 droeschl 5746: }
1.721 harmsja 5747: .LC_ContentBoxSpecial
1.693 droeschl 5748: {
1.701 harmsja 5749: border: solid 1px $lg_border_color;
1.746 neumanie 5750: }
5751: .LC_ContentBoxSpecialContactInfo
5752: {
5753: border: solid 1px $lg_border_color;
5754: max-width:25%;
5755: min-width:25%;
1.698 harmsja 5756: }
1.747 neumanie 5757: .LC_AboutMe_Image
5758: {
5759: float:left;
5760: margin-right:10px;
5761: }
5762: .LC_Clear_AboutMe_Image
5763: {
5764: clear:left;
5765: }
1.721 harmsja 5766: dl.LC_ListStyleClean dt {
1.693 droeschl 5767: padding-right: 5px;
5768: display: table-header-group;
5769: }
5770:
1.721 harmsja 5771: dl.LC_ListStyleClean dd {
1.693 droeschl 5772: display: table-row;
5773: }
5774:
1.721 harmsja 5775: .LC_ListStyleClean,
5776: .LC_ListStyleSimple,
5777: .LC_ListStyleNormal,
1.777 tempelho 5778: .LC_ListStyle_Border,
1.721 harmsja 5779: .LC_ListStyleSpecial
1.693 droeschl 5780: {
5781: /*display:block; */
5782: list-style-position: inside;
5783: list-style-type: none;
5784: overflow: hidden;
5785: padding: 0px;
5786: }
5787:
1.721 harmsja 5788: .LC_ListStyleSimple li,
5789: .LC_ListStyleSimple dd,
5790: .LC_ListStyleNormal li,
5791: .LC_ListStyleNormal dd,
5792: .LC_ListStyleSpecial li,
5793: .LC_ListStyleSpecial dd
1.693 droeschl 5794: {
5795: margin: 0px;
5796: padding: 5px 5px 5px 10px;
5797: clear: both;
5798: }
5799:
1.721 harmsja 5800: .LC_ListStyleClean li,
5801: .LC_ListStyleClean dd {
1.693 droeschl 5802: padding-top: 0px;
5803: padding-bottom: 0px;
5804: }
5805:
1.721 harmsja 5806: .LC_ListStyleSimple dd,
5807: .LC_ListStyleSimple li{
1.698 harmsja 5808: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 5809: }
5810:
1.721 harmsja 5811: .LC_ListStyleSpecial li,
5812: .LC_ListStyleSpecial dd {
1.693 droeschl 5813: list-style-type: none;
5814: background-color: RGB(220, 220, 220);
5815: margin-bottom: 4px;
5816: }
5817:
1.721 harmsja 5818: table.LC_SimpleTable {
1.698 harmsja 5819: margin:5px;
5820: border:solid 1px $lg_border_color;
1.693 droeschl 5821: }
5822:
1.721 harmsja 5823: table.LC_SimpleTable tr {
1.698 harmsja 5824: padding:0px;
5825: border:solid 1px $lg_border_color;
1.693 droeschl 5826: }
1.721 harmsja 5827: table.LC_SimpleTable thead{
1.698 harmsja 5828: background:rgb(220,220,220);
1.693 droeschl 5829: }
5830:
1.721 harmsja 5831: div.LC_columnSection {
1.693 droeschl 5832: display: block;
5833: clear: both;
5834: overflow: hidden;
5835: margin:0px;
5836: }
5837:
1.721 harmsja 5838: div.LC_columnSection>* {
1.693 droeschl 5839: float: left;
5840: margin: 10px 20px 10px 0px;
1.747 neumanie 5841: overflow:hidden;
1.693 droeschl 5842: }
1.721 harmsja 5843:
1.719 ehlerst 5844: .ContentBoxSpecialTemplate
5845: {
1.747 neumanie 5846: border: solid 1px $lg_border_color;
1.719 ehlerst 5847: }
5848: .ContentBoxTemplate {
5849: padding:10px;
5850: }
5851:
1.721 harmsja 5852: div.LC_columnSection > .ContentBoxTemplate,
5853: div.LC_columnSection > .ContentBoxSpecialTemplate
1.719 ehlerst 5854: {
5855: width: 600px;
5856: }
1.753 droeschl 5857:
1.720 ehlerst 5858: .clear{
5859: clear: both;
5860: line-height: 0px;
5861: font-size: 0px;
5862: height: 0px;
5863: }
1.693 droeschl 5864:
1.694 tempelho 5865: .LC_loginpage_container {
5866: text-align:left;
5867: margin : 0 auto;
5868: width:65%;
5869: padding: 10px;
5870: height: auto;
1.712 muellerd 5871: background-color:#FFFFFF;
1.694 tempelho 5872: border:1px solid #CCCCCC;
5873: }
5874:
5875:
5876: .LC_loginpage_loginContainer {
5877: float:left;
1.712 muellerd 5878: width: 182px;
5879: border:1px solid #CCCCCC;
5880: background-color:$loginbg;
1.694 tempelho 5881: }
5882:
1.717 tempelho 5883: .LC_loginpage_loginContainer h2{
1.712 muellerd 5884: margin-top:0;
5885: display:block;
5886: background:$bgcol;
5887: color:$textcol;
5888: padding-left:5px;
5889: }
1.694 tempelho 5890: .LC_loginpage_loginInfo {
5891: margin-left:20px;
5892: float:left;
5893: width:30%;
5894: border:1px solid #CCCCCC;
5895: padding:10px;
5896: }
5897:
1.712 muellerd 5898: .LC_loginpage_loginDomain {
5899: margin-right:20px;
5900: width:20%;
5901: float:left;
5902: padding:10px;
5903: }
5904:
1.694 tempelho 5905: .LC_loginpage_space {
1.754 droeschl 5906: clear: both;
5907: margin-bottom: 20px;
1.694 tempelho 5908: border-bottom: 1px solid #CCCCCC;
5909: }
5910:
1.748 schulted 5911: table em{
1.754 droeschl 5912: font-weight: bold;
5913: font-style: normal;
1.748 schulted 5914: }
1.779 bisitz 5915: table.LC_tableBrowseRes,
1.768 schulted 5916: table.LC_tableOfContent{
1.769 schulted 5917: border:none;
5918: border-spacing: 1;
1.754 droeschl 5919: padding: 3px;
5920: background-color: #FFFFFF;
5921: font-size: 90%;
1.753 droeschl 5922: }
1.771 droeschl 5923: table.LC_tableBrowseRes a,
1.768 schulted 5924: table.LC_tableOfContent a {
1.771 droeschl 5925: background-color: transparent;
1.753 droeschl 5926: text-decoration: none;
5927: }
5928:
1.771 droeschl 5929: table.LC_tableBrowseRes tr.LC_trOdd,
1.768 schulted 5930: table.LC_tableOfContent tr.LC_trOdd{
1.754 droeschl 5931: background-color: #EEEEEE;
1.753 droeschl 5932: }
5933:
1.768 schulted 5934: table.LC_tableOfContent img{
1.753 droeschl 5935: border: none;
5936: height: 1.3em;
5937: vertical-align: text-bottom;
5938: margin-right: 0.3em;
5939: }
1.757 schulted 5940:
1.774 ehlerst 5941: a#LC_content_toolbar_firsthomework{
5942: background-image:url(/res/adm/pages/open-first-problem.gif);
5943: }
5944:
5945: a#LC_content_toolbar_launchnav{
5946: background-image:url(/res/adm/pages/start-navigation.gif);
5947: }
5948:
5949: a#LC_content_toolbar_closenav{
5950: background-image:url(/res/adm/pages/close-navigation.gif);
5951: }
5952:
5953: a#LC_content_toolbar_everything{
5954: background-image:url(/res/adm/pages/show-all.gif);
5955: }
5956:
5957: a#LC_content_toolbar_uncompleted{
5958: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
5959: }
5960:
5961: #LC_content_toolbar_clearbubbles{
5962: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
5963: }
5964:
1.757 schulted 5965: a#LC_content_toolbar_changefolder{
5966: background : url(/res/adm/pages/close-all-folders.gif) top center ;
5967: }
5968:
5969: a#LC_content_toolbar_changefolder_toggled{
5970: background-image:url(/res/adm/pages/open-all-folders.gif);
5971: }
5972:
5973: ul#LC_toolbar li a:hover{
5974: background-position: bottom center;
5975: }
5976:
5977: ul#LC_toolbar{
1.779 bisitz 5978: padding:0;
1.757 schulted 5979: margin: 2px;
5980: list-style:none;
5981: position:relative;
5982: background-color:white;
5983: }
5984:
5985: ul#LC_toolbar li{
5986: border:1px solid white;
5987: padding:0;
5988: margin: 0;
1.767 droeschl 5989: float: left;
5990: display:inline;
1.757 schulted 5991: vertical-align:middle;
5992: }
5993:
5994: a.LC_toolbarItem{
1.767 droeschl 5995: display:block;
1.757 schulted 5996: padding:0;
5997: margin:0;
5998: height: 32px;
5999: width: 32px;
1.779 bisitz 6000: color:white;
6001: border:0 none;
1.757 schulted 6002: background-repeat:no-repeat;
6003: background-color:transparent;
6004: }
6005:
6006:
1.343 albertel 6007: END
6008: }
6009:
1.306 albertel 6010: =pod
6011:
6012: =item * &headtag()
6013:
6014: Returns a uniform footer for LON-CAPA web pages.
6015:
1.307 albertel 6016: Inputs: $title - optional title for the head
6017: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 6018: $args - optional arguments
1.319 albertel 6019: force_register - if is true call registerurl so the remote is
6020: informed
1.415 albertel 6021: redirect -> array ref of
6022: 1- seconds before redirect occurs
6023: 2- url to redirect to
6024: 3- whether the side effect should occur
1.315 albertel 6025: (side effect of setting
6026: $env{'internal.head.redirect'} to the url
6027: redirected too)
1.352 albertel 6028: domain -> force to color decorate a page for a specific
6029: domain
6030: function -> force usage of a specific rolish color scheme
6031: bgcolor -> override the default page bgcolor
1.460 albertel 6032: no_auto_mt_title
6033: -> prevent &mt()ing the title arg
1.464 albertel 6034:
1.306 albertel 6035: =cut
6036:
6037: sub headtag {
1.313 albertel 6038: my ($title,$head_extra,$args) = @_;
1.306 albertel 6039:
1.363 albertel 6040: my $function = $args->{'function'} || &get_users_function();
6041: my $domain = $args->{'domain'} || &determinedomain();
6042: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 6043: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 6044: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 6045: #time(),
1.418 albertel 6046: $env{'environment.color.timestamp'},
1.363 albertel 6047: $function,$domain,$bgcolor);
6048:
1.369 www 6049: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 6050:
1.308 albertel 6051: my $result =
6052: '<head>'.
1.461 albertel 6053: &font_settings();
1.319 albertel 6054:
1.461 albertel 6055: if (!$args->{'frameset'}) {
6056: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
6057: }
1.319 albertel 6058: if ($args->{'force_register'}) {
6059: $result .= &Apache::lonmenu::registerurl(1);
6060: }
1.436 albertel 6061: if (!$args->{'no_nav_bar'}
6062: && !$args->{'only_body'}
6063: && !$args->{'frameset'}) {
6064: $result .= &help_menu_js();
6065: }
1.319 albertel 6066:
1.314 albertel 6067: if (ref($args->{'redirect'})) {
1.414 albertel 6068: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 6069: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 6070: if (!$inhibit_continue) {
6071: $env{'internal.head.redirect'} = $url;
6072: }
1.313 albertel 6073: $result.=<<ADDMETA
6074: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 6075: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 6076: ADDMETA
6077: }
1.306 albertel 6078: if (!defined($title)) {
6079: $title = 'The LearningOnline Network with CAPA';
6080: }
1.460 albertel 6081: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
6082: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 6083: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
6084: .$head_extra;
1.306 albertel 6085: return $result;
6086: }
6087:
6088: =pod
6089:
1.340 albertel 6090: =item * &font_settings()
6091:
6092: Returns neccessary <meta> to set the proper encoding
6093:
6094: Inputs: none
6095:
6096: =cut
6097:
6098: sub font_settings {
6099: my $headerstring='';
1.647 www 6100: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 6101: $headerstring.=
6102: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
6103: }
6104: return $headerstring;
6105: }
6106:
1.341 albertel 6107: =pod
6108:
6109: =item * &xml_begin()
6110:
6111: Returns the needed doctype and <html>
6112:
6113: Inputs: none
6114:
6115: =cut
6116:
6117: sub xml_begin {
6118: my $output='';
6119:
1.592 albertel 6120: if ($env{'internal.start_page'}==1) {
6121: &Apache::lonhtmlcommon::init_htmlareafields();
6122: }
1.342 albertel 6123:
1.341 albertel 6124: if ($env{'browser.mathml'}) {
6125: $output='<?xml version="1.0"?>'
6126: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
6127: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
6128:
6129: # .'<!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">] >'
6130: .'<!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">'
6131: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
6132: .'xmlns="http://www.w3.org/1999/xhtml">';
6133: } else {
6134: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>';
6135: }
6136: return $output;
6137: }
1.340 albertel 6138:
6139: =pod
6140:
1.306 albertel 6141: =item * &endheadtag()
6142:
6143: Returns a uniform </head> for LON-CAPA web pages.
6144:
6145: Inputs: none
6146:
6147: =cut
6148:
6149: sub endheadtag {
6150: return '</head>';
6151: }
6152:
6153: =pod
6154:
6155: =item * &head()
6156:
6157: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
6158:
1.648 raeburn 6159: Inputs:
6160:
6161: =over 4
6162:
6163: $title - optional title for the page
6164:
6165: $head_extra - optional extra HTML to put inside the <head>
6166:
6167: =back
1.405 albertel 6168:
1.306 albertel 6169: =cut
6170:
6171: sub head {
1.325 albertel 6172: my ($title,$head_extra,$args) = @_;
6173: return &headtag($title,$head_extra,$args).&endheadtag();
1.306 albertel 6174: }
6175:
6176: =pod
6177:
6178: =item * &start_page()
6179:
6180: Returns a complete <html> .. <body> section for LON-CAPA web pages.
6181:
1.648 raeburn 6182: Inputs:
6183:
6184: =over 4
6185:
6186: $title - optional title for the page
6187:
6188: $head_extra - optional extra HTML to incude inside the <head>
6189:
6190: $args - additional optional args supported are:
6191:
6192: =over 8
6193:
6194: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 6195: arg on
1.648 raeburn 6196: no_nav_bar -> is true will set &bodytag() notopbar arg on
6197: add_entries -> additional attributes to add to the <body>
6198: domain -> force to color decorate a page for a
1.317 albertel 6199: specific domain
1.648 raeburn 6200: function -> force usage of a specific rolish color
1.317 albertel 6201: scheme
1.648 raeburn 6202: redirect -> see &headtag()
6203: bgcolor -> override the default page bg color
6204: js_ready -> return a string ready for being used in
1.317 albertel 6205: a javascript writeln
1.648 raeburn 6206: html_encode -> return a string ready for being used in
1.320 albertel 6207: a html attribute
1.648 raeburn 6208: force_register -> if is true will turn on the &bodytag()
1.317 albertel 6209: $forcereg arg
1.648 raeburn 6210: body_title -> alternate text to use instead of $title
1.326 albertel 6211: in the title box that appears, this text
6212: is not auto translated like the $title is
1.648 raeburn 6213: frameset -> if true will start with a <frameset>
1.330 albertel 6214: rather than <body>
1.648 raeburn 6215: no_title -> if true the title bar won't be shown
6216: skip_phases -> hash ref of
1.338 albertel 6217: head -> skip the <html><head> generation
6218: body -> skip all <body> generation
1.648 raeburn 6219: no_inline_link -> if true and in remote mode, don't show the
1.361 albertel 6220: 'Switch To Inline Menu' link
1.648 raeburn 6221: no_auto_mt_title -> prevent &mt()ing the title arg
6222: inherit_jsmath -> when creating popup window in a page,
6223: should it have jsmath forced on by the
6224: current page
1.361 albertel 6225:
1.648 raeburn 6226: =back
1.460 albertel 6227:
1.648 raeburn 6228: =back
1.562 albertel 6229:
1.306 albertel 6230: =cut
6231:
6232: sub start_page {
1.309 albertel 6233: my ($title,$head_extra,$args) = @_;
1.318 albertel 6234: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313 albertel 6235: my %head_args;
1.352 albertel 6236: foreach my $arg ('redirect','force_register','domain','function',
1.460 albertel 6237: 'bgcolor','frameset','no_nav_bar','only_body',
6238: 'no_auto_mt_title') {
1.319 albertel 6239: if (defined($args->{$arg})) {
1.324 raeburn 6240: $head_args{$arg} = $args->{$arg};
1.319 albertel 6241: }
1.313 albertel 6242: }
1.319 albertel 6243:
1.315 albertel 6244: $env{'internal.start_page'}++;
1.338 albertel 6245: my $result;
6246: if (! exists($args->{'skip_phases'}{'head'}) ) {
6247: $result.=
1.341 albertel 6248: &xml_begin().
1.338 albertel 6249: &headtag($title,$head_extra,\%head_args).&endheadtag();
6250: }
6251:
6252: if (! exists($args->{'skip_phases'}{'body'}) ) {
6253: if ($args->{'frameset'}) {
6254: my $attr_string = &make_attr_string($args->{'force_register'},
6255: $args->{'add_entries'});
6256: $result .= "\n<frameset $attr_string>\n";
6257: } else {
6258: $result .=
6259: &bodytag($title,
6260: $args->{'function'}, $args->{'add_entries'},
6261: $args->{'only_body'}, $args->{'domain'},
6262: $args->{'force_register'}, $args->{'body_title'},
6263: $args->{'no_nav_bar'}, $args->{'bgcolor'},
1.460 albertel 6264: $args->{'no_title'}, $args->{'no_inline_link'},
6265: $args);
1.338 albertel 6266: }
1.330 albertel 6267: }
1.338 albertel 6268:
1.315 albertel 6269: if ($args->{'js_ready'}) {
1.713 kaisler 6270: $result = &js_ready($result);
1.315 albertel 6271: }
1.320 albertel 6272: if ($args->{'html_encode'}) {
1.713 kaisler 6273: $result = &html_encode($result);
6274: }
6275:
1.758 kaisler 6276: #Breadcrumbs
6277: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
6278: &Apache::lonhtmlcommon::clear_breadcrumbs();
6279: #if any br links exists, add them to the breadcrumbs
6280: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
6281: foreach my $crumb (@{$args->{'bread_crumbs'}}){
6282: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
6283: }
6284: }
6285:
6286: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
6287: if(exists($args->{'bread_crumbs_component'})){
6288: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
6289: }else{
6290: $result .= &Apache::lonhtmlcommon::breadcrumbs();
6291: }
1.320 albertel 6292: }
1.315 albertel 6293: return $result;
1.306 albertel 6294: }
6295:
1.330 albertel 6296:
1.306 albertel 6297: =pod
6298:
6299: =item * &head()
6300:
6301: Returns a complete </body></html> section for LON-CAPA web pages.
6302:
1.315 albertel 6303: Inputs: $args - additional optional args supported are:
6304: js_ready -> return a string ready for being used in
6305: a javascript writeln
1.320 albertel 6306: html_encode -> return a string ready for being used in
6307: a html attribute
1.330 albertel 6308: frameset -> if true will start with a <frameset>
6309: rather than <body>
1.493 albertel 6310: dicsussion -> if true will get discussion from
6311: lonxml::xmlend
6312: (you can pass the target and parser arguments
6313: through optional 'target' and 'parser' args
6314: to this routine)
1.306 albertel 6315:
6316: =cut
6317:
6318: sub end_page {
1.315 albertel 6319: my ($args) = @_;
6320: $env{'internal.end_page'}++;
1.330 albertel 6321: my $result;
1.335 albertel 6322: if ($args->{'discussion'}) {
6323: my ($target,$parser);
6324: if (ref($args->{'discussion'})) {
6325: ($target,$parser) =($args->{'discussion'}{'target'},
6326: $args->{'discussion'}{'parser'});
6327: }
6328: $result .= &Apache::lonxml::xmlend($target,$parser);
6329: }
6330:
1.330 albertel 6331: if ($args->{'frameset'}) {
6332: $result .= '</frameset>';
6333: } else {
1.635 raeburn 6334: $result .= &endbodytag($args);
1.330 albertel 6335: }
6336: $result .= "\n</html>";
6337:
1.315 albertel 6338: if ($args->{'js_ready'}) {
1.317 albertel 6339: $result = &js_ready($result);
1.315 albertel 6340: }
1.335 albertel 6341:
1.320 albertel 6342: if ($args->{'html_encode'}) {
6343: $result = &html_encode($result);
6344: }
1.335 albertel 6345:
1.315 albertel 6346: return $result;
6347: }
6348:
1.320 albertel 6349: sub html_encode {
6350: my ($result) = @_;
6351:
1.322 albertel 6352: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 6353:
6354: return $result;
6355: }
1.317 albertel 6356: sub js_ready {
6357: my ($result) = @_;
6358:
1.323 albertel 6359: $result =~ s/[\n\r]/ /xmsg;
6360: $result =~ s/\\/\\\\/xmsg;
6361: $result =~ s/'/\\'/xmsg;
1.372 albertel 6362: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 6363:
6364: return $result;
6365: }
6366:
1.315 albertel 6367: sub validate_page {
6368: if ( exists($env{'internal.start_page'})
1.316 albertel 6369: && $env{'internal.start_page'} > 1) {
6370: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 6371: $env{'internal.start_page'}.' '.
1.316 albertel 6372: $ENV{'request.filename'});
1.315 albertel 6373: }
6374: if ( exists($env{'internal.end_page'})
1.316 albertel 6375: && $env{'internal.end_page'} > 1) {
6376: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 6377: $env{'internal.end_page'}.' '.
1.316 albertel 6378: $env{'request.filename'});
1.315 albertel 6379: }
6380: if ( exists($env{'internal.start_page'})
6381: && ! exists($env{'internal.end_page'})) {
1.316 albertel 6382: &Apache::lonnet::logthis('start_page called without end_page '.
6383: $env{'request.filename'});
1.315 albertel 6384: }
6385: if ( ! exists($env{'internal.start_page'})
6386: && exists($env{'internal.end_page'})) {
1.316 albertel 6387: &Apache::lonnet::logthis('end_page called without start_page'.
6388: $env{'request.filename'});
1.315 albertel 6389: }
1.306 albertel 6390: }
1.315 albertel 6391:
1.318 albertel 6392: sub simple_error_page {
6393: my ($r,$title,$msg) = @_;
6394: my $page =
6395: &Apache::loncommon::start_page($title).
6396: &mt($msg).
6397: &Apache::loncommon::end_page();
6398: if (ref($r)) {
6399: $r->print($page);
1.327 albertel 6400: return;
1.318 albertel 6401: }
6402: return $page;
6403: }
1.347 albertel 6404:
6405: {
1.610 albertel 6406: my @row_count;
1.347 albertel 6407: sub start_data_table {
1.422 albertel 6408: my ($add_class) = @_;
6409: my $css_class = (join(' ','LC_data_table',$add_class));
1.610 albertel 6410: unshift(@row_count,0);
1.422 albertel 6411: return '<table class="'.$css_class.'">'."\n";
1.347 albertel 6412: }
6413:
6414: sub end_data_table {
1.610 albertel 6415: shift(@row_count);
1.389 albertel 6416: return '</table>'."\n";;
1.347 albertel 6417: }
6418:
6419: sub start_data_table_row {
1.422 albertel 6420: my ($add_class) = @_;
1.610 albertel 6421: $row_count[0]++;
6422: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.428 albertel 6423: $css_class = (join(' ',$css_class,$add_class));
1.422 albertel 6424: return '<tr class="'.$css_class.'">'."\n";;
1.347 albertel 6425: }
1.471 banghart 6426:
6427: sub continue_data_table_row {
6428: my ($add_class) = @_;
1.610 albertel 6429: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.471 banghart 6430: $css_class = (join(' ',$css_class,$add_class));
6431: return '<tr class="'.$css_class.'">'."\n";;
6432: }
1.347 albertel 6433:
6434: sub end_data_table_row {
1.389 albertel 6435: return '</tr>'."\n";;
1.347 albertel 6436: }
1.367 www 6437:
1.421 albertel 6438: sub start_data_table_empty_row {
1.707 bisitz 6439: # $row_count[0]++;
1.421 albertel 6440: return '<tr class="LC_empty_row" >'."\n";;
6441: }
6442:
6443: sub end_data_table_empty_row {
6444: return '</tr>'."\n";;
6445: }
6446:
1.367 www 6447: sub start_data_table_header_row {
1.389 albertel 6448: return '<tr class="LC_header_row">'."\n";;
1.367 www 6449: }
6450:
6451: sub end_data_table_header_row {
1.389 albertel 6452: return '</tr>'."\n";;
1.367 www 6453: }
1.347 albertel 6454: }
6455:
1.548 albertel 6456: =pod
6457:
6458: =item * &inhibit_menu_check($arg)
6459:
6460: Checks for a inhibitmenu state and generates output to preserve it
6461:
6462: Inputs: $arg - can be any of
6463: - undef - in which case the return value is a string
6464: to add into arguments list of a uri
6465: - 'input' - in which case the return value is a HTML
6466: <form> <input> field of type hidden to
6467: preserve the value
6468: - a url - in which case the return value is the url with
6469: the neccesary cgi args added to preserve the
6470: inhibitmenu state
6471: - a ref to a url - no return value, but the string is
6472: updated to include the neccessary cgi
6473: args to preserve the inhibitmenu state
6474:
6475: =cut
6476:
6477: sub inhibit_menu_check {
6478: my ($arg) = @_;
6479: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6480: if ($arg eq 'input') {
6481: if ($env{'form.inhibitmenu'}) {
6482: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
6483: } else {
6484: return
6485: }
6486: }
6487: if ($env{'form.inhibitmenu'}) {
6488: if (ref($arg)) {
6489: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6490: } elsif ($arg eq '') {
6491: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
6492: } else {
6493: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6494: }
6495: }
6496: if (!ref($arg)) {
6497: return $arg;
6498: }
6499: }
6500:
1.251 albertel 6501: ###############################################
1.182 matthew 6502:
6503: =pod
6504:
1.549 albertel 6505: =back
6506:
6507: =head1 User Information Routines
6508:
6509: =over 4
6510:
1.405 albertel 6511: =item * &get_users_function()
1.182 matthew 6512:
6513: Used by &bodytag to determine the current users primary role.
6514: Returns either 'student','coordinator','admin', or 'author'.
6515:
6516: =cut
6517:
6518: ###############################################
6519: sub get_users_function {
6520: my $function = 'student';
1.258 albertel 6521: if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
1.182 matthew 6522: $function='coordinator';
6523: }
1.258 albertel 6524: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 6525: $function='admin';
6526: }
1.258 albertel 6527: if (($env{'request.role'}=~/^(au|ca)/) ||
1.182 matthew 6528: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
6529: $function='author';
6530: }
6531: return $function;
1.54 www 6532: }
1.99 www 6533:
6534: ###############################################
6535:
1.233 raeburn 6536: =pod
6537:
1.542 raeburn 6538: =item * &check_user_status()
1.274 raeburn 6539:
6540: Determines current status of supplied role for a
6541: specific user. Roles can be active, previous or future.
6542:
6543: Inputs:
6544: user's domain, user's username, course's domain,
1.375 raeburn 6545: course's number, optional section ID.
1.274 raeburn 6546:
6547: Outputs:
6548: role status: active, previous or future.
6549:
6550: =cut
6551:
6552: sub check_user_status {
1.412 raeburn 6553: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274 raeburn 6554: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
6555: my @uroles = keys %userinfo;
6556: my $srchstr;
6557: my $active_chk = 'none';
1.412 raeburn 6558: my $now = time;
1.274 raeburn 6559: if (@uroles > 0) {
1.412 raeburn 6560: if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 6561: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
6562: } else {
1.412 raeburn 6563: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
6564: }
6565: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 6566: my $role_end = 0;
6567: my $role_start = 0;
6568: $active_chk = 'active';
1.412 raeburn 6569: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
6570: $role_end = $1;
6571: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
6572: $role_start = $1;
1.274 raeburn 6573: }
6574: }
6575: if ($role_start > 0) {
1.412 raeburn 6576: if ($now < $role_start) {
1.274 raeburn 6577: $active_chk = 'future';
6578: }
6579: }
6580: if ($role_end > 0) {
1.412 raeburn 6581: if ($now > $role_end) {
1.274 raeburn 6582: $active_chk = 'previous';
6583: }
6584: }
6585: }
6586: }
6587: return $active_chk;
6588: }
6589:
6590: ###############################################
6591:
6592: =pod
6593:
1.405 albertel 6594: =item * &get_sections()
1.233 raeburn 6595:
6596: Determines all the sections for a course including
6597: sections with students and sections containing other roles.
1.419 raeburn 6598: Incoming parameters:
6599:
6600: 1. domain
6601: 2. course number
6602: 3. reference to array containing roles for which sections should
6603: be gathered (optional).
6604: 4. reference to array containing status types for which sections
6605: should be gathered (optional).
6606:
6607: If the third argument is undefined, sections are gathered for any role.
6608: If the fourth argument is undefined, sections are gathered for any status.
6609: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 6610:
1.374 raeburn 6611: Returns section hash (keys are section IDs, values are
6612: number of users in each section), subject to the
1.419 raeburn 6613: optional roles filter, optional status filter
1.233 raeburn 6614:
6615: =cut
6616:
6617: ###############################################
6618: sub get_sections {
1.419 raeburn 6619: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 6620: if (!defined($cdom) || !defined($cnum)) {
6621: my $cid = $env{'request.course.id'};
6622:
6623: return if (!defined($cid));
6624:
6625: $cdom = $env{'course.'.$cid.'.domain'};
6626: $cnum = $env{'course.'.$cid.'.num'};
6627: }
6628:
6629: my %sectioncount;
1.419 raeburn 6630: my $now = time;
1.240 albertel 6631:
1.366 albertel 6632: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276 albertel 6633: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 6634: my $sec_index = &Apache::loncoursedata::CL_SECTION();
6635: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 6636: my $start_index = &Apache::loncoursedata::CL_START();
6637: my $end_index = &Apache::loncoursedata::CL_END();
6638: my $status;
1.366 albertel 6639: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 6640: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
6641: $data->[$status_index],
6642: $data->[$start_index],
6643: $data->[$end_index]);
6644: if ($stu_status eq 'Active') {
6645: $status = 'active';
6646: } elsif ($end < $now) {
6647: $status = 'previous';
6648: } elsif ($start > $now) {
6649: $status = 'future';
6650: }
6651: if ($section ne '-1' && $section !~ /^\s*$/) {
6652: if ((!defined($possible_status)) || (($status ne '') &&
6653: (grep/^\Q$status\E$/,@{$possible_status}))) {
6654: $sectioncount{$section}++;
6655: }
1.240 albertel 6656: }
6657: }
6658: }
6659: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6660: foreach my $user (sort(keys(%courseroles))) {
6661: if ($user !~ /^(\w{2})/) { next; }
6662: my ($role) = ($user =~ /^(\w{2})/);
6663: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 6664: my ($section,$status);
1.240 albertel 6665: if ($role eq 'cr' &&
6666: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
6667: $section=$1;
6668: }
6669: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
6670: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 6671: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
6672: if ($end == -1 && $start == -1) {
6673: next; #deleted role
6674: }
6675: if (!defined($possible_status)) {
6676: $sectioncount{$section}++;
6677: } else {
6678: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
6679: $status = 'active';
6680: } elsif ($end < $now) {
6681: $status = 'future';
6682: } elsif ($start > $now) {
6683: $status = 'previous';
6684: }
6685: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
6686: $sectioncount{$section}++;
6687: }
6688: }
1.233 raeburn 6689: }
1.366 albertel 6690: return %sectioncount;
1.233 raeburn 6691: }
6692:
1.274 raeburn 6693: ###############################################
1.294 raeburn 6694:
6695: =pod
1.405 albertel 6696:
6697: =item * &get_course_users()
6698:
1.275 raeburn 6699: Retrieves usernames:domains for users in the specified course
6700: with specific role(s), and access status.
6701:
6702: Incoming parameters:
1.277 albertel 6703: 1. course domain
6704: 2. course number
6705: 3. access status: users must have - either active,
1.275 raeburn 6706: previous, future, or all.
1.277 albertel 6707: 4. reference to array of permissible roles
1.288 raeburn 6708: 5. reference to array of section restrictions (optional)
6709: 6. reference to results object (hash of hashes).
6710: 7. reference to optional userdata hash
1.609 raeburn 6711: 8. reference to optional statushash
1.630 raeburn 6712: 9. flag if privileged users (except those set to unhide in
6713: course settings) should be excluded
1.609 raeburn 6714: Keys of top level results hash are roles.
1.275 raeburn 6715: Keys of inner hashes are username:domain, with
6716: values set to access type.
1.288 raeburn 6717: Optional userdata hash returns an array with arguments in the
6718: same order as loncoursedata::get_classlist() for student data.
6719:
1.609 raeburn 6720: Optional statushash returns
6721:
1.288 raeburn 6722: Entries for end, start, section and status are blank because
6723: of the possibility of multiple values for non-student roles.
6724:
1.275 raeburn 6725: =cut
1.405 albertel 6726:
1.275 raeburn 6727: ###############################################
1.405 albertel 6728:
1.275 raeburn 6729: sub get_course_users {
1.630 raeburn 6730: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 6731: my %idx = ();
1.419 raeburn 6732: my %seclists;
1.288 raeburn 6733:
6734: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
6735: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
6736: $idx{end} = &Apache::loncoursedata::CL_END();
6737: $idx{start} = &Apache::loncoursedata::CL_START();
6738: $idx{id} = &Apache::loncoursedata::CL_ID();
6739: $idx{section} = &Apache::loncoursedata::CL_SECTION();
6740: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
6741: $idx{status} = &Apache::loncoursedata::CL_STATUS();
6742:
1.290 albertel 6743: if (grep(/^st$/,@{$roles})) {
1.276 albertel 6744: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 6745: my $now = time;
1.277 albertel 6746: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 6747: my $match = 0;
1.412 raeburn 6748: my $secmatch = 0;
1.419 raeburn 6749: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 6750: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 6751: if ($section eq '') {
6752: $section = 'none';
6753: }
1.291 albertel 6754: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 6755: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 6756: $secmatch = 1;
6757: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 6758: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 6759: $secmatch = 1;
6760: }
6761: } else {
1.419 raeburn 6762: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 6763: $secmatch = 1;
6764: }
1.290 albertel 6765: }
1.412 raeburn 6766: if (!$secmatch) {
6767: next;
6768: }
1.419 raeburn 6769: }
1.275 raeburn 6770: if (defined($$types{'active'})) {
1.288 raeburn 6771: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 6772: push(@{$$users{st}{$student}},'active');
1.288 raeburn 6773: $match = 1;
1.275 raeburn 6774: }
6775: }
6776: if (defined($$types{'previous'})) {
1.609 raeburn 6777: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 6778: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 6779: $match = 1;
1.275 raeburn 6780: }
6781: }
6782: if (defined($$types{'future'})) {
1.609 raeburn 6783: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 6784: push(@{$$users{st}{$student}},'future');
1.288 raeburn 6785: $match = 1;
1.275 raeburn 6786: }
6787: }
1.609 raeburn 6788: if ($match) {
6789: push(@{$seclists{$student}},$section);
6790: if (ref($userdata) eq 'HASH') {
6791: $$userdata{$student} = $$classlist{$student};
6792: }
6793: if (ref($statushash) eq 'HASH') {
6794: $statushash->{$student}{'st'}{$section} = $status;
6795: }
1.288 raeburn 6796: }
1.275 raeburn 6797: }
6798: }
1.412 raeburn 6799: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 6800: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6801: my $now = time;
1.609 raeburn 6802: my %displaystatus = ( previous => 'Expired',
6803: active => 'Active',
6804: future => 'Future',
6805: );
1.630 raeburn 6806: my %nothide;
6807: if ($hidepriv) {
6808: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
6809: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
6810: if ($user !~ /:/) {
6811: $nothide{join(':',split(/[\@]/,$user))}=1;
6812: } else {
6813: $nothide{$user} = 1;
6814: }
6815: }
6816: }
1.439 raeburn 6817: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 6818: my $match = 0;
1.412 raeburn 6819: my $secmatch = 0;
1.439 raeburn 6820: my $status;
1.412 raeburn 6821: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 6822: $user =~ s/:$//;
1.439 raeburn 6823: my ($end,$start) = split(/:/,$coursepersonnel{$person});
6824: if ($end == -1 || $start == -1) {
6825: next;
6826: }
6827: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
6828: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 6829: my ($uname,$udom) = split(/:/,$user);
6830: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 6831: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 6832: $secmatch = 1;
6833: } elsif ($usec eq '') {
1.420 albertel 6834: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 6835: $secmatch = 1;
6836: }
6837: } else {
6838: if (grep(/^\Q$usec\E$/,@{$sections})) {
6839: $secmatch = 1;
6840: }
6841: }
6842: if (!$secmatch) {
6843: next;
6844: }
1.288 raeburn 6845: }
1.419 raeburn 6846: if ($usec eq '') {
6847: $usec = 'none';
6848: }
1.275 raeburn 6849: if ($uname ne '' && $udom ne '') {
1.630 raeburn 6850: if ($hidepriv) {
6851: if ((&Apache::lonnet::privileged($uname,$udom)) &&
6852: (!$nothide{$uname.':'.$udom})) {
6853: next;
6854: }
6855: }
1.503 raeburn 6856: if ($end > 0 && $end < $now) {
1.439 raeburn 6857: $status = 'previous';
6858: } elsif ($start > $now) {
6859: $status = 'future';
6860: } else {
6861: $status = 'active';
6862: }
1.277 albertel 6863: foreach my $type (keys(%{$types})) {
1.275 raeburn 6864: if ($status eq $type) {
1.420 albertel 6865: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 6866: push(@{$$users{$role}{$user}},$type);
6867: }
1.288 raeburn 6868: $match = 1;
6869: }
6870: }
1.419 raeburn 6871: if (($match) && (ref($userdata) eq 'HASH')) {
6872: if (!exists($$userdata{$uname.':'.$udom})) {
6873: &get_user_info($udom,$uname,\%idx,$userdata);
6874: }
1.420 albertel 6875: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 6876: push(@{$seclists{$uname.':'.$udom}},$usec);
6877: }
1.609 raeburn 6878: if (ref($statushash) eq 'HASH') {
6879: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
6880: }
1.275 raeburn 6881: }
6882: }
6883: }
6884: }
1.290 albertel 6885: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 6886: if ((defined($cdom)) && (defined($cnum))) {
6887: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
6888: if ( defined($csettings{'internal.courseowner'}) ) {
6889: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 6890: next if ($owner eq '');
6891: my ($ownername,$ownerdom);
6892: if ($owner =~ /^([^:]+):([^:]+)$/) {
6893: $ownername = $1;
6894: $ownerdom = $2;
6895: } else {
6896: $ownername = $owner;
6897: $ownerdom = $cdom;
6898: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 6899: }
6900: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 6901: if (defined($userdata) &&
1.609 raeburn 6902: !exists($$userdata{$owner})) {
6903: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
6904: if (!grep(/^none$/,@{$seclists{$owner}})) {
6905: push(@{$seclists{$owner}},'none');
6906: }
6907: if (ref($statushash) eq 'HASH') {
6908: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 6909: }
1.290 albertel 6910: }
1.279 raeburn 6911: }
6912: }
6913: }
1.419 raeburn 6914: foreach my $user (keys(%seclists)) {
6915: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
6916: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
6917: }
1.275 raeburn 6918: }
6919: return;
6920: }
6921:
1.288 raeburn 6922: sub get_user_info {
6923: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 6924: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
6925: &plainname($uname,$udom,'lastname');
1.291 albertel 6926: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 6927: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 6928: my %idhash = &Apache::lonnet::idrget($udom,($uname));
6929: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 6930: return;
6931: }
1.275 raeburn 6932:
1.472 raeburn 6933: ###############################################
6934:
6935: =pod
6936:
6937: =item * &get_user_quota()
6938:
6939: Retrieves quota assigned for storage of portfolio files for a user
6940:
6941: Incoming parameters:
6942: 1. user's username
6943: 2. user's domain
6944:
6945: Returns:
1.536 raeburn 6946: 1. Disk quota (in Mb) assigned to student.
6947: 2. (Optional) Type of setting: custom or default
6948: (individually assigned or default for user's
6949: institutional status).
6950: 3. (Optional) - User's institutional status (e.g., faculty, staff
6951: or student - types as defined in localenroll::inst_usertypes
6952: for user's domain, which determines default quota for user.
6953: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 6954:
6955: If a value has been stored in the user's environment,
1.536 raeburn 6956: it will return that, otherwise it returns the maximal default
6957: defined for the user's instituional status(es) in the domain.
1.472 raeburn 6958:
6959: =cut
6960:
6961: ###############################################
6962:
6963:
6964: sub get_user_quota {
6965: my ($uname,$udom) = @_;
1.536 raeburn 6966: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 6967: if (!defined($udom)) {
6968: $udom = $env{'user.domain'};
6969: }
6970: if (!defined($uname)) {
6971: $uname = $env{'user.name'};
6972: }
6973: if (($udom eq '' || $uname eq '') ||
6974: ($udom eq 'public') && ($uname eq 'public')) {
6975: $quota = 0;
1.536 raeburn 6976: $quotatype = 'default';
6977: $defquota = 0;
1.472 raeburn 6978: } else {
1.536 raeburn 6979: my $inststatus;
1.472 raeburn 6980: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
6981: $quota = $env{'environment.portfolioquota'};
1.536 raeburn 6982: $inststatus = $env{'environment.inststatus'};
1.472 raeburn 6983: } else {
1.536 raeburn 6984: my %userenv =
6985: &Apache::lonnet::get('environment',['portfolioquota',
6986: 'inststatus'],$udom,$uname);
1.472 raeburn 6987: my ($tmp) = keys(%userenv);
6988: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
6989: $quota = $userenv{'portfolioquota'};
1.536 raeburn 6990: $inststatus = $userenv{'inststatus'};
1.472 raeburn 6991: } else {
6992: undef(%userenv);
6993: }
6994: }
1.536 raeburn 6995: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472 raeburn 6996: if ($quota eq '') {
1.536 raeburn 6997: $quota = $defquota;
6998: $quotatype = 'default';
6999: } else {
7000: $quotatype = 'custom';
1.472 raeburn 7001: }
7002: }
1.536 raeburn 7003: if (wantarray) {
7004: return ($quota,$quotatype,$settingstatus,$defquota);
7005: } else {
7006: return $quota;
7007: }
1.472 raeburn 7008: }
7009:
7010: ###############################################
7011:
7012: =pod
7013:
7014: =item * &default_quota()
7015:
1.536 raeburn 7016: Retrieves default quota assigned for storage of user portfolio files,
7017: given an (optional) user's institutional status.
1.472 raeburn 7018:
7019: Incoming parameters:
7020: 1. domain
1.536 raeburn 7021: 2. (Optional) institutional status(es). This is a : separated list of
7022: status types (e.g., faculty, staff, student etc.)
7023: which apply to the user for whom the default is being retrieved.
7024: If the institutional status string in undefined, the domain
7025: default quota will be returned.
1.472 raeburn 7026:
7027: Returns:
7028: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 7029: 2. (Optional) institutional type which determined the value of the
7030: default quota.
1.472 raeburn 7031:
7032: If a value has been stored in the domain's configuration db,
7033: it will return that, otherwise it returns 20 (for backwards
7034: compatibility with domains which have not set up a configuration
7035: db file; the original statically defined portfolio quota was 20 Mb).
7036:
1.536 raeburn 7037: If the user's status includes multiple types (e.g., staff and student),
7038: the largest default quota which applies to the user determines the
7039: default quota returned.
7040:
1.780 raeburn 7041: =back
7042:
1.472 raeburn 7043: =cut
7044:
7045: ###############################################
7046:
7047:
7048: sub default_quota {
1.536 raeburn 7049: my ($udom,$inststatus) = @_;
7050: my ($defquota,$settingstatus);
7051: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 7052: ['quotas'],$udom);
7053: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 7054: if ($inststatus ne '') {
1.765 raeburn 7055: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 7056: foreach my $item (@statuses) {
1.711 raeburn 7057: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7058: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
7059: if ($defquota eq '') {
7060: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7061: $settingstatus = $item;
7062: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
7063: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7064: $settingstatus = $item;
7065: }
7066: }
7067: } else {
7068: if ($quotahash{'quotas'}{$item} ne '') {
7069: if ($defquota eq '') {
7070: $defquota = $quotahash{'quotas'}{$item};
7071: $settingstatus = $item;
7072: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
7073: $defquota = $quotahash{'quotas'}{$item};
7074: $settingstatus = $item;
7075: }
1.536 raeburn 7076: }
7077: }
7078: }
7079: }
7080: if ($defquota eq '') {
1.711 raeburn 7081: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7082: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
7083: } else {
7084: $defquota = $quotahash{'quotas'}{'default'};
7085: }
1.536 raeburn 7086: $settingstatus = 'default';
7087: }
7088: } else {
7089: $settingstatus = 'default';
7090: $defquota = 20;
7091: }
7092: if (wantarray) {
7093: return ($defquota,$settingstatus);
1.472 raeburn 7094: } else {
1.536 raeburn 7095: return $defquota;
1.472 raeburn 7096: }
7097: }
7098:
1.384 raeburn 7099: sub get_secgrprole_info {
7100: my ($cdom,$cnum,$needroles,$type) = @_;
7101: my %sections_count = &get_sections($cdom,$cnum);
7102: my @sections = (sort {$a <=> $b} keys(%sections_count));
7103: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
7104: my @groups = sort(keys(%curr_groups));
7105: my $allroles = [];
7106: my $rolehash;
7107: my $accesshash = {
7108: active => 'Currently has access',
7109: future => 'Will have future access',
7110: previous => 'Previously had access',
7111: };
7112: if ($needroles) {
7113: $rolehash = {'all' => 'all'};
1.385 albertel 7114: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7115: if (&Apache::lonnet::error(%user_roles)) {
7116: undef(%user_roles);
7117: }
7118: foreach my $item (keys(%user_roles)) {
1.384 raeburn 7119: my ($role)=split(/\:/,$item,2);
7120: if ($role eq 'cr') { next; }
7121: if ($role =~ /^cr/) {
7122: $$rolehash{$role} = (split('/',$role))[3];
7123: } else {
7124: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
7125: }
7126: }
7127: foreach my $key (sort(keys(%{$rolehash}))) {
7128: push(@{$allroles},$key);
7129: }
7130: push (@{$allroles},'st');
7131: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
7132: }
7133: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
7134: }
7135:
1.555 raeburn 7136: sub user_picker {
1.627 raeburn 7137: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555 raeburn 7138: my $currdom = $dom;
7139: my %curr_selected = (
7140: srchin => 'dom',
1.580 raeburn 7141: srchby => 'lastname',
1.555 raeburn 7142: );
7143: my $srchterm;
1.625 raeburn 7144: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 7145: if ($srch->{'srchby'} ne '') {
7146: $curr_selected{'srchby'} = $srch->{'srchby'};
7147: }
7148: if ($srch->{'srchin'} ne '') {
7149: $curr_selected{'srchin'} = $srch->{'srchin'};
7150: }
7151: if ($srch->{'srchtype'} ne '') {
7152: $curr_selected{'srchtype'} = $srch->{'srchtype'};
7153: }
7154: if ($srch->{'srchdomain'} ne '') {
7155: $currdom = $srch->{'srchdomain'};
7156: }
7157: $srchterm = $srch->{'srchterm'};
7158: }
7159: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 7160: 'usr' => 'Search criteria',
1.563 raeburn 7161: 'doma' => 'Domain/institution to search',
1.558 albertel 7162: 'uname' => 'username',
7163: 'lastname' => 'last name',
1.555 raeburn 7164: 'lastfirst' => 'last name, first name',
1.558 albertel 7165: 'crs' => 'in this course',
1.576 raeburn 7166: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 7167: 'alc' => 'all LON-CAPA',
1.573 raeburn 7168: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 7169: 'exact' => 'is',
7170: 'contains' => 'contains',
1.569 raeburn 7171: 'begins' => 'begins with',
1.571 raeburn 7172: 'youm' => "You must include some text to search for.",
7173: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
7174: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
7175: 'yomc' => "You must choose a domain when using an institutional directory search.",
7176: 'ymcd' => "You must choose a domain when using a domain search.",
7177: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
7178: 'whse' => "When searching by last,first you must include at least one character in the first name.",
7179: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 7180: );
1.563 raeburn 7181: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
7182: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 7183:
7184: my @srchins = ('crs','dom','alc','instd');
7185:
7186: foreach my $option (@srchins) {
7187: # FIXME 'alc' option unavailable until
7188: # loncreateuser::print_user_query_page()
7189: # has been completed.
7190: next if ($option eq 'alc');
7191: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 7192: if ($curr_selected{'srchin'} eq $option) {
7193: $srchinsel .= '
7194: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7195: } else {
7196: $srchinsel .= '
7197: <option value="'.$option.'">'.$lt{$option}.'</option>';
7198: }
1.555 raeburn 7199: }
1.563 raeburn 7200: $srchinsel .= "\n </select>\n";
1.555 raeburn 7201:
7202: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 7203: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 7204: if ($curr_selected{'srchby'} eq $option) {
7205: $srchbysel .= '
7206: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7207: } else {
7208: $srchbysel .= '
7209: <option value="'.$option.'">'.$lt{$option}.'</option>';
7210: }
7211: }
7212: $srchbysel .= "\n </select>\n";
7213:
7214: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 7215: foreach my $option ('begins','contains','exact') {
1.555 raeburn 7216: if ($curr_selected{'srchtype'} eq $option) {
7217: $srchtypesel .= '
7218: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7219: } else {
7220: $srchtypesel .= '
7221: <option value="'.$option.'">'.$lt{$option}.'</option>';
7222: }
7223: }
7224: $srchtypesel .= "\n </select>\n";
7225:
1.558 albertel 7226: my ($newuserscript,$new_user_create);
1.556 raeburn 7227:
7228: if ($forcenewuser) {
1.576 raeburn 7229: if (ref($srch) eq 'HASH') {
7230: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627 raeburn 7231: if ($cancreate) {
7232: $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>';
7233: } else {
7234: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
7235: my %usertypetext = (
7236: official => 'institutional',
7237: unofficial => 'non-institutional',
7238: );
7239: $new_user_create = '<br /><span class="LC_warning">'.&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.").' '.&mt('Contact the <a[_1]>helpdesk</a> for assistance.',$helplink).'</span><br /><br />';
7240: }
1.576 raeburn 7241: }
7242: }
7243:
1.556 raeburn 7244: $newuserscript = <<"ENDSCRIPT";
7245:
1.570 raeburn 7246: function setSearch(createnew,callingForm) {
1.556 raeburn 7247: if (createnew == 1) {
1.570 raeburn 7248: for (var i=0; i<callingForm.srchby.length; i++) {
7249: if (callingForm.srchby.options[i].value == 'uname') {
7250: callingForm.srchby.selectedIndex = i;
1.556 raeburn 7251: }
7252: }
1.570 raeburn 7253: for (var i=0; i<callingForm.srchin.length; i++) {
7254: if ( callingForm.srchin.options[i].value == 'dom') {
7255: callingForm.srchin.selectedIndex = i;
1.556 raeburn 7256: }
7257: }
1.570 raeburn 7258: for (var i=0; i<callingForm.srchtype.length; i++) {
7259: if (callingForm.srchtype.options[i].value == 'exact') {
7260: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 7261: }
7262: }
1.570 raeburn 7263: for (var i=0; i<callingForm.srchdomain.length; i++) {
7264: if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
7265: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 7266: }
7267: }
7268: }
7269: }
7270: ENDSCRIPT
1.558 albertel 7271:
1.556 raeburn 7272: }
7273:
1.555 raeburn 7274: my $output = <<"END_BLOCK";
1.556 raeburn 7275: <script type="text/javascript">
1.570 raeburn 7276: function validateEntry(callingForm) {
1.558 albertel 7277:
1.556 raeburn 7278: var checkok = 1;
1.558 albertel 7279: var srchin;
1.570 raeburn 7280: for (var i=0; i<callingForm.srchin.length; i++) {
7281: if ( callingForm.srchin[i].checked ) {
7282: srchin = callingForm.srchin[i].value;
1.558 albertel 7283: }
7284: }
7285:
1.570 raeburn 7286: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
7287: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
7288: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
7289: var srchterm = callingForm.srchterm.value;
7290: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 7291: var msg = "";
7292:
7293: if (srchterm == "") {
7294: checkok = 0;
1.571 raeburn 7295: msg += "$lt{'youm'}\\n";
1.556 raeburn 7296: }
7297:
1.569 raeburn 7298: if (srchtype== 'begins') {
7299: if (srchterm.length < 2) {
7300: checkok = 0;
1.571 raeburn 7301: msg += "$lt{'thte'}\\n";
1.569 raeburn 7302: }
7303: }
7304:
1.556 raeburn 7305: if (srchtype== 'contains') {
7306: if (srchterm.length < 3) {
7307: checkok = 0;
1.571 raeburn 7308: msg += "$lt{'thet'}\\n";
1.556 raeburn 7309: }
7310: }
7311: if (srchin == 'instd') {
7312: if (srchdomain == '') {
7313: checkok = 0;
1.571 raeburn 7314: msg += "$lt{'yomc'}\\n";
1.556 raeburn 7315: }
7316: }
7317: if (srchin == 'dom') {
7318: if (srchdomain == '') {
7319: checkok = 0;
1.571 raeburn 7320: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 7321: }
7322: }
7323: if (srchby == 'lastfirst') {
7324: if (srchterm.indexOf(",") == -1) {
7325: checkok = 0;
1.571 raeburn 7326: msg += "$lt{'whus'}\\n";
1.556 raeburn 7327: }
7328: if (srchterm.indexOf(",") == srchterm.length -1) {
7329: checkok = 0;
1.571 raeburn 7330: msg += "$lt{'whse'}\\n";
1.556 raeburn 7331: }
7332: }
7333: if (checkok == 0) {
1.571 raeburn 7334: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 7335: return;
7336: }
7337: if (checkok == 1) {
1.570 raeburn 7338: callingForm.submit();
1.556 raeburn 7339: }
7340: }
7341:
7342: $newuserscript
7343:
7344: </script>
1.558 albertel 7345:
7346: $new_user_create
7347:
1.555 raeburn 7348: <table>
1.558 albertel 7349: <tr>
1.573 raeburn 7350: <td>$lt{'doma'}:</td>
7351: <td>$domform</td>
7352: </td>
7353: </tr>
7354: <tr>
7355: <td>$lt{'usr'}:</td>
1.563 raeburn 7356: <td>$srchbysel
7357: $srchtypesel
7358: <input type="text" size="15" name="srchterm" value="$srchterm" />
1.564 albertel 7359: $srchinsel
1.563 raeburn 7360: </td>
7361: </tr>
1.555 raeburn 7362: </table>
7363: <br />
7364: END_BLOCK
1.558 albertel 7365:
1.555 raeburn 7366: return $output;
7367: }
7368:
1.612 raeburn 7369: sub user_rule_check {
1.615 raeburn 7370: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 7371: my $response;
7372: if (ref($usershash) eq 'HASH') {
7373: foreach my $user (keys(%{$usershash})) {
7374: my ($uname,$udom) = split(/:/,$user);
7375: next if ($udom eq '' || $uname eq '');
1.615 raeburn 7376: my ($id,$newuser);
1.612 raeburn 7377: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 7378: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 7379: $id = $usershash->{$user}->{'id'};
7380: }
7381: my $inst_response;
7382: if (ref($checks) eq 'HASH') {
7383: if (defined($checks->{'username'})) {
1.615 raeburn 7384: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7385: &Apache::lonnet::get_instuser($udom,$uname);
7386: } elsif (defined($checks->{'id'})) {
1.615 raeburn 7387: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7388: &Apache::lonnet::get_instuser($udom,undef,$id);
7389: }
1.615 raeburn 7390: } else {
7391: ($inst_response,%{$inst_results->{$user}}) =
7392: &Apache::lonnet::get_instuser($udom,$uname);
7393: return;
1.612 raeburn 7394: }
1.615 raeburn 7395: if (!$got_rules->{$udom}) {
1.612 raeburn 7396: my %domconfig = &Apache::lonnet::get_dom('configuration',
7397: ['usercreation'],$udom);
7398: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 7399: foreach my $item ('username','id') {
1.612 raeburn 7400: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
7401: $$curr_rules{$udom}{$item} =
7402: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 7403: }
7404: }
7405: }
1.615 raeburn 7406: $got_rules->{$udom} = 1;
1.585 raeburn 7407: }
1.612 raeburn 7408: foreach my $item (keys(%{$checks})) {
7409: if (ref($$curr_rules{$udom}) eq 'HASH') {
7410: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
7411: if (@{$$curr_rules{$udom}{$item}} > 0) {
7412: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
7413: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
7414: if ($rule_check{$rule}) {
7415: $$rulematch{$user}{$item} = $rule;
7416: if ($inst_response eq 'ok') {
1.615 raeburn 7417: if (ref($inst_results) eq 'HASH') {
7418: if (ref($inst_results->{$user}) eq 'HASH') {
7419: if (keys(%{$inst_results->{$user}}) == 0) {
7420: $$alerts{$item}{$udom}{$uname} = 1;
7421: }
1.612 raeburn 7422: }
7423: }
1.615 raeburn 7424: }
7425: last;
1.585 raeburn 7426: }
7427: }
7428: }
7429: }
7430: }
7431: }
7432: }
7433: }
1.612 raeburn 7434: return;
7435: }
7436:
7437: sub user_rule_formats {
7438: my ($domain,$domdesc,$curr_rules,$check) = @_;
7439: my %text = (
7440: 'username' => 'Usernames',
7441: 'id' => 'IDs',
7442: );
7443: my $output;
7444: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
7445: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
7446: if (@{$ruleorder} > 0) {
7447: $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>';
7448: foreach my $rule (@{$ruleorder}) {
7449: if (ref($curr_rules) eq 'ARRAY') {
7450: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
7451: if (ref($rules->{$rule}) eq 'HASH') {
7452: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
7453: $rules->{$rule}{'desc'}.'</li>';
7454: }
7455: }
7456: }
7457: }
7458: $output .= '</ul>';
7459: }
7460: }
7461: return $output;
7462: }
7463:
7464: sub instrule_disallow_msg {
1.615 raeburn 7465: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 7466: my $response;
7467: my %text = (
7468: item => 'username',
7469: items => 'usernames',
7470: match => 'matches',
7471: do => 'does',
7472: action => 'a username',
7473: one => 'one',
7474: );
7475: if ($count > 1) {
7476: $text{'item'} = 'usernames';
7477: $text{'match'} ='match';
7478: $text{'do'} = 'do';
7479: $text{'action'} = 'usernames',
7480: $text{'one'} = 'ones';
7481: }
7482: if ($checkitem eq 'id') {
7483: $text{'items'} = 'IDs';
7484: $text{'item'} = 'ID';
7485: $text{'action'} = 'an ID';
1.615 raeburn 7486: if ($count > 1) {
7487: $text{'item'} = 'IDs';
7488: $text{'action'} = 'IDs';
7489: }
1.612 raeburn 7490: }
1.674 bisitz 7491: $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 />';
1.615 raeburn 7492: if ($mode eq 'upload') {
7493: if ($checkitem eq 'username') {
7494: $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'}.");
7495: } elsif ($checkitem eq 'id') {
1.674 bisitz 7496: $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.");
1.615 raeburn 7497: }
1.669 raeburn 7498: } elsif ($mode eq 'selfcreate') {
7499: if ($checkitem eq 'id') {
7500: $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.");
7501: }
1.615 raeburn 7502: } else {
7503: if ($checkitem eq 'username') {
7504: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
7505: } elsif ($checkitem eq 'id') {
7506: $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.");
7507: }
1.612 raeburn 7508: }
7509: return $response;
1.585 raeburn 7510: }
7511:
1.624 raeburn 7512: sub personal_data_fieldtitles {
7513: my %fieldtitles = &Apache::lonlocal::texthash (
7514: id => 'Student/Employee ID',
7515: permanentemail => 'E-mail address',
7516: lastname => 'Last Name',
7517: firstname => 'First Name',
7518: middlename => 'Middle Name',
7519: generation => 'Generation',
7520: gen => 'Generation',
1.765 raeburn 7521: inststatus => 'Affiliation',
1.624 raeburn 7522: );
7523: return %fieldtitles;
7524: }
7525:
1.642 raeburn 7526: sub sorted_inst_types {
7527: my ($dom) = @_;
7528: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
7529: my $othertitle = &mt('All users');
7530: if ($env{'request.course.id'}) {
1.668 raeburn 7531: $othertitle = &mt('Any users');
1.642 raeburn 7532: }
7533: my @types;
7534: if (ref($order) eq 'ARRAY') {
7535: @types = @{$order};
7536: }
7537: if (@types == 0) {
7538: if (ref($usertypes) eq 'HASH') {
7539: @types = sort(keys(%{$usertypes}));
7540: }
7541: }
7542: if (keys(%{$usertypes}) > 0) {
7543: $othertitle = &mt('Other users');
7544: }
7545: return ($othertitle,$usertypes,\@types);
7546: }
7547:
1.645 raeburn 7548: sub get_institutional_codes {
7549: my ($settings,$allcourses,$LC_code) = @_;
7550: # Get complete list of course sections to update
7551: my @currsections = ();
7552: my @currxlists = ();
7553: my $coursecode = $$settings{'internal.coursecode'};
7554:
7555: if ($$settings{'internal.sectionnums'} ne '') {
7556: @currsections = split(/,/,$$settings{'internal.sectionnums'});
7557: }
7558:
7559: if ($$settings{'internal.crosslistings'} ne '') {
7560: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
7561: }
7562:
7563: if (@currxlists > 0) {
7564: foreach (@currxlists) {
7565: if (m/^([^:]+):(\w*)$/) {
7566: unless (grep/^$1$/,@{$allcourses}) {
7567: push @{$allcourses},$1;
7568: $$LC_code{$1} = $2;
7569: }
7570: }
7571: }
7572: }
7573:
7574: if (@currsections > 0) {
7575: foreach (@currsections) {
7576: if (m/^(\w+):(\w*)$/) {
7577: my $sec = $coursecode.$1;
7578: my $lc_sec = $2;
7579: unless (grep/^$sec$/,@{$allcourses}) {
7580: push @{$allcourses},$sec;
7581: $$LC_code{$sec} = $lc_sec;
7582: }
7583: }
7584: }
7585: }
7586: return;
7587: }
7588:
1.112 bowersj2 7589: =pod
7590:
1.780 raeburn 7591: =head1 Slot Helpers
7592:
7593: =over 4
7594:
7595: =item * sorted_slots()
7596:
7597: Sorts an array of slot names in order of slot start time (earliest first).
7598:
7599: Inputs:
7600:
7601: =over 4
7602:
7603: slotsarr - Reference to array of unsorted slot names.
7604:
7605: slots - Reference to hash of hash, where outer hash keys are slot names.
7606:
1.549 albertel 7607: =back
7608:
1.780 raeburn 7609: Returns:
7610:
7611: =over 4
7612:
7613: sorted - An array of slot names sorted by the start time of the slot.
7614:
7615: =back
7616:
7617: =back
7618:
7619: =cut
7620:
7621:
7622: sub sorted_slots {
7623: my ($slotsarr,$slots) = @_;
7624: my @sorted;
7625: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
7626: @sorted =
7627: sort {
7628: if (ref($slots->{$a}) && ref($slots->{$b})) {
7629: return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
7630: }
7631: if (ref($slots->{$a})) { return -1;}
7632: if (ref($slots->{$b})) { return 1;}
7633: return 0;
7634: } @{$slotsarr};
7635: }
7636: return @sorted;
7637: }
7638:
7639:
7640: =pod
7641:
1.549 albertel 7642: =head1 HTTP Helpers
7643:
7644: =over 4
7645:
1.648 raeburn 7646: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 7647:
1.258 albertel 7648: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 7649: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 7650: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 7651:
7652: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
7653: $possible_names is an ref to an array of form element names. As an example:
7654: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 7655: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 7656:
7657: =cut
1.1 albertel 7658:
1.6 albertel 7659: sub get_unprocessed_cgi {
1.25 albertel 7660: my ($query,$possible_names)= @_;
1.26 matthew 7661: # $Apache::lonxml::debug=1;
1.356 albertel 7662: foreach my $pair (split(/&/,$query)) {
7663: my ($name, $value) = split(/=/,$pair);
1.369 www 7664: $name = &unescape($name);
1.25 albertel 7665: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
7666: $value =~ tr/+/ /;
7667: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 7668: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 7669: }
1.16 harris41 7670: }
1.6 albertel 7671: }
7672:
1.112 bowersj2 7673: =pod
7674:
1.648 raeburn 7675: =item * &cacheheader()
1.112 bowersj2 7676:
7677: returns cache-controlling header code
7678:
7679: =cut
7680:
1.7 albertel 7681: sub cacheheader {
1.258 albertel 7682: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 7683: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
7684: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 7685: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
7686: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 7687: return $output;
1.7 albertel 7688: }
7689:
1.112 bowersj2 7690: =pod
7691:
1.648 raeburn 7692: =item * &no_cache($r)
1.112 bowersj2 7693:
7694: specifies header code to not have cache
7695:
7696: =cut
7697:
1.9 albertel 7698: sub no_cache {
1.216 albertel 7699: my ($r) = @_;
7700: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 7701: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 7702: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
7703: $r->no_cache(1);
7704: $r->header_out("Expires" => $date);
7705: $r->header_out("Pragma" => "no-cache");
1.123 www 7706: }
7707:
7708: sub content_type {
1.181 albertel 7709: my ($r,$type,$charset) = @_;
1.299 foxr 7710: if ($r) {
7711: # Note that printout.pl calls this with undef for $r.
7712: &no_cache($r);
7713: }
1.258 albertel 7714: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 7715: unless ($charset) {
7716: $charset=&Apache::lonlocal::current_encoding;
7717: }
7718: if ($charset) { $type.='; charset='.$charset; }
7719: if ($r) {
7720: $r->content_type($type);
7721: } else {
7722: print("Content-type: $type\n\n");
7723: }
1.9 albertel 7724: }
1.25 albertel 7725:
1.112 bowersj2 7726: =pod
7727:
1.648 raeburn 7728: =item * &add_to_env($name,$value)
1.112 bowersj2 7729:
1.258 albertel 7730: adds $name to the %env hash with value
1.112 bowersj2 7731: $value, if $name already exists, the entry is converted to an array
7732: reference and $value is added to the array.
7733:
7734: =cut
7735:
1.25 albertel 7736: sub add_to_env {
7737: my ($name,$value)=@_;
1.258 albertel 7738: if (defined($env{$name})) {
7739: if (ref($env{$name})) {
1.25 albertel 7740: #already have multiple values
1.258 albertel 7741: push(@{ $env{$name} },$value);
1.25 albertel 7742: } else {
7743: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 7744: my $first=$env{$name};
7745: undef($env{$name});
7746: push(@{ $env{$name} },$first,$value);
1.25 albertel 7747: }
7748: } else {
1.258 albertel 7749: $env{$name}=$value;
1.25 albertel 7750: }
1.31 albertel 7751: }
1.149 albertel 7752:
7753: =pod
7754:
1.648 raeburn 7755: =item * &get_env_multiple($name)
1.149 albertel 7756:
1.258 albertel 7757: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 7758: values may be defined and end up as an array ref.
7759:
7760: returns an array of values
7761:
7762: =cut
7763:
7764: sub get_env_multiple {
7765: my ($name) = @_;
7766: my @values;
1.258 albertel 7767: if (defined($env{$name})) {
1.149 albertel 7768: # exists is it an array
1.258 albertel 7769: if (ref($env{$name})) {
7770: @values=@{ $env{$name} };
1.149 albertel 7771: } else {
1.258 albertel 7772: $values[0]=$env{$name};
1.149 albertel 7773: }
7774: }
7775: return(@values);
7776: }
7777:
1.660 raeburn 7778: sub ask_for_embedded_content {
7779: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
7780: my $upload_output = '
7781: <form name="upload_embedded" action="'.$actionurl.'"
7782: method="post" enctype="multipart/form-data">';
7783: $upload_output .= $state;
1.661 raeburn 7784: $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
1.660 raeburn 7785:
7786: my $num = 0;
7787: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
7788: $upload_output .= &start_data_table_row().
7789: '<td>'.$embed_file.'</td><td>';
7790: if ($args->{'ignore_remote_references'}
7791: && $embed_file =~ m{^\w+://}) {
7792: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
7793: } elsif ($args->{'error_on_invalid_names'}
7794: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
7795:
7796: $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
7797:
7798: } else {
7799: $upload_output .='
1.661 raeburn 7800: <input name="embedded_item_'.$num.'" type="file" value="" />
1.660 raeburn 7801: <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
7802: my $attrib = join(':',@{$$allfiles{$embed_file}});
7803: $upload_output .=
7804: "\n\t\t".
7805: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
7806: $attrib.'" />';
7807: if (exists($$codebase{$embed_file})) {
7808: $upload_output .=
7809: "\n\t\t".
7810: '<input name="codebase_'.$num.'" type="hidden" value="'.
7811: &escape($$codebase{$embed_file}).'" />';
7812: }
7813: }
7814: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
7815: $num++;
7816: }
7817: $upload_output .= &Apache::loncommon::end_data_table().'<br />
7818: <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
7819: <input type ="submit" value="'.&mt('Upload Listed Files').'" />
7820: '.&mt('(only files for which a location has been provided will be uploaded)').'
7821: </form>';
7822: return $upload_output;
7823: }
7824:
1.661 raeburn 7825: sub upload_embedded {
7826: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
7827: $current_disk_usage) = @_;
7828: my $output;
7829: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
7830: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
7831: my $orig_uploaded_filename =
7832: $env{'form.embedded_item_'.$i.'.filename'};
7833:
7834: $env{'form.embedded_orig_'.$i} =
7835: &unescape($env{'form.embedded_orig_'.$i});
7836: my ($path,$fname) =
7837: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
7838: # no path, whole string is fname
7839: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
7840:
7841: $path = $env{'form.currentpath'}.$path;
7842: $fname = &Apache::lonnet::clean_filename($fname);
7843: # See if there is anything left
7844: next if ($fname eq '');
7845:
7846: # Check if file already exists as a file or directory.
7847: my ($state,$msg);
7848: if ($context eq 'portfolio') {
7849: my $port_path = $dirpath;
7850: if ($group ne '') {
7851: $port_path = "groups/$group/$port_path";
7852: }
7853: ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
7854: $dir_root,$port_path,$disk_quota,
7855: $current_disk_usage,$uname,$udom);
7856: if ($state eq 'will_exceed_quota'
7857: || $state eq 'file_locked'
7858: || $state eq 'file_exists' ) {
7859: $output .= $msg;
7860: next;
7861: }
7862: } elsif (($context eq 'author') || ($context eq 'testbank')) {
7863: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
7864: if ($state eq 'exists') {
7865: $output .= $msg;
7866: next;
7867: }
7868: }
7869: # Check if extension is valid
7870: if (($fname =~ /\.(\w+)$/) &&
7871: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
7872: $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
7873: next;
7874: } elsif (($fname =~ /\.(\w+)$/) &&
7875: (!defined(&Apache::loncommon::fileembstyle($1)))) {
7876: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
7877: next;
7878: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
7879: $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
7880: next;
7881: }
7882:
7883: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
7884: if ($context eq 'portfolio') {
7885: my $result=
7886: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
7887: $dirpath.$path);
7888: if ($result !~ m|^/uploaded/|) {
7889: $output .= '<span class="LC_error">'
7890: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
7891: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
7892: .'</span><br />';
7893: next;
7894: } else {
7895: $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
7896: $path.$fname.'</span>').'</p>';
7897: }
7898: } else {
7899: # Save the file
7900: my $target = $env{'form.embedded_item_'.$i};
7901: my $fullpath = $dir_root.$dirpath.'/'.$path;
7902: my $dest = $fullpath.$fname;
7903: my $url = $url_root.$dirpath.'/'.$path.$fname;
7904: my @parts=split(/\//,$fullpath);
7905: my $count;
7906: my $filepath = $dir_root;
7907: for ($count=4;$count<=$#parts;$count++) {
7908: $filepath .= "/$parts[$count]";
7909: if ((-e $filepath)!=1) {
7910: mkdir($filepath,0770);
7911: }
7912: }
7913: my $fh;
7914: if (!open($fh,'>'.$dest)) {
7915: &Apache::lonnet::logthis('Failed to create '.$dest);
7916: $output .= '<span class="LC_error">'.
7917: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
7918: '</span><br />';
7919: } else {
7920: if (!print $fh $env{'form.embedded_item_'.$i}) {
7921: &Apache::lonnet::logthis('Failed to write to '.$dest);
7922: $output .= '<span class="LC_error">'.
7923: &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
7924: '</span><br />';
7925: } else {
7926: if ($context eq 'testbank') {
7927: $output .= &mt('Embedded file uploaded successfully:').
7928: ' <a href="'.$url.'">'.
7929: $orig_uploaded_filename.'</a><br />';
7930: } else {
1.705 tempelho 7931: $output .= '<span class=\"LC_fontsize_large\">'.
1.661 raeburn 7932: &mt('View embedded file: [_1]','<a href="'.$url.'">'.
1.705 tempelho 7933: $orig_uploaded_filename.'</a>').'</span><br />';
1.661 raeburn 7934: }
7935: }
7936: close($fh);
7937: }
7938: }
7939: }
7940: return $output;
7941: }
7942:
7943: sub check_for_existing {
7944: my ($path,$fname,$element) = @_;
7945: my ($state,$msg);
7946: if (-d $path.'/'.$fname) {
7947: $state = 'exists';
7948: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
7949: } elsif (-e $path.'/'.$fname) {
7950: $state = 'exists';
7951: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
7952: }
7953: if ($state eq 'exists') {
7954: $msg = '<span class="LC_error">'.$msg.'</span><br />';
7955: }
7956: return ($state,$msg);
7957: }
7958:
7959: sub check_for_upload {
7960: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
7961: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
7962: my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
7963: my $getpropath = 1;
7964: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
7965: $getpropath);
7966: my $found_file = 0;
7967: my $locked_file = 0;
7968: foreach my $line (@dir_list) {
7969: my ($file_name)=split(/\&/,$line,2);
7970: if ($file_name eq $fname){
7971: $file_name = $path.$file_name;
7972: if ($group ne '') {
7973: $file_name = $group.$file_name;
7974: }
7975: $found_file = 1;
7976: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
7977: $locked_file = 1;
7978: }
7979: }
7980: }
7981: if (($current_disk_usage + $filesize) > $disk_quota){
7982: my $msg = '<span class="LC_error">'.
7983: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
7984: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
7985: return ('will_exceed_quota',$msg);
7986: } elsif ($found_file) {
7987: if ($locked_file) {
7988: my $msg = '<span class="LC_error">';
7989: $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>');
7990: $msg .= '</span><br />';
7991: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
7992: return ('file_locked',$msg);
7993: } else {
7994: my $msg = '<span class="LC_error">';
7995: $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'});
7996: $msg .= '</span>';
7997: $msg .= '<br />';
7998: $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
7999: return ('file_exists',$msg);
8000: }
8001: }
8002: }
8003:
1.31 albertel 8004:
1.41 ng 8005: =pod
1.45 matthew 8006:
1.464 albertel 8007: =back
1.41 ng 8008:
1.112 bowersj2 8009: =head1 CSV Upload/Handling functions
1.38 albertel 8010:
1.41 ng 8011: =over 4
8012:
1.648 raeburn 8013: =item * &upfile_store($r)
1.41 ng 8014:
8015: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 8016: needs $env{'form.upfile'}
1.41 ng 8017: returns $datatoken to be put into hidden field
8018:
8019: =cut
1.31 albertel 8020:
8021: sub upfile_store {
8022: my $r=shift;
1.258 albertel 8023: $env{'form.upfile'}=~s/\r/\n/gs;
8024: $env{'form.upfile'}=~s/\f/\n/gs;
8025: $env{'form.upfile'}=~s/\n+/\n/gs;
8026: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 8027:
1.258 albertel 8028: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
8029: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 8030: {
1.158 raeburn 8031: my $datafile = $r->dir_config('lonDaemons').
8032: '/tmp/'.$datatoken.'.tmp';
8033: if ( open(my $fh,">$datafile") ) {
1.258 albertel 8034: print $fh $env{'form.upfile'};
1.158 raeburn 8035: close($fh);
8036: }
1.31 albertel 8037: }
8038: return $datatoken;
8039: }
8040:
1.56 matthew 8041: =pod
8042:
1.648 raeburn 8043: =item * &load_tmp_file($r)
1.41 ng 8044:
8045: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 8046: needs $env{'form.datatoken'},
8047: sets $env{'form.upfile'} to the contents of the file
1.41 ng 8048:
8049: =cut
1.31 albertel 8050:
8051: sub load_tmp_file {
8052: my $r=shift;
8053: my @studentdata=();
8054: {
1.158 raeburn 8055: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 8056: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 8057: if ( open(my $fh,"<$studentfile") ) {
8058: @studentdata=<$fh>;
8059: close($fh);
8060: }
1.31 albertel 8061: }
1.258 albertel 8062: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 8063: }
8064:
1.56 matthew 8065: =pod
8066:
1.648 raeburn 8067: =item * &upfile_record_sep()
1.41 ng 8068:
8069: Separate uploaded file into records
8070: returns array of records,
1.258 albertel 8071: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 8072:
8073: =cut
1.31 albertel 8074:
8075: sub upfile_record_sep {
1.258 albertel 8076: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 8077: } else {
1.248 albertel 8078: my @records;
1.258 albertel 8079: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 8080: if ($line=~/^\s*$/) { next; }
8081: push(@records,$line);
8082: }
8083: return @records;
1.31 albertel 8084: }
8085: }
8086:
1.56 matthew 8087: =pod
8088:
1.648 raeburn 8089: =item * &record_sep($record)
1.41 ng 8090:
1.258 albertel 8091: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 8092:
8093: =cut
8094:
1.263 www 8095: sub takeleft {
8096: my $index=shift;
8097: return substr('0000'.$index,-4,4);
8098: }
8099:
1.31 albertel 8100: sub record_sep {
8101: my $record=shift;
8102: my %components=();
1.258 albertel 8103: if ($env{'form.upfiletype'} eq 'xml') {
8104: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 8105: my $i=0;
1.356 albertel 8106: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 8107: $field=~s/^(\"|\')//;
8108: $field=~s/(\"|\')$//;
1.263 www 8109: $components{&takeleft($i)}=$field;
1.31 albertel 8110: $i++;
8111: }
1.258 albertel 8112: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 8113: my $i=0;
1.356 albertel 8114: foreach my $field (split(/\t/,$record)) {
1.31 albertel 8115: $field=~s/^(\"|\')//;
8116: $field=~s/(\"|\')$//;
1.263 www 8117: $components{&takeleft($i)}=$field;
1.31 albertel 8118: $i++;
8119: }
8120: } else {
1.561 www 8121: my $separator=',';
1.480 banghart 8122: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 8123: $separator=';';
1.480 banghart 8124: }
1.31 albertel 8125: my $i=0;
1.561 www 8126: # the character we are looking for to indicate the end of a quote or a record
8127: my $looking_for=$separator;
8128: # do not add the characters to the fields
8129: my $ignore=0;
8130: # we just encountered a separator (or the beginning of the record)
8131: my $just_found_separator=1;
8132: # store the field we are working on here
8133: my $field='';
8134: # work our way through all characters in record
8135: foreach my $character ($record=~/(.)/g) {
8136: if ($character eq $looking_for) {
8137: if ($character ne $separator) {
8138: # Found the end of a quote, again looking for separator
8139: $looking_for=$separator;
8140: $ignore=1;
8141: } else {
8142: # Found a separator, store away what we got
8143: $components{&takeleft($i)}=$field;
8144: $i++;
8145: $just_found_separator=1;
8146: $ignore=0;
8147: $field='';
8148: }
8149: next;
8150: }
8151: # single or double quotation marks after a separator indicate beginning of a quote
8152: # we are now looking for the end of the quote and need to ignore separators
8153: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
8154: $looking_for=$character;
8155: next;
8156: }
8157: # ignore would be true after we reached the end of a quote
8158: if ($ignore) { next; }
8159: if (($just_found_separator) && ($character=~/\s/)) { next; }
8160: $field.=$character;
8161: $just_found_separator=0;
1.31 albertel 8162: }
1.561 www 8163: # catch the very last entry, since we never encountered the separator
8164: $components{&takeleft($i)}=$field;
1.31 albertel 8165: }
8166: return %components;
8167: }
8168:
1.144 matthew 8169: ######################################################
8170: ######################################################
8171:
1.56 matthew 8172: =pod
8173:
1.648 raeburn 8174: =item * &upfile_select_html()
1.41 ng 8175:
1.144 matthew 8176: Return HTML code to select a file from the users machine and specify
8177: the file type.
1.41 ng 8178:
8179: =cut
8180:
1.144 matthew 8181: ######################################################
8182: ######################################################
1.31 albertel 8183: sub upfile_select_html {
1.144 matthew 8184: my %Types = (
8185: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 8186: semisv => &mt('Semicolon separated values'),
1.144 matthew 8187: space => &mt('Space separated'),
8188: tab => &mt('Tabulator separated'),
8189: # xml => &mt('HTML/XML'),
8190: );
8191: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 8192: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 8193: foreach my $type (sort(keys(%Types))) {
8194: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
8195: }
8196: $Str .= "</select>\n";
8197: return $Str;
1.31 albertel 8198: }
8199:
1.301 albertel 8200: sub get_samples {
8201: my ($records,$toget) = @_;
8202: my @samples=({});
8203: my $got=0;
8204: foreach my $rec (@$records) {
8205: my %temp = &record_sep($rec);
8206: if (! grep(/\S/, values(%temp))) { next; }
8207: if (%temp) {
8208: $samples[$got]=\%temp;
8209: $got++;
8210: if ($got == $toget) { last; }
8211: }
8212: }
8213: return \@samples;
8214: }
8215:
1.144 matthew 8216: ######################################################
8217: ######################################################
8218:
1.56 matthew 8219: =pod
8220:
1.648 raeburn 8221: =item * &csv_print_samples($r,$records)
1.41 ng 8222:
8223: Prints a table of sample values from each column uploaded $r is an
8224: Apache Request ref, $records is an arrayref from
8225: &Apache::loncommon::upfile_record_sep
8226:
8227: =cut
8228:
1.144 matthew 8229: ######################################################
8230: ######################################################
1.31 albertel 8231: sub csv_print_samples {
8232: my ($r,$records) = @_;
1.662 bisitz 8233: my $samples = &get_samples($records,5);
1.301 albertel 8234:
1.594 raeburn 8235: $r->print(&mt('Samples').'<br />'.&start_data_table().
8236: &start_data_table_header_row());
1.356 albertel 8237: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8238: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 8239: $r->print(&end_data_table_header_row());
1.301 albertel 8240: foreach my $hash (@$samples) {
1.594 raeburn 8241: $r->print(&start_data_table_row());
1.356 albertel 8242: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 8243: $r->print('<td>');
1.356 albertel 8244: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 8245: $r->print('</td>');
8246: }
1.594 raeburn 8247: $r->print(&end_data_table_row());
1.31 albertel 8248: }
1.594 raeburn 8249: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 8250: }
8251:
1.144 matthew 8252: ######################################################
8253: ######################################################
8254:
1.56 matthew 8255: =pod
8256:
1.648 raeburn 8257: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 8258:
8259: Prints a table to create associations between values and table columns.
1.144 matthew 8260:
1.41 ng 8261: $r is an Apache Request ref,
8262: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 8263: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 8264:
8265: =cut
8266:
1.144 matthew 8267: ######################################################
8268: ######################################################
1.31 albertel 8269: sub csv_print_select_table {
8270: my ($r,$records,$d) = @_;
1.301 albertel 8271: my $i=0;
8272: my $samples = &get_samples($records,1);
1.144 matthew 8273: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 8274: &start_data_table().&start_data_table_header_row().
1.144 matthew 8275: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 8276: '<th>'.&mt('Column').'</th>'.
8277: &end_data_table_header_row()."\n");
1.356 albertel 8278: foreach my $array_ref (@$d) {
8279: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 8280: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 8281:
8282: $r->print('<td><select name=f'.$i.
1.32 matthew 8283: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 8284: $r->print('<option value="none"></option>');
1.356 albertel 8285: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8286: $r->print('<option value="'.$sample.'"'.
8287: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 8288: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 8289: }
1.594 raeburn 8290: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 8291: $i++;
8292: }
1.594 raeburn 8293: $r->print(&end_data_table());
1.31 albertel 8294: $i--;
8295: return $i;
8296: }
1.56 matthew 8297:
1.144 matthew 8298: ######################################################
8299: ######################################################
8300:
1.56 matthew 8301: =pod
1.31 albertel 8302:
1.648 raeburn 8303: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 8304:
8305: Prints a table of sample values from the upload and can make associate samples to internal names.
8306:
8307: $r is an Apache Request ref,
8308: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
8309: $d is an array of 2 element arrays (internal name, displayed name)
8310:
8311: =cut
8312:
1.144 matthew 8313: ######################################################
8314: ######################################################
1.31 albertel 8315: sub csv_samples_select_table {
8316: my ($r,$records,$d) = @_;
8317: my $i=0;
1.144 matthew 8318: #
1.662 bisitz 8319: my $max_samples = 5;
8320: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 8321: $r->print(&start_data_table().
8322: &start_data_table_header_row().'<th>'.
8323: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
8324: &end_data_table_header_row());
1.301 albertel 8325:
8326: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 8327: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 8328: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 8329: foreach my $option (@$d) {
8330: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 8331: $r->print('<option value="'.$value.'"'.
1.253 albertel 8332: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 8333: $display.'</option>');
1.31 albertel 8334: }
8335: $r->print('</select></td><td>');
1.662 bisitz 8336: foreach my $line (0..($max_samples-1)) {
1.301 albertel 8337: if (defined($samples->[$line]{$key})) {
8338: $r->print($samples->[$line]{$key}."<br />\n");
8339: }
8340: }
1.594 raeburn 8341: $r->print('</td>'.&end_data_table_row());
1.31 albertel 8342: $i++;
8343: }
1.594 raeburn 8344: $r->print(&end_data_table());
1.31 albertel 8345: $i--;
8346: return($i);
1.115 matthew 8347: }
8348:
1.144 matthew 8349: ######################################################
8350: ######################################################
8351:
1.115 matthew 8352: =pod
8353:
1.648 raeburn 8354: =item * &clean_excel_name($name)
1.115 matthew 8355:
8356: Returns a replacement for $name which does not contain any illegal characters.
8357:
8358: =cut
8359:
1.144 matthew 8360: ######################################################
8361: ######################################################
1.115 matthew 8362: sub clean_excel_name {
8363: my ($name) = @_;
8364: $name =~ s/[:\*\?\/\\]//g;
8365: if (length($name) > 31) {
8366: $name = substr($name,0,31);
8367: }
8368: return $name;
1.25 albertel 8369: }
1.84 albertel 8370:
1.85 albertel 8371: =pod
8372:
1.648 raeburn 8373: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 8374:
8375: Returns either 1 or undef
8376:
8377: 1 if the part is to be hidden, undef if it is to be shown
8378:
8379: Arguments are:
8380:
8381: $id the id of the part to be checked
8382: $symb, optional the symb of the resource to check
8383: $udom, optional the domain of the user to check for
8384: $uname, optional the username of the user to check for
8385:
8386: =cut
1.84 albertel 8387:
8388: sub check_if_partid_hidden {
8389: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 8390: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 8391: $symb,$udom,$uname);
1.141 albertel 8392: my $truth=1;
8393: #if the string starts with !, then the list is the list to show not hide
8394: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 8395: my @hiddenlist=split(/,/,$hiddenparts);
8396: foreach my $checkid (@hiddenlist) {
1.141 albertel 8397: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 8398: }
1.141 albertel 8399: return !$truth;
1.84 albertel 8400: }
1.127 matthew 8401:
1.138 matthew 8402:
8403: ############################################################
8404: ############################################################
8405:
8406: =pod
8407:
1.157 matthew 8408: =back
8409:
1.138 matthew 8410: =head1 cgi-bin script and graphing routines
8411:
1.157 matthew 8412: =over 4
8413:
1.648 raeburn 8414: =item * &get_cgi_id()
1.138 matthew 8415:
8416: Inputs: none
8417:
8418: Returns an id which can be used to pass environment variables
8419: to various cgi-bin scripts. These environment variables will
8420: be removed from the users environment after a given time by
8421: the routine &Apache::lonnet::transfer_profile_to_env.
8422:
8423: =cut
8424:
8425: ############################################################
8426: ############################################################
1.152 albertel 8427: my $uniq=0;
1.136 matthew 8428: sub get_cgi_id {
1.154 albertel 8429: $uniq=($uniq+1)%100000;
1.280 albertel 8430: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 8431: }
8432:
1.127 matthew 8433: ############################################################
8434: ############################################################
8435:
8436: =pod
8437:
1.648 raeburn 8438: =item * &DrawBarGraph()
1.127 matthew 8439:
1.138 matthew 8440: Facilitates the plotting of data in a (stacked) bar graph.
8441: Puts plot definition data into the users environment in order for
8442: graph.png to plot it. Returns an <img> tag for the plot.
8443: The bars on the plot are labeled '1','2',...,'n'.
8444:
8445: Inputs:
8446:
8447: =over 4
8448:
8449: =item $Title: string, the title of the plot
8450:
8451: =item $xlabel: string, text describing the X-axis of the plot
8452:
8453: =item $ylabel: string, text describing the Y-axis of the plot
8454:
8455: =item $Max: scalar, the maximum Y value to use in the plot
8456: If $Max is < any data point, the graph will not be rendered.
8457:
1.140 matthew 8458: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 8459: they are plotted. If undefined, default values will be used.
8460:
1.178 matthew 8461: =item $labels: array ref holding the labels to use on the x-axis for the bars.
8462:
1.138 matthew 8463: =item @Values: An array of array references. Each array reference holds data
8464: to be plotted in a stacked bar chart.
8465:
1.239 matthew 8466: =item If the final element of @Values is a hash reference the key/value
8467: pairs will be added to the graph definition.
8468:
1.138 matthew 8469: =back
8470:
8471: Returns:
8472:
8473: An <img> tag which references graph.png and the appropriate identifying
8474: information for the plot.
8475:
1.127 matthew 8476: =cut
8477:
8478: ############################################################
8479: ############################################################
1.134 matthew 8480: sub DrawBarGraph {
1.178 matthew 8481: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 8482: #
8483: if (! defined($colors)) {
8484: $colors = ['#33ff00',
8485: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
8486: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
8487: ];
8488: }
1.228 matthew 8489: my $extra_settings = {};
8490: if (ref($Values[-1]) eq 'HASH') {
8491: $extra_settings = pop(@Values);
8492: }
1.127 matthew 8493: #
1.136 matthew 8494: my $identifier = &get_cgi_id();
8495: my $id = 'cgi.'.$identifier;
1.129 matthew 8496: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 8497: return '';
8498: }
1.225 matthew 8499: #
8500: my @Labels;
8501: if (defined($labels)) {
8502: @Labels = @$labels;
8503: } else {
8504: for (my $i=0;$i<@{$Values[0]};$i++) {
8505: push (@Labels,$i+1);
8506: }
8507: }
8508: #
1.129 matthew 8509: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 8510: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 8511: my %ValuesHash;
8512: my $NumSets=1;
8513: foreach my $array (@Values) {
8514: next if (! ref($array));
1.136 matthew 8515: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 8516: join(',',@$array);
1.129 matthew 8517: }
1.127 matthew 8518: #
1.136 matthew 8519: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 8520: if ($NumBars < 3) {
8521: $width = 120+$NumBars*32;
1.220 matthew 8522: $xskip = 1;
1.225 matthew 8523: $bar_width = 30;
8524: } elsif ($NumBars < 5) {
8525: $width = 120+$NumBars*20;
8526: $xskip = 1;
8527: $bar_width = 20;
1.220 matthew 8528: } elsif ($NumBars < 10) {
1.136 matthew 8529: $width = 120+$NumBars*15;
8530: $xskip = 1;
8531: $bar_width = 15;
8532: } elsif ($NumBars <= 25) {
8533: $width = 120+$NumBars*11;
8534: $xskip = 5;
8535: $bar_width = 8;
8536: } elsif ($NumBars <= 50) {
8537: $width = 120+$NumBars*8;
8538: $xskip = 5;
8539: $bar_width = 4;
8540: } else {
8541: $width = 120+$NumBars*8;
8542: $xskip = 5;
8543: $bar_width = 4;
8544: }
8545: #
1.137 matthew 8546: $Max = 1 if ($Max < 1);
8547: if ( int($Max) < $Max ) {
8548: $Max++;
8549: $Max = int($Max);
8550: }
1.127 matthew 8551: $Title = '' if (! defined($Title));
8552: $xlabel = '' if (! defined($xlabel));
8553: $ylabel = '' if (! defined($ylabel));
1.369 www 8554: $ValuesHash{$id.'.title'} = &escape($Title);
8555: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
8556: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 8557: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 8558: $ValuesHash{$id.'.NumBars'} = $NumBars;
8559: $ValuesHash{$id.'.NumSets'} = $NumSets;
8560: $ValuesHash{$id.'.PlotType'} = 'bar';
8561: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8562: $ValuesHash{$id.'.height'} = $height;
8563: $ValuesHash{$id.'.width'} = $width;
8564: $ValuesHash{$id.'.xskip'} = $xskip;
8565: $ValuesHash{$id.'.bar_width'} = $bar_width;
8566: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 8567: #
1.228 matthew 8568: # Deal with other parameters
8569: while (my ($key,$value) = each(%$extra_settings)) {
8570: $ValuesHash{$id.'.'.$key} = $value;
8571: }
8572: #
1.646 raeburn 8573: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 8574: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8575: }
8576:
8577: ############################################################
8578: ############################################################
8579:
8580: =pod
8581:
1.648 raeburn 8582: =item * &DrawXYGraph()
1.137 matthew 8583:
1.138 matthew 8584: Facilitates the plotting of data in an XY graph.
8585: Puts plot definition data into the users environment in order for
8586: graph.png to plot it. Returns an <img> tag for the plot.
8587:
8588: Inputs:
8589:
8590: =over 4
8591:
8592: =item $Title: string, the title of the plot
8593:
8594: =item $xlabel: string, text describing the X-axis of the plot
8595:
8596: =item $ylabel: string, text describing the Y-axis of the plot
8597:
8598: =item $Max: scalar, the maximum Y value to use in the plot
8599: If $Max is < any data point, the graph will not be rendered.
8600:
8601: =item $colors: Array ref containing the hex color codes for the data to be
8602: plotted in. If undefined, default values will be used.
8603:
8604: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8605:
8606: =item $Ydata: Array ref containing Array refs.
1.185 www 8607: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 8608:
8609: =item %Values: hash indicating or overriding any default values which are
8610: passed to graph.png.
8611: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
8612:
8613: =back
8614:
8615: Returns:
8616:
8617: An <img> tag which references graph.png and the appropriate identifying
8618: information for the plot.
8619:
1.137 matthew 8620: =cut
8621:
8622: ############################################################
8623: ############################################################
8624: sub DrawXYGraph {
8625: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
8626: #
8627: # Create the identifier for the graph
8628: my $identifier = &get_cgi_id();
8629: my $id = 'cgi.'.$identifier;
8630: #
8631: $Title = '' if (! defined($Title));
8632: $xlabel = '' if (! defined($xlabel));
8633: $ylabel = '' if (! defined($ylabel));
8634: my %ValuesHash =
8635: (
1.369 www 8636: $id.'.title' => &escape($Title),
8637: $id.'.xlabel' => &escape($xlabel),
8638: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 8639: $id.'.y_max_value'=> $Max,
8640: $id.'.labels' => join(',',@$Xlabels),
8641: $id.'.PlotType' => 'XY',
8642: );
8643: #
8644: if (defined($colors) && ref($colors) eq 'ARRAY') {
8645: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8646: }
8647: #
8648: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
8649: return '';
8650: }
8651: my $NumSets=1;
1.138 matthew 8652: foreach my $array (@{$Ydata}){
1.137 matthew 8653: next if (! ref($array));
8654: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
8655: }
1.138 matthew 8656: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 8657: #
8658: # Deal with other parameters
8659: while (my ($key,$value) = each(%Values)) {
8660: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 8661: }
8662: #
1.646 raeburn 8663: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 8664: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8665: }
8666:
8667: ############################################################
8668: ############################################################
8669:
8670: =pod
8671:
1.648 raeburn 8672: =item * &DrawXYYGraph()
1.138 matthew 8673:
8674: Facilitates the plotting of data in an XY graph with two Y axes.
8675: Puts plot definition data into the users environment in order for
8676: graph.png to plot it. Returns an <img> tag for the plot.
8677:
8678: Inputs:
8679:
8680: =over 4
8681:
8682: =item $Title: string, the title of the plot
8683:
8684: =item $xlabel: string, text describing the X-axis of the plot
8685:
8686: =item $ylabel: string, text describing the Y-axis of the plot
8687:
8688: =item $colors: Array ref containing the hex color codes for the data to be
8689: plotted in. If undefined, default values will be used.
8690:
8691: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8692:
8693: =item $Ydata1: The first data set
8694:
8695: =item $Min1: The minimum value of the left Y-axis
8696:
8697: =item $Max1: The maximum value of the left Y-axis
8698:
8699: =item $Ydata2: The second data set
8700:
8701: =item $Min2: The minimum value of the right Y-axis
8702:
8703: =item $Max2: The maximum value of the left Y-axis
8704:
8705: =item %Values: hash indicating or overriding any default values which are
8706: passed to graph.png.
8707: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
8708:
8709: =back
8710:
8711: Returns:
8712:
8713: An <img> tag which references graph.png and the appropriate identifying
8714: information for the plot.
1.136 matthew 8715:
8716: =cut
8717:
8718: ############################################################
8719: ############################################################
1.137 matthew 8720: sub DrawXYYGraph {
8721: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
8722: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 8723: #
8724: # Create the identifier for the graph
8725: my $identifier = &get_cgi_id();
8726: my $id = 'cgi.'.$identifier;
8727: #
8728: $Title = '' if (! defined($Title));
8729: $xlabel = '' if (! defined($xlabel));
8730: $ylabel = '' if (! defined($ylabel));
8731: my %ValuesHash =
8732: (
1.369 www 8733: $id.'.title' => &escape($Title),
8734: $id.'.xlabel' => &escape($xlabel),
8735: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 8736: $id.'.labels' => join(',',@$Xlabels),
8737: $id.'.PlotType' => 'XY',
8738: $id.'.NumSets' => 2,
1.137 matthew 8739: $id.'.two_axes' => 1,
8740: $id.'.y1_max_value' => $Max1,
8741: $id.'.y1_min_value' => $Min1,
8742: $id.'.y2_max_value' => $Max2,
8743: $id.'.y2_min_value' => $Min2,
1.136 matthew 8744: );
8745: #
1.137 matthew 8746: if (defined($colors) && ref($colors) eq 'ARRAY') {
8747: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8748: }
8749: #
8750: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
8751: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 8752: return '';
8753: }
8754: my $NumSets=1;
1.137 matthew 8755: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 8756: next if (! ref($array));
8757: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 8758: }
8759: #
8760: # Deal with other parameters
8761: while (my ($key,$value) = each(%Values)) {
8762: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 8763: }
8764: #
1.646 raeburn 8765: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 8766: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 8767: }
8768:
8769: ############################################################
8770: ############################################################
8771:
8772: =pod
8773:
1.157 matthew 8774: =back
8775:
1.139 matthew 8776: =head1 Statistics helper routines?
8777:
8778: Bad place for them but what the hell.
8779:
1.157 matthew 8780: =over 4
8781:
1.648 raeburn 8782: =item * &chartlink()
1.139 matthew 8783:
8784: Returns a link to the chart for a specific student.
8785:
8786: Inputs:
8787:
8788: =over 4
8789:
8790: =item $linktext: The text of the link
8791:
8792: =item $sname: The students username
8793:
8794: =item $sdomain: The students domain
8795:
8796: =back
8797:
1.157 matthew 8798: =back
8799:
1.139 matthew 8800: =cut
8801:
8802: ############################################################
8803: ############################################################
8804: sub chartlink {
8805: my ($linktext, $sname, $sdomain) = @_;
8806: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 8807: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 8808: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 8809: '">'.$linktext.'</a>';
1.153 matthew 8810: }
8811:
8812: #######################################################
8813: #######################################################
8814:
8815: =pod
8816:
8817: =head1 Course Environment Routines
1.157 matthew 8818:
8819: =over 4
1.153 matthew 8820:
1.648 raeburn 8821: =item * &restore_course_settings()
1.153 matthew 8822:
1.648 raeburn 8823: =item * &store_course_settings()
1.153 matthew 8824:
8825: Restores/Store indicated form parameters from the course environment.
8826: Will not overwrite existing values of the form parameters.
8827:
8828: Inputs:
8829: a scalar describing the data (e.g. 'chart', 'problem_analysis')
8830:
8831: a hash ref describing the data to be stored. For example:
8832:
8833: %Save_Parameters = ('Status' => 'scalar',
8834: 'chartoutputmode' => 'scalar',
8835: 'chartoutputdata' => 'scalar',
8836: 'Section' => 'array',
1.373 raeburn 8837: 'Group' => 'array',
1.153 matthew 8838: 'StudentData' => 'array',
8839: 'Maps' => 'array');
8840:
8841: Returns: both routines return nothing
8842:
1.631 raeburn 8843: =back
8844:
1.153 matthew 8845: =cut
8846:
8847: #######################################################
8848: #######################################################
8849: sub store_course_settings {
1.496 albertel 8850: return &store_settings($env{'request.course.id'},@_);
8851: }
8852:
8853: sub store_settings {
1.153 matthew 8854: # save to the environment
8855: # appenv the same items, just to be safe
1.300 albertel 8856: my $udom = $env{'user.domain'};
8857: my $uname = $env{'user.name'};
1.496 albertel 8858: my ($context,$prefix,$Settings) = @_;
1.153 matthew 8859: my %SaveHash;
8860: my %AppHash;
8861: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 8862: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 8863: my $envname = 'environment.'.$basename;
1.258 albertel 8864: if (exists($env{'form.'.$setting})) {
1.153 matthew 8865: # Save this value away
8866: if ($type eq 'scalar' &&
1.258 albertel 8867: (! exists($env{$envname}) ||
8868: $env{$envname} ne $env{'form.'.$setting})) {
8869: $SaveHash{$basename} = $env{'form.'.$setting};
8870: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 8871: } elsif ($type eq 'array') {
8872: my $stored_form;
1.258 albertel 8873: if (ref($env{'form.'.$setting})) {
1.153 matthew 8874: $stored_form = join(',',
8875: map {
1.369 www 8876: &escape($_);
1.258 albertel 8877: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 8878: } else {
8879: $stored_form =
1.369 www 8880: &escape($env{'form.'.$setting});
1.153 matthew 8881: }
8882: # Determine if the array contents are the same.
1.258 albertel 8883: if ($stored_form ne $env{$envname}) {
1.153 matthew 8884: $SaveHash{$basename} = $stored_form;
8885: $AppHash{$envname} = $stored_form;
8886: }
8887: }
8888: }
8889: }
8890: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 8891: $udom,$uname);
1.153 matthew 8892: if ($put_result !~ /^(ok|delayed)/) {
8893: &Apache::lonnet::logthis('unable to save form parameters, '.
8894: 'got error:'.$put_result);
8895: }
8896: # Make sure these settings stick around in this session, too
1.646 raeburn 8897: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 8898: return;
8899: }
8900:
8901: sub restore_course_settings {
1.499 albertel 8902: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 8903: }
8904:
8905: sub restore_settings {
8906: my ($context,$prefix,$Settings) = @_;
1.153 matthew 8907: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 8908: next if (exists($env{'form.'.$setting}));
1.496 albertel 8909: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 8910: '.'.$setting;
1.258 albertel 8911: if (exists($env{$envname})) {
1.153 matthew 8912: if ($type eq 'scalar') {
1.258 albertel 8913: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 8914: } elsif ($type eq 'array') {
1.258 albertel 8915: $env{'form.'.$setting} = [
1.153 matthew 8916: map {
1.369 www 8917: &unescape($_);
1.258 albertel 8918: } split(',',$env{$envname})
1.153 matthew 8919: ];
8920: }
8921: }
8922: }
1.127 matthew 8923: }
8924:
1.618 raeburn 8925: #######################################################
8926: #######################################################
8927:
8928: =pod
8929:
8930: =head1 Domain E-mail Routines
8931:
8932: =over 4
8933:
1.648 raeburn 8934: =item * &build_recipient_list()
1.618 raeburn 8935:
1.766 raeburn 8936: Build recipient lists for four types of e-mail:
8937: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
8938: (d) Help requests, generated by
8939: lonerrorhandler.pm, CHECKRPMS, loncron, and lonsupportreq.pm respectively.
1.618 raeburn 8940:
8941: Inputs:
1.619 raeburn 8942: defmail (scalar - email address of default recipient),
1.618 raeburn 8943: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 8944: defdom (domain for which to retrieve configuration settings),
8945: origmail (scalar - email address of recipient from loncapa.conf,
8946: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 8947:
1.655 raeburn 8948: Returns: comma separated list of addresses to which to send e-mail.
8949:
8950: =back
1.618 raeburn 8951:
8952: =cut
8953:
8954: ############################################################
8955: ############################################################
8956: sub build_recipient_list {
1.619 raeburn 8957: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 8958: my @recipients;
8959: my $otheremails;
8960: my %domconfig =
8961: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
8962: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 8963: if (exists($domconfig{'contacts'}{$mailing})) {
8964: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
8965: my @contacts = ('adminemail','supportemail');
8966: foreach my $item (@contacts) {
8967: if ($domconfig{'contacts'}{$mailing}{$item}) {
8968: my $addr = $domconfig{'contacts'}{$item};
8969: if (!grep(/^\Q$addr\E$/,@recipients)) {
8970: push(@recipients,$addr);
8971: }
1.619 raeburn 8972: }
1.766 raeburn 8973: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 8974: }
8975: }
1.766 raeburn 8976: } elsif ($origmail ne '') {
8977: push(@recipients,$origmail);
1.618 raeburn 8978: }
1.619 raeburn 8979: } elsif ($origmail ne '') {
8980: push(@recipients,$origmail);
1.618 raeburn 8981: }
1.688 raeburn 8982: if (defined($defmail)) {
8983: if ($defmail ne '') {
8984: push(@recipients,$defmail);
8985: }
1.618 raeburn 8986: }
8987: if ($otheremails) {
1.619 raeburn 8988: my @others;
8989: if ($otheremails =~ /,/) {
8990: @others = split(/,/,$otheremails);
1.618 raeburn 8991: } else {
1.619 raeburn 8992: push(@others,$otheremails);
8993: }
8994: foreach my $addr (@others) {
8995: if (!grep(/^\Q$addr\E$/,@recipients)) {
8996: push(@recipients,$addr);
8997: }
1.618 raeburn 8998: }
8999: }
1.619 raeburn 9000: my $recipientlist = join(',',@recipients);
1.618 raeburn 9001: return $recipientlist;
9002: }
9003:
1.127 matthew 9004: ############################################################
9005: ############################################################
1.154 albertel 9006:
1.655 raeburn 9007: =pod
9008:
9009: =head1 Course Catalog Routines
9010:
9011: =over 4
9012:
9013: =item * &gather_categories()
9014:
9015: Converts category definitions - keys of categories hash stored in
9016: coursecategories in configuration.db on the primary library server in a
9017: domain - to an array. Also generates javascript and idx hash used to
9018: generate Domain Coordinator interface for editing Course Categories.
9019:
9020: Inputs:
1.663 raeburn 9021:
1.655 raeburn 9022: categories (reference to hash of category definitions).
1.663 raeburn 9023:
1.655 raeburn 9024: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9025: categories and subcategories).
1.663 raeburn 9026:
1.655 raeburn 9027: idx (reference to hash of counters used in Domain Coordinator interface for
9028: editing Course Categories).
1.663 raeburn 9029:
1.655 raeburn 9030: jsarray (reference to array of categories used to create Javascript arrays for
9031: Domain Coordinator interface for editing Course Categories).
9032:
9033: Returns: nothing
9034:
9035: Side effects: populates cats, idx and jsarray.
9036:
9037: =cut
9038:
9039: sub gather_categories {
9040: my ($categories,$cats,$idx,$jsarray) = @_;
9041: my %counters;
9042: my $num = 0;
9043: foreach my $item (keys(%{$categories})) {
9044: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
9045: if ($container eq '' && $depth == 0) {
9046: $cats->[$depth][$categories->{$item}] = $cat;
9047: } else {
9048: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
9049: }
9050: my ($escitem,$tail) = split(/:/,$item,2);
9051: if ($counters{$tail} eq '') {
9052: $counters{$tail} = $num;
9053: $num ++;
9054: }
9055: if (ref($idx) eq 'HASH') {
9056: $idx->{$item} = $counters{$tail};
9057: }
9058: if (ref($jsarray) eq 'ARRAY') {
9059: push(@{$jsarray->[$counters{$tail}]},$item);
9060: }
9061: }
9062: return;
9063: }
9064:
9065: =pod
9066:
9067: =item * &extract_categories()
9068:
9069: Used to generate breadcrumb trails for course categories.
9070:
9071: Inputs:
1.663 raeburn 9072:
1.655 raeburn 9073: categories (reference to hash of category definitions).
1.663 raeburn 9074:
1.655 raeburn 9075: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9076: categories and subcategories).
1.663 raeburn 9077:
1.655 raeburn 9078: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 9079:
1.655 raeburn 9080: allitems (reference to hash - key is category key
9081: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 9082:
1.655 raeburn 9083: idx (reference to hash of counters used in Domain Coordinator interface for
9084: editing Course Categories).
1.663 raeburn 9085:
1.655 raeburn 9086: jsarray (reference to array of categories used to create Javascript arrays for
9087: Domain Coordinator interface for editing Course Categories).
9088:
1.665 raeburn 9089: subcats (reference to hash of arrays containing all subcategories within each
9090: category, -recursive)
9091:
1.655 raeburn 9092: Returns: nothing
9093:
9094: Side effects: populates trails and allitems hash references.
9095:
9096: =cut
9097:
9098: sub extract_categories {
1.665 raeburn 9099: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 9100: if (ref($categories) eq 'HASH') {
9101: &gather_categories($categories,$cats,$idx,$jsarray);
9102: if (ref($cats->[0]) eq 'ARRAY') {
9103: for (my $i=0; $i<@{$cats->[0]}; $i++) {
9104: my $name = $cats->[0][$i];
9105: my $item = &escape($name).'::0';
9106: my $trailstr;
9107: if ($name eq 'instcode') {
9108: $trailstr = &mt('Official courses (with institutional codes)');
9109: } else {
9110: $trailstr = $name;
9111: }
9112: if ($allitems->{$item} eq '') {
9113: push(@{$trails},$trailstr);
9114: $allitems->{$item} = scalar(@{$trails})-1;
9115: }
9116: my @parents = ($name);
9117: if (ref($cats->[1]{$name}) eq 'ARRAY') {
9118: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
9119: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 9120: if (ref($subcats) eq 'HASH') {
9121: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
9122: }
9123: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
9124: }
9125: } else {
9126: if (ref($subcats) eq 'HASH') {
9127: $subcats->{$item} = [];
1.655 raeburn 9128: }
9129: }
9130: }
9131: }
9132: }
9133: return;
9134: }
9135:
9136: =pod
9137:
9138: =item *&recurse_categories()
9139:
9140: Recursively used to generate breadcrumb trails for course categories.
9141:
9142: Inputs:
1.663 raeburn 9143:
1.655 raeburn 9144: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9145: categories and subcategories).
1.663 raeburn 9146:
1.655 raeburn 9147: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 9148:
9149: category (current course category, for which breadcrumb trail is being generated).
9150:
9151: trails (reference to array of breadcrumb trails for each category).
9152:
1.655 raeburn 9153: allitems (reference to hash - key is category key
9154: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 9155:
1.655 raeburn 9156: parents (array containing containers directories for current category,
9157: back to top level).
9158:
9159: Returns: nothing
9160:
9161: Side effects: populates trails and allitems hash references
9162:
9163: =cut
9164:
9165: sub recurse_categories {
1.665 raeburn 9166: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 9167: my $shallower = $depth - 1;
9168: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
9169: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
9170: my $name = $cats->[$depth]{$category}[$k];
9171: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9172: my $trailstr = join(' -> ',(@{$parents},$category));
9173: if ($allitems->{$item} eq '') {
9174: push(@{$trails},$trailstr);
9175: $allitems->{$item} = scalar(@{$trails})-1;
9176: }
9177: my $deeper = $depth+1;
9178: push(@{$parents},$category);
1.665 raeburn 9179: if (ref($subcats) eq 'HASH') {
9180: my $subcat = &escape($name).':'.$category.':'.$depth;
9181: for (my $j=@{$parents}; $j>=0; $j--) {
9182: my $higher;
9183: if ($j > 0) {
9184: $higher = &escape($parents->[$j]).':'.
9185: &escape($parents->[$j-1]).':'.$j;
9186: } else {
9187: $higher = &escape($parents->[$j]).'::'.$j;
9188: }
9189: push(@{$subcats->{$higher}},$subcat);
9190: }
9191: }
9192: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
9193: $subcats);
1.655 raeburn 9194: pop(@{$parents});
9195: }
9196: } else {
9197: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9198: my $trailstr = join(' -> ',(@{$parents},$category));
9199: if ($allitems->{$item} eq '') {
9200: push(@{$trails},$trailstr);
9201: $allitems->{$item} = scalar(@{$trails})-1;
9202: }
9203: }
9204: return;
9205: }
9206:
1.663 raeburn 9207: =pod
9208:
9209: =item *&assign_categories_table()
9210:
9211: Create a datatable for display of hierarchical categories in a domain,
9212: with checkboxes to allow a course to be categorized.
9213:
9214: Inputs:
9215:
9216: cathash - reference to hash of categories defined for the domain (from
9217: configuration.db)
9218:
9219: currcat - scalar with an & separated list of categories assigned to a course.
9220:
9221: Returns: $output (markup to be displayed)
9222:
9223: =cut
9224:
9225: sub assign_categories_table {
9226: my ($cathash,$currcat) = @_;
9227: my $output;
9228: if (ref($cathash) eq 'HASH') {
9229: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
9230: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
9231: $maxdepth = scalar(@cats);
9232: if (@cats > 0) {
9233: my $itemcount = 0;
9234: if (ref($cats[0]) eq 'ARRAY') {
9235: $output = &Apache::loncommon::start_data_table();
9236: my @currcategories;
9237: if ($currcat ne '') {
9238: @currcategories = split('&',$currcat);
9239: }
9240: for (my $i=0; $i<@{$cats[0]}; $i++) {
9241: my $parent = $cats[0][$i];
9242: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9243: next if ($parent eq 'instcode');
9244: my $item = &escape($parent).'::0';
9245: my $checked = '';
9246: if (@currcategories > 0) {
9247: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 9248: $checked = ' checked="checked"';
1.663 raeburn 9249: }
9250: }
1.675 raeburn 9251: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
9252: '<input type="checkbox" name="usecategory" value="'.
9253: $item.'"'.$checked.' />'.$parent.'</span>'.
9254: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 9255: my $depth = 1;
9256: push(@path,$parent);
9257: $output .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
9258: pop(@path);
9259: $output .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
9260: $itemcount ++;
9261: }
9262: $output .= &Apache::loncommon::end_data_table();
9263: }
9264: }
9265: }
9266: return $output;
9267: }
9268:
9269: =pod
9270:
9271: =item *&assign_category_rows()
9272:
9273: Create a datatable row for display of nested categories in a domain,
9274: with checkboxes to allow a course to be categorized,called recursively.
9275:
9276: Inputs:
9277:
9278: itemcount - track row number for alternating colors
9279:
9280: cats - reference to array of arrays/hashes which encapsulates hierarchy of
9281: categories and subcategories.
9282:
9283: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
9284:
9285: parent - parent of current category item
9286:
9287: path - Array containing all categories back up through the hierarchy from the
9288: current category to the top level.
9289:
9290: currcategories - reference to array of current categories assigned to the course
9291:
9292: Returns: $output (markup to be displayed).
9293:
9294: =cut
9295:
9296: sub assign_category_rows {
9297: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
9298: my ($text,$name,$item,$chgstr);
9299: if (ref($cats) eq 'ARRAY') {
9300: my $maxdepth = scalar(@{$cats});
9301: if (ref($cats->[$depth]) eq 'HASH') {
9302: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
9303: my $numchildren = @{$cats->[$depth]{$parent}};
9304: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9305: $text .= '<td><table class="LC_datatable">';
9306: for (my $j=0; $j<$numchildren; $j++) {
9307: $name = $cats->[$depth]{$parent}[$j];
9308: $item = &escape($name).':'.&escape($parent).':'.$depth;
9309: my $deeper = $depth+1;
9310: my $checked = '';
9311: if (ref($currcategories) eq 'ARRAY') {
9312: if (@{$currcategories} > 0) {
9313: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 9314: $checked = ' checked="checked"';
1.663 raeburn 9315: }
9316: }
9317: }
1.664 raeburn 9318: $text .= '<tr><td><span class="LC_nobreak"><label>'.
9319: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 9320: $item.'"'.$checked.' />'.$name.'</label></span>'.
9321: '<input type="hidden" name="catname" value="'.$name.'" />'.
9322: '</td><td>';
1.663 raeburn 9323: if (ref($path) eq 'ARRAY') {
9324: push(@{$path},$name);
9325: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
9326: pop(@{$path});
9327: }
9328: $text .= '</td></tr>';
9329: }
9330: $text .= '</table></td>';
9331: }
9332: }
9333: }
9334: return $text;
9335: }
9336:
1.655 raeburn 9337: ############################################################
9338: ############################################################
9339:
9340:
1.443 albertel 9341: sub commit_customrole {
1.664 raeburn 9342: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 9343: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 9344: ($start?', '.&mt('starting').' '.localtime($start):'').
9345: ($end?', ending '.localtime($end):'').': <b>'.
9346: &Apache::lonnet::assigncustomrole(
1.664 raeburn 9347: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 9348: '</b><br />';
9349: return $output;
9350: }
9351:
9352: sub commit_standardrole {
1.541 raeburn 9353: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
9354: my ($output,$logmsg,$linefeed);
9355: if ($context eq 'auto') {
9356: $linefeed = "\n";
9357: } else {
9358: $linefeed = "<br />\n";
9359: }
1.443 albertel 9360: if ($three eq 'st') {
1.541 raeburn 9361: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
9362: $one,$two,$sec,$context);
9363: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 9364: ($result eq 'unknown_course') || ($result eq 'refused')) {
9365: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 9366: } else {
1.541 raeburn 9367: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 9368: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9369: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
9370: if ($context eq 'auto') {
9371: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
9372: } else {
9373: $output .= '<b>'.$result.'</b>'.$linefeed.
9374: &mt('Add to classlist').': <b>ok</b>';
9375: }
9376: $output .= $linefeed;
1.443 albertel 9377: }
9378: } else {
9379: $output = &mt('Assigning').' '.$three.' in '.$url.
9380: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9381: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 9382: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 9383: if ($context eq 'auto') {
9384: $output .= $result.$linefeed;
9385: } else {
9386: $output .= '<b>'.$result.'</b>'.$linefeed;
9387: }
1.443 albertel 9388: }
9389: return $output;
9390: }
9391:
9392: sub commit_studentrole {
1.541 raeburn 9393: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626 raeburn 9394: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 9395: if ($context eq 'auto') {
9396: $linefeed = "\n";
9397: } else {
9398: $linefeed = '<br />'."\n";
9399: }
1.443 albertel 9400: if (defined($one) && defined($two)) {
9401: my $cid=$one.'_'.$two;
9402: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
9403: my $secchange = 0;
9404: my $expire_role_result;
9405: my $modify_section_result;
1.628 raeburn 9406: if ($oldsec ne '-1') {
9407: if ($oldsec ne $sec) {
1.443 albertel 9408: $secchange = 1;
1.628 raeburn 9409: my $now = time;
1.443 albertel 9410: my $uurl='/'.$cid;
9411: $uurl=~s/\_/\//g;
9412: if ($oldsec) {
9413: $uurl.='/'.$oldsec;
9414: }
1.626 raeburn 9415: $oldsecurl = $uurl;
1.628 raeburn 9416: $expire_role_result =
1.652 raeburn 9417: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 9418: if ($env{'request.course.sec'} ne '') {
9419: if ($expire_role_result eq 'refused') {
9420: my @roles = ('st');
9421: my @statuses = ('previous');
9422: my @roledoms = ($one);
9423: my $withsec = 1;
9424: my %roleshash =
9425: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
9426: \@statuses,\@roles,\@roledoms,$withsec);
9427: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
9428: my ($oldstart,$oldend) =
9429: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
9430: if ($oldend > 0 && $oldend <= $now) {
9431: $expire_role_result = 'ok';
9432: }
9433: }
9434: }
9435: }
1.443 albertel 9436: $result = $expire_role_result;
9437: }
9438: }
9439: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652 raeburn 9440: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443 albertel 9441: if ($modify_section_result =~ /^ok/) {
9442: if ($secchange == 1) {
1.628 raeburn 9443: if ($sec eq '') {
9444: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
9445: } else {
9446: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
9447: }
1.443 albertel 9448: } elsif ($oldsec eq '-1') {
1.628 raeburn 9449: if ($sec eq '') {
9450: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
9451: } else {
9452: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9453: }
1.443 albertel 9454: } else {
1.628 raeburn 9455: if ($sec eq '') {
9456: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
9457: } else {
9458: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9459: }
1.443 albertel 9460: }
9461: } else {
1.628 raeburn 9462: if ($secchange) {
9463: $$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;
9464: } else {
9465: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
9466: }
1.443 albertel 9467: }
9468: $result = $modify_section_result;
9469: } elsif ($secchange == 1) {
1.628 raeburn 9470: if ($oldsec eq '') {
9471: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
9472: } else {
9473: $$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;
9474: }
1.626 raeburn 9475: if ($expire_role_result eq 'refused') {
9476: my $newsecurl = '/'.$cid;
9477: $newsecurl =~ s/\_/\//g;
9478: if ($sec ne '') {
9479: $newsecurl.='/'.$sec;
9480: }
9481: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
9482: if ($sec eq '') {
9483: $$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;
9484: } else {
9485: $$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;
9486: }
9487: }
9488: }
1.443 albertel 9489: }
9490: } else {
1.626 raeburn 9491: $$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;
1.443 albertel 9492: $result = "error: incomplete course id\n";
9493: }
9494: return $result;
9495: }
9496:
9497: ############################################################
9498: ############################################################
9499:
1.566 albertel 9500: sub check_clone {
1.578 raeburn 9501: my ($args,$linefeed) = @_;
1.566 albertel 9502: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
9503: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
9504: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
9505: my $clonemsg;
9506: my $can_clone = 0;
9507:
9508: if ($clonehome eq 'no_host') {
1.578 raeburn 9509: $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'});
1.566 albertel 9510: } else {
9511: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.568 albertel 9512: if ($env{'request.role.domain'} eq $args->{'clonedomain'}) {
1.566 albertel 9513: $can_clone = 1;
9514: } else {
9515: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
9516: $args->{'clonedomain'},$args->{'clonecourse'});
9517: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 9518: if (grep(/^\*$/,@cloners)) {
9519: $can_clone = 1;
9520: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
9521: $can_clone = 1;
9522: } else {
9523: my %roleshash =
9524: &Apache::lonnet::get_my_roles($args->{'ccuname'},
9525: $args->{'ccdomain'},
9526: 'userroles',['active'],['cc'],
9527: [$args->{'clonedomain'}]);
9528: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
9529: $can_clone = 1;
9530: } else {
9531: $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'});
9532: }
1.566 albertel 9533: }
1.578 raeburn 9534: }
1.566 albertel 9535: }
9536: return ($can_clone, $clonemsg, $cloneid, $clonehome);
9537: }
9538:
1.444 albertel 9539: sub construct_course {
1.541 raeburn 9540: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context) = @_;
1.444 albertel 9541: my $outcome;
1.541 raeburn 9542: my $linefeed = '<br />'."\n";
9543: if ($context eq 'auto') {
9544: $linefeed = "\n";
9545: }
1.566 albertel 9546:
9547: #
9548: # Are we cloning?
9549: #
9550: my ($can_clone, $clonemsg, $cloneid, $clonehome);
9551: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 9552: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 9553: if ($context ne 'auto') {
1.578 raeburn 9554: if ($clonemsg ne '') {
9555: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
9556: }
1.566 albertel 9557: }
9558: $outcome .= $clonemsg.$linefeed;
9559:
9560: if (!$can_clone) {
9561: return (0,$outcome);
9562: }
9563: }
9564:
1.444 albertel 9565: #
9566: # Open course
9567: #
9568: my $crstype = lc($args->{'crstype'});
9569: my %cenv=();
9570: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
9571: $args->{'cdescr'},
9572: $args->{'curl'},
9573: $args->{'course_home'},
9574: $args->{'nonstandard'},
9575: $args->{'crscode'},
9576: $args->{'ccuname'}.':'.
9577: $args->{'ccdomain'},
9578: $args->{'crstype'});
9579:
9580: # Note: The testing routines depend on this being output; see
9581: # Utils::Course. This needs to at least be output as a comment
9582: # if anyone ever decides to not show this, and Utils::Course::new
9583: # will need to be suitably modified.
1.541 raeburn 9584: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.444 albertel 9585: #
9586: # Check if created correctly
9587: #
1.479 albertel 9588: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 9589: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.541 raeburn 9590: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 9591:
1.444 albertel 9592: #
1.566 albertel 9593: # Do the cloning
9594: #
9595: if ($can_clone && $cloneid) {
9596: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
9597: if ($context ne 'auto') {
9598: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
9599: }
9600: $outcome .= $clonemsg.$linefeed;
9601: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 9602: # Copy all files
1.637 www 9603: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 9604: # Restore URL
1.566 albertel 9605: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 9606: # Restore title
1.566 albertel 9607: $cenv{'description'}=$oldcenv{'description'};
1.444 albertel 9608: # Mark as cloned
1.566 albertel 9609: $cenv{'clonedfrom'}=$cloneid;
1.638 www 9610: # Need to clone grading mode
9611: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
9612: $cenv{'grading'}=$newenv{'grading'};
9613: # Do not clone these environment entries
9614: &Apache::lonnet::del('environment',
9615: ['default_enrollment_start_date',
9616: 'default_enrollment_end_date',
9617: 'question.email',
9618: 'policy.email',
9619: 'comment.email',
9620: 'pch.users.denied',
1.725 raeburn 9621: 'plc.users.denied',
9622: 'hidefromcat',
9623: 'categories'],
1.638 www 9624: $$crsudom,$$crsunum);
1.444 albertel 9625: }
1.566 albertel 9626:
1.444 albertel 9627: #
9628: # Set environment (will override cloned, if existing)
9629: #
9630: my @sections = ();
9631: my @xlists = ();
9632: if ($args->{'crstype'}) {
9633: $cenv{'type'}=$args->{'crstype'};
9634: }
9635: if ($args->{'crsid'}) {
9636: $cenv{'courseid'}=$args->{'crsid'};
9637: }
9638: if ($args->{'crscode'}) {
9639: $cenv{'internal.coursecode'}=$args->{'crscode'};
9640: }
9641: if ($args->{'crsquota'} ne '') {
9642: $cenv{'internal.coursequota'}=$args->{'crsquota'};
9643: } else {
9644: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
9645: }
9646: if ($args->{'ccuname'}) {
9647: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
9648: ':'.$args->{'ccdomain'};
9649: } else {
9650: $cenv{'internal.courseowner'} = $args->{'curruser'};
9651: }
9652: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
9653: if ($args->{'crssections'}) {
9654: $cenv{'internal.sectionnums'} = '';
9655: if ($args->{'crssections'} =~ m/,/) {
9656: @sections = split/,/,$args->{'crssections'};
9657: } else {
9658: $sections[0] = $args->{'crssections'};
9659: }
9660: if (@sections > 0) {
9661: foreach my $item (@sections) {
9662: my ($sec,$gp) = split/:/,$item;
9663: my $class = $args->{'crscode'}.$sec;
9664: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
9665: $cenv{'internal.sectionnums'} .= $item.',';
9666: unless ($addcheck eq 'ok') {
9667: push @badclasses, $class;
9668: }
9669: }
9670: $cenv{'internal.sectionnums'} =~ s/,$//;
9671: }
9672: }
9673: # do not hide course coordinator from staff listing,
9674: # even if privileged
9675: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9676: # add crosslistings
9677: if ($args->{'crsxlist'}) {
9678: $cenv{'internal.crosslistings'}='';
9679: if ($args->{'crsxlist'} =~ m/,/) {
9680: @xlists = split/,/,$args->{'crsxlist'};
9681: } else {
9682: $xlists[0] = $args->{'crsxlist'};
9683: }
9684: if (@xlists > 0) {
9685: foreach my $item (@xlists) {
9686: my ($xl,$gp) = split/:/,$item;
9687: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
9688: $cenv{'internal.crosslistings'} .= $item.',';
9689: unless ($addcheck eq 'ok') {
9690: push @badclasses, $xl;
9691: }
9692: }
9693: $cenv{'internal.crosslistings'} =~ s/,$//;
9694: }
9695: }
9696: if ($args->{'autoadds'}) {
9697: $cenv{'internal.autoadds'}=$args->{'autoadds'};
9698: }
9699: if ($args->{'autodrops'}) {
9700: $cenv{'internal.autodrops'}=$args->{'autodrops'};
9701: }
9702: # check for notification of enrollment changes
9703: my @notified = ();
9704: if ($args->{'notify_owner'}) {
9705: if ($args->{'ccuname'} ne '') {
9706: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
9707: }
9708: }
9709: if ($args->{'notify_dc'}) {
9710: if ($uname ne '') {
1.630 raeburn 9711: push(@notified,$uname.':'.$udom);
1.444 albertel 9712: }
9713: }
9714: if (@notified > 0) {
9715: my $notifylist;
9716: if (@notified > 1) {
9717: $notifylist = join(',',@notified);
9718: } else {
9719: $notifylist = $notified[0];
9720: }
9721: $cenv{'internal.notifylist'} = $notifylist;
9722: }
9723: if (@badclasses > 0) {
9724: my %lt=&Apache::lonlocal::texthash(
9725: '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',
9726: 'dnhr' => 'does not have rights to access enrollment in these classes',
9727: 'adby' => 'as determined by the policies of your institution on access to official classlists'
9728: );
1.541 raeburn 9729: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
9730: ' ('.$lt{'adby'}.')';
9731: if ($context eq 'auto') {
9732: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 9733: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 9734: foreach my $item (@badclasses) {
9735: if ($context eq 'auto') {
9736: $outcome .= " - $item\n";
9737: } else {
9738: $outcome .= "<li>$item</li>\n";
9739: }
9740: }
9741: if ($context eq 'auto') {
9742: $outcome .= $linefeed;
9743: } else {
1.566 albertel 9744: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 9745: }
9746: }
1.444 albertel 9747: }
9748: if ($args->{'no_end_date'}) {
9749: $args->{'endaccess'} = 0;
9750: }
9751: $cenv{'internal.autostart'}=$args->{'enrollstart'};
9752: $cenv{'internal.autoend'}=$args->{'enrollend'};
9753: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
9754: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
9755: if ($args->{'showphotos'}) {
9756: $cenv{'internal.showphotos'}=$args->{'showphotos'};
9757: }
9758: $cenv{'internal.authtype'} = $args->{'authtype'};
9759: $cenv{'internal.autharg'} = $args->{'autharg'};
9760: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
9761: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 9762: 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');
9763: if ($context eq 'auto') {
9764: $outcome .= $krb_msg;
9765: } else {
1.566 albertel 9766: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 9767: }
9768: $outcome .= $linefeed;
1.444 albertel 9769: }
9770: }
9771: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
9772: if ($args->{'setpolicy'}) {
9773: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9774: }
9775: if ($args->{'setcontent'}) {
9776: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9777: }
9778: }
9779: if ($args->{'reshome'}) {
9780: $cenv{'reshome'}=$args->{'reshome'}.'/';
9781: $cenv{'reshome'}=~s/\/+$/\//;
9782: }
9783: #
9784: # course has keyed access
9785: #
9786: if ($args->{'setkeys'}) {
9787: $cenv{'keyaccess'}='yes';
9788: }
9789: # if specified, key authority is not course, but user
9790: # only active if keyaccess is yes
9791: if ($args->{'keyauth'}) {
1.487 albertel 9792: my ($user,$domain) = split(':',$args->{'keyauth'});
9793: $user = &LONCAPA::clean_username($user);
9794: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 9795: if ($user ne '' && $domain ne '') {
1.487 albertel 9796: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 9797: }
9798: }
9799:
9800: if ($args->{'disresdis'}) {
9801: $cenv{'pch.roles.denied'}='st';
9802: }
9803: if ($args->{'disablechat'}) {
9804: $cenv{'plc.roles.denied'}='st';
9805: }
9806:
9807: # Record we've not yet viewed the Course Initialization Helper for this
9808: # course
9809: $cenv{'course.helper.not.run'} = 1;
9810: #
9811: # Use new Randomseed
9812: #
9813: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
9814: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
9815: #
9816: # The encryption code and receipt prefix for this course
9817: #
9818: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
9819: $cenv{'internal.encpref'}=100+int(9*rand(99));
9820: #
9821: # By default, use standard grading
9822: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
9823:
1.541 raeburn 9824: $outcome .= $linefeed.&mt('Setting environment').': '.
9825: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 9826: #
9827: # Open all assignments
9828: #
9829: if ($args->{'openall'}) {
9830: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
9831: my %storecontent = ($storeunder => time,
9832: $storeunder.'.type' => 'date_start');
9833:
9834: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 9835: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 9836: }
9837: #
9838: # Set first page
9839: #
9840: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
9841: || ($cloneid)) {
1.445 albertel 9842: use LONCAPA::map;
1.444 albertel 9843: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 9844:
9845: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
9846: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
9847:
1.444 albertel 9848: $outcome .= ($fatal?$errtext:'read ok').' - ';
9849: my $title; my $url;
9850: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 9851: $title=&mt('Syllabus');
1.444 albertel 9852: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
9853: } else {
1.690 bisitz 9854: $title=&mt('Navigate Contents');
1.444 albertel 9855: $url='/adm/navmaps';
9856: }
1.445 albertel 9857:
9858: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
9859: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
9860:
9861: if ($errtext) { $fatal=2; }
1.541 raeburn 9862: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 9863: }
1.566 albertel 9864:
9865: return (1,$outcome);
1.444 albertel 9866: }
9867:
9868: ############################################################
9869: ############################################################
9870:
1.378 raeburn 9871: sub course_type {
9872: my ($cid) = @_;
9873: if (!defined($cid)) {
9874: $cid = $env{'request.course.id'};
9875: }
1.404 albertel 9876: if (defined($env{'course.'.$cid.'.type'})) {
9877: return $env{'course.'.$cid.'.type'};
1.378 raeburn 9878: } else {
9879: return 'Course';
1.377 raeburn 9880: }
9881: }
1.156 albertel 9882:
1.406 raeburn 9883: sub group_term {
9884: my $crstype = &course_type();
9885: my %names = (
9886: 'Course' => 'group',
9887: 'Group' => 'team',
9888: );
9889: return $names{$crstype};
9890: }
9891:
1.156 albertel 9892: sub icon {
9893: my ($file)=@_;
1.505 albertel 9894: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 9895: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 9896: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 9897: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
9898: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
9899: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
9900: $curfext.".gif") {
9901: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
9902: $curfext.".gif";
9903: }
9904: }
1.249 albertel 9905: return &lonhttpdurl($iconname);
1.154 albertel 9906: }
1.84 albertel 9907:
1.575 albertel 9908: sub lonhttpdurl {
1.692 www 9909: #
9910: # Had been used for "small fry" static images on separate port 8080.
9911: # Modify here if lightweight http functionality desired again.
9912: # Currently eliminated due to increasing firewall issues.
9913: #
1.575 albertel 9914: my ($url)=@_;
1.692 www 9915: return $url;
1.215 albertel 9916: }
9917:
1.213 albertel 9918: sub connection_aborted {
9919: my ($r)=@_;
9920: $r->print(" ");$r->rflush();
9921: my $c = $r->connection;
9922: return $c->aborted();
9923: }
9924:
1.221 foxr 9925: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 9926: # strings as 'strings'.
9927: sub escape_single {
1.221 foxr 9928: my ($input) = @_;
1.223 albertel 9929: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 9930: $input =~ s/\'/\\\'/g; # Esacpe the 's....
9931: return $input;
9932: }
1.223 albertel 9933:
1.222 foxr 9934: # Same as escape_single, but escape's "'s This
9935: # can be used for "strings"
9936: sub escape_double {
9937: my ($input) = @_;
9938: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
9939: $input =~ s/\"/\\\"/g; # Esacpe the "s....
9940: return $input;
9941: }
1.223 albertel 9942:
1.222 foxr 9943: # Escapes the last element of a full URL.
9944: sub escape_url {
9945: my ($url) = @_;
1.238 raeburn 9946: my @urlslices = split(/\//, $url,-1);
1.369 www 9947: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 9948: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 9949: }
1.462 albertel 9950:
9951: # -------------------------------------------------------- Initliaze user login
9952: sub init_user_environment {
1.463 albertel 9953: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 9954: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
9955:
9956: my $public=($username eq 'public' && $domain eq 'public');
9957:
9958: # See if old ID present, if so, remove
9959:
9960: my ($filename,$cookie,$userroles);
9961: my $now=time;
9962:
9963: if ($public) {
9964: my $max_public=100;
9965: my $oldest;
9966: my $oldest_time=0;
9967: for(my $next=1;$next<=$max_public;$next++) {
9968: if (-e $lonids."/publicuser_$next.id") {
9969: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
9970: if ($mtime<$oldest_time || !$oldest_time) {
9971: $oldest_time=$mtime;
9972: $oldest=$next;
9973: }
9974: } else {
9975: $cookie="publicuser_$next";
9976: last;
9977: }
9978: }
9979: if (!$cookie) { $cookie="publicuser_$oldest"; }
9980: } else {
1.463 albertel 9981: # if this isn't a robot, kill any existing non-robot sessions
9982: if (!$args->{'robot'}) {
9983: opendir(DIR,$lonids);
9984: while ($filename=readdir(DIR)) {
9985: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
9986: unlink($lonids.'/'.$filename);
9987: }
1.462 albertel 9988: }
1.463 albertel 9989: closedir(DIR);
1.462 albertel 9990: }
9991: # Give them a new cookie
1.463 albertel 9992: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 9993: : $now.$$.int(rand(10000)));
1.463 albertel 9994: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 9995:
9996: # Initialize roles
9997:
9998: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
9999: }
10000: # ------------------------------------ Check browser type and MathML capability
10001:
10002: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
10003: $clientunicode,$clientos) = &decode_user_agent($r);
10004:
10005: # -------------------------------------- Any accessibility options to remember?
10006: if (($form->{'interface'}) && ($form->{'remember'} eq 'true')) {
10007: foreach my $option ('imagesuppress','appletsuppress',
10008: 'embedsuppress','fontenhance','blackwhite') {
10009: if ($form->{$option} eq 'true') {
10010: &Apache::lonnet::put('environment',{$option => 'on'},
10011: $domain,$username);
10012: } else {
10013: &Apache::lonnet::del('environment',[$option],
10014: $domain,$username);
10015: }
10016: }
10017: }
10018: # ------------------------------------------------------------- Get environment
10019:
10020: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
10021: my ($tmp) = keys(%userenv);
10022: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
10023: # default remote control to off
10024: if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
10025: } else {
10026: undef(%userenv);
10027: }
10028: if (($userenv{'interface'}) && (!$form->{'interface'})) {
10029: $form->{'interface'}=$userenv{'interface'};
10030: }
10031: $env{'environment.remote'}=$userenv{'remote'};
10032: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
10033:
10034: # --------------- Do not trust query string to be put directly into environment
10035: foreach my $option ('imagesuppress','appletsuppress',
10036: 'embedsuppress','fontenhance','blackwhite',
10037: 'interface','localpath','localres') {
10038: $form->{$option}=~s/[\n\r\=]//gs;
10039: }
10040: # --------------------------------------------------------- Write first profile
10041:
10042: {
10043: my %initial_env =
10044: ("user.name" => $username,
10045: "user.domain" => $domain,
10046: "user.home" => $authhost,
10047: "browser.type" => $clientbrowser,
10048: "browser.version" => $clientversion,
10049: "browser.mathml" => $clientmathml,
10050: "browser.unicode" => $clientunicode,
10051: "browser.os" => $clientos,
10052: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
10053: "request.course.fn" => '',
10054: "request.course.uri" => '',
10055: "request.course.sec" => '',
10056: "request.role" => 'cm',
10057: "request.role.adv" => $env{'user.adv'},
10058: "request.host" => $ENV{'REMOTE_ADDR'},);
10059:
10060: if ($form->{'localpath'}) {
10061: $initial_env{"browser.localpath"} = $form->{'localpath'};
10062: $initial_env{"browser.localres"} = $form->{'localres'};
10063: }
10064:
10065: if ($public) {
10066: $initial_env{"environment.remote"} = "off";
10067: }
10068: if ($form->{'interface'}) {
10069: $form->{'interface'}=~s/\W//gs;
10070: $initial_env{"browser.interface"} = $form->{'interface'};
10071: $env{'browser.interface'}=$form->{'interface'};
10072: foreach my $option ('imagesuppress','appletsuppress',
10073: 'embedsuppress','fontenhance','blackwhite') {
10074: if (($form->{$option} eq 'true') ||
10075: ($userenv{$option} eq 'on')) {
10076: $initial_env{"browser.$option"} = "on";
10077: }
10078: }
10079: }
10080:
1.724 raeburn 10081: foreach my $tool ('aboutme','blog','portfolio') {
10082: $userenv{'availabletools.'.$tool} =
10083: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload');
10084: }
10085:
1.765 raeburn 10086: foreach my $crstype ('official','unofficial') {
10087: $userenv{'canrequest.'.$crstype} =
10088: &Apache::lonnet::usertools_access($username,$domain,$crstype,
10089: 'reload','requestcourses');
10090: }
10091:
1.462 albertel 10092: $env{'user.environment'} = "$lonids/$cookie.id";
10093:
10094: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
10095: &GDBM_WRCREAT(),0640)) {
10096: &_add_to_env(\%disk_env,\%initial_env);
10097: &_add_to_env(\%disk_env,\%userenv,'environment.');
10098: &_add_to_env(\%disk_env,$userroles);
1.463 albertel 10099: if (ref($args->{'extra_env'})) {
10100: &_add_to_env(\%disk_env,$args->{'extra_env'});
10101: }
1.462 albertel 10102: untie(%disk_env);
10103: } else {
1.705 tempelho 10104: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
10105: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 10106: return 'error: '.$!;
10107: }
10108: }
10109: $env{'request.role'}='cm';
10110: $env{'request.role.adv'}=$env{'user.adv'};
10111: $env{'browser.type'}=$clientbrowser;
10112:
10113: return $cookie;
10114:
10115: }
10116:
10117: sub _add_to_env {
10118: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 10119: if (ref($env_data) eq 'HASH') {
10120: while (my ($key,$value) = each(%$env_data)) {
10121: $idf->{$prefix.$key} = $value;
10122: $env{$prefix.$key} = $value;
10123: }
1.462 albertel 10124: }
10125: }
10126:
1.685 tempelho 10127: # --- Get the symbolic name of a problem and the url
10128: sub get_symb {
10129: my ($request,$silent) = @_;
1.726 raeburn 10130: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 10131: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
10132: if ($symb eq '') {
10133: if (!$silent) {
10134: $request->print("Unable to handle ambiguous references:$url:.");
10135: return ();
10136: }
10137: }
10138: &Apache::lonenc::check_decrypt(\$symb);
10139: return ($symb);
10140: }
10141:
10142: # --------------------------------------------------------------Get annotation
10143:
10144: sub get_annotation {
10145: my ($symb,$enc) = @_;
10146:
10147: my $key = $symb;
10148: if (!$enc) {
10149: $key =
10150: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
10151: }
10152: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
10153: return $annotation{$key};
10154: }
10155:
10156: sub clean_symb {
1.731 raeburn 10157: my ($symb,$delete_enc) = @_;
1.685 tempelho 10158:
10159: &Apache::lonenc::check_decrypt(\$symb);
10160: my $enc = $env{'request.enc'};
1.731 raeburn 10161: if ($delete_enc) {
1.730 raeburn 10162: delete($env{'request.enc'});
10163: }
1.685 tempelho 10164:
10165: return ($symb,$enc);
10166: }
1.462 albertel 10167:
1.41 ng 10168: =pod
10169:
10170: =back
10171:
1.112 bowersj2 10172: =cut
1.41 ng 10173:
1.112 bowersj2 10174: 1;
10175: __END__;
1.41 ng 10176:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>