Annotation of loncom/interface/loncommon.pm, revision 1.753
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.753 ! droeschl 4: # $Id: loncommon.pm,v 1.750 2009/02/17 10:14:56 weissno 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');
409: <script type="text/javascript" language="Javascript" >
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";
455: <script type="text/javascript">
456: var stdeditbrowser;
457:
458: function openauthorbrowser(formname,udom) {
459: var url = '/adm/pickauthor?';
460: url += 'form='+formname+'&roledom='+udom;
461: var title = 'Author_Browser';
462: var options = 'scrollbars=1,resizable=1,menubar=0';
463: options += ',width=700,height=600';
464: stdeditbrowser = open(url,title,options,'1');
465: stdeditbrowser.focus();
466: }
467:
468: </script>
469: ENDAUTHORBRW
470: }
471:
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.538 albertel 476: <script type="text/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.219 albertel 799: $result.="<script type=\"text/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.572 banghart 926: if ($text ne "") {
1.77 www 927: $template .=
1.572 banghart 928: "<table bgcolor='#3333AA' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 929: "<td bgcolor='#5555FF'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.48 bowersj2 930: }
931:
932: # Add the graphic
1.179 matthew 933: my $title = &mt('Online Help');
1.667 raeburn 934: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.48 bowersj2 935: $template .= <<"ENDTEMPLATE";
1.436 albertel 936: <a target="_top" href="$link" title="$title"><img src="$helpicon" border="0" alt="(Help: $topic)" /></a>
1.44 bowersj2 937: ENDTEMPLATE
1.705 tempelho 938: if ($text ne '') { $template.='</td></tr></table>' };
1.44 bowersj2 939: return $template;
940:
1.106 bowersj2 941: }
942:
943: # This is a quicky function for Latex cheatsheet editing, since it
944: # appears in at least four places
945: sub helpLatexCheatsheet {
1.732 raeburn 946: my ($topic,$text,$not_author) = @_;
947: my $out;
1.106 bowersj2 948: my $addOther = '';
1.732 raeburn 949: if ($topic) {
950: $addOther = &Apache::loncommon::help_open_topic($topic,$text,
951: undef, undef, 600).
1.106 bowersj2 952: '</td><td>';
953: }
1.732 raeburn 954: $out = '<table><tr><td>'.
955: $addOther .
956: &Apache::loncommon::help_open_topic("Greek_Symbols",&mt('Greek Symbols'),
957: undef,undef,600).
958: '</td><td>'.
959: &Apache::loncommon::help_open_topic("Other_Symbols",&mt('Other Symbols'),
960: undef,undef,600).
961: '</td>';
962: unless ($not_author) {
963: $out .= '<td>'.
964: &Apache::loncommon::help_open_topic("Authoring_Output_Tags",&mt('Output Tags'),
965: undef,undef,600).
966: '</td>';
967: }
968: $out .= '</tr></table>';
969: return $out;
1.172 www 970: }
971:
1.430 albertel 972: sub general_help {
973: my $helptopic='Student_Intro';
974: if ($env{'request.role'}=~/^(ca|au)/) {
975: $helptopic='Authoring_Intro';
976: } elsif ($env{'request.role'}=~/^cc/) {
977: $helptopic='Course_Coordination_Intro';
1.672 raeburn 978: } elsif ($env{'request.role'}=~/^dc/) {
979: $helptopic='Domain_Coordination_Intro';
1.430 albertel 980: }
981: return $helptopic;
982: }
983:
984: sub update_help_link {
985: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
986: my $origurl = $ENV{'REQUEST_URI'};
987: $origurl=~s|^/~|/priv/|;
988: my $timestamp = time;
989: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
990: $$datum = &escape($$datum);
991: }
992:
993: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
994: my $output .= <<"ENDOUTPUT";
995: <script type="text/javascript">
996: banner_link = '$banner_link';
997: </script>
998: ENDOUTPUT
999: return $output;
1000: }
1001:
1002: # now just updates the help link and generates a blue icon
1.193 raeburn 1003: sub help_open_menu {
1.430 albertel 1004: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1005: = @_;
1.430 albertel 1006: $stayOnPage = 0 if (not defined $stayOnPage);
1.572 banghart 1007: # only use pop-up help (stayOnPage == 0)
1.552 banghart 1008: # if environment.remote is on (using remote control UI)
1.572 banghart 1009: if ($env{'browser.interface'} eq 'textual' ||
1010: $env{'environment.remote'} eq 'off' ) {
1.552 banghart 1011: $stayOnPage=1;
1.430 albertel 1012: }
1013: my $output;
1014: if ($component_help) {
1015: if (!$text) {
1016: $output=&help_open_topic($component_help,undef,$stayOnPage,
1017: $width,$height);
1018: } else {
1019: my $help_text;
1020: $help_text=&unescape($topic);
1021: $output='<table><tr><td>'.
1022: &help_open_topic($component_help,$help_text,$stayOnPage,
1023: $width,$height).'</td></tr></table>';
1024: }
1025: }
1026: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1027: return $output.$banner_link;
1028: }
1029:
1030: sub top_nav_help {
1031: my ($text) = @_;
1.436 albertel 1032: $text = &mt($text);
1.572 banghart 1033: my $stay_on_page =
1.436 albertel 1034: ($env{'browser.interface'} eq 'textual' ||
1035: $env{'environment.remote'} eq 'off' );
1.572 banghart 1036: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436 albertel 1037: : "javascript:helpMenu('open')";
1.572 banghart 1038: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436 albertel 1039:
1.201 raeburn 1040: my $title = &mt('Get help');
1.436 albertel 1041:
1042: return <<"END";
1043: $banner_link
1044: <a href="$link" title="$title">$text</a>
1045: END
1046: }
1047:
1048: sub help_menu_js {
1049: my ($text) = @_;
1050:
1051: my $stayOnPage =
1052: ($env{'browser.interface'} eq 'textual' ||
1053: $env{'environment.remote'} eq 'off' );
1054:
1055: my $width = 620;
1056: my $height = 600;
1.430 albertel 1057: my $helptopic=&general_help();
1058: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1059: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1060: my $start_page =
1061: &Apache::loncommon::start_page('Help Menu', undef,
1062: {'frameset' => 1,
1063: 'js_ready' => 1,
1064: 'add_entries' => {
1065: 'border' => '0',
1.579 raeburn 1066: 'rows' => "110,*",},});
1.331 albertel 1067: my $end_page =
1068: &Apache::loncommon::end_page({'frameset' => 1,
1069: 'js_ready' => 1,});
1070:
1.436 albertel 1071: my $template .= <<"ENDTEMPLATE";
1072: <script type="text/javascript">
1.253 albertel 1073: // <!-- BEGIN LON-CAPA Internal
1074: // <![CDATA[
1.430 albertel 1075: var banner_link = '';
1.243 raeburn 1076: function helpMenu(target) {
1077: var caller = this;
1078: if (target == 'open') {
1079: var newWindow = null;
1080: try {
1.262 albertel 1081: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1082: }
1083: catch(error) {
1084: writeHelp(caller);
1085: return;
1086: }
1087: if (newWindow) {
1088: caller = newWindow;
1089: }
1.193 raeburn 1090: }
1.243 raeburn 1091: writeHelp(caller);
1092: return;
1093: }
1094: function writeHelp(caller) {
1.430 albertel 1095: caller.document.writeln('$start_page<frame name="bannerframe" src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243 raeburn 1096: caller.document.close()
1097: caller.focus()
1.193 raeburn 1098: }
1.253 albertel 1099: // ]]>
1.219 albertel 1100: // END LON-CAPA Internal -->
1.436 albertel 1101: </script>
1.193 raeburn 1102: ENDTEMPLATE
1103: return $template;
1104: }
1105:
1.172 www 1106: sub help_open_bug {
1107: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1108: unless ($env{'user.adv'}) { return ''; }
1.172 www 1109: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1110: $text = "" if (not defined $text);
1111: $stayOnPage = 0 if (not defined $stayOnPage);
1.258 albertel 1112: if ($env{'browser.interface'} eq 'textual' ||
1113: $env{'environment.remote'} eq 'off' ) {
1.172 www 1114: $stayOnPage=1;
1115: }
1.184 albertel 1116: $width = 600 if (not defined $width);
1117: $height = 600 if (not defined $height);
1.172 www 1118:
1119: $topic=~s/\W+/\+/g;
1120: my $link='';
1121: my $template='';
1.379 albertel 1122: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1123: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1124: if (!$stayOnPage)
1125: {
1126: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1127: }
1128: else
1129: {
1130: $link = $url;
1131: }
1132: # Add the text
1133: if ($text ne "")
1134: {
1135: $template .=
1136: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1137: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1138: }
1139:
1140: # Add the graphic
1.179 matthew 1141: my $title = &mt('Report a Bug');
1.215 albertel 1142: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1143: $template .= <<"ENDTEMPLATE";
1.436 albertel 1144: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1145: ENDTEMPLATE
1146: if ($text ne '') { $template.='</td></tr></table>' };
1147: return $template;
1148:
1149: }
1150:
1151: sub help_open_faq {
1152: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1153: unless ($env{'user.adv'}) { return ''; }
1.172 www 1154: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1155: $text = "" if (not defined $text);
1156: $stayOnPage = 0 if (not defined $stayOnPage);
1.258 albertel 1157: if ($env{'browser.interface'} eq 'textual' ||
1158: $env{'environment.remote'} eq 'off' ) {
1.172 www 1159: $stayOnPage=1;
1160: }
1161: $width = 350 if (not defined $width);
1162: $height = 400 if (not defined $height);
1163:
1164: $topic=~s/\W+/\+/g;
1165: my $link='';
1166: my $template='';
1167: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1168: if (!$stayOnPage)
1169: {
1170: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1171: }
1172: else
1173: {
1174: $link = $url;
1175: }
1176:
1177: # Add the text
1178: if ($text ne "")
1179: {
1180: $template .=
1.173 www 1181: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1182: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1183: }
1184:
1185: # Add the graphic
1.179 matthew 1186: my $title = &mt('View the FAQ');
1.215 albertel 1187: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1188: $template .= <<"ENDTEMPLATE";
1.436 albertel 1189: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1190: ENDTEMPLATE
1191: if ($text ne '') { $template.='</td></tr></table>' };
1192: return $template;
1193:
1.44 bowersj2 1194: }
1.37 matthew 1195:
1.180 matthew 1196: ###############################################################
1197: ###############################################################
1198:
1.45 matthew 1199: =pod
1200:
1.648 raeburn 1201: =item * &change_content_javascript():
1.256 matthew 1202:
1203: This and the next function allow you to create small sections of an
1204: otherwise static HTML page that you can update on the fly with
1205: Javascript, even in Netscape 4.
1206:
1207: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1208: must be written to the HTML page once. It will prove the Javascript
1209: function "change(name, content)". Calling the change function with the
1210: name of the section
1211: you want to update, matching the name passed to C<changable_area>, and
1212: the new content you want to put in there, will put the content into
1213: that area.
1214:
1215: B<Note>: Netscape 4 only reserves enough space for the changable area
1216: to contain room for the original contents. You need to "make space"
1217: for whatever changes you wish to make, and be B<sure> to check your
1218: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1219: it's adequate for updating a one-line status display, but little more.
1220: This script will set the space to 100% width, so you only need to
1221: worry about height in Netscape 4.
1222:
1223: Modern browsers are much less limiting, and if you can commit to the
1224: user not using Netscape 4, this feature may be used freely with
1225: pretty much any HTML.
1226:
1227: =cut
1228:
1229: sub change_content_javascript {
1230: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1231: if ($env{'browser.type'} eq 'netscape' &&
1232: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1233: return (<<NETSCAPE4);
1234: function change(name, content) {
1235: doc = document.layers[name+"___escape"].layers[0].document;
1236: doc.open();
1237: doc.write(content);
1238: doc.close();
1239: }
1240: NETSCAPE4
1241: } else {
1242: # Otherwise, we need to use semi-standards-compliant code
1243: # (technically, "innerHTML" isn't standard but the equivalent
1244: # is really scary, and every useful browser supports it
1245: return (<<DOMBASED);
1246: function change(name, content) {
1247: element = document.getElementById(name);
1248: element.innerHTML = content;
1249: }
1250: DOMBASED
1251: }
1252: }
1253:
1254: =pod
1255:
1.648 raeburn 1256: =item * &changable_area($name,$origContent):
1.256 matthew 1257:
1258: This provides a "changable area" that can be modified on the fly via
1259: the Javascript code provided in C<change_content_javascript>. $name is
1260: the name you will use to reference the area later; do not repeat the
1261: same name on a given HTML page more then once. $origContent is what
1262: the area will originally contain, which can be left blank.
1263:
1264: =cut
1265:
1266: sub changable_area {
1267: my ($name, $origContent) = @_;
1268:
1.258 albertel 1269: if ($env{'browser.type'} eq 'netscape' &&
1270: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1271: # If this is netscape 4, we need to use the Layer tag
1272: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1273: } else {
1274: return "<span id='$name'>$origContent</span>";
1275: }
1276: }
1277:
1278: =pod
1279:
1.648 raeburn 1280: =item * &viewport_geometry_js
1.590 raeburn 1281:
1282: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1283:
1284: =cut
1285:
1286:
1287: sub viewport_geometry_js {
1288: return <<"GEOMETRY";
1289: var Geometry = {};
1290: function init_geometry() {
1291: if (Geometry.init) { return };
1292: Geometry.init=1;
1293: if (window.innerHeight) {
1294: Geometry.getViewportHeight = function() { return window.innerHeight; };
1295: Geometry.getViewportWidth = function() { return window.innerWidth; };
1296: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1297: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1298: }
1299: else if (document.documentElement && document.documentElement.clientHeight) {
1300: Geometry.getViewportHeight =
1301: function() { return document.documentElement.clientHeight; };
1302: Geometry.getViewportWidth =
1303: function() { return document.documentElement.clientWidth; };
1304:
1305: Geometry.getHorizontalScroll =
1306: function() { return document.documentElement.scrollLeft; };
1307: Geometry.getVerticalScroll =
1308: function() { return document.documentElement.scrollTop; };
1309: }
1310: else if (document.body.clientHeight) {
1311: Geometry.getViewportHeight =
1312: function() { return document.body.clientHeight; };
1313: Geometry.getViewportWidth =
1314: function() { return document.body.clientWidth; };
1315: Geometry.getHorizontalScroll =
1316: function() { return document.body.scrollLeft; };
1317: Geometry.getVerticalScroll =
1318: function() { return document.body.scrollTop; };
1319: }
1320: }
1321:
1322: GEOMETRY
1323: }
1324:
1325: =pod
1326:
1.648 raeburn 1327: =item * &viewport_size_js()
1.590 raeburn 1328:
1329: Provides a javascript function to set values of two form elements - width and height (elements are passed in as arguments to the javascript function) to the dimensions of the user's browser window.
1330:
1331: =cut
1332:
1333: sub viewport_size_js {
1334: my $geometry = &viewport_geometry_js();
1335: return <<"DIMS";
1336:
1337: $geometry
1338:
1339: function getViewportDims(width,height) {
1340: init_geometry();
1341: width.value = Geometry.getViewportWidth();
1342: height.value = Geometry.getViewportHeight();
1343: return;
1344: }
1345:
1346: DIMS
1347: }
1348:
1349: =pod
1350:
1.648 raeburn 1351: =item * &resize_textarea_js()
1.565 albertel 1352:
1353: emits the needed javascript to resize a textarea to be as big as possible
1354:
1355: creates a function resize_textrea that takes two IDs first should be
1356: the id of the element to resize, second should be the id of a div that
1357: surrounds everything that comes after the textarea, this routine needs
1358: to be attached to the <body> for the onload and onresize events.
1359:
1.648 raeburn 1360: =back
1.565 albertel 1361:
1362: =cut
1363:
1364: sub resize_textarea_js {
1.590 raeburn 1365: my $geometry = &viewport_geometry_js();
1.565 albertel 1366: return <<"RESIZE";
1367: <script type="text/javascript">
1.590 raeburn 1368: $geometry
1.565 albertel 1369:
1.588 albertel 1370: function getX(element) {
1371: var x = 0;
1372: while (element) {
1373: x += element.offsetLeft;
1374: element = element.offsetParent;
1375: }
1376: return x;
1377: }
1378: function getY(element) {
1379: var y = 0;
1380: while (element) {
1381: y += element.offsetTop;
1382: element = element.offsetParent;
1383: }
1384: return y;
1385: }
1386:
1387:
1.565 albertel 1388: function resize_textarea(textarea_id,bottom_id) {
1389: init_geometry();
1390: var textarea = document.getElementById(textarea_id);
1391: //alert(textarea);
1392:
1.588 albertel 1393: var textarea_top = getY(textarea);
1.565 albertel 1394: var textarea_height = textarea.offsetHeight;
1395: var bottom = document.getElementById(bottom_id);
1.588 albertel 1396: var bottom_top = getY(bottom);
1.565 albertel 1397: var bottom_height = bottom.offsetHeight;
1398: var window_height = Geometry.getViewportHeight();
1.588 albertel 1399: var fudge = 23;
1.565 albertel 1400: var new_height = window_height-fudge-textarea_top-bottom_height;
1401: if (new_height < 300) {
1402: new_height = 300;
1403: }
1404: textarea.style.height=new_height+'px';
1405: }
1406: </script>
1407: RESIZE
1408:
1409: }
1410:
1411: =pod
1412:
1.256 matthew 1413: =head1 Excel and CSV file utility routines
1414:
1415: =over 4
1416:
1417: =cut
1418:
1419: ###############################################################
1420: ###############################################################
1421:
1422: =pod
1423:
1.648 raeburn 1424: =item * &csv_translate($text)
1.37 matthew 1425:
1.185 www 1426: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1427: format.
1428:
1429: =cut
1430:
1.180 matthew 1431: ###############################################################
1432: ###############################################################
1.37 matthew 1433: sub csv_translate {
1434: my $text = shift;
1435: $text =~ s/\"/\"\"/g;
1.209 albertel 1436: $text =~ s/\n/ /g;
1.37 matthew 1437: return $text;
1438: }
1.180 matthew 1439:
1440: ###############################################################
1441: ###############################################################
1442:
1443: =pod
1444:
1.648 raeburn 1445: =item * &define_excel_formats()
1.180 matthew 1446:
1447: Define some commonly used Excel cell formats.
1448:
1449: Currently supported formats:
1450:
1451: =over 4
1452:
1453: =item header
1454:
1455: =item bold
1456:
1457: =item h1
1458:
1459: =item h2
1460:
1461: =item h3
1462:
1.256 matthew 1463: =item h4
1464:
1465: =item i
1466:
1.180 matthew 1467: =item date
1468:
1469: =back
1470:
1471: Inputs: $workbook
1472:
1473: Returns: $format, a hash reference.
1474:
1475: =cut
1476:
1477: ###############################################################
1478: ###############################################################
1479: sub define_excel_formats {
1480: my ($workbook) = @_;
1481: my $format;
1482: $format->{'header'} = $workbook->add_format(bold => 1,
1483: bottom => 1,
1484: align => 'center');
1485: $format->{'bold'} = $workbook->add_format(bold=>1);
1486: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1487: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1488: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1489: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1490: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1491: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1492: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1493: return $format;
1494: }
1495:
1496: ###############################################################
1497: ###############################################################
1.113 bowersj2 1498:
1499: =pod
1500:
1.648 raeburn 1501: =item * &create_workbook()
1.255 matthew 1502:
1503: Create an Excel worksheet. If it fails, output message on the
1504: request object and return undefs.
1505:
1506: Inputs: Apache request object
1507:
1508: Returns (undef) on failure,
1509: Excel worksheet object, scalar with filename, and formats
1510: from &Apache::loncommon::define_excel_formats on success
1511:
1512: =cut
1513:
1514: ###############################################################
1515: ###############################################################
1516: sub create_workbook {
1517: my ($r) = @_;
1518: #
1519: # Create the excel spreadsheet
1520: my $filename = '/prtspool/'.
1.258 albertel 1521: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1522: time.'_'.rand(1000000000).'.xls';
1523: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1524: if (! defined($workbook)) {
1525: $r->log_error("Error creating excel spreadsheet $filename: $!");
1526: $r->print('<p>'.&mt("Unable to create new Excel file. ".
1527: "This error has been logged. ".
1528: "Please alert your LON-CAPA administrator").
1529: '</p>');
1530: return (undef);
1531: }
1532: #
1533: $workbook->set_tempdir('/home/httpd/perl/tmp');
1534: #
1535: my $format = &Apache::loncommon::define_excel_formats($workbook);
1536: return ($workbook,$filename,$format);
1537: }
1538:
1539: ###############################################################
1540: ###############################################################
1541:
1542: =pod
1543:
1.648 raeburn 1544: =item * &create_text_file()
1.113 bowersj2 1545:
1.542 raeburn 1546: Create a file to write to and eventually make available to the user.
1.256 matthew 1547: If file creation fails, outputs an error message on the request object and
1548: return undefs.
1.113 bowersj2 1549:
1.256 matthew 1550: Inputs: Apache request object, and file suffix
1.113 bowersj2 1551:
1.256 matthew 1552: Returns (undef) on failure,
1553: Filehandle and filename on success.
1.113 bowersj2 1554:
1555: =cut
1556:
1.256 matthew 1557: ###############################################################
1558: ###############################################################
1559: sub create_text_file {
1560: my ($r,$suffix) = @_;
1561: if (! defined($suffix)) { $suffix = 'txt'; };
1562: my $fh;
1563: my $filename = '/prtspool/'.
1.258 albertel 1564: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1565: time.'_'.rand(1000000000).'.'.$suffix;
1566: $fh = Apache::File->new('>/home/httpd'.$filename);
1567: if (! defined($fh)) {
1568: $r->log_error("Couldn't open $filename for output $!");
1.683 bisitz 1569: $r->print(&mt('Problems occurred in creating the output file. '
1570: .'This error has been logged. '
1571: .'Please alert your LON-CAPA administrator.'));
1.113 bowersj2 1572: }
1.256 matthew 1573: return ($fh,$filename)
1.113 bowersj2 1574: }
1575:
1576:
1.256 matthew 1577: =pod
1.113 bowersj2 1578:
1579: =back
1580:
1581: =cut
1.37 matthew 1582:
1583: ###############################################################
1.33 matthew 1584: ## Home server <option> list generating code ##
1585: ###############################################################
1.35 matthew 1586:
1.169 www 1587: # ------------------------------------------
1588:
1589: sub domain_select {
1590: my ($name,$value,$multiple)=@_;
1591: my %domains=map {
1.514 albertel 1592: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1593: } &Apache::lonnet::all_domains();
1.169 www 1594: if ($multiple) {
1595: $domains{''}=&mt('Any domain');
1.550 albertel 1596: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1597: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1598: } else {
1.550 albertel 1599: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.169 www 1600: return &select_form($name,$value,%domains);
1601: }
1602: }
1603:
1.282 albertel 1604: #-------------------------------------------
1605:
1606: =pod
1607:
1.519 raeburn 1608: =head1 Routines for form select boxes
1609:
1610: =over 4
1611:
1.648 raeburn 1612: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1613:
1614: Returns a string containing a <select> element int multiple mode
1615:
1616:
1617: Args:
1618: $name - name of the <select> element
1.506 raeburn 1619: $value - scalar or array ref of values that should already be selected
1.282 albertel 1620: $size - number of rows long the select element is
1.283 albertel 1621: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1622: (shown text should already have been &mt())
1.506 raeburn 1623: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1624:
1.282 albertel 1625: =cut
1626:
1627: #-------------------------------------------
1.169 www 1628: sub multiple_select_form {
1.284 albertel 1629: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1630: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1631: my $output='';
1.191 matthew 1632: if (! defined($size)) {
1633: $size = 4;
1.283 albertel 1634: if (scalar(keys(%$hash))<4) {
1635: $size = scalar(keys(%$hash));
1.191 matthew 1636: }
1637: }
1.734 bisitz 1638: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 1639: my @order;
1.506 raeburn 1640: if (ref($order) eq 'ARRAY') {
1641: @order = @{$order};
1642: } else {
1643: @order = sort(keys(%$hash));
1.501 banghart 1644: }
1645: if (exists($$hash{'select_form_order'})) {
1646: @order = @{$$hash{'select_form_order'}};
1647: }
1648:
1.284 albertel 1649: foreach my $key (@order) {
1.356 albertel 1650: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1651: $output.='selected="selected" ' if ($selected{$key});
1652: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1653: }
1654: $output.="</select>\n";
1655: return $output;
1656: }
1657:
1.88 www 1658: #-------------------------------------------
1659:
1660: =pod
1661:
1.648 raeburn 1662: =item * &select_form($defdom,$name,%hash)
1.88 www 1663:
1664: Returns a string containing a <select name='$name' size='1'> form to
1665: allow a user to select options from a hash option_name => displayed text.
1666: See lonrights.pm for an example invocation and use.
1667:
1668: =cut
1669:
1670: #-------------------------------------------
1671: sub select_form {
1672: my ($def,$name,%hash) = @_;
1673: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1.128 albertel 1674: my @keys;
1675: if (exists($hash{'select_form_order'})) {
1676: @keys=@{$hash{'select_form_order'}};
1677: } else {
1678: @keys=sort(keys(%hash));
1679: }
1.356 albertel 1680: foreach my $key (@keys) {
1681: $selectform.=
1682: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
1683: ($key eq $def ? 'selected="selected" ' : '').
1684: ">".&mt($hash{$key})."</option>\n";
1.88 www 1685: }
1686: $selectform.="</select>";
1687: return $selectform;
1688: }
1689:
1.475 www 1690: # For display filters
1691:
1692: sub display_filter {
1693: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 1694: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.714 bisitz 1695: return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1.475 www 1696: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
1697: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 1698: '</label></span> <span class="LC_nobreak">'.
1.475 www 1699: &mt('Filter [_1]',
1.477 www 1700: &select_form($env{'form.displayfilter'},
1701: 'displayfilter',
1702: ('currentfolder' => 'Current folder/page',
1703: 'containing' => 'Containing phrase',
1704: 'none' => 'None'))).
1.714 bisitz 1705: '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1.475 www 1706: }
1707:
1.167 www 1708: sub gradeleveldescription {
1709: my $gradelevel=shift;
1710: my %gradelevels=(0 => 'Not specified',
1711: 1 => 'Grade 1',
1712: 2 => 'Grade 2',
1713: 3 => 'Grade 3',
1714: 4 => 'Grade 4',
1715: 5 => 'Grade 5',
1716: 6 => 'Grade 6',
1717: 7 => 'Grade 7',
1718: 8 => 'Grade 8',
1719: 9 => 'Grade 9',
1720: 10 => 'Grade 10',
1721: 11 => 'Grade 11',
1722: 12 => 'Grade 12',
1723: 13 => 'Grade 13',
1724: 14 => '100 Level',
1725: 15 => '200 Level',
1726: 16 => '300 Level',
1727: 17 => '400 Level',
1728: 18 => 'Graduate Level');
1729: return &mt($gradelevels{$gradelevel});
1730: }
1731:
1.163 www 1732: sub select_level_form {
1733: my ($deflevel,$name)=@_;
1734: unless ($deflevel) { $deflevel=0; }
1.167 www 1735: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1736: for (my $i=0; $i<=18; $i++) {
1737: $selectform.="<option value=\"$i\" ".
1.253 albertel 1738: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 1739: ">".&gradeleveldescription($i)."</option>\n";
1740: }
1741: $selectform.="</select>";
1742: return $selectform;
1.163 www 1743: }
1.167 www 1744:
1.35 matthew 1745: #-------------------------------------------
1746:
1.45 matthew 1747: =pod
1748:
1.743 raeburn 1749: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$autosubmit)
1.35 matthew 1750:
1751: Returns a string containing a <select name='$name' size='1'> form to
1752: allow a user to select the domain to preform an operation in.
1753: See loncreateuser.pm for an example invocation and use.
1754:
1.90 www 1755: If the $includeempty flag is set, it also includes an empty choice ("no domain
1756: selected");
1757:
1.743 raeburn 1758: If the $showdomdesc flag is set, the domain name is followed by the domain description.
1759:
1760: If the $autosubmit flag is set, the form containing the domain selector will be auto-submitted by an onchange action.
1.563 raeburn 1761:
1.35 matthew 1762: =cut
1763:
1764: #-------------------------------------------
1.34 matthew 1765: sub select_dom_form {
1.743 raeburn 1766: my ($defdom,$name,$includeempty,$showdomdesc,$autosubmit) = @_;
1767: my $onchange;
1768: if ($autosubmit) {
1769: $onchange = ' onchange="this.form.submit()"';
1770: }
1.550 albertel 1771: my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1.90 www 1772: if ($includeempty) { @domains=('',@domains); }
1.743 raeburn 1773: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 1774: foreach my $dom (@domains) {
1775: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 1776: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
1777: if ($showdomdesc) {
1778: if ($dom ne '') {
1779: my $domdesc = &Apache::lonnet::domain($dom,'description');
1780: if ($domdesc ne '') {
1781: $selectdomain .= ' ('.$domdesc.')';
1782: }
1783: }
1784: }
1785: $selectdomain .= "</option>\n";
1.34 matthew 1786: }
1787: $selectdomain.="</select>";
1788: return $selectdomain;
1789: }
1790:
1.35 matthew 1791: #-------------------------------------------
1792:
1.45 matthew 1793: =pod
1794:
1.648 raeburn 1795: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 1796:
1.586 raeburn 1797: input: 4 arguments (two required, two optional) -
1798: $domain - domain of new user
1799: $name - name of form element
1800: $default - Value of 'default' causes a default item to be first
1801: option, and selected by default.
1802: $hide - Value of 'hide' causes hiding of the name of the server,
1803: if 1 server found, or default, if 0 found.
1.594 raeburn 1804: output: returns 2 items:
1.586 raeburn 1805: (a) form element which contains either:
1806: (i) <select name="$name">
1807: <option value="$hostid1">$hostid $servers{$hostid}</option>
1808: <option value="$hostid2">$hostid $servers{$hostid}</option>
1809: </select>
1810: form item if there are multiple library servers in $domain, or
1811: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
1812: if there is only one library server in $domain.
1813:
1814: (b) number of library servers found.
1815:
1816: See loncreateuser.pm for example of use.
1.35 matthew 1817:
1818: =cut
1819:
1820: #-------------------------------------------
1.586 raeburn 1821: sub home_server_form_item {
1822: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 1823: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 1824: my $result;
1825: my $numlib = keys(%servers);
1826: if ($numlib > 1) {
1827: $result .= '<select name="'.$name.'" />'."\n";
1828: if ($default) {
1829: $result .= '<option value="default" selected>'.&mt('default').
1830: '</option>'."\n";
1831: }
1832: foreach my $hostid (sort(keys(%servers))) {
1833: $result.= '<option value="'.$hostid.'">'.
1834: $hostid.' '.$servers{$hostid}."</option>\n";
1835: }
1836: $result .= '</select>'."\n";
1837: } elsif ($numlib == 1) {
1838: my $hostid;
1839: foreach my $item (keys(%servers)) {
1840: $hostid = $item;
1841: }
1842: $result .= '<input type="hidden" name="'.$name.'" value="'.
1843: $hostid.'" />';
1844: if (!$hide) {
1845: $result .= $hostid.' '.$servers{$hostid};
1846: }
1847: $result .= "\n";
1848: } elsif ($default) {
1849: $result .= '<input type="hidden" name="'.$name.
1850: '" value="default" />';
1851: if (!$hide) {
1852: $result .= &mt('default');
1853: }
1854: $result .= "\n";
1.33 matthew 1855: }
1.586 raeburn 1856: return ($result,$numlib);
1.33 matthew 1857: }
1.112 bowersj2 1858:
1859: =pod
1860:
1.534 albertel 1861: =back
1862:
1.112 bowersj2 1863: =cut
1.87 matthew 1864:
1865: ###############################################################
1.112 bowersj2 1866: ## Decoding User Agent ##
1.87 matthew 1867: ###############################################################
1868:
1869: =pod
1870:
1.112 bowersj2 1871: =head1 Decoding the User Agent
1872:
1873: =over 4
1874:
1875: =item * &decode_user_agent()
1.87 matthew 1876:
1877: Inputs: $r
1878:
1879: Outputs:
1880:
1881: =over 4
1882:
1.112 bowersj2 1883: =item * $httpbrowser
1.87 matthew 1884:
1.112 bowersj2 1885: =item * $clientbrowser
1.87 matthew 1886:
1.112 bowersj2 1887: =item * $clientversion
1.87 matthew 1888:
1.112 bowersj2 1889: =item * $clientmathml
1.87 matthew 1890:
1.112 bowersj2 1891: =item * $clientunicode
1.87 matthew 1892:
1.112 bowersj2 1893: =item * $clientos
1.87 matthew 1894:
1895: =back
1896:
1.157 matthew 1897: =back
1898:
1.87 matthew 1899: =cut
1900:
1901: ###############################################################
1902: ###############################################################
1903: sub decode_user_agent {
1.247 albertel 1904: my ($r)=@_;
1.87 matthew 1905: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
1906: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
1907: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 1908: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 1909: my $clientbrowser='unknown';
1910: my $clientversion='0';
1911: my $clientmathml='';
1912: my $clientunicode='0';
1913: for (my $i=0;$i<=$#browsertype;$i++) {
1914: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
1915: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
1916: $clientbrowser=$bname;
1917: $httpbrowser=~/$vreg/i;
1918: $clientversion=$1;
1919: $clientmathml=($clientversion>=$minv);
1920: $clientunicode=($clientversion>=$univ);
1921: }
1922: }
1923: my $clientos='unknown';
1924: if (($httpbrowser=~/linux/i) ||
1925: ($httpbrowser=~/unix/i) ||
1926: ($httpbrowser=~/ux/i) ||
1927: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
1928: if (($httpbrowser=~/vax/i) ||
1929: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
1930: if ($httpbrowser=~/next/i) { $clientos='next'; }
1931: if (($httpbrowser=~/mac/i) ||
1932: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1933: if ($httpbrowser=~/win/i) { $clientos='win'; }
1934: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1935: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1936: $clientunicode,$clientos,);
1937: }
1938:
1.32 matthew 1939: ###############################################################
1940: ## Authentication changing form generation subroutines ##
1941: ###############################################################
1942: ##
1943: ## All of the authform_xxxxxxx subroutines take their inputs in a
1944: ## hash, and have reasonable default values.
1945: ##
1946: ## formname = the name given in the <form> tag.
1.35 matthew 1947: #-------------------------------------------
1948:
1.45 matthew 1949: =pod
1950:
1.112 bowersj2 1951: =head1 Authentication Routines
1952:
1953: =over 4
1954:
1.648 raeburn 1955: =item * &authform_xxxxxx()
1.35 matthew 1956:
1957: The authform_xxxxxx subroutines provide javascript and html forms which
1958: handle some of the conveniences required for authentication forms.
1959: This is not an optimal method, but it works.
1960:
1961: =over 4
1962:
1.112 bowersj2 1963: =item * authform_header
1.35 matthew 1964:
1.112 bowersj2 1965: =item * authform_authorwarning
1.35 matthew 1966:
1.112 bowersj2 1967: =item * authform_nochange
1.35 matthew 1968:
1.112 bowersj2 1969: =item * authform_kerberos
1.35 matthew 1970:
1.112 bowersj2 1971: =item * authform_internal
1.35 matthew 1972:
1.112 bowersj2 1973: =item * authform_filesystem
1.35 matthew 1974:
1975: =back
1976:
1.648 raeburn 1977: See loncreateuser.pm for invocation and use examples.
1.157 matthew 1978:
1.35 matthew 1979: =cut
1980:
1981: #-------------------------------------------
1.32 matthew 1982: sub authform_header{
1983: my %in = (
1984: formname => 'cu',
1.80 albertel 1985: kerb_def_dom => '',
1.32 matthew 1986: @_,
1987: );
1988: $in{'formname'} = 'document.' . $in{'formname'};
1989: my $result='';
1.80 albertel 1990:
1991: #---------------------------------------------- Code for upper case translation
1992: my $Javascript_toUpperCase;
1993: unless ($in{kerb_def_dom}) {
1994: $Javascript_toUpperCase =<<"END";
1995: switch (choice) {
1996: case 'krb': currentform.elements[choicearg].value =
1997: currentform.elements[choicearg].value.toUpperCase();
1998: break;
1999: default:
2000: }
2001: END
2002: } else {
2003: $Javascript_toUpperCase = "";
2004: }
2005:
1.165 raeburn 2006: my $radioval = "'nochange'";
1.591 raeburn 2007: if (defined($in{'curr_authtype'})) {
2008: if ($in{'curr_authtype'} ne '') {
2009: $radioval = "'".$in{'curr_authtype'}."arg'";
2010: }
1.174 matthew 2011: }
1.165 raeburn 2012: my $argfield = 'null';
1.591 raeburn 2013: if (defined($in{'mode'})) {
1.165 raeburn 2014: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2015: if (defined($in{'curr_autharg'})) {
2016: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2017: $argfield = "'$in{'curr_autharg'}'";
2018: }
2019: }
2020: }
2021: }
2022:
1.32 matthew 2023: $result.=<<"END";
2024: var current = new Object();
1.165 raeburn 2025: current.radiovalue = $radioval;
2026: current.argfield = $argfield;
1.32 matthew 2027:
2028: function changed_radio(choice,currentform) {
2029: var choicearg = choice + 'arg';
2030: // If a radio button in changed, we need to change the argfield
2031: if (current.radiovalue != choice) {
2032: current.radiovalue = choice;
2033: if (current.argfield != null) {
2034: currentform.elements[current.argfield].value = '';
2035: }
2036: if (choice == 'nochange') {
2037: current.argfield = null;
2038: } else {
2039: current.argfield = choicearg;
2040: switch(choice) {
2041: case 'krb':
2042: currentform.elements[current.argfield].value =
2043: "$in{'kerb_def_dom'}";
2044: break;
2045: default:
2046: break;
2047: }
2048: }
2049: }
2050: return;
2051: }
1.22 www 2052:
1.32 matthew 2053: function changed_text(choice,currentform) {
2054: var choicearg = choice + 'arg';
2055: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2056: $Javascript_toUpperCase
1.32 matthew 2057: // clear old field
2058: if ((current.argfield != choicearg) && (current.argfield != null)) {
2059: currentform.elements[current.argfield].value = '';
2060: }
2061: current.argfield = choicearg;
2062: }
2063: set_auth_radio_buttons(choice,currentform);
2064: return;
1.20 www 2065: }
1.32 matthew 2066:
2067: function set_auth_radio_buttons(newvalue,currentform) {
2068: var i=0;
2069: while (i < currentform.login.length) {
2070: if (currentform.login[i].value == newvalue) { break; }
2071: i++;
2072: }
2073: if (i == currentform.login.length) {
2074: return;
2075: }
2076: current.radiovalue = newvalue;
2077: currentform.login[i].checked = true;
2078: return;
2079: }
2080: END
2081: return $result;
2082: }
2083:
2084: sub authform_authorwarning{
2085: my $result='';
1.144 matthew 2086: $result='<i>'.
2087: &mt('As a general rule, only authors or co-authors should be '.
2088: 'filesystem authenticated '.
2089: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2090: return $result;
2091: }
2092:
2093: sub authform_nochange{
2094: my %in = (
2095: formname => 'document.cu',
2096: kerb_def_dom => 'MSU.EDU',
2097: @_,
2098: );
1.586 raeburn 2099: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2100: my $result;
2101: if (keys(%can_assign) == 0) {
2102: $result = &mt('Under you current role you are not permitted to change login settings for this user');
2103: } else {
2104: $result = '<label>'.&mt('[_1] Do not change login data',
2105: '<input type="radio" name="login" value="nochange" '.
2106: 'checked="checked" onclick="'.
1.281 albertel 2107: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2108: '</label>';
1.586 raeburn 2109: }
1.32 matthew 2110: return $result;
2111: }
2112:
1.591 raeburn 2113: sub authform_kerberos {
1.32 matthew 2114: my %in = (
2115: formname => 'document.cu',
2116: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2117: kerb_def_auth => 'krb4',
1.32 matthew 2118: @_,
2119: );
1.586 raeburn 2120: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2121: $autharg,$jscall);
2122: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2123: if ($in{'kerb_def_auth'} eq 'krb5') {
1.586 raeburn 2124: $check5 = ' checked="on"';
1.80 albertel 2125: } else {
1.586 raeburn 2126: $check4 = ' checked="on"';
1.80 albertel 2127: }
1.165 raeburn 2128: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2129: if (defined($in{'curr_authtype'})) {
2130: if ($in{'curr_authtype'} eq 'krb') {
1.586 raeburn 2131: $krbcheck = ' checked="on"';
1.623 raeburn 2132: if (defined($in{'mode'})) {
2133: if ($in{'mode'} eq 'modifyuser') {
2134: $krbcheck = '';
2135: }
2136: }
1.591 raeburn 2137: if (defined($in{'curr_kerb_ver'})) {
2138: if ($in{'curr_krb_ver'} eq '5') {
2139: $check5 = ' checked="on"';
2140: $check4 = '';
2141: } else {
2142: $check4 = ' checked="on"';
2143: $check5 = '';
2144: }
1.586 raeburn 2145: }
1.591 raeburn 2146: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2147: $krbarg = $in{'curr_autharg'};
2148: }
1.586 raeburn 2149: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2150: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2151: $result =
2152: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2153: $in{'curr_autharg'},$krbver);
2154: } else {
2155: $result =
2156: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2157: }
2158: return $result;
2159: }
2160: }
2161: } else {
2162: if ($authnum == 1) {
2163: $authtype = '<input type="hidden" name="login" value="krb">';
1.165 raeburn 2164: }
2165: }
1.586 raeburn 2166: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2167: return;
1.587 raeburn 2168: } elsif ($authtype eq '') {
1.591 raeburn 2169: if (defined($in{'mode'})) {
1.587 raeburn 2170: if ($in{'mode'} eq 'modifycourse') {
2171: if ($authnum == 1) {
2172: $authtype = '<input type="hidden" name="login" value="krb">';
2173: }
2174: }
2175: }
1.586 raeburn 2176: }
2177: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2178: if ($authtype eq '') {
2179: $authtype = '<input type="radio" name="login" value="krb" '.
2180: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2181: $krbcheck.' />';
2182: }
2183: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
2184: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
2185: $in{'curr_authtype'} eq 'krb5') ||
2186: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
2187: $in{'curr_authtype'} eq 'krb4')) {
2188: $result .= &mt
1.144 matthew 2189: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2190: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2191: '<label>'.$authtype,
1.281 albertel 2192: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2193: 'value="'.$krbarg.'" '.
1.144 matthew 2194: 'onchange="'.$jscall.'" />',
1.281 albertel 2195: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2196: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2197: '</label>');
1.586 raeburn 2198: } elsif ($can_assign{'krb4'}) {
2199: $result .= &mt
2200: ('[_1] Kerberos authenticated with domain [_2] '.
2201: '[_3] Version 4 [_4]',
2202: '<label>'.$authtype,
2203: '</label><input type="text" size="10" name="krbarg" '.
2204: 'value="'.$krbarg.'" '.
2205: 'onchange="'.$jscall.'" />',
2206: '<label><input type="hidden" name="krbver" value="4" />',
2207: '</label>');
2208: } elsif ($can_assign{'krb5'}) {
2209: $result .= &mt
2210: ('[_1] Kerberos authenticated with domain [_2] '.
2211: '[_3] Version 5 [_4]',
2212: '<label>'.$authtype,
2213: '</label><input type="text" size="10" name="krbarg" '.
2214: 'value="'.$krbarg.'" '.
2215: 'onchange="'.$jscall.'" />',
2216: '<label><input type="hidden" name="krbver" value="5" />',
2217: '</label>');
2218: }
1.32 matthew 2219: return $result;
2220: }
2221:
2222: sub authform_internal{
1.586 raeburn 2223: my %in = (
1.32 matthew 2224: formname => 'document.cu',
2225: kerb_def_dom => 'MSU.EDU',
2226: @_,
2227: );
1.586 raeburn 2228: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
2229: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2230: if (defined($in{'curr_authtype'})) {
2231: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2232: if ($can_assign{'int'}) {
2233: $intcheck = 'checked="on" ';
1.623 raeburn 2234: if (defined($in{'mode'})) {
2235: if ($in{'mode'} eq 'modifyuser') {
2236: $intcheck = '';
2237: }
2238: }
1.591 raeburn 2239: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2240: $intarg = $in{'curr_autharg'};
2241: }
2242: } else {
2243: $result = &mt('Currently internally authenticated.');
2244: return $result;
1.165 raeburn 2245: }
2246: }
1.586 raeburn 2247: } else {
2248: if ($authnum == 1) {
2249: $authtype = '<input type="hidden" name="login" value="int">';
2250: }
2251: }
2252: if (!$can_assign{'int'}) {
2253: return;
1.587 raeburn 2254: } elsif ($authtype eq '') {
1.591 raeburn 2255: if (defined($in{'mode'})) {
1.587 raeburn 2256: if ($in{'mode'} eq 'modifycourse') {
2257: if ($authnum == 1) {
2258: $authtype = '<input type="hidden" name="login" value="int">';
2259: }
2260: }
2261: }
1.165 raeburn 2262: }
1.586 raeburn 2263: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2264: if ($authtype eq '') {
2265: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2266: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2267: }
1.605 bisitz 2268: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2269: $intarg.'" onchange="'.$jscall.'" />';
2270: $result = &mt
1.144 matthew 2271: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2272: '<label>'.$authtype,'</label>'.$autharg);
1.620 www 2273: $result.="<label><input type=\"checkbox\" name=\"visible\" onClick='if (this.checked) { this.form.intarg.type=\"text\" } else { this.form.intarg.type=\"password\" }' />".&mt('Visible input').'</label>';
1.32 matthew 2274: return $result;
2275: }
2276:
2277: sub authform_local{
2278: my %in = (
2279: formname => 'document.cu',
2280: kerb_def_dom => 'MSU.EDU',
2281: @_,
2282: );
1.586 raeburn 2283: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
2284: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2285: if (defined($in{'curr_authtype'})) {
2286: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2287: if ($can_assign{'loc'}) {
2288: $loccheck = 'checked="on" ';
1.623 raeburn 2289: if (defined($in{'mode'})) {
2290: if ($in{'mode'} eq 'modifyuser') {
2291: $loccheck = '';
2292: }
2293: }
1.591 raeburn 2294: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2295: $locarg = $in{'curr_autharg'};
2296: }
2297: } else {
2298: $result = &mt('Currently using local (institutional) authentication.');
2299: return $result;
1.165 raeburn 2300: }
2301: }
1.586 raeburn 2302: } else {
2303: if ($authnum == 1) {
2304: $authtype = '<input type="hidden" name="login" value="loc">';
2305: }
2306: }
2307: if (!$can_assign{'loc'}) {
2308: return;
1.587 raeburn 2309: } elsif ($authtype eq '') {
1.591 raeburn 2310: if (defined($in{'mode'})) {
1.587 raeburn 2311: if ($in{'mode'} eq 'modifycourse') {
2312: if ($authnum == 1) {
2313: $authtype = '<input type="hidden" name="login" value="loc">';
2314: }
2315: }
2316: }
1.165 raeburn 2317: }
1.586 raeburn 2318: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2319: if ($authtype eq '') {
2320: $authtype = '<input type="radio" name="login" value="loc" '.
2321: $loccheck.' onchange="'.$jscall.'" onclick="'.
2322: $jscall.'" />';
2323: }
2324: $autharg = '<input type="text" size="10" name="locarg" value="'.
2325: $locarg.'" onchange="'.$jscall.'" />';
2326: $result = &mt('[_1] Local Authentication with argument [_2]',
2327: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2328: return $result;
2329: }
2330:
2331: sub authform_filesystem{
2332: my %in = (
2333: formname => 'document.cu',
2334: kerb_def_dom => 'MSU.EDU',
2335: @_,
2336: );
1.586 raeburn 2337: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
2338: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2339: if (defined($in{'curr_authtype'})) {
2340: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2341: if ($can_assign{'fsys'}) {
2342: $fsyscheck = 'checked="on" ';
1.623 raeburn 2343: if (defined($in{'mode'})) {
2344: if ($in{'mode'} eq 'modifyuser') {
2345: $fsyscheck = '';
2346: }
2347: }
1.586 raeburn 2348: } else {
2349: $result = &mt('Currently Filesystem Authenticated.');
2350: return $result;
2351: }
2352: }
2353: } else {
2354: if ($authnum == 1) {
2355: $authtype = '<input type="hidden" name="login" value="fsys">';
2356: }
2357: }
2358: if (!$can_assign{'fsys'}) {
2359: return;
1.587 raeburn 2360: } elsif ($authtype eq '') {
1.591 raeburn 2361: if (defined($in{'mode'})) {
1.587 raeburn 2362: if ($in{'mode'} eq 'modifycourse') {
2363: if ($authnum == 1) {
2364: $authtype = '<input type="hidden" name="login" value="fsys">';
2365: }
2366: }
2367: }
1.586 raeburn 2368: }
2369: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2370: if ($authtype eq '') {
2371: $authtype = '<input type="radio" name="login" value="fsys" '.
2372: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2373: $jscall.'" />';
2374: }
2375: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2376: ' onchange="'.$jscall.'" />';
2377: $result = &mt
1.144 matthew 2378: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2379: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2380: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2381: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2382: 'onchange="'.$jscall.'" />');
1.32 matthew 2383: return $result;
2384: }
2385:
1.586 raeburn 2386: sub get_assignable_auth {
2387: my ($dom) = @_;
2388: if ($dom eq '') {
2389: $dom = $env{'request.role.domain'};
2390: }
2391: my %can_assign = (
2392: krb4 => 1,
2393: krb5 => 1,
2394: int => 1,
2395: loc => 1,
2396: );
2397: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2398: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2399: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2400: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2401: my $context;
2402: if ($env{'request.role'} =~ /^au/) {
2403: $context = 'author';
2404: } elsif ($env{'request.role'} =~ /^dc/) {
2405: $context = 'domain';
2406: } elsif ($env{'request.course.id'}) {
2407: $context = 'course';
2408: }
2409: if ($context) {
2410: if (ref($authhash->{$context}) eq 'HASH') {
2411: %can_assign = %{$authhash->{$context}};
2412: }
2413: }
2414: }
2415: }
2416: my $authnum = 0;
2417: foreach my $key (keys(%can_assign)) {
2418: if ($can_assign{$key}) {
2419: $authnum ++;
2420: }
2421: }
2422: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2423: $authnum --;
2424: }
2425: return ($authnum,%can_assign);
2426: }
2427:
1.80 albertel 2428: ###############################################################
2429: ## Get Kerberos Defaults for Domain ##
2430: ###############################################################
2431: ##
2432: ## Returns default kerberos version and an associated argument
2433: ## as listed in file domain.tab. If not listed, provides
2434: ## appropriate default domain and kerberos version.
2435: ##
2436: #-------------------------------------------
2437:
2438: =pod
2439:
1.648 raeburn 2440: =item * &get_kerberos_defaults()
1.80 albertel 2441:
2442: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2443: version and domain. If not found, it defaults to version 4 and the
2444: domain of the server.
1.80 albertel 2445:
1.648 raeburn 2446: =over 4
2447:
1.80 albertel 2448: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2449:
1.648 raeburn 2450: =back
2451:
2452: =back
2453:
1.80 albertel 2454: =cut
2455:
2456: #-------------------------------------------
2457: sub get_kerberos_defaults {
2458: my $domain=shift;
1.641 raeburn 2459: my ($krbdef,$krbdefdom);
2460: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2461: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2462: $krbdef = $domdefaults{'auth_def'};
2463: $krbdefdom = $domdefaults{'auth_arg_def'};
2464: } else {
1.80 albertel 2465: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2466: my $krbdefdom=$1;
2467: $krbdefdom=~tr/a-z/A-Z/;
2468: $krbdef = "krb4";
2469: }
2470: return ($krbdef,$krbdefdom);
2471: }
1.112 bowersj2 2472:
1.32 matthew 2473:
1.46 matthew 2474: ###############################################################
2475: ## Thesaurus Functions ##
2476: ###############################################################
1.20 www 2477:
1.46 matthew 2478: =pod
1.20 www 2479:
1.112 bowersj2 2480: =head1 Thesaurus Functions
2481:
2482: =over 4
2483:
1.648 raeburn 2484: =item * &initialize_keywords()
1.46 matthew 2485:
2486: Initializes the package variable %Keywords if it is empty. Uses the
2487: package variable $thesaurus_db_file.
2488:
2489: =cut
2490:
2491: ###################################################
2492:
2493: sub initialize_keywords {
2494: return 1 if (scalar keys(%Keywords));
2495: # If we are here, %Keywords is empty, so fill it up
2496: # Make sure the file we need exists...
2497: if (! -e $thesaurus_db_file) {
2498: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2499: " failed because it does not exist");
2500: return 0;
2501: }
2502: # Set up the hash as a database
2503: my %thesaurus_db;
2504: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2505: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2506: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2507: $thesaurus_db_file);
2508: return 0;
2509: }
2510: # Get the average number of appearances of a word.
2511: my $avecount = $thesaurus_db{'average.count'};
2512: # Put keywords (those that appear > average) into %Keywords
2513: while (my ($word,$data)=each (%thesaurus_db)) {
2514: my ($count,undef) = split /:/,$data;
2515: $Keywords{$word}++ if ($count > $avecount);
2516: }
2517: untie %thesaurus_db;
2518: # Remove special values from %Keywords.
1.356 albertel 2519: foreach my $value ('total.count','average.count') {
2520: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2521: }
1.46 matthew 2522: return 1;
2523: }
2524:
2525: ###################################################
2526:
2527: =pod
2528:
1.648 raeburn 2529: =item * &keyword($word)
1.46 matthew 2530:
2531: Returns true if $word is a keyword. A keyword is a word that appears more
2532: than the average number of times in the thesaurus database. Calls
2533: &initialize_keywords
2534:
2535: =cut
2536:
2537: ###################################################
1.20 www 2538:
2539: sub keyword {
1.46 matthew 2540: return if (!&initialize_keywords());
2541: my $word=lc(shift());
2542: $word=~s/\W//g;
2543: return exists($Keywords{$word});
1.20 www 2544: }
1.46 matthew 2545:
2546: ###############################################################
2547:
2548: =pod
1.20 www 2549:
1.648 raeburn 2550: =item * &get_related_words()
1.46 matthew 2551:
1.160 matthew 2552: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 2553: an array of words. If the keyword is not in the thesaurus, an empty array
2554: will be returned. The order of the words returned is determined by the
2555: database which holds them.
2556:
2557: Uses global $thesaurus_db_file.
2558:
2559: =cut
2560:
2561: ###############################################################
2562: sub get_related_words {
2563: my $keyword = shift;
2564: my %thesaurus_db;
2565: if (! -e $thesaurus_db_file) {
2566: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
2567: "failed because the file does not exist");
2568: return ();
2569: }
2570: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2571: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2572: return ();
2573: }
2574: my @Words=();
1.429 www 2575: my $count=0;
1.46 matthew 2576: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 2577: # The first element is the number of times
2578: # the word appears. We do not need it now.
1.429 www 2579: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
2580: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
2581: my $threshold=$mostfrequentcount/10;
2582: foreach my $possibleword (@RelatedWords) {
2583: my ($word,$wordcount)=split(/\,/,$possibleword);
2584: if ($wordcount>$threshold) {
2585: push(@Words,$word);
2586: $count++;
2587: if ($count>10) { last; }
2588: }
1.20 www 2589: }
2590: }
1.46 matthew 2591: untie %thesaurus_db;
2592: return @Words;
1.14 harris41 2593: }
1.46 matthew 2594:
1.112 bowersj2 2595: =pod
2596:
2597: =back
2598:
2599: =cut
1.61 www 2600:
2601: # -------------------------------------------------------------- Plaintext name
1.81 albertel 2602: =pod
2603:
1.112 bowersj2 2604: =head1 User Name Functions
2605:
2606: =over 4
2607:
1.648 raeburn 2608: =item * &plainname($uname,$udom,$first)
1.81 albertel 2609:
1.112 bowersj2 2610: Takes a users logon name and returns it as a string in
1.226 albertel 2611: "first middle last generation" form
2612: if $first is set to 'lastname' then it returns it as
2613: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 2614:
2615: =cut
1.61 www 2616:
1.295 www 2617:
1.81 albertel 2618: ###############################################################
1.61 www 2619: sub plainname {
1.226 albertel 2620: my ($uname,$udom,$first)=@_;
1.537 albertel 2621: return if (!defined($uname) || !defined($udom));
1.295 www 2622: my %names=&getnames($uname,$udom);
1.226 albertel 2623: my $name=&Apache::lonnet::format_name($names{'firstname'},
2624: $names{'middlename'},
2625: $names{'lastname'},
2626: $names{'generation'},$first);
2627: $name=~s/^\s+//;
1.62 www 2628: $name=~s/\s+$//;
2629: $name=~s/\s+/ /g;
1.353 albertel 2630: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 2631: return $name;
1.61 www 2632: }
1.66 www 2633:
2634: # -------------------------------------------------------------------- Nickname
1.81 albertel 2635: =pod
2636:
1.648 raeburn 2637: =item * &nickname($uname,$udom)
1.81 albertel 2638:
2639: Gets a users name and returns it as a string as
2640:
2641: ""nickname""
1.66 www 2642:
1.81 albertel 2643: if the user has a nickname or
2644:
2645: "first middle last generation"
2646:
2647: if the user does not
2648:
2649: =cut
1.66 www 2650:
2651: sub nickname {
2652: my ($uname,$udom)=@_;
1.537 albertel 2653: return if (!defined($uname) || !defined($udom));
1.295 www 2654: my %names=&getnames($uname,$udom);
1.68 albertel 2655: my $name=$names{'nickname'};
1.66 www 2656: if ($name) {
2657: $name='"'.$name.'"';
2658: } else {
2659: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
2660: $names{'lastname'}.' '.$names{'generation'};
2661: $name=~s/\s+$//;
2662: $name=~s/\s+/ /g;
2663: }
2664: return $name;
2665: }
2666:
1.295 www 2667: sub getnames {
2668: my ($uname,$udom)=@_;
1.537 albertel 2669: return if (!defined($uname) || !defined($udom));
1.433 albertel 2670: if ($udom eq 'public' && $uname eq 'public') {
2671: return ('lastname' => &mt('Public'));
2672: }
1.295 www 2673: my $id=$uname.':'.$udom;
2674: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
2675: if ($cached) {
2676: return %{$names};
2677: } else {
2678: my %loadnames=&Apache::lonnet::get('environment',
2679: ['firstname','middlename','lastname','generation','nickname'],
2680: $udom,$uname);
2681: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
2682: return %loadnames;
2683: }
2684: }
1.61 www 2685:
1.542 raeburn 2686: # -------------------------------------------------------------------- getemails
1.648 raeburn 2687:
1.542 raeburn 2688: =pod
2689:
1.648 raeburn 2690: =item * &getemails($uname,$udom)
1.542 raeburn 2691:
2692: Gets a user's email information and returns it as a hash with keys:
2693: notification, critnotification, permanentemail
2694:
2695: For notification and critnotification, values are comma-separated lists
1.648 raeburn 2696: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 2697:
1.648 raeburn 2698:
1.542 raeburn 2699: =cut
2700:
1.648 raeburn 2701:
1.466 albertel 2702: sub getemails {
2703: my ($uname,$udom)=@_;
2704: if ($udom eq 'public' && $uname eq 'public') {
2705: return;
2706: }
1.467 www 2707: if (!$udom) { $udom=$env{'user.domain'}; }
2708: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 2709: my $id=$uname.':'.$udom;
2710: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
2711: if ($cached) {
2712: return %{$names};
2713: } else {
2714: my %loadnames=&Apache::lonnet::get('environment',
2715: ['notification','critnotification',
2716: 'permanentemail'],
2717: $udom,$uname);
2718: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
2719: return %loadnames;
2720: }
2721: }
2722:
1.551 albertel 2723: sub flush_email_cache {
2724: my ($uname,$udom)=@_;
2725: if (!$udom) { $udom =$env{'user.domain'}; }
2726: if (!$uname) { $uname=$env{'user.name'}; }
2727: return if ($udom eq 'public' && $uname eq 'public');
2728: my $id=$uname.':'.$udom;
2729: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
2730: }
2731:
1.728 raeburn 2732: # -------------------------------------------------------------------- getlangs
2733:
2734: =pod
2735:
2736: =item * &getlangs($uname,$udom)
2737:
2738: Gets a user's language preference and returns it as a hash with key:
2739: language.
2740:
2741: =cut
2742:
2743:
2744: sub getlangs {
2745: my ($uname,$udom) = @_;
2746: if (!$udom) { $udom =$env{'user.domain'}; }
2747: if (!$uname) { $uname=$env{'user.name'}; }
2748: my $id=$uname.':'.$udom;
2749: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
2750: if ($cached) {
2751: return %{$langs};
2752: } else {
2753: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
2754: $udom,$uname);
2755: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
2756: return %loadlangs;
2757: }
2758: }
2759:
2760: sub flush_langs_cache {
2761: my ($uname,$udom)=@_;
2762: if (!$udom) { $udom =$env{'user.domain'}; }
2763: if (!$uname) { $uname=$env{'user.name'}; }
2764: return if ($udom eq 'public' && $uname eq 'public');
2765: my $id=$uname.':'.$udom;
2766: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
2767: }
2768:
1.61 www 2769: # ------------------------------------------------------------------ Screenname
1.81 albertel 2770:
2771: =pod
2772:
1.648 raeburn 2773: =item * &screenname($uname,$udom)
1.81 albertel 2774:
2775: Gets a users screenname and returns it as a string
2776:
2777: =cut
1.61 www 2778:
2779: sub screenname {
2780: my ($uname,$udom)=@_;
1.258 albertel 2781: if ($uname eq $env{'user.name'} &&
2782: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 2783: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 2784: return $names{'screenname'};
1.62 www 2785: }
2786:
1.212 albertel 2787:
1.62 www 2788: # ------------------------------------------------------------- Message Wrapper
2789:
2790: sub messagewrapper {
1.369 www 2791: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 2792: return
1.441 albertel 2793: '<a href="/adm/email?compose=individual&'.
2794: 'recname='.$username.'&recdom='.$domain.
2795: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 2796: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 2797: }
2798: # --------------------------------------------------------------- Notes Wrapper
2799:
2800: sub noteswrapper {
2801: my ($link,$un,$do)=@_;
2802: return
2803: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 2804: }
2805: # ------------------------------------------------------------- Aboutme Wrapper
2806:
2807: sub aboutmewrapper {
1.166 www 2808: my ($link,$username,$domain,$target)=@_;
1.447 raeburn 2809: if (!defined($username) && !defined($domain)) {
2810: return;
2811: }
1.205 www 2812: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.753 ! droeschl 2813: ($target?' target="$target"':'').' title="'.&mt("View this user's personal
! 2814: homepage").'">'.$link.'</a>';
1.62 www 2815: }
2816:
2817: # ------------------------------------------------------------ Syllabus Wrapper
2818:
2819:
2820: sub syllabuswrapper {
1.707 bisitz 2821: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 2822: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 2823: }
1.14 harris41 2824:
1.208 matthew 2825: sub track_student_link {
1.268 albertel 2826: my ($linktext,$sname,$sdom,$target,$start) = @_;
2827: my $link ="/adm/trackstudent?";
1.208 matthew 2828: my $title = 'View recent activity';
2829: if (defined($sname) && $sname !~ /^\s*$/ &&
2830: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 2831: $link .= "selected_student=$sname:$sdom";
1.208 matthew 2832: $title .= ' of this student';
1.268 albertel 2833: }
1.208 matthew 2834: if (defined($target) && $target !~ /^\s*$/) {
2835: $target = qq{target="$target"};
2836: } else {
2837: $target = '';
2838: }
1.268 albertel 2839: if ($start) { $link.='&start='.$start; }
1.554 albertel 2840: $title = &mt($title);
2841: $linktext = &mt($linktext);
1.448 albertel 2842: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
2843: &help_open_topic('View_recent_activity');
1.208 matthew 2844: }
2845:
1.508 www 2846: # ===================================================== Display a student photo
2847:
2848:
1.509 albertel 2849: sub student_image_tag {
1.508 www 2850: my ($domain,$user)=@_;
2851: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
2852: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
2853: return '<img src="'.$imgsrc.'" align="right" />';
2854: } else {
2855: return '';
2856: }
2857: }
2858:
1.112 bowersj2 2859: =pod
2860:
2861: =back
2862:
2863: =head1 Access .tab File Data
2864:
2865: =over 4
2866:
1.648 raeburn 2867: =item * &languageids()
1.112 bowersj2 2868:
2869: returns list of all language ids
2870:
2871: =cut
2872:
1.14 harris41 2873: sub languageids {
1.16 harris41 2874: return sort(keys(%language));
1.14 harris41 2875: }
2876:
1.112 bowersj2 2877: =pod
2878:
1.648 raeburn 2879: =item * &languagedescription()
1.112 bowersj2 2880:
2881: returns description of a specified language id
2882:
2883: =cut
2884:
1.14 harris41 2885: sub languagedescription {
1.125 www 2886: my $code=shift;
2887: return ($supported_language{$code}?'* ':'').
2888: $language{$code}.
1.126 www 2889: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 2890: }
2891:
2892: sub plainlanguagedescription {
2893: my $code=shift;
2894: return $language{$code};
2895: }
2896:
2897: sub supportedlanguagecode {
2898: my $code=shift;
2899: return $supported_language{$code};
1.97 www 2900: }
2901:
1.112 bowersj2 2902: =pod
2903:
1.648 raeburn 2904: =item * ©rightids()
1.112 bowersj2 2905:
2906: returns list of all copyrights
2907:
2908: =cut
2909:
2910: sub copyrightids {
2911: return sort(keys(%cprtag));
2912: }
2913:
2914: =pod
2915:
1.648 raeburn 2916: =item * ©rightdescription()
1.112 bowersj2 2917:
2918: returns description of a specified copyright id
2919:
2920: =cut
2921:
2922: sub copyrightdescription {
1.166 www 2923: return &mt($cprtag{shift(@_)});
1.112 bowersj2 2924: }
1.197 matthew 2925:
2926: =pod
2927:
1.648 raeburn 2928: =item * &source_copyrightids()
1.192 taceyjo1 2929:
2930: returns list of all source copyrights
2931:
2932: =cut
2933:
2934: sub source_copyrightids {
2935: return sort(keys(%scprtag));
2936: }
2937:
2938: =pod
2939:
1.648 raeburn 2940: =item * &source_copyrightdescription()
1.192 taceyjo1 2941:
2942: returns description of a specified source copyright id
2943:
2944: =cut
2945:
2946: sub source_copyrightdescription {
2947: return &mt($scprtag{shift(@_)});
2948: }
1.112 bowersj2 2949:
2950: =pod
2951:
1.648 raeburn 2952: =item * &filecategories()
1.112 bowersj2 2953:
2954: returns list of all file categories
2955:
2956: =cut
2957:
2958: sub filecategories {
2959: return sort(keys(%category_extensions));
2960: }
2961:
2962: =pod
2963:
1.648 raeburn 2964: =item * &filecategorytypes()
1.112 bowersj2 2965:
2966: returns list of file types belonging to a given file
2967: category
2968:
2969: =cut
2970:
2971: sub filecategorytypes {
1.356 albertel 2972: my ($cat) = @_;
2973: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 2974: }
2975:
2976: =pod
2977:
1.648 raeburn 2978: =item * &fileembstyle()
1.112 bowersj2 2979:
2980: returns embedding style for a specified file type
2981:
2982: =cut
2983:
2984: sub fileembstyle {
2985: return $fe{lc(shift(@_))};
1.169 www 2986: }
2987:
1.351 www 2988: sub filemimetype {
2989: return $fm{lc(shift(@_))};
2990: }
2991:
1.169 www 2992:
2993: sub filecategoryselect {
2994: my ($name,$value)=@_;
1.189 matthew 2995: return &select_form($value,$name,
1.169 www 2996: '' => &mt('Any category'),
2997: map { $_,$_ } sort(keys(%category_extensions)));
1.112 bowersj2 2998: }
2999:
3000: =pod
3001:
1.648 raeburn 3002: =item * &filedescription()
1.112 bowersj2 3003:
3004: returns description for a specified file type
3005:
3006: =cut
3007:
3008: sub filedescription {
1.188 matthew 3009: my $file_description = $fd{lc(shift())};
3010: $file_description =~ s:([\[\]]):~$1:g;
3011: return &mt($file_description);
1.112 bowersj2 3012: }
3013:
3014: =pod
3015:
1.648 raeburn 3016: =item * &filedescriptionex()
1.112 bowersj2 3017:
3018: returns description for a specified file type with
3019: extra formatting
3020:
3021: =cut
3022:
3023: sub filedescriptionex {
3024: my $ex=shift;
1.188 matthew 3025: my $file_description = $fd{lc($ex)};
3026: $file_description =~ s:([\[\]]):~$1:g;
3027: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3028: }
3029:
3030: # End of .tab access
3031: =pod
3032:
3033: =back
3034:
3035: =cut
3036:
3037: # ------------------------------------------------------------------ File Types
3038: sub fileextensions {
3039: return sort(keys(%fe));
3040: }
3041:
1.97 www 3042: # ----------------------------------------------------------- Display Languages
3043: # returns a hash with all desired display languages
3044: #
3045:
3046: sub display_languages {
3047: my %languages=();
1.695 raeburn 3048: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3049: $languages{$lang}=1;
1.97 www 3050: }
3051: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3052: if ($env{'form.displaylanguage'}) {
1.356 albertel 3053: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3054: $languages{$lang}=1;
1.97 www 3055: }
3056: }
3057: return %languages;
1.14 harris41 3058: }
3059:
1.582 albertel 3060: sub languages {
3061: my ($possible_langs) = @_;
1.695 raeburn 3062: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3063: if (!ref($possible_langs)) {
3064: if( wantarray ) {
3065: return @preferred_langs;
3066: } else {
3067: return $preferred_langs[0];
3068: }
3069: }
3070: my %possibilities = map { $_ => 1 } (@$possible_langs);
3071: my @preferred_possibilities;
3072: foreach my $preferred_lang (@preferred_langs) {
3073: if (exists($possibilities{$preferred_lang})) {
3074: push(@preferred_possibilities, $preferred_lang);
3075: }
3076: }
3077: if( wantarray ) {
3078: return @preferred_possibilities;
3079: }
3080: return $preferred_possibilities[0];
3081: }
3082:
1.742 raeburn 3083: sub user_lang {
3084: my ($touname,$toudom,$fromcid) = @_;
3085: my @userlangs;
3086: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3087: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3088: $env{'course.'.$fromcid.'.languages'}));
3089: } else {
3090: my %langhash = &getlangs($touname,$toudom);
3091: if ($langhash{'languages'} ne '') {
3092: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3093: } else {
3094: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3095: if ($domdefs{'lang_def'} ne '') {
3096: @userlangs = ($domdefs{'lang_def'});
3097: }
3098: }
3099: }
3100: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3101: my $user_lh = Apache::localize->get_handle(@languages);
3102: return $user_lh;
3103: }
3104:
3105:
1.112 bowersj2 3106: ###############################################################
3107: ## Student Answer Attempts ##
3108: ###############################################################
3109:
3110: =pod
3111:
3112: =head1 Alternate Problem Views
3113:
3114: =over 4
3115:
1.648 raeburn 3116: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3117: $getattempt, $regexp, $gradesub)
3118:
3119: Return string with previous attempt on problem. Arguments:
3120:
3121: =over 4
3122:
3123: =item * $symb: Problem, including path
3124:
3125: =item * $username: username of the desired student
3126:
3127: =item * $domain: domain of the desired student
1.14 harris41 3128:
1.112 bowersj2 3129: =item * $course: Course ID
1.14 harris41 3130:
1.112 bowersj2 3131: =item * $getattempt: Leave blank for all attempts, otherwise put
3132: something
1.14 harris41 3133:
1.112 bowersj2 3134: =item * $regexp: if string matches this regexp, the string will be
3135: sent to $gradesub
1.14 harris41 3136:
1.112 bowersj2 3137: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3138:
1.112 bowersj2 3139: =back
1.14 harris41 3140:
1.112 bowersj2 3141: The output string is a table containing all desired attempts, if any.
1.16 harris41 3142:
1.112 bowersj2 3143: =cut
1.1 albertel 3144:
3145: sub get_previous_attempt {
1.43 ng 3146: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3147: my $prevattempts='';
1.43 ng 3148: no strict 'refs';
1.1 albertel 3149: if ($symb) {
1.3 albertel 3150: my (%returnhash)=
3151: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3152: if ($returnhash{'version'}) {
3153: my %lasthash=();
3154: my $version;
3155: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3156: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3157: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3158: }
1.1 albertel 3159: }
1.596 albertel 3160: $prevattempts=&start_data_table().&start_data_table_header_row();
3161: $prevattempts.='<th>'.&mt('History').'</th>';
1.356 albertel 3162: foreach my $key (sort(keys(%lasthash))) {
3163: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3164: if ($#parts > 0) {
1.31 albertel 3165: my $data=$parts[-1];
3166: pop(@parts);
1.596 albertel 3167: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.31 albertel 3168: } else {
1.41 ng 3169: if ($#parts == 0) {
3170: $prevattempts.='<th>'.$parts[0].'</th>';
3171: } else {
3172: $prevattempts.='<th>'.$ign.'</th>';
3173: }
1.31 albertel 3174: }
1.16 harris41 3175: }
1.596 albertel 3176: $prevattempts.=&end_data_table_header_row();
1.40 ng 3177: if ($getattempt eq '') {
3178: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.596 albertel 3179: $prevattempts.=&start_data_table_row().
3180: '<td>'.&mt('Transaction [_1]',$version).'</td>';
1.356 albertel 3181: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3182: my $value = &format_previous_attempt_value($key,
3183: $returnhash{$version.':'.$key});
3184: $prevattempts.='<td>'.$value.' </td>';
1.40 ng 3185: }
1.596 albertel 3186: $prevattempts.=&end_data_table_row();
1.40 ng 3187: }
1.1 albertel 3188: }
1.596 albertel 3189: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3190: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3191: my $value = &format_previous_attempt_value($key,$lasthash{$key});
1.356 albertel 3192: if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
1.40 ng 3193: $prevattempts.='<td>'.$value.' </td>';
1.16 harris41 3194: }
1.596 albertel 3195: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3196: } else {
1.596 albertel 3197: $prevattempts=
3198: &start_data_table().&start_data_table_row().
3199: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3200: &end_data_table_row().&end_data_table();
1.1 albertel 3201: }
3202: } else {
1.596 albertel 3203: $prevattempts=
3204: &start_data_table().&start_data_table_row().
3205: '<td>'.&mt('No data.').'</td>'.
3206: &end_data_table_row().&end_data_table();
1.1 albertel 3207: }
1.10 albertel 3208: }
3209:
1.581 albertel 3210: sub format_previous_attempt_value {
3211: my ($key,$value) = @_;
3212: if ($key =~ /timestamp/) {
3213: $value = &Apache::lonlocal::locallocaltime($value);
3214: } elsif (ref($value) eq 'ARRAY') {
3215: $value = '('.join(', ', @{ $value }).')';
3216: } else {
3217: $value = &unescape($value);
3218: }
3219: return $value;
3220: }
3221:
3222:
1.107 albertel 3223: sub relative_to_absolute {
3224: my ($url,$output)=@_;
3225: my $parser=HTML::TokeParser->new(\$output);
3226: my $token;
3227: my $thisdir=$url;
3228: my @rlinks=();
3229: while ($token=$parser->get_token) {
3230: if ($token->[0] eq 'S') {
3231: if ($token->[1] eq 'a') {
3232: if ($token->[2]->{'href'}) {
3233: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3234: }
3235: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3236: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3237: } elsif ($token->[1] eq 'base') {
3238: $thisdir=$token->[2]->{'href'};
3239: }
3240: }
3241: }
3242: $thisdir=~s-/[^/]*$--;
1.356 albertel 3243: foreach my $link (@rlinks) {
1.726 raeburn 3244: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3245: ($link=~/^\//) ||
3246: ($link=~/^javascript:/i) ||
3247: ($link=~/^mailto:/i) ||
3248: ($link=~/^\#/)) {
3249: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3250: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3251: }
3252: }
3253: # -------------------------------------------------- Deal with Applet codebases
3254: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3255: return $output;
3256: }
3257:
1.112 bowersj2 3258: =pod
3259:
1.648 raeburn 3260: =item * &get_student_view()
1.112 bowersj2 3261:
3262: show a snapshot of what student was looking at
3263:
3264: =cut
3265:
1.10 albertel 3266: sub get_student_view {
1.186 albertel 3267: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3268: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3269: my (%form);
1.10 albertel 3270: my @elements=('symb','courseid','domain','username');
3271: foreach my $element (@elements) {
1.186 albertel 3272: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3273: }
1.186 albertel 3274: if (defined($moreenv)) {
3275: %form=(%form,%{$moreenv});
3276: }
1.236 albertel 3277: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3278: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 3279: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3280: $userview=~s/\<body[^\>]*\>//gi;
3281: $userview=~s/\<\/body\>//gi;
3282: $userview=~s/\<html\>//gi;
3283: $userview=~s/\<\/html\>//gi;
3284: $userview=~s/\<head\>//gi;
3285: $userview=~s/\<\/head\>//gi;
3286: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 3287: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 3288: if (wantarray) {
3289: return ($userview,$response);
3290: } else {
3291: return $userview;
3292: }
3293: }
3294:
3295: sub get_student_view_with_retries {
3296: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3297:
3298: my $ok = 0; # True if we got a good response.
3299: my $content;
3300: my $response;
3301:
3302: # Try to get the student_view done. within the retries count:
3303:
3304: do {
3305: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3306: $ok = $response->is_success;
3307: if (!$ok) {
3308: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3309: }
3310: $retries--;
3311: } while (!$ok && ($retries > 0));
3312:
3313: if (!$ok) {
3314: $content = ''; # On error return an empty content.
3315: }
1.651 www 3316: if (wantarray) {
3317: return ($content, $response);
3318: } else {
3319: return $content;
3320: }
1.11 albertel 3321: }
3322:
1.112 bowersj2 3323: =pod
3324:
1.648 raeburn 3325: =item * &get_student_answers()
1.112 bowersj2 3326:
3327: show a snapshot of how student was answering problem
3328:
3329: =cut
3330:
1.11 albertel 3331: sub get_student_answers {
1.100 sakharuk 3332: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 3333: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3334: my (%moreenv);
1.11 albertel 3335: my @elements=('symb','courseid','domain','username');
3336: foreach my $element (@elements) {
1.186 albertel 3337: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3338: }
1.186 albertel 3339: $moreenv{'grade_target'}='answer';
3340: %moreenv=(%form,%moreenv);
1.497 raeburn 3341: $feedurl = &Apache::lonnet::clutter($feedurl);
3342: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 3343: return $userview;
1.1 albertel 3344: }
1.116 albertel 3345:
3346: =pod
3347:
3348: =item * &submlink()
3349:
1.242 albertel 3350: Inputs: $text $uname $udom $symb $target
1.116 albertel 3351:
3352: Returns: A link to grades.pm such as to see the SUBM view of a student
3353:
3354: =cut
3355:
3356: ###############################################
3357: sub submlink {
1.242 albertel 3358: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 3359: if (!($uname && $udom)) {
3360: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3361: &Apache::lonnet::whichuser($symb);
1.116 albertel 3362: if (!$symb) { $symb=$cursymb; }
3363: }
1.254 matthew 3364: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3365: $symb=&escape($symb);
1.242 albertel 3366: if ($target) { $target="target=\"$target\""; }
3367: return '<a href="/adm/grades?&command=submission&'.
3368: 'symb='.$symb.'&student='.$uname.
3369: '&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
3370: }
3371: ##############################################
3372:
3373: =pod
3374:
3375: =item * &pgrdlink()
3376:
3377: Inputs: $text $uname $udom $symb $target
3378:
3379: Returns: A link to grades.pm such as to see the PGRD view of a student
3380:
3381: =cut
3382:
3383: ###############################################
3384: sub pgrdlink {
3385: my $link=&submlink(@_);
3386: $link=~s/(&command=submission)/$1&showgrading=yes/;
3387: return $link;
3388: }
3389: ##############################################
3390:
3391: =pod
3392:
3393: =item * &pprmlink()
3394:
3395: Inputs: $text $uname $udom $symb $target
3396:
3397: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 3398: student and a specific resource
1.242 albertel 3399:
3400: =cut
3401:
3402: ###############################################
3403: sub pprmlink {
3404: my ($text,$uname,$udom,$symb,$target)=@_;
3405: if (!($uname && $udom)) {
3406: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3407: &Apache::lonnet::whichuser($symb);
1.242 albertel 3408: if (!$symb) { $symb=$cursymb; }
3409: }
1.254 matthew 3410: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3411: $symb=&escape($symb);
1.242 albertel 3412: if ($target) { $target="target=\"$target\""; }
1.595 albertel 3413: return '<a href="/adm/parmset?command=set&'.
3414: 'symb='.$symb.'&uname='.$uname.
3415: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 3416: }
3417: ##############################################
1.37 matthew 3418:
1.112 bowersj2 3419: =pod
3420:
3421: =back
3422:
3423: =cut
3424:
1.37 matthew 3425: ###############################################
1.51 www 3426:
3427:
3428: sub timehash {
1.687 raeburn 3429: my ($thistime) = @_;
3430: my $timezone = &Apache::lonlocal::gettimezone();
3431: my $dt = DateTime->from_epoch(epoch => $thistime)
3432: ->set_time_zone($timezone);
3433: my $wday = $dt->day_of_week();
3434: if ($wday == 7) { $wday = 0; }
3435: return ( 'second' => $dt->second(),
3436: 'minute' => $dt->minute(),
3437: 'hour' => $dt->hour(),
3438: 'day' => $dt->day_of_month(),
3439: 'month' => $dt->month(),
3440: 'year' => $dt->year(),
3441: 'weekday' => $wday,
3442: 'dayyear' => $dt->day_of_year(),
3443: 'dlsav' => $dt->is_dst() );
1.51 www 3444: }
3445:
1.370 www 3446: sub utc_string {
3447: my ($date)=@_;
1.371 www 3448: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 3449: }
3450:
1.51 www 3451: sub maketime {
3452: my %th=@_;
1.687 raeburn 3453: my ($epoch_time,$timezone,$dt);
3454: $timezone = &Apache::lonlocal::gettimezone();
3455: eval {
3456: $dt = DateTime->new( year => $th{'year'},
3457: month => $th{'month'},
3458: day => $th{'day'},
3459: hour => $th{'hour'},
3460: minute => $th{'minute'},
3461: second => $th{'second'},
3462: time_zone => $timezone,
3463: );
3464: };
3465: if (!$@) {
3466: $epoch_time = $dt->epoch;
3467: if ($epoch_time) {
3468: return $epoch_time;
3469: }
3470: }
1.51 www 3471: return POSIX::mktime(
3472: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 3473: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 3474: }
3475:
3476: #########################################
1.51 www 3477:
3478: sub findallcourses {
1.482 raeburn 3479: my ($roles,$uname,$udom) = @_;
1.355 albertel 3480: my %roles;
3481: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 3482: my %courses;
1.51 www 3483: my $now=time;
1.482 raeburn 3484: if (!defined($uname)) {
3485: $uname = $env{'user.name'};
3486: }
3487: if (!defined($udom)) {
3488: $udom = $env{'user.domain'};
3489: }
3490: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
3491: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
3492: if (!%roles) {
3493: %roles = (
3494: cc => 1,
3495: in => 1,
3496: ep => 1,
3497: ta => 1,
3498: cr => 1,
3499: st => 1,
3500: );
3501: }
3502: foreach my $entry (keys(%roleshash)) {
3503: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
3504: if ($trole =~ /^cr/) {
3505: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
3506: } else {
3507: next if (!exists($roles{$trole}));
3508: }
3509: if ($tend) {
3510: next if ($tend < $now);
3511: }
3512: if ($tstart) {
3513: next if ($tstart > $now);
3514: }
3515: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
3516: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
3517: if ($secpart eq '') {
3518: ($cnum,$role) = split(/_/,$cnumpart);
3519: $sec = 'none';
3520: $realsec = '';
3521: } else {
3522: $cnum = $cnumpart;
3523: ($sec,$role) = split(/_/,$secpart);
3524: $realsec = $sec;
1.490 raeburn 3525: }
1.482 raeburn 3526: $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
3527: }
3528: } else {
3529: foreach my $key (keys(%env)) {
1.483 albertel 3530: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
3531: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 3532: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
3533: next if ($role eq 'ca' || $role eq 'aa');
3534: next if (%roles && !exists($roles{$role}));
3535: my ($starttime,$endtime)=split(/\./,$env{$key});
3536: my $active=1;
3537: if ($starttime) {
3538: if ($now<$starttime) { $active=0; }
3539: }
3540: if ($endtime) {
3541: if ($now>$endtime) { $active=0; }
3542: }
3543: if ($active) {
3544: if ($sec eq '') {
3545: $sec = 'none';
3546: }
3547: $courses{$cdom.'_'.$cnum}{$sec} =
3548: $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474 raeburn 3549: }
3550: }
1.51 www 3551: }
3552: }
1.474 raeburn 3553: return %courses;
1.51 www 3554: }
1.37 matthew 3555:
1.54 www 3556: ###############################################
1.474 raeburn 3557:
3558: sub blockcheck {
1.482 raeburn 3559: my ($setters,$activity,$uname,$udom) = @_;
1.490 raeburn 3560:
3561: if (!defined($udom)) {
3562: $udom = $env{'user.domain'};
3563: }
3564: if (!defined($uname)) {
3565: $uname = $env{'user.name'};
3566: }
3567:
3568: # If uname and udom are for a course, check for blocks in the course.
3569:
3570: if (&Apache::lonnet::is_course($udom,$uname)) {
3571: my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502 raeburn 3572: my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490 raeburn 3573: return ($startblock,$endblock);
3574: }
1.474 raeburn 3575:
1.502 raeburn 3576: my $startblock = 0;
3577: my $endblock = 0;
1.482 raeburn 3578: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 3579:
1.490 raeburn 3580: # If uname is for a user, and activity is course-specific, i.e.,
3581: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 3582:
1.490 raeburn 3583: if (($activity eq 'boards' || $activity eq 'chat' ||
3584: $activity eq 'groups') && ($env{'request.course.id'})) {
3585: foreach my $key (keys(%live_courses)) {
3586: if ($key ne $env{'request.course.id'}) {
3587: delete($live_courses{$key});
3588: }
3589: }
3590: }
3591:
3592: my $otheruser = 0;
3593: my %own_courses;
3594: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
3595: # Resource belongs to user other than current user.
3596: $otheruser = 1;
3597: # Gather courses for current user
3598: %own_courses =
3599: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
3600: }
3601:
3602: # Gather active course roles - course coordinator, instructor,
3603: # exam proctor, ta, student, or custom role.
1.474 raeburn 3604:
3605: foreach my $course (keys(%live_courses)) {
1.482 raeburn 3606: my ($cdom,$cnum);
3607: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
3608: $cdom = $env{'course.'.$course.'.domain'};
3609: $cnum = $env{'course.'.$course.'.num'};
3610: } else {
1.490 raeburn 3611: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 3612: }
3613: my $no_ownblock = 0;
3614: my $no_userblock = 0;
1.533 raeburn 3615: if ($otheruser && $activity ne 'com') {
1.490 raeburn 3616: # Check if current user has 'evb' priv for this
3617: if (defined($own_courses{$course})) {
3618: foreach my $sec (keys(%{$own_courses{$course}})) {
3619: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
3620: if ($sec ne 'none') {
3621: $checkrole .= '/'.$sec;
3622: }
3623: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3624: $no_ownblock = 1;
3625: last;
3626: }
3627: }
3628: }
3629: # if they have 'evb' priv and are currently not playing student
3630: next if (($no_ownblock) &&
3631: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
3632: }
1.474 raeburn 3633: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 3634: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 3635: if ($sec ne 'none') {
1.482 raeburn 3636: $checkrole .= '/'.$sec;
1.474 raeburn 3637: }
1.490 raeburn 3638: if ($otheruser) {
3639: # Resource belongs to user other than current user.
3640: # Assemble privs for that user, and check for 'evb' priv.
1.482 raeburn 3641: my ($trole,$tdom,$tnum,$tsec);
3642: my $entry = $live_courses{$course}{$sec};
3643: if ($entry =~ /^cr/) {
3644: ($trole,$tdom,$tnum,$tsec) =
3645: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
3646: } else {
3647: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
3648: }
3649: my ($spec,$area,$trest,%allroles,%userroles);
3650: $area = '/'.$tdom.'/'.$tnum;
3651: $trest = $tnum;
3652: if ($tsec ne '') {
3653: $area .= '/'.$tsec;
3654: $trest .= '/'.$tsec;
3655: }
3656: $spec = $trole.'.'.$area;
3657: if ($trole =~ /^cr/) {
3658: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
3659: $tdom,$spec,$trest,$area);
3660: } else {
3661: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
3662: $tdom,$spec,$trest,$area);
3663: }
3664: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486 raeburn 3665: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
3666: if ($1) {
3667: $no_userblock = 1;
3668: last;
3669: }
3670: }
1.490 raeburn 3671: } else {
3672: # Resource belongs to current user
3673: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 3674: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3675: $no_ownblock = 1;
3676: last;
3677: }
1.474 raeburn 3678: }
3679: }
3680: # if they have the evb priv and are currently not playing student
1.482 raeburn 3681: next if (($no_ownblock) &&
1.491 albertel 3682: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 3683: next if ($no_userblock);
1.474 raeburn 3684:
1.490 raeburn 3685: # Retrieve blocking times and identity of blocker for course
3686: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 3687:
3688: my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
3689: if (($start != 0) &&
3690: (($startblock == 0) || ($startblock > $start))) {
3691: $startblock = $start;
3692: }
3693: if (($end != 0) &&
3694: (($endblock == 0) || ($endblock < $end))) {
3695: $endblock = $end;
3696: }
1.490 raeburn 3697: }
3698: return ($startblock,$endblock);
3699: }
3700:
3701: sub get_blocks {
3702: my ($setters,$activity,$cdom,$cnum) = @_;
3703: my $startblock = 0;
3704: my $endblock = 0;
3705: my $course = $cdom.'_'.$cnum;
3706: $setters->{$course} = {};
3707: $setters->{$course}{'staff'} = [];
3708: $setters->{$course}{'times'} = [];
3709: my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
3710: foreach my $record (keys(%records)) {
3711: my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
3712: if ($start <= time && $end >= time) {
3713: my ($staff_name,$staff_dom,$title,$blocks) =
3714: &parse_block_record($records{$record});
3715: if ($blocks->{$activity} eq 'on') {
3716: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
3717: push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491 albertel 3718: if ( ($startblock == 0) || ($startblock > $start) ) {
3719: $startblock = $start;
1.490 raeburn 3720: }
1.491 albertel 3721: if ( ($endblock == 0) || ($endblock < $end) ) {
3722: $endblock = $end;
1.474 raeburn 3723: }
3724: }
3725: }
3726: }
3727: return ($startblock,$endblock);
3728: }
3729:
3730: sub parse_block_record {
3731: my ($record) = @_;
3732: my ($setuname,$setudom,$title,$blocks);
3733: if (ref($record) eq 'HASH') {
3734: ($setuname,$setudom) = split(/:/,$record->{'setter'});
3735: $title = &unescape($record->{'event'});
3736: $blocks = $record->{'blocks'};
3737: } else {
3738: my @data = split(/:/,$record,3);
3739: if (scalar(@data) eq 2) {
3740: $title = $data[1];
3741: ($setuname,$setudom) = split(/@/,$data[0]);
3742: } else {
3743: ($setuname,$setudom,$title) = @data;
3744: }
3745: $blocks = { 'com' => 'on' };
3746: }
3747: return ($setuname,$setudom,$title,$blocks);
3748: }
3749:
3750: sub build_block_table {
3751: my ($startblock,$endblock,$setters) = @_;
3752: my %lt = &Apache::lonlocal::texthash(
3753: 'cacb' => 'Currently active communication blocks',
3754: 'cour' => 'Course',
3755: 'dura' => 'Duration',
3756: 'blse' => 'Block set by'
3757: );
3758: my $output;
1.476 raeburn 3759: $output = '<br />'.$lt{'cacb'}.':<br />';
1.474 raeburn 3760: $output .= &start_data_table();
3761: $output .= '
3762: <tr>
3763: <th>'.$lt{'cour'}.'</th>
3764: <th>'.$lt{'dura'}.'</th>
3765: <th>'.$lt{'blse'}.'</th>
3766: </tr>
3767: ';
3768: foreach my $course (keys(%{$setters})) {
3769: my %courseinfo=&Apache::lonnet::coursedescription($course);
3770: for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) {
3771: my ($uname,$udom) = @{$$setters{$course}{staff}[$i]};
1.490 raeburn 3772: my $fullname = &plainname($uname,$udom);
3773: if (defined($env{'user.name'}) && defined($env{'user.domain'})
3774: && $env{'user.name'} ne 'public'
3775: && $env{'user.domain'} ne 'public') {
3776: $fullname = &aboutmewrapper($fullname,$uname,$udom);
3777: }
1.474 raeburn 3778: my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]};
3779: $openblock = &Apache::lonlocal::locallocaltime($openblock);
3780: $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
3781: $output .= &Apache::loncommon::start_data_table_row().
3782: '<td>'.$courseinfo{'description'}.'</td>'.
3783: '<td>'.$openblock.' to '.$closeblock.'</td>'.
1.490 raeburn 3784: '<td>'.$fullname.'</td>'.
1.474 raeburn 3785: &Apache::loncommon::end_data_table_row();
3786: }
3787: }
3788: $output .= &end_data_table();
3789: }
3790:
1.490 raeburn 3791: sub blocking_status {
3792: my ($activity,$uname,$udom) = @_;
3793: my %setters;
3794: my ($blocked,$output,$ownitem,$is_course);
3795: my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
3796: if ($startblock && $endblock) {
3797: $blocked = 1;
3798: if (wantarray) {
3799: my $category;
3800: if ($activity eq 'boards') {
3801: $category = 'Discussion posts in this course';
3802: } elsif ($activity eq 'blogs') {
3803: $category = 'Blogs';
3804: } elsif ($activity eq 'port') {
3805: if (defined($uname) && defined($udom)) {
3806: if ($uname eq $env{'user.name'} &&
3807: $udom eq $env{'user.domain'}) {
3808: $ownitem = 1;
3809: }
3810: }
3811: $is_course = &Apache::lonnet::is_course($udom,$uname);
3812: if ($ownitem) {
3813: $category = 'Your portfolio files';
3814: } elsif ($is_course) {
3815: my $coursedesc;
3816: foreach my $course (keys(%setters)) {
3817: my %courseinfo =
3818: &Apache::lonnet::coursedescription($course);
3819: $coursedesc = $courseinfo{'description'};
3820: }
3821: $category = "Group files in the course '$coursedesc'";
3822: } else {
3823: $category = 'Portfolio files belonging to ';
3824: if ($env{'user.name'} eq 'public' &&
3825: $env{'user.domain'} eq 'public') {
3826: $category .= &plainname($uname,$udom);
3827: } else {
3828: $category .= &aboutmewrapper(&plainname($uname,$udom),$uname,$udom);
3829: }
3830: }
3831: } elsif ($activity eq 'groups') {
3832: $category = 'Groups in this course';
3833: }
3834: my $showstart = &Apache::lonlocal::locallocaltime($startblock);
3835: my $showend = &Apache::lonlocal::locallocaltime($endblock);
3836: $output = '<br />'.&mt('[_1] will be inaccessible between [_2] and [_3] because communication is being blocked.',$category,$showstart,$showend).'<br />';
3837: if (!($activity eq 'port' && !($ownitem) && !($is_course))) {
3838: $output .= &build_block_table($startblock,$endblock,\%setters);
3839: }
3840: }
3841: }
3842: if (wantarray) {
3843: return ($blocked,$output);
3844: } else {
3845: return $blocked;
3846: }
3847: }
3848:
1.60 matthew 3849: ###############################################
3850:
1.682 raeburn 3851: sub check_ip_acc {
3852: my ($acc)=@_;
3853: &Apache::lonxml::debug("acc is $acc");
3854: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
3855: return 1;
3856: }
3857: my $allowed=0;
3858: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
3859:
3860: my $name;
3861: foreach my $pattern (split(',',$acc)) {
3862: $pattern =~ s/^\s*//;
3863: $pattern =~ s/\s*$//;
3864: if ($pattern =~ /\*$/) {
3865: #35.8.*
3866: $pattern=~s/\*//;
3867: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
3868: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
3869: #35.8.3.[34-56]
3870: my $low=$2;
3871: my $high=$3;
3872: $pattern=$1;
3873: if ($ip =~ /^\Q$pattern\E/) {
3874: my $last=(split(/\./,$ip))[3];
3875: if ($last <=$high && $last >=$low) { $allowed=1; }
3876: }
3877: } elsif ($pattern =~ /^\*/) {
3878: #*.msu.edu
3879: $pattern=~s/\*//;
3880: if (!defined($name)) {
3881: use Socket;
3882: my $netaddr=inet_aton($ip);
3883: ($name)=gethostbyaddr($netaddr,AF_INET);
3884: }
3885: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
3886: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
3887: #127.0.0.1
3888: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
3889: } else {
3890: #some.name.com
3891: if (!defined($name)) {
3892: use Socket;
3893: my $netaddr=inet_aton($ip);
3894: ($name)=gethostbyaddr($netaddr,AF_INET);
3895: }
3896: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
3897: }
3898: if ($allowed) { last; }
3899: }
3900: return $allowed;
3901: }
3902:
3903: ###############################################
3904:
1.60 matthew 3905: =pod
3906:
1.112 bowersj2 3907: =head1 Domain Template Functions
3908:
3909: =over 4
3910:
3911: =item * &determinedomain()
1.60 matthew 3912:
3913: Inputs: $domain (usually will be undef)
3914:
1.63 www 3915: Returns: Determines which domain should be used for designs
1.60 matthew 3916:
3917: =cut
1.54 www 3918:
1.60 matthew 3919: ###############################################
1.63 www 3920: sub determinedomain {
3921: my $domain=shift;
1.531 albertel 3922: if (! $domain) {
1.60 matthew 3923: # Determine domain if we have not been given one
3924: $domain = $Apache::lonnet::perlvar{'lonDefDomain'};
1.258 albertel 3925: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
3926: if ($env{'request.role.domain'}) {
3927: $domain=$env{'request.role.domain'};
1.60 matthew 3928: }
3929: }
1.63 www 3930: return $domain;
3931: }
3932: ###############################################
1.517 raeburn 3933:
1.518 albertel 3934: sub devalidate_domconfig_cache {
3935: my ($udom)=@_;
3936: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
3937: }
3938:
3939: # ---------------------- Get domain configuration for a domain
3940: sub get_domainconf {
3941: my ($udom) = @_;
3942: my $cachetime=1800;
3943: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
3944: if (defined($cached)) { return %{$result}; }
3945:
3946: my %domconfig = &Apache::lonnet::get_dom('configuration',
3947: ['login','rolecolors'],$udom);
1.632 raeburn 3948: my (%designhash,%legacy);
1.518 albertel 3949: if (keys(%domconfig) > 0) {
3950: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 3951: if (keys(%{$domconfig{'login'}})) {
3952: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 3953: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
3954: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
3955: $designhash{$udom.'.login.'.$key.'_'.$img} =
3956: $domconfig{'login'}{$key}{$img};
3957: }
3958: } else {
3959: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
3960: }
1.632 raeburn 3961: }
3962: } else {
3963: $legacy{'login'} = 1;
1.518 albertel 3964: }
1.632 raeburn 3965: } else {
3966: $legacy{'login'} = 1;
1.518 albertel 3967: }
3968: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 3969: if (keys(%{$domconfig{'rolecolors'}})) {
3970: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
3971: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
3972: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
3973: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
3974: }
1.518 albertel 3975: }
3976: }
1.632 raeburn 3977: } else {
3978: $legacy{'rolecolors'} = 1;
1.518 albertel 3979: }
1.632 raeburn 3980: } else {
3981: $legacy{'rolecolors'} = 1;
1.518 albertel 3982: }
1.632 raeburn 3983: if (keys(%legacy) > 0) {
3984: my %legacyhash = &get_legacy_domconf($udom);
3985: foreach my $item (keys(%legacyhash)) {
3986: if ($item =~ /^\Q$udom\E\.login/) {
3987: if ($legacy{'login'}) {
3988: $designhash{$item} = $legacyhash{$item};
3989: }
3990: } else {
3991: if ($legacy{'rolecolors'}) {
3992: $designhash{$item} = $legacyhash{$item};
3993: }
1.518 albertel 3994: }
3995: }
3996: }
1.632 raeburn 3997: } else {
3998: %designhash = &get_legacy_domconf($udom);
1.518 albertel 3999: }
4000: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4001: $cachetime);
4002: return %designhash;
4003: }
4004:
1.632 raeburn 4005: sub get_legacy_domconf {
4006: my ($udom) = @_;
4007: my %legacyhash;
4008: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4009: my $designfile = $designdir.'/'.$udom.'.tab';
4010: if (-e $designfile) {
4011: if ( open (my $fh,"<$designfile") ) {
4012: while (my $line = <$fh>) {
4013: next if ($line =~ /^\#/);
4014: chomp($line);
4015: my ($key,$val)=(split(/\=/,$line));
4016: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4017: }
4018: close($fh);
4019: }
4020: }
4021: if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
4022: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4023: }
4024: return %legacyhash;
4025: }
4026:
1.63 www 4027: =pod
4028:
1.112 bowersj2 4029: =item * &domainlogo()
1.63 www 4030:
4031: Inputs: $domain (usually will be undef)
4032:
4033: Returns: A link to a domain logo, if the domain logo exists.
4034: If the domain logo does not exist, a description of the domain.
4035:
4036: =cut
1.112 bowersj2 4037:
1.63 www 4038: ###############################################
4039: sub domainlogo {
1.517 raeburn 4040: my $domain = &determinedomain(shift);
1.518 albertel 4041: my %designhash = &get_domainconf($domain);
1.517 raeburn 4042: # See if there is a logo
4043: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4044: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4045: if ($imgsrc =~ m{^/(adm|res)/}) {
4046: if ($imgsrc =~ m{^/res/}) {
4047: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4048: &Apache::lonnet::repcopy($local_name);
4049: }
4050: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4051: }
4052: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4053: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4054: return &Apache::lonnet::domain($domain,'description');
1.59 www 4055: } else {
1.60 matthew 4056: return '';
1.59 www 4057: }
4058: }
1.63 www 4059: ##############################################
4060:
4061: =pod
4062:
1.112 bowersj2 4063: =item * &designparm()
1.63 www 4064:
4065: Inputs: $which parameter; $domain (usually will be undef)
4066:
4067: Returns: value of designparamter $which
4068:
4069: =cut
1.112 bowersj2 4070:
1.397 albertel 4071:
1.400 albertel 4072: ##############################################
1.397 albertel 4073: sub designparm {
4074: my ($which,$domain)=@_;
1.258 albertel 4075: if ($env{'browser.blackwhite'} eq 'on') {
1.635 raeburn 4076: if ($which=~/\.(font|alink|vlink|link|textcol)$/) {
1.110 www 4077: return '#000000';
4078: }
1.635 raeburn 4079: if ($which=~/\.(pgbg|sidebg|bgcol)$/) {
1.110 www 4080: return '#FFFFFF';
4081: }
4082: if ($which=~/\.tabbg$/) {
4083: return '#CCCCCC';
4084: }
4085: }
1.397 albertel 4086: if (exists($env{'environment.color.'.$which})) {
1.258 albertel 4087: return $env{'environment.color.'.$which};
1.96 www 4088: }
1.63 www 4089: $domain=&determinedomain($domain);
1.518 albertel 4090: my %domdesign = &get_domainconf($domain);
1.520 raeburn 4091: my $output;
1.517 raeburn 4092: if ($domdesign{$domain.'.'.$which} ne '') {
1.520 raeburn 4093: $output = $domdesign{$domain.'.'.$which};
1.63 www 4094: } else {
1.520 raeburn 4095: $output = $defaultdesign{$which};
4096: }
4097: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4098: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4099: if ($output =~ m{^/(adm|res)/}) {
4100: if ($output =~ m{^/res/}) {
4101: my $local_name = &Apache::lonnet::filelocation('',$output);
4102: &Apache::lonnet::repcopy($local_name);
4103: }
1.520 raeburn 4104: $output = &lonhttpdurl($output);
4105: }
1.63 www 4106: }
1.520 raeburn 4107: return $output;
1.63 www 4108: }
1.59 www 4109:
1.60 matthew 4110: ###############################################
4111: ###############################################
4112:
4113: =pod
4114:
1.112 bowersj2 4115: =back
4116:
1.549 albertel 4117: =head1 HTML Helpers
1.112 bowersj2 4118:
4119: =over 4
4120:
4121: =item * &bodytag()
1.60 matthew 4122:
4123: Returns a uniform header for LON-CAPA web pages.
4124:
4125: Inputs:
4126:
1.112 bowersj2 4127: =over 4
4128:
4129: =item * $title, A title to be displayed on the page.
4130:
4131: =item * $function, the current role (can be undef).
4132:
4133: =item * $addentries, extra parameters for the <body> tag.
4134:
4135: =item * $bodyonly, if defined, only return the <body> tag.
4136:
4137: =item * $domain, if defined, force a given domain.
4138:
4139: =item * $forcereg, if page should register as content page (relevant for
1.86 www 4140: text interface only)
1.60 matthew 4141:
1.326 albertel 4142: =item * $customtitle, alternate text to use instead of $title
4143: in the title box that appears, this text
4144: is not auto translated like the $title is
1.309 albertel 4145:
4146: =item * $notopbar, if true, keep the 'what is this' info but remove the
4147: navigational links
1.317 albertel 4148:
1.338 albertel 4149: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
4150:
4151: =item * $notitle, if true keep the nav controls, but remove the title bar
4152:
1.361 albertel 4153: =item * $no_inline_link, if true and in remote mode, don't show the
4154: 'Switch To Inline Menu' link
4155:
1.460 albertel 4156: =item * $args, optional argument valid values are
4157: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 4158: inherit_jsmath -> when creating popup window in a page,
4159: should it have jsmath forced on by the
4160: current page
1.460 albertel 4161:
1.112 bowersj2 4162: =back
4163:
1.60 matthew 4164: Returns: A uniform header for LON-CAPA web pages.
4165: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
4166: If $bodyonly is undef or zero, an html string containing a <body> tag and
4167: other decorations will be returned.
4168:
4169: =cut
4170:
1.54 www 4171: sub bodytag {
1.309 albertel 4172: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,$customtitle,
1.460 albertel 4173: $notopbar,$bgcolor,$notitle,$no_inline_link,$args)=@_;
1.339 albertel 4174:
1.460 albertel 4175: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 4176:
1.183 matthew 4177: $function = &get_users_function() if (!$function);
1.339 albertel 4178: my $img = &designparm($function.'.img',$domain);
4179: my $font = &designparm($function.'.font',$domain);
4180: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
4181:
4182: my %design = ( 'style' => 'margin-top: 0px',
1.535 albertel 4183: 'bgcolor' => $pgbg,
1.339 albertel 4184: 'text' => $font,
4185: 'alink' => &designparm($function.'.alink',$domain),
4186: 'vlink' => &designparm($function.'.vlink',$domain),
4187: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 4188: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 4189:
1.63 www 4190: # role and realm
1.378 raeburn 4191: my ($role,$realm) = split(/\./,$env{'request.role'},2);
4192: if ($role eq 'ca') {
1.479 albertel 4193: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 4194: $realm = &plainname($rname,$rdom);
1.378 raeburn 4195: }
1.55 www 4196: # realm
1.258 albertel 4197: if ($env{'request.course.id'}) {
1.378 raeburn 4198: if ($env{'request.role'} !~ /^cr/) {
4199: $role = &Apache::lonnet::plaintext($role,&course_type());
4200: }
1.359 albertel 4201: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 4202: } else {
4203: $role = &Apache::lonnet::plaintext($role);
1.54 www 4204: }
1.433 albertel 4205:
1.359 albertel 4206: if (!$realm) { $realm=' '; }
1.55 www 4207: # Set messages
1.60 matthew 4208: my $messages=&domainlogo($domain);
1.330 albertel 4209:
1.438 albertel 4210: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 4211:
1.101 www 4212: # construct main body tag
1.359 albertel 4213: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 4214: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 4215:
1.530 albertel 4216: if ($bodyonly) {
1.60 matthew 4217: return $bodytag;
1.258 albertel 4218: } elsif ($env{'browser.interface'} eq 'textual') {
1.95 www 4219: # Accessibility
1.224 raeburn 4220:
1.337 albertel 4221: $bodytag.=&Apache::lonmenu::menubuttons($forcereg,$forcereg);
1.338 albertel 4222: if (!$notitle) {
1.337 albertel 4223: $bodytag.='<h1>LON-CAPA: '.$title.'</h1>';
4224: }
4225: return $bodytag;
1.359 albertel 4226: }
4227:
1.410 albertel 4228: my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.433 albertel 4229: if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
4230: undef($role);
1.434 albertel 4231: } else {
4232: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433 albertel 4233: }
1.359 albertel 4234:
4235: my $roleinfo=(<<ENDROLE);
4236: <td class="LC_title_bar_who">
4237: <div class="LC_title_bar_name">
1.410 albertel 4238: $name
1.361 albertel 4239:
1.359 albertel 4240: </div>
4241: <div class="LC_title_bar_role">
1.361 albertel 4242: $role
1.359 albertel 4243: </div>
4244: <div class="LC_title_bar_realm">
1.361 albertel 4245: $realm
1.359 albertel 4246: </div>
1.206 albertel 4247: </td>
4248: ENDROLE
1.235 raeburn 4249:
1.359 albertel 4250: my $titleinfo = '<span class="LC_title_bar_title">'.$title.'</span>';
4251: if ($customtitle) {
4252: $titleinfo = $customtitle;
4253: }
4254: #
4255: # Extra info if you are the DC
4256: my $dc_info = '';
4257: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
4258: $env{'course.'.$env{'request.course.id'}.
4259: '.domain'}.'/'})) {
4260: my $cid = $env{'request.course.id'};
4261: $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 4262: $dc_info =~ s/\s+$//;
1.359 albertel 4263: $dc_info = '('.$dc_info.')';
4264: }
4265:
1.644 www 4266: if (($env{'environment.remote'} eq 'off') || ($args->{'suppress_header_logos'})) {
1.359 albertel 4267: # No Remote
1.258 albertel 4268: if ($env{'request.state'} eq 'construct') {
1.359 albertel 4269: $forcereg=1;
4270: }
4271:
4272: if (!$customtitle && $env{'request.state'} eq 'construct') {
4273: # this is for resources; directories have customtitle, and crumbs
4274: # and select recent are created in lonpubdir.pm
1.229 albertel 4275: my ($uname,$thisdisfn)=
1.258 albertel 4276: ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
1.229 albertel 4277: my $formaction='/priv/'.$uname.'/'.$thisdisfn;
4278: $formaction=~s/\/+/\//g;
4279:
1.359 albertel 4280: my $parentpath = '';
4281: my $lastitem = '';
4282: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4283: $parentpath = $1;
4284: $lastitem = $2;
4285: } else {
4286: $lastitem = $thisdisfn;
4287: }
4288: $titleinfo =
1.640 bisitz 4289: &Apache::loncommon::help_open_menu('','',3,'Authoring')
4290: .'<b>'.&mt('Construction Space').'</b>: '
4291: .'<form name="dirs" method="post" action="'.$formaction
1.359 albertel 4292: .'" target="_top"><tt><b>'
1.705 tempelho 4293: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."<span class=\"LC_fontsize_big\">$lastitem</span></b></tt><br />"
1.359 albertel 4294: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4295: .'</form>'
4296: .&Apache::lonmenu::constspaceform();
1.235 raeburn 4297: }
1.359 albertel 4298:
1.337 albertel 4299: my $titletable;
1.338 albertel 4300: if (!$notitle) {
1.337 albertel 4301: $titletable =
1.359 albertel 4302: '<table id="LC_title_bar">'.
4303: "<tr><td> $titleinfo $dc_info</td>".$roleinfo.
4304: '</tr></table>';
1.337 albertel 4305: }
1.359 albertel 4306: if ($notopbar) {
4307: $bodytag .= $titletable;
4308: } else {
4309: if ($env{'request.state'} eq 'construct') {
1.337 albertel 4310: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg,
4311: $titletable);
1.272 raeburn 4312: } else {
1.336 albertel 4313: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg).
1.359 albertel 4314: $titletable;
1.272 raeburn 4315: }
1.235 raeburn 4316: }
4317: return $bodytag;
1.94 www 4318: }
1.95 www 4319:
1.93 www 4320: #
1.95 www 4321: # Top frame rendering, Remote is up
1.93 www 4322: #
1.359 albertel 4323:
1.517 raeburn 4324: my $imgsrc = $img;
4325: if ($img =~ /^\/adm/) {
1.575 albertel 4326: $imgsrc = &lonhttpdurl($img);
1.517 raeburn 4327: }
4328: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359 albertel 4329:
1.305 www 4330: # Explicit link to get inline menu
1.361 albertel 4331: my $menu= ($no_inline_link?''
4332: :'<br /><a href="/adm/remote?action=collapse">'.&mt('Switch to Inline Menu Mode').'</a>');
1.245 matthew 4333: #
1.338 albertel 4334: if ($notitle) {
1.337 albertel 4335: return $bodytag;
4336: }
1.94 www 4337: return(<<ENDBODY);
1.60 matthew 4338: $bodytag
1.359 albertel 4339: <table id="LC_title_bar" class="LC_with_remote">
1.368 albertel 4340: <tr><td class="LC_title_bar_role_logo">$upperleft</td>
1.359 albertel 4341: <td class="LC_title_bar_domain_logo">$messages </td>
1.54 www 4342: </tr>
1.359 albertel 4343: <tr><td>$titleinfo $dc_info $menu</td>
4344: $roleinfo
1.368 albertel 4345: </tr>
1.356 albertel 4346: </table>
1.54 www 4347: ENDBODY
1.182 matthew 4348: }
4349:
1.330 albertel 4350: sub make_attr_string {
4351: my ($register,$attr_ref) = @_;
4352:
4353: if ($attr_ref && !ref($attr_ref)) {
4354: die("addentries Must be a hash ref ".
4355: join(':',caller(1))." ".
4356: join(':',caller(0))." ");
4357: }
4358:
4359: if ($register) {
1.339 albertel 4360: my ($on_load,$on_unload);
4361: foreach my $key (keys(%{$attr_ref})) {
4362: if (lc($key) eq 'onload') {
4363: $on_load.=$attr_ref->{$key}.';';
4364: delete($attr_ref->{$key});
4365:
4366: } elsif (lc($key) eq 'onunload') {
4367: $on_unload.=$attr_ref->{$key}.';';
4368: delete($attr_ref->{$key});
4369: }
4370: }
4371: $attr_ref->{'onload'} =
4372: &Apache::lonmenu::loadevents(). $on_load;
4373: $attr_ref->{'onunload'}=
4374: &Apache::lonmenu::unloadevents().$on_unload;
4375: }
4376:
4377: # Accessibility font enhance
4378: if ($env{'browser.fontenhance'} eq 'on') {
4379: my $style;
4380: foreach my $key (keys(%{$attr_ref})) {
4381: if (lc($key) eq 'style') {
4382: $style.=$attr_ref->{$key}.';';
4383: delete($attr_ref->{$key});
4384: }
4385: }
4386: $attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330 albertel 4387: }
1.339 albertel 4388:
4389: if ($env{'browser.blackwhite'} eq 'on') {
4390: delete($attr_ref->{'font'});
4391: delete($attr_ref->{'link'});
4392: delete($attr_ref->{'alink'});
4393: delete($attr_ref->{'vlink'});
4394: delete($attr_ref->{'bgcolor'});
4395: delete($attr_ref->{'background'});
4396: }
4397:
1.330 albertel 4398: my $attr_string;
4399: foreach my $attr (keys(%$attr_ref)) {
4400: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
4401: }
4402: return $attr_string;
4403: }
4404:
4405:
1.182 matthew 4406: ###############################################
1.251 albertel 4407: ###############################################
4408:
4409: =pod
4410:
4411: =item * &endbodytag()
4412:
4413: Returns a uniform footer for LON-CAPA web pages.
4414:
1.635 raeburn 4415: Inputs: 1 - optional reference to an args hash
4416: If in the hash, key for noredirectlink has a value which evaluates to true,
4417: a 'Continue' link is not displayed if the page contains an
4418: internal redirect in the <head></head> section,
4419: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 4420:
4421: =cut
4422:
4423: sub endbodytag {
1.635 raeburn 4424: my ($args) = @_;
1.251 albertel 4425: my $endbodytag='</body>';
1.269 albertel 4426: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 4427: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 4428: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
4429: $endbodytag=
4430: "<br /><a href=\"$env{'internal.head.redirect'}\">".
4431: &mt('Continue').'</a>'.
4432: $endbodytag;
4433: }
1.315 albertel 4434: }
1.251 albertel 4435: return $endbodytag;
4436: }
4437:
1.352 albertel 4438: =pod
4439:
4440: =item * &standard_css()
4441:
4442: Returns a style sheet
4443:
4444: Inputs: (all optional)
4445: domain -> force to color decorate a page for a specific
4446: domain
4447: function -> force usage of a specific rolish color scheme
4448: bgcolor -> override the default page bgcolor
4449:
4450: =cut
4451:
1.343 albertel 4452: sub standard_css {
1.345 albertel 4453: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 4454: $function = &get_users_function() if (!$function);
4455: my $img = &designparm($function.'.img', $domain);
4456: my $tabbg = &designparm($function.'.tabbg', $domain);
4457: my $font = &designparm($function.'.font', $domain);
1.345 albertel 4458: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 4459: my $pgbg_or_bgcolor =
4460: $bgcolor ||
1.352 albertel 4461: &designparm($function.'.pgbg', $domain);
1.382 albertel 4462: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 4463: my $alink = &designparm($function.'.alink', $domain);
4464: my $vlink = &designparm($function.'.vlink', $domain);
4465: my $link = &designparm($function.'.link', $domain);
4466:
1.704 muellerd 4467: my $loginbg = &designparm('login.sidebg',$domain);
1.712 muellerd 4468: my $bgcol = &designparm('login.bgcol',$domain);
4469: my $textcol = &designparm('login.textcol',$domain);
1.704 muellerd 4470:
1.602 albertel 4471: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 4472: my $mono = 'monospace';
1.352 albertel 4473: my $data_table_head = $tabbg;
4474: my $data_table_light = '#EEEEEE';
1.470 banghart 4475: my $data_table_dark = '#DDDDDD';
4476: my $data_table_darker = '#CCCCCC';
1.349 albertel 4477: my $data_table_highlight = '#FFFF00';
1.352 albertel 4478: my $mail_new = '#FFBB77';
4479: my $mail_new_hover = '#DD9955';
4480: my $mail_read = '#BBBB77';
4481: my $mail_read_hover = '#999944';
4482: my $mail_replied = '#AAAA88';
4483: my $mail_replied_hover = '#888855';
4484: my $mail_other = '#99BBBB';
4485: my $mail_other_hover = '#669999';
1.391 albertel 4486: my $table_header = '#DDDDDD';
1.489 raeburn 4487: my $feedback_link_bg = '#BBBBBB';
1.701 harmsja 4488: my $lg_border_color = '#C8C8C8';
1.392 albertel 4489:
1.608 albertel 4490: my $border = ($env{'browser.type'} eq 'explorer' ||
4491: $env{'browser.type'} eq 'safari' ) ? '0px 2px 0px 2px'
4492: : '0px 3px 0px 4px';
1.448 albertel 4493:
1.523 albertel 4494:
1.343 albertel 4495: return <<END;
1.698 harmsja 4496: body{
4497: font-family: $sans;
4498: line-height:130%;
1.701 harmsja 4499: font-size:0.83em;
1.698 harmsja 4500: color:$font;
4501: }
1.701 harmsja 4502: a:link, a:visited { font-size:100%; }
1.698 harmsja 4503:
1.343 albertel 4504: a:focus { color: red; background: yellow }
1.510 albertel 4505: table.thinborder,
4506: table.thinborder tr th {
4507: border-style: solid;
4508: border-width: 1px;
1.698 harmsja 4509: border-color: $lg_border_color;
1.510 albertel 4510: background: $tabbg;
4511: }
1.523 albertel 4512: table.thinborder tr td {
1.510 albertel 4513: border-style: solid;
1.698 harmsja 4514: border-width: 1px;
4515: border-color: $lg_border_color;
1.510 albertel 4516: }
1.426 albertel 4517:
1.343 albertel 4518: form, .inline { display: inline; }
1.721 harmsja 4519:
4520: .LC_center { text-align: center; }
4521: .LC_left { text-align:left; }
4522: .LC_right {text-align:right;}
4523: .LC_middle {vertical-align:middle;}
4524: .LC_top {vertical-align:top;}
4525: .LC_bottom {vertical-align:bottom;}
4526:
4527: /* just for tests */
4528: .LC_300Box { width:300px; }
1.753 ! droeschl 4529: .LC_200Box {width:200px; }
1.721 harmsja 4530: .LC_500Box {width:500px; }
4531: .LC_600Box {width:600px; }
1.741 harmsja 4532: .LC_800Box {width:800px;}
1.721 harmsja 4533: /* end */
4534:
1.593 albertel 4535: .LC_filename {font-family: $mono; white-space:pre;}
1.350 albertel 4536: .LC_error {
4537: color: red;
4538: font-size: larger;
4539: }
1.457 albertel 4540: .LC_warning,
4541: .LC_diff_removed {
1.733 bisitz 4542: color: red;
1.394 albertel 4543: }
1.532 albertel 4544:
4545: .LC_info,
1.457 albertel 4546: .LC_success,
4547: .LC_diff_added {
1.350 albertel 4548: color: green;
4549: }
1.543 albertel 4550: .LC_unknown {
4551: color: yellow;
4552: }
4553:
1.440 albertel 4554: .LC_icon {
4555: border: 0px;
4556: }
1.539 albertel 4557: .LC_indexer_icon {
4558: border: 0px;
4559: height: 22px;
4560: }
1.543 albertel 4561: .LC_docs_spacer {
4562: width: 25px;
4563: height: 1px;
4564: border: 0px;
4565: }
1.346 albertel 4566:
1.532 albertel 4567: .LC_internal_info {
1.735 bisitz 4568: color: #999999;
1.532 albertel 4569: }
4570:
1.458 albertel 4571: table.LC_pastsubmission {
4572: border: 1px solid black;
4573: margin: 2px;
4574: }
4575:
1.606 albertel 4576: table#LC_top_nav, table#LC_menubuttons,table#LC_nav_location {
1.345 albertel 4577: width: 100%;
4578: background: $pgbg;
1.392 albertel 4579: border: 2px;
1.402 albertel 4580: border-collapse: separate;
1.403 albertel 4581: padding: 0px;
1.345 albertel 4582: }
1.392 albertel 4583:
1.606 albertel 4584: table#LC_title_bar, table.LC_breadcrumbs,
1.393 albertel 4585: table#LC_title_bar.LC_with_remote {
1.359 albertel 4586: width: 100%;
1.392 albertel 4587: border-color: $pgbg;
4588: border-style: solid;
4589: border-width: $border;
4590:
1.379 albertel 4591: background: $pgbg;
4592: font-family: $sans;
1.392 albertel 4593: border-collapse: collapse;
1.403 albertel 4594: padding: 0px;
1.359 albertel 4595: }
1.409 albertel 4596: table.LC_docs_path {
4597: width: 100%;
4598: border: 0;
4599: background: $pgbg;
4600: font-family: $sans;
4601: border-collapse: collapse;
4602: padding: 0px;
4603: }
4604:
1.359 albertel 4605: table#LC_title_bar td {
4606: background: $tabbg;
4607: }
4608: table#LC_title_bar td.LC_title_bar_who {
4609: background: $tabbg;
4610: color: $font;
1.427 albertel 4611: font: small $sans;
1.359 albertel 4612: text-align: right;
4613: }
1.469 banghart 4614: span.LC_metadata {
4615: font-family: $sans;
4616: }
1.359 albertel 4617: span.LC_title_bar_title {
1.416 albertel 4618: font: bold x-large $sans;
1.359 albertel 4619: }
4620: table#LC_title_bar td.LC_title_bar_domain_logo {
4621: background: $sidebg;
4622: text-align: right;
1.368 albertel 4623: padding: 0px;
4624: }
4625: table#LC_title_bar td.LC_title_bar_role_logo {
4626: background: $sidebg;
4627: padding: 0px;
1.359 albertel 4628: }
4629:
1.706 harmsja 4630: table#LC_menubuttons img{
1.346 albertel 4631: border: 0px;
4632: }
1.345 albertel 4633: table#LC_top_nav td {
4634: background: $tabbg;
1.392 albertel 4635: border: 0px;
1.407 albertel 4636: font-size: small;
1.706 harmsja 4637: vertical-align:top;
4638: padding:2px 5px 2px 5px;
1.345 albertel 4639: }
4640: table#LC_top_nav td a, div#LC_top_nav a {
4641: color: $font;
4642: font-family: $sans;
4643: }
1.364 albertel 4644: table#LC_top_nav td.LC_top_nav_logo {
4645: background: $tabbg;
1.432 albertel 4646: text-align: left;
1.408 albertel 4647: white-space: nowrap;
1.432 albertel 4648: width: 31px;
1.408 albertel 4649: }
4650: table#LC_top_nav td.LC_top_nav_logo img {
1.432 albertel 4651: border: 0px;
1.408 albertel 4652: vertical-align: bottom;
1.364 albertel 4653: }
1.432 albertel 4654: table#LC_top_nav td.LC_top_nav_exit,
4655: table#LC_top_nav td.LC_top_nav_help {
4656: width: 2.0em;
4657: }
1.442 albertel 4658: table#LC_top_nav td.LC_top_nav_login {
4659: width: 4.0em;
4660: text-align: center;
4661: }
1.409 albertel 4662: table.LC_breadcrumbs td, table.LC_docs_path td {
1.357 albertel 4663: background: $tabbg;
4664: color: $font;
4665: font-family: $sans;
1.358 albertel 4666: font-size: smaller;
1.357 albertel 4667: }
1.411 albertel 4668: table.LC_breadcrumbs td.LC_breadcrumbs_component,
1.409 albertel 4669: table.LC_docs_path td.LC_docs_path_component {
1.357 albertel 4670: background: $tabbg;
4671: color: $font;
4672: font-family: $sans;
4673: font-size: larger;
4674: text-align: right;
4675: }
1.383 albertel 4676: td.LC_table_cell_checkbox {
4677: text-align: center;
4678: }
1.522 albertel 4679: table#LC_mainmenu td.LC_mainmenu_column {
4680: vertical-align: top;
4681: }
4682:
1.705 tempelho 4683: .LC_fontsize_small
4684: {
4685: font-size: 70%;
4686: }
4687:
4688: .LC_fontsize_medium
4689: {
4690: font-size: 85%;
4691: }
4692:
4693: .LC_fontsize_large
4694: {
4695: font-size: 120%;
4696: }
4697:
4698: .LC_fontcolor_red
4699: {
4700: color: #FF0000;
4701: }
4702:
1.346 albertel 4703: .LC_menubuttons_inline_text {
4704: color: $font;
4705: font-family: $sans;
1.698 harmsja 4706: font-size: 90%;
1.701 harmsja 4707: padding-left:3px;
1.346 albertel 4708: }
4709:
1.526 www 4710: .LC_menubuttons_link {
4711: text-decoration: none;
4712: }
1.698 harmsja 4713: /*2008--9-5: new menu style sheet.Changed category*/
1.522 albertel 4714: .LC_menubuttons_category {
1.521 www 4715: color: $font;
1.526 www 4716: background: $pgbg;
1.521 www 4717: font-family: $sans;
4718: font-size: larger;
4719: font-weight: bold;
4720: }
4721:
1.346 albertel 4722: td.LC_menubuttons_text {
1.701 harmsja 4723: color: $font;
1.346 albertel 4724: }
1.706 harmsja 4725:
4726:
1.526 www 4727:
1.346 albertel 4728: .LC_current_location {
4729: font-family: $sans;
4730: background: $tabbg;
4731: }
4732: .LC_new_mail {
4733: font-family: $sans;
1.634 www 4734: background: $tabbg;
1.346 albertel 4735: font-weight: bold;
4736: }
1.347 albertel 4737:
1.526 www 4738:
1.527 www 4739: .LC_dropadd_labeltext {
4740: font-family: $sans;
4741: text-align: right;
4742: }
4743:
4744: .LC_preferences_labeltext {
4745: font-family: $sans;
4746: text-align: right;
4747: }
4748:
1.666 raeburn 4749: .LC_roleslog_note {
1.701 harmsja 4750: font-size: small;
1.666 raeburn 4751: }
4752:
1.715 raeburn 4753: .LC_mail_functions {
4754: font-weight: bold;
4755: }
4756:
1.440 albertel 4757: table.LC_aboutme_port {
4758: border: 0px;
4759: border-collapse: collapse;
4760: border-spacing: 0px;
4761: }
1.349 albertel 4762: table.LC_data_table, table.LC_mail_list {
1.347 albertel 4763: border: 1px solid #000000;
1.402 albertel 4764: border-collapse: separate;
1.426 albertel 4765: border-spacing: 1px;
1.610 albertel 4766: background: $pgbg;
1.347 albertel 4767: }
1.422 albertel 4768: .LC_data_table_dense {
4769: font-size: small;
4770: }
1.507 raeburn 4771: table.LC_nested_outer {
4772: border: 1px solid #000000;
1.589 raeburn 4773: border-collapse: collapse;
1.507 raeburn 4774: border-spacing: 0px;
4775: width: 100%;
4776: }
4777: table.LC_nested {
4778: border: 0px;
1.589 raeburn 4779: border-collapse: collapse;
1.507 raeburn 4780: border-spacing: 0px;
4781: width: 100%;
4782: }
1.523 albertel 4783: table.LC_data_table tr th, table.LC_calendar tr th, table.LC_mail_list tr th,
4784: table.LC_prior_tries tr th {
1.349 albertel 4785: font-weight: bold;
4786: background-color: $data_table_head;
1.701 harmsja 4787: font-size:90%;
1.347 albertel 4788: }
1.711 raeburn 4789: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 4790: background-color: #CCCCCC;
1.711 raeburn 4791: font-weight: bold;
4792: text-align: left;
4793: }
1.610 albertel 4794: table.LC_data_table tr.LC_odd_row > td,
1.709 bisitz 4795: table.LC_pick_box tr > td.LC_odd_row,
1.440 albertel 4796: table.LC_aboutme_port tr td {
1.349 albertel 4797: background-color: $data_table_light;
1.425 albertel 4798: padding: 2px;
1.347 albertel 4799: }
1.610 albertel 4800: table.LC_data_table tr.LC_even_row > td,
1.709 bisitz 4801: table.LC_pick_box tr > td.LC_even_row,
1.440 albertel 4802: table.LC_aboutme_port tr.LC_even_row td {
1.349 albertel 4803: background-color: $data_table_dark;
1.709 bisitz 4804: padding: 2px;
1.347 albertel 4805: }
1.425 albertel 4806: table.LC_data_table tr.LC_data_table_highlight td {
4807: background-color: $data_table_darker;
4808: }
1.639 raeburn 4809: table.LC_data_table tr td.LC_leftcol_header {
4810: background-color: $data_table_head;
4811: font-weight: bold;
4812: }
1.451 albertel 4813: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 4814: table.LC_nested tr.LC_empty_row td {
1.347 albertel 4815: background-color: #FFFFFF;
1.421 albertel 4816: font-weight: bold;
4817: font-style: italic;
4818: text-align: center;
4819: padding: 8px;
1.347 albertel 4820: }
1.507 raeburn 4821: table.LC_nested tr.LC_empty_row td {
1.465 albertel 4822: padding: 4ex
4823: }
1.507 raeburn 4824: table.LC_nested_outer tr th {
4825: font-weight: bold;
4826: background-color: $data_table_head;
1.701 harmsja 4827: font-size: small;
1.507 raeburn 4828: border-bottom: 1px solid #000000;
4829: }
4830: table.LC_nested_outer tr td.LC_subheader {
4831: background-color: $data_table_head;
4832: font-weight: bold;
4833: font-size: small;
4834: border-bottom: 1px solid #000000;
4835: text-align: right;
1.451 albertel 4836: }
1.507 raeburn 4837: table.LC_nested tr.LC_info_row td {
1.735 bisitz 4838: background-color: #CCCCCC;
1.451 albertel 4839: font-weight: bold;
4840: font-size: small;
1.507 raeburn 4841: text-align: center;
4842: }
1.589 raeburn 4843: table.LC_nested tr.LC_info_row td.LC_left_item,
4844: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 4845: text-align: left;
1.451 albertel 4846: }
1.507 raeburn 4847: table.LC_nested td {
1.735 bisitz 4848: background-color: #FFFFFF;
1.451 albertel 4849: font-size: small;
1.507 raeburn 4850: }
4851: table.LC_nested_outer tr th.LC_right_item,
4852: table.LC_nested tr.LC_info_row td.LC_right_item,
4853: table.LC_nested tr.LC_odd_row td.LC_right_item,
4854: table.LC_nested tr td.LC_right_item {
1.451 albertel 4855: text-align: right;
4856: }
4857:
1.507 raeburn 4858: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 4859: background-color: #EEEEEE;
1.451 albertel 4860: }
4861:
1.473 raeburn 4862: table.LC_createuser {
4863: }
4864:
4865: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 4866: font-size: small;
1.473 raeburn 4867: }
4868:
4869: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 4870: background-color: #CCCCCC;
1.473 raeburn 4871: font-weight: bold;
4872: text-align: center;
4873: }
4874:
1.349 albertel 4875: table.LC_calendar {
4876: border: 1px solid #000000;
4877: border-collapse: collapse;
4878: }
4879: table.LC_calendar_pickdate {
4880: font-size: xx-small;
4881: }
4882: table.LC_calendar tr td {
4883: border: 1px solid #000000;
4884: vertical-align: top;
4885: }
4886: table.LC_calendar tr td.LC_calendar_day_empty {
4887: background-color: $data_table_dark;
4888: }
4889: table.LC_calendar tr td.LC_calendar_day_current {
4890: background-color: $data_table_highlight;
4891: }
4892:
4893: table.LC_mail_list tr.LC_mail_new {
4894: background-color: $mail_new;
4895: }
4896: table.LC_mail_list tr.LC_mail_new:hover {
4897: background-color: $mail_new_hover;
4898: }
4899: table.LC_mail_list tr.LC_mail_read {
4900: background-color: $mail_read;
4901: }
4902: table.LC_mail_list tr.LC_mail_read:hover {
4903: background-color: $mail_read_hover;
4904: }
4905: table.LC_mail_list tr.LC_mail_replied {
4906: background-color: $mail_replied;
4907: }
4908: table.LC_mail_list tr.LC_mail_replied:hover {
4909: background-color: $mail_replied_hover;
4910: }
4911: table.LC_mail_list tr.LC_mail_other {
4912: background-color: $mail_other;
4913: }
4914: table.LC_mail_list tr.LC_mail_other:hover {
4915: background-color: $mail_other_hover;
4916: }
1.494 raeburn 4917: table.LC_mail_list tr.LC_mail_even {
4918: }
4919: table.LC_mail_list tr.LC_mail_odd {
4920: }
4921:
1.696 bisitz 4922: table.LC_data_table tr > td.LC_browser_file,
4923: table.LC_data_table tr > td.LC_browser_file_published {
1.389 albertel 4924: background: #CCFF88;
4925: }
1.696 bisitz 4926: table.LC_data_table tr > td.LC_browser_file_locked,
4927: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 4928: background: #FFAA99;
1.387 albertel 4929: }
1.696 bisitz 4930: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.389 albertel 4931: background: #AAAAAA;
1.387 albertel 4932: }
1.696 bisitz 4933: table.LC_data_table tr > td.LC_browser_file_modified,
4934: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.389 albertel 4935: background: #FFFF77;
1.387 albertel 4936: }
1.696 bisitz 4937: table.LC_data_table tr.LC_browser_folder > td {
1.389 albertel 4938: background: #CCCCFF;
1.387 albertel 4939: }
1.696 bisitz 4940:
1.707 bisitz 4941: table.LC_data_table tr > td.LC_roles_is {
4942: /* background: #77FF77; */
4943: }
4944: table.LC_data_table tr > td.LC_roles_future {
4945: background: #FFFF77;
4946: }
4947: table.LC_data_table tr > td.LC_roles_will {
4948: background: #FFAA77;
4949: }
4950: table.LC_data_table tr > td.LC_roles_expired {
4951: background: #FF7777;
4952: }
4953: table.LC_data_table tr > td.LC_roles_will_not {
4954: background: #AAFF77;
4955: }
4956: table.LC_data_table tr > td.LC_roles_selected {
4957: background: #11CC55;
4958: }
4959:
1.388 albertel 4960: span.LC_current_location {
1.701 harmsja 4961: font-size:larger;
1.388 albertel 4962: background: $pgbg;
4963: }
1.387 albertel 4964:
1.395 albertel 4965: span.LC_parm_menu_item {
4966: font-size: larger;
4967: font-family: $sans;
4968: }
4969: span.LC_parm_scope_all {
4970: color: red;
4971: }
4972: span.LC_parm_scope_folder {
4973: color: green;
4974: }
4975: span.LC_parm_scope_resource {
4976: color: orange;
4977: }
4978: span.LC_parm_part {
4979: color: blue;
4980: }
4981: span.LC_parm_folder, span.LC_parm_symb {
4982: font-size: x-small;
4983: font-family: $mono;
4984: color: #AAAAAA;
4985: }
4986:
1.396 albertel 4987: td.LC_parm_overview_level_menu, td.LC_parm_overview_map_menu,
4988: td.LC_parm_overview_parm_selectors, td.LC_parm_overview_parm_restrictions {
4989: border: 1px solid black;
4990: border-collapse: collapse;
4991: }
4992: table.LC_parm_overview_restrictions td {
4993: border-width: 1px 4px 1px 4px;
4994: border-style: solid;
4995: border-color: $pgbg;
4996: text-align: center;
4997: }
4998: table.LC_parm_overview_restrictions th {
4999: background: $tabbg;
5000: border-width: 1px 4px 1px 4px;
5001: border-style: solid;
5002: border-color: $pgbg;
5003: }
1.398 albertel 5004: table#LC_helpmenu {
5005: border: 0px;
5006: height: 55px;
5007: border-spacing: 0px;
5008: }
5009:
5010: table#LC_helpmenu fieldset legend {
5011: font-size: larger;
5012: font-weight: bold;
5013: }
1.397 albertel 5014: table#LC_helpmenu_links {
5015: width: 100%;
5016: border: 1px solid black;
5017: background: $pgbg;
5018: padding: 0px;
5019: border-spacing: 1px;
5020: }
5021: table#LC_helpmenu_links tr td {
5022: padding: 1px;
5023: background: $tabbg;
1.399 albertel 5024: text-align: center;
5025: font-weight: bold;
1.397 albertel 5026: }
1.396 albertel 5027:
1.397 albertel 5028: table#LC_helpmenu_links a:link, table#LC_helpmenu_links a:visited,
5029: table#LC_helpmenu_links a:active {
5030: text-decoration: none;
5031: color: $font;
5032: }
5033: table#LC_helpmenu_links a:hover {
5034: text-decoration: underline;
5035: color: $vlink;
5036: }
1.396 albertel 5037:
1.417 albertel 5038: .LC_chrt_popup_exists {
5039: border: 1px solid #339933;
5040: margin: -1px;
5041: }
5042: .LC_chrt_popup_up {
5043: border: 1px solid yellow;
5044: margin: -1px;
5045: }
5046: .LC_chrt_popup {
5047: border: 1px solid #8888FF;
5048: background: #CCCCFF;
5049: }
1.421 albertel 5050: table.LC_pick_box {
5051: border-collapse: separate;
5052: background: white;
5053: border: 1px solid black;
5054: border-spacing: 1px;
5055: }
5056: table.LC_pick_box td.LC_pick_box_title {
5057: background: $tabbg;
5058: font-weight: bold;
5059: text-align: right;
1.740 bisitz 5060: vertical-align: top;
1.421 albertel 5061: width: 184px;
5062: padding: 8px;
5063: }
1.645 raeburn 5064: table.LC_pick_box td.LC_selfenroll_pick_box_title {
5065: background: $tabbg;
5066: font-weight: bold;
5067: text-align: right;
5068: width: 350px;
5069: padding: 8px;
5070: }
5071:
1.579 raeburn 5072: table.LC_pick_box td.LC_pick_box_value {
5073: text-align: left;
5074: padding: 8px;
5075: }
5076: table.LC_pick_box td.LC_pick_box_select {
5077: text-align: left;
5078: padding: 8px;
5079: }
1.424 albertel 5080: table.LC_pick_box td.LC_pick_box_separator {
1.421 albertel 5081: padding: 0px;
5082: height: 1px;
5083: background: black;
5084: }
5085: table.LC_pick_box td.LC_pick_box_submit {
5086: text-align: right;
5087: }
1.579 raeburn 5088: table.LC_pick_box td.LC_evenrow_value {
5089: text-align: left;
5090: padding: 8px;
5091: background-color: $data_table_light;
5092: }
5093: table.LC_pick_box td.LC_oddrow_value {
5094: text-align: left;
5095: padding: 8px;
5096: background-color: $data_table_light;
5097: }
5098: table.LC_helpform_receipt {
5099: width: 620px;
5100: border-collapse: separate;
5101: background: white;
5102: border: 1px solid black;
5103: border-spacing: 1px;
5104: }
5105: table.LC_helpform_receipt td.LC_pick_box_title {
5106: background: $tabbg;
5107: font-weight: bold;
5108: text-align: right;
5109: width: 184px;
5110: padding: 8px;
5111: }
5112: table.LC_helpform_receipt td.LC_evenrow_value {
5113: text-align: left;
5114: padding: 8px;
5115: background-color: $data_table_light;
5116: }
5117: table.LC_helpform_receipt td.LC_oddrow_value {
5118: text-align: left;
5119: padding: 8px;
5120: background-color: $data_table_light;
5121: }
5122: table.LC_helpform_receipt td.LC_pick_box_separator {
5123: padding: 0px;
5124: height: 1px;
5125: background: black;
5126: }
5127: span.LC_helpform_receipt_cat {
5128: font-weight: bold;
5129: }
1.424 albertel 5130: table.LC_group_priv_box {
5131: background: white;
5132: border: 1px solid black;
5133: border-spacing: 1px;
5134: }
5135: table.LC_group_priv_box td.LC_pick_box_title {
5136: background: $tabbg;
5137: font-weight: bold;
5138: text-align: right;
5139: width: 184px;
5140: }
5141: table.LC_group_priv_box td.LC_groups_fixed {
5142: background: $data_table_light;
5143: text-align: center;
5144: }
5145: table.LC_group_priv_box td.LC_groups_optional {
5146: background: $data_table_dark;
5147: text-align: center;
5148: }
5149: table.LC_group_priv_box td.LC_groups_functionality {
5150: background: $data_table_darker;
5151: text-align: center;
5152: font-weight: bold;
5153: }
5154: table.LC_group_priv td {
5155: text-align: left;
5156: padding: 0px;
5157: }
5158:
1.421 albertel 5159: table.LC_notify_front_page {
5160: background: white;
5161: border: 1px solid black;
5162: padding: 8px;
5163: }
5164: table.LC_notify_front_page td {
5165: padding: 8px;
5166: }
1.424 albertel 5167: .LC_navbuttons {
5168: margin: 2ex 0ex 2ex 0ex;
5169: }
1.423 albertel 5170: .LC_topic_bar {
5171: font-family: $sans;
5172: font-weight: bold;
5173: width: 100%;
5174: background: $tabbg;
5175: vertical-align: middle;
5176: margin: 2ex 0ex 2ex 0ex;
5177: }
5178: .LC_topic_bar span {
5179: vertical-align: middle;
5180: }
5181: .LC_topic_bar img {
5182: vertical-align: bottom;
5183: }
5184: table.LC_course_group_status {
5185: margin: 20px;
5186: }
5187: table.LC_status_selector td {
5188: vertical-align: top;
5189: text-align: center;
1.424 albertel 5190: padding: 4px;
5191: }
5192: table.LC_descriptive_input td.LC_description {
5193: vertical-align: top;
5194: text-align: right;
5195: font-weight: bold;
1.423 albertel 5196: }
1.599 albertel 5197: div.LC_feedback_link {
1.616 albertel 5198: clear: both;
1.599 albertel 5199: background: white;
5200: width: 100%;
1.489 raeburn 5201: }
5202: span.LC_feedback_link {
1.599 albertel 5203: background: $feedback_link_bg;
5204: font-size: larger;
5205: }
5206: span.LC_message_link {
5207: background: $feedback_link_bg;
5208: font-size: larger;
5209: position: absolute;
5210: right: 1em;
1.489 raeburn 5211: }
1.421 albertel 5212:
1.515 albertel 5213: table.LC_prior_tries {
1.524 albertel 5214: border: 1px solid #000000;
5215: border-collapse: separate;
5216: border-spacing: 1px;
1.515 albertel 5217: }
1.523 albertel 5218:
1.515 albertel 5219: table.LC_prior_tries td {
1.524 albertel 5220: padding: 2px;
1.515 albertel 5221: }
1.523 albertel 5222:
5223: .LC_answer_correct {
5224: background: #AAFFAA;
5225: color: black;
5226: }
5227: .LC_answer_charged_try {
5228: background: #FFAAAA ! important;
5229: color: black;
5230: }
5231: .LC_answer_not_charged_try,
5232: .LC_answer_no_grade,
5233: .LC_answer_late {
5234: background: #FFFFAA;
5235: color: black;
5236: }
5237: .LC_answer_previous {
5238: background: #AAAAFF;
5239: color: black;
5240: }
5241: .LC_answer_no_message {
5242: background: #FFFFFF;
5243: color: black;
5244: }
5245: .LC_answer_unknown {
5246: background: orange;
5247: color: black;
5248: }
5249:
5250:
1.529 albertel 5251: span.LC_prior_numerical,
5252: span.LC_prior_string,
5253: span.LC_prior_custom,
5254: span.LC_prior_reaction,
5255: span.LC_prior_math {
1.523 albertel 5256: font-family: monospace;
5257: white-space: pre;
5258: }
5259:
1.525 albertel 5260: span.LC_prior_string {
5261: font-family: monospace;
5262: white-space: pre;
5263: }
5264:
1.523 albertel 5265: table.LC_prior_option {
5266: width: 100%;
5267: border-collapse: collapse;
5268: }
1.528 albertel 5269: table.LC_prior_rank, table.LC_prior_match {
5270: border-collapse: collapse;
5271: }
5272: table.LC_prior_option tr td,
5273: table.LC_prior_rank tr td,
5274: table.LC_prior_match tr td {
1.524 albertel 5275: border: 1px solid #000000;
1.515 albertel 5276: }
5277:
1.519 raeburn 5278: span.LC_nobreak {
1.544 albertel 5279: white-space: nowrap;
1.519 raeburn 5280: }
5281:
1.576 raeburn 5282: span.LC_cusr_emph {
5283: font-style: italic;
5284: }
5285:
1.633 raeburn 5286: span.LC_cusr_subheading {
5287: font-weight: normal;
5288: font-size: 85%;
5289: }
5290:
1.545 albertel 5291: table.LC_docs_documents {
5292: background: #BBBBBB;
1.547 albertel 5293: border-width: 0px;
1.545 albertel 5294: border-collapse: collapse;
5295: }
5296:
5297: table.LC_docs_documents td.LC_docs_document {
5298: border: 2px solid black;
5299: padding: 4px;
5300: }
5301:
5302: .LC_docs_entry_move {
5303: border: 0px;
5304: border-collapse: collapse;
1.544 albertel 5305: }
5306:
1.545 albertel 5307: .LC_docs_entry_move td {
5308: border: 2px solid #BBBBBB;
5309: background: #DDDDDD;
5310: }
5311:
5312: .LC_docs_editor td.LC_docs_entry_commands {
5313: background: #DDDDDD;
5314: font-size: x-small;
5315: }
1.544 albertel 5316: .LC_docs_copy {
1.545 albertel 5317: color: #000099;
1.544 albertel 5318: }
5319: .LC_docs_cut {
1.545 albertel 5320: color: #550044;
1.544 albertel 5321: }
5322: .LC_docs_rename {
1.545 albertel 5323: color: #009900;
1.544 albertel 5324: }
5325: .LC_docs_remove {
1.545 albertel 5326: color: #990000;
5327: }
5328:
1.547 albertel 5329: .LC_docs_reinit_warn,
5330: .LC_docs_ext_edit {
5331: font-size: x-small;
5332: }
5333:
1.545 albertel 5334: .LC_docs_editor td.LC_docs_entry_title,
5335: .LC_docs_editor td.LC_docs_entry_icon {
5336: background: #FFFFBB;
5337: }
5338: .LC_docs_editor td.LC_docs_entry_parameter {
5339: background: #BBBBFF;
5340: font-size: x-small;
5341: white-space: nowrap;
5342: }
5343:
5344: table.LC_docs_adddocs td,
5345: table.LC_docs_adddocs th {
5346: border: 1px solid #BBBBBB;
5347: padding: 4px;
5348: background: #DDDDDD;
1.543 albertel 5349: }
5350:
1.584 albertel 5351: table.LC_sty_begin {
5352: background: #BBFFBB;
5353: }
5354: table.LC_sty_end {
5355: background: #FFBBBB;
5356: }
5357:
1.589 raeburn 5358: table.LC_double_column {
5359: border-width: 0px;
5360: border-collapse: collapse;
5361: width: 100%;
5362: padding: 2px;
5363: }
5364:
5365: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 5366: top: 2px;
1.589 raeburn 5367: left: 2px;
5368: width: 47%;
5369: vertical-align: top;
5370: }
5371:
5372: table.LC_double_column tr td.LC_right_col {
5373: top: 2px;
5374: right: 2px;
5375: width: 47%;
5376: vertical-align: top;
5377: }
5378:
1.594 raeburn 5379: span.LC_role_level {
5380: font-weight: bold;
5381: }
5382:
1.591 raeburn 5383: div.LC_left_float {
5384: float: left;
5385: padding-right: 5%;
1.597 albertel 5386: padding-bottom: 4px;
1.591 raeburn 5387: }
5388:
5389: div.LC_clear_float_header {
1.597 albertel 5390: padding-bottom: 2px;
1.591 raeburn 5391: }
5392:
5393: div.LC_clear_float_footer {
1.597 albertel 5394: padding-top: 10px;
1.591 raeburn 5395: clear: both;
5396: }
5397:
1.597 albertel 5398:
5399: div.LC_grade_show_user {
5400: margin-top: 20px;
5401: border: 1px solid black;
5402: }
5403: div.LC_grade_user_name {
5404: background: #DDDDEE;
5405: border-bottom: 1px solid black;
1.705 tempelho 5406: font-weight: bold;
5407: font-size: large;
1.597 albertel 5408: }
5409: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
5410: background: #DDEEDD;
5411: }
5412:
5413: div.LC_grade_show_problem,
5414: div.LC_grade_submissions,
5415: div.LC_grade_message_center,
5416: div.LC_grade_info_links,
5417: div.LC_grade_assign {
5418: margin: 5px;
5419: width: 99%;
5420: background: #FFFFFF;
5421: }
5422: div.LC_grade_show_problem_header,
5423: div.LC_grade_submissions_header,
5424: div.LC_grade_message_center_header,
5425: div.LC_grade_assign_header {
1.705 tempelho 5426: font-weight: bold;
5427: font-size: large;
1.597 albertel 5428: }
5429: div.LC_grade_show_problem_problem,
5430: div.LC_grade_submissions_body,
5431: div.LC_grade_message_center_body,
5432: div.LC_grade_assign_body {
5433: border: 1px solid black;
5434: width: 99%;
5435: background: #FFFFFF;
5436: }
1.598 albertel 5437: span.LC_grade_check_note {
1.705 tempelho 5438: font-weight: normal;
5439: font-size: medium;
1.598 albertel 5440: display: inline;
5441: position: absolute;
5442: right: 1em;
5443: }
1.597 albertel 5444:
1.613 albertel 5445: table.LC_scantron_action {
5446: width: 100%;
5447: }
5448: table.LC_scantron_action tr th {
1.698 harmsja 5449: font-weight:bold;
5450: font-style:normal;
1.613 albertel 5451: }
1.698 harmsja 5452: .LC_edit_problem_header,
1.614 albertel 5453: div.LC_edit_problem_footer {
1.705 tempelho 5454: font-weight: normal;
5455: font-size: medium;
1.602 albertel 5456: margin: 2px;
1.600 albertel 5457: }
5458: div.LC_edit_problem_header,
1.602 albertel 5459: div.LC_edit_problem_header div,
1.614 albertel 5460: div.LC_edit_problem_footer,
5461: div.LC_edit_problem_footer div,
1.602 albertel 5462: div.LC_edit_problem_editxml_header,
5463: div.LC_edit_problem_editxml_header div {
1.600 albertel 5464: margin-top: 5px;
5465: }
1.602 albertel 5466: div.LC_edit_problem_header_edit_row {
5467: background: $tabbg;
5468: padding: 3px;
5469: margin-bottom: 5px;
5470: }
1.600 albertel 5471: div.LC_edit_problem_header_title {
1.705 tempelho 5472: font-weight: bold;
5473: font-size: larger;
1.602 albertel 5474: background: $tabbg;
5475: padding: 3px;
5476: }
5477: table.LC_edit_problem_header_title {
1.705 tempelho 5478: font-size: larger;
5479: font-weight: bold;
1.602 albertel 5480: width: 100%;
5481: border-color: $pgbg;
5482: border-style: solid;
5483: border-width: $border;
5484:
1.600 albertel 5485: background: $tabbg;
1.602 albertel 5486: border-collapse: collapse;
5487: padding: 0px
5488: }
5489:
5490: div.LC_edit_problem_discards {
5491: float: left;
5492: padding-bottom: 5px;
5493: }
5494: div.LC_edit_problem_saves {
5495: float: right;
5496: padding-bottom: 5px;
1.600 albertel 5497: }
5498: hr.LC_edit_problem_divide {
1.602 albertel 5499: clear: both;
1.600 albertel 5500: color: $tabbg;
5501: background-color: $tabbg;
5502: height: 3px;
5503: border: 0px;
5504: }
1.679 riegler 5505: img.stift{
1.678 riegler 5506: border-width:0;
1.679 riegler 5507: vertical-align:middle;
1.677 riegler 5508: }
1.680 riegler 5509:
1.681 riegler 5510: table#LC_mainmenu{
5511: margin-top:10px;
5512: width:80%;
5513:
5514: }
5515:
1.680 riegler 5516: table#LC_mainmenu td.LC_mainmenu_col_fieldset{
5517: vertical-align: top;
5518: width: 45%;
5519: }
5520: .LC_mainmenu_fieldset_category {
5521: color: $font;
5522: background: $pgbg;
5523: font-family: $sans;
5524: font-size: small;
5525: font-weight: bold;
5526: }
5527:
1.716 raeburn 5528: div.LC_createcourse {
5529: margin: 10px 10px 10px 10px;
5530: }
5531:
1.693 droeschl 5532: /* ---- Remove when done ----
5533: # The following styles is part of the redesign of LON-CAPA and are
5534: # subject to change during this project.
5535: # Don't rely on their current functionality as they might be
5536: # changed or removed.
5537: # --------------------------*/
5538:
1.698 harmsja 5539: a:hover,
1.721 harmsja 5540: ol.LC_smallMenu a:hover,
5541: ol#LC_MenuBreadcrumbs a:hover,
5542: ol#LC_PathBreadcrumbs a:hover,
5543: ul#LC_TabMainMenuContent a:hover,
5544: .LC_FormSectionClearButton input:hover
5545: ul.LC_TabContent li:hover a{
1.698 harmsja 5546: color:#BF2317;
5547: text-decoration:none;
1.693 droeschl 5548: }
5549:
5550: h1 {
1.721 harmsja 5551: padding:5px 10px 5px 20px;
1.693 droeschl 5552: line-height:130%;
5553: }
1.698 harmsja 5554:
1.693 droeschl 5555: h2,h3,h4,h5,h6
5556: {
1.721 harmsja 5557: margin:5px 0px 5px 0px;
5558: padding:0px;
5559: line-height:130%;
1.693 droeschl 5560: }
1.721 harmsja 5561: .LC_hcell{
1.698 harmsja 5562: padding:3px 15px 3px 15px;
5563: margin:0px;
1.703 harmsja 5564: background-color:$tabbg;
5565: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 5566: }
1.721 harmsja 5567: .LC_noBorder {
1.698 harmsja 5568: border:0px;
5569: }
1.693 droeschl 5570:
1.722 harmsja 5571: .LC_bgLightGrey{
1.741 harmsja 5572: background:URL(/adm/lonIcons/lightGreyBG.png) repeat-x left bottom;
1.722 harmsja 5573: }
1.741 harmsja 5574:
1.693 droeschl 5575:
1.698 harmsja 5576: /* Main Header with discription of Person, Course, etc. */
1.721 harmsja 5577: .LC_HeadRight {
1.693 droeschl 5578: text-align: right;
5579: float: right;
5580: margin: 0px;
5581: padding: 0px;
1.698 harmsja 5582: right:0;
1.693 droeschl 5583: position:absolute;
1.698 harmsja 5584: overflow:hidden;
1.693 droeschl 5585: }
5586:
1.721 harmsja 5587: p, .LC_ContentBox {
1.698 harmsja 5588: padding: 10px;
5589:
5590: }
1.721 harmsja 5591: .LC_FormSectionClearButton input {
1.741 harmsja 5592: background-color:transparent;
1.698 harmsja 5593: border:0px;
5594: cursor:pointer;
5595: text-decoration:underline;
1.693 droeschl 5596: }
5597:
5598:
1.698 harmsja 5599: dl,ul,div,fieldset {
5600: margin: 10px 10px 10px 0px;
1.693 droeschl 5601: overflow:hidden;
5602: }
1.721 harmsja 5603: ol.LC_smallMenu, ol#LC_PathBreadcrumbs {
1.698 harmsja 5604: margin: 0px;
1.693 droeschl 5605: }
5606:
1.721 harmsja 5607: ol.LC_smallMenu li {
1.693 droeschl 5608: display: inline;
5609: padding: 5px 5px 0px 10px;
5610: vertical-align: top;
5611: }
5612:
1.721 harmsja 5613: ol.LC_smallMenu li img {
1.693 droeschl 5614: vertical-align: bottom;
5615: }
5616:
1.721 harmsja 5617: ol.LC_smallMenu a {
1.693 droeschl 5618: font-size: 90%;
5619: color: RGB(80, 80, 80);
5620: text-decoration: none;
5621: }
1.744 ehlerst 5622: ol#LC_TabMainMenueContent, ul.LC_TabContent ,
1.741 harmsja 5623: ul.LC_TabContentBigger {
1.721 harmsja 5624: display:block;
5625: list-style:none;
1.741 harmsja 5626: margin: 0px;
1.693 droeschl 5627: padding: 0px;
5628: }
5629:
1.744 ehlerst 5630: ol#LC_TabMainMenuContent li, ul.LC_TabContent li,
1.741 harmsja 5631: ul.LC_TabContentBigger li{
1.693 droeschl 5632: display: inline;
1.741 harmsja 5633: border-right: solid 1px $lg_border_color;
5634: float:left;
5635: line-height:140%;
5636: white-space:nowrap;
5637: }
5638: ol#LC_TabMainMenuContent li{
1.693 droeschl 5639: vertical-align: bottom;
5640: border-bottom: solid 1px RGB(175, 175, 175);
1.721 harmsja 5641: padding: 5px 10px 5px 10px;
1.741 harmsja 5642: margin-right:5px;
5643: margin-bottom:3px;
1.693 droeschl 5644: font-weight: bold;
1.723 riegler 5645: background: url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
1.693 droeschl 5646: }
5647:
1.721 harmsja 5648: ol#LC_TabMainMenuContent li a{
1.693 droeschl 5649: color: RGB(47, 47, 47);
5650: text-decoration: none;
5651: }
1.721 harmsja 5652: ul.LC_TabContent {
1.741 harmsja 5653: min-height:1.6em;
1.721 harmsja 5654: }
5655: ul.LC_TabContent li{
1.741 harmsja 5656: vertical-align:middle;
5657: padding:0px 10px 0px 10px;
1.745 ehlerst 5658: background-color:$tabbg;
5659: border-bottom:solid 1px $lg_border_color;
1.721 harmsja 5660: }
1.744 ehlerst 5661: ul.LC_TabContent li a, ul.LC_TabContent li{
1.721 harmsja 5662: color:rgb(47,47,47);
5663: text-decoration:none;
5664: font-size:95%;
5665: font-weight:bold;
5666: }
1.744 ehlerst 5667: ul.LC_TabContent li:hover, ul.LC_TabContent li.active{
5668: background-color:#FFFFFF;
1.745 ehlerst 5669: border-bottom:solid 1px #FFFFFF;
1.744 ehlerst 5670: }
1.741 harmsja 5671: ul.LC_TabContentBigger li{
5672: vertical-align:bottom;
5673: border-top:solid 1px $lg_border_color;
5674: border-left:solid 1px $lg_border_color;
5675: padding:5px 10px 5px 10px;
5676: margin-left:2px;
5677: background:url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
5678: }
1.744 ehlerst 5679: ul.LC_TabContentBigger li:hover, ul.LC_TabContentBigger li.active{
5680: background:url(/adm/lonIcons/lightGreyBG.png) repeat-x right bottom;
5681: }
1.741 harmsja 5682: ul.LC_TabContentBigger li, ul.LC_TabContentBigger li a{
5683: font-size:110%;
5684: font-weight:bold;
5685: }
5686: #LC_CourseDocuments, #LC_SupplementalCourseDocuments
5687: {
5688: margin:0px;
1.737 tempelho 5689: }
5690:
1.721 harmsja 5691: .LC_hideThis
5692: {
5693: display:none;
5694: visibility:hidden;
1.693 droeschl 5695: }
5696:
1.721 harmsja 5697: ol#LC_MenuBreadcrumbs, ol#LC_PathBreadcrumbs {
1.693 droeschl 5698: border-top: solid 1px RGB(255, 255, 255);
5699: height: 20px;
5700: line-height: 20px;
5701: vertical-align: bottom;
5702: margin: 0px 0px 30px 0px;
5703: padding-left: 10px;
5704: list-style-position: inside;
1.723 riegler 5705: background: url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
1.693 droeschl 5706: }
5707:
1.721 harmsja 5708: ol#LC_MenuBreadcrumbs li, ol#LC_PathBreadcrumbs li {
1.741 harmsja 5709: /*
1.723 riegler 5710: background: url(/adm/lonIcons/arrow_white.png) no-repeat left center;
1.741 harmsja 5711: */
1.693 droeschl 5712: display: inline;
5713: padding: 0px 0px 0px 10px;
5714: vertical-align: bottom;
5715: overflow:hidden;
5716: }
5717:
1.721 harmsja 5718: ol#LC_MenuBreadcrumbs li a {
1.693 droeschl 5719: text-decoration: none;
5720: font-size:90%;
5721: }
1.721 harmsja 5722: ol#LC_PathBreadcrumbs li a{
1.698 harmsja 5723: text-decoration:none;
5724: font-size:100%;
5725: font-weight:bold;
1.693 droeschl 5726: }
1.721 harmsja 5727: .LC_ContentBoxSpecial
1.693 droeschl 5728: {
1.701 harmsja 5729: border: solid 1px $lg_border_color;
1.746 neumanie 5730: }
5731: .LC_ContentBoxSpecialContactInfo
5732: {
5733: border: solid 1px $lg_border_color;
5734: max-width:25%;
5735: min-width:25%;
1.698 harmsja 5736: }
1.747 neumanie 5737: .LC_AboutMe_Image
5738: {
5739: float:left;
5740: margin-right:10px;
5741: }
5742: .LC_Clear_AboutMe_Image
5743: {
5744: clear:left;
5745: }
1.721 harmsja 5746: dl.LC_ListStyleClean dt {
1.693 droeschl 5747: padding-right: 5px;
5748: display: table-header-group;
5749: }
5750:
1.721 harmsja 5751: dl.LC_ListStyleClean dd {
1.693 droeschl 5752: display: table-row;
5753: }
5754:
1.721 harmsja 5755: .LC_ListStyleClean,
5756: .LC_ListStyleSimple,
5757: .LC_ListStyleNormal,
5758: .LC_ListStyleNormal_Border,
5759: .LC_ListStyleSpecial
1.693 droeschl 5760: {
5761: /*display:block; */
5762: list-style-position: inside;
5763: list-style-type: none;
5764: overflow: hidden;
5765: padding: 0px;
5766: }
5767:
1.721 harmsja 5768: .LC_ListStyleSimple li,
5769: .LC_ListStyleSimple dd,
5770: .LC_ListStyleNormal li,
5771: .LC_ListStyleNormal dd,
5772: .LC_ListStyleSpecial li,
5773: .LC_ListStyleSpecial dd
1.693 droeschl 5774: {
5775: margin: 0px;
5776: padding: 5px 5px 5px 10px;
5777: clear: both;
5778: }
5779:
1.721 harmsja 5780: .LC_ListStyleClean li,
5781: .LC_ListStyleClean dd {
1.693 droeschl 5782: padding-top: 0px;
5783: padding-bottom: 0px;
5784: }
5785:
1.721 harmsja 5786: .LC_ListStyleSimple dd,
5787: .LC_ListStyleSimple li{
1.698 harmsja 5788: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 5789: }
5790:
1.721 harmsja 5791: .LC_ListStyleSpecial li,
5792: .LC_ListStyleSpecial dd {
1.693 droeschl 5793: list-style-type: none;
5794: background-color: RGB(220, 220, 220);
5795: margin-bottom: 4px;
5796: }
5797:
1.721 harmsja 5798: table.LC_SimpleTable {
1.698 harmsja 5799: margin:5px;
5800: border:solid 1px $lg_border_color;
1.693 droeschl 5801: }
5802:
1.721 harmsja 5803: table.LC_SimpleTable tr {
1.698 harmsja 5804: padding:0px;
5805: border:solid 1px $lg_border_color;
1.693 droeschl 5806: }
1.721 harmsja 5807: table.LC_SimpleTable thead{
1.698 harmsja 5808: background:rgb(220,220,220);
1.693 droeschl 5809: }
5810:
1.721 harmsja 5811: div.LC_columnSection {
1.693 droeschl 5812: display: block;
5813: clear: both;
5814: overflow: hidden;
5815: margin:0px;
5816: }
5817:
1.721 harmsja 5818: div.LC_columnSection>* {
1.693 droeschl 5819: float: left;
5820: margin: 10px 20px 10px 0px;
1.747 neumanie 5821: overflow:hidden;
1.693 droeschl 5822: }
1.753 ! droeschl 5823: div.LC_columnSection > .LC_ContentBox,
! 5824: div.LC_columnSection > .LC_ContentBoxSpecial
! 5825: {
! 5826: width: 400px;
! 5827: }
1.721 harmsja 5828:
1.719 ehlerst 5829: .ContentBoxSpecialTemplate
5830: {
1.747 neumanie 5831: border: solid 1px $lg_border_color;
1.719 ehlerst 5832: }
5833: .ContentBoxTemplate {
5834: padding:10px;
5835: }
5836:
1.721 harmsja 5837: div.LC_columnSection > .ContentBoxTemplate,
5838: div.LC_columnSection > .ContentBoxSpecialTemplate
1.719 ehlerst 5839: {
5840: width: 600px;
1.753 ! droeschl 5841:
1.719 ehlerst 5842: }
1.753 ! droeschl 5843:
1.720 ehlerst 5844: .clear{
5845: clear: both;
5846: line-height: 0px;
5847: font-size: 0px;
5848: height: 0px;
5849: }
1.693 droeschl 5850:
1.694 tempelho 5851: .LC_loginpage_container {
5852: text-align:left;
5853: margin : 0 auto;
5854: width:65%;
5855: padding: 10px;
5856: height: auto;
1.712 muellerd 5857: background-color:#FFFFFF;
1.694 tempelho 5858: border:1px solid #CCCCCC;
5859: }
5860:
5861:
5862: .LC_loginpage_loginContainer {
5863: float:left;
1.712 muellerd 5864: width: 182px;
5865: border:1px solid #CCCCCC;
5866: background-color:$loginbg;
1.694 tempelho 5867: }
5868:
1.717 tempelho 5869: .LC_loginpage_loginContainer h2{
1.712 muellerd 5870: margin-top:0;
5871: display:block;
5872: background:$bgcol;
5873: color:$textcol;
5874: padding-left:5px;
5875: }
1.694 tempelho 5876: .LC_loginpage_loginInfo {
5877: margin-left:20px;
5878: float:left;
5879: width:30%;
5880: border:1px solid #CCCCCC;
5881: padding:10px;
5882: }
5883:
1.712 muellerd 5884: .LC_loginpage_loginDomain {
5885: margin-right:20px;
5886: width:20%;
5887: float:left;
5888: padding:10px;
5889: }
5890:
1.694 tempelho 5891: .LC_loginpage_space {
5892: clear:both;
5893: margin-bottom:20px;
5894: border-bottom: 1px solid #CCCCCC;
5895: }
5896:
1.748 schulted 5897: table em{
5898: font-weight:bold;
5899: font-style:normal;
5900: }
5901:
1.753 ! droeschl 5902: table#LC_tableOfContent{
! 5903: border-collapse: collapse;
! 5904: border-spacing:0;
! 5905: padding:3px;
! 5906: border:0;
! 5907: background-color:#ffffff;
! 5908: font-size:90%;
! 5909: }
! 5910: table#LC_tableOfContent a {
! 5911: text-decoration: none;
! 5912: }
! 5913:
! 5914: table#LC_tableOfContent tr.LC_trOdd{
! 5915: background-color:#eeeeee;
! 5916: }
! 5917:
! 5918: table#LC_tableOfContent img{
! 5919: border: none;
! 5920: height: 1.3em;
! 5921: vertical-align: text-bottom;
! 5922: margin-right: 0.3em;
! 5923: }
1.343 albertel 5924: END
5925: }
5926:
1.306 albertel 5927: =pod
5928:
5929: =item * &headtag()
5930:
5931: Returns a uniform footer for LON-CAPA web pages.
5932:
1.307 albertel 5933: Inputs: $title - optional title for the head
5934: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 5935: $args - optional arguments
1.319 albertel 5936: force_register - if is true call registerurl so the remote is
5937: informed
1.415 albertel 5938: redirect -> array ref of
5939: 1- seconds before redirect occurs
5940: 2- url to redirect to
5941: 3- whether the side effect should occur
1.315 albertel 5942: (side effect of setting
5943: $env{'internal.head.redirect'} to the url
5944: redirected too)
1.352 albertel 5945: domain -> force to color decorate a page for a specific
5946: domain
5947: function -> force usage of a specific rolish color scheme
5948: bgcolor -> override the default page bgcolor
1.460 albertel 5949: no_auto_mt_title
5950: -> prevent &mt()ing the title arg
1.464 albertel 5951:
1.306 albertel 5952: =cut
5953:
5954: sub headtag {
1.313 albertel 5955: my ($title,$head_extra,$args) = @_;
1.306 albertel 5956:
1.363 albertel 5957: my $function = $args->{'function'} || &get_users_function();
5958: my $domain = $args->{'domain'} || &determinedomain();
5959: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 5960: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 5961: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 5962: #time(),
1.418 albertel 5963: $env{'environment.color.timestamp'},
1.363 albertel 5964: $function,$domain,$bgcolor);
5965:
1.369 www 5966: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 5967:
1.308 albertel 5968: my $result =
5969: '<head>'.
1.461 albertel 5970: &font_settings();
1.319 albertel 5971:
1.461 albertel 5972: if (!$args->{'frameset'}) {
5973: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
5974: }
1.319 albertel 5975: if ($args->{'force_register'}) {
5976: $result .= &Apache::lonmenu::registerurl(1);
5977: }
1.436 albertel 5978: if (!$args->{'no_nav_bar'}
5979: && !$args->{'only_body'}
5980: && !$args->{'frameset'}) {
5981: $result .= &help_menu_js();
5982: }
1.319 albertel 5983:
1.314 albertel 5984: if (ref($args->{'redirect'})) {
1.414 albertel 5985: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 5986: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 5987: if (!$inhibit_continue) {
5988: $env{'internal.head.redirect'} = $url;
5989: }
1.313 albertel 5990: $result.=<<ADDMETA
5991: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 5992: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 5993: ADDMETA
5994: }
1.306 albertel 5995: if (!defined($title)) {
5996: $title = 'The LearningOnline Network with CAPA';
5997: }
1.460 albertel 5998: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
5999: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 6000: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
6001: .$head_extra;
1.306 albertel 6002: return $result;
6003: }
6004:
6005: =pod
6006:
1.340 albertel 6007: =item * &font_settings()
6008:
6009: Returns neccessary <meta> to set the proper encoding
6010:
6011: Inputs: none
6012:
6013: =cut
6014:
6015: sub font_settings {
6016: my $headerstring='';
1.647 www 6017: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 6018: $headerstring.=
6019: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
6020: }
6021: return $headerstring;
6022: }
6023:
1.341 albertel 6024: =pod
6025:
6026: =item * &xml_begin()
6027:
6028: Returns the needed doctype and <html>
6029:
6030: Inputs: none
6031:
6032: =cut
6033:
6034: sub xml_begin {
6035: my $output='';
6036:
1.592 albertel 6037: if ($env{'internal.start_page'}==1) {
6038: &Apache::lonhtmlcommon::init_htmlareafields();
6039: }
1.342 albertel 6040:
1.341 albertel 6041: if ($env{'browser.mathml'}) {
6042: $output='<?xml version="1.0"?>'
6043: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
6044: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
6045:
6046: # .'<!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">] >'
6047: .'<!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">'
6048: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
6049: .'xmlns="http://www.w3.org/1999/xhtml">';
6050: } else {
6051: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>';
6052: }
6053: return $output;
6054: }
1.340 albertel 6055:
6056: =pod
6057:
1.306 albertel 6058: =item * &endheadtag()
6059:
6060: Returns a uniform </head> for LON-CAPA web pages.
6061:
6062: Inputs: none
6063:
6064: =cut
6065:
6066: sub endheadtag {
6067: return '</head>';
6068: }
6069:
6070: =pod
6071:
6072: =item * &head()
6073:
6074: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
6075:
1.648 raeburn 6076: Inputs:
6077:
6078: =over 4
6079:
6080: $title - optional title for the page
6081:
6082: $head_extra - optional extra HTML to put inside the <head>
6083:
6084: =back
1.405 albertel 6085:
1.306 albertel 6086: =cut
6087:
6088: sub head {
1.325 albertel 6089: my ($title,$head_extra,$args) = @_;
6090: return &headtag($title,$head_extra,$args).&endheadtag();
1.306 albertel 6091: }
6092:
6093: =pod
6094:
6095: =item * &start_page()
6096:
6097: Returns a complete <html> .. <body> section for LON-CAPA web pages.
6098:
1.648 raeburn 6099: Inputs:
6100:
6101: =over 4
6102:
6103: $title - optional title for the page
6104:
6105: $head_extra - optional extra HTML to incude inside the <head>
6106:
6107: $args - additional optional args supported are:
6108:
6109: =over 8
6110:
6111: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 6112: arg on
1.648 raeburn 6113: no_nav_bar -> is true will set &bodytag() notopbar arg on
6114: add_entries -> additional attributes to add to the <body>
6115: domain -> force to color decorate a page for a
1.317 albertel 6116: specific domain
1.648 raeburn 6117: function -> force usage of a specific rolish color
1.317 albertel 6118: scheme
1.648 raeburn 6119: redirect -> see &headtag()
6120: bgcolor -> override the default page bg color
6121: js_ready -> return a string ready for being used in
1.317 albertel 6122: a javascript writeln
1.648 raeburn 6123: html_encode -> return a string ready for being used in
1.320 albertel 6124: a html attribute
1.648 raeburn 6125: force_register -> if is true will turn on the &bodytag()
1.317 albertel 6126: $forcereg arg
1.648 raeburn 6127: body_title -> alternate text to use instead of $title
1.326 albertel 6128: in the title box that appears, this text
6129: is not auto translated like the $title is
1.648 raeburn 6130: frameset -> if true will start with a <frameset>
1.330 albertel 6131: rather than <body>
1.648 raeburn 6132: no_title -> if true the title bar won't be shown
6133: skip_phases -> hash ref of
1.338 albertel 6134: head -> skip the <html><head> generation
6135: body -> skip all <body> generation
1.648 raeburn 6136: no_inline_link -> if true and in remote mode, don't show the
1.361 albertel 6137: 'Switch To Inline Menu' link
1.648 raeburn 6138: no_auto_mt_title -> prevent &mt()ing the title arg
6139: inherit_jsmath -> when creating popup window in a page,
6140: should it have jsmath forced on by the
6141: current page
1.361 albertel 6142:
1.648 raeburn 6143: =back
1.460 albertel 6144:
1.648 raeburn 6145: =back
1.562 albertel 6146:
1.306 albertel 6147: =cut
6148:
6149: sub start_page {
1.309 albertel 6150: my ($title,$head_extra,$args) = @_;
1.318 albertel 6151: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313 albertel 6152: my %head_args;
1.352 albertel 6153: foreach my $arg ('redirect','force_register','domain','function',
1.460 albertel 6154: 'bgcolor','frameset','no_nav_bar','only_body',
6155: 'no_auto_mt_title') {
1.319 albertel 6156: if (defined($args->{$arg})) {
1.324 raeburn 6157: $head_args{$arg} = $args->{$arg};
1.319 albertel 6158: }
1.313 albertel 6159: }
1.319 albertel 6160:
1.315 albertel 6161: $env{'internal.start_page'}++;
1.338 albertel 6162: my $result;
6163: if (! exists($args->{'skip_phases'}{'head'}) ) {
6164: $result.=
1.341 albertel 6165: &xml_begin().
1.338 albertel 6166: &headtag($title,$head_extra,\%head_args).&endheadtag();
6167: }
6168:
6169: if (! exists($args->{'skip_phases'}{'body'}) ) {
6170: if ($args->{'frameset'}) {
6171: my $attr_string = &make_attr_string($args->{'force_register'},
6172: $args->{'add_entries'});
6173: $result .= "\n<frameset $attr_string>\n";
6174: } else {
6175: $result .=
6176: &bodytag($title,
6177: $args->{'function'}, $args->{'add_entries'},
6178: $args->{'only_body'}, $args->{'domain'},
6179: $args->{'force_register'}, $args->{'body_title'},
6180: $args->{'no_nav_bar'}, $args->{'bgcolor'},
1.460 albertel 6181: $args->{'no_title'}, $args->{'no_inline_link'},
6182: $args);
1.338 albertel 6183: }
1.330 albertel 6184: }
1.338 albertel 6185:
1.315 albertel 6186: if ($args->{'js_ready'}) {
1.713 kaisler 6187: $result = &js_ready($result);
1.315 albertel 6188: }
1.320 albertel 6189: if ($args->{'html_encode'}) {
1.713 kaisler 6190: $result = &html_encode($result);
6191: }
6192:
1.718 raeburn 6193: if (exists($args->{'bread_crumbs'})) {
6194: &Apache::lonhtmlcommon::clear_breadcrumbs();
6195: if (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
6196: foreach my $crumb (@{$args->{'bread_crumbs'}}){
6197: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
6198: }
6199: }
6200: $result .= &Apache::lonhtmlcommon::breadcrumbs();
1.320 albertel 6201: }
1.713 kaisler 6202:
1.315 albertel 6203: return $result;
1.306 albertel 6204: }
6205:
1.330 albertel 6206:
1.306 albertel 6207: =pod
6208:
6209: =item * &head()
6210:
6211: Returns a complete </body></html> section for LON-CAPA web pages.
6212:
1.315 albertel 6213: Inputs: $args - additional optional args supported are:
6214: js_ready -> return a string ready for being used in
6215: a javascript writeln
1.320 albertel 6216: html_encode -> return a string ready for being used in
6217: a html attribute
1.330 albertel 6218: frameset -> if true will start with a <frameset>
6219: rather than <body>
1.493 albertel 6220: dicsussion -> if true will get discussion from
6221: lonxml::xmlend
6222: (you can pass the target and parser arguments
6223: through optional 'target' and 'parser' args
6224: to this routine)
1.306 albertel 6225:
6226: =cut
6227:
6228: sub end_page {
1.315 albertel 6229: my ($args) = @_;
6230: $env{'internal.end_page'}++;
1.330 albertel 6231: my $result;
1.335 albertel 6232: if ($args->{'discussion'}) {
6233: my ($target,$parser);
6234: if (ref($args->{'discussion'})) {
6235: ($target,$parser) =($args->{'discussion'}{'target'},
6236: $args->{'discussion'}{'parser'});
6237: }
6238: $result .= &Apache::lonxml::xmlend($target,$parser);
6239: }
6240:
1.330 albertel 6241: if ($args->{'frameset'}) {
6242: $result .= '</frameset>';
6243: } else {
1.635 raeburn 6244: $result .= &endbodytag($args);
1.330 albertel 6245: }
6246: $result .= "\n</html>";
6247:
1.315 albertel 6248: if ($args->{'js_ready'}) {
1.317 albertel 6249: $result = &js_ready($result);
1.315 albertel 6250: }
1.335 albertel 6251:
1.320 albertel 6252: if ($args->{'html_encode'}) {
6253: $result = &html_encode($result);
6254: }
1.335 albertel 6255:
1.315 albertel 6256: return $result;
6257: }
6258:
1.320 albertel 6259: sub html_encode {
6260: my ($result) = @_;
6261:
1.322 albertel 6262: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 6263:
6264: return $result;
6265: }
1.317 albertel 6266: sub js_ready {
6267: my ($result) = @_;
6268:
1.323 albertel 6269: $result =~ s/[\n\r]/ /xmsg;
6270: $result =~ s/\\/\\\\/xmsg;
6271: $result =~ s/'/\\'/xmsg;
1.372 albertel 6272: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 6273:
6274: return $result;
6275: }
6276:
1.315 albertel 6277: sub validate_page {
6278: if ( exists($env{'internal.start_page'})
1.316 albertel 6279: && $env{'internal.start_page'} > 1) {
6280: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 6281: $env{'internal.start_page'}.' '.
1.316 albertel 6282: $ENV{'request.filename'});
1.315 albertel 6283: }
6284: if ( exists($env{'internal.end_page'})
1.316 albertel 6285: && $env{'internal.end_page'} > 1) {
6286: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 6287: $env{'internal.end_page'}.' '.
1.316 albertel 6288: $env{'request.filename'});
1.315 albertel 6289: }
6290: if ( exists($env{'internal.start_page'})
6291: && ! exists($env{'internal.end_page'})) {
1.316 albertel 6292: &Apache::lonnet::logthis('start_page called without end_page '.
6293: $env{'request.filename'});
1.315 albertel 6294: }
6295: if ( ! exists($env{'internal.start_page'})
6296: && exists($env{'internal.end_page'})) {
1.316 albertel 6297: &Apache::lonnet::logthis('end_page called without start_page'.
6298: $env{'request.filename'});
1.315 albertel 6299: }
1.306 albertel 6300: }
1.315 albertel 6301:
1.318 albertel 6302: sub simple_error_page {
6303: my ($r,$title,$msg) = @_;
6304: my $page =
6305: &Apache::loncommon::start_page($title).
6306: &mt($msg).
6307: &Apache::loncommon::end_page();
6308: if (ref($r)) {
6309: $r->print($page);
1.327 albertel 6310: return;
1.318 albertel 6311: }
6312: return $page;
6313: }
1.347 albertel 6314:
6315: {
1.610 albertel 6316: my @row_count;
1.347 albertel 6317: sub start_data_table {
1.422 albertel 6318: my ($add_class) = @_;
6319: my $css_class = (join(' ','LC_data_table',$add_class));
1.610 albertel 6320: unshift(@row_count,0);
1.422 albertel 6321: return '<table class="'.$css_class.'">'."\n";
1.347 albertel 6322: }
6323:
6324: sub end_data_table {
1.610 albertel 6325: shift(@row_count);
1.389 albertel 6326: return '</table>'."\n";;
1.347 albertel 6327: }
6328:
6329: sub start_data_table_row {
1.422 albertel 6330: my ($add_class) = @_;
1.610 albertel 6331: $row_count[0]++;
6332: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.428 albertel 6333: $css_class = (join(' ',$css_class,$add_class));
1.422 albertel 6334: return '<tr class="'.$css_class.'">'."\n";;
1.347 albertel 6335: }
1.471 banghart 6336:
6337: sub continue_data_table_row {
6338: my ($add_class) = @_;
1.610 albertel 6339: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.471 banghart 6340: $css_class = (join(' ',$css_class,$add_class));
6341: return '<tr class="'.$css_class.'">'."\n";;
6342: }
1.347 albertel 6343:
6344: sub end_data_table_row {
1.389 albertel 6345: return '</tr>'."\n";;
1.347 albertel 6346: }
1.367 www 6347:
1.421 albertel 6348: sub start_data_table_empty_row {
1.707 bisitz 6349: # $row_count[0]++;
1.421 albertel 6350: return '<tr class="LC_empty_row" >'."\n";;
6351: }
6352:
6353: sub end_data_table_empty_row {
6354: return '</tr>'."\n";;
6355: }
6356:
1.367 www 6357: sub start_data_table_header_row {
1.389 albertel 6358: return '<tr class="LC_header_row">'."\n";;
1.367 www 6359: }
6360:
6361: sub end_data_table_header_row {
1.389 albertel 6362: return '</tr>'."\n";;
1.367 www 6363: }
1.347 albertel 6364: }
6365:
1.548 albertel 6366: =pod
6367:
6368: =item * &inhibit_menu_check($arg)
6369:
6370: Checks for a inhibitmenu state and generates output to preserve it
6371:
6372: Inputs: $arg - can be any of
6373: - undef - in which case the return value is a string
6374: to add into arguments list of a uri
6375: - 'input' - in which case the return value is a HTML
6376: <form> <input> field of type hidden to
6377: preserve the value
6378: - a url - in which case the return value is the url with
6379: the neccesary cgi args added to preserve the
6380: inhibitmenu state
6381: - a ref to a url - no return value, but the string is
6382: updated to include the neccessary cgi
6383: args to preserve the inhibitmenu state
6384:
6385: =cut
6386:
6387: sub inhibit_menu_check {
6388: my ($arg) = @_;
6389: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6390: if ($arg eq 'input') {
6391: if ($env{'form.inhibitmenu'}) {
6392: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
6393: } else {
6394: return
6395: }
6396: }
6397: if ($env{'form.inhibitmenu'}) {
6398: if (ref($arg)) {
6399: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6400: } elsif ($arg eq '') {
6401: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
6402: } else {
6403: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6404: }
6405: }
6406: if (!ref($arg)) {
6407: return $arg;
6408: }
6409: }
6410:
1.251 albertel 6411: ###############################################
1.182 matthew 6412:
6413: =pod
6414:
1.549 albertel 6415: =back
6416:
6417: =head1 User Information Routines
6418:
6419: =over 4
6420:
1.405 albertel 6421: =item * &get_users_function()
1.182 matthew 6422:
6423: Used by &bodytag to determine the current users primary role.
6424: Returns either 'student','coordinator','admin', or 'author'.
6425:
6426: =cut
6427:
6428: ###############################################
6429: sub get_users_function {
6430: my $function = 'student';
1.258 albertel 6431: if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
1.182 matthew 6432: $function='coordinator';
6433: }
1.258 albertel 6434: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 6435: $function='admin';
6436: }
1.258 albertel 6437: if (($env{'request.role'}=~/^(au|ca)/) ||
1.182 matthew 6438: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
6439: $function='author';
6440: }
6441: return $function;
1.54 www 6442: }
1.99 www 6443:
6444: ###############################################
6445:
1.233 raeburn 6446: =pod
6447:
1.542 raeburn 6448: =item * &check_user_status()
1.274 raeburn 6449:
6450: Determines current status of supplied role for a
6451: specific user. Roles can be active, previous or future.
6452:
6453: Inputs:
6454: user's domain, user's username, course's domain,
1.375 raeburn 6455: course's number, optional section ID.
1.274 raeburn 6456:
6457: Outputs:
6458: role status: active, previous or future.
6459:
6460: =cut
6461:
6462: sub check_user_status {
1.412 raeburn 6463: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274 raeburn 6464: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
6465: my @uroles = keys %userinfo;
6466: my $srchstr;
6467: my $active_chk = 'none';
1.412 raeburn 6468: my $now = time;
1.274 raeburn 6469: if (@uroles > 0) {
1.412 raeburn 6470: if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 6471: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
6472: } else {
1.412 raeburn 6473: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
6474: }
6475: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 6476: my $role_end = 0;
6477: my $role_start = 0;
6478: $active_chk = 'active';
1.412 raeburn 6479: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
6480: $role_end = $1;
6481: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
6482: $role_start = $1;
1.274 raeburn 6483: }
6484: }
6485: if ($role_start > 0) {
1.412 raeburn 6486: if ($now < $role_start) {
1.274 raeburn 6487: $active_chk = 'future';
6488: }
6489: }
6490: if ($role_end > 0) {
1.412 raeburn 6491: if ($now > $role_end) {
1.274 raeburn 6492: $active_chk = 'previous';
6493: }
6494: }
6495: }
6496: }
6497: return $active_chk;
6498: }
6499:
6500: ###############################################
6501:
6502: =pod
6503:
1.405 albertel 6504: =item * &get_sections()
1.233 raeburn 6505:
6506: Determines all the sections for a course including
6507: sections with students and sections containing other roles.
1.419 raeburn 6508: Incoming parameters:
6509:
6510: 1. domain
6511: 2. course number
6512: 3. reference to array containing roles for which sections should
6513: be gathered (optional).
6514: 4. reference to array containing status types for which sections
6515: should be gathered (optional).
6516:
6517: If the third argument is undefined, sections are gathered for any role.
6518: If the fourth argument is undefined, sections are gathered for any status.
6519: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 6520:
1.374 raeburn 6521: Returns section hash (keys are section IDs, values are
6522: number of users in each section), subject to the
1.419 raeburn 6523: optional roles filter, optional status filter
1.233 raeburn 6524:
6525: =cut
6526:
6527: ###############################################
6528: sub get_sections {
1.419 raeburn 6529: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 6530: if (!defined($cdom) || !defined($cnum)) {
6531: my $cid = $env{'request.course.id'};
6532:
6533: return if (!defined($cid));
6534:
6535: $cdom = $env{'course.'.$cid.'.domain'};
6536: $cnum = $env{'course.'.$cid.'.num'};
6537: }
6538:
6539: my %sectioncount;
1.419 raeburn 6540: my $now = time;
1.240 albertel 6541:
1.366 albertel 6542: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276 albertel 6543: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 6544: my $sec_index = &Apache::loncoursedata::CL_SECTION();
6545: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 6546: my $start_index = &Apache::loncoursedata::CL_START();
6547: my $end_index = &Apache::loncoursedata::CL_END();
6548: my $status;
1.366 albertel 6549: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 6550: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
6551: $data->[$status_index],
6552: $data->[$start_index],
6553: $data->[$end_index]);
6554: if ($stu_status eq 'Active') {
6555: $status = 'active';
6556: } elsif ($end < $now) {
6557: $status = 'previous';
6558: } elsif ($start > $now) {
6559: $status = 'future';
6560: }
6561: if ($section ne '-1' && $section !~ /^\s*$/) {
6562: if ((!defined($possible_status)) || (($status ne '') &&
6563: (grep/^\Q$status\E$/,@{$possible_status}))) {
6564: $sectioncount{$section}++;
6565: }
1.240 albertel 6566: }
6567: }
6568: }
6569: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6570: foreach my $user (sort(keys(%courseroles))) {
6571: if ($user !~ /^(\w{2})/) { next; }
6572: my ($role) = ($user =~ /^(\w{2})/);
6573: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 6574: my ($section,$status);
1.240 albertel 6575: if ($role eq 'cr' &&
6576: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
6577: $section=$1;
6578: }
6579: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
6580: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 6581: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
6582: if ($end == -1 && $start == -1) {
6583: next; #deleted role
6584: }
6585: if (!defined($possible_status)) {
6586: $sectioncount{$section}++;
6587: } else {
6588: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
6589: $status = 'active';
6590: } elsif ($end < $now) {
6591: $status = 'future';
6592: } elsif ($start > $now) {
6593: $status = 'previous';
6594: }
6595: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
6596: $sectioncount{$section}++;
6597: }
6598: }
1.233 raeburn 6599: }
1.366 albertel 6600: return %sectioncount;
1.233 raeburn 6601: }
6602:
1.274 raeburn 6603: ###############################################
1.294 raeburn 6604:
6605: =pod
1.405 albertel 6606:
6607: =item * &get_course_users()
6608:
1.275 raeburn 6609: Retrieves usernames:domains for users in the specified course
6610: with specific role(s), and access status.
6611:
6612: Incoming parameters:
1.277 albertel 6613: 1. course domain
6614: 2. course number
6615: 3. access status: users must have - either active,
1.275 raeburn 6616: previous, future, or all.
1.277 albertel 6617: 4. reference to array of permissible roles
1.288 raeburn 6618: 5. reference to array of section restrictions (optional)
6619: 6. reference to results object (hash of hashes).
6620: 7. reference to optional userdata hash
1.609 raeburn 6621: 8. reference to optional statushash
1.630 raeburn 6622: 9. flag if privileged users (except those set to unhide in
6623: course settings) should be excluded
1.609 raeburn 6624: Keys of top level results hash are roles.
1.275 raeburn 6625: Keys of inner hashes are username:domain, with
6626: values set to access type.
1.288 raeburn 6627: Optional userdata hash returns an array with arguments in the
6628: same order as loncoursedata::get_classlist() for student data.
6629:
1.609 raeburn 6630: Optional statushash returns
6631:
1.288 raeburn 6632: Entries for end, start, section and status are blank because
6633: of the possibility of multiple values for non-student roles.
6634:
1.275 raeburn 6635: =cut
1.405 albertel 6636:
1.275 raeburn 6637: ###############################################
1.405 albertel 6638:
1.275 raeburn 6639: sub get_course_users {
1.630 raeburn 6640: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 6641: my %idx = ();
1.419 raeburn 6642: my %seclists;
1.288 raeburn 6643:
6644: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
6645: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
6646: $idx{end} = &Apache::loncoursedata::CL_END();
6647: $idx{start} = &Apache::loncoursedata::CL_START();
6648: $idx{id} = &Apache::loncoursedata::CL_ID();
6649: $idx{section} = &Apache::loncoursedata::CL_SECTION();
6650: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
6651: $idx{status} = &Apache::loncoursedata::CL_STATUS();
6652:
1.290 albertel 6653: if (grep(/^st$/,@{$roles})) {
1.276 albertel 6654: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 6655: my $now = time;
1.277 albertel 6656: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 6657: my $match = 0;
1.412 raeburn 6658: my $secmatch = 0;
1.419 raeburn 6659: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 6660: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 6661: if ($section eq '') {
6662: $section = 'none';
6663: }
1.291 albertel 6664: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 6665: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 6666: $secmatch = 1;
6667: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 6668: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 6669: $secmatch = 1;
6670: }
6671: } else {
1.419 raeburn 6672: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 6673: $secmatch = 1;
6674: }
1.290 albertel 6675: }
1.412 raeburn 6676: if (!$secmatch) {
6677: next;
6678: }
1.419 raeburn 6679: }
1.275 raeburn 6680: if (defined($$types{'active'})) {
1.288 raeburn 6681: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 6682: push(@{$$users{st}{$student}},'active');
1.288 raeburn 6683: $match = 1;
1.275 raeburn 6684: }
6685: }
6686: if (defined($$types{'previous'})) {
1.609 raeburn 6687: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 6688: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 6689: $match = 1;
1.275 raeburn 6690: }
6691: }
6692: if (defined($$types{'future'})) {
1.609 raeburn 6693: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 6694: push(@{$$users{st}{$student}},'future');
1.288 raeburn 6695: $match = 1;
1.275 raeburn 6696: }
6697: }
1.609 raeburn 6698: if ($match) {
6699: push(@{$seclists{$student}},$section);
6700: if (ref($userdata) eq 'HASH') {
6701: $$userdata{$student} = $$classlist{$student};
6702: }
6703: if (ref($statushash) eq 'HASH') {
6704: $statushash->{$student}{'st'}{$section} = $status;
6705: }
1.288 raeburn 6706: }
1.275 raeburn 6707: }
6708: }
1.412 raeburn 6709: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 6710: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6711: my $now = time;
1.609 raeburn 6712: my %displaystatus = ( previous => 'Expired',
6713: active => 'Active',
6714: future => 'Future',
6715: );
1.630 raeburn 6716: my %nothide;
6717: if ($hidepriv) {
6718: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
6719: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
6720: if ($user !~ /:/) {
6721: $nothide{join(':',split(/[\@]/,$user))}=1;
6722: } else {
6723: $nothide{$user} = 1;
6724: }
6725: }
6726: }
1.439 raeburn 6727: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 6728: my $match = 0;
1.412 raeburn 6729: my $secmatch = 0;
1.439 raeburn 6730: my $status;
1.412 raeburn 6731: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 6732: $user =~ s/:$//;
1.439 raeburn 6733: my ($end,$start) = split(/:/,$coursepersonnel{$person});
6734: if ($end == -1 || $start == -1) {
6735: next;
6736: }
6737: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
6738: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 6739: my ($uname,$udom) = split(/:/,$user);
6740: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 6741: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 6742: $secmatch = 1;
6743: } elsif ($usec eq '') {
1.420 albertel 6744: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 6745: $secmatch = 1;
6746: }
6747: } else {
6748: if (grep(/^\Q$usec\E$/,@{$sections})) {
6749: $secmatch = 1;
6750: }
6751: }
6752: if (!$secmatch) {
6753: next;
6754: }
1.288 raeburn 6755: }
1.419 raeburn 6756: if ($usec eq '') {
6757: $usec = 'none';
6758: }
1.275 raeburn 6759: if ($uname ne '' && $udom ne '') {
1.630 raeburn 6760: if ($hidepriv) {
6761: if ((&Apache::lonnet::privileged($uname,$udom)) &&
6762: (!$nothide{$uname.':'.$udom})) {
6763: next;
6764: }
6765: }
1.503 raeburn 6766: if ($end > 0 && $end < $now) {
1.439 raeburn 6767: $status = 'previous';
6768: } elsif ($start > $now) {
6769: $status = 'future';
6770: } else {
6771: $status = 'active';
6772: }
1.277 albertel 6773: foreach my $type (keys(%{$types})) {
1.275 raeburn 6774: if ($status eq $type) {
1.420 albertel 6775: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 6776: push(@{$$users{$role}{$user}},$type);
6777: }
1.288 raeburn 6778: $match = 1;
6779: }
6780: }
1.419 raeburn 6781: if (($match) && (ref($userdata) eq 'HASH')) {
6782: if (!exists($$userdata{$uname.':'.$udom})) {
6783: &get_user_info($udom,$uname,\%idx,$userdata);
6784: }
1.420 albertel 6785: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 6786: push(@{$seclists{$uname.':'.$udom}},$usec);
6787: }
1.609 raeburn 6788: if (ref($statushash) eq 'HASH') {
6789: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
6790: }
1.275 raeburn 6791: }
6792: }
6793: }
6794: }
1.290 albertel 6795: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 6796: if ((defined($cdom)) && (defined($cnum))) {
6797: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
6798: if ( defined($csettings{'internal.courseowner'}) ) {
6799: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 6800: next if ($owner eq '');
6801: my ($ownername,$ownerdom);
6802: if ($owner =~ /^([^:]+):([^:]+)$/) {
6803: $ownername = $1;
6804: $ownerdom = $2;
6805: } else {
6806: $ownername = $owner;
6807: $ownerdom = $cdom;
6808: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 6809: }
6810: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 6811: if (defined($userdata) &&
1.609 raeburn 6812: !exists($$userdata{$owner})) {
6813: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
6814: if (!grep(/^none$/,@{$seclists{$owner}})) {
6815: push(@{$seclists{$owner}},'none');
6816: }
6817: if (ref($statushash) eq 'HASH') {
6818: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 6819: }
1.290 albertel 6820: }
1.279 raeburn 6821: }
6822: }
6823: }
1.419 raeburn 6824: foreach my $user (keys(%seclists)) {
6825: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
6826: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
6827: }
1.275 raeburn 6828: }
6829: return;
6830: }
6831:
1.288 raeburn 6832: sub get_user_info {
6833: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 6834: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
6835: &plainname($uname,$udom,'lastname');
1.291 albertel 6836: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 6837: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 6838: my %idhash = &Apache::lonnet::idrget($udom,($uname));
6839: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 6840: return;
6841: }
1.275 raeburn 6842:
1.472 raeburn 6843: ###############################################
6844:
6845: =pod
6846:
6847: =item * &get_user_quota()
6848:
6849: Retrieves quota assigned for storage of portfolio files for a user
6850:
6851: Incoming parameters:
6852: 1. user's username
6853: 2. user's domain
6854:
6855: Returns:
1.536 raeburn 6856: 1. Disk quota (in Mb) assigned to student.
6857: 2. (Optional) Type of setting: custom or default
6858: (individually assigned or default for user's
6859: institutional status).
6860: 3. (Optional) - User's institutional status (e.g., faculty, staff
6861: or student - types as defined in localenroll::inst_usertypes
6862: for user's domain, which determines default quota for user.
6863: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 6864:
6865: If a value has been stored in the user's environment,
1.536 raeburn 6866: it will return that, otherwise it returns the maximal default
6867: defined for the user's instituional status(es) in the domain.
1.472 raeburn 6868:
6869: =cut
6870:
6871: ###############################################
6872:
6873:
6874: sub get_user_quota {
6875: my ($uname,$udom) = @_;
1.536 raeburn 6876: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 6877: if (!defined($udom)) {
6878: $udom = $env{'user.domain'};
6879: }
6880: if (!defined($uname)) {
6881: $uname = $env{'user.name'};
6882: }
6883: if (($udom eq '' || $uname eq '') ||
6884: ($udom eq 'public') && ($uname eq 'public')) {
6885: $quota = 0;
1.536 raeburn 6886: $quotatype = 'default';
6887: $defquota = 0;
1.472 raeburn 6888: } else {
1.536 raeburn 6889: my $inststatus;
1.472 raeburn 6890: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
6891: $quota = $env{'environment.portfolioquota'};
1.536 raeburn 6892: $inststatus = $env{'environment.inststatus'};
1.472 raeburn 6893: } else {
1.536 raeburn 6894: my %userenv =
6895: &Apache::lonnet::get('environment',['portfolioquota',
6896: 'inststatus'],$udom,$uname);
1.472 raeburn 6897: my ($tmp) = keys(%userenv);
6898: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
6899: $quota = $userenv{'portfolioquota'};
1.536 raeburn 6900: $inststatus = $userenv{'inststatus'};
1.472 raeburn 6901: } else {
6902: undef(%userenv);
6903: }
6904: }
1.536 raeburn 6905: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472 raeburn 6906: if ($quota eq '') {
1.536 raeburn 6907: $quota = $defquota;
6908: $quotatype = 'default';
6909: } else {
6910: $quotatype = 'custom';
1.472 raeburn 6911: }
6912: }
1.536 raeburn 6913: if (wantarray) {
6914: return ($quota,$quotatype,$settingstatus,$defquota);
6915: } else {
6916: return $quota;
6917: }
1.472 raeburn 6918: }
6919:
6920: ###############################################
6921:
6922: =pod
6923:
6924: =item * &default_quota()
6925:
1.536 raeburn 6926: Retrieves default quota assigned for storage of user portfolio files,
6927: given an (optional) user's institutional status.
1.472 raeburn 6928:
6929: Incoming parameters:
6930: 1. domain
1.536 raeburn 6931: 2. (Optional) institutional status(es). This is a : separated list of
6932: status types (e.g., faculty, staff, student etc.)
6933: which apply to the user for whom the default is being retrieved.
6934: If the institutional status string in undefined, the domain
6935: default quota will be returned.
1.472 raeburn 6936:
6937: Returns:
6938: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 6939: 2. (Optional) institutional type which determined the value of the
6940: default quota.
1.472 raeburn 6941:
6942: If a value has been stored in the domain's configuration db,
6943: it will return that, otherwise it returns 20 (for backwards
6944: compatibility with domains which have not set up a configuration
6945: db file; the original statically defined portfolio quota was 20 Mb).
6946:
1.536 raeburn 6947: If the user's status includes multiple types (e.g., staff and student),
6948: the largest default quota which applies to the user determines the
6949: default quota returned.
6950:
1.472 raeburn 6951: =cut
6952:
6953: ###############################################
6954:
6955:
6956: sub default_quota {
1.536 raeburn 6957: my ($udom,$inststatus) = @_;
6958: my ($defquota,$settingstatus);
6959: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 6960: ['quotas'],$udom);
6961: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 6962: if ($inststatus ne '') {
6963: my @statuses = split(/:/,$inststatus);
6964: foreach my $item (@statuses) {
1.711 raeburn 6965: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
6966: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
6967: if ($defquota eq '') {
6968: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
6969: $settingstatus = $item;
6970: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
6971: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
6972: $settingstatus = $item;
6973: }
6974: }
6975: } else {
6976: if ($quotahash{'quotas'}{$item} ne '') {
6977: if ($defquota eq '') {
6978: $defquota = $quotahash{'quotas'}{$item};
6979: $settingstatus = $item;
6980: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
6981: $defquota = $quotahash{'quotas'}{$item};
6982: $settingstatus = $item;
6983: }
1.536 raeburn 6984: }
6985: }
6986: }
6987: }
6988: if ($defquota eq '') {
1.711 raeburn 6989: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
6990: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
6991: } else {
6992: $defquota = $quotahash{'quotas'}{'default'};
6993: }
1.536 raeburn 6994: $settingstatus = 'default';
6995: }
6996: } else {
6997: $settingstatus = 'default';
6998: $defquota = 20;
6999: }
7000: if (wantarray) {
7001: return ($defquota,$settingstatus);
1.472 raeburn 7002: } else {
1.536 raeburn 7003: return $defquota;
1.472 raeburn 7004: }
7005: }
7006:
1.384 raeburn 7007: sub get_secgrprole_info {
7008: my ($cdom,$cnum,$needroles,$type) = @_;
7009: my %sections_count = &get_sections($cdom,$cnum);
7010: my @sections = (sort {$a <=> $b} keys(%sections_count));
7011: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
7012: my @groups = sort(keys(%curr_groups));
7013: my $allroles = [];
7014: my $rolehash;
7015: my $accesshash = {
7016: active => 'Currently has access',
7017: future => 'Will have future access',
7018: previous => 'Previously had access',
7019: };
7020: if ($needroles) {
7021: $rolehash = {'all' => 'all'};
1.385 albertel 7022: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7023: if (&Apache::lonnet::error(%user_roles)) {
7024: undef(%user_roles);
7025: }
7026: foreach my $item (keys(%user_roles)) {
1.384 raeburn 7027: my ($role)=split(/\:/,$item,2);
7028: if ($role eq 'cr') { next; }
7029: if ($role =~ /^cr/) {
7030: $$rolehash{$role} = (split('/',$role))[3];
7031: } else {
7032: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
7033: }
7034: }
7035: foreach my $key (sort(keys(%{$rolehash}))) {
7036: push(@{$allroles},$key);
7037: }
7038: push (@{$allroles},'st');
7039: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
7040: }
7041: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
7042: }
7043:
1.555 raeburn 7044: sub user_picker {
1.627 raeburn 7045: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555 raeburn 7046: my $currdom = $dom;
7047: my %curr_selected = (
7048: srchin => 'dom',
1.580 raeburn 7049: srchby => 'lastname',
1.555 raeburn 7050: );
7051: my $srchterm;
1.625 raeburn 7052: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 7053: if ($srch->{'srchby'} ne '') {
7054: $curr_selected{'srchby'} = $srch->{'srchby'};
7055: }
7056: if ($srch->{'srchin'} ne '') {
7057: $curr_selected{'srchin'} = $srch->{'srchin'};
7058: }
7059: if ($srch->{'srchtype'} ne '') {
7060: $curr_selected{'srchtype'} = $srch->{'srchtype'};
7061: }
7062: if ($srch->{'srchdomain'} ne '') {
7063: $currdom = $srch->{'srchdomain'};
7064: }
7065: $srchterm = $srch->{'srchterm'};
7066: }
7067: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 7068: 'usr' => 'Search criteria',
1.563 raeburn 7069: 'doma' => 'Domain/institution to search',
1.558 albertel 7070: 'uname' => 'username',
7071: 'lastname' => 'last name',
1.555 raeburn 7072: 'lastfirst' => 'last name, first name',
1.558 albertel 7073: 'crs' => 'in this course',
1.576 raeburn 7074: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 7075: 'alc' => 'all LON-CAPA',
1.573 raeburn 7076: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 7077: 'exact' => 'is',
7078: 'contains' => 'contains',
1.569 raeburn 7079: 'begins' => 'begins with',
1.571 raeburn 7080: 'youm' => "You must include some text to search for.",
7081: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
7082: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
7083: 'yomc' => "You must choose a domain when using an institutional directory search.",
7084: 'ymcd' => "You must choose a domain when using a domain search.",
7085: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
7086: 'whse' => "When searching by last,first you must include at least one character in the first name.",
7087: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 7088: );
1.563 raeburn 7089: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
7090: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 7091:
7092: my @srchins = ('crs','dom','alc','instd');
7093:
7094: foreach my $option (@srchins) {
7095: # FIXME 'alc' option unavailable until
7096: # loncreateuser::print_user_query_page()
7097: # has been completed.
7098: next if ($option eq 'alc');
7099: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 7100: if ($curr_selected{'srchin'} eq $option) {
7101: $srchinsel .= '
7102: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7103: } else {
7104: $srchinsel .= '
7105: <option value="'.$option.'">'.$lt{$option}.'</option>';
7106: }
1.555 raeburn 7107: }
1.563 raeburn 7108: $srchinsel .= "\n </select>\n";
1.555 raeburn 7109:
7110: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 7111: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 7112: if ($curr_selected{'srchby'} eq $option) {
7113: $srchbysel .= '
7114: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7115: } else {
7116: $srchbysel .= '
7117: <option value="'.$option.'">'.$lt{$option}.'</option>';
7118: }
7119: }
7120: $srchbysel .= "\n </select>\n";
7121:
7122: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 7123: foreach my $option ('begins','contains','exact') {
1.555 raeburn 7124: if ($curr_selected{'srchtype'} eq $option) {
7125: $srchtypesel .= '
7126: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7127: } else {
7128: $srchtypesel .= '
7129: <option value="'.$option.'">'.$lt{$option}.'</option>';
7130: }
7131: }
7132: $srchtypesel .= "\n </select>\n";
7133:
1.558 albertel 7134: my ($newuserscript,$new_user_create);
1.556 raeburn 7135:
7136: if ($forcenewuser) {
1.576 raeburn 7137: if (ref($srch) eq 'HASH') {
7138: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627 raeburn 7139: if ($cancreate) {
7140: $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>';
7141: } else {
7142: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
7143: my %usertypetext = (
7144: official => 'institutional',
7145: unofficial => 'non-institutional',
7146: );
7147: $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 />';
7148: }
1.576 raeburn 7149: }
7150: }
7151:
1.556 raeburn 7152: $newuserscript = <<"ENDSCRIPT";
7153:
1.570 raeburn 7154: function setSearch(createnew,callingForm) {
1.556 raeburn 7155: if (createnew == 1) {
1.570 raeburn 7156: for (var i=0; i<callingForm.srchby.length; i++) {
7157: if (callingForm.srchby.options[i].value == 'uname') {
7158: callingForm.srchby.selectedIndex = i;
1.556 raeburn 7159: }
7160: }
1.570 raeburn 7161: for (var i=0; i<callingForm.srchin.length; i++) {
7162: if ( callingForm.srchin.options[i].value == 'dom') {
7163: callingForm.srchin.selectedIndex = i;
1.556 raeburn 7164: }
7165: }
1.570 raeburn 7166: for (var i=0; i<callingForm.srchtype.length; i++) {
7167: if (callingForm.srchtype.options[i].value == 'exact') {
7168: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 7169: }
7170: }
1.570 raeburn 7171: for (var i=0; i<callingForm.srchdomain.length; i++) {
7172: if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
7173: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 7174: }
7175: }
7176: }
7177: }
7178: ENDSCRIPT
1.558 albertel 7179:
1.556 raeburn 7180: }
7181:
1.555 raeburn 7182: my $output = <<"END_BLOCK";
1.556 raeburn 7183: <script type="text/javascript">
1.570 raeburn 7184: function validateEntry(callingForm) {
1.558 albertel 7185:
1.556 raeburn 7186: var checkok = 1;
1.558 albertel 7187: var srchin;
1.570 raeburn 7188: for (var i=0; i<callingForm.srchin.length; i++) {
7189: if ( callingForm.srchin[i].checked ) {
7190: srchin = callingForm.srchin[i].value;
1.558 albertel 7191: }
7192: }
7193:
1.570 raeburn 7194: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
7195: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
7196: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
7197: var srchterm = callingForm.srchterm.value;
7198: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 7199: var msg = "";
7200:
7201: if (srchterm == "") {
7202: checkok = 0;
1.571 raeburn 7203: msg += "$lt{'youm'}\\n";
1.556 raeburn 7204: }
7205:
1.569 raeburn 7206: if (srchtype== 'begins') {
7207: if (srchterm.length < 2) {
7208: checkok = 0;
1.571 raeburn 7209: msg += "$lt{'thte'}\\n";
1.569 raeburn 7210: }
7211: }
7212:
1.556 raeburn 7213: if (srchtype== 'contains') {
7214: if (srchterm.length < 3) {
7215: checkok = 0;
1.571 raeburn 7216: msg += "$lt{'thet'}\\n";
1.556 raeburn 7217: }
7218: }
7219: if (srchin == 'instd') {
7220: if (srchdomain == '') {
7221: checkok = 0;
1.571 raeburn 7222: msg += "$lt{'yomc'}\\n";
1.556 raeburn 7223: }
7224: }
7225: if (srchin == 'dom') {
7226: if (srchdomain == '') {
7227: checkok = 0;
1.571 raeburn 7228: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 7229: }
7230: }
7231: if (srchby == 'lastfirst') {
7232: if (srchterm.indexOf(",") == -1) {
7233: checkok = 0;
1.571 raeburn 7234: msg += "$lt{'whus'}\\n";
1.556 raeburn 7235: }
7236: if (srchterm.indexOf(",") == srchterm.length -1) {
7237: checkok = 0;
1.571 raeburn 7238: msg += "$lt{'whse'}\\n";
1.556 raeburn 7239: }
7240: }
7241: if (checkok == 0) {
1.571 raeburn 7242: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 7243: return;
7244: }
7245: if (checkok == 1) {
1.570 raeburn 7246: callingForm.submit();
1.556 raeburn 7247: }
7248: }
7249:
7250: $newuserscript
7251:
7252: </script>
1.558 albertel 7253:
7254: $new_user_create
7255:
1.555 raeburn 7256: <table>
1.558 albertel 7257: <tr>
1.573 raeburn 7258: <td>$lt{'doma'}:</td>
7259: <td>$domform</td>
7260: </td>
7261: </tr>
7262: <tr>
7263: <td>$lt{'usr'}:</td>
1.563 raeburn 7264: <td>$srchbysel
7265: $srchtypesel
7266: <input type="text" size="15" name="srchterm" value="$srchterm" />
1.564 albertel 7267: $srchinsel
1.563 raeburn 7268: </td>
7269: </tr>
1.555 raeburn 7270: </table>
7271: <br />
7272: END_BLOCK
1.558 albertel 7273:
1.555 raeburn 7274: return $output;
7275: }
7276:
1.612 raeburn 7277: sub user_rule_check {
1.615 raeburn 7278: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 7279: my $response;
7280: if (ref($usershash) eq 'HASH') {
7281: foreach my $user (keys(%{$usershash})) {
7282: my ($uname,$udom) = split(/:/,$user);
7283: next if ($udom eq '' || $uname eq '');
1.615 raeburn 7284: my ($id,$newuser);
1.612 raeburn 7285: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 7286: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 7287: $id = $usershash->{$user}->{'id'};
7288: }
7289: my $inst_response;
7290: if (ref($checks) eq 'HASH') {
7291: if (defined($checks->{'username'})) {
1.615 raeburn 7292: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7293: &Apache::lonnet::get_instuser($udom,$uname);
7294: } elsif (defined($checks->{'id'})) {
1.615 raeburn 7295: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7296: &Apache::lonnet::get_instuser($udom,undef,$id);
7297: }
1.615 raeburn 7298: } else {
7299: ($inst_response,%{$inst_results->{$user}}) =
7300: &Apache::lonnet::get_instuser($udom,$uname);
7301: return;
1.612 raeburn 7302: }
1.615 raeburn 7303: if (!$got_rules->{$udom}) {
1.612 raeburn 7304: my %domconfig = &Apache::lonnet::get_dom('configuration',
7305: ['usercreation'],$udom);
7306: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 7307: foreach my $item ('username','id') {
1.612 raeburn 7308: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
7309: $$curr_rules{$udom}{$item} =
7310: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 7311: }
7312: }
7313: }
1.615 raeburn 7314: $got_rules->{$udom} = 1;
1.585 raeburn 7315: }
1.612 raeburn 7316: foreach my $item (keys(%{$checks})) {
7317: if (ref($$curr_rules{$udom}) eq 'HASH') {
7318: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
7319: if (@{$$curr_rules{$udom}{$item}} > 0) {
7320: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
7321: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
7322: if ($rule_check{$rule}) {
7323: $$rulematch{$user}{$item} = $rule;
7324: if ($inst_response eq 'ok') {
1.615 raeburn 7325: if (ref($inst_results) eq 'HASH') {
7326: if (ref($inst_results->{$user}) eq 'HASH') {
7327: if (keys(%{$inst_results->{$user}}) == 0) {
7328: $$alerts{$item}{$udom}{$uname} = 1;
7329: }
1.612 raeburn 7330: }
7331: }
1.615 raeburn 7332: }
7333: last;
1.585 raeburn 7334: }
7335: }
7336: }
7337: }
7338: }
7339: }
7340: }
7341: }
1.612 raeburn 7342: return;
7343: }
7344:
7345: sub user_rule_formats {
7346: my ($domain,$domdesc,$curr_rules,$check) = @_;
7347: my %text = (
7348: 'username' => 'Usernames',
7349: 'id' => 'IDs',
7350: );
7351: my $output;
7352: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
7353: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
7354: if (@{$ruleorder} > 0) {
7355: $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>';
7356: foreach my $rule (@{$ruleorder}) {
7357: if (ref($curr_rules) eq 'ARRAY') {
7358: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
7359: if (ref($rules->{$rule}) eq 'HASH') {
7360: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
7361: $rules->{$rule}{'desc'}.'</li>';
7362: }
7363: }
7364: }
7365: }
7366: $output .= '</ul>';
7367: }
7368: }
7369: return $output;
7370: }
7371:
7372: sub instrule_disallow_msg {
1.615 raeburn 7373: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 7374: my $response;
7375: my %text = (
7376: item => 'username',
7377: items => 'usernames',
7378: match => 'matches',
7379: do => 'does',
7380: action => 'a username',
7381: one => 'one',
7382: );
7383: if ($count > 1) {
7384: $text{'item'} = 'usernames';
7385: $text{'match'} ='match';
7386: $text{'do'} = 'do';
7387: $text{'action'} = 'usernames',
7388: $text{'one'} = 'ones';
7389: }
7390: if ($checkitem eq 'id') {
7391: $text{'items'} = 'IDs';
7392: $text{'item'} = 'ID';
7393: $text{'action'} = 'an ID';
1.615 raeburn 7394: if ($count > 1) {
7395: $text{'item'} = 'IDs';
7396: $text{'action'} = 'IDs';
7397: }
1.612 raeburn 7398: }
1.674 bisitz 7399: $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 7400: if ($mode eq 'upload') {
7401: if ($checkitem eq 'username') {
7402: $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'}.");
7403: } elsif ($checkitem eq 'id') {
1.674 bisitz 7404: $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 7405: }
1.669 raeburn 7406: } elsif ($mode eq 'selfcreate') {
7407: if ($checkitem eq 'id') {
7408: $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.");
7409: }
1.615 raeburn 7410: } else {
7411: if ($checkitem eq 'username') {
7412: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
7413: } elsif ($checkitem eq 'id') {
7414: $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.");
7415: }
1.612 raeburn 7416: }
7417: return $response;
1.585 raeburn 7418: }
7419:
1.624 raeburn 7420: sub personal_data_fieldtitles {
7421: my %fieldtitles = &Apache::lonlocal::texthash (
7422: id => 'Student/Employee ID',
7423: permanentemail => 'E-mail address',
7424: lastname => 'Last Name',
7425: firstname => 'First Name',
7426: middlename => 'Middle Name',
7427: generation => 'Generation',
7428: gen => 'Generation',
7429: );
7430: return %fieldtitles;
7431: }
7432:
1.642 raeburn 7433: sub sorted_inst_types {
7434: my ($dom) = @_;
7435: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
7436: my $othertitle = &mt('All users');
7437: if ($env{'request.course.id'}) {
1.668 raeburn 7438: $othertitle = &mt('Any users');
1.642 raeburn 7439: }
7440: my @types;
7441: if (ref($order) eq 'ARRAY') {
7442: @types = @{$order};
7443: }
7444: if (@types == 0) {
7445: if (ref($usertypes) eq 'HASH') {
7446: @types = sort(keys(%{$usertypes}));
7447: }
7448: }
7449: if (keys(%{$usertypes}) > 0) {
7450: $othertitle = &mt('Other users');
7451: }
7452: return ($othertitle,$usertypes,\@types);
7453: }
7454:
1.645 raeburn 7455: sub get_institutional_codes {
7456: my ($settings,$allcourses,$LC_code) = @_;
7457: # Get complete list of course sections to update
7458: my @currsections = ();
7459: my @currxlists = ();
7460: my $coursecode = $$settings{'internal.coursecode'};
7461:
7462: if ($$settings{'internal.sectionnums'} ne '') {
7463: @currsections = split(/,/,$$settings{'internal.sectionnums'});
7464: }
7465:
7466: if ($$settings{'internal.crosslistings'} ne '') {
7467: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
7468: }
7469:
7470: if (@currxlists > 0) {
7471: foreach (@currxlists) {
7472: if (m/^([^:]+):(\w*)$/) {
7473: unless (grep/^$1$/,@{$allcourses}) {
7474: push @{$allcourses},$1;
7475: $$LC_code{$1} = $2;
7476: }
7477: }
7478: }
7479: }
7480:
7481: if (@currsections > 0) {
7482: foreach (@currsections) {
7483: if (m/^(\w+):(\w*)$/) {
7484: my $sec = $coursecode.$1;
7485: my $lc_sec = $2;
7486: unless (grep/^$sec$/,@{$allcourses}) {
7487: push @{$allcourses},$sec;
7488: $$LC_code{$sec} = $lc_sec;
7489: }
7490: }
7491: }
7492: }
7493: return;
7494: }
7495:
1.112 bowersj2 7496: =pod
7497:
1.549 albertel 7498: =back
7499:
7500: =head1 HTTP Helpers
7501:
7502: =over 4
7503:
1.648 raeburn 7504: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 7505:
1.258 albertel 7506: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 7507: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 7508: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 7509:
7510: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
7511: $possible_names is an ref to an array of form element names. As an example:
7512: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 7513: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 7514:
7515: =cut
1.1 albertel 7516:
1.6 albertel 7517: sub get_unprocessed_cgi {
1.25 albertel 7518: my ($query,$possible_names)= @_;
1.26 matthew 7519: # $Apache::lonxml::debug=1;
1.356 albertel 7520: foreach my $pair (split(/&/,$query)) {
7521: my ($name, $value) = split(/=/,$pair);
1.369 www 7522: $name = &unescape($name);
1.25 albertel 7523: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
7524: $value =~ tr/+/ /;
7525: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 7526: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 7527: }
1.16 harris41 7528: }
1.6 albertel 7529: }
7530:
1.112 bowersj2 7531: =pod
7532:
1.648 raeburn 7533: =item * &cacheheader()
1.112 bowersj2 7534:
7535: returns cache-controlling header code
7536:
7537: =cut
7538:
1.7 albertel 7539: sub cacheheader {
1.258 albertel 7540: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 7541: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
7542: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 7543: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
7544: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 7545: return $output;
1.7 albertel 7546: }
7547:
1.112 bowersj2 7548: =pod
7549:
1.648 raeburn 7550: =item * &no_cache($r)
1.112 bowersj2 7551:
7552: specifies header code to not have cache
7553:
7554: =cut
7555:
1.9 albertel 7556: sub no_cache {
1.216 albertel 7557: my ($r) = @_;
7558: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 7559: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 7560: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
7561: $r->no_cache(1);
7562: $r->header_out("Expires" => $date);
7563: $r->header_out("Pragma" => "no-cache");
1.123 www 7564: }
7565:
7566: sub content_type {
1.181 albertel 7567: my ($r,$type,$charset) = @_;
1.299 foxr 7568: if ($r) {
7569: # Note that printout.pl calls this with undef for $r.
7570: &no_cache($r);
7571: }
1.258 albertel 7572: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 7573: unless ($charset) {
7574: $charset=&Apache::lonlocal::current_encoding;
7575: }
7576: if ($charset) { $type.='; charset='.$charset; }
7577: if ($r) {
7578: $r->content_type($type);
7579: } else {
7580: print("Content-type: $type\n\n");
7581: }
1.9 albertel 7582: }
1.25 albertel 7583:
1.112 bowersj2 7584: =pod
7585:
1.648 raeburn 7586: =item * &add_to_env($name,$value)
1.112 bowersj2 7587:
1.258 albertel 7588: adds $name to the %env hash with value
1.112 bowersj2 7589: $value, if $name already exists, the entry is converted to an array
7590: reference and $value is added to the array.
7591:
7592: =cut
7593:
1.25 albertel 7594: sub add_to_env {
7595: my ($name,$value)=@_;
1.258 albertel 7596: if (defined($env{$name})) {
7597: if (ref($env{$name})) {
1.25 albertel 7598: #already have multiple values
1.258 albertel 7599: push(@{ $env{$name} },$value);
1.25 albertel 7600: } else {
7601: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 7602: my $first=$env{$name};
7603: undef($env{$name});
7604: push(@{ $env{$name} },$first,$value);
1.25 albertel 7605: }
7606: } else {
1.258 albertel 7607: $env{$name}=$value;
1.25 albertel 7608: }
1.31 albertel 7609: }
1.149 albertel 7610:
7611: =pod
7612:
1.648 raeburn 7613: =item * &get_env_multiple($name)
1.149 albertel 7614:
1.258 albertel 7615: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 7616: values may be defined and end up as an array ref.
7617:
7618: returns an array of values
7619:
7620: =cut
7621:
7622: sub get_env_multiple {
7623: my ($name) = @_;
7624: my @values;
1.258 albertel 7625: if (defined($env{$name})) {
1.149 albertel 7626: # exists is it an array
1.258 albertel 7627: if (ref($env{$name})) {
7628: @values=@{ $env{$name} };
1.149 albertel 7629: } else {
1.258 albertel 7630: $values[0]=$env{$name};
1.149 albertel 7631: }
7632: }
7633: return(@values);
7634: }
7635:
1.660 raeburn 7636: sub ask_for_embedded_content {
7637: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
7638: my $upload_output = '
7639: <form name="upload_embedded" action="'.$actionurl.'"
7640: method="post" enctype="multipart/form-data">';
7641: $upload_output .= $state;
1.661 raeburn 7642: $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
1.660 raeburn 7643:
7644: my $num = 0;
7645: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
7646: $upload_output .= &start_data_table_row().
7647: '<td>'.$embed_file.'</td><td>';
7648: if ($args->{'ignore_remote_references'}
7649: && $embed_file =~ m{^\w+://}) {
7650: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
7651: } elsif ($args->{'error_on_invalid_names'}
7652: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
7653:
7654: $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
7655:
7656: } else {
7657: $upload_output .='
1.661 raeburn 7658: <input name="embedded_item_'.$num.'" type="file" value="" />
1.660 raeburn 7659: <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
7660: my $attrib = join(':',@{$$allfiles{$embed_file}});
7661: $upload_output .=
7662: "\n\t\t".
7663: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
7664: $attrib.'" />';
7665: if (exists($$codebase{$embed_file})) {
7666: $upload_output .=
7667: "\n\t\t".
7668: '<input name="codebase_'.$num.'" type="hidden" value="'.
7669: &escape($$codebase{$embed_file}).'" />';
7670: }
7671: }
7672: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
7673: $num++;
7674: }
7675: $upload_output .= &Apache::loncommon::end_data_table().'<br />
7676: <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
7677: <input type ="submit" value="'.&mt('Upload Listed Files').'" />
7678: '.&mt('(only files for which a location has been provided will be uploaded)').'
7679: </form>';
7680: return $upload_output;
7681: }
7682:
1.661 raeburn 7683: sub upload_embedded {
7684: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
7685: $current_disk_usage) = @_;
7686: my $output;
7687: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
7688: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
7689: my $orig_uploaded_filename =
7690: $env{'form.embedded_item_'.$i.'.filename'};
7691:
7692: $env{'form.embedded_orig_'.$i} =
7693: &unescape($env{'form.embedded_orig_'.$i});
7694: my ($path,$fname) =
7695: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
7696: # no path, whole string is fname
7697: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
7698:
7699: $path = $env{'form.currentpath'}.$path;
7700: $fname = &Apache::lonnet::clean_filename($fname);
7701: # See if there is anything left
7702: next if ($fname eq '');
7703:
7704: # Check if file already exists as a file or directory.
7705: my ($state,$msg);
7706: if ($context eq 'portfolio') {
7707: my $port_path = $dirpath;
7708: if ($group ne '') {
7709: $port_path = "groups/$group/$port_path";
7710: }
7711: ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
7712: $dir_root,$port_path,$disk_quota,
7713: $current_disk_usage,$uname,$udom);
7714: if ($state eq 'will_exceed_quota'
7715: || $state eq 'file_locked'
7716: || $state eq 'file_exists' ) {
7717: $output .= $msg;
7718: next;
7719: }
7720: } elsif (($context eq 'author') || ($context eq 'testbank')) {
7721: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
7722: if ($state eq 'exists') {
7723: $output .= $msg;
7724: next;
7725: }
7726: }
7727: # Check if extension is valid
7728: if (($fname =~ /\.(\w+)$/) &&
7729: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
7730: $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
7731: next;
7732: } elsif (($fname =~ /\.(\w+)$/) &&
7733: (!defined(&Apache::loncommon::fileembstyle($1)))) {
7734: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
7735: next;
7736: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
7737: $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
7738: next;
7739: }
7740:
7741: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
7742: if ($context eq 'portfolio') {
7743: my $result=
7744: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
7745: $dirpath.$path);
7746: if ($result !~ m|^/uploaded/|) {
7747: $output .= '<span class="LC_error">'
7748: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
7749: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
7750: .'</span><br />';
7751: next;
7752: } else {
7753: $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
7754: $path.$fname.'</span>').'</p>';
7755: }
7756: } else {
7757: # Save the file
7758: my $target = $env{'form.embedded_item_'.$i};
7759: my $fullpath = $dir_root.$dirpath.'/'.$path;
7760: my $dest = $fullpath.$fname;
7761: my $url = $url_root.$dirpath.'/'.$path.$fname;
7762: my @parts=split(/\//,$fullpath);
7763: my $count;
7764: my $filepath = $dir_root;
7765: for ($count=4;$count<=$#parts;$count++) {
7766: $filepath .= "/$parts[$count]";
7767: if ((-e $filepath)!=1) {
7768: mkdir($filepath,0770);
7769: }
7770: }
7771: my $fh;
7772: if (!open($fh,'>'.$dest)) {
7773: &Apache::lonnet::logthis('Failed to create '.$dest);
7774: $output .= '<span class="LC_error">'.
7775: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
7776: '</span><br />';
7777: } else {
7778: if (!print $fh $env{'form.embedded_item_'.$i}) {
7779: &Apache::lonnet::logthis('Failed to write to '.$dest);
7780: $output .= '<span class="LC_error">'.
7781: &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
7782: '</span><br />';
7783: } else {
7784: if ($context eq 'testbank') {
7785: $output .= &mt('Embedded file uploaded successfully:').
7786: ' <a href="'.$url.'">'.
7787: $orig_uploaded_filename.'</a><br />';
7788: } else {
1.705 tempelho 7789: $output .= '<span class=\"LC_fontsize_large\">'.
1.661 raeburn 7790: &mt('View embedded file: [_1]','<a href="'.$url.'">'.
1.705 tempelho 7791: $orig_uploaded_filename.'</a>').'</span><br />';
1.661 raeburn 7792: }
7793: }
7794: close($fh);
7795: }
7796: }
7797: }
7798: return $output;
7799: }
7800:
7801: sub check_for_existing {
7802: my ($path,$fname,$element) = @_;
7803: my ($state,$msg);
7804: if (-d $path.'/'.$fname) {
7805: $state = 'exists';
7806: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
7807: } elsif (-e $path.'/'.$fname) {
7808: $state = 'exists';
7809: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
7810: }
7811: if ($state eq 'exists') {
7812: $msg = '<span class="LC_error">'.$msg.'</span><br />';
7813: }
7814: return ($state,$msg);
7815: }
7816:
7817: sub check_for_upload {
7818: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
7819: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
7820: my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
7821: my $getpropath = 1;
7822: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
7823: $getpropath);
7824: my $found_file = 0;
7825: my $locked_file = 0;
7826: foreach my $line (@dir_list) {
7827: my ($file_name)=split(/\&/,$line,2);
7828: if ($file_name eq $fname){
7829: $file_name = $path.$file_name;
7830: if ($group ne '') {
7831: $file_name = $group.$file_name;
7832: }
7833: $found_file = 1;
7834: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
7835: $locked_file = 1;
7836: }
7837: }
7838: }
7839: if (($current_disk_usage + $filesize) > $disk_quota){
7840: my $msg = '<span class="LC_error">'.
7841: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
7842: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
7843: return ('will_exceed_quota',$msg);
7844: } elsif ($found_file) {
7845: if ($locked_file) {
7846: my $msg = '<span class="LC_error">';
7847: $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>');
7848: $msg .= '</span><br />';
7849: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
7850: return ('file_locked',$msg);
7851: } else {
7852: my $msg = '<span class="LC_error">';
7853: $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'});
7854: $msg .= '</span>';
7855: $msg .= '<br />';
7856: $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
7857: return ('file_exists',$msg);
7858: }
7859: }
7860: }
7861:
1.31 albertel 7862:
1.41 ng 7863: =pod
1.45 matthew 7864:
1.464 albertel 7865: =back
1.41 ng 7866:
1.112 bowersj2 7867: =head1 CSV Upload/Handling functions
1.38 albertel 7868:
1.41 ng 7869: =over 4
7870:
1.648 raeburn 7871: =item * &upfile_store($r)
1.41 ng 7872:
7873: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 7874: needs $env{'form.upfile'}
1.41 ng 7875: returns $datatoken to be put into hidden field
7876:
7877: =cut
1.31 albertel 7878:
7879: sub upfile_store {
7880: my $r=shift;
1.258 albertel 7881: $env{'form.upfile'}=~s/\r/\n/gs;
7882: $env{'form.upfile'}=~s/\f/\n/gs;
7883: $env{'form.upfile'}=~s/\n+/\n/gs;
7884: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 7885:
1.258 albertel 7886: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
7887: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 7888: {
1.158 raeburn 7889: my $datafile = $r->dir_config('lonDaemons').
7890: '/tmp/'.$datatoken.'.tmp';
7891: if ( open(my $fh,">$datafile") ) {
1.258 albertel 7892: print $fh $env{'form.upfile'};
1.158 raeburn 7893: close($fh);
7894: }
1.31 albertel 7895: }
7896: return $datatoken;
7897: }
7898:
1.56 matthew 7899: =pod
7900:
1.648 raeburn 7901: =item * &load_tmp_file($r)
1.41 ng 7902:
7903: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 7904: needs $env{'form.datatoken'},
7905: sets $env{'form.upfile'} to the contents of the file
1.41 ng 7906:
7907: =cut
1.31 albertel 7908:
7909: sub load_tmp_file {
7910: my $r=shift;
7911: my @studentdata=();
7912: {
1.158 raeburn 7913: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 7914: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 7915: if ( open(my $fh,"<$studentfile") ) {
7916: @studentdata=<$fh>;
7917: close($fh);
7918: }
1.31 albertel 7919: }
1.258 albertel 7920: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 7921: }
7922:
1.56 matthew 7923: =pod
7924:
1.648 raeburn 7925: =item * &upfile_record_sep()
1.41 ng 7926:
7927: Separate uploaded file into records
7928: returns array of records,
1.258 albertel 7929: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 7930:
7931: =cut
1.31 albertel 7932:
7933: sub upfile_record_sep {
1.258 albertel 7934: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 7935: } else {
1.248 albertel 7936: my @records;
1.258 albertel 7937: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 7938: if ($line=~/^\s*$/) { next; }
7939: push(@records,$line);
7940: }
7941: return @records;
1.31 albertel 7942: }
7943: }
7944:
1.56 matthew 7945: =pod
7946:
1.648 raeburn 7947: =item * &record_sep($record)
1.41 ng 7948:
1.258 albertel 7949: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 7950:
7951: =cut
7952:
1.263 www 7953: sub takeleft {
7954: my $index=shift;
7955: return substr('0000'.$index,-4,4);
7956: }
7957:
1.31 albertel 7958: sub record_sep {
7959: my $record=shift;
7960: my %components=();
1.258 albertel 7961: if ($env{'form.upfiletype'} eq 'xml') {
7962: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 7963: my $i=0;
1.356 albertel 7964: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 7965: $field=~s/^(\"|\')//;
7966: $field=~s/(\"|\')$//;
1.263 www 7967: $components{&takeleft($i)}=$field;
1.31 albertel 7968: $i++;
7969: }
1.258 albertel 7970: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 7971: my $i=0;
1.356 albertel 7972: foreach my $field (split(/\t/,$record)) {
1.31 albertel 7973: $field=~s/^(\"|\')//;
7974: $field=~s/(\"|\')$//;
1.263 www 7975: $components{&takeleft($i)}=$field;
1.31 albertel 7976: $i++;
7977: }
7978: } else {
1.561 www 7979: my $separator=',';
1.480 banghart 7980: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 7981: $separator=';';
1.480 banghart 7982: }
1.31 albertel 7983: my $i=0;
1.561 www 7984: # the character we are looking for to indicate the end of a quote or a record
7985: my $looking_for=$separator;
7986: # do not add the characters to the fields
7987: my $ignore=0;
7988: # we just encountered a separator (or the beginning of the record)
7989: my $just_found_separator=1;
7990: # store the field we are working on here
7991: my $field='';
7992: # work our way through all characters in record
7993: foreach my $character ($record=~/(.)/g) {
7994: if ($character eq $looking_for) {
7995: if ($character ne $separator) {
7996: # Found the end of a quote, again looking for separator
7997: $looking_for=$separator;
7998: $ignore=1;
7999: } else {
8000: # Found a separator, store away what we got
8001: $components{&takeleft($i)}=$field;
8002: $i++;
8003: $just_found_separator=1;
8004: $ignore=0;
8005: $field='';
8006: }
8007: next;
8008: }
8009: # single or double quotation marks after a separator indicate beginning of a quote
8010: # we are now looking for the end of the quote and need to ignore separators
8011: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
8012: $looking_for=$character;
8013: next;
8014: }
8015: # ignore would be true after we reached the end of a quote
8016: if ($ignore) { next; }
8017: if (($just_found_separator) && ($character=~/\s/)) { next; }
8018: $field.=$character;
8019: $just_found_separator=0;
1.31 albertel 8020: }
1.561 www 8021: # catch the very last entry, since we never encountered the separator
8022: $components{&takeleft($i)}=$field;
1.31 albertel 8023: }
8024: return %components;
8025: }
8026:
1.144 matthew 8027: ######################################################
8028: ######################################################
8029:
1.56 matthew 8030: =pod
8031:
1.648 raeburn 8032: =item * &upfile_select_html()
1.41 ng 8033:
1.144 matthew 8034: Return HTML code to select a file from the users machine and specify
8035: the file type.
1.41 ng 8036:
8037: =cut
8038:
1.144 matthew 8039: ######################################################
8040: ######################################################
1.31 albertel 8041: sub upfile_select_html {
1.144 matthew 8042: my %Types = (
8043: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 8044: semisv => &mt('Semicolon separated values'),
1.144 matthew 8045: space => &mt('Space separated'),
8046: tab => &mt('Tabulator separated'),
8047: # xml => &mt('HTML/XML'),
8048: );
8049: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 8050: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 8051: foreach my $type (sort(keys(%Types))) {
8052: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
8053: }
8054: $Str .= "</select>\n";
8055: return $Str;
1.31 albertel 8056: }
8057:
1.301 albertel 8058: sub get_samples {
8059: my ($records,$toget) = @_;
8060: my @samples=({});
8061: my $got=0;
8062: foreach my $rec (@$records) {
8063: my %temp = &record_sep($rec);
8064: if (! grep(/\S/, values(%temp))) { next; }
8065: if (%temp) {
8066: $samples[$got]=\%temp;
8067: $got++;
8068: if ($got == $toget) { last; }
8069: }
8070: }
8071: return \@samples;
8072: }
8073:
1.144 matthew 8074: ######################################################
8075: ######################################################
8076:
1.56 matthew 8077: =pod
8078:
1.648 raeburn 8079: =item * &csv_print_samples($r,$records)
1.41 ng 8080:
8081: Prints a table of sample values from each column uploaded $r is an
8082: Apache Request ref, $records is an arrayref from
8083: &Apache::loncommon::upfile_record_sep
8084:
8085: =cut
8086:
1.144 matthew 8087: ######################################################
8088: ######################################################
1.31 albertel 8089: sub csv_print_samples {
8090: my ($r,$records) = @_;
1.662 bisitz 8091: my $samples = &get_samples($records,5);
1.301 albertel 8092:
1.594 raeburn 8093: $r->print(&mt('Samples').'<br />'.&start_data_table().
8094: &start_data_table_header_row());
1.356 albertel 8095: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8096: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 8097: $r->print(&end_data_table_header_row());
1.301 albertel 8098: foreach my $hash (@$samples) {
1.594 raeburn 8099: $r->print(&start_data_table_row());
1.356 albertel 8100: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 8101: $r->print('<td>');
1.356 albertel 8102: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 8103: $r->print('</td>');
8104: }
1.594 raeburn 8105: $r->print(&end_data_table_row());
1.31 albertel 8106: }
1.594 raeburn 8107: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 8108: }
8109:
1.144 matthew 8110: ######################################################
8111: ######################################################
8112:
1.56 matthew 8113: =pod
8114:
1.648 raeburn 8115: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 8116:
8117: Prints a table to create associations between values and table columns.
1.144 matthew 8118:
1.41 ng 8119: $r is an Apache Request ref,
8120: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 8121: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 8122:
8123: =cut
8124:
1.144 matthew 8125: ######################################################
8126: ######################################################
1.31 albertel 8127: sub csv_print_select_table {
8128: my ($r,$records,$d) = @_;
1.301 albertel 8129: my $i=0;
8130: my $samples = &get_samples($records,1);
1.144 matthew 8131: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 8132: &start_data_table().&start_data_table_header_row().
1.144 matthew 8133: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 8134: '<th>'.&mt('Column').'</th>'.
8135: &end_data_table_header_row()."\n");
1.356 albertel 8136: foreach my $array_ref (@$d) {
8137: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 8138: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 8139:
8140: $r->print('<td><select name=f'.$i.
1.32 matthew 8141: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 8142: $r->print('<option value="none"></option>');
1.356 albertel 8143: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8144: $r->print('<option value="'.$sample.'"'.
8145: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 8146: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 8147: }
1.594 raeburn 8148: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 8149: $i++;
8150: }
1.594 raeburn 8151: $r->print(&end_data_table());
1.31 albertel 8152: $i--;
8153: return $i;
8154: }
1.56 matthew 8155:
1.144 matthew 8156: ######################################################
8157: ######################################################
8158:
1.56 matthew 8159: =pod
1.31 albertel 8160:
1.648 raeburn 8161: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 8162:
8163: Prints a table of sample values from the upload and can make associate samples to internal names.
8164:
8165: $r is an Apache Request ref,
8166: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
8167: $d is an array of 2 element arrays (internal name, displayed name)
8168:
8169: =cut
8170:
1.144 matthew 8171: ######################################################
8172: ######################################################
1.31 albertel 8173: sub csv_samples_select_table {
8174: my ($r,$records,$d) = @_;
8175: my $i=0;
1.144 matthew 8176: #
1.662 bisitz 8177: my $max_samples = 5;
8178: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 8179: $r->print(&start_data_table().
8180: &start_data_table_header_row().'<th>'.
8181: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
8182: &end_data_table_header_row());
1.301 albertel 8183:
8184: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 8185: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 8186: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 8187: foreach my $option (@$d) {
8188: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 8189: $r->print('<option value="'.$value.'"'.
1.253 albertel 8190: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 8191: $display.'</option>');
1.31 albertel 8192: }
8193: $r->print('</select></td><td>');
1.662 bisitz 8194: foreach my $line (0..($max_samples-1)) {
1.301 albertel 8195: if (defined($samples->[$line]{$key})) {
8196: $r->print($samples->[$line]{$key}."<br />\n");
8197: }
8198: }
1.594 raeburn 8199: $r->print('</td>'.&end_data_table_row());
1.31 albertel 8200: $i++;
8201: }
1.594 raeburn 8202: $r->print(&end_data_table());
1.31 albertel 8203: $i--;
8204: return($i);
1.115 matthew 8205: }
8206:
1.144 matthew 8207: ######################################################
8208: ######################################################
8209:
1.115 matthew 8210: =pod
8211:
1.648 raeburn 8212: =item * &clean_excel_name($name)
1.115 matthew 8213:
8214: Returns a replacement for $name which does not contain any illegal characters.
8215:
8216: =cut
8217:
1.144 matthew 8218: ######################################################
8219: ######################################################
1.115 matthew 8220: sub clean_excel_name {
8221: my ($name) = @_;
8222: $name =~ s/[:\*\?\/\\]//g;
8223: if (length($name) > 31) {
8224: $name = substr($name,0,31);
8225: }
8226: return $name;
1.25 albertel 8227: }
1.84 albertel 8228:
1.85 albertel 8229: =pod
8230:
1.648 raeburn 8231: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 8232:
8233: Returns either 1 or undef
8234:
8235: 1 if the part is to be hidden, undef if it is to be shown
8236:
8237: Arguments are:
8238:
8239: $id the id of the part to be checked
8240: $symb, optional the symb of the resource to check
8241: $udom, optional the domain of the user to check for
8242: $uname, optional the username of the user to check for
8243:
8244: =cut
1.84 albertel 8245:
8246: sub check_if_partid_hidden {
8247: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 8248: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 8249: $symb,$udom,$uname);
1.141 albertel 8250: my $truth=1;
8251: #if the string starts with !, then the list is the list to show not hide
8252: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 8253: my @hiddenlist=split(/,/,$hiddenparts);
8254: foreach my $checkid (@hiddenlist) {
1.141 albertel 8255: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 8256: }
1.141 albertel 8257: return !$truth;
1.84 albertel 8258: }
1.127 matthew 8259:
1.138 matthew 8260:
8261: ############################################################
8262: ############################################################
8263:
8264: =pod
8265:
1.157 matthew 8266: =back
8267:
1.138 matthew 8268: =head1 cgi-bin script and graphing routines
8269:
1.157 matthew 8270: =over 4
8271:
1.648 raeburn 8272: =item * &get_cgi_id()
1.138 matthew 8273:
8274: Inputs: none
8275:
8276: Returns an id which can be used to pass environment variables
8277: to various cgi-bin scripts. These environment variables will
8278: be removed from the users environment after a given time by
8279: the routine &Apache::lonnet::transfer_profile_to_env.
8280:
8281: =cut
8282:
8283: ############################################################
8284: ############################################################
1.152 albertel 8285: my $uniq=0;
1.136 matthew 8286: sub get_cgi_id {
1.154 albertel 8287: $uniq=($uniq+1)%100000;
1.280 albertel 8288: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 8289: }
8290:
1.127 matthew 8291: ############################################################
8292: ############################################################
8293:
8294: =pod
8295:
1.648 raeburn 8296: =item * &DrawBarGraph()
1.127 matthew 8297:
1.138 matthew 8298: Facilitates the plotting of data in a (stacked) bar graph.
8299: Puts plot definition data into the users environment in order for
8300: graph.png to plot it. Returns an <img> tag for the plot.
8301: The bars on the plot are labeled '1','2',...,'n'.
8302:
8303: Inputs:
8304:
8305: =over 4
8306:
8307: =item $Title: string, the title of the plot
8308:
8309: =item $xlabel: string, text describing the X-axis of the plot
8310:
8311: =item $ylabel: string, text describing the Y-axis of the plot
8312:
8313: =item $Max: scalar, the maximum Y value to use in the plot
8314: If $Max is < any data point, the graph will not be rendered.
8315:
1.140 matthew 8316: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 8317: they are plotted. If undefined, default values will be used.
8318:
1.178 matthew 8319: =item $labels: array ref holding the labels to use on the x-axis for the bars.
8320:
1.138 matthew 8321: =item @Values: An array of array references. Each array reference holds data
8322: to be plotted in a stacked bar chart.
8323:
1.239 matthew 8324: =item If the final element of @Values is a hash reference the key/value
8325: pairs will be added to the graph definition.
8326:
1.138 matthew 8327: =back
8328:
8329: Returns:
8330:
8331: An <img> tag which references graph.png and the appropriate identifying
8332: information for the plot.
8333:
1.127 matthew 8334: =cut
8335:
8336: ############################################################
8337: ############################################################
1.134 matthew 8338: sub DrawBarGraph {
1.178 matthew 8339: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 8340: #
8341: if (! defined($colors)) {
8342: $colors = ['#33ff00',
8343: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
8344: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
8345: ];
8346: }
1.228 matthew 8347: my $extra_settings = {};
8348: if (ref($Values[-1]) eq 'HASH') {
8349: $extra_settings = pop(@Values);
8350: }
1.127 matthew 8351: #
1.136 matthew 8352: my $identifier = &get_cgi_id();
8353: my $id = 'cgi.'.$identifier;
1.129 matthew 8354: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 8355: return '';
8356: }
1.225 matthew 8357: #
8358: my @Labels;
8359: if (defined($labels)) {
8360: @Labels = @$labels;
8361: } else {
8362: for (my $i=0;$i<@{$Values[0]};$i++) {
8363: push (@Labels,$i+1);
8364: }
8365: }
8366: #
1.129 matthew 8367: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 8368: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 8369: my %ValuesHash;
8370: my $NumSets=1;
8371: foreach my $array (@Values) {
8372: next if (! ref($array));
1.136 matthew 8373: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 8374: join(',',@$array);
1.129 matthew 8375: }
1.127 matthew 8376: #
1.136 matthew 8377: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 8378: if ($NumBars < 3) {
8379: $width = 120+$NumBars*32;
1.220 matthew 8380: $xskip = 1;
1.225 matthew 8381: $bar_width = 30;
8382: } elsif ($NumBars < 5) {
8383: $width = 120+$NumBars*20;
8384: $xskip = 1;
8385: $bar_width = 20;
1.220 matthew 8386: } elsif ($NumBars < 10) {
1.136 matthew 8387: $width = 120+$NumBars*15;
8388: $xskip = 1;
8389: $bar_width = 15;
8390: } elsif ($NumBars <= 25) {
8391: $width = 120+$NumBars*11;
8392: $xskip = 5;
8393: $bar_width = 8;
8394: } elsif ($NumBars <= 50) {
8395: $width = 120+$NumBars*8;
8396: $xskip = 5;
8397: $bar_width = 4;
8398: } else {
8399: $width = 120+$NumBars*8;
8400: $xskip = 5;
8401: $bar_width = 4;
8402: }
8403: #
1.137 matthew 8404: $Max = 1 if ($Max < 1);
8405: if ( int($Max) < $Max ) {
8406: $Max++;
8407: $Max = int($Max);
8408: }
1.127 matthew 8409: $Title = '' if (! defined($Title));
8410: $xlabel = '' if (! defined($xlabel));
8411: $ylabel = '' if (! defined($ylabel));
1.369 www 8412: $ValuesHash{$id.'.title'} = &escape($Title);
8413: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
8414: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 8415: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 8416: $ValuesHash{$id.'.NumBars'} = $NumBars;
8417: $ValuesHash{$id.'.NumSets'} = $NumSets;
8418: $ValuesHash{$id.'.PlotType'} = 'bar';
8419: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8420: $ValuesHash{$id.'.height'} = $height;
8421: $ValuesHash{$id.'.width'} = $width;
8422: $ValuesHash{$id.'.xskip'} = $xskip;
8423: $ValuesHash{$id.'.bar_width'} = $bar_width;
8424: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 8425: #
1.228 matthew 8426: # Deal with other parameters
8427: while (my ($key,$value) = each(%$extra_settings)) {
8428: $ValuesHash{$id.'.'.$key} = $value;
8429: }
8430: #
1.646 raeburn 8431: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 8432: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8433: }
8434:
8435: ############################################################
8436: ############################################################
8437:
8438: =pod
8439:
1.648 raeburn 8440: =item * &DrawXYGraph()
1.137 matthew 8441:
1.138 matthew 8442: Facilitates the plotting of data in an XY graph.
8443: Puts plot definition data into the users environment in order for
8444: graph.png to plot it. Returns an <img> tag for the plot.
8445:
8446: Inputs:
8447:
8448: =over 4
8449:
8450: =item $Title: string, the title of the plot
8451:
8452: =item $xlabel: string, text describing the X-axis of the plot
8453:
8454: =item $ylabel: string, text describing the Y-axis of the plot
8455:
8456: =item $Max: scalar, the maximum Y value to use in the plot
8457: If $Max is < any data point, the graph will not be rendered.
8458:
8459: =item $colors: Array ref containing the hex color codes for the data to be
8460: plotted in. If undefined, default values will be used.
8461:
8462: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8463:
8464: =item $Ydata: Array ref containing Array refs.
1.185 www 8465: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 8466:
8467: =item %Values: hash indicating or overriding any default values which are
8468: passed to graph.png.
8469: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
8470:
8471: =back
8472:
8473: Returns:
8474:
8475: An <img> tag which references graph.png and the appropriate identifying
8476: information for the plot.
8477:
1.137 matthew 8478: =cut
8479:
8480: ############################################################
8481: ############################################################
8482: sub DrawXYGraph {
8483: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
8484: #
8485: # Create the identifier for the graph
8486: my $identifier = &get_cgi_id();
8487: my $id = 'cgi.'.$identifier;
8488: #
8489: $Title = '' if (! defined($Title));
8490: $xlabel = '' if (! defined($xlabel));
8491: $ylabel = '' if (! defined($ylabel));
8492: my %ValuesHash =
8493: (
1.369 www 8494: $id.'.title' => &escape($Title),
8495: $id.'.xlabel' => &escape($xlabel),
8496: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 8497: $id.'.y_max_value'=> $Max,
8498: $id.'.labels' => join(',',@$Xlabels),
8499: $id.'.PlotType' => 'XY',
8500: );
8501: #
8502: if (defined($colors) && ref($colors) eq 'ARRAY') {
8503: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8504: }
8505: #
8506: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
8507: return '';
8508: }
8509: my $NumSets=1;
1.138 matthew 8510: foreach my $array (@{$Ydata}){
1.137 matthew 8511: next if (! ref($array));
8512: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
8513: }
1.138 matthew 8514: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 8515: #
8516: # Deal with other parameters
8517: while (my ($key,$value) = each(%Values)) {
8518: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 8519: }
8520: #
1.646 raeburn 8521: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 8522: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8523: }
8524:
8525: ############################################################
8526: ############################################################
8527:
8528: =pod
8529:
1.648 raeburn 8530: =item * &DrawXYYGraph()
1.138 matthew 8531:
8532: Facilitates the plotting of data in an XY graph with two Y axes.
8533: Puts plot definition data into the users environment in order for
8534: graph.png to plot it. Returns an <img> tag for the plot.
8535:
8536: Inputs:
8537:
8538: =over 4
8539:
8540: =item $Title: string, the title of the plot
8541:
8542: =item $xlabel: string, text describing the X-axis of the plot
8543:
8544: =item $ylabel: string, text describing the Y-axis of the plot
8545:
8546: =item $colors: Array ref containing the hex color codes for the data to be
8547: plotted in. If undefined, default values will be used.
8548:
8549: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8550:
8551: =item $Ydata1: The first data set
8552:
8553: =item $Min1: The minimum value of the left Y-axis
8554:
8555: =item $Max1: The maximum value of the left Y-axis
8556:
8557: =item $Ydata2: The second data set
8558:
8559: =item $Min2: The minimum value of the right Y-axis
8560:
8561: =item $Max2: The maximum value of the left Y-axis
8562:
8563: =item %Values: hash indicating or overriding any default values which are
8564: passed to graph.png.
8565: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
8566:
8567: =back
8568:
8569: Returns:
8570:
8571: An <img> tag which references graph.png and the appropriate identifying
8572: information for the plot.
1.136 matthew 8573:
8574: =cut
8575:
8576: ############################################################
8577: ############################################################
1.137 matthew 8578: sub DrawXYYGraph {
8579: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
8580: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 8581: #
8582: # Create the identifier for the graph
8583: my $identifier = &get_cgi_id();
8584: my $id = 'cgi.'.$identifier;
8585: #
8586: $Title = '' if (! defined($Title));
8587: $xlabel = '' if (! defined($xlabel));
8588: $ylabel = '' if (! defined($ylabel));
8589: my %ValuesHash =
8590: (
1.369 www 8591: $id.'.title' => &escape($Title),
8592: $id.'.xlabel' => &escape($xlabel),
8593: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 8594: $id.'.labels' => join(',',@$Xlabels),
8595: $id.'.PlotType' => 'XY',
8596: $id.'.NumSets' => 2,
1.137 matthew 8597: $id.'.two_axes' => 1,
8598: $id.'.y1_max_value' => $Max1,
8599: $id.'.y1_min_value' => $Min1,
8600: $id.'.y2_max_value' => $Max2,
8601: $id.'.y2_min_value' => $Min2,
1.136 matthew 8602: );
8603: #
1.137 matthew 8604: if (defined($colors) && ref($colors) eq 'ARRAY') {
8605: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8606: }
8607: #
8608: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
8609: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 8610: return '';
8611: }
8612: my $NumSets=1;
1.137 matthew 8613: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 8614: next if (! ref($array));
8615: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 8616: }
8617: #
8618: # Deal with other parameters
8619: while (my ($key,$value) = each(%Values)) {
8620: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 8621: }
8622: #
1.646 raeburn 8623: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 8624: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 8625: }
8626:
8627: ############################################################
8628: ############################################################
8629:
8630: =pod
8631:
1.157 matthew 8632: =back
8633:
1.139 matthew 8634: =head1 Statistics helper routines?
8635:
8636: Bad place for them but what the hell.
8637:
1.157 matthew 8638: =over 4
8639:
1.648 raeburn 8640: =item * &chartlink()
1.139 matthew 8641:
8642: Returns a link to the chart for a specific student.
8643:
8644: Inputs:
8645:
8646: =over 4
8647:
8648: =item $linktext: The text of the link
8649:
8650: =item $sname: The students username
8651:
8652: =item $sdomain: The students domain
8653:
8654: =back
8655:
1.157 matthew 8656: =back
8657:
1.139 matthew 8658: =cut
8659:
8660: ############################################################
8661: ############################################################
8662: sub chartlink {
8663: my ($linktext, $sname, $sdomain) = @_;
8664: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 8665: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 8666: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 8667: '">'.$linktext.'</a>';
1.153 matthew 8668: }
8669:
8670: #######################################################
8671: #######################################################
8672:
8673: =pod
8674:
8675: =head1 Course Environment Routines
1.157 matthew 8676:
8677: =over 4
1.153 matthew 8678:
1.648 raeburn 8679: =item * &restore_course_settings()
1.153 matthew 8680:
1.648 raeburn 8681: =item * &store_course_settings()
1.153 matthew 8682:
8683: Restores/Store indicated form parameters from the course environment.
8684: Will not overwrite existing values of the form parameters.
8685:
8686: Inputs:
8687: a scalar describing the data (e.g. 'chart', 'problem_analysis')
8688:
8689: a hash ref describing the data to be stored. For example:
8690:
8691: %Save_Parameters = ('Status' => 'scalar',
8692: 'chartoutputmode' => 'scalar',
8693: 'chartoutputdata' => 'scalar',
8694: 'Section' => 'array',
1.373 raeburn 8695: 'Group' => 'array',
1.153 matthew 8696: 'StudentData' => 'array',
8697: 'Maps' => 'array');
8698:
8699: Returns: both routines return nothing
8700:
1.631 raeburn 8701: =back
8702:
1.153 matthew 8703: =cut
8704:
8705: #######################################################
8706: #######################################################
8707: sub store_course_settings {
1.496 albertel 8708: return &store_settings($env{'request.course.id'},@_);
8709: }
8710:
8711: sub store_settings {
1.153 matthew 8712: # save to the environment
8713: # appenv the same items, just to be safe
1.300 albertel 8714: my $udom = $env{'user.domain'};
8715: my $uname = $env{'user.name'};
1.496 albertel 8716: my ($context,$prefix,$Settings) = @_;
1.153 matthew 8717: my %SaveHash;
8718: my %AppHash;
8719: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 8720: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 8721: my $envname = 'environment.'.$basename;
1.258 albertel 8722: if (exists($env{'form.'.$setting})) {
1.153 matthew 8723: # Save this value away
8724: if ($type eq 'scalar' &&
1.258 albertel 8725: (! exists($env{$envname}) ||
8726: $env{$envname} ne $env{'form.'.$setting})) {
8727: $SaveHash{$basename} = $env{'form.'.$setting};
8728: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 8729: } elsif ($type eq 'array') {
8730: my $stored_form;
1.258 albertel 8731: if (ref($env{'form.'.$setting})) {
1.153 matthew 8732: $stored_form = join(',',
8733: map {
1.369 www 8734: &escape($_);
1.258 albertel 8735: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 8736: } else {
8737: $stored_form =
1.369 www 8738: &escape($env{'form.'.$setting});
1.153 matthew 8739: }
8740: # Determine if the array contents are the same.
1.258 albertel 8741: if ($stored_form ne $env{$envname}) {
1.153 matthew 8742: $SaveHash{$basename} = $stored_form;
8743: $AppHash{$envname} = $stored_form;
8744: }
8745: }
8746: }
8747: }
8748: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 8749: $udom,$uname);
1.153 matthew 8750: if ($put_result !~ /^(ok|delayed)/) {
8751: &Apache::lonnet::logthis('unable to save form parameters, '.
8752: 'got error:'.$put_result);
8753: }
8754: # Make sure these settings stick around in this session, too
1.646 raeburn 8755: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 8756: return;
8757: }
8758:
8759: sub restore_course_settings {
1.499 albertel 8760: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 8761: }
8762:
8763: sub restore_settings {
8764: my ($context,$prefix,$Settings) = @_;
1.153 matthew 8765: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 8766: next if (exists($env{'form.'.$setting}));
1.496 albertel 8767: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 8768: '.'.$setting;
1.258 albertel 8769: if (exists($env{$envname})) {
1.153 matthew 8770: if ($type eq 'scalar') {
1.258 albertel 8771: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 8772: } elsif ($type eq 'array') {
1.258 albertel 8773: $env{'form.'.$setting} = [
1.153 matthew 8774: map {
1.369 www 8775: &unescape($_);
1.258 albertel 8776: } split(',',$env{$envname})
1.153 matthew 8777: ];
8778: }
8779: }
8780: }
1.127 matthew 8781: }
8782:
1.618 raeburn 8783: #######################################################
8784: #######################################################
8785:
8786: =pod
8787:
8788: =head1 Domain E-mail Routines
8789:
8790: =over 4
8791:
1.648 raeburn 8792: =item * &build_recipient_list()
1.618 raeburn 8793:
8794: Build recipient lists for three types of e-mail:
8795: (a) Error Reports, (b) Package Updates, (c) Help requests, generated by
1.619 raeburn 8796: lonerrorhandler.pm, CHECKRPMS and lonsupportreq.pm respectively.
1.618 raeburn 8797:
8798: Inputs:
1.619 raeburn 8799: defmail (scalar - email address of default recipient),
1.618 raeburn 8800: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 8801: defdom (domain for which to retrieve configuration settings),
8802: origmail (scalar - email address of recipient from loncapa.conf,
8803: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 8804:
1.655 raeburn 8805: Returns: comma separated list of addresses to which to send e-mail.
8806:
8807: =back
1.618 raeburn 8808:
8809: =cut
8810:
8811: ############################################################
8812: ############################################################
8813: sub build_recipient_list {
1.619 raeburn 8814: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 8815: my @recipients;
8816: my $otheremails;
8817: my %domconfig =
8818: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
8819: if (ref($domconfig{'contacts'}) eq 'HASH') {
8820: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
8821: my @contacts = ('adminemail','supportemail');
8822: foreach my $item (@contacts) {
8823: if ($domconfig{'contacts'}{$mailing}{$item}) {
1.619 raeburn 8824: my $addr = $domconfig{'contacts'}{$item};
8825: if (!grep(/^\Q$addr\E$/,@recipients)) {
8826: push(@recipients,$addr);
8827: }
1.618 raeburn 8828: }
8829: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
8830: }
8831: }
1.619 raeburn 8832: } elsif ($origmail ne '') {
8833: push(@recipients,$origmail);
1.618 raeburn 8834: }
1.688 raeburn 8835: if (defined($defmail)) {
8836: if ($defmail ne '') {
8837: push(@recipients,$defmail);
8838: }
1.618 raeburn 8839: }
8840: if ($otheremails) {
1.619 raeburn 8841: my @others;
8842: if ($otheremails =~ /,/) {
8843: @others = split(/,/,$otheremails);
1.618 raeburn 8844: } else {
1.619 raeburn 8845: push(@others,$otheremails);
8846: }
8847: foreach my $addr (@others) {
8848: if (!grep(/^\Q$addr\E$/,@recipients)) {
8849: push(@recipients,$addr);
8850: }
1.618 raeburn 8851: }
8852: }
1.619 raeburn 8853: my $recipientlist = join(',',@recipients);
1.618 raeburn 8854: return $recipientlist;
8855: }
8856:
1.127 matthew 8857: ############################################################
8858: ############################################################
1.154 albertel 8859:
1.655 raeburn 8860: =pod
8861:
8862: =head1 Course Catalog Routines
8863:
8864: =over 4
8865:
8866: =item * &gather_categories()
8867:
8868: Converts category definitions - keys of categories hash stored in
8869: coursecategories in configuration.db on the primary library server in a
8870: domain - to an array. Also generates javascript and idx hash used to
8871: generate Domain Coordinator interface for editing Course Categories.
8872:
8873: Inputs:
1.663 raeburn 8874:
1.655 raeburn 8875: categories (reference to hash of category definitions).
1.663 raeburn 8876:
1.655 raeburn 8877: cats (reference to array of arrays/hashes which encapsulates hierarchy of
8878: categories and subcategories).
1.663 raeburn 8879:
1.655 raeburn 8880: idx (reference to hash of counters used in Domain Coordinator interface for
8881: editing Course Categories).
1.663 raeburn 8882:
1.655 raeburn 8883: jsarray (reference to array of categories used to create Javascript arrays for
8884: Domain Coordinator interface for editing Course Categories).
8885:
8886: Returns: nothing
8887:
8888: Side effects: populates cats, idx and jsarray.
8889:
8890: =cut
8891:
8892: sub gather_categories {
8893: my ($categories,$cats,$idx,$jsarray) = @_;
8894: my %counters;
8895: my $num = 0;
8896: foreach my $item (keys(%{$categories})) {
8897: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
8898: if ($container eq '' && $depth == 0) {
8899: $cats->[$depth][$categories->{$item}] = $cat;
8900: } else {
8901: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
8902: }
8903: my ($escitem,$tail) = split(/:/,$item,2);
8904: if ($counters{$tail} eq '') {
8905: $counters{$tail} = $num;
8906: $num ++;
8907: }
8908: if (ref($idx) eq 'HASH') {
8909: $idx->{$item} = $counters{$tail};
8910: }
8911: if (ref($jsarray) eq 'ARRAY') {
8912: push(@{$jsarray->[$counters{$tail}]},$item);
8913: }
8914: }
8915: return;
8916: }
8917:
8918: =pod
8919:
8920: =item * &extract_categories()
8921:
8922: Used to generate breadcrumb trails for course categories.
8923:
8924: Inputs:
1.663 raeburn 8925:
1.655 raeburn 8926: categories (reference to hash of category definitions).
1.663 raeburn 8927:
1.655 raeburn 8928: cats (reference to array of arrays/hashes which encapsulates hierarchy of
8929: categories and subcategories).
1.663 raeburn 8930:
1.655 raeburn 8931: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 8932:
1.655 raeburn 8933: allitems (reference to hash - key is category key
8934: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 8935:
1.655 raeburn 8936: idx (reference to hash of counters used in Domain Coordinator interface for
8937: editing Course Categories).
1.663 raeburn 8938:
1.655 raeburn 8939: jsarray (reference to array of categories used to create Javascript arrays for
8940: Domain Coordinator interface for editing Course Categories).
8941:
1.665 raeburn 8942: subcats (reference to hash of arrays containing all subcategories within each
8943: category, -recursive)
8944:
1.655 raeburn 8945: Returns: nothing
8946:
8947: Side effects: populates trails and allitems hash references.
8948:
8949: =cut
8950:
8951: sub extract_categories {
1.665 raeburn 8952: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 8953: if (ref($categories) eq 'HASH') {
8954: &gather_categories($categories,$cats,$idx,$jsarray);
8955: if (ref($cats->[0]) eq 'ARRAY') {
8956: for (my $i=0; $i<@{$cats->[0]}; $i++) {
8957: my $name = $cats->[0][$i];
8958: my $item = &escape($name).'::0';
8959: my $trailstr;
8960: if ($name eq 'instcode') {
8961: $trailstr = &mt('Official courses (with institutional codes)');
8962: } else {
8963: $trailstr = $name;
8964: }
8965: if ($allitems->{$item} eq '') {
8966: push(@{$trails},$trailstr);
8967: $allitems->{$item} = scalar(@{$trails})-1;
8968: }
8969: my @parents = ($name);
8970: if (ref($cats->[1]{$name}) eq 'ARRAY') {
8971: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
8972: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 8973: if (ref($subcats) eq 'HASH') {
8974: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
8975: }
8976: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
8977: }
8978: } else {
8979: if (ref($subcats) eq 'HASH') {
8980: $subcats->{$item} = [];
1.655 raeburn 8981: }
8982: }
8983: }
8984: }
8985: }
8986: return;
8987: }
8988:
8989: =pod
8990:
8991: =item *&recurse_categories()
8992:
8993: Recursively used to generate breadcrumb trails for course categories.
8994:
8995: Inputs:
1.663 raeburn 8996:
1.655 raeburn 8997: cats (reference to array of arrays/hashes which encapsulates hierarchy of
8998: categories and subcategories).
1.663 raeburn 8999:
1.655 raeburn 9000: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 9001:
9002: category (current course category, for which breadcrumb trail is being generated).
9003:
9004: trails (reference to array of breadcrumb trails for each category).
9005:
1.655 raeburn 9006: allitems (reference to hash - key is category key
9007: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 9008:
1.655 raeburn 9009: parents (array containing containers directories for current category,
9010: back to top level).
9011:
9012: Returns: nothing
9013:
9014: Side effects: populates trails and allitems hash references
9015:
9016: =cut
9017:
9018: sub recurse_categories {
1.665 raeburn 9019: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 9020: my $shallower = $depth - 1;
9021: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
9022: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
9023: my $name = $cats->[$depth]{$category}[$k];
9024: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9025: my $trailstr = join(' -> ',(@{$parents},$category));
9026: if ($allitems->{$item} eq '') {
9027: push(@{$trails},$trailstr);
9028: $allitems->{$item} = scalar(@{$trails})-1;
9029: }
9030: my $deeper = $depth+1;
9031: push(@{$parents},$category);
1.665 raeburn 9032: if (ref($subcats) eq 'HASH') {
9033: my $subcat = &escape($name).':'.$category.':'.$depth;
9034: for (my $j=@{$parents}; $j>=0; $j--) {
9035: my $higher;
9036: if ($j > 0) {
9037: $higher = &escape($parents->[$j]).':'.
9038: &escape($parents->[$j-1]).':'.$j;
9039: } else {
9040: $higher = &escape($parents->[$j]).'::'.$j;
9041: }
9042: push(@{$subcats->{$higher}},$subcat);
9043: }
9044: }
9045: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
9046: $subcats);
1.655 raeburn 9047: pop(@{$parents});
9048: }
9049: } else {
9050: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9051: my $trailstr = join(' -> ',(@{$parents},$category));
9052: if ($allitems->{$item} eq '') {
9053: push(@{$trails},$trailstr);
9054: $allitems->{$item} = scalar(@{$trails})-1;
9055: }
9056: }
9057: return;
9058: }
9059:
1.663 raeburn 9060: =pod
9061:
9062: =item *&assign_categories_table()
9063:
9064: Create a datatable for display of hierarchical categories in a domain,
9065: with checkboxes to allow a course to be categorized.
9066:
9067: Inputs:
9068:
9069: cathash - reference to hash of categories defined for the domain (from
9070: configuration.db)
9071:
9072: currcat - scalar with an & separated list of categories assigned to a course.
9073:
9074: Returns: $output (markup to be displayed)
9075:
9076: =cut
9077:
9078: sub assign_categories_table {
9079: my ($cathash,$currcat) = @_;
9080: my $output;
9081: if (ref($cathash) eq 'HASH') {
9082: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
9083: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
9084: $maxdepth = scalar(@cats);
9085: if (@cats > 0) {
9086: my $itemcount = 0;
9087: if (ref($cats[0]) eq 'ARRAY') {
9088: $output = &Apache::loncommon::start_data_table();
9089: my @currcategories;
9090: if ($currcat ne '') {
9091: @currcategories = split('&',$currcat);
9092: }
9093: for (my $i=0; $i<@{$cats[0]}; $i++) {
9094: my $parent = $cats[0][$i];
9095: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9096: next if ($parent eq 'instcode');
9097: my $item = &escape($parent).'::0';
9098: my $checked = '';
9099: if (@currcategories > 0) {
9100: if (grep(/^\Q$item\E$/,@currcategories)) {
9101: $checked = ' checked="checked" ';
9102: }
9103: }
1.675 raeburn 9104: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
9105: '<input type="checkbox" name="usecategory" value="'.
9106: $item.'"'.$checked.' />'.$parent.'</span>'.
9107: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 9108: my $depth = 1;
9109: push(@path,$parent);
9110: $output .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
9111: pop(@path);
9112: $output .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
9113: $itemcount ++;
9114: }
9115: $output .= &Apache::loncommon::end_data_table();
9116: }
9117: }
9118: }
9119: return $output;
9120: }
9121:
9122: =pod
9123:
9124: =item *&assign_category_rows()
9125:
9126: Create a datatable row for display of nested categories in a domain,
9127: with checkboxes to allow a course to be categorized,called recursively.
9128:
9129: Inputs:
9130:
9131: itemcount - track row number for alternating colors
9132:
9133: cats - reference to array of arrays/hashes which encapsulates hierarchy of
9134: categories and subcategories.
9135:
9136: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
9137:
9138: parent - parent of current category item
9139:
9140: path - Array containing all categories back up through the hierarchy from the
9141: current category to the top level.
9142:
9143: currcategories - reference to array of current categories assigned to the course
9144:
9145: Returns: $output (markup to be displayed).
9146:
9147: =cut
9148:
9149: sub assign_category_rows {
9150: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
9151: my ($text,$name,$item,$chgstr);
9152: if (ref($cats) eq 'ARRAY') {
9153: my $maxdepth = scalar(@{$cats});
9154: if (ref($cats->[$depth]) eq 'HASH') {
9155: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
9156: my $numchildren = @{$cats->[$depth]{$parent}};
9157: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9158: $text .= '<td><table class="LC_datatable">';
9159: for (my $j=0; $j<$numchildren; $j++) {
9160: $name = $cats->[$depth]{$parent}[$j];
9161: $item = &escape($name).':'.&escape($parent).':'.$depth;
9162: my $deeper = $depth+1;
9163: my $checked = '';
9164: if (ref($currcategories) eq 'ARRAY') {
9165: if (@{$currcategories} > 0) {
9166: if (grep(/^\Q$item\E$/,@{$currcategories})) {
9167: $checked = ' checked="checked" ';
9168: }
9169: }
9170: }
1.664 raeburn 9171: $text .= '<tr><td><span class="LC_nobreak"><label>'.
9172: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 9173: $item.'"'.$checked.' />'.$name.'</label></span>'.
9174: '<input type="hidden" name="catname" value="'.$name.'" />'.
9175: '</td><td>';
1.663 raeburn 9176: if (ref($path) eq 'ARRAY') {
9177: push(@{$path},$name);
9178: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
9179: pop(@{$path});
9180: }
9181: $text .= '</td></tr>';
9182: }
9183: $text .= '</table></td>';
9184: }
9185: }
9186: }
9187: return $text;
9188: }
9189:
1.655 raeburn 9190: ############################################################
9191: ############################################################
9192:
9193:
1.443 albertel 9194: sub commit_customrole {
1.664 raeburn 9195: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 9196: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 9197: ($start?', '.&mt('starting').' '.localtime($start):'').
9198: ($end?', ending '.localtime($end):'').': <b>'.
9199: &Apache::lonnet::assigncustomrole(
1.664 raeburn 9200: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 9201: '</b><br />';
9202: return $output;
9203: }
9204:
9205: sub commit_standardrole {
1.541 raeburn 9206: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
9207: my ($output,$logmsg,$linefeed);
9208: if ($context eq 'auto') {
9209: $linefeed = "\n";
9210: } else {
9211: $linefeed = "<br />\n";
9212: }
1.443 albertel 9213: if ($three eq 'st') {
1.541 raeburn 9214: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
9215: $one,$two,$sec,$context);
9216: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 9217: ($result eq 'unknown_course') || ($result eq 'refused')) {
9218: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 9219: } else {
1.541 raeburn 9220: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 9221: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9222: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
9223: if ($context eq 'auto') {
9224: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
9225: } else {
9226: $output .= '<b>'.$result.'</b>'.$linefeed.
9227: &mt('Add to classlist').': <b>ok</b>';
9228: }
9229: $output .= $linefeed;
1.443 albertel 9230: }
9231: } else {
9232: $output = &mt('Assigning').' '.$three.' in '.$url.
9233: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9234: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 9235: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 9236: if ($context eq 'auto') {
9237: $output .= $result.$linefeed;
9238: } else {
9239: $output .= '<b>'.$result.'</b>'.$linefeed;
9240: }
1.443 albertel 9241: }
9242: return $output;
9243: }
9244:
9245: sub commit_studentrole {
1.541 raeburn 9246: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626 raeburn 9247: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 9248: if ($context eq 'auto') {
9249: $linefeed = "\n";
9250: } else {
9251: $linefeed = '<br />'."\n";
9252: }
1.443 albertel 9253: if (defined($one) && defined($two)) {
9254: my $cid=$one.'_'.$two;
9255: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
9256: my $secchange = 0;
9257: my $expire_role_result;
9258: my $modify_section_result;
1.628 raeburn 9259: if ($oldsec ne '-1') {
9260: if ($oldsec ne $sec) {
1.443 albertel 9261: $secchange = 1;
1.628 raeburn 9262: my $now = time;
1.443 albertel 9263: my $uurl='/'.$cid;
9264: $uurl=~s/\_/\//g;
9265: if ($oldsec) {
9266: $uurl.='/'.$oldsec;
9267: }
1.626 raeburn 9268: $oldsecurl = $uurl;
1.628 raeburn 9269: $expire_role_result =
1.652 raeburn 9270: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 9271: if ($env{'request.course.sec'} ne '') {
9272: if ($expire_role_result eq 'refused') {
9273: my @roles = ('st');
9274: my @statuses = ('previous');
9275: my @roledoms = ($one);
9276: my $withsec = 1;
9277: my %roleshash =
9278: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
9279: \@statuses,\@roles,\@roledoms,$withsec);
9280: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
9281: my ($oldstart,$oldend) =
9282: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
9283: if ($oldend > 0 && $oldend <= $now) {
9284: $expire_role_result = 'ok';
9285: }
9286: }
9287: }
9288: }
1.443 albertel 9289: $result = $expire_role_result;
9290: }
9291: }
9292: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652 raeburn 9293: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443 albertel 9294: if ($modify_section_result =~ /^ok/) {
9295: if ($secchange == 1) {
1.628 raeburn 9296: if ($sec eq '') {
9297: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
9298: } else {
9299: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
9300: }
1.443 albertel 9301: } elsif ($oldsec eq '-1') {
1.628 raeburn 9302: if ($sec eq '') {
9303: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
9304: } else {
9305: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9306: }
1.443 albertel 9307: } else {
1.628 raeburn 9308: if ($sec eq '') {
9309: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
9310: } else {
9311: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9312: }
1.443 albertel 9313: }
9314: } else {
1.628 raeburn 9315: if ($secchange) {
9316: $$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;
9317: } else {
9318: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
9319: }
1.443 albertel 9320: }
9321: $result = $modify_section_result;
9322: } elsif ($secchange == 1) {
1.628 raeburn 9323: if ($oldsec eq '') {
9324: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
9325: } else {
9326: $$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;
9327: }
1.626 raeburn 9328: if ($expire_role_result eq 'refused') {
9329: my $newsecurl = '/'.$cid;
9330: $newsecurl =~ s/\_/\//g;
9331: if ($sec ne '') {
9332: $newsecurl.='/'.$sec;
9333: }
9334: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
9335: if ($sec eq '') {
9336: $$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;
9337: } else {
9338: $$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;
9339: }
9340: }
9341: }
1.443 albertel 9342: }
9343: } else {
1.626 raeburn 9344: $$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 9345: $result = "error: incomplete course id\n";
9346: }
9347: return $result;
9348: }
9349:
9350: ############################################################
9351: ############################################################
9352:
1.566 albertel 9353: sub check_clone {
1.578 raeburn 9354: my ($args,$linefeed) = @_;
1.566 albertel 9355: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
9356: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
9357: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
9358: my $clonemsg;
9359: my $can_clone = 0;
9360:
9361: if ($clonehome eq 'no_host') {
1.578 raeburn 9362: $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 9363: } else {
9364: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.568 albertel 9365: if ($env{'request.role.domain'} eq $args->{'clonedomain'}) {
1.566 albertel 9366: $can_clone = 1;
9367: } else {
9368: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
9369: $args->{'clonedomain'},$args->{'clonecourse'});
9370: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 9371: if (grep(/^\*$/,@cloners)) {
9372: $can_clone = 1;
9373: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
9374: $can_clone = 1;
9375: } else {
9376: my %roleshash =
9377: &Apache::lonnet::get_my_roles($args->{'ccuname'},
9378: $args->{'ccdomain'},
9379: 'userroles',['active'],['cc'],
9380: [$args->{'clonedomain'}]);
9381: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
9382: $can_clone = 1;
9383: } else {
9384: $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'});
9385: }
1.566 albertel 9386: }
1.578 raeburn 9387: }
1.566 albertel 9388: }
9389: return ($can_clone, $clonemsg, $cloneid, $clonehome);
9390: }
9391:
1.444 albertel 9392: sub construct_course {
1.541 raeburn 9393: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context) = @_;
1.444 albertel 9394: my $outcome;
1.541 raeburn 9395: my $linefeed = '<br />'."\n";
9396: if ($context eq 'auto') {
9397: $linefeed = "\n";
9398: }
1.566 albertel 9399:
9400: #
9401: # Are we cloning?
9402: #
9403: my ($can_clone, $clonemsg, $cloneid, $clonehome);
9404: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 9405: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 9406: if ($context ne 'auto') {
1.578 raeburn 9407: if ($clonemsg ne '') {
9408: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
9409: }
1.566 albertel 9410: }
9411: $outcome .= $clonemsg.$linefeed;
9412:
9413: if (!$can_clone) {
9414: return (0,$outcome);
9415: }
9416: }
9417:
1.444 albertel 9418: #
9419: # Open course
9420: #
9421: my $crstype = lc($args->{'crstype'});
9422: my %cenv=();
9423: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
9424: $args->{'cdescr'},
9425: $args->{'curl'},
9426: $args->{'course_home'},
9427: $args->{'nonstandard'},
9428: $args->{'crscode'},
9429: $args->{'ccuname'}.':'.
9430: $args->{'ccdomain'},
9431: $args->{'crstype'});
9432:
9433: # Note: The testing routines depend on this being output; see
9434: # Utils::Course. This needs to at least be output as a comment
9435: # if anyone ever decides to not show this, and Utils::Course::new
9436: # will need to be suitably modified.
1.541 raeburn 9437: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.444 albertel 9438: #
9439: # Check if created correctly
9440: #
1.479 albertel 9441: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 9442: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.541 raeburn 9443: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 9444:
1.444 albertel 9445: #
1.566 albertel 9446: # Do the cloning
9447: #
9448: if ($can_clone && $cloneid) {
9449: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
9450: if ($context ne 'auto') {
9451: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
9452: }
9453: $outcome .= $clonemsg.$linefeed;
9454: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 9455: # Copy all files
1.637 www 9456: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 9457: # Restore URL
1.566 albertel 9458: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 9459: # Restore title
1.566 albertel 9460: $cenv{'description'}=$oldcenv{'description'};
1.444 albertel 9461: # Mark as cloned
1.566 albertel 9462: $cenv{'clonedfrom'}=$cloneid;
1.638 www 9463: # Need to clone grading mode
9464: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
9465: $cenv{'grading'}=$newenv{'grading'};
9466: # Do not clone these environment entries
9467: &Apache::lonnet::del('environment',
9468: ['default_enrollment_start_date',
9469: 'default_enrollment_end_date',
9470: 'question.email',
9471: 'policy.email',
9472: 'comment.email',
9473: 'pch.users.denied',
1.725 raeburn 9474: 'plc.users.denied',
9475: 'hidefromcat',
9476: 'categories'],
1.638 www 9477: $$crsudom,$$crsunum);
1.444 albertel 9478: }
1.566 albertel 9479:
1.444 albertel 9480: #
9481: # Set environment (will override cloned, if existing)
9482: #
9483: my @sections = ();
9484: my @xlists = ();
9485: if ($args->{'crstype'}) {
9486: $cenv{'type'}=$args->{'crstype'};
9487: }
9488: if ($args->{'crsid'}) {
9489: $cenv{'courseid'}=$args->{'crsid'};
9490: }
9491: if ($args->{'crscode'}) {
9492: $cenv{'internal.coursecode'}=$args->{'crscode'};
9493: }
9494: if ($args->{'crsquota'} ne '') {
9495: $cenv{'internal.coursequota'}=$args->{'crsquota'};
9496: } else {
9497: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
9498: }
9499: if ($args->{'ccuname'}) {
9500: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
9501: ':'.$args->{'ccdomain'};
9502: } else {
9503: $cenv{'internal.courseowner'} = $args->{'curruser'};
9504: }
9505: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
9506: if ($args->{'crssections'}) {
9507: $cenv{'internal.sectionnums'} = '';
9508: if ($args->{'crssections'} =~ m/,/) {
9509: @sections = split/,/,$args->{'crssections'};
9510: } else {
9511: $sections[0] = $args->{'crssections'};
9512: }
9513: if (@sections > 0) {
9514: foreach my $item (@sections) {
9515: my ($sec,$gp) = split/:/,$item;
9516: my $class = $args->{'crscode'}.$sec;
9517: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
9518: $cenv{'internal.sectionnums'} .= $item.',';
9519: unless ($addcheck eq 'ok') {
9520: push @badclasses, $class;
9521: }
9522: }
9523: $cenv{'internal.sectionnums'} =~ s/,$//;
9524: }
9525: }
9526: # do not hide course coordinator from staff listing,
9527: # even if privileged
9528: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9529: # add crosslistings
9530: if ($args->{'crsxlist'}) {
9531: $cenv{'internal.crosslistings'}='';
9532: if ($args->{'crsxlist'} =~ m/,/) {
9533: @xlists = split/,/,$args->{'crsxlist'};
9534: } else {
9535: $xlists[0] = $args->{'crsxlist'};
9536: }
9537: if (@xlists > 0) {
9538: foreach my $item (@xlists) {
9539: my ($xl,$gp) = split/:/,$item;
9540: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
9541: $cenv{'internal.crosslistings'} .= $item.',';
9542: unless ($addcheck eq 'ok') {
9543: push @badclasses, $xl;
9544: }
9545: }
9546: $cenv{'internal.crosslistings'} =~ s/,$//;
9547: }
9548: }
9549: if ($args->{'autoadds'}) {
9550: $cenv{'internal.autoadds'}=$args->{'autoadds'};
9551: }
9552: if ($args->{'autodrops'}) {
9553: $cenv{'internal.autodrops'}=$args->{'autodrops'};
9554: }
9555: # check for notification of enrollment changes
9556: my @notified = ();
9557: if ($args->{'notify_owner'}) {
9558: if ($args->{'ccuname'} ne '') {
9559: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
9560: }
9561: }
9562: if ($args->{'notify_dc'}) {
9563: if ($uname ne '') {
1.630 raeburn 9564: push(@notified,$uname.':'.$udom);
1.444 albertel 9565: }
9566: }
9567: if (@notified > 0) {
9568: my $notifylist;
9569: if (@notified > 1) {
9570: $notifylist = join(',',@notified);
9571: } else {
9572: $notifylist = $notified[0];
9573: }
9574: $cenv{'internal.notifylist'} = $notifylist;
9575: }
9576: if (@badclasses > 0) {
9577: my %lt=&Apache::lonlocal::texthash(
9578: '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',
9579: 'dnhr' => 'does not have rights to access enrollment in these classes',
9580: 'adby' => 'as determined by the policies of your institution on access to official classlists'
9581: );
1.541 raeburn 9582: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
9583: ' ('.$lt{'adby'}.')';
9584: if ($context eq 'auto') {
9585: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 9586: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 9587: foreach my $item (@badclasses) {
9588: if ($context eq 'auto') {
9589: $outcome .= " - $item\n";
9590: } else {
9591: $outcome .= "<li>$item</li>\n";
9592: }
9593: }
9594: if ($context eq 'auto') {
9595: $outcome .= $linefeed;
9596: } else {
1.566 albertel 9597: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 9598: }
9599: }
1.444 albertel 9600: }
9601: if ($args->{'no_end_date'}) {
9602: $args->{'endaccess'} = 0;
9603: }
9604: $cenv{'internal.autostart'}=$args->{'enrollstart'};
9605: $cenv{'internal.autoend'}=$args->{'enrollend'};
9606: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
9607: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
9608: if ($args->{'showphotos'}) {
9609: $cenv{'internal.showphotos'}=$args->{'showphotos'};
9610: }
9611: $cenv{'internal.authtype'} = $args->{'authtype'};
9612: $cenv{'internal.autharg'} = $args->{'autharg'};
9613: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
9614: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 9615: 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');
9616: if ($context eq 'auto') {
9617: $outcome .= $krb_msg;
9618: } else {
1.566 albertel 9619: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 9620: }
9621: $outcome .= $linefeed;
1.444 albertel 9622: }
9623: }
9624: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
9625: if ($args->{'setpolicy'}) {
9626: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9627: }
9628: if ($args->{'setcontent'}) {
9629: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9630: }
9631: }
9632: if ($args->{'reshome'}) {
9633: $cenv{'reshome'}=$args->{'reshome'}.'/';
9634: $cenv{'reshome'}=~s/\/+$/\//;
9635: }
9636: #
9637: # course has keyed access
9638: #
9639: if ($args->{'setkeys'}) {
9640: $cenv{'keyaccess'}='yes';
9641: }
9642: # if specified, key authority is not course, but user
9643: # only active if keyaccess is yes
9644: if ($args->{'keyauth'}) {
1.487 albertel 9645: my ($user,$domain) = split(':',$args->{'keyauth'});
9646: $user = &LONCAPA::clean_username($user);
9647: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 9648: if ($user ne '' && $domain ne '') {
1.487 albertel 9649: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 9650: }
9651: }
9652:
9653: if ($args->{'disresdis'}) {
9654: $cenv{'pch.roles.denied'}='st';
9655: }
9656: if ($args->{'disablechat'}) {
9657: $cenv{'plc.roles.denied'}='st';
9658: }
9659:
9660: # Record we've not yet viewed the Course Initialization Helper for this
9661: # course
9662: $cenv{'course.helper.not.run'} = 1;
9663: #
9664: # Use new Randomseed
9665: #
9666: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
9667: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
9668: #
9669: # The encryption code and receipt prefix for this course
9670: #
9671: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
9672: $cenv{'internal.encpref'}=100+int(9*rand(99));
9673: #
9674: # By default, use standard grading
9675: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
9676:
1.541 raeburn 9677: $outcome .= $linefeed.&mt('Setting environment').': '.
9678: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 9679: #
9680: # Open all assignments
9681: #
9682: if ($args->{'openall'}) {
9683: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
9684: my %storecontent = ($storeunder => time,
9685: $storeunder.'.type' => 'date_start');
9686:
9687: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 9688: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 9689: }
9690: #
9691: # Set first page
9692: #
9693: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
9694: || ($cloneid)) {
1.445 albertel 9695: use LONCAPA::map;
1.444 albertel 9696: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 9697:
9698: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
9699: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
9700:
1.444 albertel 9701: $outcome .= ($fatal?$errtext:'read ok').' - ';
9702: my $title; my $url;
9703: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 9704: $title=&mt('Syllabus');
1.444 albertel 9705: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
9706: } else {
1.690 bisitz 9707: $title=&mt('Navigate Contents');
1.444 albertel 9708: $url='/adm/navmaps';
9709: }
1.445 albertel 9710:
9711: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
9712: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
9713:
9714: if ($errtext) { $fatal=2; }
1.541 raeburn 9715: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 9716: }
1.566 albertel 9717:
9718: return (1,$outcome);
1.444 albertel 9719: }
9720:
9721: ############################################################
9722: ############################################################
9723:
1.378 raeburn 9724: sub course_type {
9725: my ($cid) = @_;
9726: if (!defined($cid)) {
9727: $cid = $env{'request.course.id'};
9728: }
1.404 albertel 9729: if (defined($env{'course.'.$cid.'.type'})) {
9730: return $env{'course.'.$cid.'.type'};
1.378 raeburn 9731: } else {
9732: return 'Course';
1.377 raeburn 9733: }
9734: }
1.156 albertel 9735:
1.406 raeburn 9736: sub group_term {
9737: my $crstype = &course_type();
9738: my %names = (
9739: 'Course' => 'group',
9740: 'Group' => 'team',
9741: );
9742: return $names{$crstype};
9743: }
9744:
1.156 albertel 9745: sub icon {
9746: my ($file)=@_;
1.505 albertel 9747: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 9748: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 9749: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 9750: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
9751: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
9752: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
9753: $curfext.".gif") {
9754: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
9755: $curfext.".gif";
9756: }
9757: }
1.249 albertel 9758: return &lonhttpdurl($iconname);
1.154 albertel 9759: }
1.84 albertel 9760:
1.575 albertel 9761: sub lonhttpdurl {
1.692 www 9762: #
9763: # Had been used for "small fry" static images on separate port 8080.
9764: # Modify here if lightweight http functionality desired again.
9765: # Currently eliminated due to increasing firewall issues.
9766: #
1.575 albertel 9767: my ($url)=@_;
1.692 www 9768: return $url;
1.215 albertel 9769: }
9770:
1.213 albertel 9771: sub connection_aborted {
9772: my ($r)=@_;
9773: $r->print(" ");$r->rflush();
9774: my $c = $r->connection;
9775: return $c->aborted();
9776: }
9777:
1.221 foxr 9778: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 9779: # strings as 'strings'.
9780: sub escape_single {
1.221 foxr 9781: my ($input) = @_;
1.223 albertel 9782: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 9783: $input =~ s/\'/\\\'/g; # Esacpe the 's....
9784: return $input;
9785: }
1.223 albertel 9786:
1.222 foxr 9787: # Same as escape_single, but escape's "'s This
9788: # can be used for "strings"
9789: sub escape_double {
9790: my ($input) = @_;
9791: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
9792: $input =~ s/\"/\\\"/g; # Esacpe the "s....
9793: return $input;
9794: }
1.223 albertel 9795:
1.222 foxr 9796: # Escapes the last element of a full URL.
9797: sub escape_url {
9798: my ($url) = @_;
1.238 raeburn 9799: my @urlslices = split(/\//, $url,-1);
1.369 www 9800: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 9801: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 9802: }
1.462 albertel 9803:
9804: # -------------------------------------------------------- Initliaze user login
9805: sub init_user_environment {
1.463 albertel 9806: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 9807: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
9808:
9809: my $public=($username eq 'public' && $domain eq 'public');
9810:
9811: # See if old ID present, if so, remove
9812:
9813: my ($filename,$cookie,$userroles);
9814: my $now=time;
9815:
9816: if ($public) {
9817: my $max_public=100;
9818: my $oldest;
9819: my $oldest_time=0;
9820: for(my $next=1;$next<=$max_public;$next++) {
9821: if (-e $lonids."/publicuser_$next.id") {
9822: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
9823: if ($mtime<$oldest_time || !$oldest_time) {
9824: $oldest_time=$mtime;
9825: $oldest=$next;
9826: }
9827: } else {
9828: $cookie="publicuser_$next";
9829: last;
9830: }
9831: }
9832: if (!$cookie) { $cookie="publicuser_$oldest"; }
9833: } else {
1.463 albertel 9834: # if this isn't a robot, kill any existing non-robot sessions
9835: if (!$args->{'robot'}) {
9836: opendir(DIR,$lonids);
9837: while ($filename=readdir(DIR)) {
9838: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
9839: unlink($lonids.'/'.$filename);
9840: }
1.462 albertel 9841: }
1.463 albertel 9842: closedir(DIR);
1.462 albertel 9843: }
9844: # Give them a new cookie
1.463 albertel 9845: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 9846: : $now.$$.int(rand(10000)));
1.463 albertel 9847: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 9848:
9849: # Initialize roles
9850:
9851: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
9852: }
9853: # ------------------------------------ Check browser type and MathML capability
9854:
9855: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
9856: $clientunicode,$clientos) = &decode_user_agent($r);
9857:
9858: # -------------------------------------- Any accessibility options to remember?
9859: if (($form->{'interface'}) && ($form->{'remember'} eq 'true')) {
9860: foreach my $option ('imagesuppress','appletsuppress',
9861: 'embedsuppress','fontenhance','blackwhite') {
9862: if ($form->{$option} eq 'true') {
9863: &Apache::lonnet::put('environment',{$option => 'on'},
9864: $domain,$username);
9865: } else {
9866: &Apache::lonnet::del('environment',[$option],
9867: $domain,$username);
9868: }
9869: }
9870: }
9871: # ------------------------------------------------------------- Get environment
9872:
9873: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
9874: my ($tmp) = keys(%userenv);
9875: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9876: # default remote control to off
9877: if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
9878: } else {
9879: undef(%userenv);
9880: }
9881: if (($userenv{'interface'}) && (!$form->{'interface'})) {
9882: $form->{'interface'}=$userenv{'interface'};
9883: }
9884: $env{'environment.remote'}=$userenv{'remote'};
9885: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
9886:
9887: # --------------- Do not trust query string to be put directly into environment
9888: foreach my $option ('imagesuppress','appletsuppress',
9889: 'embedsuppress','fontenhance','blackwhite',
9890: 'interface','localpath','localres') {
9891: $form->{$option}=~s/[\n\r\=]//gs;
9892: }
9893: # --------------------------------------------------------- Write first profile
9894:
9895: {
9896: my %initial_env =
9897: ("user.name" => $username,
9898: "user.domain" => $domain,
9899: "user.home" => $authhost,
9900: "browser.type" => $clientbrowser,
9901: "browser.version" => $clientversion,
9902: "browser.mathml" => $clientmathml,
9903: "browser.unicode" => $clientunicode,
9904: "browser.os" => $clientos,
9905: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
9906: "request.course.fn" => '',
9907: "request.course.uri" => '',
9908: "request.course.sec" => '',
9909: "request.role" => 'cm',
9910: "request.role.adv" => $env{'user.adv'},
9911: "request.host" => $ENV{'REMOTE_ADDR'},);
9912:
9913: if ($form->{'localpath'}) {
9914: $initial_env{"browser.localpath"} = $form->{'localpath'};
9915: $initial_env{"browser.localres"} = $form->{'localres'};
9916: }
9917:
9918: if ($public) {
9919: $initial_env{"environment.remote"} = "off";
9920: }
9921: if ($form->{'interface'}) {
9922: $form->{'interface'}=~s/\W//gs;
9923: $initial_env{"browser.interface"} = $form->{'interface'};
9924: $env{'browser.interface'}=$form->{'interface'};
9925: foreach my $option ('imagesuppress','appletsuppress',
9926: 'embedsuppress','fontenhance','blackwhite') {
9927: if (($form->{$option} eq 'true') ||
9928: ($userenv{$option} eq 'on')) {
9929: $initial_env{"browser.$option"} = "on";
9930: }
9931: }
9932: }
9933:
1.724 raeburn 9934: foreach my $tool ('aboutme','blog','portfolio') {
9935: $userenv{'availabletools.'.$tool} =
9936: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload');
9937: }
9938:
1.462 albertel 9939: $env{'user.environment'} = "$lonids/$cookie.id";
9940:
9941: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
9942: &GDBM_WRCREAT(),0640)) {
9943: &_add_to_env(\%disk_env,\%initial_env);
9944: &_add_to_env(\%disk_env,\%userenv,'environment.');
9945: &_add_to_env(\%disk_env,$userroles);
1.463 albertel 9946: if (ref($args->{'extra_env'})) {
9947: &_add_to_env(\%disk_env,$args->{'extra_env'});
9948: }
1.462 albertel 9949: untie(%disk_env);
9950: } else {
1.705 tempelho 9951: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
9952: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 9953: return 'error: '.$!;
9954: }
9955: }
9956: $env{'request.role'}='cm';
9957: $env{'request.role.adv'}=$env{'user.adv'};
9958: $env{'browser.type'}=$clientbrowser;
9959:
9960: return $cookie;
9961:
9962: }
9963:
9964: sub _add_to_env {
9965: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 9966: if (ref($env_data) eq 'HASH') {
9967: while (my ($key,$value) = each(%$env_data)) {
9968: $idf->{$prefix.$key} = $value;
9969: $env{$prefix.$key} = $value;
9970: }
1.462 albertel 9971: }
9972: }
9973:
1.685 tempelho 9974: # --- Get the symbolic name of a problem and the url
9975: sub get_symb {
9976: my ($request,$silent) = @_;
1.726 raeburn 9977: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 9978: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
9979: if ($symb eq '') {
9980: if (!$silent) {
9981: $request->print("Unable to handle ambiguous references:$url:.");
9982: return ();
9983: }
9984: }
9985: &Apache::lonenc::check_decrypt(\$symb);
9986: return ($symb);
9987: }
9988:
9989: # --------------------------------------------------------------Get annotation
9990:
9991: sub get_annotation {
9992: my ($symb,$enc) = @_;
9993:
9994: my $key = $symb;
9995: if (!$enc) {
9996: $key =
9997: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
9998: }
9999: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
10000: return $annotation{$key};
10001: }
10002:
10003: sub clean_symb {
1.731 raeburn 10004: my ($symb,$delete_enc) = @_;
1.685 tempelho 10005:
10006: &Apache::lonenc::check_decrypt(\$symb);
10007: my $enc = $env{'request.enc'};
1.731 raeburn 10008: if ($delete_enc) {
1.730 raeburn 10009: delete($env{'request.enc'});
10010: }
1.685 tempelho 10011:
10012: return ($symb,$enc);
10013: }
1.462 albertel 10014:
1.41 ng 10015: =pod
10016:
10017: =back
10018:
1.112 bowersj2 10019: =cut
1.41 ng 10020:
1.112 bowersj2 10021: 1;
10022: __END__;
1.41 ng 10023:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>